@hyperframes/studio-server 0.8.150 → 0.8.151

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.
@@ -307,11 +307,20 @@ function setElementDuration(el, start, duration, trackIndex) {
307
307
  ...trackIndex != null ? { trackIndex } : {}
308
308
  });
309
309
  }
310
+ function isWindowOf(media, row) {
311
+ if (media.duration <= 0) return false;
312
+ const near = (a, b) => Math.abs(a - b) < 1e-3;
313
+ return !row || near(media.start, row.start) && near(media.duration, row.duration);
314
+ }
310
315
  function splitElementInHtml(source, target, splitTime, newId, fallbackTiming) {
311
316
  const { document, wrappedFragment } = parseSourceDocument(source);
312
317
  const el = findTargetElement(document, target);
313
318
  if (!el || !isHTMLElement(el)) return { html: source, matched: false, newId: null };
314
- const timing = resolveElementTiming(el);
319
+ const timedMediaSelector = "video[data-start], audio[data-start]";
320
+ const innerMedia = el.hasAttribute("data-start") || resolveElementTiming(el).duration > 0 || el.matches("[data-composition-src], [data-composition-id]") ? null : el.querySelector(timedMediaSelector);
321
+ const timedMedia = innerMedia && isWindowOf(resolveElementTiming(innerMedia), fallbackTiming) ? innerMedia : null;
322
+ const timed = timedMedia ?? el;
323
+ const timing = resolveElementTiming(timed);
315
324
  let { start, duration } = timing;
316
325
  if (duration <= 0 && fallbackTiming && fallbackTiming.duration > 0) {
317
326
  start = fallbackTiming.start;
@@ -329,16 +338,22 @@ function splitElementInHtml(source, target, splitTime, newId, fallbackTiming) {
329
338
  dedupeClonedCompositionId(document, clone);
330
339
  clone.removeAttribute("data-hf-id");
331
340
  for (const node of clone.querySelectorAll("[data-hf-id]")) node.removeAttribute("data-hf-id");
332
- setElementDuration(clone, splitTime, secondDuration, fallbackTiming?.track);
333
- const playbackStartAttr = el.hasAttribute("data-playback-start") ? "data-playback-start" : el.hasAttribute("data-media-start") ? "data-media-start" : el.matches("[data-composition-src], [data-composition-id]") ? "data-playback-start" : el.matches("audio, video") ? "data-media-start" : null;
341
+ const clonedTimed = timedMedia ? clone.querySelector(timedMediaSelector) : clone;
342
+ if (timedMedia?.id) {
343
+ const mediaId = nextUniqueId(document, `${timedMedia.id}-split`, /* @__PURE__ */ new Set([newId]));
344
+ duplicateCssRulesForId(document, timedMedia.id, mediaId);
345
+ clonedTimed.setAttribute("id", mediaId);
346
+ }
347
+ setElementDuration(clonedTimed, splitTime, secondDuration, fallbackTiming?.track);
348
+ const playbackStartAttr = timed.hasAttribute("data-playback-start") ? "data-playback-start" : timed.hasAttribute("data-media-start") ? "data-media-start" : timed.matches("[data-composition-src], [data-composition-id]") ? "data-playback-start" : timed.matches("audio, video") ? "data-media-start" : null;
334
349
  if (playbackStartAttr) {
335
- const readAttr = (name) => el.getAttribute(name);
336
- const authoredTrim = el.getAttribute(playbackStartAttr);
350
+ const readAttr = (name) => timed.getAttribute(name);
351
+ const authoredTrim = timed.getAttribute(playbackStartAttr);
337
352
  const currentTrim = authoredTrim !== null ? readMediaOffsetSeconds(readAttr) : fallbackTiming?.playbackStart ?? 0;
338
353
  const rate = readPlaybackRate(readAttr, fallbackTiming?.playbackRate);
339
354
  if (authoredTrim === null || Number(authoredTrim) !== currentTrim)
340
- el.setAttribute(playbackStartAttr, String(Math.round(currentTrim * 1e3) / 1e3));
341
- clone.setAttribute(
355
+ timed.setAttribute(playbackStartAttr, String(Math.round(currentTrim * 1e3) / 1e3));
356
+ clonedTimed.setAttribute(
342
357
  playbackStartAttr,
343
358
  String(Math.round((currentTrim + firstDuration * rate) * 1e3) / 1e3)
344
359
  );
@@ -347,7 +362,7 @@ function splitElementInHtml(source, target, splitTime, newId, fallbackTiming) {
347
362
  if (originalId) {
348
363
  duplicateCssRulesForId(document, originalId, newId);
349
364
  }
350
- setElementDuration(el, start, firstDuration, fallbackTiming?.track);
365
+ setElementDuration(timed, start, firstDuration, fallbackTiming?.track);
351
366
  if (el.nextSibling) {
352
367
  el.parentElement.insertBefore(clone, el.nextSibling);
353
368
  } else {
@@ -13,7 +13,7 @@ import {
13
13
  splitElementInHtml,
14
14
  unwrapElementsFromHtml,
15
15
  wrapElementsInHtml
16
- } from "../chunk-Z5UJMFO4.js";
16
+ } from "../chunk-JBFOY5SI.js";
17
17
  export {
18
18
  dedupeClonedCompositionId,
19
19
  findTargetElement,
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  splitElementInHtml,
18
18
  unwrapElementsFromHtml,
19
19
  wrapElementsInHtml
20
- } from "./chunk-Z5UJMFO4.js";
20
+ } from "./chunk-JBFOY5SI.js";
21
21
  import {
22
22
  isCompositionSource,
23
23
  stampProjectHfIds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio-server",
3
- "version": "0.8.150",
3
+ "version": "0.8.151",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -81,8 +81,8 @@
81
81
  "postcss": "^8.5.8",
82
82
  "postcss-selector-parser": "^7.1.2",
83
83
  "sharp": "^0.35.0",
84
- "@hyperframes/core": "0.8.150",
85
- "@hyperframes/parsers": "0.8.150"
84
+ "@hyperframes/core": "0.8.151",
85
+ "@hyperframes/parsers": "0.8.151"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@types/node": "^25.0.10",