@ng-native/web 0.0.1 → 0.1.1

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -1
  3. package/dist/browser-engine.d.ts +146 -0
  4. package/dist/browser-engine.js +585 -0
  5. package/dist/browser-engine.js.map +1 -0
  6. package/dist/browser-renderer.d.ts +87 -0
  7. package/dist/browser-renderer.js +295 -0
  8. package/dist/browser-renderer.js.map +1 -0
  9. package/dist/css-units.d.ts +9 -0
  10. package/dist/css-units.js +98 -0
  11. package/dist/css-units.js.map +1 -0
  12. package/dist/device-sources.d.ts +53 -0
  13. package/dist/device-sources.js +96 -0
  14. package/dist/device-sources.js.map +1 -0
  15. package/dist/dom-node.d.ts +63 -0
  16. package/dist/dom-node.js +103 -0
  17. package/dist/dom-node.js.map +1 -0
  18. package/dist/elements.d.ts +79 -0
  19. package/dist/elements.js +53 -0
  20. package/dist/elements.js.map +1 -0
  21. package/dist/index.d.ts +17 -0
  22. package/dist/index.js +18 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/island.d.ts +46 -0
  25. package/dist/island.js +109 -0
  26. package/dist/island.js.map +1 -0
  27. package/dist/jsdom-env.d.ts +4 -0
  28. package/dist/jsdom-env.js +67 -0
  29. package/dist/jsdom-env.js.map +1 -0
  30. package/dist/mount.d.ts +88 -0
  31. package/dist/mount.js +240 -0
  32. package/dist/mount.js.map +1 -0
  33. package/dist/native-style.d.ts +8 -0
  34. package/dist/native-style.js +108 -0
  35. package/dist/native-style.js.map +1 -0
  36. package/dist/props.d.ts +54 -0
  37. package/dist/props.js +608 -0
  38. package/dist/props.js.map +1 -0
  39. package/dist/reset-css.d.ts +26 -0
  40. package/dist/reset-css.js +163 -0
  41. package/dist/reset-css.js.map +1 -0
  42. package/dist/reset.css +282 -0
  43. package/dist/responder.d.ts +55 -0
  44. package/dist/responder.js +137 -0
  45. package/dist/responder.js.map +1 -0
  46. package/dist/web-view.d.ts +46 -0
  47. package/dist/web-view.js +93 -0
  48. package/dist/web-view.js.map +1 -0
  49. package/package.json +92 -3
  50. package/vite.d.mts +11 -0
  51. package/vite.mjs +41 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The JS responder negotiation, over DOM pointer events instead of Fabric's raw touch stream.
