@signality/core 0.1.2 → 0.2.0

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.
Files changed (94) hide show
  1. package/browser/device-pixel-ratio/index.d.ts +30 -0
  2. package/browser/file-dialog/index.d.ts +1 -2
  3. package/browser/index.d.ts +1 -0
  4. package/browser/listener/index.d.ts +1 -0
  5. package/browser/picture-in-picture/index.d.ts +1 -5
  6. package/browser/text-selection/index.d.ts +9 -2
  7. package/browser/web-notification/index.d.ts +3 -3
  8. package/fesm2022/signality-core-browser-clipboard.mjs +13 -30
  9. package/fesm2022/signality-core-browser-clipboard.mjs.map +1 -1
  10. package/fesm2022/signality-core-browser-device-pixel-ratio.mjs +45 -0
  11. package/fesm2022/signality-core-browser-device-pixel-ratio.mjs.map +1 -0
  12. package/fesm2022/signality-core-browser-eye-dropper.mjs +2 -3
  13. package/fesm2022/signality-core-browser-eye-dropper.mjs.map +1 -1
  14. package/fesm2022/signality-core-browser-file-dialog.mjs +2 -1
  15. package/fesm2022/signality-core-browser-file-dialog.mjs.map +1 -1
  16. package/fesm2022/signality-core-browser-fullscreen.mjs +8 -19
  17. package/fesm2022/signality-core-browser-fullscreen.mjs.map +1 -1
  18. package/fesm2022/signality-core-browser-gamepad.mjs +2 -10
  19. package/fesm2022/signality-core-browser-gamepad.mjs.map +1 -1
  20. package/fesm2022/signality-core-browser-listener.mjs +2 -1
  21. package/fesm2022/signality-core-browser-listener.mjs.map +1 -1
  22. package/fesm2022/signality-core-browser-media-query.mjs +2 -1
  23. package/fesm2022/signality-core-browser-media-query.mjs.map +1 -1
  24. package/fesm2022/signality-core-browser-picture-in-picture.mjs +10 -13
  25. package/fesm2022/signality-core-browser-picture-in-picture.mjs.map +1 -1
  26. package/fesm2022/signality-core-browser-speech-recognition.mjs +2 -1
  27. package/fesm2022/signality-core-browser-speech-recognition.mjs.map +1 -1
  28. package/fesm2022/signality-core-browser-speech-synthesis.mjs +2 -1
  29. package/fesm2022/signality-core-browser-speech-synthesis.mjs.map +1 -1
  30. package/fesm2022/signality-core-browser-storage.mjs +38 -68
  31. package/fesm2022/signality-core-browser-storage.mjs.map +1 -1
  32. package/fesm2022/signality-core-browser-text-direction.mjs +2 -1
  33. package/fesm2022/signality-core-browser-text-direction.mjs.map +1 -1
  34. package/fesm2022/signality-core-browser-text-selection.mjs +36 -4
  35. package/fesm2022/signality-core-browser-text-selection.mjs.map +1 -1
  36. package/fesm2022/signality-core-browser-vibration.mjs +16 -30
  37. package/fesm2022/signality-core-browser-vibration.mjs.map +1 -1
  38. package/fesm2022/signality-core-browser-web-notification.mjs +33 -53
  39. package/fesm2022/signality-core-browser-web-notification.mjs.map +1 -1
  40. package/fesm2022/signality-core-browser-web-share.mjs +3 -11
  41. package/fesm2022/signality-core-browser-web-share.mjs.map +1 -1
  42. package/fesm2022/signality-core-browser-web-worker.mjs +2 -1
  43. package/fesm2022/signality-core-browser-web-worker.mjs.map +1 -1
  44. package/fesm2022/signality-core-browser.mjs +1 -0
  45. package/fesm2022/signality-core-browser.mjs.map +1 -1
  46. package/fesm2022/signality-core-elements-dropzone.mjs +2 -1
  47. package/fesm2022/signality-core-elements-dropzone.mjs.map +1 -1
  48. package/fesm2022/signality-core-elements-element-focus-within.mjs +2 -1
  49. package/fesm2022/signality-core-elements-element-focus-within.mjs.map +1 -1
  50. package/fesm2022/signality-core-elements-element-focus.mjs +2 -1
  51. package/fesm2022/signality-core-elements-element-focus.mjs.map +1 -1
  52. package/fesm2022/signality-core-elements-element-size.mjs +2 -1
  53. package/fesm2022/signality-core-elements-element-size.mjs.map +1 -1
  54. package/fesm2022/signality-core-elements-on-click-outside.mjs +2 -1
  55. package/fesm2022/signality-core-elements-on-click-outside.mjs.map +1 -1
  56. package/fesm2022/signality-core-elements-on-disconnect.mjs +2 -1
  57. package/fesm2022/signality-core-elements-on-disconnect.mjs.map +1 -1
  58. package/fesm2022/signality-core-elements-on-long-press.mjs +2 -1
  59. package/fesm2022/signality-core-elements-on-long-press.mjs.map +1 -1
  60. package/fesm2022/signality-core-elements-scroll-position.mjs +2 -1
  61. package/fesm2022/signality-core-elements-scroll-position.mjs.map +1 -1
  62. package/fesm2022/signality-core-forms-cva.mjs +13 -3
  63. package/fesm2022/signality-core-forms-cva.mjs.map +1 -1
  64. package/fesm2022/signality-core-internal.mjs +35 -27
  65. package/fesm2022/signality-core-internal.mjs.map +1 -1
  66. package/fesm2022/signality-core-observers-intersection-observer.mjs +2 -1
  67. package/fesm2022/signality-core-observers-intersection-observer.mjs.map +1 -1
  68. package/fesm2022/signality-core-observers-mutation-observer.mjs +2 -1
  69. package/fesm2022/signality-core-observers-mutation-observer.mjs.map +1 -1
  70. package/fesm2022/signality-core-observers-resize-observer.mjs +2 -1
  71. package/fesm2022/signality-core-observers-resize-observer.mjs.map +1 -1
  72. package/fesm2022/signality-core-reactivity-debounced.mjs +2 -1
  73. package/fesm2022/signality-core-reactivity-debounced.mjs.map +1 -1
  74. package/fesm2022/signality-core-reactivity-throttled.mjs +2 -1
  75. package/fesm2022/signality-core-reactivity-throttled.mjs.map +1 -1
  76. package/fesm2022/signality-core-scheduling-debounce-callback.mjs +2 -1
  77. package/fesm2022/signality-core-scheduling-debounce-callback.mjs.map +1 -1
  78. package/fesm2022/signality-core-scheduling-interval.mjs +2 -1
  79. package/fesm2022/signality-core-scheduling-interval.mjs.map +1 -1
  80. package/fesm2022/signality-core-scheduling-throttle-callback.mjs +2 -1
  81. package/fesm2022/signality-core-scheduling-throttle-callback.mjs.map +1 -1
  82. package/fesm2022/signality-core-utilities.mjs +64 -0
  83. package/fesm2022/signality-core-utilities.mjs.map +1 -0
  84. package/fesm2022/signality-core.mjs +1 -0
  85. package/fesm2022/signality-core.mjs.map +1 -1
  86. package/forms/cva/index.d.ts +10 -5
  87. package/index.d.ts +1 -0
  88. package/internal/utils/index.d.ts +1 -2
  89. package/internal/utils/wait-for-value.d.ts +6 -0
  90. package/package.json +13 -5
  91. package/utilities/generate-id.d.ts +29 -0
  92. package/utilities/index.d.ts +3 -0
  93. /package/{internal/utils → utilities}/to-element.d.ts +0 -0
  94. /package/{internal/utils → utilities}/to-value.d.ts +0 -0
@@ -1,6 +1,8 @@
1
1
  import { signal, computed } from '@angular/core';
2
- import { setupContext, NOOP_FN, constSignal, ALWAYS_FALSE_FN, createToken } from '@signality/core/internal';
2
+ import { setupContext, NOOP_FN, constSignal, ALWAYS_FALSE_FN, createToken, isNodeWithin } from '@signality/core/internal';
3
+ import { toElement } from '@signality/core/utilities';
3
4
  import { setupSync, listener } from '@signality/core/browser/listener';
5
+ import { onDisconnect } from '@signality/core/elements/on-disconnect';
4
6
 
