@rohal12/spindle 0.64.26 → 0.64.27
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/dist/pkg/format.js +1 -1
- package/dist/pkg/headless.js +283 -34
- package/package.json +1 -1
- package/src/components/macros/PassageDisplay.tsx +3 -3
- package/src/index.tsx +2 -2
- package/src/markup/render.tsx +3 -2
- package/src/markup/svg-names.ts +69 -0
- package/src/observe/observable-text.ts +61 -7
- package/src/observe/svg-instances.ts +210 -0
- package/src/saves/save-manager.ts +25 -9
- package/src/store.ts +16 -2
- package/src/story-init.ts +6 -1
- package/src/utils/element-visibility.ts +27 -10
package/dist/pkg/headless.js
CHANGED
|
@@ -92,12 +92,19 @@ var SVG_NOT_TEXT = /* @__PURE__ */ new Set([
|
|
|
92
92
|
"pattern",
|
|
93
93
|
"marker"
|
|
94
94
|
]);
|
|
95
|
+
/** Detached/headless DOMs may have no computed value; CSSOM still resolves
|
|
96
|
+
* duplicate inline declarations and priorities correctly.
|
|
97
|
+
*/
|
|
98
|
+
function styleValue(el, name) {
|
|
99
|
+
return (el.ownerDocument.defaultView ?? globalThis.window)?.getComputedStyle?.(el)[name] || el.style?.[name] || "";
|
|
100
|
+
}
|
|
95
101
|
/**
|
|
96
102
|
* Whether the element hides its whole subtree, including stylesheet rules.
|
|
97
103
|
* This needs computed styles but no layout, so it also works headlessly.
|
|
104
|
+
* A symbol referenced by SVG use is rendered only as an instance root.
|
|
98
105
|
*/
|
|
99
|
-
function isHidden(el) {
|
|
100
|
-
return el.hasAttribute("hidden") || el.getAttribute("aria-hidden") === "true" ||
|
|
106
|
+
function isHidden(el, svgInstanceRoot = false) {
|
|
107
|
+
return el.hasAttribute("hidden") || el.getAttribute("aria-hidden") === "true" || styleValue(el, "display") === "none" || NOT_TEXT.has(el.localName.toLowerCase()) || el.namespaceURI === "http://www.w3.org/2000/svg" && SVG_NOT_TEXT.has(el.localName.toLowerCase()) && !(svgInstanceRoot && el.localName.toLowerCase() === "symbol") || el.parentElement?.tagName === "DETAILS" && !el.parentElement.hasAttribute("open") && el !== Array.from(el.parentElement.children).find((c) => c.tagName === "SUMMARY");
|
|
101
108
|
}
|
|
102
109
|
/**
|
|
103
110
|
* Whether `el` is in a closed `<details>`, other than in the summary that
|
|
@@ -122,12 +129,11 @@ function inClosedDetails(el, root) {
|
|
|
122
129
|
* `<details>`. An optional root bounds ancestor checks, so observations can
|
|
123
130
|
* read StoryContext inside its deliberately hidden host.
|
|
124
131
|
*/
|
|
125
|
-
function isRendered(el, root) {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
if (visibility === "hidden" || visibility === "collapse") return false;
|
|
132
|
+
function isRendered(el, root, checkVisibility = true) {
|
|
133
|
+
const visibility = styleValue(el, "visibility");
|
|
134
|
+
if (checkVisibility && (visibility === "hidden" || visibility === "collapse")) return false;
|
|
129
135
|
for (let e = el; e; e = composedParent(e)) {
|
|
130
|
-
if (
|
|
136
|
+
if (styleValue(e, "display") === "none") return false;
|
|
131
137
|
if (e === root) break;
|
|
132
138
|
const parent = e.parentElement;
|
|
133
139
|
if (parent?.shadowRoot && !e.assignedSlot) return false;
|
|
@@ -16766,6 +16772,69 @@ function HtmlAnnotation({ attributes, children }) {
|
|
|
16766
16772
|
}
|
|
16767
16773
|
}, isHtmlEncoding(attributes.encoding) ? void 0 : children), container && isHtmlEncoding(attributes.encoding) && createPortal(children, container)] });
|
|
16768
16774
|
}
|
|
16775
|
+
// src/markup/svg-names.ts
|
|
16776
|
+
/** HTML foreign-content name adjustments; unknown foreign names stay intact.
|
|
16777
|
+
* https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
|
|
16778
|
+
*/
|
|
16779
|
+
var TAGS = `svg a animate circle defs desc discard ellipse filter g image line
|
|
16780
|
+
marker mask metadata mpath path pattern polygon polyline rect script set stop
|
|
16781
|
+
style switch symbol text title tspan use view
|
|
16782
|
+
altGlyph altGlyphDef altGlyphItem animateColor animateMotion
|
|
16783
|
+
animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite
|
|
16784
|
+
feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feDropShadow
|
|
16785
|
+
feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode
|
|
16786
|
+
feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile
|
|
16787
|
+
feTurbulence foreignObject glyphRef linearGradient radialGradient textPath`;
|
|
16788
|
+
var ATTRIBUTES = `id class style lang tabindex role autofocus
|
|
16789
|
+
accent-height accumulate additive alignment-baseline alphabetic amplitude
|
|
16790
|
+
arabic-form ascent azimuth baseline-shift bbox begin bias by clip
|
|
16791
|
+
clip-path clip-rule color color-interpolation color-interpolation-filters
|
|
16792
|
+
color-profile color-rendering contentscripttype contentstyletype cursor
|
|
16793
|
+
cx cy d decelerate descent direction display divisor dominant-baseline dur dx dy
|
|
16794
|
+
elevation enable-background end exponent externalresourcesrequired fill
|
|
16795
|
+
fill-opacity fill-rule filter flood-color flood-opacity focusable font-family
|
|
16796
|
+
font-size font-size-adjust font-stretch font-style font-variant font-weight
|
|
16797
|
+
format from fr fx fy g1 g2 glyph-name glyph-orientation-horizontal
|
|
16798
|
+
glyph-orientation-vertical hanging height horiz-adv-x horiz-origin-x href
|
|
16799
|
+
ideographic image-rendering in in2 intercept k k1 k2 k3 k4 kerning
|
|
16800
|
+
letter-spacing lighting-color local marker-end marker-mid marker-start
|
|
16801
|
+
mathematical max media method min mode name offset opacity operator order orient
|
|
16802
|
+
orientation origin overflow overline-position overline-thickness panose-1
|
|
16803
|
+
paint-order pointer-events points r radius rendering-intent restart result
|
|
16804
|
+
rotate rx ry scale seed shape-rendering slope spacing speed stemh stemv
|
|
16805
|
+
stop-color stop-opacity strikethrough-position strikethrough-thickness string
|
|
16806
|
+
stroke stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin
|
|
16807
|
+
stroke-miterlimit stroke-opacity stroke-width target text-anchor
|
|
16808
|
+
text-decoration text-overflow text-rendering to transform transform-origin type u1 u2
|
|
16809
|
+
underline-position underline-thickness unicode unicode-bidi unicode-range
|
|
16810
|
+
units-per-em v-alphabetic v-hanging v-ideographic v-mathematical values
|
|
16811
|
+
vector-effect version vert-adv-y vert-origin-x vert-origin-y visibility width
|
|
16812
|
+
widths word-spacing writing-mode x x-height x1 x2 xlink:actuate xlink:arcrole
|
|
16813
|
+
xlink:href xlink:role xlink:show xlink:title xlink:type xml:base xml:lang xml:space
|
|
16814
|
+
xmlns xmlns:xlink y y1 y2 z
|
|
16815
|
+
attributeName attributeType baseFrequency baseProfile calcMode
|
|
16816
|
+
clipPathUnits diffuseConstant edgeMode filterUnits glyphRef gradientTransform
|
|
16817
|
+
gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes
|
|
16818
|
+
lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth
|
|
16819
|
+
maskContentUnits maskUnits numOctaves pathLength patternContentUnits
|
|
16820
|
+
patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha
|
|
16821
|
+
preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur
|
|
16822
|
+
requiredExtensions requiredFeatures specularConstant specularExponent
|
|
16823
|
+
spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage
|
|
16824
|
+
tableValues targetX targetY textLength viewBox viewTarget xChannelSelector
|
|
16825
|
+
yChannelSelector zoomAndPan`;
|
|
16826
|
+
function adjustments(names) {
|
|
16827
|
+
return new Map(names.split(/\s+/).map((name) => [name.toLowerCase(), name]));
|
|
16828
|
+
}
|
|
16829
|
+
var tags = adjustments(TAGS);
|
|
16830
|
+
var attributes = adjustments(ATTRIBUTES);
|
|
16831
|
+
function svgTagName(name) {
|
|
16832
|
+
return tags.get(name.toLowerCase()) ?? name;
|
|
16833
|
+
}
|
|
16834
|
+
function svgAttributeName(name) {
|
|
16835
|
+
const lower = name.toLowerCase();
|
|
16836
|
+
return attributes.get(lower) ?? (/^(?:aria-|data-)/.test(lower) ? lower : name);
|
|
16837
|
+
}
|
|
16769
16838
|
// src/components/macros/include-args.ts
|
|
16770
16839
|
/**
|
|
16771
16840
|
* The parameters of `{include}`. A standalone `inline` flag only counts
|
|
@@ -17423,7 +17492,7 @@ function HtmlNodeRenderer({ node }) {
|
|
|
17423
17492
|
const namespace = tag === "svg" || tag === "math" ? tag : parentNamespace;
|
|
17424
17493
|
const errors = [];
|
|
17425
17494
|
const resolved = Object.entries(node.attributes).map(([k, v]) => [
|
|
17426
|
-
k,
|
|
17495
|
+
namespace === "svg" ? svgAttributeName(k) : k,
|
|
17427
17496
|
resolveAttributeValue(k, v, scope, errors),
|
|
17428
17497
|
v,
|
|
17429
17498
|
hasInterpolation(v)
|
|
@@ -17473,7 +17542,7 @@ function HtmlNodeRenderer({ node }) {
|
|
|
17473
17542
|
value: childNamespace,
|
|
17474
17543
|
children
|
|
17475
17544
|
});
|
|
17476
|
-
const element = authorElement(node.tag, props, children, namespace === "math");
|
|
17545
|
+
const element = authorElement(namespace === "svg" ? svgTagName(node.tag) : node.tag, props, children, namespace === "math");
|
|
17477
17546
|
return withAttributeErrors(errors, isRawRoot ? /* @__PURE__ */ jsx(RawTextContext.Provider, {
|
|
17478
17547
|
value: true,
|
|
17479
17548
|
children: element
|
|
@@ -19298,23 +19367,28 @@ function saveSession(ifid, payload) {
|
|
|
19298
19367
|
return { error };
|
|
19299
19368
|
}
|
|
19300
19369
|
}
|
|
19301
|
-
/**
|
|
19302
|
-
*
|
|
19303
|
-
* session written by an incompatible version of Spindle is dropped with a
|
|
19304
|
-
* warning, and the story starts fresh.
|
|
19370
|
+
/** Capture storage before StoryInit can navigate and write a new session,
|
|
19371
|
+
* but defer revival until its class registrations have run.
|
|
19305
19372
|
*/
|
|
19306
|
-
function
|
|
19373
|
+
function prepareSessionRestore(ifid) {
|
|
19374
|
+
let raw;
|
|
19307
19375
|
try {
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
return
|
|
19311
|
-
} catch (err) {
|
|
19312
|
-
if (err instanceof IncompatibleSaveError) {
|
|
19313
|
-
console.warn(`spindle: ${err.message}; the session was not restored.`);
|
|
19314
|
-
clearSession(ifid);
|
|
19315
|
-
}
|
|
19316
|
-
return;
|
|
19376
|
+
raw = sessionStorage.getItem(`${SESSION_KEY_PREFIX}${ifid}`);
|
|
19377
|
+
} catch {
|
|
19378
|
+
return () => void 0;
|
|
19317
19379
|
}
|
|
19380
|
+
return () => {
|
|
19381
|
+
try {
|
|
19382
|
+
if (!raw) return void 0;
|
|
19383
|
+
return decodePayload(JSON.parse(raw));
|
|
19384
|
+
} catch (err) {
|
|
19385
|
+
if (err instanceof IncompatibleSaveError) {
|
|
19386
|
+
console.warn(`spindle: ${err.message}; the session was not restored.`);
|
|
19387
|
+
clearSession(ifid);
|
|
19388
|
+
}
|
|
19389
|
+
return;
|
|
19390
|
+
}
|
|
19391
|
+
};
|
|
19318
19392
|
}
|
|
19319
19393
|
function clearSession(ifid) {
|
|
19320
19394
|
try {
|
|
@@ -19517,8 +19591,9 @@ function executeStoryInit() {
|
|
|
19517
19591
|
* handlers set synchronously belongs to the start moment, like StoryInit's
|
|
19518
19592
|
* changes; a restored session keeps the history it recorded.
|
|
19519
19593
|
*/
|
|
19520
|
-
function initializeStory(
|
|
19594
|
+
function initializeStory(savedSession) {
|
|
19521
19595
|
executeStoryInit();
|
|
19596
|
+
let session = typeof savedSession === "function" ? savedSession() : savedSession;
|
|
19522
19597
|
const missing = session ? missingPassage(useStoryStore.getState().storyData, session) : void 0;
|
|
19523
19598
|
if (missing !== void 0) {
|
|
19524
19599
|
console.warn(`spindle: discarding the saved session: the story no longer has the passage "${missing}"`);
|
|
@@ -20373,6 +20448,7 @@ function clearAndRestart(get, set, clearing, message) {
|
|
|
20373
20448
|
get().restart();
|
|
20374
20449
|
return reported(cleared, message);
|
|
20375
20450
|
}
|
|
20451
|
+
var consumedTransition;
|
|
20376
20452
|
var useStoryStore = create()(storyStore((set, get) => ({
|
|
20377
20453
|
storyData: null,
|
|
20378
20454
|
currentPassage: "",
|
|
@@ -20417,6 +20493,7 @@ var useStoryStore = create()(storyStore((set, get) => ({
|
|
|
20417
20493
|
});
|
|
20418
20494
|
},
|
|
20419
20495
|
init: (storyData, variableDefaults = {}, transientDefaults = {}) => {
|
|
20496
|
+
consumedTransition = void 0;
|
|
20420
20497
|
const startPassage = storyData.passagesById.get(storyData.startNode);
|
|
20421
20498
|
if (!startPassage) throw new Error(`spindle: Start passage (pid=${storyData.startNode}) not found.`);
|
|
20422
20499
|
const initialVars = startVariables(variableDefaults);
|
|
@@ -20783,8 +20860,13 @@ var useStoryStore = create()(storyStore((set, get) => ({
|
|
|
20783
20860
|
state.nextTransition = config;
|
|
20784
20861
|
});
|
|
20785
20862
|
},
|
|
20786
|
-
consumeNextTransition: () => {
|
|
20863
|
+
consumeNextTransition: (navigationId) => {
|
|
20864
|
+
if (navigationId !== void 0 && consumedTransition?.navigationId === navigationId) return consumedTransition.config;
|
|
20787
20865
|
const current = get().nextTransition;
|
|
20866
|
+
if (navigationId !== void 0) consumedTransition = {
|
|
20867
|
+
navigationId,
|
|
20868
|
+
config: current
|
|
20869
|
+
};
|
|
20788
20870
|
if (current !== null) set((state) => {
|
|
20789
20871
|
state.nextTransition = null;
|
|
20790
20872
|
});
|
|
@@ -22058,6 +22140,142 @@ function storyContextElement() {
|
|
|
22058
22140
|
}
|
|
22059
22141
|
return el;
|
|
22060
22142
|
}
|
|
22143
|
+
// src/observe/svg-instances.ts
|
|
22144
|
+
var frames = /* @__PURE__ */ new WeakMap();
|
|
22145
|
+
var detachedDocuments = /* @__PURE__ */ new WeakMap();
|
|
22146
|
+
/**
|
|
22147
|
+
* Resolve a use instance's styles in an isolated tree. Source computed styles
|
|
22148
|
+
* inherit from the definition's ancestors, whereas SVG instances inherit from
|
|
22149
|
+
* their use host and match selectors within their own shadow tree.
|
|
22150
|
+
*/
|
|
22151
|
+
var SvgInstances = class {
|
|
22152
|
+
constructor() {
|
|
22153
|
+
this.hosts = [];
|
|
22154
|
+
this.sources = /* @__PURE__ */ new WeakMap();
|
|
22155
|
+
this.stylesheets = /* @__PURE__ */ new WeakMap();
|
|
22156
|
+
this.remaining = 1e4;
|
|
22157
|
+
}
|
|
22158
|
+
source(element) {
|
|
22159
|
+
return this.sources.get(element) ?? element;
|
|
22160
|
+
}
|
|
22161
|
+
stylesheet(use) {
|
|
22162
|
+
const root = this.source(use).getRootNode();
|
|
22163
|
+
const cached = this.stylesheets.get(root);
|
|
22164
|
+
if (cached !== void 0) return cached;
|
|
22165
|
+
const rules = (sheet) => {
|
|
22166
|
+
try {
|
|
22167
|
+
return [...sheet.cssRules].map((rule) => {
|
|
22168
|
+
if (rule.type === 3) {
|
|
22169
|
+
const imported = rule;
|
|
22170
|
+
if (!imported.styleSheet) return "";
|
|
22171
|
+
const text = rules(imported.styleSheet);
|
|
22172
|
+
let wrapped = imported.media.mediaText ? `@media ${imported.media.mediaText}{${text}}` : text;
|
|
22173
|
+
if (imported.supportsText) wrapped = `@supports (${imported.supportsText}){${wrapped}}`;
|
|
22174
|
+
if (imported.layerName !== null && imported.layerName !== void 0) wrapped = `@layer ${imported.layerName}{${wrapped}}`;
|
|
22175
|
+
return wrapped;
|
|
22176
|
+
}
|
|
22177
|
+
return rule.cssText;
|
|
22178
|
+
}).join("\n");
|
|
22179
|
+
} catch {
|
|
22180
|
+
return "";
|
|
22181
|
+
}
|
|
22182
|
+
};
|
|
22183
|
+
const text = [...root.styleSheets ?? [], ...root.adoptedStyleSheets ?? []].filter((sheet) => !sheet.disabled).map((sheet) => {
|
|
22184
|
+
const text = rules(sheet);
|
|
22185
|
+
return sheet.media.mediaText ? `@media ${sheet.media.mediaText}{${text}}` : text;
|
|
22186
|
+
}).join("\n");
|
|
22187
|
+
this.stylesheets.set(root, text);
|
|
22188
|
+
return text;
|
|
22189
|
+
}
|
|
22190
|
+
expand(use, target) {
|
|
22191
|
+
if (this.remaining <= 0) return;
|
|
22192
|
+
if (!this.document) {
|
|
22193
|
+
const doc = use.ownerDocument;
|
|
22194
|
+
const detached = doc.implementation.createHTMLDocument("");
|
|
22195
|
+
const probe = detached.createElement("div");
|
|
22196
|
+
probe.style.visibility = "hidden";
|
|
22197
|
+
detached.body.appendChild(probe);
|
|
22198
|
+
if ((doc.defaultView ?? globalThis.window)?.getComputedStyle(probe).visibility === "hidden") {
|
|
22199
|
+
probe.remove();
|
|
22200
|
+
let isolated = detachedDocuments.get(doc);
|
|
22201
|
+
if (!isolated) {
|
|
22202
|
+
const view = doc.defaultView ?? globalThis.window;
|
|
22203
|
+
isolated = detached;
|
|
22204
|
+
try {
|
|
22205
|
+
isolated = Reflect.construct(view.Window, [{ settings: {
|
|
22206
|
+
disableJavaScriptEvaluation: true,
|
|
22207
|
+
disableCSSFileLoading: true,
|
|
22208
|
+
disableIframePageLoading: true
|
|
22209
|
+
} }]).document ?? detached;
|
|
22210
|
+
} catch {}
|
|
22211
|
+
detachedDocuments.set(doc, isolated);
|
|
22212
|
+
}
|
|
22213
|
+
this.document = isolated;
|
|
22214
|
+
} else {
|
|
22215
|
+
let frame = frames.get(doc);
|
|
22216
|
+
if (!frame?.isConnected) {
|
|
22217
|
+
frame = doc.createElement("iframe");
|
|
22218
|
+
frame.setAttribute("sandbox", "allow-same-origin");
|
|
22219
|
+
frame.setAttribute("aria-hidden", "true");
|
|
22220
|
+
frame.tabIndex = -1;
|
|
22221
|
+
frame.style.cssText = `all:initial!important;display:block!important;position:fixed!important;left:-100000px!important;top:0!important;visibility:hidden!important;pointer-events:none!important;border:0!important;width:${doc.defaultView?.innerWidth ?? 1024}px!important;height:${doc.defaultView?.innerHeight ?? 768}px!important;`;
|
|
22222
|
+
doc.documentElement.insertBefore(frame, doc.body);
|
|
22223
|
+
frames.set(doc, frame);
|
|
22224
|
+
const isolated = frame.contentDocument;
|
|
22225
|
+
if (isolated) {
|
|
22226
|
+
const meta = isolated.createElement("meta");
|
|
22227
|
+
meta.httpEquiv = "Content-Security-Policy";
|
|
22228
|
+
meta.content = "default-src 'none'; style-src 'unsafe-inline'";
|
|
22229
|
+
isolated.head.appendChild(meta);
|
|
22230
|
+
}
|
|
22231
|
+
}
|
|
22232
|
+
this.document = frame.contentDocument ?? void 0;
|
|
22233
|
+
if (!this.document) return;
|
|
22234
|
+
const width = `${doc.defaultView?.innerWidth ?? 1024}px`;
|
|
22235
|
+
const height = `${doc.defaultView?.innerHeight ?? 768}px`;
|
|
22236
|
+
if (frame.style.width !== width) frame.style.setProperty("width", width, "important");
|
|
22237
|
+
if (frame.style.height !== height) frame.style.setProperty("height", height, "important");
|
|
22238
|
+
}
|
|
22239
|
+
}
|
|
22240
|
+
const doc = this.document;
|
|
22241
|
+
const host = doc.createElement("div");
|
|
22242
|
+
const computed = (use.ownerDocument.defaultView ?? globalThis.window)?.getComputedStyle(use);
|
|
22243
|
+
if (computed) {
|
|
22244
|
+
host.style.visibility = computed.visibility || use.style.visibility || use.getAttribute("visibility") || "";
|
|
22245
|
+
host.style.display = computed.display || use.style.display;
|
|
22246
|
+
for (const name of Array.from(computed)) if (name.startsWith("--")) host.style.setProperty(name, computed.getPropertyValue(name));
|
|
22247
|
+
}
|
|
22248
|
+
doc.body.appendChild(host);
|
|
22249
|
+
this.hosts.push(host);
|
|
22250
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
22251
|
+
const style = doc.createElement("style");
|
|
22252
|
+
style.textContent = this.stylesheet(use);
|
|
22253
|
+
const copy = (node) => {
|
|
22254
|
+
if (--this.remaining < 0) return;
|
|
22255
|
+
let clone;
|
|
22256
|
+
if (node.nodeType === 1) {
|
|
22257
|
+
const element = node;
|
|
22258
|
+
clone = doc.createElementNS(element.namespaceURI, element.localName);
|
|
22259
|
+
for (const attribute of element.attributes) clone.setAttributeNS(attribute.namespaceURI, attribute.name, attribute.value);
|
|
22260
|
+
this.sources.set(clone, this.source(node));
|
|
22261
|
+
} else if (node.nodeType === 3) clone = doc.createTextNode(node.textContent ?? "");
|
|
22262
|
+
else return;
|
|
22263
|
+
for (const child of node.childNodes) {
|
|
22264
|
+
if (this.remaining <= 0) break;
|
|
22265
|
+
const copied = copy(child);
|
|
22266
|
+
if (copied) clone.appendChild(copied);
|
|
22267
|
+
}
|
|
22268
|
+
return clone;
|
|
22269
|
+
};
|
|
22270
|
+
const clone = copy(target);
|
|
22271
|
+
if (clone) shadow.appendChild(clone);
|
|
22272
|
+
shadow.appendChild(style);
|
|
22273
|
+
return clone;
|
|
22274
|
+
}
|
|
22275
|
+
dispose() {
|
|
22276
|
+
for (const host of this.hosts) host.remove();
|
|
22277
|
+
}
|
|
22278
|
+
};
|
|
22061
22279
|
// src/observe/observable-text.ts
|
|
22062
22280
|
/** Elements that start and end a line. */
|
|
22063
22281
|
var BLOCKS = /* @__PURE__ */ new Set([
|
|
@@ -22121,10 +22339,27 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22121
22339
|
const endLine = () => {
|
|
22122
22340
|
if (out !== "" && !out.endsWith("\n")) out += "\n";
|
|
22123
22341
|
};
|
|
22124
|
-
const
|
|
22342
|
+
const references = /* @__PURE__ */ new Set();
|
|
22343
|
+
const instances = new SvgInstances();
|
|
22344
|
+
let instanceNodes = 1e4;
|
|
22345
|
+
const localTarget = (use) => {
|
|
22346
|
+
use = instances.source(use);
|
|
22347
|
+
const href = use.getAttribute("href") ?? use.getAttributeNS("http://www.w3.org/1999/xlink", "href");
|
|
22348
|
+
if (!href?.startsWith("#") || href.length === 1) return;
|
|
22349
|
+
let id;
|
|
22350
|
+
try {
|
|
22351
|
+
id = decodeURIComponent(href.slice(1));
|
|
22352
|
+
} catch {
|
|
22353
|
+
return;
|
|
22354
|
+
}
|
|
22355
|
+
const root = use.getRootNode();
|
|
22356
|
+
return "getElementById" in root ? root.getElementById(id) ?? void 0 : [root, ...root.querySelectorAll("[id]")].find((node) => node.id === id);
|
|
22357
|
+
};
|
|
22358
|
+
const walk = (node, inPre, instanceRoot) => {
|
|
22359
|
+
if (instanceRoot && --instanceNodes < 0) return;
|
|
22125
22360
|
if (node.nodeType === 3) {
|
|
22126
22361
|
const parent = node.assignedSlot ?? node.parentElement ?? node.getRootNode().host;
|
|
22127
|
-
if (parent && !isRendered(parent, visibilityRoot)) return;
|
|
22362
|
+
if (parent && !isRendered(parent, instanceRoot ?? visibilityRoot)) return;
|
|
22128
22363
|
const data = node.textContent ?? "";
|
|
22129
22364
|
if (inPre) out += data;
|
|
22130
22365
|
else {
|
|
@@ -22135,15 +22370,25 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22135
22370
|
}
|
|
22136
22371
|
if (node.nodeType !== 1) return;
|
|
22137
22372
|
const child = node;
|
|
22138
|
-
if (isHidden(child) || skip && child !== el && child.matches(skip)) return;
|
|
22373
|
+
if (isHidden(child, child === instanceRoot) || skip && child !== el && child.matches(skip)) return;
|
|
22374
|
+
if (child.namespaceURI === "http://www.w3.org/2000/svg" && child.localName === "use") {
|
|
22375
|
+
if (!isRendered(child, instanceRoot ?? visibilityRoot, false)) return;
|
|
22376
|
+
const target = localTarget(child);
|
|
22377
|
+
if (!target || target.namespaceURI !== child.namespaceURI || references.has(target) || references.size >= 32) return;
|
|
22378
|
+
references.add(target);
|
|
22379
|
+
const instance = instances.expand(child, target);
|
|
22380
|
+
if (instance) walk(instance, inPre, instance);
|
|
22381
|
+
references.delete(target);
|
|
22382
|
+
return;
|
|
22383
|
+
}
|
|
22139
22384
|
if (child.matches("input, textarea, select") || child.hasAttribute("data-action") && getAction(child.getAttribute("data-action"))?.type === "cycle") {
|
|
22140
22385
|
if (child.matches("input[type=\"hidden\" i]")) return;
|
|
22141
|
-
if (!isRendered(child, visibilityRoot)) return;
|
|
22386
|
+
if (!isRendered(child, instanceRoot ?? visibilityRoot)) return;
|
|
22142
22387
|
out += controlMarker(child);
|
|
22143
22388
|
return;
|
|
22144
22389
|
}
|
|
22145
22390
|
if (child.tagName === "BR") {
|
|
22146
|
-
if (isRendered(child, visibilityRoot)) out += "\n";
|
|
22391
|
+
if (isRendered(child, instanceRoot ?? visibilityRoot)) out += "\n";
|
|
22147
22392
|
return;
|
|
22148
22393
|
}
|
|
22149
22394
|
const block = BLOCKS.has(child.tagName);
|
|
@@ -22151,11 +22396,15 @@ function observableText(el, skip, visibilityRoot) {
|
|
|
22151
22396
|
const closedDetails = child.tagName === "DETAILS" && !child.hasAttribute("open");
|
|
22152
22397
|
const rendered = composedChildNodes(child);
|
|
22153
22398
|
const children = closedDetails ? rendered.filter((c) => c.nodeType === 1 && !isHidden(c)) : rendered;
|
|
22154
|
-
for (const c of children) walk(c, inPre || child.tagName === "PRE");
|
|
22399
|
+
for (const c of children) walk(c, inPre || child.tagName === "PRE", instanceRoot);
|
|
22155
22400
|
if (child.tagName === "TD" || child.tagName === "TH") out += " ";
|
|
22156
22401
|
if (block) endLine();
|
|
22157
22402
|
};
|
|
22158
|
-
|
|
22403
|
+
try {
|
|
22404
|
+
walk(el, false);
|
|
22405
|
+
} finally {
|
|
22406
|
+
instances.dispose();
|
|
22407
|
+
}
|
|
22159
22408
|
return out.split("\n").map((line) => line.trimEnd()).join("\n").replace(/\n{3,}/g, "\n\n").replace(/^\n+|\s+$/g, "");
|
|
22160
22409
|
}
|
|
22161
22410
|
/**
|
|
@@ -24643,7 +24892,7 @@ defineMacro({
|
|
|
24643
24892
|
const isFirstLoad = !displayedPassage;
|
|
24644
24893
|
const isReplacement = navigationId === replacementNavigationId;
|
|
24645
24894
|
if (navigationId === displayed.id) return;
|
|
24646
|
-
const next = store.consumeNextTransition();
|
|
24895
|
+
const next = store.consumeNextTransition(navigationId);
|
|
24647
24896
|
cancelTransition();
|
|
24648
24897
|
const targetPassage = storyData?.passages.get(currentPassage);
|
|
24649
24898
|
if (!targetPassage) {
|
|
@@ -26818,7 +27067,7 @@ function boot() {
|
|
|
26818
27067
|
useStoryStore.getState().init(storyData, defaults, transientDefaults);
|
|
26819
27068
|
enterRuntimePhase();
|
|
26820
27069
|
for (const [, passage] of storyData.passages) if (passage.tags.includes("widget")) orStop(() => registerWidgetDefinitions(parseMarkup(passage.content), passage.name), `Passage "${passage.name}": `);
|
|
26821
|
-
initializeStory(
|
|
27070
|
+
initializeStory(prepareSessionRestore(storyData.ifid));
|
|
26822
27071
|
const markup = [...variableErrors(storyData, schema), ...markupErrors(storyData, (p) => p.name !== "StoryInit")];
|
|
26823
27072
|
const storyContext = storyData.passages.get("StoryContext");
|
|
26824
27073
|
if (storyContext) markup.push(...storyContextErrors(storyContext.content, storeVarMacroNames()));
|
package/package.json
CHANGED
|
@@ -920,9 +920,9 @@ defineMacro({
|
|
|
920
920
|
return;
|
|
921
921
|
}
|
|
922
922
|
|
|
923
|
-
//
|
|
924
|
-
//
|
|
925
|
-
const next = store.consumeNextTransition();
|
|
923
|
+
// Consume once per navigation and share across all displays (including
|
|
924
|
+
// when tags override it). Initial render doesn't consume the one-shot.
|
|
925
|
+
const next = store.consumeNextTransition(navigationId);
|
|
926
926
|
|
|
927
927
|
// Cancel any in-progress transition
|
|
928
928
|
cancelTransition();
|
package/src/index.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import { resetIdCounters } from './action-registry';
|
|
|
11
11
|
import { initializeStory } from './story-init';
|
|
12
12
|
import { storyContextErrors } from './story-context-passage';
|
|
13
13
|
import { connectTriggersToStore } from './triggers';
|
|
14
|
-
import {
|
|
14
|
+
import { prepareSessionRestore } from './saves/save-manager';
|
|
15
15
|
import {
|
|
16
16
|
parseStoryVariables,
|
|
17
17
|
validatePassages,
|
|
@@ -262,7 +262,7 @@ export function boot() {
|
|
|
262
262
|
|
|
263
263
|
// Run StoryInit, restore the session if the page was refreshed, and fire
|
|
264
264
|
// storyinit after all state is settled (defaults + StoryInit + session)
|
|
265
|
-
initializeStory(
|
|
265
|
+
initializeStory(prepareSessionRestore(storyData.ifid));
|
|
266
266
|
|
|
267
267
|
// Every other passage's markup, now that StoryInit may have defined macros;
|
|
268
268
|
// so are the variable references, which macros' parameters decide
|
package/src/markup/render.tsx
CHANGED
|
@@ -27,6 +27,7 @@ import { isCodeAttribute } from './code-attributes';
|
|
|
27
27
|
import { errorMessage } from '../utils/error-message';
|
|
28
28
|
import { EMPTY_NAMESPACE } from '../utils/namespace';
|
|
29
29
|
import { authorElement, isHtmlEncoding } from './html-integration';
|
|
30
|
+
import { svgTagName, svgAttributeName } from './svg-names';
|
|
30
31
|
import { parseMarkup } from './parse';
|
|
31
32
|
import { useStoryStore } from '../store';
|
|
32
33
|
import { passageTarget } from '../components/macros/macro-args';
|
|
@@ -871,7 +872,7 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
|
|
|
871
872
|
const namespace = tag === 'svg' || tag === 'math' ? tag : parentNamespace;
|
|
872
873
|
const errors: AttributeError[] = [];
|
|
873
874
|
const resolved = Object.entries(node.attributes).map(([k, v]): Attribute => [
|
|
874
|
-
k,
|
|
875
|
+
namespace === 'svg' ? svgAttributeName(k) : k,
|
|
875
876
|
resolveAttributeValue(k, v, scope, errors),
|
|
876
877
|
v,
|
|
877
878
|
hasInterpolation(v),
|
|
@@ -971,7 +972,7 @@ function HtmlNodeRenderer({ node }: { node: HtmlNode }) {
|
|
|
971
972
|
);
|
|
972
973
|
}
|
|
973
974
|
const element = authorElement(
|
|
974
|
-
node.tag,
|
|
975
|
+
namespace === 'svg' ? svgTagName(node.tag) : node.tag,
|
|
975
976
|
props,
|
|
976
977
|
children,
|
|
977
978
|
namespace === 'math',
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** HTML foreign-content name adjustments; unknown foreign names stay intact.
|
|
2
|
+
* https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inforeign
|
|
3
|
+
*/
|
|
4
|
+
const TAGS = `svg a animate circle defs desc discard ellipse filter g image line
|
|
5
|
+
marker mask metadata mpath path pattern polygon polyline rect script set stop
|
|
6
|
+
style switch symbol text title tspan use view
|
|
7
|
+
altGlyph altGlyphDef altGlyphItem animateColor animateMotion
|
|
8
|
+
animateTransform clipPath feBlend feColorMatrix feComponentTransfer feComposite
|
|
9
|
+
feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feDropShadow
|
|
10
|
+
feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode
|
|
11
|
+
feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile
|
|
12
|
+
feTurbulence foreignObject glyphRef linearGradient radialGradient textPath`;
|
|
13
|
+
|
|
14
|
+
const ATTRIBUTES = `id class style lang tabindex role autofocus
|
|
15
|
+
accent-height accumulate additive alignment-baseline alphabetic amplitude
|
|
16
|
+
arabic-form ascent azimuth baseline-shift bbox begin bias by clip
|
|
17
|
+
clip-path clip-rule color color-interpolation color-interpolation-filters
|
|
18
|
+
color-profile color-rendering contentscripttype contentstyletype cursor
|
|
19
|
+
cx cy d decelerate descent direction display divisor dominant-baseline dur dx dy
|
|
20
|
+
elevation enable-background end exponent externalresourcesrequired fill
|
|
21
|
+
fill-opacity fill-rule filter flood-color flood-opacity focusable font-family
|
|
22
|
+
font-size font-size-adjust font-stretch font-style font-variant font-weight
|
|
23
|
+
format from fr fx fy g1 g2 glyph-name glyph-orientation-horizontal
|
|
24
|
+
glyph-orientation-vertical hanging height horiz-adv-x horiz-origin-x href
|
|
25
|
+
ideographic image-rendering in in2 intercept k k1 k2 k3 k4 kerning
|
|
26
|
+
letter-spacing lighting-color local marker-end marker-mid marker-start
|
|
27
|
+
mathematical max media method min mode name offset opacity operator order orient
|
|
28
|
+
orientation origin overflow overline-position overline-thickness panose-1
|
|
29
|
+
paint-order pointer-events points r radius rendering-intent restart result
|
|
30
|
+
rotate rx ry scale seed shape-rendering slope spacing speed stemh stemv
|
|
31
|
+
stop-color stop-opacity strikethrough-position strikethrough-thickness string
|
|
32
|
+
stroke stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin
|
|
33
|
+
stroke-miterlimit stroke-opacity stroke-width target text-anchor
|
|
34
|
+
text-decoration text-overflow text-rendering to transform transform-origin type u1 u2
|
|
35
|
+
underline-position underline-thickness unicode unicode-bidi unicode-range
|
|
36
|
+
units-per-em v-alphabetic v-hanging v-ideographic v-mathematical values
|
|
37
|
+
vector-effect version vert-adv-y vert-origin-x vert-origin-y visibility width
|
|
38
|
+
widths word-spacing writing-mode x x-height x1 x2 xlink:actuate xlink:arcrole
|
|
39
|
+
xlink:href xlink:role xlink:show xlink:title xlink:type xml:base xml:lang xml:space
|
|
40
|
+
xmlns xmlns:xlink y y1 y2 z
|
|
41
|
+
attributeName attributeType baseFrequency baseProfile calcMode
|
|
42
|
+
clipPathUnits diffuseConstant edgeMode filterUnits glyphRef gradientTransform
|
|
43
|
+
gradientUnits kernelMatrix kernelUnitLength keyPoints keySplines keyTimes
|
|
44
|
+
lengthAdjust limitingConeAngle markerHeight markerUnits markerWidth
|
|
45
|
+
maskContentUnits maskUnits numOctaves pathLength patternContentUnits
|
|
46
|
+
patternTransform patternUnits pointsAtX pointsAtY pointsAtZ preserveAlpha
|
|
47
|
+
preserveAspectRatio primitiveUnits refX refY repeatCount repeatDur
|
|
48
|
+
requiredExtensions requiredFeatures specularConstant specularExponent
|
|
49
|
+
spreadMethod startOffset stdDeviation stitchTiles surfaceScale systemLanguage
|
|
50
|
+
tableValues targetX targetY textLength viewBox viewTarget xChannelSelector
|
|
51
|
+
yChannelSelector zoomAndPan`;
|
|
52
|
+
|
|
53
|
+
function adjustments(names: string): Map<string, string> {
|
|
54
|
+
return new Map(names.split(/\s+/).map((name) => [name.toLowerCase(), name]));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const tags = adjustments(TAGS);
|
|
58
|
+
const attributes = adjustments(ATTRIBUTES);
|
|
59
|
+
|
|
60
|
+
export function svgTagName(name: string): string {
|
|
61
|
+
return tags.get(name.toLowerCase()) ?? name;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function svgAttributeName(name: string): string {
|
|
65
|
+
const lower = name.toLowerCase();
|
|
66
|
+
return (
|
|
67
|
+
attributes.get(lower) ?? (/^(?:aria-|data-)/.test(lower) ? lower : name)
|
|
68
|
+
);
|
|
69
|
+
}
|