3
+ *
4
+ * `packages/fabric/src/engine.ts` runs a two-phase election on every `topTouchStart`: a capture
5
+ * pass root-to-target where an ancestor (a scroll view) can pre-empt, then a bubble pass
6
+ * target-to-root where the innermost interested node wins. Exactly one node ever holds the
7
+ * gesture, and a `grant` can be refused by `onResponderTerminationRequest`. This file is that
8
+ * algorithm, ported line for line from `negotiate`/`grant`/`release` in `engine.ts`, over
9
+ * `BrowserNode`'s `.parent` chain instead of `EngineNode`'s.
10
+ *
11
+ * ## What is faithfully reproduced
12
+ *
13
+ * The whole negotiation: capture pre-emption, bubble election, termination requests, and a
14
+ * scroll view taking over a drag mid-press (`notifyScroll`, the counterpart of `engine.ts`'s
15
+ * `cancelPressForScroll`). `pressable.test.ts`-equivalent scenarios - a pressable nested in a
16
+ * scroll view nested in a dialog - behave the same on both platforms because this is the same
17
+ * algorithm, not a different one that happens to agree on simple cases.
18
+ *
19
+ * ## What differs, and why
20
+ *
21
+ * There is no native side to tell who currently owns the gesture (`tellNative`/`setIsJSResponder`
22
+ * in `engine.ts`): a DOM scroll container has no separate "JS responder" concept to defer to, it
23
+ * simply does not receive the pointer events this system does not propagate to it as a drag. So
24
+ * `blockNativeResponder` is accepted (for API parity - a component that sets it does not break)
25
+ * and does nothing, which is a real gap only for a native scroll gesture that would otherwise
26
+ * fight a JS one; on the web the browser's own scroll only starts from events this system's
27
+ * `setPointerCapture` call (`browser-engine.ts`) already keeps from reaching it while a responder
28
+ * holds the gesture.
29
+ *
30
+ * `notifyScroll`'s cancellation is coarser than `engine.ts`'s: native tells the responder system
31
+ * apart a real drag from a momentum settle or a programmatic `scrollTo` because it is the same
32
+ * code sending both `topScroll` and `topScrollBeginDrag`. A DOM `scroll` event carries no such
33
+ * distinction, so this cancels on the first `scroll` a descendant responder sees, drag or not.
34
+ * The one case that reads differently: a programmatic `scrollTo()` call that happens to run while
35
+ * something inside that scroll view is mid-press will cancel the press on the web and not on
36
+ * native. Narrow, and named here rather than found by a user later.
37
+ */
38
+ import { type ResponderEvent, type ResponderHandlers } from '@ng-native/fabric';
39
+ import { type BrowserNode } from './dom-node.ts';
40
+ export declare class ResponderSystem {
41
+ private readonly responders;
42
+ private current;
43
+ get responder(): BrowserNode | null;
44
+ /** Whether `node` takes part in the negotiation at all: a control, rather than a plain view. */
45
+ responds(node: BrowserNode): boolean;
46
+ setResponder(node: BrowserNode, handlers: ResponderHandlers): () => void;
47
+ /** Root-first capture, then target-first bubble. Mirrors `engine.ts`'s `negotiate`. */
48
+ private negotiate;
49
+ private grant;
50
+ private release;
51
+ /** Drives the negotiation from a synthesised `topTouchStart`/`Move`/`End`/`Cancel`. */
52
+ runResponder(target: BrowserNode, type: string, event: ResponderEvent): void;
53
+ /** A scroll container moved under the finger. Cancels a press inside it; see the file doc. */
54
+ notifyScroll(scrollNode: BrowserNode): void;
55
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * The JS responder negotiation, over DOM pointer events instead of Fabric's raw touch stream.
3
+ *
4
+ * `packages/fabric/src/engine.ts` runs a two-phase election on every `topTouchStart`: a capture
5
+ * pass root-to-target where an ancestor (a scroll view) can pre-empt, then a bubble pass
6
+ * target-to-root where the innermost interested node wins. Exactly one node ever holds the
7
+ * gesture, and a `grant` can be refused by `onResponderTerminationRequest`. This file is that
8
+ * algorithm, ported line for line from `negotiate`/`grant`/`release` in `engine.ts`, over
9
+ * `BrowserNode`'s `.parent` chain instead of `EngineNode`'s.
10
+ *
11
+ * ## What is faithfully reproduced
12
+ *
13
+ * The whole negotiation: capture pre-emption, bubble election, termination requests, and a
14
+ * scroll view taking over a drag mid-press (`notifyScroll`, the counterpart of `engine.ts`'s
15
+ * `cancelPressForScroll`). `pressable.test.ts`-equivalent scenarios - a pressable nested in a
16
+ * scroll view nested in a dialog - behave the same on both platforms because this is the same
17
+ * algorithm, not a different one that happens to agree on simple cases.
18
+ *
19
+ * ## What differs, and why
20
+ *
21
+ * There is no native side to tell who currently owns the gesture (`tellNative`/`setIsJSResponder`
22
+ * in `engine.ts`): a DOM scroll container has no separate "JS responder" concept to defer to, it
23
+ * simply does not receive the pointer events this system does not propagate to it as a drag. So
24
+ * `blockNativeResponder` is accepted (for API parity - a component that sets it does not break)
25
+ * and does nothing, which is a real gap only for a native scroll gesture that would otherwise
26
+ * fight a JS one; on the web the browser's own scroll only starts from events this system's
27
+ * `setPointerCapture` call (`browser-engine.ts`) already keeps from reaching it while a responder
28
+ * holds the gesture.
29
+ *
30
+ * `notifyScroll`'s cancellation is coarser than `engine.ts`'s: native tells the responder system
31
+ * apart a real drag from a momentum settle or a programmatic `scrollTo` because it is the same
32
+ * code sending both `topScroll` and `topScrollBeginDrag`. A DOM `scroll` event carries no such
33
+ * distinction, so this cancels on the first `scroll` a descendant responder sees, drag or not.
34
+ * The one case that reads differently: a programmatic `scrollTo()` call that happens to run while
35
+ * something inside that scroll view is mid-press will cancel the press on the web and not on
36
+ * native. Narrow, and named here rather than found by a user later.
37
+ */
38
+ import { SyntheticEvent } from '@ng-native/fabric';
39
+ import { pathTo } from "./dom-node.js";
40
+ export class ResponderSystem {
41
+ responders = new WeakMap();
42
+ current = null;
43
+ get responder() {
44
+ return this.current;
45
+ }
46
+ /** Whether `node` takes part in the negotiation at all: a control, rather than a plain view. */
47
+ responds(node) {
48
+ return this.responders.has(node);
49
+ }
50
+ setResponder(node, handlers) {
51
+ this.responders.set(node, handlers);
52
+ return () => {
53
+ this.responders.delete(node);
54
+ if (this.current !== node)
55
+ return;
56
+ // Torn down mid-gesture: no release is coming, so the responder is cleared here or the
57
+ // negotiation would believe forever that a node no longer registered still holds it.
58
+ this.current = null;
59
+ };
60
+ }
61
+ /** Root-first capture, then target-first bubble. Mirrors `engine.ts`'s `negotiate`. */
62
+ negotiate(target, event, phase) {
63
+ const path = pathTo(target);
64
+ const capture = `on${phase}ShouldSetResponderCapture`;
65
+ const bubble = `on${phase}ShouldSetResponder`;
66
+ for (const node of path) {
67
+ if (this.responders.get(node)?.[capture]?.(event, target))
68
+ return node;
69
+ }
70
+ for (let i = path.length - 1; i >= 0; i--) {
71
+ if (this.responders.get(path[i])?.[bubble]?.(event, target))
72
+ return path[i];
73
+ }
74
+ return null;
75
+ }
76
+ grant(node, event) {
77
+ const previous = this.current;
78
+ if (previous === node)
79
+ return;
80
+ if (previous) {
81
+ const handlers = this.responders.get(previous);
82
+ // `undefined` means yes: RN's default is to allow the takeover.
83
+ if (handlers?.onResponderTerminationRequest?.(event) === false)
84
+ return;
85
+ handlers?.onResponderTerminate?.(event);
86
+ }
87
+ this.current = node;
88
+ this.responders.get(node)?.onResponderGrant?.(event);
89
+ }
90
+ release(event, terminated) {
91
+ const node = this.current;
92
+ if (!node)
93
+ return;
94
+ this.current = null;
95
+ const handlers = this.responders.get(node);
96
+ if (terminated)
97
+ handlers?.onResponderTerminate?.(event);
98
+ else
99
+ handlers?.onResponderRelease?.(event);
100
+ }
101
+ /** Drives the negotiation from a synthesised `topTouchStart`/`Move`/`End`/`Cancel`. */
102
+ runResponder(target, type, event) {
103
+ if (type === 'topTouchStart') {
104
+ const elected = this.negotiate(target, event, 'Start');
105
+ if (elected)
106
+ this.grant(elected, event);
107
+ return;
108
+ }
109
+ if (type === 'topTouchMove') {
110
+ if (this.current)
111
+ this.responders.get(this.current)?.onResponderMove?.(event);
112
+ else {
113
+ const elected = this.negotiate(target, event, 'Move');
114
+ if (elected)
115
+ this.grant(elected, event);
116
+ }
117
+ return;
118
+ }
119
+ if (type === 'topTouchEnd')
120
+ this.release(event, false);
121
+ else if (type === 'topTouchCancel')
122
+ this.release(event, true);
123
+ }
124
+ /** A scroll container moved under the finger. Cancels a press inside it; see the file doc. */
125
+ notifyScroll(scrollNode) {
126
+ const responder = this.current;
127
+ if (!responder || responder === scrollNode)
128
+ return;
129
+ for (let node = responder; node; node = node.parent) {
130
+ if (node === scrollNode) {
131
+ this.release(new SyntheticEvent({}), true);
132
+ return;
133
+ }
134
+ }
135
+ }
136
+ }
137
+ //# sourceMappingURL=responder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responder.js","sourceRoot":"","sources":["../src/responder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,cAAc,EAA+C,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAoB,MAAM,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,OAAO,eAAe;IACT,UAAU,GAAG,IAAI,OAAO,EAAkC,CAAC;IACpE,OAAO,GAAuB,IAAI,CAAC;IAE3C,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,gGAAgG;IAChG,QAAQ,CAAC,IAAiB;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,YAAY,CAAC,IAAiB,EAAE,QAA2B;QACzD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI;gBAAE,OAAO;YAClC,uFAAuF;YACvF,qFAAqF;YACrF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC;IAED,uFAAuF;IAC/E,SAAS,CACf,MAAmB,EACnB,KAAqB,EACrB,KAAuB;QAEvB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,MAAM,OAAO,GAAG,KAAK,KAAK,2BAAoC,CAAC;QAC/D,MAAM,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AAY,CAAC,UAAuB;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,SAAS,IAAI,SAAS,KAAK,UAAU;YAAE,OAAO;QACnD,KAAK,IAAI,IAAI,GAAuB,SAAS,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACxE,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;gBACxB,IAAI,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;gBAC3C,OAAO;YACT,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["/**\n * The JS responder negotiation, over DOM pointer events instead of Fabric's raw touch stream.\n *\n * `packages/fabric/src/engine.ts` runs a two-phase election on every `topTouchStart`: a capture\n * pass root-to-target where an ancestor (a scroll view) can pre-empt, then a bubble pass\n * target-to-root where the innermost interested node wins. Exactly one node ever holds the\n * gesture, and a `grant` can be refused by `onResponderTerminationRequest`. This file is that\n * algorithm, ported line for line from `negotiate`/`grant`/`release` in `engine.ts`, over\n * `BrowserNode`'s `.parent` chain instead of `EngineNode`'s.\n *\n * ## What is faithfully reproduced\n *\n * The whole negotiation: capture pre-emption, bubble election, termination requests, and a\n * scroll view taking over a drag mid-press (`notifyScroll`, the counterpart of `engine.ts`'s\n * `cancelPressForScroll`). `pressable.test.ts`-equivalent scenarios - a pressable nested in a\n * scroll view nested in a dialog - behave the same on both platforms because this is the same\n * algorithm, not a different one that happens to agree on simple cases.\n *\n * ## What differs, and why\n *\n * There is no native side to tell who currently owns the gesture (`tellNative`/`setIsJSResponder`\n * in `engine.ts`): a DOM scroll container has no separate \"JS responder\" concept to defer to, it\n * simply does not receive the pointer events this system does not propagate to it as a drag. So\n * `blockNativeResponder` is accepted (for API parity - a component that sets it does not break)\n * and does nothing, which is a real gap only for a native scroll gesture that would otherwise\n * fight a JS one; on the web the browser's own scroll only starts from events this system's\n * `setPointerCapture` call (`browser-engine.ts`) already keeps from reaching it while a responder\n * holds the gesture.\n *\n * `notifyScroll`'s cancellation is coarser than `engine.ts`'s: native tells the responder system\n * apart a real drag from a momentum settle or a programmatic `scrollTo` because it is the same\n * code sending both `topScroll` and `topScrollBeginDrag`. A DOM `scroll` event carries no such\n * distinction, so this cancels on the first `scroll` a descendant responder sees, drag or not.\n * The one case that reads differently: a programmatic `scrollTo()` call that happens to run while\n * something inside that scroll view is mid-press will cancel the press on the web and not on\n * native. Narrow, and named here rather than found by a user later.\n */\nimport { SyntheticEvent, type ResponderEvent, type ResponderHandlers } from '@ng-native/fabric';\nimport { type BrowserNode, pathTo } from './dom-node.ts';\n\nexport class ResponderSystem {\n private readonly responders = new WeakMap<BrowserNode, ResponderHandlers>();\n private current: BrowserNode | null = null;\n\n get responder(): BrowserNode | null {\n return this.current;\n }\n\n /** Whether `node` takes part in the negotiation at all: a control, rather than a plain view. */\n responds(node: BrowserNode): boolean {\n return this.responders.has(node);\n }\n\n setResponder(node: BrowserNode, handlers: ResponderHandlers): () => void {\n this.responders.set(node, handlers);\n return () => {\n this.responders.delete(node);\n if (this.current !== node) return;\n // Torn down mid-gesture: no release is coming, so the responder is cleared here or the\n // negotiation would believe forever that a node no longer registered still holds it.\n this.current = null;\n };\n }\n\n /** Root-first capture, then target-first bubble. Mirrors `engine.ts`'s `negotiate`. */\n private negotiate(\n target: BrowserNode,\n event: ResponderEvent,\n phase: 'Start' | 'Move',\n ): BrowserNode | null {\n const path = pathTo(target);\n const capture = `on${phase}ShouldSetResponderCapture` as const;\n const bubble = `on${phase}ShouldSetResponder` as const;\n\n for (const node of path) {\n if (this.responders.get(node)?.[capture]?.(event, target as never)) return node;\n }\n for (let i = path.length - 1; i >= 0; i--) {\n if (this.responders.get(path[i]!)?.[bubble]?.(event, target as never)) return path[i]!;\n }\n return null;\n }\n\n private grant(node: BrowserNode, event: ResponderEvent): void {\n const previous = this.current;\n if (previous === node) return;\n\n if (previous) {\n const handlers = this.responders.get(previous);\n // `undefined` means yes: RN's default is to allow the takeover.\n if (handlers?.onResponderTerminationRequest?.(event) === false) return;\n handlers?.onResponderTerminate?.(event);\n }\n\n this.current = node;\n this.responders.get(node)?.onResponderGrant?.(event);\n }\n\n private release(event: ResponderEvent, terminated: boolean): void {\n const node = this.current;\n if (!node) return;\n this.current = null;\n const handlers = this.responders.get(node);\n if (terminated) handlers?.onResponderTerminate?.(event);\n else handlers?.onResponderRelease?.(event);\n }\n\n /** Drives the negotiation from a synthesised `topTouchStart`/`Move`/`End`/`Cancel`. */\n runResponder(target: BrowserNode, type: string, event: ResponderEvent): void {\n if (type === 'topTouchStart') {\n const elected = this.negotiate(target, event, 'Start');\n if (elected) this.grant(elected, event);\n return;\n }\n if (type === 'topTouchMove') {\n if (this.current) this.responders.get(this.current)?.onResponderMove?.(event);\n else {\n const elected = this.negotiate(target, event, 'Move');\n if (elected) this.grant(elected, event);\n }\n return;\n }\n if (type === 'topTouchEnd') this.release(event, false);\n else if (type === 'topTouchCancel') this.release(event, true);\n }\n\n /** A scroll container moved under the finger. Cancels a press inside it; see the file doc. */\n notifyScroll(scrollNode: BrowserNode): void {\n const responder = this.current;\n if (!responder || responder === scrollNode) return;\n for (let node: BrowserNode | null = responder; node; node = node.parent) {\n if (node === scrollNode) {\n this.release(new SyntheticEvent({}), true);\n return;\n }\n }\n }\n}\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The web half of `<dom-component>`: an Angular DOM component, mounted in the page a native web
3
+ * view loaded, and talking to the app around it.
4
+ *
5
+ * ```ts
6
+ * // web/note.ts - an ordinary Angular DOM component, in the app's own source
7
+ * 'use dom';
8
+ * @Component({ selector: 'app-note', template: '<textarea ...></textarea>', styles: [...] })
9
+ * export class Note { ... }
10
+ *
11
+ * export default mountInWebView(Note);
12
+ * ```
13
+ *
14
+ * The default export is what native code imports and hands to `<dom-component [src]>`. On native
15
+ * the build replaces the whole file with a reference to its page (see `@ng-native/metro`'s
16
+ * `dom-component.cjs`), so the type is the same on both sides and nothing here runs there.
17
+ *
18
+ * The page is a separate JavaScript runtime from the app, so only JSON crosses:
19
+ *
20
+ * - **Inputs** arrive before the page loads, in the object the web view injected
21
+ * (`ReactNativeWebView.injectedObjectJson()`), and later as `inputs` messages the app runs
22
+ * through `window.__ngNative.receive`. Each is set by public name, without remounting.
23
+ * - **Outputs** are every output the component declares, a `model()`'s `...Change` included. Each
24
+ * emit is posted to the app as `{ type: 'output', name, value }`.
25
+ * - **`ready`** is posted once mounted, with the output names, so the app can check its handlers
26
+ * against them and re-send any input that changed while the page was loading.
27
+ * - **Errors** are posted as `{ type: 'error', message }`: a web view's console is in Safari's
28
+ * inspector, and the app's is where someone is looking.
29
+ *
30
+ * This is the same protocol shape as Expo's DOM components, which do this for React.
31
+ */
32
+ import { type ComponentRef, type EnvironmentProviders, type Provider, type Type } from '@angular/core';
33
+ /**
34
+ * A DOM component, as `export default mountInWebView(...)` gives it. Native code imports this and
35
+ * passes it to `<dom-component [src]>`.
36
+ */
37
+ export interface DomComponentFile<T = unknown> {
38
+ /** The page to load. Set by the build in native code; empty in the web view itself. */
39
+ readonly domComponent: string;
40
+ /** The mounted component, in the web view only. */
41
+ readonly mounted?: Promise<ComponentRef<T>>;
42
+ }
43
+ export interface MountInWebViewOptions {
44
+ readonly providers?: (Provider | EnvironmentProviders)[];
45
+ }
46
+ export declare function mountInWebView<T>(component: Type<T>, options?: MountInWebViewOptions): DomComponentFile<T>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The web half of `<dom-component>`: an Angular DOM component, mounted in the page a native web
3
+ * view loaded, and talking to the app around it.
4
+ *
5
+ * ```ts
6
+ * // web/note.ts - an ordinary Angular DOM component, in the app's own source
7
+ * 'use dom';
8
+ * @Component({ selector: 'app-note', template: '<textarea ...></textarea>', styles: [...] })
9
+ * export class Note { ... }
10
+ *
11
+ * export default mountInWebView(Note);
12
+ * ```
13
+ *
14
+ * The default export is what native code imports and hands to `<dom-component [src]>`. On native
15
+ * the build replaces the whole file with a reference to its page (see `@ng-native/metro`'s
16
+ * `dom-component.cjs`), so the type is the same on both sides and nothing here runs there.
17
+ *
18
+ * The page is a separate JavaScript runtime from the app, so only JSON crosses:
19
+ *
20
+ * - **Inputs** arrive before the page loads, in the object the web view injected
21
+ * (`ReactNativeWebView.injectedObjectJson()`), and later as `inputs` messages the app runs
22
+ * through `window.__ngNative.receive`. Each is set by public name, without remounting.
23
+ * - **Outputs** are every output the component declares, a `model()`'s `...Change` included. Each
24
+ * emit is posted to the app as `{ type: 'output', name, value }`.
25
+ * - **`ready`** is posted once mounted, with the output names, so the app can check its handlers
26
+ * against them and re-send any input that changed while the page was loading.
27
+ * - **Errors** are posted as `{ type: 'error', message }`: a web view's console is in Safari's
28
+ * inspector, and the app's is where someone is looking.
29
+ *
30
+ * This is the same protocol shape as Expo's DOM components, which do this for React.
31
+ */
32
+ import { ErrorHandler, createComponent, provideZonelessChangeDetection, reflectComponentType, } from '@angular/core';
33
+ import { createApplication } from '@angular/platform-browser';
34
+ export function mountInWebView(component, options = {}) {
35
+ return { domComponent: '', mounted: mount(component, options) };
36
+ }
37
+ async function mount(component, options) {
38
+ const bridge = window.ReactNativeWebView;
39
+ const post = (message) => bridge?.postMessage(JSON.stringify(message));
40
+ const initial = readInjected(bridge);
41
+ const appRef = await createApplication({
42
+ providers: [
43
+ provideZonelessChangeDetection(),
44
+ {
45
+ provide: ErrorHandler,
46
+ useValue: {
47
+ handleError: (error) => post({ type: 'error', message: describe(error) }),
48
+ },
49
+ },
50
+ ...(options.providers ?? []),
51
+ ],
52
+ });
53
+ // The page is the component's, edge to edge, so the browser's default body margin goes.
54
+ document.body.style.margin = '0';
55
+ const host = document.querySelector('ng-native-web-root') ??
56
+ document.body.appendChild(document.createElement('ng-native-web-root'));
57
+ const ref = createComponent(component, {
58
+ environmentInjector: appRef.injector,
59
+ hostElement: host,
60
+ });
61
+ setInputs(ref, initial.inputs ?? {});
62
+ appRef.attachView(ref.hostView);
63
+ const outputs = reflectComponentType(component)?.outputs ?? [];
64
+ const instance = ref.instance;
65
+ for (const { propName, templateName } of outputs) {
66
+ instance[propName].subscribe((value) => post({ type: 'output', name: templateName, value }));
67
+ }
68
+ window.__ngNative = {
69
+ receive(message) {
70
+ if (message.type === 'inputs')
71
+ setInputs(ref, message.inputs ?? {});
72
+ },
73
+ };
74
+ ref.changeDetectorRef.detectChanges();
75
+ post({ type: 'ready', outputs: outputs.map((output) => output.templateName) });
76
+ return ref;
77
+ }
78
+ function readInjected(bridge) {
79
+ try {
80
+ return JSON.parse(bridge?.injectedObjectJson?.() ?? '{}');
81
+ }
82
+ catch {
83
+ return {};
84
+ }
85
+ }
86
+ function setInputs(ref, inputs) {
87
+ for (const [name, value] of Object.entries(inputs))
88
+ ref.setInput(name, value);
89
+ }
90
+ function describe(error) {
91
+ return error instanceof Error ? `${error.message}\n${error.stack ?? ''}` : String(error);
92
+ }
93
+ //# sourceMappingURL=web-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-view.js","sourceRoot":"","sources":["../src/web-view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EACL,YAAY,EACZ,eAAe,EACf,8BAA8B,EAC9B,oBAAoB,GAMrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AA4B9D,MAAM,UAAU,cAAc,CAC5B,SAAkB,EAClB,UAAiC,EAAE;IAEnC,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC;AAClE,CAAC;AAED,KAAK,UAAU,KAAK,CAClB,SAAkB,EAClB,OAA8B;IAE9B,MAAM,MAAM,GAAI,MAA2D,CAAC,kBAAkB,CAAC;IAC/F,MAAM,IAAI,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,OA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n * view loaded, and talking to the app around it.\n *\n * ```ts\n * // web/note.ts - an ordinary Angular DOM component, in the app's own source\n * 'use dom';\n * @Component({ selector: 'app-note', template: '<textarea ...></textarea>', styles: [...] })\n * export class Note { ... }\n *\n * export default mountInWebView(Note);\n * ```\n *\n * The default export is what native code imports and hands to `<dom-component [src]>`. On native\n * the build replaces the whole file with a reference to its page (see `@ng-native/metro`'s\n * `dom-component.cjs`), so the type is the same on both sides and nothing here runs there.\n *\n * The page is a separate JavaScript runtime from the app, so only JSON crosses:\n *\n * - **Inputs** arrive before the page loads, in the object the web view injected\n * (`ReactNativeWebView.injectedObjectJson()`), and later as `inputs` messages the app runs\n * through `window.__ngNative.receive`. Each is set by public name, without remounting.\n * - **Outputs** are every output the component declares, a `model()`'s `...Change` included. Each\n * emit is posted to the app as `{ type: 'output', name, value }`.\n * - **`ready`** is posted once mounted, with the output names, so the app can check its handlers\n * against them and re-send any input that changed while the page was loading.\n * - **Errors** are posted as `{ type: 'error', message }`: a web view's console is in Safari's\n * inspector, and the app's is where someone is looking.\n *\n * This is the same protocol shape as Expo's DOM components, which do this for React.\n */\nimport {\n ErrorHandler,\n createComponent,\n provideZonelessChangeDetection,\n reflectComponentType,\n type ComponentRef,\n type EnvironmentProviders,\n type OutputRef,\n type Provider,\n type Type,\n} from '@angular/core';\nimport { createApplication } from '@angular/platform-browser';\n\n/** What the native web view puts on `window` for the page. */\ninterface NativeBridge {\n injectedObjectJson?(): string;\n postMessage(data: string): void;\n}\n\ntype Message =\n | { type: 'ready'; outputs: string[] }\n | { type: 'output'; name: string; value: unknown }\n | { type: 'error'; message: string };\n\n/**\n * A DOM component, as `export default mountInWebView(...)` gives it. Native code imports this and\n * passes it to `<dom-component [src]>`.\n */\nexport interface DomComponentFile<T = unknown> {\n /** The page to load. Set by the build in native code; empty in the web view itself. */\n readonly domComponent: string;\n /** The mounted component, in the web view only. */\n readonly mounted?: Promise<ComponentRef<T>>;\n}\n\nexport interface MountInWebViewOptions {\n readonly providers?: (Provider | EnvironmentProviders)[];\n}\n\nexport function mountInWebView<T>(\n component: Type<T>,\n options: MountInWebViewOptions = {},\n): DomComponentFile<T> {\n return { domComponent: '', mounted: mount(component, options) };\n}\n\nasync function mount<T>(\n component: Type<T>,\n options: MountInWebViewOptions,\n): Promise<ComponentRef<T>> {\n const bridge = (window as unknown as { ReactNativeWebView?: NativeBridge }).ReactNativeWebView;\n const post = (message: Message) => bridge?.postMessage(JSON.stringify(message));\n const initial = readInjected(bridge);\n\n const appRef = await createApplication({\n providers: [\n provideZonelessChangeDetection(),\n {\n provide: ErrorHandler,\n useValue: {\n handleError: (error: unknown) => post({ type: 'error', message: describe(error) }),\n },\n },\n ...(options.providers ?? []),\n ],\n });\n\n // The page is the component's, edge to edge, so the browser's default body margin goes.\n document.body.style.margin = '0';\n const host =\n document.querySelector('ng-native-web-root') ??\n document.body.appendChild(document.createElement('ng-native-web-root'));\n const ref = createComponent(component, {\n environmentInjector: appRef.injector,\n hostElement: host,\n });\n setInputs(ref, initial.inputs ?? {});\n appRef.attachView(ref.hostView);\n\n const outputs = reflectComponentType(component)?.outputs ?? [];\n const instance = ref.instance as Record<string, OutputRef<unknown>>;\n for (const { propName, templateName } of outputs) {\n instance[propName]!.subscribe((value) => post({ type: 'output', name: templateName, value }));\n }\n\n (window as unknown as { __ngNative: unknown }).__ngNative = {\n receive(message: { type: string; inputs?: Record<string, unknown> }) {\n if (message.type === 'inputs') setInputs(ref, message.inputs ?? {});\n },\n };\n\n ref.changeDetectorRef.detectChanges();\n post({ type: 'ready', outputs: outputs.map((output) => output.templateName) });\n return ref;\n}\n\nfunction readInjected(bridge: NativeBridge | undefined): { inputs?: Record<string, unknown> } {\n try {\n return JSON.parse(bridge?.injectedObjectJson?.() ?? '{}');\n } catch {\n return {};\n }\n}\n\nfunction setInputs(ref: ComponentRef<unknown>, inputs: Record<string, unknown>): void {\n for (const [name, value] of Object.entries(inputs)) ref.setInput(name, value);\n}\n\nfunction describe(error: unknown): string {\n return error instanceof Error ? `${error.message}\\n${error.stack ?? ''}` : String(error);\n}\n"]}
package/package.json CHANGED
@@ -1,12 +1,101 @@
1
1
  {
2
2
  "name": "@ng-native/web",
3
- "version": "0.0.1",
4
- "description": "Reserved for ng-native. The first release follows.",
3
+ "version": "0.1.1",
4
+ "description": "A browser host for Angular Native: the same components, rendered into the DOM instead of native views.",
5
+ "keywords": [
6
+ "angular",
7
+ "react-native",
8
+ "angular-native",
9
+ "ios",
10
+ "android",
11
+ "fabric",
12
+ "native",
13
+ "web",
14
+ "dom"
15
+ ],
16
+ "type": "module",
17
+ "main": "dist/index.js",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./web-view": {
24
+ "types": "./dist/web-view.d.ts",
25
+ "default": "./dist/web-view.js"
26
+ },
27
+ "./reset.css": "./dist/reset.css",
28
+ "./vite": {
29
+ "types": "./vite.d.mts",
30
+ "default": "./vite.mjs"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "dependencies": {
38
+ "@oxc-angular/vite": "0.0.38",
39
+ "@ng-native/device": "0.1.1",
40
+ "@ng-native/fabric": "0.1.1"
41
+ },
42
+ "peerDependencies": {
43
+ "@angular/core": "^22.0.0",
44
+ "vite": ">=8.0.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "vite": {
48
+ "optional": true
49
+ }
50
+ },
51
+ "devDependencies": {
52
+ "@angular/common": "22.2.0",
53
+ "@angular/compiler": "22.2.0",
54
+ "@angular/platform-browser": "22.2.0",
55
+ "@ng-icons/core": "^36.0.0",
56
+ "@tailwindcss/vite": "^4.3.3",
57
+ "@types/jsdom": "^27.0.0",
58
+ "@vitest/browser": "^5.0.2",
59
+ "@vitest/browser-playwright": "^5.0.2",
60
+ "@vitest/coverage-v8": "^5.0.2",
61
+ "jsdom": "^27.0.0",
62
+ "playwright": "^1.63.0",
63
+ "rxjs": "^7.8.2",
64
+ "tailwindcss": "^4.3.3",
65
+ "vite": "^8.3.1",
66
+ "vitest": "^5.0.2",
67
+ "@ng-native/icons": "0.1.1",
68
+ "@ng-native/metro": "0.1.1",
69
+ "@ng-native/tailwind": "0.1.1",
70
+ "@ng-native/testing": "0.1.1",
71
+ "@ng-native/components": "0.1.1"
72
+ },
73
+ "nx": {
74
+ "tags": [
75
+ "scope:web",
76
+ "layer:angular"
77
+ ]
78
+ },
5
79
  "license": "MIT",
80
+ "homepage": "https://ng-native.com/packages/web",
81
+ "bugs": {
82
+ "url": "https://github.com/ng-native/ng-native/issues"
83
+ },
84
+ "files": [
85
+ "dist",
86
+ "vite.mjs",
87
+ "vite.d.mts"
88
+ ],
6
89
  "repository": {
7
90
  "type": "git",
8
91
  "url": "git+https://github.com/ng-native/ng-native.git",
9
92
  "directory": "packages/web"
10
93
  },
11
- "homepage": "https://ng-native.com/packages/web"
94
+ "scripts": {
95
+ "build": "ngc -p tsconfig.build.json && cp src/reset.css dist/",
96
+ "typecheck": "tsc -p tsconfig.json --noEmit",
97
+ "test": "node --import ./register-linker.mjs --test \"src/*.test.ts\"",
98
+ "test:browser": "vitest run"
99
+ },
100
+ "types": "dist/index.d.ts"
12
101
  }