5
7
  /**
6
8
  * Signal-based wrapper around the [Selection API](https://developer.mozilla.org/en-US/docs/Web/API/Selection_API).
@@ -36,17 +38,40 @@ function textSelection(options) {
36
38
  clear: NOOP_FN,
37
39
  };
38
40
  }
39
- const selection = signal(window.getSelection(), ...(ngDevMode ? [{ debugName: "selection", equal: ALWAYS_FALSE_FN }] : [{ equal: ALWAYS_FALSE_FN }]));
41
+ const root = options?.root;
42
+ const getSelection = () => {
43
+ const sel = window.getSelection();
44
+ if (!root || !sel) {
45
+ return sel;
46
+ }
47
+ const rootEl = toElement(root);
48
+ if (rootEl && isSelectionWithinRoot(sel, rootEl)) {
49
+ return sel;
50
+ }
51
+ else {
52
+ return null;
53
+ }
54
+ };
55
+ const selection = signal(getSelection(), ...(ngDevMode ? [{ debugName: "selection", equal: ALWAYS_FALSE_FN }] : [{
56
+ equal: ALWAYS_FALSE_FN,
57
+ }]));
40
58
  const text = computed(() => selection()?.toString() ?? '', ...(ngDevMode ? [{ debugName: "text" }] : []));
41
59
  const ranges = computed(() => {
42
60
  const sel = selection();
43
61
  return sel ? getRangesFromSelection(sel) : [];
44
62
  }, ...(ngDevMode ? [{ debugName: "ranges" }] : []));
45
63
  const rects = computed(() => ranges().map(range => range.getBoundingClientRect()), ...(ngDevMode ? [{ debugName: "rects" }] : []));
46
- const clear = () => window.getSelection()?.removeAllRanges();
64
+ const clear = () => {
65
+ window.getSelection()?.removeAllRanges();
66
+ };
47
67
  setupSync(() => {
48
- listener(document, 'selectionchange', () => selection.set(window.getSelection()));
68
+ listener(document, 'selectionchange', () => {
69
+ selection.set(getSelection());
70
+ });
49
71
  });
72
+ if (root) {
73
+ onDisconnect(root, () => selection.set(null));
74
+ }
50
75
  return {
51
76
  selection: selection.asReadonly(),
52
77
  text,
@@ -61,6 +86,13 @@ function getRangesFromSelection(selection) {
61
86
  const rangeCount = selection.rangeCount ?? 0;
62
87
  return Array.from({ length: rangeCount }, (_, i) => selection.getRangeAt(i));
63
88
  }
89
+ function isSelectionWithinRoot(selection, rootEl) {
90
+ if (selection.rangeCount === 0) {
91
+ return false;
92
+ }
93
+ const { startContainer, endContainer } = selection.getRangeAt(0);
94
+ return isNodeWithin(startContainer, rootEl) && isNodeWithin(endContainer, rootEl);
95
+ }
64
96
 
65
97
  /**
66
98
  * Generated bundle index. Do not edit.
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-browser-text-selection.mjs","sources":["../../../projects/core/browser/text-selection/index.ts","../../../projects/core/browser/text-selection/signality-core-browser-text-selection.ts"],"sourcesContent":["import { computed, type Signal, signal } from '@angular/core';\nimport {\n ALWAYS_FALSE_FN,\n constSignal,\n createToken,\n NOOP_FN,\n setupContext,\n} from '@signality/core/internal';\nimport type { WithInjector } from '@signality/core/types';\nimport { listener, setupSync } from '@signality/core/browser/listener';\n\nexport type TextSelectionOptions = WithInjector;\n\nexport interface TextSelectionRef {\n /** The selected text content */\n readonly text: Signal<string>;\n\n /** Array of Range objects */\n readonly ranges: Signal<Range[]>;\n\n /** Bounding rectangles of selection */\n readonly rects: Signal<DOMRect[]>;\n\n /** The raw Selection object */\n readonly selection: Signal<Selection | null>;\n\n /** Clear the current text selection */\n readonly clear: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Selection API](https://developer.mozilla.org/en-US/docs/Web/API/Selection_API).\n *\n * @param options - Optional configuration including injector\n * @returns A TextSelectionRef with reactive signals for text, ranges, rects, and selection\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <p>Select some text below:</p>\n * <div>Lorem ipsum dolor sit amet...</div>\n * @if (selection.text(); as text) {\n * <p>Selected: \"{{ text }}\"</p>\n * }\n * `\n * })\n * export class TextSelectionDemo {\n * readonly selection = textSelection();\n * }\n * ```\n */\nexport function textSelection(options?: TextSelectionOptions): TextSelectionRef {\n const { runInContext } = setupContext(options?.injector, textSelection);\n\n return runInContext(({ isServer }) => {\n if (isServer) {\n return {\n selection: constSignal(null),\n text: constSignal(''),\n ranges: constSignal([]),\n rects: constSignal([]),\n clear: NOOP_FN,\n };\n }\n\n const selection = signal<Selection | null>(window.getSelection(), { equal: ALWAYS_FALSE_FN });\n const text = computed(() => selection()?.toString() ?? '');\n const ranges = computed<Range[]>(() => {\n const sel = selection();\n return sel ? getRangesFromSelection(sel) : [];\n });\n const rects = computed(() => ranges().map(range => range.getBoundingClientRect()));\n\n const clear = () => window.getSelection()?.removeAllRanges();\n\n setupSync(() => {\n listener(document, 'selectionchange', () => selection.set(window.getSelection()));\n });\n\n return {\n selection: selection.asReadonly(),\n text,\n ranges,\n rects,\n clear,\n };\n });\n}\n\nexport const TEXT_SELECTION = /* @__PURE__ */ createToken(textSelection);\n\nfunction getRangesFromSelection(selection: Selection): Range[] {\n const rangeCount = selection.rangeCount ?? 0;\n return Array.from({ length: rangeCount }, (_, i) => selection.getRangeAt(i));\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AA8BA;;;;;;;;;;;;;;;;;;;;;AAqBG;AACG,SAAU,aAAa,CAAC,OAA8B,EAAA;AAC1D,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC;AAEvE,IAAA,OAAO,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAI;QACnC,IAAI,QAAQ,EAAE;YACZ,OAAO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C,IAAI;YACJ,MAAM;YACN,KAAK;YACL,KAAK;SACN;AACH,IAAA,CAAC,CAAC;AACJ;AAEO,MAAM,cAAc,mBAAmB,WAAW,CAAC,aAAa;AAEvE,SAAS,sBAAsB,CAAC,SAAoB,EAAA;AAClD,IAAA,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,CAAC;IAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC9E;;AC/FA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-browser-text-selection.mjs","sources":["../../../projects/core/browser/text-selection/index.ts","../../../projects/core/browser/text-selection/signality-core-browser-text-selection.ts"],"sourcesContent":["import { computed, type Signal, signal } from '@angular/core';\nimport {\n ALWAYS_FALSE_FN,\n constSignal,\n createToken,\n isNodeWithin,\n NOOP_FN,\n setupContext,\n} from '@signality/core/internal';\nimport type { MaybeElementSignal, WithInjector } from '@signality/core/types';\nimport { toElement } from '@signality/core/utilities';\nimport { listener, setupSync } from '@signality/core/browser/listener';\nimport { onDisconnect } from '@signality/core/elements/on-disconnect';\n\nexport interface TextSelectionOptions extends WithInjector {\n /**\n * Element to track selection within.\n * When provided, only selections entirely contained within this element are tracked.\n * @default document (all selections)\n */\n readonly root?: MaybeElementSignal<Element>;\n}\n\nexport interface TextSelectionRef {\n /** The selected text content */\n readonly text: Signal<string>;\n\n /** Array of Range objects */\n readonly ranges: Signal<Range[]>;\n\n /** Bounding rectangles of selection */\n readonly rects: Signal<DOMRect[]>;\n\n /** The raw Selection object */\n readonly selection: Signal<Selection | null>;\n\n /** Clear the current text selection */\n readonly clear: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Selection API](https://developer.mozilla.org/en-US/docs/Web/API/Selection_API).\n *\n * @param options - Optional configuration including injector\n * @returns A TextSelectionRef with reactive signals for text, ranges, rects, and selection\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <p>Select some text below:</p>\n * <div>Lorem ipsum dolor sit amet...</div>\n * @if (selection.text(); as text) {\n * <p>Selected: \"{{ text }}\"</p>\n * }\n * `\n * })\n * export class TextSelectionDemo {\n * readonly selection = textSelection();\n * }\n * ```\n */\nexport function textSelection(options?: TextSelectionOptions): TextSelectionRef {\n const { runInContext } = setupContext(options?.injector, textSelection);\n\n return runInContext(({ isServer }) => {\n if (isServer) {\n return {\n selection: constSignal(null),\n text: constSignal(''),\n ranges: constSignal([]),\n rects: constSignal([]),\n clear: NOOP_FN,\n };\n }\n\n const root = options?.root;\n\n const getSelection = (): Selection | null => {\n const sel = window.getSelection();\n if (!root || !sel) {\n return sel;\n }\n\n const rootEl = toElement(root);\n if (rootEl && isSelectionWithinRoot(sel, rootEl)) {\n return sel;\n } else {\n return null;\n }\n };\n\n const selection = signal<Selection | null>(getSelection(), {\n equal: ALWAYS_FALSE_FN,\n });\n\n const text = computed(() => selection()?.toString() ?? '');\n\n const ranges = computed<Range[]>(() => {\n const sel = selection();\n return sel ? getRangesFromSelection(sel) : [];\n });\n\n const rects = computed(() => ranges().map(range => range.getBoundingClientRect()));\n\n const clear = () => {\n window.getSelection()?.removeAllRanges();\n };\n\n setupSync(() => {\n listener(document, 'selectionchange', () => {\n selection.set(getSelection());\n });\n });\n\n if (root) {\n onDisconnect(root, () => selection.set(null));\n }\n\n return {\n selection: selection.asReadonly(),\n text,\n ranges,\n rects,\n clear,\n };\n });\n}\n\nexport const TEXT_SELECTION = /* @__PURE__ */ createToken(textSelection);\n\nfunction getRangesFromSelection(selection: Selection): Range[] {\n const rangeCount = selection.rangeCount ?? 0;\n return Array.from({ length: rangeCount }, (_, i) => selection.getRangeAt(i));\n}\n\nfunction isSelectionWithinRoot(selection: Selection, rootEl: Element): boolean {\n if (selection.rangeCount === 0) {\n return false;\n }\n const { startContainer, endContainer } = selection.getRangeAt(0);\n return isNodeWithin(startContainer, rootEl) && isNodeWithin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AAE,UAAU,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAC9E;AAEA,SAAS,qBAAqB,CAAC,SAAoB,EAAE,MAAe,EAAA;AAClE,IAAA,IAAI,SAAS,CAAC,UAAU,KAAK,CAAC,EAAE;AAC9B,QAAA,OAAO,KAAK;IACd;AACA,IAAA,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AAChE,IAAA,OAAO,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,IAAI,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC;AACnF;;AC9IA;;AAEG;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { signal } from '@angular/core';
2
- import { setupContext, constSignal, NOOP_FN, toValue } from '@signality/core/internal';
2
+ import { setupContext, constSignal, NOOP_FN } from '@signality/core/internal';
3
+ import { toValue } from '@signality/core/utilities';
3
4
 
4
5
  /**
5
6
  * Signal-based wrapper around the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API).
@@ -47,39 +48,24 @@ function vibration(options) {
47
48
  let vibrateTimeout;
48
49
  const vibrate = (vibratePattern) => {
49
50
  const resolvedPattern = vibratePattern ?? toValue.untracked(options?.pattern) ?? 200;
50
- try {
51
- const result = navigator.vibrate(resolvedPattern);
52
- isVibrating.set(result);
53
- const duration = Array.isArray(resolvedPattern)
54
- ? resolvedPattern.reduce((a, b) => a + b, 0)
55
- : resolvedPattern;
56
- if (result && duration > 0) {
57
- if (vibrateTimeout) {
58
- clearTimeout(vibrateTimeout);
59
- }
60
- vibrateTimeout = setTimeout(() => {
61
- isVibrating.set(false);
62
- vibrateTimeout = undefined;
63
- }, duration);
64
- }
65
- }
66
- catch (error) {
67
- isVibrating.set(false);
68
- if (ngDevMode) {
69
- console.warn(`[vibration] Failed to vibrate device.`, error);
51
+ const result = navigator.vibrate(resolvedPattern);
52
+ isVibrating.set(result);
53
+ const duration = Array.isArray(resolvedPattern)
54
+ ? resolvedPattern.reduce((a, b) => a + b, 0)
55
+ : resolvedPattern;
56
+ if (result && duration > 0) {
57
+ if (vibrateTimeout) {
58
+ clearTimeout(vibrateTimeout);
70
59
  }
60
+ vibrateTimeout = setTimeout(() => {
61
+ isVibrating.set(false);
62
+ vibrateTimeout = undefined;
63
+ }, duration);
71
64
  }
72
65
  };
73
66
  const stop = () => {
74
- try {
75
- navigator.vibrate(0);
76
- isVibrating.set(false);
77
- }
78
- catch (error) {
79
- if (ngDevMode) {
80
- console.warn(`[vibration] Failed to stop vibration.`, error);
81
- }
82
- }
67
+ navigator.vibrate(0);
68
+ isVibrating.set(false);
83
69
  if (vibrateTimeout) {
84
70
  clearTimeout(vibrateTimeout);
85
71
  vibrateTimeout = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-browser-vibration.mjs","sources":["../../../projects/core/browser/vibration/index.ts","../../../projects/core/browser/vibration/signality-core-browser-vibration.ts"],"sourcesContent":["import { type Signal, signal } from '@angular/core';\nimport { constSignal, NOOP_FN, setupContext, type Timer, toValue } from '@signality/core/internal';\nimport type { MaybeSignal, WithInjector } from '@signality/core/types';\n\nexport interface VibrationOptions extends WithInjector {\n /**\n * Default vibration pattern in milliseconds. A single number vibrates for that duration;\n * an array alternates between vibration and pause durations.\n *\n * @see [Navigator: vibrate() pattern on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate#pattern)\n */\n readonly pattern?: MaybeSignal<number | number[]>;\n}\n\nexport interface VibrationRef {\n /**\n * Whether the Vibration API is supported in the current browser.\n *\n * @see [Vibration API browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API#browser_compatibility)\n */\n readonly isSupported: Signal<boolean>;\n\n /**\n * Whether the device is currently vibrating.\n */\n readonly isVibrating: Signal<boolean>;\n\n /**\n * Trigger vibration with an optional pattern. Falls back to the default pattern from options, then `200ms`.\n *\n * @see [Navigator: vibrate() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)\n */\n readonly vibrate: (pattern?: number | number[]) => void;\n\n /**\n * Stop any active vibration by calling `navigator.vibrate(0)`.\n *\n * @see [Navigator: vibrate() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)\n */\n readonly stop: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API).\n *\n * @param options - Optional configuration including default pattern and injector\n * @returns A VibrationRef with vibration control methods\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * @if (vib.isSupported()) {\n * <button (click)=\"vib.vibrate(100)\">Vibrate 100ms</button>\n * <button (click)=\"vib.vibrate([100, 50, 100])\">Pattern</button>\n * <button (click)=\"vib.stop()\">Stop</button>\n * }\n * `\n * })\n * export class VibrationDemo {\n * readonly vib = vibration();\n * }\n * ```\n *\n * @example\n * ```typescript\n * // With a default pattern\n * const vib = vibration({ pattern: 200 });\n *\n * vib.vibrate(); // Uses default 200ms pattern\n * ```\n */\nexport function vibration(options?: VibrationOptions): VibrationRef {\n const { runInContext } = setupContext(options?.injector, vibration);\n\n return runInContext(({ isBrowser, onCleanup }) => {\n const isSupported = constSignal(isBrowser && 'vibrate' in navigator);\n\n if (!isSupported()) {\n return {\n isSupported,\n isVibrating: constSignal(false),\n vibrate: NOOP_FN,\n stop: NOOP_FN,\n };\n }\n\n const isVibrating = signal(false);\n\n let vibrateTimeout: Timer;\n\n const vibrate = (vibratePattern?: number | number[]) => {\n const resolvedPattern = vibratePattern ?? toValue.untracked(options?.pattern) ?? 200;\n\n try {\n const result = navigator.vibrate(resolvedPattern);\n\n isVibrating.set(result);\n\n const duration = Array.isArray(resolvedPattern)\n ? resolvedPattern.reduce((a, b) => a + b, 0)\n : resolvedPattern;\n\n if (result && duration > 0) {\n if (vibrateTimeout) {\n clearTimeout(vibrateTimeout);\n }\n\n vibrateTimeout = setTimeout(() => {\n isVibrating.set(false);\n vibrateTimeout = undefined;\n }, duration);\n }\n } catch (error) {\n isVibrating.set(false);\n if (ngDevMode) {\n console.warn(`[vibration] Failed to vibrate device.`, error);\n }\n }\n };\n\n const stop = () => {\n try {\n navigator.vibrate(0);\n isVibrating.set(false);\n } catch (error) {\n if (ngDevMode) {\n console.warn(`[vibration] Failed to stop vibration.`, error);\n }\n }\n\n if (vibrateTimeout) {\n clearTimeout(vibrateTimeout);\n vibrateTimeout = undefined;\n }\n };\n\n onCleanup(stop);\n\n return {\n isSupported,\n isVibrating: isVibrating.asReadonly(),\n vibrate,\n stop,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AA0CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,SAAS,CAAC,OAA0B,EAAA;AAClD,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC;IAEnE,OAAO,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAI;QAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,IAAI,SAAS,IAAI,SAAS,CAAC;AAEpE,QAAA,IAAI,CAAC,WAAW,EAAE,EAAE;YAClB,OAAO;gBACL,WAAW;AACX,gBAAA,WAAW,EAAE,WAAW,CAAC,KAAK,CAAC;AAC/B,gBAAA,OAAO,EAAE,OAAO;AAChB,gBAAA,IAAI,EAAE,OAAO;aACd;QACH;AAEA,QAAA,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,uDAAC;AAEjC,QAAA,IAAI,cAAqB;AAEzB,QAAA,MAAM,OAAO,GAAG,CAAC,cAAkC,KAAI;AACrD,YAAA,MAAM,eAAe,GAAG,cAAc,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,GAAG;AAEpF,YAAA,IAAI;gBACF,MAAM,MAAM,GAAG,SAAS,CAAC,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L;AACH,IAAA,CAAC,CAAC;AACJ;;AClJA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-browser-vibration.mjs","sources":["../../../projects/core/browser/vibration/index.ts","../../../projects/core/browser/vibration/signality-core-browser-vibration.ts"],"sourcesContent":["import { type Signal, signal } from '@angular/core';\nimport { constSignal, NOOP_FN, setupContext, type Timer } from '@signality/core/internal';\nimport { toValue } from '@signality/core/utilities';\nimport type { MaybeSignal, WithInjector } from '@signality/core/types';\n\nexport interface VibrationOptions extends WithInjector {\n /**\n * Default vibration pattern in milliseconds. A single number vibrates for that duration;\n * an array alternates between vibration and pause durations.\n *\n * @see [Navigator: vibrate() pattern on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate#pattern)\n */\n readonly pattern?: MaybeSignal<number | number[]>;\n}\n\nexport interface VibrationRef {\n /**\n * Whether the Vibration API is supported in the current browser.\n *\n * @see [Vibration API browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API#browser_compatibility)\n */\n readonly isSupported: Signal<boolean>;\n\n /**\n * Whether the device is currently vibrating.\n */\n readonly isVibrating: Signal<boolean>;\n\n /**\n * Trigger vibration with an optional pattern. Falls back to the default pattern from options, then `200ms`.\n *\n * @see [Navigator: vibrate() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)\n */\n readonly vibrate: (pattern?: number | number[]) => void;\n\n /**\n * Stop any active vibration by calling `navigator.vibrate(0)`.\n *\n * @see [Navigator: vibrate() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)\n */\n readonly stop: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Vibration API](https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API).\n *\n * @param options - Optional configuration including default pattern and injector\n * @returns A VibrationRef with vibration control methods\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * @if (vib.isSupported()) {\n * <button (click)=\"vib.vibrate(100)\">Vibrate 100ms</button>\n * <button (click)=\"vib.vibrate([100, 50, 100])\">Pattern</button>\n * <button (click)=\"vib.stop()\">Stop</button>\n * }\n * `\n * })\n * export class VibrationDemo {\n * readonly vib = vibration();\n * }\n * ```\n *\n * @example\n * ```typescript\n * // With a default pattern\n * const vib = vibration({ pattern: 200 });\n *\n * vib.vibrate(); // Uses default 200ms pattern\n * ```\n */\nexport function vibration(options?: VibrationOptions): VibrationRef {\n const { runInContext } = setupContext(options?.injector, vibration);\n\n return runInContext(({ isBrowser, onCleanup }) => {\n const isSupported = constSignal(isBrowser && 'vibrate' in navigator);\n\n if (!isSupported()) {\n return {\n isSupported,\n isVibrating: constSignal(false),\n vibrate: NOOP_FN,\n stop: NOOP_FN,\n };\n }\n\n const isVibrating = signal(false);\n\n let vibrateTimeout: Timer;\n\n const vibrate = (vibratePattern?: number | number[]) => {\n const resolvedPattern = vibratePattern ?? toValue.untracked(options?.pattern) ?? 200;\n\n const result = navigator.vibrate(resolvedPattern);\n\n isVibrating.set(result);\n\n const duration = Array.isArray(resolvedPattern)\n ? resolvedPattern.reduce((a, b) => a + b, 0)\n : resolvedPattern;\n\n if (result && duration > 0) {\n if (vibrateTimeout) {\n clearTimeout(vibrateTimeout);\n }\n\n vibrateTimeout = setTimeout(() => {\n isVibrating.set(false);\n vibrateTimeout = undefined;\n }, duration);\n }\n };\n\n const stop = () => {\n navigator.vibrate(0);\n isVibrating.set(false);\n\n if (vibrateTimeout) {\n clearTimeout(vibrateTimeout);\n vibrateTimeout = undefined;\n }\n };\n\n onCleanup(stop);\n\n return {\n isSupported,\n isVibrating: isVibrating.asReadonly(),\n vibrate,\n stop,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AA2CA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,SAAS,CAAC,OAA0B,EAAA;AAClD,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,SA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;AACpB,YAAA,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC;YAEtB,IAAI,cAAc,EAAE;gBAClB,YAAY,CAAC,cAAc,CAAC;gBAC5B,cAAc,GAAG,SAAS;YAC5B;AACF,QAAA,CAAC;QAED,SAAS,CAAC,IAAI,CAAC;QAEf,OAAO;YACL,WAAW;AACX,YAAA,WAAW,EAAE,WAAW,CAAC,UAAU,EAAE;YACrC,OAAO;YACP,IAAI;SACL;AACH,IAAA,CAAC,CAAC;AACJ;;ACtIA;;AAEG;;;;"}
@@ -1,5 +1,8 @@
1
1
  import { signal, untracked } from '@angular/core';
2
- import { setupContext, constSignal, NOOP_FN, toValue } from '@signality/core/internal';
2
+ import { setupContext, constSignal, NOOP_FN, NOOP_ASYNC_FN } from '@signality/core/internal';
3
+ import { toValue } from '@signality/core/utilities';
4
+ import { watcher } from '@signality/core/reactivity';
5
+ import { permissionState } from '@signality/core/browser/permission-state';
3
6
 
4
7
  /**
5
8
  * Signal-based wrapper around the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API).
@@ -45,77 +48,54 @@ function webNotification(options) {
45
48
  isSupported,
46
49
  permission: constSignal('denied'),
47
50
  notification: constSignal(null),
48
- requestPermission: async () => 'denied',
49
- show: () => undefined,
51
+ requestPermission: NOOP_ASYNC_FN,
52
+ show: NOOP_FN,
50
53
  close: NOOP_FN,
51
54
  };
52
55
  }
53
56
  const permission = signal(Notification.permission, ...(ngDevMode ? [{ debugName: "permission" }] : []));
54
57
  const notification = signal(null, ...(ngDevMode ? [{ debugName: "notification" }] : []));
55
58
  let autoCloseTimeout;
56
- const clearAutoClose = () => {
59
+ const cancelAutoClose = () => {
57
60
  clearTimeout(autoCloseTimeout);
58
61
  autoCloseTimeout = undefined;
59
62
  };
60
63
  const requestPermission = async () => {
61
- try {
62
- const result = await Notification.requestPermission();
63
- permission.set(result);
64
- return result;
65
- }
66
- catch (error) {
67
- if (ngDevMode) {
68
- console.warn(`[webNotification] Failed to request notification permission.`, error);
69
- }
70
- return permission();
71
- }
64
+ const result = await Notification.requestPermission();
65
+ permission.set(result);
72
66
  };
73
67
  const close = () => {
74
- clearAutoClose();
75
- const current = notification();
68
+ cancelAutoClose();
69
+ const current = untracked(notification);
76
70
  if (current) {
77
- try {
78
- current.onclose = null;
79
- current.close();
80
- }
81
- catch (error) {
82
- if (ngDevMode) {
83
- console.warn(`[webNotification] Failed to close notification.`, error);
84
- }
85
- }
71
+ current.onclose = null;
72
+ current.close();
86
73
  notification.set(null);
87
74
  }
88
75
  };
89
76
  const show = (title, overrides) => {
90
- return untracked(() => {
91
- if (permission() !== 'granted') {
92
- return undefined;
93
- }
94
- close();
95
- try {
96
- const { autoClose, ...defaults } = options ?? {};
97
- const mergedOptions = { ...defaults, ...overrides };
98
- const instance = new Notification(title, mergedOptions);
99
- instance.onclose = () => {
100
- clearAutoClose();
101
- notification.set(null);
102
- };
103
- notification.set(instance);
104
- const autoCloseMs = toValue(autoClose);
105
- if (autoCloseMs && autoCloseMs > 0) {
106
- autoCloseTimeout = setTimeout(close, autoCloseMs);
107
- }
108
- return instance;
109
- }
110
- catch (error) {
111
- if (ngDevMode) {
112
- console.warn(`[webNotification] Failed to show notification.`, error);
113
- }
114
- return undefined;
115
- }
116
- });
77
+ if (untracked(permission) !== 'granted') {
78
+ return;
79
+ }
80
+ const { autoClose, ...defaultOptions } = options ?? {};
81
+ const instance = new Notification(title, { ...defaultOptions, ...overrides });
82
+ instance.onclose = () => {
83
+ cancelAutoClose();
84
+ notification.set(null);
85
+ };
86
+ notification.set(instance);
87
+ const autoCloseMs = toValue(autoClose);
88
+ if (autoCloseMs && autoCloseMs > 0) {
89
+ autoCloseTimeout = setTimeout(close, autoCloseMs);
90
+ }
117
91
  };
118
92
  onCleanup(close);
93
+ watcher(permissionState('notifications'), state => {
94
+ permission.set(state === 'prompt' ? 'default' : state);
95
+ if (state === 'denied') {
96
+ close();
97
+ }
98
+ });
119
99
  return {
120
100
  isSupported,
121
101
  permission: permission.asReadonly(),
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-browser-web-notification.mjs","sources":["../../../projects/core/browser/web-notification/index.ts","../../../projects/core/browser/web-notification/signality-core-browser-web-notification.ts"],"sourcesContent":["import { type Signal, signal, untracked } from '@angular/core';\nimport { constSignal, NOOP_FN, setupContext, type Timer, toValue } from '@signality/core/internal';\nimport type { MaybeSignal, WithInjector } from '@signality/core/types';\n\nexport interface WebNotificationOptions extends NotificationOptions, WithInjector {\n /**\n * Auto-close the notification after the specified number of milliseconds.\n *\n * @see [Notification: close() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/close)\n */\n readonly autoClose?: MaybeSignal<number>;\n}\n\nexport interface WebNotificationRef {\n /**\n * Whether the Notifications API is supported in the current browser.\n *\n * @see [Notifications API browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API#browser_compatibility)\n */\n readonly isSupported: Signal<boolean>;\n\n /**\n * Current notification permission state: `'granted'`, `'denied'`, or `'default'`.\n *\n * @see [Notification: permission static property on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission_static)\n */\n readonly permission: Signal<NotificationPermission>;\n\n /**\n * The currently active notification instance, or `null` if none is shown.\n *\n * @see [Notification on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification)\n */\n readonly notification: Signal<Notification | null>;\n\n /**\n * Request permission to show notifications.\n *\n * @see [Notification: requestPermission() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission_static)\n */\n readonly requestPermission: () => Promise<NotificationPermission>;\n\n /**\n * Show a notification. Automatically closes the previous one. Per-call options override constructor defaults.\n *\n * @see [Notification() constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification)\n */\n readonly show: (title: string, options?: NotificationOptions) => Notification | undefined;\n\n /**\n * Close the currently active notification.\n *\n * @see [Notification: close() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/close)\n */\n readonly close: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API).\n *\n * Tracks the current notification as a signal. Calling `show()` auto-closes\n * the previous notification. Calling `close()` closes the current one.\n *\n * @param options - Optional configuration and default notification options\n * @returns A WebNotificationRef with notification state and control methods\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <button (click)=\"requestPermission()\">Request Permission</button>\n * <button (click)=\"showNotification()\" [disabled]=\"notif.permission() !== 'granted'\">\n * Show Notification\n * </button>\n * @if (notif.notification()) {\n * <button (click)=\"notif.close()\">Close</button>\n * }\n * `\n * })\n * export class NotificationDemo {\n * readonly notif = webNotification({ icon: '/icon.png' });\n *\n * async requestPermission() {\n * await this.notif.requestPermission();\n * }\n *\n * showNotification() {\n * this.notif.show('Hello!', { body: 'This is a notification' });\n * }\n * }\n * ```\n */\nexport function webNotification(options?: WebNotificationOptions): WebNotificationRef {\n const { runInContext } = setupContext(options?.injector, webNotification);\n\n return runInContext(({ isBrowser, onCleanup }) => {\n const isSupported = constSignal(isBrowser && 'Notification' in window);\n\n if (!isSupported()) {\n return {\n isSupported,\n permission: constSignal('denied'),\n notification: constSignal(null),\n requestPermission: async () => 'denied',\n show: () => undefined,\n close: NOOP_FN,\n };\n }\n\n const permission = signal(Notification.permission);\n const notification = signal<Notification | null>(null);\n\n let autoCloseTimeout: Timer;\n\n const clearAutoClose = () => {\n clearTimeout(autoCloseTimeout);\n autoCloseTimeout = undefined;\n };\n\n const requestPermission = async (): Promise<NotificationPermission> => {\n try {\n const result = await Notification.requestPermission();\n permission.set(result);\n return result;\n } catch (error) {\n if (ngDevMode) {\n console.warn(`[webNotification] Failed to request notification permission.`, error);\n }\n return permission();\n }\n };\n\n const close = (): void => {\n clearAutoClose();\n\n const current = notification();\n\n if (current) {\n try {\n current.onclose = null;\n current.close();\n } catch (error) {\n if (ngDevMode) {\n console.warn(`[webNotification] Failed to close notification.`, error);\n }\n }\n notification.set(null);\n }\n };\n\n const show = (title: string, overrides?: NotificationOptions): Notification | undefined => {\n return untracked(() => {\n if (permission() !== 'granted') {\n return undefined;\n }\n\n close();\n\n try {\n const { autoClose, ...defaults } = options ?? {};\n const mergedOptions = { ...defaults, ...overrides };\n\n const instance = new Notification(title, mergedOptions);\n\n instance.onclose = () => {\n clearAutoClose();\n notification.set(null);\n };\n\n notification.set(instance);\n\n const autoCloseMs = toValue(autoClose);\n if (autoCloseMs && autoCloseMs > 0) {\n autoCloseTimeout = setTimeout(close, autoCloseMs);\n }\n\n return instance;\n } catch (error) {\n if (ngDevMode) {\n console.warn(`[webNotification] Failed to show notification.`, error);\n }\n return undefined;\n }\n });\n };\n\n onCleanup(close);\n\n return {\n isSupported,\n permission: permission.asReadonly(),\n notification: notification.asReadonly(),\n requestPermission,\n show,\n close,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACG,SAAU,eAAe,CAAC,OAAgC,EAAA;AAC9D,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC;IAEzE,OAAO,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAI;QAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,IAAI,cAAc,IAAI,MAAM,CAAC;AAEtE,QAAA,IAAI,CAAC,WAAW,EAAE,EAAE;YAClB,OAAO;gBACL,WAAW;AACX,gBAAA,UAAU,EAAE,WAAW,CAAC,QAAQ,CAAC;AACjC,gBAAA,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC;AAC/B,gBAAA,iBAAiB,EAAE,YAAY,QAAQ;AACvC,gBAAA,IAAI,EAAE,MAAM,SAAS;AACrB,gBAAA,KAAK,EAAE,OAAO;aACf;QACH;QAEA,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,sDAAC;AAClD,QAAA,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GAAG,OAAO,IAAI,EAAE;oBAChD,MAAM,aAAa,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE;oBAEnD,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,KAAK,EAAE,aAAa,CAAC;AAEvD,oBAAA,QAAQ,CAAC,OAAO,GAAG,MAAK;AACtB,wBAAA,cAAc,EAAE;AAChB,wBAAA,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC;AACxB,oBAAA,CAAC;AAED,oBAAA,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC;AAE1B,oBAAA,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;AACtC,oBAAA,IAAI,WAAW,IAAI,WAAW,GAAG,CAAC,EAAE;AAClC,wBAAA,gBAAgB,GAAG,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC;oBACnD;AAEA,oBAAA,OAAO,QAAQ;gBACjB;gBAAE,OAAO,KAAK,EAAE;oBACd,IAAI,SAAS,EAAE;AACb,wBAAA,OAAO,CAAC,IAAI,CAAC,gDAAgD,EAAE,KAAK,CAAC;oBACvE;AACA,oBAAA,OAAO,SAAS;gBAClB;AACF,YAAA,CAAC,CAAC;AACJ,QAAA,CAAC;QAED,SAAS,CAAC,KAAK,CAAC;QAEhB,OAAO;YACL,WAAW;AACX,YAAA,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE;AACnC,YAAA,YAAY,EAAE,YAAY,CAAC,UAAU,EAAE;YACvC,iBAAiB;YACjB,IAAI;YACJ,KAAK;SACN;AACH,IAAA,CAAC,CAAC;AACJ;;ACrMA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-browser-web-notification.mjs","sources":["../../../projects/core/browser/web-notification/index.ts","../../../projects/core/browser/web-notification/signality-core-browser-web-notification.ts"],"sourcesContent":["import { type Signal, signal, untracked } from '@angular/core';\nimport {\n constSignal,\n NOOP_ASYNC_FN,\n NOOP_FN,\n setupContext,\n type Timer,\n} from '@signality/core/internal';\nimport { toValue } from '@signality/core/utilities';\nimport type { MaybeSignal, WithInjector } from '@signality/core/types';\nimport { watcher } from '@signality/core/reactivity';\nimport { permissionState } from '@signality/core/browser/permission-state';\n\nexport interface WebNotificationOptions extends NotificationOptions, WithInjector {\n /**\n * Auto-close the notification after the specified number of milliseconds.\n *\n * @see [Notification: close() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/close)\n */\n readonly autoClose?: MaybeSignal<number>;\n}\n\nexport interface WebNotificationRef {\n /**\n * Whether the Notifications API is supported in the current browser.\n *\n * @see [Notifications API browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API#browser_compatibility)\n */\n readonly isSupported: Signal<boolean>;\n\n /**\n * Current notification permission state: `'granted'`, `'denied'`, or `'default'`.\n *\n * @see [Notification: permission static property on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/permission_static)\n */\n readonly permission: Signal<NotificationPermission>;\n\n /**\n * The currently active notification instance, or `null` if none is shown.\n *\n * @see [Notification on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification)\n */\n readonly notification: Signal<Notification | null>;\n\n /**\n * Request permission to show notifications.\n *\n * @see [Notification: requestPermission() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/requestPermission_static)\n */\n readonly requestPermission: () => Promise<void>;\n\n /**\n * Show a notification.\n *\n * @see [Notification() constructor on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/Notification)\n */\n readonly show: (title: string, options?: NotificationOptions) => void;\n\n /**\n * Close the currently active notification.\n *\n * @see [Notification: close() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Notification/close)\n */\n readonly close: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Notifications API](https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API).\n *\n * Tracks the current notification as a signal. Calling `show()` auto-closes\n * the previous notification. Calling `close()` closes the current one.\n *\n * @param options - Optional configuration and default notification options\n * @returns A WebNotificationRef with notification state and control methods\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <button (click)=\"requestPermission()\">Request Permission</button>\n * <button (click)=\"showNotification()\" [disabled]=\"notif.permission() !== 'granted'\">\n * Show Notification\n * </button>\n * @if (notif.notification()) {\n * <button (click)=\"notif.close()\">Close</button>\n * }\n * `\n * })\n * export class NotificationDemo {\n * readonly notif = webNotification({ icon: '/icon.png' });\n *\n * async requestPermission() {\n * await this.notif.requestPermission();\n * }\n *\n * showNotification() {\n * this.notif.show('Hello!', { body: 'This is a notification' });\n * }\n * }\n * ```\n */\nexport function webNotification(options?: WebNotificationOptions): WebNotificationRef {\n const { runInContext } = setupContext(options?.injector, webNotification);\n\n return runInContext(({ isBrowser, onCleanup }) => {\n const isSupported = constSignal(isBrowser && 'Notification' in window);\n\n if (!isSupported()) {\n return {\n isSupported,\n permission: constSignal('denied'),\n notification: constSignal(null),\n requestPermission: NOOP_ASYNC_FN,\n show: NOOP_FN,\n close: NOOP_FN,\n };\n }\n\n const permission = signal(Notification.permission);\n const notification = signal<Notification | null>(null);\n\n let autoCloseTimeout: Timer;\n\n const cancelAutoClose = () => {\n clearTimeout(autoCloseTimeout);\n autoCloseTimeout = undefined;\n };\n\n const requestPermission = async (): Promise<void> => {\n const result = await Notification.requestPermission();\n permission.set(result);\n };\n\n const close = () => {\n cancelAutoClose();\n\n const current = untracked(notification);\n\n if (current) {\n current.onclose = null;\n current.close();\n notification.set(null);\n }\n };\n\n const show = (title: string, overrides?: NotificationOptions) => {\n if (untracked(permission) !== 'granted') {\n return;\n }\n\n const { autoClose, ...defaultOptions } = options ?? {};\n const instance = new Notification(title, { ...defaultOptions, ...overrides });\n\n instance.onclose = () => {\n cancelAutoClose();\n notification.set(null);\n };\n\n notification.set(instance);\n\n const autoCloseMs = toValue(autoClose);\n if (autoCloseMs && autoCloseMs > 0) {\n autoCloseTimeout = setTimeout(close, autoCloseMs);\n }\n };\n\n onCleanup(close);\n\n watcher(permissionState('notifications'), state => {\n permission.set(state === 'prompt' ? 'default' : state);\n\n if (state === 'denied') {\n close();\n }\n });\n\n return {\n isSupported,\n permission: permission.asReadonly(),\n notification: notification.asReadonly(),\n requestPermission,\n show,\n close,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAkEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACG,SAAU,eAAe,CAAC,OAAgC,EAAA;AAC9D,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC;IAEzE,OAAO,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAI;QAC/C,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,IAAI,cAAc,IAAI,MAAM,CAAC;AAEtE,QAAA,IAAI,CAAC,WAAW,EAAE,EAAE;YAClB,OAAO;gBACL,WAAW;AACX,gBAAA,UAAU,EAAE,WAAW,CAAC,QAAQ,CAAC;AACjC,gBAAA,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC;AAC/B,gBAAA,iBAAiB,EAAE,aAAa;AAChC,gBAAA,IAAI,EAAE,OAAO;AACb,gBAAA,KAAK,EAAE,OAAO;aACf;QACH;QAEA,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,sDAAC;AAClD,QAAA,MAAM,YAAY,GAAG,MAAM,CAAsB,IAAI,wDAAC;AAEtD,QAAA,IAAI,gBAAuB;QAE3B,MAAM,eAAe,GAAG,MAAK;YAC3B,YAAY,CAAC,gBAAgB,CAAC;YAC9B,gBAAgB,GAAG,SAAS;AAC9B,QAAA,CAAC;AAED,QAAA,MAAM,iBAAiB,GAAG,YAA0B;AAClD,YAAA,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,iBAAiB,EAAE;AACrD,YAAA,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC;AACxB,QAAA,CAAC;QAED,MAAM,KAAK,GAAG,MAAK;AACjB,YAA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AACX,YAAA,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE;AACnC,YAAA,YAAY,EAAE,YAAY,CAAC,UAAU,EAAE;YACvC,iBAAiB;YACjB,IAAI;YACJ,KAAK;SACN;AACH,IAAA,CAAC,CAAC;AACJ;;ACzLA;;AAEG;;;;"}
@@ -54,8 +54,8 @@ function webShare(options) {
54
54
  catch (error) {
55
55
  // user canceled, or share failed
56
56
  // AbortError is expected when a user cancels
57
- if (ngDevMode && error.name !== 'AbortError') {
58
- console.warn(`[webShare] Failed to share content.`, error);
57
+ if (error.name !== 'AbortError') {
58
+ throw error;
59
59
  }
60
60
  }
61
61
  finally {
@@ -63,15 +63,7 @@ function webShare(options) {
63
63
  }
64
64
  };
65
65
  const canShare = (data) => {
66
- try {
67
- return navigator.canShare(data);
68
- }
69
- catch (error) {
70
- if (ngDevMode) {
71
- console.warn(`[webShare] Failed to check if content can be shared.`, error);
72
- }
73
- return false;
74
- }
66
+ return navigator.canShare(data);
75
67
  };
76
68
  return {
77
69
  isSupported,
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-browser-web-share.mjs","sources":["../../../projects/core/browser/web-share/index.ts","../../../projects/core/browser/web-share/signality-core-browser-web-share.ts"],"sourcesContent":["import { type Signal, signal, untracked } from '@angular/core';\nimport { constSignal, NOOP_ASYNC_FN, setupContext } from '@signality/core/internal';\nimport type { WithInjector } from '@signality/core/types';\n\nexport interface WebShareRef {\n /**\n * Whether the Web Share API is supported in the current browser.\n *\n * @see [Web Share API browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API#browser_compatibility)\n */\n readonly isSupported: Signal<boolean>;\n\n /**\n * Whether the native share dialog is currently open.\n */\n readonly isSharing: Signal<boolean>;\n\n /**\n * Open the native share dialog with the provided data.\n *\n * @see [Navigator: share() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share)\n */\n readonly share: (data: ShareData) => Promise<void>;\n\n /**\n * Check whether the given data can be shared via the Web Share API.\n *\n * @see [Navigator: canShare() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/canShare)\n */\n readonly canShare: (data?: ShareData) => boolean;\n}\n\n/**\n * Signal-based wrapper around the [Web Share API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API).\n *\n * @param options - Optional injector for DI context\n * @returns A WebShareRef with share methods and state signals\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * @if (webShare.isSupported()) {\n * <button (click)=\"shareContent()\" [disabled]=\"webShare.isSharing()\">\n * Share This Page\n * </button>\n * }\n * `\n * })\n * export class WebShareDemo {\n * readonly webShare = webShare();\n *\n * async shareContent() {\n * await this.webShare.share({\n * title: 'Check this out!',\n * url: window.location.href,\n * });\n * }\n * }\n * ```\n */\nexport function webShare(options?: WithInjector): WebShareRef {\n const { runInContext } = setupContext(options?.injector, webShare);\n\n return runInContext(({ isBrowser }) => {\n const isSupported = constSignal(isBrowser && 'share' in navigator);\n\n if (!isSupported()) {\n return {\n isSupported,\n isSharing: constSignal(false),\n canShare: () => false,\n share: NOOP_ASYNC_FN,\n };\n }\n\n const isSharing = signal(false);\n\n const share = async (data: ShareData): Promise<void> => {\n if (untracked(isSharing)) {\n return;\n }\n\n try {\n isSharing.set(true);\n await navigator.share(data);\n } catch (error) {\n // user canceled, or share failed\n // AbortError is expected when a user cancels\n if (ngDevMode && (error as Error).name !== 'AbortError') {\n console.warn(`[webShare] Failed to share content.`, error);\n }\n } finally {\n isSharing.set(false);\n }\n };\n\n const canShare = (data?: ShareData): boolean => {\n try {\n return navigator.canShare(data);\n } catch (error) {\n if (ngDevMode) {\n console.warn(`[webShare] Failed to check if content can be shared.`, error);\n }\n return false;\n }\n };\n\n return {\n isSupported,\n isSharing: isSharing.asReadonly(),\n canShare,\n share,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACG,SAAU,QAAQ,C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gBAAA,OAAO,KAAK;YACd;AACF,QAAA,CAAC;QAED,OAAO;YACL,WAAW;AACX,YAAA,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE;YACjC,QAAQ;YACR,KAAK;SACN;AACH,IAAA,CAAC,CAAC;AACJ;;ACnHA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-browser-web-share.mjs","sources":["../../../projects/core/browser/web-share/index.ts","../../../projects/core/browser/web-share/signality-core-browser-web-share.ts"],"sourcesContent":["import { type Signal, signal, untracked } from '@angular/core';\nimport { constSignal, NOOP_ASYNC_FN, setupContext } from '@signality/core/internal';\nimport type { WithInjector } from '@signality/core/types';\n\nexport interface WebShareRef {\n /**\n * Whether the Web Share API is supported in the current browser.\n *\n * @see [Web Share API browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API#browser_compatibility)\n */\n readonly isSupported: Signal<boolean>;\n\n /**\n * Whether the native share dialog is currently open.\n */\n readonly isSharing: Signal<boolean>;\n\n /**\n * Open the native share dialog with the provided data.\n *\n * @see [Navigator: share() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share)\n */\n readonly share: (data: ShareData) => Promise<void>;\n\n /**\n * Check whether the given data can be shared via the Web Share API.\n *\n * @see [Navigator: canShare() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/canShare)\n */\n readonly canShare: (data?: ShareData) => boolean;\n}\n\n/**\n * Signal-based wrapper around the [Web Share API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API).\n *\n * @param options - Optional injector for DI context\n * @returns A WebShareRef with share methods and state signals\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * @if (webShare.isSupported()) {\n * <button (click)=\"shareContent()\" [disabled]=\"webShare.isSharing()\">\n * Share This Page\n * </button>\n * }\n * `\n * })\n * export class WebShareDemo {\n * readonly webShare = webShare();\n *\n * async shareContent() {\n * await this.webShare.share({\n * title: 'Check this out!',\n * url: window.location.href,\n * });\n * }\n * }\n * ```\n */\nexport function webShare(options?: WithInjector): WebShareRef {\n const { runInContext } = setupContext(options?.injector, webShare);\n\n return runInContext(({ isBrowser }) => {\n const isSupported = constSignal(isBrowser && 'share' in navigator);\n\n if (!isSupported()) {\n return {\n isSupported,\n isSharing: constSignal(false),\n canShare: () => false,\n share: NOOP_ASYNC_FN,\n };\n }\n\n const isSharing = signal(false);\n\n const share = async (data: ShareData): Promise<void> => {\n if (untracked(isSharing)) {\n return;\n }\n\n try {\n isSharing.set(true);\n await navigator.share(data);\n } catch (error) {\n // user canceled, or share failed\n // AbortError is expected when a user cancels\n if ((error as Error).name !== 'AbortError') {\n throw error;\n }\n } finally {\n isSharing.set(false);\n }\n };\n\n const canShare = (data?: ShareData): boolean => {\n return navigator.canShare(data);\n };\n\n return {\n isSupported,\n isSharing: isSharing.asReadonly(),\n canShare,\n share,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACG,SAAU,QAAQ,CAAC,OAAsB,EAAA;AAC7C,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAElE,IAAA,OAAO,YAAY,CAAC,CAAC,EAAE,SAAS,EAAE,KAAI;QACpC,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,IAAI,OAAO,IAAI,SAAS,CAAC;AAElE,QAAA,IAAI,CAAC,WAAW,EAAE,EAAE;YAClB,OAAO;gBACL,WAAW;AACX,gBAAA,SAAS,EAAE,WAAW,CAAC,KAAK,CAAC;AAC7B,gBAAA,QAAQ,EAAE,MAAM,KAAK;AACrB,gBAAA,KAAK,EAAE,aAAa;aACrB;QACH;AAEA,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,qDAAC;AAE/B,QAAA,MAAM,KAAK,GAAG,OAAO,IAAe,KAAmB;AACrD,YAAA,IAAI,SAAS,CAAC,SAAS,CAAC,EAAE;gBACxB;YACF;AAEA,YAAA,IAAI;AACF,gBAAA,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;AACnB,gBAAA,MAAM,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;YAC7B;YAAE,OAAO,KAAK,EAAE;;;AAGd,gBAAA,IAAK,KAAe,CAAC,IAAI,KAAK,YAAY,EAAE;AAC1C,oBAAA,MAAM,KAAK;gBACb;YACF;oBAAU;AACR,gBAAA,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC;YACtB;AACF,QAAA,CAAC;AAED,QAAA,MAAM,QAAQ,GAAG,CAAC,IAAgB,KAAa;AAC7C,YAAA,OAAO,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC;AACjC,QAAA,CAAC;QAED,OAAO;YACL,WAAW;AACX,YAAA,SAAS,EAAE,SAAS,CAAC,UAAU,EAAE;YACjC,QAAQ;YACR,KAAK;SACN;AACH,IAAA,CAAC,CAAC;AACJ;;AC5GA;;AAEG;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { signal, untracked, isSignal } from '@angular/core';
2
- import { setupContext, NOOP_FN, constSignal, toValue } from '@signality/core/internal';
2
+ import { setupContext, NOOP_FN, constSignal } from '@signality/core/internal';
3
+ import { toValue } from '@signality/core/utilities';
3
4
  import { watcher } from '@signality/core/reactivity/watcher';
4
5
 
5
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-browser-web-worker.mjs","sources":["../../../projects/core/browser/web-worker/index.ts","../../../projects/core/browser/web-worker/signality-core-browser-web-worker.ts"],"sourcesContent":["import { isSignal, type Signal, signal, untracked } from '@angular/core';\nimport { constSignal, NOOP_FN, setupContext, toValue } from '@signality/core/internal';\nimport type { MaybeSignal, WithInjector } from '@signality/core/types';\nimport { watcher } from '@signality/core/reactivity/watcher';\n\nexport interface WebWorkerOptions extends WithInjector {\n /**\n * Worker script type.\n *\n * @default 'classic'\n * @see [Worker: Worker() constructor — type on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#type)\n */\n readonly type?: 'classic' | 'module';\n\n /**\n * Credentials mode used when fetching the worker script.\n *\n * @see [Worker: Worker() constructor — credentials on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#credentials)\n */\n readonly credentials?: RequestCredentials;\n\n /**\n * Identifying name for the worker, useful for debugging in DevTools.\n *\n * @see [Worker: Worker() constructor — name on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#name)\n */\n readonly name?: string;\n}\n\nexport interface WebWorkerRef<I, O> {\n /**\n * The last message received from the worker via `postMessage`.\n * `undefined` until the first message is received.\n */\n readonly data: Signal<O | undefined>;\n\n /**\n * Whether the worker has been successfully created and is ready to receive messages.\n */\n readonly isReady: Signal<boolean>;\n\n /**\n * The last error emitted by the worker, or `null` if no error has occurred.\n */\n readonly error: Signal<Error | null>;\n\n /**\n * Send a message to the worker.\n *\n * @see [Worker.postMessage() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage)\n */\n readonly post: (data: I) => void;\n\n /**\n * Terminate the worker immediately, discarding any pending messages.\n *\n * @see [Worker.terminate() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate)\n */\n readonly terminate: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Web Workers API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).\n * Run scripts in background threads without blocking the main thread.\n *\n * When `url` is a signal, the worker is automatically recreated whenever the URL changes.\n *\n * @param url - Worker script URL (static or reactive signal)\n * @param options - Optional configuration\n * @returns A WebWorkerRef with data signal and control methods\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <button (click)=\"worker.post(42)\">Calculate</button>\n * @if (worker.data()) {\n * <p>Result: {{ worker.data() }}</p>\n * }\n * `\n * })\n * export class WorkerDemo {\n * readonly worker = webWorker<number, number>('/workers/calc.js');\n * }\n * ```\n */\nexport function webWorker<I, O>(\n url: MaybeSignal<string | URL>,\n options?: WebWorkerOptions\n): WebWorkerRef<I, O> {\n const { runInContext } = setupContext(options?.injector, webWorker);\n\n return runInContext(({ isServer, onCleanup }) => {\n if (isServer) {\n return {\n data: constSignal(undefined),\n isReady: constSignal(false),\n error: constSignal(null),\n post: NOOP_FN,\n terminate: NOOP_FN,\n };\n }\n\n const type = options?.type ?? 'classic';\n const credentials = options?.credentials;\n const name = options?.name;\n\n const data = signal<O | undefined>(undefined);\n const isReady = signal(false);\n const error = signal<Error | null>(null);\n\n let worker: Worker | null = null;\n\n const createWorker = (workerUrl: string | URL) => {\n if (worker) {\n worker.terminate();\n }\n\n try {\n worker = new Worker(workerUrl, { type, credentials, name });\n\n worker.onmessage = (event: MessageEvent<O>) => {\n data.set(event.data);\n };\n\n worker.onerror = (event: ErrorEvent) => {\n error.set(new Error(event.message));\n };\n\n worker.onmessageerror = () => {\n error.set(new Error('Message deserialization error'));\n };\n\n isReady.set(true);\n } catch (e) {\n error.set(e as Error);\n isReady.set(false);\n }\n };\n\n const post = (message: I) => {\n if (worker && untracked(isReady)) {\n try {\n worker.postMessage(message);\n } catch (e) {\n error.set(e as Error);\n }\n }\n };\n\n const terminate = () => {\n if (worker) {\n worker.terminate();\n worker = null;\n isReady.set(false);\n }\n };\n\n if (isSignal(url)) {\n watcher(url, createWorker);\n }\n\n onCleanup(terminate);\n\n createWorker(toValue(url));\n\n return {\n data: data.asReadonly(),\n isReady: isReady.asReadonly(),\n error: error.asReadonly(),\n post,\n terminate,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AA6DA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,SAAU,SAAS,CACvB,GAA8B,EAC9B,OAA0B,EAAA;AAE1B,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC;IAEnE,OAAO,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAA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,CAAC,+BAA+B,CAAC,CAAC;AACvD,gBAAA,CAAC;AAED,gBAAA,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;YACnB;YAAE,OAAO,CAAC,EAAE;AACV,gBAAA,KAAK,CAAC,GAAG,CAAC,CAAU,CAAC;AACrB,gBAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;YACpB;AACF,QAAA,CAAC;AAED,QAAA,MAAM,IAAI,GAAG,CAAC,OAAU,KAAI;AAC1B,YAAA,IAAI,MAAM,IAAI,SAAS,CAAC,OAAO,CAAC,EAAE;AAChC,gBAAA,IAAI;AACF,oBAAA,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;gBAC7B;gBAAE,OAAO,CAAC,EAAE;AACV,oBAAA,KAAK,CAAC,GAAG,CAAC,CAAU,CAAC;gBACvB;YACF;AACF,QAAA,CAAC;QAED,MAAM,SAAS,GAAG,MAAK;YACrB,IAAI,MAAM,EAAE;gBACV,MAAM,CAAC,SAAS,EAAE;gBAClB,MAAM,GAAG,IAAI;AACb,gBAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;YACpB;AACF,QAAA,CAAC;AAED,QAAA,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE;AACjB,YAAA,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC;QAC5B;QAEA,SAAS,CAAC,SAAS,CAAC;AAEpB,QAAA,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAE1B,OAAO;AACL,YAAA,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE;AACvB,YAAA,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;AAC7B,YAAA,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE;YACzB,IAAI;YACJ,SAAS;SACV;AACH,IAAA,CAAC,CAAC;AACJ;;AC9KA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-browser-web-worker.mjs","sources":["../../../projects/core/browser/web-worker/index.ts","../../../projects/core/browser/web-worker/signality-core-browser-web-worker.ts"],"sourcesContent":["import { isSignal, type Signal, signal, untracked } from '@angular/core';\nimport { constSignal, NOOP_FN, setupContext } from '@signality/core/internal';\nimport { toValue } from '@signality/core/utilities';\nimport type { MaybeSignal, WithInjector } from '@signality/core/types';\nimport { watcher } from '@signality/core/reactivity/watcher';\n\nexport interface WebWorkerOptions extends WithInjector {\n /**\n * Worker script type.\n *\n * @default 'classic'\n * @see [Worker: Worker() constructor — type on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#type)\n */\n readonly type?: 'classic' | 'module';\n\n /**\n * Credentials mode used when fetching the worker script.\n *\n * @see [Worker: Worker() constructor — credentials on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#credentials)\n */\n readonly credentials?: RequestCredentials;\n\n /**\n * Identifying name for the worker, useful for debugging in DevTools.\n *\n * @see [Worker: Worker() constructor — name on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#name)\n */\n readonly name?: string;\n}\n\nexport interface WebWorkerRef<I, O> {\n /**\n * The last message received from the worker via `postMessage`.\n * `undefined` until the first message is received.\n */\n readonly data: Signal<O | undefined>;\n\n /**\n * Whether the worker has been successfully created and is ready to receive messages.\n */\n readonly isReady: Signal<boolean>;\n\n /**\n * The last error emitted by the worker, or `null` if no error has occurred.\n */\n readonly error: Signal<Error | null>;\n\n /**\n * Send a message to the worker.\n *\n * @see [Worker.postMessage() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage)\n */\n readonly post: (data: I) => void;\n\n /**\n * Terminate the worker immediately, discarding any pending messages.\n *\n * @see [Worker.terminate() on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Worker/terminate)\n */\n readonly terminate: () => void;\n}\n\n/**\n * Signal-based wrapper around the [Web Workers API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).\n * Run scripts in background threads without blocking the main thread.\n *\n * When `url` is a signal, the worker is automatically recreated whenever the URL changes.\n *\n * @param url - Worker script URL (static or reactive signal)\n * @param options - Optional configuration\n * @returns A WebWorkerRef with data signal and control methods\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <button (click)=\"worker.post(42)\">Calculate</button>\n * @if (worker.data()) {\n * <p>Result: {{ worker.data() }}</p>\n * }\n * `\n * })\n * export class WorkerDemo {\n * readonly worker = webWorker<number, number>('/workers/calc.js');\n * }\n * ```\n */\nexport function webWorker<I, O>(\n url: MaybeSignal<string | URL>,\n options?: WebWorkerOptions\n): WebWorkerRef<I, O> {\n const { runInContext } = setupContext(options?.injector, webWorker);\n\n return runInContext(({ isServer, onCleanup }) => {\n if (isServer) {\n return {\n data: constSignal(undefined),\n isReady: constSignal(false),\n error: constSignal(null),\n post: NOOP_FN,\n terminate: NOOP_FN,\n };\n }\n\n const type = options?.type ?? 'classic';\n const credentials = options?.credentials;\n const name = options?.name;\n\n const data = signal<O | undefined>(undefined);\n const isReady = signal(false);\n const error = signal<Error | null>(null);\n\n let worker: Worker | null = null;\n\n const createWorker = (workerUrl: string | URL) => {\n if (worker) {\n worker.terminate();\n }\n\n try {\n worker = new Worker(workerUrl, { type, credentials, name });\n\n worker.onmessage = (event: MessageEvent<O>) => {\n data.set(event.data);\n };\n\n worker.onerror = (event: ErrorEvent) => {\n error.set(new Error(event.message));\n };\n\n worker.onmessageerror = () => {\n error.set(new Error('Message deserialization error'));\n };\n\n isReady.set(true);\n } catch (e) {\n error.set(e as Error);\n isReady.set(false);\n }\n };\n\n const post = (message: I) => {\n if (worker && untracked(isReady)) {\n try {\n worker.postMessage(message);\n } catch (e) {\n error.set(e as Error);\n }\n }\n };\n\n const terminate = () => {\n if (worker) {\n worker.terminate();\n worker = null;\n isReady.set(false);\n }\n };\n\n if (isSignal(url)) {\n watcher(url, createWorker);\n }\n\n onCleanup(terminate);\n\n createWorker(toValue(url));\n\n return {\n data: data.asReadonly(),\n isReady: isReady.asReadonly(),\n error: error.asReadonly(),\n post,\n terminate,\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */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AC,UAAU,EAAE;AACvB,YAAA,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;AAC7B,YAAA,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE;YACzB,IAAI;YACJ,SAAS;SACV;AACH,IAAA,CAAC,CAAC;AACJ;;AC/KA;;AAEG;;;;"}
@@ -4,6 +4,7 @@ export * from '@signality/core/browser/breakpoints';
4
4
  export * from '@signality/core/browser/broadcast-channel';
5
5
  export * from '@signality/core/browser/browser-language';
6
6
  export * from '@signality/core/browser/clipboard';
7
+ export * from '@signality/core/browser/device-pixel-ratio';
7
8
  export * from '@signality/core/browser/device-posture';
8
9
  export * from '@signality/core/browser/display-media';
9
10
  export * from '@signality/core/browser/eye-dropper';
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-browser.mjs","sources":["../../../projects/core/browser/signality-core-browser.ts"],"sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEG"}
1
+ {"version":3,"file":"signality-core-browser.mjs","sources":["../../../projects/core/browser/signality-core-browser.ts"],"sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEG"}
@@ -1,5 +1,6 @@
1
1
  import { signal, isSignal } from '@angular/core';
2
- import { setupContext, constSignal, toValue, isAcceptedFile, toElement, isNodeWithin } from '@signality/core/internal';
2
+ import { setupContext, constSignal, isAcceptedFile, isNodeWithin } from '@signality/core/internal';
3
+ import { toValue, toElement } from '@signality/core/utilities';
3
4
  import { listener } from '@signality/core/browser/listener';
4
5
  import { onDisconnect } from '@signality/core/elements/on-disconnect';
5
6
  import { watcher } from '@signality/core/reactivity/watcher';
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-elements-dropzone.mjs","sources":["../../../projects/core/elements/dropzone/index.ts","../../../projects/core/elements/dropzone/signality-core-elements-dropzone.ts"],"sourcesContent":["import { isSignal, type Signal, signal, type WritableSignal } from '@angular/core';\nimport {\n constSignal,\n isAcceptedFile,\n isNodeWithin,\n setupContext,\n toElement,\n toValue,\n} from '@signality/core/internal';\nimport type { MaybeElementSignal, MaybeSignal, WithInjector } from '@signality/core/types';\nimport { listener } from '@signality/core/browser/listener';\nimport { onDisconnect } from '@signality/core/elements/on-disconnect';\nimport { watcher } from '@signality/core/reactivity/watcher';\n\nexport interface DropzoneOptions extends WithInjector {\n /**\n * Comma-separated list of accepted file types, matching the native HTML\n * [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept) attribute format.\n * Supports MIME types (`'image/png'`), wildcards (`'image/*'`), and file extensions (`'.pdf'`).\n * Use `'*'` to accept all file types.\n *\n * @default '*'\n * @see [accept attribute on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept)\n */\n readonly accept?: MaybeSignal<string>;\n\n /**\n * Whether to allow dropping multiple files at once.\n * When `false`, only the first accepted file is kept.\n *\n * @default true\n */\n readonly multiple?: MaybeSignal<boolean>;\n\n /**\n * When `true`, prevents files from being dropped anywhere outside the drop zone\n * by intercepting `dragover` and `drop` events on the document.\n *\n * @default true\n */\n readonly preventDocumentDrop?: boolean;\n\n /**\n * Custom validation predicate called for each dropped file.\n * Return `true` to keep the file, `false` to reject it.\n *\n * When provided, the `accept` option is ignored — the validator\n * takes full responsibility for deciding which files are valid.\n *\n * @example\n * ```typescript\n * dropzone(target, {\n * validator: (file) => file.size <= 5 * 1024 * 1024, // max 5 MB\n * });\n * ```\n */\n readonly validator?: (file: File) => boolean;\n\n /**\n * Callback invoked with files that were rejected during a drop.\n * Called once per drop with the full array of rejected files.\n * Useful for showing toast notifications or validation errors.\n *\n * @example\n * ```typescript\n * dropzone(target, {\n * accept: 'image/*',\n * onReject: (rejected) => {\n * rejected.forEach(f => toast.error(`${f.name} is not an image`));\n * },\n * });\n * ```\n */\n readonly onReject?: (files: File[]) => void;\n}\n\nexport interface DropzoneRef {\n /**\n * List of files dropped onto the zone, filtered by `accept` and `multiple`.\n * A `WritableSignal` — can be reset externally (e.g. after upload).\n *\n * @see [DataTransfer.files on MDN](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/files)\n */\n readonly files: WritableSignal<File[]>;\n\n /**\n * Whether the user is currently dragging over the drop zone.\n */\n readonly isOver: Signal<boolean>;\n\n /**\n * Whether any drag operation is in progress anywhere on the document.\n * Useful for showing a global drop overlay.\n */\n readonly isDragging: Signal<boolean>;\n}\n\n/**\n * Signal-based wrapper around the [HTML Drag and Drop API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API).\n *\n * @param target - Drop zone element\n * @param options - Optional configuration\n * @returns An object with isOver, files, data, and isDragging signals\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <div\n * #zone\n * [class.over]=\"drop.isOver()\"\n * [class.dragging]=\"drop.isDragging()\"\n * >\n * Drop files here\n * @if (drop.files().length > 0) {\n * <ul>\n * @for (file of drop.files(); track file.name) {\n * <li>{{ file.name }} ({{ file.size }} bytes)</li>\n * }\n * </ul>\n * }\n * </div>\n * `\n * })\n * export class DropzoneDemo {\n * readonly zone = viewChild<ElementRef>('zone');\n * readonly drop = dropzone(this.zone, { accept: 'image/*', multiple: true });\n * }\n * ```\n */\nexport function dropzone(\n target: MaybeElementSignal<HTMLElement>,\n options?: DropzoneOptions\n): DropzoneRef {\n const { runInContext } = setupContext(options?.injector, dropzone);\n\n return runInContext(({ isServer }) => {\n if (isServer) {\n return {\n files: signal([]),\n isOver: constSignal(false),\n isDragging: constSignal(false),\n };\n }\n\n const accept = options?.accept ?? '*';\n const multiple = options?.multiple ?? true;\n const preventDocumentDrop = options?.preventDocumentDrop ?? true;\n const validatorFn = options?.validator;\n const onReject = options?.onReject;\n\n const files = signal<File[]>([]);\n const isOver = signal(false);\n const isDragging = signal(false);\n\n let dragCounter = 0;\n\n const processFiles = (files: File[]): File[] => {\n const accepted: File[] = [];\n const rejected: File[] = [];\n const acceptValue = toValue(accept);\n const multipleValue = toValue(multiple);\n\n const isAccepted = validatorFn\n ? validatorFn\n : (file: File) => isAcceptedFile(file, acceptValue);\n\n for (const file of files) {\n if (isAccepted(file)) {\n accepted.push(file);\n if (!multipleValue) {\n break;\n }\n } else {\n rejected.push(file);\n }\n }\n\n if (onReject && rejected.length > 0) {\n onReject(rejected);\n }\n\n return accepted;\n };\n\n listener.prevent.capture(target, 'dragenter', () => {\n dragCounter++;\n isOver.set(true);\n });\n\n listener.prevent.capture(target, 'dragleave', () => {\n dragCounter--;\n if (dragCounter === 0) {\n isOver.set(false);\n }\n });\n\n listener.prevent.capture(target, 'dragover', (e: DragEvent) => {\n if (e.dataTransfer) {\n e.dataTransfer.dropEffect = 'copy';\n }\n });\n\n listener.prevent.stop.capture(target, 'drop', (e: DragEvent) => {\n dragCounter = 0;\n isOver.set(false);\n isDragging.set(false);\n\n if (e.dataTransfer && e.dataTransfer.files.length > 0) {\n const arr = Array.from(e.dataTransfer.files);\n files.set(processFiles(arr));\n }\n });\n\n listener.capture(document, 'dragenter', () => {\n isDragging.set(true);\n });\n\n listener.capture(document, 'dragleave', (e: DragEvent) => {\n if (e.relatedTarget === null) {\n isDragging.set(false);\n }\n });\n\n listener.capture(document, 'drop', () => {\n isDragging.set(false);\n });\n\n if (preventDocumentDrop) {\n listener.capture(document, 'dragover', (e: DragEvent) => {\n const el = toElement(target);\n\n if (el && !isNodeWithin(e.target as Node, el)) {\n e.preventDefault();\n if (e.dataTransfer) {\n e.dataTransfer.dropEffect = 'none';\n }\n }\n });\n\n listener.capture(document, 'drop', (e: DragEvent) => {\n const el = toElement(target);\n\n if (el && !isNodeWithin(e.target as Node, el)) {\n e.preventDefault();\n }\n });\n }\n\n const filters = [accept, multiple].filter(isSignal) as Signal<any>[];\n\n if (filters.length) {\n watcher(filters, () => files.update(processFiles));\n }\n\n onDisconnect(target, () => {\n files.set([]);\n isOver.set(false);\n isDragging.set(false);\n });\n\n return {\n files,\n isOver: isOver.asReadonly(),\n isDragging: isDragging.asReadonly(),\n };\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAiGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCG;AACG,SAAU,QAAQ,CACtB,MAAuC,EACvC,OAAyB,EAAA;AAEzB,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAElE,IAAA,OAAO,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAI;QACnC,IAAI,QAAQ,EAAE;YACZ,OAAO;AACL,gBAAA,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;AACjB,gBAAA,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC;AAC1B,gBAAA,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC;aAC/B;QACH;AAEA,QAAA,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,GAAG;AACrC,QAAA,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,IAAI;AAC1C,QAAA,MAAM,mBAAmB,GAAG,OAAO,EAAE,mBAAmB,IAAI,IAAI;AAChE,QAAA,MAAM,WAAW,GAAG,OAAO,EAAE,SAAS;AACtC,QAAA,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ;AAElC,QAAA,MAAM,KAAK,GAAG,MAAM,CAAS,EAAE,iDAAC;AAChC,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,kDAAC;AAC5B,QAAA,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,sDAAC;QAEhC,IAAI,WAAW,GAAG,CAAC;AAEnB,QAAA,MAAM,YAAY,GAAG,CAAC,KAAa,KAAY;YAC7C,MAAM,QAAQ,GAAW,EAAE;YAC3B,MAAM,QAAQ,GAAW,EAAE;AAC3B,YAAA,MAAM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,CAAC,cAAc,EAAE;AAClB,oBAAA,IAAI,CAAC,CAAC,YAAY,EAAE;AAClB,wBAAA,CAAC,CAAC,YAAY,CAAC,UAAU,GAAG,MAAM;oBACpC;gBACF;AACF,YAAA,CAAC,CAAC;YAEF,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAY,KAAI;AAClD,gBAAA,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC;AAE5B,gBAAA,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,EAAE;oBAC7C,CAAC,CAAC,cAAc,EAAE;gBACpB;AACF,YAAA,CAAC,CAAC;QACJ;AAEA,QAAA,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAkB;AAEpE,QAAA,IAAI,OAAO,CAAC,MAAM,EAAE;AAClB,YAAA,OAAO,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACpD;AAEA,QAAA,YAAY,CAAC,MAAM,EAAE,MAAK;AACxB,YAAA,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;AACb,YAAA,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;AACjB,YAAA,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;AACvB,QAAA,CAAC,CAAC;QAEF,OAAO;YACL,KAAK;AACL,YAAA,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE;AAC3B,YAAA,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE;SACpC;AACH,IAAA,CAAC,CAAC;AACJ;;AC3QA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-elements-dropzone.mjs","sources":["../../../projects/core/elements/dropzone/index.ts","../../../projects/core/elements/dropzone/signality-core-elements-dropzone.ts"],"sourcesContent":["import { isSignal, type Signal, signal, type WritableSignal } from '@angular/core';\nimport { constSignal, isAcceptedFile, isNodeWithin, setupContext } from '@signality/core/internal';\nimport { toElement, toValue } from '@signality/core/utilities';\nimport type { MaybeElementSignal, MaybeSignal, WithInjector } from '@signality/core/types';\nimport { listener } from '@signality/core/browser/listener';\nimport { onDisconnect } from '@signality/core/elements/on-disconnect';\nimport { watcher } from '@signality/core/reactivity/watcher';\n\nexport interface DropzoneOptions extends WithInjector {\n /**\n * Comma-separated list of accepted file types, matching the native HTML\n * [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept) attribute format.\n * Supports MIME types (`'image/png'`), wildcards (`'image/*'`), and file extensions (`'.pdf'`).\n * Use `'*'` to accept all file types.\n *\n * @default '*'\n * @see [accept attribute on MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept)\n */\n readonly accept?: MaybeSignal<string>;\n\n /**\n * Whether to allow dropping multiple files at once.\n * When `false`, only the first accepted file is kept.\n *\n * @default true\n */\n readonly multiple?: MaybeSignal<boolean>;\n\n /**\n * When `true`, prevents files from being dropped anywhere outside the drop zone\n * by intercepting `dragover` and `drop` events on the document.\n *\n * @default true\n */\n readonly preventDocumentDrop?: boolean;\n\n /**\n * Custom validation predicate called for each dropped file.\n * Return `true` to keep the file, `false` to reject it.\n *\n * When provided, the `accept` option is ignored — the validator\n * takes full responsibility for deciding which files are valid.\n *\n * @example\n * ```typescript\n * dropzone(target, {\n * validator: (file) => file.size <= 5 * 1024 * 1024, // max 5 MB\n * });\n * ```\n */\n readonly validator?: (file: File) => boolean;\n\n /**\n * Callback invoked with files that were rejected during a drop.\n * Called once per drop with the full array of rejected files.\n * Useful for showing toast notifications or validation errors.\n *\n * @example\n * ```typescript\n * dropzone(target, {\n * accept: 'image/*',\n * onReject: (rejected) => {\n * rejected.forEach(f => toast.error(`${f.name} is not an image`));\n * },\n * });\n * ```\n */\n readonly onReject?: (files: File[]) => void;\n}\n\nexport interface DropzoneRef {\n /**\n * List of files dropped onto the zone, filtered by `accept` and `multiple`.\n * A `WritableSignal` — can be reset externally (e.g. after upload).\n *\n * @see [DataTransfer.files on MDN](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/files)\n */\n readonly files: WritableSignal<File[]>;\n\n /**\n * Whether the user is currently dragging over the drop zone.\n */\n readonly isOver: Signal<boolean>;\n\n /**\n * Whether any drag operation is in progress anywhere on the document.\n * Useful for showing a global drop overlay.\n */\n readonly isDragging: Signal<boolean>;\n}\n\n/**\n * Signal-based wrapper around the [HTML Drag and Drop API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API).\n *\n * @param target - Drop zone element\n * @param options - Optional configuration\n * @returns An object with isOver, files, data, and isDragging signals\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <div\n * #zone\n * [class.over]=\"drop.isOver()\"\n * [class.dragging]=\"drop.isDragging()\"\n * >\n * Drop files here\n * @if (drop.files().length > 0) {\n * <ul>\n * @for (file of drop.files(); track file.name) {\n * <li>{{ file.name }} ({{ file.size }} bytes)</li>\n * }\n * </ul>\n * }\n * </div>\n * `\n * })\n * export class DropzoneDemo {\n * readonly zone = viewChild<ElementRef>('zone');\n * readonly drop = dropzone(this.zone, { accept: 'image/*', multiple: true });\n * }\n * ```\n */\nexport function dropzone(\n target: MaybeElementSignal<HTMLElement>,\n options?: DropzoneOptions\n): DropzoneRef {\n const { runInContext } = setupContext(options?.injector, dropzone);\n\n return runInContext(({ isServer }) => {\n if (isServer) {\n return {\n files: signal([]),\n isOver: constSignal(false),\n isDragging: constSignal(false),\n };\n }\n\n const accept = options?.accept ?? '*';\n const multiple = options?.multiple ?? true;\n const preventDocumentDrop = options?.preventDocumentDrop ?? true;\n const validatorFn = options?.validator;\n const onReject = options?.onReject;\n\n const files = signal<File[]>([]);\n const isOver = signal(false);\n const isDragging = signal(false);\n\n let dragCounter = 0;\n\n const processFiles = (files: File[]): File[] => {\n const accepted: File[] = [];\n const rejected: File[] = [];\n const acceptValue = toValue(accept);\n const multipleValue = toValue(multiple);\n\n const isAccepted = validatorFn\n ? validatorFn\n : (file: File) => isAcceptedFile(file, acceptValue);\n\n for (const file of files) {\n if (isAccepted(file)) {\n accepted.push(file);\n if (!multipleValue) {\n break;\n }\n } else {\n rejected.push(file);\n }\n }\n\n if (onReject && rejected.length > 0) {\n onReject(rejected);\n }\n\n return accepted;\n };\n\n listener.prevent.capture(target, 'dragenter', () => {\n dragCounter++;\n isOver.set(true);\n });\n\n listener.prevent.capture(target, 'dragleave', () => {\n dragCounter--;\n if (dragCounter === 0) {\n isOver.set(false);\n }\n });\n\n listener.prevent.capture(target, 'dragover', (e: DragEvent) => {\n if (e.dataTransfer) {\n e.dataTransfer.dropEffect = 'copy';\n }\n });\n\n listener.prevent.stop.capture(target, 'drop', (e: DragEvent) => {\n dragCounter = 0;\n isOver.set(false);\n isDragging.set(false);\n\n if (e.dataTransfer && e.dataTransfer.files.length > 0) {\n const arr = Array.from(e.dataTransfer.files);\n files.set(processFiles(arr));\n }\n });\n\n listener.capture(document, 'dragenter', () => {\n isDragging.set(true);\n });\n\n listener.capture(document, 'dragleave', (e: DragEvent) => {\n if (e.relatedTarget === null) {\n isDragging.set(false);\n }\n });\n\n listener.capture(document, 'drop', () => {\n isDragging.set(false);\n });\n\n if (preventDocumentDrop) {\n listener.capture(document, 'dragover', (e: DragEvent) => {\n const el = toElement(target);\n\n if (el && !isNodeWithin(e.target as Node, el)) {\n e.preventDefault();\n if (e.dataTransfer) {\n e.dataTransfer.dropEffect = 'none';\n }\n }\n });\n\n listener.capture(document, 'drop', (e: DragEvent) => {\n const el = toElement(target);\n\n if (el && !isNodeWithin(e.target as Node, el)) {\n e.preventDefault();\n }\n });\n }\n\n const filters = [accept, multiple].filter(isSignal) as Signal<any>[];\n\n if (filters.length) {\n watcher(filters, () => files.update(processFiles));\n }\n\n onDisconnect(target, () => {\n files.set([]);\n isOver.set(false);\n isDragging.set(false);\n });\n\n return {\n files,\n isOver: isOver.asReadonly(),\n isDragging: isDragging.asReadonly(),\n };\n });\n}\n","/**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AC,UAAU,GAAG,MAAM;oBACpC;gBACF;AACF,YAAA,CAAC,CAAC;YAEF,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAY,KAAI;AAClD,gBAAA,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC;AAE5B,gBAAA,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,EAAE;oBAC7C,CAAC,CAAC,cAAc,EAAE;gBACpB;AACF,YAAA,CAAC,CAAC;QACJ;AAEA,QAAA,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAkB;AAEpE,QAAA,IAAI,OAAO,CAAC,MAAM,EAAE;AAClB,YAAA,OAAO,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QACpD;AAEA,QAAA,YAAY,CAAC,MAAM,EAAE,MAAK;AACxB,YAAA,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;AACb,YAAA,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC;AACjB,YAAA,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;AACvB,QAAA,CAAC,CAAC;QAEF,OAAO;YACL,KAAK;AACL,YAAA,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE;AAC3B,YAAA,UAAU,EAAE,UAAU,CAAC,UAAU,EAAE;SACpC;AACH,IAAA,CAAC,CAAC;AACJ;;ACrQA;;AAEG;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { signal } from '@angular/core';
2
- import { setupContext, constSignal, toElement } from '@signality/core/internal';
2
+ import { setupContext, constSignal } from '@signality/core/internal';
3
+ import { toElement } from '@signality/core/utilities';
3
4
  import { listener } from '@signality/core/browser/listener';
4
5
  import { onDisconnect } from '@signality/core/elements/on-disconnect';
5
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"signality-core-elements-element-focus-within.mjs","sources":["../../../projects/core/elements/element-focus-within/index.ts","../../../projects/core/elements/element-focus-within/signality-core-elements-element-focus-within.ts"],"sourcesContent":["import { type CreateSignalOptions, signal, type Signal } from '@angular/core';\nimport { constSignal, setupContext, toElement } from '@signality/core/internal';\nimport type { MaybeElementSignal, WithInjector } from '@signality/core/types';\nimport { listener } from '@signality/core/browser/listener';\nimport { onDisconnect } from '@signality/core/elements/on-disconnect';\n\nexport type ElementFocusWithinOptions = CreateSignalOptions<boolean> & WithInjector;\n\n/**\n * Reactive tracking of focus-within state on an element.\n * Detects when focus is inside an element or any of its descendants,\n * analogous to the CSS `:focus-within` pseudo-class.\n *\n * @param target - The element to track focus-within state on\n * @param options - Optional configuration including signal options and injector\n * @returns A signal that is `true` when focus is within the element\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <div #container [class.focused]=\"isFocusedWithin()\">\n * <input placeholder=\"First\" />\n * <input placeholder=\"Second\" />\n * </div>\n * `\n * })\n * export class FocusWithinDemo {\n * readonly container = viewChild<ElementRef>('container');\n * readonly isFocusedWithin = elementFocusWithin(this.container);\n * }\n * ```\n */\nexport function elementFocusWithin(\n target: MaybeElementSignal<HTMLElement>,\n options?: ElementFocusWithinOptions\n): Signal<boolean> {\n const { runInContext } = setupContext(options?.injector, elementFocusWithin);\n\n return runInContext(({ isServer }) => {\n if (isServer) {\n return constSignal(false);\n }\n\n const focused = signal<boolean>(false, options);\n\n listener(target, 'focusin', () => focused.set(true));\n\n listener(target, 'focusout', e => {\n const el = toElement(target);\n\n if (el && e.relatedTarget instanceof Node && el.contains(e.relatedTarget)) {\n return;\n }\n\n focused.set(false);\n });\n\n onDisconnect(target, () => focused.set(false));\n\n return focused.asReadonly();\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,SAAU,kBAAkB,CAChC,MAAuC,EACvC,OAAmC,EAAA;AAEnC,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,CAAC;AAE5E,IAAA,OAAO,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAI;QACnC,IAAI,QAAQ,EAAE;AACZ,YAAA,OAAO,WAAW,CAAC,KAAK,CAAC;QAC3B;QAEA,MAAM,OAAO,GAAG,MAAM,CAAU,KAAK,EAAE,OAAO,CAAC;AAE/C,QAAA,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAEpD,QAAA,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,IAAG;AAC/B,YAAA,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC;AAE5B,YAAA,IAAI,EAAE,IAAI,CAAC,CAAC,aAAa,YAAY,IAAI,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE;gBACzE;YACF;AAEA,YAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;AACpB,QAAA,CAAC,CAAC;AAEF,QAAA,YAAY,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAE9C,QAAA,OAAO,OAAO,CAAC,UAAU,EAAE;AAC7B,IAAA,CAAC,CAAC;AACJ;;AC9DA;;AAEG;;;;"}
1
+ {"version":3,"file":"signality-core-elements-element-focus-within.mjs","sources":["../../../projects/core/elements/element-focus-within/index.ts","../../../projects/core/elements/element-focus-within/signality-core-elements-element-focus-within.ts"],"sourcesContent":["import { type CreateSignalOptions, signal, type Signal } from '@angular/core';\nimport { constSignal, setupContext } from '@signality/core/internal';\nimport { toElement } from '@signality/core/utilities';\nimport type { MaybeElementSignal, WithInjector } from '@signality/core/types';\nimport { listener } from '@signality/core/browser/listener';\nimport { onDisconnect } from '@signality/core/elements/on-disconnect';\n\nexport type ElementFocusWithinOptions = CreateSignalOptions<boolean> & WithInjector;\n\n/**\n * Reactive tracking of focus-within state on an element.\n * Detects when focus is inside an element or any of its descendants,\n * analogous to the CSS `:focus-within` pseudo-class.\n *\n * @param target - The element to track focus-within state on\n * @param options - Optional configuration including signal options and injector\n * @returns A signal that is `true` when focus is within the element\n *\n * @example\n * ```typescript\n * @Component({\n * template: `\n * <div #container [class.focused]=\"isFocusedWithin()\">\n * <input placeholder=\"First\" />\n * <input placeholder=\"Second\" />\n * </div>\n * `\n * })\n * export class FocusWithinDemo {\n * readonly container = viewChild<ElementRef>('container');\n * readonly isFocusedWithin = elementFocusWithin(this.container);\n * }\n * ```\n */\nexport function elementFocusWithin(\n target: MaybeElementSignal<HTMLElement>,\n options?: ElementFocusWithinOptions\n): Signal<boolean> {\n const { runInContext } = setupContext(options?.injector, elementFocusWithin);\n\n return runInContext(({ isServer }) => {\n if (isServer) {\n return constSignal(false);\n }\n\n const focused = signal<boolean>(false, options);\n\n listener(target, 'focusin', () => focused.set(true));\n\n listener(target, 'focusout', e => {\n const el = toElement(target);\n\n if (el && e.relatedTarget instanceof Node && el.contains(e.relatedTarget)) {\n return;\n }\n\n focused.set(false);\n });\n\n onDisconnect(target, () => focused.set(false));\n\n return focused.asReadonly();\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AASA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG,SAAU,kBAAkB,CAChC,MAAuC,EACvC,OAAmC,EAAA;AAEnC,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,kBAAkB,CAAC;AAE5E,IAAA,OAAO,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAI;QACnC,IAAI,QAAQ,EAAE;AACZ,YAAA,OAAO,WAAW,CAAC,KAAK,CAAC;QAC3B;QAEA,MAAM,OAAO,GAAG,MAAM,CAAU,KAAK,EAAE,OAAO,CAAC;AAE/C,QAAA,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAEpD,QAAA,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,IAAG;AAC/B,YAAA,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC;AAE5B,YAAA,IAAI,EAAE,IAAI,CAAC,CAAC,aAAa,YAAY,IAAI,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE;gBACzE;YACF;AAEA,YAAA,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;AACpB,QAAA,CAAC,CAAC;AAEF,QAAA,YAAY,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAE9C,QAAA,OAAO,OAAO,CAAC,UAAU,EAAE;AAC7B,IAAA,CAAC,CAAC;AACJ;;AC/DA;;AAEG;;;;"}
@@ -1,5 +1,6 @@
1
1
  import { signal } from '@angular/core';
2
- import { setupContext, proxySignal, toElement } from '@signality/core/internal';
2
+ import { setupContext, proxySignal } from '@signality/core/internal';
3
+ import { toElement } from '@signality/core/utilities';
3
4
  import { listener } from '@signality/core/browser/listener';
4
5
  import { onDisconnect } from '@signality/core/elements/on-disconnect';
5
6