@brandup/ui-helpers 2.0.3 → 2.0.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/README.md CHANGED
@@ -154,3 +154,13 @@ try {
154
154
  - `timeout(promise, ms, abort?)` — races `promise` against `ms` ms; rejects with a `TimeoutError` on timeout, or with the signal's reason on abort. Throws synchronously if `ms ≤ 0`. The underlying `promise` is not cancelled — only the wait ends.
155
155
  - `abortable(promise, abort?)` — makes *waiting* for `promise` abortable: rejects with the signal's reason on abort. Does not stop the underlying work; without a signal the promise is awaited as-is.
156
156
  - `TimeoutError` — error class thrown by `timeout` when the time limit is exceeded.
157
+
158
+ ## Polyfills
159
+
160
+ An opt-in, side-effect-only entry point fills in `AbortSignal` APIs that older runtimes may lack — `AbortSignal.prototype.throwIfAborted`, `AbortSignal.timeout` and `AbortSignal.any`. Import it once, as early as possible (e.g. in your entry module):
161
+
162
+ ```TypeScript
163
+ import "@brandup/ui-helpers/polyfill";
164
+ ```
165
+
166
+ Each implementation installs only when missing, so native behaviour is preserved where available. Types ship with the TypeScript `ESNext` lib; this module provides just the runtime. It is excluded from tree-shaking (`sideEffects`), so a bare import is never dropped by the bundler.
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Runtime polyfills for `AbortSignal`, installed only when the host lacks them:
5
+ * `AbortSignal.prototype.throwIfAborted`, `AbortSignal.timeout` and `AbortSignal.any`.
6
+ *
7
+ * Import for its side effect — there are no exports:
8
+ *
9
+ * ```TypeScript
10
+ * import "@brandup/ui-helpers/polyfill";
11
+ * ```
12
+ *
13
+ * Types already ship with the TypeScript `ESNext` lib; this module only fills in the
14
+ * implementations missing in older runtimes, matching the standard behaviour.
15
+ */
16
+ if (typeof AbortSignal.prototype.throwIfAborted !== "function") {
17
+ AbortSignal.prototype.throwIfAborted = function () {
18
+ if (this.aborted)
19
+ throw this.reason;
20
+ };
21
+ }
22
+ if (typeof AbortSignal.timeout !== "function") {
23
+ AbortSignal.timeout = (milliseconds) => {
24
+ const controller = new AbortController();
25
+ setTimeout(() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")), milliseconds);
26
+ return controller.signal;
27
+ };
28
+ }
29
+ if (typeof AbortSignal.any !== "function") {
30
+ AbortSignal.any = (signals) => {
31
+ const controller = new AbortController();
32
+ for (const signal of signals) {
33
+ // If one is already aborted, the combined signal aborts immediately with its reason.
34
+ if (signal.aborted) {
35
+ controller.abort(signal.reason);
36
+ break;
37
+ }
38
+ // Tying each listener to the combined signal removes them all once it aborts — no leak.
39
+ signal.addEventListener("abort", () => controller.abort(signal.reason), { signal: controller.signal });
40
+ }
41
+ return controller.signal;
42
+ };
43
+ }
44
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfill.js","sources":["../../../source/polyfill.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA;;;;;;;;;;;;AAYG;AAEH,IAAI,OAAO,WAAW,CAAC,SAAS,CAAC,cAAc,KAAK,UAAU,EAAE;AAC/D,IAAA,WAAW,CAAC,SAAS,CAAC,cAAc,GAAG,YAAA;QACtC,IAAI,IAAI,CAAC,OAAO;YACf,MAAM,IAAI,CAAC,MAAM;AACnB,IAAA,CAAC;AACF;AAEA,IAAI,OAAO,WAAW,CAAC,OAAO,KAAK,UAAU,EAAE;AAC9C,IAAA,WAAW,CAAC,OAAO,GAAG,CAAC,YAAoB,KAAiB;AAC3D,QAAA,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE;AACxC,QAAA,UAAU,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,0BAA0B,EAAE,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC;QAC9G,OAAO,UAAU,CAAC,MAAM;AACzB,IAAA,CAAC;AACF;AAEA,IAAI,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU,EAAE;AAC1C,IAAA,WAAW,CAAC,GAAG,GAAG,CAAC,OAAsB,KAAiB;AACzD,QAAA,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE;AAExC,QAAA,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;;AAE7B,YAAA,IAAI,MAAM,CAAC,OAAO,EAAE;AACnB,gBAAA,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC/B;YACD;;YAGA,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;QACvG;QAEA,OAAO,UAAU,CAAC,MAAM;AACzB,IAAA,CAAC;AACF;;"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Runtime polyfills for `AbortSignal`, installed only when the host lacks them:
3
+ * `AbortSignal.prototype.throwIfAborted`, `AbortSignal.timeout` and `AbortSignal.any`.
4
+ *
5
+ * Import for its side effect — there are no exports:
6
+ *
7
+ * ```TypeScript
8
+ * import "@brandup/ui-helpers/polyfill";
9
+ * ```
10
+ *
11
+ * Types already ship with the TypeScript `ESNext` lib; this module only fills in the
12
+ * implementations missing in older runtimes, matching the standard behaviour.
13
+ */
14
+ if (typeof AbortSignal.prototype.throwIfAborted !== "function") {
15
+ AbortSignal.prototype.throwIfAborted = function () {
16
+ if (this.aborted)
17
+ throw this.reason;
18
+ };
19
+ }
20
+ if (typeof AbortSignal.timeout !== "function") {
21
+ AbortSignal.timeout = (milliseconds) => {
22
+ const controller = new AbortController();
23
+ setTimeout(() => controller.abort(new DOMException("The operation timed out.", "TimeoutError")), milliseconds);
24
+ return controller.signal;
25
+ };
26
+ }
27
+ if (typeof AbortSignal.any !== "function") {
28
+ AbortSignal.any = (signals) => {
29
+ const controller = new AbortController();
30
+ for (const signal of signals) {
31
+ // If one is already aborted, the combined signal aborts immediately with its reason.
32
+ if (signal.aborted) {
33
+ controller.abort(signal.reason);
34
+ break;
35
+ }
36
+ // Tying each listener to the combined signal removes them all once it aborts — no leak.
37
+ signal.addEventListener("abort", () => controller.abort(signal.reason), { signal: controller.signal });
38
+ }
39
+ return controller.signal;
40
+ };
41
+ }
42
+ //# sourceMappingURL=polyfill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfill.js","sources":["../../../source/polyfill.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;AAYG;AAEH,IAAI,OAAO,WAAW,CAAC,SAAS,CAAC,cAAc,KAAK,UAAU,EAAE;AAC/D,IAAA,WAAW,CAAC,SAAS,CAAC,cAAc,GAAG,YAAA;QACtC,IAAI,IAAI,CAAC,OAAO;YACf,MAAM,IAAI,CAAC,MAAM;AACnB,IAAA,CAAC;AACF;AAEA,IAAI,OAAO,WAAW,CAAC,OAAO,KAAK,UAAU,EAAE;AAC9C,IAAA,WAAW,CAAC,OAAO,GAAG,CAAC,YAAoB,KAAiB;AAC3D,QAAA,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE;AACxC,QAAA,UAAU,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,0BAA0B,EAAE,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC;QAC9G,OAAO,UAAU,CAAC,MAAM;AACzB,IAAA,CAAC;AACF;AAEA,IAAI,OAAO,WAAW,CAAC,GAAG,KAAK,UAAU,EAAE;AAC1C,IAAA,WAAW,CAAC,GAAG,GAAG,CAAC,OAAsB,KAAiB;AACzD,QAAA,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE;AAExC,QAAA,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;;AAE7B,YAAA,IAAI,MAAM,CAAC,OAAO,EAAE;AACnB,gBAAA,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC/B;YACD;;YAGA,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;QACvG;QAEA,OAAO,UAAU,CAAC,MAAM;AACzB,IAAA,CAAC;AACF"}
@@ -0,0 +1,2 @@
1
+
2
+ export { };
package/package.json CHANGED
@@ -22,16 +22,24 @@
22
22
  "email": "it@brandup.online"
23
23
  },
24
24
  "license": "Apache-2.0",
25
- "version": "2.0.3",
25
+ "version": "2.0.4",
26
26
  "main": "dist/cjs/index.js",
27
27
  "module": "dist/mjs/index.js",
28
28
  "types": "dist/types.d.ts",
29
- "sideEffects": false,
29
+ "sideEffects": [
30
+ "./dist/cjs/polyfill.js",
31
+ "./dist/mjs/polyfill.js"
32
+ ],
30
33
  "exports": {
31
34
  ".": {
32
35
  "types": "./dist/types.d.ts",
33
36
  "import": "./dist/mjs/index.js",
34
37
  "require": "./dist/cjs/index.js"
38
+ },
39
+ "./polyfill": {
40
+ "types": "./dist/polyfill.d.ts",
41
+ "import": "./dist/mjs/polyfill.js",
42
+ "require": "./dist/cjs/polyfill.js"
35
43
  }
36
44
  },
37
45
  "files": [