@johnoscott/isometric-engine 0.15.0 → 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.
Files changed (78) hide show
  1. package/README.md +3 -1
  2. package/iso-editor.js +230 -193
  3. package/iso-remotion.js +353 -0
  4. package/iso-render.js +184 -147
  5. package/iso-systems.js +183 -146
  6. package/isometric-diagram.js +389 -0
  7. package/js/iso-core/arimo.js +5 -0
  8. package/js/iso-core/arimo.json +1 -0
  9. package/js/iso-core/index.js +8 -2
  10. package/js/iso-core/kernel.js +13 -2
  11. package/js/iso-core/mono.js +242 -0
  12. package/js/iso-editor/ui/canvas.js +23 -1
  13. package/js/iso-objects/ants.js +1 -1
  14. package/js/iso-objects/index.js +10 -2
  15. package/js/iso-objects/mono-paint.js +96 -0
  16. package/js/iso-objects/motion-doc.js +0 -79
  17. package/js/iso-objects/motion-entry.js +4 -2
  18. package/js/iso-objects/motion-schema.js +83 -0
  19. package/js/iso-objects/motion.js +9 -4
  20. package/js/iso-objects/timeline.js +60 -16
  21. package/js/iso-systems/compile.js +34 -3
  22. package/js/iso-systems/render.js +1 -1
  23. package/js/iso-systems/schema.json +1 -0
  24. package/js/iso-viewer/index.js +6 -0
  25. package/js/iso-viewer/page.js +40 -17
  26. package/js/iso-viewer/play.js +340 -0
  27. package/js/iso-viewer/player.js +147 -162
  28. package/js/iso-viewer/transport.js +289 -0
  29. package/package.json +61 -2
  30. package/src/iso-core/arimo.json +1 -0
  31. package/src/iso-core/arimo.ts +6 -0
  32. package/src/iso-core/index.ts +2 -1
  33. package/src/iso-core/kernel.ts +11 -1
  34. package/src/iso-core/mono.ts +306 -0
  35. package/src/iso-core/theme.ts +2 -1
  36. package/src/iso-editor/ui/canvas.ts +14 -1
  37. package/src/iso-objects/ants.ts +2 -2
  38. package/src/iso-objects/index.ts +5 -3
  39. package/src/iso-objects/mono-paint.ts +97 -0
  40. package/src/iso-objects/motion-doc.ts +0 -52
  41. package/src/iso-objects/motion-entry.ts +4 -3
  42. package/src/iso-objects/motion-schema.ts +55 -0
  43. package/src/iso-objects/motion.ts +6 -5
  44. package/src/iso-objects/scene.ts +3 -0
  45. package/src/iso-objects/timeline.ts +71 -15
  46. package/src/iso-objects/types.ts +2 -0
  47. package/src/iso-systems/compile.ts +37 -4
  48. package/src/iso-systems/render.ts +5 -1
  49. package/src/iso-systems/schema.json +1 -0
  50. package/src/iso-viewer/index.ts +4 -0
  51. package/src/iso-viewer/page.ts +28 -12
  52. package/src/iso-viewer/play.ts +280 -0
  53. package/src/iso-viewer/player.ts +133 -134
  54. package/src/iso-viewer/transport.ts +272 -0
  55. package/types/iso-core/arimo.d.ts +2 -0
  56. package/types/iso-core/index.d.ts +2 -1
  57. package/types/iso-core/kernel.d.ts +9 -0
  58. package/types/iso-core/mono.d.ts +61 -0
  59. package/types/iso-core/theme.d.ts +2 -0
  60. package/types/iso-objects/ants.d.ts +1 -0
  61. package/types/iso-objects/index.d.ts +5 -3
  62. package/types/iso-objects/mono-paint.d.ts +20 -0
  63. package/types/iso-objects/motion-doc.d.ts +0 -594
  64. package/types/iso-objects/motion-entry.d.ts +4 -3
  65. package/types/iso-objects/motion-schema.d.ts +594 -0
  66. package/types/iso-objects/motion.d.ts +4 -2
  67. package/types/iso-objects/scene.d.ts +3 -0
  68. package/types/iso-objects/timeline.d.ts +26 -3
  69. package/types/iso-objects/types.d.ts +2 -0
  70. package/types/iso-systems/compile.d.ts +8 -0
  71. package/types/iso-systems/render.d.ts +4 -0
  72. package/types/iso-viewer/index.d.ts +4 -0
  73. package/types/iso-viewer/play.d.ts +37 -0
  74. package/types/iso-viewer/transport.d.ts +73 -0
  75. package/types/player/isometric-diagram.d.ts +24 -0
  76. package/types/remotion/entry.d.ts +2 -0
  77. package/types/remotion/frames.d.ts +70 -0
  78. package/types/remotion/index.d.ts +39 -0
