@squinch/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +41 -0
  3. package/dist/api.d.ts +91 -0
  4. package/dist/api.js +232 -0
  5. package/dist/browser.d.ts +3 -0
  6. package/dist/browser.js +9 -0
  7. package/dist/diff/diff.d.ts +30 -0
  8. package/dist/diff/diff.js +365 -0
  9. package/dist/fonts.generated.d.ts +1 -0
  10. package/dist/fonts.generated.js +6 -0
  11. package/dist/grammar/parser.js +22 -0
  12. package/dist/grammar/parser.terms.js +115 -0
  13. package/dist/index.d.ts +4 -0
  14. package/dist/index.js +4 -0
  15. package/dist/layout/layout.d.ts +197 -0
  16. package/dist/layout/layout.js +1721 -0
  17. package/dist/metrics.d.ts +20 -0
  18. package/dist/metrics.generated.d.ts +4 -0
  19. package/dist/metrics.generated.js +4 -0
  20. package/dist/metrics.js +57 -0
  21. package/dist/model/build.d.ts +8 -0
  22. package/dist/model/build.js +1343 -0
  23. package/dist/model/packs.d.ts +13 -0
  24. package/dist/model/packs.js +29 -0
  25. package/dist/model/source.d.ts +10 -0
  26. package/dist/model/source.js +28 -0
  27. package/dist/model/suggest.d.ts +2 -0
  28. package/dist/model/suggest.js +24 -0
  29. package/dist/model/types.d.ts +226 -0
  30. package/dist/model/types.js +24 -0
  31. package/dist/packs/node-fs.d.ts +1 -0
  32. package/dist/packs/node-fs.js +37 -0
  33. package/dist/packs/registry.d.ts +61 -0
  34. package/dist/packs/registry.js +122 -0
  35. package/dist/packs/sanitize.d.ts +12 -0
  36. package/dist/packs/sanitize.js +127 -0
  37. package/dist/packs/sysGlyphs.d.ts +2 -0
  38. package/dist/packs/sysGlyphs.js +21 -0
  39. package/dist/render/adaptive.d.ts +13 -0
  40. package/dist/render/adaptive.js +112 -0
  41. package/dist/render/html/runtime.d.ts +1 -0
  42. package/dist/render/html/runtime.generated.d.ts +1 -0
  43. package/dist/render/html/runtime.generated.js +6 -0
  44. package/dist/render/html/runtime.js +362 -0
  45. package/dist/render/html.d.ts +39 -0
  46. package/dist/render/html.js +235 -0
  47. package/dist/render/svg.d.ts +75 -0
  48. package/dist/render/svg.js +1403 -0
  49. package/dist/render/validate.d.ts +4 -0
  50. package/dist/render/validate.js +9 -0
  51. package/dist/themes/index.d.ts +84 -0
  52. package/dist/themes/index.js +90 -0
  53. package/dist/view/dive.d.ts +55 -0
  54. package/dist/view/dive.js +57 -0
  55. package/dist/view/navigate.d.ts +38 -0
  56. package/dist/view/navigate.js +81 -0
  57. package/dist/view/resolve.d.ts +92 -0
  58. package/dist/view/resolve.js +591 -0
  59. package/fonts/inter-400.ttf +0 -0
  60. package/fonts/inter-500.ttf +0 -0
  61. package/fonts/inter-600.ttf +0 -0
  62. package/fonts/mono-400.ttf +0 -0
  63. package/metrics.json +510 -0
  64. package/package.json +89 -0
