@puzzmo/sdk 1.0.81 → 1.0.82

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 (148) hide show
  1. package/dist/analytics.d.ts.map +1 -1
  2. package/dist/bootstrapPayload.d.ts.map +1 -1
  3. package/dist/bootstrapPayload.spec.d.ts.map +1 -1
  4. package/dist/bundles.cjs +1 -1
  5. package/dist/bundles.cjs.map +1 -1
  6. package/dist/bundles.d.ts +10 -2
  7. package/dist/bundles.d.ts.map +1 -1
  8. package/dist/bundles.js +2 -2
  9. package/dist/bundles.js.map +1 -1
  10. package/dist/contracts.d.ts.map +1 -1
  11. package/dist/createSimulator-CIE72Xs2.cjs +2233 -0
  12. package/dist/createSimulator-CIE72Xs2.cjs.map +1 -0
  13. package/dist/{createSimulator-2M7vXzRZ.js → createSimulator-Dz1KYZ25.js} +1579 -596
  14. package/dist/createSimulator-Dz1KYZ25.js.map +1 -0
  15. package/dist/easing.d.ts +6 -0
  16. package/dist/easing.d.ts.map +1 -0
  17. package/dist/editor.d.ts +25 -3
  18. package/dist/editor.d.ts.map +1 -1
  19. package/dist/fontFiles.gen.d.ts.map +1 -1
  20. package/dist/fonts-CP_kAAac.js +83 -0
  21. package/dist/fonts-CP_kAAac.js.map +1 -0
  22. package/dist/fonts-CS5qdLf3.cjs +3 -0
  23. package/dist/fonts-CS5qdLf3.cjs.map +1 -0
  24. package/dist/fonts.cjs +1 -3
  25. package/dist/fonts.d.ts +2 -0
  26. package/dist/fonts.d.ts.map +1 -1
  27. package/dist/fonts.js +2 -83
  28. package/dist/gameTracker.d.ts.map +1 -1
  29. package/dist/global.d.ts.map +1 -1
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.global.js.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/inputs/decoder.d.ts.map +1 -1
  36. package/dist/inputs/encoder.d.ts.map +1 -1
  37. package/dist/inputs/encodings.d.ts.map +1 -1
  38. package/dist/inputs/index.d.ts.map +1 -1
  39. package/dist/inputs/inputStringEncoder.spec.d.ts.map +1 -1
  40. package/dist/inputs/migration.d.ts.map +1 -1
  41. package/dist/inputs/types.d.ts.map +1 -1
  42. package/dist/keyboard.d.ts.map +1 -1
  43. package/dist/keyboard.spec.d.ts.map +1 -1
  44. package/dist/{lua-DKb2Tu2V.js → lua-B8exrfmB.js} +1 -1
  45. package/dist/{lua-DKb2Tu2V.js.map → lua-B8exrfmB.js.map} +1 -1
  46. package/dist/{lua-CclI-QKD.cjs → lua-C5r7UXeR.cjs} +1 -1
  47. package/dist/{lua-CclI-QKD.cjs.map → lua-C5r7UXeR.cjs.map} +1 -1
  48. package/dist/pico8/channel.d.ts.map +1 -1
  49. package/dist/pico8/index.cjs +1 -1
  50. package/dist/pico8/index.d.ts.map +1 -1
  51. package/dist/pico8/index.js +1 -1
  52. package/dist/pico8/lua.d.ts.map +1 -1
  53. package/dist/pico8/palette.d.ts.map +1 -1
  54. package/dist/pico8/pico8.spec.d.ts.map +1 -1
  55. package/dist/pico8/protocol.d.ts.map +1 -1
  56. package/dist/pico8/vitePlugin.d.ts.map +1 -1
  57. package/dist/plugins.d.ts.map +1 -1
  58. package/dist/plugins.spec.d.ts.map +1 -1
  59. package/dist/sdk.d.ts.map +1 -1
  60. package/dist/sdk.gameCompleted.spec.d.ts.map +1 -1
  61. package/dist/sdk.gameReady.spec.d.ts.map +1 -1
  62. package/dist/sdk.pause.spec.d.ts.map +1 -1
  63. package/dist/sdk.session.spec.d.ts.map +1 -1
  64. package/dist/settings.spec.d.ts.map +1 -1
  65. package/dist/simulator/checklistProgress.d.ts.map +1 -1
  66. package/dist/simulator/checklistProgress.spec.d.ts.map +1 -1
  67. package/dist/simulator/createSimulator.d.ts.map +1 -1
  68. package/dist/simulator/dockedKeyboard.d.ts.map +1 -1
  69. package/dist/simulator/fixtures.d.ts.map +1 -1
  70. package/dist/simulator/index.cjs +1 -1
  71. package/dist/simulator/index.d.ts.map +1 -1
  72. package/dist/simulator/index.js +2 -1
  73. package/dist/simulator/marker.d.ts.map +1 -1
  74. package/dist/simulator/messaging.d.ts.map +1 -1
  75. package/dist/simulator/normalizeThumbnail.d.ts.map +1 -1
  76. package/dist/simulator/pmmgOverlay.d.ts +36 -0
  77. package/dist/simulator/pmmgOverlay.d.ts.map +1 -0
  78. package/dist/simulator/pmmgOverlay.spec.d.ts +2 -0
  79. package/dist/simulator/pmmgOverlay.spec.d.ts.map +1 -0
  80. package/dist/simulator/pmmgRenderer.d.ts +86 -0
  81. package/dist/simulator/pmmgRenderer.d.ts.map +1 -0
  82. package/dist/simulator/pmmgRenderer.spec.d.ts +2 -0
  83. package/dist/simulator/pmmgRenderer.spec.d.ts.map +1 -0
  84. package/dist/simulator/standalone.cjs +1 -1
  85. package/dist/simulator/standalone.cjs.map +1 -1
  86. package/dist/simulator/standalone.d.ts.map +1 -1
  87. package/dist/simulator/standalone.js +2 -1
  88. package/dist/simulator/standalone.js.map +1 -1
  89. package/dist/simulator/state.d.ts +19 -0
  90. package/dist/simulator/state.d.ts.map +1 -1
  91. package/dist/simulator/state.spec.d.ts.map +1 -1
  92. package/dist/simulator/styles.d.ts +1 -1
  93. package/dist/simulator/styles.d.ts.map +1 -1
  94. package/dist/simulator/types.d.ts +5 -0
  95. package/dist/simulator/types.d.ts.map +1 -1
  96. package/dist/simulator/views/AuthView.d.ts.map +1 -1
  97. package/dist/simulator/views/ChecklistView.d.ts.map +1 -1
  98. package/dist/simulator/views/CheckpointsView.d.ts.map +1 -1
  99. package/dist/simulator/views/CtrlView.d.ts.map +1 -1
  100. package/dist/simulator/views/DataView.d.ts.map +1 -1
  101. package/dist/simulator/views/DoneView.d.ts.map +1 -1
  102. package/dist/simulator/views/FeaturesView.d.ts.map +1 -1
  103. package/dist/simulator/views/HostView.d.ts.map +1 -1
  104. package/dist/simulator/views/KeyboardView.d.ts.map +1 -1
  105. package/dist/simulator/views/MsgsView.d.ts.map +1 -1
  106. package/dist/simulator/views/PmmgView.d.ts +7 -0
  107. package/dist/simulator/views/PmmgView.d.ts.map +1 -0
  108. package/dist/simulator/views/SettingsView.d.ts.map +1 -1
  109. package/dist/simulator/views/SoundView.d.ts.map +1 -1
  110. package/dist/simulator/views/ThemeView.d.ts.map +1 -1
  111. package/dist/simulator/views/ThumbView.d.ts.map +1 -1
  112. package/dist/simulator/views/index.d.ts +1 -0
  113. package/dist/simulator/views/index.d.ts.map +1 -1
  114. package/dist/svgJSX.d.ts.map +1 -1
  115. package/dist/tableBoard-B0I9wVQq.js +635 -0
  116. package/dist/tableBoard-B0I9wVQq.js.map +1 -0
  117. package/dist/tableBoard-CLDBwRYs.cjs +2 -0
  118. package/dist/tableBoard-CLDBwRYs.cjs.map +1 -0
  119. package/dist/tableBoard.cjs +1 -0
  120. package/dist/tableBoard.d.ts +138 -0
  121. package/dist/tableBoard.d.ts.map +1 -0
  122. package/dist/tableBoard.js +2 -0
  123. package/dist/tableBoardScene.d.ts +21 -0
  124. package/dist/tableBoardScene.d.ts.map +1 -0
  125. package/dist/themes.d.ts +16 -16
  126. package/dist/themes.d.ts.map +1 -1
  127. package/dist/types.d.ts +161 -0
  128. package/dist/types.d.ts.map +1 -1
  129. package/dist/vite.cjs +3 -3
  130. package/dist/vite.cjs.map +1 -1
  131. package/dist/vite.d.ts +20 -0
  132. package/dist/vite.d.ts.map +1 -1
  133. package/dist/vite.js +72 -16
  134. package/dist/vite.js.map +1 -1
  135. package/package.json +5 -5
  136. package/dist/createSimulator-2M7vXzRZ.js.map +0 -1
  137. package/dist/createSimulator-B4QlohUV.cjs +0 -1930
  138. package/dist/createSimulator-B4QlohUV.cjs.map +0 -1
  139. package/dist/fonts.cjs.map +0 -1
  140. package/dist/fonts.js.map +0 -1
  141. package/dist/thumbnailMotion.cjs +0 -5
  142. package/dist/thumbnailMotion.cjs.map +0 -1
  143. package/dist/thumbnailMotion.d.ts +0 -119
  144. package/dist/thumbnailMotion.d.ts.map +0 -1
  145. package/dist/thumbnailMotion.js +0 -480
  146. package/dist/thumbnailMotion.js.map +0 -1
  147. package/dist/thumbnailMotion.spec.d.ts +0 -2
  148. package/dist/thumbnailMotion.spec.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableBoard-B0I9wVQq.js","names":[],"sources":["../src/easing.ts","../src/tableBoardScene.ts","../src/tableBoard.ts"],"sourcesContent":["// CSS easings as progress functions, for the table's boards. A scene names its easings in CSS syntax, so a game writes\n// the same `ease-out` or `cubic-bezier()` it would in a stylesheet.\n\n/**\n * Turns a CSS easing into a progress function: keywords, cubic-bezier() and linear() with optional stops. Anything\n * else (`steps()`, or a malformed value) is linear.\n */\nexport const parseEasing = (value: string): ((t: number) => number) => {\n const v = value.trim()\n if (v === \"linear\") return linear\n const keyword = keywordEasings[v]\n if (keyword) return cubicBezier(keyword[0], keyword[1], keyword[2], keyword[3])\n const bezier = /^cubic-bezier\\(([^)]+)\\)$/.exec(v)\n if (bezier) {\n const n = bezier[1].split(\",\").map(Number)\n if (n.length !== 4 || n.some((x) => Number.isNaN(x))) return linear\n return cubicBezier(n[0], n[1], n[2], n[3])\n }\n const lin = /^linear\\(([^)]+)\\)$/.exec(v)\n if (lin) return linearStops(lin[1])\n return linear\n}\n\nconst linear = (t: number) => t\n\nconst keywordEasings: Record<string, [number, number, number, number]> = {\n ease: [0.25, 0.1, 0.25, 1],\n \"ease-in\": [0.42, 0, 1, 1],\n \"ease-out\": [0, 0, 0.58, 1],\n \"ease-in-out\": [0.42, 0, 0.58, 1],\n}\n\nconst cubicBezier = (x1: number, y1: number, x2: number, y2: number) => {\n const sx = (t: number) => 3 * x1 * t * (1 - t) * (1 - t) + 3 * x2 * t * t * (1 - t) + t * t * t\n const sy = (t: number) => 3 * y1 * t * (1 - t) * (1 - t) + 3 * y2 * t * t * (1 - t) + t * t * t\n return (x: number) => {\n let lo = 0\n let hi = 1\n let t = x\n for (let i = 0; i < 24; i++) {\n const cx = sx(t)\n if (Math.abs(cx - x) < 1e-5) break\n if (cx < x) lo = t\n else hi = t\n t = (lo + hi) / 2\n }\n return sy(t)\n }\n}\n\n/** The inside of a linear(), stops with or without positions */\nconst linearStops = (list: string) => {\n const stops = list.split(\",\").map((s) => {\n const parts = s.trim().split(/\\s+/)\n return { value: Number(parts[0]), at: parts[1] ? parseFloat(parts[1]) / 100 : NaN }\n })\n if (stops.some((stop) => Number.isNaN(stop.value))) return linear\n if (Number.isNaN(stops[0].at)) stops[0].at = 0\n if (Number.isNaN(stops[stops.length - 1].at)) stops[stops.length - 1].at = 1\n // Missing positions spread evenly between the known ones on either side\n let last = 0\n for (let i = 0; i < stops.length; i++) {\n if (!Number.isNaN(stops[i].at)) {\n last = i\n continue\n }\n let next = i\n while (Number.isNaN(stops[next].at)) next++\n for (let j = last + 1; j < next; j++) stops[j].at = stops[last].at + ((stops[next].at - stops[last].at) * (j - last)) / (next - last)\n last = next\n }\n return (t: number) => {\n if (t <= stops[0].at) return stops[0].value\n for (let i = 1; i < stops.length; i++) {\n if (t <= stops[i].at) {\n const a = stops[i - 1]\n const b = stops[i]\n return a.value + ((b.value - a.value) * (t - a.at)) / (b.at - a.at || 1)\n }\n }\n return stops[stops.length - 1].value\n }\n}\n","import type {\n TableBoardAnimation,\n TableBoardBlend,\n TableBoardEffect,\n TableBoardKeyframe,\n TableBoardNode,\n TableBoardScene,\n TableBoardTiming,\n} from \"./types\"\n\n// A scene comes from a game's code, so the host takes nothing on trust: every field is checked and copied, and anything\n// unknown is dropped. A scene that breaks a rule is refused whole, with the reason, rather than drawn in part. In the\n// SDK so the simulator's Pmmg tab refuses the same scenes Puzzmo's table does.\n\n/** The most of each thing one scene can hold */\nexport const sceneLimits = {\n nodes: 5000,\n effects: 5000,\n keyframes: 32,\n /** The longest delay or duration, in ms */\n ms: 10_000,\n /** The largest board, in board units */\n size: 100_000,\n text: 200,\n /** How many nodes deep a node can sit, itself counted. Each isolated level draws on a layer the canvas's size */\n depth: 16,\n /** The brightest a node draws, however its own, its keyframes' and its parents' brightness multiply */\n brightness: 10,\n}\n\n/** The scene with only what the host knows how to draw, or throws saying what's wrong with it */\nexport const validateScene = (input: unknown): TableBoardScene => {\n const scene = record(input, \"The scene\")\n const width = positive(scene.width, \"The scene's width\", sceneLimits.size)\n const height = positive(scene.height, \"The scene's height\", sceneLimits.size)\n const rawNodes = list(scene.nodes, \"The scene's nodes\", sceneLimits.nodes)\n const keys = new Set<string>()\n const parents = new Map<string, string | undefined>()\n // Isolated nodes whose children are being listed, innermost last, and those whose run of children is over\n const open: string[] = []\n const closed = new Set<string>()\n const nodes = rawNodes.map((raw, index) => {\n const node = validateNode(raw, `Node ${index}`)\n if (keys.has(node.key)) throw new Error(`Node ${index}'s key \"${node.key}\" is used twice`)\n if (node.parent !== undefined && !keys.has(node.parent))\n throw new Error(`Node \"${node.key}\"'s parent \"${node.parent}\" must come before it`)\n keys.add(node.key)\n parents.set(node.key, node.parent)\n const ancestors = new Set<string>()\n for (let at = node.parent; at !== undefined; at = parents.get(at)) ancestors.add(at)\n if (ancestors.size >= sceneLimits.depth) throw new Error(`Node \"${node.key}\" is nested over ${sceneLimits.depth} nodes deep`)\n while (open.length && !ancestors.has(open[open.length - 1])) closed.add(open.pop()!)\n const split = [...ancestors].find((key) => closed.has(key))\n if (split) throw new Error(`Node \"${node.key}\" is in isolated \"${split}\", so it must come straight after its other children`)\n if (node.isolate) open.push(node.key)\n return node\n })\n const out: TableBoardScene = { width, height, nodes }\n if (scene.grid !== undefined) out.grid = positive(scene.grid, \"The scene's grid\", width)\n if (scene.transition !== undefined) out.transition = timing(scene.transition, \"The scene's transition\")\n if (scene.effects !== undefined) {\n out.effects = list(scene.effects, \"The scene's effects\", sceneLimits.effects).map((raw, index) => {\n const effect = validateEffect(raw, `Effect ${index}`)\n if (!keys.has(effect.key)) throw new Error(`Effect ${index} is for \"${effect.key}\", which isn't in the scene`)\n return effect\n })\n }\n return out\n}\n\n/** Every sprite a scene names, in its nodes and in its keyframes */\nexport const spritesIn = (scene: TableBoardScene): Set<string> => {\n const ids = new Set<string>()\n const fromFrames = (animation?: TableBoardAnimation) => animation?.keyframes.forEach((frame) => frame.sprite && ids.add(frame.sprite))\n for (const node of scene.nodes) {\n if (node.sprite) ids.add(node.sprite)\n fromFrames(node.enter)\n fromFrames(node.exit)\n }\n scene.effects?.forEach(fromFrames)\n return ids\n}\n\nconst validateNode = (input: unknown, label: string): TableBoardNode => {\n const raw = record(input, label)\n const node: TableBoardNode = { key: text(raw.key, `${label}'s key`), x: finite(raw.x, `${label}'s x`), y: finite(raw.y, `${label}'s y`) }\n if (raw.sprite !== undefined) node.sprite = text(raw.sprite, `${label}'s sprite`)\n if (raw.parent !== undefined) node.parent = text(raw.parent, `${label}'s parent`)\n if (raw.blend !== undefined) {\n if (!blends.includes(raw.blend as TableBoardBlend)) throw new Error(`${label}'s blend must be one of ${blends.join(\", \")}`)\n node.blend = raw.blend as TableBoardBlend\n }\n if (raw.isolate === true) node.isolate = true\n Object.assign(node, appearance(raw, label))\n if (raw.transition === false) node.transition = false\n else if (raw.transition !== undefined) node.transition = timing(raw.transition, `${label}'s transition`)\n if (raw.enter !== undefined) node.enter = animation(raw.enter, `${label}'s enter`)\n if (raw.exit !== undefined) node.exit = animation(raw.exit, `${label}'s exit`)\n return node\n}\n\nconst validateEffect = (input: unknown, label: string): TableBoardEffect => {\n const raw = record(input, label)\n const effect: TableBoardEffect = { key: text(raw.key, `${label}'s key`), ...animation(raw, label) }\n if (raw.iterations !== undefined) {\n const iterations = Number(raw.iterations)\n if (!(iterations >= 1)) throw new Error(`${label}'s iterations must be 1 or more`)\n effect.iterations = iterations\n }\n return effect\n}\n\n/** The values a node and a keyframe share */\nconst appearance = (raw: Record<string, unknown>, label: string) => {\n const out: Partial<TableBoardKeyframe> = {}\n if (raw.rotation !== undefined) out.rotation = finite(raw.rotation, `${label}'s rotation`)\n if (raw.scale !== undefined) out.scale = pair(raw.scale, `${label}'s scale`)\n if (raw.opacity !== undefined) out.opacity = clamp(finite(raw.opacity, `${label}'s opacity`), 0, 1)\n if (raw.brightness !== undefined) out.brightness = clamp(finite(raw.brightness, `${label}'s brightness`), 0, sceneLimits.brightness)\n if (raw.tint !== undefined) out.tint = text(raw.tint, `${label}'s tint`)\n return out\n}\n\nconst animation = (input: unknown, label: string): TableBoardAnimation => {\n const raw = record(input, label)\n let last = -1\n const keyframes = list(raw.keyframes, `${label}'s keyframes`, sceneLimits.keyframes).map((rawFrame, index) => {\n const frameLabel = `${label}'s keyframe ${index}`\n const frame = record(rawFrame, frameLabel)\n const offset = finite(frame.offset, `${frameLabel}'s offset`)\n if (offset < 0 || offset > 1 || offset < last) throw new Error(`${frameLabel}'s offset must be from 0 to 1, in order`)\n last = offset\n const out: TableBoardKeyframe = { offset, ...appearance(frame, frameLabel) }\n if (frame.x !== undefined) out.x = finite(frame.x, `${frameLabel}'s x`)\n if (frame.y !== undefined) out.y = finite(frame.y, `${frameLabel}'s y`)\n if (frame.easing !== undefined) out.easing = text(frame.easing, `${frameLabel}'s easing`)\n if (frame.sprite !== undefined) out.sprite = text(frame.sprite, `${frameLabel}'s sprite`)\n return out\n })\n return { ...timing(raw, label), keyframes }\n}\n\nconst timing = (input: unknown, label: string): TableBoardTiming => {\n const raw = record(input, label)\n const out: TableBoardTiming = { duration: clamp(finite(raw.duration, `${label}'s duration`), 0, sceneLimits.ms) }\n if (raw.delay !== undefined) out.delay = clamp(finite(raw.delay, `${label}'s delay`), 0, sceneLimits.ms)\n if (raw.easing !== undefined) out.easing = text(raw.easing, `${label}'s easing`)\n return out\n}\n\nconst blends: TableBoardBlend[] = [\n \"normal\",\n \"multiply\",\n \"screen\",\n \"overlay\",\n \"darken\",\n \"lighten\",\n \"color-dodge\",\n \"color-burn\",\n \"hard-light\",\n \"soft-light\",\n \"difference\",\n \"exclusion\",\n \"hue\",\n \"saturation\",\n \"color\",\n \"luminosity\",\n]\n\nconst record = (value: unknown, label: string) => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(`${label} must be an object`)\n return value as Record<string, unknown>\n}\n\nconst list = (value: unknown, label: string, max: number) => {\n if (!Array.isArray(value)) throw new Error(`${label} must be a list`)\n if (value.length > max) throw new Error(`${label} can hold at most ${max}, got ${value.length}`)\n return value as unknown[]\n}\n\nconst text = (value: unknown, label: string) => {\n if (typeof value !== \"string\" || !value || value.length > sceneLimits.text)\n throw new Error(`${label} must be text of 1 to ${sceneLimits.text} characters`)\n return value\n}\n\nconst finite = (value: unknown, label: string) => {\n if (typeof value !== \"number\" || !Number.isFinite(value)) throw new Error(`${label} must be a finite number`)\n return value\n}\n\nconst positive = (value: unknown, label: string, max: number) => {\n const n = finite(value, label)\n if (n <= 0 || n > max) throw new Error(`${label} must be above 0 and at most ${max}`)\n return n\n}\n\nconst pair = (value: unknown, label: string): [number, number] => {\n if (!Array.isArray(value) || value.length !== 2) throw new Error(`${label} must be two numbers`)\n return [finite(value[0], label), finite(value[1], label)]\n}\n\nconst clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n))\n","// A neighbour's board drawn from its game's pmmg bundle (see TableBoardCapability). The bundle turns each update into a\n// scene of keyed nodes and makes the sprites they show, in its sandbox; this draws scenes on a canvas and does all the\n// animating: a node that changes moves from its old values to its new ones, new nodes enter, gone ones exit, and\n// effects play over the top. Every board at the table draws from one animation loop, only while one moves. It's in the\n// SDK so puzzmo.com's table and the simulator's Pmmg tab draw a board the same way.\n//\n// A board draws wherever its canvas is: on the page, or in a worker on a canvas the page handed over, which keeps the\n// drawing off the page's main thread. A worker has no document, so there the page says what it knows of the screen\n// through setTableBoardEnvironment, and sizes the canvas's element from onFit.\n//\n// Updates queue: the step on screen plays out, at most one update waits behind it (a newer one\n// replaces it), and the next render goes from what's showing to what's waiting, so the renderer animates across any\n// update that was passed over.\n\nimport { parseEasing } from \"./easing\"\nimport type {\n TableBoardAnimation,\n TableBoardBackgroundStyle,\n TableBoardBlend,\n TableBoardFidelity,\n TableBoardKeyframe,\n TableBoardNode,\n TableBoardScene,\n TableBoardUpdate,\n Theme,\n} from \"./types\"\nimport { sceneLimits } from \"./tableBoardScene\"\n\nexport { sceneLimits, spritesIn, validateScene } from \"./tableBoardScene\"\n\n/** A sprite's picture, at one resolution */\nexport type SpriteBitmap = {\n bitmap: ImageBitmap\n /** In board units */\n width: number\n height: number\n anchor: [number, number]\n}\n\n/** What a board draws from: Puzzmo's sandboxed pmmg bundle at the table, the game's own code in the simulator */\nexport type TableBoardRenderer = {\n /** The board after an update, once every sprite it names is here to draw */\n render(update: TableBoardUpdate): Promise<TableBoardScene>\n /** A sprite at a resolution, once a render has made it */\n sprite(id: string, pixelsPerUnit: number): SpriteBitmap | undefined\n}\n\n/** One frame as a board drew it, for a debugging overlay drawn over the top */\nexport type TableBoardFrame = {\n /** The board's canvas, its transform reset, so the overlay draws in device pixels */\n ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D\n /** Device pixels per board unit on the canvas */\n scale: number\n scene: TableBoardScene\n /** Every node with a place this frame, in drawing order, children after their parents */\n nodes: TableBoardDrawnNode[]\n}\n\nexport type TableBoardDrawnNode = {\n key: string\n /** The sprite it showed, keyframes applied; none for a node that only carries its children */\n sprite?: string\n /** Where it sits in board units, its parents' places folded in, as a canvas transform */\n matrix: [number, number, number, number, number, number]\n alpha: number\n /** Gone from the scene and playing its exit */\n exiting: boolean\n}\n\n/** Where a board is shown, which the bundle can draw it for; the background is the theme's when it's left out */\nexport type TableBoardLook = { fidelity: TableBoardFidelity; backgroundStyle?: TableBoardBackgroundStyle }\n\ntype View = { puzzle: string; input: string }\n\n/** The longest a step holds the queue, however long its animations run */\nconst maxStepMs = 3_000\n/** How long a board's width has to hold before its sprites are made again at the new size */\nconst settleMs = 250\n/** Failed renders in a row a board survives once it has drawn; one that hasn't gives up at once */\nconst failuresBeforeGivingUp = 3\n\nconst boards = new Set<TableBoard>()\nlet frame = 0\n\nexport class TableBoard {\n private scene: TableBoardScene | null = null\n /** The resolution the scene's sprites were made at, and the one the canvas wants once its width settles */\n private spritesPpu = 0\n private wantedPpu = 0\n private live = new Map<string, Live>()\n private order: Live[] = []\n /** When everything the last step started has finished, loops aside */\n private until = 0\n private looping = false\n private shown: View | null = null\n private waiting: View | null = null\n private skipped = 0\n private rendering = false\n private failures = 0\n private disposed = false\n /** The box the board fits inside, and the width it's drawn at there */\n private boxWidth = 0\n private boxHeight = 0\n private cssWidth = 0\n /** The canvas's width in device pixels, which sets the board's scale */\n private pixelWidth = 0\n private height = 0\n private pendingHeight = 0\n private needsFit = false\n private settleTimer: ReturnType<typeof setTimeout> | undefined\n private stepTimer: ReturnType<typeof setTimeout> | undefined\n private ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D\n private theme: Theme | null = null\n private look: TableBoardLook = { fidelity: \"high\" }\n private layers: OffscreenCanvasRenderingContext2D[] = []\n dirty = false\n /** Called after every frame with where each node was drawn, for the simulator's debug overlay */\n onDrawn?: (frame: TableBoardFrame) => void\n /** Called with the canvas's size on the page whenever it changes, for a canvas whose element is on another thread */\n onFit?: (cssWidth: number, cssHeight: number) => void\n private fittedWidth = 0\n private fittedHeight = 0\n\n constructor(\n private canvas: HTMLCanvasElement | OffscreenCanvas,\n private renderer: TableBoardRenderer,\n /** Steady for the board's life, for the renderer's caches */\n private boardID: string,\n /** Told when the board stops for good: frozen on its last scene if it had one (`drew`), else blank */\n private onBroken: (error: unknown, drew: boolean) => void,\n ) {\n this.ctx = (canvas as OffscreenCanvas).getContext(\"2d\")!\n boards.add(this)\n }\n\n /** The newest view of the board; it shows once the step on screen has played out */\n update(view: View) {\n if (this.waiting) this.skipped++\n else if (this.shown && view.input === this.shown.input && view.puzzle === this.shown.puzzle) return\n this.waiting = view\n this.pump()\n }\n\n /** A new theme makes new sprites, so the board is drawn again in it; nothing's drawn before the first */\n setTheme(theme: Theme) {\n if (theme === this.theme) return\n this.theme = theme\n if (this.shown && !this.waiting) this.waiting = this.shown\n this.pump()\n }\n\n /** How much detail to draw and what's behind the board; a change draws it again, as a theme's does. Set it before the theme. */\n setLook(look: TableBoardLook) {\n if (look.fidelity === this.look.fidelity && look.backgroundStyle === this.look.backgroundStyle) return\n this.look = look\n if (this.shown && !this.waiting) this.waiting = this.shown\n this.pump()\n }\n\n /**\n * The box the board fits inside, as a thumbnail does: as wide as it can be without running past the bottom. A box\n * with no height of its own is only a width. The fitted width sets the canvas's pixel size and, once it settles, the\n * sprites' resolution\n */\n resize(boxWidth: number, boxHeight: number) {\n if ((boxWidth === this.boxWidth && boxHeight === this.boxHeight) || boxWidth <= 0) return\n this.boxWidth = boxWidth\n this.boxHeight = boxHeight\n // Before the first scene its shape isn't known, so its first sprites are made for the box's width\n if (!this.scene) this.cssWidth = boxWidth\n // On the next frame rather than in the resize observer: sizing the canvas there loops the observer\n this.needsFit = true\n this.dirty = true\n wake()\n }\n\n /** Draws the board again on the next frame, for an overlay that changed when nothing on the board did */\n redraw() {\n this.dirty = true\n wake()\n }\n\n /** Stops for good, showing the last scene as it ends, so a broken renderer reads as a neighbour who's paused */\n freeze() {\n if (this.disposed) return\n if (this.scene) this.draw(Infinity)\n this.dispose()\n }\n\n dispose() {\n this.disposed = true\n clearTimeout(this.settleTimer)\n clearTimeout(this.stepTimer)\n boards.delete(this)\n }\n\n /** Starts the next render when the queue allows one */\n private pump() {\n if (this.disposed || this.rendering || !this.theme) return\n const now = performance.now()\n const stepDone = now >= Math.min(this.until, this.stepStart + maxStepMs) || instant()\n if (this.waiting && !stepDone) {\n clearTimeout(this.stepTimer)\n this.stepTimer = setTimeout(() => this.pump(), Math.min(this.until, this.stepStart + maxStepMs) - now + 1)\n return\n }\n // The same view again at a new resolution: nothing changes, so nothing animates\n const next = this.waiting ?? (this.shown && this.wantedPpu && this.wantedPpu !== this.spritesPpu ? this.shown : null)\n if (!next) return\n this.waiting = null\n const skipped = this.skipped\n this.skipped = 0\n void this.render(next, skipped)\n }\n\n private stepStart = 0\n\n private async render(next: View, skipped: number) {\n this.rendering = true\n const ppu = this.wantedPpu || this.ppuFor(this.scene?.width ?? lastWidth.get(this.renderer))\n try {\n const scene = await this.renderer.render({\n board: this.boardID,\n puzzle: next.puzzle,\n input: next.input,\n previous: this.shown ?? undefined,\n skipped,\n theme: this.theme!,\n fidelity: this.look.fidelity,\n backgroundStyle: this.look.backgroundStyle ?? this.theme!.type,\n pixelsPerUnit: ppu,\n })\n if (this.disposed) return\n this.failures = 0\n lastWidth.set(this.renderer, scene.width)\n this.spritesPpu = ppu\n // The first scene says how wide the board is; if the guess was off, its sprites are made again at the right size\n this.wantedPpu = this.ppuFor(scene.width)\n this.show(scene, this.shown ? performance.now() : -Infinity)\n this.shown = next\n } catch (error) {\n if (this.disposed) return\n this.failures++\n if (!this.shown || this.failures >= failuresBeforeGivingUp) {\n this.freeze()\n return this.onBroken(error, !!this.shown)\n }\n console.warn(\"A table board couldn't render:\", error)\n // Tried again with whatever's newest\n this.waiting ??= next\n } finally {\n this.rendering = false\n }\n this.pump()\n }\n\n /** Device pixels per board unit: the canvas's exactly, so sprites drawn at their own size are the board's size */\n private ppuFor(width: number | undefined) {\n const dpr = pixelRatio()\n if (!width) return dpr\n // Before the first scene the canvas isn't sized, so it's a guess from the box\n const pixels = this.pixelWidth || this.cssWidth * dpr\n // Rounded only past where floats wobble, so the same size always names the same sprites\n return pixels ? Math.round((pixels / width) * 1e6) / 1e6 : dpr\n }\n\n /** Matches the scene to what's on screen by key, and starts what moves; `now` of -Infinity shows it settled */\n private show(scene: TableBoardScene, now: number) {\n const still = now === -Infinity || instant()\n const at = still ? 0 : now\n this.stepStart = at\n let until = at\n let looping = false\n const previous = this.live\n const next = new Map<string, Live>()\n\n for (const node of scene.nodes) {\n const parent = node.parent ? next.get(node.parent)! : null\n const old = previous.get(node.key)\n const target = valuesOf(node)\n if (old && !old.exit) {\n const timing = still ? null : node.transition === false ? null : (node.transition ?? scene.transition ?? null)\n const from = baseAt(old, at)\n old.from = from\n old.to = target\n old.start = at + (timing?.delay ?? 0)\n old.duration = timing?.duration ?? 0\n old.ease = easing(timing?.easing)\n old.node = node\n old.parent = parent\n until = Math.max(until, old.start + old.duration)\n next.set(node.key, old)\n } else {\n const live: Live = { node, parent, from: target, to: target, start: at, duration: 0, ease: linear, effects: [] }\n if (node.enter && !still) {\n live.enter = running(node.enter, at)\n until = Math.max(until, live.enter.end)\n }\n next.set(node.key, live)\n }\n }\n\n // Gone from the scene: exits from where it is now, in its place in the drawing order, then goes\n const order: Live[] = scene.nodes.map((node) => next.get(node.key)!)\n for (let i = 0; i < this.order.length; i++) {\n const old = this.order[i]\n if (next.get(old.node.key) === old) continue\n // Already leaving: it plays on, or it's gone. Starting its exit again would bring back every node that ever left\n if (old.exit) {\n if (!still && old.exit.end > at) insertAfterPrevious(order, this.order, i, old)\n continue\n }\n if (!old.node.exit || still) continue\n old.frozen = { ...baseAt(old, at), ...frozenParent(old, at) }\n old.exit = running(old.node.exit, at)\n old.effects = []\n until = Math.max(until, old.exit.end)\n insertAfterPrevious(order, this.order, i, old)\n }\n\n if (!still) {\n for (const effect of scene.effects ?? []) {\n const live = next.get(effect.key)\n if (!live) continue\n const run = running(effect, at, effect.iterations ?? 1)\n live.effects.push(run)\n if (run.end === Infinity) looping = true\n else until = Math.max(until, run.end)\n }\n }\n for (const live of next.values()) {\n live.effects = live.effects.filter((run) => run.end > at)\n if (live.effects.some((run) => run.end === Infinity)) looping = true\n }\n\n this.live = next\n this.order = order\n this.until = until\n this.looping = looping\n const grew = !this.scene || scene.height / scene.width > this.height / (this.scene.width || 1)\n this.scene = scene\n // A board grows at once, and shrinks once what's leaving has left\n if (grew || still) {\n this.height = scene.height\n this.pendingHeight = 0\n } else this.pendingHeight = scene.height\n this.fit()\n this.dirty = true\n wake()\n }\n\n animating(now: number) {\n return this.looping || now < this.until || (this.pendingHeight > 0 && now >= this.until)\n }\n\n /** Draws the board as it is at `now`; true while something still moves */\n draw(now: number) {\n this.dirty = false\n const scene = this.scene\n if (!scene || !this.cssWidth) return false\n if (this.needsFit) this.fit()\n if (this.pendingHeight && now >= this.until) {\n this.height = this.pendingHeight\n this.pendingHeight = 0\n this.fit()\n }\n const { ctx, canvas } = this\n const scale = canvas.width / scene.width\n ctx.setTransform(1, 0, 0, 1, 0, 0)\n ctx.clearRect(0, 0, canvas.width, canvas.height)\n const worlds = new Map<Live, World>()\n // Isolated nodes being drawn, innermost last: each one's children go on a layer of their own, put down when its\n // run of children ends\n const open: { owner: Live; layer: OffscreenCanvasRenderingContext2D }[] = []\n const target = () => (open.length ? open[open.length - 1].layer : ctx)\n const close = () => {\n const { owner, layer } = open.pop()!\n const into = target()\n into.setTransform(1, 0, 0, 1, 0, 0)\n into.globalAlpha = 1\n into.globalCompositeOperation = compositeFor(owner.node.blend)\n into.drawImage(layer.canvas, 0, 0)\n into.globalCompositeOperation = \"source-over\"\n }\n // Only gathered when something is listening\n const drawn: TableBoardDrawnNode[] | null = this.onDrawn ? [] : null\n for (const live of this.order) {\n if (live.exit && now >= live.exit.end) continue\n while (open.length && !isInside(live, open[open.length - 1].owner)) close()\n const world = worldOf(live, now, worlds)\n if (world && drawn)\n drawn.push({ key: live.node.key, sprite: world.sprite, matrix: world.matrix, alpha: world.alpha, exiting: !!live.exit })\n if (!world || world.alpha <= 0) continue\n if (live.node.isolate) open.push({ owner: live, layer: this.layer(open.length) })\n if (world.sprite) this.drawSprite(target(), world.sprite, world, world.alpha, scale, live.node.blend)\n }\n while (open.length) close()\n ctx.globalAlpha = 1\n ctx.globalCompositeOperation = \"source-over\"\n ctx.setTransform(1, 0, 0, 1, 0, 0)\n if (drawn) this.onDrawn!({ ctx, scale, scene, nodes: drawn })\n return this.animating(now)\n }\n\n /** A cleared layer the canvas's size for isolated nodes at `depth`, kept from frame to frame */\n private layer(depth: number) {\n let layer = this.layers[depth]\n if (!layer || layer.canvas.width !== this.canvas.width || layer.canvas.height !== this.canvas.height)\n layer = this.layers[depth] = new OffscreenCanvas(this.canvas.width, this.canvas.height).getContext(\"2d\")!\n layer.setTransform(1, 0, 0, 1, 0, 0)\n layer.clearRect(0, 0, layer.canvas.width, layer.canvas.height)\n return layer\n }\n\n private drawSprite(\n ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,\n id: string,\n world: World,\n alpha: number,\n scale: number,\n blend: TableBoardBlend | undefined,\n ) {\n const sprite = this.renderer.sprite(id, this.spritesPpu)\n if (!sprite || alpha <= 0) return\n const m = world.matrix\n const image: CanvasImageSource = world.tint ? tinted(sprite, world.tint) : sprite.bitmap\n // Within a percent of the size it was made at counts as that size, since the resolution is rounded\n const pixelPerfect = m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && Math.abs(scale / this.spritesPpu - 1) < 1e-5\n ctx.globalAlpha = alpha\n ctx.globalCompositeOperation = compositeFor(blend)\n if (pixelPerfect) {\n // Only moved, at the size it was made: whole device pixels, so it's as sharp as its sprite\n ctx.setTransform(1, 0, 0, 1, 0, 0)\n const left = Math.round((m[4] - sprite.anchor[0]) * scale)\n const top = Math.round((m[5] - sprite.anchor[1]) * scale)\n ctx.drawImage(image, left, top)\n for (let extra = world.brightness - 1; extra > 0; extra--) {\n ctx.globalCompositeOperation = \"lighter\"\n ctx.globalAlpha = alpha * Math.min(1, extra)\n ctx.drawImage(image, left, top)\n }\n } else {\n ctx.setTransform(m[0] * scale, m[1] * scale, m[2] * scale, m[3] * scale, m[4] * scale, m[5] * scale)\n const draw = () => ctx.drawImage(image, -sprite.anchor[0], -sprite.anchor[1], sprite.width, sprite.height)\n draw()\n for (let extra = world.brightness - 1; extra > 0; extra--) {\n ctx.globalCompositeOperation = \"lighter\"\n ctx.globalAlpha = alpha * Math.min(1, extra)\n draw()\n }\n }\n ctx.globalCompositeOperation = \"source-over\"\n }\n\n /** The canvas's size on the page and in pixels, for its box and the board's shape */\n private fit() {\n const scene = this.scene\n if (!scene || !this.boxWidth) return\n this.needsFit = false\n const dpr = pixelRatio()\n const fitted = this.boxHeight > 0 ? Math.min(this.boxWidth, (this.boxHeight * scene.width) / this.height) : this.boxWidth\n // With a grid, the largest scale that fits and puts each grid step on whole device pixels\n const pixelWidth = Math.round(\n scene.grid ? Math.max(1, Math.floor(((fitted * dpr) / scene.width) * scene.grid)) * (scene.width / scene.grid) : fitted * dpr,\n )\n const cssWidth = pixelWidth / dpr\n this.pixelWidth = pixelWidth\n if (cssWidth !== this.cssWidth) {\n this.cssWidth = cssWidth\n clearTimeout(this.settleTimer)\n this.settleTimer = setTimeout(() => {\n this.wantedPpu = this.ppuFor(this.scene?.width)\n this.pump()\n }, settleMs)\n }\n const cssHeight = (this.cssWidth * this.height) / scene.width\n const width = pixelWidth\n const height = Math.round((pixelWidth * this.height) / scene.width)\n // An offscreen canvas has no element here to size\n if (\"style\" in this.canvas) {\n this.canvas.style.width = `${this.cssWidth}px`\n this.canvas.style.height = `${cssHeight}px`\n }\n if (this.cssWidth !== this.fittedWidth || cssHeight !== this.fittedHeight) {\n this.fittedWidth = this.cssWidth\n this.fittedHeight = cssHeight\n this.onFit?.(this.cssWidth, cssHeight)\n }\n // Setting a canvas's size, even to the same one, clears it\n if (width === this.canvas.width && height === this.canvas.height) return\n this.canvas.width = width\n this.canvas.height = height\n this.dirty = true\n wake()\n }\n}\n\n/** The renderer's last board width, so a new board's first sprites are made near the right size */\nconst lastWidth = new WeakMap<TableBoardRenderer, number>()\n\n/** What a board needs to know of the screen it's shown on, which a worker can't read for itself */\nexport type TableBoardEnvironment = { devicePixelRatio: number; hidden: boolean; reducedMotion: boolean }\n\nconst environment: Partial<TableBoardEnvironment> = {}\n\n/** Says what the page knows of the screen, where boards draw without a document; what's left out is read from the globals */\nexport const setTableBoardEnvironment = (next: Partial<TableBoardEnvironment>) => void Object.assign(environment, next)\n\nconst pixelRatio = () => environment.devicePixelRatio ?? (devicePixelRatio || 1)\n\nconst instant = () =>\n (environment.hidden ?? document.hidden) ||\n (environment.reducedMotion ?? (reducedMotion ??= matchMedia(\"(prefers-reduced-motion: reduce)\")).matches)\n/** Made on first use, not when the module loads, so importing the table is safe where there's no window */\nlet reducedMotion: MediaQueryList | undefined\n\nconst wake = () => {\n if (!frame) frame = requestAnimationFrame(loop)\n}\n\nconst loop = (now: number) => {\n frame = 0\n let moving = false\n for (const board of boards) {\n if (!board.dirty && !board.animating(now)) continue\n try {\n moving = board.draw(now) || moving\n } catch (error) {\n console.error(\"A table board couldn't be drawn:\", error)\n }\n }\n if (moving) wake()\n}\n\n// Animation state\n\ntype RGB = [number, number, number]\n\n/** A node's values: what transitions animate between */\ntype Values = { x: number; y: number; rotation: number; sx: number; sy: number; opacity: number; brightness: number; tint: RGB | null }\n\n/** One animation playing on a node, its keyframes ready to sample */\ntype Running = { frames: TableBoardKeyframe[]; start: number; duration: number; end: number; iterations: number; ease: Ease[] }\n\ntype Ease = (t: number) => number\n\n/** A node on screen and what it's doing */\ntype Live = {\n node: TableBoardNode\n parent: Live | null\n /** The transition from `from` to `to` */\n from: Values\n to: Values\n start: number\n duration: number\n ease: Ease\n enter?: Running\n exit?: Running\n /** Where an exiting node was, its parent's place folded in, since its parent may be gone */\n frozen?: Values & { parentMatrix?: Matrix; parentAlpha?: number }\n effects: Running[]\n}\n\ntype World = { matrix: Matrix; alpha: number; brightness: number; tint: RGB | null; sprite?: string }\n\nconst linear: Ease = (t) => t\n\nconst valuesOf = (node: TableBoardNode): Values => ({\n x: node.x,\n y: node.y,\n rotation: node.rotation ?? 0,\n sx: node.scale?.[0] ?? 1,\n sy: node.scale?.[1] ?? 1,\n opacity: node.opacity ?? 1,\n brightness: node.brightness ?? 1,\n tint: node.tint ? parseColor(node.tint) : null,\n})\n\n/** A node's own values at `now`, its transition applied but not its animations */\nconst baseAt = (live: Live, now: number): Values => {\n if (live.frozen) return live.frozen\n if (!live.duration || now >= live.start + live.duration) return live.to\n const t = now <= live.start ? 0 : live.ease((now - live.start) / live.duration)\n return mix(live.from, live.to, t)\n}\n\nconst mix = (a: Values, b: Values, t: number): Values => ({\n x: a.x + (b.x - a.x) * t,\n y: a.y + (b.y - a.y) * t,\n rotation: a.rotation + (b.rotation - a.rotation) * t,\n sx: a.sx + (b.sx - a.sx) * t,\n sy: a.sy + (b.sy - a.sy) * t,\n opacity: a.opacity + (b.opacity - a.opacity) * t,\n brightness: a.brightness + (b.brightness - a.brightness) * t,\n tint: a.tint && b.tint ? mixRGB(a.tint, b.tint, t) : b.tint,\n})\n\nconst mixRGB = (a: RGB, b: RGB, t: number): RGB => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t]\n\n/** An exiting node's parent as it was, so the node stays put if its parent goes first */\nconst frozenParent = (live: Live, now: number) => {\n if (!live.parent) return {}\n const world = worldOf(live.parent, now, new Map())\n return world ? { parentMatrix: world.matrix, parentAlpha: world.alpha } : {}\n}\n\nconst running = (animation: TableBoardAnimation, now: number, iterations = 1): Running => {\n const frames = [...animation.keyframes]\n // CSS's implied ends: the node's own values\n if (!frames.length || frames[0].offset > 0) frames.unshift({ offset: 0 })\n if (frames[frames.length - 1].offset < 1) frames.push({ offset: 1 })\n const start = now + (animation.delay ?? 0)\n const duration = Math.max(1, animation.duration)\n const fallback = animation.easing\n return {\n frames,\n start,\n duration,\n iterations,\n end: iterations === Infinity ? Infinity : start + duration * iterations,\n ease: frames.map((frame) => easing(frame.easing ?? fallback)),\n }\n}\n\n/** What an animation adds at `now`: null outside it, unless it fills (an enter before it starts, an exit after it ends) */\nconst sample = (run: Running, now: number, fill: boolean) => {\n if (now < run.start && !fill) return null\n if (now >= run.end && !fill) return null\n const elapsed = Math.max(0, Math.min(now, run.end === Infinity ? now : run.end) - run.start)\n let progress = elapsed / run.duration\n progress = now >= run.end ? 1 : progress - Math.floor(progress)\n const { frames } = run\n let i = 0\n while (i < frames.length - 2 && progress > frames[i + 1].offset) i++\n const a = frames[i]\n const b = frames[i + 1]\n const span = b.offset - a.offset || 1\n const t = run.ease[i](Math.min(1, Math.max(0, (progress - a.offset) / span)))\n let sprite: string | undefined\n for (const frame of frames) if (frame.offset <= progress && frame.sprite) sprite = frame.sprite\n const lerp = (x: number | undefined, y: number | undefined, identity: number) => (x ?? identity) + ((y ?? identity) - (x ?? identity)) * t\n return {\n x: lerp(a.x, b.x, 0),\n y: lerp(a.y, b.y, 0),\n rotation: lerp(a.rotation, b.rotation, 0),\n sx: lerp(a.scale?.[0], b.scale?.[0], 1),\n sy: lerp(a.scale?.[1], b.scale?.[1], 1),\n opacity: lerp(a.opacity, b.opacity, 1),\n brightness: lerp(a.brightness, b.brightness, 1),\n tint: a.tint || b.tint ? mixRGB(parseColor(a.tint ?? b.tint!), parseColor(b.tint ?? a.tint!), t) : null,\n sprite,\n }\n}\n\n/** Where a node is on the board at `now`, and how it's drawn, its parents' places folded in */\nconst worldOf = (live: Live, now: number, worlds: Map<Live, World>): World | null => {\n const known = worlds.get(live)\n if (known) return known\n const base = baseAt(live, now)\n let { x, y, rotation, sx, sy, opacity, brightness, tint } = base\n let sprite = live.node.sprite\n const runs: [Running | undefined, boolean][] = [\n [live.enter, true],\n [live.exit, true],\n ...live.effects.map((run): [Running, boolean] => [run, false]),\n ]\n for (const [run, fill] of runs) {\n if (!run) continue\n const at = sample(run, now, fill)\n if (!at) continue\n x += at.x\n y += at.y\n rotation += at.rotation\n sx *= at.sx\n sy *= at.sy\n opacity *= at.opacity\n brightness *= at.brightness\n if (at.tint) tint = at.tint\n if (at.sprite) sprite = at.sprite\n }\n let parentMatrix = identity\n let parentAlpha = 1\n let parentBrightness = 1\n if (live.frozen?.parentMatrix) {\n parentMatrix = live.frozen.parentMatrix\n parentAlpha = live.frozen.parentAlpha ?? 1\n } else if (live.parent) {\n const parent = worldOf(live.parent, now, worlds)\n if (!parent) return null\n parentMatrix = parent.matrix\n parentAlpha = parent.alpha\n parentBrightness = parent.brightness\n }\n const radians = (rotation * Math.PI) / 180\n const cos = Math.cos(radians)\n const sin = Math.sin(radians)\n const local: Matrix = [cos * sx, sin * sx, -sin * sy, cos * sy, x, y]\n const world: World = {\n matrix: multiply(parentMatrix, snap(local)),\n alpha: parentAlpha * opacity,\n // Capped here, as each extra unit is another draw: multiplied unchecked, a scene's brightness could reach Infinity\n brightness: Math.min(parentBrightness * brightness, sceneLimits.brightness),\n tint,\n sprite,\n }\n worlds.set(live, world)\n return world\n}\n\ntype Matrix = [number, number, number, number, number, number]\nconst identity: Matrix = [1, 0, 0, 1, 0, 0]\n\nconst multiply = (m: Matrix, n: Matrix): Matrix => [\n m[0] * n[0] + m[2] * n[1],\n m[1] * n[0] + m[3] * n[1],\n m[0] * n[2] + m[2] * n[3],\n m[1] * n[2] + m[3] * n[3],\n m[0] * n[4] + m[2] * n[5] + m[4],\n m[1] * n[4] + m[3] * n[5] + m[5],\n]\n\n/** Rounds away float noise in a whole turn, so a card at 360° still counts as unturned and draws pixel-perfect */\nconst snap = (m: Matrix): Matrix => m.map((v, i) => (i < 4 && Math.abs(v - Math.round(v)) < 1e-9 ? Math.round(v) : v)) as Matrix\n\n/** A blend as the canvas names it: CSS's other modes are the canvas's own words, and its normal is source-over */\nconst compositeFor = (blend: TableBoardBlend | undefined): GlobalCompositeOperation =>\n !blend || blend === \"normal\" ? \"source-over\" : blend\n\n/** Whether `live` is one of `owner`'s children, or theirs */\nconst isInside = (live: Live, owner: Live) => {\n for (let at = live.parent; at; at = at.parent) if (at === owner) return true\n return false\n}\n\n/** Puts an exiting node back after the node it followed, in the new drawing order */\nconst insertAfterPrevious = (order: Live[], oldOrder: Live[], index: number, live: Live) => {\n for (let i = index - 1; i >= 0; i--) {\n const at = order.indexOf(oldOrder[i])\n if (at >= 0) return void order.splice(at + 1, 0, live)\n }\n order.unshift(live)\n}\n\nconst easings = new Map<string, Ease>()\nconst easing = (value: string | undefined): Ease => {\n if (!value) return linear\n let ease = easings.get(value)\n if (!ease) easings.set(value, (ease = parseEasing(value)))\n return ease\n}\n\n// Colours\n\n/** Made on first use, as reducedMotion is */\nlet colorContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | undefined\nconst colors = new Map<string, RGB>()\n\n/** A CSS colour as RGB, read back through a canvas so every syntax the browser knows works */\nconst parseColor = (value: string): RGB => {\n let rgb = colors.get(value)\n if (rgb) return rgb\n // An offscreen canvas where there is one, as a worker has no document\n // getContext is called on each canvas type, as TS 5.x can't resolve the \"2d\" overload on the union\n colorContext ??=\n typeof OffscreenCanvas === \"undefined\"\n ? document.createElement(\"canvas\").getContext(\"2d\")!\n : new OffscreenCanvas(1, 1).getContext(\"2d\")!\n colorContext.fillStyle = \"#000\"\n colorContext.fillStyle = value\n const normal = String(colorContext.fillStyle)\n const hex = /^#([0-9a-f]{6})$/i.exec(normal)\n const parts = hex\n ? [0, 2, 4].map((i) => parseInt(hex[1].slice(i, i + 2), 16))\n : (/rgba?\\(([^)]+)\\)/.exec(normal)?.[1].split(\",\").slice(0, 3).map(Number) ?? [0, 0, 0])\n rgb = [parts[0], parts[1], parts[2]]\n colors.set(value, rgb)\n return rgb\n}\n\n/** Tinted copies of a sprite, by colour; a tint that's animating makes a copy per step, so the set is capped */\nconst tints = new WeakMap<ImageBitmap, Map<string, OffscreenCanvas>>()\nconst tintsPerSprite = 48\n\nconst tinted = (sprite: SpriteBitmap, rgb: RGB): OffscreenCanvas => {\n // Steps of 4 in each channel: a tint mid-animation reuses copies, and the eye can't tell\n const key = rgb.map((c) => Math.round(c / 4) * 4).join(\",\")\n let copies = tints.get(sprite.bitmap)\n if (!copies) tints.set(sprite.bitmap, (copies = new Map()))\n let copy = copies.get(key)\n if (copy) return copy\n if (copies.size >= tintsPerSprite) copies.clear()\n const { width, height } = sprite.bitmap\n copy = new OffscreenCanvas(width, height)\n const ctx = copy.getContext(\"2d\")!\n ctx.drawImage(sprite.bitmap, 0, 0)\n ctx.globalCompositeOperation = \"multiply\"\n ctx.fillStyle = `rgb(${key})`\n ctx.fillRect(0, 0, width, height)\n // Multiplying fills the transparent pixels too; the sprite's own alpha cuts them back out\n ctx.globalCompositeOperation = \"destination-in\"\n ctx.drawImage(sprite.bitmap, 0, 0)\n copies.set(key, copy)\n return copy\n}\n"],"mappings":";;;;;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AK,MAAM,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,IAAI,EACvD,IAAS,EAAM,IAAI,EAAO,OAAO;AACrC,CAAK,KAAQ,EAAM,IAAI,EAAO,QAAS,oBAAS,IAAI,KAAK,CAAE;CAC3D,IAAI,IAAO,EAAO,IAAI,EAAI;AAC1B,KAAI,EAAM,QAAO;AACjB,CAAI,EAAO,QAAQ,MAAgB,EAAO,OAAO;CACjD,IAAM,EAAE,UAAO,cAAW,EAAO;AACjC,KAAO,IAAI,gBAAgB,GAAO,EAAO;CACzC,IAAM,IAAM,EAAK,WAAW,KAAK;AASjC,QARA,EAAI,UAAU,EAAO,QAAQ,GAAG,EAAE,EAClC,EAAI,2BAA2B,YAC/B,EAAI,YAAY,OAAO,EAAI,IAC3B,EAAI,SAAS,GAAG,GAAG,GAAO,EAAO,EAEjC,EAAI,2BAA2B,kBAC/B,EAAI,UAAU,EAAO,QAAQ,GAAG,EAAE,EAClC,EAAO,IAAI,GAAK,EAAK,EACd"}