@@ -0,0 +1,289 @@
1
+ function pageClock() {
2
+ const g = globalThis;
3
+ return {
4
+ now: () => performance.now(),
5
+ next(f) {
6
+ const id = {};
7
+ const once = () => {
8
+ if (id.raf !== void 0) g.cancelAnimationFrame?.(id.raf);
9
+ clearTimeout(id.timer);
10
+ f();
11
+ };
12
+ id.raf = g.requestAnimationFrame?.(once);
13
+ id.timer = setTimeout(once, id.raf === void 0 ? 16 : 100);
14
+ return id;
15
+ },
16
+ cancel(id) {
17
+ const x = id;
18
+ if (x.raf !== void 0) g.cancelAnimationFrame?.(x.raf);
19
+ clearTimeout(x.timer);
20
+ }
21
+ };
22
+ }
23
+ const BACK_WITHIN = 400;
24
+ function transport(tl0, o = {}) {
25
+ const clock = o.clock ?? pageClock();
26
+ let tl = tl0, T = 0, rate = good(o.rate ?? 1), loop = o.loop ?? false, playing = false, active = true, gone = false;
27
+ let on = (o.ambient ?? tl.ambient) === "on";
28
+ let A = on ? 0 : "off";
29
+ let pending, last = 0, beat = tl.beatAt(0), told = false, turn = 0, until;
30
+ const subs = {};
31
+ function good(r) {
32
+ if (!(Number.isFinite(r) && r > 0)) throw new Error("rate is a number over 0");
33
+ return r;
34
+ }
35
+ const clamp = (ms) => Math.max(0, Math.min(tl.duration, ms));
36
+ function emit(k, ...a) {
37
+ for (const f of [...subs[k] ?? []]) f(...a);
38
+ }
39
+ const moves = () => active && !gone && (playing || on && tl.loops);
40
+ function arm() {
41
+ if (moves()) {
42
+ if (pending === void 0) {
43
+ last = clock.now();
44
+ pending = clock.next(tick);
45
+ }
46
+ } else if (pending !== void 0) {
47
+ clock.cancel(pending);
48
+ pending = void 0;
49
+ }
50
+ }
51
+ function passed(from, to) {
52
+ const mine = turn;
53
+ for (const b of tl.beats) {
54
+ if (b.start <= from || b.start > to || b.index === beat?.index) continue;
55
+ beat = b;
56
+ told = true;
57
+ emit("beat", b, "play");
58
+ if (turn !== mine) return false;
59
+ }
60
+ return true;
61
+ }
62
+ function play1(dt) {
63
+ if (!playing) {
64
+ emit("time", T, "ambient");
65
+ return;
66
+ }
67
+ const was = T, to = T + dt, mine = turn;
68
+ if (until !== void 0 && to >= until) {
69
+ T = until;
70
+ if (!passed(was, T)) return;
71
+ until = void 0;
72
+ playing = false;
73
+ emit("time", T, "play");
74
+ if (turn === mine) emit("pause");
75
+ return;
76
+ }
77
+ if (to < tl.duration) {
78
+ T = to;
79
+ if (passed(was, T)) emit("time", T, "play");
80
+ return;
81
+ }
82
+ if (loop) {
83
+ if (!passed(was, tl.duration)) return;
84
+ T = to % tl.duration;
85
+ if (on) A = T;
86
+ beat = void 0;
87
+ emit("loop");
88
+ if (turn !== mine) return;
89
+ const first = tl.beatAt(0);
90
+ if (first) {
91
+ beat = first;
92
+ emit("beat", first, "play");
93
+ if (turn !== mine || !passed(first.start, T)) return;
94
+ }
95
+ emit("time", T, "play");
96
+ return;
97
+ }
98
+ T = tl.duration;
99
+ if (!passed(was, T)) return;
100
+ playing = false;
101
+ emit("time", T, "play");
102
+ if (turn !== mine) return;
103
+ emit("pause");
104
+ if (turn !== mine) return;
105
+ emit("end");
106
+ }
107
+ function tick() {
108
+ pending = void 0;
109
+ const now = clock.now(), dt = Math.max(0, now - last) * rate;
110
+ last = now;
111
+ if (on && A !== "off") A += dt;
112
+ play1(dt);
113
+ if (pending === void 0) {
114
+ if (moves()) pending = clock.next(tick);
115
+ }
116
+ }
117
+ function land(how, again = false) {
118
+ const b = tl.beatAt(T);
119
+ turn++;
120
+ const mine = turn, other = b?.name !== beat?.name || b?.index !== beat?.index;
121
+ beat = b;
122
+ if (b && (other || again)) {
123
+ told = true;
124
+ emit("beat", b, how);
125
+ if (turn !== mine) return;
126
+ }
127
+ emit("time", T, how);
128
+ }
129
+ function seek(ms, o2 = {}) {
130
+ if (gone || !Number.isFinite(ms)) return;
131
+ const to = clamp(ms);
132
+ if (on && A !== "off") A = o2.join ? to : A + to - T;
133
+ T = to;
134
+ last = clock.now();
135
+ if (until !== void 0 && T >= until) until = void 0;
136
+ land("seek");
137
+ arm();
138
+ }
139
+ function restart() {
140
+ if (gone) return;
141
+ T = 0;
142
+ if (on) A = 0;
143
+ until = void 0;
144
+ last = clock.now();
145
+ land("seek", true);
146
+ arm();
147
+ }
148
+ const api = {
149
+ get timeline() {
150
+ return tl;
151
+ },
152
+ get duration() {
153
+ return tl.duration;
154
+ },
155
+ get time() {
156
+ return T;
157
+ },
158
+ get ambientTime() {
159
+ return A;
160
+ },
161
+ get playing() {
162
+ return playing;
163
+ },
164
+ get beat() {
165
+ return beat;
166
+ },
167
+ get cue() {
168
+ return tl.cues(T);
169
+ },
170
+ get rate() {
171
+ return rate;
172
+ },
173
+ set rate(r) {
174
+ const v = good(r);
175
+ if (v === rate) return;
176
+ rate = v;
177
+ emit("rate", v);
178
+ },
179
+ get loop() {
180
+ return loop;
181
+ },
182
+ set loop(v) {
183
+ loop = v;
184
+ },
185
+ get ambient() {
186
+ return on;
187
+ },
188
+ set ambient(v) {
189
+ if (gone || v === on) return;
190
+ on = v;
191
+ if (on && A === "off") A = beat?.start ?? 0;
192
+ arm();
193
+ emit("ambient", on);
194
+ emit("time", T, "ambient");
195
+ },
196
+ get active() {
197
+ return active;
198
+ },
199
+ set active(v) {
200
+ if (v === active) return;
201
+ active = v;
202
+ arm();
203
+ },
204
+ state: () => tl.at(T, { ambient: A }),
205
+ play(p = {}) {
206
+ if (gone || playing || tl.duration <= 0) return;
207
+ if (T >= tl.duration && p.until === void 0) restart();
208
+ until = p.until !== void 0 && p.until > T && p.until <= tl.duration ? p.until : void 0;
209
+ if (p.until !== void 0 && until === void 0) return;
210
+ playing = true;
211
+ last = clock.now();
212
+ arm();
213
+ emit("play");
214
+ if (playing && !told && beat) {
215
+ told = true;
216
+ emit("beat", beat, "play");
217
+ }
218
+ },
219
+ pause() {
220
+ if (!playing) return;
221
+ playing = false;
222
+ until = void 0;
223
+ turn++;
224
+ arm();
225
+ emit("pause");
226
+ },
227
+ toggle() {
228
+ if (playing) api.pause();
229
+ else api.play();
230
+ },
231
+ seek,
232
+ seekBeat(b) {
233
+ const ms = typeof b === "number" ? tl.beats[b]?.start : tl.beats.find((x) => x.name === b)?.start;
234
+ if (ms === void 0) return false;
235
+ seek(ms);
236
+ return true;
237
+ },
238
+ next() {
239
+ const n = tl.beats.find((b) => b.start > T);
240
+ seek(n ? n.start : tl.duration);
241
+ },
242
+ prev() {
243
+ const back = [...tl.beats].reverse().find((b) => b.start < T - BACK_WITHIN);
244
+ seek(back ? back.start : 0);
245
+ },
246
+ restart,
247
+ rebind(next) {
248
+ if (gone || !next.ok) return false;
249
+ until = void 0;
250
+ const was = tl.beatAt(T), frac = was ? (T - was.start) / Math.max(1, was.end - was.start) : 0, d = A === "off" ? 0 : A - T, before = tl;
251
+ tl = next;
252
+ if (was) {
253
+ const same = next.beats.find((b) => b.name === was.name);
254
+ if (same) T = same.start + frac * (same.end - same.start);
255
+ else {
256
+ const near = before.beats.filter((b) => b.index < was.index).reverse().map((b) => next.beats.find((x) => x.name === b.name)).find(Boolean);
257
+ T = near ? near.start : 0;
258
+ }
259
+ }
260
+ T = clamp(T);
261
+ if (on && A !== "off") A = T + d;
262
+ last = clock.now();
263
+ land("rebind");
264
+ arm();
265
+ return true;
266
+ },
267
+ on(k, f) {
268
+ const set = subs[k] ??= /* @__PURE__ */ new Set();
269
+ set.add(f);
270
+ return () => {
271
+ set.delete(f);
272
+ };
273
+ },
274
+ dispose() {
275
+ gone = true;
276
+ turn++;
277
+ playing = false;
278
+ if (pending !== void 0) clock.cancel(pending);
279
+ pending = void 0;
280
+ for (const k of Object.keys(subs)) subs[k].clear();
281
+ }
282
+ };
283
+ arm();
284
+ return api;
285
+ }
286
+ export {
287
+ pageClock,
288
+ transport
289
+ };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@johnoscott/isometric-engine",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "A generic isometric diagram engine: render (L0–L2) and editor (L0–L3), with a 2D view and a YAML diagram format.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "sideEffects": [
8
8
  "./src/**",
9
- "./js/**"
9
+ "./js/**",
10
+ "./isometric-diagram.js"
10
11
  ],
