@johnoscott/isometric-engine 0.0.0-stage → 0.10.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.
Files changed (310) hide show
  1. package/EDITOR-GUIDE.md +355 -0
  2. package/LICENSE +21 -0
  3. package/LICENSES/ajv.txt +22 -0
  4. package/LICENSES/lucide-static.txt +43 -0
  5. package/LICENSES/yaml.txt +13 -0
  6. package/README.md +62 -2
  7. package/assets/app.css +269 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +39 -0
  11. package/assets/skin.css +181 -0
  12. package/iso-editor.d.ts +4 -0
  13. package/iso-editor.js +550 -0
  14. package/iso-render.d.ts +3 -0
  15. package/iso-render.js +388 -0
  16. package/iso-systems.d.ts +4 -0
  17. package/iso-systems.js +389 -0
  18. package/js/iso-core/compile-schema.js +22 -0
  19. package/js/iso-core/depth.js +55 -0
  20. package/js/iso-core/errors.js +65 -0
  21. package/js/iso-core/glyphs.js +100 -0
  22. package/js/iso-core/index.js +55 -0
  23. package/js/iso-core/kernel.js +158 -0
  24. package/js/iso-core/metrics.json +1 -0
  25. package/js/iso-core/package.json +6 -0
  26. package/js/iso-core/parse.js +79 -0
  27. package/js/iso-core/schema-errors.js +170 -0
  28. package/js/iso-core/shims/crypto.js +125 -0
  29. package/js/iso-core/shims/path.js +49 -0
  30. package/js/iso-core/svg-dom.js +144 -0
  31. package/js/iso-core/theme.js +48 -0
  32. package/js/iso-core/vdom.js +48 -0
  33. package/js/iso-editor/adapter.js +0 -0
  34. package/js/iso-editor/clipboard.js +152 -0
  35. package/js/iso-editor/commands.js +173 -0
  36. package/js/iso-editor/complete.js +55 -0
  37. package/js/iso-editor/doc.js +182 -0
  38. package/js/iso-editor/index.js +105 -0
  39. package/js/iso-editor/model.js +210 -0
  40. package/js/iso-editor/outline.js +111 -0
  41. package/js/iso-editor/package.json +6 -0
  42. package/js/iso-editor/path.js +19 -0
  43. package/js/iso-editor/providers.js +96 -0
  44. package/js/iso-editor/schema-nav.js +117 -0
  45. package/js/iso-editor/splice.js +443 -0
  46. package/js/iso-editor/storage-keys.js +6 -0
  47. package/js/iso-editor/ui/actions.js +116 -0
  48. package/js/iso-editor/ui/canvas-layer.js +0 -0
  49. package/js/iso-editor/ui/canvas.js +1403 -0
  50. package/js/iso-editor/ui/clip.js +133 -0
  51. package/js/iso-editor/ui/dialog.js +26 -0
  52. package/js/iso-editor/ui/flat-canvas.js +54 -0
  53. package/js/iso-editor/ui/icons.js +15 -0
  54. package/js/iso-editor/ui/keys.js +26 -0
  55. package/js/iso-editor/ui/later.js +28 -0
  56. package/js/iso-editor/ui/layer.js +11 -0
  57. package/js/iso-editor/ui/menu.js +105 -0
  58. package/js/iso-editor/ui/monaco-entry.js +2 -0
  59. package/js/iso-editor/ui/mount-kit.js +0 -0
  60. package/js/iso-editor/ui/mount.js +767 -0
  61. package/js/iso-editor/ui/pane.js +0 -0
  62. package/js/iso-editor/ui/part.js +0 -0
  63. package/js/iso-editor/ui/plain-icons.js +34 -0
  64. package/js/iso-editor/ui/props.js +314 -0
  65. package/js/iso-editor/ui/scope-css.js +81 -0
  66. package/js/iso-editor/ui/setup.js +149 -0
  67. package/js/iso-editor/ui/text.js +323 -0
  68. package/js/iso-editor/ui/tree.js +728 -0
  69. package/js/iso-editor/validate.js +33 -0
  70. package/js/iso-editor/window/protocol.js +8 -0
  71. package/js/iso-objects/assemble.js +43 -0
  72. package/js/iso-objects/assets.js +88 -0
  73. package/js/iso-objects/board.js +162 -0
  74. package/js/iso-objects/compile.js +60 -0
  75. package/js/iso-objects/css.js +154 -0
  76. package/js/iso-objects/flat.js +696 -0
  77. package/js/iso-objects/focus.js +16 -0
  78. package/js/iso-objects/geometry.js +76 -0
  79. package/js/iso-objects/index.js +93 -0
  80. package/js/iso-objects/kinds.js +12 -0
  81. package/js/iso-objects/labels.js +325 -0
  82. package/js/iso-objects/package.json +6 -0
  83. package/js/iso-objects/place.js +347 -0
  84. package/js/iso-objects/route.js +461 -0
  85. package/js/iso-objects/scene.js +350 -0
  86. package/js/iso-objects/steps.js +246 -0
  87. package/js/iso-objects/types.js +0 -0
  88. package/js/iso-systems/catalog.js +42 -0
  89. package/js/iso-systems/compile.js +34 -0
  90. package/js/iso-systems/css.js +8 -0
  91. package/js/iso-systems/index.js +16 -0
  92. package/js/iso-systems/nodes.js +124 -0
  93. package/js/iso-systems/package.json +6 -0
  94. package/js/iso-systems/schema.json +311 -0
  95. package/js/iso-systems/validate.js +35 -0
  96. package/js/iso-viewer/bundle.js +20 -0
  97. package/js/iso-viewer/card-motion.js +228 -0
  98. package/js/iso-viewer/dom.js +14 -0
  99. package/js/iso-viewer/dual-view.js +212 -0
  100. package/js/iso-viewer/flat-view.js +124 -0
  101. package/js/iso-viewer/history.js +990 -0
  102. package/js/iso-viewer/index.js +98 -0
  103. package/js/iso-viewer/morph.js +192 -0
  104. package/js/iso-viewer/overlay.js +199 -0
  105. package/js/iso-viewer/package.json +6 -0
  106. package/js/iso-viewer/page.js +138 -0
  107. package/js/iso-viewer/player.js +409 -0
  108. package/js/iso-viewer/still.js +81 -0
  109. package/js/iso-viewer/timeline-contract.js +14 -0
  110. package/js/iso-viewer/timeline-engine.js +475 -0
  111. package/js/iso-viewer/timeline-export.js +36 -0
  112. package/js/iso-viewer/timeline-scale.js +116 -0
  113. package/js/iso-viewer/timeline-scope.js +58 -0
  114. package/js/iso-viewer/timeline-search.js +216 -0
  115. package/js/iso-viewer/timeline-time.js +55 -0
  116. package/js/iso-viewer/view-css.js +68 -0
  117. package/js/iso-viewer/viewport.js +177 -0
  118. package/package.json +511 -4
  119. package/src/iso-core/compile-schema.ts +23 -0
  120. package/src/iso-core/depth.ts +56 -0
  121. package/src/iso-core/errors.ts +73 -0
  122. package/src/iso-core/glyphs.ts +108 -0
  123. package/src/iso-core/index.ts +27 -0
  124. package/src/iso-core/kernel.ts +163 -0
  125. package/src/iso-core/metrics.json +1 -0
  126. package/src/iso-core/package.json +6 -0
  127. package/src/iso-core/parse.ts +91 -0
  128. package/src/iso-core/schema-errors.ts +163 -0
  129. package/src/iso-core/shims/crypto.ts +37 -0
  130. package/src/iso-core/shims/path.ts +24 -0
  131. package/src/iso-core/svg-dom.ts +103 -0
  132. package/src/iso-core/theme.ts +64 -0
  133. package/src/iso-core/vdom.ts +41 -0
  134. package/src/iso-editor/adapter.ts +147 -0
  135. package/src/iso-editor/clipboard.ts +163 -0
  136. package/src/iso-editor/commands.ts +191 -0
  137. package/src/iso-editor/complete.ts +73 -0
  138. package/src/iso-editor/doc.ts +207 -0
  139. package/src/iso-editor/index.ts +67 -0
  140. package/src/iso-editor/model.ts +234 -0
  141. package/src/iso-editor/outline.ts +126 -0
  142. package/src/iso-editor/package.json +6 -0
  143. package/src/iso-editor/path.ts +18 -0
  144. package/src/iso-editor/providers.ts +113 -0
  145. package/src/iso-editor/schema-nav.ts +129 -0
  146. package/src/iso-editor/splice.ts +477 -0
  147. package/src/iso-editor/storage-keys.ts +6 -0
  148. package/src/iso-editor/ui/actions.ts +119 -0
  149. package/src/iso-editor/ui/app.css +230 -0
  150. package/src/iso-editor/ui/canvas-layer.ts +56 -0
  151. package/src/iso-editor/ui/canvas.ts +1227 -0
  152. package/src/iso-editor/ui/clip.ts +97 -0
  153. package/src/iso-editor/ui/dialog.ts +25 -0
  154. package/src/iso-editor/ui/flat-canvas.ts +51 -0
  155. package/src/iso-editor/ui/icons.ts +21 -0
  156. package/src/iso-editor/ui/keys.ts +30 -0
  157. package/src/iso-editor/ui/later.ts +22 -0
  158. package/src/iso-editor/ui/layer.ts +7 -0
  159. package/src/iso-editor/ui/marks.css +39 -0
  160. package/src/iso-editor/ui/menu.ts +67 -0
  161. package/src/iso-editor/ui/monaco-entry.ts +6 -0
  162. package/src/iso-editor/ui/mount-kit.ts +35 -0
  163. package/src/iso-editor/ui/mount.ts +684 -0
  164. package/src/iso-editor/ui/pane.ts +45 -0
  165. package/src/iso-editor/ui/part.ts +45 -0
  166. package/src/iso-editor/ui/plain-icons.ts +83 -0
  167. package/src/iso-editor/ui/props.ts +347 -0
  168. package/src/iso-editor/ui/scope-css.ts +65 -0
  169. package/src/iso-editor/ui/setup.ts +153 -0
  170. package/src/iso-editor/ui/skin.css +181 -0
  171. package/src/iso-editor/ui/text.ts +262 -0
  172. package/src/iso-editor/ui/tree.ts +657 -0
  173. package/src/iso-editor/validate.ts +62 -0
  174. package/src/iso-editor/window/protocol.ts +33 -0
  175. package/src/iso-objects/assemble.ts +57 -0
  176. package/src/iso-objects/assets.ts +122 -0
  177. package/src/iso-objects/board.ts +169 -0
  178. package/src/iso-objects/compile.ts +76 -0
  179. package/src/iso-objects/css.ts +163 -0
  180. package/src/iso-objects/flat.ts +653 -0
  181. package/src/iso-objects/focus.ts +14 -0
  182. package/src/iso-objects/geometry.ts +86 -0
  183. package/src/iso-objects/index.ts +33 -0
  184. package/src/iso-objects/kinds.ts +56 -0
  185. package/src/iso-objects/labels.ts +310 -0
  186. package/src/iso-objects/package.json +6 -0
  187. package/src/iso-objects/place.ts +318 -0
  188. package/src/iso-objects/route.ts +444 -0
  189. package/src/iso-objects/scene.ts +376 -0
  190. package/src/iso-objects/steps.ts +234 -0
  191. package/src/iso-objects/types.ts +68 -0
  192. package/src/iso-systems/catalog.ts +31 -0
  193. package/src/iso-systems/compile.ts +39 -0
  194. package/src/iso-systems/css.ts +9 -0
  195. package/src/iso-systems/index.ts +12 -0
  196. package/src/iso-systems/nodes.ts +126 -0
  197. package/src/iso-systems/package.json +6 -0
  198. package/src/iso-systems/schema.json +311 -0
  199. package/src/iso-systems/validate.ts +34 -0
  200. package/src/iso-viewer/bundle.ts +15 -0
  201. package/src/iso-viewer/card-motion.ts +237 -0
  202. package/src/iso-viewer/dom.ts +13 -0
  203. package/src/iso-viewer/dual-view.ts +212 -0
  204. package/src/iso-viewer/flat-view.ts +127 -0
  205. package/src/iso-viewer/history.ts +781 -0
  206. package/src/iso-viewer/index.ts +40 -0
  207. package/src/iso-viewer/morph.ts +191 -0
  208. package/src/iso-viewer/overlay.ts +212 -0
  209. package/src/iso-viewer/package.json +6 -0
  210. package/src/iso-viewer/page.ts +150 -0
  211. package/src/iso-viewer/player.ts +321 -0
  212. package/src/iso-viewer/still.ts +74 -0
  213. package/src/iso-viewer/timeline-contract.ts +342 -0
  214. package/src/iso-viewer/timeline-engine.ts +420 -0
  215. package/src/iso-viewer/timeline-export.ts +31 -0
  216. package/src/iso-viewer/timeline-scale.ts +129 -0
  217. package/src/iso-viewer/timeline-scope.ts +56 -0
  218. package/src/iso-viewer/timeline-search.ts +198 -0
  219. package/src/iso-viewer/timeline-time.ts +54 -0
  220. package/src/iso-viewer/view-css.ts +59 -0
  221. package/src/iso-viewer/viewport.ts +142 -0
  222. package/types/iso-core/compile-schema.d.ts +11 -0
  223. package/types/iso-core/depth.d.ts +6 -0
  224. package/types/iso-core/errors.d.ts +24 -0
  225. package/types/iso-core/glyphs.d.ts +19 -0
  226. package/types/iso-core/index.d.ts +17 -0
  227. package/types/iso-core/kernel.d.ts +130 -0
  228. package/types/iso-core/metrics.json +1 -0
  229. package/types/iso-core/parse.d.ts +18 -0
  230. package/types/iso-core/schema-errors.d.ts +14 -0
  231. package/types/iso-core/shims/crypto.d.ts +9 -0
  232. package/types/iso-core/svg-dom.d.ts +15 -0
  233. package/types/iso-core/theme.d.ts +38 -0
  234. package/types/iso-core/vdom.d.ts +26 -0
  235. package/types/iso-editor/adapter.d.ts +178 -0
  236. package/types/iso-editor/clipboard.d.ts +23 -0
  237. package/types/iso-editor/commands.d.ts +32 -0
  238. package/types/iso-editor/complete.d.ts +25 -0
  239. package/types/iso-editor/doc.d.ts +50 -0
  240. package/types/iso-editor/index.d.ts +57 -0
  241. package/types/iso-editor/model.d.ts +96 -0
  242. package/types/iso-editor/outline.d.ts +28 -0
  243. package/types/iso-editor/path.d.ts +7 -0
  244. package/types/iso-editor/providers.d.ts +43 -0
  245. package/types/iso-editor/schema-nav.d.ts +34 -0
  246. package/types/iso-editor/splice.d.ts +53 -0
  247. package/types/iso-editor/storage-keys.d.ts +5 -0
  248. package/types/iso-editor/ui/actions.d.ts +23 -0
  249. package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
  250. package/types/iso-editor/ui/canvas.d.ts +307 -0
  251. package/types/iso-editor/ui/clip.d.ts +14 -0
  252. package/types/iso-editor/ui/dialog.d.ts +7 -0
  253. package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
  254. package/types/iso-editor/ui/icons.d.ts +5 -0
  255. package/types/iso-editor/ui/keys.d.ts +7 -0
  256. package/types/iso-editor/ui/later.d.ts +12 -0
  257. package/types/iso-editor/ui/layer.d.ts +2 -0
  258. package/types/iso-editor/ui/menu.d.ts +21 -0
  259. package/types/iso-editor/ui/mount-kit.d.ts +31 -0
  260. package/types/iso-editor/ui/mount.d.ts +146 -0
  261. package/types/iso-editor/ui/pane.d.ts +60 -0
  262. package/types/iso-editor/ui/part.d.ts +40 -0
  263. package/types/iso-editor/ui/plain-icons.d.ts +10 -0
  264. package/types/iso-editor/ui/props.d.ts +57 -0
  265. package/types/iso-editor/ui/scope-css.d.ts +5 -0
  266. package/types/iso-editor/ui/setup.d.ts +49 -0
  267. package/types/iso-editor/ui/text.d.ts +19 -0
  268. package/types/iso-editor/ui/tree.d.ts +100 -0
  269. package/types/iso-editor/validate.d.ts +36 -0
  270. package/types/iso-editor/window/protocol.d.ts +60 -0
  271. package/types/iso-objects/assemble.d.ts +35 -0
  272. package/types/iso-objects/assets.d.ts +49 -0
  273. package/types/iso-objects/board.d.ts +36 -0
  274. package/types/iso-objects/compile.d.ts +35 -0
  275. package/types/iso-objects/css.d.ts +16 -0
  276. package/types/iso-objects/flat.d.ts +130 -0
  277. package/types/iso-objects/focus.d.ts +1 -0
  278. package/types/iso-objects/geometry.d.ts +59 -0
  279. package/types/iso-objects/index.d.ts +26 -0
  280. package/types/iso-objects/kinds.d.ts +53 -0
  281. package/types/iso-objects/labels.d.ts +92 -0
  282. package/types/iso-objects/place.d.ts +25 -0
  283. package/types/iso-objects/route.d.ts +67 -0
  284. package/types/iso-objects/scene.d.ts +63 -0
  285. package/types/iso-objects/steps.d.ts +90 -0
  286. package/types/iso-objects/types.d.ts +140 -0
  287. package/types/iso-systems/catalog.d.ts +4 -0
  288. package/types/iso-systems/compile.d.ts +6 -0
  289. package/types/iso-systems/css.d.ts +3 -0
  290. package/types/iso-systems/index.d.ts +5 -0
  291. package/types/iso-systems/nodes.d.ts +3 -0
  292. package/types/iso-viewer/card-motion.d.ts +56 -0
  293. package/types/iso-viewer/dom.d.ts +1 -0
  294. package/types/iso-viewer/dual-view.d.ts +44 -0
  295. package/types/iso-viewer/flat-view.d.ts +25 -0
  296. package/types/iso-viewer/history.d.ts +91 -0
  297. package/types/iso-viewer/index.d.ts +31 -0
  298. package/types/iso-viewer/morph.d.ts +28 -0
  299. package/types/iso-viewer/overlay.d.ts +135 -0
  300. package/types/iso-viewer/page.d.ts +13 -0
  301. package/types/iso-viewer/still.d.ts +26 -0
  302. package/types/iso-viewer/timeline-contract.d.ts +345 -0
  303. package/types/iso-viewer/timeline-engine.d.ts +20 -0
  304. package/types/iso-viewer/timeline-export.d.ts +5 -0
  305. package/types/iso-viewer/timeline-scale.d.ts +44 -0
  306. package/types/iso-viewer/timeline-scope.d.ts +33 -0
  307. package/types/iso-viewer/timeline-search.d.ts +52 -0
  308. package/types/iso-viewer/timeline-time.d.ts +8 -0
  309. package/types/iso-viewer/view-css.d.ts +7 -0
  310. package/types/iso-viewer/viewport.d.ts +50 -0