package/vite.d.mts ADDED
@@ -0,0 +1,11 @@
1
+ import type { PluginOptions } from '@oxc-angular/vite';
2
+ import type { Plugin } from 'vite';
3
+
4
+ /**
5
+ * The Vite preset for a browser app on `@ng-native/web`: compiles the app's components, links the
6
+ * `@ng-native/*` packages, and keeps React Native and Expo out of the build.
7
+ *
8
+ * `options` go to `@oxc-angular/vite`'s `angular()`, over `zoneless: true` and
9
+ * `emitClassMetadata: false`.
10
+ */
11
+ export declare function ngNativeWeb(options?: PluginOptions): Plugin[];
package/vite.mjs ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * `ngNativeWeb()`: the Vite preset for a browser app that renders `@ng-native/components` through
3
+ * `@ng-native/web`.
4
+ *
5
+ * Two plugins, in this order:
6
+ *
7
+ * - `ng-native:config`, the resolution a browser build needs. React Native and Expo are reachable
8
+ * from the packages behind guards a browser never passes, but a bundler still resolves every
9
+ * specifier it sees, and React Native's source is Flow. They stay out of the build.
10
+ * - `@oxc-angular/vite`'s own plugins, for the app's components and for the linker, which handles
11
+ * the `@ng-native/*` packages as it handles every partial-compiled Angular library on npm.
12
+ */
13
+ import { angular } from '@oxc-angular/vite';
14
+
15
+ /**
16
+ * What the packages `require` on a device, behind a check a browser never passes. Only these: an
17
+ * import of anything else native-only is a module a browser build really would need, so it fails
18
+ * the build rather than the page.
19
+ */
20
+ const NATIVE_ONLY = ['react-native', 'expo'];
21
+ const NATIVE_ONLY_PATTERN = /^(react-native|expo)(\/|$)/;
22
+
23
+ /** @returns {import('vite').Plugin} */
24
+ function config() {
25
+ return {
26
+ name: 'ng-native:config',
27
+ config: () => ({
28
+ optimizeDeps: { exclude: NATIVE_ONLY },
29
+ build: { rolldownOptions: { external: (id) => NATIVE_ONLY_PATTERN.test(id) } },
30
+ }),
31
+ };
32
+ }
33
+
34
+ /**
35
+ * @param {import('@oxc-angular/vite').PluginOptions} [options] passed on to `@oxc-angular/vite`'s
36
+ * `angular()`, over `zoneless: true` and `emitClassMetadata: false`.
37
+ * @returns {import('vite').Plugin[]}
38
+ */
39
+ export function ngNativeWeb(options = {}) {
40
+ return [config(), ...angular({ zoneless: true, emitClassMetadata: false, ...options })];
41
+ }