11
12
  "repository": {
12
13
  "type": "git",
@@ -28,6 +29,8 @@
28
29
  "iso-editor.d.ts",
29
30
  "iso-systems.js",
30
31
  "iso-systems.d.ts",
32
+ "isometric-diagram.js",
33
+ "iso-remotion.js",
31
34
  "types/",
32
35
  "assets/",
33
36
  "LICENSES/",
@@ -54,6 +57,25 @@
54
57
  "source": "./src/iso-objects/motion-entry.ts",
55
58
  "default": "./js/iso-objects/motion-entry.js"
56
59
  },
60
+ "./transport": {
61
+ "types": "./types/iso-viewer/transport.d.ts",
62
+ "source": "./src/iso-viewer/transport.ts",
63
+ "default": "./js/iso-viewer/transport.js"
64
+ },
65
+ "./player": {
66
+ "types": "./types/player/isometric-diagram.d.ts",
67
+ "default": "./isometric-diagram.js"
68
+ },
69
+ "./isometric-diagram.js": "./isometric-diagram.js",
70
+ "./remotion": {
71
+ "types": "./types/remotion/entry.d.ts",
72
+ "default": "./iso-remotion.js"
73
+ },
74
+ "./modules/iso-core/arimo": {
75
+ "types": "./types/iso-core/arimo.d.ts",
76
+ "source": "./src/iso-core/arimo.ts",
77
+ "default": "./js/iso-core/arimo.js"
78
+ },
57
79
  "./modules/iso-core/compile-schema": {
58
80
  "types": "./types/iso-core/compile-schema.d.ts",
59
81
  "source": "./src/iso-core/compile-schema.ts",
@@ -84,6 +106,11 @@
84
106
  "source": "./src/iso-core/kernel.ts",
85
107
  "default": "./js/iso-core/kernel.js"
86
108
  },
