stormcloud-video-player 0.7.43 → 0.7.44
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/stormcloud-vp.min.js +1 -1
- package/lib/index.cjs +74 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +74 -2
- package/lib/index.js.map +1 -1
- package/lib/ui/OverlayRenderer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +74 -2
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/utils/overlays.cjs +74 -2
- package/lib/utils/overlays.cjs.map +1 -1
- package/package.json +1 -1
package/lib/utils/overlays.cjs
CHANGED
|
@@ -356,6 +356,59 @@ function swirlProjectHasNabDemoMixedWithOther(overlays) {
|
|
|
356
356
|
}
|
|
357
357
|
return hasNab && hasOther;
|
|
358
358
|
}
|
|
359
|
+
var STANDARD_16_9_LADDER = [
|
|
360
|
+
{
|
|
361
|
+
width: 384,
|
|
362
|
+
height: 216
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
width: 640,
|
|
366
|
+
height: 360
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
width: 854,
|
|
370
|
+
height: 480
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
width: 1280,
|
|
374
|
+
height: 720
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
width: 1920,
|
|
378
|
+
height: 1080
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
width: 2560,
|
|
382
|
+
height: 1440
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
width: 3840,
|
|
386
|
+
height: 2160
|
|
387
|
+
}
|
|
388
|
+
];
|
|
389
|
+
function smallestLadderRungContaining(maxR, maxB, eps) {
|
|
390
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
391
|
+
try {
|
|
392
|
+
for(var _iterator = STANDARD_16_9_LADDER[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
393
|
+
var rung = _step.value;
|
|
394
|
+
if (maxR <= rung.width + eps && maxB <= rung.height + eps) return rung;
|
|
395
|
+
}
|
|
396
|
+
} catch (err) {
|
|
397
|
+
_didIteratorError = true;
|
|
398
|
+
_iteratorError = err;
|
|
399
|
+
} finally{
|
|
400
|
+
try {
|
|
401
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
402
|
+
_iterator.return();
|
|
403
|
+
}
|
|
404
|
+
} finally{
|
|
405
|
+
if (_didIteratorError) {
|
|
406
|
+
throw _iteratorError;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
359
412
|
function inferSwirlOverlayCoordinateSpace(overlays, videoWidth, videoHeight) {
|
|
360
413
|
if (!videoWidth || !videoHeight) {
|
|
361
414
|
return {
|
|
@@ -371,9 +424,15 @@ function inferSwirlOverlayCoordinateSpace(overlays, videoWidth, videoHeight) {
|
|
|
371
424
|
}
|
|
372
425
|
var _overlayExtents = overlayExtents(overlays), maxR = _overlayExtents.maxR, maxB = _overlayExtents.maxB;
|
|
373
426
|
var EPS = 1;
|
|
374
|
-
|
|
375
|
-
|
|
427
|
+
if (maxR <= 0 || maxB <= 0) {
|
|
428
|
+
return {
|
|
429
|
+
width: videoWidth,
|
|
430
|
+
height: videoHeight
|
|
431
|
+
};
|
|
432
|
+
}
|
|
376
433
|
var mixed = swirlProjectHasNabDemoMixedWithOther(overlays);
|
|
434
|
+
var fitsHdCanvas = maxR <= SWIRL_HD_AUTHORING_WIDTH + EPS && maxB <= SWIRL_HD_AUTHORING_HEIGHT + EPS;
|
|
435
|
+
var exceedsDecode = maxR > videoWidth + EPS || maxB > videoHeight + EPS;
|
|
377
436
|
var decodeLargerThanHd = videoWidth > SWIRL_HD_AUTHORING_WIDTH + EPS || videoHeight > SWIRL_HD_AUTHORING_HEIGHT + EPS;
|
|
378
437
|
if (fitsHdCanvas && (decodeLargerThanHd || exceedsDecode && !mixed)) {
|
|
379
438
|
return {
|
|
@@ -381,6 +440,19 @@ function inferSwirlOverlayCoordinateSpace(overlays, videoWidth, videoHeight) {
|
|
|
381
440
|
height: SWIRL_HD_AUTHORING_HEIGHT
|
|
382
441
|
};
|
|
383
442
|
}
|
|
443
|
+
if (mixed) {
|
|
444
|
+
return {
|
|
445
|
+
width: videoWidth,
|
|
446
|
+
height: videoHeight
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
var rung = smallestLadderRungContaining(maxR, maxB, EPS);
|
|
450
|
+
if (rung && rung.width < videoWidth - EPS && rung.height < videoHeight - EPS) {
|
|
451
|
+
return {
|
|
452
|
+
width: rung.width,
|
|
453
|
+
height: rung.height
|
|
454
|
+
};
|
|
455
|
+
}
|
|
384
456
|
return {
|
|
385
457
|
width: videoWidth,
|
|
386
458
|
height: videoHeight
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/ubuntu24-new/Dev/stormcloud-vp/lib/utils/overlays.cjs"],"names":["__hasOwnProp","__defProp","Object","defineProperty","__getOwnPropNames","getOwnPropertyNames","prototype","hasOwnProperty","__export","target","all","name","get","__copyProps","to","from","except","desc","key","call","enumerable","__getOwnPropDesc"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;kDAAA;6CAAA","sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/utils/overlays.ts\nvar overlays_exports = {};\n__export(overlays_exports, {\n OVERLAY_API_BASE: () => OVERLAY_API_BASE,\n SWIRL_HD_AUTHORING_HEIGHT: () => SWIRL_HD_AUTHORING_HEIGHT,\n SWIRL_HD_AUTHORING_WIDTH: () => SWIRL_HD_AUTHORING_WIDTH,\n fetchProjectOverlays: () => fetchProjectOverlays,\n inferSwirlOverlayCoordinateSpace: () => inferSwirlOverlayCoordinateSpace,\n isOverlayActive: () => isOverlayActive,\n normalizeSwirlOverlay: () => normalizeSwirlOverlay,\n overlayAuthoringDimensions: () => overlayAuthoringDimensions,\n resolveImageUrl: () => resolveImageUrl,\n swirlProjectHasNabDemoMixedWithOther: () => swirlProjectHasNabDemoMixedWithOther,\n timeStringToSeconds: () => timeStringToSeconds\n});\nmodule.exports = __toCommonJS(overlays_exports);\nvar OVERLAY_API_BASE = \"https://adstorm.co/api-adstorm-dev\";\nfunction timeStringToSeconds(timeStr) {\n if (!timeStr) return 0;\n const parts = timeStr.split(\":\");\n if (parts.length >= 3) {\n const hours = parseInt(parts[0] ?? \"0\", 10) || 0;\n const minutes = parseInt(parts[1] ?? \"0\", 10) || 0;\n const secStr = parts[2] ?? \"0\";\n const dotIdx = secStr.indexOf(\".\");\n const seconds = parseInt(dotIdx >= 0 ? secStr.substring(0, dotIdx) : secStr, 10) || 0;\n const msFrag = dotIdx >= 0 ? secStr.substring(dotIdx + 1) : \"\";\n const ms = msFrag ? parseInt(msFrag.padEnd(3, \"0\").substring(0, 3), 10) || 0 : 0;\n return hours * 3600 + minutes * 60 + seconds + ms / 1e3;\n }\n if (parts.length === 2) {\n const minutes = parseInt(parts[0] ?? \"0\", 10) || 0;\n const secStr = parts[1] ?? \"0\";\n const dotIdx = secStr.indexOf(\".\");\n const seconds = parseInt(dotIdx >= 0 ? secStr.substring(0, dotIdx) : secStr, 10) || 0;\n const msFrag = dotIdx >= 0 ? secStr.substring(dotIdx + 1) : \"\";\n const ms = msFrag ? parseInt(msFrag.padEnd(3, \"0\").substring(0, 3), 10) || 0 : 0;\n return minutes * 60 + seconds + ms / 1e3;\n }\n const num = parseFloat(timeStr);\n return isFinite(num) ? Math.max(0, num) : 0;\n}\nfunction isOverlayActive(overlay, currentTime) {\n if (!overlay.visible) return false;\n const startSec = timeStringToSeconds(overlay.start_time);\n const durationSec = timeStringToSeconds(overlay.duration);\n if (durationSec <= 0) return false;\n return currentTime >= startSec && currentTime < startSec + durationSec;\n}\nvar SWIRL_HD_AUTHORING_WIDTH = 1920;\nvar SWIRL_HD_AUTHORING_HEIGHT = 1080;\nvar NAB_DEMO_NAME_PREFIX = \"NAB Demo \\u2014 \";\nfunction overlayAuthoringDimensions(overlay, decodeWidth, decodeHeight) {\n if (overlay.name.startsWith(NAB_DEMO_NAME_PREFIX)) {\n return {\n width: SWIRL_HD_AUTHORING_WIDTH,\n height: SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n if (!decodeWidth || !decodeHeight) {\n return {\n width: decodeWidth || SWIRL_HD_AUTHORING_WIDTH,\n height: decodeHeight || SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n return { width: decodeWidth, height: decodeHeight };\n}\nfunction overlayExtents(overlays) {\n let maxR = 0;\n let maxB = 0;\n for (const o of overlays) {\n if (!o.visible) continue;\n maxR = Math.max(maxR, o.x + o.width);\n maxB = Math.max(maxB, o.y + o.height);\n }\n return { maxR, maxB };\n}\nfunction swirlProjectHasNabDemoMixedWithOther(overlays) {\n let hasNab = false;\n let hasOther = false;\n for (const o of overlays) {\n if (!o.visible) continue;\n if (o.name.startsWith(NAB_DEMO_NAME_PREFIX)) hasNab = true;\n else hasOther = true;\n }\n return hasNab && hasOther;\n}\nfunction inferSwirlOverlayCoordinateSpace(overlays, videoWidth, videoHeight) {\n if (!videoWidth || !videoHeight) {\n return {\n width: videoWidth || SWIRL_HD_AUTHORING_WIDTH,\n height: videoHeight || SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n if (!overlays.length) {\n return { width: videoWidth, height: videoHeight };\n }\n const { maxR, maxB } = overlayExtents(overlays);\n const EPS = 1;\n const exceedsDecode = maxR > videoWidth + EPS || maxB > videoHeight + EPS;\n const fitsHdCanvas = maxR <= SWIRL_HD_AUTHORING_WIDTH + EPS && maxB <= SWIRL_HD_AUTHORING_HEIGHT + EPS;\n const mixed = swirlProjectHasNabDemoMixedWithOther(overlays);\n const decodeLargerThanHd = videoWidth > SWIRL_HD_AUTHORING_WIDTH + EPS || videoHeight > SWIRL_HD_AUTHORING_HEIGHT + EPS;\n if (fitsHdCanvas && (decodeLargerThanHd || exceedsDecode && !mixed)) {\n return {\n width: SWIRL_HD_AUTHORING_WIDTH,\n height: SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n return { width: videoWidth, height: videoHeight };\n}\nfunction normalizeScrollerConfig(raw) {\n if (!raw || typeof raw !== \"object\") return void 0;\n const r = raw;\n const merged = { ...raw };\n if (merged.use_custom_text === void 0 && typeof r.useCustomText === \"boolean\") {\n merged.use_custom_text = r.useCustomText;\n }\n if ((merged.custom_text === void 0 || merged.custom_text === \"\") && typeof r.customText === \"string\") {\n merged.custom_text = r.customText;\n }\n if (!merged.rss_url && typeof r.rssUrl === \"string\") {\n merged.rss_url = r.rssUrl;\n }\n return merged;\n}\nfunction normalizeSwirlOverlay(raw) {\n const o = { ...raw };\n if (o.type === \"scroller\") {\n const sc = raw.scroller_config ?? raw.scrollerConfig;\n const normalized = normalizeScrollerConfig(sc);\n if (normalized) o.scroller_config = normalized;\n }\n return o;\n}\nasync function fetchProjectOverlays(projectId, apiBaseUrl = OVERLAY_API_BASE) {\n const base = apiBaseUrl.replace(/\\/$/, \"\");\n const response = await fetch(\n `${base}/adstorm/swirl/projects/${projectId}/overlays`\n );\n if (!response.ok) {\n throw new Error(\n `Failed to fetch overlays: ${response.status} ${response.statusText}`\n );\n }\n const data = await response.json();\n if (!Array.isArray(data)) return [];\n return data.map(\n (row) => normalizeSwirlOverlay(row)\n );\n}\nfunction resolveImageUrl(imageUrl, apiBaseUrl = OVERLAY_API_BASE) {\n if (!imageUrl) return \"\";\n if (imageUrl.startsWith(\"http://\") || imageUrl.startsWith(\"https://\")) {\n return imageUrl;\n }\n if (imageUrl.startsWith(\"/\")) {\n try {\n const url = new URL(apiBaseUrl);\n return `${url.origin}${imageUrl}`;\n } catch {\n return imageUrl;\n }\n }\n return `${apiBaseUrl}/${imageUrl}`;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n OVERLAY_API_BASE,\n SWIRL_HD_AUTHORING_HEIGHT,\n SWIRL_HD_AUTHORING_WIDTH,\n fetchProjectOverlays,\n inferSwirlOverlayCoordinateSpace,\n isOverlayActive,\n normalizeSwirlOverlay,\n overlayAuthoringDimensions,\n resolveImageUrl,\n swirlProjectHasNabDemoMixedWithOther,\n timeStringToSeconds\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/ubuntu24-new/Dev/stormcloud-vp/lib/utils/overlays.cjs","../../src/utils/overlays.ts"],"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toC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AA,GAAAA;;iCAAAC,2BAAA,SAAAA;2CAAAA;;wCAAAC,0BAAA,SAAAA;kCAAAA;;kCAAAC,sBAAA,SAAAA;kCAAAA;;2BAAAC,kCAAA,SAAAA;gBAAAA","sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n\n// src/utils/overlays.ts\nvar overlays_exports = {};\n__export(overlays_exports, {\n OVERLAY_API_BASE: () => OVERLAY_API_BASE,\n SWIRL_HD_AUTHORING_HEIGHT: () => SWIRL_HD_AUTHORING_HEIGHT,\n SWIRL_HD_AUTHORING_WIDTH: () => SWIRL_HD_AUTHORING_WIDTH,\n fetchProjectOverlays: () => fetchProjectOverlays,\n inferSwirlOverlayCoordinateSpace: () => inferSwirlOverlayCoordinateSpace,\n isOverlayActive: () => isOverlayActive,\n normalizeSwirlOverlay: () => normalizeSwirlOverlay,\n overlayAuthoringDimensions: () => overlayAuthoringDimensions,\n resolveImageUrl: () => resolveImageUrl,\n swirlProjectHasNabDemoMixedWithOther: () => swirlProjectHasNabDemoMixedWithOther,\n timeStringToSeconds: () => timeStringToSeconds\n});\nmodule.exports = __toCommonJS(overlays_exports);\nvar OVERLAY_API_BASE = \"https://adstorm.co/api-adstorm-dev\";\nfunction timeStringToSeconds(timeStr) {\n if (!timeStr) return 0;\n const parts = timeStr.split(\":\");\n if (parts.length >= 3) {\n const hours = parseInt(parts[0] ?? \"0\", 10) || 0;\n const minutes = parseInt(parts[1] ?? \"0\", 10) || 0;\n const secStr = parts[2] ?? \"0\";\n const dotIdx = secStr.indexOf(\".\");\n const seconds = parseInt(dotIdx >= 0 ? secStr.substring(0, dotIdx) : secStr, 10) || 0;\n const msFrag = dotIdx >= 0 ? secStr.substring(dotIdx + 1) : \"\";\n const ms = msFrag ? parseInt(msFrag.padEnd(3, \"0\").substring(0, 3), 10) || 0 : 0;\n return hours * 3600 + minutes * 60 + seconds + ms / 1e3;\n }\n if (parts.length === 2) {\n const minutes = parseInt(parts[0] ?? \"0\", 10) || 0;\n const secStr = parts[1] ?? \"0\";\n const dotIdx = secStr.indexOf(\".\");\n const seconds = parseInt(dotIdx >= 0 ? secStr.substring(0, dotIdx) : secStr, 10) || 0;\n const msFrag = dotIdx >= 0 ? secStr.substring(dotIdx + 1) : \"\";\n const ms = msFrag ? parseInt(msFrag.padEnd(3, \"0\").substring(0, 3), 10) || 0 : 0;\n return minutes * 60 + seconds + ms / 1e3;\n }\n const num = parseFloat(timeStr);\n return isFinite(num) ? Math.max(0, num) : 0;\n}\nfunction isOverlayActive(overlay, currentTime) {\n if (!overlay.visible) return false;\n const startSec = timeStringToSeconds(overlay.start_time);\n const durationSec = timeStringToSeconds(overlay.duration);\n if (durationSec <= 0) return false;\n return currentTime >= startSec && currentTime < startSec + durationSec;\n}\nvar SWIRL_HD_AUTHORING_WIDTH = 1920;\nvar SWIRL_HD_AUTHORING_HEIGHT = 1080;\nvar NAB_DEMO_NAME_PREFIX = \"NAB Demo \\u2014 \";\nfunction overlayAuthoringDimensions(overlay, decodeWidth, decodeHeight) {\n if (overlay.name.startsWith(NAB_DEMO_NAME_PREFIX)) {\n return {\n width: SWIRL_HD_AUTHORING_WIDTH,\n height: SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n if (!decodeWidth || !decodeHeight) {\n return {\n width: decodeWidth || SWIRL_HD_AUTHORING_WIDTH,\n height: decodeHeight || SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n return { width: decodeWidth, height: decodeHeight };\n}\nfunction overlayExtents(overlays) {\n let maxR = 0;\n let maxB = 0;\n for (const o of overlays) {\n if (!o.visible) continue;\n maxR = Math.max(maxR, o.x + o.width);\n maxB = Math.max(maxB, o.y + o.height);\n }\n return { maxR, maxB };\n}\nfunction swirlProjectHasNabDemoMixedWithOther(overlays) {\n let hasNab = false;\n let hasOther = false;\n for (const o of overlays) {\n if (!o.visible) continue;\n if (o.name.startsWith(NAB_DEMO_NAME_PREFIX)) hasNab = true;\n else hasOther = true;\n }\n return hasNab && hasOther;\n}\nvar STANDARD_16_9_LADDER = [\n { width: 384, height: 216 },\n { width: 640, height: 360 },\n { width: 854, height: 480 },\n { width: 1280, height: 720 },\n { width: 1920, height: 1080 },\n { width: 2560, height: 1440 },\n { width: 3840, height: 2160 }\n];\nfunction smallestLadderRungContaining(maxR, maxB, eps) {\n for (const rung of STANDARD_16_9_LADDER) {\n if (maxR <= rung.width + eps && maxB <= rung.height + eps) return rung;\n }\n return null;\n}\nfunction inferSwirlOverlayCoordinateSpace(overlays, videoWidth, videoHeight) {\n if (!videoWidth || !videoHeight) {\n return {\n width: videoWidth || SWIRL_HD_AUTHORING_WIDTH,\n height: videoHeight || SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n if (!overlays.length) {\n return { width: videoWidth, height: videoHeight };\n }\n const { maxR, maxB } = overlayExtents(overlays);\n const EPS = 1;\n if (maxR <= 0 || maxB <= 0) {\n return { width: videoWidth, height: videoHeight };\n }\n const mixed = swirlProjectHasNabDemoMixedWithOther(overlays);\n const fitsHdCanvas = maxR <= SWIRL_HD_AUTHORING_WIDTH + EPS && maxB <= SWIRL_HD_AUTHORING_HEIGHT + EPS;\n const exceedsDecode = maxR > videoWidth + EPS || maxB > videoHeight + EPS;\n const decodeLargerThanHd = videoWidth > SWIRL_HD_AUTHORING_WIDTH + EPS || videoHeight > SWIRL_HD_AUTHORING_HEIGHT + EPS;\n if (fitsHdCanvas && (decodeLargerThanHd || exceedsDecode && !mixed)) {\n return {\n width: SWIRL_HD_AUTHORING_WIDTH,\n height: SWIRL_HD_AUTHORING_HEIGHT\n };\n }\n if (mixed) {\n return { width: videoWidth, height: videoHeight };\n }\n const rung = smallestLadderRungContaining(maxR, maxB, EPS);\n if (rung && rung.width < videoWidth - EPS && rung.height < videoHeight - EPS) {\n return { width: rung.width, height: rung.height };\n }\n return { width: videoWidth, height: videoHeight };\n}\nfunction normalizeScrollerConfig(raw) {\n if (!raw || typeof raw !== \"object\") return void 0;\n const r = raw;\n const merged = { ...raw };\n if (merged.use_custom_text === void 0 && typeof r.useCustomText === \"boolean\") {\n merged.use_custom_text = r.useCustomText;\n }\n if ((merged.custom_text === void 0 || merged.custom_text === \"\") && typeof r.customText === \"string\") {\n merged.custom_text = r.customText;\n }\n if (!merged.rss_url && typeof r.rssUrl === \"string\") {\n merged.rss_url = r.rssUrl;\n }\n return merged;\n}\nfunction normalizeSwirlOverlay(raw) {\n const o = { ...raw };\n if (o.type === \"scroller\") {\n const sc = raw.scroller_config ?? raw.scrollerConfig;\n const normalized = normalizeScrollerConfig(sc);\n if (normalized) o.scroller_config = normalized;\n }\n return o;\n}\nasync function fetchProjectOverlays(projectId, apiBaseUrl = OVERLAY_API_BASE) {\n const base = apiBaseUrl.replace(/\\/$/, \"\");\n const response = await fetch(\n `${base}/adstorm/swirl/projects/${projectId}/overlays`\n );\n if (!response.ok) {\n throw new Error(\n `Failed to fetch overlays: ${response.status} ${response.statusText}`\n );\n }\n const data = await response.json();\n if (!Array.isArray(data)) return [];\n return data.map(\n (row) => normalizeSwirlOverlay(row)\n );\n}\nfunction resolveImageUrl(imageUrl, apiBaseUrl = OVERLAY_API_BASE) {\n if (!imageUrl) return \"\";\n if (imageUrl.startsWith(\"http://\") || imageUrl.startsWith(\"https://\")) {\n return imageUrl;\n }\n if (imageUrl.startsWith(\"/\")) {\n try {\n const url = new URL(apiBaseUrl);\n return `${url.origin}${imageUrl}`;\n } catch {\n return imageUrl;\n }\n }\n return `${apiBaseUrl}/${imageUrl}`;\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n OVERLAY_API_BASE,\n SWIRL_HD_AUTHORING_HEIGHT,\n SWIRL_HD_AUTHORING_WIDTH,\n fetchProjectOverlays,\n inferSwirlOverlayCoordinateSpace,\n isOverlayActive,\n normalizeSwirlOverlay,\n overlayAuthoringDimensions,\n resolveImageUrl,\n swirlProjectHasNabDemoMixedWithOther,\n timeStringToSeconds\n});\n","export const OVERLAY_API_BASE = \"https://adstorm.co/api-adstorm-dev\";\n\nexport interface OverlayCoordinateSpace {\n width: number;\n height: number;\n}\n\nexport interface SwirlScrollerConfig {\n rss_url?: string;\n update_interval?: number;\n scroll_speed?: number;\n direction?: string;\n font_size?: number;\n font_family?: string;\n font_weight?: string;\n text_color?: string;\n background_color?: string;\n background_opacity?: number;\n border_color?: string;\n border_width?: number;\n border_radius?: number;\n padding?: number;\n margin?: number;\n show_title?: boolean;\n show_description?: boolean;\n show_timestamp?: boolean;\n show_author?: boolean;\n show_category?: boolean;\n max_items?: number;\n item_spacing?: number;\n fade_in_out?: boolean;\n fade_distance?: number;\n auto_refresh?: boolean;\n use_custom_text?: boolean;\n custom_text?: string;\n label?: string;\n label_line2?: string;\n label_color?: string;\n label_text_color?: string;\n accent_color?: string;\n show_accent_line?: boolean;\n separator_char?: string;\n preset?: string;\n}\n\nexport type SwirlOverlayType =\n | \"image\"\n | \"text\"\n | \"scroller\"\n | \"shape\"\n | \"score_bug\"\n | \"lower_third\"\n | \"qr_code\"\n | \"coming_up_next\"\n | \"contextual_trigger\"\n | \"odds_betting\"\n | \"breaking_news\"\n | \"countdown\";\n\nexport interface SwirlOverlay {\n id: number;\n project_id: number;\n name: string;\n type: SwirlOverlayType | string;\n visible: boolean;\n x: number;\n y: number;\n width: number;\n height: number;\n opacity: number;\n start_time: string;\n duration: string;\n content?: string;\n image_url?: string;\n scroller_config?: SwirlScrollerConfig;\n z_index: number;\n created_at?: string;\n updated_at?: string;\n}\n\nexport function timeStringToSeconds(timeStr: string): number {\n if (!timeStr) return 0;\n\n const parts = timeStr.split(\":\");\n\n if (parts.length >= 3) {\n const hours = parseInt(parts[0] ?? \"0\", 10) || 0;\n const minutes = parseInt(parts[1] ?? \"0\", 10) || 0;\n const secStr = parts[2] ?? \"0\";\n const dotIdx = secStr.indexOf(\".\");\n const seconds =\n parseInt(dotIdx >= 0 ? secStr.substring(0, dotIdx) : secStr, 10) || 0;\n const msFrag = dotIdx >= 0 ? secStr.substring(dotIdx + 1) : \"\";\n const ms = msFrag ? parseInt(msFrag.padEnd(3, \"0\").substring(0, 3), 10) || 0 : 0;\n return hours * 3600 + minutes * 60 + seconds + ms / 1000;\n }\n\n if (parts.length === 2) {\n const minutes = parseInt(parts[0] ?? \"0\", 10) || 0;\n const secStr = parts[1] ?? \"0\";\n const dotIdx = secStr.indexOf(\".\");\n const seconds =\n parseInt(dotIdx >= 0 ? secStr.substring(0, dotIdx) : secStr, 10) || 0;\n const msFrag = dotIdx >= 0 ? secStr.substring(dotIdx + 1) : \"\";\n const ms = msFrag ? parseInt(msFrag.padEnd(3, \"0\").substring(0, 3), 10) || 0 : 0;\n return minutes * 60 + seconds + ms / 1000;\n }\n\n const num = parseFloat(timeStr);\n return isFinite(num) ? Math.max(0, num) : 0;\n}\n\nexport function isOverlayActive(\n overlay: SwirlOverlay,\n currentTime: number\n): boolean {\n if (!overlay.visible) return false;\n const startSec = timeStringToSeconds(overlay.start_time);\n const durationSec = timeStringToSeconds(overlay.duration);\n if (durationSec <= 0) return false;\n return currentTime >= startSec && currentTime < startSec + durationSec;\n}\n\nexport const SWIRL_HD_AUTHORING_WIDTH = 1920;\nexport const SWIRL_HD_AUTHORING_HEIGHT = 1080;\n\nconst NAB_DEMO_NAME_PREFIX = \"NAB Demo — \";\n\nexport function overlayAuthoringDimensions(\n overlay: SwirlOverlay,\n decodeWidth: number,\n decodeHeight: number\n): { width: number; height: number } {\n if (overlay.name.startsWith(NAB_DEMO_NAME_PREFIX)) {\n return {\n width: SWIRL_HD_AUTHORING_WIDTH,\n height: SWIRL_HD_AUTHORING_HEIGHT,\n };\n }\n if (!decodeWidth || !decodeHeight) {\n return {\n width: decodeWidth || SWIRL_HD_AUTHORING_WIDTH,\n height: decodeHeight || SWIRL_HD_AUTHORING_HEIGHT,\n };\n }\n return { width: decodeWidth, height: decodeHeight };\n}\n\nfunction overlayExtents(overlays: SwirlOverlay[]): { maxR: number; maxB: number } {\n let maxR = 0;\n let maxB = 0;\n for (const o of overlays) {\n if (!o.visible) continue;\n maxR = Math.max(maxR, o.x + o.width);\n maxB = Math.max(maxB, o.y + o.height);\n }\n return { maxR, maxB };\n}\n\nexport function swirlProjectHasNabDemoMixedWithOther(overlays: SwirlOverlay[]): boolean {\n let hasNab = false;\n let hasOther = false;\n for (const o of overlays) {\n if (!o.visible) continue;\n if (o.name.startsWith(NAB_DEMO_NAME_PREFIX)) hasNab = true;\n else hasOther = true;\n }\n return hasNab && hasOther;\n}\n\nconst STANDARD_16_9_LADDER: ReadonlyArray<OverlayCoordinateSpace> = [\n { width: 384, height: 216 },\n { width: 640, height: 360 },\n { width: 854, height: 480 },\n { width: 1280, height: 720 },\n { width: 1920, height: 1080 },\n { width: 2560, height: 1440 },\n { width: 3840, height: 2160 },\n];\n\nfunction smallestLadderRungContaining(\n maxR: number,\n maxB: number,\n eps: number\n): OverlayCoordinateSpace | null {\n for (const rung of STANDARD_16_9_LADDER) {\n if (maxR <= rung.width + eps && maxB <= rung.height + eps) return rung;\n }\n return null;\n}\n\nexport function inferSwirlOverlayCoordinateSpace(\n overlays: SwirlOverlay[],\n videoWidth: number,\n videoHeight: number\n): OverlayCoordinateSpace {\n if (!videoWidth || !videoHeight) {\n return {\n width: videoWidth || SWIRL_HD_AUTHORING_WIDTH,\n height: videoHeight || SWIRL_HD_AUTHORING_HEIGHT,\n };\n }\n if (!overlays.length) {\n return { width: videoWidth, height: videoHeight };\n }\n\n const { maxR, maxB } = overlayExtents(overlays);\n const EPS = 1;\n\n if (maxR <= 0 || maxB <= 0) {\n return { width: videoWidth, height: videoHeight };\n }\n\n const mixed = swirlProjectHasNabDemoMixedWithOther(overlays);\n const fitsHdCanvas =\n maxR <= SWIRL_HD_AUTHORING_WIDTH + EPS &&\n maxB <= SWIRL_HD_AUTHORING_HEIGHT + EPS;\n const exceedsDecode = maxR > videoWidth + EPS || maxB > videoHeight + EPS;\n const decodeLargerThanHd =\n videoWidth > SWIRL_HD_AUTHORING_WIDTH + EPS ||\n videoHeight > SWIRL_HD_AUTHORING_HEIGHT + EPS;\n\n if (fitsHdCanvas && (decodeLargerThanHd || (exceedsDecode && !mixed))) {\n return {\n width: SWIRL_HD_AUTHORING_WIDTH,\n height: SWIRL_HD_AUTHORING_HEIGHT,\n };\n }\n\n if (mixed) {\n return { width: videoWidth, height: videoHeight };\n }\n\n const rung = smallestLadderRungContaining(maxR, maxB, EPS);\n if (rung && rung.width < videoWidth - EPS && rung.height < videoHeight - EPS) {\n return { width: rung.width, height: rung.height };\n }\n\n return { width: videoWidth, height: videoHeight };\n}\n\nfunction normalizeScrollerConfig(\n raw: SwirlScrollerConfig | Record<string, unknown> | undefined\n): SwirlScrollerConfig | undefined {\n if (!raw || typeof raw !== \"object\") return undefined;\n const r = raw as Record<string, unknown>;\n const merged: SwirlScrollerConfig = { ...(raw as SwirlScrollerConfig) };\n if (merged.use_custom_text === undefined && typeof r.useCustomText === \"boolean\") {\n merged.use_custom_text = r.useCustomText;\n }\n if ((merged.custom_text === undefined || merged.custom_text === \"\") && typeof r.customText === \"string\") {\n merged.custom_text = r.customText;\n }\n if (!merged.rss_url && typeof r.rssUrl === \"string\") {\n merged.rss_url = r.rssUrl;\n }\n return merged;\n}\n\nexport function normalizeSwirlOverlay(raw: SwirlOverlay & Record<string, unknown>): SwirlOverlay {\n const o = { ...raw };\n if (o.type === \"scroller\") {\n const sc = raw.scroller_config ?? (raw as Record<string, unknown>).scrollerConfig;\n const normalized = normalizeScrollerConfig(sc as SwirlScrollerConfig);\n if (normalized) o.scroller_config = normalized;\n }\n return o;\n}\n\nexport async function fetchProjectOverlays(\n projectId: number,\n apiBaseUrl: string = OVERLAY_API_BASE\n): Promise<SwirlOverlay[]> {\n const base = apiBaseUrl.replace(/\\/$/, \"\");\n const response = await fetch(\n `${base}/adstorm/swirl/projects/${projectId}/overlays`\n );\n if (!response.ok) {\n throw new Error(\n `Failed to fetch overlays: ${response.status} ${response.statusText}`\n );\n }\n const data = await response.json();\n if (!Array.isArray(data)) return [];\n return data.map((row: SwirlOverlay & Record<string, unknown>) =>\n normalizeSwirlOverlay(row)\n );\n}\n\nexport function resolveImageUrl(\n imageUrl: string,\n apiBaseUrl: string = OVERLAY_API_BASE\n): string {\n if (!imageUrl) return \"\";\n if (imageUrl.startsWith(\"http://\") || imageUrl.startsWith(\"https://\")) {\n return imageUrl;\n }\n if (imageUrl.startsWith(\"/\")) {\n try {\n const url = new URL(apiBaseUrl);\n return `${url.origin}${imageUrl}`;\n } catch {\n return imageUrl;\n }\n }\n return `${apiBaseUrl}/${imageUrl}`;\n}\n"]}
|