geometryview 0.0.0-stage → 0.1.1

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 (46) hide show
  1. package/README.md +37 -2
  2. package/bin/geometryview.mjs +65 -0
  3. package/package.json +42 -4
  4. package/src/bridge.mjs +77 -0
  5. package/src/mcp.mjs +73 -0
  6. package/src/native.mjs +183 -0
  7. package/src/page.mjs +147 -0
  8. package/src/tools.mjs +265 -0
  9. package/src/web.mjs +173 -0
  10. package/src/websocket.mjs +104 -0
  11. package/web/LICENSE +21 -0
  12. package/web/NOTICES.md +49 -0
  13. package/web/bridge.js +29 -0
  14. package/web/build/geometryview-web.mjs +2 -0
  15. package/web/build/geometryview-web.wasm +0 -0
  16. package/web/chrome.js +541 -0
  17. package/web/engine.js +453 -0
  18. package/web/fonts/IBMPlexMono-Medium.ttf +0 -0
  19. package/web/fonts/IBMPlexMono-Regular.ttf +0 -0
  20. package/web/fonts/IBMPlexMono-SemiBold.ttf +0 -0
  21. package/web/fonts/LICENSE.txt +93 -0
  22. package/web/icons/icon-180.png +0 -0
  23. package/web/icons/icon-192.png +0 -0
  24. package/web/icons/icon-32.png +0 -0
  25. package/web/icons/icon-512.png +0 -0
  26. package/web/icons.js +50 -0
  27. package/web/import-worker.js +329 -0
  28. package/web/index.html +17 -0
  29. package/web/input.js +255 -0
  30. package/web/isolation-worker.js +21 -0
  31. package/web/library-rows.js +120 -0
  32. package/web/library-store.js +368 -0
  33. package/web/library.js +306 -0
  34. package/web/manifest.webmanifest +14 -0
  35. package/web/occt/geometryview-occt-web.mjs +2 -0
  36. package/web/occt/geometryview-occt-web.wasm +0 -0
  37. package/web/occt/geometryview-step-web.mjs +2 -0
  38. package/web/occt/geometryview-step-web.wasm +0 -0
  39. package/web/occt-threads/geometryview-step-web.mjs +2 -0
  40. package/web/occt-threads/geometryview-step-web.wasm +0 -0
  41. package/web/occt-worker.js +45 -0
  42. package/web/structure.js +435 -0
  43. package/web/toolbar-fold.js +49 -0
  44. package/web/ui.js +134 -0
  45. package/web/viewer.css +558 -0
  46. package/web/viewer.js +1163 -0