109
+ "./modules/iso-core/mono": {
110
+ "types": "./types/iso-core/mono.d.ts",
111
+ "source": "./src/iso-core/mono.ts",
112
+ "default": "./js/iso-core/mono.js"
113
+ },
87
114
  "./modules/iso-core/parse": {
88
115
  "types": "./types/iso-core/parse.d.ts",
89
116
  "source": "./src/iso-core/parse.ts",
@@ -179,6 +206,11 @@
179
206
  "source": "./src/iso-objects/looks.ts",
180
207
  "default": "./js/iso-objects/looks.js"
181
208
  },
209
+ "./modules/iso-objects/mono-paint": {
210
+ "types": "./types/iso-objects/mono-paint.d.ts",
211
+ "source": "./src/iso-objects/mono-paint.ts",
212
+ "default": "./js/iso-objects/mono-paint.js"
213
+ },
182
214
  "./modules/iso-objects/motion-builder": {
183
215
  "types": "./types/iso-objects/motion-builder.d.ts",
184
216
  "source": "./src/iso-objects/motion-builder.ts",
@@ -189,6 +221,11 @@
189
221
  "source": "./src/iso-objects/motion-doc.ts",
190
222
  "default": "./js/iso-objects/motion-doc.js"
191
223
  },
224
+ "./modules/iso-objects/motion-schema": {
225
+ "types": "./types/iso-objects/motion-schema.d.ts",
226
+ "source": "./src/iso-objects/motion-schema.ts",
227
+ "default": "./js/iso-objects/motion-schema.js"
228
+ },
192
229
  "./modules/iso-objects/motion": {
193
230
  "types": "./types/iso-objects/motion.d.ts",
194
231
  "source": "./src/iso-objects/motion.ts",
@@ -279,6 +316,11 @@
279
316
  "source": "./src/iso-viewer/page.ts",
280
317
  "default": "./js/iso-viewer/page.js"
281
318
  },
