@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,40 @@
1
+ // iso-viewer (L2): looking at a drawn scene (docs/editor/LAYERS.md §2): the viewport (pan, zoom, fit, fitted until
2
+ // moved), the overlay's painters (marks, ghosts, cards over objects, by key), the cards' motion, a still render's
3
+ // machinery, the drawing's stylesheet scoped into a page, the static page with its step player, and the timeline
4
+ // (its generic contract, scope paths, search, memory source, export and component).
5
+ //
6
+ // The layer's public API. Importers name the module a name comes from (with code splitting, a barrel puts every file
7
+ // it reaches into each bundle that imports it); the Node tests may import this index.
8
+
9
+ export { MIN_ZOOM, viewport, MAX_ZOOM } from './viewport.ts';
10
+ export type { View, ViewportOpts, Viewport } from './viewport.ts';
11
+ export { CARD, P3, pts, overlayPaint } from './overlay.ts';
12
+ export type { Box, Outline, Box3, CardGeo, Glyph, Mark, Ghost, Card, OverlayCtx, OverlayPaint } from './overlay.ts';
13
+ export { APPEARS, IDLES, cardMotion } from './card-motion.ts';
14
+ export type { Appear, Idle, MotionSettings, CardNames, MotionHost, CardMotion } from './card-motion.ts';
15
+ export { n, node, rewrite, prune, cls, attr, extent, unite, fitWithOverlay } from './still.ts';
16
+ export { isoVars, scopeSelector, scope } from './view-css.ts';
17
+ export { md, stepData, legend, renderPage } from './page.ts';
18
+ export type { PageOpts } from './page.ts';
19
+ export { playerScript } from './bundle.ts';
20
+ export { h } from './dom.ts';
21
+ export { TIMELINE_VERSION, SEGMENT_NAME, SEVERITIES, BINS, BIN_MS, scopePattern } from './timeline-contract.ts';
22
+ export type { TimelineTypes, AnyTimeline, Scope, Severity, AttrValue, TimelineEvent, Bin, MetricPoint, MetricRollup, EventBin, Match, AstTerm, SearchAst, Days, Retention, SeriesInfo, KindInfo, SourceInfo, EffectiveRetention, ScopeName, Catalog, Filters, Query, Row, Result, Batch, View as TimelineView, Recording, TimelineSource, TimelineCatalog } from './timeline-contract.ts';
23
+ export { scopeRules, escapeName, formatScope, join, levelOf, prefixAt, parentOf, within, hasSegment, kindOf, nameOf, crumbs } from './timeline-scope.ts';
24
+ export type { Segment } from './timeline-scope.ts';
25
+ export { BASE_FIELDS, readTime, searchFor, rangeOf, highlights, severities } from './timeline-search.ts';
26
+ export type { Field, SearchDialect, Term, ParsedSearch, Search } from './timeline-search.ts';
27
+ export { offsetAt, isZone, binStart, binNext } from './timeline-time.ts';
28
+ export { findGaps, gapLabel, gapKey, timeScale, ticks } from './timeline-scale.ts';
29
+ export type { Gap, Cut, TimeScale, Tick } from './timeline-scale.ts';
30
+ export { toJSON, toCSV } from './timeline-export.ts';
31
+ export { memorySource } from './timeline-engine.ts';
32
+ export type { MemorySourceOptions, MemorySource } from './timeline-engine.ts';
33
+ export { modeFor, activityOf, mountTimeline } from './history.ts';
34
+ export type { TimelineMountOptions, TimelineHandle } from './history.ts';
35
+ export { flatSvg, flatCss, measureIn, rectOf } from './flat-view.ts';
36
+ export type { FlatStyle } from './flat-view.ts';
37
+ export { dualView, storedMode, viewToggle, DUAL_VIEW_CSS } from './dual-view.ts';
38
+ export type { ViewMode, DualViewOptions, DualView } from './dual-view.ts';
39
+ export { morphSvgs, markConnectors } from './morph.ts';
40
+ export type { SvgMorph } from './morph.ts';
@@ -0,0 +1,191 @@
1
+ // The morph between a drawing's two views (0.7.5, out of dual-view.ts so the editor's canvas can run it too, handed
2
+ // over by its 2D view's implementation): things move from where they are in one view to where they are in the other,
3
+ // a 3D top face becoming its 2D card (or coming from it), connectors fade out and draw in, on a layer of its own over
4
+ // both. No flat layout here: a page that only morphs bundles none of it.
5
+
6
+ import { parseEnd } from '../iso-objects/route.ts';
7
+ import type { CompiledScene } from '../iso-objects/compile.ts';
8
+ import type { Board } from '../iso-objects/flat.ts';
9
+
10
+ export type ViewMode = '3d' | '2d';
11
+ const NS = 'http://www.w3.org/2000/svg';
12
+
13
+ /** a 3D drawing's connectors marked with the ends they join (data-a, data-b), as the 2D ones are: a board's link may be
14
+ * drawn to a panel, so its ends are the board's when given */
15
+ export function markConnectors(svg3: SVGSVGElement, scene: CompiledScene, board?: Board): void {
16
+ const links = new Map((board?.links ?? []).map((l, i) => [l.id ?? `link-${i}`, l]));
17
+ for (const r of scene.routes) {
18
+ const l = links.get(r.id), a = l?.a ?? parseEnd(r.raw.from).id, b = l?.b ?? parseEnd(r.raw.to).id;
19
+ for (const g of svg3.querySelectorAll(`[data-id="${CSS.escape(r.id)}"]`)) { g.setAttribute('data-a', a); g.setAttribute('data-b', b); }
20
+ }
21
+ }
22
+
23
+ /** whether a switch should animate, by the motion option (0.7.3) */
24
+ export const morphs = (motion: 'auto' | 'always' | 'never' = 'auto') =>
25
+ motion === 'always' || (motion === 'auto' && !(typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches));
26
+
27
+ /** A running morph between two drawings already laid out in `root` (positioned): `done` resolves when it ends,
28
+ * `finish()` ends it at once (the layer gone). The caller shows and hides the drawings themselves. */
29
+ export interface SvgMorph { readonly done: Promise<void>; finish(): void }
30
+ /** The morph dualView runs (0.7.5: for the editor's canvas too), from one view's svg to the other's, over `root`:
31
+ * things move from where they are to where they will be (a 3D top face becoming its 2D card, or back), connectors fade
32
+ * out and draw in. Undefined when the motion option says not to animate (or the duration is 0). */
33
+ export function morphSvgs(root: HTMLElement, fromSvg: SVGSVGElement, toSvg: SVGSVGElement, from: ViewMode,
34
+ o: { duration?: number; motion?: 'auto' | 'always' | 'never' } = {}): SvgMorph | undefined {
35
+ const T = o.duration ?? 600;
36
+ if (!T || !morphs(o.motion)) return undefined;
37
+ const layer = buildLayer(root, fromSvg, toSvg, from);
38
+ root.appendChild(layer.svg);
39
+ layer.at(0);
40
+ let frame = 0, over = false, resolve!: () => void;
41
+ const done = new Promise<void>(r => (resolve = r));
42
+ const finish = () => { if (over) return; over = true; cancelAnimationFrame(frame); layer.svg.remove(); resolve(); };
43
+ const t0 = performance.now();
44
+ const step = (now: number) => {
45
+ if (over) return;
46
+ const t = Math.min(1, (now - t0) / T);
47
+ layer.at(t);
48
+ if (t < 1) frame = requestAnimationFrame(step); else finish();
49
+ };
50
+ frame = requestAnimationFrame(step);
51
+ return { done, finish };
52
+ }
53
+
54
+
55
+ export const clamp = (v: number) => Math.max(0, Math.min(1, v));
56
+ export const ease = (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2);
57
+
58
+ /** an element and everything in it, with its computed paint inlined (the layer is outside the views' stylesheets) */
59
+ function paintedClone(el: Element): Element {
60
+ const c = el.cloneNode(true) as Element;
61
+ const src = [el, ...el.querySelectorAll('*')], dst = [c, ...c.querySelectorAll('*')];
62
+ src.forEach((s, i) => {
63
+ const cs = getComputedStyle(s), d = dst[i] as SVGElement;
64
+ d.removeAttribute('class');
65
+ d.removeAttribute('tabindex');
66
+ for (const p of ['fill', 'fill-opacity', 'stroke', 'stroke-width', 'stroke-dasharray', 'stroke-opacity', 'opacity', 'font-size', 'font-weight', 'font-family', 'letter-spacing', 'paint-order', 'stroke-linejoin', 'text-anchor']) d.style.setProperty(p, cs.getPropertyValue(p));
67
+ });
68
+ return c;
69
+ }
70
+
71
+ interface Rect { x: number; y: number; w: number; h: number }
72
+ const rectIn = (el: Element, origin: DOMRect): Rect => { const r = el.getBoundingClientRect(); return { x: r.left - origin.left, y: r.top - origin.top, w: r.width, h: r.height }; };
73
+ const union = (rs: Rect[]): Rect => {
74
+ const x0 = Math.min(...rs.map(r => r.x)), y0 = Math.min(...rs.map(r => r.y)), x1 = Math.max(...rs.map(r => r.x + r.w)), y1 = Math.max(...rs.map(r => r.y + r.h));
75
+ return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
76
+ };
77
+ /** the svg's own coordinates in the root's pixels */
78
+ const ctmIn = (svg: SVGSVGElement, origin: DOMRect) => { const m = svg.getScreenCTM()!; return `matrix(${m.a} ${m.b} ${m.c} ${m.d} ${m.e - origin.left} ${m.f - origin.top})`; };
79
+ /** the map taking rect a onto rect b, `t` of the way (0: none) */
80
+ const toward = (a: Rect, b: Rect, t: number) => {
81
+ const sx = 1 + (b.w / Math.max(a.w, 1e-6) - 1) * t, sy = 1 + (b.h / Math.max(a.h, 1e-6) - 1) * t;
82
+ const tx = (b.x - a.x * (b.w / Math.max(a.w, 1e-6))) * t, ty = (b.y - a.y * (b.h / Math.max(a.h, 1e-6))) * t;
83
+ return `matrix(${sx} 0 0 ${sy} ${tx} ${ty})`;
84
+ };
85
+ /** the top face of a 3D thing (its four corners, in the root's pixels), if it has one */
86
+ function topFace(g: Element, origin: DOMRect): { pts: [number, number][]; fill: string } | undefined {
87
+ const poly = g.querySelector('polygon.top') as SVGPolygonElement | null;
88
+ if (!poly) return undefined;
89
+ const m = poly.getScreenCTM()!, pts: [number, number][] = [];
90
+ for (let i = 0; i < poly.points.numberOfItems; i++) { const p = poly.points.getItem(i); pts.push([m.a * p.x + m.c * p.y + m.e - origin.left, m.b * p.x + m.d * p.y + m.f - origin.top]); }
91
+ return pts.length === 4 ? { pts, fill: getComputedStyle(poly).fill } : undefined;
92
+ }
93
+
94
+ /** the layer a morph draws on: `at(t)` paints it t of the way from one view to the other */
95
+ export function buildLayer(root: HTMLElement, fromSvg: SVGSVGElement, toSvg: SVGSVGElement, from: ViewMode): { svg: SVGSVGElement; at(t: number): void } {
96
+ const origin = root.getBoundingClientRect();
97
+ const layer = document.createElementNS(NS, 'svg') as SVGSVGElement;
98
+ layer.setAttribute('class', 'dual-morph');
99
+ layer.setAttribute('aria-hidden', 'true');
100
+ layer.style.cssText = `position:absolute;left:0;top:0;width:${origin.width}px;height:${Math.max(origin.height, fromSvg.getBoundingClientRect().height, toSvg.getBoundingClientRect().height)}px;overflow:visible;pointer-events:none`;
101
+ const inUser = (svg: SVGSVGElement) => { const g = document.createElementNS(NS, 'g'); g.setAttribute('transform', ctmIn(svg, origin)); return g; };
102
+ const isConn = (e: Element) => e.hasAttribute('data-a') || e.hasAttribute('data-for');
103
+ const things = (svg: SVGSVGElement) => {
104
+ const m = new Map<string, Element[]>();
105
+ for (const e of svg.querySelectorAll('[data-id]')) {
106
+ if (isConn(e) || e.parentElement?.closest('[data-id]') || e.closest('.overlay')) continue;
107
+ const id = e.getAttribute('data-id')!;
108
+ (m.get(id) ?? m.set(id, []).get(id)!).push(e);
109
+ }
110
+ return m;
111
+ };
112
+ const A = things(fromSvg), B = things(toSvg);
113
+ // connectors (and their labels) of each view
114
+ const connsOut = document.createElementNS(NS, 'g'), connsIn = document.createElementNS(NS, 'g');
115
+ const cOut = inUser(fromSvg), cIn = inUser(toSvg);
116
+ // (an editor's overlay marks carry data-for too: never theirs)
117
+ for (const e of fromSvg.querySelectorAll('[data-a],[data-for]')) if (!e.closest('.overlay')) cOut.appendChild(paintedClone(e));
118
+ for (const e of toSvg.querySelectorAll('[data-a],[data-for]')) if (!e.closest('.overlay')) cIn.appendChild(paintedClone(e));
119
+ connsOut.appendChild(cOut); connsIn.appendChild(cIn);
120
+ const drawIn = [...cIn.querySelectorAll('path')].map(p => { const len = (p as SVGPathElement).getTotalLength?.() ?? 0; return { p: p as SVGPathElement, len }; });
121
+ const inLabels = [...cIn.children].filter(e => e.tagName.toLowerCase() === 'text') as SVGElement[];
122
+ // panels below cards: the 2D order (panels by depth, then cards), the 3D one's by its painter's order
123
+ const order = [...(from === '2d' ? A : B).keys()];
124
+ const items: { a?: Rect; b?: Rect; src?: SVGGElement; dst?: SVGGElement; face?: SVGPolygonElement; faceFrom?: [number, number][]; faceTo?: [number, number][]; faceFill?: [string, string] }[] = [];
125
+ const shapes = document.createElementNS(NS, 'g');
126
+ for (const id of new Set([...order, ...A.keys(), ...B.keys()])) {
127
+ const ea = A.get(id), eb = B.get(id);
128
+ const it: (typeof items)[number] = {};
129
+ if (ea) {
130
+ it.a = union(ea.map(e => rectIn(e, origin)));
131
+ const g = document.createElementNS(NS, 'g') as SVGGElement, u = inUser(fromSvg);
132
+ for (const e of ea) u.appendChild(paintedClone(e));
133
+ g.appendChild(u); it.src = g;
134
+ }
135
+ if (eb) {
136
+ it.b = union(eb.map(e => rectIn(e, origin)));
137
+ const g = document.createElementNS(NS, 'g') as SVGGElement, u = inUser(toSvg);
138
+ for (const e of eb) u.appendChild(paintedClone(e));
139
+ g.appendChild(u); it.dst = g;
140
+ }
141
+ // the 3D top face becomes the 2D card (or comes from it)
142
+ const g3 = from === '3d' ? ea?.[0] : eb?.[0], g2 = from === '3d' ? eb?.[0] : ea?.[0];
143
+ const top = g3 ? topFace(g3, origin) : undefined, face2 = g2?.querySelector('rect.face');
144
+ if (top && face2) {
145
+ const r = rectIn(face2, origin);
146
+ const flat: [number, number][] = [[r.x, r.y], [r.x + r.w, r.y], [r.x + r.w, r.y + r.h], [r.x, r.y + r.h]];
147
+ // match the corners: the 3D face's corners in order round it, starting from its leftmost
148
+ const k = top.pts.reduce((m, p, i) => (p[0] < top.pts[m][0] ? i : m), 0);
149
+ const rot = [...top.pts.slice(k), ...top.pts.slice(0, k)];
150
+ const ordered: [number, number][] = [rot[0], rot[1], rot[2], rot[3]];
151
+ const f2 = getComputedStyle(face2).fill;
152
+ const poly = document.createElementNS(NS, 'polygon') as SVGPolygonElement;
153
+ it.face = poly;
154
+ it.faceFrom = from === '3d' ? ordered : flat; it.faceTo = from === '3d' ? flat : ordered;
155
+ it.faceFill = from === '3d' ? [top.fill, f2] : [f2, top.fill];
156
+ }
157
+ if (it.src) shapes.appendChild(it.src);
158
+ if (it.face) shapes.appendChild(it.face);
159
+ if (it.dst) shapes.appendChild(it.dst);
160
+ items.push(it);
161
+ }
162
+ layer.append(connsOut, shapes, connsIn);
163
+ const mix = (a: string, b: string, t: number) => `color-mix(in srgb, ${a} ${Math.round((1 - t) * 100)}%, ${b})`;
164
+ return {
165
+ svg: layer,
166
+ at(t: number) {
167
+ const out = clamp(t / 0.2), mid = ease(clamp((t - 0.2) / 0.6)), inn = clamp((t - 0.8) / 0.2);
168
+ connsOut.setAttribute('opacity', String(1 - out));
169
+ for (const { p, len } of drawIn) { p.style.strokeDasharray = `${len} ${len}`; p.style.strokeDashoffset = String(len * (1 - inn)); }
170
+ connsIn.setAttribute('opacity', String(inn > 0 ? 1 : 0));
171
+ for (const l of inLabels) l.style.opacity = String(inn);
172
+ for (const it of items) {
173
+ if (it.src) {
174
+ it.src.setAttribute('transform', it.a && it.b ? toward(it.a, it.b, mid) : '');
175
+ it.src.setAttribute('opacity', String(it.b ? 1 - clamp(mid / (it.face ? 0.35 : 0.6)) : 1 - mid));
176
+ }
177
+ if (it.dst) {
178
+ it.dst.setAttribute('transform', it.a && it.b ? toward(it.b, it.a, 1 - mid) : '');
179
+ it.dst.setAttribute('opacity', String(it.a ? clamp((mid - (it.face ? 0.65 : 0.4)) / (it.face ? 0.35 : 0.6)) : mid));
180
+ }
181
+ if (it.face) {
182
+ const pts = it.faceFrom!.map((p, i) => [p[0] + (it.faceTo![i][0] - p[0]) * mid, p[1] + (it.faceTo![i][1] - p[1]) * mid]);
183
+ it.face.setAttribute('points', pts.map(p => p.join(',')).join(' '));
184
+ it.face.style.fill = mix(it.faceFill![0], it.faceFill![1], mid);
185
+ it.face.setAttribute('opacity', String(mid < 0.08 ? mid / 0.08 : mid > 0.92 ? (1 - mid) / 0.08 : 1));
186
+ }
187
+ }
188
+ },
189
+ };
190
+ }
191
+
@@ -0,0 +1,212 @@
1
+ // The overlay's painters (docs/editor/LAYERS.md §2): state drawn over a scene's objects, keyed by what each is drawn
2
+ // over. A domain says what to draw (marks: an outline, a badge, a dot, a tag; ghosts: things not in the drawing; cards:
3
+ // a thick card standing over what it is about, with a stack behind it); these make the elements. Shared by an
4
+ // interactive view (drawn into its DOM, measured there) and a still render (drawn into a small virtual document,
5
+ // measured from the layout), so the two never differ. The painters only make elements, with createElementNS,
6
+ // setAttribute, append, textContent and style, the subset the virtual document (src/iso-core/vdom.ts) has.
7
+
8
+ import { C, S } from '../iso-core/kernel.ts';
9
+ import { overlaps } from '../iso-objects/geometry.ts';
10
+
11
+ const SVGNS = 'http://www.w3.org/2000/svg';
12
+ export type Box = { x: number; y: number; w: number; h: number };
13
+ export type Outline = { kind: 'poly'; id: string; points: [number, number][] } | { kind: 'route'; d: string };
14
+ /** a box in grid cells */
15
+ export type Box3 = { x0: number; x1: number; y0: number; y1: number; z0: number; z1: number };
16
+ /** a card's model: its middle, the tail's tip (z), the card's box and its stack's boxes */
17
+ export interface CardGeo { cx: number; cy: number; tipZ: number; card: Box3; panes: Box3[] }
18
+
19
+ /** a badge: a character, or an icon (by name), in a small circle; cls: its tone */
20
+ export type Glyph = { g: string; cls: string } | { icon: string; cls: string };
21
+
22
+ /** what is drawn over one object, in this order: its outline, its badge (or, with none, a hit area for its title),
23
+ * badges beside it, a dot at its bottom left and a tag at its bottom right */
24
+ export interface Mark {
25
+ /** what it is drawn over (the host's boxOf and outlinesFor know it) */
26
+ at: string;
27
+ title: string;
28
+ /** the class of its outline: an outline is drawn when it has one */
29
+ outline?: string;
30
+ badge?: Glyph;
31
+ /** no badge: a transparent rect over it, holding its title */
32
+ hit?: boolean;
33
+ /** badges beside the first, each a badge's width further right */
34
+ beside?: { glyph: Glyph; title: string }[];
35
+ dot?: { glyph: Glyph; title: string };
36
+ tag?: { cls: string; text: string };
37
+ }
38
+
39
+ /** a thing that isn't in the drawing, drawn as a ghost where the domain puts it */
40
+ export interface Ghost {
41
+ rect: { x: number; y: number; w: number; hgt: number; k: number };
42
+ /** classes beside the ghost's own */
43
+ cls: string;
44
+ /** attributes on its group (data-*) */
45
+ data: [string, string][];
46
+ line1: string; line2: string; title: string;
47
+ }
48
+
49
+ /** a card standing over what it is about */
50
+ export interface Card {
51
+ /** the box (grid cells) it stands over */
52
+ over: { x0: number; y0: number; x1: number; y1: number; z1: number };
53
+ /** classes beside the card's own */
54
+ cls: string;
55
+ /** attributes on its group (data-*) */
56
+ data: [string, string][];
57
+ /** the big mark on its face, who it is from, how old it is, and (shown near) one line of its text */
58
+ mark: string; who: string; age: string; line?: string;
59
+ /** how many it stands for: more than one, a stack behind it (up to three) and the count on it */
60
+ count: number;
61
+ title: string;
62
+ }
63
+
64
+ export interface OverlayCtx {
65
+ /** pixels per unit of the drawing (badges keep their size on screen) */
66
+ k(): number;
67
+ /** an object's box on screen (the view measures its elements; a still render, its layout) */
68
+ boxOf(at: string): Box | undefined;
69
+ outlinesFor(at: string): Outline[];
70
+ /** an icon's reference (the view's sprite, or the still render's own symbols) */
71
+ iconHref(name: string): string;
72
+ /** a card drawn, with its geometry in grid cells (a view turns it in 3D) */
73
+ onCard?(card: Element, geo: CardGeo): void;
74
+ }
75
+
76
+ /** the card's size in grid cells (large: the first thing the eye finds), its height above what it stands over, the
77
+ * stack's fan (up and right per card) and the gap between its cards (back to front) */
78
+ export const CARD = { half: 2.4, h: 3.2, t: 0.25, above: 1.4, lift: 3.8, fan: 0.32, gap: 0.3 };
79
+ export const P3 = (x: number, y: number, z: number) => [(x - y) * C * S, (x + y) * 0.5 * S - z * S] as [number, number];
80
+ export const pts = (ps: [number, number][]) => ps.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(' ');
81
+
82
+ /** The painters. cards: the class prefix the domain's cards are drawn and styled with (PREFIX-card, PREFIX-face…). */
83
+ export function overlayPaint(ctx: OverlayCtx, cards: string) {
84
+ function paintMarks(d: Document, put: (n: Element) => void, marks: Mark[]) {
85
+ const k = ctx.k();
86
+ const glyph = (x: number, y: number, spec: Glyph, title: string, extra = '') => {
87
+ const g = d.createElementNS(SVGNS, 'g');
88
+ g.setAttribute('class', `live-badge ${spec.cls} ${extra}`.trim());
89
+ const rr = 8 / k;
90
+ const c = d.createElementNS(SVGNS, 'circle'); c.setAttribute('cx', String(x)); c.setAttribute('cy', String(y)); c.setAttribute('r', String(rr));
91
+ g.append(c);
92
+ if ('g' in spec) {
93
+ const t = d.createElementNS(SVGNS, 'text'); t.setAttribute('x', String(x)); t.setAttribute('y', String(y)); t.style.fontSize = `${(10 / k).toFixed(2)}px`; t.textContent = spec.g; g.append(t);
94
+ } else {
95
+ const u = d.createElementNS(SVGNS, 'use'); u.setAttribute('href', ctx.iconHref(spec.icon)); const s = 11 / k;
96
+ u.setAttribute('x', String(x - s / 2)); u.setAttribute('y', String(y - s / 2)); u.setAttribute('width', String(s)); u.setAttribute('height', String(s)); g.append(u);
97
+ }
98
+ const tt = d.createElementNS(SVGNS, 'title'); tt.textContent = title; g.append(tt);
99
+ put(g);
100
+ };
101
+ const outline = (at: string, cls: string) => {
102
+ for (const sh of ctx.outlinesFor(at)) {
103
+ if (sh.kind !== 'poly') continue;
104
+ const p = d.createElementNS(SVGNS, 'polygon');
105
+ p.setAttribute('class', cls);
106
+ p.setAttribute('points', sh.points.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(' '));
107
+ put(p);
108
+ }
109
+ };
110
+ for (const m of marks) {
111
+ const b = ctx.boxOf(m.at);
112
+ if (!b) continue;
113
+ if (m.outline) outline(m.at, m.outline);
114
+ if (m.badge) glyph(b.x, b.y, m.badge, m.title);
115
+ else if (m.hit) { const t = d.createElementNS(SVGNS, 'title'); t.textContent = m.title; const hit = d.createElementNS(SVGNS, 'rect'); hit.setAttribute('class', 'live-hit'); hit.setAttribute('x', String(b.x)); hit.setAttribute('y', String(b.y)); hit.setAttribute('width', String(b.w)); hit.setAttribute('height', String(b.h)); hit.append(t); put(hit); }
116
+ (m.beside ?? []).forEach((x, i) => glyph(b.x + (18 * (i + 1)) / k, b.y, x.glyph, x.title));
117
+ if (m.dot) glyph(b.x, b.y + b.h, m.dot.glyph, m.dot.title);
118
+ if (m.tag) {
119
+ const t = d.createElementNS(SVGNS, 'text');
120
+ t.setAttribute('class', `live-life ${m.tag.cls}`); t.setAttribute('x', String(b.x + b.w)); t.setAttribute('y', String(b.y + b.h));
121
+ t.style.fontSize = `${(9 / k).toFixed(2)}px`; t.textContent = m.tag.text;
122
+ put(t);
123
+ }
124
+ }
125
+ }
126
+
127
+ function paintGhosts(d: Document, put: (n: Element) => void, ghosts: Ghost[]) {
128
+ for (const gh of ghosts) {
129
+ const g = d.createElementNS(SVGNS, 'g');
130
+ g.setAttribute('class', `live-extra${gh.cls}`);
131
+ for (const [a, v] of gh.data) g.setAttribute(a, v);
132
+ const { x, y, w, hgt, k } = gh.rect;
133
+ const r = d.createElementNS(SVGNS, 'rect');
134
+ r.setAttribute('x', String(x)); r.setAttribute('y', String(y)); r.setAttribute('width', String(w)); r.setAttribute('height', String(hgt)); r.setAttribute('rx', String(6 / k));
135
+ const t1 = d.createElementNS(SVGNS, 'text'); t1.setAttribute('x', String(x + 8 / k)); t1.setAttribute('y', String(y + 13 / k)); t1.style.fontSize = `${(11 / k).toFixed(2)}px`; t1.textContent = gh.line1;
136
+ const t2 = d.createElementNS(SVGNS, 'text'); t2.setAttribute('class', 'sub'); t2.setAttribute('x', String(x + 8 / k)); t2.setAttribute('y', String(y + 27 / k)); t2.style.fontSize = `${(9 / k).toFixed(2)}px`; t2.textContent = gh.line2;
137
+ const tt = d.createElementNS(SVGNS, 'title'); tt.textContent = gh.title;
138
+ g.append(r, t1, t2, tt);
139
+ put(g);
140
+ }
141
+ }
142
+
143
+ /** each card over its box, lifted until it overlaps no card already placed; drawn back to front */
144
+ function paintCards(d: Document, put: (n: Element) => void, list: Card[]) {
145
+ const placed: { x0: number; y0: number; x1: number; y1: number }[] = [];
146
+ for (const cd of list) {
147
+ const b = cd.over, cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2;
148
+ let lift = 0, bbox = { x0: 0, y0: 0, x1: 0, y1: 0 };
149
+ for (let tries = 0; tries < 6; tries++) {
150
+ const z0 = b.z1 + CARD.above + lift, z1 = z0 + CARD.h;
151
+ const corners = [P3(cx - CARD.half, cy + CARD.t, z0), P3(cx + CARD.half, cy + CARD.t, z0), P3(cx + CARD.half, cy - CARD.t, z1), P3(cx - CARD.half, cy + CARD.t, z1)];
152
+ bbox = { x0: Math.min(...corners.map(p => p[0])), y0: Math.min(...corners.map(p => p[1])), x1: Math.max(...corners.map(p => p[0])), y1: Math.max(...corners.map(p => p[1])) };
153
+ if (!overlaps(bbox, placed)) break;
154
+ lift += CARD.lift;
155
+ }
156
+ placed.push(bbox);
157
+ const z0 = b.z1 + CARD.above + lift, z1 = z0 + CARD.h, x0 = cx - CARD.half, x1 = cx + CARD.half, yf = cy + CARD.t, yb = cy - CARD.t;
158
+ const g = d.createElementNS(SVGNS, 'g');
159
+ g.setAttribute('class', `${cards}-card${cd.cls}`);
160
+ for (const [a, v] of cd.data) g.setAttribute(a, v);
161
+ // it grows out of what it stands over: every motion's origin is the tail's tip
162
+ const [tipX, tipY] = P3(cx, cy, b.z1 + 0.15);
163
+ const origin = `${tipX.toFixed(1)}px ${tipY.toFixed(1)}px`;
164
+ g.style.transformOrigin = origin;
165
+ const float = d.createElementNS(SVGNS, 'g');
166
+ float.setAttribute('class', `${cards}-float`);
167
+ float.style.transformOrigin = origin;
168
+ const panes: Box3[] = [];
169
+ // the stack behind it: one card per further one, each as thick as the front one (its front, top and side), behind
170
+ // the card's back face by a constant pitch and fanned up and right by the same step, so the gaps read equal.
171
+ // Drawn back to front.
172
+ for (let i = Math.min(cd.count - 1, 3); i >= 1; i--) {
173
+ const o = i * CARD.fan, pf = yb - (i - 1) * (2 * CARD.t + CARD.gap) - CARD.gap, pb = pf - 2 * CARD.t;
174
+ const a0 = x0 + o, a1 = x1 + o, h0 = z0 + o, h1 = z1 + o;
175
+ const pane = (cls: string, ps: [number, number][]) => { const f = d.createElementNS(SVGNS, 'polygon'); f.setAttribute('class', `${cards}-face stacked ${cls}`); f.setAttribute('points', pts(ps)); float.append(f); };
176
+ pane('s-top', [P3(a0, pb, h1), P3(a1, pb, h1), P3(a1, pf, h1), P3(a0, pf, h1)]);
177
+ pane('s-side', [P3(a1, pb, h0), P3(a1, pf, h0), P3(a1, pf, h1), P3(a1, pb, h1)]);
178
+ pane('s-front', [P3(a0, pf, h0), P3(a1, pf, h0), P3(a1, pf, h1), P3(a0, pf, h1)]);
179
+ panes.push({ x0: a0, x1: a1, y0: pb, y1: pf, z0: h0, z1: h1 });
180
+ }
181
+ // the tail, down to what it stands over
182
+ const tail = d.createElementNS(SVGNS, 'polygon');
183
+ tail.setAttribute('class', `${cards}-tail`);
184
+ tail.setAttribute('points', pts([P3(cx - 0.5, yf, z0 + 0.05), P3(cx + 0.5, yf, z0 + 0.05), P3(cx, cy, b.z1 + 0.15)]));
185
+ // the card: its top, its side, its face
186
+ const face = (cls: string, ps: [number, number][]) => { const f = d.createElementNS(SVGNS, 'polygon'); f.setAttribute('class', cls); f.setAttribute('points', pts(ps)); return f; };
187
+ const front = face(`${cards}-face front`, [P3(x0, yf, z0), P3(x1, yf, z0), P3(x1, yf, z1), P3(x0, yf, z1)]);
188
+ float.append(tail,
189
+ face(`${cards}-face top`, [P3(x0, yb, z1), P3(x1, yb, z1), P3(x1, yf, z1), P3(x0, yf, z1)]),
190
+ face(`${cards}-face side`, [P3(x1, yb, z0), P3(x1, yf, z0), P3(x1, yf, z1), P3(x1, yb, z1)]),
191
+ front);
192
+ // what the face says, on the face (its plane: x along the card, down the card's height)
193
+ const [ox, oy] = P3(x0, yf, z1), U = 40;
194
+ const txt = d.createElementNS(SVGNS, 'g');
195
+ txt.setAttribute('transform', `matrix(${(C * S / U).toFixed(4)} ${(0.5 * S / U).toFixed(4)} 0 ${(S / U).toFixed(4)} ${ox.toFixed(1)} ${oy.toFixed(1)})`);
196
+ const t = (cls: string, x: number, y: number, text: string) => { const e = d.createElementNS(SVGNS, 'text'); e.setAttribute('class', cls); e.setAttribute('x', String(x)); e.setAttribute('y', String(y)); e.textContent = text; return e; };
197
+ // the face is 192 × 128 of these units (40 a cell): the mark fills its left, who and the age beside it
198
+ txt.append(t(`${cards}-mark`, 34, 98, cd.mark), t(`${cards}-who`, 70, 52, cd.who), t(`${cards}-age`, 70, 82, cd.age));
199
+ if (cd.line !== undefined) txt.append(t(`${cards}-q`, 12, 118, cd.line));
200
+ if (cd.count > 1) { const c = d.createElementNS(SVGNS, 'circle'); c.setAttribute('class', `${cards}-count-bg`); c.setAttribute('cx', '178'); c.setAttribute('cy', '14'); c.setAttribute('r', '15'); txt.append(c, t(`${cards}-count`, 178, 14, String(cd.count))); }
201
+ float.append(txt);
202
+ const title = d.createElementNS(SVGNS, 'title');
203
+ title.textContent = cd.title;
204
+ g.append(float, title);
205
+ ctx.onCard?.(g, { cx, cy, tipZ: b.z1 + 0.15, card: { x0, x1, y0: yb, y1: yf, z0, z1 }, panes: panes.reverse() });
206
+ put(g);
207
+ }
208
+ }
209
+
210
+ return { paintMarks, paintGhosts, paintCards };
211
+ }
212
+ export type OverlayPaint = ReturnType<typeof overlayPaint>;
@@ -0,0 +1,6 @@
1
+ {
2
+ "//": "iso-viewer (L2) has no side effects: bundles drop the modules they do not use. LAYERS.md S4.",
3
+ "type": "module",
4
+ "private": true,
5
+ "sideEffects": false
6
+ }
@@ -0,0 +1,150 @@
1
+ // The HTML page around the scenes: header, one section per scene, theme toggle. One file, no network.
2
+
3
+ import { esc } from '../iso-core/kernel.ts';
4
+ import type { Compiled } from '../iso-objects/compile.ts';
5
+ import { themeCss } from '../iso-core/theme.ts';
6
+ import { baseCss, PLAYER_CSS } from '../iso-objects/css.ts';
7
+ import { regionKind } from '../iso-objects/kinds.ts';
8
+ import type { CompiledScene } from '../iso-objects/compile.ts';
9
+ import { colorRef } from '../iso-core/theme.ts';
10
+
11
+ /** the page's script tags opened as a joined string: a bundle of this module, inlined in an HTML page, then holds no
12
+ * "<script" (which would switch the page's parser) — a minifier folds a literal, never a join */
13
+ const SCRIPT = ['<', 'script'].join('');
14
+
15
+ /** A small Markdown subset for captions: `code`, **bold**, *em*, [text](url), paragraphs. */
16
+ export function md(s: string | undefined): string {
17
+ if (!s) return '';
18
+ return esc(s)
19
+ .replace(/`([^`]+)`/g, '<code>$1</code>')
20
+ .replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>')
21
+ .replace(/(^|[^*])\*([^*\s][^*]*)\*/g, '$1<em>$2</em>')
22
+ .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, t, u) => /^(https?:|#|\.{0,2}\/)/.test(u.replace(/&amp;/g, '&')) ? `<a href="${u}">${t}</a>` : t);
23
+ }
24
+ const paras = (s: string | undefined) => (s ?? '').split(/\n\s*\n/).filter(Boolean).map(p => `<p class="sec-sub">${md(p.trim())}</p>`).join('');
25
+
26
+ export interface PageOpts { runtime?: string; extraHead?: string; extraBody?: string }
27
+
28
+ /** The data the player runs on, for every scene with steps. */
29
+ export function stepData(c: Compiled): string {
30
+ return JSON.stringify({
31
+ scenes: c.scenes.map(s => ({
32
+ id: s.id, loop: s.raw.loop ?? true, dim: s.raw.dim ?? 'flows', vis: s.steps.vis,
33
+ steps: s.steps.steps.map(st => ({ ...st, caption: md(st.caption) })),
34
+ assemble: s.assemble, grid: !!s.grid.show, assembly: s.rendered.assembly,
35
+ })),
36
+ });
37
+ }
38
+
39
+ export function legend(c: Compiled, s: CompiledScene): string {
40
+ const t = c.theme!, spec = s.raw.legend;
41
+ if (spec === false) return '';
42
+ const kinds = Array.isArray(spec) ? spec : s.steps.kindsUsed.filter(k => s.routes.some(r => r.kind === k) || s.steps.steps.some(st => st.phases.some(p => p.some(tk => tk.kind === k))));
43
+ // a region kind's own row (its kind's legend), else a route kind's from the theme
44
+ const row = (l: { label: string; swatch: string; box: boolean }) => `<span><i${l.box ? ' class="box"' : ''} style="${l.swatch}"></i>${l.label}</span>`;
45
+ const items = kinds.map(k => {
46
+ const rl = regionKind(c.catalog, k)?.legend;
47
+ if (rl) return row(rl);
48
+ const d = t.kinds[k];
49
+ if (!d) return '';
50
+ const style = `border-color:${colorRef(t, d.color)}${d.dash === 'dashed' ? ';border-top-style:dashed' : d.dash === 'dotted' ? ';border-top-style:dotted' : ''}`;
51
+ return `<span><i style="${style}"></i>${md(d.legend)}</span>`;
52
+ });
53
+ if (!Array.isArray(spec)) {
54
+ const kindsOf = new Set(s.layout.items.map(p => p.region?.kind));
55
+ for (const [name, rk] of Object.entries(c.catalog.regions)) if (rk.legend?.auto && kindsOf.has(name)) items.push(row(rk.legend));
56
+ }
57
+ return items.join('');
58
+ }
59
+
60
+ function player(s: CompiledScene): string {
61
+ const st = s.steps.steps;
62
+ const tools = `<div class="tools">
63
+ <button class="pbtn small" type="button" data-a="grid" aria-pressed="${s.grid.show ? 'true' : 'false'}" title="Show the floor grid">Grid</button>
64
+ <button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
65
+ </div>`;
66
+ if (!st.length) return `<div class="player">${tools}</div>`;
67
+ const f = st[0];
68
+ return `<div class="player">
69
+ <div class="ctrls">
70
+ <button class="pbtn icon" type="button" data-a="prev" aria-label="Previous step">‹</button>
71
+ <button class="pbtn primary" type="button" data-a="play" aria-label="Play">▶ Play</button>
72
+ <button class="pbtn icon" type="button" data-a="next" aria-label="Next step">›</button>
73
+ </div>
74
+ ${tools}
75
+ <div class="cap" aria-live="polite">
76
+ <div class="cap-h"><span class="num" style="background:${f.color}">${f.num}</span><span class="h">${esc(f.heading)}</span><span class="cnt">1 / ${st.length}</span></div>
77
+ <p class="cap-t">${md(f.caption)}</p>
78
+ <pre class="cap-c">${esc(f.command)}</pre>
79
+ <div class="prog"><i></i></div>
80
+ </div>
81
+ <div class="dots"></div>
82
+ </div>`;
83
+ }
84
+
85
+ function stepList(s: CompiledScene): string {
86
+ const st = s.steps.steps;
87
+ if (!st.length) return '';
88
+ return `<details class="steps"><summary>All ${st.length} steps as text</summary><ol>${st.map(x =>
89
+ `<li value="${x.num}"><b>${esc(x.heading)}.</b> ${md(x.caption)}${x.command ? `<br><code>${esc(x.command)}</code>` : ''}</li>`).join('')}</ol></details>`;
90
+ }
91
+
92
+ export function renderPage(c: Compiled, opts: PageOpts = {}): string {
93
+ const doc = c.doc!, title = doc.title ?? doc.scenes[0]?.title ?? 'Diagram';
94
+ const pills = (doc.pills ?? []).map(p => `<span class="pill">${md(p)}</span>`).join('');
95
+ const sections = c.scenes.map(s => `
96
+ <section class="scene" id="scene-${esc(s.id)}">
97
+ <h2>${esc(s.raw.title)}</h2>
98
+ ${paras(s.raw.caption)}
99
+ <div class="figure" tabindex="-1">
100
+ <div class="scroller">${s.grid.show ? s.rendered.svg.replace('<svg ', '<svg class="show-grid" ') : s.rendered.svg}</div>
101
+ ${player(s)}
102
+ <div class="legend">${legend(c, s)}</div>
103
+ </div>
104
+ ${stepList(s)}
105
+ ${s.raw.after ? `<div class="after">${paras(s.raw.after)}</div>` : ''}
106
+ </section>`).join('\n');
107
+ return `<!doctype html>
108
+ <html lang="en">
109
+ <head>
110
+ <meta charset="utf-8">
111
+ <meta name="viewport" content="width=device-width, initial-scale=1">
112
+ <title>${esc(title)}</title>
113
+ ${doc.lede ? `<meta name="description" content="${esc(doc.lede)}">` : ''}
114
+ <style>
115
+ ${themeCss(c.theme!)}${baseCss(c.catalog)}${PLAYER_CSS}
116
+ </style>
117
+ ${opts.extraHead ?? ''}
118
+ </head>
119
+ <body>
120
+ <div class="wrap">
121
+ <header class="page">
122
+ <div>
123
+ <h1>${esc(title)}</h1>
124
+ ${doc.lede ? `<p class="lede">${md(doc.lede)}</p>` : ''}
125
+ </div>
126
+ <div class="pills">${pills}<button class="theme" id="themeBtn" type="button">Theme</button></div>
127
+ </header>
128
+ ${sections}
129
+ ${doc.after ? paras(doc.after) : ''}
130
+ ${doc.footer ? `<footer>${md(doc.footer)}</footer>` : ''}
131
+ </div>
132
+ ${SCRIPT} type="application/json" id="diagram-steps">${stepData(c).replace(/</g, '\\u003c')}</script>
133
+ ${SCRIPT}>
134
+ (function(){
135
+ var root=document.documentElement, m=/theme=(light|dark)/.exec(location.hash);
136
+ try{var t=localStorage.getItem('diagram-theme'); if(t) root.dataset.theme=t;}catch(e){}
137
+ if(m) root.dataset.theme=m[1];
138
+ document.getElementById('themeBtn').addEventListener('click',function(){
139
+ var dark=root.dataset.theme?root.dataset.theme==='dark':matchMedia('(prefers-color-scheme: dark)').matches;
140
+ root.dataset.theme=dark?'light':'dark';
141
+ try{localStorage.setItem('diagram-theme',root.dataset.theme);}catch(e){}
142
+ });
143
+ })();
144
+ </script>
145
+ ${opts.runtime ? `${SCRIPT}>${opts.runtime}</script>` : ''}
146
+ ${opts.extraBody ?? ''}
147
+ </body>
148
+ </html>
149
+ `;
150
+ }