package/web/engine.js ADDED
@@ -0,0 +1,453 @@
1
+ // The engine in the page: loads the WebAssembly module, answers its host calls, streams files into
2
+ // it, draws the overlay's text, and wraps its geo_web_* functions. Framework-free; everything runs
3
+ // on the main thread, as the engine does.
4
+
5
+ import createGeometryView from "./build/geometryview-web.mjs";
6
+
7
+ // GeoEventKind, as engine.h numbers them.
8
+ export const Events = Object.freeze({
9
+ Loading: 0, SceneReady: 1, Failed: 2, Progress: 3, ModelReady: 4, SelectionChanged: 5,
10
+ HoverChanged: 6, LooksChanged: 7, VisibilityChanged: 8,
11
+ });
12
+ export const Actions = Object.freeze({
13
+ Fit: 0, ClearSelection: 1, ToggleProjection: 2, ShowAll: 3, UnghostAll: 4, Isolate: 5,
14
+ HideSelection: 6, GhostSelection: 7, Undo: 8, Redo: 9, ViewFront: 10, ViewBack: 11,
15
+ ViewLeft: 12, ViewRight: 13, ViewTop: 14, ViewBottom: 15, ViewIso: 16, FitSelection: 17,
16
+ ToggleSeeThrough: 18,
17
+ });
18
+ export const Pointer = Object.freeze({ Move: 0, Down: 1, Up: 2, Scroll: 3, Magnify: 4, Leave: 5,
19
+ Cancel: 6 });
20
+ export const Buttons = Object.freeze({ None: 0, Left: 1, Right: 2, Middle: 3 });
21
+ export const Modifiers = Object.freeze({ Shift: 1, Control: 2, Option: 4, Command: 8, Space: 16 });
22
+ export const NodeKinds = Object.freeze({ Assembly: 0, Part: 1, Body: 2 });
23
+ export const NodeActions = Object.freeze({ Hide: 0, Show: 1, Ghost: 2, Unghost: 3, Isolate: 4 });
24
+ export const Tools = Object.freeze({ Select: 0, Hide: 1, Ghost: 2 });
25
+
26
+ // The overlay atlas's layout, as gpu_types.h fixes it.
27
+ const kAtlasWidth = 512, kAtlasHeight = 6 * 48 + 48;
28
+ const kLabelWidth = 144, kLabelHeight = 48, kGlyphWidth = 28, kGlyphHeight = 48;
29
+ const kAtlasGlyphs = " 0123456789.kmu";
30
+
31
+ // Bytes handed to the engine at a time, through one staging buffer it owns.
32
+ const kStage = 1 << 20;
33
+
34
+ // Why the frame loop runs, from its stat: just started, the core wants frames (something moves, or
35
+ // it lingers after), the still view's samples are yet to be drawn, or both.
36
+ const kLoopCauses = [null, "starting", "moving", "settling", "moving, settling"];
37
+
38
+ export class Engine {
39
+ // `canvas` is drawn into; `handlers` takes the engine's events: { event(kind, document, node,
40
+ // done, total, message), framesRunning(running) }.
41
+ static async start(canvas, handlers, { phone = false } = {}) {
42
+ const engine = new Engine(canvas, handlers, phone);
43
+ await engine.#load();
44
+ return engine;
45
+ }
46
+
47
+ #module = null;
48
+ #canvas;
49
+ #handlers;
50
+ #sources = new Map(); // what each open path streams from
51
+ #imports = new Map(); // token to its stream's state
52
+ #nextSource = 1;
53
+ #stage = 0;
54
+ // How the last file read arrived: { bytes, pieces, largest, firstMs, ms }, the times from
55
+ // asking for it. A file whose length WebKit knows can come in one piece, all at the end.
56
+ lastRead = null;
57
+
58
+ constructor(canvas, handlers, phone) {
59
+ this.#canvas = canvas;
60
+ this.#handlers = handlers;
61
+ this.phone = phone;
62
+ }
63
+
64
+ async #load() {
65
+ const phone = this.phone;
66
+ const module = await createGeometryView();
67
+ this.#module = module;
68
+ const ready = new Promise((resolve, reject) => {
69
+ module.geoHost = {
70
+ ready: () => resolve(),
71
+ failed: (message) => reject(new Error(message)),
72
+ runFrames: (running) => this.#handlers.framesRunning?.(running),
73
+ // WebAssembly hands unsigned values over as signed ones.
74
+ // A throw here would unwind through the engine, so the page's errors stop at this edge.
75
+ event: (kind, document, node, done, total, message) => {
76
+ try {
77
+ this.#handlers.event?.(kind >>> 0, document >>> 0, node >>> 0, done >>> 0, total >>> 0, message);
78
+ } catch (error) {
79
+ reportError(error);
80
+ }
81
+ },
82
+ startImport: (token, path) => this.#startImport(token, path),
83
+ cancelImport: (token) => this.#imports.get(token)?.cancel(),
84
+ // Finer geometry for some of a document's definitions, from the file it was imported
85
+ // from: the page answers through refineSegment and finishRefinement, later, never at once.
86
+ startRefinement: (token, path, level, definitions) => {
87
+ const name = path.slice(path.indexOf("/") + 1);
88
+ const refine = this.#handlers.refine;
89
+ if (refine) {
90
+ refine(token, name, level, Array.from(definitions));
91
+ } else {
92
+ setTimeout(() => this.finishRefinement(token, false));
93
+ }
94
+ },
95
+ cancelRefinement: () => this.#handlers.cancelRefinement?.(),
96
+ snapshot: (pointer, width, height, bgra) => this.#snapshotArrived(pointer, width, height, bgra),
97
+ };
98
+ });
99
+ const { width, height, scale } = this.#size();
100
+ if (!this.#canvas.id) this.#canvas.id = "viewport";
101
+ const reduceMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
102
+ this.#withString(`#${this.#canvas.id}`, (selector) => module._geo_web_start(
103
+ selector, width, height, scale, (reduceMotion ? 1 : 0) | (phone ? 2 : 0)));
104
+ await ready;
105
+ this.#stage = module._geo_web_staging(kStage);
106
+ await this.#drawAtlas();
107
+ }
108
+
109
+ // ---- Sizes and input ---------------------------------------------------------------------
110
+
111
+ #size() {
112
+ const scale = this.scale;
113
+ const rect = this.#canvas.getBoundingClientRect();
114
+ const width = Math.max(1, Math.round(rect.width * scale));
115
+ const height = Math.max(1, Math.round(rect.height * scale));
116
+ this.#canvas.width = width;
117
+ this.#canvas.height = height;
118
+ return { width, height, scale };
119
+ }
120
+
121
+ // Pixels per CSS pixel. Phones draw at 2 at most: the third costs more than it shows.
122
+ get scale() {
123
+ return this.phone ? Math.min(devicePixelRatio, 2) : devicePixelRatio;
124
+ }
125
+
126
+ resize() {
127
+ const { width, height, scale } = this.#size();
128
+ this.#module._geo_web_resize(width, height, scale);
129
+ }
130
+
131
+ setInsets(left, top, right, bottom) {
132
+ this.#module._geo_web_set_insets(left, top, right, bottom);
133
+ }
134
+
135
+ /** Whether the view cube and scale bar are drawn. */
136
+ setOverlayShown(shown) {
137
+ this.#module._geo_web_set_overlay_shown(shown ? 1 : 0);
138
+ }
139
+
140
+ pointer(kind, button, x, y, delta = 0, modifiers = 0, timestamp = performance.now() / 1000) {
141
+ this.#module._geo_web_pointer(kind, button, x, y, delta, modifiers, timestamp);
142
+ }
143
+
144
+ perform(action) { this.#module._geo_web_perform(action); }
145
+ setSelectionMode(mode) { this.#module._geo_web_set_selection_mode(mode); }
146
+ setTool(tool) { this.#module._geo_web_set_tool(tool); }
147
+ setLook({ style, colorMode, ghostStyle, castShadow, grain, wobble }) {
148
+ this.#module._geo_web_set_look(style, colorMode, ghostStyle, castShadow ? 1 : 0, grain, wobble);
149
+ }
150
+ // The cache file version this engine reads.
151
+ get cacheVersion() { return this.#module._geo_web_cache_version(); }
152
+
153
+ // The look every app starts with, as setLook takes it: the engine's, so all agree.
154
+ defaultLook() {
155
+ const m = this.#module;
156
+ const out = m._malloc(6 * 8);
157
+ m._geo_web_default_look(out);
158
+ const v = new Float64Array(m.HEAPU8.buffer, out, 6).slice();
159
+ m._free(out);
160
+ return { style: v[0], colorMode: v[1], ghostStyle: v[2], castShadow: v[3] !== 0, grain: v[4], wobble: v[5] };
161
+ }
162
+ // `cuts` is three { enabled, position, flip }.
163
+ setSection(cuts) {
164
+ let bits = 0;
165
+ cuts.forEach((cut, axis) => {
166
+ if (cut.enabled) bits |= 1 << axis;
167
+ if (cut.flip) bits |= 16 << axis;
168
+ });
169
+ this.#module._geo_web_set_section(bits, cuts[0].position, cuts[1].position, cuts[2].position);
170
+ }
171
+ selectNode(document, node, extend) { this.#module._geo_web_select_node(document, node, extend ? 1 : 0); }
172
+ hoverNode(document, node) { this.#module._geo_web_hover_node(document, node); }
173
+ nodeAction(document, node, action) { this.#module._geo_web_node_action(document, node, action); }
174
+ requestFrame() { this.#module._geo_web_request_frame(); }
175
+ // Looks at what is shown from a direction, in degrees around Z and above the XY plane.
176
+ setView(azimuth, elevation, perspective) {
177
+ this.#module._geo_web_set_view(azimuth, elevation, perspective ? 1 : 0);
178
+ }
179
+
180
+ // The latest GPU error the engine saw, for diagnosing.
181
+ lastError() { return this.#module.UTF8ToString(this.#module._geo_web_last_error()); }
182
+
183
+ // The scene's bounds and face count.
184
+ sceneInfo() {
185
+ const m = this.#module;
186
+ const out = m._malloc(8 * 8);
187
+ m._geo_web_scene_info(out);
188
+ const v = new Float64Array(m.HEAPU8.buffer, out, 8).slice();
189
+ m._free(out);
190
+ return { min: [v[0], v[1], v[2]], max: [v[3], v[4], v[5]], faces: v[6], triangles: v[7] };
191
+ }
192
+
193
+ // ---- Files -------------------------------------------------------------------------------
194
+
195
+ // Opens a cache file from a URL or a File, replacing what is open or added to it. `name` is
196
+ // what the interface calls it.
197
+ open(source, name, { add = false } = {}) {
198
+ const path = `${this.#nextSource++}/${name}`;
199
+ this.#sources.set(path, source);
200
+ this.#withString(path, (pointer) => this.#module._geo_web_open(pointer, add ? 1 : 0));
201
+ }
202
+
203
+ // Opens a document whose segments the page will hand over as an importer writes them, so the
204
+ // model shows while it imports. Resolves to the import's token.
205
+ openImport(name, { add = false } = {}) {
206
+ return new Promise((resolve) => {
207
+ const path = `${this.#nextSource++}/${name}`;
208
+ this.#sources.set(path, { importing: resolve });
209
+ this.#withString(path, (pointer) => this.#module._geo_web_open(pointer, add ? 1 : 0));
210
+ });
211
+ }
212
+
213
+ // One whole segment, for the import of `token`. False if the engine refused it or the import
214
+ // was cancelled.
215
+ importSegment(token, bytes) {
216
+ const m = this.#module;
217
+ const pointer = m._malloc(bytes.length);
218
+ m.HEAPU8.set(bytes, pointer);
219
+ const taken = m._geo_web_import_segment(token, pointer, bytes.length);
220
+ m._free(pointer);
221
+ return taken > 0;
222
+ }
223
+
224
+ // One whole segment of the refinement of `token`'s document. False if the engine refused it or
225
+ // the refinement was cancelled.
226
+ refineSegment(token, bytes) {
227
+ const m = this.#module;
228
+ const pointer = m._malloc(bytes.length);
229
+ m.HEAPU8.set(bytes, pointer);
230
+ const taken = m._geo_web_refine_segment(token, pointer, bytes.length);
231
+ m._free(pointer);
232
+ return taken > 0;
233
+ }
234
+
235
+ // Ends the refinement of `token`'s document: every segment handed over if `ok`.
236
+ finishRefinement(token, ok) {
237
+ this.#module._geo_web_refine_end(token, ok ? 1 : 0);
238
+ }
239
+
240
+ // Ends the import of `token`: every segment handed over, or failed, as `message` says.
241
+ finishImport(token, message = null) {
242
+ if (message === null) this.#module._geo_web_import_end(token, 0);
243
+ else this.#withString(message, (pointer) => this.#module._geo_web_import_end(token, pointer));
244
+ }
245
+
246
+ async #startImport(token, path) {
247
+ const source = this.#sources.get(path);
248
+ if (source?.importing) {
249
+ source.importing(token);
250
+ return;
251
+ }
252
+ const module = this.#module;
253
+ let cancelled = false;
254
+ let reader = null;
255
+ this.#imports.set(token, { cancel: () => { cancelled = true; reader?.cancel(); } });
256
+ const asked = performance.now();
257
+ const read = { bytes: 0, pieces: 0, largest: 0, firstMs: null, ms: null };
258
+ try {
259
+ let body = source, size = 0;
260
+ if (typeof source === "string") {
261
+ const response = await fetch(source);
262
+ body = response.body;
263
+ // The launcher and the iPhone shell send files chunked, which WebKit streams, with their
264
+ // size apart.
265
+ const length = response.headers.get("content-length") ?? response.headers.get("geometryview-size");
266
+ size = Number(length ?? 0);
267
+ } else if (source instanceof Blob) {
268
+ body = source.stream();
269
+ size = source.size;
270
+ }
271
+ // The file's real size bounds what its header may ask to be placed.
272
+ if (size > 0) module._geo_web_stream_size(token, size);
273
+ reader = body.getReader();
274
+ for (;;) {
275
+ const { done, value } = await reader.read();
276
+ if (cancelled) return;
277
+ if (done) break;
278
+ read.firstMs ??= performance.now() - asked;
279
+ read.pieces += 1;
280
+ read.bytes += value.length;
281
+ read.largest = Math.max(read.largest, value.length);
282
+ for (let at = 0; at < value.length; at += kStage) {
283
+ const piece = value.subarray(at, Math.min(value.length, at + kStage));
284
+ module.HEAPU8.set(piece, this.#stage);
285
+ if (module._geo_web_stream_chunk(token, this.#stage, piece.length) <= 0) {
286
+ reader.cancel();
287
+ return;
288
+ }
289
+ }
290
+ }
291
+ read.ms = performance.now() - asked;
292
+ this.lastRead = read;
293
+ module._geo_web_stream_end(token, 0);
294
+ } catch (error) {
295
+ if (!cancelled) {
296
+ this.#withString(`The file could not be read: ${error.message}`,
297
+ (message) => module._geo_web_stream_end(token, message));
298
+ }
299
+ } finally {
300
+ this.#imports.delete(token);
301
+ }
302
+ }
303
+
304
+ // The view as drawn, with all its samples and the overlay: { width, height, pixels } with
305
+ // pixels as RGBA, or null if nothing is open.
306
+ snapshot() {
307
+ return new Promise((resolve) => {
308
+ this.#snapshots.push(resolve);
309
+ if (this.#snapshots.length === 1) this.#module._geo_web_snapshot();
310
+ });
311
+ }
312
+
313
+ #snapshots = [];
314
+
315
+ #snapshotArrived(pointer, width, height, bgra) {
316
+ const resolve = this.#snapshots.shift();
317
+ let image = null;
318
+ if (pointer !== 0 && width > 0) {
319
+ const pixels = this.#module.HEAPU8.slice(pointer, pointer + width * height * 4);
320
+ if (bgra) {
321
+ for (let p = 0; p < pixels.length; p += 4) {
322
+ const b = pixels[p];
323
+ pixels[p] = pixels[p + 2];
324
+ pixels[p + 2] = b;
325
+ }
326
+ }
327
+ image = { width, height, pixels };
328
+ }
329
+ resolve?.(image);
330
+ if (this.#snapshots.length > 0) this.#module._geo_web_snapshot();
331
+ }
332
+
333
+ // ---- What the engine publishes -----------------------------------------------------------
334
+
335
+ // A document's tree: rows of { parent, end, firstOccurrence, occurrenceEnd, name, kind }.
336
+ model(document) {
337
+ const m = this.#module;
338
+ const count = m._geo_web_model_node_count(document);
339
+ if (count === 0) return null;
340
+ const words = new Uint32Array(m.HEAPU8.buffer, m._geo_web_model_nodes(document), count * 8);
341
+ const strings = new Uint8Array(m.HEAPU8.buffer, m._geo_web_model_strings(document),
342
+ m._geo_web_model_strings_size(document));
343
+ const decoder = new TextDecoder();
344
+ const nodes = new Array(count);
345
+ for (let n = 0; n < count; ++n) {
346
+ const w = n * 8;
347
+ nodes[n] = {
348
+ parent: words[w] === 0xFFFFFFFF ? -1 : words[w],
349
+ end: words[w + 1],
350
+ firstOccurrence: words[w + 2],
351
+ occurrenceEnd: words[w + 3],
352
+ name: decoder.decode(strings.subarray(words[w + 4], words[w + 4] + words[w + 5])),
353
+ kind: words[w + 6],
354
+ };
355
+ }
356
+ return nodes;
357
+ }
358
+
359
+ // One NodeVisibility per row: 0 shown, 1 hidden, 2 ghosted, 3 mixed.
360
+ nodeStates(document) {
361
+ const m = this.#module;
362
+ const count = m._geo_web_node_state_count(document);
363
+ return count === 0 ? new Uint8Array(0)
364
+ : new Uint8Array(m.HEAPU8.buffer, m._geo_web_node_states(document), count).slice();
365
+ }
366
+
367
+ // Each occurrence's swatch, RGBA8 with red in the low byte, in global order, and each
368
+ // document's first occurrence.
369
+ swatches() {
370
+ const m = this.#module;
371
+ const at = (pointer, count) => count === 0 ? new Uint32Array(0)
372
+ : new Uint32Array(m.HEAPU8.buffer, pointer, count).slice();
373
+ return { colors: at(m._geo_web_swatches(), m._geo_web_swatch_count()),
374
+ bases: at(m._geo_web_swatch_bases(), m._geo_web_swatch_base_count()) };
375
+ }
376
+
377
+ summary() {
378
+ const m = this.#module;
379
+ const out = m._malloc(7 * 4);
380
+ m._geo_web_summary(out);
381
+ const v = new Uint32Array(m.HEAPU8.buffer, out, 7).slice();
382
+ m._free(out);
383
+ return { occurrences: v[0], faces: v[1], document: v[2], node: v[3] === 0xFFFFFFFF ? -1 : v[3],
384
+ mode: v[4], selected: v[5], hidden: v[6] };
385
+ }
386
+
387
+ stats() {
388
+ const m = this.#module;
389
+ const out = m._malloc(9 * 8);
390
+ m._geo_web_stats(out);
391
+ const v = new Float64Array(m.HEAPU8.buffer, out, 9).slice();
392
+ m._free(out);
393
+ return { frames: v[0], settledFrames: v[1], gpuMs: v[2], bufferMB: v[3], targetMB: v[4],
394
+ triangles: v[5], edgeSegments: v[6], looping: v[7] !== 0, loopCause: kLoopCauses[v[7]],
395
+ hovered: v[8], heapMB: m.HEAPU8.length / 1048576 };
396
+ }
397
+
398
+ // ---- The overlay's text ------------------------------------------------------------------
399
+
400
+ // The view cube's labels and the scale bar's glyphs, drawn as the Mac draws them with Core
401
+ // Text: IBM Plex Mono SemiBold, white on black, each centred on its cap height in its cell.
402
+ async #drawAtlas() {
403
+ const family = "GeometryView Plex Mono";
404
+ try {
405
+ const face = new FontFace(family, `url(${new URL("./fonts/IBMPlexMono-SemiBold.ttf", import.meta.url)})`,
406
+ { weight: "600" });
407
+ document.fonts.add(await face.load());
408
+ } catch {
409
+ // The browser's own monospace stands in.
410
+ }
411
+ const canvas = new OffscreenCanvas(kAtlasWidth, kAtlasHeight);
412
+ const context = canvas.getContext("2d", { willReadFrequently: true });
413
+ context.fillStyle = "#000";
414
+ context.fillRect(0, 0, kAtlasWidth, kAtlasHeight);
415
+ context.fillStyle = "#fff";
416
+ context.textBaseline = "alphabetic";
417
+ const draw = (text, size, left, width, top, height) => {
418
+ context.font = `600 ${size}px "${family}", Menlo, monospace`;
419
+ const capHeight = context.measureText("H").actualBoundingBoxAscent;
420
+ const x = left + (width - context.measureText(text).width) / 2;
421
+ context.fillText(text, x, top + (height + capHeight) / 2);
422
+ };
423
+ ["FRONT", "BACK", "LEFT", "RIGHT", "TOP", "BOTTOM"].forEach((label, face) => {
424
+ draw(label, 23, 0, kLabelWidth, face * kLabelHeight, kLabelHeight);
425
+ });
426
+ // The glyph strip, drawn for a 2x display: 11 points is 22 pixels.
427
+ [...kAtlasGlyphs].forEach((c, cell) => {
428
+ draw(c === "u" ? "µ" : c, 22, cell * kGlyphWidth, kGlyphWidth, 6 * kLabelHeight, kGlyphHeight);
429
+ });
430
+ context.font = `600 22px "${family}", Menlo, monospace`;
431
+ const advance = context.measureText("0").width;
432
+ const rgba = context.getImageData(0, 0, kAtlasWidth, kAtlasHeight).data;
433
+ const m = this.#module;
434
+ const pixels = m._malloc(kAtlasWidth * kAtlasHeight);
435
+ const coverage = new Uint8Array(m.HEAPU8.buffer, pixels, kAtlasWidth * kAtlasHeight);
436
+ for (let p = 0; p < coverage.length; ++p) coverage[p] = rgba[p * 4];
437
+ m._geo_web_set_atlas(pixels, kAtlasWidth * kAtlasHeight, advance);
438
+ m._free(pixels);
439
+ }
440
+
441
+ // Calls `use` with `text` in the module's memory, which the engine copies if it keeps it.
442
+ #withString(text, use) {
443
+ const m = this.#module;
444
+ const size = m.lengthBytesUTF8(text) + 1;
445
+ const pointer = m._malloc(size);
446
+ m.stringToUTF8(text, pointer, size);
447
+ try {
448
+ return use(pointer);
449
+ } finally {
450
+ m._free(pointer);
451
+ }
452
+ }
453
+ }
Binary file
@@ -0,0 +1,93 @@
1
+ Copyright © 2017 IBM Corp. with Reserved Font Name "Plex"
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+
5
+ This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file
Binary file
Binary file
Binary file
package/web/icons.js ADDED
@@ -0,0 +1,50 @@
1
+ // Line icons for the chrome, on a 16 unit grid, stroked in the current text colour. The Mac app
2
+ // draws these same icons: it reads this file, so each icon stays on one line of its own, as
3
+ // `name: \`markup\`,` with plain SVG markup and nothing computed. Launcher/test/icons.test.mjs
4
+ // reads it the way the app does.
5
+
6
+ const svg = (markup, size = 16) =>
7
+ `<svg viewBox="0 0 16 16" width="${size}" height="${size}" fill="none" stroke="currentColor" ` +
8
+ `stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${markup}</svg>`;
9
+
10
+ export const iconMarkup = {
11
+ eye: `<path d="M1.5 8s2.4-4.5 6.5-4.5S14.5 8 14.5 8 12.1 12.5 8 12.5 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="2"/>`,
12
+ eyeSlash: `<path d="M1.5 8s2.4-4.5 6.5-4.5S14.5 8 14.5 8 12.1 12.5 8 12.5 1.5 8 1.5 8z"/><circle cx="8" cy="8" r="2"/><path d="M2.5 2.5l11 11"/>`,
13
+ ghost: `<circle cx="8" cy="8" r="5.5" stroke-dasharray="2.2 1.8"/>`,
14
+ scope: `<circle cx="8" cy="8" r="4.5"/><path d="M8 1.5v3M8 11.5v3M1.5 8h3M11.5 8h3"/>`,
15
+ undo: `<path d="M5.5 4.5L2.5 7.5l3 3"/><path d="M2.5 7.5H10a3.5 3.5 0 0 1 0 7H8"/>`,
16
+ redo: `<path d="M10.5 4.5l3 3-3 3"/><path d="M13.5 7.5H6a3.5 3.5 0 0 0 0 7h2"/>`,
17
+ seeThrough: `<circle cx="8" cy="8" r="5.5"/><path d="M8 2.5v11a5.5 5.5 0 0 1 0-11z" fill="currentColor"/>`,
18
+ scissors: `<circle cx="4" cy="11.5" r="2"/><circle cx="12" cy="11.5" r="2"/><path d="M5.5 10L12 2.5M10.5 10L4 2.5"/>`,
19
+ palette: `<path d="M8 1.75a6.25 6.25 0 1 0 0 12.5c1 0 1.5-.6 1.5-1.3 0-.9-.8-1.3-.8-2 0-.8.6-1.2 1.4-1.2h1.6c1.6 0 2.55-1.1 2.55-2.6C14.25 4.4 11.6 1.75 8 1.75z"/><circle cx="4.6" cy="7.4" r=".9" fill="currentColor"/><circle cx="6.6" cy="4.6" r=".9" fill="currentColor"/><circle cx="10" cy="4.6" r=".9" fill="currentColor"/>`,
20
+ cube: `<path d="M8 1.75l5.5 3v6.5L8 14.25l-5.5-3V4.75z"/><path d="M2.5 4.75L8 7.75l5.5-3M8 7.75v6.5"/>`,
21
+ fit: `<path d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"/>`,
22
+ chevron: `<path d="M6 4l4 4-4 4"/>`,
23
+ assembly: `<path stroke-width="1.25" d="M9.24 8.1L5.6 10.2L1.96 8.1L1.96 3.9L5.6 1.8L9.24 3.9zM14.04 12.1L10.4 14.2L6.76 12.1L6.76 7.9L10.4 5.8L14.04 7.9z"/>`,
24
+ search: `<circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5l3.5 3.5"/>`,
25
+ folder: `<path d="M2.5 4.5v8h11V6.5H8L6.5 4.5z"/>`,
26
+ folderPlus: `<path d="M2.5 4.5v8h11V6.5H8L6.5 4.5z"/><path d="M8 7.75v3.5M6.25 9.5h3.5"/>`,
27
+ file: `<path d="M4 1.75h5.25L12.5 5v9.25H4z"/><path d="M9.25 1.75V5h3.25"/>`,
28
+ plus: `<path d="M8 3v10M3 8h10"/>`,
29
+ close: `<path d="M4 4l8 8M12 4l-8 8"/>`,
30
+ parts: `<path d="M3 4h10M3 8h10M3 12h10"/>`,
31
+ more: `<circle cx="3.5" cy="8" r="1.1" fill="currentColor" stroke="none"/><circle cx="8" cy="8" r="1.1" fill="currentColor" stroke="none"/><circle cx="12.5" cy="8" r="1.1" fill="currentColor" stroke="none"/>`,
32
+ check: `<path d="M3.5 8.5l3 3 6-7"/>`,
33
+ };
34
+
35
+ export const icons = Object.fromEntries(
36
+ Object.entries(iconMarkup).map(([name, markup]) => [name, (size) => svg(markup, size)]));
37
+
38
+ // An icon as an element, parsed once and then cloned, for chrome made often, such as tree rows.
39
+ const parsed = new Map();
40
+ export function iconNode(name, size) {
41
+ const key = `${name} ${size}`;
42
+ let node = parsed.get(key);
43
+ if (!node) {
44
+ const template = document.createElement("template");
45
+ template.innerHTML = icons[name](size);
46
+ node = template.content.firstChild;
47
+ parsed.set(key, node);
48
+ }
49
+ return node.cloneNode(true);
50
+ }