319
+ "./modules/iso-viewer/play": {
320
+ "types": "./types/iso-viewer/play.d.ts",
321
+ "source": "./src/iso-viewer/play.ts",
322
+ "default": "./js/iso-viewer/play.js"
323
+ },
282
324
  "./modules/iso-viewer/still": {
283
325
  "types": "./types/iso-viewer/still.d.ts",
284
326
  "source": "./src/iso-viewer/still.ts",
@@ -319,6 +361,11 @@
319
361
  "source": "./src/iso-viewer/timeline-time.ts",
320
362
  "default": "./js/iso-viewer/timeline-time.js"
321
363
  },
364
+ "./modules/iso-viewer/transport": {
365
+ "types": "./types/iso-viewer/transport.d.ts",
366
+ "source": "./src/iso-viewer/transport.ts",
367
+ "default": "./js/iso-viewer/transport.js"
368
+ },
322
369
  "./modules/iso-viewer/view-css": {
323
370
  "types": "./types/iso-viewer/view-css.d.ts",
324
371
  "source": "./src/iso-viewer/view-css.ts",
@@ -554,5 +601,17 @@
554
601
  },
555
602
  "./assets/*": "./assets/*",
556
603
  "./package.json": "./package.json"
604
+ },
605
+ "peerDependencies": {
606
+ "react": ">=18",
607
+ "remotion": ">=4.0.546"
608
+ },
609
+ "peerDependenciesMeta": {
610
+ "react": {
611
+ "optional": true
612
+ },
613
+ "remotion": {
614
+ "optional": true
615
+ }
557
616
  }
