thunderous 0.3.2 → 0.3.4

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:.+\}\})/;
@@ -205,8 +218,7 @@ var html = (strings, ...values) => {
205
218
  parseChildren(fragment);
206
219
  return fragment;
207
220
  };
208
- var _a, _b;
209
- 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");
210
222
  var isCSSStyleSheet = (stylesheet) => {
211
223
  return typeof CSSStyleSheet !== "undefined" && stylesheet instanceof CSSStyleSheet;
212
224
  };
@@ -282,13 +294,14 @@ var customElement = (render, options) => {
282
294
  #connectedFns = /* @__PURE__ */ new Set();
283
295
  #disconnectedFns = /* @__PURE__ */ new Set();
284
296
  #adoptedCallbackFns = /* @__PURE__ */ new Set();
297
+ #formAssociatedCallbackFns = /* @__PURE__ */ new Set();
285
298
  #formDisabledCallbackFns = /* @__PURE__ */ new Set();
286
299
  #formResetCallbackFns = /* @__PURE__ */ new Set();
287
300
  #formStateRestoreCallbackFns = /* @__PURE__ */ new Set();
288
301
  __customCallbackFns = /* @__PURE__ */ new Map();
289
302
  #shadowRoot = attachShadow ? this.attachShadow(shadowRootOptions) : null;
290
303
  #internals = this.attachInternals();
291
- #observer = (options == null ? void 0 : options.observedAttributes) !== void 0 ? null : new MutationObserver((mutations) => {
304
+ #observer = options?.observedAttributes !== void 0 ? null : new MutationObserver((mutations) => {
292
305
  for (const mutation of mutations) {
293
306
  const attrName = mutation.attributeName;
294
307
  if (mutation.type !== "attributes" || attrName === null) continue;
@@ -313,6 +326,7 @@ var customElement = (render, options) => {
313
326
  connectedCallback: (fn) => this.#connectedFns.add(fn),
314
327
  disconnectedCallback: (fn) => this.#disconnectedFns.add(fn),
315
328
  adoptedCallback: (fn) => this.#adoptedCallbackFns.add(fn),
329
+ formAssociatedCallback: (fn) => this.#formAssociatedCallbackFns.add(fn),
316
330
  formDisabledCallback: (fn) => this.#formDisabledCallbackFns.add(fn),
317
331
  formResetCallback: (fn) => this.#formResetCallbackFns.add(fn),
318
332
  formStateRestoreCallback: (fn) => this.#formStateRestoreCallbackFns.add(fn),
@@ -450,7 +464,7 @@ var customElement = (render, options) => {
450
464
  }
451
465
  attributeChangedCallback(name, oldValue, newValue) {
452
466
  const [, attrSetter] = this.#attrSignals[name] ?? [];
453
- attrSetter == null ? void 0 : attrSetter(newValue);
467
+ attrSetter?.(newValue);
454
468
  const prop = this.#attributesAsPropertiesMap.get(name);
455
469
  if (prop !== void 0) {
456
470
  this[prop.prop] = newValue === null ? null : prop.coerce(newValue);
@@ -464,6 +478,11 @@ var customElement = (render, options) => {
464
478
  fn();
465
479
  }
466
480
  }
481
+ formAssociatedCallback() {
482
+ for (const fn of this.#formAssociatedCallbackFns) {
483
+ fn();
484
+ }
485
+ }
467
486
  formDisabledCallback() {
468
487
  for (const fn of this.#formDisabledCallbackFns) {
469
488
  fn();
package/dist/index.d.cts CHANGED
@@ -14,8 +14,35 @@ type SignalOptions = {
14
14
  type SignalGetter<T> = (options?: SignalOptions) => T;
15
15
  type SignalSetter<T> = (newValue: T, options?: SignalOptions) => void;
16
16
  type Signal<T = unknown> = [SignalGetter<T>, SignalSetter<T>];
17
+ /**
18
+ * Create a signal with an initial value.
19
+ * @example
20
+ * ```ts
21
+ * const [getCount, setCount] = createSignal(0);
22
+ * const increment = () => setCount(getCount() + 1);
23
+ * const decrement = () => setCount(getCount() - 1);
24
+ * ```
25
+ */
17
26
  declare const createSignal: <T = undefined>(initVal?: T, options?: SignalOptions) => Signal<T>;
27
+ /**
28
+ * Create a derived signal that depends on other signals.
29
+ * @example
30
+ * ```ts
31
+ * const [getCount, setCount] = createSignal(0);
32
+ * const doubleCount = derived(() => getCount() * 2);
33
+ * ```
34
+ */
18
35
  declare const derived: <T>(fn: () => T) => SignalGetter<T>;
36
+ /**
37
+ * Create an effect that runs when signals change.
38
+ * @example
39
+ * ```ts
40
+ * const [getCount, setCount] = createSignal(0);
41
+ * createEffect(() => {
42
+ * console.log('Count:', getCount());
43
+ * });
44
+ * ```
45
+ */
19
46
  declare const createEffect: (fn: () => void) => void;
20
47
 
21
48
  declare global {
@@ -40,6 +67,7 @@ type RenderProps = {
40
67
  formDisabledCallback: (fn: () => void) => void;
41
68
  formResetCallback: (fn: () => void) => void;
42
69
  formStateRestoreCallback: (fn: () => void) => void;
70
+ formAssociatedCallback: (fn: () => void) => void;
43
71
  customCallback: (fn: () => void) => `{{callback:${string}}}`;
44
72
  attrSignals: Record<string, Signal<string | null>>;
45
73
  propSignals: Record<string, Signal<unknown>>;
@@ -55,11 +83,31 @@ type RenderOptions = {
55
83
  shadowRootOptions: ShadowRootInit;
56
84
  };
57
85
  type RenderFunction = (props: RenderProps) => DocumentFragment;
86
+ /**
87
+ * Create a custom element that can be defined for use in the DOM.
88
+ * @example
89
+ * ```ts
90
+ * const MyElement = customElement(() => {
91
+ * return html`<h1>Hello, World!</h1>`;
92
+ * });
93
+ * MyElement.define('my-element');
94
+ * ```
95
+ */
58
96
  declare const customElement: (render: RenderFunction, options?: Partial<RenderOptions>) => ElementResult;
59
97
  type Registry = {
60
98
  register: (tagName: string, element: CustomElementConstructor) => void;
61
99
  getTagName: (element: CustomElementConstructor) => string | undefined;
62
100
  };
101
+ /**
102
+ * Create a registry for custom elements.
103
+ * @example
104
+ * ```ts
105
+ * const registry = createRegistry();
106
+ * registry.register('my-element', MyElement);
107
+ * const tagName = registry.getTagName(MyElement);
108
+ * console.log(tagName); // 'MY-ELEMENT'
109
+ * ```
110
+ */
63
111
  declare const createRegistry: () => Registry;
64
112
 
65
113
  export { type RenderFunction, type RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
package/dist/index.d.ts CHANGED
@@ -14,8 +14,35 @@ type SignalOptions = {
14
14
  type SignalGetter<T> = (options?: SignalOptions) => T;
15
15
  type SignalSetter<T> = (newValue: T, options?: SignalOptions) => void;
16
16
  type Signal<T = unknown> = [SignalGetter<T>, SignalSetter<T>];
17
+ /**
18
+ * Create a signal with an initial value.
19
+ * @example
20
+ * ```ts
21
+ * const [getCount, setCount] = createSignal(0);
22
+ * const increment = () => setCount(getCount() + 1);
23
+ * const decrement = () => setCount(getCount() - 1);
24
+ * ```
25
+ */
17
26
  declare const createSignal: <T = undefined>(initVal?: T, options?: SignalOptions) => Signal<T>;
27
+ /**
28
+ * Create a derived signal that depends on other signals.
29
+ * @example
30
+ * ```ts
31
+ * const [getCount, setCount] = createSignal(0);
32
+ * const doubleCount = derived(() => getCount() * 2);
33
+ * ```
34
+ */
18
35
  declare const derived: <T>(fn: () => T) => SignalGetter<T>;
36
+ /**
37
+ * Create an effect that runs when signals change.
38
+ * @example
39
+ * ```ts
40
+ * const [getCount, setCount] = createSignal(0);
41
+ * createEffect(() => {
42
+ * console.log('Count:', getCount());
43
+ * });
44
+ * ```
45
+ */
19
46
  declare const createEffect: (fn: () => void) => void;
20
47
 
21
48
  declare global {
@@ -40,6 +67,7 @@ type RenderProps = {
40
67
  formDisabledCallback: (fn: () => void) => void;
41
68
  formResetCallback: (fn: () => void) => void;
42
69
  formStateRestoreCallback: (fn: () => void) => void;
70
+ formAssociatedCallback: (fn: () => void) => void;
43
71
  customCallback: (fn: () => void) => `{{callback:${string}}}`;
44
72
  attrSignals: Record<string, Signal<string | null>>;
45
73
  propSignals: Record<string, Signal<unknown>>;
@@ -55,11 +83,31 @@ type RenderOptions = {
55
83
  shadowRootOptions: ShadowRootInit;
56
84
  };
57
85
  type RenderFunction = (props: RenderProps) => DocumentFragment;
86
+ /**
87
+ * Create a custom element that can be defined for use in the DOM.
88
+ * @example
89
+ * ```ts
90
+ * const MyElement = customElement(() => {
91
+ * return html`<h1>Hello, World!</h1>`;
92
+ * });
93
+ * MyElement.define('my-element');
94
+ * ```
95
+ */
58
96
  declare const customElement: (render: RenderFunction, options?: Partial<RenderOptions>) => ElementResult;
59
97
  type Registry = {
60
98
  register: (tagName: string, element: CustomElementConstructor) => void;
61
99
  getTagName: (element: CustomElementConstructor) => string | undefined;
62
100
  };
101
+ /**
102
+ * Create a registry for custom elements.
103
+ * @example
104
+ * ```ts
105
+ * const registry = createRegistry();
106
+ * registry.register('my-element', MyElement);
107
+ * const tagName = registry.getTagName(MyElement);
108
+ * console.log(tagName); // 'MY-ELEMENT'
109
+ * ```
110
+ */
63
111
  declare const createRegistry: () => Registry;
64
112
 
65
113
  export { type RenderFunction, type RenderProps, type Signal, type SignalGetter, type SignalSetter, createEffect, createRegistry, createSignal, css, customElement, derived, html };
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:.+\}\})/;
@@ -174,8 +176,7 @@ var html = (strings, ...values) => {
174
176
  parseChildren(fragment);
175
177
  return fragment;
176
178
  };
177
- var _a, _b;
178
- 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");
179
180
  var isCSSStyleSheet = (stylesheet) => {
180
181
  return typeof CSSStyleSheet !== "undefined" && stylesheet instanceof CSSStyleSheet;
181
182
  };
@@ -251,13 +252,14 @@ var customElement = (render, options) => {
251
252
  #connectedFns = /* @__PURE__ */ new Set();
252
253
  #disconnectedFns = /* @__PURE__ */ new Set();
253
254
  #adoptedCallbackFns = /* @__PURE__ */ new Set();
255
+ #formAssociatedCallbackFns = /* @__PURE__ */ new Set();
254
256
  #formDisabledCallbackFns = /* @__PURE__ */ new Set();
255
257
  #formResetCallbackFns = /* @__PURE__ */ new Set();
256
258
  #formStateRestoreCallbackFns = /* @__PURE__ */ new Set();
257
259
  __customCallbackFns = /* @__PURE__ */ new Map();
258
260
  #shadowRoot = attachShadow ? this.attachShadow(shadowRootOptions) : null;
259
261
  #internals = this.attachInternals();
260
- #observer = (options == null ? void 0 : options.observedAttributes) !== void 0 ? null : new MutationObserver((mutations) => {
262
+ #observer = options?.observedAttributes !== void 0 ? null : new MutationObserver((mutations) => {
261
263
  for (const mutation of mutations) {
262
264
  const attrName = mutation.attributeName;
263
265
  if (mutation.type !== "attributes" || attrName === null) continue;
@@ -282,6 +284,7 @@ var customElement = (render, options) => {
282
284
  connectedCallback: (fn) => this.#connectedFns.add(fn),
283
285
  disconnectedCallback: (fn) => this.#disconnectedFns.add(fn),
284
286
  adoptedCallback: (fn) => this.#adoptedCallbackFns.add(fn),
287
+ formAssociatedCallback: (fn) => this.#formAssociatedCallbackFns.add(fn),
285
288
  formDisabledCallback: (fn) => this.#formDisabledCallbackFns.add(fn),
286
289
  formResetCallback: (fn) => this.#formResetCallbackFns.add(fn),
287
290
  formStateRestoreCallback: (fn) => this.#formStateRestoreCallbackFns.add(fn),
@@ -419,7 +422,7 @@ var customElement = (render, options) => {
419
422
  }
420
423
  attributeChangedCallback(name, oldValue, newValue) {
421
424
  const [, attrSetter] = this.#attrSignals[name] ?? [];
422
- attrSetter == null ? void 0 : attrSetter(newValue);
425
+ attrSetter?.(newValue);
423
426
  const prop = this.#attributesAsPropertiesMap.get(name);
424
427
  if (prop !== void 0) {
425
428
  this[prop.prop] = newValue === null ? null : prop.coerce(newValue);
@@ -433,6 +436,11 @@ var customElement = (render, options) => {
433
436
  fn();
434
437
  }
435
438
  }
439
+ formAssociatedCallback() {
440
+ for (const fn of this.#formAssociatedCallbackFns) {
441
+ fn();
442
+ }
443
+ }
436
444
  formDisabledCallback() {
437
445
  for (const fn of this.#formDisabledCallbackFns) {
438
446
  fn();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderous",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
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
  }