@scenoco-three/editor 0.6.0 → 0.7.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.
Files changed (76) hide show
  1. package/README.md +31 -44
  2. package/bin/serve.js +37 -0
  3. package/dist/editor.js +12521 -0
  4. package/package.json +26 -34
  5. package/dist/cli/index.d.ts +0 -2
  6. package/dist/cli/index.js +0 -56
  7. package/dist-app/assets/EffectComposer-lekj9UUq.js +0 -1
  8. package/dist-app/assets/GLTFLoader-C2lUhzim.js +0 -1
  9. package/dist-app/assets/OutputPass-DZtd342R.js +0 -72
  10. package/dist-app/assets/Pass-BP3b3hlf.js +0 -1
  11. package/dist-app/assets/RenderPass-BjVchlYg.js +0 -1
  12. package/dist-app/assets/ShaderPass-DMXLcV9X.js +0 -24
  13. package/dist-app/assets/SkeletonUtils-Cxy_owx9.js +0 -1
  14. package/dist-app/assets/index-AxOpglZ-.css +0 -1
  15. package/dist-app/assets/index-D-Iq7tix.js +0 -4135
  16. package/dist-app/assets/inter-CaiW00F8.js +0 -1
  17. package/dist-app/assets/registry-BOM35tSr.js +0 -1433
  18. package/dist-app/assets/worker-_Lh8Vt-i.js +0 -1270
  19. package/dist-app/examples/breakout/assets/geometry/ball.geometry.xml +0 -1
  20. package/dist-app/examples/breakout/assets/geometry/brick.geometry.xml +0 -1
  21. package/dist-app/examples/breakout/assets/geometry/floor-sensor.geometry.xml +0 -1
  22. package/dist-app/examples/breakout/assets/geometry/paddle.geometry.xml +0 -1
  23. package/dist-app/examples/breakout/assets/geometry/wall-side.geometry.xml +0 -1
  24. package/dist-app/examples/breakout/assets/geometry/wall-top.geometry.xml +0 -1
  25. package/dist-app/examples/breakout/assets/materials/ball.material.xml +0 -1
  26. package/dist-app/examples/breakout/assets/materials/brick-firm.material.xml +0 -1
  27. package/dist-app/examples/breakout/assets/materials/brick-hard.material.xml +0 -1
  28. package/dist-app/examples/breakout/assets/materials/brick-soft.material.xml +0 -1
  29. package/dist-app/examples/breakout/assets/materials/paddle.material.xml +0 -10
  30. package/dist-app/examples/breakout/assets/materials/wall.material.xml +0 -1
  31. package/dist-app/examples/breakout/assets/render/neon.render.xml +0 -14
  32. package/dist-app/examples/breakout/assets/scenes/arena.prefab.xml +0 -68
  33. package/dist-app/examples/breakout/assets/scenes/brick.prefab.xml +0 -15
  34. package/dist-app/examples/breakout/assets/scenes/hud.scene.xml +0 -56
  35. package/dist-app/examples/breakout/assets/scenes/level-1.scene.xml +0 -36
  36. package/dist-app/examples/breakout/assets/scenes/level-2.scene.xml +0 -36
  37. package/dist-app/examples/breakout/assets/scenes/level-3.scene.xml +0 -36
  38. package/dist-app/examples/castle/assets/geometry/capsule.geometry.xml +0 -3
  39. package/dist-app/examples/castle/assets/geometry/cone.geometry.xml +0 -2
  40. package/dist-app/examples/castle/assets/geometry/cube.geometry.xml +0 -3
  41. package/dist-app/examples/castle/assets/geometry/cylinder.geometry.xml +0 -3
  42. package/dist-app/examples/castle/assets/geometry/plane.geometry.xml +0 -4
  43. package/dist-app/examples/castle/assets/geometry/quad.geometry.xml +0 -3
  44. package/dist-app/examples/castle/assets/geometry/sphere.geometry.xml +0 -2
  45. package/dist-app/examples/castle/assets/materials/grass.material.xml +0 -1
  46. package/dist-app/examples/castle/assets/materials/roof.material.xml +0 -1
  47. package/dist-app/examples/castle/assets/materials/stone.material.xml +0 -1
  48. package/dist-app/examples/castle/assets/materials/wood.material.xml +0 -1
  49. package/dist-app/examples/castle/assets/scenes/main.scene.xml +0 -25
  50. package/dist-app/examples/collector/assets/geometry/capsule.geometry.xml +0 -3
  51. package/dist-app/examples/collector/assets/geometry/cone.geometry.xml +0 -2
  52. package/dist-app/examples/collector/assets/geometry/cube.geometry.xml +0 -3
  53. package/dist-app/examples/collector/assets/geometry/cylinder.geometry.xml +0 -3
  54. package/dist-app/examples/collector/assets/geometry/plane.geometry.xml +0 -4
  55. package/dist-app/examples/collector/assets/geometry/quad.geometry.xml +0 -3
  56. package/dist-app/examples/collector/assets/geometry/sphere.geometry.xml +0 -2
  57. package/dist-app/examples/collector/assets/materials/crate.material.xml +0 -1
  58. package/dist-app/examples/collector/assets/materials/depot.material.xml +0 -1
  59. package/dist-app/examples/collector/assets/materials/ground.material.xml +0 -1
  60. package/dist-app/examples/collector/assets/materials/player.material.xml +0 -1
  61. package/dist-app/examples/collector/assets/scenes/crate.prefab.xml +0 -9
  62. package/dist-app/examples/collector/assets/scenes/main.scene.xml +0 -83
  63. package/dist-app/examples/playable/assets/geometry/capsule.geometry.xml +0 -3
  64. package/dist-app/examples/playable/assets/geometry/cone.geometry.xml +0 -2
  65. package/dist-app/examples/playable/assets/geometry/cube.geometry.xml +0 -3
  66. package/dist-app/examples/playable/assets/geometry/cylinder.geometry.xml +0 -3
  67. package/dist-app/examples/playable/assets/geometry/plane.geometry.xml +0 -4
  68. package/dist-app/examples/playable/assets/geometry/quad.geometry.xml +0 -3
  69. package/dist-app/examples/playable/assets/geometry/sphere.geometry.xml +0 -2
  70. package/dist-app/examples/playable/assets/materials/ground.material.xml +0 -1
  71. package/dist-app/examples/playable/assets/materials/target.material.xml +0 -2
  72. package/dist-app/examples/playable/assets/scenes/main.scene.xml +0 -53
  73. package/dist-app/examples/playable/assets/scenes/target.prefab.xml +0 -9
  74. package/dist-app/examples.json +0 -68
  75. package/dist-app/index.html +0 -14
  76. package/dist-app/model.json +0 -1
