@hyperframes/studio 0.9.63 → 0.9.64
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/assets/{hyperframes-player-CUQxAJaE.js → hyperframes-player-mSF_GvRs.js} +1 -1
- package/dist/assets/{index-DSrTQv-k.js → index-CVmmHGol.js} +130 -130
- package/dist/assets/{index-D3rdYBVx.js → index-DN167Uqf.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-BWllfjF-.js → pausedVideoDecoder-C8rhpGPx.js} +1 -1
- package/dist/{chunk-UM4CLD4M.js → chunk-OJLNM6V5.js} +1 -1
- package/dist/{chunk-ZUDVUI7K.js → chunk-VDDEXNVX.js} +1 -1
- package/dist/{chunk-OOGQ5KCC.js → chunk-YQ3ZAXXY.js} +8 -27
- package/dist/{domEditingLayers-IHYA42AJ.js → domEditingLayers-YYHWRNF4.js} +2 -2
- package/dist/index.html +1 -1
- package/dist/index.js +36 -72
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +98 -0
- package/src/player/hooks/useTimelineSyncCallbacks.ts +23 -8
- package/src/player/lib/playbackTypes.ts +0 -2
- package/src/player/lib/timelineElementHelpers.ts +7 -42
- package/src/player/lib/timelineIframeHelpers.test.ts +18 -137
- package/src/player/lib/timelineIframeHelpers.ts +15 -94
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Input as V,ALL_FORMATS as G,UrlSource as K,VideoSampleSink as Q}from"./index-
|
|
1
|
+
import{Input as V,ALL_FORMATS as G,UrlSource as K,VideoSampleSink as Q}from"./index-DN167Uqf.js";import{l as X}from"./index-CVmmHGol.js";const x=1e-5,k=1e-9,T=h=>!h.variableFrameRate&&(h.frameRate??0)>0;function Y(h,s){const{sourceLead:r,inputLead:l,timeResolution:d,frameRate:p=0}=s;if(!T(s))return Math.max(l,h-r+l)+k;const w=Math.max(0,Math.floor((h-r)*p+k)),f=l+w/p;return(d>0?Math.round(f*d)/d:f)+x}function J(h,s,r){const{frameRate:l=0,sourceLead:d,inputLead:p}=r,w=T(r)?Math.round((h-p)*l)/l+d:h-p+d,f=Math.min(s,w);return{timestamp:f,duration:Math.max(T(r)?1/l:0,s-f+x)}}const E=64*1024*1024,M=4,Z=.5,$=2e3;async function q(h,s){if(!h.transparent)return h.sink.getSample(s);let r=null;try{for await(const l of h.sink.samplesAtTimestamps([s]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function ot(h){const s=new Map,r=new Map,l=new Map,d=new Map,p=new Map;let w=0,f=!1;const _=t=>{var o,n;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(n=Object.entries(((o=h.contentWindow)==null?void 0:o.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([i])=>e.endsWith(i)).sort(([i],[a])=>a.length-i.length)[0])==null?void 0:n[1]},b=(t=E)=>{for(const[e,o]of p){if(w<=t)break;e.pins>0||(p.delete(e),o.cache.delete(e.timestamp),w-=e.bytes,e.image.close())}},v=async t=>{if(t.disposed)return;t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key);const e=(async()=>{t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const o of t.cache.values())p.delete(o),w-=o.bytes,o.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0})();return t.transparent?new Promise((o,n)=>{const i=setTimeout(()=>{t.cancelReads(),o()},$);e.then(o,n).finally(()=>clearTimeout(i))}):e},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(s.delete(t.key),v(t))},1e4))},D=async t=>{const e=X("thumbnail"),o=new V({source:new K(t,e),formats:G});l.set(o,e.cancelReads);try{const n=await o.getPrimaryVideoTrack();if(!n||f)throw new Error("Preview video unavailable");const[i,a,u,c,m,S,F,B,j]=await Promise.all([n.getDisplayWidth(),n.getDisplayHeight(),n.getFirstTimestamp(),n.getTimeResolution(),n.getSquarePixelWidth(),n.getSquarePixelHeight(),n.getRotation(),n.getFlip(),n.canBeTransparent()]),g=document.createElement("canvas");g.width=Math.max(1,Math.ceil(i));const z=F%180===0?m/S:S/m;return g.height=Math.max(1,Math.round(g.width/z)),{key:t,input:o,cancelReads:e.cancelReads,sink:new Q(n),canvas:g,rotation:F,flip:B,width:i,height:a,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(n){throw o.dispose(),e.cancelReads(),n}finally{l.delete(o)}},I=()=>{for(const[t]of s){if(s.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(o=>o.pins>0)&&(s.delete(t),v(e))}if(s.size>=M)throw new Error("Preview decoder budget reached")},L=async t=>{const e=t;if((d.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let o=s.get(e);o||(I(),o=D(t),s.set(e,o)),s.delete(e),s.set(e,o);let n;try{n=await o}catch(i){throw s.get(e)===o&&(s.delete(e),d.set(e,performance.now()+5e3)),i}if(f||n.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,n),n.users++,clearTimeout(n.idleTimer),n},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},R=(t,e)=>{if(e.throwIfAborted(),f||t.disposed)throw new Error("Preview disposed")},O=async(t,e,o)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){R(t,o);const n=await t.iterator.next();if(n.done)return null;const i=n.value;let a=!1;try{if(R(t,o),i.timestamp>e+1e-6)return null;if(a=i.timestamp+i.duration>e+1e-6,a)return i}finally{a||i.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,o,n,i)=>{const a=t.canvas.getContext("2d",{alpha:!0});if(!a)throw new Error("Preview canvas unavailable");a.clearRect(0,0,t.canvas.width,t.canvas.height),a.imageSmoothingQuality="high",e.drawWithFit(a,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(i.aborted||f||t.disposed)throw u.close(),i.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,o,n),bytes:u.width*u.height*4,pins:1},m=t.cache.get(c.timestamp);if(m)return m.duration=Math.max(m.duration,c.duration),u.close(),A(t,m);if(b(E-c.bytes),w+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),w+=c.bytes,c},U=(t,e,o)=>!t.transparent&&!o.variableFrameRate&&(o.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,C=async(t,e,o,n)=>{R(t,n);const i=[...t.cache.values()].find(m=>e>=m.timestamp-1e-6&&e<m.timestamp+m.duration-1e-6);if(i)return A(t,i);const a=Y(e,o),u=U(t,e,o);let c=null;try{if((!u||a>=t.iteratorEnd)&&await y(t),c=u?await O(t,a,n):null,c||(await y(t),c=await q(t,a)),!c)throw new Error("No preview frame at requested time");return R(t,n),t.lastTime=e,await W(t,c,e,o,n)}finally{c==null||c.close(),(n.aborted||f)&&await y(t).catch(()=>{})}},H=(t,e)=>{const o=_(t.source);return{frameRate:o==null?void 0:o.frameRate,variableFrameRate:o==null?void 0:o.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},N=async(t,e)=>{e.throwIfAborted();const o=t.source;if(!o)throw new Error("Preview source unavailable");const n=await L(o);try{const i=H(t,n),a=n.tail.then(()=>C(n,t.time,i,e));n.tail=a.then(()=>{},()=>{});const u=await a;let c=!1;return b(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:n.width,height:n.height,release(){c||(c=!0,u.pins--,b(),P(n))}}}finally{n.users--,P(n)}};return{async decode(t,e){if(f)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:a})=>a)).size>M)throw new Error("Preview decoder budget reached");const o=await Promise.allSettled(t.map(a=>N(a,e))),n=o.find(a=>a.status==="rejected"),i=o.flatMap(a=>a.status==="fulfilled"?[a.value]:[]);if(n||f||e.aborted){for(const a of i)a.release();throw n?n.reason:new DOMException("Preview cancelled","AbortError")}return i},async suspend(){const t=[...s.values()].map(e=>e.then(v).catch(()=>{}));s.clear();for(const[e,o]of l)o(),e.dispose();await Promise.all(t)},dispose(){if(!f){f=!0;for(const[t,e]of l)e(),t.dispose();for(const t of s.values())t.then(v).catch(()=>{});s.clear(),d.clear()}}}}export{ot as createPausedVideoDecoder};
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
querySelectorAllSafely,
|
|
19
19
|
studioApiFetch,
|
|
20
20
|
withSelectorIndexPass
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-YQ3ZAXXY.js";
|
|
22
22
|
|
|
23
23
|
// src/components/editor/domEditingLayers.ts
|
|
24
24
|
import { isClipHiddenByRuntime, PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
|
|
@@ -437,6 +437,12 @@ function sameTimelineText(a, b) {
|
|
|
437
437
|
return a.value === b.value && a.fontFamily === b.fontFamily && a.fontWeight === b.fontWeight && a.color === b.color && a.background === b.background;
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
// src/player/lib/timelineElementHelpers.ts
|
|
441
|
+
import {
|
|
442
|
+
previewElementFinder,
|
|
443
|
+
previewElementSourceFile as getTimelineElementSourceFile
|
|
444
|
+
} from "@hyperframes/core/studio-preview-mark";
|
|
445
|
+
|
|
440
446
|
// src/player/lib/playbackAdapter.ts
|
|
441
447
|
function isFinitePositive(value) {
|
|
442
448
|
return Number.isFinite(value) && value > 0;
|
|
@@ -749,10 +755,6 @@ function getTimelineElementSelector(el) {
|
|
|
749
755
|
}
|
|
750
756
|
return void 0;
|
|
751
757
|
}
|
|
752
|
-
function getTimelineElementSourceFile(el) {
|
|
753
|
-
const ownerRoot = el.parentElement?.closest("[data-composition-id]");
|
|
754
|
-
return ownerRoot?.getAttribute("data-composition-file") ?? ownerRoot?.getAttribute("data-composition-src") ?? void 0;
|
|
755
|
-
}
|
|
756
758
|
function getTimelineElementSelectorIndex(doc, el, selector) {
|
|
757
759
|
return getSourceScopedSelectorIndex(
|
|
758
760
|
doc,
|
|
@@ -849,27 +851,6 @@ function findInClipScope(doc, clip, selectors) {
|
|
|
849
851
|
}
|
|
850
852
|
return lone;
|
|
851
853
|
}
|
|
852
|
-
function previewElementFinder(doc, selector = "[data-hf-id], [id]") {
|
|
853
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
854
|
-
const add = (key, node) => {
|
|
855
|
-
const nodes = byKey.get(key);
|
|
856
|
-
if (nodes) nodes.push(node);
|
|
857
|
-
else byKey.set(key, [node]);
|
|
858
|
-
};
|
|
859
|
-
for (const node of doc.querySelectorAll(selector)) {
|
|
860
|
-
const hfId = node.getAttribute("data-hf-id");
|
|
861
|
-
const id = node.getAttribute("id");
|
|
862
|
-
if (hfId) add(`hf:${hfId}`, node);
|
|
863
|
-
if (id) add(`id:${id}`, node);
|
|
864
|
-
}
|
|
865
|
-
return (target) => {
|
|
866
|
-
const matches = [
|
|
867
|
-
...target.hfId && byKey.get(`hf:${target.hfId}`) || [],
|
|
868
|
-
...byKey.get(`id:${target.domId ?? target.id}`) ?? []
|
|
869
|
-
];
|
|
870
|
-
return matches.find((node) => getTimelineElementSourceFile(node) === target.sourceFile) ?? matches[0] ?? null;
|
|
871
|
-
};
|
|
872
|
-
}
|
|
873
854
|
function findClipElementById(doc, clip) {
|
|
874
855
|
if (!clip.id) return null;
|
|
875
856
|
const first = doc.getElementById(clip.id);
|
|
@@ -1096,6 +1077,8 @@ export {
|
|
|
1096
1077
|
wrapTimeline,
|
|
1097
1078
|
parseStoredVolume,
|
|
1098
1079
|
elementVolume,
|
|
1080
|
+
previewElementFinder,
|
|
1081
|
+
getTimelineElementSourceFile,
|
|
1099
1082
|
LAYER_REVEAL_PRIOR_Z_ATTR,
|
|
1100
1083
|
LAYER_REVEAL_PRIOR_POSITION_ATTR,
|
|
1101
1084
|
readLayerRevealPriorZ,
|
|
@@ -1111,7 +1094,6 @@ export {
|
|
|
1111
1094
|
applyMediaMetadataFromElement,
|
|
1112
1095
|
getTimelineElementDisplayLabel,
|
|
1113
1096
|
getTimelineElementSelector,
|
|
1114
|
-
getTimelineElementSourceFile,
|
|
1115
1097
|
getTimelineElementSelectorIndex,
|
|
1116
1098
|
buildTimelineElementKey,
|
|
1117
1099
|
splitTimelineElementKey,
|
|
@@ -1120,7 +1102,6 @@ export {
|
|
|
1120
1102
|
runtimeAudioId,
|
|
1121
1103
|
deriveTimelineStoreKey,
|
|
1122
1104
|
deriveTimelineStoreKeyForDomId,
|
|
1123
|
-
previewElementFinder,
|
|
1124
1105
|
findClipElementById,
|
|
1125
1106
|
createTimelineDomNodeResolver,
|
|
1126
1107
|
isSdkFamilyEnabled,
|
|
@@ -20,8 +20,8 @@ import {
|
|
|
20
20
|
resolveDomEditCapabilities,
|
|
21
21
|
resolveDomEditSelection,
|
|
22
22
|
serializeDomEditTextFields
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import "./chunk-
|
|
23
|
+
} from "./chunk-OJLNM6V5.js";
|
|
24
|
+
import "./chunk-YQ3ZAXXY.js";
|
|
25
25
|
import "./chunk-MLKGABMK.js";
|
|
26
26
|
export {
|
|
27
27
|
buildDefaultDomEditTextField,
|
package/dist/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
document.documentElement.dataset.theme = "paper";
|
|
15
15
|
}
|
|
16
16
|
</script>
|
|
17
|
-
<script type="module" crossorigin src="/assets/index-
|
|
17
|
+
<script type="module" crossorigin src="/assets/index-CVmmHGol.js"></script>
|
|
18
18
|
<link rel="stylesheet" crossorigin href="/assets/index-CRiuMxyq.css">
|
|
19
19
|
</head>
|
|
20
20
|
<body>
|
package/dist/index.js
CHANGED
|
@@ -92,7 +92,7 @@ import {
|
|
|
92
92
|
whileScriptWrites,
|
|
93
93
|
writeStudioUiPreferences,
|
|
94
94
|
zoomToSelectedClips
|
|
95
|
-
} from "./chunk-
|
|
95
|
+
} from "./chunk-VDDEXNVX.js";
|
|
96
96
|
import {
|
|
97
97
|
Button,
|
|
98
98
|
ContextMenu,
|
|
@@ -159,7 +159,7 @@ import {
|
|
|
159
159
|
selectionTargetIndex,
|
|
160
160
|
serializeDomEditTextFields,
|
|
161
161
|
timelineElementLookup
|
|
162
|
-
} from "./chunk-
|
|
162
|
+
} from "./chunk-OJLNM6V5.js";
|
|
163
163
|
import {
|
|
164
164
|
CURATED_STYLE_PROPERTIES,
|
|
165
165
|
LAYER_REVEAL_PRIOR_POSITION_ATTR,
|
|
@@ -234,7 +234,7 @@ import {
|
|
|
234
234
|
toHexColor,
|
|
235
235
|
withSelectorIndexPass,
|
|
236
236
|
wrapTimeline
|
|
237
|
-
} from "./chunk-
|
|
237
|
+
} from "./chunk-YQ3ZAXXY.js";
|
|
238
238
|
import {
|
|
239
239
|
MediaFetchError,
|
|
240
240
|
mediaUrlSourceOptions,
|
|
@@ -29701,77 +29701,26 @@ function resolveIframe(el) {
|
|
|
29701
29701
|
if (el instanceof HTMLIFrameElement) return el;
|
|
29702
29702
|
return el.shadowRoot?.querySelector("iframe") ?? el.querySelector("iframe") ?? null;
|
|
29703
29703
|
}
|
|
29704
|
-
var
|
|
29705
|
-
var scrubAudioEl = null;
|
|
29706
|
-
var scrubStopTimer = null;
|
|
29707
|
-
var scrubPrevMuted = null;
|
|
29708
|
-
var scrubPrevVolume = null;
|
|
29709
|
-
function isAudioNode(node) {
|
|
29710
|
-
return node !== null && node.namespaceURI === "http://www.w3.org/1999/xhtml" && node.localName === "audio";
|
|
29711
|
-
}
|
|
29712
|
-
function resolveScrubAudioEl(doc, music) {
|
|
29713
|
-
if (music) {
|
|
29714
|
-
const byId = previewElementFinder(doc, "audio")(music);
|
|
29715
|
-
if (isAudioNode(byId)) return byId;
|
|
29716
|
-
}
|
|
29717
|
-
return doc.querySelector("audio[data-timeline-role='music']");
|
|
29718
|
-
}
|
|
29719
|
-
function leaseScrubElement(el) {
|
|
29720
|
-
el.ownerDocument.defaultView?.__hf?.leasePausedMedia?.(el);
|
|
29721
|
-
}
|
|
29722
|
-
function releaseScrubElement(el) {
|
|
29723
|
-
el.ownerDocument.defaultView?.__hf?.releasePausedMedia?.(el);
|
|
29724
|
-
}
|
|
29725
|
-
function applyScrub(el, audioFileTime, previewVolume) {
|
|
29726
|
-
if (scrubAudioEl && scrubAudioEl !== el) stopScrubPreviewAudio();
|
|
29727
|
-
if (scrubPrevMuted === null) scrubPrevMuted = el.muted;
|
|
29728
|
-
if (scrubPrevVolume === null) scrubPrevVolume = el.volume;
|
|
29729
|
-
scrubAudioEl = el;
|
|
29730
|
-
leaseScrubElement(el);
|
|
29731
|
-
try {
|
|
29732
|
-
el.muted = false;
|
|
29733
|
-
el.volume = SCRUB_VOLUME * normalizePreviewVolume(previewVolume);
|
|
29734
|
-
if (Math.abs(el.currentTime - audioFileTime) > 0.04) el.currentTime = audioFileTime;
|
|
29735
|
-
if (el.paused) void el.play().catch(() => {
|
|
29736
|
-
});
|
|
29737
|
-
} catch {
|
|
29738
|
-
}
|
|
29739
|
-
if (scrubStopTimer) clearTimeout(scrubStopTimer);
|
|
29740
|
-
scrubStopTimer = setTimeout(stopScrubPreviewAudio, 140);
|
|
29741
|
-
}
|
|
29704
|
+
var scrubFrame = null;
|
|
29742
29705
|
function scrubPreviewAudio(iframe, audioFileTime, music, previewVolume = 1) {
|
|
29743
29706
|
if (!iframe) return;
|
|
29744
29707
|
if (audioFileTime === null) {
|
|
29745
29708
|
stopScrubPreviewAudio();
|
|
29746
29709
|
return;
|
|
29747
29710
|
}
|
|
29748
|
-
|
|
29749
|
-
|
|
29750
|
-
|
|
29751
|
-
}
|
|
29752
|
-
|
|
29753
|
-
|
|
29754
|
-
|
|
29755
|
-
|
|
29756
|
-
|
|
29711
|
+
const frame3 = iframe.contentWindow;
|
|
29712
|
+
if (scrubFrame && scrubFrame !== frame3) stopScrubPreviewAudio();
|
|
29713
|
+
scrubFrame = frame3;
|
|
29714
|
+
const target = music ? { id: music.id, hfId: music.hfId, domId: music.domId, sourceFile: music.sourceFile } : null;
|
|
29715
|
+
postRuntimeControlMessage(frame3, "scrub-audio", {
|
|
29716
|
+
target,
|
|
29717
|
+
time: audioFileTime,
|
|
29718
|
+
volume: normalizePreviewVolume(previewVolume)
|
|
29719
|
+
});
|
|
29757
29720
|
}
|
|
29758
29721
|
function stopScrubPreviewAudio() {
|
|
29759
|
-
|
|
29760
|
-
|
|
29761
|
-
scrubStopTimer = null;
|
|
29762
|
-
}
|
|
29763
|
-
const el = scrubAudioEl;
|
|
29764
|
-
scrubAudioEl = null;
|
|
29765
|
-
if (!el) return;
|
|
29766
|
-
releaseScrubElement(el);
|
|
29767
|
-
try {
|
|
29768
|
-
el.pause();
|
|
29769
|
-
if (scrubPrevMuted !== null) el.muted = scrubPrevMuted;
|
|
29770
|
-
if (scrubPrevVolume !== null) el.volume = scrubPrevVolume;
|
|
29771
|
-
} catch {
|
|
29772
|
-
}
|
|
29773
|
-
scrubPrevMuted = null;
|
|
29774
|
-
scrubPrevVolume = null;
|
|
29722
|
+
postRuntimeControlMessage(scrubFrame, "scrub-audio", { time: null });
|
|
29723
|
+
scrubFrame = null;
|
|
29775
29724
|
}
|
|
29776
29725
|
function timelineDuration(iframeWin, compositionId) {
|
|
29777
29726
|
return iframeWin.__timelines?.[compositionId]?.duration?.() ?? 0;
|
|
@@ -30499,15 +30448,12 @@ function useTimelineSyncCallbacks({
|
|
|
30499
30448
|
onLoadGiveUp,
|
|
30500
30449
|
hostOwnsDeadline
|
|
30501
30450
|
}) {
|
|
30502
|
-
const
|
|
30503
|
-
(data) => {
|
|
30504
|
-
if (!data.clips) return;
|
|
30505
|
-
usePlayerStore.getState().setClipManifest(data.clips);
|
|
30451
|
+
const applyTimelineMessage = useCallback38(
|
|
30452
|
+
(data, iframeDoc) => {
|
|
30506
30453
|
const clipCompositionIds = new Set(data.clips.map((c) => c.compositionId).filter(Boolean));
|
|
30507
30454
|
const filtered = data.clips.filter(
|
|
30508
30455
|
(clip) => !clip.parentCompositionId || !clipCompositionIds.has(clip.parentCompositionId)
|
|
30509
30456
|
);
|
|
30510
|
-
const iframeDoc = safeContentDocument(iframeRef.current);
|
|
30511
30457
|
try {
|
|
30512
30458
|
const parentMap = clipTreeParentMap(iframeRef.current?.contentWindow ?? null);
|
|
30513
30459
|
const domClipChildren = collectSubCompositionDomChildren(iframeDoc, data.clips, parentMap);
|
|
@@ -30532,6 +30478,24 @@ function useTimelineSyncCallbacks({
|
|
|
30532
30478
|
},
|
|
30533
30479
|
[iframeRef, syncTimelineElements]
|
|
30534
30480
|
);
|
|
30481
|
+
const timelineReads = useRef47(0);
|
|
30482
|
+
const processTimelineMessage = useCallback38(
|
|
30483
|
+
(data) => {
|
|
30484
|
+
if (!data.clips) return;
|
|
30485
|
+
usePlayerStore.getState().setClipManifest(data.clips);
|
|
30486
|
+
const iframe = iframeRef.current;
|
|
30487
|
+
const read2 = ++timelineReads.current;
|
|
30488
|
+
if (!iframe || !previewFrameOpaque(iframe)) {
|
|
30489
|
+
applyTimelineMessage(data, safeContentDocument(iframe));
|
|
30490
|
+
return;
|
|
30491
|
+
}
|
|
30492
|
+
void previewDocumentCopy(iframe).then((doc) => {
|
|
30493
|
+
if (read2 === timelineReads.current && iframeRef.current === iframe)
|
|
30494
|
+
applyTimelineMessage(data, doc);
|
|
30495
|
+
});
|
|
30496
|
+
},
|
|
30497
|
+
[iframeRef, applyTimelineMessage]
|
|
30498
|
+
);
|
|
30535
30499
|
const enrichMissingCompositions = useCallback38(() => {
|
|
30536
30500
|
try {
|
|
30537
30501
|
const iframe = iframeRef.current;
|
|
@@ -40464,7 +40428,7 @@ function OffCanvasIndicators({
|
|
|
40464
40428
|
const selectOffCanvas = async () => {
|
|
40465
40429
|
const el = elements.current.get(r.key);
|
|
40466
40430
|
if (!el) return;
|
|
40467
|
-
const { resolveDomEditSelection: resolveDomEditSelection2 } = await import("./domEditingLayers-
|
|
40431
|
+
const { resolveDomEditSelection: resolveDomEditSelection2 } = await import("./domEditingLayers-YYHWRNF4.js");
|
|
40468
40432
|
const acp = activeCompositionPathRef.current ?? "index.html";
|
|
40469
40433
|
const sel = await resolveDomEditSelection2(el, {
|
|
40470
40434
|
activeCompositionPath: acp,
|
package/dist/player.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.64",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"dockview-react": "8.3.1",
|
|
65
65
|
"gsap": "^3.13.0",
|
|
66
66
|
"mediabunny": "^1.66.0",
|
|
67
|
-
"@hyperframes/
|
|
68
|
-
"@hyperframes/
|
|
69
|
-
"@hyperframes/player": "0.9.
|
|
70
|
-
"@hyperframes/
|
|
71
|
-
"@hyperframes/
|
|
72
|
-
"@hyperframes/
|
|
67
|
+
"@hyperframes/core": "0.9.64",
|
|
68
|
+
"@hyperframes/parsers": "0.9.64",
|
|
69
|
+
"@hyperframes/player": "0.9.64",
|
|
70
|
+
"@hyperframes/sdk": "0.9.64",
|
|
71
|
+
"@hyperframes/studio-server": "0.9.64",
|
|
72
|
+
"@hyperframes/shader-transitions": "0.9.64"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"vite": "^6.4.5",
|
|
87
87
|
"vitest": "^4.1.12",
|
|
88
88
|
"zustand": "^5.0.0",
|
|
89
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.64"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "19",
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { act, createElement } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
6
|
+
// The frame's real runtime agent, serving the opaque frame from this document as Studio's marked preview page.
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
9
|
+
import { detachedFakeIframe } from "./timelinePlayerTestHarness";
|
|
10
|
+
import { useTimelineSyncCallbacks } from "./useTimelineSyncCallbacks";
|
|
11
|
+
|
|
12
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
13
|
+
|
|
14
|
+
const closers: Array<() => void> = [];
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
closers.splice(0).forEach((close) => close());
|
|
17
|
+
document.body.innerHTML = "";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
21
|
+
function opaqueFrame() {
|
|
22
|
+
const frame: Record<string, unknown> = {};
|
|
23
|
+
const iframe = detachedFakeIframe(frame);
|
|
24
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
25
|
+
Object.defineProperty(frame, "document", {
|
|
26
|
+
get: () => {
|
|
27
|
+
throw new DOMException("blocked", "SecurityError");
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const parent = {
|
|
31
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
32
|
+
window.dispatchEvent(
|
|
33
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
34
|
+
),
|
|
35
|
+
} as unknown as Window;
|
|
36
|
+
const agent = installMarkedEditingAgent(parent);
|
|
37
|
+
frame.postMessage = (data: unknown) =>
|
|
38
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
39
|
+
closers.push(() => agent.dispose());
|
|
40
|
+
return iframe;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function processWith(iframe: HTMLIFrameElement) {
|
|
44
|
+
const sync = vi.fn<(els: TimelineElement[], duration?: number) => void>();
|
|
45
|
+
let callbacks: ReturnType<typeof useTimelineSyncCallbacks> | undefined;
|
|
46
|
+
function Harness() {
|
|
47
|
+
callbacks = useTimelineSyncCallbacks({
|
|
48
|
+
iframeRef: { current: iframe },
|
|
49
|
+
probeIntervalRef: { current: undefined },
|
|
50
|
+
pendingSeekRef: { current: null },
|
|
51
|
+
isRefreshingRef: { current: false },
|
|
52
|
+
getAdapter: () => null,
|
|
53
|
+
syncTimelineElements: sync,
|
|
54
|
+
setDuration: () => {},
|
|
55
|
+
setCurrentTime: () => {},
|
|
56
|
+
requestTimelineReady: () => {},
|
|
57
|
+
setIsPlaying: () => {},
|
|
58
|
+
attachIframeShortcutListeners: () => {},
|
|
59
|
+
applyPreviewAudioState: () => {},
|
|
60
|
+
});
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const host = document.createElement("div");
|
|
64
|
+
act(() => createRoot(host).render(createElement(Harness)));
|
|
65
|
+
return { sync, process: callbacks!.processTimelineMessage };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const boxClip = {
|
|
69
|
+
id: "box",
|
|
70
|
+
label: "box",
|
|
71
|
+
start: 0,
|
|
72
|
+
duration: 2,
|
|
73
|
+
track: 0,
|
|
74
|
+
kind: "element" as const,
|
|
75
|
+
tagName: "div",
|
|
76
|
+
compositionId: null,
|
|
77
|
+
parentCompositionId: null,
|
|
78
|
+
compositionSrc: null,
|
|
79
|
+
assetUrl: null,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// fails without the fix: a sealed frame's rows had no element behind them, so no id, source file or audio group.
|
|
83
|
+
it("binds a sealed preview's timeline row to its element, as an open preview does", async () => {
|
|
84
|
+
document.body.innerHTML = `<div data-composition-id="main" data-composition-file="index.html">
|
|
85
|
+
<div id="box" class="clip" data-start="0" data-duration="2" data-audio-group="voice"></div>
|
|
86
|
+
</div>`;
|
|
87
|
+
const { sync, process } = processWith(opaqueFrame());
|
|
88
|
+
|
|
89
|
+
process({ clips: [boxClip], durationInFrames: 60 });
|
|
90
|
+
|
|
91
|
+
await vi.waitFor(() => expect(sync.mock.calls.at(-1)?.[0][0]?.domId).toBe("box"));
|
|
92
|
+
const [row] = sync.mock.calls.at(-1)![0];
|
|
93
|
+
expect(row).toMatchObject({
|
|
94
|
+
key: "index.html#box",
|
|
95
|
+
sourceFile: "index.html",
|
|
96
|
+
audioGroup: "voice",
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -15,6 +15,7 @@ import type { PlaybackAdapter, IframeWindow } from "../lib/playbackTypes";
|
|
|
15
15
|
import { readTimelineDurationFromDocument } from "../lib/timelineDOM";
|
|
16
16
|
import { buildMissingCompositionElements } from "../lib/timelineIframeHelpers";
|
|
17
17
|
import { acceptedRuntimeMessageFps } from "../lib/runtimeProtocol";
|
|
18
|
+
import { previewDocumentCopy, previewFrameOpaque } from "../lib/previewChannel";
|
|
18
19
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
19
20
|
import {
|
|
20
21
|
buildTimelineElementsFromClips,
|
|
@@ -171,19 +172,13 @@ export function useTimelineSyncCallbacks({
|
|
|
171
172
|
hostOwnsDeadline,
|
|
172
173
|
}: UseTimelineSyncCallbacksParams) {
|
|
173
174
|
// Convert a runtime timeline message (from iframe postMessage) into TimelineElements
|
|
174
|
-
const
|
|
175
|
-
(data: RuntimeTimelineMessage) => {
|
|
176
|
-
if (!data.clips) return;
|
|
177
|
-
|
|
178
|
-
usePlayerStore.getState().setClipManifest(data.clips);
|
|
179
|
-
|
|
175
|
+
const applyTimelineMessage = useCallback(
|
|
176
|
+
(data: RuntimeTimelineMessage, iframeDoc: Document | null) => {
|
|
180
177
|
// Show root-level clips: no parentCompositionId, OR parent is a "phantom wrapper"
|
|
181
178
|
const clipCompositionIds = new Set(data.clips.map((c) => c.compositionId).filter(Boolean));
|
|
182
179
|
const filtered = data.clips.filter(
|
|
183
180
|
(clip) => !clip.parentCompositionId || !clipCompositionIds.has(clip.parentCompositionId),
|
|
184
181
|
);
|
|
185
|
-
const iframeDoc = safeContentDocument(iframeRef.current);
|
|
186
|
-
|
|
187
182
|
try {
|
|
188
183
|
const parentMap = clipTreeParentMap(iframeRef.current?.contentWindow ?? null);
|
|
189
184
|
const domClipChildren = collectSubCompositionDomChildren(iframeDoc, data.clips, parentMap);
|
|
@@ -219,6 +214,26 @@ export function useTimelineSyncCallbacks({
|
|
|
219
214
|
[iframeRef, syncTimelineElements],
|
|
220
215
|
);
|
|
221
216
|
|
|
217
|
+
const timelineReads = useRef(0);
|
|
218
|
+
const processTimelineMessage = useCallback(
|
|
219
|
+
(data: RuntimeTimelineMessage) => {
|
|
220
|
+
if (!data.clips) return;
|
|
221
|
+
usePlayerStore.getState().setClipManifest(data.clips);
|
|
222
|
+
const iframe = iframeRef.current;
|
|
223
|
+
const read = ++timelineReads.current;
|
|
224
|
+
if (!iframe || !previewFrameOpaque(iframe)) {
|
|
225
|
+
applyTimelineMessage(data, safeContentDocument(iframe));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// A sealed frame's rows bind to a copy of its document from the editing port; the newest read wins.
|
|
229
|
+
void previewDocumentCopy(iframe).then((doc) => {
|
|
230
|
+
if (read === timelineReads.current && iframeRef.current === iframe)
|
|
231
|
+
applyTimelineMessage(data, doc);
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
[iframeRef, applyTimelineMessage],
|
|
235
|
+
);
|
|
236
|
+
|
|
222
237
|
const enrichMissingCompositions = useCallback(() => {
|
|
223
238
|
try {
|
|
224
239
|
const iframe = iframeRef.current;
|
|
@@ -73,8 +73,6 @@ export type IframeWindow = Window & {
|
|
|
73
73
|
* Every member stays optional and is optional-called, so a runtime that
|
|
74
74
|
* predates the hook degrades to a no-op instead of throwing. */
|
|
75
75
|
__hf?: {
|
|
76
|
-
leasePausedMedia?: (el: HTMLMediaElement) => void;
|
|
77
|
-
releasePausedMedia?: (el: HTMLMediaElement) => void;
|
|
78
76
|
setPausedVideoFrameProvider?: (provider: PausedVideoFrameProvider | null) => void;
|
|
79
77
|
setLoopStart?: (seconds: number | null) => void;
|
|
80
78
|
};
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
import type { TimelineElement } from "../store/playerStore";
|
|
11
11
|
import { readTimelineText } from "./timelineText";
|
|
12
12
|
import type { ClipManifestClip } from "./playbackTypes";
|
|
13
|
+
import {
|
|
14
|
+
previewElementFinder,
|
|
15
|
+
previewElementSourceFile as getTimelineElementSourceFile,
|
|
16
|
+
} from "@hyperframes/core/studio-preview-mark";
|
|
17
|
+
|
|
18
|
+
export type { PreviewTarget } from "@hyperframes/core/studio-preview-mark";
|
|
19
|
+
export { getTimelineElementSourceFile, previewElementFinder };
|
|
13
20
|
import { isFinitePositive } from "./playbackAdapter";
|
|
14
21
|
import { getSourceScopedSelectorIndex } from "../../utils/sourceScopedSelectorIndex";
|
|
15
22
|
import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
|
|
@@ -296,15 +303,6 @@ export function getTimelineElementSelector(el: Element): string | undefined {
|
|
|
296
303
|
return undefined;
|
|
297
304
|
}
|
|
298
305
|
|
|
299
|
-
export function getTimelineElementSourceFile(el: Element): string | undefined {
|
|
300
|
-
const ownerRoot = el.parentElement?.closest("[data-composition-id]");
|
|
301
|
-
return (
|
|
302
|
-
ownerRoot?.getAttribute("data-composition-file") ??
|
|
303
|
-
ownerRoot?.getAttribute("data-composition-src") ??
|
|
304
|
-
undefined
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
306
|
export function getTimelineElementSelectorIndex(
|
|
309
307
|
doc: Document,
|
|
310
308
|
el: Element,
|
|
@@ -491,39 +489,6 @@ function findInClipScope(
|
|
|
491
489
|
return lone;
|
|
492
490
|
}
|
|
493
491
|
|
|
494
|
-
export type PreviewTarget = Pick<TimelineElement, "hfId" | "domId" | "id" | "sourceFile">;
|
|
495
|
-
|
|
496
|
-
/** Finds a row's preview element by `data-hf-id`, then id, preferring one in the row's own file: both repeat across
|
|
497
|
-
* files. Indexes the document once, so a pass over every row costs one scan. */
|
|
498
|
-
export function previewElementFinder(
|
|
499
|
-
doc: Document,
|
|
500
|
-
selector = "[data-hf-id], [id]",
|
|
501
|
-
): (target: PreviewTarget) => Element | null {
|
|
502
|
-
const byKey = new Map<string, Element[]>();
|
|
503
|
-
const add = (key: string, node: Element) => {
|
|
504
|
-
const nodes = byKey.get(key);
|
|
505
|
-
if (nodes) nodes.push(node);
|
|
506
|
-
else byKey.set(key, [node]);
|
|
507
|
-
};
|
|
508
|
-
for (const node of doc.querySelectorAll(selector)) {
|
|
509
|
-
const hfId = node.getAttribute("data-hf-id");
|
|
510
|
-
const id = node.getAttribute("id");
|
|
511
|
-
if (hfId) add(`hf:${hfId}`, node);
|
|
512
|
-
if (id) add(`id:${id}`, node);
|
|
513
|
-
}
|
|
514
|
-
return (target) => {
|
|
515
|
-
const matches = [
|
|
516
|
-
...((target.hfId && byKey.get(`hf:${target.hfId}`)) || []),
|
|
517
|
-
...(byKey.get(`id:${target.domId ?? target.id}`) ?? []),
|
|
518
|
-
];
|
|
519
|
-
return (
|
|
520
|
-
matches.find((node) => getTimelineElementSourceFile(node) === target.sourceFile) ??
|
|
521
|
-
matches[0] ??
|
|
522
|
-
null
|
|
523
|
-
);
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
|
|
527
492
|
export function findClipElementById(doc: Document, clip: ClipManifestClip): Element | null {
|
|
528
493
|
if (!clip.id) return null;
|
|
529
494
|
const first = doc.getElementById(clip.id);
|