@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ashley Hunter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
1
  # @ng-native/web
2
2
 
3
- A placeholder: this version has no code. See https://ng-native.com.
3
+ A browser host for Angular Native: the same `@ng-native/components` templates, rendered into the
4
+ DOM instead of native views. It implements the `HostEngine` seam the Fabric engine implements, so
5
+ a `<view>`, a `<pressable>` or a `<text-input>` behaves the same way in a browser as it does on a
6
+ phone - which is what the documentation site's live examples and this project's browser tests run
7
+ on.
8
+
9
+ Alpha: APIs may change before 1.0.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ npm install @angular/core rxjs @ng-native/components @ng-native/web
15
+ npm install --save-dev vite typescript
16
+ ```
17
+
18
+ A browser app builds with Vite. `ngNativeWeb()` compiles the app's components, links the
19
+ `@ng-native/*` packages, and keeps React Native and Expo out of the bundle:
20
+
21
+ ```ts
22
+ // vite.config.ts
23
+ import { ngNativeWeb } from '@ng-native/web/vite';
24
+ import { defineConfig } from 'vite';
25
+
26
+ export default defineConfig({
27
+ plugins: [ngNativeWeb()],
28
+ });
29
+ ```
30
+
31
+ The Angular CLI's builders cannot compile the packages; an Angular app that hosts islands builds
32
+ with Vite and `ngNativeWeb()` instead.
33
+
34
+ ## Example
35
+
36
+ Mounting a component into a page:
37
+
38
+ ```ts
39
+ import { mount } from '@ng-native/web';
40
+ import { App } from './app';
41
+
42
+ mount(document.querySelector('app-root')!, App);
43
+ ```
44
+
45
+ `mount` injects a reset stylesheet that gives elements React Native's layout defaults (border-box,
46
+ no flex shrinking, a full-height column root) unless `injectReset: false` is passed, and takes
47
+ `providers` the way `bootstrapApplication` does.
48
+
49
+ Inside an Angular web app you already have, place a component in any template with
50
+ `<ng-native-island>`. It shares the app's services and change detection:
51
+
52
+ ```ts
53
+ import { NgNativeIsland } from '@ng-native/web';
54
+
55
+ @Component({
56
+ imports: [NgNativeIsland],
57
+ template: `<ng-native-island
58
+ [component]="wallet"
59
+ [inputs]="{ accountId }"
60
+ [outputs]="{ paid: onPaid }"
61
+ />`,
62
+ })
63
+ export class AccountPage {}
64
+ ```
65
+
66
+ Or from code, `mount(element, Wallet, { injector })` with an injector from the app, and
67
+ `destroy()` on the result to take the island down again.
68
+
69
+ ## Docs
70
+
71
+ - [Web](https://ng-native.com/packages/web):
72
+ setting up a browser app, with Tailwind
73
+ - [Native and web](https://ng-native.com/guide/native-and-web)
74
+ - [Islands](https://ng-native.com/packages/web/islands):
75
+ Angular Native components inside an existing Angular web app
76
+ - [Root README](https://github.com/ng-native/ng-native/blob/main/README.md) and
77
+ [ARCHITECTURE.md](https://github.com/ng-native/ng-native/blob/main/ARCHITECTURE.md)
78
+
79
+ ## License
80
+
81
+ MIT
@@ -0,0 +1,146 @@
1
+ /**
2
+ * `HostEngine` over real DOM APIs: the browser counterpart to `packages/fabric/src/engine.ts`'s
3
+ * `Engine`.
4
+ *
5
+ * One instance per `mount()` call. It owns the prop/DOM translation (`props.ts`), the element
6
+ * mapping (`elements.ts`), and the responder negotiation (`responder.ts`); this file is mostly
7
+ * the wiring between them and the handful of DOM event listeners the whole tree shares - one
8
+ * `pointerdown`/`pointermove`/`pointerup`/`pointercancel` set on `document` for the responder
9
+ * system, one `focusin`/`focusout` set for `:focus` tracking, because both need to see every
10
+ * node's events rather than each node installing its own (Fabric's own engine is exactly this
11
+ * shape: one `registerEventHandler` callback for the whole tree, not one per view).
12
+ *
13
+ * `dispatchEvent` mirrors `engine.ts`'s method of the same name step for step: run the responder
14
+ * negotiation first, then propagate to whatever `(eventName)` bindings are listening, in the
15
+ * same two-phase order a real touch would arrive in on native.
16
+ */
17
+ import { HostEngine, type ResponderHandlers, type WindowFrame } from '@ng-native/fabric';
18
+ import { type BrowserNode } from './dom-node.ts';
19
+ export declare class BrowserEngine extends HostEngine {
20
+ private readonly document;
21
+ private readonly responders;
22
+ private focusedNode;
23
+ /** `TextInput`'s echo protocol: a change count that only ever goes up. One counter per field. */
24
+ private readonly eventCounts;
25
+ /** Mount points `wrapRoot` wrapped; see `isRoot`. */
26
+ private readonly roots;
27
+ /**
28
+ * The node each in-progress gesture began on, by `pointerId`, so `pointermove`/`pointerup`
29
+ * resolve to the same node however far the finger has travelled - `setPointerCapture` keeps
30
+ * the browser routing them there; this is what this class trusts instead of re-reading
31
+ * `event.target`. Keyed by `pointerId` rather than holding just one, so two fingers on two
32
+ * different controls (a phone reports multi-touch) do not clobber each other.
33
+ */
34
+ private readonly activeTouches;
35
+ /**
36
+ * The element nodes this engine made, and so the only ones its document listeners act for.
37
+ *
38
+ * Every engine listens on the one `document`, and a page can hold several - one per island, or
39
+ * the documentation site's three roots - while `nearestNodeOf` finds a node whichever engine
40
+ * made it. Without this, each engine delivered every focus, blur and touch in any root on the
41
+ * page, so a text field's `(blur)` ran once per island.
42
+ */
43
+ private readonly owned;
44
+ /** Removes the document listeners, once the app they served is gone; see `dispose`. */
45
+ private readonly listening;
46
+ constructor(document: Document);
47
+ /** Stop listening to the document. `mount` calls this as its app is destroyed. */
48
+ dispose(): void;
49
+ createElementNode(name: string): BrowserNode;
50
+ createTextNode(value: string): BrowserNode;
51
+ createAnchorNode(): BrowserNode;
52
+ /** Wrap an existing real element - the app's own mount point - as the tree's root node. */
53
+ wrapRoot(el: Element): BrowserNode;
54
+ /**
55
+ * Whether `node` is a mount point `wrapRoot` wrapped. It belongs to whoever called `mount`, not
56
+ * to the app rendered into it, so the renderer empties it rather than removing it.
57
+ */
58
+ isRoot(node: BrowserNode): boolean;
59
+ setProp(node: BrowserNode, key: string, value: unknown): void;
60
+ setEventListener(node: BrowserNode, topLevelType: string, fn: (event: unknown) => void): () => void;
61
+ setResponder(node: BrowserNode, handlers: ResponderHandlers): () => void;
62
+ /**
63
+ * Where a node is, relative to the mount root rather than to the viewport.
64
+ *
65
+ * `measureInWindow` on native answers in window coordinates, and the overlay host is a
66
+ * full-screen absolutely positioned view at the window's origin, so the two agree and an
67
+ * anchored overlay can use one as the other. `getBoundingClientRect` answers in *viewport*
68
+ * coordinates, and `<overlay-host>` is absolutely positioned inside the mount root - so
69
+ * those two agree only when the root sits at the top left of an unscrolled viewport.
70
+ *
71
+ * That is true of a full-page app, which is why every popover in the gallery lands correctly
72
+ * and this went unnoticed. It is false in the two cases that matter: an app mounted into a box
73
+ * partway down a page, where every overlay is offset by the box's own position, and a document
74
+ * that scrolls, where the offset changes as you scroll. Subtracting the root's own rect from a
75
+ * viewport-relative one cancels the scroll term as well as the offset, since both rects move
76
+ * together as the page scrolls - so one subtraction fixes both cases at once.
77
+ *
78
+ * `closest`, not `querySelector`: a page can hold more than one mounted root at a time (the
79
+ * documentation site's own home page does, three of them), and `querySelector` always answers
80
+ * the first one in document order regardless of which root's own tree `node` actually lives in.
81
+ * That made every root after the first measure its overlays against someone else's box.
82
+ * `closest` walks up from the node itself, so each root only ever measures against its own.
83
+ */
84
+ measure(node: BrowserNode, into: (frame: WindowFrame) => void): void;
85
+ dispatchCommand(node: BrowserNode, name: string, args?: readonly unknown[]): void;
86
+ commit(): boolean;
87
+ get focused(): BrowserNode | null;
88
+ private isAttached;
89
+ /**
90
+ * A `require()`d numeric asset has no web analogue - there is no bundler-provided asset
91
+ * registry this package can read at runtime - so it resolves to nothing rather than a guess.
92
+ * A `{uri}` source, or an array of them, passes through unchanged: `props.ts`'s image handler
93
+ * reads it directly.
94
+ */
95
+ resolveAsset(value: unknown): unknown;
96
+ /**
97
+ * A colour the app wrote is passed straight through: CSS accepts the same hex/rgb/named
98
+ * strings RN does. `platform-color(...)`'s semantic iOS/Android names have no web colour
99
+ * system to resolve against, so they resolve to nothing rather than to a wrong guess.
100
+ */
101
+ color(value: unknown): unknown;
102
+ dispatchEvent(target: BrowserNode, topLevelType: string, nativeEvent: unknown): void;
103
+ /** As on native: a listener that stops the event ends the bubble after its own node. */
104
+ private propagate;
105
+ private wireAlwaysOnListeners;
106
+ /**
107
+ * `scroll` does not bubble, so this is a real per-node listener rather than a document one.
108
+ *
109
+ * `scrollend` is the browser saying the scroll has come to rest, whatever moved it: a wheel's
110
+ * or a trackpad's glide, a flick, or an animated `scrollTo`. That is the moment a device reports
111
+ * as `(momentumScrollEnd)` - iOS sends it after an animated `scrollTo` as well as after a fling -
112
+ * and the event a paging carousel reads its page from, which never arrived here at all.
113
+ */
114
+ private wireScroll;
115
+ private wireTextInput;
116
+ private wireSwitch;
117
+ /**
118
+ * `topLayout` and hover, opted into once per node the first time something listens for them -
119
+ * never torn down again, exactly as `engine.ts`'s own `EVENT_OPT_IN_PROPS` never unsets the
120
+ * native prop it wrote either. A second listener for the same type on the same node (unusual,
121
+ * but not forbidden) shares the one observer rather than getting a duplicate.
122
+ */
123
+ private wireOptIn;
124
+ private installGlobalListeners;
125
+ /** The control a held Space is pressing, released on the matching `keyup`. */
126
+ private keyPress;
127
+ /**
128
+ * Enter and Space press the focused control, as they press a `<button>`.
129
+ *
130
+ * A pressable is focusable and announces itself as a button, but it presses through the
131
+ * responder negotiation, which only pointer events drove - so a keyboard user could tab to it
132
+ * and do nothing with it. The key becomes the same touch a finger would make, on the control
133
+ * itself, so `pressIn`, `press` and `pressOut` all fire, in order, through the same code.
134
+ *
135
+ * Enter presses on the way down and Space on the way up, which is the browser's own rule for a
136
+ * button; Space is also kept from scrolling the page. A text field and a switch are left alone,
137
+ * because the browser's own control already does the right thing with both keys.
138
+ */
139
+ private onKey;
140
+ /** The focused control a key would press, or null where the key belongs to something else. */
141
+ private keyTarget;
142
+ /** A touch at the control's centre, so nothing downstream mistakes it for a drag. */
143
+ private keyTouch;
144
+ private onPointer;
145
+ private onFocusChange;
146
+ }