558
617
  }
@@ -0,0 +1 @@
1
+ {"sans700_13":{"0":0.5562,"1":0.5037,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.333,"\"":0.4741,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.7222,"'":0.2378,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.333,";":0.333,"<":0.584,"=":0.584,">":0.584,"?":0.6108,"@":0.9751,"A":0.7222,"B":0.7222,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5562,"K":0.7222,"L":0.6108,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.333,"\\":0.2778,"]":0.333,"^":0.584,"_":0.5562,"`":0.333,"a":0.5562,"b":0.6108,"c":0.5562,"d":0.6108,"e":0.5562,"f":0.333,"g":0.6108,"h":0.6108,"i":0.2778,"j":0.2778,"k":0.5562,"l":0.2778,"m":0.8892,"n":0.6108,"o":0.6108,"p":0.6108,"q":0.6108,"r":0.3892,"s":0.5562,"t":0.333,"u":0.6108,"v":0.5562,"w":0.7778,"x":0.5562,"y":0.5562,"z":0.5,"{":0.3892,"|":0.2798,"}":0.3892,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.2426,"‘":0.2426,"“":0.5,"”":0.5,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562},"sans800_15":{"0":0.5562,"1":0.5037,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.333,"\"":0.4741,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.7222,"'":0.2378,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.333,";":0.333,"<":0.584,"=":0.584,">":0.584,"?":0.6108,"@":0.9751,"A":0.7222,"B":0.7222,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5562,"K":0.7222,"L":0.6108,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.333,"\\":0.2778,"]":0.333,"^":0.584,"_":0.5562,"`":0.333,"a":0.5562,"b":0.6108,"c":0.5562,"d":0.6108,"e":0.5562,"f":0.333,"g":0.6108,"h":0.6108,"i":0.2778,"j":0.2778,"k":0.5562,"l":0.2778,"m":0.8892,"n":0.6108,"o":0.6108,"p":0.6108,"q":0.6108,"r":0.3892,"s":0.5562,"t":0.333,"u":0.6108,"v":0.5562,"w":0.7778,"x":0.5562,"y":0.5562,"z":0.5,"{":0.3892,"|":0.2798,"}":0.3892,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.2426,"‘":0.2426,"“":0.5,"”":0.5,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562},"sans800_10_5":{"0":0.5562,"1":0.5037,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.333,"\"":0.4741,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.7222,"'":0.2378,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.333,";":0.333,"<":0.584,"=":0.584,">":0.584,"?":0.6108,"@":0.9751,"A":0.7222,"B":0.7222,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5562,"K":0.7222,"L":0.6108,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.333,"\\":0.2778,"]":0.333,"^":0.584,"_":0.5562,"`":0.333,"a":0.5562,"b":0.6108,"c":0.5562,"d":0.6108,"e":0.5562,"f":0.333,"g":0.6108,"h":0.6108,"i":0.2778,"j":0.2778,"k":0.5562,"l":0.2778,"m":0.8892,"n":0.6108,"o":0.6108,"p":0.6108,"q":0.6108,"r":0.3892,"s":0.5562,"t":0.333,"u":0.6108,"v":0.5562,"w":0.7778,"x":0.5562,"y":0.5562,"z":0.5,"{":0.3892,"|":0.2798,"}":0.3892,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.2426,"‘":0.2426,"“":0.5,"”":0.5,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562},"sans600_12":{"0":0.5562,"1":0.4977,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.3146,"\"":0.4344,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.7038,"'":0.2222,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.3146,";":0.3146,"<":0.584,"=":0.584,">":0.584,"?":0.5926,"@":0.9884,"A":0.7038,"B":0.7038,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5374,"K":0.7038,"L":0.5926,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.3146,"\\":0.2778,"]":0.3146,"^":0.5457,"_":0.5562,"`":0.333,"a":0.5562,"b":0.5926,"c":0.5374,"d":0.5926,"e":0.5562,"f":0.3089,"g":0.5926,"h":0.5926,"i":0.2593,"j":0.2593,"k":0.5374,"l":0.2593,"m":0.8704,"n":0.5926,"o":0.5926,"p":0.5926,"q":0.5926,"r":0.3704,"s":0.5374,"t":0.3146,"u":0.5926,"v":0.5374,"w":0.7593,"x":0.5374,"y":0.5374,"z":0.5,"{":0.3708,"|":0.2731,"}":0.3708,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.2301,"‘":0.2301,"“":0.4443,"”":0.4443,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562},"sans800_12":{"0":0.5562,"1":0.5037,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.333,"\"":0.4741,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.7222,"'":0.2378,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.333,";":0.333,"<":0.584,"=":0.584,">":0.584,"?":0.6108,"@":0.9751,"A":0.7222,"B":0.7222,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5562,"K":0.7222,"L":0.6108,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.333,"\\":0.2778,"]":0.333,"^":0.584,"_":0.5562,"`":0.333,"a":0.5562,"b":0.6108,"c":0.5562,"d":0.6108,"e":0.5562,"f":0.333,"g":0.6108,"h":0.6108,"i":0.2778,"j":0.2778,"k":0.5562,"l":0.2778,"m":0.8892,"n":0.6108,"o":0.6108,"p":0.6108,"q":0.6108,"r":0.3892,"s":0.5562,"t":0.333,"u":0.6108,"v":0.5562,"w":0.7778,"x":0.5562,"y":0.5562,"z":0.5,"{":0.3892,"|":0.2798,"}":0.3892,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.2426,"‘":0.2426,"“":0.5,"”":0.5,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562},"sans800_11_5":{"0":0.5562,"1":0.5037,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.333,"\"":0.4741,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.7222,"'":0.2378,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.333,";":0.333,"<":0.584,"=":0.584,">":0.584,"?":0.6108,"@":0.9751,"A":0.7222,"B":0.7222,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5562,"K":0.7222,"L":0.6108,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.333,"\\":0.2778,"]":0.333,"^":0.584,"_":0.5562,"`":0.333,"a":0.5562,"b":0.6108,"c":0.5562,"d":0.6108,"e":0.5562,"f":0.333,"g":0.6108,"h":0.6108,"i":0.2778,"j":0.2778,"k":0.5562,"l":0.2778,"m":0.8892,"n":0.6108,"o":0.6108,"p":0.6108,"q":0.6108,"r":0.3892,"s":0.5562,"t":0.333,"u":0.6108,"v":0.5562,"w":0.7778,"x":0.5562,"y":0.5562,"z":0.5,"{":0.3892,"|":0.2798,"}":0.3892,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.2426,"‘":0.2426,"“":0.5,"”":0.5,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562},"sans400_13":{"0":0.5562,"1":0.4856,"2":0.5562,"3":0.5562,"4":0.5562,"5":0.5562,"6":0.5562,"7":0.5562,"8":0.5562,"9":0.5562," ":0.2778,"!":0.2778,"\"":0.355,"#":0.5562,"$":0.5562,"%":0.8892,"&":0.667,"'":0.1909,"(":0.333,")":0.333,"*":0.3892,"+":0.584,",":0.2778,"-":0.333,".":0.2778,"/":0.2778,":":0.2778,";":0.2778,"<":0.584,"=":0.584,">":0.584,"?":0.5562,"@":1.0151,"A":0.667,"B":0.667,"C":0.7222,"D":0.7222,"E":0.667,"F":0.6108,"G":0.7778,"H":0.7222,"I":0.2778,"J":0.5,"K":0.667,"L":0.5562,"M":0.833,"N":0.7222,"O":0.7778,"P":0.667,"Q":0.7778,"R":0.7222,"S":0.667,"T":0.6108,"U":0.7222,"V":0.667,"W":0.9438,"X":0.667,"Y":0.667,"Z":0.6108,"[":0.2778,"\\":0.2778,"]":0.2778,"^":0.4692,"_":0.5562,"`":0.333,"a":0.5562,"b":0.5562,"c":0.5,"d":0.5562,"e":0.5562,"f":0.2607,"g":0.5562,"h":0.5562,"i":0.2222,"j":0.2222,"k":0.5,"l":0.2222,"m":0.833,"n":0.5562,"o":0.5562,"p":0.5562,"q":0.5562,"r":0.333,"s":0.5,"t":0.2778,"u":0.5562,"v":0.5,"w":0.7222,"x":0.5,"y":0.5,"z":0.5,"{":0.334,"|":0.2598,"}":0.334,"~":0.584,"·":0.333,"→":1,"←":1,"↑":0.5,"↓":0.5,"’":0.205,"‘":0.205,"“":0.333,"”":0.333,"…":1,"–":0.5562,"—":1,"✕":0.7622,"×":0.584,"≈":0.5488,"≤":0.5488,"≥":0.5488,"é":0.5562}}
@@ -0,0 +1,6 @@
1
+ // Arimo (OFL 1.1; the font file is not here, nor in the package), measured: a second table beside the default's, for a drawing whose host
2
+ // loads that font. Its widths are Arial's, so Arial stands in for it. It has no monospace beside it: that text stays the system's.
3
+ import type { FontTable } from './kernel.ts';
4
+ import widths from './arimo.json' with { type: 'json' };
5
+
6
+ export const ARIMO: FontTable = { name: 'arimo', sans: 'Arimo, Arial, Helvetica, sans-serif', widths };
@@ -8,7 +8,7 @@
8
8
  // that never validates never carries ajv. shims/ are the browser's node:path and node:crypto, which the build aliases.
