vizmatic 0.5.0 → 0.6.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.
@@ -4089,8 +4089,17 @@ function readPairs(r, sub) {
4089
4089
  var FILES = {
4090
4090
  sans: { "400": "Inter-Regular.ttf", "600": "Inter-SemiBold.ttf", "700": "Inter-Bold.ttf" },
4091
4091
  serif: { "400": "InstrumentSerif-Regular.ttf", "italic": "InstrumentSerif-Italic.ttf" },
4092
+ "text-serif": { "400": "SourceSerif4-24pt-Regular.ttf", "italic": "SourceSerif4-24pt-Italic.ttf" },
4092
4093
  mono: { "400": "JetBrainsMono-Regular.ttf" },
4093
- noto: { "400": "NotoSans-Regular.ttf" }
4094
+ noto: { "400": "NotoSans-Regular.ttf" },
4095
+ math: { "400": "NotoSansMath-Regular.ttf" }
4096
+ };
4097
+ var FALLBACKS = {
4098
+ sans: ["noto", "math"],
4099
+ serif: ["text-serif", "noto", "math"],
4100
+ "text-serif": ["noto", "math"],
4101
+ mono: ["noto", "math"],
4102
+ noto: ["math"]
4094
4103
  };
4095
4104
  var fonts = /* @__PURE__ */ new Map();
4096
4105
  var pending = /* @__PURE__ */ new Map();
@@ -4109,6 +4118,14 @@ function fontFor(family, weight = 400, italic = false) {
4109
4118
  }
4110
4119
  throw new Suspend(waiting);
4111
4120
  }
4121
+ function fallbackGlyph(family, code, weight = 400, italic = false) {
4122
+ for (const next of FALLBACKS[family]) {
4123
+ const font = fontFor(next, weight, italic);
4124
+ const glyph = font.glyphFor(code);
4125
+ if (glyph !== 0) return { font, glyph };
4126
+ }
4127
+ return null;
4128
+ }
4112
4129
  var glyphPaths = /* @__PURE__ */ new WeakMap();
