@hyperframes/sdk 0.9.92 → 0.9.94

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/document.js CHANGED
@@ -8,20 +8,9 @@
8
8
  * HyperFramesElement is the editing view (ALL editable elements, with raw attrs).
9
9
  */
10
10
  import { parseHTMLContent } from "@hyperframes/core/compiler/html-document";
11
- import { ensureHfIds, isCompositionTemplate } from "@hyperframes/parsers/hf-ids";
11
+ import { EXCLUDED_TAGS, ensureHfIds, isCompositionTemplate } from "@hyperframes/parsers/hf-ids";
12
12
  import { parseGsapScriptAcornForWrite } from "@hyperframes/core/gsap-parser-acorn";
13
13
  import { findRoot, getElementStyles, getGsapScripts, getOwnText, isNewHostBoundary, querySelectorAllDeep, } from "./engine/model.js";
14
- // Tags that carry no editable content and must not enter the element tree.
15
- const EXCLUDED_TAGS = new Set([
16
- "script",
17
- "style",
18
- "template",
19
- "meta",
20
- "link",
21
- "noscript",
22
- "base",
23
- "head",
24
- ]);
25
14
  // Snapshot text is TRIMMED for display (markup indentation produces noisy
26
15
  // whitespace text nodes). The raw text target is shared with setText so shadow
27
16
  // value checks and dispatch serialization use the same DOM target.
@@ -124,7 +113,8 @@ function buildChildren(parent, scopePrefix, animationIdsByHfId) {
124
113
  // fallow-ignore-next-line complexity
125
114
  function buildElement(el, scopePrefix, animationIdsByHfId) {
126
115
  const tag = el.tagName.toLowerCase();
127
- if (EXCLUDED_TAGS.has(tag))
116
+ // `head` holds no content but isn't a text-edit target the shared set has to refuse, so only the tree leaves it out.
117
+ if (EXCLUDED_TAGS.has(tag) || tag === "head")
128
118
  return null;
129
119
  const id = el.getAttribute("data-hf-id") ?? "";
130
120
  if (!id)
@@ -89,8 +89,8 @@ export declare function setElementStyles(el: Element, updates: Record<string, st
89
89
  /** Read the text target used by SDK setText. `<br>` line breaks are surfaced as
90
90
  * "\n" so a multi-line leaf round-trips through setOwnText. */
91
91
  export declare function getOwnText(el: Element): string;
92
- /** Replace the SDK text target without destroying multi-child element structure. */
93
- export declare function setOwnText(el: Element, text: string): void;
92
+ /** Replace the SDK text target, keeping multi-child structure; false, writing nothing, on non-content. */
93
+ export declare function setOwnText(el: Element, text: string): boolean;
94
94
  export declare function getStyleSheet(document: Document): string;
95
95
  export declare function setStyleSheet(document: Document, css: string): void;
96
96
  export declare function getGsapScripts(document: Document): string[];
@@ -7,7 +7,7 @@
7
7
  import { isFullHtmlDocument, parseHTMLContent } from "@hyperframes/core/compiler/html-document";
8
8
  import { findTimelineScript } from "@hyperframes/core/gsap-parser-acorn";
9
9
  import { findVariableDeclaration } from "./variableModel.js";
10
- import { ensureHfIds, isCompositionTemplate, walkCompositionDescendants, } from "@hyperframes/core/hf-ids";
10
+ import { ensureHfIds, isCompositionTemplate, isNonContentElement, walkCompositionDescendants, } from "@hyperframes/core/hf-ids";
11
11
  export function parseMutable(html) {
12
12
  const stamped = ensureHfIds(html);
13
13
  const wrapped = !isFullHtmlDocument(stamped);
@@ -319,7 +319,7 @@ function resolveSingleChildTextTarget(el) {
319
319
  const inner = el.children.length === 1 ? el.firstElementChild : null;
320
320
  if (!inner || !isHTMLElementTarget(inner))
321
321
  return null;
322
- if (VOID_TEXT_TARGET_TAGS.has(inner.tagName))
322
+ if (VOID_TEXT_TARGET_TAGS.has(inner.tagName) || isNonContentElement(inner))
323
323
  return null;
324
324
  return inner;
325
325
  }
@@ -338,12 +338,19 @@ export function getOwnText(el) {
338
338
  });
339
339
  return text;
340
340
  }
341
- /** Replace the SDK text target without destroying multi-child element structure. */
341
+ /** The element, or its lone child, is a script, style or other non-content element. */
342
+ function declinesText(el) {
343
+ const lone = el.children.length === 1 ? el.firstElementChild : null;
344
+ return isNonContentElement(el) || (lone !== null && isNonContentElement(lone));
345
+ }
346
+ /** Replace the SDK text target, keeping multi-child structure; false, writing nothing, on non-content. */
342
347
  export function setOwnText(el, text) {
348
+ if (declinesText(el))
349
+ return false;
343
350
  const singleChild = resolveSingleChildTextTarget(el);
344
351
  if (singleChild) {
345
352
  singleChild.textContent = text;
346
- return;
353
+ return true;
347
354
  }
348
355
  const doc = el.ownerDocument;
349
356
  // Flat text leaf (text and/or `<br>` only): rebuild the text/`<br>` run from
@@ -362,7 +369,7 @@ export function setOwnText(el, text) {
362
369
  if (line)
363
370
  el.appendChild(doc.createTextNode(line));
364
371
  });
365
- return;
372
+ return true;
366
373
  }
367
374
  const children = Array.from(el.childNodes);
368
375
  // Track original position of the first text node so we restore there, not at firstChild.
@@ -383,6 +390,7 @@ export function setOwnText(el, text) {
383
390
  const ref = firstTextIdx >= 0 ? (current[firstTextIdx] ?? null) : null;
384
391
  el.insertBefore(doc.createTextNode(text), ref);
385
392
  }
393
+ return true;
386
394
  }
