@pie-element/shared-utils 0.1.3-next.20261007075859 → 0.2.0-next.20261007021359

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 CHANGED
@@ -89,75 +89,36 @@ 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",
99
92
  "semantics",
100
93
  "annotation",
101
94
  "none"
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 = {
95
+ ]), h = /^[a-z_][\w.-]*:[a-z][\w.-]*$/, g = {
123
96
  ADD_TAGS: (e) => m.has(e) || h.test(e),
124
- ADD_ATTR: g,
97
+ ADD_ATTR: [
98
+ "alignment",
99
+ "target",
100
+ "allow",
101
+ "allowfullscreen",
102
+ "frameborder",
103
+ "scrolling",
104
+ "data"
105
+ ],
125
106
  FORBID_TAGS: f,
126
107
  FORBID_ATTR: p,
127
108
  ALLOW_UNKNOWN_PROTOCOLS: !1,
128
109
  RETURN_TRUSTED_TYPE: !1
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) {
110
+ }, _ = 1e6, v = /* @__PURE__ */ new Map(), y = 0;
111
+ function b(t) {
151
112
  if (t == null || t === "" || !e.isSupported) return "";
152
- let n = typeof t == "string" ? t : String(t), r = T.get(n);
113
+ let n = typeof t == "string" ? t : String(t), r = v.get(n);
153
114
  if (r !== void 0) return r;
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;
115
+ let i = String(e.sanitize(n, g)), a = n.length + i.length;
116
+ if (a > _) return i;
117
+ for (let [e, t] of v) {
118
+ if (y + a <= _) break;
119
+ v.delete(e), y -= e.length + t.length;
159
120
  }
160
- return T.set(n, i), E += a, i;
121
+ return v.set(n, i), y += a, i;
161
122
  }
162
123
  //#endregion
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 };
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, b as sanitizeModelHtml, d as sessionsEqual, r as showFeedback, i as showRationale, c as shuffle, o as uuid };
@@ -13,11 +13,9 @@
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";
17
16
  /**
18
17
  * Returns `html` with scripts, event handlers, `javascript:` URLs and the forbidden tags and
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.
18
+ * attributes removed. Returns an empty string where there is no DOM to sanitize against.
21
19
  *
22
20
  * Takes any value because model fields are not always strings: a number renders as its text,
23
21
  * 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-next.20261007075859",
3
+ "version": "0.2.0-next.20261007021359",
4
4
  "description": "Shared utilities for PIE elements",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",