@johnoscott/isometric-engine 0.16.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.
@@ -0,0 +1,5 @@
1
+ import widths from "./arimo.json" with { type: "json" };
2
+ const ARIMO = { name: "arimo", sans: "Arimo, Arial, Helvetica, sans-serif", widths };
3
+ export {
4
+ ARIMO
5
+ };
@@ -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}}
@@ -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
  };
@@ -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 : "linear" in g ? ms(g.linear, 0) : ms(g.spring.duration, settleMs(g.spring));
178
+ const length = t.presentation === "none" ? 0 : transitionMs(g, fps);
179
179
  into = { t, length };
180
180
  return;
181
181
  }
@@ -338,10 +338,7 @@ function bindMotion(drawing, doc, opts = {}) {
338
338
  };
339
339
  const entered = (k, T) => {
340
340
  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
- }
341
+ if (p.into && p.into.length > 0) return transitionAt(p.into.t.timing, lt, p.into.length);
345
342
  const e = p.s.enter;
346
343
  if (!e) return 1;
347
344
  const over = ms(e.fade, 0);
@@ -549,6 +546,11 @@ function bindMotion(drawing, doc, opts = {}) {
549
546
  }
550
547
  };
551
548
  }
549
+ const transitionMs = (g, fps) => "linear" in g ? msOf(g.linear, fps) ?? 0 : msOf(g.spring.duration, fps) ?? settleMs(g.spring);
550
+ function transitionAt(g, t, length) {
551
+ if (length <= 0 || t >= length) return 1;
552
+ return "spring" in g ? clamp(springAt(t, { ...g.spring, overshootClamping: true }) / springAt(length, { ...g.spring, overshootClamping: true })) : clamp(t / length);
553
+ }
552
554
  function settleMs(c) {
553
555
  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
556
  return Math.ceil(Math.log(200) / (z * w0) * 1e3 * (z >= 1 ? 1.6 : 1));
@@ -589,5 +591,7 @@ function motionOfSteps(scene) {
589
591
  export {
590
592
  bindMotion,
591
593
  motionOfSteps,
592
- motionSource
594
+ motionSource,
595
+ transitionAt,
596
+ transitionMs
593
597
  };
@@ -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
- const c = compileAll(source, themeText, opts);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnoscott/isometric-engine",
3
- "version": "0.16.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",
@@ -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 };
@@ -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';
@@ -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 : 'linear' in g ? ms(g.linear, 0) : ms(g.spring.duration, settleMs(g.spring));
187
+ const length = t.presentation === 'none' ? 0 : transitionMs(g, fps);
188
188
  into = { t, length };
189
189
  return;
190
190
  }
@@ -301,7 +301,7 @@ export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc
301
301
  /** how much of beat k has come in at T (1: all of it) */
302
302
  const entered = (k: number, T: number) => {
303
303
  const p = top.list[k], lt = T - p.start;
304
- if (p.into && p.into.length > 0) { const g = p.into.t.timing; 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); }
304
+ if (p.into && p.into.length > 0) return transitionAt(p.into.t.timing, lt, p.into.length);
305
305
  const e = p.s.enter; if (!e) return 1;
306
306
  const over = ms(e.fade, 0);
307
307
  return over <= 0 ? 1 : easeOf(e.easing, over, 'ease')(clamp(lt / over));
@@ -457,6 +457,12 @@ export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc
457
457
  },
458
458
  };
459
459
  }
460
+ /** how long a transition is, ms, and how far it is in at t of them */
461
+ 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));
462
+ export function transitionAt(g: Transition['timing'], t: number, length: number): number {
463
+ if (length <= 0 || t >= length) return 1;
464
+ return 'spring' in g ? clamp(springAt(t, { ...g.spring, overshootClamping: true }) / springAt(length, { ...g.spring, overshootClamping: true })) : clamp(t / length);
465
+ }
460
466
  /** how long a spring takes to come to rest, ms: its envelope under half a percent */
461
467
  function settleMs(c: { mass?: number; damping?: number; stiffness?: number }): number {
462
468
  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
- const c = compileAll(source, themeText, opts);
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])) };
@@ -0,0 +1,2 @@
1
+ import type { FontTable } from './kernel.js';
2
+ export declare const ARIMO: FontTable;
@@ -1,4 +1,4 @@
1
- export { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, apply, matStr, faceFrame, Bounds, Kernel, center } from './kernel.js';
1
+ export { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, withFont, apply, matStr, faceFrame, Bounds, Kernel, center } from './kernel.js';
2
2
  export type { P2, P3, Box, Attrs, FontKey, Font, Mat, Face, TextRect } from './kernel.js';
