thunderous 0.3.1 → 0.3.3

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.cjs CHANGED
@@ -1,6 +1,9 @@
1
+ "use strict";
2
+ var __create = Object.create;
1
3
  var __defProp = Object.defineProperty;
2
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
4
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
8
  var __export = (target, all) => {
6
9
  for (var name in all)
@@ -14,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
14
17
  }
15
18
  return to;
16
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
17
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
29
 
19
30
  // src/index.ts
@@ -57,15 +68,15 @@ var createSignal = (initVal, options) => {
57
68
  if (subscriber !== null) {
58
69
  subscribers.add(subscriber);
59
70
  }
60
- if ((options == null ? void 0 : options.debugMode) || (getterOptions == null ? void 0 : getterOptions.debugMode)) {
71
+ if (options?.debugMode || getterOptions?.debugMode) {
61
72
  requestAnimationFrame(() => {
62
73
  let label = "anonymous signal";
63
- if ((options == null ? void 0 : options.label) !== void 0) {
74
+ if (options?.label !== void 0) {
64
75
  label = `(${options.label})`;
65
- if ((getterOptions == null ? void 0 : getterOptions.label) !== void 0) {
76
+ if (getterOptions?.label !== void 0) {
66
77
  label += ` ${getterOptions.label}`;
67
78
  }
68
- } else if ((getterOptions == null ? void 0 : getterOptions.label) !== void 0) {
79
+ } else if (getterOptions?.label !== void 0) {
69
80
  label = getterOptions.label;
70
81
  }
71
82
  console.log("Signal retrieved:", { value, subscribers, label });
@@ -91,14 +102,14 @@ var createSignal = (initVal, options) => {
91
102
  console.error("Error in subscriber:", { error, oldValue, newValue, fn });
92
103
  }
93
104
  }
94
- if ((options == null ? void 0 : options.debugMode) || (setterOptions == null ? void 0 : setterOptions.debugMode)) {
105
+ if (options?.debugMode || setterOptions?.debugMode) {
95
106
  let label = "anonymous signal";
96
- if ((options == null ? void 0 : options.label) !== void 0) {
107
+ if (options?.label !== void 0) {
97
108
  label = `(${options.label})`;
98
- if ((setterOptions == null ? void 0 : setterOptions.label) !== void 0) {
109
+ if (setterOptions?.label !== void 0) {
99
110
  label += ` ${setterOptions.label}`;
100
111
  }
101
- } else if ((setterOptions == null ? void 0 : setterOptions.label) !== void 0) {
112
+ } else if (setterOptions?.label !== void 0) {
102
113
  label = setterOptions.label;
103
114
  }
104
115
  console.log("Signal set:", { oldValue, newValue, subscribers, label });
@@ -132,6 +143,7 @@ var createEffect = (fn) => {
132
143
  };
133
144
 
134
145
  // src/render.ts
146
+ var import_dompurify = __toESM(require("dompurify"), 1);
135
147
  var html = (strings, ...values) => {
136
148
  let innerHTML = "";
137
149
  const signalMap = /* @__PURE__ */ new Map();
@@ -144,6 +156,7 @@ var html = (strings, ...values) => {
144
156
  }
145
157
  innerHTML += string + String(value);
146
158
  });
159
+ import_dompurify.default.sanitize(innerHTML);
147
160
  const fragment = parseFragment(innerHTML);
148
161
  const callbackBindingRegex = /(\{\{callback:.+\}\})/;
149
162
  const signalBindingRegex = /(\{\{signal:.+\}\})/;
@@ -174,12 +187,19 @@ var html = (strings, ...values) => {
174
187
  const textList = attr.value.split(signalBindingRegex);
175
188
  createEffect(() => {
176
189
  let newText = "";
190
+ let hasNull = false;
177
191
  for (const text of textList) {
178
192
  const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
179
193
  const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : null;
180
- newText += signal !== null ? signal() : text;
194
+ const value = signal !== null ? signal() : text;
195
+ if (value === null) hasNull = true;
196
+ newText += value;
197
+ }
198
+ if (hasNull && newText === "null") {
199
+ child.removeAttribute(attr.name);
200
+ } else {
201
+ child.setAttribute(attr.name, newText);
181
202
  }
182
- child.setAttribute(attr.name, newText);
183
203
  });
184
204
  } else if (callbackBindingRegex.test(attr.value)) {
185
205
  const getRootNode = child.getRootNode.bind(child);
@@ -198,8 +218,7 @@ var html = (strings, ...values) => {
198
218
  parseChildren(fragment);
199
219
  return fragment;
200
220
  };
201
- var _a, _b;
202
- var adoptedStylesSupported = typeof window !== "undefined" && ((_a = window.ShadowRoot) == null ? void 0 : _a.prototype.hasOwnProperty("adoptedStyleSheets")) && ((_b = window.CSSStyleSheet) == null ? void 0 : _b.prototype.hasOwnProperty("replace"));
221
+ var adoptedStylesSupported = typeof window !== "undefined" && window.ShadowRoot?.prototype.hasOwnProperty("adoptedStyleSheets") && window.CSSStyleSheet?.prototype.hasOwnProperty("replace");
203
222
  var isCSSStyleSheet = (stylesheet) => {
204
223
  return typeof CSSStyleSheet !== "undefined" && stylesheet instanceof CSSStyleSheet;
205
224
  };
@@ -281,7 +300,7 @@ var customElement = (render, options) => {
281
300
  __customCallbackFns = /* @__PURE__ */ new Map();
282
301
  #shadowRoot = attachShadow ? this.attachShadow(shadowRootOptions) : null;
283
302
  #internals = this.attachInternals();
284
- #observer = (options == null ? void 0 : options.observedAttributes) !== void 0 ? null : new MutationObserver((mutations) => {
303
+ #observer = options?.observedAttributes !== void 0 ? null : new MutationObserver((mutations) => {
285
304
  for (const mutation of mutations) {
286
305
  const attrName = mutation.attributeName;
287
306
  if (mutation.type !== "attributes" || attrName === null) continue;
@@ -443,7 +462,7 @@ var customElement = (render, options) => {
443
462
  }
444
463
  attributeChangedCallback(name, oldValue, newValue) {
445
464
  const [, attrSetter] = this.#attrSignals[name] ?? [];
446
- attrSetter == null ? void 0 : attrSetter(newValue);
465
+ attrSetter?.(newValue);
447
466
  const prop = this.#attributesAsPropertiesMap.get(name);
448
467
  if (prop !== void 0) {
449
468
  this[prop.prop] = newValue === null ? null : prop.coerce(newValue);
package/dist/index.js CHANGED
@@ -26,15 +26,15 @@ var createSignal = (initVal, options) => {
26
26
  if (subscriber !== null) {
27
27
  subscribers.add(subscriber);
28
28
  }
29
- if ((options == null ? void 0 : options.debugMode) || (getterOptions == null ? void 0 : getterOptions.debugMode)) {
29
+ if (options?.debugMode || getterOptions?.debugMode) {
30
30
  requestAnimationFrame(() => {
31
31
  let label = "anonymous signal";
32
- if ((options == null ? void 0 : options.label) !== void 0) {
32
+ if (options?.label !== void 0) {
33
33
  label = `(${options.label})`;
34
- if ((getterOptions == null ? void 0 : getterOptions.label) !== void 0) {
34
+ if (getterOptions?.label !== void 0) {
35
35
  label += ` ${getterOptions.label}`;
36
36
  }
37
- } else if ((getterOptions == null ? void 0 : getterOptions.label) !== void 0) {
37
+ } else if (getterOptions?.label !== void 0) {
38
38
  label = getterOptions.label;
39
39
  }
40
40
  console.log("Signal retrieved:", { value, subscribers, label });
@@ -60,14 +60,14 @@ var createSignal = (initVal, options) => {
60
60
  console.error("Error in subscriber:", { error, oldValue, newValue, fn });
61
61
  }
62
62
  }
63
- if ((options == null ? void 0 : options.debugMode) || (setterOptions == null ? void 0 : setterOptions.debugMode)) {
63
+ if (options?.debugMode || setterOptions?.debugMode) {
64
64
  let label = "anonymous signal";
65
- if ((options == null ? void 0 : options.label) !== void 0) {
65
+ if (options?.label !== void 0) {
66
66
  label = `(${options.label})`;
67
- if ((setterOptions == null ? void 0 : setterOptions.label) !== void 0) {
67
+ if (setterOptions?.label !== void 0) {
68
68
  label += ` ${setterOptions.label}`;
69
69
  }
70
- } else if ((setterOptions == null ? void 0 : setterOptions.label) !== void 0) {
70
+ } else if (setterOptions?.label !== void 0) {
71
71
  label = setterOptions.label;
72
72
  }
73
73
  console.log("Signal set:", { oldValue, newValue, subscribers, label });
@@ -101,6 +101,7 @@ var createEffect = (fn) => {
101
101
  };
102
102
 
103
103
  // src/render.ts
104
+ import DOMPurify from "dompurify";
104
105
  var html = (strings, ...values) => {
105
106
  let innerHTML = "";
106
107
  const signalMap = /* @__PURE__ */ new Map();
@@ -113,6 +114,7 @@ var html = (strings, ...values) => {
113
114
  }
114
115
  innerHTML += string + String(value);
115
116
  });
117
+ DOMPurify.sanitize(innerHTML);
116
118
  const fragment = parseFragment(innerHTML);
117
119
  const callbackBindingRegex = /(\{\{callback:.+\}\})/;
118
120
  const signalBindingRegex = /(\{\{signal:.+\}\})/;
@@ -143,12 +145,19 @@ var html = (strings, ...values) => {
143
145
  const textList = attr.value.split(signalBindingRegex);
144
146
  createEffect(() => {
145
147
  let newText = "";
148
+ let hasNull = false;
146
149
  for (const text of textList) {
147
150
  const uniqueKey = text.replace(/\{\{signal:(.+)\}\}/, "$1");
148
151
  const signal = uniqueKey !== text ? signalMap.get(uniqueKey) : null;
149
- newText += signal !== null ? signal() : text;
152
+ const value = signal !== null ? signal() : text;
153
+ if (value === null) hasNull = true;
154
+ newText += value;
155
+ }
156
+ if (hasNull && newText === "null") {
157
+ child.removeAttribute(attr.name);
158
+ } else {
159
+ child.setAttribute(attr.name, newText);
150
160
  }
151
- child.setAttribute(attr.name, newText);
152
161
  });
153
162
  } else if (callbackBindingRegex.test(attr.value)) {
154
163
  const getRootNode = child.getRootNode.bind(child);
@@ -167,8 +176,7 @@ var html = (strings, ...values) => {
167
176
  parseChildren(fragment);
168
177
  return fragment;
169
178
  };
170
- var _a, _b;
171
- var adoptedStylesSupported = typeof window !== "undefined" && ((_a = window.ShadowRoot) == null ? void 0 : _a.prototype.hasOwnProperty("adoptedStyleSheets")) && ((_b = window.CSSStyleSheet) == null ? void 0 : _b.prototype.hasOwnProperty("replace"));
179
+ var adoptedStylesSupported = typeof window !== "undefined" && window.ShadowRoot?.prototype.hasOwnProperty("adoptedStyleSheets") && window.CSSStyleSheet?.prototype.hasOwnProperty("replace");
172
180
  var isCSSStyleSheet = (stylesheet) => {
173
181
  return typeof CSSStyleSheet !== "undefined" && stylesheet instanceof CSSStyleSheet;
174
182
  };
@@ -250,7 +258,7 @@ var customElement = (render, options) => {
250
258
  __customCallbackFns = /* @__PURE__ */ new Map();
251
259
  #shadowRoot = attachShadow ? this.attachShadow(shadowRootOptions) : null;
252
260
  #internals = this.attachInternals();
253
- #observer = (options == null ? void 0 : options.observedAttributes) !== void 0 ? null : new MutationObserver((mutations) => {
261
+ #observer = options?.observedAttributes !== void 0 ? null : new MutationObserver((mutations) => {
254
262
  for (const mutation of mutations) {
255
263
  const attrName = mutation.attributeName;
256
264
  if (mutation.type !== "attributes" || attrName === null) continue;
@@ -412,7 +420,7 @@ var customElement = (render, options) => {
412
420
  }
413
421
  attributeChangedCallback(name, oldValue, newValue) {
414
422
  const [, attrSetter] = this.#attrSignals[name] ?? [];
415
- attrSetter == null ? void 0 : attrSetter(newValue);
423
+ attrSetter?.(newValue);
416
424
  const prop = this.#attributesAsPropertiesMap.get(name);
417
425
  if (prop !== void 0) {
418
426
  this[prop.prop] = newValue === null ? null : prop.coerce(newValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderous",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -34,6 +34,7 @@
34
34
  "build": "tsup src/index.ts --format cjs,esm --dts --no-clean"
35
35
  },
36
36
  "devDependencies": {
37
+ "@types/dompurify": "^3.0.5",
37
38
  "@types/eslint": "^8.56.10",
38
39
  "@typescript-eslint/eslint-plugin": "^7.1.1",
39
40
  "@typescript-eslint/parser": "^7.1.1",
@@ -45,5 +46,8 @@
45
46
  "prettier": "^3.3.3",
46
47
  "tsup": "^8.3.0",
47
48
  "typescript": "^5.6.3"
49
+ },
50
+ "dependencies": {
51
+ "dompurify": "^3.1.7"
48
52
  }
49
53
  }