@kubohiroya/turbowarp-bubble 0.10.0 → 0.12.0

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/reveal.js CHANGED
@@ -1,21 +1,44 @@
1
+ //#region src/content-run.ts
2
+ function e(e) {
3
+ return e.every((e) => e.type === "text");
4
+ }
5
+ function t(e) {
6
+ return e.map((e) => e.type === "ruby" ? e.base : e.text).join("");
7
+ }
8
+ function n(e) {
9
+ let t = [];
10
+ for (let n of e) {
11
+ let e = t[t.length - 1];
12
+ if (n.type === "text" && e?.type === "text") {
13
+ t[t.length - 1] = Object.freeze({
14
+ text: `${e.text}${n.text}`,
15
+ type: "text"
16
+ });
17
+ continue;
18
+ }
19
+ t.push(n);
20
+ }
21
+ return Object.freeze(t);
22
+ }
23
+ //#endregion
1
24
  //#region src/reveal.ts
2
- var e = Object.freeze([
25
+ var r = Object.freeze([
3
26
  "CHARACTER",
4
27
  "WORD",
5
28
  "LINE",
6
29
  "BLOCK"
7
30
  ]);
8
- function t(e) {
31
+ function i(e) {
9
32
  let t = globalThis.Intl?.Segmenter;
10
33
  return typeof t == "function" ? [...new t(void 0, { granularity: "grapheme" }).segment(e)].map(({ segment: e }) => e) : Array.from(e);
11
34
  }
12
- function n(t) {
13
- if (typeof t != "string" || !e.includes(t)) throw TypeError("Bubble reveal unit must be CHARACTER, WORD, LINE, or BLOCK.");
14
- return t;
35
+ function a(e) {
36
+ if (typeof e != "string" || !r.includes(e)) throw TypeError("Bubble reveal unit must be CHARACTER, WORD, LINE, or BLOCK.");
37
+ return e;
15
38
  }
16
- function r(e) {
39
+ function o(e) {
17
40
  if (typeof e != "object" || !e || Array.isArray(e)) throw TypeError("Bubble reveal must be an object.");
18
- let t = e, r = /* @__PURE__ */ new Set([
41
+ let t = e, n = /* @__PURE__ */ new Set([
19
42
  "unit",
20
43
  "delimiters",
21
44
  "showDelimiters",
@@ -23,9 +46,9 @@ function r(e) {
23
46
  "intervalSeconds",
24
47
  "sound"
25
48
  ]);
26
- if (Object.keys(t).filter((e) => !r.has(e)).length > 0 || t.unit === void 0) throw TypeError("Bubble reveal has unknown or missing properties.");
27
- let i = n(t.unit), a = t.delimiters ?? " \r\n";
28
- if (typeof a != "string" || a.length === 0) throw TypeError("Bubble WORD delimiters must be a non-empty string.");
49
+ if (Object.keys(t).filter((e) => !n.has(e)).length > 0 || t.unit === void 0) throw TypeError("Bubble reveal has unknown or missing properties.");
50
+ let r = a(t.unit), i = t.delimiters ?? " \r\n";
51
+ if (typeof i != "string" || i.length === 0) throw TypeError("Bubble WORD delimiters must be a non-empty string.");
29
52
  let o = t.showDelimiters ?? !1;
30
53
  if (typeof o != "boolean") throw TypeError("Bubble reveal showDelimiters must be boolean.");
31
54
  let s = t.layout ?? "DYNAMIC";
@@ -35,43 +58,88 @@ function r(e) {
35
58
  let l = t.sound;
36
59
  if (l !== void 0 && (typeof l != "string" || l.length === 0)) throw TypeError("Bubble reveal sound must be a non-empty asset name.");
37
60
  return Object.freeze({
38
- unit: i,
39
- delimiters: a,
61
+ unit: r,
62
+ delimiters: i,
40
63
  showDelimiters: o,
41
64
  layout: s,
42
65
  intervalSeconds: c,
43
66
  ...l === void 0 ? {} : { sound: l }
44
67
  });
45
68
  }
46
- function i(e, n, r) {
47
- let i = new Set(Array.from(n)), a = [], o = "";
48
- for (let n of t(e)) o += n, i.has(n) && ((r || o.slice(0, -n.length).length > 0) && a.push(r ? o : o.slice(0, -n.length)), o = "");
69
+ function s(e, t, n) {
70
+ let r = new Set(Array.from(t)), a = [], o = "";
71
+ for (let t of i(e)) o += t, r.has(t) && ((n || o.slice(0, -t.length).length > 0) && a.push(n ? o : o.slice(0, -t.length)), o = "");
49
72
  return o.length > 0 && a.push(o), a.filter((e) => e.length > 0);
50
73
  }
51
- function a(e, n) {
74
+ function c(e, t) {
52
75
  if (e.length === 0) return Object.freeze([""]);
53
- if (n.unit === "CHARACTER") return Object.freeze(t(e));
54
- if (n.unit === "WORD") {
55
- let t = i(e, n.delimiters, n.showDelimiters);
56
- if (n.showDelimiters) return Object.freeze(t);
57
- let r = [], a = 0;
58
- for (let i of t) {
59
- let t = e.indexOf(i, a);
60
- if (t < 0) r.push(i);
61
- else for (r.push(i), a = t + i.length; a < e.length && n.delimiters.includes(e[a] ?? "");) a += 1;
76
+ if (t.unit === "CHARACTER") return Object.freeze(i(e));
77
+ if (t.unit === "WORD") {
78
+ let n = s(e, t.delimiters, t.showDelimiters);
79
+ if (t.showDelimiters) return Object.freeze(n);
80
+ let r = [], i = 0;
81
+ for (let a of n) {
82
+ let n = e.indexOf(a, i);
83
+ if (n < 0) r.push(a);
84
+ else for (r.push(a), i = n + a.length; i < e.length && t.delimiters.includes(e[i] ?? "");) i += 1;
62
85
  }
63
86
  return Object.freeze(r);
64
87
  }
65
- let r = n.unit === "LINE" ? /(?<=\n)/u : /\n{2,}/u, a = e.split(r).filter((e) => e.length > 0);
66
- if (n.unit === "BLOCK") {
67
- let t = [...e.matchAll(/\n{2,}/gu)].map(([e]) => e), n = a.map((e, n) => n < t.length ? `${e}${t[n] ?? ""}` : e);
88
+ let n = t.unit === "LINE" ? /(?<=\n)/u : /\n{2,}/u, r = e.split(n).filter((e) => e.length > 0);
89
+ if (t.unit === "BLOCK") {
90
+ let t = [...e.matchAll(/\n{2,}/gu)].map(([e]) => e), n = r.map((e, n) => n < t.length ? `${e}${t[n] ?? ""}` : e);
68
91
  return Object.freeze(n.length > 0 ? n : [e]);
69
92
  }
70
- let o = a;
71
- return Object.freeze(o.length > 0 ? o : [e]);
93
+ let a = r;
94
+ return Object.freeze(a.length > 0 ? a : [e]);
72
95
  }
73
- function o(e, t) {
96
+ function l(e, t) {
74
97
  return e.slice(0, Math.max(0, Math.min(t, e.length))).join("");
75
98
  }
99
+ function u(e) {
100
+ return Object.freeze(n(Object.freeze([...e])));
101
+ }
102
+ function d(e) {
103
+ return Object.freeze({
104
+ text: e,
105
+ type: "text"
106
+ });
107
+ }
108
+ function f(e, t) {
109
+ let n = [], r = [], i = () => {
110
+ r.length !== 0 && (n.push(u(r)), r = []);
111
+ };
112
+ for (let n of e) {
113
+ if (n.type === "ruby") {
114
+ r.push(n);
115
+ continue;
116
+ }
117
+ if (t === "LINE") {
118
+ for (let e of n.text.split(/(?<=\n)/u)) e.length !== 0 && (r.push(d(e)), e.endsWith("\n") && i());
119
+ continue;
120
+ }
121
+ let e = n.text.split(/(\n{2,})/u);
122
+ for (let [t, n] of e.entries()) n.length !== 0 && (r.push(d(n)), t % 2 == 1 && i());
123
+ }
124
+ return i(), Object.freeze(n.length > 0 ? n : [u(e)]);
125
+ }
126
+ function p(n, r) {
127
+ if (e(n)) return Object.freeze(c(t(n), r).map((e) => Object.freeze([d(e)])));
128
+ if (r.unit === "LINE" || r.unit === "BLOCK") return f(n, r.unit);
129
+ let a = [];
130
+ for (let e of n) {
131
+ if (e.type === "ruby") {
132
+ a.push(Object.freeze([e]));
133
+ continue;
134
+ }
135
+ let t = r.unit === "CHARACTER" ? i(e.text) : s(e.text, r.delimiters, r.showDelimiters);
136
+ for (let e of t) a.push(Object.freeze([d(e)]));
137
+ }
138
+ return Object.freeze(a.length > 0 ? a : [Object.freeze([d("")])]);
139
+ }
140
+ function m(e, t) {
141
+ let r = e.slice(0, Math.max(0, Math.min(t, e.length)));
142
+ return n(Object.freeze(r.flat()));
143
+ }
76
144
  //#endregion
77
- export { e as bubbleRevealUnits, r as normalizeBubbleReveal, o as revealedBubbleText, a as splitBubbleText };
145
+ export { r as bubbleRevealUnits, o as normalizeBubbleReveal, m as revealedBubbleContent, l as revealedBubbleText, p as splitBubbleContent, c as splitBubbleText };