@hyperframes/core 0.9.15 → 0.9.17

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.
@@ -1 +1,2 @@
1
1
  export declare function hyperframesCacheDir(...parts: string[]): string;
2
+ export declare function namedCacheDir(...parts: string[]): string | undefined;
package/dist/cacheDir.js CHANGED
@@ -4,3 +4,6 @@ export function hyperframesCacheDir(...parts) {
4
4
  const named = process.env["HYPERFRAMES_CACHE_DIR"];
5
5
  return join(named ? resolve(named) : join(homedir(), ".cache", "hyperframes"), ...parts);
6
6
  }
7
+ export function namedCacheDir(...parts) {
8
+ return process.env["HYPERFRAMES_CACHE_DIR"] ? hyperframesCacheDir(...parts) : undefined;
9
+ }
@@ -14,7 +14,7 @@ import { compositionStyle, cssStyleMergeKey, hasSameLink, } from "./scriptRuns.j
14
14
  import { rewriteAssetPath, rewriteAssetPaths, rewriteCssAssetUrls, rewriteInlineStyleAssetUrls, } from "./rewriteSubCompPaths.js";
15
15
  import { warnUnknownEnumValues } from "../runtime/getVariables.js";
16
16
  import { createCompositionCssScoper, AUTHORED_SOURCE_BEGIN, AUTHORED_SOURCE_END, wrapInlineScriptWithErrorBoundary, scopedModulePrelude, wrapScopedCompositionScript, } from "./compositionScoping.js";
17
- import { namespaceCollidingSvgIds, rewriteSvgIdReferencesInCss, } from "./svgIdNamespacing.js";
17
+ import { namespaceCollidingSvgIds, sceneClipRoots, rewriteSvgIdReferencesInCss, } from "./svgIdNamespacing.js";
18
18
  import { checkSubCompositionUsability, resolveSubCompositionContent, } from "@hyperframes/parsers/sub-composition-validity";
19
19
  import { enumerateNestedCompositionHosts, planCompositionAssembly, extractedCompositionAssets, } from "./compositionAssembly.js";
20
20
  import { SCENE_NO_SWAP_ATTR, SCENE_PART_ATTR } from "../sceneParts.js";
