@vosjs/studio-core 0.40.0 → 0.40.1

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RichText, LayoutRun } from '@vosjs/elements/text';
2
- export { CaretStop, DECORATION_THICKNESS_EM, Fragment, HIGHLIGHT_HALF_EM, LayoutInput, LayoutLine, LayoutRun, LayoutUnit, Unit as LayoutUnitBox, MIXED, RUN_STYLE_KEYS, RichText, RunStyle, RunStyleKey, STRIKE_OFFSET_EM, TextLayout, Measure as TextMeasure, TextRun, TextRunStyle, UNDERLINE_OFFSET_EM, caretAt, caretStops, clearStyle, commonStyle, decorationRect, diffInput, layoutText, lineOfOffset, normalizeRuns, offsetAtX, plainText, rangeRects, replaceRange, runsOf, setStyle, sliceRuns, snapOffset, styleAt, styleOf, toggleStyle, tokenRanges } from '@vosjs/elements/text';
2
+ export { CaretStop, DECORATION_THICKNESS_EM, DataRef, Fragment, HIGHLIGHT_HALF_EM, LayoutInput, LayoutLine, LayoutRun, LayoutUnit, Unit as LayoutUnitBox, MIXED, RUN_STYLE_KEYS, RichText, RunColor, RunStyle, RunStyleKey, STRIKE_OFFSET_EM, TextLayout, Measure as TextMeasure, TextRun, TextRunStyle, UNDERLINE_OFFSET_EM, caretAt, caretStops, clearStyle, commonStyle, decorationRect, diffInput, isDataRef, layoutText, lineOfOffset, normalizeRuns, offsetAtX, plainText, rangeRects, replaceRange, resolveRunColors, runsOf, setStyle, sliceRuns, snapOffset, styleAt, styleOf, toggleStyle, tokenRanges } from '@vosjs/elements/text';
3
3
  import { Segment, KeyframeTrack } from '@vosjs/timeline';
4
4
  export { Segment } from '@vosjs/timeline';
5
5
  import { TimelineEdit } from '@vosjs/shared/timelineEdits';
package/dist/index.js CHANGED
@@ -2213,7 +2213,7 @@ function htmlLayerPayload(clip) {
2213
2213
  };
2214
2214
  }
2215
2215
 
2216
- // ../elements/dist/chunk-GYJBPCR2.js
2216
+ // ../elements/dist/chunk-ZHIPLA3M.js
2217
2217
  var sameStyle = (a, b) => (a.f || 0) === (b.f || 0) && a.c === b.c && a.u === b.u && a.s === b.s && a.h === b.h;