9
9
 
10
10
  // Named, not export *: with code splitting, esbuild keeps every module an export * reaches.
11
- export { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, apply, matStr, faceFrame, Bounds, Kernel, center } from './kernel.ts';
11
+ export { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, withFont, apply, matStr, faceFrame, Bounds, Kernel, center } from './kernel.ts';
12
12
  export type { P2, P3, Box, Attrs, FontKey, Font, Mat, Face, TextRect } from './kernel.ts';
13
13
  export { termLines, envelope, bubble, fileLines, keyGlyph, socketGlyph, screenFaces, screenGlass, placeholderFace } from './glyphs.ts';
14
14
  export type { FacePainter } from './glyphs.ts';
@@ -25,3 +25,4 @@ export type { SvgNode } from './svg-dom.ts';
25
25
  export { VEl, vdoc, serialize } from './vdom.ts';
26
26
  export type { VNode } from './vdom.ts';
27
27
  export { createHash, sha256Hex } from './shims/crypto.ts';
28
+ export { MONO, greyOf, contrast, monoOf, type MonoLook, type MonoTable, type MonoPattern } from './mono.ts';
@@ -48,8 +48,18 @@ export const FONTS = {
48
48
  badge: { key: 'sans800_11_5', size: 11.5 },
49
49
  } satisfies Record<string, Font>;
50
50
 
51
+ /** Another font's widths, by its name: never the default, and a drawing laid out with it says so. What it has no table for is the default's. */
52
+ export interface FontTable { name: string; /** its font-family, with what stands in for it */ sans: string; /** the mono text's, when it has one */ mono?: string; widths: Partial<Record<FontKey, Record<string, number>>> }
53
+ let using: FontTable | undefined;
54
+ /** runs `fn` (now: it may not wait for anything) with its text measured as that font's */
55
+ export function withFont<T>(f: FontTable | undefined, fn: () => T): T {
56
+ const was = using;
57
+ using = f;
58
+ try { return fn(); } finally { using = was; }
59
+ }
60
+
51
61
  export function textWidth(str: string, f: Font): number {
52
- const table = metrics[f.key] as Record<string, number>;
62
+ const table = (using?.widths[f.key] ?? metrics[f.key]) as Record<string, number>;
53
63
  const avg = f.key.startsWith('mono') ? 0.6 : 0.58;
54
64
  let w = 0;
55
65
  for (const ch of str) w += table[ch] ?? avg;