Spaces:
Sleeping
Sleeping
File size: 38,881 Bytes
7aec436 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
<script>
import {onDestroy} from 'svelte';
import {_} from '../locales/';
import {slide, fade} from 'svelte/transition';
import Section from './Section.svelte';
import Button from '../p4/Button.svelte';
import ImageInput from './ImageInput.svelte';
import CustomExtensions from '../p4/CustomExtensions.svelte';
import LearnMore from './LearnMore.svelte';
import ColorPicker from './ColorPicker.svelte';
import Downloads from './Downloads.svelte';
import writablePersistentStore from './persistent-store';
import fileStore from './file-store';
import {progress, currentTask, error} from './stores';
import Preview from './preview';
import deepClone from './deep-clone';
import Packager from '../packager/web/export';
import Task from './task';
import downloadURL from './download-url';
import {recursivelySerializeBlobs, recursivelyDeserializeBlobs} from './blob-serializer';
import {readAsText} from '../common/readers';
import merge from './merge';
import DropArea from './DropArea.svelte';
import {APP_NAME} from '../packager/brand';
export let projectData;
export let title;
// JSON can't easily parse Infinity, so we'll just store large numbers instead
const ALMOST_INFINITY = 9999999999;
const cloudVariables = projectData.project.analysis.stageVariables
.filter(i => i.isCloud)
.map(i => i.name);
const defaultOptions = Packager.DEFAULT_OPTIONS();
defaultOptions.projectId = projectData.projectId || `p4-${projectData.uniqueId}`;
for (const variable of cloudVariables) {
defaultOptions.cloudVariables.custom[variable] = 'ws';
}
defaultOptions.app.packageName = Packager.getDefaultPackageNameFromFileName(projectData.title);
defaultOptions.app.windowTitle = Packager.getWindowTitleFromFileName(projectData.title);
defaultOptions.extensions = projectData.project.analysis.extensions;
const options = writablePersistentStore(`PackagerOptions.${projectData.uniqueId}`, defaultOptions);
// Compatibility with https://github.com/TurboWarp/packager/commit/f66199abd1c896c11aa69247275a1594fdfc95b8
$options.extensions = $options.extensions.map(i => {
if (typeof i === 'object' && i) return i.url || '';
return i;
});
const hasMagicComment = (magic) => projectData.project.analysis.stageComments.find(
(text) => text.split('\n').find((line) => line.endsWith(magic))
);
const hasSettingsStoredInProject = hasMagicComment(' // _twconfig_');
let result = null;
let previewer = null;
const resetResult = () => {
previewer = null;
if (result) {
URL.revokeObjectURL(result.url);
}
result = null;
}
$: if (previewer) {
previewer.setProgress($progress.progress, $progress.text);
}
$: $options, resetResult(), currentTask.abort();
const icon = fileStore.writableFileStore(`PackagerOptions.icon.${projectData.uniqueId}`);
$: $options.app.icon = $icon;
const customCursorIcon = fileStore.writableFileStore(`PackagerOptions.customCursorIcon.${projectData.uniqueId}`);
$: $options.cursor.custom = $customCursorIcon;
const loadingScreenImage = fileStore.writableFileStore(`PackagerOptions.loadingScreenImage.${projectData.uniqueId}`);
$: $options.loadingScreen.image = $loadingScreenImage;
$: title = $options.app.windowTitle;
const setOptions = (newOptions) => {
$options = newOptions;
$icon = $options.app.icon;
$customCursorIcon = $options.cursor.custom;
$loadingScreenImage = $options.loadingScreen.image;
};
const otherEnvironmentsInitiallyOpen = ![
'html',
'zip',
'electron-win32',
'webview-mac',
'electron-linux64'
].includes($options.target);
const advancedOptionsInitiallyOpen = (
$options.compiler.enabled !== defaultOptions.compiler.enabled ||
$options.compiler.warpTimer !== defaultOptions.compiler.warpTimer ||
$options.extensions.length !== 0 ||
$options.bakeExtensions !== defaultOptions.bakeExtensions ||
$options.custom.css !== '' ||
$options.custom.js !== '' ||
$options.projectId !== defaultOptions.projectId ||
$options.packagedRuntime !== defaultOptions.packagedRuntime ||
$options.maxTextureDimension !== defaultOptions.maxTextureDimension
);
const automaticallyCenterCursor = () => {
const icon = $customCursorIcon;
const url = URL.createObjectURL(icon)
const image = new Image();
const cleanup = () => {
image.onerror = null;
image.onload = null;
URL.revokeObjectURL(url);
};
image.onload = () => {
$options.cursor.center.x = Math.round(image.width / 2);
$options.cursor.center.y = Math.round(image.height / 2);
cleanup();
};
image.onerror = () => {
cleanup();
$error = new Error('Image could not be loaded');
throw $error;
};
image.src = url;
};
const runPackager = async (task, options) => {
const packager = new Packager();
packager.options = options;
packager.project = projectData.project;
task.addEventListener('abort', () => {
packager.abort();
});
task.setProgressText($_('progress.loadingScripts'));
packager.addEventListener('fetch-extensions', ({detail}) => {
task.setProgressText($_('progress.downloadingExtensions'));
task.setProgress(detail.progress);
});
packager.addEventListener('large-asset-fetch', ({detail}) => {
let thing;
if (detail.asset.startsWith('nwjs-')) {
thing = 'NW.js';
} else if (detail.asset.startsWith('electron-')) {
thing = 'Electron';
} else if (detail.asset === 'webview-mac') {
thing = 'WKWebView';
}
if (thing) {
task.setProgressText($_('progress.loadingLargeAsset').replace('{thing}', thing));
}
task.setProgress(detail.progress);
});
packager.addEventListener('zip-progress', ({detail}) => {
task.setProgressText($_('progress.compressingProject'));
task.setProgress(detail.progress);
});
const result = await packager.package();
result.blob = new Blob([result.data], {
type: result.type
});
result.url = URL.createObjectURL(result.blob);
return result;
};
const pack = async () => {
resetResult();
const task = new Task();
result = await task.do(runPackager(task, deepClone($options)));
task.done();
downloadURL(result.filename, result.url);
};
const preview = async () => {
resetResult();
previewer = new Preview();
const task = new Task();
const optionsClone = deepClone($options);
optionsClone.target = 'html';
try {
result = await task.do(runPackager(task, optionsClone));
task.done();
previewer.setContent(result.blob);
} catch (e) {
previewer.close();
}
};
const resetOptions = (properties) => {
for (const key of properties) {
let current = $options;
let defaults = defaultOptions;
const parts = key.split('.');
const lastPart = parts.pop();
for (const i of parts) {
current = current[i];
defaults = defaults[i];
}
current[lastPart] = deepClone(defaults[lastPart]);
}
$options = $options;
};
const resetAll = () => {
if (confirm($_('reset.confirmAll'))) {
resetOptions(Object.keys($options));
$icon = null;
$customCursorIcon = null;
$loadingScreenImage = null;
}
};
const exportOptions = async () => {
const exported = await recursivelySerializeBlobs($options);
const blob = new Blob([JSON.stringify(exported)], {
type: 'application/json'
});
const url = URL.createObjectURL(blob);
const formattedAppName = APP_NAME
.replace(/[^a-z0-9 ]/gi, '')
.replace(/ /g, '-')
.toLowerCase();
downloadURL(`${formattedAppName}-settings.json`, url);
URL.revokeObjectURL(url);
};
const importOptions = async () => {
const input = document.createElement("input");
input.type = 'file';
input.accept = '.json';
input.addEventListener('change', (e) => {
importOptionsFromDataTransfer(e.target);
});
document.body.appendChild(input);
input.click();
input.remove();
};
const importOptionsFromDataTransfer = async (dataTransfer) => {
const file = dataTransfer.files[0];
if (!file) {
// Should never happen.
return;
}
try {
const text = await readAsText(file);
const parsed = JSON.parse(text);
const deserialized = recursivelyDeserializeBlobs(parsed);
const copiedDefaultOptions = deepClone(defaultOptions);
const mergedWithDefaults = merge(deserialized, copiedDefaultOptions);
const isUnsafe = Packager.usesUnsafeOptions(mergedWithDefaults);
if (!isUnsafe || confirm($_('options.confirmImportUnsafe'))) {
setOptions(mergedWithDefaults);
}
} catch (e) {
$error = e;
}
};
onDestroy(() => {
if (result) {
URL.revokeObjectURL(result.url);
}
});
</script>
<style>
.option {
display: block;
margin: 4px 0;
}
.group {
margin: 12px 0;
}
p {
margin: 8px 0;
}
.group:last-child, .option:last-child, p:last-child {
margin-bottom: 0;
}
textarea {
box-sizing: border-box;
width: 100%;
min-width: 100%;
height: 150px;
}
input[type="text"] {
width: 200px;
}
input[type="text"].shorter {
width: 150px;
}
input[type="number"] {
width: 50px;
}
input:invalid {
outline: 2px solid red;
}
.warning {
font-weight: bold;
background: yellow;
color: black;
padding: 10px;
border-radius: 10px;
}
.buttons {
display: flex;
}
.button {
margin-right: 4px;
}
.side-buttons {
display: flex;
margin-left: auto;
}
</style>
<Section
accent="#FFAB19"
reset={() => {
resetOptions([
'turbo',
'framerate',
'interpolation',
'highQualityPen',
'maxClones',
'fencing',
'miscLimits',
'dangerousOptimizations',
'stageWidth',
'stageHeight',
'resizeMode',
'username'
]);
}}
>
<div>
<h2>{$_('options.runtimeOptions')}</h2>
{#if hasSettingsStoredInProject}
<div class="group">
{$_('options.storedWarning')}
</div>
{/if}
<label class="option">
<input type="checkbox" bind:checked={$options.turbo}>
{$_('options.turbo')}
</label>
<div class="option">
<label>
{$_('options.framerate')}
<input type="number" min="0" max="240" bind:value={$options.framerate}>
</label>
<LearnMore slug="custom-fps" />
</div>
<div class="option">
<label>
<input type="checkbox" bind:checked={$options.interpolation}>
{$_('options.interpolation')}
</label>
<LearnMore slug="interpolation" />
</div>
<div class="option">
<label>
<input type="checkbox" bind:checked={$options.highQualityPen}>
{$_('options.highQualityPen')}
</label>
<LearnMore slug="high-quality-pen" />
</div>
<div class="option">
<label>
<input type="checkbox" checked={$options.maxClones === ALMOST_INFINITY} on:change={(e) => {
$options.maxClones = e.target.checked ? ALMOST_INFINITY : 300;
}}>
{$_('options.infiniteClones')}
</label>
<LearnMore slug="infinite-clones" />
</div>
<div class="option">
<label>
<input type="checkbox" checked={!$options.fencing} on:change={(e) => {
$options.fencing = !e.target.checked;
}}>
{$_('options.removeFencing')}
</label>
<LearnMore slug="remove-fencing" />
</div>
<div class="option">
<label>
<input type="checkbox" checked={!$options.miscLimits} on:change={(e) => {
$options.miscLimits = !e.target.checked;
}}>
{$_('options.removeMiscLimits')}
</label>
<LearnMore slug="remove-misc-limits" />
</div>
<div class="option">
<label>
<input type="checkbox" checked={!$options.dangerousOptimizations} on:change={(e) => {
$options.dangerousOptimizations = e.target.checked;
}}>
Enable Dangerous Optimizations
</label>
</div>
<label class="option">
{$_('options.username')}
<input type="text" class="shorter" bind:value={$options.username}>
</label>
{#if $options.username !== defaultOptions.username && cloudVariables.length !== 0}
<p class="warning">
{$_('options.customUsernameWarning')}
</p>
{/if}
<label class="option">
<input type="checkbox" bind:checked={$options.closeWhenStopped}>
{$_('options.closeWhenStopped')}
</label>
<h3>{$_('options.stage')}</h3>
<label class="option">
{$_('options.stageSize')}
<input type="number" min="1" max="4096" step="1" bind:value={$options.stageWidth}>
×
<input type="number" min="1" max="4096" step="1" bind:value={$options.stageHeight}>
<LearnMore slug="custom-stage-size" />
</label>
<div class="group">
<label class="option">
<input type="radio" name="resize-mode" value="preserve-ratio" bind:group={$options.resizeMode}>
{$_('options.preserveRatio')}
</label>
<label class="option">
<input type="radio" name="resize-mode" value="stretch" bind:group={$options.resizeMode}>
{$_('options.stretch')}
</label>
<label class="option">
<input type="radio" name="resize-mode" value="dynamic-resize" bind:group={$options.resizeMode}>
{$_('options.dynamicResize')}
<LearnMore slug="packager/dynamic-stage-resize" />
</label>
</div>
</div>
</Section>
<Section
accent="#9966FF"
reset={() => {
$icon = null;
$loadingScreenImage = null;
resetOptions([
'app.windowTitle',
'loadingScreen',
'autoplay',
'controls',
'appearance',
'monitors',
]);
}}
>
<div>
<h2>{$_('options.playerOptions')}</h2>
<label class="option">
{$_('options.pageTitle')}
<input type="text" bind:value={$options.app.windowTitle}>
</label>
<div class="option">
{$_('options.icon')}
<ImageInput bind:file={$icon} previewSizes={[[64, 64], [32, 32], [16, 16]]} />
</div>
<h3>{$_('options.loadingScreen')}</h3>
<label class="option">
<input type="checkbox" bind:checked={$options.loadingScreen.progressBar}>
{$_('options.showProgressBar')}
</label>
<label class="option">
{$_('options.loadingScreenText')}
<input type="text" bind:value={$options.loadingScreen.text} placeholder={$_('options.loadingScreenTextPlaceholder')}>
</label>
<div class="option">
{$_('options.loadingScreenImage')}
<!-- Display preview at image's native size -->
<ImageInput bind:file={$loadingScreenImage} previewSizes={[['', '']]} />
</div>
{#if $loadingScreenImage}
<label class="option">
<input type="radio" name="loading-screen-mode" value="normal" bind:group={$options.loadingScreen.imageMode}>
{$_('options.sizeNormal')}
</label>
<label class="option">
<input type="radio" name="loading-screen-mode" value="stretch" bind:group={$options.loadingScreen.imageMode}>
{$_('options.sizeStretch')}
</label>
{/if}
<h3>{$_('options.controls')}</h3>
<div class="group">
<label class="option">
<input type="checkbox" bind:checked={$options.autoplay}>
{$_('options.autoplay')}
</label>
{#if $options.autoplay}
{$_('options.autoplayHint')}
{/if}
</div>
<label class="option">
<input type="checkbox" bind:checked={$options.controls.greenFlag.enabled}>
{$_('options.showFlag')}
</label>
<label class="option">
<input type="checkbox" bind:checked={$options.controls.stopAll.enabled}>
{$_('options.showStop')}
</label>
<label class="option">
<input type="checkbox" bind:checked={$options.controls.pause.enabled}>
{$_('options.showPause')}
</label>
<label class="option">
<input type="checkbox" bind:checked={$options.controls.fullscreen.enabled}>
{$_('options.showFullscreen')}
</label>
<p>{$_('options.controlsHelp')}</p>
<h3>{$_('options.colors')}</h3>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<ColorPicker bind:value={$options.appearance.background} />
{$_('options.backgroundColor')}
</label>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<ColorPicker bind:value={$options.appearance.foreground} />
{$_('options.foregroundColor')}
</label>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<ColorPicker bind:value={$options.appearance.accent} />
{$_('options.accentColor')}
</label>
<h3>{$_('options.monitors')}</h3>
<label class="option">
<input type="checkbox" bind:checked={$options.monitors.editableLists}>
{$_('options.editableLists')}
</label>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<ColorPicker bind:value={$options.monitors.variableColor} />
{$_('options.variableColor')}
</label>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<ColorPicker bind:value={$options.monitors.listColor} />
{$_('options.listColor')}
</label>
<h3>Permissions</h3>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<input type="checkbox" bind:checked={$options.penguinmod.permissionManager.enabled}>
Enable permission manager
</label>
<p>The permission manager in PenguinMod is the prompts that appear when asking for permission to do something. You can disable it if the permission manager doesn't work in your case, or is causing annoying pop-ups constantly throughout your project.</p>
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
<input type="checkbox" bind:checked={$options.penguinmod.permissionManager.unsandboxedJavascript}>
Remove sandbox on the JavaScript Extension
</label>
<p>For security, the JavaScript blocks in the JavaScript extensions are sandboxed to limit the things they can access.</p>
<p class="warning">
Removing the sandbox on projects not owned by you can allow them to delete your settings, phish for passwords or do other bad stuff. Only remove the sandbox on projects you own.
</p>
</div>
</Section>
<Section
accent="#4CBFE6"
reset={() => {
$customCursorIcon = null;
resetOptions([
'cursor',
'chunks',
]);
}}
>
<div>
<h2>{$_('options.interaction')}</h2>
<div class="group">
<label class="option">
<input type="radio" name="cursor-type" bind:group={$options.cursor.type} value="auto">
{$_('options.normalCursor')}
</label>
<label class="option">
<input type="radio" name="cursor-type" bind:group={$options.cursor.type} value="none">
{$_('options.noCursor')}
</label>
<label class="option">
<input type="radio" name="cursor-type" bind:group={$options.cursor.type} value="custom">
{$_('options.customCursor')}
</label>
</div>
{#if $options.cursor.type === 'custom'}
<div in:slide|self class="option">
<ImageInput bind:file={$customCursorIcon} previewSizes={[[32, 32], [16, 16]]} />
<p>{$_('options.cursorHelp')}</p>
<label class="option">
{$_('options.cursorCenter')}
<!-- X: and Y: intentionally not translated -->
X: <input type="number" min="0" bind:value={$options.cursor.center.x}>
Y: <input type="number" min="0" bind:value={$options.cursor.center.y}>
<button
on:click={automaticallyCenterCursor}
disabled={!$customCursorIcon}
>
{$_('options.automaticallyCenter')}
</button>
</label>
</div>
{/if}
<div class="group">
<label class="option">
<input type="checkbox" bind:checked={$options.chunks.pointerlock}>
{$_('options.pointerlock')}
</label>
<a href="https://experiments.turbowarp.org/pointerlock/" target="_blank" rel="noopener noreferrer">
{$_('options.pointerlockHelp')}
</a>
</div>
<div class="group">
<label class="option">
<input type="checkbox" bind:checked={$options.chunks.gamepad}>
{$_('options.gamepad')}
</label>
<a href="https://turbowarp.org/addons#gamepad" target="_blank" rel="noopener noreferrer">
{$_('options.gamepadHelp')}
</a>
</div>
</div>
</Section>
<Section
accent="#FF8C1A"
reset={cloudVariables.length === 0 ? null : () => {
resetOptions([
'cloudVariables'
]);
}}
>
<div>
<h2>{$_('options.cloudVariables')}</h2>
{#if cloudVariables.length > 0}
<label class="option">
{$_('options.mode')}
<select bind:value={$options.cloudVariables.mode}>
<option value="ws">{$_('options.cloudVariables-ws')}</option>
<option value="local">{$_('options.cloudVariables-local')}</option>
<option value="">{$_('options.cloudVariables-ignore')}</option>
<option value="custom">{$_('options.cloudVariables-custom')}</option>
</select>
</label>
{#if $options.cloudVariables.mode === "custom"}
<div transition:fade|local>
{#each cloudVariables as variable}
<label class="option">
<select bind:value={$options.cloudVariables.custom[variable]}>
<option value="ws">{$_('options.cloudVariables-ws')}</option>
<option value="local">{$_('options.cloudVariables-local')}</option>
<option value="">{$_('options.cloudVariables-ignore')}</option>
</select>
{variable}
</label>
{/each}
</div>
{/if}
{#if $options.cloudVariables.mode === 'ws' || $options.cloudVariables.mode === 'custom'}
<div transition:fade|local>
<label class="option">
{$_('options.cloudVariablesHost')}
<!-- Examples of valid values: -->
<!-- wss://clouddata.turbowarp.org -->
<!-- ws:localhost:8080 -->
<input type="text" bind:value={$options.cloudVariables.cloudHost} pattern="wss?:.*">
</label>
</div>
{/if}
<p>{$_('options.cloudVariables-ws-help')}</p>
<p>{$_('options.cloudVariables-local-help')}</p>
<p>{$_('options.cloudVariables-ignore-help')}</p>
<p>{$_('options.cloudVariables-custom-help')}</p>
<div class="option">
<label>
<input type="checkbox" bind:checked={$options.cloudVariables.specialCloudBehaviors}>
{$_('options.specialCloudBehaviors')}
</label>
<LearnMore slug="packager/special-cloud-behaviors" />
</div>
<div class="option">
<label>
<input type="checkbox" bind:checked={$options.cloudVariables.unsafeCloudBehaviors}>
{$_('options.unsafeCloudBehaviors')}
</label>
<LearnMore slug="packager/special-cloud-behaviors#eval" />
</div>
{#if $options.cloudVariables.unsafeCloudBehaviors}
<p class="warning">{$_('options.unsafeCloudBehaviorsWarning')}</p>
{/if}
<p>{$_('options.implicitCloudHint').replace('{cloud}', '☁')}</p>
{:else}
<p>{$_('options.noCloudVariables')}</p>
{/if}
</div>
</Section>
<Section
accent="#FF6680"
reset={() => {
resetOptions([
'compiler',
'extensions',
'bakeExtensions',
'custom',
'projectId',
'maxTextureDimension'
]);
}}
>
<div>
<h2>{$_('options.advancedOptions')}</h2>
<details open={advancedOptionsInitiallyOpen}>
<summary>{$_('options.advancedSummary')}</summary>
<div class="option" style="display:none">
<label>
<input type="checkbox" bind:checked={$options.compiler.enabled}>
{$_('options.enableCompiler')}
</label>
<LearnMore slug="disable-compiler" />
</div>
<div class="option">
<label>
<input type="checkbox" bind:checked={$options.compiler.warpTimer}>
{$_('options.warpTimer')}
</label>
<LearnMore slug="warp-timer" />
</div>
<!-- Ignore because CustomExtensions will have a <textarea> inside it -->
<!-- svelte-ignore a11y-label-has-associated-control -->
<label class="option">
{$_('options.customExtensions')}
<!-- TODO: use the user-facing documentation when that becomes available -->
<LearnMore slug="development/custom-extensions" />
<CustomExtensions bind:extensions={$options.extensions} />
<p class="warning">{$_('options.customExtensionsSecurity')}</p>
</label>
<label class="option">
<input type="checkbox" bind:checked={$options.bakeExtensions}>
{$_('options.bakeExtensions')}
</label>
<label class="option">
{$_('options.customCSS')}
<textarea bind:value={$options.custom.css}></textarea>
</label>
<label class="option">
{$_('options.customJS')}
<textarea bind:value={$options.custom.js}></textarea>
</label>
<label class="option">
{$_('options.projectId')}
<input type="text" bind:value={$options.projectId}>
</label>
<p>{$_('options.projectIdHelp')}</p>
<label class="option">
<input type="checkbox" bind:checked={$options.packagedRuntime} />
{$_('options.packagedRuntime')}
</label>
<label class="option">
<input type="checkbox" checked={$options.maxTextureDimension !== defaultOptions.maxTextureDimension} on:change={(e) => {
$options.maxTextureDimension = defaultOptions.maxTextureDimension * (e.target.checked ? 2 : 1);
}} />
{$_('options.maxTextureDimension')}
</label>
</details>
</div>
</Section>
<Section
accent="#0FBD8C"
reset={() => {
resetOptions([
'target'
])
}}
>
<div>
<h2>{$_('options.environment')}</h2>
<div class="group">
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="html">
{$_('options.html')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="zip">
{$_('options.zip')}
</label>
</div>
<div class="group">
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-win32">
{$_('options.application-win32').replace('{type}', 'Electron')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="webview-mac">
{$_('options.application-mac').replace('{type}', 'WKWebView')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-linux64">
{$_('options.application-linux64').replace('{type}', 'Electron')}
</label>
</div>
<details open={otherEnvironmentsInitiallyOpen}>
<summary>{$_('options.otherEnvironments')}</summary>
<p>{$_('options.otherEnvironmentsHelp')}</p>
<div class="group">
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="zip-one-asset">
{$_('options.zip-one-asset')}
</label>
</div>
<div class="group">
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-win64">
{$_('options.application-win64').replace('{type}', 'Electron')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-win-arm">
{$_('options.application-win-arm').replace('{type}', 'Electron')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-mac">
{$_('options.application-mac').replace('{type}', 'Electron')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-linux-arm32">
{$_('options.application-linux-arm32').replace('{type}', 'Electron')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="electron-linux-arm64">
{$_('options.application-linux-arm64').replace('{type}', 'Electron')}
</label>
</div>
<div class="group">
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="nwjs-win32">
{$_('options.application-win32').replace('{type}', 'NW.js')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="nwjs-win64">
{$_('options.application-win64').replace('{type}', 'NW.js')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="nwjs-mac">
{$_('options.application-mac').replace('{type}', 'NW.js')}
</label>
<label class="option">
<input type="radio" name="environment" bind:group={$options.target} value="nwjs-linux-x64">
{$_('options.application-linux64').replace('{type}', 'NW.js')}
</label>
</div>
</details>
</div>
</Section>
{#if $options.target !== 'html'}
<div in:fade|local>
<Section
accent="#FF661A"
reset={$options.target.startsWith('zip') ? null : () => {
resetOptions([
'app.packageName',
'app.windowMode'
]);
}}
>
<div>
{#if $options.target.startsWith('zip')}
<h2>Zip</h2>
<p>The zip environment is intended to be used for publishing to a website. Other uses such as sending your project to a friend over a chat app or email should use "Plain HTML" instead as zip will not work.</p>
{:else}
<h2>{$_('options.applicationSettings')}</h2>
<label class="option">
{$_('options.packageName')}
<input type="text" bind:value={$options.app.packageName} pattern="[\w \-]+" minlength="1">
</label>
<p>{$_('options.packageNameHelp')}</p>
<label class="option">
{$_('options.version')}
<input type="text" bind:value={$options.app.version} pattern="\d+\.\d+\.\d+" minlength="1">
</label>
<p>{$_('options.versionHelp')}</p>
{#if $options.target.includes('electron')}
<div class="group">
<label class="option">
<input type="radio" name="app-window-mode" bind:group={$options.app.windowMode} value="window">
{$_('options.startWindow')}
</label>
<label class="option">
<input type="radio" name="app-window-mode" bind:group={$options.app.windowMode} value="maximize">
{$_('options.startMaximized')}
</label>
<label class="option">
<input type="radio" name="app-window-mode" bind:group={$options.app.windowMode} value="fullscreen">
{$_('options.startFullscreen')}
</label>
</div>
{/if}
<div class="warning">
<div>Creating native applications for specific platforms is discouraged. In most cases, Plain HTML or Zip will have numerous advantages:</div>
<ul>
<li>Can be run directly from a website on any platform, even phones</li>
<li>Users are significantly less likely to be suspicious of a virus</li>
<li>Significantly smaller file size</li>
<li>Can still be downloaded locally and run offline</li>
</ul>
<div>If you don't truly need to make a self-contained application for each platform (we understand there are some cases where this is necessary), we recommend you don't.</div>
</div>
{#if $options.target.includes('win')}
<div>
<h2>Windows</h2>
<p>All Windows applications generated by this site are unsigned, so users will see SmartScreen warnings when they try to run it for the first time. They can bypass these warnings by pressing "More info" then "Run anyways".</p>
<p>To change the icon of the executable file or create an installer program, download and run <a href="https://github.com/TurboWarp/packager-extras/releases">TurboWarp Packager Extras</a> and select the output of this website.</p>
</div>
{:else if $options.target.includes('mac')}
<div>
<h2>macOS</h2>
<p>Due to Apple policy, packaging for their platforms is troublesome. You either have to:</p>
<ul>
<li>Instruct users to ignore scary Gatekeeper warnings by opening Finder > Navigating to the application > Right click > Open > Open. This website generates applications that require this workaround.</li>
<li>Or pay Apple $100/year for a developer account to sign and notarize the app (very involved process; reach out in feedback for more information)</li>
</ul>
</div>
{:else if $options.target.includes('linux')}
<div>
<h2>Linux</h2>
<p>Linux support is still experimental.</p>
</div>
{/if}
{#if $options.target.includes('electron')}
<div>
<h2>Electron</h2>
<p>The Electron environment works by embedding a copy of Chromium (the open source part of Google Chrome) along with your project, which means the app will be very large.</p>
{#if $options.target.includes('win')}
{#if $options.target.includes('32')}
<p>Note: You have selected the 32-bit or 64-bit mode. This maximizes device compatibility but limits the amount of memory the app can use. If you encounter crashes, try going into "Other environments" and using the 64-bit only mode instead.</p>
{/if}
{:else if $options.target.includes('mac')}
<p>On macOS, the app will run natively on both Intel Silicon and Apple Silicon Macs.</p>
{:else if $options.target.includes('linux')}
<p>On Linux, the application can be started by running <code>start.sh</code></p>
{/if}
</div>
{:else if $options.target.includes('nwjs')}
<div>
<h2>NW.js</h2>
<p class="warning">NW.js support is deprecated and may be removed in the future. Use the Electron environments instead. They're better in every way.</p>
<p>The NW.js environment works by embedding a copy of Chromium (the open source part of Google Chrome) along with your project, which means the app will be very large.</p>
<p>For further help and steps, see <a href="https://docs.nwjs.io/en/latest/For%20Users/Package%20and%20Distribute/#linux">NW.js Documentation</a>.</p>
{#if $options.target.includes('mac')}
<p>On macOS, the app will run using Rosetta on Apple Silicon Macs.</p>
{/if}
</div>
{:else if $options.target.includes('webview-mac')}
<div>
<h2>WKWebView</h2>
<p>WKWebView is the preferred way to package for macOS. It will be hundreds of MB smaller than the other macOS-specific environments and typically run the fastest.</p>
<p>The app will run natively on both Intel and Apple silicon Macs running macOS 10.13 or later.</p>
<p>Note that:</p>
<ul>
<li>Video sensing and loudness blocks will only work in macOS 12 or later.</li>
<li>Pointer lock will not work.</li>
<li>Extremely large projects might not work properly.</li>
</ul>
<p>Use the "Electron macOS Application" (inside Other environments) or "Plain HTML" environments instead if you encounter these issues.</p>
</div>
{/if}
{/if}
</div>
</Section>
</div>
{/if}
<Section>
<DropArea on:drop={(e) => importOptionsFromDataTransfer(e.detail)}>
<div class="buttons">
<div class="button">
<Button on:click={exportOptions} secondary text={$_('options.export')} />
</div>
<div class="button">
<Button on:click={importOptions} secondary text={$_('options.import')} />
</div>
<div class="side-buttons">
<Button on:click={resetAll} dangerous text={$_('options.resetAll')} />
</div>
</div>
</DropArea>
</Section>
<Section>
<div class="buttons">
<div class="button">
<Button on:click={pack} text={$_('options.package')} />
</div>
<div clas="button">
<Button on:click={preview} secondary text={$_('options.preview')} />
</div>
</div>
</Section>
{#if result}
<Downloads
name={result ? result.filename : null}
url={result ? result.url : null}
blob={result ? result.blob : null}
/>
{:else if !$progress.visible}
<Section caption>
<p>{$_('options.downloadsWillAppearHere')}</p>
</Section>
{/if}
|