@pie-element/shared-utils 0.1.2 → 0.1.3-next.20261007075859
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.js +59 -20
- package/dist/sanitize-model-html.d.ts +3 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -89,36 +89,75 @@ var f = [
|
|
|
89
89
|
], m = /* @__PURE__ */ new Set([
|
|
90
90
|
"iframe",
|
|
91
91
|
"object",
|
|
92
|
+
"mstack",
|
|
93
|
+
"mlongdiv",
|
|
94
|
+
"msgroup",
|
|
95
|
+
"msrow",
|
|
96
|
+
"msline",
|
|
97
|
+
"mscarries",
|
|
98
|
+
"mscarry",
|
|
92
99
|
"semantics",
|
|
93
100
|
"annotation",
|
|
94
101
|
"none"
|
|
95
|
-
]), h = /^[a-z_][\w.-]*:[a-z][\w.-]*$/, g =
|
|
102
|
+
]), h = /^[a-z_][\w.-]*:[a-z][\w.-]*$/, g = [
|
|
103
|
+
"alignment",
|
|
104
|
+
"target",
|
|
105
|
+
"allow",
|
|
106
|
+
"allowfullscreen",
|
|
107
|
+
"frameborder",
|
|
108
|
+
"scrolling",
|
|
109
|
+
"data",
|
|
110
|
+
"stackalign",
|
|
111
|
+
"charalign",
|
|
112
|
+
"charspacing",
|
|
113
|
+
"longdivstyle",
|
|
114
|
+
"position",
|
|
115
|
+
"shift",
|
|
116
|
+
"location",
|
|
117
|
+
"crossout",
|
|
118
|
+
"leftoverhang",
|
|
119
|
+
"rightoverhang",
|
|
120
|
+
"mslinethickness",
|
|
121
|
+
"linebreak"
|
|
122
|
+
], _ = /^\s*document\.getElementById\((['"])([^'"]+)\1\)\.play\(\)\s*;?\s*(?:return\s+false\s*;?\s*)?$/, v = "data-pie-play-audio", y = {
|
|
96
123
|
ADD_TAGS: (e) => m.has(e) || h.test(e),
|
|
97
|
-
ADD_ATTR:
|
|
98
|
-
"alignment",
|
|
99
|
-
"target",
|
|
100
|
-
"allow",
|
|
101
|
-
"allowfullscreen",
|
|
102
|
-
"frameborder",
|
|
103
|
-
"scrolling",
|
|
104
|
-
"data"
|
|
105
|
-
],
|
|
124
|
+
ADD_ATTR: g,
|
|
106
125
|
FORBID_TAGS: f,
|
|
107
126
|
FORBID_ATTR: p,
|
|
108
127
|
ALLOW_UNKNOWN_PROTOCOLS: !1,
|
|
109
128
|
RETURN_TRUSTED_TYPE: !1
|
|
110
|
-
},
|
|
111
|
-
function
|
|
129
|
+
}, b = !1;
|
|
130
|
+
function x(e) {
|
|
131
|
+
for (let t of e.composedPath()) {
|
|
132
|
+
if (!(t instanceof Element)) continue;
|
|
133
|
+
let n = t.getAttribute(v);
|
|
134
|
+
if (n === null) continue;
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
let r = t.getRootNode().getElementById?.(n) ?? document.getElementById(n);
|
|
137
|
+
r instanceof HTMLMediaElement && r.play()?.catch(() => void 0);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
var S = null;
|
|
142
|
+
function C() {
|
|
143
|
+
return S || (S = e(window), S.addHook("beforeSanitizeAttributes", (e) => {
|
|
144
|
+
if (e.nodeName !== "A") return;
|
|
145
|
+
let t = _.exec(e.getAttribute("onclick") ?? "")?.[2];
|
|
146
|
+
t !== void 0 && (e.removeAttribute("onclick"), e.setAttribute(v, t), b ||= (document.addEventListener("click", x), !0));
|
|
147
|
+
}), S);
|
|
148
|
+
}
|
|
149
|
+
var w = 1e6, T = /* @__PURE__ */ new Map(), E = 0;
|
|
150
|
+
function D(t) {
|
|
112
151
|
if (t == null || t === "" || !e.isSupported) return "";
|
|
113
|
-
let n = typeof t == "string" ? t : String(t), r =
|
|
152
|
+
let n = typeof t == "string" ? t : String(t), r = T.get(n);
|
|
114
153
|
if (r !== void 0) return r;
|
|
115
|
-
let i = String(
|
|
116
|
-
if (a >
|
|
117
|
-
for (let [e, t] of
|
|
118
|
-
if (
|
|
119
|
-
|
|
154
|
+
let i = String(C().sanitize(n, y)), a = n.length + i.length;
|
|
155
|
+
if (a > w) return i;
|
|
156
|
+
for (let [e, t] of T) {
|
|
157
|
+
if (E + a <= w) break;
|
|
158
|
+
T.delete(e), E -= e.length + t.length;
|
|
120
159
|
}
|
|
121
|
-
return
|
|
160
|
+
return T.set(n, i), E += a, i;
|
|
122
161
|
}
|
|
123
162
|
//#endregion
|
|
124
|
-
export { p as MODEL_HTML_FORBIDDEN_ATTRS, f as MODEL_HTML_FORBIDDEN_TAGS, u as assignProps, a as clamp, s as debounce, t as debug, n as isEmpty,
|
|
163
|
+
export { p as MODEL_HTML_FORBIDDEN_ATTRS, f as MODEL_HTML_FORBIDDEN_TAGS, v as PLAY_AUDIO_ATTR, u as assignProps, a as clamp, s as debounce, t as debug, n as isEmpty, D as sanitizeModelHtml, d as sessionsEqual, r as showFeedback, i as showRationale, c as shuffle, o as uuid };
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const MODEL_HTML_FORBIDDEN_TAGS: string[];
|
|
15
15
|
export declare const MODEL_HTML_FORBIDDEN_ATTRS: string[];
|
|
16
|
+
export declare const PLAY_AUDIO_ATTR = "data-pie-play-audio";
|
|
16
17
|
/**
|
|
17
18
|
* Returns `html` with scripts, event handlers, `javascript:` URLs and the forbidden tags and
|
|
18
|
-
* attributes removed.
|
|
19
|
+
* attributes removed. A link that only plays an `<audio>` keeps working; see `PLAY_AUDIO_ATTR`.
|
|
20
|
+
* Returns an empty string where there is no DOM to sanitize against.
|
|
19
21
|
*
|
|
20
22
|
* Takes any value because model fields are not always strings: a number renders as its text,
|
|
21
23
|
* as it did when passed to `innerHTML` directly.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/shared-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3-next.20261007075859",
|
|
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.
|
|
24
|
+
"@pie-element/shared-types": "0.2.1-next.20261002215153",
|
|
25
25
|
"dompurify": "^3.4.16"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|