@@ -0,0 +1,73 @@
1
+ // Diagnostics: a message tied to a place in the YAML source, printed with a caret excerpt.
2
+
3
+ export type Severity = 'error' | 'warning';
4
+
5
+ export interface Diag {
6
+ severity: Severity;
7
+ message: string;
8
+ /** 1-based; 0 when the place is unknown */
9
+ line: number;
10
+ col: number;
11
+ /** the JSON path in the document, for tools and tests, e.g. /scenes/0/nodes/2/asset */
12
+ path: string;
13
+ hint?: string;
14
+ /** another file the place is in (a defaults or override file), with its text for the excerpt */
15
+ file?: string;
16
+ source?: string;
17
+ }
18
+
19
+ export class DiagError extends Error {
20
+ diags: Diag[];
21
+ constructor(diags: Diag[]) {
22
+ super(diags.map(d => `${d.line}:${d.col} ${d.message}`).join('\n'));
23
+ this.diags = diags;
24
+ }
25
+ }
26
+
27
+ /** Edit distance where swapping two neighbouring letters counts as one edit (optimal string alignment). */
28
+ export function distance(a: string, b: string): number {
29
+ const m = a.length, n = b.length;
30
+ if (!m) return n;
31
+ if (!n) return m;
32
+ const d: number[][] = Array.from({ length: m + 1 }, (_, i) => [i, ...Array(n).fill(0)]);
33
+ for (let j = 0; j <= n; j++) d[0][j] = j;
34
+ for (let i = 1; i <= m; i++) {
35
+ for (let j = 1; j <= n; j++) {
36
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
37
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
38
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
39
+ }
40
+ }
41
+ return d[m][n];
42
+ }
43
+
44
+ /** The closest candidate, if it is close enough to be a likely typo. */
45
+ export function didYouMean(word: string, candidates: Iterable<string>): string | undefined {
46
+ let best: string | undefined, bd = Infinity;
47
+ const w = word.toLowerCase();
48
+ for (const c of candidates) {
49
+ const d = distance(w, c.toLowerCase());
50
+ if (d < bd) { bd = d; best = c; }
51
+ }
52
+ if (best === undefined) return undefined;
53
+ const limit = Math.max(1, Math.min(3, Math.floor(Math.max(word.length, best.length) / 3)));
54
+ return bd <= limit ? best : undefined;
55
+ }
56
+
57
+ export function formatDiag(d: Diag, file: string, source?: string): string {
58
+ if (d.file) { file = d.file; source = d.source; }
59
+ const where = d.line ? `${file}:${d.line}:${d.col}` : file;
60
+ let out = `${where} ${d.severity}: ${d.message}`;
61
+ if (d.hint) out += `\n ${d.hint}`;
62
+ if (source && d.line) {
63
+ const lines = source.split(/\r?\n/);
64
+ const text = lines[d.line - 1] ?? '';
65
+ const gutter = String(d.line).padStart(4);
66
+ out += `\n${gutter} | ${text}\n${' '.repeat(gutter.length)} | ${' '.repeat(Math.max(0, d.col - 1))}^`;
67
+ }
68
+ return out;
69
+ }
70
+
71
+ export function formatDiags(diags: Diag[], file: string, source?: string): string {
72
+ return diags.map(d => formatDiag(d, file, source)).join('\n\n');
73
+ }
@@ -0,0 +1,108 @@
1
+ // Decorations painted on a block's faces, from the reference pages: terminal lines, icons, envelope,
2
+ // chat bubble, file lines, and the faces shown on upright screens.
3
+
4
+ import { type Box, type Kernel, type P3, iso, pt, tag, n1 } from './kernel.ts';
5
+
6
+ /** "terminal lines" on the +y (front-left) face */
7
+ export function termLines(k: Kernel, b: Box, n: number): string {
8
+ let s = '';
9
+ for (let i = 0; i < n; i++) {
10
+ const z = b.z1 - (b.z1 - b.z0) * (0.28 + i * 0.2);
11
+ const len = (b.x1 - b.x0) * (i === n - 1 ? 0.35 : 0.62 - i * 0.1);
12
+ s += k.line3([b.x0 + 0.35, b.y1, z], [b.x0 + 0.35 + len, b.y1, z], 'det');
13
+ }
14
+ return s;
15
+ }
16
+
17
+ /** Envelope on the top face (a mailbox, an inbox). */
18
+ export function envelope(k: Kernel, b: Box): string {
19
+ const m = 0.55, z = b.z1;
20
+ const a: P3 = [b.x0 + m, b.y0 + m, z], bb: P3 = [b.x1 - m, b.y0 + m, z], c: P3 = [b.x1 - m, b.y1 - m, z], d: P3 = [b.x0 + m, b.y1 - m, z];
21
+ const mid: P3 = [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, z];
22
+ return k.poly([a, bb, c, d], 'det') + k.line3(a, mid, 'det') + k.line3(mid, bb, 'det');
23
+ }
24
+
25
+ /** Chat bubble on the top face: a frame with two lines of text (chat servers). */
26
+ export function bubble(k: Kernel, b: Box): string {
27
+ const m = 0.55, z = b.z1;
28
+ let s = k.poly([[b.x0 + m, b.y0 + m, z], [b.x1 - m, b.y0 + m, z], [b.x1 - m, b.y1 - m, z], [b.x0 + m, b.y1 - m, z]], 'det');
29
+ for (let i = 1; i <= 2; i++) {
30
+ const y = b.y0 + m + (b.y1 - b.y0 - 2 * m) * i / 3;
31
+ s += k.line3([b.x0 + m + 0.3, y, z], [b.x1 - m - 0.3 - (i === 2 ? 0.5 : 0), y, z], 'det');
32
+ }
33
+ return s;
34
+ }
35
+
36
+ /** Two lines of text on the top face (files, records). */
37
+ export function fileLines(k: Kernel, b: Box): string {
38
+ const m = 0.3, z = b.z1, ym = (b.y0 + b.y1) / 2;
39
+ return k.line3([b.x0 + m, ym - 0.2, z], [b.x1 - m, ym - 0.2, z], 'det') + k.line3([b.x0 + m, ym + 0.2, z], [b.x1 - m - 0.3, ym + 0.2, z], 'det');
40
+ }
41
+
42
+ /** A key glyph on the top face: a bow and a bit. */
43
+ export function keyGlyph(k: Kernel, b: Box): string {
44
+ const cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2, z = b.z1 + 0.005, r = Math.min(b.x1 - b.x0, b.y1 - b.y0) * 0.16;
45
+ const ring: P3[] = [];
46
+ for (let i = 0; i < 20; i++) { const a = i / 20 * Math.PI * 2; ring.push([cx - r * 1.4 + Math.cos(a) * r, cy + Math.sin(a) * r, z]); }
47
+ return k.poly(ring, 'det') + k.line3([cx - r * 0.4, cy, z], [cx + r * 2.2, cy, z], 'det') + k.line3([cx + r * 1.7, cy, z], [cx + r * 1.7, cy + r * 0.8, z], 'det');
48
+ }
49
+
50
+ /** A socket: a round opening on the top face. */
51
+ export function socketGlyph(k: Kernel, b: Box): string {
52
+ const cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2, z = b.z1 + 0.005, r = Math.min(b.x1 - b.x0, b.y1 - b.y0) * 0.28;
53
+ const ring: P3[] = [];
54
+ for (let i = 0; i < 24; i++) { const a = i / 24 * Math.PI * 2; ring.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r, z]); }
55
+ return k.poly(ring, 'det sock-hole');
56
+ }
57
+
58
+ // ---- screen faces: drawn in a screen's own 2D pixel plane (w across, h down) ----
59
+
60
+ const rect = (cls: string, x: number, y: number, w: number, h: number, rx = 0) => tag('rect', { class: cls, x, y, width: w, height: h, rx: rx || undefined });
61
+
62
+ /** what a screen shows, drawn in its own 2D plane; a host adds its own by name (iso-objects' registerMarks) */
63
+ export type FacePainter = (w: number, h: number) => string;
64
+
65
+ export const screenFaces: Record<string, FacePainter> = {
66
+ terminal(w, h) {
67
+ let s = '';
68
+ const rows = Math.max(2, Math.floor((h - 12) / 9));
69
+ for (let i = 0; i < rows; i++) {
70
+ const y = 10 + i * 9, len = (w - 18) * [0.7, 0.45, 0.6, 0.3, 0.55][i % 5];
71
+ s += tag('line', { class: 'ln', x1: 8, y1: y, x2: 8 + len, y2: y });
72
+ }
73
+ return s;
74
+ },
75
+ chat(w, h) {
76
+ const rows: [number, number, string][] = [[6, 0.62, 'w'], [0.30, 0.58, 'm'], [6, 0.46, 'w'], [0.42, 0.5, 'm']];
77
+ return rows.map((r, i) => {
78
+ const bw = (w - 14) * r[1], x = r[0] === 6 ? 7 : w - 7 - bw;
79
+ return rect(r[2], x, 8 + i * (h - 18) / 4, bw, (h - 18) / 4 - 4, 3);
80
+ }).join('');
81
+ },
82
+ desktop(w, h) {
83
+ return rect('wall', 5, 5, w - 10, h - 10, 2) + rect('bar', 5, 5, w - 10, 6) + rect('win', w * 0.5, 13, w * 0.38, h * 0.42, 2);
84
+ },
85
+ /** a tiled grid of terminals: a dashboard of sessions */
86
+ tiles(w, h) {
87
+ const m = 6, gap = 2.5, cols = 3, rows = 2, tw = (w - 2 * m - gap * (cols - 1)) / cols, th = (h - 2 * m - gap * (rows - 1)) / rows;
88
+ let s = '';
89
+ for (let r = 0; r < rows; r++) for (let c = 0; c < cols; c++) {
90
+ const x = m + c * (tw + gap), y = m + r * (th + gap);
91
+ s += rect('t', x, y, tw, th, 1.5);
92
+ [0.3, 0.52, 0.74].forEach((k, i) => { s += tag('line', { class: 'ln', x1: x + 2.5, y1: y + th * k, x2: x + 2.5 + (tw - 5) * [0.8, 0.5, 0.65][(i + r + c) % 3], y2: y + th * k }); });
93
+ }
94
+ return s;
95
+ },
96
+ };
97
+
98
+ /** a face the drawing names but nothing has registered: a dashed frame with a question mark, so the gap shows */
99
+ export function placeholderFace(w: number, h: number): string {
100
+ const cx = w / 2, cy = h / 2, r = Math.min(w, h) * 0.22;
101
+ return rect('unk', w * 0.2, h * 0.2, w * 0.6, h * 0.6, 2)
102
+ + tag('path', { class: 'unk-q', d: `M${n1(cx - r * 0.5)},${n1(cy - r * 0.45)}a${n1(r * 0.5)},${n1(r * 0.5)} 0 1 1 ${n1(r * 0.5)},${n1(r * 0.55)}v${n1(r * 0.3)}` })
103
+ + tag('circle', { class: 'unk-dot', cx: n1(cx), cy: n1(cy + r * 0.75), r: n1(Math.max(0.8, r * 0.1)) });
104
+ }
105
+
106
+ export function screenGlass(w: number, h: number): string {
107
+ return rect('glass', 3, 3, w - 6, h - 6, 3);
108
+ }
@@ -0,0 +1,27 @@
1
+ // iso-core (L0): the isometric drawing core, with no domain in it (docs/editor/LAYERS.md §2). The projection and boxes,
2
+ // the SVG string builder and the block faces (kernel), the glyph painters, painter's order (depth), fonts and text
3
+ // metrics, theme tokens, YAML with source locations and diagnostics, the safe SVG DOM and the virtual document, and
4
+ // the browser's small sha-256.
5
+ //
6
+ // This is the layer's public API. Its other public entry is compile-schema.ts (ajv): it is kept out of this index
7
+ // because it makes a validator when it loads, and the portable build swaps it for precompiled validators, so a bundle
8
+ // that never validates never carries ajv. shims/ are the browser's node:path and node:crypto, which the build aliases.
9
+
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';
12
+ export type { P2, P3, Box, Attrs, FontKey, Font, Mat, Face, TextRect } from './kernel.ts';
13
+ export { termLines, envelope, bubble, fileLines, keyGlyph, socketGlyph, screenFaces, screenGlass, placeholderFace } from './glyphs.ts';
14
+ export type { FacePainter } from './glyphs.ts';
15
+ export { depthSort } from './depth.ts';
16
+ export type { Drawable } from './depth.ts';
17
+ export { loadTheme, extendTheme, colorRef, themeCss, themeParts } from './theme.ts';
18
+ export type { RawRole, RawKind, Theme } from './theme.ts';
19
+ export { DiagError, distance, didYouMean, formatDiag, formatDiags } from './errors.ts';
20
+ export type { Severity, Diag } from './errors.ts';
21
+ export { parse } from './parse.ts';
22
+ export type { Parsed } from './parse.ts';
23
+ export { allowed, parseSvg, buildSvg } from './svg-dom.ts';
24
+ export type { SvgNode } from './svg-dom.ts';
25
+ export { VEl, vdoc, serialize } from './vdom.ts';
26
+ export type { VNode } from './vdom.ts';
27
+ export { createHash, sha256Hex } from './shims/crypto.ts';
@@ -0,0 +1,163 @@
1
+ // The drawing kernel, generalised from the reference pages: the isometric projection, block faces,
2
+ // 2D painting on any face, text on the floor or a face, and an SVG string builder that tracks bounds.
3
+
4
+ import metrics from './metrics.json' with { type: 'json' };
5
+
6
+ /** pixels per grid unit, as in the references */
7
+ export const S = 34;
8
+ export const C = Math.cos(Math.PI / 6);
9
+
10
+ export type P2 = [number, number];
11
+ export type P3 = [number, number, number];
12
+ export interface Box { x0: number; y0: number; z0: number; x1: number; y1: number; z1: number }
13
+
14
+ export const iso = (x: number, y: number, z = 0): P2 => [(x - y) * C * S, (x + y) * 0.5 * S - z * S];
15
+ export const n1 = (v: number) => {
16
+ const r = Math.round(v * 10) / 10;
17
+ return Object.is(r, -0) ? '0' : String(r);
18
+ };
19
+ export const pt = (p: P2) => `${n1(p[0])},${n1(p[1])}`;
20
+
21
+ export const esc = (s: string) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
22
+
23
+ export type Attrs = Record<string, string | number | undefined | null | false>;
24
+ export function tag(name: string, attrs: Attrs = {}, inner?: string): string {
25
+ let a = '';
26
+ for (const k in attrs) {
27
+ const v = attrs[k];
28
+ if (v === undefined || v === null || v === false || v === '') continue;
29
+ a += ` ${k}="${esc(typeof v === 'number' ? n1(v) : v)}"`;
30
+ }
31
+ return inner === undefined ? `<${name}${a}/>` : `<${name}${a}>${inner}</${name}>`;
32
+ }
33
+
34
+ // ---- text metrics ----
35
+
36
+ export type FontKey = keyof typeof metrics;
37
+ export interface Font { key: FontKey; size: number; spacing?: number /* em */ }
38
+
39
+ /** the fonts of the reference CSS classes; metrics are measured at these exact sizes (scripts/measure-fonts.mjs) */
40
+ export const FONTS = {
41
+ lbl: { key: 'sans700_13', size: 13 },
42
+ sub: { key: 'mono400_11', size: 11 },
43
+ slabname: { key: 'sans800_15', size: 15, spacing: 0.12 },
44
+ sm: { key: 'sans800_10_5', size: 10.5, spacing: 0.1 },
45
+ floor: { key: 'mono600_11', size: 11, spacing: 0.01 },
46
+ say: { key: 'sans600_12', size: 12 },
47
+ tunname: { key: 'sans800_12', size: 12, spacing: 0.14 },
48
+ badge: { key: 'sans800_11_5', size: 11.5 },
49
+ } satisfies Record<string, Font>;
50
+
51
+ export function textWidth(str: string, f: Font): number {
52
+ const table = metrics[f.key] as Record<string, number>;
53
+ const avg = f.key.startsWith('mono') ? 0.6 : 0.58;
54
+ let w = 0;
55
+ for (const ch of str) w += table[ch] ?? avg;
56
+ return (w + (f.spacing ?? 0) * [...str].length) * f.size;
57
+ }
58
+
59
+ // ---- 2D affine maps for painting on faces ----
60
+
61
+ /** [a b c d e f] as in SVG matrix(): x' = a x + c y + e, y' = b x + d y + f */
62
+ export type Mat = [number, number, number, number, number, number];
63
+ export const apply = (m: Mat, x: number, y: number): P2 => [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
64
+ export const matStr = (m: Mat) => `matrix(${m.map(v => (Math.round(v * 10000) / 10000)).join(' ')})`;
65
+
66
+ export type Face = 'top' | 'left' | 'right';
67
+ /**
68
+ * A face's own 2D plane, in pixels: u to the right, v down, origin at the face's top-left corner as seen.
69
+ * left = the +y face (front-left), right = the +x face (front-right), top = the z1 face (u along +x, v along +y).
70
+ */
71
+ export function faceFrame(b: Box, face: Face): { m: Mat; w: number; h: number } {
72
+ if (face === 'left') { const [X, Y] = iso(b.x0, b.y1, b.z1); return { m: [C, 0.5, 0, 1, X, Y], w: (b.x1 - b.x0) * S, h: (b.z1 - b.z0) * S }; }
73
+ if (face === 'right') { const [X, Y] = iso(b.x1, b.y1, b.z1); return { m: [C, -0.5, 0, 1, X, Y], w: (b.y1 - b.y0) * S, h: (b.z1 - b.z0) * S }; }
74
+ const [X, Y] = iso(b.x0, b.y0, b.z1);
75
+ return { m: [C, 0.5, -C, 0.5, X, Y], w: (b.x1 - b.x0) * S, h: (b.y1 - b.y0) * S };
76
+ }
77
+
78
+ // ---- the canvas: SVG strings plus the bounds of everything drawn ----
79
+
80
+ export class Bounds {
81
+ x0 = Infinity; y0 = Infinity; x1 = -Infinity; y1 = -Infinity;
82
+ add(p: P2) { if (p[0] < this.x0) this.x0 = p[0]; if (p[0] > this.x1) this.x1 = p[0]; if (p[1] < this.y0) this.y0 = p[1]; if (p[1] > this.y1) this.y1 = p[1]; }
83
+ addRect(x: number, y: number, w: number, h: number) { this.add([x, y]); this.add([x + w, y + h]); }
84
+ get empty() { return this.x0 === Infinity; }
85
+ }
86
+
87
+ export interface TextRect { x: number; y: number; w: number; h: number; text: string; owner?: string }
88
+
89
+ /** One per scene: collects bounds (and text rectangles for layout checks) while assets draw. */
90
+ export class Kernel {
91
+ bounds = new Bounds();
92
+ texts: TextRect[] = [];
93
+ /** screen bounds of text drawn in a skewed plane (floor, faces), for label placement */
94
+ planes: { x: number; y: number; w: number; h: number }[] = [];
95
+ /** the same, as the actual parallelograms */
96
+ planePolys: P2[][] = [];
97
+ defs = new Map<string, string>();
98
+
99
+ poly(pts: P3[], cls?: string, extra: Attrs = {}): string {
100
+ const p = pts.map(q => iso(q[0], q[1], q[2]));
101
+ p.forEach(q => this.bounds.add(q));
102
+ return tag('polygon', { points: p.map(pt).join(' '), class: cls, ...extra });
103
+ }
104
+ line3(a: P3, b: P3, cls?: string, extra: Attrs = {}): string {
105
+ const p = iso(...a), q = iso(...b);
106
+ this.bounds.add(p); this.bounds.add(q);
107
+ return tag('line', { x1: p[0], y1: p[1], x2: q[0], y2: q[1], class: cls, ...extra });
108
+ }
109
+ /** The three visible faces of a box, as in the references: lft (+y), rgt (+x), top. */
110
+ blockFaces(b: Box): string {
111
+ const { x0, y0, x1, y1, z0, z1 } = b;
112
+ return this.poly([[x0, y1, z0], [x1, y1, z0], [x1, y1, z1], [x0, y1, z1]], 'lft')
113
+ + this.poly([[x1, y0, z0], [x1, y1, z0], [x1, y1, z1], [x1, y0, z1]], 'rgt')
114
+ + this.poly([[x0, y0, z1], [x1, y0, z1], [x1, y1, z1], [x0, y1, z1]], 'top');
115
+ }
116
+ /** A group in a face's own 2D pixel plane. `draw` gets the face width and height. */
117
+ onFace(b: Box, face: Face, draw: (w: number, h: number) => string, cls?: string): string {
118
+ const f = faceFrame(b, face);
119
+ for (const [u, v] of [[0, 0], [f.w, 0], [0, f.h], [f.w, f.h]]) this.bounds.add(apply(f.m, u, v));
120
+ return tag('g', { class: cls, transform: matStr(f.m) }, draw(f.w, f.h));
121
+ }
122
+ /** Same, with an explicit matrix (screens at an angle). */
123
+ onMatrix(m: Mat, w: number, h: number, draw: (w: number, h: number) => string, cls?: string): string {
124
+ for (const [u, v] of [[0, 0], [w, 0], [0, h], [w, h]]) this.bounds.add(apply(m, u, v));
125
+ return tag('g', { class: cls, transform: matStr(m) }, draw(w, h));
126
+ }
127
+ /** Upright text, e.g. labels. (x, y) in screen pixels; y is the baseline. */
128
+ text(x: number, y: number, str: string, cls: string, font: Font, anchor: 'start' | 'middle' | 'end' = 'middle', extra: Attrs = {}, owner?: string): string {
129
+ const w = textWidth(str, font);
130
+ const left = anchor === 'start' ? x : anchor === 'end' ? x - w : x - w / 2;
131
+ const r = { x: left, y: y - font.size * 0.8, w, h: font.size * 1.05, text: str, owner };
132
+ // the halo stroke (4px) also paints
133
+ this.bounds.addRect(r.x - 2, r.y - 2, r.w + 4, r.h + 4);
134
+ this.texts.push(r);
135
+ return tag('text', { x, y, class: cls, 'text-anchor': anchor === 'start' ? undefined : anchor, ...extra }, esc(str));
136
+ }
137
+ /** Text in a skewed plane (floor or face), with bounds through the matrix. */
138
+ planeText(m: Mat, str: string, cls: string, font: Font, anchor: 'start' | 'middle' | 'end' = 'start', extra: Attrs = {}): string {
139
+ const w = textWidth(str, font);
140
+ const left = anchor === 'start' ? 0 : anchor === 'end' ? -w : -w / 2;
141
+ const c = [[left, -font.size * 0.8], [left + w, -font.size * 0.8], [left, font.size * 0.25], [left + w, font.size * 0.25]].map(([u, v]) => apply(m, u, v));
142
+ c.forEach(p => this.bounds.add(p));
143
+ const xs = c.map(p => p[0]), ys = c.map(p => p[1]);
144
+ this.planePolys.push([c[0], c[1], c[3], c[2]]);
145
+ this.planes.push({ x: Math.min(...xs), y: Math.min(...ys), w: Math.max(...xs) - Math.min(...xs), h: Math.max(...ys) - Math.min(...ys) });
146
+ return tag('text', { transform: matStr(m), class: cls, 'text-anchor': anchor === 'start' ? undefined : anchor, ...extra }, esc(str));
147
+ }
148
+ /** Text lying on the floor at height z: dir 'x' runs along +x, 'y' runs along −y (as in floorText()). */
149
+ floorText(x: number, y: number, z: number, str: string, cls: string, dir: 'x' | 'y' = 'x', anchor: 'start' | 'middle' | 'end' = 'start', extra: Attrs = {}): string {
150
+ const [X, Y] = iso(x, y, z);
151
+ const m: Mat = dir === 'x' ? [C, 0.5, -C, 0.5, X, Y] : [C, -0.5, C, 0.5, X, Y];
152
+ return this.planeText(m, str, cls, FONTS.floor, anchor, extra);
153
+ }
154
+ /** Text standing on a +y face (left) or a +x face (right) at a point. */
155
+ faceText(x: number, y: number, z: number, str: string, cls: string, font: Font, face: 'left' | 'right' = 'left', anchor: 'start' | 'middle' | 'end' = 'start', extra: Attrs = {}): string {
156
+ const [X, Y] = iso(x, y, z);
157
+ const m: Mat = face === 'left' ? [C, 0.5, 0, 1, X, Y] : [C, -0.5, 0, 1, X, Y];
158
+ return this.planeText(m, str, cls, font, anchor, extra);
159
+ }
160
+ def(id: string, svg: string) { this.defs.set(id, svg); }
161
+ }
162
+
163
+ export const center = (b: Box): P3 => [(b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, b.z1];
@@ -0,0 +1 @@
1
+ {"sans700_13":{"0":0.6787,"1":0.5059,"2":0.6372,"3":0.6631,"4":0.6812,"5":0.6577,"6":0.6777,"7":0.6172,"8":0.688,"9":0.6777," ":0.252,"!":0.3506,"\"":0.563,"#":0.6655,"$":0.6655,"%":1.0298,"&":0.7388,"'":0.3418,"(":0.4229,")":0.4229,"*":0.4785,"+":0.6655,",":0.3418,"-":0.4785,".":0.3418,"/":0.3286,":":0.3418,";":0.3418,"<":0.6655,"=":0.6655,">":0.6655,"?":0.5513,"@":0.9214,"A":0.7266,"B":0.6875,"C":0.7354,"D":0.7417,"E":0.6162,"F":0.5918,"G":0.7544,"H":0.7773,"I":0.3125,"J":0.5952,"K":0.7036,"L":0.5889,"M":0.9009,"N":0.7622,"O":0.7808,"P":0.668,"Q":0.7808,"R":0.6885,"S":0.6694,"T":0.6543,"U":0.7544,"V":0.7153,"W":1.0034,"X":0.7236,"Y":0.7021,"Z":0.6699,"[":0.4229,"\\":0.3286,"]":0.4229,"^":0.6655,"_":0.5845,"`":0.4941,"a":0.584,"b":0.6455,"c":0.5815,"d":0.6455,"e":0.5952,"f":0.407,"g":0.6396,"h":0.6265,"i":0.2813,"j":0.2813,"k":0.5957,"l":0.2891,"m":0.9263,"n":0.6216,"o":0.6138,"p":0.6411,"q":0.6416,"r":0.4338,"s":0.5513,"t":0.4114,"u":0.6216,"v":0.5771,"w":0.8413,"x":0.5747,"y":0.5913,"z":0.5605,"{":0.4229,"|":0.2935,"}":0.4229,"~":0.6655,"·":0.3418,"→":0.9375,"←":0.9375,"↑":0.8096,"↓":0.8096,"’":0.3418,"‘":0.3418,"“":0.5474,"”":0.5474,"…":0.9482,"–":0.6216,"—":0.9045,"✕":0.7622,"×":0.6655,"≈":0.6655,"≤":0.6655,"≥":0.6655,"é":0.5952},"sans800_15":{"0":0.687,"1":0.5122,"2":0.6406,"3":0.6675,"4":0.686,"5":0.6626,"6":0.6836,"7":0.6191,"8":0.6968,"9":0.6836," ":0.2344,"!":0.3555,"\"":0.5835,"#":0.6694,"$":0.6694,"%":1.0566,"&":0.7397,"'":0.3491,"(":0.4287,")":0.4287,"*":0.4731,"+":0.6694,",":0.3491,"-":0.4731,".":0.3491,"/":0.3286,":":0.3491,";":0.3491,"<":0.6694,"=":0.6694,">":0.6694,"?":0.5562,"@":0.9146,"A":0.7363,"B":0.6899,"C":0.7339,"D":0.7388,"E":0.6147,"F":0.5903,"G":0.749,"H":0.7813,"I":0.3198,"J":0.6064,"K":0.7104,"L":0.5879,"M":0.9019,"N":0.7612,"O":0.7759,"P":0.6709,"Q":0.7759,"R":0.6924,"S":0.6719,"T":0.6533,"U":0.7524,"V":0.7212,"W":1.0073,"X":0.731,"Y":0.71,"Z":0.6646,"[":0.4287,"\\":0.3286,"]":0.4287,"^":0.6694,"_":0.5889,"`":0.4844,"a":0.5864,"b":0.6479,"c":0.5811,"d":0.6479,"e":0.5952,"f":0.4139,"g":0.6416,"h":0.6309,"i":0.2847,"j":0.2847,"k":0.605,"l":0.2935,"m":0.937,"n":0.626,"o":0.6138,"p":0.6436,"q":0.6445,"r":0.4406,"s":0.5557,"t":0.4198,"u":0.626,"v":0.5806,"w":0.856,"x":0.5835,"y":0.5996,"z":0.5601,"{":0.4287,"|":0.2974,"}":0.4287,"~":0.6694,"·":0.3491,"→":0.9404,"←":0.9404,"↑":0.811,"↓":0.811,"’":0.3491,"‘":0.3491,"“":0.5688,"”":0.5688,"…":0.9883,"–":0.626,"—":0.9118,"✕":0.7622,"×":0.6694,"≈":0.6694,"≤":0.6694,"≥":0.6694,"é":0.5952},"sans800_10_5":{"0":0.7114,"1":0.5366,"2":0.665,"3":0.6919,"4":0.7104,"5":0.687,"6":0.708,"7":0.6436,"8":0.7212,"9":0.708," ":0.2588,"!":0.3799,"\"":0.6079,"#":0.6938,"$":0.6938,"%":1.0811,"&":0.7642,"'":0.3735,"(":0.4531,")":0.4531,"*":0.4976,"+":0.6938,",":0.3735,"-":0.4976,".":0.3735,"/":0.353,":":0.3735,";":0.3735,"<":0.6938,"=":0.6938,">":0.6938,"?":0.5806,"@":0.939,"A":0.7607,"B":0.7144,"C":0.7583,"D":0.7632,"E":0.6392,"F":0.6147,"G":0.7734,"H":0.8057,"I":0.3442,"J":0.6309,"K":0.7349,"L":0.6123,"M":0.9263,"N":0.7856,"O":0.8003,"P":0.6953,"Q":0.8003,"R":0.7168,"S":0.6963,"T":0.6777,"U":0.7769,"V":0.7456,"W":1.0317,"X":0.7554,"Y":0.7344,"Z":0.689,"[":0.4531,"\\":0.353,"]":0.4531,"^":0.6938,"_":0.6133,"`":0.5088,"a":0.6108,"b":0.6724,"c":0.6055,"d":0.6724,"e":0.6196,"f":0.4383,"g":0.666,"h":0.6553,"i":0.3091,"j":0.3091,"k":0.6294,"l":0.3179,"m":0.9614,"n":0.6504,"o":0.6382,"p":0.668,"q":0.6689,"r":0.465,"s":0.5801,"t":0.4442,"u":0.6504,"v":0.605,"w":0.8804,"x":0.6079,"y":0.624,"z":0.5845,"{":0.4531,"|":0.3218,"}":0.4531,"~":0.6938,"·":0.3735,"→":0.9648,"←":0.9648,"↑":0.8354,"↓":0.8354,"’":0.3735,"‘":0.3735,"“":0.5933,"”":0.5933,"…":1.0127,"–":0.6504,"—":0.9204,"✕":0.7622,"×":0.6938,"≈":0.6938,"≤":0.6938,"≥":0.6938,"é":0.6196},"sans600_12":{"0":0.6665,"1":0.4956,"2":0.6299,"3":0.6548,"4":0.6724,"5":0.6484,"6":0.668,"7":0.6113,"8":0.6753,"9":0.668," ":0.2656,"!":0.3413,"\"":0.5386,"#":0.6577,"$":0.6577,"%":0.999,"&":0.7334,"'":0.3306,"(":0.4131,")":0.4131,"*":0.48,"+":0.6577,",":0.3306,"-":0.48,".":0.3306,"/":0.3247,":":0.3306,";":0.3306,"<":0.6577,"=":0.6577,">":0.6577,"?":0.5425,"@":0.9238,"A":0.7129,"B":0.6812,"C":0.7329,"D":0.7402,"E":0.6133,"F":0.5889,"G":0.7559,"H":0.7695,"I":0.3013,"J":0.5801,"K":0.6924,"L":0.5859,"M":0.8955,"N":0.7593,"O":0.7813,"P":0.6606,"Q":0.7813,"R":0.6807,"S":0.6626,"T":0.6514,"U":0.7524,"V":0.7056,"W":0.9956,"X":0.7124,"Y":0.6904,"Z":0.6709,"[":0.4131,"\\":0.3247,"]":0.4131,"^":0.6577,"_":0.5757,"`":0.5,"a":0.5771,"b":0.6392,"c":0.5781,"d":0.6392,"e":0.5908,"f":0.3957,"g":0.6333,"h":0.6177,"i":0.2739,"j":0.2734,"k":0.582,"l":0.2808,"m":0.9116,"n":0.6128,"o":0.6099,"p":0.6348,"q":0.6348,"r":0.4232,"s":0.543,"t":0.3991,"u":0.6128,"v":0.5693,"w":0.8228,"x":0.562,"y":0.5791,"z":0.5571,"{":0.4131,"|":0.2856,"}":0.4131,"~":0.6577,"·":0.3306,"→":0.9307,"←":0.9307,"↑":0.8037,"↓":0.8037,"’":0.3306,"‘":0.3306,"“":0.522,"”":0.522,"…":0.9043,"–":0.6128,"—":0.8957,"✕":0.7622,"×":0.6577,"≈":0.6577,"≤":0.6577,"≥":0.6577,"é":0.5908},"sans800_12":{"0":0.7026,"1":0.5278,"2":0.6563,"3":0.6831,"4":0.7017,"5":0.6782,"6":0.6992,"7":0.6348,"8":0.7124,"9":0.6992," ":0.25,"!":0.3711,"\"":0.5991,"#":0.6851,"$":0.6851,"%":1.0723,"&":0.7554,"'":0.3647,"(":0.4443,")":0.4443,"*":0.4888,"+":0.6851,",":0.3647,"-":0.4888,".":0.3647,"/":0.3442,":":0.3647,";":0.3647,"<":0.6851,"=":0.6851,">":0.6851,"?":0.5718,"@":0.9302,"A":0.752,"B":0.7056,"C":0.7495,"D":0.7544,"E":0.6304,"F":0.606,"G":0.7646,"H":0.7969,"I":0.3354,"J":0.6221,"K":0.7261,"L":0.6035,"M":0.9175,"N":0.7769,"O":0.7915,"P":0.6865,"Q":0.7915,"R":0.708,"S":0.6875,"T":0.6689,"U":0.7681,"V":0.7368,"W":1.0229,"X":0.7466,"Y":0.7256,"Z":0.6802,"[":0.4443,"\\":0.3442,"]":0.4443,"^":0.6851,"_":0.6045,"`":0.5,"a":0.6021,"b":0.6636,"c":0.5967,"d":0.6636,"e":0.6108,"f":0.4295,"g":0.6572,"h":0.6465,"i":0.3003,"j":0.3003,"k":0.6206,"l":0.3091,"m":0.9526,"n":0.6416,"o":0.6294,"p":0.6592,"q":0.6602,"r":0.4562,"s":0.5713,"t":0.4354,"u":0.6416,"v":0.5962,"w":0.8716,"x":0.5991,"y":0.6152,"z":0.5757,"{":0.4443,"|":0.313,"}":0.4443,"~":0.6851,"·":0.3647,"→":0.9561,"←":0.9561,"↑":0.8267,"↓":0.8267,"’":0.3647,"‘":0.3647,"“":0.5845,"”":0.5845,"…":1.0039,"–":0.6416,"—":0.9173,"✕":0.7622,"×":0.6851,"≈":0.6851,"≤":0.6851,"≥":0.6851,"é":0.6108},"sans800_11_5":{"0":0.7056,"1":0.5308,"2":0.6592,"3":0.686,"4":0.7046,"5":0.6812,"6":0.7021,"7":0.6377,"8":0.7153,"9":0.7021," ":0.2529,"!":0.374,"\"":0.6021,"#":0.688,"$":0.688,"%":1.0752,"&":0.7583,"'":0.3677,"(":0.4473,")":0.4473,"*":0.4917,"+":0.688,",":0.3677,"-":0.4917,".":0.3677,"/":0.3472,":":0.3677,";":0.3677,"<":0.688,"=":0.688,">":0.688,"?":0.5747,"@":0.9331,"A":0.7549,"B":0.7085,"C":0.7524,"D":0.7573,"E":0.6333,"F":0.6089,"G":0.7676,"H":0.7998,"I":0.3384,"J":0.625,"K":0.729,"L":0.6064,"M":0.9204,"N":0.7798,"O":0.7944,"P":0.6895,"Q":0.7944,"R":0.7109,"S":0.6904,"T":0.6719,"U":0.771,"V":0.7397,"W":1.0259,"X":0.7495,"Y":0.7285,"Z":0.6831,"[":0.4473,"\\":0.3472,"]":0.4473,"^":0.688,"_":0.6074,"`":0.5029,"a":0.605,"b":0.6665,"c":0.5996,"d":0.6665,"e":0.6138,"f":0.4325,"g":0.6602,"h":0.6494,"i":0.3032,"j":0.3032,"k":0.6235,"l":0.312,"m":0.9556,"n":0.6445,"o":0.6323,"p":0.6621,"q":0.6631,"r":0.4591,"s":0.5742,"t":0.4383,"u":0.6445,"v":0.5991,"w":0.8745,"x":0.6021,"y":0.6182,"z":0.5786,"{":0.4473,"|":0.3159,"}":0.4473,"~":0.688,"·":0.3677,"→":0.959,"←":0.959,"↑":0.8296,"↓":0.8296,"’":0.3677,"‘":0.3677,"“":0.5874,"”":0.5874,"…":1.0068,"–":0.6445,"—":0.9183,"✕":0.7622,"×":0.688,"≈":0.688,"≤":0.688,"≥":0.688,"é":0.6138},"sans400_13":{"0":0.624,"1":0.458,"2":0.5977,"3":0.6211,"4":0.6377,"5":0.6123,"6":0.6309,"7":0.582,"8":0.6328,"9":0.6309," ":0.2754,"!":0.3052,"\"":0.4717,"#":0.624,"$":0.624,"%":0.9194,"&":0.7056,"'":0.291,"(":0.376,")":0.376,"*":0.4658,"+":0.624,",":0.291,"-":0.4658,".":0.291,"/":0.2988,":":0.291,";":0.291,"<":0.624,"=":0.624,">":0.624,"?":0.5068,"@":0.9121,"A":0.668,"B":0.6514,"C":0.71,"D":0.7207,"E":0.5898,"F":0.5664,"G":0.7407,"H":0.7363,"I":0.2617,"J":0.5322,"K":0.6528,"L":0.562,"M":0.8682,"N":0.7363,"O":0.7656,"P":0.6294,"Q":0.7656,"R":0.6475,"S":0.6313,"T":0.6279,"U":0.7314,"V":0.668,"W":0.9619,"X":0.6729,"Y":0.6494,"Z":0.6558,"[":0.376,"\\":0.2988,"]":0.376,"^":0.624,"_":0.5405,"`":0.4941,"a":0.5459,"b":0.6084,"c":0.5537,"d":0.6084,"e":0.5654,"f":0.356,"g":0.6035,"h":0.5825,"i":0.2412,"j":0.2407,"k":0.5371,"l":0.2471,"m":0.8643,"n":0.5776,"o":0.585,"p":0.6045,"q":0.6035,"r":0.3843,"s":0.5083,"t":0.3574,"u":0.5776,"v":0.5361,"w":0.7686,"x":0.5186,"y":0.5371,"z":0.5332,"{":0.376,"|":0.2529,"}":0.376,"~":0.624,"·":0.291,"→":0.8999,"←":0.8999,"↑":0.7754,"↓":0.7754,"’":0.291,"‘":0.291,"“":0.4531,"”":0.4531,"…":0.7988,"–":0.5776,"—":0.872,"✕":0.7622,"×":0.624,"≈":0.624,"≤":0.624,"≥":0.624,"é":0.5654},"mono400_11":{"0":0.6021,"1":0.6021,"2":0.6021,"3":0.6021,"4":0.6021,"5":0.6021,"6":0.6021,"7":0.6021,"8":0.6021,"9":0.6021," ":0.6021,"!":0.6021,"\"":0.6021,"#":0.6021,"$":0.6021,"%":0.6021,"&":0.6021,"'":0.6021,"(":0.6021,")":0.6021,"*":0.6021,"+":0.6021,",":0.6021,"-":0.6021,".":0.6021,"/":0.6021,":":0.6021,";":0.6021,"<":0.6021,"=":0.6021,">":0.6021,"?":0.6021,"@":0.6021,"A":0.6021,"B":0.6021,"C":0.6021,"D":0.6021,"E":0.6021,"F":0.6021,"G":0.6021,"H":0.6021,"I":0.6021,"J":0.6021,"K":0.6021,"L":0.6021,"M":0.6021,"N":0.6021,"O":0.6021,"P":0.6021,"Q":0.6021,"R":0.6021,"S":0.6021,"T":0.6021,"U":0.6021,"V":0.6021,"W":0.6021,"X":0.6021,"Y":0.6021,"Z":0.6021,"[":0.6021,"\\":0.6021,"]":0.6021,"^":0.6021,"_":0.6021,"`":0.6021,"a":0.6021,"b":0.6021,"c":0.6021,"d":0.6021,"e":0.6021,"f":0.6021,"g":0.6021,"h":0.6021,"i":0.6021,"j":0.6021,"k":0.6021,"l":0.6021,"m":0.6021,"n":0.6021,"o":0.6021,"p":0.6021,"q":0.6021,"r":0.6021,"s":0.6021,"t":0.6021,"u":0.6021,"v":0.6021,"w":0.6021,"x":0.6021,"y":0.6021,"z":0.6021,"{":0.6021,"|":0.6021,"}":0.6021,"~":0.6021,"·":0.6021,"→":0.6021,"←":0.6021,"↑":0.6021,"↓":0.6021,"’":0.6021,"‘":0.6021,"“":0.6021,"”":0.6021,"…":0.6021,"–":0.6021,"—":0.6021,"✕":0.6021,"×":0.6021,"≈":0.6021,"≤":0.6021,"≥":0.6021,"é":0.6021},"mono600_11":{"0":0.6021,"1":0.6021,"2":0.6021,"3":0.6021,"4":0.6021,"5":0.6021,"6":0.6021,"7":0.6021,"8":0.6021,"9":0.6021," ":0.6021,"!":0.6021,"\"":0.6021,"#":0.6021,"$":0.6021,"%":0.6021,"&":0.6021,"'":0.6021,"(":0.6021,")":0.6021,"*":0.6021,"+":0.6021,",":0.6021,"-":0.6021,".":0.6021,"/":0.6021,":":0.6021,";":0.6021,"<":0.6021,"=":0.6021,">":0.6021,"?":0.6021,"@":0.6021,"A":0.6021,"B":0.6021,"C":0.6021,"D":0.6021,"E":0.6021,"F":0.6021,"G":0.6021,"H":0.6021,"I":0.6021,"J":0.6021,"K":0.6021,"L":0.6021,"M":0.6021,"N":0.6021,"O":0.6021,"P":0.6021,"Q":0.6021,"R":0.6021,"S":0.6021,"T":0.6021,"U":0.6021,"V":0.6021,"W":0.6021,"X":0.6021,"Y":0.6021,"Z":0.6021,"[":0.6021,"\\":0.6021,"]":0.6021,"^":0.6021,"_":0.6021,"`":0.6021,"a":0.6021,"b":0.6021,"c":0.6021,"d":0.6021,"e":0.6021,"f":0.6021,"g":0.6021,"h":0.6021,"i":0.6021,"j":0.6021,"k":0.6021,"l":0.6021,"m":0.6021,"n":0.6021,"o":0.6021,"p":0.6021,"q":0.6021,"r":0.6021,"s":0.6021,"t":0.6021,"u":0.6021,"v":0.6021,"w":0.6021,"x":0.6021,"y":0.6021,"z":0.6021,"{":0.6021,"|":0.6021,"}":0.6021,"~":0.6021,"·":0.6021,"→":0.6021,"←":0.6021,"↑":0.6021,"↓":0.6021,"’":0.6021,"‘":0.6021,"“":0.6021,"”":0.6021,"…":0.6021,"–":0.6021,"—":0.6021,"✕":0.6021,"×":0.6021,"≈":0.6021,"≤":0.6021,"≥":0.6021,"é":0.6021}}
@@ -0,0 +1,6 @@
1
+ {
2
+ "//": "iso-core (L0) has no side effects but compile-schema.ts (ajv makes a validator when it loads): bundles drop what they do not use. LAYERS.md S1.",
3
+ "type": "module",
4
+ "private": true,
5
+ "sideEffects": ["./compile-schema.ts"]
6
+ }
@@ -0,0 +1,91 @@
1
+ // YAML text → plain data, keeping a way back from any JSON path to its line and column.
2
+
3
+ import { parseDocument, LineCounter, isMap, isSeq, isPair, isScalar, type Document, type Node as YNode } from 'yaml';
4
+ import type { Diag } from './errors.ts';
5
+
6
+ export interface Parsed {
7
+ data: unknown;
8
+ /** line/col (1-based) of the value at a JSON path; `key: true` gives the key's place in its map instead */
9
+ locate(path: string, opts?: { key?: boolean }): { line: number; col: number };
10
+ /** the lines (1-based, inclusive) the value at a JSON path spans in the source; undefined if not found */
11
+ span(path: string): { start: number; end: number } | undefined;
12
+ diags: Diag[];
13
+ }
14
+
15
+ function splitPath(path: string): (string | number)[] {
16
+ return path.split('/').slice(1).map(s => {
17
+ const u = s.replace(/~1/g, '/').replace(/~0/g, '~');
18
+ return /^\d+$/.test(u) ? Number(u) : u;
19
+ });
20
+ }
21
+
22
+ export function parse(source: string): Parsed {
23
+ const lc = new LineCounter();
24
+ const doc: Document = parseDocument(source, { lineCounter: lc, prettyErrors: false, uniqueKeys: true });
25
+ const diags: Diag[] = [];
26
+ const pos = (offset: number) => { const p = lc.linePos(offset); return { line: p.line, col: p.col }; };
27
+
28
+ for (const e of doc.errors) {
29
+ const p = pos(e.pos[0]);
30
+ const msg = e.message.split('\n')[0];
31
+ const hint = /Nested mappings|Implicit keys|mapping values/i.test(msg) ? 'text that contains ": " (a colon followed by a blank) must be in quotes, e.g. command: \'send "a: b"\''
32
+ : /Map keys must be unique/i.test(msg) ? 'a key is written twice in the same map' : undefined;
33
+ diags.push({ severity: 'error', message: `YAML: ${msg}`, line: p.line, col: p.col, path: '', hint });
34
+ }
35
+ for (const w of doc.warnings) {
36
+ const p = pos(w.pos[0]);
37
+ diags.push({ severity: 'warning', message: `YAML: ${w.message.split('\n')[0]}`, line: p.line, col: p.col, path: '' });
38
+ }
39
+
40
+ function locate(path: string, opts: { key?: boolean } = {}) {
41
+ const parts = splitPath(path);
42
+ let node: unknown = doc.contents;
43
+ let last: { line: number; col: number } = { line: 1, col: 1 };
44
+ const here = (n: unknown) => {
45
+ const r = (n as YNode | undefined)?.range;
46
+ if (r) last = pos(r[0]);
47
+ };
48
+ here(node);
49
+ for (let i = 0; i < parts.length; i++) {
50
+ const k = parts[i];
51
+ if (isMap(node)) {
52
+ const pair = node.items.find(p => isPair(p) && isScalar(p.key) && String(p.key.value) === String(k));
53
+ if (!pair) break;
54
+ if (opts.key && i === parts.length - 1) { here(pair.key); return last; }
55
+ here(pair.key);
56
+ node = pair.value;
57
+ if (node) here(node);
58
+ } else if (isSeq(node) && typeof k === 'number') {
59
+ node = node.items[k];
60
+ if (!node) break;
61
+ here(node);
62
+ } else break;
63
+ }
64
+ return last;
65
+ }
66
+
67
+ function span(path: string) {
68
+ let node: unknown = doc.contents;
69
+ for (const k of splitPath(path)) {
70
+ if (isMap(node)) {
71
+ const pair = node.items.find(p => isPair(p) && isScalar(p.key) && String(p.key.value) === String(k));
72
+ if (!pair) return undefined;
73
+ node = pair.value;
74
+ } else if (isSeq(node) && typeof k === 'number') node = node.items[k];
75
+ else return undefined;
76
+ if (!node) return undefined;
77
+ }
78
+ const r = (node as YNode).range;
79
+ if (!r) return undefined;
80
+ // a sequence item starts at its "- " (one column before the node); its end is where its value ends
81
+ let end = lc.linePos(Math.max(r[0], r[1] - 1)).line;
82
+ // trailing blank or comment-only lines are not part of the item
83
+ const lines = source.split(/\r?\n/);
84
+ while (end > lc.linePos(r[0]).line && /^\s*(#.*)?$/.test(lines[end - 1] ?? '')) end--;
85
+ return { start: lc.linePos(r[0]).line, end };
86
+ }
87
+
88
+ let data: unknown = null;
89
+ if (!doc.errors.length) data = doc.toJS({ maxAliasCount: 100 });
90
+ return { data, locate, span, diags };
91
+ }