@bendyline/squisq-react 2.12.9 → 2.12.10
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/{chunk-3SMC447F.js → chunk-4JZJEJNO.js} +117 -18
- package/dist/index.js +1 -1
- package/dist/player/index.js +1 -1
- package/dist/squisq-player.full.global.js +203 -202
- package/dist/squisq-player.global.js +55 -54
- package/dist/standalone-player-full.js +1 -1
- package/dist/standalone-source.js +1 -1
- package/package.json +2 -2
|
@@ -523,6 +523,9 @@ var SOCIAL_CAPTION_LAYOUT = {
|
|
|
523
523
|
chunkPadXEm: 0.55,
|
|
524
524
|
letterSpacingEm: 0.01
|
|
525
525
|
};
|
|
526
|
+
function socialCaptionLayout(textCase = "upper") {
|
|
527
|
+
return textCase === "upper" ? SOCIAL_CAPTION_LAYOUT : { ...SOCIAL_CAPTION_LAYOUT, columnGapEm: 0.16 };
|
|
528
|
+
}
|
|
526
529
|
var CHAR_EM = {
|
|
527
530
|
A: 0.76,
|
|
528
531
|
B: 0.76,
|
|
@@ -582,28 +585,116 @@ var CHAR_EM = {
|
|
|
582
585
|
"\xB0": 0.42,
|
|
583
586
|
$: 0.64
|
|
584
587
|
};
|
|
588
|
+
var AS_WRITTEN_CHAR_EM = {
|
|
589
|
+
A: 0.76,
|
|
590
|
+
B: 0.76,
|
|
591
|
+
C: 0.74,
|
|
592
|
+
D: 0.83,
|
|
593
|
+
E: 0.72,
|
|
594
|
+
F: 0.67,
|
|
595
|
+
G: 0.81,
|
|
596
|
+
H: 0.91,
|
|
597
|
+
I: 0.45,
|
|
598
|
+
J: 0.6,
|
|
599
|
+
K: 0.82,
|
|
600
|
+
L: 0.69,
|
|
601
|
+
M: 1.02,
|
|
602
|
+
N: 0.84,
|
|
603
|
+
O: 0.82,
|
|
604
|
+
P: 0.7,
|
|
605
|
+
Q: 0.82,
|
|
606
|
+
R: 0.8,
|
|
607
|
+
S: 0.67,
|
|
608
|
+
T: 0.68,
|
|
609
|
+
U: 0.83,
|
|
610
|
+
V: 0.76,
|
|
611
|
+
W: 1.13,
|
|
612
|
+
X: 0.81,
|
|
613
|
+
Y: 0.73,
|
|
614
|
+
Z: 0.69,
|
|
615
|
+
a: 0.6,
|
|
616
|
+
b: 0.65,
|
|
617
|
+
c: 0.57,
|
|
618
|
+
d: 0.66,
|
|
619
|
+
e: 0.57,
|
|
620
|
+
f: 0.39,
|
|
621
|
+
g: 0.61,
|
|
622
|
+
h: 0.68,
|
|
623
|
+
i: 0.35,
|
|
624
|
+
j: 0.35,
|
|
625
|
+
k: 0.63,
|
|
626
|
+
l: 0.34,
|
|
627
|
+
m: 1.02,
|
|
628
|
+
n: 0.69,
|
|
629
|
+
o: 0.64,
|
|
630
|
+
p: 0.66,
|
|
631
|
+
q: 0.65,
|
|
632
|
+
r: 0.52,
|
|
633
|
+
s: 0.56,
|
|
634
|
+
t: 0.4,
|
|
635
|
+
u: 0.68,
|
|
636
|
+
v: 0.57,
|
|
637
|
+
w: 0.86,
|
|
638
|
+
x: 0.59,
|
|
639
|
+
y: 0.56,
|
|
640
|
+
z: 0.53,
|
|
641
|
+
"0": 0.7,
|
|
642
|
+
"1": 0.57,
|
|
643
|
+
"2": 0.63,
|
|
644
|
+
"3": 0.62,
|
|
645
|
+
"4": 0.65,
|
|
646
|
+
"5": 0.6,
|
|
647
|
+
"6": 0.65,
|
|
648
|
+
"7": 0.57,
|
|
649
|
+
"8": 0.68,
|
|
650
|
+
"9": 0.65,
|
|
651
|
+
"'": 0.28,
|
|
652
|
+
"\u2019": 0.31,
|
|
653
|
+
".": 0.33,
|
|
654
|
+
",": 0.33,
|
|
655
|
+
";": 0.37,
|
|
656
|
+
":": 0.37,
|
|
657
|
+
"!": 0.38,
|
|
658
|
+
"?": 0.61,
|
|
659
|
+
"-": 0.41,
|
|
660
|
+
"\u2013": 0.7,
|
|
661
|
+
"\u2014": 1,
|
|
662
|
+
'"': 0.51,
|
|
663
|
+
"\u201C": 0.52,
|
|
664
|
+
"\u201D": 0.52,
|
|
665
|
+
"(": 0.45,
|
|
666
|
+
")": 0.45,
|
|
667
|
+
"%": 1,
|
|
668
|
+
"&": 0.9,
|
|
669
|
+
"/": 0.47,
|
|
670
|
+
"\xB0": 0.44,
|
|
671
|
+
$: 0.64
|
|
672
|
+
};
|
|
585
673
|
var DEFAULT_CHAR_EM = 0.9;
|
|
586
674
|
var WIDTH_SAFETY = 1.06;
|
|
587
|
-
function estimateSocialWordEm(text) {
|
|
675
|
+
function estimateSocialWordEm(text, textCase = "upper") {
|
|
676
|
+
const upper = textCase === "upper";
|
|
677
|
+
const table = upper ? CHAR_EM : AS_WRITTEN_CHAR_EM;
|
|
588
678
|
let em = 0;
|
|
589
679
|
let count = 0;
|
|
590
|
-
for (const ch of text.toUpperCase().normalize("NFD").replace(/\p{M}/gu, "")) {
|
|
591
|
-
em +=
|
|
680
|
+
for (const ch of (upper ? text.toUpperCase() : text).normalize("NFD").replace(/\p{M}/gu, "")) {
|
|
681
|
+
em += table[ch] ?? DEFAULT_CHAR_EM;
|
|
592
682
|
count++;
|
|
593
683
|
}
|
|
594
|
-
const { letterSpacingEm
|
|
595
|
-
return (em + count *
|
|
684
|
+
const { letterSpacingEm, wordPadEm } = socialCaptionLayout(textCase);
|
|
685
|
+
return (em + count * letterSpacingEm) * WIDTH_SAFETY + 2 * wordPadEm;
|
|
596
686
|
}
|
|
597
|
-
function estimateSocialRows(words, rowEm) {
|
|
687
|
+
function estimateSocialRows(words, rowEm, textCase = "upper") {
|
|
688
|
+
const { columnGapEm } = socialCaptionLayout(textCase);
|
|
598
689
|
let rows = 0;
|
|
599
690
|
let x = 0;
|
|
600
691
|
for (const word of words) {
|
|
601
|
-
const width = estimateSocialWordEm(word);
|
|
692
|
+
const width = estimateSocialWordEm(word, textCase);
|
|
602
693
|
if (rows === 0) {
|
|
603
694
|
rows = 1;
|
|
604
695
|
x = width;
|
|
605
|
-
} else if (x +
|
|
606
|
-
x +=
|
|
696
|
+
} else if (x + columnGapEm + width <= rowEm) {
|
|
697
|
+
x += columnGapEm + width;
|
|
607
698
|
} else {
|
|
608
699
|
rows++;
|
|
609
700
|
x = width;
|
|
@@ -611,12 +702,16 @@ function estimateSocialRows(words, rowEm) {
|
|
|
611
702
|
}
|
|
612
703
|
return rows;
|
|
613
704
|
}
|
|
705
|
+
function endsSentence(text) {
|
|
706
|
+
return /[.!?…]["'”’»)\]]*$/.test(text);
|
|
707
|
+
}
|
|
614
708
|
function resolvePhraseTiming(phrase) {
|
|
615
709
|
if (phrase.words && phrase.words.length > 0) {
|
|
616
710
|
return phrase.words.map((w) => ({
|
|
617
711
|
text: w.text,
|
|
618
712
|
startTime: w.startTime,
|
|
619
|
-
endTime: w.endTime
|
|
713
|
+
endTime: w.endTime,
|
|
714
|
+
...w.paragraphEnd ? { paragraphEnd: true } : {}
|
|
620
715
|
}));
|
|
621
716
|
}
|
|
622
717
|
const rawWords = phrase.text.split(/\s+/).filter((w) => w.length > 0);
|
|
@@ -629,7 +724,7 @@ function resolvePhraseTiming(phrase) {
|
|
|
629
724
|
endTime: phrase.startTime + (i + 1) * wordDuration
|
|
630
725
|
}));
|
|
631
726
|
}
|
|
632
|
-
function buildWordStream(captions, rowEm = Number.POSITIVE_INFINITY) {
|
|
727
|
+
function buildWordStream(captions, rowEm = Number.POSITIVE_INFINITY, textCase = "upper") {
|
|
633
728
|
const allWords = [];
|
|
634
729
|
for (const phrase of captions.phrases) {
|
|
635
730
|
for (const word of resolvePhraseTiming(phrase))
|
|
@@ -656,7 +751,7 @@ function buildWordStream(captions, rowEm = Number.POSITIVE_INFINITY) {
|
|
|
656
751
|
current = [];
|
|
657
752
|
};
|
|
658
753
|
for (const word of allWords) {
|
|
659
|
-
if (current.length > 0 && (current.length >= chunkSize || word.segment !== current[0].segment || estimateSocialRows([...current.map((w) => w.text), word.text], rowEm) > SOCIAL_CAPTION_MAX_ROWS)) {
|
|
754
|
+
if (current.length > 0 && (current.length >= chunkSize || word.segment !== current[0].segment || current[current.length - 1].paragraphEnd || current.length >= MIN_CHUNK_SIZE && endsSentence(current[current.length - 1].text) || estimateSocialRows([...current.map((w) => w.text), word.text], rowEm, textCase) > SOCIAL_CAPTION_MAX_ROWS)) {
|
|
660
755
|
close();
|
|
661
756
|
}
|
|
662
757
|
current.push(word);
|
|
@@ -667,7 +762,6 @@ function buildWordStream(captions, rowEm = Number.POSITIVE_INFINITY) {
|
|
|
667
762
|
|
|
668
763
|
// src/SocialCaptionOverlay.tsx
|
|
669
764
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
670
|
-
var { wordPadEm, columnGapEm, chunkPadXEm, letterSpacingEm } = SOCIAL_CAPTION_LAYOUT;
|
|
671
765
|
function positionStyle(position, portrait) {
|
|
672
766
|
switch (position) {
|
|
673
767
|
case "top":
|
|
@@ -703,10 +797,12 @@ function SocialCaptionOverlay({
|
|
|
703
797
|
const baseFontSize = Math.min(viewportHeight * 0.055, viewportWidth * 0.068);
|
|
704
798
|
const fontSize = Math.max(22, Math.min(96, Math.round(baseFontSize)));
|
|
705
799
|
const sidePadding = portrait ? 0.07 : 0.1;
|
|
800
|
+
const textCase = theme?.typography?.captionCase ?? "upper";
|
|
801
|
+
const { wordPadEm, columnGapEm, chunkPadXEm, letterSpacingEm } = socialCaptionLayout(textCase);
|
|
706
802
|
const rowEm = viewportWidth * (1 - 2 * sidePadding) / fontSize - 2 * chunkPadXEm;
|
|
707
803
|
const { chunks } = useMemo3(
|
|
708
|
-
() => captions ? buildWordStream(captions, rowEm) : { words: [], chunks: [] },
|
|
709
|
-
[captions, rowEm]
|
|
804
|
+
() => captions ? buildWordStream(captions, rowEm, textCase) : { words: [], chunks: [] },
|
|
805
|
+
[captions, rowEm, textCase]
|
|
710
806
|
);
|
|
711
807
|
if (!enabled || chunks.length === 0) {
|
|
712
808
|
return /* @__PURE__ */ jsx2(
|
|
@@ -765,8 +861,11 @@ function SocialCaptionOverlay({
|
|
|
765
861
|
if (activeWordIndex === -1) activeWordIndex = 0;
|
|
766
862
|
}
|
|
767
863
|
const primaryColor = theme?.colors?.primary ?? "#5b9bd5";
|
|
768
|
-
const
|
|
769
|
-
const
|
|
864
|
+
const captionFont = theme?.typography?.captionFont ?? theme?.typography?.titleFont;
|
|
865
|
+
const fontFamily = captionFont ? resolveFontFamily(captionFont, '"PT Serif", Georgia, serif') : '"PT Serif", Georgia, serif';
|
|
866
|
+
const widestEm = Math.max(
|
|
867
|
+
...activeChunk.words.map((w) => estimateSocialWordEm(w.text, textCase))
|
|
868
|
+
);
|
|
770
869
|
const chunkFontSize = widestEm > rowEm ? Math.max(16, Math.floor(fontSize * rowEm / widestEm)) : fontSize;
|
|
771
870
|
return /* @__PURE__ */ jsx2(
|
|
772
871
|
"div",
|
|
@@ -806,7 +905,7 @@ function SocialCaptionOverlay({
|
|
|
806
905
|
fontFamily,
|
|
807
906
|
fontSize: `${chunkFontSize}px`,
|
|
808
907
|
lineHeight: 1.18,
|
|
809
|
-
textTransform: "uppercase",
|
|
908
|
+
textTransform: textCase === "upper" ? "uppercase" : "none",
|
|
810
909
|
letterSpacing: `${letterSpacingEm}em`,
|
|
811
910
|
whiteSpace: "normal"
|
|
812
911
|
},
|
package/dist/index.js
CHANGED
package/dist/player/index.js
CHANGED