4113
4130
  function glyphPath(font, glyph, size) {
4114
4131
  let bySize = glyphPaths.get(font);
@@ -4154,7 +4171,10 @@ function centered(path) {
4154
4171
  }
4155
4172
  function text(content, options = {}) {
4156
4173
  const size = options.size ?? 40;
4157
- const font = fontFor(options.font ?? "sans", options.weight ?? 400, options.italic ?? false);
4174
+ const family = options.font ?? "sans";
4175
+ const weight = options.weight ?? 400;
4176
+ const italic = options.italic ?? false;
4177
+ const font = fontFor(family, weight, italic);
4158
4178
  const scale = size / font.unitsPerEm;
4159
4179
  const tracking = (options.tracking ?? 0) * size;
4160
4180
  const leading = (options.leading ?? 1.3) * size;
@@ -4162,14 +4182,23 @@ function text(content, options = {}) {
4162
4182
  const source = options.uppercase ? content.toUpperCase() : content;
4163
4183
  const measureWord = (word) => {
4164
4184
  const glyphs = [];
4165
- let x = 0, previous = 0;
4185
+ let x = 0, previous = 0, previousFont = null;
4166
4186
  for (const char of word) {
4167
4187
  const code = char.codePointAt(0);
4168
- const glyph = font.glyphFor(code);
4169
- if (previous) x += font.kern(previous, glyph) * scale;
4170
- glyphs.push({ code, glyph, x, char });
4171
- x += font.advance(glyph) * scale + tracking;
4188
+ let owner = font, glyph = font.glyphFor(code);
4189
+ if (glyph === 0) {
4190
+ const found = fallbackGlyph(family, code, weight, italic);
4191
+ if (found) {
4192
+ owner = found.font;
4193
+ glyph = found.glyph;
4194
+ }
4195
+ }
4196
+ const ownerScale = size / owner.unitsPerEm;
4197
+ if (previous && previousFont === owner) x += owner.kern(previous, glyph) * ownerScale;
4198
+ glyphs.push({ font: owner, glyph, x, char });
4199
+ x += owner.advance(glyph) * ownerScale + tracking;
4172
4200
  previous = glyph;
4201
+ previousFont = owner;
4173
4202
  }
4174
4203
  return { glyphs, width: x };
4175
4204
  };
@@ -4199,13 +4228,14 @@ function text(content, options = {}) {
4199
4228
  lines.forEach((line, row) => {
4200
4229
  const start = align === "left" ? 0 : align === "center" ? (blockWidth - line.width) / 2 : blockWidth - line.width;
4201
4230
  for (const placed of line.glyphs) {
4202
- const path = glyphPath(font, placed.glyph, size);
4231
+ const path = glyphPath(placed.font, placed.glyph, size);
4203
4232
  if (path.length === 0) continue;
4204
4233
  const shape = centered(path);
4205
4234
  const leaf = new Node(shape.path).at(start + placed.x + shape.x, row * leading + shape.y);
4206
4235
  leaf.base.fill = paint;
4207
4236
  leaf.base.trimEach = true;
4208
4237
  leaf.data["key"] = placed.char;
4238
+ if (placed.glyph === 0) leaf.data["missingGlyph"] = true;
4209
4239
  node.chars.push(leaf);
4210
4240
  node.children.push(leaf);
4211
4241
  leaf.parent = node;
@@ -10,7 +10,7 @@ import {
10
10
  isFilm,
11
11
  isSuspend,
12
12
  parseColor
13
- } from "./chunk-WHT6HRMX.js";
13
+ } from "./chunk-5ZAFH2JC.js";
14
14
  import "./chunk-MLKGABMK.js";
15
15
 
16
16
  // src/stage/export.ts
package/dist/stage.cjs CHANGED
@@ -2581,7 +2581,7 @@ function ghost(stage, from, to2, ctx) {
2581
2581
  node.tween("strokeOpacity", to2.strokeOpacity, ctx.t0, ctx.t1, ctx.ease);
2582
2582
  node.tween("strokeWidth", to2.strokeWidth || from.strokeWidth, ctx.t0, ctx.t1, ctx.ease);
2583
2583
  if (from.glow !== to2.glow) node.tween("glow", to2.glow, ctx.t0, ctx.t1, ctx.ease);
2584
- stepAt(node, "visible", false, ctx.t1);
2584
+ stepAt(node, "visible", false, ctx.hide ?? ctx.t1);
2585
2585
  return node;
2586
2586
  }
2587
2587
  function pairCounts(from, to2) {
@@ -2615,7 +2615,7 @@ function morph(from, to2, options = {}) {
2615
2615
  const each = (ctx.t1 - ctx.t0) / (1 + Math.max(0, pairs.length - 1) * lag);
2616
2616
  pairs.forEach(([x, y], i) => {
2617
2617
  const start = ctx.t0 + i * lag * each;
2618
- ghost(ctx.stage, x, y, { t0: start, t1: start + each, ease: ctx.ease, appear: ctx.t0 });
2618
+ ghost(ctx.stage, x, y, { t0: start, t1: start + each, ease: ctx.ease, appear: ctx.t0, hide: ctx.t1 });
2619
2619
  });
2620
2620
  finishMorph(a, b, ctx);
2621
2621
  }
@@ -3934,8 +3934,17 @@ function readPairs(r, sub) {
3934
3934
  var FILES = {
3935
3935
  sans: { "400": "Inter-Regular.ttf", "600": "Inter-SemiBold.ttf", "700": "Inter-Bold.ttf" },
3936
3936
  serif: { "400": "InstrumentSerif-Regular.ttf", "italic": "InstrumentSerif-Italic.ttf" },
3937
+ "text-serif": { "400": "SourceSerif4-24pt-Regular.ttf", "italic": "SourceSerif4-24pt-Italic.ttf" },
3937
3938
  mono: { "400": "JetBrainsMono-Regular.ttf" },
3938
- noto: { "400": "NotoSans-Regular.ttf" }
3939
+ noto: { "400": "NotoSans-Regular.ttf" },
3940
+ math: { "400": "NotoSansMath-Regular.ttf" }
3941
+ };
3942
+ var FALLBACKS = {
3943
+ sans: ["noto", "math"],
3944
+ serif: ["text-serif", "noto", "math"],
3945
+ "text-serif": ["noto", "math"],
3946
+ mono: ["noto", "math"],
3947
+ noto: ["math"]
3939
3948
  };
3940
3949
  var fonts = /* @__PURE__ */ new Map();
3941
3950
  var pending = /* @__PURE__ */ new Map();
@@ -3954,6 +3963,14 @@ function fontFor(family, weight = 400, italic = false) {
3954
3963
  }
3955
3964
  throw new Suspend(waiting);
3956
3965
  }
3966
+ function fallbackGlyph(family, code, weight = 400, italic = false) {
3967
+ for (const next of FALLBACKS[family]) {
3968
+ const font = fontFor(next, weight, italic);
3969
+ const glyph = font.glyphFor(code);
3970
+ if (glyph !== 0) return { font, glyph };
3971
+ }
3972
+ return null;
3973
+ }
3957
3974
  var glyphPaths = /* @__PURE__ */ new WeakMap();
3958
3975
  function glyphPath(font, glyph, size) {
3959
3976
  let bySize = glyphPaths.get(font);
@@ -3999,7 +4016,10 @@ function centered(path) {
3999
4016
  }
4000
4017
  function text(content, options = {}) {
4001
4018
  const size = options.size ?? 40;
4002
- const font = fontFor(options.font ?? "sans", options.weight ?? 400, options.italic ?? false);
4019
+ const family = options.font ?? "sans";
4020
+ const weight = options.weight ?? 400;
4021
+ const italic = options.italic ?? false;
4022
+ const font = fontFor(family, weight, italic);
4003
4023
  const scale = size / font.unitsPerEm;
4004
4024
  const tracking = (options.tracking ?? 0) * size;
4005
4025
  const leading = (options.leading ?? 1.3) * size;
@@ -4007,14 +4027,23 @@ function text(content, options = {}) {
4007
4027
  const source = options.uppercase ? content.toUpperCase() : content;
4008
4028
  const measureWord = (word) => {
4009
4029
  const glyphs = [];
4010
- let x = 0, previous = 0;
4030
+ let x = 0, previous = 0, previousFont = null;
4011
4031
  for (const char of word) {
4012
4032
  const code = char.codePointAt(0);
4013
- const glyph = font.glyphFor(code);
4014
- if (previous) x += font.kern(previous, glyph) * scale;
4015
- glyphs.push({ code, glyph, x, char });
4016
- x += font.advance(glyph) * scale + tracking;
4033
+ let owner = font, glyph = font.glyphFor(code);
4034
+ if (glyph === 0) {
4035
+ const found = fallbackGlyph(family, code, weight, italic);
4036
+ if (found) {
4037
+ owner = found.font;
4038
+ glyph = found.glyph;
4039
+ }
4040
+ }
4041
+ const ownerScale = size / owner.unitsPerEm;
4042
+ if (previous && previousFont === owner) x += owner.kern(previous, glyph) * ownerScale;
4043
+ glyphs.push({ font: owner, glyph, x, char });
4044
+ x += owner.advance(glyph) * ownerScale + tracking;
4017
4045
  previous = glyph;
4046
+ previousFont = owner;
4018
4047
  }
4019
4048
  return { glyphs, width: x };
4020
4049
  };
@@ -4044,13 +4073,14 @@ function text(content, options = {}) {
4044
4073
  lines.forEach((line2, row) => {
4045
4074
  const start = align === "left" ? 0 : align === "center" ? (blockWidth - line2.width) / 2 : blockWidth - line2.width;
4046
4075
  for (const placed of line2.glyphs) {
4047
- const path = glyphPath(font, placed.glyph, size);
4076
+ const path = glyphPath(placed.font, placed.glyph, size);
4048
4077
  if (path.length === 0) continue;
4049
4078
  const shape2 = centered(path);
4050
4079
  const leaf = new Node(shape2.path).at(start + placed.x + shape2.x, row * leading + shape2.y);
4051
4080
  leaf.base.fill = paint;
4052
4081
  leaf.base.trimEach = true;
4053
4082
  leaf.data["key"] = placed.char;
4083
+ if (placed.glyph === 0) leaf.data["missingGlyph"] = true;
4054
4084
  node.chars.push(leaf);
4055
4085
  node.children.push(leaf);
4056
4086
  leaf.parent = node;
@@ -4742,6 +4772,20 @@ function inspect(frame, time, zoomed, bleed) {
4742
4772
  });
4743
4773
  }
4744
4774
  }
4775
+ if (glyph && op.node.data["missingGlyph"] && op.fillAlpha >= MIN_TEXT_ALPHA) {
4776
+ const char = String(op.node.data["key"]);
4777
+ const code = `U+${char.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
4778
+ const text2 = block ? sourceOf(block) : "";
4779
+ findings.push({
4780
+ key: `film.missing_glyph:${text2}:${code}`,
4781
+ code: "film.missing_glyph",
4782
+ severity: "error",
4783
+ time,
4784
+ box: shape2,
4785
+ message: `Text ${JSON.stringify(text2)} has a character that no bundled font can draw (${code}). It renders as an empty box.`,
4786
+ text: text2
4787
+ });
4788
+ }
4745
4789
  if (glyph && block && op.fillAlpha >= MIN_TEXT_ALPHA) {
4746
4790
  let entry = blocks.get(block);
4747
4791
  if (!entry) blocks.set(block, entry = { id: block, source: sourceOf(block), bounds: shape2, glyphs: [] });
package/dist/stage.d.cts CHANGED
@@ -17,10 +17,11 @@ interface LoadedFont {
17
17
  }
18
18
 
19
19
  declare function parseFont(bytes: ArrayBuffer): LoadedFont;
20
- type FontFamily = 'sans' | 'serif' | 'mono' | 'noto';
20
+ type FontFamily = 'sans' | 'serif' | 'text-serif' | 'mono' | 'noto';
21
21
  type FontWeight = 400 | 600 | 700;
22
+ type BundledFamily = FontFamily | 'math';
22
23
  /** Get a font now, or suspend the current compile until it arrives. */
23
- declare function fontFor(family: FontFamily, weight?: FontWeight, italic?: boolean): LoadedFont;
24
+ declare function fontFor(family: BundledFamily, weight?: FontWeight, italic?: boolean): LoadedFont;
24
25
  /** Glyph outline scaled to a pixel size, with y pointing down and the origin on the baseline. */
25
26
  declare function glyphPath(font: LoadedFont, glyph: number, size: number): Path;
26
27
 
@@ -220,7 +221,7 @@ interface DecimalOptions {
220
221
  /** A number readout that follows a function of the timeline, drawn fresh each frame. */
221
222
  declare function decimal(read: () => number, options?: DecimalOptions): Node;
222
223
 
223
- type FilmDiagnosticCode = 'film.off_canvas' | 'film.text_overlap' | 'film.text_crossed';
224
+ type FilmDiagnosticCode = 'film.off_canvas' | 'film.text_overlap' | 'film.text_crossed' | 'film.missing_glyph';
224
225
  interface FilmDiagnostic {
225
226
  code: FilmDiagnosticCode;
226
227
  severity: 'error' | 'warning';
@@ -261,8 +262,8 @@ interface FilmCheckOptions extends CompileOverrides {
261
262
  samples?: number;
262
263
  }
263
264
  /**
264
- * Inspect a film for layout defects: marks off the canvas, text on text, and
265
- * strokes through text. It looks where the film comes to rest, because objects may
265
+ * Inspect a film for layout defects: marks off the canvas, text on text, strokes
266
+ * through text, and characters that no font can draw. It looks where the film comes to rest, because objects may
266
267
  * cross each other while moving. Runs anywhere, with no rendering.
267
268
  */
268
269
  declare function checkFilm(film: FilmDefinition | CompiledFilm, options?: FilmCheckOptions): Promise<FilmCheckReport>;
package/dist/stage.d.ts CHANGED
@@ -17,10 +17,11 @@ interface LoadedFont {
17
17
  }
18
18
 
19
19
  declare function parseFont(bytes: ArrayBuffer): LoadedFont;
20
- type FontFamily = 'sans' | 'serif' | 'mono' | 'noto';
20
+ type FontFamily = 'sans' | 'serif' | 'text-serif' | 'mono' | 'noto';
21
21
  type FontWeight = 400 | 600 | 700;
22
+ type BundledFamily = FontFamily | 'math';
22
23
  /** Get a font now, or suspend the current compile until it arrives. */
23
- declare function fontFor(family: FontFamily, weight?: FontWeight, italic?: boolean): LoadedFont;
24
+ declare function fontFor(family: BundledFamily, weight?: FontWeight, italic?: boolean): LoadedFont;
24
25
  /** Glyph outline scaled to a pixel size, with y pointing down and the origin on the baseline. */
25
26
  declare function glyphPath(font: LoadedFont, glyph: number, size: number): Path;
26
27
 
@@ -220,7 +221,7 @@ interface DecimalOptions {
220
221
  /** A number readout that follows a function of the timeline, drawn fresh each frame. */
221
222
  declare function decimal(read: () => number, options?: DecimalOptions): Node;
222
223
 
223
- type FilmDiagnosticCode = 'film.off_canvas' | 'film.text_overlap' | 'film.text_crossed';
224
+ type FilmDiagnosticCode = 'film.off_canvas' | 'film.text_overlap' | 'film.text_crossed' | 'film.missing_glyph';
224
225
  interface FilmDiagnostic {
225
226
  code: FilmDiagnosticCode;
226
227
  severity: 'error' | 'warning';
@@ -261,8 +262,8 @@ interface FilmCheckOptions extends CompileOverrides {
261
262
  samples?: number;
262
263
  }
263
264
  /**
264
- * Inspect a film for layout defects: marks off the canvas, text on text, and
265
- * strokes through text. It looks where the film comes to rest, because objects may
265
+ * Inspect a film for layout defects: marks off the canvas, text on text, strokes
266
+ * through text, and characters that no font can draw. It looks where the film comes to rest, because objects may
266
267
  * cross each other while moving. Runs anywhere, with no rendering.
267
268
  */
268
269
  declare function checkFilm(film: FilmDefinition | CompiledFilm, options?: FilmCheckOptions): Promise<FilmCheckReport>;
package/dist/stage.js CHANGED
@@ -135,7 +135,7 @@ import {
135
135
  warpPath,
136
136
  wiggle,
137
137
  write
138
- } from "./chunk-WHT6HRMX.js";
138
+ } from "./chunk-5ZAFH2JC.js";
139
139
  import "./chunk-MLKGABMK.js";
140
140
 
141
141
  // src/stage/tex.ts
@@ -816,6 +816,20 @@ function inspect(frame, time, zoomed, bleed) {
816
816
  });
817
817
  }
818
818
  }
819
+ if (glyph && op.node.data["missingGlyph"] && op.fillAlpha >= MIN_TEXT_ALPHA) {
820
+ const char = String(op.node.data["key"]);
821
+ const code = `U+${char.codePointAt(0).toString(16).toUpperCase().padStart(4, "0")}`;
822
+ const text2 = block ? sourceOf(block) : "";
823
+ findings.push({
824
+ key: `film.missing_glyph:${text2}:${code}`,
825
+ code: "film.missing_glyph",
826
+ severity: "error",
827
+ time,
828
+ box: shape2,
829
+ message: `Text ${JSON.stringify(text2)} has a character that no bundled font can draw (${code}). It renders as an empty box.`,
830
+ text: text2
831
+ });
832
+ }
819
833
  if (glyph && block && op.fillAlpha >= MIN_TEXT_ALPHA) {
820
834
  let entry = blocks.get(block);
821
835
  if (!entry) blocks.set(block, entry = { id: block, source: sourceOf(block), bounds: shape2, glyphs: [] });
@@ -46,7 +46,7 @@ TSX file, add the [consumer security overrides](../../README.md#consumer-securit
46
46
  before installing Vizmatic and React:
47
47
 
48
48
  ```bash
49
- npm install --save-dev vizmatic@0.5.0 react
49
+ npm install --save-dev vizmatic@0.6.0 react
50
50
  npx vizmatic video ./request-lifecycle.tsx --out ./dist/videos --theme dark --fps 30
51
51
  ```
52
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vizmatic",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Code-driven animation, diagrams, and charts: vector films that play live in a browser and export to MP4, with typed components for dense technical figures.",
5
5
  "type": "module",
6
6
  "license": "MIT",