387
395
  // ─── CSS style helpers ────────────────────────────────────────────────────────
388
396
  function findStyleElement(document) {
@@ -4,7 +4,7 @@ import { idsToUnlink, linkedPartnerIds } from "./linkedTiming.js";
4
4
  import { resolveScoped, escapeHfId, findRoot, declarationElement, getElementStyles, setElementStyles, toCamel, getOwnText, setOwnText, getSiblingIndex, getGsapScript, findGsapScriptElement, setGsapScript, getStyleSheet, setStyleSheet, } from "./model.js";
5
5
  import { stylePath, textPath, attrPath, timingPath, holdPath, elementPath, variablePath, variableDeclPath, metaPath, gsapScriptPath, styleSheetPath, scalarChange, scalarDelete, valueChange, patchAdd, patchRemove, } from "./patches.js";
6
6
  import { upsertCssRule } from "./cssWriter.js";
7
- import { mintHfId, EXCLUDED_TAGS } from "@hyperframes/core/hf-ids";
7
+ import { mintHfId, EXCLUDED_TAGS, isNonContentElement } from "@hyperframes/core/hf-ids";
8
8
  import { EDIT_BASE_X_ATTR, EDIT_BASE_Y_ATTR } from "@hyperframes/core/runtime/position-edits";
9
9
  import { readClipTiming, writeClipTiming } from "@hyperframes/core/composition-contract";
10
10
  import { parseGsapScriptAcornForWrite } from "@hyperframes/core/gsap-parser-acorn";
@@ -61,6 +61,10 @@ export class UnsupportedOpError extends Error {
61
61
  function targets(target) {
62
62
  return Array.isArray(target) ? target : [target];
63
63
  }
64
+ function resolveEditable(document, id) {
65
+ const el = resolveScoped(document, id);
66
+ return el && !isNonContentElement(el) ? el : null;
67
+ }
64
68
  // ─── Op dispatch ────────────────────────────────────────────────────────────
65
69
  function dispatchRemoveGsapKeyframe(parsed, op) {
66
70
  return handleRemoveGsapKeyframeByPercentage(parsed, op.animationId, op.percentage);
@@ -283,7 +287,7 @@ export function applyOp(parsed, op) {
283
287
  function handleSetStyle(parsed, ids, styles) {
284
288
  const result = { forward: [], inverse: [] };
285
289
  for (const id of ids) {
286
- const el = resolveScoped(parsed.document, id);
290
+ const el = resolveEditable(parsed.document, id);
287
291
  if (!el)
288
292
  continue;
289
293
  const old = getElementStyles(el);
@@ -321,7 +325,7 @@ function handleMoveElement(parsed, ids, x, y) {
321
325
  // GSAP-animated transforms instead of being overwritten per-axis.
322
326
  const parts = [];
323
327
  for (const id of ids) {
324
- const el = resolveScoped(parsed.document, id);
328
+ const el = resolveEditable(parsed.document, id);
325
329
  if (!el)
326
330
  continue;
327
331
  if (el.getAttribute(EDIT_BASE_X_ATTR) === null) {
@@ -344,11 +348,12 @@ function handleMoveElement(parsed, ids, x, y) {
344
348
  function handleSetText(parsed, ids, value) {
345
349
  const result = { forward: [], inverse: [] };
346
350
  for (const id of ids) {
347
- const el = resolveScoped(parsed.document, id);
351
+ const el = resolveEditable(parsed.document, id);
348
352
  if (!el)
349
353
  continue;
350
354
  const oldText = getOwnText(el);
351
- setOwnText(el, value);
355
+ if (!setOwnText(el, value))
356
+ continue;
352
357
  const path = textPath(id);
353
358
  // getOwnText always returns string ("" for empty) — use it directly so
354
359
  // the forward patch is always op:'replace', not op:'add'. An op:'add' on
@@ -364,7 +369,7 @@ function handleSetAttribute(parsed, ids, name, value) {
364
369
  validateSetAttribute(name, value);
365
370
  const result = { forward: [], inverse: [] };
366
371
  for (const id of ids) {
367
- const el = resolveScoped(parsed.document, id);
372
+ const el = resolveEditable(parsed.document, id);
368
373
  if (!el)
369
374
  continue;
370
375
  const oldValue = el.getAttribute(name);
@@ -402,7 +407,7 @@ function handleSetTiming(parsed, ids, timing) {
402
407
  const clipRoot = scriptElement ? clipQueryRoot(scriptElement) : parsed.document;
403
408
  let currentScript = origScript;
404
409
  for (const id of ids) {
405
- const el = resolveScoped(parsed.document, id);
410
+ const el = resolveEditable(parsed.document, id);
406
411
  if (!el)
407
412
  continue;
408
413
  const beforeAttributes = {
@@ -522,7 +527,7 @@ function handleSetTiming(parsed, ids, timing) {
522
527
  function handleSetHold(parsed, ids, hold) {
523
528
  const result = { forward: [], inverse: [] };
524
529
  for (const id of ids) {
525
- const el = resolveScoped(parsed.document, id);
530
+ const el = resolveEditable(parsed.document, id);
526
531
  if (!el)
527
532
  continue;
528
533
  const fields = [
@@ -639,7 +644,7 @@ function handleAddElement(parsed, parent, index, html) {
639
644
  // _dispatch does not run validateOp, so a bad parent id must not crash here.
640
645
  const parentEl = parent === null
641
646
  ? (parsed.document.body ?? null)
642
- : resolveScoped(parsed.document, parent);
647
+ : resolveEditable(parsed.document, parent);
643
648
  if (!parentEl)
644
649
  return EMPTY;
645
650
  const node = parseInsertableFragment(parsed.document, html);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/sdk",
3
- "version": "0.9.92",
3
+ "version": "0.9.94",
4
4
  "description": "Headless, framework-neutral HyperFrames composition editing engine",
5
5
  "repository": {
6
6
  "type": "git",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "linkedom": "^0.18.12",
47
- "@hyperframes/parsers": "0.9.92",
48
- "@hyperframes/core": "0.9.92"
47
+ "@hyperframes/parsers": "0.9.94",
48
+ "@hyperframes/core": "0.9.94"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^25.0.10",