3
3
  export { termLines, envelope, bubble, fileLines, keyGlyph, socketGlyph, screenFaces, screenGlass, placeholderFace } from './glyphs.js';
4
4
  export type { FacePainter } from './glyphs.js';
@@ -63,6 +63,15 @@ export declare const FONTS: {
63
63
  size: number;
64
64
  };
65
65
  };
66
+ /** 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. */
67
+ export interface FontTable {
68
+ name: string; /** its font-family, with what stands in for it */
69
+ sans: string; /** the mono text's, when it has one */
70
+ mono?: string;
71
+ widths: Partial<Record<FontKey, Record<string, number>>>;
72
+ }
73
+ /** runs `fn` (now: it may not wait for anything) with its text measured as that font's */
74
+ export declare function withFont<T>(f: FontTable | undefined, fn: () => T): T;
66
75
  export declare function textWidth(str: string, f: Font): number;
67
76
  /** [a b c d e f] as in SVG matrix(): x' = a x + c y + e, y' = b x + d y + f */
68
77
  export type Mat = [number, number, number, number, number, number];
@@ -1,7 +1,7 @@
1
1
  import type { CompiledScene } from './compile.js';
2
2
  import { antsOf } from './ants.js';
3
3
  import { type MotionModel, type SceneState } from './motion.js';
4
- import { type MotionDiag, type MotionDoc, type Say } from './motion-doc.js';
4
+ import { type MotionDiag, type MotionDoc, type Say, type Transition } from './motion-doc.js';
5
5
  export interface BeatInfo {
6
6
  name: string;
7
7
  index: number;
@@ -62,5 +62,8 @@ export interface MotionSource {
62
62
  }
63
63
  export declare function motionSource(scene: CompiledScene): MotionSource;
64
64
  export declare function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc, opts?: BindOptions): Timeline;
65
+ /** how long a transition is, ms, and how far it is in at t of them */
66
+ export declare const transitionMs: (g: Transition['timing'], fps?: number) => number;
67
+ export declare function transitionAt(g: Transition['timing'], t: number, length: number): number;
65
68
  /** A drawing's own steps as a motion document, so that every drawing with steps has a timeline. */
66
69
  export declare function motionOfSteps(scene: CompiledScene): MotionDoc;
@@ -2,6 +2,7 @@ import type { Diag } from '../iso-core/errors.js';
2
2
  import { type Compiled } from '../iso-objects/compile.js';
3
3
  import { type ThemeMode } from '../iso-objects/resolve.js';
4
4
  import type { MonoTable } from '../iso-core/mono.js';
5
+ import { type FontTable } from '../iso-core/kernel.js';
5
6
  export type { Compiled, CompiledScene } from '../iso-objects/compile.js';