@@ -544,6 +544,8 @@ export function inlineSubCompositions(document, hosts, options) {
544
544
  // `<style>` text gets the same substitution its DOM just received. See
545
545
  // svgIdNamespacing.ts for why this is a rename, unlike the sibling
546
546
  // getElementById/media-id fixes.
547
+ const hostRoots = svgIdScopes.map(({ root }) => root);
548
+ const clips = sceneClipRoots(document, hostRoots);
547
549
  const svgIdMaps = namespaceCollidingSvgIds(document, [
548
550
  ...svgIdScopes.map(({ root, namespace, exclude, styleStart, styleEnd }) => ({
549
551
  root,
@@ -555,9 +557,14 @@ export function inlineSubCompositions(document, hosts, options) {
555
557
  root: document.documentElement,
556
558
  namespace: "",
557
559
  referenceTarget: "document",
558
- exclude: svgIdScopes.map(({ root }) => root),
560
+ exclude: [...hostRoots, ...clips],
559
561
  cssTexts: rootStyles.map((style) => style.textContent ?? ""),
560
562
  },
563
+ ...clips.map((root, index) => ({
564
+ root,
565
+ namespace: `clip-${index}`,
566
+ exclude: hostRoots.filter((host) => root.contains(host)),
567
+ })),
561
568
  ]);
562
569
  svgIdMaps.slice(0, svgIdScopes.length).forEach((idMap, index) => {
563
570
  const { styleStart, styleEnd } = svgIdScopes[index];
@@ -1,8 +1,6 @@
1
- import { collectExternalStyles, lintHyperframeHtml } from "@hyperframes/lint";
1
+ import { linkedSources, lintHyperframeHtml } from "@hyperframes/lint";
2
2
  export async function validateHyperframeHtmlContract(html, project) {
3
- const result = await lintHyperframeHtml(html, project && {
4
- externalStyles: collectExternalStyles(project.dir, html, project.compSrcPath),
5
- });
3
+ const result = await lintHyperframeHtml(html, project && linkedSources(project.dir, html, project.compSrcPath));
6
4
  const missingKeys = result.findings
7
5
  .filter((finding) => finding.severity === "error")
8
6
  .map((finding) => finding.message);
@@ -45,6 +45,9 @@ export interface SvgIdScope {
45
45
  */
46
46
  cssTexts?: readonly string[];
47
47
  }
48
+ /** The outermost timed clips holding an `<svg>` outside every composition host. Each is its own id scope, as an
49
+ * inlined composition is, so two scenes drawn with the same ids each resolve their own `url(#id)` and `href`. */
50
+ export declare function sceneClipRoots(document: SvgIdQueryable, hosts: readonly Element[]): Element[];
48
51
  /**
49
52
  * Rename every colliding, natively-referenced SVG id across the inlined
50
53
  * composition instances in `scopes` and rewrite each instance's attribute
@@ -312,6 +312,15 @@ function applyRenames(resolved, idMap) {
312
312
  rewriteElementIdReferences(el, idMap);
313
313
  }
314
314
  }
315
+ const CLIP_SELECTOR = "[data-start]:not([data-composition-id]):not([data-composition-src])";
316
+ /** The outermost timed clips holding an `<svg>` outside every composition host. Each is its own id scope, as an
317
+ * inlined composition is, so two scenes drawn with the same ids each resolve their own `url(#id)` and `href`. */
318
+ export function sceneClipRoots(document, hosts) {
319
+ return [...document.querySelectorAll(CLIP_SELECTOR)].filter((clip) => !clip.parentElement?.closest(CLIP_SELECTOR) &&
320
+ !!clip.parentElement?.closest("[data-composition-id]") &&
321
+ !isExcluded(clip, hosts) &&
322
+ !!clip.querySelector("svg"));
323
+ }
315
324
  /**
316
325
  * Rename every colliding, natively-referenced SVG id across the inlined
317
326
  * composition instances in `scopes` and rewrite each instance's attribute
@@ -37,7 +37,6 @@ function isActiveAtFirstFrame(element, resolver, timelineRegistry) {
37
37
  currentTime: 0,
38
38
  compositionDuration: Number.POSITIVE_INFINITY,
39
39
  canonicalFps: 30,
40
- exportRenderSeek: false,
41
40
  timelineRegistry,
42
41
  resolver,
43
42
  }))
@@ -1,5 +1,5 @@
1
1
  // Generated by scripts/build-position-edits-render.ts; do not edit.
2
- const POSITION_EDITS_RENDER_IIFE = '"use strict";(()=>{function x(){return globalThis}function T(e,t){if(typeof window>"u")return;let o=x(),r=o.__hf?.onSwallowed;if(r)try{r({label:e,error:t})}catch(s){}(o.__hfDebug||o.__HYPERFRAMES_DEBUG)&&console.debug(`[hyperframes] ${e} swallowed:`,t)}var P=null;function R(e,t){if(P)try{P({source:"hf-preview",type:"analytics",event:e,properties:t??{}})}catch(o){T("runtime.analytics.site1",o)}}var I="http://www.w3.org/1999/xhtml";function N(e){return e!=null&&e.nodeType===1}function _(e){return N(e)&&(e.namespaceURI===I||e.namespaceURI==="http://www.w3.org/2000/svg")}var y="data-hf-edit-base-x",w="data-hf-edit-base-y",m="data-hf-edit-original-translate",k=e=>{let t=parseFloat(e??"");return Number.isFinite(t)?t:0},C=e=>{let t=[],o=0,r="";for(let s of e.trim())s==="("&&(o+=1),s===")"&&(o=Math.max(0,o-1)),/\\s/.test(s)&&o===0?(r&&t.push(r),r=""):r+=s;return r&&t.push(r),t},$=/^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)px$/,E=(e,t)=>$.test(e)&&$.test(t)?`${parseFloat(e)+parseFloat(t)}px`:`calc(${e} + ${t})`,O=(e,t,o)=>{if(!e||e==="none")return`${t} ${o}`;let[r,s,a]=C(e);if(r===void 0)return`${t} ${o}`;if(s===void 0)return`${E(r,t)} ${o}`;let i=a===void 0?"":` ${a}`;return`${E(r,t)} ${E(s,o)}${i}`},j=e=>{try{e.ownerDocument.defaultView?.gsap?.getProperty?.(e,"x")}catch{}},V=e=>{let t=e.style.getPropertyValue("translate").trim();if(t)return t==="none"?"":t;try{let o=e.ownerDocument.defaultView,r=o?o.getComputedStyle(e).getPropertyValue("translate").trim():"";return r==="none"?"":r}catch{return""}},b=new WeakMap;function B(e,t){let o=b.get(e);if(!t?.force&&o!==void 0&&e.style.getPropertyValue("translate")!==o){R("position_edit_fold_skipped",{hfId:e.getAttribute("data-hf-id")});return}let r=k(e.getAttribute("data-x"))-k(e.getAttribute(y)),s=k(e.getAttribute("data-y"))-k(e.getAttribute(w));e.hasAttribute(m)||e.setAttribute(m,V(e)),o===void 0&&j(e);let a=e.getAttribute(m)??"",i=O(a,`${r}px`,`${s}px`);e.style.setProperty("translate",i),b.set(e,e.style.getPropertyValue("translate"))}function S(e,t){let o=e.querySelectorAll(`[${m}]:not([${y}]):not([${w}])`);for(let a=0;a<o.length;a++){let i=o[a];if(i===void 0||!_(i))continue;let g=i.getAttribute(m)??"";g===""?i.style.removeProperty("translate"):i.style.setProperty("translate",g),i.removeAttribute(m),b.delete(i)}let r=e.querySelectorAll(`[${y}], [${w}]`),s=0;for(let a=0;a<r.length;a++){let i=r[a];i===void 0||!_(i)||(B(i,t),s+=1)}return s}var L="__hfPositionEditsSeekReapplyWrapped",D=new WeakSet,F=new WeakMap,H=new WeakMap;function M(e){let t=e,o=()=>{try{S(t.document)}catch{}},r=n=>typeof n=="function"&&(D.has(n)||!!n[L]),s=n=>{D.add(n);try{Object.defineProperty(n,L,{value:!0})}catch{}},a=n=>{if(typeof n!="function"||r(n))return n;let l=function(...u){let d=n.apply(this,u);return o(),d};return s(l),l},i=(n,l)=>{let u=F.get(n);if(u?.has(l))return!0;let d=Object.getOwnPropertyDescriptor(n,l);if(d?.configurable===!1){let c=n[l];return typeof c=="function"&&(n[l]=a(c),o()),!1}let p=n[l],f=d?.set;return Object.defineProperty(n,l,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>p,set:c=>{p=a(c),f?.call(n,c)}}),p=a(p),u??(u=new Set),u.add(l),F.set(n,u),o(),!0},g=(n,l)=>{let u=H.get(t),d=Object.getOwnPropertyDescriptor(t,n);if(!u?.has(n)){if(d?.configurable===!1){let c=t[n];return c?i(c,l):!1}let f=t[n];Object.defineProperty(t,n,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>f,set:c=>{f=c,f&&i(f,l)}}),u??(u=new Set),u.add(n),H.set(t,u)}let p=t[n];return p?i(p,l):!1},h=()=>{let n=g("__hf","seek"),l=g("__player","renderSeek");return n&&l};if(h())return;let v=120,A=t.setInterval(()=>{if(h()){t.clearInterval(A);return}v-=1,v<=0&&t.clearInterval(A)},50)}function W(){document.querySelector(`[${y}], [${w}]`)&&(S(document),M(window))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",W,{once:!0}):W();})();\n';
2
+ const POSITION_EDITS_RENDER_IIFE = '"use strict";(()=>{function x(){return globalThis}function R(e,t){if(typeof window>"u")return;let o=x(),r=o.__hf?.onSwallowed;if(r)try{r({label:e,error:t})}catch(s){}(o.__hfDebug||o.__HYPERFRAMES_DEBUG)&&console.debug(`[hyperframes] ${e} swallowed:`,t)}var T=null;function P(e,t){if(T)try{T({source:"hf-preview",type:"analytics",event:e,properties:t??{}})}catch(o){R("runtime.analytics.site1",o)}}var I="http://www.w3.org/1999/xhtml";function N(e){return e!=null&&e.nodeType===1}function k(e){return N(e)&&(e.namespaceURI===I||e.namespaceURI==="http://www.w3.org/2000/svg")}var w="data-hf-edit-base-x",y="data-hf-edit-base-y",m="data-hf-edit-original-translate",_=e=>{let t=parseFloat(e??"");return Number.isFinite(t)?t:0},C=e=>{let t=[],o=0,r="";for(let s of e.trim())s==="("&&(o+=1),s===")"&&(o=Math.max(0,o-1)),/\\s/.test(s)&&o===0?(r&&t.push(r),r=""):r+=s;return r&&t.push(r),t},$=/^-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)px$/,E=(e,t)=>$.test(e)&&$.test(t)?`${parseFloat(e)+parseFloat(t)}px`:`calc(${e} + ${t})`,O=(e,t,o)=>{if(!e||e==="none")return`${t} ${o}`;let[r,s,a]=C(e);if(r===void 0)return`${t} ${o}`;if(s===void 0)return`${E(r,t)} ${o}`;let i=a===void 0?"":` ${a}`;return`${E(r,t)} ${E(s,o)}${i}`},j=e=>{try{e.ownerDocument.defaultView?.gsap?.getProperty?.(e,"x")}catch{}},B=e=>{let t=e.style.getPropertyValue("translate").trim();if(t)return t==="none"?"":t;try{let o=e.ownerDocument.defaultView,r=o?o.getComputedStyle(e).getPropertyValue("translate").trim():"";return r==="none"?"":r}catch{return""}},b=new WeakMap;function V(e,t){let o=b.get(e);if(!t?.force&&o!==void 0&&e.style.getPropertyValue("translate")!==o){P("position_edit_fold_skipped",{hfId:e.getAttribute("data-hf-id")});return}let r=_(e.getAttribute("data-x"))-_(e.getAttribute(w)),s=_(e.getAttribute("data-y"))-_(e.getAttribute(y));e.hasAttribute(m)||e.setAttribute(m,B(e)),o===void 0&&j(e);let a=e.getAttribute(m)??"",i=O(a,`${r}px`,`${s}px`);e.style.setProperty("translate",i),b.set(e,e.style.getPropertyValue("translate"))}function h(e,t){let o=e.querySelectorAll(`[${m}]:not([${w}]):not([${y}])`);for(let a=0;a<o.length;a++){let i=o[a];if(i===void 0||!k(i))continue;let g=i.getAttribute(m)??"";g===""?i.style.removeProperty("translate"):i.style.setProperty("translate",g),i.removeAttribute(m),b.delete(i)}let r=e.querySelectorAll(`[${w}], [${y}]`),s=0;for(let a=0;a<r.length;a++){let i=r[a];i===void 0||!k(i)||(V(i,t),s+=1)}return s}var L="__hfPositionEditsSeekReapplyWrapped",D=new WeakSet,F=new WeakMap,H=new WeakMap;function W(e){let t=e,o=()=>{try{h(t.document)}catch{}},r=n=>typeof n=="function"&&(D.has(n)||!!n[L]),s=n=>{D.add(n);try{Object.defineProperty(n,L,{value:!0})}catch{}},a=n=>{if(typeof n!="function"||r(n))return n;let l=function(...u){let d=n.apply(this,u);return o(),d};return s(l),l},i=(n,l)=>{let u=F.get(n);if(u?.has(l))return!0;let d=Object.getOwnPropertyDescriptor(n,l);if(d?.configurable===!1){let c=n[l];return typeof c=="function"&&(n[l]=a(c),o()),!1}let p=n[l],f=d?.set;return Object.defineProperty(n,l,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>p,set:c=>{p=a(c),f?.call(n,c)}}),p=a(p),u??(u=new Set),u.add(l),F.set(n,u),o(),!0},g=(n,l)=>{let u=H.get(t),d=Object.getOwnPropertyDescriptor(t,n);if(!u?.has(n)){if(d?.configurable===!1){let c=t[n];return c?i(c,l):!1}let f=t[n];Object.defineProperty(t,n,{configurable:!0,enumerable:d?.enumerable??!0,get:()=>f,set:c=>{f=c,f&&i(f,l)}}),u??(u=new Set),u.add(n),H.set(t,u)}let p=t[n];return p?i(p,l):!1},S=()=>{let n=g("__hf","seek"),l=g("__player","renderSeek");return n&&l};if(S())return;let v=120,A=t.setInterval(()=>{if(S()){t.clearInterval(A);return}v-=1,v<=0&&t.clearInterval(A)},50)}function M(){document.querySelector(`[${w}], [${y}]`)&&(h(document),W(window))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",M,{once:!0}):M();})();\n';
3
3
  /** Returns the pre-built position-edits render IIFE as a string constant. */
4
4
  export function getPositionEditsRenderScript() {
5
5
  return POSITION_EDITS_RENDER_IIFE;