@johnoscott/isometric-engine 0.16.0 → 0.17.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.
- package/README.md +7 -1
- package/iso-editor.js +157 -154
- package/iso-remotion.js +353 -0
- package/iso-render.js +120 -117
- package/iso-systems.js +114 -111
- package/isometric-diagram.js +105 -102
- package/js/iso-core/arimo.js +5 -0
- package/js/iso-core/arimo.json +1 -0
- package/js/iso-core/index.js +3 -2
- package/js/iso-core/kernel.js +13 -2
- package/js/iso-objects/timeline.js +14 -6
- package/js/iso-systems/compile.js +13 -6
- package/js/iso-viewer/play.js +43 -8
- package/package.json +23 -1
- package/src/iso-core/arimo.json +1 -0
- package/src/iso-core/arimo.ts +6 -0
- package/src/iso-core/index.ts +1 -1
- package/src/iso-core/kernel.ts +11 -1
- package/src/iso-objects/timeline.ts +10 -2
- package/src/iso-systems/compile.ts +12 -6
- package/src/iso-viewer/play.ts +37 -9
- package/types/iso-core/arimo.d.ts +2 -0
- package/types/iso-core/index.d.ts +1 -1
- package/types/iso-core/kernel.d.ts +9 -0
- package/types/iso-objects/timeline.d.ts +4 -1
- package/types/iso-systems/compile.d.ts +3 -0
- package/types/iso-viewer/play.d.ts +2 -2
- package/types/remotion/entry.d.ts +2 -0
- package/types/remotion/frames.d.ts +71 -0
- package/types/remotion/index.d.ts +39 -0
|
@@ -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}}
|
package/js/iso-core/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, apply, matStr, faceFrame, Bounds, Kernel, center } from "./kernel.js";
|
|
1
|
+
import { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, withFont, apply, matStr, faceFrame, Bounds, Kernel, center } from "./kernel.js";
|
|
2
2
|
import { termLines, envelope, bubble, fileLines, keyGlyph, socketGlyph, screenFaces, screenGlass, placeholderFace } from "./glyphs.js";
|
|
3
3
|
import { depthSort } from "./depth.js";
|
|
4
4
|
import { loadTheme, extendTheme, colorRef, themeCss, themeParts } from "./theme.js";
|
|
@@ -56,5 +56,6 @@ export {
|
|
|
56
56
|
textWidth,
|
|
57
57
|
themeCss,
|
|
58
58
|
themeParts,
|
|
59
|
-
vdoc
|
|
59
|
+
vdoc,
|
|
60
|
+
withFont
|
|
60
61
|
};
|
package/js/iso-core/kernel.js
CHANGED
|
@@ -27,8 +27,18 @@ const FONTS = {
|
|
|
27
27
|
tunname: { key: "sans800_12", size: 12, spacing: 0.14 },
|
|
28
28
|
badge: { key: "sans800_11_5", size: 11.5 }
|
|
29
29
|
};
|
|
30
|
+
let using;
|
|
31
|
+
function withFont(f, fn) {
|
|
32
|
+
const was = using;
|
|
33
|
+
using = f;
|
|
34
|
+
try {
|
|
35
|
+
return fn();
|
|
36
|
+
} finally {
|
|
37
|
+
using = was;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
30
40
|
function textWidth(str, f) {
|
|
31
|
-
const table = metrics[f.key];
|
|
41
|
+
const table = using?.widths[f.key] ?? metrics[f.key];
|
|
32
42
|
const avg = f.key.startsWith("mono") ? 0.6 : 0.58;
|
|
33
43
|
let w = 0;
|
|
34
44
|
for (const ch of str) w += table[ch] ?? avg;
|
|
@@ -154,5 +164,6 @@ export {
|
|
|
154
164
|
n1,
|
|
155
165
|
pt,
|
|
156
166
|
tag,
|
|
157
|
-
textWidth
|
|
167
|
+
textWidth,
|
|
168
|
+
withFont
|
|
158
169
|
};
|
|
@@ -175,7 +175,7 @@ function bindMotion(drawing, doc, opts = {}) {
|
|
|
175
175
|
items.forEach((it, i) => {
|
|
176
176
|
if ("transition" in it) {
|
|
177
177
|
const t = it.transition, g = t.timing;
|
|
178
|
-
const length = t.presentation === "none" ? 0 :
|
|
178
|
+
const length = t.presentation === "none" ? 0 : transitionMs(g, fps);
|
|
179
179
|
into = { t, length };
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
@@ -213,6 +213,10 @@ function bindMotion(drawing, doc, opts = {}) {
|
|
|
213
213
|
n.layers.forEach((x, i) => visit(x, `${path}/layers/${i}`, abs));
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
+
if ("assemble" in n || "disassemble" in n) {
|
|
217
|
+
nodeEnd(n, path);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
216
220
|
if ("travel" in n) n.travel.forEach((x, i) => (Array.isArray(x) ? x : [x]).forEach((id, j) => need(id.split(":")[0], `${path}/travel/${i}${Array.isArray(x) ? `/${j}` : ""}`, "route")));
|
|
217
221
|
else if ("pulse" in n) needAll(n.pulse, `${path}/pulse`, "thing");
|
|
218
222
|
else if ("ants" in n) {
|
|
@@ -338,10 +342,7 @@ function bindMotion(drawing, doc, opts = {}) {
|
|
|
338
342
|
};
|
|
339
343
|
const entered = (k, T) => {
|
|
340
344
|
const p = top.list[k], lt = T - p.start;
|
|
341
|
-
if (p.into && p.into.length > 0)
|
|
342
|
-
const g = p.into.t.timing;
|
|
343
|
-
return "spring" in g ? lt >= p.into.length ? 1 : clamp(springAt(lt, { ...g.spring, overshootClamping: true }) / springAt(p.into.length, { ...g.spring, overshootClamping: true })) : clamp(lt / p.into.length);
|
|
344
|
-
}
|
|
345
|
+
if (p.into && p.into.length > 0) return transitionAt(p.into.t.timing, lt, p.into.length);
|
|
345
346
|
const e = p.s.enter;
|
|
346
347
|
if (!e) return 1;
|
|
347
348
|
const over = ms(e.fade, 0);
|
|
@@ -549,6 +550,11 @@ function bindMotion(drawing, doc, opts = {}) {
|
|
|
549
550
|
}
|
|
550
551
|
};
|
|
551
552
|
}
|
|
553
|
+
const transitionMs = (g, fps) => "linear" in g ? msOf(g.linear, fps) ?? 0 : msOf(g.spring.duration, fps) ?? settleMs(g.spring);
|
|
554
|
+
function transitionAt(g, t, length) {
|
|
555
|
+
if (length <= 0 || t >= length) return 1;
|
|
556
|
+
return "spring" in g ? clamp(springAt(t, { ...g.spring, overshootClamping: true }) / springAt(length, { ...g.spring, overshootClamping: true })) : clamp(t / length);
|
|
557
|
+
}
|
|
552
558
|
function settleMs(c) {
|
|
553
559
|
const m = c.mass ?? 1, k = c.stiffness ?? 100, d = c.damping ?? 10, w0 = Math.sqrt(k / m), z = Math.min(1, d / (2 * Math.sqrt(k * m)));
|
|
554
560
|
return Math.ceil(Math.log(200) / (z * w0) * 1e3 * (z >= 1 ? 1.6 : 1));
|
|
@@ -589,5 +595,7 @@ function motionOfSteps(scene) {
|
|
|
589
595
|
export {
|
|
590
596
|
bindMotion,
|
|
591
597
|
motionOfSteps,
|
|
592
|
-
motionSource
|
|
598
|
+
motionSource,
|
|
599
|
+
transitionAt,
|
|
600
|
+
transitionMs
|
|
593
601
|
};
|
|
@@ -3,8 +3,9 @@ import { validateSchema } from "./validate.js";
|
|
|
3
3
|
import { place } from "../iso-objects/place.js";
|
|
4
4
|
import { extendTheme, loadTheme } from "../iso-core/theme.js";
|
|
5
5
|
import { compileRaw } from "../iso-objects/compile.js";
|
|
6
|
-
import { resolveSvg } from "../iso-objects/resolve.js";
|
|
6
|
+
import { FONT_STACKS, resolveSvg } from "../iso-objects/resolve.js";
|
|
7
7
|
import { monoOfDrawing, paintMono } from "../iso-objects/mono-paint.js";
|
|
8
|
+
import { withFont } from "../iso-core/kernel.js";
|
|
8
9
|
import { bindMotion } from "../iso-objects/timeline.js";
|
|
9
10
|
import { antsOf } from "../iso-objects/ants.js";
|
|
10
11
|
import { drawLooks } from "../iso-objects/looks.js";
|
|
@@ -19,7 +20,8 @@ class CompileError extends Error {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
function compile(source, themeText, opts = {}) {
|
|
22
|
-
|
|
23
|
+
if (opts.font && !opts.resolveVars) throw new Error("font: a self-contained drawing's (resolveVars)");
|
|
24
|
+
const c = withFont(opts.font, () => compileAll(source, themeText, opts)), fonts = opts.font && { sans: opts.font.sans, mono: opts.font.mono ?? FONT_STACKS.mono };
|
|
23
25
|
if (!c.ok && opts.strict === "throw") throw new CompileError(c.diags);
|
|
24
26
|
if (!c.ok && opts.strict) c.scenes = [];
|
|
25
27
|
if (opts.stepMs !== void 0) for (const s of c.scenes) for (const st of s.steps.steps) st.duration = opts.stepMs;
|
|
@@ -30,10 +32,10 @@ function compile(source, themeText, opts = {}) {
|
|
|
30
32
|
if (opts.resolveVars) for (const s of c.scenes) {
|
|
31
33
|
const mode = opts.mode ?? "light", css = drawingCss(systems) + MARKS_CSS + GRID_CSS;
|
|
32
34
|
if (treatment) {
|
|
33
|
-
toMono(s, theme, mode, css, opts.mono);
|
|
35
|
+
toMono(s, theme, mode, css, opts.mono, fonts);
|
|
34
36
|
continue;
|
|
35
37
|
}
|
|
36
|
-
const o = { mode, theme: c.theme, css };
|
|
38
|
+
const o = { mode, theme: c.theme, css, fonts };
|
|
37
39
|
s.rendered.svg = resolveSvg(s.rendered.svg, o);
|
|
38
40
|
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, resolveSvg(v, o)]));
|
|
39
41
|
s.rendered.inks = {
|
|
@@ -42,16 +44,21 @@ function compile(source, themeText, opts = {}) {
|
|
|
42
44
|
kinds: Object.fromEntries(Object.entries(c.theme.kinds).map(([k, v]) => [k, c.theme[o.mode][v.color] ?? v.color]))
|
|
43
45
|
};
|
|
44
46
|
}
|
|
47
|
+
if (opts.font) for (const s of c.scenes) {
|
|
48
|
+
const name = opts.font.name, mark = (svg) => svg.replace("<svg ", `<svg data-font="${name.replace(/[^\w-]/g, "")}" `);
|
|
49
|
+
s.rendered.svg = mark(s.rendered.svg);
|
|
50
|
+
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, mark(v)]));
|
|
51
|
+
}
|
|
45
52
|
if (opts.resolveVars && treatment && theme) c.theme = { ...theme, kinds: Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => {
|
|
46
53
|
const d = c.scenes.map((s) => s.rendered.mono?.kinds[k]?.dash).find((x) => x && x.length > 1);
|
|
47
54
|
return [k, d ? { ...v, ants: [d[0], d[1]] } : v];
|
|
48
55
|
})) };
|
|
49
56
|
return c;
|
|
50
57
|
}
|
|
51
|
-
function toMono(s, theme, mode, css, own) {
|
|
58
|
+
function toMono(s, theme, mode, css, own, fonts) {
|
|
52
59
|
const all = [s.rendered.svg, ...Object.values(s.rendered.variants ?? {})];
|
|
53
60
|
const m = monoOfDrawing(all.join(""), theme, mode, [...s.routes.map((r) => r.kind), ...s.steps.kindsUsed], own);
|
|
54
|
-
const draw = (svg) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css }), m.look, s.id);
|
|
61
|
+
const draw = (svg) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css, fonts }), m.look, s.id);
|
|
55
62
|
s.rendered.svg = draw(s.rendered.svg);
|
|
56
63
|
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, draw(v)]));
|
|
57
64
|
s.rendered.inks = { surface: m.look.paper, control: m.look.ink, kinds: Object.fromEntries(Object.keys(theme.kinds).map((k) => [k, m.look.ink])) };
|
package/js/iso-viewer/play.js
CHANGED
|
@@ -34,8 +34,8 @@ function mountPlayer(host, o) {
|
|
|
34
34
|
let scene = o.scene, svg = svgOf(scene.rendered.svg), frozen, stepTo, userPaused = false, gone = false;
|
|
35
35
|
const tr = transport(o.timeline ?? NOTHING, { loop: o.loop, rate: o.rate, ambient: o.ambient, clock: o.clock });
|
|
36
36
|
const controls = o.controls ?? true;
|
|
37
|
-
const
|
|
38
|
-
let resting = calm;
|
|
37
|
+
const asked = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches, calm = asked && o.reducedMotion === "respect";
|
|
38
|
+
let resting = calm, off = false, inView = true;
|
|
39
39
|
const btn = (cls, label, text2, f) => h("button", { type: "button", class: `iso-play-btn ${cls}`, "aria-label": label, title: label, on: { click: f } }, text2);
|
|
40
40
|
const stage = h("div", { class: "iso-play-stage" }, svg);
|
|
41
41
|
const back = btn("back", "Back", "\u2039", () => byHand(() => step(Math.max(0, at() - 1))));
|
|
@@ -43,13 +43,16 @@ function mountPlayer(host, o) {
|
|
|
43
43
|
const next = btn("next", "Next", "\u203A", () => byHand(() => step(Math.min(tr.timeline.beats.length - 1, at() + 1))));
|
|
44
44
|
const again = btn("again", "Reset", "\u21BA", () => byHand(() => {
|
|
45
45
|
stop();
|
|
46
|
-
tr.
|
|
46
|
+
if (off) tr.seek(0);
|
|
47
|
+
else tr.restart();
|
|
47
48
|
}));
|
|
48
49
|
const amb = btn("ambient", "Ambient motion", "\u223F", () => {
|
|
49
50
|
wake();
|
|
50
51
|
tr.ambient = !tr.ambient;
|
|
51
52
|
show();
|
|
52
53
|
});
|
|
54
|
+
const still = btn("still", "Motion off", "Motion off", () => setOff(!off));
|
|
55
|
+
still.title = "Draw everything in place, with nothing moving";
|
|
53
56
|
const bar = h("input", { type: "range", class: "iso-play-bar", min: 0, step: 1, "aria-label": "Time", on: { input: (() => byHand(() => {
|
|
54
57
|
stop();
|
|
55
58
|
tr.seek(Number(bar.value));
|
|
@@ -60,12 +63,12 @@ function mountPlayer(host, o) {
|
|
|
60
63
|
const text = h("div", { class: "iso-play-text" }), code = h("pre", { class: "iso-play-code" }), facts = h("dl", { class: "iso-play-facts" });
|
|
61
64
|
const say = h("div", { class: "iso-play-say", "aria-live": "polite" }, h("div", { class: "iso-play-head" }, num, title, chapter, count), text, code, facts);
|
|
62
65
|
const list = h("details", { class: "iso-play-list" });
|
|
63
|
-
const row = h("div", { class: "iso-play-row" }, back, play, next, again, amb, bar, time);
|
|
66
|
+
const row = h("div", { class: "iso-play-row" }, back, play, next, again, amb, still, bar, time), alone = h("div", { class: "iso-play-row" });
|
|
64
67
|
const root = h(
|
|
65
68
|
"div",
|
|
66
69
|
{ class: "iso-play", role: "group", "aria-roledescription": "animated diagram", "aria-label": o.label ?? "Diagram", tabindex: controls ? 0 : void 0, "data-mode": o.mode ?? "light" },
|
|
67
70
|
stage,
|
|
68
|
-
controls
|
|
71
|
+
controls ? row : alone,
|
|
69
72
|
controls && dots,
|
|
70
73
|
controls && say,
|
|
71
74
|
controls && list
|
|
@@ -92,6 +95,9 @@ function mountPlayer(host, o) {
|
|
|
92
95
|
say.hidden = !said;
|
|
93
96
|
list.hidden = !said;
|
|
94
97
|
amb.hidden = !tr.timeline.loops;
|
|
98
|
+
still.hidden = !asked || calm || tr.duration <= 0 && !tr.timeline.loops || !controls && !o.autoplay && !tr.timeline.loops;
|
|
99
|
+
alone.hidden = still.hidden;
|
|
100
|
+
if (!controls && !still.hidden) alone.append(still);
|
|
95
101
|
bar.max = String(Math.round(tr.duration));
|
|
96
102
|
for (const el of [play, again, bar, time]) el.hidden = tr.duration <= 0;
|
|
97
103
|
told = void 0;
|
|
@@ -144,7 +150,7 @@ function mountPlayer(host, o) {
|
|
|
144
150
|
});
|
|
145
151
|
}
|
|
146
152
|
function show() {
|
|
147
|
-
const S = frozen !== void 0 ? tr.timeline.at(frozen, { ambient: frozen }) : resting ? lit(tr.timeline.at(tr.duration, { ambient: "off" })) : tr.state();
|
|
153
|
+
const S = frozen !== void 0 ? tr.timeline.at(frozen, { ambient: frozen }) : resting ? lit(tr.timeline.at(tr.duration, { ambient: "off" })) : off ? tr.timeline.at(tr.time, { ambient: "off" }) : tr.state();
|
|
148
154
|
paint(svg, S, scene.rendered, { styles: "cssom" });
|
|
149
155
|
root.dataset.time = String(Math.round(frozen ?? tr.time));
|
|
150
156
|
if (frozen !== void 0) marks(tr.timeline.beatAt(frozen));
|
|
@@ -162,6 +168,9 @@ function mountPlayer(host, o) {
|
|
|
162
168
|
amb.setAttribute("aria-pressed", String(tr.ambient));
|
|
163
169
|
say.setAttribute("aria-live", on ? "off" : "polite");
|
|
164
170
|
root.dataset.playing = String(on);
|
|
171
|
+
still.setAttribute("aria-pressed", String(off));
|
|
172
|
+
play.disabled = off;
|
|
173
|
+
amb.disabled = off;
|
|
165
174
|
}
|
|
166
175
|
const going = () => tr.playing && stepTo === void 0;
|
|
167
176
|
const at = () => tr.beat?.index ?? 0;
|
|
@@ -182,6 +191,21 @@ function mountPlayer(host, o) {
|
|
|
182
191
|
stepTo = void 0;
|
|
183
192
|
tr.pause();
|
|
184
193
|
}
|
|
194
|
+
function setOff(v) {
|
|
195
|
+
if (gone || v === off) return;
|
|
196
|
+
off = v;
|
|
197
|
+
resting = v;
|
|
198
|
+
told = void 0;
|
|
199
|
+
stop();
|
|
200
|
+
tr.active = inView && !off;
|
|
201
|
+
tr.seek(off ? tr.duration : 0);
|
|
202
|
+
if (off) list.open = true;
|
|
203
|
+
marks(tr.beat);
|
|
204
|
+
buttons();
|
|
205
|
+
show();
|
|
206
|
+
if (!off && o.autoplay === true && !userPaused) tr.play();
|
|
207
|
+
pick();
|
|
208
|
+
}
|
|
185
209
|
function step(i) {
|
|
186
210
|
const b = tr.timeline.beats[i];
|
|
187
211
|
if (!b || gone) return;
|
|
@@ -189,9 +213,16 @@ function mountPlayer(host, o) {
|
|
|
189
213
|
tr.seek(b.start, { join: true });
|
|
190
214
|
const nextStart = tr.timeline.beats[i + 1]?.start ?? Infinity;
|
|
191
215
|
stepTo = Math.max(b.start, Math.min(b.end, nextStart, tr.duration) - 1);
|
|
216
|
+
if (off) {
|
|
217
|
+
const to = stepTo;
|
|
218
|
+
stepTo = void 0;
|
|
219
|
+
tr.seek(to);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
192
222
|
tr.play({ until: stepTo });
|
|
193
223
|
}
|
|
194
224
|
function toggle() {
|
|
225
|
+
if (off) return;
|
|
195
226
|
wake();
|
|
196
227
|
if (going()) {
|
|
197
228
|
userPaused = true;
|
|
@@ -240,7 +271,7 @@ function mountPlayer(host, o) {
|
|
|
240
271
|
wants: o.autoplay === "visible" && !calm,
|
|
241
272
|
auto(on) {
|
|
242
273
|
if (on) {
|
|
243
|
-
if (!userPaused && !going()) {
|
|
274
|
+
if (!off && !userPaused && !going()) {
|
|
244
275
|
stepTo = void 0;
|
|
245
276
|
tr.play();
|
|
246
277
|
}
|
|
@@ -254,7 +285,8 @@ function mountPlayer(host, o) {
|
|
|
254
285
|
const io = typeof IntersectionObserver === "function" ? new IntersectionObserver((es) => {
|
|
255
286
|
for (const e of es) {
|
|
256
287
|
me.seen = e.isIntersecting ? e.intersectionRatio : 0;
|
|
257
|
-
|
|
288
|
+
inView = e.isIntersecting;
|
|
289
|
+
if (frozen === void 0) tr.active = inView && !off;
|
|
258
290
|
}
|
|
259
291
|
pick();
|
|
260
292
|
}, { threshold: [0, 0.2, 0.35, 0.5, 0.7, 0.9, 1] }) : void 0;
|
|
@@ -310,6 +342,9 @@ const PLAY_CSS = `
|
|
|
310
342
|
.iso-play-btn:hover{border-color:var(--ip-muted)}
|
|
311
343
|
.iso-play-btn.play{background:var(--ip-ink);color:var(--ip-bg);border-color:var(--ip-ink);min-width:44px}
|
|
312
344
|
.iso-play-btn.ambient[aria-pressed="false"]{color:var(--ip-muted);text-decoration:line-through}
|
|
345
|
+
.iso-play-btn.still{font-size:12px;white-space:nowrap}
|
|
346
|
+
.iso-play-btn.still[aria-pressed="true"]{background:var(--ip-ink);color:var(--ip-bg)}
|
|
347
|
+
.iso-play-btn:disabled{opacity:.4;cursor:default}
|
|
313
348
|
.iso-play-bar{flex:1 1 60px;min-width:0;accent-color:var(--ip-ink)}
|
|
314
349
|
.iso-play-time{color:var(--ip-muted);font-size:12px;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
315
350
|
.iso-play-dots{display:flex;flex-wrap:wrap;gap:4px 12px;padding:2px 12px}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnoscott/isometric-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
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",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"iso-systems.js",
|
|
31
31
|
"iso-systems.d.ts",
|
|
32
32
|
"isometric-diagram.js",
|
|
33
|
+
"iso-remotion.js",
|
|
33
34
|
"types/",
|
|
34
35
|
"assets/",
|
|
35
36
|
"LICENSES/",
|
|
@@ -66,6 +67,15 @@
|
|
|
66
67
|
"default": "./isometric-diagram.js"
|
|
67
68
|
},
|
|
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
|
+
},
|
|
69
79
|
"./modules/iso-core/compile-schema": {
|
|
70
80
|
"types": "./types/iso-core/compile-schema.d.ts",
|
|
71
81
|
"source": "./src/iso-core/compile-schema.ts",
|
|
@@ -591,5 +601,17 @@
|
|
|
591
601
|
},
|
|
592
602
|
"./assets/*": "./assets/*",
|
|
593
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
|
+
}
|
|
594
616
|
}
|
|
595
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 };
|
package/src/iso-core/index.ts
CHANGED
|
@@ -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';
|
package/src/iso-core/kernel.ts
CHANGED
|
@@ -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;
|
|
@@ -184,7 +184,7 @@ export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc
|
|
|
184
184
|
items.forEach((it, i) => {
|
|
185
185
|
if ('transition' in it) {
|
|
186
186
|
const t = it.transition, g = t.timing;
|
|
187
|
-
const length = t.presentation === 'none' ? 0 :
|
|
187
|
+
const length = t.presentation === 'none' ? 0 : transitionMs(g, fps);
|
|
188
188
|
into = { t, length };
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
@@ -217,6 +217,8 @@ export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc
|
|
|
217
217
|
if ('sequence' in n) { seq(n.sequence, `${path}/sequence`, at(ms(n.sequence.from, 0)), false); return; }
|
|
218
218
|
if ('series' in n) { for (const p of layoutSeries(n.series, `${path}/series`).list) seq(p.s, p.path, at(p.start), false); return; }
|
|
219
219
|
if ('layers' in n) { n.layers.forEach((x, i) => visit(x, `${path}/layers/${i}`, abs)); return; }
|
|
220
|
+
// its plan, whether or not its length was asked for (a beat that says its own length doesn't ask)
|
|
221
|
+
if ('assemble' in n || 'disassemble' in n) { nodeEnd(n, path); return; }
|
|
220
222
|
if ('travel' in n) n.travel.forEach((x, i) => (Array.isArray(x) ? x : [x]).forEach((id, j) => need(id.split(':')[0], `${path}/travel/${i}${Array.isArray(x) ? `/${j}` : ''}`, 'route')));
|
|
221
223
|
else if ('pulse' in n) needAll(n.pulse, `${path}/pulse`, 'thing');
|
|
222
224
|
else if ('ants' in n) { if (n.ants !== true) needAll(n.ants, `${path}/ants`, 'route'); }
|
|
@@ -301,7 +303,7 @@ export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc
|
|
|
301
303
|
/** how much of beat k has come in at T (1: all of it) */
|
|
302
304
|
const entered = (k: number, T: number) => {
|
|
303
305
|
const p = top.list[k], lt = T - p.start;
|
|
304
|
-
if (p.into && p.into.length > 0)
|
|
306
|
+
if (p.into && p.into.length > 0) return transitionAt(p.into.t.timing, lt, p.into.length);
|
|
305
307
|
const e = p.s.enter; if (!e) return 1;
|
|
306
308
|
const over = ms(e.fade, 0);
|
|
307
309
|
return over <= 0 ? 1 : easeOf(e.easing, over, 'ease')(clamp(lt / over));
|
|
@@ -457,6 +459,12 @@ export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc
|
|
|
457
459
|
},
|
|
458
460
|
};
|
|
459
461
|
}
|
|
462
|
+
/** how long a transition is, ms, and how far it is in at t of them */
|
|
463
|
+
export const transitionMs = (g: Transition['timing'], fps?: number): number => ('linear' in g ? msOf(g.linear, fps) ?? 0 : msOf(g.spring.duration, fps) ?? settleMs(g.spring));
|
|
464
|
+
export function transitionAt(g: Transition['timing'], t: number, length: number): number {
|
|
465
|
+
if (length <= 0 || t >= length) return 1;
|
|
466
|
+
return 'spring' in g ? clamp(springAt(t, { ...g.spring, overshootClamping: true }) / springAt(length, { ...g.spring, overshootClamping: true })) : clamp(t / length);
|
|
467
|
+
}
|
|
460
468
|
/** how long a spring takes to come to rest, ms: its envelope under half a percent */
|
|
461
469
|
function settleMs(c: { mass?: number; damping?: number; stiffness?: number }): number {
|
|
462
470
|
const m = c.mass ?? 1, k = c.stiffness ?? 100, d = c.damping ?? 10, w0 = Math.sqrt(k / m), z = Math.min(1, d / (2 * Math.sqrt(k * m)));
|
|
@@ -7,10 +7,11 @@ import { place } from '../iso-objects/place.ts';
|
|
|
7
7
|
import { extendTheme, loadTheme, type Theme } from '../iso-core/theme.ts';
|
|
8
8
|
import type { RawDiagram } from '../iso-objects/types.ts';
|
|
9
9
|
import { compileRaw, type Compiled } from '../iso-objects/compile.ts';
|
|
10
|
-
import { resolveSvg, type ThemeMode } from '../iso-objects/resolve.ts';
|
|
10
|
+
import { FONT_STACKS, resolveSvg, type ThemeMode } from '../iso-objects/resolve.ts';
|
|
11
11
|
import { monoOfDrawing, paintMono } from '../iso-objects/mono-paint.ts';
|
|
12
12
|
import type { MonoTable } from '../iso-core/mono.ts';
|
|
13
13
|
import type { CompiledScene } from '../iso-objects/compile.ts';
|
|
14
|
+
import { withFont, type FontTable } from '../iso-core/kernel.ts';
|
|
14
15
|
import { bindMotion } from '../iso-objects/timeline.ts';
|
|
15
16
|
import type { MotionDoc } from '../iso-objects/motion-doc.ts';
|
|
16
17
|
import { antsOf } from '../iso-objects/ants.ts';
|
|
@@ -31,6 +32,8 @@ export interface CompileOptions {
|
|
|
31
32
|
treatment?: 'mono' | 'none';
|
|
32
33
|
/** a host's own table, over the treatment's */
|
|
33
34
|
mono?: MonoTable;
|
|
35
|
+
/** (0.17.0) a self-contained drawing laid out with another font's widths (Arimo's: modules/iso-core/arimo), and asking for it. The host loads the font */
|
|
36
|
+
font?: FontTable;
|
|
34
37
|
/** a file with an error draws nothing: `scenes` is empty (true), or it throws ('throw'). Default: what could be laid
|
|
35
38
|
* out is in `scenes` all the same, with `ok` false */
|
|
36
39
|
strict?: boolean | 'throw';
|
|
@@ -43,7 +46,8 @@ export class CompileError extends Error {
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
export function compile(source: string, themeText: string, opts: CompileOptions = {}): Compiled {
|
|
46
|
-
|
|
49
|
+
if (opts.font && !opts.resolveVars) throw new Error('font: a self-contained drawing\'s (resolveVars)');
|
|
50
|
+
const c = withFont(opts.font, () => compileAll(source, themeText, opts)), fonts = opts.font && { sans: opts.font.sans, mono: opts.font.mono ?? FONT_STACKS.mono };
|
|
47
51
|
if (!c.ok && opts.strict === 'throw') throw new CompileError(c.diags);
|
|
48
52
|
if (!c.ok && opts.strict) c.scenes = [];
|
|
49
53
|
if (opts.stepMs !== undefined) for (const s of c.scenes) for (const st of s.steps.steps) st.duration = opts.stepMs;
|
|
@@ -53,23 +57,25 @@ export function compile(source: string, themeText: string, opts: CompileOptions
|
|
|
53
57
|
const theme = c.theme;
|
|
54
58
|
if (opts.resolveVars) for (const s of c.scenes) {
|
|
55
59
|
const mode = opts.mode ?? 'light', css = drawingCss(systems) + MARKS_CSS + GRID_CSS;
|
|
56
|
-
if (treatment) { toMono(s, theme!, mode, css, opts.mono); continue; }
|
|
57
|
-
const o = { mode, theme: c.theme!, css } as const;
|
|
60
|
+
if (treatment) { toMono(s, theme!, mode, css, opts.mono, fonts); continue; }
|
|
61
|
+
const o = { mode, theme: c.theme!, css, fonts } as const;
|
|
58
62
|
s.rendered.svg = resolveSvg(s.rendered.svg, o);
|
|
59
63
|
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, resolveSvg(v, o)]));
|
|
60
64
|
s.rendered.inks = { surface: c.theme![o.mode].surface ?? c.theme!.light.surface, control: c.theme![o.mode].control ?? c.theme!.light.control,
|
|
61
65
|
kinds: Object.fromEntries(Object.entries(c.theme!.kinds).map(([k, v]) => [k, c.theme![o.mode][v.color] ?? v.color])) };
|
|
62
66
|
}
|
|
67
|
+
// it says which font it was laid out with (nothing: the default)
|
|
68
|
+
if (opts.font) for (const s of c.scenes) { const name = opts.font.name, mark = (svg: string) => svg.replace('<svg ', `<svg data-font="${name.replace(/[^\w-]/g, '')}" `); s.rendered.svg = mark(s.rendered.svg); if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, mark(v)])); }
|
|
63
69
|
// its connectors march in their own rhythms
|
|
64
70
|
if (opts.resolveVars && treatment && theme) c.theme = { ...theme, kinds: Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => { const d = c.scenes.map(s => s.rendered.mono?.kinds[k]?.dash).find(x => x && x.length > 1); return [k, d ? { ...v, ants: [d[0], d[1]] as [number, number] } : v]; })) };
|
|
65
71
|
return c;
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
/** a scene in black and white: its drawing and its looks alike, by one table */
|
|
69
|
-
function toMono(s: CompiledScene, theme: Theme, mode: ThemeMode, css: string, own?: MonoTable) {
|
|
75
|
+
function toMono(s: CompiledScene, theme: Theme, mode: ThemeMode, css: string, own?: MonoTable, fonts?: { sans: string; mono: string }) {
|
|
70
76
|
const all = [s.rendered.svg, ...Object.values(s.rendered.variants ?? {})];
|
|
71
77
|
const m = monoOfDrawing(all.join(''), theme, mode, [...s.routes.map(r => r.kind), ...s.steps.kindsUsed], own);
|
|
72
|
-
const draw = (svg: string) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css }), m.look, s.id);
|
|
78
|
+
const draw = (svg: string) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css, fonts }), m.look, s.id);
|
|
73
79
|
s.rendered.svg = draw(s.rendered.svg);
|
|
74
80
|
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, draw(v)]));
|
|
75
81
|
s.rendered.inks = { surface: m.look.paper, control: m.look.ink, kinds: Object.fromEntries(Object.keys(theme.kinds).map(k => [k, m.look.ink])) };
|