2218
2218
  function graphemesOf(text) {
2219
2219
  if (typeof Intl !== "undefined" && typeof Intl.Segmenter === "function") {
@@ -2375,6 +2375,9 @@ function decorationRect(kind, x, w, y, px) {
2375
2375
  );
2376
2376
  return { x: x0, y: top, w: x1 - x0, h: t };
2377
2377
  }
2378
+ function isDataRef(value) {
2379
+ return typeof value === "object" && value !== null && typeof value.$data === "string" && value.$data.length > 0;
2380
+ }
2378
2381
  var RUN_STYLE_KEYS = [
2379
2382
  "weight",
2380
2383
  "italic",
@@ -2393,17 +2396,24 @@ function plainText(text) {
2393
2396
  function runsOf(text) {
2394
2397
  return typeof text === "string" ? text ? [{ text }] : [] : text;
2395
2398
  }
2399
+ function colorOf(value) {
2400
+ if (typeof value === "string") return value || void 0;
2401
+ return isDataRef(value) ? { $data: value.$data } : void 0;
2402
+ }
2403
+ var sameValue = (a, b) => a === b || isDataRef(a) && isDataRef(b) && a.$data === b.$data;
2396
2404
  function styleOf(run) {
2397
2405
  const out = {};
2398
2406
  if (typeof run.weight === "number") out.weight = run.weight;
2399
2407
  if (typeof run.italic === "boolean") out.italic = run.italic;
2400
- if (run.color) out.color = run.color;
2408
+ const color = colorOf(run.color);
2409
+ if (color) out.color = color;
2401
2410
  if (run.underline) out.underline = true;
2402
2411
  if (run.strike) out.strike = true;
2403
- if (run.highlight) out.highlight = run.highlight;
2412
+ const highlight = colorOf(run.highlight);
2413
+ if (highlight) out.highlight = highlight;
2404
2414
  return out;
2405
2415
  }
2406
- var sameStyle2 = (a, b) => RUN_STYLE_KEYS.every((k) => a[k] === b[k]);
2416
+ var sameStyle2 = (a, b) => RUN_STYLE_KEYS.every((k) => sameValue(a[k], b[k]));
2407
2417
  var isStyled = (s) => RUN_STYLE_KEYS.some((k) => s[k] !== void 0);
2408
2418
  function normalizeRuns(text) {
2409
2419
  if (typeof text === "string") return text;
@@ -2419,16 +2429,36 @@ function normalizeRuns(text) {
2419
2429
  if (out.length === 1 && !isStyled(out[0])) return out[0].text;
2420
2430
  return out;
2421
2431
  }
2432
+ function resolveRunColors(text, data) {
2433
+ if (typeof text === "string") return text;
2434
+ const read = (value) => {
2435
+ if (!isDataRef(value)) return value;
2436
+ const v = data?.[value.$data];
2437
+ return typeof v === "string" && v ? v : void 0;
2438
+ };
2439
+ return normalizeRuns(
2440
+ text.map((run) => {
2441
+ const { color, highlight, ...rest } = run;
2442
+ const c = read(color);
2443
+ const h = read(highlight);
2444
+ return {
2445
+ ...rest,
2446
+ ...c ? { color: c } : {},
2447
+ ...h ? { highlight: h } : {}
2448
+ };
2449
+ })
2450
+ );
2451
+ }
2422
2452
  function layoutLines(text, fontOf) {
2423
2453
  const lines = [[]];
2424
2454
  for (const run of runsOf(text)) {
2425
2455
  const f = fontOf(run);
2426
2456
  const set = {
2427
2457
  ...f ? { f } : {},
2428
- ...run.color ? { c: run.color } : {},
2458
+ ...typeof run.color === "string" && run.color ? { c: run.color } : {},
2429
2459
  ...run.underline ? { u: 1 } : {},
2430
2460
  ...run.strike ? { s: 1 } : {},
2431
- ...run.highlight ? { h: run.highlight } : {}
2461
+ ...typeof run.highlight === "string" && run.highlight ? { h: run.highlight } : {}
2432
2462
  };
2433
2463
  run.text.split("\n").forEach((part, i) => {
2434
2464
  if (i > 0) lines.push([]);
@@ -2520,7 +2550,7 @@ function commonStyle(text, start, end) {
2520
2550
  if (!runs.length) return styleAt(text, start);
2521
2551
  for (const k of RUN_STYLE_KEYS) {
2522
2552
  const first = styleOf(runs[0])[k];
2523
- const agree = runs.every((run) => styleOf(run)[k] === first);
2553
+ const agree = runs.every((run) => sameValue(styleOf(run)[k], first));
2524
2554
  if (!agree) out[k] = MIXED;
2525
2555
  else if (first !== void 0) out[k] = first;
2526
2556
  }
@@ -12489,6 +12519,7 @@ export {
12489
12519
  htmlStarterClip,
12490
12520
  idleGaps,
12491
12521
  idleKey,
12522
+ isDataRef,
12492
12523
  isKeyedOverlay,
12493
12524
  isLookKind,
12494
12525
  isMusicBed,
@@ -12587,6 +12618,7 @@ export {
12587
12618
  resolveOverlayBox,
12588
12619
  resolveOverlayStyle,
12589
12620
  resolvePins,
12621
+ resolveRunColors,
12590
12622
  resolveText3dAsset,
12591
12623
  resolveZoomStyle,
12592
12624
  restLeanOf,