@@ -0,0 +1,2 @@
1
+ const e=require(`./objectSpread2-BU9HzoRm.cjs`),t=require(`./asyncToGenerator-Tjg_Hpik.cjs`),n=e=>{let t=e.trim();if(t===`linear`)return r;let n=i[t];if(n)return a(n[0],n[1],n[2],n[3]);let s=/^cubic-bezier\(([^)]+)\)$/.exec(t);if(s){let e=s[1].split(`,`).map(Number);return e.length!==4||e.some(e=>Number.isNaN(e))?r:a(e[0],e[1],e[2],e[3])}let c=/^linear\(([^)]+)\)$/.exec(t);return c?o(c[1]):r};var r=e=>e,i={ease:[.25,.1,.25,1],"ease-in":[.42,0,1,1],"ease-out":[0,0,.58,1],"ease-in-out":[.42,0,.58,1]},a=(e,t,n,r)=>{let i=t=>3*e*t*(1-t)*(1-t)+3*n*t*t*(1-t)+t*t*t,a=e=>3*t*e*(1-e)*(1-e)+3*r*e*e*(1-e)+e*e*e;return e=>{let t=0,n=1,r=e;for(let a=0;a<24;a++){let a=i(r);if(Math.abs(a-e)<1e-5)break;a<e?t=r:n=r,r=(t+n)/2}return a(r)}},o=e=>{let t=e.split(`,`).map(e=>{let t=e.trim().split(/\s+/);return{value:Number(t[0]),at:t[1]?parseFloat(t[1])/100:NaN}});if(t.some(e=>Number.isNaN(e.value)))return r;Number.isNaN(t[0].at)&&(t[0].at=0),Number.isNaN(t[t.length-1].at)&&(t[t.length-1].at=1);let n=0;for(let e=0;e<t.length;e++){if(!Number.isNaN(t[e].at)){n=e;continue}let r=e;for(;Number.isNaN(t[r].at);)r++;for(let e=n+1;e<r;e++)t[e].at=t[n].at+(t[r].at-t[n].at)*(e-n)/(r-n);n=r}return e=>{if(e<=t[0].at)return t[0].value;for(let n=1;n<t.length;n++)if(e<=t[n].at){let r=t[n-1],i=t[n];return r.value+(i.value-r.value)*(e-r.at)/(i.at-r.at||1)}return t[t.length-1].value}};const s={nodes:5e3,effects:5e3,keyframes:32,ms:1e4,size:1e5,text:200,depth:16,brightness:10},c=e=>{let t=g(e,`The scene`),n=b(t.width,`The scene's width`,s.size),r=b(t.height,`The scene's height`,s.size),i=_(t.nodes,`The scene's nodes`,s.nodes),a=new Set,o=new Map,c=[],l=new Set,f={width:n,height:r,nodes:i.map((e,t)=>{let n=u(e,`Node ${t}`);if(a.has(n.key))throw Error(`Node ${t}'s key "${n.key}" is used twice`);if(n.parent!==void 0&&!a.has(n.parent))throw Error(`Node "${n.key}"'s parent "${n.parent}" must come before it`);a.add(n.key),o.set(n.key,n.parent);let r=new Set;for(let e=n.parent;e!==void 0;e=o.get(e))r.add(e);if(r.size>=s.depth)throw Error(`Node "${n.key}" is nested over ${s.depth} nodes deep`);for(;c.length&&!r.has(c[c.length-1]);)l.add(c.pop());let i=[...r].find(e=>l.has(e));if(i)throw Error(`Node "${n.key}" is in isolated "${i}", so it must come straight after its other children`);return n.isolate&&c.push(n.key),n})};return t.grid!==void 0&&(f.grid=b(t.grid,`The scene's grid`,n)),t.transition!==void 0&&(f.transition=m(t.transition,`The scene's transition`)),t.effects!==void 0&&(f.effects=_(t.effects,`The scene's effects`,s.effects).map((e,t)=>{let n=d(e,`Effect ${t}`);if(!a.has(n.key))throw Error(`Effect ${t} is for "${n.key}", which isn't in the scene`);return n})),f},l=e=>{var t;let n=new Set,r=e=>e==null?void 0:e.keyframes.forEach(e=>e.sprite&&n.add(e.sprite));for(let t of e.nodes)t.sprite&&n.add(t.sprite),r(t.enter),r(t.exit);return(t=e.effects)==null||t.forEach(r),n};var u=(e,t)=>{let n=g(e,t),r={key:v(n.key,`${t}'s key`),x:y(n.x,`${t}'s x`),y:y(n.y,`${t}'s y`)};if(n.sprite!==void 0&&(r.sprite=v(n.sprite,`${t}'s sprite`)),n.parent!==void 0&&(r.parent=v(n.parent,`${t}'s parent`)),n.blend!==void 0){if(!h.includes(n.blend))throw Error(`${t}'s blend must be one of ${h.join(`, `)}`);r.blend=n.blend}return n.isolate===!0&&(r.isolate=!0),Object.assign(r,f(n,t)),n.transition===!1?r.transition=!1:n.transition!==void 0&&(r.transition=m(n.transition,`${t}'s transition`)),n.enter!==void 0&&(r.enter=p(n.enter,`${t}'s enter`)),n.exit!==void 0&&(r.exit=p(n.exit,`${t}'s exit`)),r},d=(t,n)=>{let r=g(t,n),i=e.t({key:v(r.key,`${n}'s key`)},p(r,n));if(r.iterations!==void 0){let e=Number(r.iterations);if(!(e>=1))throw Error(`${n}'s iterations must be 1 or more`);i.iterations=e}return i},f=(e,t)=>{let n={};return e.rotation!==void 0&&(n.rotation=y(e.rotation,`${t}'s rotation`)),e.scale!==void 0&&(n.scale=x(e.scale,`${t}'s scale`)),e.opacity!==void 0&&(n.opacity=S(y(e.opacity,`${t}'s opacity`),0,1)),e.brightness!==void 0&&(n.brightness=S(y(e.brightness,`${t}'s brightness`),0,s.brightness)),e.tint!==void 0&&(n.tint=v(e.tint,`${t}'s tint`)),n},p=(t,n)=>{let r=g(t,n),i=-1,a=_(r.keyframes,`${n}'s keyframes`,s.keyframes).map((t,r)=>{let a=`${n}'s keyframe ${r}`,o=g(t,a),s=y(o.offset,`${a}'s offset`);if(s<0||s>1||s<i)throw Error(`${a}'s offset must be from 0 to 1, in order`);i=s;let c=e.t({offset:s},f(o,a));return o.x!==void 0&&(c.x=y(o.x,`${a}'s x`)),o.y!==void 0&&(c.y=y(o.y,`${a}'s y`)),o.easing!==void 0&&(c.easing=v(o.easing,`${a}'s easing`)),o.sprite!==void 0&&(c.sprite=v(o.sprite,`${a}'s sprite`)),c});return e.t(e.t({},m(r,n)),{},{keyframes:a})},m=(e,t)=>{let n=g(e,t),r={duration:S(y(n.duration,`${t}'s duration`),0,s.ms)};return n.delay!==void 0&&(r.delay=S(y(n.delay,`${t}'s delay`),0,s.ms)),n.easing!==void 0&&(r.easing=v(n.easing,`${t}'s easing`)),r},h=[`normal`,`multiply`,`screen`,`overlay`,`darken`,`lighten`,`color-dodge`,`color-burn`,`hard-light`,`soft-light`,`difference`,`exclusion`,`hue`,`saturation`,`color`,`luminosity`],g=(e,t)=>{if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e},_=(e,t,n)=>{if(!Array.isArray(e))throw Error(`${t} must be a list`);if(e.length>n)throw Error(`${t} can hold at most ${n}, got ${e.length}`);return e},v=(e,t)=>{if(typeof e!=`string`||!e||e.length>s.text)throw Error(`${t} must be text of 1 to ${s.text} characters`);return e},y=(e,t)=>{if(typeof e!=`number`||!Number.isFinite(e))throw Error(`${t} must be a finite number`);return e},b=(e,t,n)=>{let r=y(e,t);if(r<=0||r>n)throw Error(`${t} must be above 0 and at most ${n}`);return r},x=(e,t)=>{if(!Array.isArray(e)||e.length!==2)throw Error(`${t} must be two numbers`);return[y(e[0],t),y(e[1],t)]},S=(e,t,n)=>Math.min(n,Math.max(t,e)),C=3e3,w=250,T=3,E=new Set,D=0,O=class{constructor(t,n,r,i){e.n(this,`scene`,null),e.n(this,`spritesPpu`,0),e.n(this,`wantedPpu`,0),e.n(this,`live`,new Map),e.n(this,`order`,[]),e.n(this,`until`,0),e.n(this,`looping`,!1),e.n(this,`shown`,null),e.n(this,`waiting`,null),e.n(this,`skipped`,0),e.n(this,`rendering`,!1),e.n(this,`failures`,0),e.n(this,`disposed`,!1),e.n(this,`boxWidth`,0),e.n(this,`boxHeight`,0),e.n(this,`cssWidth`,0),e.n(this,`pixelWidth`,0),e.n(this,`height`,0),e.n(this,`pendingHeight`,0),e.n(this,`needsFit`,!1),e.n(this,`settleTimer`,void 0),e.n(this,`stepTimer`,void 0),e.n(this,`ctx`,void 0),e.n(this,`theme`,null),e.n(this,`look`,{fidelity:`high`}),e.n(this,`layers`,[]),e.n(this,`dirty`,!1),e.n(this,`onDrawn`,void 0),e.n(this,`onFit`,void 0),e.n(this,`fittedWidth`,0),e.n(this,`fittedHeight`,0),e.n(this,`stepStart`,0),this.canvas=t,this.renderer=n,this.boardID=r,this.onBroken=i,this.ctx=t.getContext(`2d`),E.add(this)}update(e){if(this.waiting)this.skipped++;else if(this.shown&&e.input===this.shown.input&&e.puzzle===this.shown.puzzle)return;this.waiting=e,this.pump()}setTheme(e){e!==this.theme&&(this.theme=e,this.shown&&!this.waiting&&(this.waiting=this.shown),this.pump())}setLook(e){e.fidelity===this.look.fidelity&&e.backgroundStyle===this.look.backgroundStyle||(this.look=e,this.shown&&!this.waiting&&(this.waiting=this.shown),this.pump())}resize(e,t){e===this.boxWidth&&t===this.boxHeight||e<=0||(this.boxWidth=e,this.boxHeight=t,this.scene||(this.cssWidth=e),this.needsFit=!0,this.dirty=!0,F())}redraw(){this.dirty=!0,F()}freeze(){this.disposed||(this.scene&&this.draw(1/0),this.dispose())}dispose(){this.disposed=!0,clearTimeout(this.settleTimer),clearTimeout(this.stepTimer),E.delete(this)}pump(){var e;if(this.disposed||this.rendering||!this.theme)return;let t=performance.now(),n=t>=Math.min(this.until,this.stepStart+C)||N();if(this.waiting&&!n){clearTimeout(this.stepTimer),this.stepTimer=setTimeout(()=>this.pump(),Math.min(this.until,this.stepStart+C)-t+1);return}let r=(e=this.waiting)==null?this.shown&&this.wantedPpu&&this.wantedPpu!==this.spritesPpu?this.shown:null:e;if(!r)return;this.waiting=null;let i=this.skipped;this.skipped=0,this.render(r,i)}render(e,n){var r=this;return t.t(function*(){var t,i;r.rendering=!0;let a=r.wantedPpu||r.ppuFor((t=(i=r.scene)==null?void 0:i.width)==null?k.get(r.renderer):t);try{var o,s;let t=yield r.renderer.render({board:r.boardID,puzzle:e.puzzle,input:e.input,previous:(o=r.shown)==null?void 0:o,skipped:n,theme:r.theme,fidelity:r.look.fidelity,backgroundStyle:(s=r.look.backgroundStyle)==null?r.theme.type:s,pixelsPerUnit:a});if(r.disposed)return;r.failures=0,k.set(r.renderer,t.width),r.spritesPpu=a,r.wantedPpu=r.ppuFor(t.width),r.show(t,r.shown?performance.now():-1/0),r.shown=e}catch(t){if(r.disposed)return;if(r.failures++,!r.shown||r.failures>=T)return r.freeze(),r.onBroken(t,!!r.shown);console.warn(`A table board couldn't render:`,t),r.waiting!=null||(r.waiting=e)}finally{r.rendering=!1}r.pump()})()}ppuFor(e){let t=M();if(!e)return t;let n=this.pixelWidth||this.cssWidth*t;return n?Math.round(n/e*1e6)/1e6:t}show(t,n){let r=n===-1/0||N(),i=r?0:n;this.stepStart=i;let a=i,o=!1,s=this.live,c=new Map;for(let e of t.nodes){let n=e.parent?c.get(e.parent):null,o=s.get(e.key),p=R(e);if(o&&!o.exit){var l,u,d,f;let s=r||e.transition===!1||(l=(u=e.transition)==null?t.transition:u)==null?null:l;o.from=z(o,i),o.to=p,o.start=i+((d=s==null?void 0:s.delay)==null?0:d),o.duration=(f=s==null?void 0:s.duration)==null?0:f,o.ease=Y(s==null?void 0:s.easing),o.node=e,o.parent=n,a=Math.max(a,o.start+o.duration),c.set(e.key,o)}else{let t={node:e,parent:n,from:p,to:p,start:i,duration:0,ease:L,effects:[]};e.enter&&!r&&(t.enter=U(e.enter,i),a=Math.max(a,t.enter.end)),c.set(e.key,t)}}let p=t.nodes.map(e=>c.get(e.key));for(let t=0;t<this.order.length;t++){let n=this.order[t];if(c.get(n.node.key)!==n){if(n.exit){!r&&n.exit.end>i&&q(p,this.order,t,n);continue}!n.node.exit||r||(n.frozen=e.t(e.t({},z(n,i)),H(n,i)),n.exit=U(n.node.exit,i),n.effects=[],a=Math.max(a,n.exit.end),q(p,this.order,t,n))}}if(!r){var m;for(let e of(m=t.effects)==null?[]:m){var h;let t=c.get(e.key);if(!t)continue;let n=U(e,i,(h=e.iterations)==null?1:h);t.effects.push(n),n.end===1/0?o=!0:a=Math.max(a,n.end)}}for(let e of c.values())e.effects=e.effects.filter(e=>e.end>i),e.effects.some(e=>e.end===1/0)&&(o=!0);this.live=c,this.order=p,this.until=a,this.looping=o;let g=!this.scene||t.height/t.width>this.height/(this.scene.width||1);this.scene=t,g||r?(this.height=t.height,this.pendingHeight=0):this.pendingHeight=t.height,this.fit(),this.dirty=!0,F()}animating(e){return this.looping||e<this.until||this.pendingHeight>0&&e>=this.until}draw(e){this.dirty=!1;let t=this.scene;if(!t||!this.cssWidth)return!1;this.needsFit&&this.fit(),this.pendingHeight&&e>=this.until&&(this.height=this.pendingHeight,this.pendingHeight=0,this.fit());let{ctx:n,canvas:r}=this,i=r.width/t.width;n.setTransform(1,0,0,1,0,0),n.clearRect(0,0,r.width,r.height);let a=new Map,o=[],s=()=>o.length?o[o.length-1].layer:n,c=()=>{let{owner:e,layer:t}=o.pop(),n=s();n.setTransform(1,0,0,1,0,0),n.globalAlpha=1,n.globalCompositeOperation=K(e.node.blend),n.drawImage(t.canvas,0,0),n.globalCompositeOperation=`source-over`},l=this.onDrawn?[]:null;for(let t of this.order){if(t.exit&&e>=t.exit.end)continue;for(;o.length&&!re(t,o[o.length-1].owner);)c();let n=G(t,e,a);n&&l&&l.push({key:t.node.key,sprite:n.sprite,matrix:n.matrix,alpha:n.alpha,exiting:!!t.exit}),!(!n||n.alpha<=0)&&(t.node.isolate&&o.push({owner:t,layer:this.layer(o.length)}),n.sprite&&this.drawSprite(s(),n.sprite,n,n.alpha,i,t.node.blend))}for(;o.length;)c();return n.globalAlpha=1,n.globalCompositeOperation=`source-over`,n.setTransform(1,0,0,1,0,0),l&&this.onDrawn({ctx:n,scale:i,scene:t,nodes:l}),this.animating(e)}layer(e){let t=this.layers[e];return(!t||t.canvas.width!==this.canvas.width||t.canvas.height!==this.canvas.height)&&(t=this.layers[e]=new OffscreenCanvas(this.canvas.width,this.canvas.height).getContext(`2d`)),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,t.canvas.width,t.canvas.height),t}drawSprite(e,t,n,r,i,a){let o=this.renderer.sprite(t,this.spritesPpu);if(!o||r<=0)return;let s=n.matrix,c=n.tint?ae(o,n.tint):o.bitmap,l=s[0]===1&&s[1]===0&&s[2]===0&&s[3]===1&&Math.abs(i/this.spritesPpu-1)<1e-5;if(e.globalAlpha=r,e.globalCompositeOperation=K(a),l){e.setTransform(1,0,0,1,0,0);let t=Math.round((s[4]-o.anchor[0])*i),a=Math.round((s[5]-o.anchor[1])*i);e.drawImage(c,t,a);for(let i=n.brightness-1;i>0;i--)e.globalCompositeOperation=`lighter`,e.globalAlpha=r*Math.min(1,i),e.drawImage(c,t,a)}else{e.setTransform(s[0]*i,s[1]*i,s[2]*i,s[3]*i,s[4]*i,s[5]*i);let t=()=>e.drawImage(c,-o.anchor[0],-o.anchor[1],o.width,o.height);t();for(let i=n.brightness-1;i>0;i--)e.globalCompositeOperation=`lighter`,e.globalAlpha=r*Math.min(1,i),t()}e.globalCompositeOperation=`source-over`}fit(){let e=this.scene;if(!e||!this.boxWidth)return;this.needsFit=!1;let t=M(),n=this.boxHeight>0?Math.min(this.boxWidth,this.boxHeight*e.width/this.height):this.boxWidth,r=Math.round(e.grid?Math.max(1,Math.floor(n*t/e.width*e.grid))*(e.width/e.grid):n*t),i=r/t;this.pixelWidth=r,i!==this.cssWidth&&(this.cssWidth=i,clearTimeout(this.settleTimer),this.settleTimer=setTimeout(()=>{var e;this.wantedPpu=this.ppuFor((e=this.scene)==null?void 0:e.width),this.pump()},w));let a=this.cssWidth*this.height/e.width,o=r,s=Math.round(r*this.height/e.width);if(`style`in this.canvas&&(this.canvas.style.width=`${this.cssWidth}px`,this.canvas.style.height=`${a}px`),this.cssWidth!==this.fittedWidth||a!==this.fittedHeight){var c;this.fittedWidth=this.cssWidth,this.fittedHeight=a,(c=this.onFit)==null||c.call(this,this.cssWidth,a)}o===this.canvas.width&&s===this.canvas.height||(this.canvas.width=o,this.canvas.height=s,this.dirty=!0,F())}},k=new WeakMap,A={};const j=e=>void Object.assign(A,e);var M=()=>{var e;return(e=A.devicePixelRatio)==null?devicePixelRatio||1:e},N=()=>{var e,t,n;return((e=A.hidden)==null?document.hidden:e)||((t=A.reducedMotion)==null?((n=P)==null?P=matchMedia(`(prefers-reduced-motion: reduce)`):n).matches:t)},P,F=()=>{D||(D=requestAnimationFrame(I))},I=e=>{D=0;let t=!1;for(let n of E)if(!(!n.dirty&&!n.animating(e)))try{t=n.draw(e)||t}catch(e){console.error(`A table board couldn't be drawn:`,e)}t&&F()},L=e=>e,R=e=>{var t,n,r,i,a,o,s;return{x:e.x,y:e.y,rotation:(t=e.rotation)==null?0:t,sx:(n=(r=e.scale)==null?void 0:r[0])==null?1:n,sy:(i=(a=e.scale)==null?void 0:a[1])==null?1:i,opacity:(o=e.opacity)==null?1:o,brightness:(s=e.brightness)==null?1:s,tint:e.tint?Q(e.tint):null}},z=(e,t)=>{if(e.frozen)return e.frozen;if(!e.duration||t>=e.start+e.duration)return e.to;let n=t<=e.start?0:e.ease((t-e.start)/e.duration);return B(e.from,e.to,n)},B=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n,rotation:e.rotation+(t.rotation-e.rotation)*n,sx:e.sx+(t.sx-e.sx)*n,sy:e.sy+(t.sy-e.sy)*n,opacity:e.opacity+(t.opacity-e.opacity)*n,brightness:e.brightness+(t.brightness-e.brightness)*n,tint:e.tint&&t.tint?V(e.tint,t.tint,n):t.tint}),V=(e,t,n)=>[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n],H=(e,t)=>{if(!e.parent)return{};let n=G(e.parent,t,new Map);return n?{parentMatrix:n.matrix,parentAlpha:n.alpha}:{}},U=(e,t,n=1)=>{var r;let i=[...e.keyframes];(!i.length||i[0].offset>0)&&i.unshift({offset:0}),i[i.length-1].offset<1&&i.push({offset:1});let a=t+((r=e.delay)==null?0:r),o=Math.max(1,e.duration),s=e.easing;return{frames:i,start:a,duration:o,iterations:n,end:n===1/0?1/0:a+o*n,ease:i.map(e=>{var t;return Y((t=e.easing)==null?s:t)})}},W=(e,t,n)=>{var r,i,a,o,s,c;if(t<e.start&&!n||t>=e.end&&!n)return null;let l=Math.max(0,Math.min(t,e.end===1/0?t:e.end)-e.start)/e.duration;l=t>=e.end?1:l-Math.floor(l);let{frames:u}=e,d=0;for(;d<u.length-2&&l>u[d+1].offset;)d++;let f=u[d],p=u[d+1],m=p.offset-f.offset||1,h=e.ease[d](Math.min(1,Math.max(0,(l-f.offset)/m))),g;for(let e of u)e.offset<=l&&e.sprite&&(g=e.sprite);let _=(e,t,n)=>(e==null?n:e)+((t==null?n:t)-(e==null?n:e))*h;return{x:_(f.x,p.x,0),y:_(f.y,p.y,0),rotation:_(f.rotation,p.rotation,0),sx:_((r=f.scale)==null?void 0:r[0],(i=p.scale)==null?void 0:i[0],1),sy:_((a=f.scale)==null?void 0:a[1],(o=p.scale)==null?void 0:o[1],1),opacity:_(f.opacity,p.opacity,1),brightness:_(f.brightness,p.brightness,1),tint:f.tint||p.tint?V(Q((s=f.tint)==null?p.tint:s),Q((c=p.tint)==null?f.tint:c),h):null,sprite:g}},G=(e,t,n)=>{var r;let i=n.get(e);if(i)return i;let{x:a,y:o,rotation:c,sx:l,sy:u,opacity:d,brightness:f,tint:p}=z(e,t),m=e.node.sprite,h=[[e.enter,!0],[e.exit,!0],...e.effects.map(e=>[e,!1])];for(let[e,n]of h){if(!e)continue;let r=W(e,t,n);r&&(a+=r.x,o+=r.y,c+=r.rotation,l*=r.sx,u*=r.sy,d*=r.opacity,f*=r.brightness,r.tint&&(p=r.tint),r.sprite&&(m=r.sprite))}let g=ee,_=1,v=1;if((r=e.frozen)!=null&&r.parentMatrix){var y;g=e.frozen.parentMatrix,_=(y=e.frozen.parentAlpha)==null?1:y}else if(e.parent){let r=G(e.parent,t,n);if(!r)return null;g=r.matrix,_=r.alpha,v=r.brightness}let b=c*Math.PI/180,x=Math.cos(b),S=Math.sin(b),C=[x*l,S*l,-S*u,x*u,a,o],w={matrix:te(g,ne(C)),alpha:_*d,brightness:Math.min(v*f,s.brightness),tint:p,sprite:m};return n.set(e,w),w},ee=[1,0,0,1,0,0],te=(e,t)=>[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]],ne=e=>e.map((e,t)=>t<4&&Math.abs(e-Math.round(e))<1e-9?Math.round(e):e),K=e=>!e||e===`normal`?`source-over`:e,re=(e,t)=>{for(let n=e.parent;n;n=n.parent)if(n===t)return!0;return!1},q=(e,t,n,r)=>{for(let i=n-1;i>=0;i--){let n=e.indexOf(t[i]);if(n>=0)return void e.splice(n+1,0,r)}e.unshift(r)},J=new Map,Y=e=>{if(!e)return L;let t=J.get(e);return t||J.set(e,t=n(e)),t},X,Z=new Map,Q=e=>{var t,n;let r=Z.get(e);if(r)return r;X!=null||(X=typeof OffscreenCanvas>`u`?document.createElement(`canvas`).getContext(`2d`):new OffscreenCanvas(1,1).getContext(`2d`)),X.fillStyle=`#000`,X.fillStyle=e;let i=String(X.fillStyle),a=/^#([0-9a-f]{6})$/i.exec(i),o=a?[0,2,4].map(e=>parseInt(a[1].slice(e,e+2),16)):(t=(n=/rgba?\(([^)]+)\)/.exec(i))==null?void 0:n[1].split(`,`).slice(0,3).map(Number))==null?[0,0,0]:t;return r=[o[0],o[1],o[2]],Z.set(e,r),r},$=new WeakMap,ie=48,ae=(e,t)=>{let n=t.map(e=>Math.round(e/4)*4).join(`,`),r=$.get(e.bitmap);r||$.set(e.bitmap,r=new Map);let i=r.get(n);if(i)return i;r.size>=ie&&r.clear();let{width:a,height:o}=e.bitmap;i=new OffscreenCanvas(a,o);let s=i.getContext(`2d`);return s.drawImage(e.bitmap,0,0),s.globalCompositeOperation=`multiply`,s.fillStyle=`rgb(${n})`,s.fillRect(0,0,a,o),s.globalCompositeOperation=`destination-in`,s.drawImage(e.bitmap,0,0),r.set(n,i),i};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return O}});
2
+ //# sourceMappingURL=tableBoard-CLDBwRYs.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableBoard-CLDBwRYs.cjs","names":[],"sources":["../src/easing.ts","../src/tableBoardScene.ts","../src/tableBoard.ts"],"sourcesContent":["// CSS easings as progress functions, for the table's boards. A scene names its easings in CSS syntax, so a game writes\n// the same `ease-out` or `cubic-bezier()` it would in a stylesheet.\n\n/**\n * Turns a CSS easing into a progress function: keywords, cubic-bezier() and linear() with optional stops. Anything\n * else (`steps()`, or a malformed value) is linear.\n */\nexport const parseEasing = (value: string): ((t: number) => number) => {\n const v = value.trim()\n if (v === \"linear\") return linear\n const keyword = keywordEasings[v]\n if (keyword) return cubicBezier(keyword[0], keyword[1], keyword[2], keyword[3])\n const bezier = /^cubic-bezier\\(([^)]+)\\)$/.exec(v)\n if (bezier) {\n const n = bezier[1].split(\",\").map(Number)\n if (n.length !== 4 || n.some((x) => Number.isNaN(x))) return linear\n return cubicBezier(n[0], n[1], n[2], n[3])\n }\n const lin = /^linear\\(([^)]+)\\)$/.exec(v)\n if (lin) return linearStops(lin[1])\n return linear\n}\n\nconst linear = (t: number) => t\n\nconst keywordEasings: Record<string, [number, number, number, number]> = {\n ease: [0.25, 0.1, 0.25, 1],\n \"ease-in\": [0.42, 0, 1, 1],\n \"ease-out\": [0, 0, 0.58, 1],\n \"ease-in-out\": [0.42, 0, 0.58, 1],\n}\n\nconst cubicBezier = (x1: number, y1: number, x2: number, y2: number) => {\n const sx = (t: number) => 3 * x1 * t * (1 - t) * (1 - t) + 3 * x2 * t * t * (1 - t) + t * t * t\n const sy = (t: number) => 3 * y1 * t * (1 - t) * (1 - t) + 3 * y2 * t * t * (1 - t) + t * t * t\n return (x: number) => {\n let lo = 0\n let hi = 1\n let t = x\n for (let i = 0; i < 24; i++) {\n const cx = sx(t)\n if (Math.abs(cx - x) < 1e-5) break\n if (cx < x) lo = t\n else hi = t\n t = (lo + hi) / 2\n }\n return sy(t)\n }\n}\n\n/** The inside of a linear(), stops with or without positions */\nconst linearStops = (list: string) => {\n const stops = list.split(\",\").map((s) => {\n const parts = s.trim().split(/\\s+/)\n return { value: Number(parts[0]), at: parts[1] ? parseFloat(parts[1]) / 100 : NaN }\n })\n if (stops.some((stop) => Number.isNaN(stop.value))) return linear\n if (Number.isNaN(stops[0].at)) stops[0].at = 0\n if (Number.isNaN(stops[stops.length - 1].at)) stops[stops.length - 1].at = 1\n // Missing positions spread evenly between the known ones on either side\n let last = 0\n for (let i = 0; i < stops.length; i++) {\n if (!Number.isNaN(stops[i].at)) {\n last = i\n continue\n }\n let next = i\n while (Number.isNaN(stops[next].at)) next++\n for (let j = last + 1; j < next; j++) stops[j].at = stops[last].at + ((stops[next].at - stops[last].at) * (j - last)) / (next - last)\n last = next\n }\n return (t: number) => {\n if (t <= stops[0].at) return stops[0].value\n for (let i = 1; i < stops.length; i++) {\n if (t <= stops[i].at) {\n const a = stops[i - 1]\n const b = stops[i]\n return a.value + ((b.value - a.value) * (t - a.at)) / (b.at - a.at || 1)\n }\n }\n return stops[stops.length - 1].value\n }\n}\n","import type {\n TableBoardAnimation,\n TableBoardBlend,\n TableBoardEffect,\n TableBoardKeyframe,\n TableBoardNode,\n TableBoardScene,\n TableBoardTiming,\n} from \"./types\"\n\n// A scene comes from a game's code, so the host takes nothing on trust: every field is checked and copied, and anything\n// unknown is dropped. A scene that breaks a rule is refused whole, with the reason, rather than drawn in part. In the\n// SDK so the simulator's Pmmg tab refuses the same scenes Puzzmo's table does.\n\n/** The most of each thing one scene can hold */\nexport const sceneLimits = {\n nodes: 5000,\n effects: 5000,\n keyframes: 32,\n /** The longest delay or duration, in ms */\n ms: 10_000,\n /** The largest board, in board units */\n size: 100_000,\n text: 200,\n /** How many nodes deep a node can sit, itself counted. Each isolated level draws on a layer the canvas's size */\n depth: 16,\n /** The brightest a node draws, however its own, its keyframes' and its parents' brightness multiply */\n brightness: 10,\n}\n\n/** The scene with only what the host knows how to draw, or throws saying what's wrong with it */\nexport const validateScene = (input: unknown): TableBoardScene => {\n const scene = record(input, \"The scene\")\n const width = positive(scene.width, \"The scene's width\", sceneLimits.size)\n const height = positive(scene.height, \"The scene's height\", sceneLimits.size)\n const rawNodes = list(scene.nodes, \"The scene's nodes\", sceneLimits.nodes)\n const keys = new Set<string>()\n const parents = new Map<string, string | undefined>()\n // Isolated nodes whose children are being listed, innermost last, and those whose run of children is over\n const open: string[] = []\n const closed = new Set<string>()\n const nodes = rawNodes.map((raw, index) => {\n const node = validateNode(raw, `Node ${index}`)\n if (keys.has(node.key)) throw new Error(`Node ${index}'s key \"${node.key}\" is used twice`)\n if (node.parent !== undefined && !keys.has(node.parent))\n throw new Error(`Node \"${node.key}\"'s parent \"${node.parent}\" must come before it`)\n keys.add(node.key)\n parents.set(node.key, node.parent)\n const ancestors = new Set<string>()\n for (let at = node.parent; at !== undefined; at = parents.get(at)) ancestors.add(at)\n if (ancestors.size >= sceneLimits.depth) throw new Error(`Node \"${node.key}\" is nested over ${sceneLimits.depth} nodes deep`)\n while (open.length && !ancestors.has(open[open.length - 1])) closed.add(open.pop()!)\n const split = [...ancestors].find((key) => closed.has(key))\n if (split) throw new Error(`Node \"${node.key}\" is in isolated \"${split}\", so it must come straight after its other children`)\n if (node.isolate) open.push(node.key)\n return node\n })\n const out: TableBoardScene = { width, height, nodes }\n if (scene.grid !== undefined) out.grid = positive(scene.grid, \"The scene's grid\", width)\n if (scene.transition !== undefined) out.transition = timing(scene.transition, \"The scene's transition\")\n if (scene.effects !== undefined) {\n out.effects = list(scene.effects, \"The scene's effects\", sceneLimits.effects).map((raw, index) => {\n const effect = validateEffect(raw, `Effect ${index}`)\n if (!keys.has(effect.key)) throw new Error(`Effect ${index} is for \"${effect.key}\", which isn't in the scene`)\n return effect\n })\n }\n return out\n}\n\n/** Every sprite a scene names, in its nodes and in its keyframes */\nexport const spritesIn = (scene: TableBoardScene): Set<string> => {\n const ids = new Set<string>()\n const fromFrames = (animation?: TableBoardAnimation) => animation?.keyframes.forEach((frame) => frame.sprite && ids.add(frame.sprite))\n for (const node of scene.nodes) {\n if (node.sprite) ids.add(node.sprite)\n fromFrames(node.enter)\n fromFrames(node.exit)\n }\n scene.effects?.forEach(fromFrames)\n return ids\n}\n\nconst validateNode = (input: unknown, label: string): TableBoardNode => {\n const raw = record(input, label)\n const node: TableBoardNode = { key: text(raw.key, `${label}'s key`), x: finite(raw.x, `${label}'s x`), y: finite(raw.y, `${label}'s y`) }\n if (raw.sprite !== undefined) node.sprite = text(raw.sprite, `${label}'s sprite`)\n if (raw.parent !== undefined) node.parent = text(raw.parent, `${label}'s parent`)\n if (raw.blend !== undefined) {\n if (!blends.includes(raw.blend as TableBoardBlend)) throw new Error(`${label}'s blend must be one of ${blends.join(\", \")}`)\n node.blend = raw.blend as TableBoardBlend\n }\n if (raw.isolate === true) node.isolate = true\n Object.assign(node, appearance(raw, label))\n if (raw.transition === false) node.transition = false\n else if (raw.transition !== undefined) node.transition = timing(raw.transition, `${label}'s transition`)\n if (raw.enter !== undefined) node.enter = animation(raw.enter, `${label}'s enter`)\n if (raw.exit !== undefined) node.exit = animation(raw.exit, `${label}'s exit`)\n return node\n}\n\nconst validateEffect = (input: unknown, label: string): TableBoardEffect => {\n const raw = record(input, label)\n const effect: TableBoardEffect = { key: text(raw.key, `${label}'s key`), ...animation(raw, label) }\n if (raw.iterations !== undefined) {\n const iterations = Number(raw.iterations)\n if (!(iterations >= 1)) throw new Error(`${label}'s iterations must be 1 or more`)\n effect.iterations = iterations\n }\n return effect\n}\n\n/** The values a node and a keyframe share */\nconst appearance = (raw: Record<string, unknown>, label: string) => {\n const out: Partial<TableBoardKeyframe> = {}\n if (raw.rotation !== undefined) out.rotation = finite(raw.rotation, `${label}'s rotation`)\n if (raw.scale !== undefined) out.scale = pair(raw.scale, `${label}'s scale`)\n if (raw.opacity !== undefined) out.opacity = clamp(finite(raw.opacity, `${label}'s opacity`), 0, 1)\n if (raw.brightness !== undefined) out.brightness = clamp(finite(raw.brightness, `${label}'s brightness`), 0, sceneLimits.brightness)\n if (raw.tint !== undefined) out.tint = text(raw.tint, `${label}'s tint`)\n return out\n}\n\nconst animation = (input: unknown, label: string): TableBoardAnimation => {\n const raw = record(input, label)\n let last = -1\n const keyframes = list(raw.keyframes, `${label}'s keyframes`, sceneLimits.keyframes).map((rawFrame, index) => {\n const frameLabel = `${label}'s keyframe ${index}`\n const frame = record(rawFrame, frameLabel)\n const offset = finite(frame.offset, `${frameLabel}'s offset`)\n if (offset < 0 || offset > 1 || offset < last) throw new Error(`${frameLabel}'s offset must be from 0 to 1, in order`)\n last = offset\n const out: TableBoardKeyframe = { offset, ...appearance(frame, frameLabel) }\n if (frame.x !== undefined) out.x = finite(frame.x, `${frameLabel}'s x`)\n if (frame.y !== undefined) out.y = finite(frame.y, `${frameLabel}'s y`)\n if (frame.easing !== undefined) out.easing = text(frame.easing, `${frameLabel}'s easing`)\n if (frame.sprite !== undefined) out.sprite = text(frame.sprite, `${frameLabel}'s sprite`)\n return out\n })\n return { ...timing(raw, label), keyframes }\n}\n\nconst timing = (input: unknown, label: string): TableBoardTiming => {\n const raw = record(input, label)\n const out: TableBoardTiming = { duration: clamp(finite(raw.duration, `${label}'s duration`), 0, sceneLimits.ms) }\n if (raw.delay !== undefined) out.delay = clamp(finite(raw.delay, `${label}'s delay`), 0, sceneLimits.ms)\n if (raw.easing !== undefined) out.easing = text(raw.easing, `${label}'s easing`)\n return out\n}\n\nconst blends: TableBoardBlend[] = [\n \"normal\",\n \"multiply\",\n \"screen\",\n \"overlay\",\n \"darken\",\n \"lighten\",\n \"color-dodge\",\n \"color-burn\",\n \"hard-light\",\n \"soft-light\",\n \"difference\",\n \"exclusion\",\n \"hue\",\n \"saturation\",\n \"color\",\n \"luminosity\",\n]\n\nconst record = (value: unknown, label: string) => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) throw new Error(`${label} must be an object`)\n return value as Record<string, unknown>\n}\n\nconst list = (value: unknown, label: string, max: number) => {\n if (!Array.isArray(value)) throw new Error(`${label} must be a list`)\n if (value.length > max) throw new Error(`${label} can hold at most ${max}, got ${value.length}`)\n return value as unknown[]\n}\n\nconst text = (value: unknown, label: string) => {\n if (typeof value !== \"string\" || !value || value.length > sceneLimits.text)\n throw new Error(`${label} must be text of 1 to ${sceneLimits.text} characters`)\n return value\n}\n\nconst finite = (value: unknown, label: string) => {\n if (typeof value !== \"number\" || !Number.isFinite(value)) throw new Error(`${label} must be a finite number`)\n return value\n}\n\nconst positive = (value: unknown, label: string, max: number) => {\n const n = finite(value, label)\n if (n <= 0 || n > max) throw new Error(`${label} must be above 0 and at most ${max}`)\n return n\n}\n\nconst pair = (value: unknown, label: string): [number, number] => {\n if (!Array.isArray(value) || value.length !== 2) throw new Error(`${label} must be two numbers`)\n return [finite(value[0], label), finite(value[1], label)]\n}\n\nconst clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n))\n","// A neighbour's board drawn from its game's pmmg bundle (see TableBoardCapability). The bundle turns each update into a\n// scene of keyed nodes and makes the sprites they show, in its sandbox; this draws scenes on a canvas and does all the\n// animating: a node that changes moves from its old values to its new ones, new nodes enter, gone ones exit, and\n// effects play over the top. Every board at the table draws from one animation loop, only while one moves. It's in the\n// SDK so puzzmo.com's table and the simulator's Pmmg tab draw a board the same way.\n//\n// A board draws wherever its canvas is: on the page, or in a worker on a canvas the page handed over, which keeps the\n// drawing off the page's main thread. A worker has no document, so there the page says what it knows of the screen\n// through setTableBoardEnvironment, and sizes the canvas's element from onFit.\n//\n// Updates queue: the step on screen plays out, at most one update waits behind it (a newer one\n// replaces it), and the next render goes from what's showing to what's waiting, so the renderer animates across any\n// update that was passed over.\n\nimport { parseEasing } from \"./easing\"\nimport type {\n TableBoardAnimation,\n TableBoardBackgroundStyle,\n TableBoardBlend,\n TableBoardFidelity,\n TableBoardKeyframe,\n TableBoardNode,\n TableBoardScene,\n TableBoardUpdate,\n Theme,\n} from \"./types\"\nimport { sceneLimits } from \"./tableBoardScene\"\n\nexport { sceneLimits, spritesIn, validateScene } from \"./tableBoardScene\"\n\n/** A sprite's picture, at one resolution */\nexport type SpriteBitmap = {\n bitmap: ImageBitmap\n /** In board units */\n width: number\n height: number\n anchor: [number, number]\n}\n\n/** What a board draws from: Puzzmo's sandboxed pmmg bundle at the table, the game's own code in the simulator */\nexport type TableBoardRenderer = {\n /** The board after an update, once every sprite it names is here to draw */\n render(update: TableBoardUpdate): Promise<TableBoardScene>\n /** A sprite at a resolution, once a render has made it */\n sprite(id: string, pixelsPerUnit: number): SpriteBitmap | undefined\n}\n\n/** One frame as a board drew it, for a debugging overlay drawn over the top */\nexport type TableBoardFrame = {\n /** The board's canvas, its transform reset, so the overlay draws in device pixels */\n ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D\n /** Device pixels per board unit on the canvas */\n scale: number\n scene: TableBoardScene\n /** Every node with a place this frame, in drawing order, children after their parents */\n nodes: TableBoardDrawnNode[]\n}\n\nexport type TableBoardDrawnNode = {\n key: string\n /** The sprite it showed, keyframes applied; none for a node that only carries its children */\n sprite?: string\n /** Where it sits in board units, its parents' places folded in, as a canvas transform */\n matrix: [number, number, number, number, number, number]\n alpha: number\n /** Gone from the scene and playing its exit */\n exiting: boolean\n}\n\n/** Where a board is shown, which the bundle can draw it for; the background is the theme's when it's left out */\nexport type TableBoardLook = { fidelity: TableBoardFidelity; backgroundStyle?: TableBoardBackgroundStyle }\n\ntype View = { puzzle: string; input: string }\n\n/** The longest a step holds the queue, however long its animations run */\nconst maxStepMs = 3_000\n/** How long a board's width has to hold before its sprites are made again at the new size */\nconst settleMs = 250\n/** Failed renders in a row a board survives once it has drawn; one that hasn't gives up at once */\nconst failuresBeforeGivingUp = 3\n\nconst boards = new Set<TableBoard>()\nlet frame = 0\n\nexport class TableBoard {\n private scene: TableBoardScene | null = null\n /** The resolution the scene's sprites were made at, and the one the canvas wants once its width settles */\n private spritesPpu = 0\n private wantedPpu = 0\n private live = new Map<string, Live>()\n private order: Live[] = []\n /** When everything the last step started has finished, loops aside */\n private until = 0\n private looping = false\n private shown: View | null = null\n private waiting: View | null = null\n private skipped = 0\n private rendering = false\n private failures = 0\n private disposed = false\n /** The box the board fits inside, and the width it's drawn at there */\n private boxWidth = 0\n private boxHeight = 0\n private cssWidth = 0\n /** The canvas's width in device pixels, which sets the board's scale */\n private pixelWidth = 0\n private height = 0\n private pendingHeight = 0\n private needsFit = false\n private settleTimer: ReturnType<typeof setTimeout> | undefined\n private stepTimer: ReturnType<typeof setTimeout> | undefined\n private ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D\n private theme: Theme | null = null\n private look: TableBoardLook = { fidelity: \"high\" }\n private layers: OffscreenCanvasRenderingContext2D[] = []\n dirty = false\n /** Called after every frame with where each node was drawn, for the simulator's debug overlay */\n onDrawn?: (frame: TableBoardFrame) => void\n /** Called with the canvas's size on the page whenever it changes, for a canvas whose element is on another thread */\n onFit?: (cssWidth: number, cssHeight: number) => void\n private fittedWidth = 0\n private fittedHeight = 0\n\n constructor(\n private canvas: HTMLCanvasElement | OffscreenCanvas,\n private renderer: TableBoardRenderer,\n /** Steady for the board's life, for the renderer's caches */\n private boardID: string,\n /** Told when the board stops for good: frozen on its last scene if it had one (`drew`), else blank */\n private onBroken: (error: unknown, drew: boolean) => void,\n ) {\n this.ctx = (canvas as OffscreenCanvas).getContext(\"2d\")!\n boards.add(this)\n }\n\n /** The newest view of the board; it shows once the step on screen has played out */\n update(view: View) {\n if (this.waiting) this.skipped++\n else if (this.shown && view.input === this.shown.input && view.puzzle === this.shown.puzzle) return\n this.waiting = view\n this.pump()\n }\n\n /** A new theme makes new sprites, so the board is drawn again in it; nothing's drawn before the first */\n setTheme(theme: Theme) {\n if (theme === this.theme) return\n this.theme = theme\n if (this.shown && !this.waiting) this.waiting = this.shown\n this.pump()\n }\n\n /** How much detail to draw and what's behind the board; a change draws it again, as a theme's does. Set it before the theme. */\n setLook(look: TableBoardLook) {\n if (look.fidelity === this.look.fidelity && look.backgroundStyle === this.look.backgroundStyle) return\n this.look = look\n if (this.shown && !this.waiting) this.waiting = this.shown\n this.pump()\n }\n\n /**\n * The box the board fits inside, as a thumbnail does: as wide as it can be without running past the bottom. A box\n * with no height of its own is only a width. The fitted width sets the canvas's pixel size and, once it settles, the\n * sprites' resolution\n */\n resize(boxWidth: number, boxHeight: number) {\n if ((boxWidth === this.boxWidth && boxHeight === this.boxHeight) || boxWidth <= 0) return\n this.boxWidth = boxWidth\n this.boxHeight = boxHeight\n // Before the first scene its shape isn't known, so its first sprites are made for the box's width\n if (!this.scene) this.cssWidth = boxWidth\n // On the next frame rather than in the resize observer: sizing the canvas there loops the observer\n this.needsFit = true\n this.dirty = true\n wake()\n }\n\n /** Draws the board again on the next frame, for an overlay that changed when nothing on the board did */\n redraw() {\n this.dirty = true\n wake()\n }\n\n /** Stops for good, showing the last scene as it ends, so a broken renderer reads as a neighbour who's paused */\n freeze() {\n if (this.disposed) return\n if (this.scene) this.draw(Infinity)\n this.dispose()\n }\n\n dispose() {\n this.disposed = true\n clearTimeout(this.settleTimer)\n clearTimeout(this.stepTimer)\n boards.delete(this)\n }\n\n /** Starts the next render when the queue allows one */\n private pump() {\n if (this.disposed || this.rendering || !this.theme) return\n const now = performance.now()\n const stepDone = now >= Math.min(this.until, this.stepStart + maxStepMs) || instant()\n if (this.waiting && !stepDone) {\n clearTimeout(this.stepTimer)\n this.stepTimer = setTimeout(() => this.pump(), Math.min(this.until, this.stepStart + maxStepMs) - now + 1)\n return\n }\n // The same view again at a new resolution: nothing changes, so nothing animates\n const next = this.waiting ?? (this.shown && this.wantedPpu && this.wantedPpu !== this.spritesPpu ? this.shown : null)\n if (!next) return\n this.waiting = null\n const skipped = this.skipped\n this.skipped = 0\n void this.render(next, skipped)\n }\n\n private stepStart = 0\n\n private async render(next: View, skipped: number) {\n this.rendering = true\n const ppu = this.wantedPpu || this.ppuFor(this.scene?.width ?? lastWidth.get(this.renderer))\n try {\n const scene = await this.renderer.render({\n board: this.boardID,\n puzzle: next.puzzle,\n input: next.input,\n previous: this.shown ?? undefined,\n skipped,\n theme: this.theme!,\n fidelity: this.look.fidelity,\n backgroundStyle: this.look.backgroundStyle ?? this.theme!.type,\n pixelsPerUnit: ppu,\n })\n if (this.disposed) return\n this.failures = 0\n lastWidth.set(this.renderer, scene.width)\n this.spritesPpu = ppu\n // The first scene says how wide the board is; if the guess was off, its sprites are made again at the right size\n this.wantedPpu = this.ppuFor(scene.width)\n this.show(scene, this.shown ? performance.now() : -Infinity)\n this.shown = next\n } catch (error) {\n if (this.disposed) return\n this.failures++\n if (!this.shown || this.failures >= failuresBeforeGivingUp) {\n this.freeze()\n return this.onBroken(error, !!this.shown)\n }\n console.warn(\"A table board couldn't render:\", error)\n // Tried again with whatever's newest\n this.waiting ??= next\n } finally {\n this.rendering = false\n }\n this.pump()\n }\n\n /** Device pixels per board unit: the canvas's exactly, so sprites drawn at their own size are the board's size */\n private ppuFor(width: number | undefined) {\n const dpr = pixelRatio()\n if (!width) return dpr\n // Before the first scene the canvas isn't sized, so it's a guess from the box\n const pixels = this.pixelWidth || this.cssWidth * dpr\n // Rounded only past where floats wobble, so the same size always names the same sprites\n return pixels ? Math.round((pixels / width) * 1e6) / 1e6 : dpr\n }\n\n /** Matches the scene to what's on screen by key, and starts what moves; `now` of -Infinity shows it settled */\n private show(scene: TableBoardScene, now: number) {\n const still = now === -Infinity || instant()\n const at = still ? 0 : now\n this.stepStart = at\n let until = at\n let looping = false\n const previous = this.live\n const next = new Map<string, Live>()\n\n for (const node of scene.nodes) {\n const parent = node.parent ? next.get(node.parent)! : null\n const old = previous.get(node.key)\n const target = valuesOf(node)\n if (old && !old.exit) {\n const timing = still ? null : node.transition === false ? null : (node.transition ?? scene.transition ?? null)\n const from = baseAt(old, at)\n old.from = from\n old.to = target\n old.start = at + (timing?.delay ?? 0)\n old.duration = timing?.duration ?? 0\n old.ease = easing(timing?.easing)\n old.node = node\n old.parent = parent\n until = Math.max(until, old.start + old.duration)\n next.set(node.key, old)\n } else {\n const live: Live = { node, parent, from: target, to: target, start: at, duration: 0, ease: linear, effects: [] }\n if (node.enter && !still) {\n live.enter = running(node.enter, at)\n until = Math.max(until, live.enter.end)\n }\n next.set(node.key, live)\n }\n }\n\n // Gone from the scene: exits from where it is now, in its place in the drawing order, then goes\n const order: Live[] = scene.nodes.map((node) => next.get(node.key)!)\n for (let i = 0; i < this.order.length; i++) {\n const old = this.order[i]\n if (next.get(old.node.key) === old) continue\n // Already leaving: it plays on, or it's gone. Starting its exit again would bring back every node that ever left\n if (old.exit) {\n if (!still && old.exit.end > at) insertAfterPrevious(order, this.order, i, old)\n continue\n }\n if (!old.node.exit || still) continue\n old.frozen = { ...baseAt(old, at), ...frozenParent(old, at) }\n old.exit = running(old.node.exit, at)\n old.effects = []\n until = Math.max(until, old.exit.end)\n insertAfterPrevious(order, this.order, i, old)\n }\n\n if (!still) {\n for (const effect of scene.effects ?? []) {\n const live = next.get(effect.key)\n if (!live) continue\n const run = running(effect, at, effect.iterations ?? 1)\n live.effects.push(run)\n if (run.end === Infinity) looping = true\n else until = Math.max(until, run.end)\n }\n }\n for (const live of next.values()) {\n live.effects = live.effects.filter((run) => run.end > at)\n if (live.effects.some((run) => run.end === Infinity)) looping = true\n }\n\n this.live = next\n this.order = order\n this.until = until\n this.looping = looping\n const grew = !this.scene || scene.height / scene.width > this.height / (this.scene.width || 1)\n this.scene = scene\n // A board grows at once, and shrinks once what's leaving has left\n if (grew || still) {\n this.height = scene.height\n this.pendingHeight = 0\n } else this.pendingHeight = scene.height\n this.fit()\n this.dirty = true\n wake()\n }\n\n animating(now: number) {\n return this.looping || now < this.until || (this.pendingHeight > 0 && now >= this.until)\n }\n\n /** Draws the board as it is at `now`; true while something still moves */\n draw(now: number) {\n this.dirty = false\n const scene = this.scene\n if (!scene || !this.cssWidth) return false\n if (this.needsFit) this.fit()\n if (this.pendingHeight && now >= this.until) {\n this.height = this.pendingHeight\n this.pendingHeight = 0\n this.fit()\n }\n const { ctx, canvas } = this\n const scale = canvas.width / scene.width\n ctx.setTransform(1, 0, 0, 1, 0, 0)\n ctx.clearRect(0, 0, canvas.width, canvas.height)\n const worlds = new Map<Live, World>()\n // Isolated nodes being drawn, innermost last: each one's children go on a layer of their own, put down when its\n // run of children ends\n const open: { owner: Live; layer: OffscreenCanvasRenderingContext2D }[] = []\n const target = () => (open.length ? open[open.length - 1].layer : ctx)\n const close = () => {\n const { owner, layer } = open.pop()!\n const into = target()\n into.setTransform(1, 0, 0, 1, 0, 0)\n into.globalAlpha = 1\n into.globalCompositeOperation = compositeFor(owner.node.blend)\n into.drawImage(layer.canvas, 0, 0)\n into.globalCompositeOperation = \"source-over\"\n }\n // Only gathered when something is listening\n const drawn: TableBoardDrawnNode[] | null = this.onDrawn ? [] : null\n for (const live of this.order) {\n if (live.exit && now >= live.exit.end) continue\n while (open.length && !isInside(live, open[open.length - 1].owner)) close()\n const world = worldOf(live, now, worlds)\n if (world && drawn)\n drawn.push({ key: live.node.key, sprite: world.sprite, matrix: world.matrix, alpha: world.alpha, exiting: !!live.exit })\n if (!world || world.alpha <= 0) continue\n if (live.node.isolate) open.push({ owner: live, layer: this.layer(open.length) })\n if (world.sprite) this.drawSprite(target(), world.sprite, world, world.alpha, scale, live.node.blend)\n }\n while (open.length) close()\n ctx.globalAlpha = 1\n ctx.globalCompositeOperation = \"source-over\"\n ctx.setTransform(1, 0, 0, 1, 0, 0)\n if (drawn) this.onDrawn!({ ctx, scale, scene, nodes: drawn })\n return this.animating(now)\n }\n\n /** A cleared layer the canvas's size for isolated nodes at `depth`, kept from frame to frame */\n private layer(depth: number) {\n let layer = this.layers[depth]\n if (!layer || layer.canvas.width !== this.canvas.width || layer.canvas.height !== this.canvas.height)\n layer = this.layers[depth] = new OffscreenCanvas(this.canvas.width, this.canvas.height).getContext(\"2d\")!\n layer.setTransform(1, 0, 0, 1, 0, 0)\n layer.clearRect(0, 0, layer.canvas.width, layer.canvas.height)\n return layer\n }\n\n private drawSprite(\n ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,\n id: string,\n world: World,\n alpha: number,\n scale: number,\n blend: TableBoardBlend | undefined,\n ) {\n const sprite = this.renderer.sprite(id, this.spritesPpu)\n if (!sprite || alpha <= 0) return\n const m = world.matrix\n const image: CanvasImageSource = world.tint ? tinted(sprite, world.tint) : sprite.bitmap\n // Within a percent of the size it was made at counts as that size, since the resolution is rounded\n const pixelPerfect = m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1 && Math.abs(scale / this.spritesPpu - 1) < 1e-5\n ctx.globalAlpha = alpha\n ctx.globalCompositeOperation = compositeFor(blend)\n if (pixelPerfect) {\n // Only moved, at the size it was made: whole device pixels, so it's as sharp as its sprite\n ctx.setTransform(1, 0, 0, 1, 0, 0)\n const left = Math.round((m[4] - sprite.anchor[0]) * scale)\n const top = Math.round((m[5] - sprite.anchor[1]) * scale)\n ctx.drawImage(image, left, top)\n for (let extra = world.brightness - 1; extra > 0; extra--) {\n ctx.globalCompositeOperation = \"lighter\"\n ctx.globalAlpha = alpha * Math.min(1, extra)\n ctx.drawImage(image, left, top)\n }\n } else {\n ctx.setTransform(m[0] * scale, m[1] * scale, m[2] * scale, m[3] * scale, m[4] * scale, m[5] * scale)\n const draw = () => ctx.drawImage(image, -sprite.anchor[0], -sprite.anchor[1], sprite.width, sprite.height)\n draw()\n for (let extra = world.brightness - 1; extra > 0; extra--) {\n ctx.globalCompositeOperation = \"lighter\"\n ctx.globalAlpha = alpha * Math.min(1, extra)\n draw()\n }\n }\n ctx.globalCompositeOperation = \"source-over\"\n }\n\n /** The canvas's size on the page and in pixels, for its box and the board's shape */\n private fit() {\n const scene = this.scene\n if (!scene || !this.boxWidth) return\n this.needsFit = false\n const dpr = pixelRatio()\n const fitted = this.boxHeight > 0 ? Math.min(this.boxWidth, (this.boxHeight * scene.width) / this.height) : this.boxWidth\n // With a grid, the largest scale that fits and puts each grid step on whole device pixels\n const pixelWidth = Math.round(\n scene.grid ? Math.max(1, Math.floor(((fitted * dpr) / scene.width) * scene.grid)) * (scene.width / scene.grid) : fitted * dpr,\n )\n const cssWidth = pixelWidth / dpr\n this.pixelWidth = pixelWidth\n if (cssWidth !== this.cssWidth) {\n this.cssWidth = cssWidth\n clearTimeout(this.settleTimer)\n this.settleTimer = setTimeout(() => {\n this.wantedPpu = this.ppuFor(this.scene?.width)\n this.pump()\n }, settleMs)\n }\n const cssHeight = (this.cssWidth * this.height) / scene.width\n const width = pixelWidth\n const height = Math.round((pixelWidth * this.height) / scene.width)\n // An offscreen canvas has no element here to size\n if (\"style\" in this.canvas) {\n this.canvas.style.width = `${this.cssWidth}px`\n this.canvas.style.height = `${cssHeight}px`\n }\n if (this.cssWidth !== this.fittedWidth || cssHeight !== this.fittedHeight) {\n this.fittedWidth = this.cssWidth\n this.fittedHeight = cssHeight\n this.onFit?.(this.cssWidth, cssHeight)\n }\n // Setting a canvas's size, even to the same one, clears it\n if (width === this.canvas.width && height === this.canvas.height) return\n this.canvas.width = width\n this.canvas.height = height\n this.dirty = true\n wake()\n }\n}\n\n/** The renderer's last board width, so a new board's first sprites are made near the right size */\nconst lastWidth = new WeakMap<TableBoardRenderer, number>()\n\n/** What a board needs to know of the screen it's shown on, which a worker can't read for itself */\nexport type TableBoardEnvironment = { devicePixelRatio: number; hidden: boolean; reducedMotion: boolean }\n\nconst environment: Partial<TableBoardEnvironment> = {}\n\n/** Says what the page knows of the screen, where boards draw without a document; what's left out is read from the globals */\nexport const setTableBoardEnvironment = (next: Partial<TableBoardEnvironment>) => void Object.assign(environment, next)\n\nconst pixelRatio = () => environment.devicePixelRatio ?? (devicePixelRatio || 1)\n\nconst instant = () =>\n (environment.hidden ?? document.hidden) ||\n (environment.reducedMotion ?? (reducedMotion ??= matchMedia(\"(prefers-reduced-motion: reduce)\")).matches)\n/** Made on first use, not when the module loads, so importing the table is safe where there's no window */\nlet reducedMotion: MediaQueryList | undefined\n\nconst wake = () => {\n if (!frame) frame = requestAnimationFrame(loop)\n}\n\nconst loop = (now: number) => {\n frame = 0\n let moving = false\n for (const board of boards) {\n if (!board.dirty && !board.animating(now)) continue\n try {\n moving = board.draw(now) || moving\n } catch (error) {\n console.error(\"A table board couldn't be drawn:\", error)\n }\n }\n if (moving) wake()\n}\n\n// Animation state\n\ntype RGB = [number, number, number]\n\n/** A node's values: what transitions animate between */\ntype Values = { x: number; y: number; rotation: number; sx: number; sy: number; opacity: number; brightness: number; tint: RGB | null }\n\n/** One animation playing on a node, its keyframes ready to sample */\ntype Running = { frames: TableBoardKeyframe[]; start: number; duration: number; end: number; iterations: number; ease: Ease[] }\n\ntype Ease = (t: number) => number\n\n/** A node on screen and what it's doing */\ntype Live = {\n node: TableBoardNode\n parent: Live | null\n /** The transition from `from` to `to` */\n from: Values\n to: Values\n start: number\n duration: number\n ease: Ease\n enter?: Running\n exit?: Running\n /** Where an exiting node was, its parent's place folded in, since its parent may be gone */\n frozen?: Values & { parentMatrix?: Matrix; parentAlpha?: number }\n effects: Running[]\n}\n\ntype World = { matrix: Matrix; alpha: number; brightness: number; tint: RGB | null; sprite?: string }\n\nconst linear: Ease = (t) => t\n\nconst valuesOf = (node: TableBoardNode): Values => ({\n x: node.x,\n y: node.y,\n rotation: node.rotation ?? 0,\n sx: node.scale?.[0] ?? 1,\n sy: node.scale?.[1] ?? 1,\n opacity: node.opacity ?? 1,\n brightness: node.brightness ?? 1,\n tint: node.tint ? parseColor(node.tint) : null,\n})\n\n/** A node's own values at `now`, its transition applied but not its animations */\nconst baseAt = (live: Live, now: number): Values => {\n if (live.frozen) return live.frozen\n if (!live.duration || now >= live.start + live.duration) return live.to\n const t = now <= live.start ? 0 : live.ease((now - live.start) / live.duration)\n return mix(live.from, live.to, t)\n}\n\nconst mix = (a: Values, b: Values, t: number): Values => ({\n x: a.x + (b.x - a.x) * t,\n y: a.y + (b.y - a.y) * t,\n rotation: a.rotation + (b.rotation - a.rotation) * t,\n sx: a.sx + (b.sx - a.sx) * t,\n sy: a.sy + (b.sy - a.sy) * t,\n opacity: a.opacity + (b.opacity - a.opacity) * t,\n brightness: a.brightness + (b.brightness - a.brightness) * t,\n tint: a.tint && b.tint ? mixRGB(a.tint, b.tint, t) : b.tint,\n})\n\nconst mixRGB = (a: RGB, b: RGB, t: number): RGB => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t]\n\n/** An exiting node's parent as it was, so the node stays put if its parent goes first */\nconst frozenParent = (live: Live, now: number) => {\n if (!live.parent) return {}\n const world = worldOf(live.parent, now, new Map())\n return world ? { parentMatrix: world.matrix, parentAlpha: world.alpha } : {}\n}\n\nconst running = (animation: TableBoardAnimation, now: number, iterations = 1): Running => {\n const frames = [...animation.keyframes]\n // CSS's implied ends: the node's own values\n if (!frames.length || frames[0].offset > 0) frames.unshift({ offset: 0 })\n if (frames[frames.length - 1].offset < 1) frames.push({ offset: 1 })\n const start = now + (animation.delay ?? 0)\n const duration = Math.max(1, animation.duration)\n const fallback = animation.easing\n return {\n frames,\n start,\n duration,\n iterations,\n end: iterations === Infinity ? Infinity : start + duration * iterations,\n ease: frames.map((frame) => easing(frame.easing ?? fallback)),\n }\n}\n\n/** What an animation adds at `now`: null outside it, unless it fills (an enter before it starts, an exit after it ends) */\nconst sample = (run: Running, now: number, fill: boolean) => {\n if (now < run.start && !fill) return null\n if (now >= run.end && !fill) return null\n const elapsed = Math.max(0, Math.min(now, run.end === Infinity ? now : run.end) - run.start)\n let progress = elapsed / run.duration\n progress = now >= run.end ? 1 : progress - Math.floor(progress)\n const { frames } = run\n let i = 0\n while (i < frames.length - 2 && progress > frames[i + 1].offset) i++\n const a = frames[i]\n const b = frames[i + 1]\n const span = b.offset - a.offset || 1\n const t = run.ease[i](Math.min(1, Math.max(0, (progress - a.offset) / span)))\n let sprite: string | undefined\n for (const frame of frames) if (frame.offset <= progress && frame.sprite) sprite = frame.sprite\n const lerp = (x: number | undefined, y: number | undefined, identity: number) => (x ?? identity) + ((y ?? identity) - (x ?? identity)) * t\n return {\n x: lerp(a.x, b.x, 0),\n y: lerp(a.y, b.y, 0),\n rotation: lerp(a.rotation, b.rotation, 0),\n sx: lerp(a.scale?.[0], b.scale?.[0], 1),\n sy: lerp(a.scale?.[1], b.scale?.[1], 1),\n opacity: lerp(a.opacity, b.opacity, 1),\n brightness: lerp(a.brightness, b.brightness, 1),\n tint: a.tint || b.tint ? mixRGB(parseColor(a.tint ?? b.tint!), parseColor(b.tint ?? a.tint!), t) : null,\n sprite,\n }\n}\n\n/** Where a node is on the board at `now`, and how it's drawn, its parents' places folded in */\nconst worldOf = (live: Live, now: number, worlds: Map<Live, World>): World | null => {\n const known = worlds.get(live)\n if (known) return known\n const base = baseAt(live, now)\n let { x, y, rotation, sx, sy, opacity, brightness, tint } = base\n let sprite = live.node.sprite\n const runs: [Running | undefined, boolean][] = [\n [live.enter, true],\n [live.exit, true],\n ...live.effects.map((run): [Running, boolean] => [run, false]),\n ]\n for (const [run, fill] of runs) {\n if (!run) continue\n const at = sample(run, now, fill)\n if (!at) continue\n x += at.x\n y += at.y\n rotation += at.rotation\n sx *= at.sx\n sy *= at.sy\n opacity *= at.opacity\n brightness *= at.brightness\n if (at.tint) tint = at.tint\n if (at.sprite) sprite = at.sprite\n }\n let parentMatrix = identity\n let parentAlpha = 1\n let parentBrightness = 1\n if (live.frozen?.parentMatrix) {\n parentMatrix = live.frozen.parentMatrix\n parentAlpha = live.frozen.parentAlpha ?? 1\n } else if (live.parent) {\n const parent = worldOf(live.parent, now, worlds)\n if (!parent) return null\n parentMatrix = parent.matrix\n parentAlpha = parent.alpha\n parentBrightness = parent.brightness\n }\n const radians = (rotation * Math.PI) / 180\n const cos = Math.cos(radians)\n const sin = Math.sin(radians)\n const local: Matrix = [cos * sx, sin * sx, -sin * sy, cos * sy, x, y]\n const world: World = {\n matrix: multiply(parentMatrix, snap(local)),\n alpha: parentAlpha * opacity,\n // Capped here, as each extra unit is another draw: multiplied unchecked, a scene's brightness could reach Infinity\n brightness: Math.min(parentBrightness * brightness, sceneLimits.brightness),\n tint,\n sprite,\n }\n worlds.set(live, world)\n return world\n}\n\ntype Matrix = [number, number, number, number, number, number]\nconst identity: Matrix = [1, 0, 0, 1, 0, 0]\n\nconst multiply = (m: Matrix, n: Matrix): Matrix => [\n m[0] * n[0] + m[2] * n[1],\n m[1] * n[0] + m[3] * n[1],\n m[0] * n[2] + m[2] * n[3],\n m[1] * n[2] + m[3] * n[3],\n m[0] * n[4] + m[2] * n[5] + m[4],\n m[1] * n[4] + m[3] * n[5] + m[5],\n]\n\n/** Rounds away float noise in a whole turn, so a card at 360° still counts as unturned and draws pixel-perfect */\nconst snap = (m: Matrix): Matrix => m.map((v, i) => (i < 4 && Math.abs(v - Math.round(v)) < 1e-9 ? Math.round(v) : v)) as Matrix\n\n/** A blend as the canvas names it: CSS's other modes are the canvas's own words, and its normal is source-over */\nconst compositeFor = (blend: TableBoardBlend | undefined): GlobalCompositeOperation =>\n !blend || blend === \"normal\" ? \"source-over\" : blend\n\n/** Whether `live` is one of `owner`'s children, or theirs */\nconst isInside = (live: Live, owner: Live) => {\n for (let at = live.parent; at; at = at.parent) if (at === owner) return true\n return false\n}\n\n/** Puts an exiting node back after the node it followed, in the new drawing order */\nconst insertAfterPrevious = (order: Live[], oldOrder: Live[], index: number, live: Live) => {\n for (let i = index - 1; i >= 0; i--) {\n const at = order.indexOf(oldOrder[i])\n if (at >= 0) return void order.splice(at + 1, 0, live)\n }\n order.unshift(live)\n}\n\nconst easings = new Map<string, Ease>()\nconst easing = (value: string | undefined): Ease => {\n if (!value) return linear\n let ease = easings.get(value)\n if (!ease) easings.set(value, (ease = parseEasing(value)))\n return ease\n}\n\n// Colours\n\n/** Made on first use, as reducedMotion is */\nlet colorContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | undefined\nconst colors = new Map<string, RGB>()\n\n/** A CSS colour as RGB, read back through a canvas so every syntax the browser knows works */\nconst parseColor = (value: string): RGB => {\n let rgb = colors.get(value)\n if (rgb) return rgb\n // An offscreen canvas where there is one, as a worker has no document\n // getContext is called on each canvas type, as TS 5.x can't resolve the \"2d\" overload on the union\n colorContext ??=\n typeof OffscreenCanvas === \"undefined\"\n ? document.createElement(\"canvas\").getContext(\"2d\")!\n : new OffscreenCanvas(1, 1).getContext(\"2d\")!\n colorContext.fillStyle = \"#000\"\n colorContext.fillStyle = value\n const normal = String(colorContext.fillStyle)\n const hex = /^#([0-9a-f]{6})$/i.exec(normal)\n const parts = hex\n ? [0, 2, 4].map((i) => parseInt(hex[1].slice(i, i + 2), 16))\n : (/rgba?\\(([^)]+)\\)/.exec(normal)?.[1].split(\",\").slice(0, 3).map(Number) ?? [0, 0, 0])\n rgb = [parts[0], parts[1], parts[2]]\n colors.set(value, rgb)\n return rgb\n}\n\n/** Tinted copies of a sprite, by colour; a tint that's animating makes a copy per step, so the set is capped */\nconst tints = new WeakMap<ImageBitmap, Map<string, OffscreenCanvas>>()\nconst tintsPerSprite = 48\n\nconst tinted = (sprite: SpriteBitmap, rgb: RGB): OffscreenCanvas => {\n // Steps of 4 in each channel: a tint mid-animation reuses copies, and the eye can't tell\n const key = rgb.map((c) => Math.round(c / 4) * 4).join(\",\")\n let copies = tints.get(sprite.bitmap)\n if (!copies) tints.set(sprite.bitmap, (copies = new Map()))\n let copy = copies.get(key)\n if (copy) return copy\n if (copies.size >= tintsPerSprite) copies.clear()\n const { width, height } = sprite.bitmap\n copy = new OffscreenCanvas(width, height)\n const ctx = copy.getContext(\"2d\")!\n ctx.drawImage(sprite.bitmap, 0, 0)\n ctx.globalCompositeOperation = \"multiply\"\n ctx.fillStyle = `rgb(${key})`\n ctx.fillRect(0, 0, width, height)\n // Multiplying fills the transparent pixels too; the sprite's own alpha cuts them back out\n ctx.globalCompositeOperation = \"destination-in\"\n ctx.drawImage(sprite.bitmap, 0, 0)\n copies.set(key, copy)\n return copy\n}\n"],"mappings":"6FAOa,EAAe,GAA2C,CACrE,IAAM,EAAI,EAAM,MAAM,CACtB,GAAI,IAAM,SAAU,OAAO,EAC3B,IAAM,EAAU,EAAe,GAC/B,GAAI,EAAS,OAAO,EAAY,EAAQ,GAAI,EAAQ,GAAI,EAAQ,GAAI,EAAQ,GAAG,CAC/E,IAAM,EAAS,4BAA4B,KAAK,EAAE,CAClD,GAAI,EAAQ,CACV,IAAM,EAAI,EAAO,GAAG,MAAM,IAAI,CAAC,IAAI,OAAO,CAE1C,OADI,EAAE,SAAW,GAAK,EAAE,KAAM,GAAM,OAAO,MAAM,EAAE,CAAC,CAAS,EACtD,EAAY,EAAE,GAAI,EAAE,GAAI,EAAE,GAAI,EAAE,GAAG,CAE5C,IAAM,EAAM,sBAAsB,KAAK,EAAE,CAEzC,OADI,EAAY,EAAY,EAAI,GAAG,CAC5B,GAGT,IAAM,EAAU,GAAc,EAExB,EAAmE,CACvE,KAAM,CAAC,IAAM,GAAK,IAAM,EAAE,CAC1B,UAAW,CAAC,IAAM,EAAG,EAAG,EAAE,CAC1B,WAAY,CAAC,EAAG,EAAG,IAAM,EAAE,CAC3B,cAAe,CAAC,IAAM,EAAG,IAAM,EAAE,CAClC,CAEK,GAAe,EAAY,EAAY,EAAY,IAAe,CACtE,IAAM,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AAI,IAAK,GAAM,KAAK,MAAM,EAAI,EAAE,CAAG,EAAE,CAAC,KAAK,IAAI,CACvD,EAAS,EAAM,IAAI,EAAO,OAAO,CAChC,GAAQ,EAAM,IAAI,EAAO,OAAS,EAAS,IAAI,IAAO,CAC3D,IAAI,EAAO,EAAO,IAAI,EAAI,CAC1B,GAAI,EAAM,OAAO,EACb,EAAO,MAAQ,IAAgB,EAAO,OAAO,CACjD,GAAM,CAAE,QAAO,UAAW,EAAO,OACjC,EAAO,IAAI,gBAAgB,EAAO,EAAO,CACzC,IAAM,EAAM,EAAK,WAAW,KAAK,CASjC,OARA,EAAI,UAAU,EAAO,OAAQ,EAAG,EAAE,CAClC,EAAI,yBAA2B,WAC/B,EAAI,UAAY,OAAO,EAAI,GAC3B,EAAI,SAAS,EAAG,EAAG,EAAO,EAAO,CAEjC,EAAI,yBAA2B,iBAC/B,EAAI,UAAU,EAAO,OAAQ,EAAG,EAAE,CAClC,EAAO,IAAI,EAAK,EAAK,CACd"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./tableBoard-CLDBwRYs.cjs`);exports.TableBoard=e.t,exports.sceneLimits=e.r,exports.setTableBoardEnvironment=e.n,exports.spritesIn=e.i,exports.validateScene=e.a;
@@ -0,0 +1,138 @@
1
+ import type { TableBoardBackgroundStyle, TableBoardFidelity, TableBoardScene, TableBoardUpdate, Theme } from "./types";
2
+ export { sceneLimits, spritesIn, validateScene } from "./tableBoardScene";
3
+ /** A sprite's picture, at one resolution */
4
+ export type SpriteBitmap = {
5
+ bitmap: ImageBitmap;
6
+ /** In board units */
7
+ width: number;
8
+ height: number;
9
+ anchor: [number, number];
10
+ };
11
+ /** What a board draws from: Puzzmo's sandboxed pmmg bundle at the table, the game's own code in the simulator */
12
+ export type TableBoardRenderer = {
13
+ /** The board after an update, once every sprite it names is here to draw */
14
+ render(update: TableBoardUpdate): Promise<TableBoardScene>;
15
+ /** A sprite at a resolution, once a render has made it */
16
+ sprite(id: string, pixelsPerUnit: number): SpriteBitmap | undefined;
17
+ };
18
+ /** One frame as a board drew it, for a debugging overlay drawn over the top */
19
+ export type TableBoardFrame = {
20
+ /** The board's canvas, its transform reset, so the overlay draws in device pixels */
21
+ ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
22
+ /** Device pixels per board unit on the canvas */
23
+ scale: number;
24
+ scene: TableBoardScene;
25
+ /** Every node with a place this frame, in drawing order, children after their parents */
26
+ nodes: TableBoardDrawnNode[];
27
+ };
28
+ export type TableBoardDrawnNode = {
29
+ key: string;
30
+ /** The sprite it showed, keyframes applied; none for a node that only carries its children */
31
+ sprite?: string;
32
+ /** Where it sits in board units, its parents' places folded in, as a canvas transform */
33
+ matrix: [number, number, number, number, number, number];
34
+ alpha: number;
35
+ /** Gone from the scene and playing its exit */
36
+ exiting: boolean;
37
+ };
38
+ /** Where a board is shown, which the bundle can draw it for; the background is the theme's when it's left out */
39
+ export type TableBoardLook = {
40
+ fidelity: TableBoardFidelity;
41
+ backgroundStyle?: TableBoardBackgroundStyle;
42
+ };
43
+ type View = {
44
+ puzzle: string;
45
+ input: string;
46
+ };
47
+ export declare class TableBoard {
48
+ private canvas;
49
+ private renderer;
50
+ /** Steady for the board's life, for the renderer's caches */
51
+ private boardID;
52
+ /** Told when the board stops for good: frozen on its last scene if it had one (`drew`), else blank */
53
+ private onBroken;
54
+ private scene;
55
+ /** The resolution the scene's sprites were made at, and the one the canvas wants once its width settles */
56
+ private spritesPpu;
57
+ private wantedPpu;
58
+ private live;
59
+ private order;
60
+ /** When everything the last step started has finished, loops aside */
61
+ private until;
62
+ private looping;
63
+ private shown;
64
+ private waiting;
65
+ private skipped;
66
+ private rendering;
67
+ private failures;
68
+ private disposed;
69
+ /** The box the board fits inside, and the width it's drawn at there */
70
+ private boxWidth;
71
+ private boxHeight;
72
+ private cssWidth;
73
+ /** The canvas's width in device pixels, which sets the board's scale */
74
+ private pixelWidth;
75
+ private height;
76
+ private pendingHeight;
77
+ private needsFit;
78
+ private settleTimer;
79
+ private stepTimer;
80
+ private ctx;
81
+ private theme;
82
+ private look;
83
+ private layers;
84
+ dirty: boolean;
85
+ /** Called after every frame with where each node was drawn, for the simulator's debug overlay */
86
+ onDrawn?: (frame: TableBoardFrame) => void;
87
+ /** Called with the canvas's size on the page whenever it changes, for a canvas whose element is on another thread */
88
+ onFit?: (cssWidth: number, cssHeight: number) => void;
89
+ private fittedWidth;
90
+ private fittedHeight;
91
+ constructor(canvas: HTMLCanvasElement | OffscreenCanvas, renderer: TableBoardRenderer,
92
+ /** Steady for the board's life, for the renderer's caches */
93
+ boardID: string,
94
+ /** Told when the board stops for good: frozen on its last scene if it had one (`drew`), else blank */
95
+ onBroken: (error: unknown, drew: boolean) => void);
96
+ /** The newest view of the board; it shows once the step on screen has played out */
97
+ update(view: View): void;
98
+ /** A new theme makes new sprites, so the board is drawn again in it; nothing's drawn before the first */
99
+ setTheme(theme: Theme): void;
100
+ /** How much detail to draw and what's behind the board; a change draws it again, as a theme's does. Set it before the theme. */
101
+ setLook(look: TableBoardLook): void;
102
+ /**
103
+ * The box the board fits inside, as a thumbnail does: as wide as it can be without running past the bottom. A box
104
+ * with no height of its own is only a width. The fitted width sets the canvas's pixel size and, once it settles, the
105
+ * sprites' resolution
106
+ */
107
+ resize(boxWidth: number, boxHeight: number): void;
108
+ /** Draws the board again on the next frame, for an overlay that changed when nothing on the board did */
109
+ redraw(): void;
110
+ /** Stops for good, showing the last scene as it ends, so a broken renderer reads as a neighbour who's paused */
111
+ freeze(): void;
112
+ dispose(): void;
113
+ /** Starts the next render when the queue allows one */
114
+ private pump;
115
+ private stepStart;
116
+ private render;
117
+ /** Device pixels per board unit: the canvas's exactly, so sprites drawn at their own size are the board's size */
118
+ private ppuFor;
119
+ /** Matches the scene to what's on screen by key, and starts what moves; `now` of -Infinity shows it settled */
120
+ private show;
121
+ animating(now: number): boolean;
122
+ /** Draws the board as it is at `now`; true while something still moves */
123
+ draw(now: number): boolean;
124
+ /** A cleared layer the canvas's size for isolated nodes at `depth`, kept from frame to frame */
125
+ private layer;
126
+ private drawSprite;
127
+ /** The canvas's size on the page and in pixels, for its box and the board's shape */
128
+ private fit;
129
+ }
130
+ /** What a board needs to know of the screen it's shown on, which a worker can't read for itself */
131
+ export type TableBoardEnvironment = {
132
+ devicePixelRatio: number;
133
+ hidden: boolean;
134
+ reducedMotion: boolean;
135
+ };
136
+ /** Says what the page knows of the screen, where boards draw without a document; what's left out is read from the globals */
137
+ export declare const setTableBoardEnvironment: (next: Partial<TableBoardEnvironment>) => undefined;
138
+ //# sourceMappingURL=tableBoard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableBoard.d.ts","sources":["../src/tableBoard.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,yBAAyB,EAEzB,kBAAkB,EAGlB,eAAe,EACf,gBAAgB,EAChB,KAAK,EACN,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEzE,4CAA4C;AAC5C,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,WAAW,CAAA;IACnB,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACzB,CAAA;AAED,iHAAiH;AACjH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,4EAA4E;IAC5E,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IAC1D,0DAA0D;IAC1D,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAAA;CACpE,CAAA;AAED,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG;IAC5B,qFAAqF;IACrF,GAAG,EAAE,wBAAwB,GAAG,iC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AM,SAGL;IAED,gHAAgH;IAChH,MAAM,SAIL;IAED,OAAO,SAKN;IAED,uDAAuD;IACvD,OAAO,CAAC,IAAI;IAkBZ,OAAO,CAAC,SAAS,CAAI;YAEP,MAAM;IAuCpB,kHAAkH;IAClH,OAAO,CAAC,MAAM;IASd,+GAA+G;IAC/G,OAAO,CAAC,IAAI;IAoFZ,SAAS,CAAC,GAAG,EAAE,MAAM,WAEpB;IAED,0EAA0E;IAC1E,IAAI,CAAC,GAAG,EAAE,MAAM,WA8Cf;IAED,gGAAgG;IAChG,OAAO,CAAC,KAAK;IASb,OAAO,CAAC,UAAU;IAwClB,qFAAqF;IACrF,OAAO,CAAC,GAAG;CAwCZ;AAKD,mGAAmG;AACnG,MAAM,MAAM,qBAAqB,GAAG;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAA;AAIzG,6HAA6H;AAC7H,eAAO,MAAM,wBAAwB,SAAU,OAAO,CAAC,qBAAqB,CAAC,cAA0C,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { a as e, i as t, n, r, t as i } from "./tableBoard-B0I9wVQq.js";
2
+ export { i as TableBoard, r as sceneLimits, n as setTableBoardEnvironment, t as spritesIn, e as validateScene };
@@ -0,0 +1,21 @@
1
+ import type { TableBoardScene } from "./types";
2
+ /** The most of each thing one scene can hold */
3
+ export declare const sceneLimits: {
4
+ nodes: number;
5
+ effects: number;
6
+ keyframes: number;
7
+ /** The longest delay or duration, in ms */
8
+ ms: number;
9
+ /** The largest board, in board units */
10
+ size: number;
11
+ text: number;
12
+ /** How many nodes deep a node can sit, itself counted. Each isolated level draws on a layer the canvas's size */
13
+ depth: number;
14
+ /** The brightest a node draws, however its own, its keyframes' and its parents' brightness multiply */
15
+ brightness: number;
16
+ };
17
+ /** The scene with only what the host knows how to draw, or throws saying what's wrong with it */
18
+ export declare const validateScene: (input: unknown) => TableBoardScene;
19
+ /** Every sprite a scene names, in its nodes and in its keyframes */
20
+ export declare const spritesIn: (scene: TableBoardScene) => Set<string>;
21
+ //# sourceMappingURL=tableBoardScene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableBoardScene.d.ts","sources":["../src/tableBoardScene.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAMV,eAAe,EAEhB,MAAM,SAAS,CAAA;AAMhB,gDAAgD;AAChD,eAAO,MAAM,WAAW;IACtB,KAAK;IACL,OAAO;IACP,SAAS;IACT,2CAA2C;IAC3C,EAAE;IACF,wCAAwC;IACxC,IAAI;IACJ,IAAI;IACJ,iHAAiH;IACjH,KAAK;IACL,uGAAuG;IACvG,UAAU;CACX,CAAA;AAED,iGAAiG;AACjG,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,eAqC9C,CAAA;AAED,oEAAoE;AACpE,eAAO,MAAM,SAAS,UAAW,eAAe,KAAG,GAAG,CAAC,MAAM,CAU5D,CAAA"}
package/dist/themes.d.ts CHANGED
@@ -5,22 +5,6 @@ export declare const defaultLightTheme: Theme;
5
5
  export declare const defaultDarkTheme: Theme;
6
6
  export declare const newsPaperLightTheme: Theme;
7
7
  export declare const modifiedNewsPaperTheme: (type: "light" | "dark", hexes: string[] | readonly string[], partnerSlug: string) => {
8
- name: string;
9
- a_puzmo: string;
10
- key: string;
11
- keyLight: string;
12
- keyStrong: string;
13
- alt1: string;
14
- alt2: string;
15
- alt3: string;
16
- keyFG: string;
17
- player: string;
18
- playerLight: string;
19
- playerFG: string;
20
- subBrand: string;
21
- subBrandFG: string;
22
- g_key: string;
23
- a_infoBG: string;
24
8
  type: "light" | "dark";
25
9
  fg: string;
26
10
  error: string;
@@ -41,6 +25,22 @@ export declare const modifiedNewsPaperTheme: (type: "light" | "dark", hexes: str
41
25
  a_tableAlt: string;
42
26
  a_inlineTag: string;
43
27
  a_anchor: string;
28
+ name: string;
29
+ a_puzmo: string;
30
+ key: string;
31
+ keyLight: string;
32
+ keyStrong: string;
33
+ alt1: string;
34
+ alt2: string;
35
+ alt3: string;
36
+ keyFG: string;
37
+ player: string;
38
+ playerLight: string;
39
+ playerFG: string;
40
+ subBrand: string;
41
+ subBrandFG: string;
42
+ g_key: string;
43
+ a_infoBG: string;
44
44
  };
45
45
  export type PuzmoTheme = typeof lightTheme;
46
46
  //# sourceMappingURL=themes.d.ts.map