@cimplify/cli 0.15.3 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/add-C3DPTVH3.mjs +140 -0
- package/dist/{add-KRIIKAS4.mjs → add-JX2GXWXU.mjs} +4 -4
- package/dist/ai-HUZTVJIQ.mjs +17 -0
- package/dist/{assets-CWB72PZG.mjs → assets-MPESJSUV.mjs} +12 -7
- package/dist/{auth-step-up-Z6KOTTV7.mjs → auth-step-up-VJAFGSW6.mjs} +5 -5
- package/dist/build-E7RRQWVF.mjs +616 -0
- package/dist/{cancel-ZHVVILOU.mjs → cancel-UMKR274A.mjs} +4 -4
- package/dist/capture-TK4NIUYM.mjs +69 -0
- package/dist/chunk-25ZPFHLF.mjs +51 -0
- package/dist/{chunk-OLZKNUMK.mjs → chunk-3LJG22FS.mjs} +6 -6
- package/dist/chunk-454RQ6NR.mjs +10614 -0
- package/dist/{chunk-O2TO2J4I.mjs → chunk-6CQMRZ2W.mjs} +2 -2
- package/dist/chunk-6KKLF5KG.mjs +32 -0
- package/dist/chunk-74QZQSCL.mjs +84 -0
- package/dist/chunk-BGM7CH5G.mjs +81 -0
- package/dist/chunk-BTNVYAC4.mjs +5557 -0
- package/dist/{chunk-I2UP7YTG.mjs → chunk-ECGDRU56.mjs} +1 -1
- package/dist/{chunk-UTD34C2H.mjs → chunk-EOOOXVHR.mjs} +2 -4
- package/dist/chunk-EYEMPIMP.mjs +74 -0
- package/dist/{chunk-3RPR33MO.mjs → chunk-FV273ECI.mjs} +11 -7
- package/dist/{chunk-MLE4MVYC.mjs → chunk-GGPN4QYQ.mjs} +2 -2
- package/dist/chunk-HQPZQIWW.mjs +1456 -0
- package/dist/{chunk-3QUK5BPY.mjs → chunk-I7GEHLDD.mjs} +16 -1
- package/dist/chunk-ITDAICBY.mjs +363 -0
- package/dist/chunk-JKECUAAV.mjs +2169 -0
- package/dist/chunk-JNCEKW2Y.mjs +41 -0
- package/dist/chunk-JTYVGORV.mjs +101 -0
- package/dist/chunk-KQNZKV6E.mjs +535 -0
- package/dist/chunk-LJDIQ4PF.mjs +6463 -0
- package/dist/{chunk-2MKZKUVH.mjs → chunk-LLRUOIMU.mjs} +1 -2
- package/dist/chunk-MJMRIMR7.mjs +86 -0
- package/dist/chunk-N2WZJX5P.mjs +1989 -0
- package/dist/chunk-NEB372WD.mjs +1152 -0
- package/dist/chunk-OPX7KPOU.mjs +68 -0
- package/dist/chunk-PHUBMRAS.mjs +623 -0
- package/dist/chunk-PQBALZUH.mjs +1941 -0
- package/dist/chunk-PVW5D5AW.mjs +42 -0
- package/dist/{chunk-LZEG3FEY.mjs → chunk-QQWYQ2HS.mjs} +7 -7
- package/dist/chunk-QVR6V6QP.mjs +46 -0
- package/dist/chunk-SGT5IJVW.mjs +28 -0
- package/dist/chunk-SZXO6YSX.mjs +502 -0
- package/dist/chunk-THATLMEX.mjs +1227 -0
- package/dist/chunk-TYR4Q37L.mjs +391 -0
- package/dist/{chunk-DMLQBAGC.mjs → chunk-V3R2NYQR.mjs} +1 -1
- package/dist/chunk-VHK7WBO3.mjs +189 -0
- package/dist/{chunk-TH4XENKH.mjs → chunk-XASDB7YS.mjs} +1 -1
- package/dist/{chunk-NYXA6X56.mjs → chunk-XBQ4LO2N.mjs} +31 -11
- package/dist/chunk-XF3MGADK.mjs +2946 -0
- package/dist/{chunk-5KYR6WJB.mjs → chunk-XQAHREKO.mjs} +17 -1
- package/dist/chunk-XZG3DTXV.mjs +696 -0
- package/dist/chunk-Y4YGR2NY.mjs +52 -0
- package/dist/{chunk-LJEKKFC7.mjs → chunk-YS2JUNSQ.mjs} +19 -11
- package/dist/chunk-ZG7NJLXN.mjs +104 -0
- package/dist/create-3TGG7B3X.mjs +10 -0
- package/dist/credits-MEG7V5DI.mjs +33 -0
- package/dist/{deploy-STWZ3OSM.mjs → deploy-CNRORHJ7.mjs} +11 -11
- package/dist/dev-RXSBY7U4.mjs +8 -0
- package/dist/dev-YLYC6B7R.mjs +401 -0
- package/dist/dispatcher.mjs +131 -30
- package/dist/{doctor-3RW3OGZJ.mjs → doctor-XRTNG2IT.mjs} +13 -21
- package/dist/{domains-FTNK4IKY.mjs → domains-JIHFKDWR.mjs} +6 -6
- package/dist/engine-runtime-fetch-QVKJVC3W.mjs +10 -0
- package/dist/{env-TNCYUAMT.mjs → env-LJ3DCAA5.mjs} +7 -7
- package/dist/env-R72AHBT2.mjs +19 -0
- package/dist/explain-32RSXEXC.mjs +251 -0
- package/dist/inspect-PYLYN45K.mjs +86 -0
- package/dist/{inspect-X3M7WSTL.mjs → inspect-ZOLZHNSZ.mjs} +28 -13
- package/dist/introspect-27MMTACH.mjs +9 -0
- package/dist/kernel-IC4ZC54Z.mjs +662 -0
- package/dist/kernel-plugin.js +6862 -0
- package/dist/keys-WKOQ4KQE.mjs +71 -0
- package/dist/lines-I6ZB2IOU.mjs +56 -0
- package/dist/{link-76Z6V6CJ.mjs → link-TE2FUX74.mjs} +6 -6
- package/dist/{lint-DDZ7HUQN.mjs → lint-735IPMC6.mjs} +2 -2
- package/dist/{list-2MFOQKKQ.mjs → list-CHYY2P4T.mjs} +7 -11
- package/dist/lock-XVR3RRZ6.mjs +57 -0
- package/dist/{login-RLMDEWAL.mjs → login-LW7CHZDZ.mjs} +10 -8
- package/dist/{logout-Z57X6HPE.mjs → logout-6U6OP5DM.mjs} +2 -2
- package/dist/{logs-TNDM4RFE.mjs → logs-HKH4H6PT.mjs} +5 -5
- package/dist/logs-SCQC5HNO.mjs +44 -0
- package/dist/mcp-VRHQOEGG.mjs +1077 -0
- package/dist/{mock-EVER34IX.mjs → mock-5H3CVPHC.mjs} +2 -2
- package/dist/outdated-T7QW6F3Z.mjs +58 -0
- package/dist/port-24R7ZNP4.mjs +2408 -0
- package/dist/{projects-YL4T24VV.mjs → projects-HYITVEXS.mjs} +6 -6
- package/dist/publish-DZRR5A5X.mjs +20 -0
- package/dist/remix-4HVXRIEB.mjs +125 -0
- package/dist/repo-FG3CMZQS.mjs +9 -0
- package/dist/report-M7F4ZYP7.mjs +2 -0
- package/dist/rollback-H7Q4XYGX.mjs +43 -0
- package/dist/{rollback-47VQ4HJK.mjs → rollback-OM64O67F.mjs} +6 -6
- package/dist/scene-QTHT3ZPL.mjs +324 -0
- package/dist/{status-TWPOMWNA.mjs → status-5D4RR3MM.mjs} +5 -5
- package/dist/status-AKI6E3JK.mjs +18 -0
- package/dist/test-W6MURUGZ.mjs +233 -0
- package/dist/testers-EI32JB5F.mjs +49 -0
- package/dist/{unlink-H3BO3DOQ.mjs → unlink-BND47IWW.mjs} +2 -2
- package/dist/{update-FLY46XI3.mjs → update-XKKFREKH.mjs} +4 -4
- package/dist/{whoami-CQPPARRS.mjs → whoami-WHLGCVRC.mjs} +3 -3
- package/dist/workshop-F2T4IDOU.mjs +1703 -0
- package/package.json +11 -7
- package/templates/storefront-auto/app/products/[slug]/page.tsx +1 -1
- package/templates/storefront-auto/package.json +1 -1
- package/templates/storefront-bakery/package.json +1 -1
- package/templates/storefront-fashion/app/products/[slug]/page.tsx +1 -1
- package/templates/storefront-fashion/package.json +1 -1
- package/templates/storefront-grocery/package.json +1 -1
- package/templates/storefront-pharmacy/app/products/[slug]/page.tsx +1 -1
- package/templates/storefront-pharmacy/package.json +1 -1
- package/templates/storefront-restaurant/package.json +1 -1
- package/templates/storefront-retail/app/products/[slug]/page.tsx +1 -1
- package/templates/storefront-retail/package.json +1 -1
- package/templates/storefront-services/package.json +1 -1
- package/dist/chunk-ARIDYKLO.mjs +0 -6463
- package/dist/dev-7O65HY6C.mjs +0 -8
- package/dist/explain-DLRUUCNS.mjs +0 -251
- package/dist/introspect-RC265ACF.mjs +0 -9
- package/dist/repo-UUT3AZ3L.mjs +0 -9
|
@@ -0,0 +1,1989 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { encodeChunk } from './chunk-EYEMPIMP.mjs';
|
|
3
|
+
import { SDK_PACKAGE, PINNED_TYPESCRIPT_VERSION, PINNED_SDK_VERSION, LIBRARY_ALLOWLIST } from './chunk-BGM7CH5G.mjs';
|
|
4
|
+
import { isDigest, sha256, compareStrings } from './chunk-25ZPFHLF.mjs';
|
|
5
|
+
import { diagnostic } from './chunk-SGT5IJVW.mjs';
|
|
6
|
+
import { authConfigDir } from './chunk-GGPN4QYQ.mjs';
|
|
7
|
+
import { randomBytes, createHash } from 'crypto';
|
|
8
|
+
import { existsSync, readFileSync, promises, realpathSync, mkdirSync, writeFileSync, renameSync } from 'fs';
|
|
9
|
+
import path4 from 'path';
|
|
10
|
+
import { FULL_ENGINE_VARIANT, TEXT_DICTIONARIES_FILE, ENGINE_AUDIO_UNIT, ENGINE_LUAU_UNIT, ENGINE_CORE_GL_UNIT, ENGINE_CORE_SCRIPTS_UNIT, AUDIO_WORKLET_FILE, LUAU_VM_FILE, isScriptsVariant, isShadersVariant, SCRIPTS_SHADERS_ENGINE_VARIANT, SCRIPTS_ENGINE_VARIANT, glVariantOf, threadedVariantOf, ENGINE_EXPORT_PROTOTYPES } from '@cimplify/sdk/interactives';
|
|
11
|
+
import { buildSync, transformSync } from 'esbuild';
|
|
12
|
+
import ts from 'typescript';
|
|
13
|
+
import os from 'os';
|
|
14
|
+
import { pathToFileURL, fileURLToPath } from 'url';
|
|
15
|
+
|
|
16
|
+
var LICENSEE_SECTION = "cimplify.licensee";
|
|
17
|
+
var ENGINE_CACHE_DIR = "engine-runtime";
|
|
18
|
+
var CACHE_OBJECTS_DIR = "objects";
|
|
19
|
+
var CACHE_VERSIONS_DIR = "versions";
|
|
20
|
+
var CACHE_CURRENT_FILE = "current.json";
|
|
21
|
+
var WASM_MAGIC = [0, 97, 115, 109];
|
|
22
|
+
var WASM_HEADER_BYTES = 8;
|
|
23
|
+
var CUSTOM_SECTION_ID = 0;
|
|
24
|
+
var LEB_PAYLOAD_BITS = 7;
|
|
25
|
+
var LEB_PAYLOAD_MASK = 127;
|
|
26
|
+
var LEB_CONTINUE = 128;
|
|
27
|
+
var LEB_U32_MAX_BYTES = 5;
|
|
28
|
+
var TEMP_PREFIX = ".tmp-";
|
|
29
|
+
var TEMP_SUFFIX_BYTES = 6;
|
|
30
|
+
var PATH_SEPARATOR = "/";
|
|
31
|
+
var VERSION_SHAPE = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
32
|
+
var UNSAFE_SEGMENTS = /* @__PURE__ */ new Set(["", ".", ".."]);
|
|
33
|
+
var ON_DEMAND_PREFIX = "tools/";
|
|
34
|
+
var ON_DEMAND_INDEX_SUFFIX = ".json";
|
|
35
|
+
function isWasm(bytes) {
|
|
36
|
+
return bytes.length >= WASM_HEADER_BYTES && WASM_MAGIC.every((b, i) => bytes[i] === b);
|
|
37
|
+
}
|
|
38
|
+
function leb(bytes, at2) {
|
|
39
|
+
let value = 0;
|
|
40
|
+
for (let i = 0; i < LEB_U32_MAX_BYTES; i++) {
|
|
41
|
+
const byte = bytes[at2 + i];
|
|
42
|
+
if (byte === void 0) throw new Error("the engine runtime wasm ends inside a section header");
|
|
43
|
+
value += (byte & LEB_PAYLOAD_MASK) * 2 ** (LEB_PAYLOAD_BITS * i);
|
|
44
|
+
if ((byte & LEB_CONTINUE) === 0) return { value, next: at2 + i + 1 };
|
|
45
|
+
}
|
|
46
|
+
throw new Error("the engine runtime wasm has an oversized section length");
|
|
47
|
+
}
|
|
48
|
+
function stripLicenseeSection(bytes) {
|
|
49
|
+
if (!isWasm(bytes)) return bytes;
|
|
50
|
+
const kept = [bytes.subarray(0, WASM_HEADER_BYTES)];
|
|
51
|
+
let stripped = false;
|
|
52
|
+
let at2 = WASM_HEADER_BYTES;
|
|
53
|
+
while (at2 < bytes.length) {
|
|
54
|
+
const start = at2;
|
|
55
|
+
const id = bytes[at2];
|
|
56
|
+
const size = leb(bytes, at2 + 1);
|
|
57
|
+
const end = size.next + size.value;
|
|
58
|
+
if (end > bytes.length) throw new Error("the engine runtime wasm has a section past its end");
|
|
59
|
+
if (id === CUSTOM_SECTION_ID) {
|
|
60
|
+
const name = leb(bytes, size.next);
|
|
61
|
+
if (name.next + name.value > end) throw new Error("the engine runtime wasm has a custom section name past its section");
|
|
62
|
+
if (new TextDecoder().decode(bytes.subarray(name.next, name.next + name.value)) === LICENSEE_SECTION) {
|
|
63
|
+
stripped = true;
|
|
64
|
+
at2 = end;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
kept.push(bytes.subarray(start, end));
|
|
69
|
+
at2 = end;
|
|
70
|
+
}
|
|
71
|
+
return stripped ? Buffer.concat(kept) : bytes;
|
|
72
|
+
}
|
|
73
|
+
function engineCacheRoot() {
|
|
74
|
+
return path4.join(authConfigDir(), ENGINE_CACHE_DIR);
|
|
75
|
+
}
|
|
76
|
+
function safeRelative(file) {
|
|
77
|
+
if (file.includes("\\") || path4.isAbsolute(file)) return false;
|
|
78
|
+
return file.split(PATH_SEPARATOR).every((segment) => !UNSAFE_SEGMENTS.has(segment));
|
|
79
|
+
}
|
|
80
|
+
function validManifest(manifest) {
|
|
81
|
+
return typeof manifest.version === "string" && VERSION_SHAPE.test(manifest.version) && Array.isArray(manifest.files) && manifest.files.length > 0 && manifest.files.every((f) => typeof f.path === "string" && safeRelative(f.path) && isDigest(f.sha256) && Number.isInteger(f.bytes) && f.bytes >= 0);
|
|
82
|
+
}
|
|
83
|
+
function cachedEngineRuntimeDir(root = engineCacheRoot()) {
|
|
84
|
+
const current = path4.join(root, CACHE_CURRENT_FILE);
|
|
85
|
+
if (!existsSync(current)) return null;
|
|
86
|
+
let version;
|
|
87
|
+
try {
|
|
88
|
+
version = JSON.parse(readFileSync(current, "utf8")).version;
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
if (typeof version !== "string" || !VERSION_SHAPE.test(version)) return null;
|
|
93
|
+
const dir = path4.join(root, CACHE_VERSIONS_DIR, version);
|
|
94
|
+
return existsSync(dir) ? dir : null;
|
|
95
|
+
}
|
|
96
|
+
function cachedVersion(root, version) {
|
|
97
|
+
const dir = path4.join(root, CACHE_VERSIONS_DIR, version);
|
|
98
|
+
return cachedEngineRuntimeDir(root) === dir ? dir : null;
|
|
99
|
+
}
|
|
100
|
+
function temporary(dir) {
|
|
101
|
+
return path4.join(dir, `${TEMP_PREFIX}${process.pid}-${randomBytes(TEMP_SUFFIX_BYTES).toString("hex")}`);
|
|
102
|
+
}
|
|
103
|
+
async function writeAtomically(file, bytes) {
|
|
104
|
+
await promises.mkdir(path4.dirname(file), { recursive: true });
|
|
105
|
+
const staged = temporary(path4.dirname(file));
|
|
106
|
+
await promises.writeFile(staged, bytes);
|
|
107
|
+
await promises.rename(staged, file);
|
|
108
|
+
}
|
|
109
|
+
function canonicalBytes(file, downloaded) {
|
|
110
|
+
const canonical2 = stripLicenseeSection(downloaded);
|
|
111
|
+
if (canonical2.length !== file.bytes || sha256(canonical2) !== file.sha256) {
|
|
112
|
+
throw new Error(`the downloaded engine runtime file ${file.path} does not match its published digest ${file.sha256}`);
|
|
113
|
+
}
|
|
114
|
+
return canonical2;
|
|
115
|
+
}
|
|
116
|
+
function onDemandRuntimeFile(file) {
|
|
117
|
+
return file.startsWith(ON_DEMAND_PREFIX) && !file.endsWith(ON_DEMAND_INDEX_SUFFIX);
|
|
118
|
+
}
|
|
119
|
+
async function storeRuntime(root, manifest, download) {
|
|
120
|
+
const objects = path4.join(root, CACHE_OBJECTS_DIR);
|
|
121
|
+
const eager = manifest.files.filter((f) => !onDemandRuntimeFile(f.path));
|
|
122
|
+
for (const file of eager) {
|
|
123
|
+
const object = path4.join(objects, file.sha256);
|
|
124
|
+
if (existsSync(object)) continue;
|
|
125
|
+
await writeAtomically(object, canonicalBytes(file, await download(file)));
|
|
126
|
+
}
|
|
127
|
+
const versions = path4.join(root, CACHE_VERSIONS_DIR);
|
|
128
|
+
const target = path4.join(versions, manifest.version);
|
|
129
|
+
if (!existsSync(target)) {
|
|
130
|
+
const staged = temporary(versions);
|
|
131
|
+
for (const file of eager) {
|
|
132
|
+
const out = path4.join(staged, ...file.path.split(PATH_SEPARATOR));
|
|
133
|
+
await promises.mkdir(path4.dirname(out), { recursive: true });
|
|
134
|
+
await promises.copyFile(path4.join(objects, file.sha256), out);
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
await promises.rename(staged, target);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
await promises.rm(staged, { recursive: true, force: true });
|
|
140
|
+
if (!existsSync(target)) throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
await writeAtomically(path4.join(root, CACHE_CURRENT_FILE), `${JSON.stringify({ version: manifest.version })}
|
|
144
|
+
`);
|
|
145
|
+
return target;
|
|
146
|
+
}
|
|
147
|
+
var COMPILER_OPTIONS = { allowJs: true, checkJs: false, noLib: true, noResolve: true, target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.ESNext, types: [] };
|
|
148
|
+
function literalOf(node) {
|
|
149
|
+
if (node === void 0) return null;
|
|
150
|
+
if (ts.isNumericLiteral(node)) return node.getText();
|
|
151
|
+
if (node.kind === ts.SyntaxKind.TrueKeyword) return "true";
|
|
152
|
+
if (node.kind === ts.SyntaxKind.FalseKeyword) return "false";
|
|
153
|
+
if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.MinusToken && ts.isNumericLiteral(node.operand)) return `-${node.operand.getText()}`;
|
|
154
|
+
if (ts.isParenthesizedExpression(node)) return literalOf(node.expression);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
function isAssignmentOperator(kind) {
|
|
158
|
+
return kind >= ts.SyntaxKind.FirstAssignment && kind <= ts.SyntaxKind.LastAssignment;
|
|
159
|
+
}
|
|
160
|
+
function assignedValue(node) {
|
|
161
|
+
const parent = node.parent;
|
|
162
|
+
if (ts.isBinaryExpression(parent) && parent.left === node && isAssignmentOperator(parent.operatorToken.kind)) {
|
|
163
|
+
return parent.operatorToken.kind === ts.SyntaxKind.EqualsToken ? parent.right : null;
|
|
164
|
+
}
|
|
165
|
+
if ((ts.isPrefixUnaryExpression(parent) || ts.isPostfixUnaryExpression(parent)) && (parent.operator === ts.SyntaxKind.PlusPlusToken || parent.operator === ts.SyntaxKind.MinusMinusToken)) return null;
|
|
166
|
+
if ((ts.isForInStatement(parent.parent) || ts.isForOfStatement(parent.parent)) && parent === parent.parent.initializer) return null;
|
|
167
|
+
if (ts.isShorthandPropertyAssignment(parent) || ts.isArrayLiteralExpression(parent) || ts.isSpreadElement(parent)) {
|
|
168
|
+
let up = parent;
|
|
169
|
+
while (ts.isArrayLiteralExpression(up) || ts.isObjectLiteralExpression(up) || ts.isShorthandPropertyAssignment(up) || ts.isPropertyAssignment(up) || ts.isSpreadElement(up)) up = up.parent;
|
|
170
|
+
if (ts.isBinaryExpression(up) && up.operatorToken.kind === ts.SyntaxKind.EqualsToken && up.left.pos <= node.pos && node.end <= up.left.end) return null;
|
|
171
|
+
}
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
function isReference(node) {
|
|
175
|
+
const parent = node.parent;
|
|
176
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === node || ts.isPropertyAssignment(parent) && parent.name === node) return false;
|
|
177
|
+
if ((ts.isMethodDeclaration(parent) || ts.isPropertyDeclaration(parent) || ts.isGetAccessor(parent) || ts.isSetAccessor(parent)) && parent.name === node) return false;
|
|
178
|
+
if (ts.isExportSpecifier(parent) || ts.isImportSpecifier(parent) || ts.isImportClause(parent) || ts.isNamespaceImport(parent)) return false;
|
|
179
|
+
if (ts.isLabeledStatement(parent) || ts.isBreakOrContinueStatement(parent)) return false;
|
|
180
|
+
if (ts.isVariableDeclaration(parent) && parent.name === node) return false;
|
|
181
|
+
if ((ts.isFunctionDeclaration(parent) || ts.isClassDeclaration(parent) || ts.isFunctionExpression(parent) || ts.isClassExpression(parent) || ts.isParameter(parent)) && parent.name === node) return false;
|
|
182
|
+
if (ts.isBindingElement(parent)) return false;
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
function program(fileName, code) {
|
|
186
|
+
const file = ts.createSourceFile(fileName, code, ts.ScriptTarget.ES2022, true, ts.ScriptKind.JS);
|
|
187
|
+
const host = {
|
|
188
|
+
getSourceFile: (name) => name === fileName ? file : void 0,
|
|
189
|
+
getDefaultLibFileName: () => "lib.d.ts",
|
|
190
|
+
writeFile: () => void 0,
|
|
191
|
+
getCurrentDirectory: () => "",
|
|
192
|
+
getCanonicalFileName: (name) => name,
|
|
193
|
+
useCaseSensitiveFileNames: () => true,
|
|
194
|
+
getNewLine: () => "\n",
|
|
195
|
+
fileExists: (name) => name === fileName,
|
|
196
|
+
readFile: (name) => name === fileName ? code : void 0
|
|
197
|
+
};
|
|
198
|
+
const built2 = ts.createProgram({ rootNames: [fileName], options: COMPILER_OPTIONS, host });
|
|
199
|
+
return { checker: built2.getTypeChecker(), file };
|
|
200
|
+
}
|
|
201
|
+
function topLevelVariables(file, checker) {
|
|
202
|
+
const out = /* @__PURE__ */ new Map();
|
|
203
|
+
for (const statement of file.statements) {
|
|
204
|
+
if (!ts.isVariableStatement(statement)) continue;
|
|
205
|
+
if ((statement.declarationList.flags & (ts.NodeFlags.Let | ts.NodeFlags.Const | ts.NodeFlags.Using)) !== 0) continue;
|
|
206
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
207
|
+
if (!ts.isIdentifier(declaration.name)) continue;
|
|
208
|
+
const symbol = checker.getSymbolAtLocation(declaration.name);
|
|
209
|
+
if (symbol === void 0 || (symbol.declarations?.length ?? 0) !== 1) continue;
|
|
210
|
+
const literal = literalOf(declaration.initializer);
|
|
211
|
+
out.set(symbol, { writes: declaration.initializer === void 0 ? 0 : 1, literal, reads: [] });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return out;
|
|
215
|
+
}
|
|
216
|
+
function inlineModuleConstants(code, fileName = "bundle.js") {
|
|
217
|
+
const { checker, file } = program(fileName, code);
|
|
218
|
+
const candidates = topLevelVariables(file, checker);
|
|
219
|
+
if (candidates.size === 0) return { code, inlined: 0, constants: 0 };
|
|
220
|
+
const visit = (node) => {
|
|
221
|
+
if (ts.isIdentifier(node) && !(ts.isVariableDeclaration(node.parent) && node.parent.name === node)) {
|
|
222
|
+
const shorthand = ts.isShorthandPropertyAssignment(node.parent) && node.parent.name === node;
|
|
223
|
+
const symbol = shorthand ? checker.getShorthandAssignmentValueSymbol(node.parent) : checker.getSymbolAtLocation(node);
|
|
224
|
+
const candidate = symbol === void 0 ? void 0 : candidates.get(symbol);
|
|
225
|
+
if (candidate !== void 0) {
|
|
226
|
+
const written = assignedValue(node);
|
|
227
|
+
if (written !== void 0) {
|
|
228
|
+
candidate.writes++;
|
|
229
|
+
candidate.literal = candidate.writes === 1 && written !== null ? literalOf(written) : null;
|
|
230
|
+
} else if (shorthand || isReference(node)) {
|
|
231
|
+
candidate.reads.push(node);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
ts.forEachChild(node, visit);
|
|
236
|
+
};
|
|
237
|
+
ts.forEachChild(file, visit);
|
|
238
|
+
const edits = [];
|
|
239
|
+
let constants = 0;
|
|
240
|
+
for (const candidate of candidates.values()) {
|
|
241
|
+
if (candidate.writes !== 1 || candidate.literal === null || candidate.reads.length === 0) continue;
|
|
242
|
+
constants++;
|
|
243
|
+
for (const read of candidate.reads) {
|
|
244
|
+
const at2 = read.getStart(file);
|
|
245
|
+
const text = ts.isShorthandPropertyAssignment(read.parent) ? `${read.text}: (${candidate.literal})` : `(${candidate.literal})`;
|
|
246
|
+
edits.push({ at: at2, end: read.end, text });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (edits.length === 0) return { code, inlined: 0, constants: 0 };
|
|
250
|
+
edits.sort((a, b) => b.at - a.at);
|
|
251
|
+
let out = code;
|
|
252
|
+
for (const edit of edits) out = out.slice(0, edit.at) + edit.text + out.slice(edit.end);
|
|
253
|
+
return { code: out, inlined: edits.length, constants };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/interactives/build/engine-abi.ts
|
|
257
|
+
var WASM_HEADER_BYTES2 = 8;
|
|
258
|
+
var IMPORT_SECTION = 2;
|
|
259
|
+
var KIND_FUNCTION = 0;
|
|
260
|
+
var KIND_TABLE = 1;
|
|
261
|
+
var KIND_MEMORY = 2;
|
|
262
|
+
var KIND_GLOBAL = 3;
|
|
263
|
+
var LIMITS_HAS_MAX = 1;
|
|
264
|
+
var LIMITS_SHARED = 2;
|
|
265
|
+
var LEB_PAYLOAD = 127;
|
|
266
|
+
var LEB_CONTINUE2 = 128;
|
|
267
|
+
var LEB_STEP = 7;
|
|
268
|
+
var ABI_EXPORT = "engine_abi_version";
|
|
269
|
+
var MEMORY_MODULE = "env";
|
|
270
|
+
var MEMORY_FIELD = "memory";
|
|
271
|
+
var FUNCTION_IMPORT = "function";
|
|
272
|
+
var PROTOTYPE_EXPORT = "engine_export_prototype_of";
|
|
273
|
+
var ALLOC_EXPORT = "engine_alloc";
|
|
274
|
+
var ENGINE_PREFIX = /^engine_[a-z0-9_]+$/;
|
|
275
|
+
var NAME_CAPACITY = 64;
|
|
276
|
+
var NAME_ALIGN = 8;
|
|
277
|
+
var NULL = 0;
|
|
278
|
+
var NO_PROTOTYPE = 0;
|
|
279
|
+
var WASM = globalThis.WebAssembly;
|
|
280
|
+
var Reader = class {
|
|
281
|
+
constructor(bytes) {
|
|
282
|
+
this.bytes = bytes;
|
|
283
|
+
}
|
|
284
|
+
bytes;
|
|
285
|
+
at = WASM_HEADER_BYTES2;
|
|
286
|
+
get done() {
|
|
287
|
+
return this.at >= this.bytes.length;
|
|
288
|
+
}
|
|
289
|
+
byte() {
|
|
290
|
+
if (this.at >= this.bytes.length) throw new Error("the engine module is truncated");
|
|
291
|
+
return this.bytes[this.at++];
|
|
292
|
+
}
|
|
293
|
+
u32() {
|
|
294
|
+
let value = 0;
|
|
295
|
+
let shift = 0;
|
|
296
|
+
for (; ; ) {
|
|
297
|
+
const b = this.byte();
|
|
298
|
+
value += (b & LEB_PAYLOAD) * 2 ** shift;
|
|
299
|
+
if ((b & LEB_CONTINUE2) === 0) return value;
|
|
300
|
+
shift += LEB_STEP;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
name() {
|
|
304
|
+
const length = this.u32();
|
|
305
|
+
const text = new TextDecoder().decode(this.bytes.subarray(this.at, this.at + length));
|
|
306
|
+
this.at += length;
|
|
307
|
+
return text;
|
|
308
|
+
}
|
|
309
|
+
limits() {
|
|
310
|
+
const flags = this.byte();
|
|
311
|
+
const initial = this.u32();
|
|
312
|
+
if ((flags & LIMITS_HAS_MAX) === 0) return { initial };
|
|
313
|
+
const maximum = this.u32();
|
|
314
|
+
return (flags & LIMITS_SHARED) === 0 ? { initial, maximum } : { initial, maximum, shared: true };
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
function importedMemory(bytes) {
|
|
318
|
+
const reader = new Reader(bytes);
|
|
319
|
+
while (!reader.done) {
|
|
320
|
+
const id = reader.byte();
|
|
321
|
+
const size = reader.u32();
|
|
322
|
+
const end = reader.at + size;
|
|
323
|
+
if (id !== IMPORT_SECTION) {
|
|
324
|
+
reader.at = end;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const count = reader.u32();
|
|
328
|
+
for (let i = 0; i < count; i++) {
|
|
329
|
+
const module = reader.name();
|
|
330
|
+
const field = reader.name();
|
|
331
|
+
const kind = reader.byte();
|
|
332
|
+
if (kind === KIND_FUNCTION) reader.u32();
|
|
333
|
+
else if (kind === KIND_TABLE) {
|
|
334
|
+
reader.byte();
|
|
335
|
+
reader.limits();
|
|
336
|
+
} else if (kind === KIND_MEMORY) {
|
|
337
|
+
const limits = reader.limits();
|
|
338
|
+
if (module === MEMORY_MODULE && field === MEMORY_FIELD) return limits;
|
|
339
|
+
} else if (kind === KIND_GLOBAL) {
|
|
340
|
+
reader.byte();
|
|
341
|
+
reader.byte();
|
|
342
|
+
} else throw new Error(`the engine module has an unknown import kind ${kind}`);
|
|
343
|
+
}
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
var UNBOUND = () => 0;
|
|
349
|
+
function unboundImports(module) {
|
|
350
|
+
const imports = {};
|
|
351
|
+
for (const entry of WASM.Module.imports(module)) {
|
|
352
|
+
if (entry.kind !== FUNCTION_IMPORT) continue;
|
|
353
|
+
imports[entry.module] ??= {};
|
|
354
|
+
imports[entry.module][entry.name] = UNBOUND;
|
|
355
|
+
}
|
|
356
|
+
return imports;
|
|
357
|
+
}
|
|
358
|
+
function instantiate(bytes) {
|
|
359
|
+
const module = new WASM.Module(bytes);
|
|
360
|
+
const limits = importedMemory(bytes);
|
|
361
|
+
const imports = unboundImports(module);
|
|
362
|
+
const imported = limits === null ? null : new WASM.Memory(limits);
|
|
363
|
+
if (imported !== null) {
|
|
364
|
+
imports[MEMORY_MODULE] ??= {};
|
|
365
|
+
imports[MEMORY_MODULE][MEMORY_FIELD] = imported;
|
|
366
|
+
}
|
|
367
|
+
const instance = new WASM.Instance(module, imports);
|
|
368
|
+
const exported = instance.exports[MEMORY_FIELD];
|
|
369
|
+
return { module, exports: instance.exports, memory: imported ?? exported ?? null };
|
|
370
|
+
}
|
|
371
|
+
function engineExportTable(bytes, fallback) {
|
|
372
|
+
const { module, exports, memory } = instantiate(bytes);
|
|
373
|
+
const query = exports[PROTOTYPE_EXPORT];
|
|
374
|
+
const alloc = exports[ALLOC_EXPORT];
|
|
375
|
+
const table = /* @__PURE__ */ new Map();
|
|
376
|
+
const names = WASM.Module.exports(module).filter((entry) => entry.kind === FUNCTION_IMPORT && ENGINE_PREFIX.test(entry.name)).map((entry) => entry.name).sort();
|
|
377
|
+
const scratch = typeof query === "function" && typeof alloc === "function" && memory !== null ? alloc(NAME_CAPACITY, NAME_ALIGN) : NULL;
|
|
378
|
+
for (const name of names) {
|
|
379
|
+
let prototype = NO_PROTOTYPE;
|
|
380
|
+
if (scratch !== NULL && memory !== null) {
|
|
381
|
+
new Uint8Array(memory.buffer, scratch, NAME_CAPACITY).set(new TextEncoder().encode(name).subarray(0, NAME_CAPACITY));
|
|
382
|
+
prototype = query(scratch, name.length) >>> 0;
|
|
383
|
+
} else prototype = fallback[name] ?? NO_PROTOTYPE;
|
|
384
|
+
if (prototype !== NO_PROTOTYPE) table.set(name, prototype);
|
|
385
|
+
}
|
|
386
|
+
return table;
|
|
387
|
+
}
|
|
388
|
+
function engineAbiVersion(bytes) {
|
|
389
|
+
const instance = instantiate(bytes);
|
|
390
|
+
const version = instance.exports[ABI_EXPORT];
|
|
391
|
+
if (typeof version !== "function") throw new Error(`the engine module does not export ${ABI_EXPORT}`);
|
|
392
|
+
const abi = version();
|
|
393
|
+
if (!Number.isInteger(abi) || abi < 0) throw new Error(`the engine module reports ABI ${abi}`);
|
|
394
|
+
return abi >>> 0;
|
|
395
|
+
}
|
|
396
|
+
var BROWSER_CONDITIONS = ["browser", "import", "module", "default"];
|
|
397
|
+
var NODE_CONDITIONS = ["node", "import", "module", "default"];
|
|
398
|
+
function findPackageDir(start, name) {
|
|
399
|
+
let dir = start;
|
|
400
|
+
for (; ; ) {
|
|
401
|
+
const candidate = path4.join(dir, "node_modules", ...name.split("/"));
|
|
402
|
+
if (existsSync(path4.join(candidate, "package.json"))) return realpathSync(candidate);
|
|
403
|
+
const parent = path4.dirname(dir);
|
|
404
|
+
if (parent === dir) return null;
|
|
405
|
+
dir = parent;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function readPackageJson(dir) {
|
|
409
|
+
return JSON.parse(readFileSync(path4.join(dir, "package.json"), "utf8"));
|
|
410
|
+
}
|
|
411
|
+
function pickTarget(target, conditions) {
|
|
412
|
+
if (target === void 0 || target === null) return null;
|
|
413
|
+
if (typeof target === "string") return target;
|
|
414
|
+
for (const condition of conditions) {
|
|
415
|
+
const hit = pickTarget(target[condition], conditions);
|
|
416
|
+
if (hit !== null) return hit;
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
function exportsMap(pkg) {
|
|
421
|
+
const exp = pkg.exports;
|
|
422
|
+
if (exp === void 0 || exp === null) return null;
|
|
423
|
+
if (typeof exp === "string") return { ".": exp };
|
|
424
|
+
const keys = Object.keys(exp);
|
|
425
|
+
if (keys.length > 0 && keys[0].startsWith(".")) return exp;
|
|
426
|
+
return { ".": exp };
|
|
427
|
+
}
|
|
428
|
+
function exportTarget(pkg, subpath, conditions) {
|
|
429
|
+
const map = exportsMap(pkg);
|
|
430
|
+
if (map !== null) return pickTarget(map[subpath], conditions);
|
|
431
|
+
return subpath === "." ? pkg.module ?? pkg.main ?? null : null;
|
|
432
|
+
}
|
|
433
|
+
function resolveExport(dir, subpath, conditions) {
|
|
434
|
+
const target = exportTarget(readPackageJson(dir), subpath, conditions);
|
|
435
|
+
if (target === null) return null;
|
|
436
|
+
const file = path4.resolve(dir, target);
|
|
437
|
+
return existsSync(file) ? file : null;
|
|
438
|
+
}
|
|
439
|
+
function stripDotSlash(target) {
|
|
440
|
+
return target.startsWith("./") ? target.slice(2) : target;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// src/interactives/build/forks/fork.ts
|
|
444
|
+
var FORK_ROOT = "cimplify-forks";
|
|
445
|
+
var DIGEST_HEX = 32;
|
|
446
|
+
function occurrences(text, find) {
|
|
447
|
+
let count = 0;
|
|
448
|
+
for (let at2 = text.indexOf(find); at2 >= 0; at2 = text.indexOf(find, at2 + find.length)) count++;
|
|
449
|
+
return count;
|
|
450
|
+
}
|
|
451
|
+
function patchAfter(fork, file, source, patch, after) {
|
|
452
|
+
const anchor = source.indexOf(after);
|
|
453
|
+
if (anchor < 0 || occurrences(source, after) !== 1) throw new Error(`the ${fork.library} fork expects one ${JSON.stringify(after)} in ${file}`);
|
|
454
|
+
const at2 = source.indexOf(patch.find, anchor);
|
|
455
|
+
if (at2 < 0) throw new Error(`the ${fork.library} fork finds no ${JSON.stringify(patch.find.slice(0, 80))} after ${JSON.stringify(after)} in ${file}`);
|
|
456
|
+
return source.slice(0, at2) + patch.replace + source.slice(at2 + patch.find.length);
|
|
457
|
+
}
|
|
458
|
+
function patchSource(fork, file, source) {
|
|
459
|
+
let out = source;
|
|
460
|
+
for (const patch of fork.patches) {
|
|
461
|
+
if (patch.file !== file) continue;
|
|
462
|
+
if (patch.after !== void 0) {
|
|
463
|
+
out = patchAfter(fork, file, out, patch, patch.after);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const expected = patch.count ?? 1;
|
|
467
|
+
const found = occurrences(out, patch.find);
|
|
468
|
+
if (found !== expected) {
|
|
469
|
+
throw new Error(`the ${fork.library} fork expects ${expected} matches in ${file} for ${JSON.stringify(patch.find.slice(0, 80))}, found ${found}`);
|
|
470
|
+
}
|
|
471
|
+
out = out.split(patch.find).join(patch.replace);
|
|
472
|
+
}
|
|
473
|
+
return out;
|
|
474
|
+
}
|
|
475
|
+
function forkedEntry(fork, packageDir) {
|
|
476
|
+
const installed = readPackageJson(packageDir).version;
|
|
477
|
+
if (installed !== fork.version) throw new Error(`the ${fork.library} fork patches ${fork.version}; ${installed ?? "an unknown version"} is installed`);
|
|
478
|
+
const sources = fork.files.map((file) => readFileSync(path4.join(packageDir, file), "utf8"));
|
|
479
|
+
const patched = fork.files.map((file, i) => patchSource(fork, file, sources[i]));
|
|
480
|
+
const digest = createHash("sha256");
|
|
481
|
+
for (let i = 0; i < patched.length; i++) digest.update(fork.files[i]).update("\0").update(patched[i]).update("\0");
|
|
482
|
+
const dir = path4.join(os.tmpdir(), FORK_ROOT, `${fork.library}@${fork.version}-${digest.digest("hex").slice(0, DIGEST_HEX)}`);
|
|
483
|
+
const entry = path4.join(dir, fork.entry);
|
|
484
|
+
if (existsSync(entry)) return entry;
|
|
485
|
+
const order = fork.files.map((_, i) => i).sort((a, b) => Number(fork.files[a] === fork.entry) - Number(fork.files[b] === fork.entry));
|
|
486
|
+
for (const i of order) {
|
|
487
|
+
const target = path4.join(dir, fork.files[i]);
|
|
488
|
+
mkdirSync(path4.dirname(target), { recursive: true });
|
|
489
|
+
const staging = `${target}.${process.pid}`;
|
|
490
|
+
writeFileSync(staging, patched[i]);
|
|
491
|
+
renameSync(staging, target);
|
|
492
|
+
}
|
|
493
|
+
return entry;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/interactives/build/forks/three.ts
|
|
497
|
+
var CORE = "build/three.core.js";
|
|
498
|
+
var MODULE = "build/three.module.js";
|
|
499
|
+
var PATCHES = [
|
|
500
|
+
{
|
|
501
|
+
file: CORE,
|
|
502
|
+
find: `class Frustum {`,
|
|
503
|
+
replace: `const _cimplifyPlaneScratch = new Float64Array( 4 );
|
|
504
|
+
|
|
505
|
+
function _cimplifyPlaneStore( plane, s ) {
|
|
506
|
+
|
|
507
|
+
const inverse = 1.0 / Math.sqrt( s[ 0 ] * s[ 0 ] + s[ 1 ] * s[ 1 ] + s[ 2 ] * s[ 2 ] );
|
|
508
|
+
const normal = plane.normal;
|
|
509
|
+
normal.x = s[ 0 ] * inverse;
|
|
510
|
+
normal.y = s[ 1 ] * inverse;
|
|
511
|
+
normal.z = s[ 2 ] * inverse;
|
|
512
|
+
plane.constant = s[ 3 ] * inverse;
|
|
513
|
+
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
class Frustum {`
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
file: CORE,
|
|
520
|
+
find: ` planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
|
|
521
|
+
planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
|
|
522
|
+
planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
|
|
523
|
+
planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
|
|
524
|
+
|
|
525
|
+
if ( reversedDepth ) {
|
|
526
|
+
|
|
527
|
+
planes[ 4 ].setComponents( me2, me6, me10, me14 ).normalize(); // far
|
|
528
|
+
planes[ 5 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); // near
|
|
529
|
+
|
|
530
|
+
} else {
|
|
531
|
+
|
|
532
|
+
planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); // far
|
|
533
|
+
|
|
534
|
+
if ( coordinateSystem === WebGLCoordinateSystem ) {
|
|
535
|
+
|
|
536
|
+
planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize(); // near
|
|
537
|
+
|
|
538
|
+
} else if ( coordinateSystem === WebGPUCoordinateSystem ) {
|
|
539
|
+
|
|
540
|
+
planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize(); // near
|
|
541
|
+
|
|
542
|
+
} else {
|
|
543
|
+
|
|
544
|
+
throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
|
|
545
|
+
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
}`,
|
|
549
|
+
replace: ` _cimplifyPlaneScratch[ 0 ] = me3 - me0; _cimplifyPlaneScratch[ 1 ] = me7 - me4; _cimplifyPlaneScratch[ 2 ] = me11 - me8; _cimplifyPlaneScratch[ 3 ] = me15 - me12; _cimplifyPlaneStore( planes[ 0 ], _cimplifyPlaneScratch );
|
|
550
|
+
_cimplifyPlaneScratch[ 0 ] = me3 + me0; _cimplifyPlaneScratch[ 1 ] = me7 + me4; _cimplifyPlaneScratch[ 2 ] = me11 + me8; _cimplifyPlaneScratch[ 3 ] = me15 + me12; _cimplifyPlaneStore( planes[ 1 ], _cimplifyPlaneScratch );
|
|
551
|
+
_cimplifyPlaneScratch[ 0 ] = me3 + me1; _cimplifyPlaneScratch[ 1 ] = me7 + me5; _cimplifyPlaneScratch[ 2 ] = me11 + me9; _cimplifyPlaneScratch[ 3 ] = me15 + me13; _cimplifyPlaneStore( planes[ 2 ], _cimplifyPlaneScratch );
|
|
552
|
+
_cimplifyPlaneScratch[ 0 ] = me3 - me1; _cimplifyPlaneScratch[ 1 ] = me7 - me5; _cimplifyPlaneScratch[ 2 ] = me11 - me9; _cimplifyPlaneScratch[ 3 ] = me15 - me13; _cimplifyPlaneStore( planes[ 3 ], _cimplifyPlaneScratch );
|
|
553
|
+
|
|
554
|
+
if ( reversedDepth ) {
|
|
555
|
+
|
|
556
|
+
_cimplifyPlaneScratch[ 0 ] = me2; _cimplifyPlaneScratch[ 1 ] = me6; _cimplifyPlaneScratch[ 2 ] = me10; _cimplifyPlaneScratch[ 3 ] = me14; _cimplifyPlaneStore( planes[ 4 ], _cimplifyPlaneScratch ); // far
|
|
557
|
+
_cimplifyPlaneScratch[ 0 ] = me3 - me2; _cimplifyPlaneScratch[ 1 ] = me7 - me6; _cimplifyPlaneScratch[ 2 ] = me11 - me10; _cimplifyPlaneScratch[ 3 ] = me15 - me14; _cimplifyPlaneStore( planes[ 5 ], _cimplifyPlaneScratch ); // near
|
|
558
|
+
|
|
559
|
+
} else {
|
|
560
|
+
|
|
561
|
+
_cimplifyPlaneScratch[ 0 ] = me3 - me2; _cimplifyPlaneScratch[ 1 ] = me7 - me6; _cimplifyPlaneScratch[ 2 ] = me11 - me10; _cimplifyPlaneScratch[ 3 ] = me15 - me14; _cimplifyPlaneStore( planes[ 4 ], _cimplifyPlaneScratch ); // far
|
|
562
|
+
|
|
563
|
+
if ( coordinateSystem === WebGLCoordinateSystem ) {
|
|
564
|
+
|
|
565
|
+
_cimplifyPlaneScratch[ 0 ] = me3 + me2; _cimplifyPlaneScratch[ 1 ] = me7 + me6; _cimplifyPlaneScratch[ 2 ] = me11 + me10; _cimplifyPlaneScratch[ 3 ] = me15 + me14; _cimplifyPlaneStore( planes[ 5 ], _cimplifyPlaneScratch ); // near
|
|
566
|
+
|
|
567
|
+
} else if ( coordinateSystem === WebGPUCoordinateSystem ) {
|
|
568
|
+
|
|
569
|
+
_cimplifyPlaneScratch[ 0 ] = me2; _cimplifyPlaneScratch[ 1 ] = me6; _cimplifyPlaneScratch[ 2 ] = me10; _cimplifyPlaneScratch[ 3 ] = me14; _cimplifyPlaneStore( planes[ 5 ], _cimplifyPlaneScratch ); // near
|
|
570
|
+
|
|
571
|
+
} else {
|
|
572
|
+
|
|
573
|
+
throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
|
|
574
|
+
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
}`
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
file: MODULE,
|
|
581
|
+
find: `currentRenderList.push( object, geometry, material, groupOrder, _vector4.z, null, camera );`,
|
|
582
|
+
replace: `currentRenderList.push( object, geometry, material, groupOrder, _vector4, null, camera );`,
|
|
583
|
+
count: 2
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
file: MODULE,
|
|
587
|
+
find: `currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector4.z, group, camera );`,
|
|
588
|
+
replace: `currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector4, group, camera );`
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
file: MODULE,
|
|
592
|
+
find: ` function init() {
|
|
593
|
+
|
|
594
|
+
renderItemsIndex = 0;
|
|
595
|
+
|
|
596
|
+
opaque.length = 0;
|
|
597
|
+
transmissive.length = 0;
|
|
598
|
+
transparent.length = 0;
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
`,
|
|
603
|
+
replace: ` let opaqueCount = 0;
|
|
604
|
+
let transmissiveCount = 0;
|
|
605
|
+
let transparentCount = 0;
|
|
606
|
+
|
|
607
|
+
function init() {
|
|
608
|
+
|
|
609
|
+
renderItemsIndex = 0;
|
|
610
|
+
opaqueCount = 0;
|
|
611
|
+
transmissiveCount = 0;
|
|
612
|
+
transparentCount = 0;
|
|
613
|
+
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
`
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
file: MODULE,
|
|
620
|
+
find: ` function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
|
|
621
|
+
|
|
622
|
+
let renderItem = renderItems[ renderItemsIndex ];
|
|
623
|
+
|
|
624
|
+
if ( renderItem === undefined ) {
|
|
625
|
+
|
|
626
|
+
renderItem = {
|
|
627
|
+
id: object.id,
|
|
628
|
+
object: object,
|
|
629
|
+
geometry: geometry,
|
|
630
|
+
material: material,
|
|
631
|
+
materialVariant: materialVariant( object ),
|
|
632
|
+
groupOrder: groupOrder,
|
|
633
|
+
renderOrder: object.renderOrder,
|
|
634
|
+
z: z,
|
|
635
|
+
group: group
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
renderItems[ renderItemsIndex ] = renderItem;
|
|
639
|
+
|
|
640
|
+
} else {
|
|
641
|
+
|
|
642
|
+
renderItem.id = object.id;
|
|
643
|
+
renderItem.object = object;
|
|
644
|
+
renderItem.geometry = geometry;
|
|
645
|
+
renderItem.material = material;
|
|
646
|
+
renderItem.materialVariant = materialVariant( object );
|
|
647
|
+
renderItem.groupOrder = groupOrder;
|
|
648
|
+
renderItem.renderOrder = object.renderOrder;
|
|
649
|
+
renderItem.z = z;
|
|
650
|
+
renderItem.group = group;
|
|
651
|
+
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
renderItemsIndex ++;
|
|
655
|
+
|
|
656
|
+
return renderItem;
|
|
657
|
+
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function push( object, geometry, material, groupOrder, z, group, camera ) {
|
|
661
|
+
|
|
662
|
+
// with a reversed depth buffer the projected z is inverted
|
|
663
|
+
|
|
664
|
+
if ( camera.reversedDepth === true ) z = - z;
|
|
665
|
+
|
|
666
|
+
const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
|
|
667
|
+
|
|
668
|
+
if ( material.transmission > 0.0 ) {
|
|
669
|
+
|
|
670
|
+
transmissive.push( renderItem );
|
|
671
|
+
|
|
672
|
+
} else if ( material.transparent === true ) {
|
|
673
|
+
|
|
674
|
+
transparent.push( renderItem );
|
|
675
|
+
|
|
676
|
+
} else {
|
|
677
|
+
|
|
678
|
+
opaque.push( renderItem );
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function unshift( object, geometry, material, groupOrder, z, group ) {
|
|
685
|
+
|
|
686
|
+
const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
|
|
687
|
+
|
|
688
|
+
if ( material.transmission > 0.0 ) {
|
|
689
|
+
|
|
690
|
+
transmissive.unshift( renderItem );
|
|
691
|
+
|
|
692
|
+
} else if ( material.transparent === true ) {
|
|
693
|
+
|
|
694
|
+
transparent.unshift( renderItem );
|
|
695
|
+
|
|
696
|
+
} else {
|
|
697
|
+
|
|
698
|
+
opaque.unshift( renderItem );
|
|
699
|
+
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
function sort( customOpaqueSort, customTransparentSort ) {
|
|
705
|
+
|
|
706
|
+
if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
|
|
707
|
+
if ( transmissive.length > 1 ) transmissive.sort( customTransparentSort || reversePainterSortStable );
|
|
708
|
+
if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
|
|
709
|
+
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
`,
|
|
713
|
+
replace: ` function getNextRenderItem( object, geometry, material, groupOrder, group ) {
|
|
714
|
+
|
|
715
|
+
let renderItem = renderItems[ renderItemsIndex ];
|
|
716
|
+
|
|
717
|
+
if ( renderItem === undefined ) {
|
|
718
|
+
|
|
719
|
+
renderItem = {
|
|
720
|
+
id: object.id,
|
|
721
|
+
object: object,
|
|
722
|
+
geometry: geometry,
|
|
723
|
+
material: material,
|
|
724
|
+
materialVariant: materialVariant( object ),
|
|
725
|
+
groupOrder: groupOrder,
|
|
726
|
+
renderOrder: object.renderOrder,
|
|
727
|
+
z: 0.5,
|
|
728
|
+
group: group
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
renderItems[ renderItemsIndex ] = renderItem;
|
|
732
|
+
|
|
733
|
+
} else {
|
|
734
|
+
|
|
735
|
+
renderItem.id = object.id;
|
|
736
|
+
renderItem.object = object;
|
|
737
|
+
renderItem.geometry = geometry;
|
|
738
|
+
renderItem.material = material;
|
|
739
|
+
renderItem.materialVariant = materialVariant( object );
|
|
740
|
+
renderItem.groupOrder = groupOrder;
|
|
741
|
+
renderItem.renderOrder = object.renderOrder;
|
|
742
|
+
renderItem.group = group;
|
|
743
|
+
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
renderItemsIndex ++;
|
|
747
|
+
|
|
748
|
+
return renderItem;
|
|
749
|
+
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function file( renderItem, material ) {
|
|
753
|
+
|
|
754
|
+
if ( material.transmission > 0.0 ) {
|
|
755
|
+
|
|
756
|
+
transmissive[ transmissiveCount ++ ] = renderItem;
|
|
757
|
+
|
|
758
|
+
} else if ( material.transparent === true ) {
|
|
759
|
+
|
|
760
|
+
transparent[ transparentCount ++ ] = renderItem;
|
|
761
|
+
|
|
762
|
+
} else {
|
|
763
|
+
|
|
764
|
+
opaque[ opaqueCount ++ ] = renderItem;
|
|
765
|
+
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
function push( object, geometry, material, groupOrder, depth, group, camera ) {
|
|
771
|
+
|
|
772
|
+
const renderItem = getNextRenderItem( object, geometry, material, groupOrder, group );
|
|
773
|
+
renderItem.z = camera.reversedDepth === true ? - depth.z : depth.z;
|
|
774
|
+
file( renderItem, material );
|
|
775
|
+
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function insertFirst( list, count, renderItem ) {
|
|
779
|
+
|
|
780
|
+
for ( let i = count; i > 0; i -- ) list[ i ] = list[ i - 1 ];
|
|
781
|
+
list[ 0 ] = renderItem;
|
|
782
|
+
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
function unshift( object, geometry, material, groupOrder, z, group ) {
|
|
786
|
+
|
|
787
|
+
const renderItem = getNextRenderItem( object, geometry, material, groupOrder, group );
|
|
788
|
+
renderItem.z = z;
|
|
789
|
+
|
|
790
|
+
if ( material.transmission > 0.0 ) {
|
|
791
|
+
|
|
792
|
+
insertFirst( transmissive, transmissiveCount ++, renderItem );
|
|
793
|
+
|
|
794
|
+
} else if ( material.transparent === true ) {
|
|
795
|
+
|
|
796
|
+
insertFirst( transparent, transparentCount ++, renderItem );
|
|
797
|
+
|
|
798
|
+
} else {
|
|
799
|
+
|
|
800
|
+
insertFirst( opaque, opaqueCount ++, renderItem );
|
|
801
|
+
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
function sortList( list, compare ) {
|
|
807
|
+
|
|
808
|
+
for ( let i = 1, l = list.length; i < l; i ++ ) {
|
|
809
|
+
|
|
810
|
+
const item = list[ i ];
|
|
811
|
+
let j = i - 1;
|
|
812
|
+
|
|
813
|
+
while ( j >= 0 && compare( list[ j ], item ) > 0 ) {
|
|
814
|
+
|
|
815
|
+
list[ j + 1 ] = list[ j ];
|
|
816
|
+
j --;
|
|
817
|
+
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
list[ j + 1 ] = item;
|
|
821
|
+
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function sort( customOpaqueSort, customTransparentSort ) {
|
|
827
|
+
|
|
828
|
+
if ( opaque.length > 1 ) sortList( opaque, customOpaqueSort || painterSortStable );
|
|
829
|
+
if ( transmissive.length > 1 ) sortList( transmissive, customTransparentSort || reversePainterSortStable );
|
|
830
|
+
if ( transparent.length > 1 ) sortList( transparent, customTransparentSort || reversePainterSortStable );
|
|
831
|
+
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
`
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
file: MODULE,
|
|
838
|
+
find: ` function finish() {
|
|
839
|
+
|
|
840
|
+
// Clear references from inactive renderItems in the list
|
|
841
|
+
`,
|
|
842
|
+
replace: ` function finish() {
|
|
843
|
+
|
|
844
|
+
if ( opaque.length !== opaqueCount ) opaque.length = opaqueCount;
|
|
845
|
+
if ( transmissive.length !== transmissiveCount ) transmissive.length = transmissiveCount;
|
|
846
|
+
if ( transparent.length !== transparentCount ) transparent.length = transparentCount;
|
|
847
|
+
`
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
file: MODULE,
|
|
851
|
+
find: ` return a.z - b.z;`,
|
|
852
|
+
replace: ` return a.z < b.z ? - 1 : 1;`
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
file: MODULE,
|
|
856
|
+
find: ` return b.z - a.z;`,
|
|
857
|
+
replace: ` return b.z < a.z ? - 1 : 1;`
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
file: CORE,
|
|
861
|
+
find: ` setFromMatrix4( m ) {
|
|
862
|
+
|
|
863
|
+
const me = m.elements;
|
|
864
|
+
|
|
865
|
+
this.set(
|
|
866
|
+
|
|
867
|
+
me[ 0 ], me[ 4 ], me[ 8 ],
|
|
868
|
+
me[ 1 ], me[ 5 ], me[ 9 ],
|
|
869
|
+
me[ 2 ], me[ 6 ], me[ 10 ]
|
|
870
|
+
|
|
871
|
+
);
|
|
872
|
+
|
|
873
|
+
return this;
|
|
874
|
+
|
|
875
|
+
}`,
|
|
876
|
+
replace: ` setFromMatrix4( m ) {
|
|
877
|
+
|
|
878
|
+
const me = m.elements;
|
|
879
|
+
const te = this.elements;
|
|
880
|
+
|
|
881
|
+
te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
|
|
882
|
+
te[ 3 ] = me[ 4 ]; te[ 4 ] = me[ 5 ]; te[ 5 ] = me[ 6 ];
|
|
883
|
+
te[ 6 ] = me[ 8 ]; te[ 7 ] = me[ 9 ]; te[ 8 ] = me[ 10 ];
|
|
884
|
+
|
|
885
|
+
return this;
|
|
886
|
+
|
|
887
|
+
}`
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
file: CORE,
|
|
891
|
+
find: ` normalize() {
|
|
892
|
+
|
|
893
|
+
return this.divideScalar( this.length() || 1 );
|
|
894
|
+
|
|
895
|
+
}`,
|
|
896
|
+
replace: ` normalize() {
|
|
897
|
+
|
|
898
|
+
const length = Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z ) || 1;
|
|
899
|
+
this.x /= length;
|
|
900
|
+
this.y /= length;
|
|
901
|
+
this.z /= length;
|
|
902
|
+
return this;
|
|
903
|
+
|
|
904
|
+
}`,
|
|
905
|
+
after: `class Vector3 {`
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
file: CORE,
|
|
909
|
+
find: ` determinantAffine() {`,
|
|
910
|
+
replace: ` _cimplifyDeterminantSign() {
|
|
911
|
+
|
|
912
|
+
const te = this.elements;
|
|
913
|
+
const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ];
|
|
914
|
+
const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ];
|
|
915
|
+
const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ];
|
|
916
|
+
const det = n11 * ( n22 * n33 - n23 * n32 ) - n12 * ( n21 * n33 - n23 * n31 ) + n13 * ( n21 * n32 - n22 * n31 );
|
|
917
|
+
return det < 0 ? - 1 : det > 0 ? 1 : 0;
|
|
918
|
+
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
determinantAffine() {`
|
|
922
|
+
},
|
|
923
|
+
{
|
|
924
|
+
file: CORE,
|
|
925
|
+
find: ` const det = this.determinantAffine();
|
|
926
|
+
|
|
927
|
+
if ( det === 0 ) {
|
|
928
|
+
|
|
929
|
+
scale.set( 1, 1, 1 );
|
|
930
|
+
quaternion.identity();
|
|
931
|
+
|
|
932
|
+
return this;
|
|
933
|
+
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
let sx = _v1$7.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
|
|
937
|
+
const sy = _v1$7.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
|
|
938
|
+
const sz = _v1$7.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
|
|
939
|
+
|
|
940
|
+
// if determinant is negative, we need to invert one scale
|
|
941
|
+
if ( det < 0 ) sx = - sx;`,
|
|
942
|
+
replace: ` const sign = this._cimplifyDeterminantSign();
|
|
943
|
+
|
|
944
|
+
if ( sign === 0 ) {
|
|
945
|
+
|
|
946
|
+
scale.set( 1, 1, 1 );
|
|
947
|
+
quaternion.identity();
|
|
948
|
+
|
|
949
|
+
return this;
|
|
950
|
+
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
let sx = Math.sqrt( te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ] );
|
|
954
|
+
const sy = Math.sqrt( te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ] );
|
|
955
|
+
const sz = Math.sqrt( te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ] );
|
|
956
|
+
|
|
957
|
+
if ( sign < 0 ) sx = - sx;`
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
file: MODULE,
|
|
961
|
+
find: `object.matrixWorld.determinantAffine() < 0`,
|
|
962
|
+
replace: `object.matrixWorld._cimplifyDeterminantSign() < 0`
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
file: CORE,
|
|
966
|
+
find: ` this.radius = this.radius * matrix.getMaxScaleOnAxis();`,
|
|
967
|
+
replace: ` const te = matrix.elements;
|
|
968
|
+
const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
|
|
969
|
+
const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
|
|
970
|
+
const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
|
|
971
|
+
this.radius = this.radius * Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );`
|
|
972
|
+
},
|
|
973
|
+
{
|
|
974
|
+
file: MODULE,
|
|
975
|
+
find: `function shadowCastingAndTexturingLightsFirst( lightA, lightB ) {`,
|
|
976
|
+
replace: `function _cimplifySort( list, compare ) {
|
|
977
|
+
|
|
978
|
+
for ( let i = 1, l = list.length; i < l; i ++ ) {
|
|
979
|
+
|
|
980
|
+
const item = list[ i ];
|
|
981
|
+
let j = i - 1;
|
|
982
|
+
|
|
983
|
+
while ( j >= 0 && compare( list[ j ], item ) > 0 ) {
|
|
984
|
+
|
|
985
|
+
list[ j + 1 ] = list[ j ];
|
|
986
|
+
j --;
|
|
987
|
+
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
list[ j + 1 ] = item;
|
|
991
|
+
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
function shadowCastingAndTexturingLightsFirst( lightA, lightB ) {`
|
|
997
|
+
},
|
|
998
|
+
{
|
|
999
|
+
file: MODULE,
|
|
1000
|
+
find: ` lights.sort( shadowCastingAndTexturingLightsFirst );`,
|
|
1001
|
+
replace: ` _cimplifySort( lights, shadowCastingAndTexturingLightsFirst );`
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
file: MODULE,
|
|
1005
|
+
find: ` function init( camera ) {
|
|
1006
|
+
|
|
1007
|
+
state.camera = camera;
|
|
1008
|
+
|
|
1009
|
+
lightsArray.length = 0;
|
|
1010
|
+
shadowsArray.length = 0;
|
|
1011
|
+
lightProbeGridArray.length = 0;
|
|
1012
|
+
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
function pushLight( light ) {
|
|
1016
|
+
|
|
1017
|
+
lightsArray.push( light );
|
|
1018
|
+
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function pushShadow( shadowLight ) {
|
|
1022
|
+
|
|
1023
|
+
shadowsArray.push( shadowLight );
|
|
1024
|
+
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function pushLightProbeGrid( volume ) {
|
|
1028
|
+
|
|
1029
|
+
lightProbeGridArray.push( volume );
|
|
1030
|
+
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function setupLights() {
|
|
1034
|
+
|
|
1035
|
+
lights.setup( lightsArray );
|
|
1036
|
+
|
|
1037
|
+
}`,
|
|
1038
|
+
replace: ` let lightsCount = 0;
|
|
1039
|
+
let shadowsCount = 0;
|
|
1040
|
+
let lightProbeGridCount = 0;
|
|
1041
|
+
|
|
1042
|
+
function init( camera ) {
|
|
1043
|
+
|
|
1044
|
+
state.camera = camera;
|
|
1045
|
+
|
|
1046
|
+
lightsCount = 0;
|
|
1047
|
+
shadowsCount = 0;
|
|
1048
|
+
lightProbeGridCount = 0;
|
|
1049
|
+
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function pushLight( light ) {
|
|
1053
|
+
|
|
1054
|
+
lightsArray[ lightsCount ++ ] = light;
|
|
1055
|
+
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
function pushShadow( shadowLight ) {
|
|
1059
|
+
|
|
1060
|
+
shadowsArray[ shadowsCount ++ ] = shadowLight;
|
|
1061
|
+
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
function pushLightProbeGrid( volume ) {
|
|
1065
|
+
|
|
1066
|
+
lightProbeGridArray[ lightProbeGridCount ++ ] = volume;
|
|
1067
|
+
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function finish() {
|
|
1071
|
+
|
|
1072
|
+
if ( lightsArray.length !== lightsCount ) lightsArray.length = lightsCount;
|
|
1073
|
+
if ( shadowsArray.length !== shadowsCount ) shadowsArray.length = shadowsCount;
|
|
1074
|
+
if ( lightProbeGridArray.length !== lightProbeGridCount ) lightProbeGridArray.length = lightProbeGridCount;
|
|
1075
|
+
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
function setupLights() {
|
|
1079
|
+
|
|
1080
|
+
finish();
|
|
1081
|
+
lights.setup( lightsArray );
|
|
1082
|
+
|
|
1083
|
+
}`
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
file: MODULE,
|
|
1087
|
+
find: ` init: init,
|
|
1088
|
+
state: state,
|
|
1089
|
+
setupLights: setupLights,`,
|
|
1090
|
+
replace: ` init: init,
|
|
1091
|
+
finish: finish,
|
|
1092
|
+
state: state,
|
|
1093
|
+
setupLights: setupLights,`
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
file: MODULE,
|
|
1097
|
+
find: ` currentRenderList.finish();`,
|
|
1098
|
+
replace: ` currentRenderList.finish();
|
|
1099
|
+
currentRenderState.finish();`
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
file: MODULE,
|
|
1103
|
+
find: `function setValueV1f( gl, v ) {
|
|
1104
|
+
|
|
1105
|
+
const cache = this.cache;
|
|
1106
|
+
|
|
1107
|
+
if ( cache[ 0 ] === v ) return;
|
|
1108
|
+
|
|
1109
|
+
gl.uniform1f( this.addr, v );
|
|
1110
|
+
|
|
1111
|
+
cache[ 0 ] = v;
|
|
1112
|
+
|
|
1113
|
+
}`,
|
|
1114
|
+
replace: `const _cimplifyUniformScratch = new Float32Array( 4 );
|
|
1115
|
+
|
|
1116
|
+
function setValueV1f( gl, v ) {
|
|
1117
|
+
|
|
1118
|
+
const cache = this._cimplifyCache;
|
|
1119
|
+
|
|
1120
|
+
if ( cache[ 0 ] === v ) return;
|
|
1121
|
+
|
|
1122
|
+
cache[ 0 ] = v;
|
|
1123
|
+
_cimplifyUniformScratch[ 0 ] = v;
|
|
1124
|
+
gl.uniform1fv( this.addr, _cimplifyUniformScratch, 0, 1 );
|
|
1125
|
+
|
|
1126
|
+
}`
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
file: MODULE,
|
|
1130
|
+
find: ` if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
|
|
1131
|
+
|
|
1132
|
+
gl.uniform3f( this.addr, v.x, v.y, v.z );
|
|
1133
|
+
|
|
1134
|
+
cache[ 0 ] = v.x;
|
|
1135
|
+
cache[ 1 ] = v.y;
|
|
1136
|
+
cache[ 2 ] = v.z;
|
|
1137
|
+
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
} else if ( v.r !== undefined ) {
|
|
1141
|
+
|
|
1142
|
+
if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
|
|
1143
|
+
|
|
1144
|
+
gl.uniform3f( this.addr, v.r, v.g, v.b );
|
|
1145
|
+
|
|
1146
|
+
cache[ 0 ] = v.r;
|
|
1147
|
+
cache[ 1 ] = v.g;
|
|
1148
|
+
cache[ 2 ] = v.b;
|
|
1149
|
+
|
|
1150
|
+
}`,
|
|
1151
|
+
replace: ` const typed = this._cimplifyCache;
|
|
1152
|
+
|
|
1153
|
+
if ( typed[ 0 ] !== v.x || typed[ 1 ] !== v.y || typed[ 2 ] !== v.z ) {
|
|
1154
|
+
|
|
1155
|
+
typed[ 0 ] = v.x;
|
|
1156
|
+
typed[ 1 ] = v.y;
|
|
1157
|
+
typed[ 2 ] = v.z;
|
|
1158
|
+
_cimplifyUniformScratch[ 0 ] = typed[ 0 ];
|
|
1159
|
+
_cimplifyUniformScratch[ 1 ] = typed[ 1 ];
|
|
1160
|
+
_cimplifyUniformScratch[ 2 ] = typed[ 2 ];
|
|
1161
|
+
gl.uniform3fv( this.addr, _cimplifyUniformScratch, 0, 3 );
|
|
1162
|
+
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
} else if ( v.r !== undefined ) {
|
|
1166
|
+
|
|
1167
|
+
const typed = this._cimplifyCache;
|
|
1168
|
+
|
|
1169
|
+
if ( typed[ 0 ] !== v.r || typed[ 1 ] !== v.g || typed[ 2 ] !== v.b ) {
|
|
1170
|
+
|
|
1171
|
+
typed[ 0 ] = v.r;
|
|
1172
|
+
typed[ 1 ] = v.g;
|
|
1173
|
+
typed[ 2 ] = v.b;
|
|
1174
|
+
_cimplifyUniformScratch[ 0 ] = typed[ 0 ];
|
|
1175
|
+
_cimplifyUniformScratch[ 1 ] = typed[ 1 ];
|
|
1176
|
+
_cimplifyUniformScratch[ 2 ] = typed[ 2 ];
|
|
1177
|
+
gl.uniform3fv( this.addr, _cimplifyUniformScratch, 0, 3 );
|
|
1178
|
+
|
|
1179
|
+
}`
|
|
1180
|
+
},
|
|
1181
|
+
{
|
|
1182
|
+
file: MODULE,
|
|
1183
|
+
find: ` uniforms.metalness.value = material.metalness;`,
|
|
1184
|
+
replace: ` if ( uniforms.metalness.value !== material.metalness ) uniforms.metalness.value = material.metalness;`
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
file: MODULE,
|
|
1188
|
+
find: ` uniforms.roughness.value = material.roughness;`,
|
|
1189
|
+
replace: ` if ( uniforms.roughness.value !== material.roughness ) uniforms.roughness.value = material.roughness;`
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
file: MODULE,
|
|
1193
|
+
find: ` this.cache = [];
|
|
1194
|
+
this.type = activeInfo.type;
|
|
1195
|
+
this.setValue = getSingularSetter( activeInfo.type );`,
|
|
1196
|
+
replace: ` this.cache = [];
|
|
1197
|
+
this._cimplifyCache = new Float64Array( 3 ).fill( NaN );
|
|
1198
|
+
this.type = activeInfo.type;
|
|
1199
|
+
this.setValue = getSingularSetter( activeInfo.type );`
|
|
1200
|
+
},
|
|
1201
|
+
{
|
|
1202
|
+
file: MODULE,
|
|
1203
|
+
find: ` if ( v.x !== undefined ) {`,
|
|
1204
|
+
replace: ` if ( v.isVector3 === true ) {`,
|
|
1205
|
+
after: `function setValueV3f( gl, v ) {`
|
|
1206
|
+
},
|
|
1207
|
+
{
|
|
1208
|
+
file: MODULE,
|
|
1209
|
+
find: ` } else if ( v.r !== undefined ) {`,
|
|
1210
|
+
replace: ` } else if ( v.isColor === true ) {`,
|
|
1211
|
+
after: `function setValueV3f( gl, v ) {`
|
|
1212
|
+
},
|
|
1213
|
+
{
|
|
1214
|
+
file: MODULE,
|
|
1215
|
+
find: ` object: vao,
|
|
1216
|
+
attributes: {},
|
|
1217
|
+
index: null`,
|
|
1218
|
+
replace: ` object: vao,
|
|
1219
|
+
attributes: {},
|
|
1220
|
+
attributesNum: 0,
|
|
1221
|
+
cimplifyNames: null,
|
|
1222
|
+
cimplifyAttributes: [],
|
|
1223
|
+
cimplifyData: [],
|
|
1224
|
+
index: null`
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
file: MODULE,
|
|
1228
|
+
find: ` function needsUpdate( object, geometry, program, index ) {
|
|
1229
|
+
|
|
1230
|
+
const cachedAttributes = currentState.attributes;
|
|
1231
|
+
const geometryAttributes = geometry.attributes;
|
|
1232
|
+
|
|
1233
|
+
let attributesNum = 0;
|
|
1234
|
+
|
|
1235
|
+
const programAttributes = program.getAttributes();
|
|
1236
|
+
|
|
1237
|
+
for ( const name in programAttributes ) {
|
|
1238
|
+
|
|
1239
|
+
const programAttribute = programAttributes[ name ];
|
|
1240
|
+
|
|
1241
|
+
if ( programAttribute.location >= 0 ) {
|
|
1242
|
+
|
|
1243
|
+
const cachedAttribute = cachedAttributes[ name ];
|
|
1244
|
+
let geometryAttribute = geometryAttributes[ name ];
|
|
1245
|
+
|
|
1246
|
+
if ( geometryAttribute === undefined ) {
|
|
1247
|
+
|
|
1248
|
+
if ( name === 'instanceMatrix' && object.instanceMatrix ) geometryAttribute = object.instanceMatrix;
|
|
1249
|
+
if ( name === 'instanceColor' && object.instanceColor ) geometryAttribute = object.instanceColor;
|
|
1250
|
+
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
if ( cachedAttribute === undefined ) return true;
|
|
1254
|
+
|
|
1255
|
+
if ( cachedAttribute.attribute !== geometryAttribute ) return true;
|
|
1256
|
+
|
|
1257
|
+
if ( geometryAttribute && cachedAttribute.data !== geometryAttribute.data ) return true;
|
|
1258
|
+
|
|
1259
|
+
attributesNum ++;
|
|
1260
|
+
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
if ( currentState.attributesNum !== attributesNum ) return true;
|
|
1266
|
+
|
|
1267
|
+
if ( currentState.index !== index ) return true;
|
|
1268
|
+
|
|
1269
|
+
return false;
|
|
1270
|
+
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
function saveCache( object, geometry, program, index ) {
|
|
1274
|
+
|
|
1275
|
+
const cache = {};
|
|
1276
|
+
const attributes = geometry.attributes;
|
|
1277
|
+
let attributesNum = 0;
|
|
1278
|
+
|
|
1279
|
+
const programAttributes = program.getAttributes();
|
|
1280
|
+
|
|
1281
|
+
for ( const name in programAttributes ) {
|
|
1282
|
+
|
|
1283
|
+
const programAttribute = programAttributes[ name ];
|
|
1284
|
+
|
|
1285
|
+
if ( programAttribute.location >= 0 ) {
|
|
1286
|
+
|
|
1287
|
+
let attribute = attributes[ name ];
|
|
1288
|
+
|
|
1289
|
+
if ( attribute === undefined ) {
|
|
1290
|
+
|
|
1291
|
+
if ( name === 'instanceMatrix' && object.instanceMatrix ) attribute = object.instanceMatrix;
|
|
1292
|
+
if ( name === 'instanceColor' && object.instanceColor ) attribute = object.instanceColor;
|
|
1293
|
+
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
const data = {};
|
|
1297
|
+
data.attribute = attribute;
|
|
1298
|
+
|
|
1299
|
+
if ( attribute && attribute.data ) {
|
|
1300
|
+
|
|
1301
|
+
data.data = attribute.data;
|
|
1302
|
+
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
cache[ name ] = data;
|
|
1306
|
+
|
|
1307
|
+
attributesNum ++;
|
|
1308
|
+
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
currentState.attributes = cache;
|
|
1314
|
+
currentState.attributesNum = attributesNum;
|
|
1315
|
+
|
|
1316
|
+
currentState.index = index;
|
|
1317
|
+
|
|
1318
|
+
}
|
|
1319
|
+
`,
|
|
1320
|
+
replace: ` function attributeNames( program ) {
|
|
1321
|
+
|
|
1322
|
+
let names = program.cimplifyAttributeNames;
|
|
1323
|
+
|
|
1324
|
+
if ( names === undefined ) {
|
|
1325
|
+
|
|
1326
|
+
names = [];
|
|
1327
|
+
const programAttributes = program.getAttributes();
|
|
1328
|
+
|
|
1329
|
+
for ( const name in programAttributes ) {
|
|
1330
|
+
|
|
1331
|
+
if ( programAttributes[ name ].location >= 0 ) names.push( name );
|
|
1332
|
+
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
program.cimplifyAttributeNames = names;
|
|
1336
|
+
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
return names;
|
|
1340
|
+
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function attributeOf( object, attributes, name ) {
|
|
1344
|
+
|
|
1345
|
+
const attribute = attributes[ name ];
|
|
1346
|
+
|
|
1347
|
+
if ( attribute !== undefined ) return attribute;
|
|
1348
|
+
if ( name === 'instanceMatrix' && object.instanceMatrix ) return object.instanceMatrix;
|
|
1349
|
+
if ( name === 'instanceColor' && object.instanceColor ) return object.instanceColor;
|
|
1350
|
+
return undefined;
|
|
1351
|
+
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
function needsUpdate( object, geometry, program, index ) {
|
|
1355
|
+
|
|
1356
|
+
const names = attributeNames( program );
|
|
1357
|
+
|
|
1358
|
+
if ( currentState.cimplifyNames !== names ) return true;
|
|
1359
|
+
if ( currentState.index !== index ) return true;
|
|
1360
|
+
|
|
1361
|
+
const cachedAttributes = currentState.cimplifyAttributes;
|
|
1362
|
+
const cachedData = currentState.cimplifyData;
|
|
1363
|
+
const geometryAttributes = geometry.attributes;
|
|
1364
|
+
|
|
1365
|
+
for ( let i = 0, l = names.length; i < l; i ++ ) {
|
|
1366
|
+
|
|
1367
|
+
const geometryAttribute = attributeOf( object, geometryAttributes, names[ i ] );
|
|
1368
|
+
|
|
1369
|
+
if ( cachedAttributes[ i ] !== geometryAttribute ) return true;
|
|
1370
|
+
if ( geometryAttribute !== undefined && cachedData[ i ] !== geometryAttribute.data ) return true;
|
|
1371
|
+
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
return false;
|
|
1375
|
+
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
function saveCache( object, geometry, program, index ) {
|
|
1379
|
+
|
|
1380
|
+
const names = attributeNames( program );
|
|
1381
|
+
const cache = {};
|
|
1382
|
+
const attributes = geometry.attributes;
|
|
1383
|
+
const cachedAttributes = currentState.cimplifyAttributes;
|
|
1384
|
+
const cachedData = currentState.cimplifyData;
|
|
1385
|
+
|
|
1386
|
+
cachedAttributes.length = names.length;
|
|
1387
|
+
cachedData.length = names.length;
|
|
1388
|
+
|
|
1389
|
+
for ( let i = 0, l = names.length; i < l; i ++ ) {
|
|
1390
|
+
|
|
1391
|
+
const name = names[ i ];
|
|
1392
|
+
const attribute = attributeOf( object, attributes, name );
|
|
1393
|
+
const data = attribute !== undefined ? attribute.data : undefined;
|
|
1394
|
+
|
|
1395
|
+
cachedAttributes[ i ] = attribute;
|
|
1396
|
+
cachedData[ i ] = data;
|
|
1397
|
+
cache[ name ] = { attribute: attribute, data: data };
|
|
1398
|
+
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
currentState.attributes = cache;
|
|
1402
|
+
currentState.attributesNum = names.length;
|
|
1403
|
+
currentState.cimplifyNames = names;
|
|
1404
|
+
currentState.index = index;
|
|
1405
|
+
|
|
1406
|
+
}
|
|
1407
|
+
`
|
|
1408
|
+
}
|
|
1409
|
+
];
|
|
1410
|
+
var THREE_FORK = {
|
|
1411
|
+
library: "three",
|
|
1412
|
+
version: "0.186.1",
|
|
1413
|
+
entry: MODULE,
|
|
1414
|
+
files: [CORE, MODULE],
|
|
1415
|
+
patches: PATCHES
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
// src/interactives/build/runtime-chunks.ts
|
|
1419
|
+
var ENGINE_CORE = "@cimplify/engine-core";
|
|
1420
|
+
var ENGINE_CORE_THREADS = "@cimplify/engine-core-threads";
|
|
1421
|
+
var ENGINE_RUNTIME_PACKAGE = "@cimplify/engine-runtime";
|
|
1422
|
+
var ENGINE_RUNTIME_ENV = "CIMPLIFY_ENGINE_RUNTIME_DIR";
|
|
1423
|
+
var ENGINE_RUNTIME_WASM_DIR = "wasm";
|
|
1424
|
+
var ENGINE_RUNTIME_WORKSPACE_DIR = "engine-runtime";
|
|
1425
|
+
var WORKSPACE_TEXT_DICTIONARIES = ["..", "..", "crates", "engine_text", "data", "dictionaries.bin"];
|
|
1426
|
+
var RUNTIME_REGISTRY_ID = "esbuild-0.28.2-cjs@3";
|
|
1427
|
+
var SDK_CHUNK_PREFIX = `${SDK_PACKAGE}/~/`;
|
|
1428
|
+
var SDK_DIST_DIR = "dist";
|
|
1429
|
+
var RELATIVE_IMPORT = /^\.\.?\//;
|
|
1430
|
+
var RUNTIME_IMPORT_META_URL = "https://runtime.cimplify.invalid/";
|
|
1431
|
+
var ESBUILD_TARGET = "es2022";
|
|
1432
|
+
var NODE_ENV = '"production"';
|
|
1433
|
+
var PREFIX_WILDCARD = "*";
|
|
1434
|
+
var VERSION_DIGEST_SEPARATOR = "+";
|
|
1435
|
+
var VERSION_DIGEST_HEX = 16;
|
|
1436
|
+
var UNIT_KEY_SEPARATOR = "\n";
|
|
1437
|
+
var SHA256 = "sha256";
|
|
1438
|
+
var PREFIX_ALIASES = [["three/examples/jsm/", "three/addons/"]];
|
|
1439
|
+
var WHOLE_SPECIFIER = "*";
|
|
1440
|
+
var SDK_SHAKEN_PREFIX = `${SDK_PACKAGE}/~`;
|
|
1441
|
+
var CANVAS_CORE_UNIT = `${SDK_PACKAGE}/~canvas-core`;
|
|
1442
|
+
var SDK_GAME_UNIT_PREFIX = `${SDK_PACKAGE}/~game-`;
|
|
1443
|
+
var SDK_GAME_NAME_HEX = 16;
|
|
1444
|
+
var CANVAS_CORE_BINDINGS = /* @__PURE__ */ new Map([["@cimplify/sdk/game/kit/canvas", /* @__PURE__ */ new Set(["firstFrame", "runCanvasGame"])]]);
|
|
1445
|
+
function isShakenSdkUnit(name) {
|
|
1446
|
+
return name.startsWith(SDK_SHAKEN_PREFIX) && !name.startsWith(SDK_CHUNK_PREFIX);
|
|
1447
|
+
}
|
|
1448
|
+
function sdkVersion() {
|
|
1449
|
+
const sdk = LIBRARY_ALLOWLIST.find((l) => l.name === SDK_PACKAGE);
|
|
1450
|
+
if (sdk === void 0) throw new Error("the SDK is not on the allowlist");
|
|
1451
|
+
return sdk.version;
|
|
1452
|
+
}
|
|
1453
|
+
function sdkUnit(specifier) {
|
|
1454
|
+
return { name: specifier, version: sdkVersion(), specifiers: [specifier] };
|
|
1455
|
+
}
|
|
1456
|
+
function isSdkRuntime(name) {
|
|
1457
|
+
return name === SDK_PACKAGE || name.startsWith(`${SDK_PACKAGE}/`);
|
|
1458
|
+
}
|
|
1459
|
+
function runtimeExportOf(specifier) {
|
|
1460
|
+
for (const [alias, target] of PREFIX_ALIASES) {
|
|
1461
|
+
if (specifier.startsWith(alias)) return target + specifier.slice(alias.length);
|
|
1462
|
+
}
|
|
1463
|
+
return specifier;
|
|
1464
|
+
}
|
|
1465
|
+
function runtimeUnitOf(raw) {
|
|
1466
|
+
const specifier = runtimeExportOf(raw);
|
|
1467
|
+
if (specifier === ENGINE_CORE) return { name: ENGINE_CORE, version: sdkVersion(), specifiers: [ENGINE_CORE] };
|
|
1468
|
+
if (specifier.startsWith(SDK_CHUNK_PREFIX) || isShakenSdkUnit(specifier)) return sdkUnit(specifier);
|
|
1469
|
+
for (const library of LIBRARY_ALLOWLIST) {
|
|
1470
|
+
for (const entry of library.entries) {
|
|
1471
|
+
if (entry.prefix && specifier.startsWith(entry.specifier)) {
|
|
1472
|
+
return { name: specifier, version: library.version, specifiers: [specifier] };
|
|
1473
|
+
}
|
|
1474
|
+
if (!entry.prefix && specifier === entry.specifier) {
|
|
1475
|
+
if (library.name === SDK_PACKAGE) return sdkUnit(specifier);
|
|
1476
|
+
const fixed = library.entries.filter((e) => !e.prefix).map((e) => e.specifier);
|
|
1477
|
+
return { name: library.name, version: library.version, specifiers: fixed };
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
return null;
|
|
1482
|
+
}
|
|
1483
|
+
function externals(unit) {
|
|
1484
|
+
const out = [];
|
|
1485
|
+
for (const library of LIBRARY_ALLOWLIST) {
|
|
1486
|
+
for (const entry of library.entries) {
|
|
1487
|
+
if (entry.prefix) out.push(`${entry.specifier}${PREFIX_WILDCARD}`);
|
|
1488
|
+
else if (library.name !== unit.name && unit.specifiers.indexOf(entry.specifier) < 0) out.push(entry.specifier);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
return out;
|
|
1492
|
+
}
|
|
1493
|
+
var FORKS = [THREE_FORK];
|
|
1494
|
+
function sdkDist(sdkDir) {
|
|
1495
|
+
return path4.join(sdkDir, SDK_DIST_DIR);
|
|
1496
|
+
}
|
|
1497
|
+
function entryPath(specifier, resolveDir) {
|
|
1498
|
+
const fork = FORKS.find((f) => f.library === specifier);
|
|
1499
|
+
if (fork !== void 0) {
|
|
1500
|
+
const dir2 = findPackageDir(resolveDir, fork.library);
|
|
1501
|
+
if (dir2 === null) throw new Error(`${specifier} does not resolve to a package`);
|
|
1502
|
+
return forkedEntry(fork, dir2);
|
|
1503
|
+
}
|
|
1504
|
+
const prefixed = LIBRARY_ALLOWLIST.some((l) => l.entries.some((e) => e.prefix && specifier.startsWith(e.specifier)));
|
|
1505
|
+
if (!prefixed) return specifier;
|
|
1506
|
+
const library = LIBRARY_ALLOWLIST.find((l) => specifier.startsWith(`${l.name}/`));
|
|
1507
|
+
const dir = library === void 0 ? null : findPackageDir(resolveDir, library.name);
|
|
1508
|
+
if (dir === null || library === void 0) throw new Error(`${specifier} does not resolve to a package`);
|
|
1509
|
+
const subpath = `.${specifier.slice(library.name.length)}`;
|
|
1510
|
+
const map = exportsMap(readPackageJson(dir)) ?? {};
|
|
1511
|
+
for (const key of Object.keys(map)) {
|
|
1512
|
+
if (!key.endsWith(PREFIX_WILDCARD) || !subpath.startsWith(key.slice(0, -1))) continue;
|
|
1513
|
+
const target = pickTarget(map[key], BROWSER_CONDITIONS);
|
|
1514
|
+
if (target === null) continue;
|
|
1515
|
+
const file = path4.resolve(dir, target.replace(PREFIX_WILDCARD, subpath.slice(key.length - 1)));
|
|
1516
|
+
if (existsSync(file)) return file;
|
|
1517
|
+
}
|
|
1518
|
+
throw new Error(`${specifier} does not resolve to a file`);
|
|
1519
|
+
}
|
|
1520
|
+
function entrySource(unit, resolveDir) {
|
|
1521
|
+
let imports = "";
|
|
1522
|
+
let record = "";
|
|
1523
|
+
unit.specifiers.forEach((specifier, i) => {
|
|
1524
|
+
imports += `import * as e${i} from ${JSON.stringify(entryPath(specifier, resolveDir))};
|
|
1525
|
+
`;
|
|
1526
|
+
record += `${JSON.stringify(specifier)}: e${i},`;
|
|
1527
|
+
});
|
|
1528
|
+
return `${imports}export default {${record}};
|
|
1529
|
+
`;
|
|
1530
|
+
}
|
|
1531
|
+
var REQUIRE_CALL = /\brequire\((["'])([^"'\\\n]+)\1\)/g;
|
|
1532
|
+
function requiresOf(code, unit, externalPaths) {
|
|
1533
|
+
const out = [];
|
|
1534
|
+
for (const match of code.matchAll(REQUIRE_CALL)) {
|
|
1535
|
+
const specifier = match[2];
|
|
1536
|
+
if (!externalPaths.has(specifier)) continue;
|
|
1537
|
+
const at2 = match.index + match[0].indexOf(match[1]) + 1;
|
|
1538
|
+
const target = runtimeUnitOf(specifier);
|
|
1539
|
+
if (target === null) throw new Error(`runtime ${unit.name} requires '${specifier}', which is not an allowlisted library`);
|
|
1540
|
+
out.push({ at: at2, end: at2 + specifier.length, module: null, library: target.name, export: runtimeExportOf(specifier), specifier });
|
|
1541
|
+
}
|
|
1542
|
+
return out;
|
|
1543
|
+
}
|
|
1544
|
+
function bundle(unit, resolveDir) {
|
|
1545
|
+
const result = buildSync({
|
|
1546
|
+
stdin: { contents: entrySource(unit, resolveDir), resolveDir, loader: "js", sourcefile: `${unit.name}.runtime.js` },
|
|
1547
|
+
bundle: true,
|
|
1548
|
+
write: false,
|
|
1549
|
+
format: "cjs",
|
|
1550
|
+
platform: "browser",
|
|
1551
|
+
target: ESBUILD_TARGET,
|
|
1552
|
+
conditions: ["browser", "import", "module"],
|
|
1553
|
+
mainFields: ["browser", "module", "main"],
|
|
1554
|
+
external: externals(unit),
|
|
1555
|
+
define: { "process.env.NODE_ENV": NODE_ENV, "import.meta.url": JSON.stringify(RUNTIME_IMPORT_META_URL) },
|
|
1556
|
+
legalComments: "none",
|
|
1557
|
+
minifyWhitespace: true,
|
|
1558
|
+
minifySyntax: true,
|
|
1559
|
+
charset: "utf8",
|
|
1560
|
+
logLevel: "silent",
|
|
1561
|
+
metafile: true
|
|
1562
|
+
});
|
|
1563
|
+
const found = /* @__PURE__ */ new Set();
|
|
1564
|
+
for (const input of Object.values(result.metafile.inputs)) {
|
|
1565
|
+
for (const imported of input.imports) if (imported.external === true) found.add(imported.path);
|
|
1566
|
+
}
|
|
1567
|
+
return { code: Buffer.from(inlineModuleConstants(result.outputFiles[0].text, `${unit.name}.runtime.js`).code, "utf8"), externals: found };
|
|
1568
|
+
}
|
|
1569
|
+
function built(unit, kind, chunk, imports, engineAbi, engineExports = null) {
|
|
1570
|
+
const version = `${unit.version}${VERSION_DIGEST_SEPARATOR}${chunk.digest.slice(0, VERSION_DIGEST_HEX)}`;
|
|
1571
|
+
return { unit, version, kind, chunk, imports, engineAbi, engineExports };
|
|
1572
|
+
}
|
|
1573
|
+
function engineWasm(unit, bytes) {
|
|
1574
|
+
return built(unit, "wasm", encodeChunk("wasm", bytes), [], engineAbiVersion(bytes), engineExportTable(bytes, ENGINE_EXPORT_PROTOTYPES));
|
|
1575
|
+
}
|
|
1576
|
+
function isEngineRuntime(dir) {
|
|
1577
|
+
return existsSync(path4.join(dir, "package.json")) && readPackageJson(dir).name === ENGINE_RUNTIME_PACKAGE;
|
|
1578
|
+
}
|
|
1579
|
+
function localEngineRuntimeDir(sdkDir) {
|
|
1580
|
+
const configured = process.env[ENGINE_RUNTIME_ENV];
|
|
1581
|
+
if (configured !== void 0 && configured !== "") return path4.resolve(configured);
|
|
1582
|
+
const installed = findPackageDir(sdkDir, ENGINE_RUNTIME_PACKAGE);
|
|
1583
|
+
if (installed !== null) return installed;
|
|
1584
|
+
const workspace = path4.resolve(sdkDir, "..", ENGINE_RUNTIME_WORKSPACE_DIR);
|
|
1585
|
+
return isEngineRuntime(workspace) ? workspace : null;
|
|
1586
|
+
}
|
|
1587
|
+
function engineRuntimeDir(sdkDir) {
|
|
1588
|
+
return localEngineRuntimeDir(sdkDir) ?? cachedEngineRuntimeDir();
|
|
1589
|
+
}
|
|
1590
|
+
function engineCoreFile(sdkDir, variant) {
|
|
1591
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1592
|
+
if (dir === null) {
|
|
1593
|
+
throw new Error(
|
|
1594
|
+
`the Cimplify Engine runtime is not downloaded yet: run \`cimplify login\` so the CLI fetches it for your account, or set ${ENGINE_RUNTIME_ENV} to a local engine runtime directory`
|
|
1595
|
+
);
|
|
1596
|
+
}
|
|
1597
|
+
for (const file of [variant.file, FULL_ENGINE_VARIANT.file]) {
|
|
1598
|
+
const candidate = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, file);
|
|
1599
|
+
if (existsSync(candidate)) return candidate;
|
|
1600
|
+
}
|
|
1601
|
+
throw new Error(`${dir} holds no ${ENGINE_RUNTIME_WASM_DIR}/${variant.file}: run bun run build in packages/engine-runtime`);
|
|
1602
|
+
}
|
|
1603
|
+
function textDictionariesFile(sdkDir) {
|
|
1604
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1605
|
+
if (dir !== null) {
|
|
1606
|
+
const staged = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, TEXT_DICTIONARIES_FILE);
|
|
1607
|
+
if (existsSync(staged)) return staged;
|
|
1608
|
+
}
|
|
1609
|
+
const workspace = path4.resolve(sdkDir, ...WORKSPACE_TEXT_DICTIONARIES);
|
|
1610
|
+
return existsSync(workspace) ? workspace : null;
|
|
1611
|
+
}
|
|
1612
|
+
function luauVmFile(sdkDir) {
|
|
1613
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1614
|
+
if (dir === null) return null;
|
|
1615
|
+
const file = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, LUAU_VM_FILE);
|
|
1616
|
+
return existsSync(file) ? file : null;
|
|
1617
|
+
}
|
|
1618
|
+
function luauVmRuntime(sdkDir) {
|
|
1619
|
+
const file = luauVmFile(sdkDir);
|
|
1620
|
+
if (file === null) return null;
|
|
1621
|
+
const unit = { name: ENGINE_LUAU_UNIT, version: sdkVersion(), specifiers: [] };
|
|
1622
|
+
return built(unit, "wasm", encodeChunk("wasm", readFileSync(file)), [], null);
|
|
1623
|
+
}
|
|
1624
|
+
function audioWorkletFile(sdkDir) {
|
|
1625
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1626
|
+
if (dir === null) return null;
|
|
1627
|
+
const file = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, AUDIO_WORKLET_FILE);
|
|
1628
|
+
return existsSync(file) ? file : null;
|
|
1629
|
+
}
|
|
1630
|
+
function audioWorkletRuntime(sdkDir) {
|
|
1631
|
+
const file = audioWorkletFile(sdkDir);
|
|
1632
|
+
if (file === null) return null;
|
|
1633
|
+
const unit = { name: ENGINE_AUDIO_UNIT, version: sdkVersion(), specifiers: [] };
|
|
1634
|
+
return built(unit, "wasm", encodeChunk("wasm", readFileSync(file)), [], null);
|
|
1635
|
+
}
|
|
1636
|
+
function linkedCoreVariant(sdkDir, variant) {
|
|
1637
|
+
return path4.basename(engineCoreFile(sdkDir, variant)) === variant.file ? variant : FULL_ENGINE_VARIANT;
|
|
1638
|
+
}
|
|
1639
|
+
function threadedCoreFile(sdkDir, variant) {
|
|
1640
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1641
|
+
if (dir === null) return null;
|
|
1642
|
+
const file = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, threadedVariantOf(linkedCoreVariant(sdkDir, variant)).file);
|
|
1643
|
+
return existsSync(file) ? file : null;
|
|
1644
|
+
}
|
|
1645
|
+
function scriptsCoreFile(sdkDir, variant) {
|
|
1646
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1647
|
+
if (dir === null) return null;
|
|
1648
|
+
const widest = isShadersVariant(variant) ? SCRIPTS_SHADERS_ENGINE_VARIANT : SCRIPTS_ENGINE_VARIANT;
|
|
1649
|
+
for (const file of [variant.file, widest.file]) {
|
|
1650
|
+
const candidate = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, file);
|
|
1651
|
+
if (existsSync(candidate)) return candidate;
|
|
1652
|
+
}
|
|
1653
|
+
return null;
|
|
1654
|
+
}
|
|
1655
|
+
function threadedCoreRuntime(core, sdkDir, variant) {
|
|
1656
|
+
const file = threadedCoreFile(sdkDir, variant);
|
|
1657
|
+
if (file === null) return null;
|
|
1658
|
+
const unit = { name: ENGINE_CORE_THREADS, version: core.version, specifiers: [] };
|
|
1659
|
+
return engineWasm(unit, readFileSync(file));
|
|
1660
|
+
}
|
|
1661
|
+
function scriptsCoreRuntime(core, sdkDir, variant) {
|
|
1662
|
+
const file = scriptsCoreFile(sdkDir, variant);
|
|
1663
|
+
if (file === null) return null;
|
|
1664
|
+
const unit = { name: ENGINE_CORE_SCRIPTS_UNIT, version: core.version, specifiers: [] };
|
|
1665
|
+
return engineWasm(unit, readFileSync(file));
|
|
1666
|
+
}
|
|
1667
|
+
function glCoreFile(sdkDir, variant) {
|
|
1668
|
+
const dir = engineRuntimeDir(sdkDir);
|
|
1669
|
+
if (dir === null) return null;
|
|
1670
|
+
const widest = isScriptsVariant(variant) ? isShadersVariant(variant) ? SCRIPTS_SHADERS_ENGINE_VARIANT : SCRIPTS_ENGINE_VARIANT : FULL_ENGINE_VARIANT;
|
|
1671
|
+
for (const candidate of [glVariantOf(variant), glVariantOf(widest)]) {
|
|
1672
|
+
if (candidate === null) continue;
|
|
1673
|
+
const file = path4.join(dir, ENGINE_RUNTIME_WASM_DIR, candidate.file);
|
|
1674
|
+
if (existsSync(file)) return file;
|
|
1675
|
+
}
|
|
1676
|
+
return null;
|
|
1677
|
+
}
|
|
1678
|
+
function glCoreRuntime(core, sdkDir, variant) {
|
|
1679
|
+
const file = glCoreFile(sdkDir, variant);
|
|
1680
|
+
if (file === null) return null;
|
|
1681
|
+
const unit = { name: ENGINE_CORE_GL_UNIT, version: core.version, specifiers: [] };
|
|
1682
|
+
return engineWasm(unit, readFileSync(file));
|
|
1683
|
+
}
|
|
1684
|
+
function engineCoreRuntime(unit, sdkDir, variant) {
|
|
1685
|
+
return engineWasm(unit, readFileSync(engineCoreFile(sdkDir, variant)));
|
|
1686
|
+
}
|
|
1687
|
+
function sdkFile(unit, sdkDir) {
|
|
1688
|
+
const dist = sdkDist(sdkDir);
|
|
1689
|
+
if (unit.name.startsWith(SDK_CHUNK_PREFIX)) {
|
|
1690
|
+
const file = path4.resolve(dist, unit.name.slice(SDK_CHUNK_PREFIX.length));
|
|
1691
|
+
if (path4.relative(dist, file).startsWith("..") || !existsSync(file)) throw new Error(`${unit.name} is not a file of ${SDK_PACKAGE}`);
|
|
1692
|
+
return { file, dist };
|
|
1693
|
+
}
|
|
1694
|
+
const target = pickTarget((exportsMap(readPackageJson(path4.dirname(dist))) ?? {})[`.${unit.name.slice(SDK_PACKAGE.length)}`], BROWSER_CONDITIONS);
|
|
1695
|
+
if (target === null) throw new Error(`${unit.name} has no browser build in ${SDK_PACKAGE}`);
|
|
1696
|
+
return { file: path4.resolve(path4.dirname(dist), target), dist };
|
|
1697
|
+
}
|
|
1698
|
+
function sdkRuntime(unit, sdkDir) {
|
|
1699
|
+
const { file, dist } = sdkFile(unit, sdkDir);
|
|
1700
|
+
const transformed = transformSync(readFileSync(file, "utf8"), {
|
|
1701
|
+
loader: "js",
|
|
1702
|
+
format: "cjs",
|
|
1703
|
+
target: ESBUILD_TARGET,
|
|
1704
|
+
define: { "process.env.NODE_ENV": NODE_ENV, "import.meta.url": JSON.stringify(RUNTIME_IMPORT_META_URL) },
|
|
1705
|
+
legalComments: "none",
|
|
1706
|
+
minifyWhitespace: true,
|
|
1707
|
+
minifySyntax: true,
|
|
1708
|
+
charset: "utf8",
|
|
1709
|
+
sourcefile: path4.relative(dist, file)
|
|
1710
|
+
});
|
|
1711
|
+
const required = /* @__PURE__ */ new Set();
|
|
1712
|
+
const body = transformed.code.replace(REQUIRE_CALL, (_call, quote, specifier) => {
|
|
1713
|
+
const name = RELATIVE_IMPORT.test(specifier) ? SDK_CHUNK_PREFIX + path4.relative(dist, path4.resolve(path4.dirname(file), specifier)).split(path4.sep).join("/") : specifier;
|
|
1714
|
+
required.add(name);
|
|
1715
|
+
return `require(${quote}${name}${quote})`;
|
|
1716
|
+
});
|
|
1717
|
+
const record = JSON.stringify(unit.name);
|
|
1718
|
+
const code = `var __unit={exports:{}};(function(module,exports){${body}
|
|
1719
|
+
})(__unit,__unit.exports);exports.default={${record}:__unit.exports};
|
|
1720
|
+
`;
|
|
1721
|
+
const inlined = Buffer.from(inlineModuleConstants(code, `${unit.name}.runtime.js`).code, "utf8");
|
|
1722
|
+
return built(unit, "code", encodeChunk("code", inlined), requiresOf(inlined.toString("utf8"), unit, required), null);
|
|
1723
|
+
}
|
|
1724
|
+
function usesCanvasCore(bindings) {
|
|
1725
|
+
for (const [specifier, names] of CANVAS_CORE_BINDINGS) {
|
|
1726
|
+
const used = bindings.get(specifier);
|
|
1727
|
+
if (used !== void 0 && (used.has(WHOLE_SPECIFIER) || [...names].some((name) => used.has(name)))) return true;
|
|
1728
|
+
}
|
|
1729
|
+
return false;
|
|
1730
|
+
}
|
|
1731
|
+
function beyond(bindings, base) {
|
|
1732
|
+
const out = /* @__PURE__ */ new Map();
|
|
1733
|
+
for (const [specifier, names] of bindings) {
|
|
1734
|
+
const covered = base.get(specifier);
|
|
1735
|
+
const left = new Set([...names].filter((name) => name === WHOLE_SPECIFIER || covered === void 0 || !covered.has(name)));
|
|
1736
|
+
if (left.size > 0) out.set(specifier, left);
|
|
1737
|
+
}
|
|
1738
|
+
return out;
|
|
1739
|
+
}
|
|
1740
|
+
function canonical(bindings) {
|
|
1741
|
+
return [...bindings.entries()].map(([specifier, names]) => [specifier, [...names].sort(compareStrings)]).sort((a, b) => compareStrings(a[0], b[0]));
|
|
1742
|
+
}
|
|
1743
|
+
function shakenEntry(name, bindings, base, sdkDir) {
|
|
1744
|
+
let imports = base === null ? "" : `import __base from ${JSON.stringify(base.unit)};
|
|
1745
|
+
`;
|
|
1746
|
+
let record = "";
|
|
1747
|
+
canonical(bindings).forEach(([specifier, names], i) => {
|
|
1748
|
+
const file = JSON.stringify(sdkFile(sdkUnit(specifier), sdkDir).file);
|
|
1749
|
+
const inherited = base !== null && base.bindings.has(specifier) ? `...__base[${JSON.stringify(specifier)}],` : "";
|
|
1750
|
+
if (names.includes(WHOLE_SPECIFIER)) {
|
|
1751
|
+
imports += `import * as s${i} from ${file};
|
|
1752
|
+
`;
|
|
1753
|
+
record += `${JSON.stringify(specifier)}: {${inherited}...s${i}},`;
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
imports += `import { ${names.map((name2, k) => `${name2} as s${i}_${k}`).join(", ")} } from ${file};
|
|
1757
|
+
`;
|
|
1758
|
+
record += `${JSON.stringify(specifier)}: {${inherited}${names.map((name2, k) => `${JSON.stringify(name2)}: s${i}_${k}`).join(",")}},`;
|
|
1759
|
+
});
|
|
1760
|
+
if (base !== null) {
|
|
1761
|
+
for (const [specifier] of canonical(base.bindings)) if (!bindings.has(specifier)) record += `${JSON.stringify(specifier)}: __base[${JSON.stringify(specifier)}],`;
|
|
1762
|
+
}
|
|
1763
|
+
return `${imports}const __record = {${record}};
|
|
1764
|
+
__record[${JSON.stringify(name)}] = __record;
|
|
1765
|
+
export default __record;
|
|
1766
|
+
`;
|
|
1767
|
+
}
|
|
1768
|
+
function sdkExternals(base) {
|
|
1769
|
+
const out = base === null ? [] : [base];
|
|
1770
|
+
for (const library of LIBRARY_ALLOWLIST) {
|
|
1771
|
+
if (library.name === SDK_PACKAGE) continue;
|
|
1772
|
+
for (const entry of library.entries) out.push(entry.prefix ? `${entry.specifier}${PREFIX_WILDCARD}` : entry.specifier);
|
|
1773
|
+
}
|
|
1774
|
+
out.push(ENGINE_CORE);
|
|
1775
|
+
return out;
|
|
1776
|
+
}
|
|
1777
|
+
function shakenSdkRuntime(name, bindings, base, sdkDir) {
|
|
1778
|
+
const unit = sdkUnit(name);
|
|
1779
|
+
const dist = sdkDist(sdkDir);
|
|
1780
|
+
const result = buildSync({
|
|
1781
|
+
stdin: { contents: shakenEntry(name, bindings, base, sdkDir), resolveDir: dist, loader: "js", sourcefile: `${name}.runtime.js` },
|
|
1782
|
+
bundle: true,
|
|
1783
|
+
write: false,
|
|
1784
|
+
format: "cjs",
|
|
1785
|
+
platform: "browser",
|
|
1786
|
+
target: ESBUILD_TARGET,
|
|
1787
|
+
conditions: ["browser", "import", "module"],
|
|
1788
|
+
mainFields: ["browser", "module", "main"],
|
|
1789
|
+
external: sdkExternals(base === null ? null : base.unit),
|
|
1790
|
+
define: { "process.env.NODE_ENV": NODE_ENV, "import.meta.url": JSON.stringify(RUNTIME_IMPORT_META_URL) },
|
|
1791
|
+
legalComments: "none",
|
|
1792
|
+
minifyWhitespace: true,
|
|
1793
|
+
minifySyntax: true,
|
|
1794
|
+
minifyIdentifiers: true,
|
|
1795
|
+
charset: "utf8",
|
|
1796
|
+
logLevel: "silent",
|
|
1797
|
+
metafile: true
|
|
1798
|
+
});
|
|
1799
|
+
const found = /* @__PURE__ */ new Set();
|
|
1800
|
+
for (const input of Object.values(result.metafile.inputs)) {
|
|
1801
|
+
for (const imported of input.imports) if (imported.external === true) found.add(imported.path);
|
|
1802
|
+
}
|
|
1803
|
+
const code = Buffer.from(inlineModuleConstants(result.outputFiles[0].text, `${name}.runtime.js`).code, "utf8");
|
|
1804
|
+
return built(unit, "code", encodeChunk("code", code), requiresOf(code.toString("utf8"), unit, found), null);
|
|
1805
|
+
}
|
|
1806
|
+
function sdkGameRuntime(bindings, sdkDir) {
|
|
1807
|
+
const base = usesCanvasCore(bindings) ? { unit: CANVAS_CORE_UNIT, bindings: CANVAS_CORE_BINDINGS } : null;
|
|
1808
|
+
const own = base === null ? new Map(bindings) : beyond(bindings, base.bindings);
|
|
1809
|
+
const key = createHash(SHA256).update(JSON.stringify([sdkVersion(), base?.unit ?? null, canonical(own)])).digest("hex").slice(0, SDK_GAME_NAME_HEX);
|
|
1810
|
+
return shakenSdkRuntime(`${SDK_GAME_UNIT_PREFIX}${key}`, own, base, sdkDir);
|
|
1811
|
+
}
|
|
1812
|
+
function buildRuntime(unit, sdkDir) {
|
|
1813
|
+
if (unit.name === CANVAS_CORE_UNIT) return shakenSdkRuntime(CANVAS_CORE_UNIT, CANVAS_CORE_BINDINGS, null, sdkDir);
|
|
1814
|
+
if (unit.name === ENGINE_CORE) return engineCoreRuntime(unit, sdkDir, FULL_ENGINE_VARIANT);
|
|
1815
|
+
if (isSdkRuntime(unit.name)) return sdkRuntime(unit, sdkDir);
|
|
1816
|
+
const bundled = bundle(unit, sdkDir);
|
|
1817
|
+
return built(unit, "code", encodeChunk("code", bundled.code), requiresOf(bundled.code.toString("utf8"), unit, bundled.externals), null);
|
|
1818
|
+
}
|
|
1819
|
+
var registries = /* @__PURE__ */ new Map();
|
|
1820
|
+
function bundledRuntimes(sdkDir) {
|
|
1821
|
+
const known = registries.get(sdkDir);
|
|
1822
|
+
if (known !== void 0) return known;
|
|
1823
|
+
const cache = /* @__PURE__ */ new Map();
|
|
1824
|
+
const registry = {
|
|
1825
|
+
id: RUNTIME_REGISTRY_ID,
|
|
1826
|
+
unitOf: runtimeUnitOf,
|
|
1827
|
+
runtime(unit) {
|
|
1828
|
+
const key = [unit.name, ...unit.specifiers].join(UNIT_KEY_SEPARATOR);
|
|
1829
|
+
const cached = cache.get(key);
|
|
1830
|
+
if (cached !== void 0) return cached;
|
|
1831
|
+
const runtime = buildRuntime(unit, sdkDir);
|
|
1832
|
+
cache.set(key, runtime);
|
|
1833
|
+
return runtime;
|
|
1834
|
+
},
|
|
1835
|
+
engineCore(unit, variant) {
|
|
1836
|
+
const key = [unit.name, variant.file].join(UNIT_KEY_SEPARATOR);
|
|
1837
|
+
const cached = cache.get(key);
|
|
1838
|
+
if (cached !== void 0) return cached;
|
|
1839
|
+
const runtime = engineCoreRuntime(unit, sdkDir, variant);
|
|
1840
|
+
cache.set(key, runtime);
|
|
1841
|
+
return runtime;
|
|
1842
|
+
},
|
|
1843
|
+
engineCoreThreads(core, variant) {
|
|
1844
|
+
const key = [ENGINE_CORE_THREADS, core.version, variant.file].join(UNIT_KEY_SEPARATOR);
|
|
1845
|
+
const cached = cache.get(key);
|
|
1846
|
+
if (cached !== void 0) return cached;
|
|
1847
|
+
const runtime = threadedCoreRuntime(core, sdkDir, variant);
|
|
1848
|
+
if (runtime !== null) cache.set(key, runtime);
|
|
1849
|
+
return runtime;
|
|
1850
|
+
},
|
|
1851
|
+
engineCoreScripts(core, variant) {
|
|
1852
|
+
const key = [ENGINE_CORE_SCRIPTS_UNIT, core.version, variant.file].join(UNIT_KEY_SEPARATOR);
|
|
1853
|
+
const cached = cache.get(key);
|
|
1854
|
+
if (cached !== void 0) return cached;
|
|
1855
|
+
const runtime = scriptsCoreRuntime(core, sdkDir, variant);
|
|
1856
|
+
if (runtime !== null) cache.set(key, runtime);
|
|
1857
|
+
return runtime;
|
|
1858
|
+
},
|
|
1859
|
+
engineCoreGl(core, variant) {
|
|
1860
|
+
const key = [ENGINE_CORE_GL_UNIT, core.version, variant.file].join(UNIT_KEY_SEPARATOR);
|
|
1861
|
+
const cached = cache.get(key);
|
|
1862
|
+
if (cached !== void 0) return cached;
|
|
1863
|
+
const runtime = glCoreRuntime(core, sdkDir, variant);
|
|
1864
|
+
if (runtime !== null) cache.set(key, runtime);
|
|
1865
|
+
return runtime;
|
|
1866
|
+
},
|
|
1867
|
+
sdkGame(bindings) {
|
|
1868
|
+
const key = JSON.stringify(canonical(bindings));
|
|
1869
|
+
const cached = cache.get(key);
|
|
1870
|
+
if (cached !== void 0) return cached;
|
|
1871
|
+
const runtime = sdkGameRuntime(bindings, sdkDir);
|
|
1872
|
+
cache.set(key, runtime);
|
|
1873
|
+
return runtime;
|
|
1874
|
+
},
|
|
1875
|
+
luauVm() {
|
|
1876
|
+
const cached = cache.get(ENGINE_LUAU_UNIT);
|
|
1877
|
+
if (cached !== void 0) return cached;
|
|
1878
|
+
const runtime = luauVmRuntime(sdkDir);
|
|
1879
|
+
if (runtime !== null) cache.set(ENGINE_LUAU_UNIT, runtime);
|
|
1880
|
+
return runtime;
|
|
1881
|
+
},
|
|
1882
|
+
audioWorklet() {
|
|
1883
|
+
const cached = cache.get(ENGINE_AUDIO_UNIT);
|
|
1884
|
+
if (cached !== void 0) return cached;
|
|
1885
|
+
const runtime = audioWorkletRuntime(sdkDir);
|
|
1886
|
+
if (runtime !== null) cache.set(ENGINE_AUDIO_UNIT, runtime);
|
|
1887
|
+
return runtime;
|
|
1888
|
+
}
|
|
1889
|
+
};
|
|
1890
|
+
registries.set(sdkDir, registry);
|
|
1891
|
+
return registry;
|
|
1892
|
+
}
|
|
1893
|
+
function runtimeClosure(registry, roots) {
|
|
1894
|
+
const reached = /* @__PURE__ */ new Map();
|
|
1895
|
+
const linked = /* @__PURE__ */ new Map();
|
|
1896
|
+
const pending = [...roots];
|
|
1897
|
+
while (pending.length > 0) {
|
|
1898
|
+
const specifier = runtimeExportOf(pending.pop());
|
|
1899
|
+
const unit = registry.unitOf(specifier);
|
|
1900
|
+
if (unit === null) throw new Error(`'${specifier}' has no shared runtime build`);
|
|
1901
|
+
let entry = reached.get(unit.name);
|
|
1902
|
+
if (entry === void 0) {
|
|
1903
|
+
entry = { unit, specifiers: /* @__PURE__ */ new Set() };
|
|
1904
|
+
reached.set(unit.name, entry);
|
|
1905
|
+
}
|
|
1906
|
+
if (entry.specifiers.has(specifier)) continue;
|
|
1907
|
+
entry.specifiers.add(specifier);
|
|
1908
|
+
const runtime = registry.runtime({ ...entry.unit, specifiers: [...entry.specifiers].sort(compareStrings) });
|
|
1909
|
+
linked.set(unit.name, runtime);
|
|
1910
|
+
for (const required of runtime.imports) pending.push(required.export);
|
|
1911
|
+
}
|
|
1912
|
+
return [...linked.values()].sort((a, b) => compareStrings(a.unit.name, b.unit.name));
|
|
1913
|
+
}
|
|
1914
|
+
var TYPESCRIPT_PACKAGE = "typescript";
|
|
1915
|
+
var PROBE_LIB = "lib.es2022.d.ts";
|
|
1916
|
+
var HEAP_HOOKS = ["./game/heap", "./game/conformance"];
|
|
1917
|
+
function builderBase() {
|
|
1918
|
+
try {
|
|
1919
|
+
const here = path4.dirname(fileURLToPath(import.meta.url));
|
|
1920
|
+
return existsSync(here) ? here : null;
|
|
1921
|
+
} catch {
|
|
1922
|
+
return null;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
function at(base, origin) {
|
|
1926
|
+
const ts2 = findPackageDir(base, TYPESCRIPT_PACKAGE);
|
|
1927
|
+
const sdk = findPackageDir(base, SDK_PACKAGE);
|
|
1928
|
+
if (ts2 === null || sdk === null) return null;
|
|
1929
|
+
const lib = path4.join(ts2, "lib");
|
|
1930
|
+
if (!existsSync(path4.join(lib, PROBE_LIB))) return null;
|
|
1931
|
+
return {
|
|
1932
|
+
origin,
|
|
1933
|
+
base,
|
|
1934
|
+
typescriptLib: lib,
|
|
1935
|
+
typescriptVersion: readPackageJson(ts2).version ?? "unknown",
|
|
1936
|
+
sdkDir: sdk,
|
|
1937
|
+
sdkVersion: readPackageJson(sdk).version ?? "unknown"
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
var located = /* @__PURE__ */ new Map();
|
|
1941
|
+
function locateToolchain(projectRoot) {
|
|
1942
|
+
const key = projectRoot ?? "";
|
|
1943
|
+
if (located.has(key)) return located.get(key) ?? null;
|
|
1944
|
+
const builder = builderBase();
|
|
1945
|
+
const found = (builder !== null ? at(builder, "builder") : null) ?? (projectRoot !== null ? at(projectRoot, "project") : null);
|
|
1946
|
+
located.set(key, found);
|
|
1947
|
+
return found;
|
|
1948
|
+
}
|
|
1949
|
+
function toolchainDiagnostics(toolchain) {
|
|
1950
|
+
if (toolchain === null) {
|
|
1951
|
+
return [diagnostic("toolchain.missing", `the pinned TypeScript ${PINNED_TYPESCRIPT_VERSION} and ${SDK_PACKAGE} ${PINNED_SDK_VERSION} are not installed where the builder can read them; run bun install in the project`, null, null)];
|
|
1952
|
+
}
|
|
1953
|
+
const out = [];
|
|
1954
|
+
if (toolchain.typescriptVersion !== PINNED_TYPESCRIPT_VERSION) {
|
|
1955
|
+
out.push(diagnostic("toolchain.version", `type checking found TypeScript ${toolchain.typescriptVersion}; the pinned toolchain is ${PINNED_TYPESCRIPT_VERSION}`, null, null));
|
|
1956
|
+
}
|
|
1957
|
+
if (toolchain.sdkVersion !== PINNED_SDK_VERSION) {
|
|
1958
|
+
out.push(diagnostic("toolchain.version", `type checking found ${SDK_PACKAGE} ${toolchain.sdkVersion}; the pinned SDK is ${PINNED_SDK_VERSION}`, null, null));
|
|
1959
|
+
}
|
|
1960
|
+
return out;
|
|
1961
|
+
}
|
|
1962
|
+
function runtimeImportMap(toolchain) {
|
|
1963
|
+
const map = {};
|
|
1964
|
+
for (const library of LIBRARY_ALLOWLIST) {
|
|
1965
|
+
const dir = findPackageDir(toolchain.base, library.name);
|
|
1966
|
+
if (dir === null) continue;
|
|
1967
|
+
const exports = exportsMap(readPackageJson(dir));
|
|
1968
|
+
for (const entry of library.entries) {
|
|
1969
|
+
const subpath = `.${entry.specifier.slice(library.name.length)}`;
|
|
1970
|
+
if (entry.prefix) {
|
|
1971
|
+
const target = pickTarget(exports?.[`${subpath}*`], NODE_CONDITIONS);
|
|
1972
|
+
if (target !== null && target.endsWith("*")) map[entry.specifier] = pathToFileURL(path4.resolve(dir, target.slice(0, -1))).href + "/";
|
|
1973
|
+
continue;
|
|
1974
|
+
}
|
|
1975
|
+
const file = resolveExport(dir, subpath, NODE_CONDITIONS);
|
|
1976
|
+
if (file !== null) map[entry.specifier] = pathToFileURL(file).href;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
return map;
|
|
1980
|
+
}
|
|
1981
|
+
function heapHooksUrl(toolchain) {
|
|
1982
|
+
for (const subpath of HEAP_HOOKS) {
|
|
1983
|
+
const file = resolveExport(toolchain.sdkDir, subpath, NODE_CONDITIONS);
|
|
1984
|
+
if (file !== null) return pathToFileURL(file).href;
|
|
1985
|
+
}
|
|
1986
|
+
return null;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
export { BROWSER_CONDITIONS, ENGINE_CORE, ENGINE_CORE_THREADS, NODE_CONDITIONS, WHOLE_SPECIFIER, bundledRuntimes, cachedEngineRuntimeDir, cachedVersion, canonicalBytes, engineCacheRoot, engineCoreFile, exportTarget, exportsMap, findPackageDir, heapHooksUrl, isSdkRuntime, localEngineRuntimeDir, locateToolchain, pickTarget, readPackageJson, resolveExport, runtimeClosure, runtimeExportOf, runtimeImportMap, storeRuntime, stripDotSlash, textDictionariesFile, toolchainDiagnostics, validManifest };
|