@pie-element/shared-utils 0.1.5-next.20261012010413 → 0.1.5-next.20261016234357

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
@@ -5,4 +5,5 @@
5
5
  */
6
6
  export * from './utils.js';
7
7
  export * from './sanitize-model-html.js';
8
+ export * from './prompt-audio.js';
8
9
  export { AUTHORED_BORDER_ATTR, AUTHORED_FILL_ATTR, AUTHORED_INK_ATTR, markAuthoredColors, type AuthoredFill, } from './authored-colors.js';
package/dist/index.js CHANGED
@@ -59,12 +59,12 @@ function d(e, t) {
59
59
  }
60
60
  //#endregion
61
61
  //#region src/authored-colors.ts
62
- var f = "data-pie-authored-ink", p = "data-pie-authored-fill", m = "data-pie-authored-border", h = [
62
+ var f = "data-pie-authored-ink", p = "data-pie-authored-fill", m = "data-pie-authored-border", ee = [
63
63
  "border-top-color",
64
64
  "border-right-color",
65
65
  "border-bottom-color",
66
66
  "border-left-color"
67
- ], g = /* @__PURE__ */ new Set([
67
+ ], te = /* @__PURE__ */ new Set([
68
68
  "currentcolor",
69
69
  "inherit",
70
70
  "initial",
@@ -73,35 +73,35 @@ var f = "data-pie-authored-ink", p = "data-pie-authored-fill", m = "data-pie-aut
73
73
  "revert-layer",
74
74
  "transparent"
75
75
  ]);
76
- function _(e) {
76
+ function h(e) {
77
77
  let t = e?.trim().toLowerCase();
78
- return !t || g.has(t) || t.includes("var(") ? !1 : b(t)?.a !== 0;
78
+ return !t || te.has(t) || t.includes("var(") ? !1 : v(t)?.a !== 0;
79
79
  }
80
- function ee(e) {
81
- let t = b(e);
80
+ function ne(e) {
81
+ let t = v(e);
82
82
  if (!t) return "shade";
83
83
  let n = (e) => (e * t.a + 255 * (1 - t.a)) / 255, [r, i, a] = [
84
84
  n(t.r),
85
85
  n(t.g),
86
86
  n(t.b)
87
- ], o = .2126 * B(r) + .7152 * B(i) + .0722 * B(a), s = Math.max(r, i, a) - Math.min(r, i, a);
87
+ ], o = .2126 * I(r) + .7152 * I(i) + .0722 * I(a), s = Math.max(r, i, a) - Math.min(r, i, a);
88
88
  return o >= .85 && s <= .08 ? "light" : "shade";
89
89
  }
90
- function v(e) {
90
+ function g(e) {
91
91
  e.removeAttribute(f), e.removeAttribute(p), e.removeAttribute(m);
92
92
  let t = e.hasAttribute("style") ? e.style : void 0, n = (e) => t?.getPropertyValue(e).trim() ?? "", r = [], i = n("color"), a = e.localName === "font" ? e.getAttribute("color") : null;
93
- _(i || a) && (e.setAttribute(f, ""), i && r.push("color"));
94
- let o = n("background-color"), s = o || y(e.getAttribute("bgcolor"));
95
- _(s) && (e.setAttribute(p, ee(s)), o && r.push("background-color"));
96
- let c = h.filter((e) => _(n(e)));
93
+ h(i || a) && (e.setAttribute(f, ""), i && r.push("color"));
94
+ let o = n("background-color"), s = o || _(e.getAttribute("bgcolor"));
95
+ h(s) && (e.setAttribute(p, ne(s)), o && r.push("background-color"));
96
+ let c = ee.filter((e) => h(n(e)));
97
97
  c.length && (e.setAttribute(m, ""), r.push(...c));
98
98
  for (let e of r) t?.getPropertyPriority(e) === "important" && t.setProperty(e, t.getPropertyValue(e));
99
99
  }
100
- function y(e) {
100
+ function _(e) {
101
101
  let t = e?.trim() ?? "";
102
102
  return /^(?:[\da-f]{3}|[\da-f]{6})$/i.test(t) ? `#${t}` : t;
103
103
  }
104
- function b(e) {
104
+ function v(e) {
105
105
  let t = e.trim().toLowerCase();
106
106
  if (t === "transparent") return {
107
107
  r: 0,
@@ -109,14 +109,14 @@ function b(e) {
109
109
  b: 0,
110
110
  a: 0
111
111
  };
112
- let n = S().get(t);
113
- if (n) return C(n);
114
- if (t.startsWith("#")) return C(t.slice(1));
112
+ let n = b().get(t);
113
+ if (n) return x(n);
114
+ if (t.startsWith("#")) return x(t.slice(1));
115
115
  let r = /^([a-z]+)\(([^()]*)\)$/.exec(t);
116
116
  if (!r) return null;
117
117
  let i = r[2].trim().split(/\s*[\s,/]\s*/);
118
118
  if (i.length !== 3 && i.length !== 4) return null;
119
- let [a, o, s, c] = i, l = D(c), u;
119
+ let [a, o, s, c] = i, l = re(c), u;
120
120
  switch (r[1]) {
121
121
  case "rgb":
122
122
  case "rgba":
@@ -124,31 +124,31 @@ function b(e) {
124
124
  a,
125
125
  o,
126
126
  s
127
- ].map((e) => T(e, 255) / 255);
127
+ ].map((e) => C(e, 255) / 255);
128
128
  break;
129
129
  case "hsl":
130
130
  case "hsla":
131
- u = k(E(a), T(o, 100) / 100, T(s, 100) / 100);
131
+ u = E(w(a), C(o, 100) / 100, C(s, 100) / 100);
132
132
  break;
133
133
  case "hwb":
134
- u = A(E(a), T(o, 100) / 100, T(s, 100) / 100);
134
+ u = D(w(a), C(o, 100) / 100, C(s, 100) / 100);
135
135
  break;
136
136
  case "lab":
137
- u = I(T(a, 100), T(o, 125), T(s, 125));
137
+ u = M(C(a, 100), C(o, 125), C(s, 125));
138
138
  break;
139
139
  case "lch":
140
- u = I(T(a, 100), ...O(T(o, 150), E(s)));
140
+ u = M(C(a, 100), ...T(C(o, 150), w(s)));
141
141
  break;
142
142
  case "oklab":
143
- u = L(T(a, 1), T(o, .4), T(s, .4));
143
+ u = N(C(a, 1), C(o, .4), C(s, .4));
144
144
  break;
145
145
  case "oklch":
146
- u = L(T(a, 1), ...O(T(o, .4), E(s)));
146
+ u = N(C(a, 1), ...T(C(o, .4), w(s)));
147
147
  break;
148
148
  default: return null;
149
149
  }
150
150
  if (Number.isNaN(l) || u.some(Number.isNaN)) return null;
151
- let [d, f, p] = u.map((e) => V(e, 0, 1) * 255);
151
+ let [d, f, p] = u.map((e) => L(e, 0, 1) * 255);
152
152
  return {
153
153
  r: d,
154
154
  g: f,
@@ -156,11 +156,11 @@ function b(e) {
156
156
  a: l
157
157
  };
158
158
  }
159
- var x;
160
- function S() {
161
- return x ??= new Map("aliceblue:f0f8ff antiquewhite:faebd7 aqua:00ffff aquamarine:7fffd4 azure:f0ffff beige:f5f5dc bisque:ffe4c4 black:000000 blanchedalmond:ffebcd blue:0000ff blueviolet:8a2be2 brown:a52a2a burlywood:deb887 cadetblue:5f9ea0 chartreuse:7fff00 chocolate:d2691e coral:ff7f50 cornflowerblue:6495ed cornsilk:fff8dc crimson:dc143c cyan:00ffff darkblue:00008b darkcyan:008b8b darkgoldenrod:b8860b darkgray:a9a9a9 darkgreen:006400 darkgrey:a9a9a9 darkkhaki:bdb76b darkmagenta:8b008b darkolivegreen:556b2f darkorange:ff8c00 darkorchid:9932cc darkred:8b0000 darksalmon:e9967a darkseagreen:8fbc8f darkslateblue:483d8b darkslategray:2f4f4f darkslategrey:2f4f4f darkturquoise:00ced1 darkviolet:9400d3 deeppink:ff1493 deepskyblue:00bfff dimgray:696969 dimgrey:696969 dodgerblue:1e90ff firebrick:b22222 floralwhite:fffaf0 forestgreen:228b22 fuchsia:ff00ff gainsboro:dcdcdc ghostwhite:f8f8ff gold:ffd700 goldenrod:daa520 gray:808080 green:008000 greenyellow:adff2f grey:808080 honeydew:f0fff0 hotpink:ff69b4 indianred:cd5c5c indigo:4b0082 ivory:fffff0 khaki:f0e68c lavender:e6e6fa lavenderblush:fff0f5 lawngreen:7cfc00 lemonchiffon:fffacd lightblue:add8e6 lightcoral:f08080 lightcyan:e0ffff lightgoldenrodyellow:fafad2 lightgray:d3d3d3 lightgreen:90ee90 lightgrey:d3d3d3 lightpink:ffb6c1 lightsalmon:ffa07a lightseagreen:20b2aa lightskyblue:87cefa lightslategray:778899 lightslategrey:778899 lightsteelblue:b0c4de lightyellow:ffffe0 lime:00ff00 limegreen:32cd32 linen:faf0e6 magenta:ff00ff maroon:800000 mediumaquamarine:66cdaa mediumblue:0000cd mediumorchid:ba55d3 mediumpurple:9370db mediumseagreen:3cb371 mediumslateblue:7b68ee mediumspringgreen:00fa9a mediumturquoise:48d1cc mediumvioletred:c71585 midnightblue:191970 mintcream:f5fffa mistyrose:ffe4e1 moccasin:ffe4b5 navajowhite:ffdead navy:000080 oldlace:fdf5e6 olive:808000 olivedrab:6b8e23 orange:ffa500 orangered:ff4500 orchid:da70d6 palegoldenrod:eee8aa palegreen:98fb98 paleturquoise:afeeee palevioletred:db7093 papayawhip:ffefd5 peachpuff:ffdab9 peru:cd853f pink:ffc0cb plum:dda0dd powderblue:b0e0e6 purple:800080 rebeccapurple:663399 red:ff0000 rosybrown:bc8f8f royalblue:4169e1 saddlebrown:8b4513 salmon:fa8072 sandybrown:f4a460 seagreen:2e8b57 seashell:fff5ee sienna:a0522d silver:c0c0c0 skyblue:87ceeb slateblue:6a5acd slategray:708090 slategrey:708090 snow:fffafa springgreen:00ff7f steelblue:4682b4 tan:d2b48c teal:008080 thistle:d8bfd8 tomato:ff6347 turquoise:40e0d0 violet:ee82ee wheat:f5deb3 white:ffffff whitesmoke:f5f5f5 yellow:ffff00 yellowgreen:9acd32".split(" ").map((e) => e.split(":"))), x;
159
+ var y;
160
+ function b() {
161
+ return y ??= new Map("aliceblue:f0f8ff antiquewhite:faebd7 aqua:00ffff aquamarine:7fffd4 azure:f0ffff beige:f5f5dc bisque:ffe4c4 black:000000 blanchedalmond:ffebcd blue:0000ff blueviolet:8a2be2 brown:a52a2a burlywood:deb887 cadetblue:5f9ea0 chartreuse:7fff00 chocolate:d2691e coral:ff7f50 cornflowerblue:6495ed cornsilk:fff8dc crimson:dc143c cyan:00ffff darkblue:00008b darkcyan:008b8b darkgoldenrod:b8860b darkgray:a9a9a9 darkgreen:006400 darkgrey:a9a9a9 darkkhaki:bdb76b darkmagenta:8b008b darkolivegreen:556b2f darkorange:ff8c00 darkorchid:9932cc darkred:8b0000 darksalmon:e9967a darkseagreen:8fbc8f darkslateblue:483d8b darkslategray:2f4f4f darkslategrey:2f4f4f darkturquoise:00ced1 darkviolet:9400d3 deeppink:ff1493 deepskyblue:00bfff dimgray:696969 dimgrey:696969 dodgerblue:1e90ff firebrick:b22222 floralwhite:fffaf0 forestgreen:228b22 fuchsia:ff00ff gainsboro:dcdcdc ghostwhite:f8f8ff gold:ffd700 goldenrod:daa520 gray:808080 green:008000 greenyellow:adff2f grey:808080 honeydew:f0fff0 hotpink:ff69b4 indianred:cd5c5c indigo:4b0082 ivory:fffff0 khaki:f0e68c lavender:e6e6fa lavenderblush:fff0f5 lawngreen:7cfc00 lemonchiffon:fffacd lightblue:add8e6 lightcoral:f08080 lightcyan:e0ffff lightgoldenrodyellow:fafad2 lightgray:d3d3d3 lightgreen:90ee90 lightgrey:d3d3d3 lightpink:ffb6c1 lightsalmon:ffa07a lightseagreen:20b2aa lightskyblue:87cefa lightslategray:778899 lightslategrey:778899 lightsteelblue:b0c4de lightyellow:ffffe0 lime:00ff00 limegreen:32cd32 linen:faf0e6 magenta:ff00ff maroon:800000 mediumaquamarine:66cdaa mediumblue:0000cd mediumorchid:ba55d3 mediumpurple:9370db mediumseagreen:3cb371 mediumslateblue:7b68ee mediumspringgreen:00fa9a mediumturquoise:48d1cc mediumvioletred:c71585 midnightblue:191970 mintcream:f5fffa mistyrose:ffe4e1 moccasin:ffe4b5 navajowhite:ffdead navy:000080 oldlace:fdf5e6 olive:808000 olivedrab:6b8e23 orange:ffa500 orangered:ff4500 orchid:da70d6 palegoldenrod:eee8aa palegreen:98fb98 paleturquoise:afeeee palevioletred:db7093 papayawhip:ffefd5 peachpuff:ffdab9 peru:cd853f pink:ffc0cb plum:dda0dd powderblue:b0e0e6 purple:800080 rebeccapurple:663399 red:ff0000 rosybrown:bc8f8f royalblue:4169e1 saddlebrown:8b4513 salmon:fa8072 sandybrown:f4a460 seagreen:2e8b57 seashell:fff5ee sienna:a0522d silver:c0c0c0 skyblue:87ceeb slateblue:6a5acd slategray:708090 slategrey:708090 snow:fffafa springgreen:00ff7f steelblue:4682b4 tan:d2b48c teal:008080 thistle:d8bfd8 tomato:ff6347 turquoise:40e0d0 violet:ee82ee wheat:f5deb3 white:ffffff whitesmoke:f5f5f5 yellow:ffff00 yellowgreen:9acd32".split(" ").map((e) => e.split(":"))), y;
162
162
  }
163
- function C(e) {
163
+ function x(e) {
164
164
  if (!/^(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/.test(e)) return null;
165
165
  let [t, n, r, i = 255] = (e.length <= 4 ? [...e].map((e) => e + e) : e.match(/../g) ?? []).map((e) => Number.parseInt(e, 16));
166
166
  return {
@@ -170,28 +170,28 @@ function C(e) {
170
170
  a: i / 255
171
171
  };
172
172
  }
173
- var w = /^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%|deg|rad|grad|turn)?$/;
174
- function T(e, t) {
173
+ var S = /^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%|deg|rad|grad|turn)?$/;
174
+ function C(e, t) {
175
175
  if (e === "none") return 0;
176
- let n = w.exec(e);
176
+ let n = S.exec(e);
177
177
  return !n || n[2] && n[2] !== "%" ? NaN : n[2] ? Number(n[1]) / 100 * t : Number(n[1]);
178
178
  }
179
- function E(e) {
179
+ function w(e) {
180
180
  if (e === "none") return 0;
181
- let t = w.exec(e);
181
+ let t = S.exec(e);
182
182
  if (!t || t[2] === "%") return NaN;
183
183
  let n = Number(t[1]);
184
184
  return ((t[2] === "rad" ? n * 180 / Math.PI : t[2] === "grad" ? n * .9 : t[2] === "turn" ? n * 360 : n) % 360 + 360) % 360;
185
185
  }
186
- function D(e) {
187
- return e === void 0 ? 1 : V(T(e, 1), 0, 1);
186
+ function re(e) {
187
+ return e === void 0 ? 1 : L(C(e, 1), 0, 1);
188
188
  }
189
- function O(e, t) {
189
+ function T(e, t) {
190
190
  let n = Math.max(0, e), r = t * Math.PI / 180;
191
191
  return [n * Math.cos(r), n * Math.sin(r)];
192
192
  }
193
- function k(e, t, n) {
194
- let r = V(t, 0, 1), i = V(n, 0, 1), a = (t) => {
193
+ function E(e, t, n) {
194
+ let r = L(t, 0, 1), i = L(n, 0, 1), a = (t) => {
195
195
  let n = (t + e / 30) % 12, a = r * Math.min(i, 1 - i);
196
196
  return i - a * Math.max(-1, Math.min(n - 3, 9 - n, 1));
197
197
  };
@@ -201,19 +201,19 @@ function k(e, t, n) {
201
201
  a(4)
202
202
  ];
203
203
  }
204
- function A(e, t, n) {
205
- let r = V(t, 0, 1), i = V(n, 0, 1);
204
+ function D(e, t, n) {
205
+ let r = L(t, 0, 1), i = L(n, 0, 1);
206
206
  return r + i >= 1 ? [
207
207
  ,
208
208
  ,
209
209
  ,
210
- ].fill(r / (r + i)) : k(e, 1, .5).map((e) => e * (1 - r - i) + r);
210
+ ].fill(r / (r + i)) : E(e, 1, .5).map((e) => e * (1 - r - i) + r);
211
211
  }
212
- var j = 24389 / 27, M = 216 / 24389, N = [
212
+ var O = 24389 / 27, k = 216 / 24389, ie = [
213
213
  .3457 / .3585,
214
214
  1,
215
215
  .2958 / .3585
216
- ], P = [
216
+ ], A = [
217
217
  [
218
218
  .955473421488075,
219
219
  -.02309845494876471,
@@ -229,7 +229,7 @@ var j = 24389 / 27, M = 216 / 24389, N = [
229
229
  -.020507649298898964,
230
230
  1.330365926242124
231
231
  ]
232
- ], F = [
232
+ ], j = [
233
233
  [
234
234
  12831 / 3959,
235
235
  -329 / 214,
@@ -246,17 +246,17 @@ var j = 24389 / 27, M = 216 / 24389, N = [
246
246
  705 / 667
247
247
  ]
248
248
  ];
249
- function I(e, t, n) {
250
- let r = V(e, 0, 100), i = (r + 16) / 116, a = t / 500 + i, o = i - n / 200;
251
- return R(F, R(P, [
252
- a ** 3 > M ? a ** 3 : (116 * a - 16) / j,
253
- r > j * M ? i ** 3 : r / j,
254
- o ** 3 > M ? o ** 3 : (116 * o - 16) / j
255
- ].map((e, t) => e * N[t]))).map(z);
256
- }
257
- function L(e, t, n) {
258
- let r = V(e, 0, 1);
259
- return R([
249
+ function M(e, t, n) {
250
+ let r = L(e, 0, 100), i = (r + 16) / 116, a = t / 500 + i, o = i - n / 200;
251
+ return P(j, P(A, [
252
+ a ** 3 > k ? a ** 3 : (116 * a - 16) / O,
253
+ r > O * k ? i ** 3 : r / O,
254
+ o ** 3 > k ? o ** 3 : (116 * o - 16) / O
255
+ ].map((e, t) => e * ie[t]))).map(F);
256
+ }
257
+ function N(e, t, n) {
258
+ let r = L(e, 0, 1);
259
+ return P([
260
260
  [
261
261
  4.0767416621,
262
262
  -3.3077115913,
@@ -276,24 +276,38 @@ function L(e, t, n) {
276
276
  r + .3963377774 * t + .2158037573 * n,
277
277
  r - .1055613458 * t - .0638541728 * n,
278
278
  r - .0894841775 * t - 1.291485548 * n
279
- ].map((e) => e ** 3)).map(z);
279
+ ].map((e) => e ** 3)).map(F);
280
280
  }
281
- function R(e, t) {
281
+ function P(e, t) {
282
282
  return e.map((e) => e[0] * t[0] + e[1] * t[1] + e[2] * t[2]);
283
283
  }
284
- function z(e) {
285
- let t = V(e, 0, 1);
284
+ function F(e) {
285
+ let t = L(e, 0, 1);
286
286
  return t <= .0031308 ? 12.92 * t : 1.055 * t ** (1 / 2.4) - .055;
287
287
  }
288
- function B(e) {
288
+ function I(e) {
289
289
  return e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
290
290
  }
291
- function V(e, t, n) {
291
+ function L(e, t, n) {
292
292
  return Math.min(n, Math.max(t, e));
293
293
  }
294
294
  //#endregion
295
+ //#region src/prompt-audio.ts
296
+ var ae = (e) => !!e?.autoplayAudioEnabled && !e?.autoplayAudioHeld, R = ["autoplay"], z = "data-pie-audio-failed", B = (e) => !!e.getAttribute("src") || !!e.querySelector("source[src]:not([src=\"\"])");
297
+ function V(e, t, n) {
298
+ if (n || t?.audioEndTime) return !1;
299
+ let r = e?.querySelector("audio");
300
+ return r?.closest(".preview-prompt") ? B(r) && r.error === null && !r.hasAttribute(z) : !1;
301
+ }
302
+ function H(e, t) {
303
+ let n = () => {
304
+ e.setAttribute(z, ""), t();
305
+ };
306
+ return e.addEventListener("error", n, !0), () => e.removeEventListener("error", n, !0);
307
+ }
308
+ //#endregion
295
309
  //#region src/sanitize-model-html.ts
296
- var H = [
310
+ var U = [
297
311
  "script",
298
312
  "embed",
299
313
  "base",
@@ -302,7 +316,7 @@ var H = [
302
316
  "link",
303
317
  "style",
304
318
  "foreignobject"
305
- ], U = [
319
+ ], W = [
306
320
  "onerror",
307
321
  "onload",
308
322
  "onclick",
@@ -320,7 +334,7 @@ var H = [
320
334
  "onbeforeunload",
321
335
  "formaction",
322
336
  "xlink:href"
323
- ], W = /* @__PURE__ */ new Set([
337
+ ], G = /* @__PURE__ */ new Set([
324
338
  "iframe",
325
339
  "object",
326
340
  "mstack",
@@ -333,7 +347,7 @@ var H = [
333
347
  "semantics",
334
348
  "annotation",
335
349
  "none"
336
- ]), G = /^[a-z_][\w.-]*:[a-z][\w.-]*$/, K = [
350
+ ]), K = /^[a-z_][\w.-]*:[a-z][\w.-]*$/, q = [
337
351
  "alignment",
338
352
  "target",
339
353
  "allow",
@@ -353,18 +367,18 @@ var H = [
353
367
  "rightoverhang",
354
368
  "mslinethickness",
355
369
  "linebreak"
356
- ], q = /^\s*document\.getElementById\((['"])([^'"]+)\1\)\.play\(\)\s*;?\s*(?:return\s+false\s*;?\s*)?$/, J = "data-pie-play-audio", Y = {
357
- ADD_TAGS: (e) => W.has(e) || G.test(e),
358
- ADD_ATTR: K,
359
- FORBID_TAGS: H,
360
- FORBID_ATTR: U,
370
+ ], J = /^\s*document\.getElementById\((['"])([^'"]+)\1\)\.play\(\)\s*;?\s*(?:return\s+false\s*;?\s*)?$/, Y = "data-pie-play-audio", oe = {
371
+ ADD_TAGS: (e) => G.has(e) || K.test(e),
372
+ ADD_ATTR: q,
373
+ FORBID_TAGS: U,
374
+ FORBID_ATTR: [...W, ...R],
361
375
  ALLOW_UNKNOWN_PROTOCOLS: !1,
362
376
  RETURN_TRUSTED_TYPE: !1
363
- }, te = !1;
364
- function ne(e) {
377
+ }, se = !1;
378
+ function ce(e) {
365
379
  for (let t of e.composedPath()) {
366
380
  if (!(t instanceof Element)) continue;
367
- let n = t.getAttribute(J);
381
+ let n = t.getAttribute(Y);
368
382
  if (n === null) continue;
369
383
  e.preventDefault();
370
384
  let r = t.getRootNode().getElementById?.(n) ?? document.getElementById(n);
@@ -373,19 +387,19 @@ function ne(e) {
373
387
  }
374
388
  }
375
389
  var X = null;
376
- function re() {
390
+ function le() {
377
391
  return X || (X = e(window), X.addHook("beforeSanitizeAttributes", (e) => {
378
392
  if (e.nodeName !== "A") return;
379
- let t = q.exec(e.getAttribute("onclick") ?? "")?.[2];
380
- t !== void 0 && (e.removeAttribute("onclick"), e.setAttribute(J, t), te ||= (document.addEventListener("click", ne), !0));
381
- }), X.addHook("afterSanitizeAttributes", v), X);
393
+ let t = J.exec(e.getAttribute("onclick") ?? "")?.[2];
394
+ t !== void 0 && (e.removeAttribute("onclick"), e.setAttribute(Y, t), se ||= (document.addEventListener("click", ce), !0));
395
+ }), X.addHook("afterSanitizeAttributes", g), X);
382
396
  }
383
397
  var Z = 1e6, Q = /* @__PURE__ */ new Map(), $ = 0;
384
- function ie(t) {
398
+ function ue(t) {
385
399
  if (t == null || t === "" || !e.isSupported) return "";
386
400
  let n = typeof t == "string" ? t : String(t), r = Q.get(n);
387
401
  if (r !== void 0) return r;
388
- let i = String(re().sanitize(n, Y)), a = n.length + i.length;
402
+ let i = String(le().sanitize(n, oe)), a = n.length + i.length;
389
403
  if (a > Z) return i;
390
404
  for (let [e, t] of Q) {
391
405
  if ($ + a <= Z) break;
@@ -394,4 +408,4 @@ function ie(t) {
394
408
  return Q.set(n, i), $ += a, i;
395
409
  }
396
410
  //#endregion
397
- export { m as AUTHORED_BORDER_ATTR, p as AUTHORED_FILL_ATTR, f as AUTHORED_INK_ATTR, U as MODEL_HTML_FORBIDDEN_ATTRS, H as MODEL_HTML_FORBIDDEN_TAGS, J as PLAY_AUDIO_ATTR, u as assignProps, a as clamp, s as debounce, t as debug, n as isEmpty, v as markAuthoredColors, ie as sanitizeModelHtml, d as sessionsEqual, r as showFeedback, i as showRationale, c as shuffle, o as uuid };
411
+ export { m as AUTHORED_BORDER_ATTR, p as AUTHORED_FILL_ATTR, f as AUTHORED_INK_ATTR, R as AUTOPLAY_AUDIO_MARKUP_ATTRS, W as MODEL_HTML_FORBIDDEN_ATTRS, U as MODEL_HTML_FORBIDDEN_TAGS, Y as PLAY_AUDIO_ATTR, u as assignProps, ae as autoplayAudioOn, a as clamp, s as debounce, t as debug, n as isEmpty, g as markAuthoredColors, V as promptAudioPending, ue as sanitizeModelHtml, d as sessionsEqual, r as showFeedback, i as showRationale, c as shuffle, H as trackPromptAudioFailure, o as uuid };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Autoplay and completion rules for a prompt's audio, shared by the elements with an authored
3
+ * `autoplayAudioEnabled` setting.
4
+ */
5
+ export interface AutoplayAudioFields {
6
+ autoplayAudioEnabled?: boolean;
7
+ /** Written by pie-players' item player when the toolkit holds autoplay for the item. */
8
+ autoplayAudioHeld?: boolean;
9
+ }
10
+ /** Whether the prompt audio starts on its own. A hold outranks the authored setting. */
11
+ export declare const autoplayAudioOn: (fields?: AutoplayAudioFields | null) => boolean;
12
+ /**
13
+ * The markup switches `autoplayAudioEnabled` replaces. `sanitizeModelHtml` removes them from
14
+ * model HTML, so the model setting is the only start for prompt audio and a hold can stop it.
15
+ * pie-players' item player removes the same from item markup through its autoplay applier.
16
+ */
17
+ export declare const AUTOPLAY_AUDIO_MARKUP_ATTRS: readonly string[];
18
+ /**
19
+ * Whether `completeAudioEnabled` still waits on the prompt audio in `root`. It waits on the
20
+ * first `<audio>` when that sits in a prompt, has a source, has not failed to load, and neither
21
+ * this mount nor the session (`audioEndTime`, kept across a resume) records it as played.
22
+ */
23
+ export declare function promptAudioPending(root: ParentNode | null | undefined, session: {
24
+ audioEndTime?: number;
25
+ } | null | undefined, audioComplete: boolean): boolean;
26
+ /**
27
+ * Marks the audio failed when it cannot load, so `promptAudioPending` stops waiting on it, and
28
+ * calls `onFailure`. A `<source>` reports its failure on itself, so the listener captures.
29
+ * Returns the listener's remover.
30
+ */
31
+ export declare function trackPromptAudioFailure(audio: HTMLAudioElement, onFailure: () => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/shared-utils",
3
- "version": "0.1.5-next.20261012010413",
3
+ "version": "0.1.5-next.20261016234357",
4
4
  "description": "Shared utilities for PIE elements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",