@pie-element/shared-utils 0.1.7-next.20261026200905 → 0.1.7-next.20261027193325
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 +1 -0
- package/dist/index.js +85 -76
- package/dist/inline-direction.d.ts +13 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export * from './utils.js';
|
|
|
7
7
|
export * from './sanitize-model-html.js';
|
|
8
8
|
export * from './prompt-audio.js';
|
|
9
9
|
export { isComposingKeyEvent } from './ime.js';
|
|
10
|
+
export { inlineSideOfArrow, isRightToLeft, type InlineSide } from './inline-direction.js';
|
|
10
11
|
export { AUTHORED_BORDER_ATTR, AUTHORED_FILL_ATTR, AUTHORED_INK_ATTR, markAuthoredColors, type AuthoredFill, } from './authored-colors.js';
|
package/dist/index.js
CHANGED
|
@@ -84,7 +84,7 @@ function ne(e) {
|
|
|
84
84
|
n(t.r),
|
|
85
85
|
n(t.g),
|
|
86
86
|
n(t.b)
|
|
87
|
-
], o = .2126 *
|
|
87
|
+
], o = .2126 * P(r) + .7152 * P(i) + .0722 * P(a), s = Math.max(r, i, a) - Math.min(r, i, a);
|
|
88
88
|
return o >= .85 && s <= .08 ? "light" : "shade";
|
|
89
89
|
}
|
|
90
90
|
function g(e) {
|
|
@@ -134,21 +134,21 @@ function v(e) {
|
|
|
134
134
|
u = ae(C(a), S(o, 100) / 100, S(s, 100) / 100);
|
|
135
135
|
break;
|
|
136
136
|
case "lab":
|
|
137
|
-
u =
|
|
137
|
+
u = A(S(a, 100), S(o, 125), S(s, 125));
|
|
138
138
|
break;
|
|
139
139
|
case "lch":
|
|
140
|
-
u =
|
|
140
|
+
u = A(S(a, 100), ...w(S(o, 150), C(s)));
|
|
141
141
|
break;
|
|
142
142
|
case "oklab":
|
|
143
|
-
u =
|
|
143
|
+
u = j(S(a, 1), S(o, .4), S(s, .4));
|
|
144
144
|
break;
|
|
145
145
|
case "oklch":
|
|
146
|
-
u =
|
|
146
|
+
u = j(S(a, 1), ...w(S(o, .4), C(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) =>
|
|
151
|
+
let [d, f, p] = u.map((e) => F(e, 0, 1) * 255);
|
|
152
152
|
return {
|
|
153
153
|
r: d,
|
|
154
154
|
g: f,
|
|
@@ -184,14 +184,14 @@ function C(e) {
|
|
|
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
186
|
function ie(e) {
|
|
187
|
-
return e === void 0 ? 1 :
|
|
187
|
+
return e === void 0 ? 1 : F(S(e, 1), 0, 1);
|
|
188
188
|
}
|
|
189
189
|
function w(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
193
|
function T(e, t, n) {
|
|
194
|
-
let r =
|
|
194
|
+
let r = F(t, 0, 1), i = F(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
|
};
|
|
@@ -202,18 +202,18 @@ function T(e, t, n) {
|
|
|
202
202
|
];
|
|
203
203
|
}
|
|
204
204
|
function ae(e, t, n) {
|
|
205
|
-
let r =
|
|
205
|
+
let r = F(t, 0, 1), i = F(n, 0, 1);
|
|
206
206
|
return r + i >= 1 ? [
|
|
207
207
|
,
|
|
208
208
|
,
|
|
209
209
|
,
|
|
210
210
|
].fill(r / (r + i)) : T(e, 1, .5).map((e) => e * (1 - r - i) + r);
|
|
211
211
|
}
|
|
212
|
-
var E = 24389 / 27, D = 216 / 24389,
|
|
212
|
+
var E = 24389 / 27, D = 216 / 24389, oe = [
|
|
213
213
|
.3457 / .3585,
|
|
214
214
|
1,
|
|
215
215
|
.2958 / .3585
|
|
216
|
-
],
|
|
216
|
+
], O = [
|
|
217
217
|
[
|
|
218
218
|
.955473421488075,
|
|
219
219
|
-.02309845494876471,
|
|
@@ -229,7 +229,7 @@ var E = 24389 / 27, D = 216 / 24389, O = [
|
|
|
229
229
|
-.020507649298898964,
|
|
230
230
|
1.330365926242124
|
|
231
231
|
]
|
|
232
|
-
],
|
|
232
|
+
], k = [
|
|
233
233
|
[
|
|
234
234
|
12831 / 3959,
|
|
235
235
|
-329 / 214,
|
|
@@ -246,17 +246,17 @@ var E = 24389 / 27, D = 216 / 24389, O = [
|
|
|
246
246
|
705 / 667
|
|
247
247
|
]
|
|
248
248
|
];
|
|
249
|
-
function
|
|
250
|
-
let r =
|
|
251
|
-
return
|
|
249
|
+
function A(e, t, n) {
|
|
250
|
+
let r = F(e, 0, 100), i = (r + 16) / 116, a = t / 500 + i, o = i - n / 200;
|
|
251
|
+
return M(k, M(O, [
|
|
252
252
|
a ** 3 > D ? a ** 3 : (116 * a - 16) / E,
|
|
253
253
|
r > E * D ? i ** 3 : r / E,
|
|
254
254
|
o ** 3 > D ? o ** 3 : (116 * o - 16) / E
|
|
255
|
-
].map((e, t) => e *
|
|
255
|
+
].map((e, t) => e * oe[t]))).map(N);
|
|
256
256
|
}
|
|
257
|
-
function
|
|
258
|
-
let r =
|
|
259
|
-
return
|
|
257
|
+
function j(e, t, n) {
|
|
258
|
+
let r = F(e, 0, 1);
|
|
259
|
+
return M([
|
|
260
260
|
[
|
|
261
261
|
4.0767416621,
|
|
262
262
|
-3.3077115913,
|
|
@@ -276,25 +276,25 @@ function M(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(
|
|
279
|
+
].map((e) => e ** 3)).map(N);
|
|
280
280
|
}
|
|
281
|
-
function
|
|
281
|
+
function M(e, t) {
|
|
282
282
|
return e.map((e) => e[0] * t[0] + e[1] * t[1] + e[2] * t[2]);
|
|
283
283
|
}
|
|
284
|
-
function
|
|
285
|
-
let t =
|
|
284
|
+
function N(e) {
|
|
285
|
+
let t = F(e, 0, 1);
|
|
286
286
|
return t <= .0031308 ? 12.92 * t : 1.055 * t ** (1 / 2.4) - .055;
|
|
287
287
|
}
|
|
288
|
-
function
|
|
288
|
+
function P(e) {
|
|
289
289
|
return e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
|
|
290
290
|
}
|
|
291
|
-
function
|
|
291
|
+
function F(e, t, n) {
|
|
292
292
|
return Math.min(n, Math.max(t, e));
|
|
293
293
|
}
|
|
294
294
|
//#endregion
|
|
295
295
|
//#region src/prompt-audio.ts
|
|
296
|
-
var
|
|
297
|
-
function
|
|
296
|
+
var I = (e) => !!e?.autoplayAudioEnabled && !e?.autoplayAudioHeld, L = ["autoplay"];
|
|
297
|
+
function R(e, t) {
|
|
298
298
|
let n = e.audioStartTime || t.audioStartTime, r = e.audioEndTime || t.audioEndTime, i = {
|
|
299
299
|
...e,
|
|
300
300
|
...n ? { audioStartTime: n } : {},
|
|
@@ -302,7 +302,7 @@ function z(e, t) {
|
|
|
302
302
|
};
|
|
303
303
|
return !i.waitTime && n && r && (i.waitTime = r - n), i;
|
|
304
304
|
}
|
|
305
|
-
var
|
|
305
|
+
var se = class {
|
|
306
306
|
#e;
|
|
307
307
|
#t;
|
|
308
308
|
#n = !1;
|
|
@@ -335,27 +335,27 @@ var oe = class {
|
|
|
335
335
|
this.#n = e;
|
|
336
336
|
}
|
|
337
337
|
#i(e) {
|
|
338
|
-
let t = this.#e.session() ?? {}, n =
|
|
338
|
+
let t = this.#e.session() ?? {}, n = R(t, e);
|
|
339
339
|
(n.audioStartTime !== t.audioStartTime || n.audioEndTime !== t.audioEndTime || n.waitTime !== t.waitTime) && this.#e.writeSession(n);
|
|
340
340
|
}
|
|
341
|
-
},
|
|
342
|
-
function
|
|
343
|
-
t.follow(
|
|
341
|
+
}, z = (e) => e.getAttribute("src") || e.querySelector("source[src]:not([src=\"\"])")?.getAttribute("src") || "";
|
|
342
|
+
function B(e, t) {
|
|
343
|
+
t.follow(z(e));
|
|
344
344
|
let n = () => t.recordStart(), r = () => t.recordEnd(), i = () => t.recordFailure();
|
|
345
345
|
return e.addEventListener("playing", n), e.addEventListener("ended", r), e.addEventListener("error", i, !0), () => {
|
|
346
346
|
e.removeEventListener("playing", n), e.removeEventListener("ended", r), e.removeEventListener("error", i, !0);
|
|
347
347
|
};
|
|
348
348
|
}
|
|
349
|
-
var
|
|
349
|
+
var V = (e) => {
|
|
350
350
|
let t = e?.querySelector("audio");
|
|
351
351
|
return t?.closest(".preview-prompt") ? t : null;
|
|
352
352
|
};
|
|
353
|
-
function
|
|
353
|
+
function H(e, t) {
|
|
354
354
|
if (!t.pending) return !1;
|
|
355
|
-
let n =
|
|
356
|
-
return !!n &&
|
|
355
|
+
let n = V(e);
|
|
356
|
+
return !!n && z(n) !== "" && n.error === null;
|
|
357
357
|
}
|
|
358
|
-
var
|
|
358
|
+
var U = "play-audio-info", W = 500, G = class {
|
|
359
359
|
#e;
|
|
360
360
|
#t = null;
|
|
361
361
|
#n = null;
|
|
@@ -374,18 +374,18 @@ var W = "play-audio-info", G = 500, K = class {
|
|
|
374
374
|
}
|
|
375
375
|
#i() {
|
|
376
376
|
let e = this.#e.settings();
|
|
377
|
-
if (!
|
|
378
|
-
let t =
|
|
379
|
-
t && t !== this.#n && (this.#o(), this.#a(t,
|
|
377
|
+
if (!I(e) && !e?.completeAudioEnabled) return;
|
|
378
|
+
let t = V(this.#e.root);
|
|
379
|
+
t && t !== this.#n && (this.#o(), this.#a(t, I(e)));
|
|
380
380
|
}
|
|
381
381
|
#a(e, t) {
|
|
382
|
-
let { root: n, tracker: r, enableAudioImage: i } = this.#e, a =
|
|
382
|
+
let { root: n, tracker: r, enableAudioImage: i } = this.#e, a = B(e, r), o = ce(i), s = () => {
|
|
383
383
|
o.isConnected && (e.play()?.catch(() => {}), o.remove()), document.removeEventListener("click", s);
|
|
384
384
|
}, c = () => o.remove();
|
|
385
385
|
e.addEventListener("playing", c);
|
|
386
386
|
let l = t ? setTimeout(() => {
|
|
387
|
-
e.paused && !n.querySelector(`.${
|
|
388
|
-
},
|
|
387
|
+
e.paused && !n.querySelector(`.${U}`) && ((n.querySelector(".main-container") ?? n).appendChild(o), document.addEventListener("click", s));
|
|
388
|
+
}, W) : void 0;
|
|
389
389
|
this.#n = e, this.#r = () => {
|
|
390
390
|
clearTimeout(l), a(), e.removeEventListener("playing", c), document.removeEventListener("click", s), o.remove();
|
|
391
391
|
};
|
|
@@ -394,9 +394,9 @@ var W = "play-audio-info", G = 500, K = class {
|
|
|
394
394
|
this.#r?.(), this.#r = null, this.#n = null;
|
|
395
395
|
}
|
|
396
396
|
};
|
|
397
|
-
function
|
|
397
|
+
function ce(e) {
|
|
398
398
|
let t = document.createElement("div");
|
|
399
|
-
t.id = `${
|
|
399
|
+
t.id = `${U}-${Math.random().toString(36).slice(2, 10)}`, t.className = U, Object.assign(t.style, {
|
|
400
400
|
position: "absolute",
|
|
401
401
|
top: "0",
|
|
402
402
|
width: "100%",
|
|
@@ -413,7 +413,7 @@ function se(e) {
|
|
|
413
413
|
}
|
|
414
414
|
//#endregion
|
|
415
415
|
//#region src/sanitize-model-html.ts
|
|
416
|
-
var
|
|
416
|
+
var K = [
|
|
417
417
|
"script",
|
|
418
418
|
"embed",
|
|
419
419
|
"base",
|
|
@@ -422,7 +422,7 @@ var q = [
|
|
|
422
422
|
"link",
|
|
423
423
|
"style",
|
|
424
424
|
"foreignobject"
|
|
425
|
-
],
|
|
425
|
+
], q = [
|
|
426
426
|
"onerror",
|
|
427
427
|
"onload",
|
|
428
428
|
"onclick",
|
|
@@ -440,7 +440,7 @@ var q = [
|
|
|
440
440
|
"onbeforeunload",
|
|
441
441
|
"formaction",
|
|
442
442
|
"xlink:href"
|
|
443
|
-
],
|
|
443
|
+
], le = /* @__PURE__ */ new Set([
|
|
444
444
|
"iframe",
|
|
445
445
|
"object",
|
|
446
446
|
"mstack",
|
|
@@ -453,7 +453,7 @@ var q = [
|
|
|
453
453
|
"semantics",
|
|
454
454
|
"annotation",
|
|
455
455
|
"none"
|
|
456
|
-
]),
|
|
456
|
+
]), ue = /^[a-z_][\w.-]*:[a-z][\w.-]*$/, de = [
|
|
457
457
|
"alignment",
|
|
458
458
|
"target",
|
|
459
459
|
"allow",
|
|
@@ -473,18 +473,18 @@ var q = [
|
|
|
473
473
|
"rightoverhang",
|
|
474
474
|
"mslinethickness",
|
|
475
475
|
"linebreak"
|
|
476
|
-
],
|
|
477
|
-
ADD_TAGS: (e) =>
|
|
478
|
-
ADD_ATTR:
|
|
479
|
-
FORBID_TAGS:
|
|
480
|
-
FORBID_ATTR: [...
|
|
476
|
+
], fe = /^\s*document\.getElementById\((['"])([^'"]+)\1\)\.play\(\)\s*;?\s*(?:return\s+false\s*;?\s*)?$/, J = "data-pie-play-audio", pe = {
|
|
477
|
+
ADD_TAGS: (e) => le.has(e) || ue.test(e),
|
|
478
|
+
ADD_ATTR: de,
|
|
479
|
+
FORBID_TAGS: K,
|
|
480
|
+
FORBID_ATTR: [...q, ...L],
|
|
481
481
|
ALLOW_UNKNOWN_PROTOCOLS: !1,
|
|
482
482
|
RETURN_TRUSTED_TYPE: !1
|
|
483
|
-
},
|
|
484
|
-
function
|
|
483
|
+
}, me = !1;
|
|
484
|
+
function he(e) {
|
|
485
485
|
for (let t of e.composedPath()) {
|
|
486
486
|
if (!(t instanceof Element)) continue;
|
|
487
|
-
let n = t.getAttribute(
|
|
487
|
+
let n = t.getAttribute(J);
|
|
488
488
|
if (n === null) continue;
|
|
489
489
|
e.preventDefault();
|
|
490
490
|
let r = t.getRootNode().getElementById?.(n) ?? document.getElementById(n);
|
|
@@ -492,32 +492,41 @@ function me(e) {
|
|
|
492
492
|
return;
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
var
|
|
496
|
-
function
|
|
497
|
-
return
|
|
495
|
+
var Y = null;
|
|
496
|
+
function ge() {
|
|
497
|
+
return Y || (Y = e(window), Y.addHook("beforeSanitizeAttributes", (e) => {
|
|
498
498
|
if (e.nodeName !== "A") return;
|
|
499
|
-
let t =
|
|
500
|
-
t !== void 0 && (e.removeAttribute("onclick"), e.setAttribute(
|
|
501
|
-
}),
|
|
499
|
+
let t = fe.exec(e.getAttribute("onclick") ?? "")?.[2];
|
|
500
|
+
t !== void 0 && (e.removeAttribute("onclick"), e.setAttribute(J, t), me ||= (document.addEventListener("click", he), !0));
|
|
501
|
+
}), Y.addHook("afterSanitizeAttributes", g), Y);
|
|
502
502
|
}
|
|
503
|
-
var
|
|
504
|
-
function
|
|
503
|
+
var X = 1e6, Z = /* @__PURE__ */ new Map(), Q = 0;
|
|
504
|
+
function _e(t) {
|
|
505
505
|
if (t == null || t === "" || !e.isSupported) return "";
|
|
506
|
-
let n = typeof t == "string" ? t : String(t), r =
|
|
506
|
+
let n = typeof t == "string" ? t : String(t), r = Z.get(n);
|
|
507
507
|
if (r !== void 0) return r;
|
|
508
|
-
let i = String(
|
|
509
|
-
if (a >
|
|
510
|
-
for (let [e, t] of
|
|
511
|
-
if (
|
|
512
|
-
|
|
508
|
+
let i = String(ge().sanitize(n, pe)), a = n.length + i.length;
|
|
509
|
+
if (a > X) return i;
|
|
510
|
+
for (let [e, t] of Z) {
|
|
511
|
+
if (Q + a <= X) break;
|
|
512
|
+
Z.delete(e), Q -= e.length + t.length;
|
|
513
513
|
}
|
|
514
|
-
return
|
|
514
|
+
return Z.set(n, i), Q += a, i;
|
|
515
515
|
}
|
|
516
516
|
//#endregion
|
|
517
517
|
//#region src/ime.ts
|
|
518
|
-
var
|
|
519
|
-
function
|
|
520
|
-
return e ? !!(e.isComposing || e.nativeEvent?.isComposing || e.keyCode ===
|
|
518
|
+
var ve = 229;
|
|
519
|
+
function ye(e) {
|
|
520
|
+
return e ? !!(e.isComposing || e.nativeEvent?.isComposing || e.keyCode === ve) : !1;
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/inline-direction.ts
|
|
524
|
+
function $(e) {
|
|
525
|
+
let t = e?.ownerDocument?.defaultView;
|
|
526
|
+
return !!(e && t && t.getComputedStyle(e).direction === "rtl");
|
|
527
|
+
}
|
|
528
|
+
function be(e, t) {
|
|
529
|
+
if (e === "ArrowLeft" || e === "ArrowRight") return e === "ArrowLeft" === $(t) ? "inline-end" : "inline-start";
|
|
521
530
|
}
|
|
522
531
|
//#endregion
|
|
523
|
-
export { m as AUTHORED_BORDER_ATTR, p as AUTHORED_FILL_ATTR, f as AUTHORED_INK_ATTR,
|
|
532
|
+
export { m as AUTHORED_BORDER_ATTR, p as AUTHORED_FILL_ATTR, f as AUTHORED_INK_ATTR, L as AUTOPLAY_AUDIO_MARKUP_ATTRS, q as MODEL_HTML_FORBIDDEN_ATTRS, K as MODEL_HTML_FORBIDDEN_TAGS, J as PLAY_AUDIO_ATTR, se as PromptAudioTracker, G as PromptAudioWatcher, u as assignProps, I as autoplayAudioOn, B as bindPromptAudio, a as clamp, s as debounce, t as debug, be as inlineSideOfArrow, ye as isComposingKeyEvent, n as isEmpty, $ as isRightToLeft, g as markAuthoredColors, H as promptAudioPending, _e as sanitizeModelHtml, d as sessionsEqual, r as showFeedback, i as showRationale, c as shuffle, o as uuid, R as withPromptAudioTiming };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The side of a line a sequential move goes toward: where text starts, or where it ends. */
|
|
2
|
+
export type InlineSide = 'inline-start' | 'inline-end';
|
|
3
|
+
/** Whether `element`'s text runs right to left, from its computed direction. */
|
|
4
|
+
export declare function isRightToLeft(element: Element | null | undefined): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* The inline side a horizontal arrow key moves toward in `element`'s text: ArrowLeft is the inline
|
|
7
|
+
* start in left-to-right text and the inline end in right-to-left text. The direction is read when
|
|
8
|
+
* the key is pressed, so a block with its own `dir` answers for itself. Every other key has none.
|
|
9
|
+
*
|
|
10
|
+
* Sequential navigation (previous and next) goes through this; spatial movement keeps the physical
|
|
11
|
+
* key.
|
|
12
|
+
*/
|
|
13
|
+
export declare function inlineSideOfArrow(key: string, element: Element | null | undefined): InlineSide | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/shared-utils",
|
|
3
|
-
"version": "0.1.7-next.
|
|
3
|
+
"version": "0.1.7-next.20261027193325",
|
|
4
4
|
"description": "Shared utilities for PIE elements",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"clean": "rm -rf dist"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@pie-element/shared-types": "0.2.4-next.
|
|
24
|
+
"@pie-element/shared-types": "0.2.4-next.20261026212738",
|
|
25
25
|
"dompurify": "^3.4.17"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|