@weasel-js/forge 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -1
- package/dist/{FrameController-BRhShqut.d.ts → FrameController-CdnaIo4C.d.ts} +18 -10
- package/dist/{chunk-7BQPHMA2.js → chunk-3BAM6M26.js} +2 -2
- package/dist/chunk-3BAM6M26.js.map +1 -0
- package/dist/{chunk-ZAWXMUGZ.js → chunk-5WS67HMU.js} +8 -3
- package/dist/chunk-5WS67HMU.js.map +1 -0
- package/dist/{chunk-R5F44ECM.js → chunk-ATI7FYJ7.js} +18 -14
- package/dist/chunk-ATI7FYJ7.js.map +1 -0
- package/dist/{chunk-2OJAV522.js → chunk-GH5RE5X5.js} +2 -2
- package/dist/chunk-GH5RE5X5.js.map +1 -0
- package/dist/{chunk-SQ4KCIEH.js → chunk-KEQBGDUZ.js} +3 -3
- package/dist/{chunk-SQ4KCIEH.js.map → chunk-KEQBGDUZ.js.map} +1 -1
- package/dist/{chunk-DPTECNYC.js → chunk-LTTEILXY.js} +3 -3
- package/dist/{chunk-DPTECNYC.js.map → chunk-LTTEILXY.js.map} +1 -1
- package/dist/chunk-ORMMZ5PV.js +59 -0
- package/dist/chunk-ORMMZ5PV.js.map +1 -0
- package/dist/{chunk-NVNTQ4AT.js → chunk-WMGEO5M6.js} +133 -9
- package/dist/chunk-WMGEO5M6.js.map +1 -0
- package/dist/chunk-YDLRSEUN.js +501 -0
- package/dist/chunk-YDLRSEUN.js.map +1 -0
- package/dist/{config-BwScQukB.d.ts → config-Mg05Ja9r.d.ts} +20 -3
- package/dist/csf/preview-api.js +2 -2
- package/dist/frame/index.css +12 -0
- package/dist/frame/index.css.map +1 -1
- package/dist/frame/index.d.ts +62 -29
- package/dist/frame/index.js +142 -15
- package/dist/frame/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/mountFrame-Ds3QLnBF.d.ts +35 -0
- package/dist/shell/index.css +131 -6
- package/dist/shell/index.css.map +1 -1
- package/dist/shell/index.d.ts +44 -16
- package/dist/shell/index.js +1663 -280
- package/dist/shell/index.js.map +1 -1
- package/dist/test/index.css +58 -0
- package/dist/test/index.css.map +1 -0
- package/dist/test/index.d.ts +2 -4
- package/dist/test/index.js +11 -13
- package/dist/test/index.js.map +1 -1
- package/dist/vite/index.js +515 -111
- package/dist/vite/index.js.map +1 -1
- package/package.json +13 -8
- package/dist/chunk-2OJAV522.js.map +0 -1
- package/dist/chunk-5DXUNLV2.js +0 -6
- package/dist/chunk-5DXUNLV2.js.map +0 -1
- package/dist/chunk-7BQPHMA2.js.map +0 -1
- package/dist/chunk-J3GYSNCK.js +0 -285
- package/dist/chunk-J3GYSNCK.js.map +0 -1
- package/dist/chunk-NVNTQ4AT.js.map +0 -1
- package/dist/chunk-R5F44ECM.js.map +0 -1
- package/dist/chunk-ZAWXMUGZ.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/forge",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "A component workshop on labkit: stories in isolated frames, controls and state in lab trials.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -69,11 +69,12 @@
|
|
|
69
69
|
"@testing-library/dom": "^10.4.0",
|
|
70
70
|
"@testing-library/user-event": "^14.6.1",
|
|
71
71
|
"@vitest/expect": "^5.0.2",
|
|
72
|
-
"@weasel-js/icons": "1.
|
|
73
|
-
"@weasel-js/prefs": "1.
|
|
74
|
-
"@weasel-js/registry": "1.
|
|
75
|
-
"@weasel-js/
|
|
76
|
-
"@weasel-js/
|
|
72
|
+
"@weasel-js/icons": "1.12.0",
|
|
73
|
+
"@weasel-js/prefs": "1.12.0",
|
|
74
|
+
"@weasel-js/registry": "1.12.0",
|
|
75
|
+
"@weasel-js/svg": "1.12.0",
|
|
76
|
+
"@weasel-js/theme": "1.12.0",
|
|
77
|
+
"@weasel-js/ui": "1.12.0",
|
|
77
78
|
"axe-core": "^4.13.0",
|
|
78
79
|
"chai": "^6.2.2"
|
|
79
80
|
},
|
|
@@ -81,15 +82,19 @@
|
|
|
81
82
|
"@babel/types": "^8.0.6"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"@weasel-js/core": "1.
|
|
85
|
-
"@weasel-js/labkit": "1.
|
|
85
|
+
"@weasel-js/core": "1.12.0",
|
|
86
|
+
"@weasel-js/labkit": "1.12.0",
|
|
86
87
|
"react": "^19.0.0",
|
|
88
|
+
"playwright": "^1.50.0",
|
|
87
89
|
"react-dom": "^19.0.0",
|
|
88
90
|
"typescript": ">=5.0.0",
|
|
89
91
|
"vite": "^8.0.0",
|
|
90
92
|
"vitest": "^4.0.0 || ^5.0.0"
|
|
91
93
|
},
|
|
92
94
|
"peerDependenciesMeta": {
|
|
95
|
+
"playwright": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
93
98
|
"typescript": {
|
|
94
99
|
"optional": true
|
|
95
100
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocol/messages.ts"],"names":[],"mappings":";;;AAEO,IAAM,gBAAA,GAAmB;AA2FzB,IAAM,YAAA,GAAe;AASrB,IAAM,WAAA,GAAc","file":"chunk-2OJAV522.js","sourcesContent":["import type { SchemaDescription } from './schema.ts';\n\nexport const PROTOCOL_VERSION = 1;\n\n/** The workshop's toolbar globals as a story reads them, by name. */\nexport type Globals = Readonly<Record<string, unknown>>;\n/** How a story sits in its frame. */\nexport type Layout = 'centered' | 'padded' | 'fullscreen';\n/** A frame size a story asks for, in CSS pixels. */\nexport interface Viewport {\n width: number;\n height: number;\n}\n/** Where a frame's fault happened: loading the story, rendering it, or reading a message. */\nexport type FaultPhase = 'import' | 'render' | 'protocol';\n\n/** One custom property as the frame found it. */\nexport interface CssVarReport {\n name: string;\n value: string;\n /** Whether a `vars.set` override is in force on it. */\n overridden: boolean;\n /** Whether the story reads it, directly or through another property it reads. */\n used: boolean;\n}\n\n/** Visibility and validation answers, keyed by the config they were computed for. */\nexport interface ConfigAnswers {\n /** `stableStringify(config)` of the config the frame evaluated. */\n configKey: string;\n hidden: string[];\n errors: Record<string, string[]>;\n}\n\n/** One element axe faulted on, inside the frame's own document. */\nexport interface A11yNode {\n /** The CSS selectors, outermost first, that reach the element in the frame. */\n target: readonly string[];\n html: string;\n failureSummary?: string;\n}\n\n/** One axe rule's outcome on the story, with the elements it names. */\nexport interface A11yFinding {\n id: string;\n impact: 'minor' | 'moderate' | 'serious' | 'critical' | null;\n help: string;\n helpUrl: string;\n description: string;\n nodes: readonly A11yNode[];\n}\n\n/** What axe found on one story: the rules it failed, and the ones it could not decide. */\nexport interface A11yReport {\n violations: readonly A11yFinding[];\n incomplete: readonly A11yFinding[];\n /** Rules that passed, and rules no element on the page could be judged by. */\n passes: number;\n inapplicable: number;\n}\n\n/** A message the workshop sends a story's frame. */\nexport type ToFrame =\n | { type: 'init'; config: unknown; state: unknown; globals: Globals }\n | { type: 'config'; config: unknown }\n | { type: 'state'; state: unknown }\n | { type: 'globals'; globals: Globals }\n | { type: 'vars.set'; name: string; value: string | null }\n /** Run axe over the story's own subtree. Answered by `a11y` carrying the same `id`. */\n | { type: 'a11y.run'; id: string };\n\n/** A message a story's frame sends the workshop. */\nexport type FromFrame =\n | { type: 'ready'; schema: SchemaDescription; layout: Layout; viewport: Viewport | null }\n /** Sent once, when the story's first render after `init` has committed. */\n | { type: 'rendered' }\n | { type: 'answers'; answers: ConfigAnswers }\n | { type: 'setConfig'; path: string; value: unknown }\n | { type: 'setState'; state: unknown }\n | { type: 'vars'; vars: CssVarReport[] }\n /** Asks the shell to show story `id` in this frame's trial in place of what it shows now. */\n | { type: 'open'; id: string }\n | { type: 'a11y'; id: string; ok: true; report: A11yReport }\n | { type: 'a11y'; id: string; ok: false; message: string }\n /** `seq`, on a render fault only: how many `init`/`config`/`state`/`globals` messages the frame had received. */\n | { type: 'fault'; phase: FaultPhase; message: string; stack?: string; seq?: number };\n\nexport interface Envelope<M> {\n v: number;\n msg: M;\n}\n\n/** Posted on the frame's window with the port transferred alongside it, as a `PortHandoff`. */\nexport const PORT_HANDOFF = 'weaselforge:port';\n\n/** What the shell posts with the port: `id` names what the frame shows, a story or an index. */\nexport interface PortHandoff {\n type: typeof PORT_HANDOFF;\n id: string;\n}\n\n/** Posted by a frame document to its parent as soon as its entry runs, asking for a port. */\nexport const FRAME_HELLO = 'weaselforge:hello';\n\nexport { stableStringify } from '@weasel-js/core';\n"]}
|
package/dist/chunk-5DXUNLV2.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/title.ts"],"names":[],"mappings":";AACO,IAAM,aAAA,GAAgB","file":"chunk-5DXUNLV2.js","sourcesContent":["/** The workshop's name when the shell config gives none: in its header, and as the document title. */\nexport const DEFAULT_TITLE = 'weaselforge';\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shell/globals.ts"],"names":["from"],"mappings":";;;;AAqCO,IAAM,WAAA,GAAc;AAEpB,IAAM,UAAA,GAAa,KAAA;AAEnB,IAAM,UAAA,GAAa;AAE1B,IAAM,UAAA,GAAa,EAAE,KAAA,EAAO,UAAA,EAAY,OAAO,KAAA,EAAM;AAErD,IAAM,QAAA,GAAW,aAAA;AAEV,IAAM,aAAA,GAAgB,CAAC,IAAA,KAA0B,IAAA,KAAS,eAAe,IAAA,CAAK,UAAA,CAAW,CAAA,EAAG,WAAW,CAAA,CAAA,CAAG;AAG1G,IAAM,YAAA,GAAe;AAG5B,IAAM,6BAAkC,IAAI,GAAA,CAAI,CAAC,WAAA,EAAa,YAAY,CAAC,CAAA;AAGpE,IAAM,WAAA,GAAc,CAAC,IAAA,KAA0B,UAAA,CAAW,GAAA,CAAI,KAAK,KAAA,CAAM,GAAG,CAAA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GAAG,OAAO,QAAA;AAAA,EAC/G;AACA,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,WAAA,CAAY,QAA+B,YAAA,EAAyD;AAClH,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,OAAA,CAAQ,YAAY,CAAA;AAC3C,EAAA,IAAI,OAAA,CAAQ,MAAA,KAAW,CAAA,EAAG,OAAO,MAAA;AACjC,EAAA,MAAM,SAAS,MAAA,CAAO,WAAA;AAAA,IACpB,QAAQ,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,WAAW,CAAA,KAAM;AAAA,MAClC,GAAA;AAAA,MACA,EAAE,IAAA,CAAK,UAAA,EAAY,CAAC,EAAE,OAAO,UAAA,EAAY,KAAA,EAAO,KAAA,EAAM,EAAG,GAAG,WAAA,CAAY,OAAO,CAAC,CAAA,CAAE,KAAA,CAAM,YAAY,KAAK;AAAA,KAC1G;AAAA,GACH;AAEA,EAAA,MAAM,QAAQ,CAAA,CAAE,KAAA,CAAM,MAAM,CAAA,CAAE,MAAM,EAAE,CAAA,CAAE,OAAA,CAAQ,SAAA,EAAW,EAAE,MAAA,EAAQ,QAAA,EAAU,MAAM,OAAA,EAAS,SAAA,EAAW,mBAAmB,CAAA;AAC5H,EAAA,OAAO,CAAA,CAAE,MAAA,CAAO,EAAE,GAAG,MAAA,CAAO,OAAO,CAAC,WAAW,GAAG,KAAA,EAAO,CAAA;AAC3D","file":"chunk-7BQPHMA2.js","sourcesContent":["import { isPlainObject } from '@weasel-js/core';\nimport type { IconRef } from '@weasel-js/icons';\nimport type { LabMode } from '@weasel-js/labkit';\nimport { type ConfigSchema, f } from '@weasel-js/labkit/config';\nimport type { Globals } from '../protocol/messages';\n\n/** One global the workshop's toolbar sets for every story, and a trial may pin for its own. */\nexport interface GlobalDeclaration {\n label: string;\n options: readonly { value: string; label: string }[];\n default: string;\n /** Another global's key: the toolbar shows this one in a popover beside that one rather than in the bar itself. */\n under?: string;\n /** The glyph on the button opening the globals declared `under` this one. Default `core:tune`. */\n icon?: IconRef;\n /**\n * Whether the toolbar offers `value` given the lab's other values; every option shows when absent. `globals` is\n * resolved without any declaration's `shows`, so one `shows` cannot depend on another's outcome.\n */\n shows?: (value: string, globals: Globals) => boolean;\n /**\n * What this global reads from the lab's own chrome. Given, the lab's value may be `App` (`FOLLOW_APP`), offered\n * first, and while it is the global follows that chrome control, as the header's mode switch sets it. A trial's\n * pin follows the lab or names a value; it cannot follow the app on its own.\n */\n follows?: (chrome: LabChrome) => string;\n}\n\n/** The lab chrome's own settings a global can follow. */\nexport interface LabChrome {\n mode: LabMode;\n}\n\n/** The shell config's `globals`: each declaration by the key stories read it under. */\nexport type GlobalDeclarations = Readonly<Record<string, GlobalDeclaration>>;\n\n/** The config group every story schema gains, holding the trial's pins. A story never sees it. */\nexport const GLOBALS_KEY = '$globals';\n/** A pin's value when the trial follows the lab. */\nexport const FOLLOW_LAB = 'lab';\n/** A lab value, for a declaration that `follows` the app, meaning whatever the app's chrome is set to. */\nexport const FOLLOW_APP = 'app';\n\nconst APP_OPTION = { value: FOLLOW_APP, label: 'App' } as const;\n\nconst isRecord = isPlainObject;\n\nexport const isGlobalsPath = (path: string): boolean => path === GLOBALS_KEY || path.startsWith(`${GLOBALS_KEY}.`);\n\n/** The config key a timeline story's paused playhead is kept under, so labkit persists and snapshots it. */\nexport const PLAYHEAD_KEY = '$playhead';\n\n/** Config keys forge owns: a story neither sees nor writes them. */\nconst FORGE_KEYS: ReadonlySet<string> = new Set([GLOBALS_KEY, PLAYHEAD_KEY]);\n\n/** Whether a config path lies under a key forge owns. */\nexport const isForgePath = (path: string): boolean => FORGE_KEYS.has(path.split('.')[0]!);\n\n/** The options the toolbar offers for `declaration` at `globals`. */\nexport function shownOptions(declaration: GlobalDeclaration, globals: Globals): GlobalDeclaration['options'] {\n const { shows } = declaration;\n return shows ? declaration.options.filter((option) => shows(option.value, globals)) : declaration.options;\n}\n\n/** The options the lab's own control offers: `shownOptions`, after `App` where the declaration follows the app. */\nexport function labOptions(declaration: GlobalDeclaration, globals: Globals): GlobalDeclaration['options'] {\n const shown = shownOptions(declaration, globals);\n return declaration.follows ? [APP_OPTION, ...shown] : shown;\n}\n\n/** `values` with each `App` replaced by what its declaration reads from `chrome`; `values` itself when none is. */\nexport function followApp(declarations: GlobalDeclarations, values: Globals, chrome: LabChrome): Globals {\n const followed = Object.entries(declarations).flatMap(([key, { follows }]) =>\n follows && values[key] === FOLLOW_APP ? [[key, follows(chrome)] as const] : [],\n );\n return followed.length === 0 ? values : { ...values, ...Object.fromEntries(followed) };\n}\n\n/**\n * The lab's values from what was stored: declared keys only. A value no option offers falls back to the default, and\n * one its declaration's `shows` hides falls back to the shown option nearest it in `options`, the earlier on a tie.\n */\nexport function labGlobals(declarations: GlobalDeclarations, stored: unknown): Globals {\n const from = isRecord(stored) ? stored : {};\n const offered: Globals = Object.fromEntries(\n Object.entries(declarations).map(([key, declaration]) => {\n const value = from[key];\n const known =\n declaration.options.some((option) => option.value === value) || (declaration.follows && value === FOLLOW_APP);\n return [key, known ? value : declaration.default];\n }),\n );\n return Object.fromEntries(\n Object.entries(declarations).map(([key, declaration]) => {\n const shown = shownOptions(declaration, offered);\n const value = offered[key];\n if (value === FOLLOW_APP && declaration.follows) return [key, value];\n if (!declaration.shows || shown.length === 0 || shown.some((option) => option.value === value)) return [key, value];\n const at = (v: unknown) => declaration.options.findIndex((option) => option.value === v);\n const from = at(value);\n const nearest = shown.reduce((best, option) =>\n Math.abs(at(option.value) - from) < Math.abs(at(best.value) - from) ? option : best,\n );\n return [key, nearest.value];\n }),\n );\n}\n\n/** The lab's values, overridden by the pins in a trial's config that do not follow the lab. */\nexport function effectiveGlobals(lab: Globals, pins: unknown): Globals {\n if (!isRecord(pins)) return lab;\n const pinned = Object.entries(pins).filter(([key, value]) => key in lab && value !== FOLLOW_LAB);\n return pinned.length === 0 ? lab : { ...lab, ...Object.fromEntries(pinned) };\n}\n\n/**\n * The config a story receives: the trial's, without the keys forge owns. Returns `previous` when every other entry is\n * the same, so a change to a pin or the playhead alone is not a change to the story's config.\n */\nexport function storyConfig(config: unknown, previous?: unknown): unknown {\n if (!isRecord(config) || !Object.keys(config).some((key) => FORGE_KEYS.has(key))) return config;\n const rest = Object.fromEntries(Object.entries(config).filter(([key]) => !FORGE_KEYS.has(key)));\n if (isRecord(previous)) {\n const keys = Object.keys(rest);\n if (keys.length === Object.keys(previous).length && keys.every((key) => rest[key] === previous[key])) return previous;\n }\n return rest;\n}\n\n/** `schema` with a `$globals` group appended: one leaf per declaration, following the lab until pinned. */\nexport function withGlobals(schema: ConfigSchema<unknown>, declarations: GlobalDeclarations): ConfigSchema<unknown> {\n const entries = Object.entries(declarations);\n if (entries.length === 0) return schema;\n const leaves = Object.fromEntries(\n entries.map(([key, declaration]) => [\n key,\n f.enum(FOLLOW_LAB, [{ value: FOLLOW_LAB, label: 'Lab' }, ...declaration.options]).label(declaration.label),\n ]),\n );\n // An empty group name contributes rows without a heading of its own, under the section's.\n const group = f.group(leaves).label('').section('Globals', { layout: 'inline', pack: 'pairs', className: 'fg-globals-pins' });\n return f.schema({ ...schema.nodes, [GLOBALS_KEY]: group }) as ConfigSchema<unknown>;\n}\n"]}
|
package/dist/chunk-J3GYSNCK.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import { GLOBALS_KEY, effectiveGlobals, storyConfig, isForgePath, PLAYHEAD_KEY } from './chunk-7BQPHMA2.js';
|
|
2
|
-
import { StoryHost, useNearViewport, IN_VIEW_MARGIN, createOverrides, createGlobalsTarget, useStoryClock, useClockLoop, scanCssVars, runAxe } from './chunk-NVNTQ4AT.js';
|
|
3
|
-
import { ClockContext } from './chunk-L5XM5VKB.js';
|
|
4
|
-
import { createEmitter } from '@weasel-js/registry';
|
|
5
|
-
import { createContext, memo, useContext, useCallback, useSyncExternalStore, useMemo, useId, useState, useRef, useLayoutEffect, useEffect } from 'react';
|
|
6
|
-
import { useLatest } from '@weasel-js/core';
|
|
7
|
-
import { usePersistedState, TrialIdContext, LabBoundary } from '@weasel-js/labkit';
|
|
8
|
-
import { OverlayPortalProvider } from '@weasel-js/ui';
|
|
9
|
-
import { jsx } from 'react/jsx-runtime';
|
|
10
|
-
|
|
11
|
-
var NO_FRAME = { send: null, vars: [], audit: null, a11y: null };
|
|
12
|
-
function createTrialFrames() {
|
|
13
|
-
const frames = /* @__PURE__ */ new Map();
|
|
14
|
-
const changes = createEmitter();
|
|
15
|
-
const changed = changes.emit;
|
|
16
|
-
const patch = (trialId, next) => {
|
|
17
|
-
const frame = frames.get(trialId);
|
|
18
|
-
if (!frame) return;
|
|
19
|
-
frames.set(trialId, { ...frame, ...next });
|
|
20
|
-
changed();
|
|
21
|
-
};
|
|
22
|
-
return {
|
|
23
|
-
connect(trialId, calls) {
|
|
24
|
-
frames.set(trialId, { send: calls.send, vars: [], audit: calls.audit, a11y: null });
|
|
25
|
-
changed();
|
|
26
|
-
return () => {
|
|
27
|
-
if (frames.get(trialId)?.send !== calls.send) return;
|
|
28
|
-
frames.delete(trialId);
|
|
29
|
-
changed();
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
report: (trialId, vars) => patch(trialId, { vars }),
|
|
33
|
-
reportA11y: (trialId, a11y) => patch(trialId, { a11y }),
|
|
34
|
-
get: (trialId) => frames.get(trialId) ?? NO_FRAME,
|
|
35
|
-
subscribe: changes.subscribe
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
var TrialFramesContext = createContext(null);
|
|
39
|
-
function useTrialFrame(trialId) {
|
|
40
|
-
const frames = useContext(TrialFramesContext);
|
|
41
|
-
const subscribe = useCallback((listener) => frames?.subscribe(listener) ?? (() => {
|
|
42
|
-
}), [frames]);
|
|
43
|
-
const read = () => frames?.get(trialId) ?? NO_FRAME;
|
|
44
|
-
return useSyncExternalStore(subscribe, read, read);
|
|
45
|
-
}
|
|
46
|
-
var StoryGlobalsContext = createContext({});
|
|
47
|
-
var NONE = {};
|
|
48
|
-
function useCssOverrides() {
|
|
49
|
-
return usePersistedState("fg-css-overrides", NONE, { scope: "trial" });
|
|
50
|
-
}
|
|
51
|
-
var VARS_SETTLE_MS = 100;
|
|
52
|
-
var scopeOf = (id) => `[data-fg-host="${id}"]`;
|
|
53
|
-
function TrialHost({ layout, setup, config, children, hostRef, onRendered }) {
|
|
54
|
-
const trialId = useContext(TrialIdContext);
|
|
55
|
-
const frames = useContext(TrialFramesContext);
|
|
56
|
-
const labGlobals = useContext(StoryGlobalsContext);
|
|
57
|
-
const pins = config?.[GLOBALS_KEY];
|
|
58
|
-
const globals = useMemo(() => effectiveGlobals(labGlobals, pins), [labGlobals, pins]);
|
|
59
|
-
const [persisted] = useCssOverrides();
|
|
60
|
-
const reactId = useId();
|
|
61
|
-
const hostId = trialId ?? reactId;
|
|
62
|
-
const [host, setHost] = useState(null);
|
|
63
|
-
const elementRef = useRef(null);
|
|
64
|
-
const inView = useNearViewport(elementRef, IN_VIEW_MARGIN);
|
|
65
|
-
const [pending, setPending] = useState(true);
|
|
66
|
-
const overridesRef = useRef(null);
|
|
67
|
-
const latest = useLatest({ setup, onRendered });
|
|
68
|
-
useLayoutEffect(() => {
|
|
69
|
-
if (!host) return;
|
|
70
|
-
const doc = host.ownerDocument;
|
|
71
|
-
const scope = scopeOf(hostId);
|
|
72
|
-
const { cssVarsScope } = latest.current.setup;
|
|
73
|
-
const overrides = createOverrides(doc, cssVarsScope ? `${scope}, ${scope} :is(${cssVarsScope})` : scope);
|
|
74
|
-
overridesRef.current = overrides;
|
|
75
|
-
let lastVars = null;
|
|
76
|
-
let reported = null;
|
|
77
|
-
const publish = (vars) => {
|
|
78
|
-
lastVars = vars;
|
|
79
|
-
const key = JSON.stringify(vars);
|
|
80
|
-
if (key === reported) return;
|
|
81
|
-
reported = key;
|
|
82
|
-
if (trialId) frames?.report(trialId, vars);
|
|
83
|
-
};
|
|
84
|
-
const scan = () => publish(scanCssVars(doc, overrides.has, host));
|
|
85
|
-
let settleTimer;
|
|
86
|
-
const ownMutation = (record) => overrides.owns(record.target) || record.type === "childList" && [...record.addedNodes, ...record.removedNodes].length > 0 && [...record.addedNodes, ...record.removedNodes].every(overrides.owns);
|
|
87
|
-
const mutations = typeof MutationObserver === "undefined" ? null : new MutationObserver((records) => {
|
|
88
|
-
if (records.every(ownMutation)) return;
|
|
89
|
-
clearTimeout(settleTimer);
|
|
90
|
-
settleTimer = setTimeout(scan, VARS_SETTLE_MS);
|
|
91
|
-
});
|
|
92
|
-
mutations?.observe(host, { subtree: true, childList: true, characterData: true, attributes: true });
|
|
93
|
-
const send = (msg) => {
|
|
94
|
-
if (msg.type !== "vars.set") return;
|
|
95
|
-
overrides.set(msg.name, msg.value);
|
|
96
|
-
if (lastVars?.some((v) => v.name === msg.name)) scan();
|
|
97
|
-
};
|
|
98
|
-
const audit = async () => {
|
|
99
|
-
let outcome;
|
|
100
|
-
try {
|
|
101
|
-
outcome = { ok: true, report: await runAxe(host, { page: false }) };
|
|
102
|
-
} catch (error) {
|
|
103
|
-
outcome = { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
104
|
-
}
|
|
105
|
-
if (trialId) frames?.reportA11y(trialId, outcome);
|
|
106
|
-
return outcome;
|
|
107
|
-
};
|
|
108
|
-
const disconnect = frames && trialId ? frames.connect(trialId, { send, audit }) : () => {
|
|
109
|
-
};
|
|
110
|
-
return () => {
|
|
111
|
-
disconnect();
|
|
112
|
-
mutations?.disconnect();
|
|
113
|
-
clearTimeout(settleTimer);
|
|
114
|
-
overrides.dispose();
|
|
115
|
-
overridesRef.current = null;
|
|
116
|
-
};
|
|
117
|
-
}, [host, hostId, trialId, frames, latest]);
|
|
118
|
-
const applied = useRef({});
|
|
119
|
-
useLayoutEffect(() => {
|
|
120
|
-
const overrides = overridesRef.current;
|
|
121
|
-
if (!overrides) return;
|
|
122
|
-
for (const name of Object.keys(applied.current)) if (!(name in persisted)) overrides.set(name, null);
|
|
123
|
-
for (const [name, value] of Object.entries(persisted)) overrides.set(name, value);
|
|
124
|
-
applied.current = { ...persisted };
|
|
125
|
-
}, [host, persisted]);
|
|
126
|
-
useLayoutEffect(() => {
|
|
127
|
-
if (!host) return;
|
|
128
|
-
const target = createGlobalsTarget(host, scopeOf(hostId));
|
|
129
|
-
latest.current.setup.applyGlobals?.(globals, target);
|
|
130
|
-
return () => target.dispose();
|
|
131
|
-
}, [host, hostId, globals, latest]);
|
|
132
|
-
const announced = useRef(false);
|
|
133
|
-
useEffect(() => {
|
|
134
|
-
if (!host || !inView || announced.current) return;
|
|
135
|
-
let canceled = false;
|
|
136
|
-
const done = () => {
|
|
137
|
-
if (canceled) return;
|
|
138
|
-
announced.current = true;
|
|
139
|
-
setPending(false);
|
|
140
|
-
latest.current.onRendered?.();
|
|
141
|
-
};
|
|
142
|
-
const { fonts } = host.ownerDocument;
|
|
143
|
-
if (!fonts) {
|
|
144
|
-
done();
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
const afterPaint = () => requestAnimationFrame(done);
|
|
148
|
-
void fonts.ready.then(afterPaint, afterPaint);
|
|
149
|
-
return () => {
|
|
150
|
-
canceled = true;
|
|
151
|
-
};
|
|
152
|
-
}, [host, inView, latest]);
|
|
153
|
-
return /* @__PURE__ */ jsx(
|
|
154
|
-
"div",
|
|
155
|
-
{
|
|
156
|
-
ref: (el) => {
|
|
157
|
-
elementRef.current = el;
|
|
158
|
-
if (hostRef) hostRef.current = el;
|
|
159
|
-
setHost(el);
|
|
160
|
-
},
|
|
161
|
-
className: "fg-story",
|
|
162
|
-
"data-fg-host": hostId,
|
|
163
|
-
"data-fg-layout": layout,
|
|
164
|
-
"data-pending": pending || void 0,
|
|
165
|
-
children: host && inView ? (
|
|
166
|
-
// The workshop is itself a lab; below the boundary a story sees no lab, trial or theme above it, as in a
|
|
167
|
-
// document of its own.
|
|
168
|
-
/* @__PURE__ */ jsx(LabBoundary, { children: /* @__PURE__ */ jsx(OverlayPortalProvider, { container: host, children: children(globals) }) })
|
|
169
|
-
) : null
|
|
170
|
-
}
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
function createTrialClocks() {
|
|
174
|
-
const clocks = /* @__PURE__ */ new Map();
|
|
175
|
-
const changed = createEmitter();
|
|
176
|
-
const notify = changed.emit;
|
|
177
|
-
return {
|
|
178
|
-
publish(trialId, clock) {
|
|
179
|
-
clocks.set(trialId, clock);
|
|
180
|
-
notify();
|
|
181
|
-
return () => {
|
|
182
|
-
if (clocks.get(trialId) !== clock) return;
|
|
183
|
-
clocks.delete(trialId);
|
|
184
|
-
notify();
|
|
185
|
-
};
|
|
186
|
-
},
|
|
187
|
-
get: (trialId) => clocks.get(trialId) ?? null,
|
|
188
|
-
subscribe: changed.subscribe
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
var TrialClocksContext = createContext(null);
|
|
192
|
-
var NEVER = () => () => {
|
|
193
|
-
};
|
|
194
|
-
var NONE2 = () => null;
|
|
195
|
-
function useTrialClock(trialId) {
|
|
196
|
-
const clocks = useContext(TrialClocksContext);
|
|
197
|
-
return useSyncExternalStore(clocks?.subscribe ?? NEVER, clocks ? () => clocks.get(trialId) : NONE2);
|
|
198
|
-
}
|
|
199
|
-
function usePersistedPlayhead(clock, persisted, write) {
|
|
200
|
-
const written = useRef(persisted);
|
|
201
|
-
const latestWrite = useLatest(write);
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (!clock || persisted === written.current) return;
|
|
204
|
-
written.current = persisted;
|
|
205
|
-
clock.request(persisted);
|
|
206
|
-
}, [clock, persisted]);
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
if (!clock) return;
|
|
209
|
-
return clock.subscribe(() => {
|
|
210
|
-
const { playing, time } = clock.get();
|
|
211
|
-
if (playing || clock.pending() !== null || time === written.current) return;
|
|
212
|
-
written.current = time;
|
|
213
|
-
latestWrite.current(time);
|
|
214
|
-
});
|
|
215
|
-
}, [clock, latestWrite]);
|
|
216
|
-
}
|
|
217
|
-
var NO_DECORATORS = [];
|
|
218
|
-
var StoryBody = memo(function StoryBody2({ story, config, setConfig, state, setState, globals, decorators, resetKey, onError }) {
|
|
219
|
-
const storyCtx = { config, setConfig, state, setState, globals, title: story.title, name: story.name };
|
|
220
|
-
return /* @__PURE__ */ jsx(StoryHost, { story, ctx: storyCtx, decorators, resetKey, onError });
|
|
221
|
-
});
|
|
222
|
-
function StoryTrial({ story, setup, ctx, hostRef, onRendered, onError }) {
|
|
223
|
-
const latestRef = useLatest(ctx);
|
|
224
|
-
const [heldConfig, setHeldConfig] = useState(() => storyConfig(ctx.config));
|
|
225
|
-
const config = storyConfig(ctx.config, heldConfig);
|
|
226
|
-
if (config !== heldConfig) setHeldConfig(config);
|
|
227
|
-
const seeded = useRef(false);
|
|
228
|
-
useEffect(() => {
|
|
229
|
-
if (seeded.current || ctx.state !== null || !story.initialState) return;
|
|
230
|
-
seeded.current = true;
|
|
231
|
-
ctx.setState(story.initialState(config));
|
|
232
|
-
}, [ctx, story, config]);
|
|
233
|
-
const [input, setInput] = useState({ config, state: ctx.state, key: 0 });
|
|
234
|
-
let resetKey = input.key;
|
|
235
|
-
if (input.config !== config || input.state !== ctx.state) {
|
|
236
|
-
resetKey = input.key + 1;
|
|
237
|
-
setInput({ config, state: ctx.state, key: resetKey });
|
|
238
|
-
}
|
|
239
|
-
const setConfig = useCallback((path, value) => {
|
|
240
|
-
if (!isForgePath(path)) latestRef.current.setConfig(path, value);
|
|
241
|
-
}, [latestRef]);
|
|
242
|
-
const setState = useCallback((next) => latestRef.current.setState(next), [latestRef]);
|
|
243
|
-
const trialId = useContext(TrialIdContext);
|
|
244
|
-
const clocks = useContext(TrialClocksContext);
|
|
245
|
-
const ownHost = useRef(null);
|
|
246
|
-
const host = hostRef ?? ownHost;
|
|
247
|
-
const kept = ctx.config?.[PLAYHEAD_KEY];
|
|
248
|
-
const persisted = typeof kept === "number" && Number.isFinite(kept) ? kept : null;
|
|
249
|
-
const clock = useStoryClock(story.timeline?.(config) ?? null, () => persisted);
|
|
250
|
-
useClockLoop(clock, host);
|
|
251
|
-
usePersistedPlayhead(clock, persisted, (time) => latestRef.current.setConfig(PLAYHEAD_KEY, time));
|
|
252
|
-
useEffect(() => clock && clocks && trialId ? clocks.publish(trialId, clock) : void 0, [clock, clocks, trialId]);
|
|
253
|
-
const decorators = setup.decorators ?? NO_DECORATORS;
|
|
254
|
-
const latestError = useLatest(onError);
|
|
255
|
-
const reportError = useCallback((error) => latestError.current?.(error), [latestError]);
|
|
256
|
-
const render = (globals) => /* @__PURE__ */ jsx(ClockContext.Provider, { value: clock, children: /* @__PURE__ */ jsx(
|
|
257
|
-
StoryBody,
|
|
258
|
-
{
|
|
259
|
-
story,
|
|
260
|
-
config,
|
|
261
|
-
setConfig,
|
|
262
|
-
state: ctx.state,
|
|
263
|
-
setState,
|
|
264
|
-
globals,
|
|
265
|
-
decorators,
|
|
266
|
-
resetKey,
|
|
267
|
-
onError: reportError
|
|
268
|
-
}
|
|
269
|
-
) });
|
|
270
|
-
return /* @__PURE__ */ jsx(
|
|
271
|
-
TrialHost,
|
|
272
|
-
{
|
|
273
|
-
layout: story.layout,
|
|
274
|
-
setup,
|
|
275
|
-
config: ctx.config,
|
|
276
|
-
hostRef: host,
|
|
277
|
-
...onRendered ? { onRendered } : {},
|
|
278
|
-
children: render
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export { StoryGlobalsContext, StoryTrial, TrialClocksContext, TrialFramesContext, TrialHost, createTrialClocks, createTrialFrames, useCssOverrides, useTrialClock, useTrialFrame };
|
|
284
|
-
//# sourceMappingURL=chunk-J3GYSNCK.js.map
|
|
285
|
-
//# sourceMappingURL=chunk-J3GYSNCK.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shell/trialFrames.ts","../src/shell/StoryGlobalsContext.ts","../src/shell/cssVars/overrides.ts","../src/shell/TrialHost.tsx","../src/timeline/trialClocks.ts","../src/timeline/usePersistedPlayhead.ts","../src/shell/StoryTrial.tsx"],"names":["createContext","useContext","create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AAM,MAAA,GAAS,CAAC,OAAA,qBACdF,GAAAA,CAAC,aAAa,QAAA,EAAb,EAAsB,KAAA,EAAO,KAAA,EAC5B,QAAA,kBAAAA,GAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,KAAA;AAAA,MACA,MAAA;AAAA,MACA,SAAA;AAAA,MACA,OAAO,GAAA,CAAI,KAAA;AAAA,MACX,QAAA;AAAA,MACA,OAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,OAAA,EAAS;AAAA;AAAA,GACX,EACF,CAAA;AAGF,EAAA,uBACEA,GAAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,QAAQ,KAAA,CAAM,MAAA;AAAA,MACd,KAAA;AAAA,MACA,QAAQ,GAAA,CAAI,MAAA;AAAA,MACZ,OAAA,EAAS,IAAA;AAAA,MACR,GAAI,UAAA,GAAa,EAAE,UAAA,KAAe,EAAC;AAAA,MAEnC,QAAA,EAAA;AAAA;AAAA,GACH;AAEJ","file":"chunk-J3GYSNCK.js","sourcesContent":["import { createEmitter } from '@weasel-js/registry';\nimport { createContext, useCallback, useContext, useSyncExternalStore } from 'react';\nimport type { A11yReport, CssVarReport, ToFrame } from '../protocol/messages';\n\n/** What an axe run in the frame came back with. */\nexport type A11yOutcome = { ok: true; report: A11yReport } | { ok: false; message: string };\n\n/** The half of a trial's frame that answers a request: each call is one round trip over the frame's channel. */\nexport interface TrialFrameCalls {\n send: (msg: ToFrame) => void;\n audit: () => Promise<A11yOutcome>;\n}\n\n/** What trial chrome can reach of the frame its trial shows. */\nexport interface TrialFrame {\n /** Null while no frame is connected. */\n send: ((msg: ToFrame) => void) | null;\n /** The frame's latest `vars` report. */\n vars: readonly CssVarReport[];\n /** Runs axe over the story and records the answer as `a11y`. Null while no frame is connected. */\n audit: (() => Promise<A11yOutcome>) | null;\n /** What the last audit found; null until one has run against the connected frame. */\n a11y: A11yOutcome | null;\n}\n\n/** Each trial's frame, keyed by trial id: `FrameView` connects and reports, trial chrome reads. */\nexport interface TrialFrames {\n /** Returns a disconnect that does nothing once a newer connection replaced this one. */\n connect(trialId: string, calls: TrialFrameCalls): () => void;\n report(trialId: string, vars: readonly CssVarReport[]): void;\n reportA11y(trialId: string, outcome: A11yOutcome): void;\n get(trialId: string): TrialFrame;\n subscribe(listener: () => void): () => void;\n}\n\nconst NO_FRAME: TrialFrame = { send: null, vars: [], audit: null, a11y: null };\n\nexport function createTrialFrames(): TrialFrames {\n const frames = new Map<string, TrialFrame>();\n const changes = createEmitter();\n const changed = changes.emit;\n const patch = (trialId: string, next: Partial<TrialFrame>) => {\n const frame = frames.get(trialId);\n if (!frame) return;\n frames.set(trialId, { ...frame, ...next });\n changed();\n };\n return {\n connect(trialId, calls) {\n frames.set(trialId, { send: calls.send, vars: [], audit: calls.audit, a11y: null });\n changed();\n return () => {\n if (frames.get(trialId)?.send !== calls.send) return;\n frames.delete(trialId);\n changed();\n };\n },\n report: (trialId, vars) => patch(trialId, { vars }),\n reportA11y: (trialId, a11y) => patch(trialId, { a11y }),\n get: (trialId) => frames.get(trialId) ?? NO_FRAME,\n subscribe: changes.subscribe,\n };\n}\n\n/** The workshop's `TrialFrames`; `null` outside a `Workshop`. */\nexport const TrialFramesContext = createContext<TrialFrames | null>(null);\n\n/** The frame of the trial `trialId` names, re-read when it connects or reports. */\nexport function useTrialFrame(trialId: string): TrialFrame {\n const frames = useContext(TrialFramesContext);\n const subscribe = useCallback((listener: () => void) => frames?.subscribe(listener) ?? (() => {}), [frames]);\n const read = () => frames?.get(trialId) ?? NO_FRAME;\n return useSyncExternalStore(subscribe, read, read);\n}\n","import { createContext } from 'react';\nimport type { Globals } from '../protocol/messages';\n\n/** The lab's global values, which a trial's pins override. A change reaches open frames without replacing instruments. */\nexport const StoryGlobalsContext = createContext<Globals>({});\n","import { usePersistedState } from '@weasel-js/labkit';\n\nexport type CssOverrides = Readonly<Record<string, string>>;\n\nconst NONE: CssOverrides = {};\n\n/** The CSS variable overrides of the trial this is rendered inside, persisted with it. */\nexport function useCssOverrides() {\n return usePersistedState<CssOverrides>('fg-css-overrides', NONE, { scope: 'trial' });\n}\n","import { useLatest } from '@weasel-js/core';\nimport { LabBoundary, TrialIdContext } from '@weasel-js/labkit';\nimport { OverlayPortalProvider } from '@weasel-js/ui';\nimport {\n type ReactNode,\n type RefObject,\n useContext,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { runAxe } from '../frame/a11y';\nimport { createOverrides, type Overrides, scanCssVars } from '../frame/cssVars';\nimport type { FrameSetup } from '../frame/FrameController';\nimport { IN_VIEW_MARGIN, useNearViewport } from '../frame/useNearViewport';\nimport { createGlobalsTarget } from '../frame/globalsTarget';\nimport type { CssVarReport, Globals, Layout, ToFrame } from '../protocol/messages';\nimport { useCssOverrides } from './cssVars/overrides';\nimport { effectiveGlobals, GLOBALS_KEY } from './globals';\nimport { StoryGlobalsContext } from './StoryGlobalsContext';\nimport { type A11yOutcome, TrialFramesContext } from './trialFrames';\n\n/** Props for `TrialHost`. */\nexport interface TrialHostProps {\n layout: Layout;\n setup: FrameSetup;\n /** The trial's config, read for its `$globals` pins. */\n config: unknown;\n /** Rendered once the host element exists, with the globals in force on it. */\n children: (globals: Globals) => ReactNode;\n /** Receives the host element, for a caller with no trial to reach it through. */\n hostRef?: RefObject<HTMLElement | null>;\n /** Called once the children's first commit has painted. */\n onRendered?: () => void;\n}\n\nconst VARS_SETTLE_MS = 100;\n\n/** A selector matching only the element carrying `id`. */\nconst scopeOf = (id: string) => `[data-fg-host=\"${id}\"]`;\n\n/**\n * One story's box in the workshop document: what a frame document was, as an element. It applies the globals to\n * itself, keeps its CSS variable overrides on itself, contains fixed-position descendants and portals, reports its\n * vars and audits to the trial's frame registry, and unmounts its content while out of view.\n */\nexport function TrialHost({ layout, setup, config, children, hostRef, onRendered }: TrialHostProps) {\n const trialId = useContext(TrialIdContext);\n const frames = useContext(TrialFramesContext);\n const labGlobals = useContext(StoryGlobalsContext);\n const pins = (config as Record<string, unknown> | null | undefined)?.[GLOBALS_KEY];\n const globals = useMemo(() => effectiveGlobals(labGlobals, pins), [labGlobals, pins]);\n const [persisted] = useCssOverrides();\n const reactId = useId();\n const hostId = trialId ?? reactId;\n const [host, setHost] = useState<HTMLDivElement | null>(null);\n const elementRef = useRef<HTMLDivElement | null>(null);\n const inView = useNearViewport(elementRef, IN_VIEW_MARGIN);\n const [pending, setPending] = useState(true);\n const overridesRef = useRef<Overrides | null>(null);\n const latest = useLatest({ setup, onRendered });\n\n // Everything the host owns for its lifetime: the globals target, the overrides rule, the registry connection.\n useLayoutEffect(() => {\n if (!host) return;\n const doc = host.ownerDocument;\n const scope = scopeOf(hostId);\n const { cssVarsScope } = latest.current.setup;\n const overrides = createOverrides(doc, cssVarsScope ? `${scope}, ${scope} :is(${cssVarsScope})` : scope);\n overridesRef.current = overrides;\n let lastVars: CssVarReport[] | null = null;\n let reported: string | null = null;\n const publish = (vars: CssVarReport[]) => {\n lastVars = vars;\n const key = JSON.stringify(vars);\n if (key === reported) return;\n reported = key;\n if (trialId) frames?.report(trialId, vars);\n };\n const scan = () => publish(scanCssVars(doc, overrides.has, host));\n let settleTimer: ReturnType<typeof setTimeout> | undefined;\n const ownMutation = (record: MutationRecord) =>\n overrides.owns(record.target) ||\n (record.type === 'childList' &&\n [...record.addedNodes, ...record.removedNodes].length > 0 &&\n [...record.addedNodes, ...record.removedNodes].every(overrides.owns));\n const mutations =\n typeof MutationObserver === 'undefined'\n ? null\n : new MutationObserver((records) => {\n if (records.every(ownMutation)) return;\n clearTimeout(settleTimer);\n settleTimer = setTimeout(scan, VARS_SETTLE_MS);\n });\n mutations?.observe(host, { subtree: true, childList: true, characterData: true, attributes: true });\n\n const send = (msg: ToFrame) => {\n if (msg.type !== 'vars.set') return;\n overrides.set(msg.name, msg.value);\n if (lastVars?.some((v) => v.name === msg.name)) scan();\n };\n const audit = async (): Promise<A11yOutcome> => {\n let outcome: A11yOutcome;\n try {\n outcome = { ok: true, report: await runAxe(host, { page: false }) };\n } catch (error) {\n outcome = { ok: false, message: error instanceof Error ? error.message : String(error) };\n }\n if (trialId) frames?.reportA11y(trialId, outcome);\n return outcome;\n };\n const disconnect = frames && trialId ? frames.connect(trialId, { send, audit }) : () => {};\n\n return () => {\n disconnect();\n mutations?.disconnect();\n clearTimeout(settleTimer);\n overrides.dispose();\n overridesRef.current = null;\n };\n }, [host, hostId, trialId, frames, latest]);\n\n // The overrides the trial persisted, put back on every mount and kept in step with the panel's edits.\n const applied = useRef<Record<string, string>>({});\n useLayoutEffect(() => {\n const overrides = overridesRef.current;\n if (!overrides) return;\n for (const name of Object.keys(applied.current)) if (!(name in persisted)) overrides.set(name, null);\n for (const [name, value] of Object.entries(persisted)) overrides.set(name, value);\n applied.current = { ...persisted };\n }, [host, persisted]);\n\n useLayoutEffect(() => {\n if (!host) return;\n const target = createGlobalsTarget(host, scopeOf(hostId));\n latest.current.setup.applyGlobals?.(globals, target);\n return () => target.dispose();\n }, [host, hostId, globals, latest]);\n\n // The host is hidden until its first commit has painted with its fonts, so a new trial never shows a jump.\n const announced = useRef(false);\n useEffect(() => {\n if (!host || !inView || announced.current) return;\n let canceled = false;\n const done = () => {\n if (canceled) return;\n announced.current = true;\n setPending(false);\n latest.current.onRendered?.();\n };\n const { fonts } = host.ownerDocument;\n if (!fonts) {\n done();\n return;\n }\n const afterPaint = () => requestAnimationFrame(done);\n void fonts.ready.then(afterPaint, afterPaint);\n return () => {\n canceled = true;\n };\n }, [host, inView, latest]);\n\n return (\n <div\n ref={(el) => {\n elementRef.current = el;\n if (hostRef) hostRef.current = el;\n setHost(el);\n }}\n className=\"fg-story\"\n data-fg-host={hostId}\n data-fg-layout={layout}\n data-pending={pending || undefined}\n >\n {host && inView ? (\n // The workshop is itself a lab; below the boundary a story sees no lab, trial or theme above it, as in a\n // document of its own.\n <LabBoundary>\n <OverlayPortalProvider container={host}>{children(globals)}</OverlayPortalProvider>\n </LabBoundary>\n ) : null}\n </div>\n );\n}\n","import { createEmitter } from '@weasel-js/registry';\nimport { createContext, useContext, useSyncExternalStore } from 'react';\nimport type { Clock } from './clock';\n\n/** Each trial's story clock, by trial id: the story's trial publishes it, and the trial's transport reads it. */\nexport interface TrialClocks {\n /** Publishes `clock` as `trialId`'s; the returned function withdraws it. */\n publish(trialId: string, clock: Clock): () => void;\n get(trialId: string): Clock | null;\n subscribe(listener: () => void): () => void;\n}\n\nexport function createTrialClocks(): TrialClocks {\n const clocks = new Map<string, Clock>();\n const changed = createEmitter();\n const notify = changed.emit;\n return {\n publish(trialId, clock) {\n clocks.set(trialId, clock);\n notify();\n return () => {\n if (clocks.get(trialId) !== clock) return;\n clocks.delete(trialId);\n notify();\n };\n },\n get: (trialId) => clocks.get(trialId) ?? null,\n subscribe: changed.subscribe,\n };\n}\n\nexport const TrialClocksContext = createContext<TrialClocks | null>(null);\n\nconst NEVER = () => () => {};\nconst NONE = () => null;\n\n/** The clock trial `trialId`'s story published, or null. */\nexport function useTrialClock(trialId: string): Clock | null {\n const clocks = useContext(TrialClocksContext);\n return useSyncExternalStore(clocks?.subscribe ?? NEVER, clocks ? () => clocks.get(trialId) : NONE);\n}\n","import { useLatest } from '@weasel-js/core';\nimport { useEffect, useRef } from 'react';\nimport type { Clock } from './clock';\n\n/**\n * Keeps `clock`'s paused time in the trial, through `write`, so a reload or a snapshot brings the story back there.\n * It writes when the clock stops or moves while stopped, never on a playing frame. A `persisted` value arriving from\n * outside — a snapshot loaded, a Reset — is requested of the clock, so a span set later can still hold it; null\n * stands for the span's start. Nothing is written while a request waits on a span.\n */\nexport function usePersistedPlayhead(clock: Clock | null, persisted: number | null, write: (time: number) => void): void {\n const written = useRef(persisted);\n const latestWrite = useLatest(write);\n\n useEffect(() => {\n if (!clock || persisted === written.current) return;\n written.current = persisted;\n clock.request(persisted);\n }, [clock, persisted]);\n\n useEffect(() => {\n if (!clock) return;\n return clock.subscribe(() => {\n const { playing, time } = clock.get();\n if (playing || clock.pending() !== null || time === written.current) return;\n written.current = time;\n latestWrite.current(time);\n });\n }, [clock, latestWrite]);\n}\n","import { type RenderContext, TrialIdContext } from '@weasel-js/labkit';\nimport { useLatest } from '@weasel-js/core';\nimport { memo, type RefObject, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport type { FrameSetup } from '../frame/FrameController';\nimport { StoryHost } from '../frame/StoryHost';\nimport type { Globals } from '../protocol/messages';\nimport type { Decorator, LoadedStory, StoryContext } from '../story/types';\nimport { ClockContext } from '../timeline/context';\nimport { useStoryClock } from '../timeline/StoryClock';\nimport { TrialClocksContext } from '../timeline/trialClocks';\nimport { useClockLoop } from '../timeline/useClockLoop';\nimport { usePersistedPlayhead } from '../timeline/usePersistedPlayhead';\nimport { isForgePath, PLAYHEAD_KEY, storyConfig } from './globals';\nimport { TrialHost } from './TrialHost';\n\n/** Props for `StoryTrial`. */\nexport interface StoryTrialProps {\n story: LoadedStory;\n setup: FrameSetup;\n /** The trial's config and state; the story reads and writes them through its `StoryContext`. */\n ctx: Pick<RenderContext<unknown, unknown>, 'config' | 'state' | 'setConfig' | 'setState'>;\n hostRef?: RefObject<HTMLElement | null>;\n onRendered?: () => void;\n /** A render throw, after the boundary has shown it. */\n onError?: (error: unknown) => void;\n}\n\nconst NO_DECORATORS: readonly Decorator[] = [];\n\ninterface StoryBodyProps {\n story: LoadedStory;\n config: StoryContext['config'];\n setConfig: StoryContext['setConfig'];\n state: unknown;\n setState: StoryContext['setState'];\n globals: Globals;\n decorators: readonly Decorator[];\n resetKey: number;\n onError: (error: unknown) => void;\n}\n\n/** Calls `render` only when its inputs change, as Storybook does: the lab re-renders a trial for its own reasons, and a\n * story declaring a component inside `render` remounts it on every extra call. */\nconst StoryBody = memo(function StoryBody({ story, config, setConfig, state, setState, globals, decorators, resetKey, onError }: StoryBodyProps) {\n const storyCtx: StoryContext = { config, setConfig, state, setState, globals, title: story.title, name: story.name };\n return <StoryHost story={story} ctx={storyCtx} decorators={decorators} resetKey={resetKey} onError={onError} />;\n});\n\n/** A story rendered in the workshop document, inside a `TrialHost`, from the trial's own config and state. */\nexport function StoryTrial({ story, setup, ctx, hostRef, onRendered, onError }: StoryTrialProps) {\n const latestRef = useLatest(ctx);\n // Kept across a write to a key forge owns, so moving the playhead or a pin does not re-render the story.\n const [heldConfig, setHeldConfig] = useState(() => storyConfig(ctx.config));\n const config = storyConfig(ctx.config, heldConfig);\n if (config !== heldConfig) setHeldConfig(config);\n\n // A trial opened on the provisional instrument starts at `null`; the story's own initial state fills it once.\n const seeded = useRef(false);\n useEffect(() => {\n if (seeded.current || ctx.state !== null || !story.initialState) return;\n seeded.current = true;\n ctx.setState(story.initialState(config));\n }, [ctx, story, config]);\n\n // Each new input retries a render the boundary caught, as the frame did on each message.\n // State, not a ref: a render React throws away takes its bump with it.\n const [input, setInput] = useState({ config, state: ctx.state, key: 0 });\n let resetKey = input.key;\n if (input.config !== config || input.state !== ctx.state) {\n resetKey = input.key + 1;\n setInput({ config, state: ctx.state, key: resetKey });\n }\n\n // Stable, as the frame's were: a story may list them as effect dependencies.\n // The pins belong to the trial; a story cannot see them, so it cannot set them either.\n const setConfig = useCallback((path: string, value: unknown) => {\n if (!isForgePath(path)) latestRef.current.setConfig(path, value);\n }, [latestRef]);\n const setState = useCallback((next: unknown) => latestRef.current.setState(next), [latestRef]);\n\n // The story's clock lives with its trial: the trial's transport reads it from the registry, the story from context.\n const trialId = useContext(TrialIdContext);\n const clocks = useContext(TrialClocksContext);\n const ownHost = useRef<HTMLElement | null>(null);\n const host = hostRef ?? ownHost;\n const kept = (ctx.config as Record<string, unknown> | null)?.[PLAYHEAD_KEY];\n const persisted = typeof kept === 'number' && Number.isFinite(kept) ? kept : null;\n const clock = useStoryClock(story.timeline?.(config) ?? null, () => persisted);\n useClockLoop(clock, host);\n usePersistedPlayhead(clock, persisted, (time) => latestRef.current.setConfig(PLAYHEAD_KEY, time));\n useEffect(() => (clock && clocks && trialId ? clocks.publish(trialId, clock) : undefined), [clock, clocks, trialId]);\n\n const decorators = setup.decorators ?? NO_DECORATORS;\n const latestError = useLatest(onError);\n const reportError = useCallback((error: unknown) => latestError.current?.(error), [latestError]);\n const render = (globals: Globals) => (\n <ClockContext.Provider value={clock}>\n <StoryBody\n story={story}\n config={config}\n setConfig={setConfig}\n state={ctx.state}\n setState={setState}\n globals={globals}\n decorators={decorators}\n resetKey={resetKey}\n onError={reportError}\n />\n </ClockContext.Provider>\n );\n\n return (\n <TrialHost\n layout={story.layout}\n setup={setup}\n config={ctx.config}\n hostRef={host}\n {...(onRendered ? { onRendered } : {})}\n >\n {render}\n </TrialHost>\n );\n}\n"]}
|