6
7
  export interface CompileOptions {
7
8
  /** overrides every scene's grid snap (the editor's snap control) */
@@ -15,6 +16,8 @@ export interface CompileOptions {
15
16
  treatment?: 'mono' | 'none';
16
17
  /** a host's own table, over the treatment's */
17
18
  mono?: MonoTable;
19
+ /** (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 */
20
+ font?: FontTable;
18
21
  /** a file with an error draws nothing: `scenes` is empty (true), or it throws ('throw'). Default: what could be laid
19
22
  * out is in `scenes` all the same, with `ok` false */
20
23
  strict?: boolean | 'throw';
@@ -0,0 +1,2 @@
1
+ export * from './index.js';
2
+ export declare const DEFAULT_THEME: string;
@@ -0,0 +1,70 @@
1
+ import { type Compiled, type CompiledScene } from '../iso-systems/compile.js';
2
+ import { type Cue, type Timeline } from '../iso-objects/timeline.js';
3
+ import { type MotionDoc, type Transition } from '../iso-objects/motion-doc.js';
4
+ export interface DrawingProps {
5
+ /** the drawing's text */
6
+ src: string;
7
+ /** the theme's text */
8
+ theme: string;
9
+ /** default: the scene's own motion, else its steps */
10
+ motion?: MotionDoc;
11
+ /** the scene's id (default: the first) */
12
+ scene?: string;
13
+ mode?: 'light' | 'dark';
14
+ treatment?: 'mono' | 'none';
15
+ /** lay the text out with Arimo's widths, and ask for it (default: the system's). The video loads the font itself: isometricFonts */
16
+ font?: 'arimo';
17
+ /** the ambient clock: with the video (default), or 'off' */
18
+ ambient?: 'off';
19
+ }
20
+ export interface Drawing {
21
+ compiled: Compiled;
22
+ scene: CompiledScene;
23
+ timeline: Timeline;
24
+ }
25
+ /** Throws, with every fault, when the drawing or its motion has one: a video of half a drawing is worse than none. */
26
+ export declare function drawingOf(p: DrawingProps): Drawing;
27
+ /** a frame's moment, ms: its start. Fractional frames too (a playback rate gives them). */
28
+ export declare const timeOf: (frame: number, fps: number) => number;
29
+ /** how many frames show all of it: the last one is at its end or past it */
30
+ export declare const framesOf: (ms: number, fps: number) => number;
31
+ /** A frame's SVG, its ids with a prefix of this instance's own (a transition mounts two at once). */
32
+ export declare function frameSvg(d: Drawing, frame: number, fps: number, o?: {
33
+ prefix?: string;
34
+ ambient?: 'off';
35
+ }): string;
36
+ export declare const cueAt: (d: Drawing, frame: number, fps: number) => Cue | undefined;
37
+ /** Remotion's calculateMetadata: the video is as long as the drawing's motion. */
38
+ export declare const isometricMetadata: (o: {
39
+ fps: number;
40
+ width: number;
41
+ height: number;
42
+ }) => ({ props }: {
43
+ props: DrawingProps;
44
+ }) => {
45
+ fps: number;
46
+ width: number;
47
+ height: number;
48
+ durationInFrames: number;
49
+ };
50
+ /** What loadFont of Remotion's fonts package takes, for a font file of the host's own: `loadFont(isometricFonts({ url: staticFile('Arimo-wght.ttf') }))`.
51
+ * The package has no font file. */
52
+ export declare function isometricFonts(o: {
53
+ url: string;
54
+ format?: 'woff2' | 'woff' | 'opentype' | 'truetype';
55
+ }): {
56
+ family: string;
57
+ url: string;
58
+ weight: string;
59
+ format?: 'woff2' | 'woff' | 'opentype' | 'truetype';
60
+ };
61
+ /** A timing as the document's transitions have it: `{ linear: 400 }`, `{ linear: '12f' }`, `{ spring: { damping: 200 } }`. */
62
+ export declare function isometricTiming(timing: Transition['timing']): {
63
+ getDurationInFrames(o: {
64
+ fps: number;
65
+ }): number;
66
+ getProgress(o: {
67
+ frame: number;
68
+ fps: number;
69
+ }): number;
70
+ };
@@ -0,0 +1,39 @@
1
+ import { type CSSProperties, type ReactElement, type ReactNode } from 'react';
2
+ import type { BeatInfo, Cue } from '../iso-objects/timeline.js';
3
+ import { type DrawingProps } from './frames.js';
4
+ export { cueAt, drawingOf, frameSvg, framesOf, isometricFonts, isometricMetadata, isometricTiming, timeOf } from './frames.js';
5
+ export type { Drawing, DrawingProps } from './frames.js';
6
+ export interface IsometricSceneProps extends DrawingProps {
7
+ width?: number | string;
8
+ height?: number | string;
9
+ className?: string;
10
+ style?: CSSProperties;
11
+ /** what its ids begin with (default: this instance's own): a transition mounts two copies at once */
12
+ prefix?: string;
13
+ }
14
+ /** the props a presentation's component is given by Remotion's transitions */
15
+ interface PresentationProps {
16
+ children?: ReactNode;
17
+ presentationDirection: 'entering' | 'exiting';
18
+ presentationProgress: number;
19
+ presentationDurationInFrames?: number;
20
+ passedProps: IsometricPresentationProps;
21
+ }
22
+ export interface IsometricPresentationProps extends Record<string, unknown> {
23
+ /** what the scene going out does: fades too (default: a drawing has no ground of its own, so it would show through), or stays */
24
+ exiting?: 'fade' | 'stay';
25
+ }
26
+ /** The document's 'fade', between two scenes of a TransitionSeries: `presentation={isometricPresentation()}`. */
27
+ export declare function isometricPresentation(props?: IsometricPresentationProps): {
28
+ component: (p: PresentationProps) => ReactElement;
29
+ props: IsometricPresentationProps;
30
+ };
31
+ /** The drawing at the current frame (a Sequence's own, inside one). */
32
+ export declare function IsometricScene(p: IsometricSceneProps): ReactElement;
33
+ /** The commentary now: for a caption of the host's own. */
34
+ export declare function useIsometricCues(p: DrawingProps): Cue | undefined;
35
+ export interface IsometricSequencesProps extends DrawingProps {
36
+ children: (beat: BeatInfo) => ReactNode;
37
+ }
38
+ /** A Remotion Sequence for each beat, by its name (so Studio's timeline shows them), with what the host puts in it. */
39
+ export declare function IsometricSequences(p: IsometricSequencesProps): ReactElement;