@@ -0,0 +1,20 @@
1
+ /** Families the metrics table carries. `inter` is the document face; `mono`
2
+ * is IBM Plex Mono, used only where digits must line up in a chip segment. */
3
+ export type FontFamily = "inter" | "mono";
4
+ /** Weights the table carries. Not every family has every weight — mono ships
5
+ * 400 alone — and asking for a missing one is a programming error, so the
6
+ * lookup below throws rather than silently measuring the wrong face. */
7
+ export type FontWeight = "400" | "500" | "600";
8
+ /** Can the bundled subset actually draw this character? `measure` answers a
9
+ * different question — it falls back to an average advance so layout never
10
+ * breaks — and the gap between the two is where a glyph goes missing from a
11
+ * render without anything failing. Space is drawable by definition. */
12
+ export declare function drawable(ch: string): boolean;
13
+ export declare function measure(text: string, sizePx: number, weight?: FontWeight, family?: FontFamily): number;
14
+ export declare function fit(text: string, maxPx: number, sizePx: number, weight?: FontWeight, family?: FontFamily): string;
15
+ /** Greedy word-wrap against the committed metrics tables, ellipsizing the last
16
+ * line. Lived in svg.ts as `wrap()` until edge notes became layout citizens:
17
+ * the layout must reserve exactly the box the renderer will draw, so the two
18
+ * have to share one wrapping function or the reservation is for a different
19
+ * note than the one drawn — the same single-source rule as `pillDims`. */
20
+ export declare function wrapText(text: string, maxPx: number, sizePx: number, fam: FontFamily, maxLines: number): string[];
@@ -0,0 +1,4 @@
1
+ export declare const METRICS: Record<string, Record<string, {
2
+ advances: Record<string, number>;
3
+ fallback: number;
4
+ }>>;
@@ -0,0 +1,4 @@
1
+ // GENERATED by scripts/gen-metrics-module.ts — do not edit.
2
+ // Precomputed advance widths (em units) per family/weight. Layout measures
3
+ // text against this table and never asks the environment.
4
+ export const METRICS = { "inter": { "400": { "advances": { "0": 0.630859, "1": 0.406738, "2": 0.609863, "3": 0.617676, "4": 0.645996, "5": 0.593262, "6": 0.620117, "7": 0.565918, "8": 0.618652, "9": 0.620117, " ": 0.28125, "!": 0.287598, "\"": 0.46582, "#": 0.633301, "$": 0.641602, "%": 0.981934, "&": 0.644043, "'": 0.299805, "(": 0.364746, ")": 0.364746, "*": 0.500977, "+": 0.661621, ",": 0.288086, "-": 0.459961, ".": 0.288086, "/": 0.360352, ":": 0.288086, ";": 0.301758, "<": 0.661621, "=": 0.661621, ">": 0.661621, "?": 0.51123, "@": 0.96582, "A": 0.689941, "B": 0.654297, "C": 0.730469, "D": 0.72168, "E": 0.601074, "F": 0.590332, "G": 0.746094, "H": 0.743164, "I": 0.268555, "J": 0.570801, "K": 0.671875, "L": 0.56543, "M": 0.90332, "N": 0.753418, "O": 0.764648, "P": 0.638672, "Q": 0.764648, "R": 0.643555, "S": 0.641602, "T": 0.645508, "U": 0.744141, "V": 0.689941, "W": 0.985352, "X": 0.682129, "Y": 0.678711, "Z": 0.628906, "[": 0.364746, "\\": 0.360352, "]": 0.364746, "^": 0.471191, "_": 0.456055, "`": 0.322754, "a": 0.561523, "b": 0.612305, "c": 0.571289, "d": 0.612305, "e": 0.583008, "f": 0.370117, "g": 0.613281, "h": 0.591309, "i": 0.242188, "j": 0.242188, "k": 0.548828, "l": 0.242188, "m": 0.875977, "n": 0.59082, "o": 0.599609, "p": 0.612305, "q": 0.612305, "r": 0.376465, "s": 0.527832, "t": 0.327148, "u": 0.591309, "v": 0.562012, "w": 0.818359, "x": 0.545898, "y": 0.562012, "z": 0.552246, "{": 0.42627, "|": 0.33252, "}": 0.42627, "~": 0.661621, "·": 0.288086, "×": 0.661621, "…": 0.864258, "—": 1, "–": 0.5, "‘": 0.260742, "’": 0.260742, "“": 0.44043, "”": 0.44043, "→": 0.65625, "←": 0.65625, "↔": 0.65625, "•": 0.5625, "§": 0.568359, "©": 0.914063, "®": 0.666016, "™": 0.61084, "°": 0.455566, "±": 0.661621, "≈": 0.65625, "≥": 0.65625, "≤": 0.65625, "‹": 0.384277, "›": 0.384277, "«": 0.58252, "»": 0.58252 }, "fallback": 0.565131 }, "500": { "advances": { "0": 0.645508, "1": 0.415039, "2": 0.616211, "3": 0.626953, "4": 0.65625, "5": 0.603027, "6": 0.629883, "7": 0.571289, "8": 0.629395, "9": 0.629883, " ": 0.266602, "!": 0.304199, "\"": 0.494141, "#": 0.638672, "$": 0.645996, "%": 0.993164, "&": 0.65332, "'": 0.312988, "(": 0.368652, ")": 0.368652, "*": 0.520508, "+": 0.66748, ",": 0.303223, "-": 0.462402, ".": 0.303223, "/": 0.369629, ":": 0.303223, ";": 0.31543, "<": 0.66748, "=": 0.66748, ">": 0.66748, "?": 0.527344, "@": 0.982422, "A": 0.708984, "B": 0.656738, "C": 0.733398, "D": 0.72168, "E": 0.603027, "F": 0.589355, "G": 0.747559, "H": 0.744629, "I": 0.272461, "J": 0.575195, "K": 0.6875, "L": 0.56543, "M": 0.912598, "N": 0.756348, "O": 0.766602, "P": 0.641602, "Q": 0.768555, "R": 0.647949, "S": 0.645996, "T": 0.652832, "U": 0.740234, "V": 0.708984, "W": 1.00293, "X": 0.700684, "Y": 0.696289, "Z": 0.640625, "[": 0.368652, "\\": 0.369629, "]": 0.368652, "^": 0.476563, "_": 0.462891, "`": 0.336914, "a": 0.567871, "b": 0.618164, "c": 0.577148, "d": 0.618164, "e": 0.587402, "f": 0.379395, "g": 0.619629, "h": 0.601563, "i": 0.251953, "j": 0.251953, "k": 0.559082, "l": 0.251953, "m": 0.888184, "n": 0.601563, "o": 0.604004, "p": 0.618164, "q": 0.618164, "r": 0.386719, "s": 0.538574, "t": 0.340332, "u": 0.601563, "v": 0.574707, "w": 0.829102, "x": 0.557129, "y": 0.575195, "z": 0.559082, "{": 0.44043, "|": 0.345703, "}": 0.44043, "~": 0.66748, "·": 0.303223, "×": 0.66748, "…": 0.910156, "—": 1, "–": 0.5, "‘": 0.277344, "’": 0.277344, "“": 0.473633, "”": 0.470703, "→": 0.65625, "←": 0.65625, "↔": 0.65625, "•": 0.533203, "§": 0.568359, "©": 0.914063, "®": 0.664551, "™": 0.620605, "°": 0.457031, "±": 0.66748, "≈": 0.65625, "≥": 0.65625, "≤": 0.65625, "‹": 0.399902, "›": 0.399902, "«": 0.608398, "»": 0.608398 }, "fallback": 0.573791 }, "600": { "advances": { "0": 0.659668, "1": 0.422852, "2": 0.623047, "3": 0.63623, "4": 0.666016, "5": 0.612305, "6": 0.639648, "7": 0.576172, "8": 0.640137, "9": 0.639648, " ": 0.251953, "!": 0.321289, "\"": 0.522949, "#": 0.643555, "$": 0.650391, "%": 1.004395, "&": 0.662598, "'": 0.325684, "(": 0.373047, ")": 0.373047, "*": 0.539551, "+": 0.672852, ",": 0.318848, "-": 0.465332, ".": 0.318848, "/": 0.378906, ":": 0.318848, ";": 0.329102, "<": 0.672852, "=": 0.672852, ">": 0.672852, "?": 0.543457, "@": 0.999023, "A": 0.727539, "B": 0.65918, "C": 0.736816, "D": 0.722168, "E": 0.605469, "F": 0.587891, "G": 0.749023, "H": 0.745605, "I": 0.276855, "J": 0.57959, "K": 0.703125, "L": 0.56543, "M": 0.922363, "N": 0.759277, "O": 0.768555, "P": 0.64502, "Q": 0.772949, "R": 0.652344, "S": 0.650391, "T": 0.660156, "U": 0.73584, "V": 0.727539, "W": 1.02002, "X": 0.719727, "Y": 0.713379, "Z": 0.652344, "[": 0.373047, "\\": 0.378906, "]": 0.373047, "^": 0.481445, "_": 0.469238, "`": 0.351074, "a": 0.574219, "b": 0.624023, "c": 0.58252, "d": 0.624023, "e": 0.591309, "f": 0.388672, "g": 0.625488, "h": 0.612305, "i": 0.261719, "j": 0.261719, "k": 0.569336, "l": 0.261719, "m": 0.900391, "n": 0.611816, "o": 0.608887, "p": 0.624023, "q": 0.624023, "r": 0.396973, "s": 0.549316, "t": 0.353027, "u": 0.612305, "v": 0.586914, "w": 0.839355, "x": 0.568848, "y": 0.588379, "z": 0.565918, "{": 0.45459, "|": 0.358887, "}": 0.45459, "~": 0.672852, "·": 0.318848, "×": 0.672852, "…": 0.956055, "—": 1, "–": 0.5, "‘": 0.293945, "’": 0.293945, "“": 0.506836, "”": 0.501465, "→": 0.65625, "←": 0.65625, "↔": 0.65625, "•": 0.503418, "§": 0.568359, "©": 0.914063, "®": 0.663574, "™": 0.630371, "°": 0.458008, "±": 0.672852, "≈": 0.65625, "≥": 0.65625, "≤": 0.65625, "‹": 0.415527, "›": 0.415527, "«": 0.634277, "»": 0.634277 }, "fallback": 0.582423 } }, "mono": { "400": { "advances": { "0": 0.6, "1": 0.6, "2": 0.6, "3": 0.6, "4": 0.6, "5": 0.6, "6": 0.6, "7": 0.6, "8": 0.6, "9": 0.6, " ": 0.6, "!": 0.6, "\"": 0.6, "#": 0.6, "$": 0.6, "%": 0.6, "&": 0.6, "'": 0.6, "(": 0.6, ")": 0.6, "*": 0.6, "+": 0.6, ",": 0.6, "-": 0.6, ".": 0.6, "/": 0.6, ":": 0.6, ";": 0.6, "<": 0.6, "=": 0.6, ">": 0.6, "?": 0.6, "@": 0.6, "A": 0.6, "B": 0.6, "C": 0.6, "D": 0.6, "E": 0.6, "F": 0.6, "G": 0.6, "H": 0.6, "I": 0.6, "J": 0.6, "K": 0.6, "L": 0.6, "M": 0.6, "N": 0.6, "O": 0.6, "P": 0.6, "Q": 0.6, "R": 0.6, "S": 0.6, "T": 0.6, "U": 0.6, "V": 0.6, "W": 0.6, "X": 0.6, "Y": 0.6, "Z": 0.6, "[": 0.6, "\\": 0.6, "]": 0.6, "^": 0.6, "_": 0.6, "`": 0.6, "a": 0.6, "b": 0.6, "c": 0.6, "d": 0.6, "e": 0.6, "f": 0.6, "g": 0.6, "h": 0.6, "i": 0.6, "j": 0.6, "k": 0.6, "l": 0.6, "m": 0.6, "n": 0.6, "o": 0.6, "p": 0.6, "q": 0.6, "r": 0.6, "s": 0.6, "t": 0.6, "u": 0.6, "v": 0.6, "w": 0.6, "x": 0.6, "y": 0.6, "z": 0.6, "{": 0.6, "|": 0.6, "}": 0.6, "~": 0.6, "·": 0.6, "×": 0.6, "…": 0.6, "—": 0.6, "–": 0.6, "‘": 0.6, "’": 0.6, "“": 0.6, "”": 0.6, "→": 0.6, "←": 0.6, "↔": 0.6, "•": 0.6, "§": 0.6, "©": 0.6, "®": 0.6, "™": 0.6, "°": 0.6, "±": 0.6, "≈": 0.6, "≥": 0.6, "≤": 0.6, "‹": 0.6, "›": 0.6, "«": 0.6, "»": 0.6 }, "fallback": 0.6 } } };
@@ -0,0 +1,57 @@
1
+ // Text measurement from the committed metrics table ONLY (non-negotiable:
2
+ // layout never asks the environment how wide text is). Browser-safe.
3
+ import { METRICS } from "./metrics.generated.js";
4
+ /** Can the bundled subset actually draw this character? `measure` answers a
5
+ * different question — it falls back to an average advance so layout never
6
+ * breaks — and the gap between the two is where a glyph goes missing from a
7
+ * render without anything failing. Space is drawable by definition. */
8
+ export function drawable(ch) {
9
+ return ch === " " || ch in METRICS.inter["400"].advances;
10
+ }
11
+ export function measure(text, sizePx, weight = "500", family = "inter") {
12
+ const m = METRICS[family]?.[weight];
13
+ if (!m)
14
+ throw new Error(`no metrics for ${family} ${weight} — regenerate with gen-metrics`);
15
+ let em = 0;
16
+ for (const ch of text)
17
+ em += m.advances[ch] ?? m.fallback;
18
+ return em * sizePx;
19
+ }
20
+ export function fit(text, maxPx, sizePx, weight = "500", family = "inter") {
21
+ if (measure(text, sizePx, weight, family) <= maxPx)
22
+ return text;
23
+ let s = text;
24
+ while (s.length > 1 && measure(s + "…", sizePx, weight, family) > maxPx)
25
+ s = s.slice(0, -1);
26
+ return s.trimEnd() + "…";
27
+ }
28
+ /** Greedy word-wrap against the committed metrics tables, ellipsizing the last
29
+ * line. Lived in svg.ts as `wrap()` until edge notes became layout citizens:
30
+ * the layout must reserve exactly the box the renderer will draw, so the two
31
+ * have to share one wrapping function or the reservation is for a different
32
+ * note than the one drawn — the same single-source rule as `pillDims`. */
33
+ export function wrapText(text, maxPx, sizePx, fam, maxLines) {
34
+ const words = text.split(" ");
35
+ const lines = [];
36
+ let cur = "";
37
+ for (const w of words) {
38
+ const attempt = cur ? `${cur} ${w}` : w;
39
+ if (measure(attempt, sizePx, "400", fam) <= maxPx)
40
+ cur = attempt;
41
+ else {
42
+ if (cur)
43
+ lines.push(cur);
44
+ cur = w;
45
+ if (lines.length === maxLines - 1)
46
+ break;
47
+ }
48
+ }
49
+ if (lines.length < maxLines)
50
+ lines.push(cur);
51
+ const consumed = lines.join(" ").length;
52
+ if (consumed < text.length) {
53
+ const last = lines[lines.length - 1];
54
+ lines[lines.length - 1] = fit(`${last}${text.slice(consumed)}`, maxPx, sizePx, "400", fam);
55
+ }
56
+ return lines;
57
+ }
@@ -0,0 +1,8 @@
1
+ import type { BuildResult, Diagnostic } from "./types.js";
2
+ export interface ProjectFile {
3
+ name: string;
4
+ src: string;
5
+ }
6
+ export declare function buildModel(src: string): BuildResult;
7
+ export declare function buildProject(input: ProjectFile[]): BuildResult;
8
+ export declare function formatDiagnostics(diags: Diagnostic[], file?: string): string;