@rohal12/spindle 0.62.0 → 0.62.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10361,6 +10361,14 @@ function* tokens(src, start, goal, options = {}) {
10361
10361
  function lexJs(src, handlers, goal = "expression") {
10362
10362
  return walkTokens(src, 0, handlers, 0, goal, false);
10363
10363
  }
10364
+ /**
10365
+ * Lex the template literal opening at `start` (a backtick) as `lexJs` does,
10366
+ * its interpolations one nesting level deeper. Returns the index just past
10367
+ * its closing backtick, or `src.length` if it is unterminated.
10368
+ */
10369
+ function lexTemplate(src, start, handlers = {}, nesting = 0) {
10370
+ return walkTokens(src, start, handlers, nesting, "expression", true);
10371
+ }
10364
10372
  function walkTokens(src, from, handlers, nesting, goal, oneTemplate) {
10365
10373
  const comments = [];
10366
10374
  const onComment = (_block, _text, s, e) => {
@@ -11140,6 +11148,17 @@ function isCloser(ch) {
11140
11148
  return ch === ")" || ch === "]" || ch === "}";
11141
11149
  }
11142
11150
  /**
11151
+ * Given the index of an opening quote (`"`, `'` or a backtick), return the
11152
+ * index just past its closing quote, or `src.length` if it is unterminated.
11153
+ * A backslash escapes the character after it, so a quote preceded by an even
11154
+ * run of backslashes still closes the string and one preceded by an odd run
11155
+ * does not. Inside a template literal, `${…}` interpolations are lexed as
11156
+ * code, so quotes, backticks, braces and regexes inside them do not end it.
11157
+ */
11158
+ function skipString(src, start) {
11159
+ return src[start] === "`" ? lexTemplate(src, start) : scanStringLiteral(src, start).end;
11160
+ }
11161
+ /**
11143
11162
  * Undo the escapes allowed in a literal quoted macro argument: `\"`, `\'`
11144
11163
  * and `\\` become `"`, `'` and `\`. Other backslash sequences (`\n`, `\d`)
11145
11164
  * are kept as written, so code and regex text inside the string survive.
@@ -11738,10 +11757,10 @@ function parameterLookup(macros) {
11738
11757
  const widgets = new NameMap();
11739
11758
  for (const { name, parameters: params, interpolate, widget } of macros) {
11740
11759
  if (params) parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
11741
- const declared = widget && widgetParameters(widget.params, widget.holds);
11742
- if (declared) widgets.set(name, declared);
11760
+ if (widget) widgets.set(name, widgetParameters(widget.params, widget.holds) ?? []);
11743
11761
  }
11744
11762
  const lookup = (name) => {
11763
+ if (widgets.has(name)) return void 0;
11745
11764
  let params = parameters.get(name);
11746
11765
  if (!params) {
11747
11766
  const sub = subMacroParameters(name);
@@ -11814,7 +11833,8 @@ function* codeAndText(src, tokens, parametersOf) {
11814
11833
  }
11815
11834
  else if (token.type === "macro" && !token.isClose) {
11816
11835
  const name = token.name.toLowerCase();
11817
- if (name === "do") {
11836
+ const widget = parametersOf.widget?.(name);
11837
+ if (name === "do" && !widget) {
11818
11838
  const close = closeOfTextBody(t, name);
11819
11839
  if (close < 0) continue;
11820
11840
  yield {
@@ -11828,7 +11848,7 @@ function* codeAndText(src, tokens, parametersOf) {
11828
11848
  continue;
11829
11849
  }
11830
11850
  const args = token.rawArgs;
11831
- if (PASSAGE_BODIES.has(name)) {
11851
+ if (PASSAGE_BODIES.has(name) && !widget) {
11832
11852
  const close = closeOfTextBody(t, name);
11833
11853
  if (close > t + 1) {
11834
11854
  const text = src.slice(token.end, tokens[close].start);
@@ -11846,7 +11866,7 @@ function* codeAndText(src, tokens, parametersOf) {
11846
11866
  if (!args) continue;
11847
11867
  const label = `{${token.name} ${args}}`;
11848
11868
  const argsAt = token.argsStart;
11849
- if (CONDITION_MACROS.has(name)) {
11869
+ if (CONDITION_MACROS.has(name) && !widget) {
11850
11870
  yield {
11851
11871
  kind: "code",
11852
11872
  code: args,
@@ -11858,7 +11878,6 @@ function* codeAndText(src, tokens, parametersOf) {
11858
11878
  }
11859
11879
  const params = parametersOf(name);
11860
11880
  if (params) yield* argPieces(args, argsAt, params, token.name, label);
11861
- const widget = parametersOf.widget?.(name);
11862
11881
  if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
11863
11882
  }
11864
11883
  }
@@ -22458,7 +22477,7 @@ function shapeSchema(shape) {
22458
22477
  function initializerSyntaxError(expr) {
22459
22478
  const prefix = "return (";
22460
22479
  try {
22461
- parse$1(prefix + expr + ")", {
22480
+ parse$1(prefix + expr + "\n)", {
22462
22481
  ecmaVersion: "latest",
22463
22482
  allowReturnOutsideFunction: true
22464
22483
  });
@@ -22567,7 +22586,7 @@ function parseStoryVariables(content, sigil = "$") {
22567
22586
  const expr = content.slice(valueStart, valueEnd);
22568
22587
  let value;
22569
22588
  try {
22570
- value = new Function("return (" + expr + ")")();
22589
+ value = new Function("return (" + expr + "\n)")();
22571
22590
  } catch (err) {
22572
22591
  throw new Error(`${passageName}: Failed to evaluate "${sigil}${name} = ${expr}": ${errorMessage(err)}`);
22573
22592
  }
@@ -22813,7 +22832,7 @@ function collectTokenRefs(content, tokens, at, emit, options) {
22813
22832
  else if (token.type === "macro" && !token.isClose) {
22814
22833
  scanArgs(token, parametersOf, at, emit, options);
22815
22834
  scanSelectors(content, token, at, emit, options);
22816
- if (storeVarMacros.has(token.name.toLowerCase())) {
22835
+ if (storeVarMacros.has(token.name.toLowerCase()) && !parametersOf.widget?.(token.name)) {
22817
22836
  const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
22818
22837
  const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
22819
22838
  const quoted = QUOTED_VAR_ARG_RE.exec(first);
@@ -22829,7 +22848,7 @@ function collectTokenRefs(content, tokens, at, emit, options) {
22829
22848
  });
22830
22849
  } else if (!/^["'`]/.test(first)) scanCode(first, (i) => at(token.argsStart + lead + i), emit);
22831
22850
  }
22832
- if (token.name.toLowerCase() === "do") {
22851
+ if (token.name.toLowerCase() === "do" && !parametersOf.widget?.(token.name)) {
22833
22852
  let close = t + 1;
22834
22853
  while (close < tokens.length) {
22835
22854
  const c = tokens[close];
@@ -23162,12 +23181,169 @@ function appendSnapshot(container, snapshot) {
23162
23181
  }
23163
23182
  pendingScrolls.delete(snapshot);
23164
23183
  }
23165
- function copyComputedStyle(style, target) {
23184
+ function copyComputedStyle(style, target, ids) {
23166
23185
  for (let i = 0; i < style.length; i++) {
23167
23186
  const name = style[i];
23168
- target.setProperty(name, style.getPropertyValue(name));
23187
+ target.setProperty(name, snapshotUrls(style.getPropertyValue(name), ids), "important");
23169
23188
  }
23170
23189
  }
23190
+ var snapshotFragmentId = 0;
23191
+ /** SVG definitions need local targets without sharing IDs with live passages. */
23192
+ function snapshotIds(root) {
23193
+ const ids = /* @__PURE__ */ new Map();
23194
+ if (root instanceof Element && root.id) ids.set(root.id, "");
23195
+ for (const element of root.querySelectorAll("[id]")) ids.set(element.id, "");
23196
+ for (const original of ids.keys()) {
23197
+ let id;
23198
+ do
23199
+ id = `spindle-snapshot-${++snapshotFragmentId}`;
23200
+ while (ids.has(id) || document.getElementById(id));
23201
+ ids.set(original, id);
23202
+ }
23203
+ return ids;
23204
+ }
23205
+ /** Rewrite only fragments in this document; external SVG URLs stay external. */
23206
+ function snapshotFragment(value, ids) {
23207
+ try {
23208
+ const url = new URL(value, document.baseURI);
23209
+ const current = new URL(document.URL);
23210
+ if (url.href.split("#")[0] !== current.href.split("#")[0]) return value;
23211
+ let fragment = url.hash.slice(1);
23212
+ try {
23213
+ fragment = decodeURIComponent(fragment);
23214
+ } catch {}
23215
+ const id = ids.get(fragment);
23216
+ return id ? `#${id}` : value;
23217
+ } catch {
23218
+ return value;
23219
+ }
23220
+ }
23221
+ /** URL-valued presentation attributes, inline CSS and computed CSS alike. */
23222
+ function snapshotUrls(value, ids, base) {
23223
+ return value.replace(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)]*?))\s*\)/gi, (match, double, single, bare) => {
23224
+ const original = double ?? single ?? bare;
23225
+ try {
23226
+ const rewritten = snapshotFragment(base ? new URL(original, base).href : original, ids);
23227
+ return original === rewritten ? match : `url("${rewritten}")`;
23228
+ } catch {
23229
+ return match;
23230
+ }
23231
+ });
23232
+ }
23233
+ /** Keep SVG's specified CSS: a use instance inherits from its use element,
23234
+ * rather than from the definition's original parent. Computed defaults on
23235
+ * definitions would replace that inheritance (and resolve currentColor).
23236
+ */
23237
+ var snapshotSvgRules = /* @__PURE__ */ new WeakSet();
23238
+ /** A detached style element has no sheet yet. Carry its CSSOM, including
23239
+ * script-inserted rules and imported styles, into the passive tree.
23240
+ */
23241
+ function copySnapshotSheet(source, ids, onOpaque) {
23242
+ const seen = /* @__PURE__ */ new Set();
23243
+ const textOf = (sheet) => {
23244
+ if (seen.has(sheet)) return "";
23245
+ seen.add(sheet);
23246
+ let rules;
23247
+ try {
23248
+ rules = [...sheet.cssRules];
23249
+ } catch {
23250
+ onOpaque?.();
23251
+ return "";
23252
+ }
23253
+ return rules.filter((rule) => !snapshotSvgRules.has(rule)).map((rule) => {
23254
+ if (rule instanceof CSSImportRule && rule.styleSheet) {
23255
+ let css = textOf(rule.styleSheet);
23256
+ if (rule.layerName !== null) css = `@layer ${rule.layerName}{${css}}`;
23257
+ if (rule.supportsText) css = `@supports (${rule.supportsText}){${css}}`;
23258
+ if (rule.media.mediaText) css = `@media ${rule.media.mediaText}{${css}}`;
23259
+ return css;
23260
+ }
23261
+ return snapshotUrls(rule.cssText, ids, sheet.href ?? document.baseURI);
23262
+ }).join("\n");
23263
+ };
23264
+ const copy = new CSSStyleSheet({
23265
+ media: source.media.mediaText,
23266
+ disabled: source.disabled
23267
+ });
23268
+ copy.replaceSync(textOf(source));
23269
+ return copy;
23270
+ }
23271
+ function installSnapshotSvgStyles(root, ids, marker, targetSheets = [...root.styleSheets, ...root.adoptedStyleSheets]) {
23272
+ if (!root.querySelector("svg")) return () => {};
23273
+ const customTags = new Set([...root instanceof ShadowRoot ? [root.host] : [], ...root.querySelectorAll("*")].filter((element) => element.localName.includes("-")).map((element) => element.localName));
23274
+ const identity = /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\[(?:\\.|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\]"'\\])*\]|([#.])?((?:\\[0-9a-fA-F]{1,6}\s?|\\.|[\w-]|[^\x00-\x7f])+)/g;
23275
+ const selectorOf = (selector, scoped = true) => {
23276
+ const rewritten = selector.replace(identity, (written, sigil, escaped, at) => {
23277
+ if (!escaped) return written.replace(/^\[\s*id(?=[\s~|^$*=\]])/, "[data-spindle-snapshot-original-id");
23278
+ const name = escaped.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g, (_, hex, char) => hex ? String.fromCodePoint(parseInt(hex, 16)) : char);
23279
+ if (sigil === "." && name === "passage") return ":is(.passage,.passage-snapshot)";
23280
+ if (!sigil && customTags.has(name) && selector[at - 1] !== ":") return `:is(${CSS.escape(name)},:where([data-spindle-snapshot-tag="${name}"]))`;
23281
+ const id = sigil === "#" && ids.get(name);
23282
+ return id ? `:is(#${id},:where([data-spindle-snapshot-id="${id}"]))` : written;
23283
+ });
23284
+ if (!scoped) return rewritten;
23285
+ const selectors = [];
23286
+ let start = 0;
23287
+ let depth = 0;
23288
+ for (let i = 0; i <= rewritten.length; i++) {
23289
+ const ch = rewritten[i];
23290
+ if (ch === "\\") i++;
23291
+ else if (ch === "\"" || ch === "'") i = skipString(rewritten, i) - 1;
23292
+ else if (ch === "(" || ch === "[") depth++;
23293
+ else if (ch === ")" || ch === "]") depth--;
23294
+ else if (i === rewritten.length || ch === "," && depth === 0) {
23295
+ selectors.push(`:where([data-spindle-snapshot-svg="${marker}"]):is(${rewritten.slice(start, i)})`);
23296
+ start = i + 1;
23297
+ }
23298
+ }
23299
+ return selectors.join(",");
23300
+ };
23301
+ const rulesOf = (rules, base) => {
23302
+ const result = [];
23303
+ for (const rule of rules) if (rule instanceof CSSStyleRule) {
23304
+ const css = snapshotUrls(rule.style.cssText, ids, base);
23305
+ result.push(`${selectorOf(rule.selectorText)}{${css}}`);
23306
+ if (rule.cssRules.length) result.push(`${selectorOf(rule.selectorText, false)}{${rulesOf(rule.cssRules, base).join("\n")}}`);
23307
+ } else if ("cssRules" in rule && !(rule instanceof CSSKeyframesRule)) {
23308
+ const contents = rulesOf(rule.cssRules, base);
23309
+ result.push(`${rule.cssText.slice(0, rule.cssText.indexOf("{"))}{${contents.join("\n")}}`);
23310
+ }
23311
+ return result;
23312
+ };
23313
+ const inserted = [];
23314
+ const sheets = /* @__PURE__ */ new Set();
23315
+ const sheetRules = (sheet) => {
23316
+ if (sheets.has(sheet) || sheet.disabled || !matchMedia(sheet.media.mediaText || "all").matches) return;
23317
+ sheets.add(sheet);
23318
+ try {
23319
+ visit(sheet, sheet.href ?? document.baseURI);
23320
+ } catch {}
23321
+ };
23322
+ const visit = (parent, base) => {
23323
+ for (const rule of [...parent.cssRules]) {
23324
+ if (snapshotSvgRules.has(rule)) continue;
23325
+ if (rule instanceof CSSStyleRule) {
23326
+ let index = [...parent.cssRules].indexOf(rule) + 1;
23327
+ for (const css of rulesOf([rule], base)) {
23328
+ parent.insertRule(css, index);
23329
+ const insertedRule = parent.cssRules[index++];
23330
+ inserted.push([parent, insertedRule]);
23331
+ snapshotSvgRules.add(insertedRule);
23332
+ }
23333
+ } else if (rule instanceof CSSImportRule) {
23334
+ if (rule.styleSheet && matchMedia(rule.media.mediaText || "all").matches) sheetRules(rule.styleSheet);
23335
+ } else if ("cssRules" in rule && !(rule instanceof CSSKeyframesRule)) visit(rule, base);
23336
+ }
23337
+ };
23338
+ for (const sheet of targetSheets) sheetRules(sheet);
23339
+ return () => {
23340
+ for (const [parent, rule] of inserted) {
23341
+ const index = [...parent.cssRules].indexOf(rule);
23342
+ if (index >= 0) parent.deleteRule(index);
23343
+ snapshotSvgRules.delete(rule);
23344
+ }
23345
+ };
23346
+ }
23171
23347
  function installSnapshotStyles(root, rules) {
23172
23348
  if (!rules.length) return;
23173
23349
  const sheet = new CSSStyleSheet();
@@ -23185,44 +23361,67 @@ var snapshotPseudoId = 0;
23185
23361
  * as ordinary native elements, without an `is` option (even if the original
23186
23362
  * has since removed its `is` attribute).
23187
23363
  */
23188
- function cloneSnapshotTree(source, freezeStyles = false, pseudoRules = []) {
23189
- const custom = source.namespaceURI === "http://www.w3.org/1999/xhtml" && source.localName.includes("-");
23190
- freezeStyles ||= custom || source.hasAttribute("is");
23364
+ function cloneSnapshotTree(source, ids, pseudoRules = [], svgMarker = String(++snapshotPseudoId), cleanups = []) {
23365
+ const html = source.namespaceURI === "http://www.w3.org/1999/xhtml";
23366
+ const svg = source.namespaceURI === "http://www.w3.org/2000/svg";
23367
+ const custom = html && source.localName.includes("-");
23191
23368
  const clone = document.createElementNS(source.namespaceURI, custom ? "span" : source.localName);
23192
23369
  for (const attr of [...source.attributes]) {
23193
23370
  if (attr.name === "id" || attr.name === "data-action" || attr.name === "is" || attr.name.toLowerCase().startsWith("on")) continue;
23194
- if (attr.namespaceURI) clone.setAttributeNS(attr.namespaceURI, attr.name, attr.value);
23195
- else clone.setAttribute(attr.name, attr.value);
23196
- }
23197
- if (freezeStyles) {
23198
- copyComputedStyle(getComputedStyle(source), clone.style);
23199
- let id;
23200
- for (const pseudo of [
23201
- "::before",
23202
- "::after",
23203
- "::marker"
23204
- ]) {
23205
- const style = getComputedStyle(source, pseudo);
23206
- if (!style.content || ["none", "normal"].includes(style.content)) continue;
23207
- id ??= String(++snapshotPseudoId);
23208
- clone.setAttribute("data-spindle-snapshot-pseudo", id);
23209
- const target = document.createElement("span").style;
23210
- copyComputedStyle(style, target);
23211
- pseudoRules.push(`[data-spindle-snapshot-pseudo="${id}"]${pseudo}{${target.cssText}}`);
23212
- }
23371
+ const value = svg && attr.localName === "href" ? snapshotFragment(attr.value, ids) : svg || attr.localName === "style" ? snapshotUrls(attr.value, ids) : attr.value;
23372
+ if (attr.namespaceURI) clone.setAttributeNS(attr.namespaceURI, attr.name, value);
23373
+ else clone.setAttribute(attr.name, value);
23374
+ }
23375
+ if (svg && source.id) clone.id = ids.get(source.id);
23376
+ if (source.id) clone.setAttribute("data-spindle-snapshot-id", ids.get(source.id));
23377
+ if (source.id) clone.setAttribute("data-spindle-snapshot-original-id", source.id);
23378
+ if (custom) clone.setAttribute("data-spindle-snapshot-tag", source.localName);
23379
+ if (svg) clone.setAttribute("data-spindle-snapshot-svg", svgMarker);
23380
+ const computed = getComputedStyle(source);
23381
+ if (!svg) copyComputedStyle(computed, clone.style, ids);
23382
+ let pseudoId;
23383
+ for (const pseudo of [
23384
+ "::before",
23385
+ "::after",
23386
+ "::marker"
23387
+ ]) {
23388
+ const style = getComputedStyle(source, pseudo);
23389
+ if (!(pseudo === "::marker" && computed.display === "list-item") && (!style.content || ["none", "normal"].includes(style.content))) continue;
23390
+ pseudoId ??= String(++snapshotPseudoId);
23391
+ clone.setAttribute("data-spindle-snapshot-pseudo", pseudoId);
23392
+ const target = document.createElement("span").style;
23393
+ copyComputedStyle(style, target, ids);
23394
+ pseudoRules.push(`[data-spindle-snapshot-pseudo="${pseudoId}"]${pseudo}{${target.cssText}}`);
23213
23395
  }
23214
23396
  if (source.localName === "script") clone.setAttribute("type", "application/x-spindle-snapshot");
23215
23397
  const from = source instanceof HTMLTemplateElement ? source.content : source;
23216
23398
  const to = clone instanceof HTMLTemplateElement ? clone.content : clone;
23217
- const copyChildren = (from, to, rules = pseudoRules) => {
23218
- for (const node of from.childNodes) to.appendChild(node instanceof Element ? cloneSnapshotTree(node, freezeStyles, rules) : node.cloneNode(false));
23399
+ const copyChildren = (from, to, rules = pseudoRules, localIds = ids) => {
23400
+ for (const node of from.childNodes) to.appendChild(node instanceof Element ? cloneSnapshotTree(node, localIds, rules, svgMarker, cleanups) : node.cloneNode(false));
23219
23401
  };
23220
- copyChildren(from, to);
23402
+ copyChildren(from, to, pseudoRules, source instanceof HTMLTemplateElement ? snapshotIds(from) : ids);
23403
+ if (source instanceof HTMLStyleElement && source.sheet) {
23404
+ const root = source.getRootNode();
23405
+ if (root.querySelector("svg")) {
23406
+ let opaque = false;
23407
+ const copy = copySnapshotSheet(source.sheet, ids, () => {
23408
+ opaque = true;
23409
+ });
23410
+ const sheet = opaque ? source.sheet : copy;
23411
+ const dispose = installSnapshotSvgStyles(root, ids, svgMarker, [sheet]);
23412
+ clone.textContent = snapshotUrls([...sheet.cssRules].map((rule) => rule.cssText).join("\n"), ids, source.sheet.href ?? document.baseURI);
23413
+ dispose();
23414
+ if (source.sheet.disabled) clone.setAttribute("media", "not all");
23415
+ }
23416
+ }
23221
23417
  if (source.shadowRoot) {
23222
23418
  const shadow = clone.attachShadow({ mode: "open" });
23223
23419
  const rules = [];
23224
- copyChildren(source.shadowRoot, shadow, rules);
23420
+ const shadowIds = snapshotIds(source.shadowRoot);
23421
+ copyChildren(source.shadowRoot, shadow, rules, shadowIds);
23422
+ shadow.adoptedStyleSheets = source.shadowRoot.adoptedStyleSheets.map((sheet) => copySnapshotSheet(sheet, shadowIds));
23225
23423
  copyLiveState(source.shadowRoot, shadow);
23424
+ cleanups.push(installSnapshotSvgStyles(source.shadowRoot, shadowIds, svgMarker, shadow.adoptedStyleSheets));
23226
23425
  installSnapshotStyles(shadow, rules);
23227
23426
  }
23228
23427
  return clone;
@@ -23247,15 +23446,18 @@ function replaceEmbeddedContexts(source, clone) {
23247
23446
  }
23248
23447
  const rect = original.getBoundingClientRect();
23249
23448
  if (getComputedStyle(original).display === "inline") placeholder.style.display = "inline-block";
23250
- placeholder.style.boxSizing = "border-box";
23251
- placeholder.style.width = `${rect.width}px`;
23252
- placeholder.style.height = `${rect.height}px`;
23449
+ placeholder.style.removeProperty("inline-size");
23450
+ placeholder.style.removeProperty("block-size");
23451
+ placeholder.style.setProperty("box-sizing", "border-box", "important");
23452
+ placeholder.style.setProperty("width", `${rect.width}px`, "important");
23453
+ placeholder.style.setProperty("height", `${rect.height}px`, "important");
23253
23454
  embedded.replaceWith(placeholder);
23254
23455
  });
23255
23456
  }
23256
23457
  /**
23257
23458
  * Create a snapshot clone of a .passage element for outgoing transitions.
23258
- * - Strips IDs, action associations and event handlers from the clone tree
23459
+ * - Strips authored IDs, action associations and event handlers; SVG IDs and
23460
+ * their fragment references receive snapshot-local names
23259
23461
  * - Disables interaction (pointer-events, user-select, inert, aria-hidden)
23260
23462
  * - Pauses/mutes any <audio>/<video>
23261
23463
  * - Copies what cloneNode leaves behind: canvas pixels, the state of form
@@ -23265,12 +23467,21 @@ function replaceEmbeddedContexts(source, clone) {
23265
23467
  */
23266
23468
  function createSnapshot(passageEl, transitionType) {
23267
23469
  const pseudoRules = [];
23268
- const clone = cloneSnapshotTree(passageEl, false, pseudoRules);
23470
+ const cleanups = [];
23471
+ const ids = snapshotIds(passageEl);
23472
+ const svgMarker = String(++snapshotPseudoId);
23473
+ const clone = cloneSnapshotTree(passageEl, ids, pseudoRules, svgMarker, cleanups);
23474
+ clone.style.removeProperty("animation");
23475
+ clone.style.removeProperty("grid-area");
23476
+ for (const name of ["opacity", "transform"]) clone.style.setProperty(name, clone.style.getPropertyValue(name));
23269
23477
  copyLiveState(passageEl, clone);
23270
23478
  pendingScrolls.set(clone, scrollOffsets(passageEl, clone));
23271
23479
  replaceEmbeddedContexts(passageEl, clone);
23272
- const cleanup = installSnapshotStyles(passageEl.getRootNode(), pseudoRules);
23273
- if (cleanup) snapshotStyleCleanup.set(clone, cleanup);
23480
+ const root = passageEl.getRootNode();
23481
+ cleanups.push(installSnapshotSvgStyles(root, ids, svgMarker));
23482
+ const cleanup = installSnapshotStyles(root, pseudoRules);
23483
+ if (cleanup) cleanups.push(cleanup);
23484
+ snapshotStyleCleanup.set(clone, () => cleanups.forEach((dispose) => dispose()));
23274
23485
  clone.style.pointerEvents = "none";
23275
23486
  clone.style.userSelect = "none";
23276
23487
  clone.setAttribute("inert", "");
@@ -11087,10 +11087,10 @@ function parameterLookup(macros) {
11087
11087
  const widgets = new NameMap();
11088
11088
  for (const { name, parameters: params, interpolate, widget } of macros) {
11089
11089
  if (params) parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
11090
- const declared = widget && widgetParameters(widget.params, widget.holds);
11091
- if (declared) widgets.set(name, declared);
11090
+ if (widget) widgets.set(name, widgetParameters(widget.params, widget.holds) ?? []);
11092
11091
  }
11093
11092
  const lookup = (name) => {
11093
+ if (widgets.has(name)) return void 0;
11094
11094
  let params = parameters.get(name);
11095
11095
  if (!params) {
11096
11096
  const sub = subMacroParameters(name);
@@ -11163,7 +11163,8 @@ function* codeAndText(src, tokens, parametersOf) {
11163
11163
  }
11164
11164
  else if (token.type === "macro" && !token.isClose) {
11165
11165
  const name = token.name.toLowerCase();
11166
- if (name === "do") {
11166
+ const widget = parametersOf.widget?.(name);
11167
+ if (name === "do" && !widget) {
11167
11168
  const close = closeOfTextBody(t, name);
11168
11169
  if (close < 0) continue;
11169
11170
  yield {
@@ -11177,7 +11178,7 @@ function* codeAndText(src, tokens, parametersOf) {
11177
11178
  continue;
11178
11179
  }
11179
11180
  const args = token.rawArgs;
11180
- if (PASSAGE_BODIES.has(name)) {
11181
+ if (PASSAGE_BODIES.has(name) && !widget) {
11181
11182
  const close = closeOfTextBody(t, name);
11182
11183
  if (close > t + 1) {
11183
11184
  const text = src.slice(token.end, tokens[close].start);
@@ -11195,7 +11196,7 @@ function* codeAndText(src, tokens, parametersOf) {
11195
11196
  if (!args) continue;
11196
11197
  const label = `{${token.name} ${args}}`;
11197
11198
  const argsAt = token.argsStart;
11198
- if (CONDITION_MACROS.has(name)) {
11199
+ if (CONDITION_MACROS.has(name) && !widget) {
11199
11200
  yield {
11200
11201
  kind: "code",
11201
11202
  code: args,
@@ -11207,7 +11208,6 @@ function* codeAndText(src, tokens, parametersOf) {
11207
11208
  }
11208
11209
  const params = parametersOf(name);
11209
11210
  if (params) yield* argPieces(args, argsAt, params, token.name, label);
11210
- const widget = parametersOf.widget?.(name);
11211
11211
  if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
11212
11212
  }
11213
11213
  }
@@ -12427,7 +12427,7 @@ function shapeSchema(shape) {
12427
12427
  function initializerSyntaxError(expr) {
12428
12428
  const prefix = "return (";
12429
12429
  try {
12430
- parse$1(prefix + expr + ")", {
12430
+ parse$1(prefix + expr + "\n)", {
12431
12431
  ecmaVersion: "latest",
12432
12432
  allowReturnOutsideFunction: true
12433
12433
  });
@@ -12536,7 +12536,7 @@ function parseStoryVariables(content, sigil = "$") {
12536
12536
  const expr = content.slice(valueStart, valueEnd);
12537
12537
  let value;
12538
12538
  try {
12539
- value = new Function("return (" + expr + ")")();
12539
+ value = new Function("return (" + expr + "\n)")();
12540
12540
  } catch (err) {
12541
12541
  throw new Error(`${passageName}: Failed to evaluate "${sigil}${name} = ${expr}": ${errorMessage(err)}`);
12542
12542
  }
@@ -12769,7 +12769,7 @@ function collectTokenRefs(content, tokens, at, emit, options) {
12769
12769
  else if (token.type === "macro" && !token.isClose) {
12770
12770
  scanArgs(token, parametersOf, at, emit, options);
12771
12771
  scanSelectors(content, token, at, emit, options);
12772
- if (storeVarMacros.has(token.name.toLowerCase())) {
12772
+ if (storeVarMacros.has(token.name.toLowerCase()) && !parametersOf.widget?.(token.name)) {
12773
12773
  const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
12774
12774
  const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
12775
12775
  const quoted = QUOTED_VAR_ARG_RE.exec(first);
@@ -12785,7 +12785,7 @@ function collectTokenRefs(content, tokens, at, emit, options) {
12785
12785
  });
12786
12786
  } else if (!/^["'`]/.test(first)) scanCode(first, (i) => at(token.argsStart + lead + i), emit);
12787
12787
  }
12788
- if (token.name.toLowerCase() === "do") {
12788
+ if (token.name.toLowerCase() === "do" && !parametersOf.widget?.(token.name)) {
12789
12789
  let close = t + 1;
12790
12790
  while (close < tokens.length) {
12791
12791
  const c = tokens[close];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.62.0",
3
+ "version": "0.62.1",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
package/src/code-check.ts CHANGED
@@ -226,9 +226,10 @@ export function widgetParameters(
226
226
  export interface ParametersOf {
227
227
  (macro: string): readonly ParameterDef[] | undefined;
228
228
  /**
229
- * The parameters of the widget `name` if it declares what some argument
230
- * holds. Its arguments are read as a widget call reads them (separated by
231
- * commas or spaces, see splitArgs), not by parseMacroArgs.
229
+ * The parameters of the widget `name`, or an empty array if it declares
230
+ * no holds. Its presence identifies a widget even without holds, so a
231
+ * shadowed macro's metadata cannot apply. Arguments are separated by
232
+ * commas or spaces (see splitArgs), not by parseMacroArgs.
232
233
  */
233
234
  widget?(name: string): readonly WidgetParameter[] | undefined;
234
235
  }
@@ -278,10 +279,11 @@ export function parameterLookup(
278
279
  for (const { name, parameters: params, interpolate, widget } of macros) {
279
280
  if (params)
280
281
  parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
281
- const declared = widget && widgetParameters(widget.params, widget.holds);
282
- if (declared) widgets.set(name, declared);
282
+ if (widget)
283
+ widgets.set(name, widgetParameters(widget.params, widget.holds) ?? []);
283
284
  }
284
285
  const lookup: ParametersOf = (name) => {
286
+ if (widgets.has(name)) return undefined;
285
287
  let params = parameters.get(name);
286
288
  if (!params) {
287
289
  const sub = subMacroParameters(name);
@@ -396,7 +398,8 @@ export function* codeAndText(
396
398
  }
397
399
  } else if (token.type === 'macro' && !token.isClose) {
398
400
  const name = token.name.toLowerCase();
399
- if (name === 'do') {
401
+ const widget = parametersOf.widget?.(name);
402
+ if (name === 'do' && !widget) {
400
403
  const close = closeOfTextBody(t, name);
401
404
  if (close < 0) continue;
402
405
  const body = src.slice(token.end, tokens[close]!.start);
@@ -411,7 +414,7 @@ export function* codeAndText(
411
414
  continue;
412
415
  }
413
416
  const args = token.rawArgs;
414
- if (PASSAGE_BODIES.has(name)) {
417
+ if (PASSAGE_BODIES.has(name) && !widget) {
415
418
  // The body names the passage when it is only text
416
419
  const close = closeOfTextBody(t, name);
417
420
  if (close > t + 1) {
@@ -430,7 +433,7 @@ export function* codeAndText(
430
433
  if (!args) continue;
431
434
  const label = `{${token.name} ${args}}`;
432
435
  const argsAt = token.argsStart;
433
- if (CONDITION_MACROS.has(name)) {
436
+ if (CONDITION_MACROS.has(name) && !widget) {
434
437
  yield {
435
438
  kind: 'code',
436
439
  code: args,
@@ -442,7 +445,6 @@ export function* codeAndText(
442
445
  }
443
446
  const params = parametersOf(name);
444
447
  if (params) yield* argPieces(args, argsAt, params, token.name, label);
445
- const widget = parametersOf.widget?.(name);
446
448
  if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
447
449
  }
448
450
  }