@@ -1,1270 +0,0 @@
1
- // src/worker.ts
2
- import { expose, transfer } from "comlink";
3
-
4
- // src/wasm/msdfgen_wasm.js
5
- var createMSDFGenModule = (() => {
6
- var _scriptName = import.meta.url;
7
- return (function(moduleArg = {}) {
8
- var moduleRtn;
9
- var m = moduleArg, aa, p, ba = new Promise((a, b) => {
10
- aa = a;
11
- p = b;
12
- }), ca = Object.assign({}, m), r = "", da;
13
- "undefined" != typeof document && document.currentScript && (r = document.currentScript.src);
14
- _scriptName && (r = _scriptName);
15
- r.startsWith("blob:") ? r = "" : r = r.substr(0, r.replace(/[?#].*/, "").lastIndexOf("/") + 1);
16
- da = async (a) => {
17
- a = await fetch(a, { credentials: "same-origin" });
18
- if (a.ok) return a.arrayBuffer();
19
- throw Error(a.status + " : " + a.url);
20
- };
21
- var ea = m.print || console.log.bind(console), w = m.printErr || console.error.bind(console);
22
- Object.assign(m, ca);
23
- ca = null;
24
- var x = m.wasmBinary, A, B = false, fa, ha, C, D, E, G, H, ia, ja;
25
- function ka() {
26
- var a = A.buffer;
27
- m.HEAP8 = ha = new Int8Array(a);
28
- m.HEAP16 = D = new Int16Array(a);
29
- m.HEAPU8 = C = new Uint8Array(a);
30
- m.HEAPU16 = E = new Uint16Array(a);
31
- m.HEAP32 = G = new Int32Array(a);
32
- m.HEAPU32 = H = new Uint32Array(a);
33
- m.HEAPF32 = ia = new Float32Array(a);
34
- m.HEAPF64 = ja = new Float64Array(a);
35
- }
36
- var la = [], ma = [], na = [];
37
- function oa() {
38
- var a = m.preRun.shift();
39
- la.unshift(a);
40
- }
41
- var I = 0, J = null;
42
- function pa(a) {
43
- m.onAbort?.(a);
44
- a = "Aborted(" + a + ")";
45
- w(a);
46
- B = true;
47
- a = new WebAssembly.RuntimeError(a + ". Build with -sASSERTIONS for more info.");
48
- p(a);
49
- throw a;
50
- }
51
- var qa = (a) => a.startsWith("data:application/octet-stream;base64,"), ra;
52
- async function sa(a) {
53
- if (!x) try {
54
- var b = await da(a);
55
- return new Uint8Array(b);
56
- } catch {
57
- }
58
- if (a == ra && x) a = new Uint8Array(x);
59
- else throw "both async and sync fetching of the wasm failed";
60
- return a;
61
- }
62
- async function ta(a, b) {
63
- try {
64
- var c = await sa(a);
65
- return await WebAssembly.instantiate(c, b);
66
- } catch (d) {
67
- w(`failed to asynchronously prepare wasm: ${d}`), pa(d);
68
- }
69
- }
70
- async function ua(a) {
71
- var b = ra;
72
- if (!x && "function" == typeof WebAssembly.instantiateStreaming && !qa(b) && "function" == typeof fetch) try {
73
- var c = fetch(b, { credentials: "same-origin" });
74
- return await WebAssembly.instantiateStreaming(c, a);
75
- } catch (d) {
76
- w(`wasm streaming compile failed: ${d}`), w("falling back to ArrayBuffer instantiation");
77
- }
78
- return ta(b, a);
79
- }
80
- class va {
81
- name = "ExitStatus";
82
- constructor(a) {
83
- this.message = `Program terminated with exit(${a})`;
84
- this.status = a;
85
- }
86
- }
87
- var wa = (a) => {
88
- for (; 0 < a.length; ) a.shift()(m);
89
- }, ya = m.noExitRuntime || true;
90
- class za {
91
- constructor(a) {
92
- this.K = a - 24;
93
- }
94
- }
95
- var Aa = 0, Ba = 0, Ca = {}, Da = (a) => {
96
- for (; a.length; ) {
97
- var b = a.pop();
98
- a.pop()(b);
99
- }
100
- };
101
- function K(a) {
102
- return this.fromWireType(H[a >> 2]);
103
- }
104
- var L = {}, M = {}, Ea = {}, N, P = (a, b, c) => {
105
- function d(g) {
106
- g = c(g);
107
- if (g.length !== a.length) throw new N("Mismatched type converter count");
108
- for (var l = 0; l < a.length; ++l) O(a[l], g[l]);
109
- }
110
- a.forEach((g) => Ea[g] = b);
111
- var e = Array(b.length), f = [], h = 0;
112
- b.forEach((g, l) => {
113
- M.hasOwnProperty(g) ? e[l] = M[g] : (f.push(g), L.hasOwnProperty(g) || (L[g] = []), L[g].push(() => {
114
- e[l] = M[g];
115
- ++h;
116
- h === f.length && d(e);
117
- }));
118
- });
119
- 0 === f.length && d(e);
120
- }, Fa, Q = (a) => {
121
- for (var b = ""; C[a]; ) b += Fa[C[a++]];
122
- return b;
123
- }, R, Ga = (a) => {
124
- throw new R(a);
125
- };
126
- function Ha(a, b, c = {}) {
127
- var d = b.name;
128
- if (!a) throw new R(`type "${d}" must have a positive integer typeid pointer`);
129
- if (M.hasOwnProperty(a)) {
130
- if (c.pa) return;
131
- throw new R(`Cannot register type '${d}' twice`);
132
- }
133
- M[a] = b;
134
- delete Ea[a];
135
- L.hasOwnProperty(a) && (b = L[a], delete L[a], b.forEach((e) => e()));
136
- }
137
- function O(a, b, c = {}) {
138
- return Ha(a, b, c);
139
- }
140
- var Ia = (a) => {
141
- throw new R(a.I.L.J.name + " instance already deleted");
142
- }, Ja = false, Ka = () => {
143
- }, La = (a, b, c) => {
144
- if (b === c) return a;
145
- if (void 0 === c.N) return null;
146
- a = La(a, b, c.N);
147
- return null === a ? null : c.ia(a);
148
- }, Ma = {}, Na = {}, Oa = (a, b) => {
149
- if (void 0 === b) throw new R("ptr should not be undefined");
150
- for (; a.N; ) b = a.Z(b), a = a.N;
151
- return Na[b];
152
- }, Pa = (a, b) => {
153
- if (!b.L || !b.K) throw new N("makeClassHandle requires ptr and ptrType");
154
- if (!!b.O !== !!b.M) throw new N("Both smartPtrType and smartPtr must be specified");
155
- b.count = { value: 1 };
156
- return S(Object.create(
157
- a,
158
- { I: { value: b, writable: true } }
159
- ));
160
- }, S = (a) => {
161
- if ("undefined" === typeof FinalizationRegistry) return S = (b) => b, a;
162
- Ja = new FinalizationRegistry((b) => {
163
- b = b.I;
164
- --b.count.value;
165
- 0 === b.count.value && (b.M ? b.O.R(b.M) : b.L.J.R(b.K));
166
- });
167
- S = (b) => {
168
- var c = b.I;
169
- c.M && Ja.register(b, { I: c }, b);
170
- return b;
171
- };
172
- Ka = (b) => {
173
- Ja.unregister(b);
174
- };
175
- return S(a);
176
- }, Qa = [];
177
- function Ra() {
178
- }
179
- var Sa = (a, b) => Object.defineProperty(b, "name", { value: a }), Ta = (a, b, c) => {
180
- if (void 0 === a[b].T) {
181
- var d = a[b];
182
- a[b] = function(...e) {
183
- if (!a[b].T.hasOwnProperty(e.length)) throw new R(`Function '${c}' called with an invalid number of arguments (${e.length}) - expects one of (${a[b].T})!`);
184
- return a[b].T[e.length].apply(this, e);
185
- };
186
- a[b].T = [];
187
- a[b].T[d.W] = d;
188
- }
189
- }, Ua = (a, b) => {
190
- if (m.hasOwnProperty(a)) throw new R(`Cannot register public name '${a}' twice`);
191
- m[a] = b;
192
- m[a].W = void 0;
193
- }, Va = (a) => {
194
- a = a.replace(/[^a-zA-Z0-9_]/g, "$");
195
- var b = a.charCodeAt(0);
196
- return 48 <= b && 57 >= b ? `_${a}` : a;
197
- };
198
- function Wa(a, b, c, d, e, f, h, g) {
199
- this.name = a;
200
- this.constructor = b;
201
- this.V = c;
202
- this.R = d;
203
- this.N = e;
204
- this.ka = f;
205
- this.Z = h;
206
- this.ia = g;
207
- this.ra = [];
208
- }
209
- var Xa = (a, b, c) => {
210
- for (; b !== c; ) {
211
- if (!b.Z) throw new R(`Expected null or instance of ${c.name}, got an instance of ${b.name}`);
212
- a = b.Z(a);
213
- b = b.N;
214
- }
215
- return a;
216
- };
217
- function Ya(a, b) {
218
- if (null === b) {
219
- if (this.ba) throw new R(`null is not a valid ${this.name}`);
220
- return 0;
221
- }
222
- if (!b.I) throw new R(`Cannot pass "${Za(b)}" as a ${this.name}`);
223
- if (!b.I.K) throw new R(`Cannot pass deleted object as a pointer of type ${this.name}`);
224
- return Xa(b.I.K, b.I.L.J, this.J);
225
- }
226
- function $a(a, b) {
227
- if (null === b) {
228
- if (this.ba) throw new R(`null is not a valid ${this.name}`);
229
- if (this.aa) {
230
- var c = this.ca();
231
- null !== a && a.push(this.R, c);
232
- return c;
233
- }
234
- return 0;
235
- }
236
- if (!b || !b.I) throw new R(`Cannot pass "${Za(b)}" as a ${this.name}`);
237
- if (!b.I.K) throw new R(`Cannot pass deleted object as a pointer of type ${this.name}`);
238
- if (!this.$ && b.I.L.$) throw new R(`Cannot convert argument of type ${b.I.O ? b.I.O.name : b.I.L.name} to parameter type ${this.name}`);
239
- c = Xa(b.I.K, b.I.L.J, this.J);
240
- if (this.aa) {
241
- if (void 0 === b.I.M) throw new R("Passing raw pointer to smart pointer is illegal");
242
- switch (this.wa) {
243
- case 0:
244
- if (b.I.O === this) c = b.I.M;
245
- else throw new R(`Cannot convert argument of type ${b.I.O ? b.I.O.name : b.I.L.name} to parameter type ${this.name}`);
246
- break;
247
- case 1:
248
- c = b.I.M;
249
- break;
250
- case 2:
251
- if (b.I.O === this) c = b.I.M;
252
- else {
253
- var d = b.clone();
254
- c = this.sa(c, ab(() => d["delete"]()));
255
- null !== a && a.push(this.R, c);
256
- }
257
- break;
258
- default:
259
- throw new R("Unsupporting sharing policy");
260
- }
261
- }
262
- return c;
263
- }
264
- function bb(a, b) {
265
- if (null === b) {
266
- if (this.ba) throw new R(`null is not a valid ${this.name}`);
267
- return 0;
268
- }
269
- if (!b.I) throw new R(`Cannot pass "${Za(b)}" as a ${this.name}`);
270
- if (!b.I.K) throw new R(`Cannot pass deleted object as a pointer of type ${this.name}`);
271
- if (b.I.L.$) throw new R(`Cannot convert argument of type ${b.I.L.name} to parameter type ${this.name}`);
272
- return Xa(b.I.K, b.I.L.J, this.J);
273
- }
274
- function cb(a, b, c, d, e, f, h, g, l, k, n) {
275
- this.name = a;
276
- this.J = b;
277
- this.ba = c;
278
- this.$ = d;
279
- this.aa = e;
280
- this.qa = f;
281
- this.wa = h;
282
- this.ga = g;
283
- this.ca = l;
284
- this.sa = k;
285
- this.R = n;
286
- e || void 0 !== b.N ? this.toWireType = $a : (this.toWireType = d ? Ya : bb, this.P = null);
287
- }
288
- var eb = (a, b) => {
289
- if (!m.hasOwnProperty(a)) throw new N("Replacing nonexistent public symbol");
290
- m[a] = b;
291
- m[a].W = void 0;
292
- }, fb, gb = (a, b, c = []) => {
293
- a.includes("j") ? (a = a.replace(/p/g, "i"), b = (0, m["dynCall_" + a])(b, ...c)) : b = fb.get(b)(...c);
294
- return b;
295
- }, hb = (a, b) => (...c) => gb(a, b, c), V = (a, b) => {
296
- a = Q(a);
297
- var c = a.includes("j") ? hb(a, b) : fb.get(b);
298
- if ("function" != typeof c) throw new R(`unknown function pointer with signature ${a}: ${b}`);
299
- return c;
300
- }, ib, kb = (a) => {
301
- a = jb(a);
302
- var b = Q(a);
303
- W(a);
304
- return b;
305
- }, lb = (a, b) => {
306
- function c(f) {
307
- e[f] || M[f] || (Ea[f] ? Ea[f].forEach(c) : (d.push(f), e[f] = true));
308
- }
309
- var d = [], e = {};
310
- b.forEach(c);
311
- throw new ib(`${a}: ` + d.map(kb).join([", "]));
312
- }, mb = (a, b) => {
313
- for (var c = [], d = 0; d < a; d++) c.push(H[b + 4 * d >> 2]);
314
- return c;
315
- };
316
- function nb(a) {
317
- for (var b = 1; b < a.length; ++b) if (null !== a[b] && void 0 === a[b].P) return true;
318
- return false;
319
- }
320
- function ob(a) {
321
- var b = Function;
322
- if (!(b instanceof Function)) throw new TypeError(`new_ called with constructor type ${typeof b} which is not a function`);
323
- var c = Sa(b.name || "unknownFunctionName", function() {
324
- });
325
- c.prototype = b.prototype;
326
- c = new c();
327
- a = b.apply(c, a);
328
- return a instanceof Object ? a : c;
329
- }
330
- function pb(a, b, c, d, e, f) {
331
- var h = b.length;
332
- if (2 > h) throw new R("argTypes array size mismatch! Must at least get return value and 'this' types!");
333
- var g = null !== b[1] && null !== c, l = nb(b);
334
- c = "void" !== b[0].name;
335
- d = [a, Ga, d, e, Da, b[0], b[1]];
336
- for (e = 0; e < h - 2; ++e) d.push(b[e + 2]);
337
- if (!l) for (e = g ? 1 : 2; e < b.length; ++e) null !== b[e].P && d.push(b[e].P);
338
- l = nb(b);
339
- e = b.length - 2;
340
- var k = [], n = ["fn"];
341
- g && n.push("thisWired");
342
- for (h = 0; h < e; ++h) k.push(`arg${h}`), n.push(`arg${h}Wired`);
343
- k = k.join(",");
344
- n = n.join(",");
345
- k = `return function (${k}) {
346
- `;
347
- l && (k += "var destructors = [];\n");
348
- var q = l ? "destructors" : "null", t = "humanName throwBindingError invoker fn runDestructors retType classParam".split(" ");
349
- g && (k += `var thisWired = classParam['toWireType'](${q}, this);
350
- `);
351
- for (h = 0; h < e; ++h) k += `var arg${h}Wired = argType${h}['toWireType'](${q}, arg${h});
352
- `, t.push(`argType${h}`);
353
- k += (c || f ? "var rv = " : "") + `invoker(${n});
354
- `;
355
- if (l) k += "runDestructors(destructors);\n";
356
- else for (h = g ? 1 : 2; h < b.length; ++h) f = 1 === h ? "thisWired" : "arg" + (h - 2) + "Wired", null !== b[h].P && (k += `${f}_dtor(${f});
357
- `, t.push(`${f}_dtor`));
358
- c && (k += "var ret = retType['fromWireType'](rv);\nreturn ret;\n");
359
- let [v, u] = [t, k + "}\n"];
360
- v.push(u);
361
- b = ob(v)(...d);
362
- return Sa(a, b);
363
- }
364
- var qb = (a) => {
365
- a = a.trim();
366
- const b = a.indexOf("(");
367
- return -1 !== b ? a.substr(0, b) : a;
368
- }, rb = [], X = [], ab = (a) => {
369
- switch (a) {
370
- case void 0:
371
- return 2;
372
- case null:
373
- return 4;
374
- case true:
375
- return 6;
376
- case false:
377
- return 8;
378
- default:
379
- const b = rb.pop() || X.length;
380
- X[b] = a;
381
- X[b + 1] = 1;
382
- return b;
383
- }
384
- }, sb = { name: "emscripten::val", fromWireType: (a) => {
385
- if (!a) throw new R("Cannot use deleted val. handle = " + a);
386
- var b = X[a];
387
- 9 < a && 0 === --X[a + 1] && (X[a] = void 0, rb.push(a));
388
- return b;
389
- }, toWireType: (a, b) => ab(b), S: 8, readValueFromPointer: K, P: null }, Za = (a) => {
390
- if (null === a) return "null";
391
- var b = typeof a;
392
- return "object" === b || "array" === b || "function" === b ? a.toString() : "" + a;
393
- }, tb = (a, b) => {
394
- switch (b) {
395
- case 4:
396
- return function(c) {
397
- return this.fromWireType(ia[c >> 2]);
398
- };
399
- case 8:
400
- return function(c) {
401
- return this.fromWireType(ja[c >> 3]);
402
- };
403
- default:
404
- throw new TypeError(`invalid float width (${b}): ${a}`);
405
- }
406
- }, ub = (a, b, c) => {
407
- switch (b) {
408
- case 1:
409
- return c ? (d) => ha[d] : (d) => C[d];
410
- case 2:
411
- return c ? (d) => D[d >> 1] : (d) => E[d >> 1];
412
- case 4:
413
- return c ? (d) => G[d >> 2] : (d) => H[d >> 2];
414
- default:
415
- throw new TypeError(`invalid integer width (${b}): ${a}`);
416
- }
417
- }, vb = Object.assign(
418
- { optional: true },
419
- sb
420
- ), wb = "undefined" != typeof TextDecoder ? new TextDecoder() : void 0, xb = (a, b = 0, c = NaN) => {
421
- var d = b + c;
422
- for (c = b; a[c] && !(c >= d); ) ++c;
423
- if (16 < c - b && a.buffer && wb) return wb.decode(a.subarray(b, c));
424
- for (d = ""; b < c; ) {
425
- var e = a[b++];
426
- if (e & 128) {
427
- var f = a[b++] & 63;
428
- if (192 == (e & 224)) d += String.fromCharCode((e & 31) << 6 | f);
429
- else {
430
- var h = a[b++] & 63;
431
- e = 224 == (e & 240) ? (e & 15) << 12 | f << 6 | h : (e & 7) << 18 | f << 12 | h << 6 | a[b++] & 63;
432
- 65536 > e ? d += String.fromCharCode(e) : (e -= 65536, d += String.fromCharCode(55296 | e >> 10, 56320 | e & 1023));
433
- }
434
- } else d += String.fromCharCode(e);
435
- }
436
- return d;
437
- }, yb = "undefined" != typeof TextDecoder ? new TextDecoder("utf-16le") : void 0, zb = (a, b) => {
438
- var c = a >> 1;
439
- for (var d = c + b / 2; !(c >= d) && E[c]; ) ++c;
440
- c <<= 1;
441
- if (32 < c - a && yb) return yb.decode(C.subarray(a, c));
442
- c = "";
443
- for (d = 0; !(d >= b / 2); ++d) {
444
- var e = D[a + 2 * d >> 1];
445
- if (0 == e) break;
446
- c += String.fromCharCode(e);
447
- }
448
- return c;
449
- }, Ab = (a, b, c) => {
450
- c ??= 2147483647;
451
- if (2 > c) return 0;
452
- c -= 2;
453
- var d = b;
454
- c = c < 2 * a.length ? c / 2 : a.length;
455
- for (var e = 0; e < c; ++e) D[b >> 1] = a.charCodeAt(e), b += 2;
456
- D[b >> 1] = 0;
457
- return b - d;
458
- }, Bb = (a) => 2 * a.length, Cb = (a, b) => {
459
- for (var c = 0, d = ""; !(c >= b / 4); ) {
460
- var e = G[a + 4 * c >> 2];
461
- if (0 == e) break;
462
- ++c;
463
- 65536 <= e ? (e -= 65536, d += String.fromCharCode(55296 | e >> 10, 56320 | e & 1023)) : d += String.fromCharCode(e);
464
- }
465
- return d;
466
- }, Db = (a, b, c) => {
467
- c ??= 2147483647;
468
- if (4 > c) return 0;
469
- var d = b;
470
- c = d + c - 4;
471
- for (var e = 0; e < a.length; ++e) {
472
- var f = a.charCodeAt(e);
473
- if (55296 <= f && 57343 >= f) {
474
- var h = a.charCodeAt(++e);
475
- f = 65536 + ((f & 1023) << 10) | h & 1023;
476
- }
477
- G[b >> 2] = f;
478
- b += 4;
479
- if (b + 4 > c) break;
480
- }
481
- G[b >> 2] = 0;
482
- return b - d;
483
- }, Eb = (a) => {
484
- for (var b = 0, c = 0; c < a.length; ++c) {
485
- var d = a.charCodeAt(c);
486
- 55296 <= d && 57343 >= d && ++c;
487
- b += 4;
488
- }
489
- return b;
490
- }, Fb = 0, Y = {}, Gb = (a) => {
491
- if (!(a instanceof va || "unwind" == a)) throw a;
492
- }, Hb = (a) => {
493
- fa = a;
494
- ya || 0 < Fb || (m.onExit?.(a), B = true);
495
- throw new va(a);
496
- }, Ib = (a) => {
497
- if (!B) try {
498
- if (a(), !(ya || 0 < Fb)) try {
499
- fa = a = fa, Hb(a);
500
- } catch (b) {
501
- Gb(b);
502
- }
503
- } catch (b) {
504
- Gb(b);
505
- }
506
- }, Jb = [null, [], []];
507
- N = m.InternalError = class extends Error {
508
- constructor(a) {
509
- super(a);
510
- this.name = "InternalError";
511
- }
512
- };
513
- for (var Kb = Array(256), Lb = 0; 256 > Lb; ++Lb) Kb[Lb] = String.fromCharCode(Lb);
514
- Fa = Kb;
515
- R = m.BindingError = class extends Error {
516
- constructor(a) {
517
- super(a);
518
- this.name = "BindingError";
519
- }
520
- };
521
- Object.assign(Ra.prototype, { isAliasOf: function(a) {
522
- if (!(this instanceof Ra && a instanceof Ra)) return false;
523
- var b = this.I.L.J, c = this.I.K;
524
- a.I = a.I;
525
- var d = a.I.L.J;
526
- for (a = a.I.K; b.N; ) c = b.Z(c), b = b.N;
527
- for (; d.N; ) a = d.Z(a), d = d.N;
528
- return b === d && c === a;
529
- }, clone: function() {
530
- this.I.K || Ia(this);
531
- if (this.I.Y) return this.I.count.value += 1, this;
532
- var a = S, b = Object, c = b.create, d = Object.getPrototypeOf(this), e = this.I;
533
- a = a(c.call(b, d, { I: { value: { count: e.count, X: e.X, Y: e.Y, K: e.K, L: e.L, M: e.M, O: e.O } } }));
534
- a.I.count.value += 1;
535
- a.I.X = false;
536
- return a;
537
- }, ["delete"]() {
538
- this.I.K || Ia(this);
539
- if (this.I.X && !this.I.Y) throw new R("Object already scheduled for deletion");
540
- Ka(this);
541
- var a = this.I;
542
- --a.count.value;
543
- 0 === a.count.value && (a.M ? a.O.R(a.M) : a.L.J.R(a.K));
544
- this.I.Y || (this.I.M = void 0, this.I.K = void 0);
545
- }, isDeleted: function() {
546
- return !this.I.K;
547
- }, deleteLater: function() {
548
- this.I.K || Ia(this);
549
- if (this.I.X && !this.I.Y) throw new R("Object already scheduled for deletion");
550
- Qa.push(this);
551
- this.I.X = true;
552
- return this;
553
- } });
554
- Object.assign(cb.prototype, { la(a) {
555
- this.ga && (a = this.ga(a));
556
- return a;
557
- }, ea(a) {
558
- this.R?.(a);
559
- }, S: 8, readValueFromPointer: K, fromWireType: function(a) {
560
- function b() {
561
- return this.aa ? Pa(this.J.V, { L: this.qa, K: c, O: this, M: a }) : Pa(this.J.V, { L: this, K: a });
562
- }
563
- var c = this.la(a);
564
- if (!c) return this.ea(a), null;
565
- var d = Oa(this.J, c);
566
- if (void 0 !== d) {
567
- if (0 === d.I.count.value) return d.I.K = c, d.I.M = a, d.clone();
568
- d = d.clone();
569
- this.ea(a);
570
- return d;
571
- }
572
- d = this.J.ka(c);
573
- d = Ma[d];
574
- if (!d) return b.call(this);
575
- d = this.$ ? d.ha : d.pointerType;
576
- var e = La(c, this.J, d.J);
577
- return null === e ? b.call(this) : this.aa ? Pa(d.J.V, { L: d, K: e, O: this, M: a }) : Pa(d.J.V, { L: d, K: e });
578
- } });
579
- ib = m.UnboundTypeError = ((a, b) => {
580
- var c = Sa(b, function(d) {
581
- this.name = b;
582
- this.message = d;
583
- d = Error(d).stack;
584
- void 0 !== d && (this.stack = this.toString() + "\n" + d.replace(/^Error(:[^\n]*)?\n/, ""));
585
- });
586
- c.prototype = Object.create(a.prototype);
587
- c.prototype.constructor = c;
588
- c.prototype.toString = function() {
589
- return void 0 === this.message ? this.name : `${this.name}: ${this.message}`;
590
- };
591
- return c;
592
- })(Error, "UnboundTypeError");
593
- X.push(0, 1, void 0, 1, null, 1, true, 1, false, 1);
594
- m.count_emval_handles = () => X.length / 2 - 5 - rb.length;
595
- var Ob = {
596
- h: (a, b, c) => {
597
- var d = new za(a);
598
- H[d.K + 16 >> 2] = 0;
599
- H[d.K + 4 >> 2] = b;
600
- H[d.K + 8 >> 2] = c;
601
- Aa = a;
602
- Ba++;
603
- throw Aa;
604
- },
605
- w: () => pa(""),
606
- e: (a) => {
607
- var b = Ca[a];
608
- delete Ca[a];
609
- var c = b.ca, d = b.R, e = b.fa, f = e.map((h) => h.oa).concat(e.map((h) => h.ua));
610
- P([a], f, (h) => {
611
- var g = {};
612
- e.forEach((l, k) => {
613
- var n = h[k], q = l.ma, t = l.na, v = h[k + e.length], u = l.ta, z = l.va;
614
- g[l.ja] = { read: (F) => n.fromWireType(q(t, F)), write: (F, T) => {
615
- var y = [];
616
- u(z, F, v.toWireType(y, T));
617
- Da(y);
618
- } };
619
- });
620
- return [{ name: b.name, fromWireType: (l) => {
621
- var k = {}, n;
622
- for (n in g) k[n] = g[n].read(l);
623
- d(l);
624
- return k;
625
- }, toWireType: (l, k) => {
626
- for (var n in g) if (!(n in k)) throw new TypeError(`Missing field: "${n}"`);
627
- var q = c();
628
- for (n in g) g[n].write(q, k[n]);
629
- null !== l && l.push(d, q);
630
- return q;
631
- }, S: 8, readValueFromPointer: K, P: d }];
632
- });
633
- },
634
- p: () => {
635
- },
636
- z: (a, b, c, d) => {
637
- b = Q(b);
638
- O(a, { name: b, fromWireType: function(e) {
639
- return !!e;
640
- }, toWireType: function(e, f) {
641
- return f ? c : d;
642
- }, S: 8, readValueFromPointer: function(e) {
643
- return this.fromWireType(C[e]);
644
- }, P: null });
645
- },
646
- j: (a, b, c, d, e, f, h, g, l, k, n, q, t) => {
647
- n = Q(n);
648
- f = V(e, f);
649
- g &&= V(h, g);
650
- k &&= V(l, k);
651
- t = V(q, t);
652
- var v = Va(n);
653
- Ua(v, function() {
654
- lb(
655
- `Cannot construct ${n} due to unbound types`,
656
- [d]
657
- );
658
- });
659
- P([a, b, c], d ? [d] : [], (u) => {
660
- u = u[0];
661
- if (d) {
662
- var z = u.J;
663
- var F = z.V;
664
- } else F = Ra.prototype;
665
- u = Sa(n, function(...xa) {
666
- if (Object.getPrototypeOf(this) !== T) throw new R("Use 'new' to construct " + n);
667
- if (void 0 === y.U) throw new R(n + " has no accessible constructor");
668
- var db = y.U[xa.length];
669
- if (void 0 === db) throw new R(`Tried to invoke ctor of ${n} with invalid number of parameters (${xa.length}) - expected (${Object.keys(y.U).toString()}) parameters instead!`);
670
- return db.apply(this, xa);
671
- });
672
- var T = Object.create(F, { constructor: { value: u } });
673
- u.prototype = T;
674
- var y = new Wa(n, u, T, t, z, f, g, k);
675
- if (y.N) {
676
- var U;
677
- (U = y.N).da ?? (U.da = []);
678
- y.N.da.push(y);
679
- }
680
- z = new cb(n, y, true, false, false);
681
- U = new cb(n + "*", y, false, false, false);
682
- F = new cb(n + " const*", y, false, true, false);
683
- Ma[a] = { pointerType: U, ha: F };
684
- eb(v, u);
685
- return [z, U, F];
686
- });
687
- },
688
- i: (a, b, c, d, e, f) => {
689
- var h = mb(b, c);
690
- e = V(d, e);
691
- P([], [a], (g) => {
692
- g = g[0];
693
- var l = `constructor ${g.name}`;
694
- void 0 === g.J.U && (g.J.U = []);
695
- if (void 0 !== g.J.U[b - 1]) throw new R(`Cannot register multiple constructors with identical number of parameters (${b - 1}) for class '${g.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);
696
- g.J.U[b - 1] = () => {
697
- lb(`Cannot construct ${g.name} due to unbound types`, h);
698
- };
699
- P([], h, (k) => {
700
- k.splice(1, 0, null);
701
- g.J.U[b - 1] = pb(l, k, null, e, f);
702
- return [];
703
- });
704
- return [];
705
- });
706
- },
707
- c: (a, b, c, d, e, f, h, g, l) => {
708
- var k = mb(c, d);
709
- b = Q(b);
710
- b = qb(b);
711
- f = V(e, f);
712
- P([], [a], (n) => {
713
- function q() {
714
- lb(`Cannot call ${t} due to unbound types`, k);
715
- }
716
- n = n[0];
717
- var t = `${n.name}.${b}`;
718
- b.startsWith("@@") && (b = Symbol[b.substring(2)]);
719
- g && n.J.ra.push(b);
720
- var v = n.J.V, u = v[b];
721
- void 0 === u || void 0 === u.T && u.className !== n.name && u.W === c - 2 ? (q.W = c - 2, q.className = n.name, v[b] = q) : (Ta(
722
- v,
723
- b,
724
- t
725
- ), v[b].T[c - 2] = q);
726
- P([], k, (z) => {
727
- z = pb(t, z, n, f, h, l);
728
- void 0 === v[b].T ? (z.W = c - 2, v[b] = z) : v[b].T[c - 2] = z;
729
- return [];
730
- });
731
- return [];
732
- });
733
- },
734
- x: (a) => O(a, sb),
735
- k: (a, b, c) => {
736
- b = Q(b);
737
- O(a, { name: b, fromWireType: (d) => d, toWireType: (d, e) => e, S: 8, readValueFromPointer: tb(b, c), P: null });
738
- },
739
- d: (a, b, c, d, e) => {
740
- b = Q(b);
741
- -1 === e && (e = 4294967295);
742
- e = (g) => g;
743
- if (0 === d) {
744
- var f = 32 - 8 * c;
745
- e = (g) => g << f >>> f;
746
- }
747
- var h = b.includes("unsigned") ? function(g, l) {
748
- return l >>> 0;
749
- } : function(g, l) {
750
- return l;
751
- };
752
- O(a, { name: b, fromWireType: e, toWireType: h, S: 8, readValueFromPointer: ub(b, c, 0 !== d), P: null });
753
- },
754
- a: (a, b, c) => {
755
- function d(f) {
756
- return new e(ha.buffer, H[f + 4 >> 2], H[f >> 2]);
757
- }
758
- var e = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array][b];
759
- c = Q(c);
760
- O(a, { name: c, fromWireType: d, S: 8, readValueFromPointer: d }, { pa: true });
761
- },
762
- n: (a) => {
763
- O(a, vb);
764
- },
765
- y: (a, b) => {
766
- b = Q(b);
767
- O(a, { name: b, fromWireType: function(c) {
768
- for (var d = H[c >> 2], e = c + 4, f, h = e, g = 0; g <= d; ++g) {
769
- var l = e + g;
770
- if (g == d || 0 == C[l]) h = h ? xb(C, h, l - h) : "", void 0 === f ? f = h : (f += String.fromCharCode(0), f += h), h = l + 1;
771
- }
772
- W(c);
773
- return f;
774
- }, toWireType: function(c, d) {
775
- d instanceof ArrayBuffer && (d = new Uint8Array(d));
776
- var e, f = "string" == typeof d;
777
- if (!(f || d instanceof Uint8Array || d instanceof Uint8ClampedArray || d instanceof Int8Array)) throw new R("Cannot pass non-string to std::string");
778
- var h;
779
- if (f) for (e = h = 0; e < d.length; ++e) {
780
- var g = d.charCodeAt(e);
781
- 127 >= g ? h++ : 2047 >= g ? h += 2 : 55296 <= g && 57343 >= g ? (h += 4, ++e) : h += 3;
782
- }
783
- else h = d.length;
784
- e = h;
785
- h = Mb(4 + e + 1);
786
- g = h + 4;
787
- H[h >> 2] = e;
788
- if (f) {
789
- if (f = g, g = e + 1, e = C, 0 < g) {
790
- g = f + g - 1;
791
- for (var l = 0; l < d.length; ++l) {
792
- var k = d.charCodeAt(l);
793
- if (55296 <= k && 57343 >= k) {
794
- var n = d.charCodeAt(++l);
795
- k = 65536 + ((k & 1023) << 10) | n & 1023;
796
- }
797
- if (127 >= k) {
798
- if (f >= g) break;
799
- e[f++] = k;
800
- } else {
801
- if (2047 >= k) {
802
- if (f + 1 >= g) break;
803
- e[f++] = 192 | k >> 6;
804
- } else {
805
- if (65535 >= k) {
806
- if (f + 2 >= g) break;
807
- e[f++] = 224 | k >> 12;
808
- } else {
809
- if (f + 3 >= g) break;
810
- e[f++] = 240 | k >> 18;
811
- e[f++] = 128 | k >> 12 & 63;
812
- }
813
- e[f++] = 128 | k >> 6 & 63;
814
- }
815
- e[f++] = 128 | k & 63;
816
- }
817
- }
818
- e[f] = 0;
819
- }
820
- } else if (f) for (f = 0; f < e; ++f) {
821
- l = d.charCodeAt(f);
822
- if (255 < l) throw W(g), new R("String has UTF-16 code units that do not fit in 8 bits");
823
- C[g + f] = l;
824
- }
825
- else for (f = 0; f < e; ++f) C[g + f] = d[f];
826
- null !== c && c.push(W, h);
827
- return h;
828
- }, S: 8, readValueFromPointer: K, P(c) {
829
- W(c);
830
- } });
831
- },
832
- g: (a, b, c) => {
833
- c = Q(c);
834
- if (2 === b) {
835
- var d = zb;
836
- var e = Ab;
837
- var f = Bb;
838
- var h = (g) => E[g >> 1];
839
- } else 4 === b && (d = Cb, e = Db, f = Eb, h = (g) => H[g >> 2]);
840
- O(a, {
841
- name: c,
842
- fromWireType: (g) => {
843
- for (var l = H[g >> 2], k, n = g + 4, q = 0; q <= l; ++q) {
844
- var t = g + 4 + q * b;
845
- if (q == l || 0 == h(t)) n = d(n, t - n), void 0 === k ? k = n : (k += String.fromCharCode(0), k += n), n = t + b;
846
- }
847
- W(g);
848
- return k;
849
- },
850
- toWireType: (g, l) => {
851
- if ("string" != typeof l) throw new R(`Cannot pass non-string to C++ string type ${c}`);
852
- var k = f(l), n = Mb(4 + k + b);
853
- H[n >> 2] = k / b;
854
- e(l, n + 4, k + b);
855
- null !== g && g.push(W, n);
856
- return n;
857
- },
858
- S: 8,
859
- readValueFromPointer: K,
860
- P(g) {
861
- W(g);
862
- }
863
- });
864
- },
865
- f: (a, b, c, d, e, f) => {
866
- Ca[a] = { name: Q(b), ca: V(c, d), R: V(e, f), fa: [] };
867
- },
868
- b: (a, b, c, d, e, f, h, g, l, k) => {
869
- Ca[a].fa.push({ ja: Q(b), oa: c, ma: V(d, e), na: f, ua: h, ta: V(g, l), va: k });
870
- },
871
- l: (a, b) => {
872
- b = Q(b);
873
- O(a, { xa: true, name: b, S: 0, fromWireType: () => {
874
- }, toWireType: () => {
875
- } });
876
- },
877
- r: () => {
878
- ya = false;
879
- Fb = 0;
880
- },
881
- m: (a, b) => {
882
- var c = M[a];
883
- if (void 0 === c) throw a = `${"_emval_take_value"} has unknown type ${kb(a)}`, new R(a);
884
- a = c;
885
- a = a.readValueFromPointer(b);
886
- return ab(a);
887
- },
888
- s: (a, b) => {
889
- Y[a] && (clearTimeout(Y[a].id), delete Y[a]);
890
- if (!b) return 0;
891
- var c = setTimeout(() => {
892
- delete Y[a];
893
- Ib(() => Nb(a, performance.now()));
894
- }, b);
895
- Y[a] = { id: c, ya: b };
896
- return 0;
897
- },
898
- t: (a) => {
899
- var b = C.length;
900
- a >>>= 0;
901
- if (2147483648 < a) return false;
902
- for (var c = 1; 4 >= c; c *= 2) {
903
- var d = b * (1 + 0.2 / c);
904
- d = Math.min(d, a + 100663296);
905
- a: {
906
- d = (Math.min(2147483648, 65536 * Math.ceil(Math.max(a, d) / 65536)) - A.buffer.byteLength + 65535) / 65536 | 0;
907
- try {
908
- A.grow(d);
909
- ka();
910
- var e = 1;
911
- break a;
912
- } catch (f) {
913
- }
914
- e = void 0;
915
- }
916
- if (e) return true;
917
- }
918
- return false;
919
- },
920
- v: () => 52,
921
- o: function() {
922
- return 70;
923
- },
924
- u: (a, b, c, d) => {
925
- for (var e = 0, f = 0; f < c; f++) {
926
- var h = H[b >> 2], g = H[b + 4 >> 2];
927
- b += 8;
928
- for (var l = 0; l < g; l++) {
929
- var k = C[h + l], n = Jb[a];
930
- 0 === k || 10 === k ? ((1 === a ? ea : w)(xb(n)), n.length = 0) : n.push(k);
931
- }
932
- e += g;
933
- }
934
- H[d >> 2] = e;
935
- return 0;
936
- },
937
- q: Hb
938
- }, Z;
939
- (async function() {
940
- function a(d) {
941
- Z = d.exports;
942
- A = Z.A;
943
- ka();
944
- fb = Z.D;
945
- ma.unshift(Z.B);
946
- I--;
947
- m.monitorRunDependencies?.(I);
948
- 0 == I && J && (d = J, J = null, d());
949
- return Z;
950
- }
951
- I++;
952
- m.monitorRunDependencies?.(I);
953
- var b = { a: Ob };
954
- if (m.instantiateWasm) try {
955
- return m.instantiateWasm(b, a);
956
- } catch (d) {
957
- w(`Module.instantiateWasm callback failed with error: ${d}`), p(d);
958
- }
959
- ra ??= m.locateFile ? qa("msdfgen_wasm.wasm") ? "msdfgen_wasm.wasm" : m.locateFile ? m.locateFile("msdfgen_wasm.wasm", r) : r + "msdfgen_wasm.wasm" : new URL("msdfgen_wasm.wasm", import.meta.url).href;
960
- try {
961
- var c = await ua(b);
962
- a(c.instance);
963
- return c;
964
- } catch (d) {
965
- p(d);
966
- }
967
- })();
968
- var jb = (a) => (jb = Z.C)(a), Mb = (a) => (Mb = Z.E)(a), W = (a) => (W = Z.F)(a), Nb = (a, b) => (Nb = Z.G)(a, b);
969
- m.dynCall_jiji = (a, b, c, d, e) => (m.dynCall_jiji = Z.H)(a, b, c, d, e);
970
- var Pb;
971
- J = function Qb() {
972
- Pb || Rb();
973
- Pb || (J = Qb);
974
- };
975
- function Rb() {
976
- function a() {
977
- if (!Pb && (Pb = true, m.calledRun = true, !B)) {
978
- wa(ma);
979
- aa(m);
980
- m.onRuntimeInitialized?.();
981
- if (m.postRun) for ("function" == typeof m.postRun && (m.postRun = [m.postRun]); m.postRun.length; ) {
982
- var b = m.postRun.shift();
983
- na.unshift(b);
984
- }
985
- wa(na);
986
- }
987
- }
988
- if (!(0 < I)) {
989
- if (m.preRun) for ("function" == typeof m.preRun && (m.preRun = [m.preRun]); m.preRun.length; ) oa();
990
- wa(la);
991
- 0 < I || (m.setStatus ? (m.setStatus("Running..."), setTimeout(() => {
992
- setTimeout(() => m.setStatus(""), 1);
993
- a();
994
- }, 1)) : a());
995
- }
996
- }
997
- if (m.preInit) for ("function" == typeof m.preInit && (m.preInit = [m.preInit]); 0 < m.preInit.length; ) m.preInit.pop()();
998
- Rb();
999
- moduleRtn = ba;
1000
- return moduleRtn;
1001
- });
1002
- })();
1003
- var msdfgen_wasm_default = createMSDFGenModule;
1004
-
1005
- // src/generator.ts
1006
- var MSDFGenerator = class {
1007
- module;
1008
- font = null;
1009
- constructor(wasmModule) {
1010
- this.module = wasmModule;
1011
- }
1012
- async loadFont(fontData) {
1013
- this.font = new this.module.Font();
1014
- const vec = new this.module.VectorUnsignedChar();
1015
- for (let i = 0; i < fontData.length; i++) {
1016
- vec.push_back(fontData[i]);
1017
- }
1018
- const success = this.font.loadFromMemory(vec);
1019
- vec.delete();
1020
- if (!success) throw new Error("Failed to load font from memory");
1021
- }
1022
- generateAtlas(options) {
1023
- if (!this.font) throw new Error("No font loaded");
1024
- const {
1025
- charset,
1026
- fontSize = 48,
1027
- textureSize = [512, 512],
1028
- fieldRange = 4,
1029
- padding = 4,
1030
- fixOverlaps = true
1031
- } = options;
1032
- const metrics = this.font.getMetrics();
1033
- const info = this.getFontProperties();
1034
- const scale = fontSize / metrics.emSize;
1035
- const baseline = metrics.ascender * scale;
1036
- const pad = Math.floor(fieldRange / 2);
1037
- const chars = Array.from(new Set(charset));
1038
- const glyphs = [];
1039
- let atlasX = 0;
1040
- let atlasY = 0;
1041
- let rowHeight = 0;
1042
- const texture = new Uint8ClampedArray(textureSize[0] * textureSize[1] * 4);
1043
- for (let i = 0; i < chars.length; i++) {
1044
- const char = chars[i];
1045
- const unicode = char.codePointAt(0);
1046
- const shape = this.font.getGlyphShape(unicode);
1047
- const pixelLeft = Math.floor(shape.left * scale);
1048
- const pixelBottom = Math.floor(shape.bottom * scale);
1049
- const pixelRight = Math.ceil(shape.right * scale);
1050
- const pixelTop = Math.ceil(shape.top * scale);
1051
- const glyphWidth = pixelRight - pixelLeft + pad * 2;
1052
- const glyphHeight = pixelTop - pixelBottom + pad * 2;
1053
- if (atlasX + glyphWidth > textureSize[0]) {
1054
- atlasX = 0;
1055
- atlasY += rowHeight + padding;
1056
- rowHeight = 0;
1057
- }
1058
- const shapeWidth = shape.right - shape.left;
1059
- const shapeHeight = shape.top - shape.bottom;
1060
- const msdfScale = scale;
1061
- const translateX = 0.5 * (glyphWidth / msdfScale - shapeWidth) - shape.left;
1062
- const rawTranslateY = 0.5 * (glyphHeight / msdfScale - shapeHeight) - shape.bottom;
1063
- const translateY = Math.round(rawTranslateY * msdfScale) / msdfScale;
1064
- const result = fixOverlaps ? this.font.generateMSDFWithOverlapFix(
1065
- unicode,
1066
- glyphWidth,
1067
- glyphHeight,
1068
- fieldRange,
1069
- translateX,
1070
- translateY,
1071
- msdfScale
1072
- ) : this.font.generateMSDF(
1073
- unicode,
1074
- glyphWidth,
1075
- glyphHeight,
1076
- fieldRange,
1077
- translateX,
1078
- translateY,
1079
- msdfScale
1080
- );
1081
- for (let py = 0; py < glyphHeight; py++) {
1082
- for (let px = 0; px < glyphWidth; px++) {
1083
- const srcIdx = (py * glyphWidth + px) * 3;
1084
- const dstIdx = ((atlasY + py) * textureSize[0] + (atlasX + px)) * 4;
1085
- texture[dstIdx + 0] = result.data.get(srcIdx + 0) ?? 0;
1086
- texture[dstIdx + 1] = result.data.get(srcIdx + 1) ?? 0;
1087
- texture[dstIdx + 2] = result.data.get(srcIdx + 2) ?? 0;
1088
- texture[dstIdx + 3] = 255;
1089
- }
1090
- }
1091
- result.data.delete();
1092
- glyphs.push({
1093
- unicode,
1094
- char,
1095
- atlasPosition: [atlasX, atlasY],
1096
- atlasSize: [glyphWidth, glyphHeight],
1097
- bounds: {
1098
- left: pixelLeft,
1099
- bottom: pixelBottom,
1100
- right: pixelRight,
1101
- top: pixelTop
1102
- },
1103
- advance: shape.advance * scale,
1104
- xoffset: pixelLeft - pad,
1105
- yoffset: baseline - pixelTop - pad
1106
- });
1107
- atlasX += glyphWidth + padding;
1108
- rowHeight = Math.max(rowHeight, glyphHeight);
1109
- }
1110
- const kerning = [];
1111
- for (let i = 0; i < chars.length; i++) {
1112
- for (let j = 0; j < chars.length; j++) {
1113
- const first = chars[i].codePointAt(0);
1114
- const second = chars[j].codePointAt(0);
1115
- const amount = this.font.getKerning(first, second) * scale;
1116
- if (amount !== 0) {
1117
- kerning.push({
1118
- first: chars[i],
1119
- second: chars[j],
1120
- amount
1121
- });
1122
- }
1123
- }
1124
- }
1125
- return {
1126
- texture: new ImageData(texture, textureSize[0], textureSize[1]),
1127
- glyphs,
1128
- metrics: {
1129
- emSize: metrics.emSize,
1130
- ascender: metrics.ascender * scale,
1131
- descender: metrics.descender * scale,
1132
- lineHeight: metrics.lineHeight * scale
1133
- },
1134
- info,
1135
- kerning,
1136
- textureSize,
1137
- fieldRange
1138
- };
1139
- }
1140
- getFontProperties() {
1141
- if (!this.font) throw new Error("No font loaded");
1142
- const props = this.font.getFontProperties();
1143
- return {
1144
- ...props,
1145
- name: String(props.name)
1146
- };
1147
- }
1148
- exportJSON(options) {
1149
- const { atlas, fontSize = 48 } = options;
1150
- const pad = Math.floor(atlas.fieldRange / 2);
1151
- return {
1152
- pages: ["texture.png"],
1153
- chars: atlas.glyphs.map((g, index) => ({
1154
- id: g.unicode,
1155
- index,
1156
- char: g.char,
1157
- width: g.atlasSize[0],
1158
- height: g.atlasSize[1],
1159
- xoffset: g.xoffset,
1160
- yoffset: g.yoffset,
1161
- xadvance: g.advance,
1162
- chnl: 15,
1163
- x: g.atlasPosition[0],
1164
- y: g.atlasPosition[1],
1165
- page: 0
1166
- })),
1167
- info: {
1168
- face: atlas.info.name,
1169
- size: fontSize,
1170
- bold: atlas.info.bold ? 1 : 0,
1171
- italic: atlas.info.italic ? 1 : 0,
1172
- charset: atlas.glyphs.map((g) => g.char),
1173
- unicode: 1,
1174
- stretchH: 100,
1175
- smooth: 1,
1176
- aa: 1,
1177
- padding: [pad, pad, pad, pad],
1178
- spacing: [0, 0],
1179
- outline: 0
1180
- },
1181
- common: {
1182
- lineHeight: atlas.metrics.lineHeight,
1183
- base: atlas.metrics.ascender,
1184
- scaleW: atlas.textureSize[0],
1185
- scaleH: atlas.textureSize[1],
1186
- pages: 1,
1187
- packed: 0,
1188
- alphaChnl: 0,
1189
- redChnl: 0,
1190
- greenChnl: 0,
1191
- blueChnl: 0
1192
- },
1193
- distanceField: {
1194
- fieldType: "msdf",
1195
- distanceRange: atlas.fieldRange
1196
- },
1197
- kernings: atlas.kerning.map((k) => ({
1198
- first: k.first.codePointAt(0),
1199
- second: k.second.codePointAt(0),
1200
- amount: k.amount
1201
- }))
1202
- };
1203
- }
1204
- /**
1205
- * Clean up resources
1206
- */
1207
- dispose() {
1208
- if (this.font) {
1209
- this.font.delete();
1210
- this.font = null;
1211
- }
1212
- }
1213
- };
1214
-
1215
- // src/worker.ts
1216
- var MSDFGeneratorWorker = class {
1217
- generator = null;
1218
- async initialize(wasmBinaryUrl) {
1219
- try {
1220
- const moduleConfig = wasmBinaryUrl ? {
1221
- locateFile: (path) => {
1222
- if (path.endsWith(".wasm")) return wasmBinaryUrl;
1223
- return path;
1224
- }
1225
- } : void 0;
1226
- const module = await msdfgen_wasm_default(moduleConfig);
1227
- this.generator = new MSDFGenerator(module);
1228
- } catch (err) {
1229
- console.error("[MSDF Generator] Failed to initialize worker:", err);
1230
- throw err;
1231
- }
1232
- }
1233
- ensureInitialized() {
1234
- if (!this.generator)
1235
- throw new Error("Worker not initialized. Call initialize() first.");
1236
- return this.generator;
1237
- }
1238
- async loadFont(fontData) {
1239
- await this.ensureInitialized().loadFont(fontData);
1240
- }
1241
- generateAtlas(options) {
1242
- return this.ensureInitialized().generateAtlas({
1243
- ...options,
1244
- font: new Uint8Array(0)
1245
- });
1246
- }
1247
- exportJSON(options) {
1248
- return this.ensureInitialized().exportJSON(options);
1249
- }
1250
- dispose() {
1251
- this.generator?.dispose();
1252
- this.generator = null;
1253
- }
1254
- async generateMSDFAtlas(options) {
1255
- this.ensureInitialized();
1256
- await this.loadFont(options.font);
1257
- const atlas = this.generateAtlas(options);
1258
- return transfer(atlas, [atlas.texture.data.buffer]);
1259
- }
1260
- async generateMSDFFont(options) {
1261
- this.ensureInitialized();
1262
- await this.loadFont(options.font);
1263
- const atlas = this.generateAtlas(options);
1264
- return this.exportJSON({
1265
- atlas,
1266
- fontSize: options.fontSize || 48
1267
- });
1268
- }
1269
- };
1270
- expose(new MSDFGeneratorWorker());