@ng-native/web 0.0.1 → 0.1.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 (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,17 @@
1
+ /**
2
+ * `@ng-native/web`'s public surface: a real browser host for `@ng-native/components`, over the
3
+ * same `HostEngine` seam Fabric implements
4
+ * (`packages/fabric/src/host.ts`).
5
+ *
6
+ * `mount.ts` is the one file with a documented relationship to `packages/platform`; the rest
7
+ * (`browser-engine.ts`, `browser-renderer.ts`, `dom-node.ts`, `elements.ts`, `props.ts`,
8
+ * `responder.ts`) has no native equivalent to compare itself to, because on native that work is
9
+ * `packages/fabric`'s, not `packages/platform`'s. This package folds both roles into one, since a
10
+ * browser host has no separate native-module boundary to split them across.
11
+ */
12
+ export { BrowserEngine } from './browser-engine.ts';
13
+ export { BrowserRenderer, type BrowserRendererFactory } from './browser-renderer.ts';
14
+ export { nodeOf, pathTo, type BrowserNode, type BrowserNodeKind } from './dom-node.ts';
15
+ export { registerElementName, type ElementSpec } from './elements.ts';
16
+ export { NgNativeIsland, type IslandOutputHandler } from './island.ts';
17
+ export { mount, type MountOptions, type MountResult } from './mount.ts';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `@ng-native/web`'s public surface: a real browser host for `@ng-native/components`, over the
3
+ * same `HostEngine` seam Fabric implements
4
+ * (`packages/fabric/src/host.ts`).
5
+ *
6
+ * `mount.ts` is the one file with a documented relationship to `packages/platform`; the rest
7
+ * (`browser-engine.ts`, `browser-renderer.ts`, `dom-node.ts`, `elements.ts`, `props.ts`,
8
+ * `responder.ts`) has no native equivalent to compare itself to, because on native that work is
9
+ * `packages/fabric`'s, not `packages/platform`'s. This package folds both roles into one, since a
10
+ * browser host has no separate native-module boundary to split them across.
11
+ */
12
+ export { BrowserEngine } from "./browser-engine.js";
13
+ export { BrowserRenderer } from "./browser-renderer.js";
14
+ export { nodeOf, pathTo } from "./dom-node.js";
15
+ export { registerElementName } from "./elements.js";
16
+ export { NgNativeIsland } from "./island.js";
17
+ export { mount } from "./mount.js";
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAA+B,MAAM,uBAAuB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,EAA0C,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAoB,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,cAAc,EAA4B,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,KAAK,EAAuC,MAAM,YAAY,CAAC","sourcesContent":["/**\n * `@ng-native/web`'s public surface: a real browser host for `@ng-native/components`, over the\n * same `HostEngine` seam Fabric implements\n * (`packages/fabric/src/host.ts`).\n *\n * `mount.ts` is the one file with a documented relationship to `packages/platform`; the rest\n * (`browser-engine.ts`, `browser-renderer.ts`, `dom-node.ts`, `elements.ts`, `props.ts`,\n * `responder.ts`) has no native equivalent to compare itself to, because on native that work is\n * `packages/fabric`'s, not `packages/platform`'s. This package folds both roles into one, since a\n * browser host has no separate native-module boundary to split them across.\n */\nexport { BrowserEngine } from './browser-engine.ts';\nexport { BrowserRenderer, type BrowserRendererFactory } from './browser-renderer.ts';\nexport { nodeOf, pathTo, type BrowserNode, type BrowserNodeKind } from './dom-node.ts';\nexport { registerElementName, type ElementSpec } from './elements.ts';\nexport { NgNativeIsland, type IslandOutputHandler } from './island.ts';\nexport { mount, type MountOptions, type MountResult } from './mount.ts';\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * `<ng-native-island>`: an Angular Native component, placed in an ordinary Angular template.
3
+ *
4
+ * `<view>`, `<text>` and `<pressable>` cannot be written straight into a web app's own templates:
5
+ * an Angular app has one renderer, and a web app's is the DOM's, which does not know what a
6
+ * `<view>` is. This element is the boundary. It mounts the component inside it with
7
+ * `mount(element, component, { injector })`, so the component renders through this package's
8
+ * renderer while sharing the surrounding app's services and change detection - see `mount.ts`.
9
+ *
10
+ * ```html
11
+ * <ng-native-island
12
+ * [component]="Wallet"
13
+ * [inputs]="{ userId: user().id }"
14
+ * [outputs]="{ paid: onPaid }"
15
+ * />
16
+ * ```
17
+ *
18
+ * - `inputs` are by the component's public input names. A changed object is set on the mounted
19
+ * component, not remounted, so its state survives.
20
+ * - `outputs` map output names to handlers. A name the component has no output for throws,
21
+ * naming the ones it does have, rather than never firing.
22
+ * - Changing `component` destroys the old one and mounts the new one in its place.
23
+ * - The island goes when this element does: `@if`, a route change, or the host being destroyed.
24
+ */
25
+ import { type Type } from '@angular/core';
26
+ import * as i0 from "@angular/core";
27
+ /** A handler for one of the mounted component's outputs. */
28
+ export type IslandOutputHandler = (value: never) => void;
29
+ export declare class NgNativeIsland {
30
+ private readonly element;
31
+ private readonly injector;
32
+ /** The Angular Native component to mount. Changing it replaces the mounted one. */
33
+ readonly component: import("@angular/core").InputSignal<Type<unknown>>;
34
+ /** Its inputs, by public name. */
35
+ readonly inputs: import("@angular/core").InputSignal<Readonly<Record<string, unknown>>>;
36
+ /** Handlers for its outputs, by public name. */
37
+ readonly outputs: import("@angular/core").InputSignal<Readonly<Record<string, IslandOutputHandler>>>;
38
+ private island?;
39
+ private subscriptions;
40
+ constructor();
41
+ private subscribe;
42
+ private unsubscribe;
43
+ private unmount;
44
+ static ɵfac: i0.ɵɵFactoryDeclaration<NgNativeIsland, never>;
45
+ static ɵcmp: i0.ɵɵComponentDeclaration<NgNativeIsland, "ng-native-island", never, { "component": { "alias": "component"; "required": true; "isSignal": true; }; "inputs": { "alias": "inputs"; "required": false; "isSignal": true; }; "outputs": { "alias": "outputs"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
46
+ }
package/dist/island.js ADDED
@@ -0,0 +1,109 @@
1
+ /**
2
+ * `<ng-native-island>`: an Angular Native component, placed in an ordinary Angular template.
3
+ *
4
+ * `<view>`, `<text>` and `<pressable>` cannot be written straight into a web app's own templates:
5
+ * an Angular app has one renderer, and a web app's is the DOM's, which does not know what a
6
+ * `<view>` is. This element is the boundary. It mounts the component inside it with
7
+ * `mount(element, component, { injector })`, so the component renders through this package's
8
+ * renderer while sharing the surrounding app's services and change detection - see `mount.ts`.
9
+ *
10
+ * ```html
11
+ * <ng-native-island
12
+ * [component]="Wallet"
13
+ * [inputs]="{ userId: user().id }"
14
+ * [outputs]="{ paid: onPaid }"
15
+ * />
16
+ * ```
17
+ *
18
+ * - `inputs` are by the component's public input names. A changed object is set on the mounted
19
+ * component, not remounted, so its state survives.
20
+ * - `outputs` map output names to handlers. A name the component has no output for throws,
21
+ * naming the ones it does have, rather than never firing.
22
+ * - Changing `component` destroys the old one and mounts the new one in its place.
23
+ * - The island goes when this element does: `@if`, a route change, or the host being destroyed.
24
+ */
25
+ import { Component, DestroyRef, ElementRef, Injector, effect, inject, input, reflectComponentType, untracked, } from '@angular/core';
26
+ import { mount } from "./mount.js";
27
+ import * as i0 from "@angular/core";
28
+ export class NgNativeIsland {
29
+ element = inject(ElementRef).nativeElement;
30
+ injector = inject(Injector);
31
+ /** The Angular Native component to mount. Changing it replaces the mounted one. */
32
+ component = input.required(/* @ts-ignore */
33
+ ...(ngDevMode ? [{ debugName: "component" }] : /* istanbul ignore next */ []));
34
+ /** Its inputs, by public name. */
35
+ inputs = input({}, /* @ts-ignore */
36
+ ...(ngDevMode ? [{ debugName: "inputs" }] : /* istanbul ignore next */ []));
37
+ /** Handlers for its outputs, by public name. */
38
+ outputs = input({}, /* @ts-ignore */
39
+ ...(ngDevMode ? [{ debugName: "outputs" }] : /* istanbul ignore next */ []));
40
+ island;
41
+ subscriptions = [];
42
+ constructor() {
43
+ // Mount, or remount when the component changes. The inputs are read untracked here: they go
44
+ // in before the first render, and a later change is the next effect's job, not a remount.
45
+ effect(() => {
46
+ const component = this.component();
47
+ untracked(() => {
48
+ this.unmount();
49
+ this.island = mount(this.element, component, {
50
+ injector: this.injector,
51
+ inputs: this.inputs(),
52
+ });
53
+ });
54
+ });
55
+ // A changed input is set on the mounted component. Also runs after a remount, which is
56
+ // harmless: setting an input to the value it already has changes nothing.
57
+ effect(() => {
58
+ const inputs = this.inputs();
59
+ this.component();
60
+ untracked(() => {
61
+ for (const [name, value] of Object.entries(inputs)) {
62
+ this.island?.componentRef.setInput(name, value);
63
+ }
64
+ });
65
+ });
66
+ // The handlers, resubscribed whenever they or the component change.
67
+ effect(() => {
68
+ const outputs = this.outputs();
69
+ const component = this.component();
70
+ untracked(() => this.subscribe(component, outputs));
71
+ });
72
+ inject(DestroyRef).onDestroy(() => this.unmount());
73
+ }
74
+ subscribe(component, outputs) {
75
+ this.unsubscribe();
76
+ const instance = this.island?.componentRef.instance;
77
+ const declared = reflectComponentType(component)?.outputs ?? [];
78
+ for (const [name, handler] of Object.entries(outputs)) {
79
+ const output = declared.find((candidate) => candidate.templateName === name);
80
+ if (!output) {
81
+ const known = declared.map((candidate) => candidate.templateName).join(', ') || 'none';
82
+ throw new Error(`[angular-native] <ng-native-island>: ${component.name} has no output '${name}' ` +
83
+ `(its outputs: ${known}).`);
84
+ }
85
+ const emitter = instance[output.propName];
86
+ this.subscriptions.push(emitter.subscribe(handler));
87
+ }
88
+ }
89
+ unsubscribe() {
90
+ for (const subscription of this.subscriptions)
91
+ subscription.unsubscribe();
92
+ this.subscriptions = [];
93
+ }
94
+ unmount() {
95
+ this.unsubscribe();
96
+ this.island?.destroy();
97
+ this.island = undefined;
98
+ }
99
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NgNativeIsland, deps: [], target: i0.ɵɵFactoryTarget.Component });
100
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.0", type: NgNativeIsland, isStandalone: true, selector: "ng-native-island", inputs: { component: { classPropertyName: "component", publicName: "component", isSignal: true, isRequired: true, transformFunction: null }, inputs: { classPropertyName: "inputs", publicName: "inputs", isSignal: true, isRequired: false, transformFunction: null }, outputs: { classPropertyName: "outputs", publicName: "outputs", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: '', isInline: true });
101
+ }
102
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NgNativeIsland, decorators: [{
103
+ type: Component,
104
+ args: [{
105
+ selector: 'ng-native-island',
106
+ template: '',
107
+ }]
108
+ }], ctorParameters: () => [], propDecorators: { component: [{ type: i0.Input, args: [{ isSignal: true, alias: "component", required: true }] }], inputs: [{ type: i0.Input, args: [{ isSignal: true, alias: "inputs", required: false }] }], outputs: [{ type: i0.Input, args: [{ isSignal: true, alias: "outputs", required: false }] }] } });
109
+ //# sourceMappingURL=island.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"island.js","sourceRoot":"","sources":["../src/island.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * `<ng-native-island>`: an Angular Native component, placed in an ordinary Angular template.\n *\n * `<view>`, `<text>` and `<pressable>` cannot be written straight into a web app's own templates:\n * an Angular app has one renderer, and a web app's is the DOM's, which does not know what a\n * `<view>` is. This element is the boundary. It mounts the component inside it with\n * `mount(element, component, { injector })`, so the component renders through this package's\n * renderer while sharing the surrounding app's services and change detection - see `mount.ts`.\n *\n * ```html\n * <ng-native-island\n * [component]=\"Wallet\"\n * [inputs]=\"{ userId: user().id }\"\n * [outputs]=\"{ paid: onPaid }\"\n * />\n * ```\n *\n * - `inputs` are by the component's public input names. A changed object is set on the mounted\n * component, not remounted, so its state survives.\n * - `outputs` map output names to handlers. A name the component has no output for throws,\n * naming the ones it does have, rather than never firing.\n * - Changing `component` destroys the old one and mounts the new one in its place.\n * - The island goes when this element does: `@if`, a route change, or the host being destroyed.\n */\nimport {\n Component,\n DestroyRef,\n ElementRef,\n Injector,\n effect,\n inject,\n input,\n reflectComponentType,\n untracked,\n type OutputRefSubscription,\n type Type,\n} from '@angular/core';\nimport { mount, type MountResult } from './mount.ts';\n\n/** A handler for one of the mounted component's outputs. */\nexport type IslandOutputHandler = (value: never) => void;\n\ninterface Subscribable {\n subscribe(handler: (value: unknown) => void): OutputRefSubscription;\n}\n\n@Component({\n selector: 'ng-native-island',\n template: '',\n})\nexport class NgNativeIsland {\n private readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;\n private readonly injector = inject(Injector);\n\n /** The Angular Native component to mount. Changing it replaces the mounted one. */\n readonly component = input.required<Type<unknown>>();\n /** Its inputs, by public name. */\n readonly inputs = input<Readonly<Record<string, unknown>>>({});\n /** Handlers for its outputs, by public name. */\n readonly outputs = input<Readonly<Record<string, IslandOutputHandler>>>({});\n\n private island?: MountResult;\n private subscriptions: OutputRefSubscription[] = [];\n\n constructor() {\n // Mount, or remount when the component changes. The inputs are read untracked here: they go\n // in before the first render, and a later change is the next effect's job, not a remount.\n effect(() => {\n const component = this.component();\n untracked(() => {\n this.unmount();\n this.island = mount(this.element, component, {\n injector: this.injector,\n inputs: this.inputs(),\n });\n });\n });\n\n // A changed input is set on the mounted component. Also runs after a remount, which is\n // harmless: setting an input to the value it already has changes nothing.\n effect(() => {\n const inputs = this.inputs();\n this.component();\n untracked(() => {\n for (const [name, value] of Object.entries(inputs)) {\n this.island?.componentRef.setInput(name, value);\n }\n });\n });\n\n // The handlers, resubscribed whenever they or the component change.\n effect(() => {\n const outputs = this.outputs();\n const component = this.component();\n untracked(() => this.subscribe(component, outputs));\n });\n\n inject(DestroyRef).onDestroy(() => this.unmount());\n }\n\n private subscribe(\n component: Type<unknown>,\n outputs: Readonly<Record<string, IslandOutputHandler>>,\n ): void {\n this.unsubscribe();\n const instance = this.island?.componentRef.instance as Record<string, Subscribable>;\n const declared = reflectComponentType(component)?.outputs ?? [];\n for (const [name, handler] of Object.entries(outputs)) {\n const output = declared.find((candidate) => candidate.templateName === name);\n if (!output) {\n const known = declared.map((candidate) => candidate.templateName).join(', ') || 'none';\n throw new Error(\n `[angular-native] <ng-native-island>: ${component.name} has no output '${name}' ` +\n `(its outputs: ${known}).`,\n );\n }\n const emitter = instance[output.propName]!;\n this.subscriptions.push(emitter.subscribe(handler as (value: unknown) => void));\n }\n }\n\n private unsubscribe(): void {\n for (const subscription of this.subscriptions) subscription.unsubscribe();\n this.subscriptions = [];\n }\n\n private unmount(): void {\n this.unsubscribe();\n this.island?.destroy();\n this.island = undefined;\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare function installJsdomEnvironment(): {
2
+ document: Document;
3
+ window: Window;
4
+ };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * A browser environment for Node, so this package's tests can run with `node --test` rather than
3
+ * needing a real browser window. Ported from the prototype at
4
+ * `examples/web-button/src/jsdom-env.ts` (see the report for what that prototype found), which
5
+ * exists to be read rather than imported - this package cannot depend on an example.
6
+ *
7
+ * Two gaps jsdom leaves that this fills: it has no `ResizeObserver` at all, and no `PointerEvent`
8
+ * constructor with the pointer-specific fields (`pointerId`) or `setPointerCapture` on `Element`.
9
+ * Both are stubbed minimally - just enough for `BrowserEngine` to observe a size once and to run
10
+ * its pointer-based responder negotiation. Neither stub ships; it exists only for this test file.
11
+ */
12
+ import { JSDOM } from 'jsdom';
13
+ export function installJsdomEnvironment() {
14
+ const dom = new JSDOM('<!doctype html><html><body><div id="app-root"></div></body></html>', {
15
+ url: 'http://localhost/',
16
+ });
17
+ const window = dom.window;
18
+ class FakeResizeObserver {
19
+ callback;
20
+ constructor(callback) {
21
+ this.callback = callback;
22
+ }
23
+ observe(target) {
24
+ queueMicrotask(() => {
25
+ const rect = target.getBoundingClientRect();
26
+ this.callback([
27
+ {
28
+ target,
29
+ contentBoxSize: [{ inlineSize: rect.width, blockSize: rect.height }],
30
+ },
31
+ ], this);
32
+ });
33
+ }
34
+ unobserve() { }
35
+ disconnect() { }
36
+ }
37
+ if (!window.Element.prototype.setPointerCapture) {
38
+ window.Element.prototype.setPointerCapture = function () { };
39
+ window.Element.prototype.releasePointerCapture = function () { };
40
+ window.Element.prototype.hasPointerCapture = function () {
41
+ return false;
42
+ };
43
+ }
44
+ const globals = {
45
+ window,
46
+ document: window.document,
47
+ Node: window.Node,
48
+ Element: window.Element,
49
+ HTMLElement: window.HTMLElement,
50
+ Text: window.Text,
51
+ Comment: window.Comment,
52
+ Event: window.Event,
53
+ PointerEvent: window.PointerEvent ?? window.MouseEvent,
54
+ KeyboardEvent: window.KeyboardEvent,
55
+ CustomEvent: window.CustomEvent,
56
+ ResizeObserver: FakeResizeObserver,
57
+ Image: window.Image,
58
+ getComputedStyle: window.getComputedStyle.bind(window),
59
+ requestAnimationFrame: (cb) => window.setTimeout(() => cb(Date.now()), 0),
60
+ cancelAnimationFrame: (id) => window.clearTimeout(id),
61
+ };
62
+ for (const [key, value] of Object.entries(globals)) {
63
+ globalThis[key] = value;
64
+ }
65
+ return { document: window.document, window };
66
+ }
67
+ //# sourceMappingURL=jsdom-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdom-env.js","sourceRoot":"","sources":["../src/jsdom-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,MAAM,UAAU,uBAAuB;IACrC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,oEAAoE,EAAE;QAC1F,GAAG,EAAE,mBAAmB;KACzB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,GAAG,CAAC,MAA+C,CAAC;IAEnE,MAAM,kBAAkB;QACL,QAAQ,CAAyB;QAClD,YAAY,QAAgC;YAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC3B,CAAC;QACD,OAAO,CAAC,MAAe;YACrB,cAAc,CAAC,GAAG,EAAE;gBAClB,MAAM,IAAI,GAAG,MAAM,CAAC,qBAAqB,EAAE,CAAC;gBAC5C,IAAI,CAAC,QAAQ,CACX;oBACE;wBACE,MAAM;wBACN,cAAc,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;qBACnC;iBACpC,EACD,IAAiC,CAClC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,SAAS,KAAU,CAAC;QACpB,UAAU,KAAU,CAAC;KACtB;IAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC;QAChD,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,GAAG,cAAmB,CAAC,CAAC;QAClE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,qBAAqB,GAAG,cAAmB,CAAC,CAAC;QACtE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,GAAG;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAA4B;QACvC,MAAM;QACN,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,UAAU;QACtD,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,cAAc,EAAE,kBAAkB;QAClC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC;QACtD,qBAAqB,EAAE,CAAC,EAAwB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/F,oBAAoB,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;KAC9D,CAAC;IACF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClD,UAAsC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACvD,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * A browser environment for Node, so this package's tests can run with `node --test` rather than\n * needing a real browser window. Ported from the prototype at\n * `examples/web-button/src/jsdom-env.ts` (see the report for what that prototype found), which\n * exists to be read rather than imported - this package cannot depend on an example.\n *\n * Two gaps jsdom leaves that this fills: it has no `ResizeObserver` at all, and no `PointerEvent`\n * constructor with the pointer-specific fields (`pointerId`) or `setPointerCapture` on `Element`.\n * Both are stubbed minimally - just enough for `BrowserEngine` to observe a size once and to run\n * its pointer-based responder negotiation. Neither stub ships; it exists only for this test file.\n */\nimport { JSDOM } from 'jsdom';\n\nexport function installJsdomEnvironment(): { document: Document; window: Window } {\n const dom = new JSDOM('<!doctype html><html><body><div id=\"app-root\"></div></body></html>', {\n url: 'http://localhost/',\n });\n const window = dom.window as unknown as Window & typeof globalThis;\n\n class FakeResizeObserver {\n private readonly callback: ResizeObserverCallback;\n constructor(callback: ResizeObserverCallback) {\n this.callback = callback;\n }\n observe(target: Element): void {\n queueMicrotask(() => {\n const rect = target.getBoundingClientRect();\n this.callback(\n [\n {\n target,\n contentBoxSize: [{ inlineSize: rect.width, blockSize: rect.height }],\n } as unknown as ResizeObserverEntry,\n ],\n this as unknown as ResizeObserver,\n );\n });\n }\n unobserve(): void {}\n disconnect(): void {}\n }\n\n if (!window.Element.prototype.setPointerCapture) {\n window.Element.prototype.setPointerCapture = function (): void {};\n window.Element.prototype.releasePointerCapture = function (): void {};\n window.Element.prototype.hasPointerCapture = function (): boolean {\n return false;\n };\n }\n\n const globals: Record<string, unknown> = {\n window,\n document: window.document,\n Node: window.Node,\n Element: window.Element,\n HTMLElement: window.HTMLElement,\n Text: window.Text,\n Comment: window.Comment,\n Event: window.Event,\n PointerEvent: window.PointerEvent ?? window.MouseEvent,\n KeyboardEvent: window.KeyboardEvent,\n CustomEvent: window.CustomEvent,\n ResizeObserver: FakeResizeObserver,\n Image: window.Image,\n getComputedStyle: window.getComputedStyle.bind(window),\n requestAnimationFrame: (cb: FrameRequestCallback) => window.setTimeout(() => cb(Date.now()), 0),\n cancelAnimationFrame: (id: number) => window.clearTimeout(id),\n };\n for (const [key, value] of Object.entries(globals)) {\n (globalThis as Record<string, unknown>)[key] = value;\n }\n\n return { document: window.document, window };\n}\n"]}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Put an Angular application on a page.
3
+ *
4
+ * The browser counterpart to `@ng-native/platform`'s `mount()`, and named the same on
5
+ * purpose: an app imports one or the other, never both, and which one it gets is the import path's
6
+ * job to say rather than the identifier's. Reading the native one first is worth it - this follows
7
+ * its shape and its documented distinction
8
+ * between `ApplicationRef` and the root `ComponentRef` (`createComponent` resolves the latter;
9
+ * `applicationRef.components` needs it pushed by hand, the same bookkeeping
10
+ * `ApplicationRef.bootstrap()` would otherwise do, for the same reason - a routed app's initial
11
+ * navigation checks `applicationRef.components[0]` before it will run at all).
12
+ *
13
+ * What is different from the native `mount()`, and why:
14
+ *
15
+ * - **The first argument is a real `Element`, not a numeric root tag.** Fabric addresses its root
16
+ * by the tag React Native's host gave it; a browser page has no such number, only the element
17
+ * an app mounts into (`document.getElementById('app-root')`, or one `document.body` itself).
18
+ * - **No `FabricUIManager`, and no `Engine` provided under its own token.** Only `HostEngine` is
19
+ * provided. `worklet-style`, `worklet-scroll` and `native-gesture`
20
+ * `inject(Engine)` directly (see `packages/fabric/src/host.ts`'s doc comment for why that is
21
+ * the honest place to draw the line) - on native `Engine` is provided under both tokens so both
22
+ * paths resolve; here it is provided under neither, so an app that uses one of those three on
23
+ * the web gets Angular's own `NullInjectorError` at the point it tries to inject `Engine`,
24
+ * which names exactly what is unsupported rather than rendering something silently wrong.
25
+ * - **`DOCUMENT` is the real `document`**, not the stub the native `mount()` builds for
26
+ * `TransferState`'s
27
+ * `getElementById`. A browser host already has one.
28
+ * - **No dev-mode animation warning, no HMR reload hook.** The native check exists
29
+ * because `@angular/core` reads whether `animate.enter`/`animate.leave` do anything from a
30
+ * global a Metro polyfill has to set before `@angular/core` first evaluates; a real browser
31
+ * already has `document.documentElement.getAnimations`, which is the same thing that global
32
+ * stands in for on native, so there is nothing to warn about. The reload hook is Metro Fast
33
+ * Refresh's fallback path specifically; a browser dev server has its own, unrelated story for
34
+ * picking up an edit, so wiring `__angularNativeReload` here would install a hook nothing calls.
35
+ */
36
+ import { ApplicationRef, type ComponentRef, type EnvironmentProviders, type Injector, type Provider, type Type } from '@angular/core';
37
+ import { BrowserEngine } from './browser-engine.ts';
38
+ import { BrowserRendererFactory } from './browser-renderer.ts';
39
+ /**
40
+ * Injects `reset.css`'s content as a `<style>` in `document.head`, once per document. Idempotent,
41
+ * so an app free to call it itself (or to load `reset.css` through its own bundler instead, and
42
+ * pass `injectReset: false` to `mount`) never ends up with the rule twice.
43
+ */
44
+ export declare function injectResetStylesheet(document: Document): void;
45
+ /**
46
+ * The same for an island inside someone else's page: `ISLAND_RESET_CSS`, which leaves the host's
47
+ * `html` and `body` alone. Its own id, so it sits beside a full reset if the page has both kinds.
48
+ */
49
+ export declare function injectIslandResetStylesheet(document: Document): void;
50
+ export interface MountOptions {
51
+ readonly providers?: (Provider | EnvironmentProviders)[];
52
+ /**
53
+ * The component's inputs, by their public name, set before its first render - so an
54
+ * `input.required()` has its value from the start rather than throwing on the first check.
55
+ * Change them afterwards with `componentRef.setInput`.
56
+ */
57
+ readonly inputs?: Readonly<Record<string, unknown>>;
58
+ /**
59
+ * Injects the reset stylesheet into `document.head` before mounting. Defaults to `true`. With
60
+ * `injector` it is the island reset, which leaves the host page's `html` and `body` alone.
61
+ */
62
+ readonly injectReset?: boolean;
63
+ /**
64
+ * Mount inside an existing Angular app instead of as an app of its own: pass an injector from
65
+ * that app - `inject(Injector)` in the component that owns `rootElement` is the usual one.
66
+ *
67
+ * The island then shares the host app's services (anything `providedIn: 'root'`, and anything
68
+ * its `bootstrapApplication` or a component above it provides) and is checked by the host's
69
+ * change detection. Only what the island has to render differently is its own: the renderer,
70
+ * the engine, and the device services that read the browser rather than a phone. See
71
+ * `packages/web/islands.md` in the documentation.
72
+ */
73
+ readonly injector?: Injector;
74
+ }
75
+ export interface MountResult {
76
+ readonly componentRef: ComponentRef<unknown>;
77
+ /** The island's own app, or with `injector` the host app it was mounted into. */
78
+ readonly applicationRef: ApplicationRef;
79
+ readonly factory: BrowserRendererFactory;
80
+ readonly engine: BrowserEngine;
81
+ /**
82
+ * Takes the island down: its component, and whatever it owns. With `injector` that is only the
83
+ * island - the host app it was mounted into keeps running - so call this rather than
84
+ * `applicationRef.destroy()`, which there would destroy the host.
85
+ */
86
+ destroy(): void;
87
+ }
88
+ export declare function mount(rootElement: Element, component: Type<unknown>, options?: MountOptions): MountResult;
package/dist/mount.js ADDED
@@ -0,0 +1,240 @@
1
+ /**
2
+ * Put an Angular application on a page.
3
+ *
4
+ * The browser counterpart to `@ng-native/platform`'s `mount()`, and named the same on
5
+ * purpose: an app imports one or the other, never both, and which one it gets is the import path's
6
+ * job to say rather than the identifier's. Reading the native one first is worth it - this follows
7
+ * its shape and its documented distinction
8
+ * between `ApplicationRef` and the root `ComponentRef` (`createComponent` resolves the latter;
9
+ * `applicationRef.components` needs it pushed by hand, the same bookkeeping
10
+ * `ApplicationRef.bootstrap()` would otherwise do, for the same reason - a routed app's initial
11
+ * navigation checks `applicationRef.components[0]` before it will run at all).
12
+ *
13
+ * What is different from the native `mount()`, and why:
14
+ *
15
+ * - **The first argument is a real `Element`, not a numeric root tag.** Fabric addresses its root
16
+ * by the tag React Native's host gave it; a browser page has no such number, only the element
17
+ * an app mounts into (`document.getElementById('app-root')`, or one `document.body` itself).
18
+ * - **No `FabricUIManager`, and no `Engine` provided under its own token.** Only `HostEngine` is
19
+ * provided. `worklet-style`, `worklet-scroll` and `native-gesture`
20
+ * `inject(Engine)` directly (see `packages/fabric/src/host.ts`'s doc comment for why that is
21
+ * the honest place to draw the line) - on native `Engine` is provided under both tokens so both
22
+ * paths resolve; here it is provided under neither, so an app that uses one of those three on
23
+ * the web gets Angular's own `NullInjectorError` at the point it tries to inject `Engine`,
24
+ * which names exactly what is unsupported rather than rendering something silently wrong.
25
+ * - **`DOCUMENT` is the real `document`**, not the stub the native `mount()` builds for
26
+ * `TransferState`'s
27
+ * `getElementById`. A browser host already has one.
28
+ * - **No dev-mode animation warning, no HMR reload hook.** The native check exists
29
+ * because `@angular/core` reads whether `animate.enter`/`animate.leave` do anything from a
30
+ * global a Metro polyfill has to set before `@angular/core` first evaluates; a real browser
31
+ * already has `document.documentElement.getAnimations`, which is the same thing that global
32
+ * stands in for on native, so there is nothing to warn about. The reload hook is Metro Fast
33
+ * Refresh's fallback path specifically; a browser dev server has its own, unrelated story for
34
+ * picking up an edit, so wiring `__angularNativeReload` here would install a hook nothing calls.
35
+ */
36
+ import { APP_BOOTSTRAP_LISTENER, ApplicationRef, DOCUMENT, PLATFORM_ID, EnvironmentInjector, ErrorHandler, RendererFactory2, createComponent, createEnvironmentInjector, ɵcreateOrReusePlatformInjector as createOrReusePlatformInjector, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵprovideZonelessChangeDetectionInternal as provideZonelessChangeDetectionInternal, } from '@angular/core';
37
+ import { HostEngine } from '@ng-native/fabric';
38
+ import { ColorScheme, Direction, HardwareBack, Screen, StatusBar } from '@ng-native/device';
39
+ import { browserColorSchemeSource, browserDirectionSource, browserScreenSource, } from "./device-sources.js";
40
+ import { BrowserEngine } from "./browser-engine.js";
41
+ import { BrowserRendererFactory } from "./browser-renderer.js";
42
+ import { ISLAND_RESET_CSS, RESET_CSS } from "./reset-css.js";
43
+ const RESET_STYLE_ID = 'angular-native-web-reset';
44
+ const ISLAND_RESET_STYLE_ID = 'angular-native-web-island-reset';
45
+ /**
46
+ * Injects `reset.css`'s content as a `<style>` in `document.head`, once per document. Idempotent,
47
+ * so an app free to call it itself (or to load `reset.css` through its own bundler instead, and
48
+ * pass `injectReset: false` to `mount`) never ends up with the rule twice.
49
+ */
50
+ export function injectResetStylesheet(document) {
51
+ injectStyle(document, RESET_STYLE_ID, RESET_CSS);
52
+ }
53
+ /**
54
+ * The same for an island inside someone else's page: `ISLAND_RESET_CSS`, which leaves the host's
55
+ * `html` and `body` alone. Its own id, so it sits beside a full reset if the page has both kinds.
56
+ */
57
+ export function injectIslandResetStylesheet(document) {
58
+ injectStyle(document, ISLAND_RESET_STYLE_ID, ISLAND_RESET_CSS);
59
+ }
60
+ function injectStyle(document, id, css) {
61
+ if (document.getElementById(id))
62
+ return;
63
+ const style = document.createElement('style');
64
+ style.id = id;
65
+ // In Tailwind's `base` layer, below every utility, as `@import '@ng-native/web/reset.css'
66
+ // layer(base)` puts it. Injected unlayered after the app's stylesheet, a reset rule is as
67
+ // specific as a class and later, so it beat `border-2`, `flex-row` and `hidden` alike. With no
68
+ // Tailwind on the page, a layered rule still loses to every unlayered one, as a reset should.
69
+ style.textContent = `@layer base {\n${css}\n}`;
70
+ // First in the head: a layer is ordered by where it is first declared, and the documented entry
71
+ // (theme.css and utilities.css) declares no `base`. Declared after it, `base` came after
72
+ // `utilities` and beat every utility again.
73
+ document.head.insertBefore(style, document.head.firstChild);
74
+ }
75
+ export function mount(rootElement, component, options = {}) {
76
+ const { providers: extraProviders = [], inputs = {}, injectReset = true, injector: host, } = options;
77
+ const document = rootElement.ownerDocument;
78
+ if (injectReset) {
79
+ if (host)
80
+ injectIslandResetStylesheet(document);
81
+ else
82
+ injectResetStylesheet(document);
83
+ }
84
+ // What `reset.css` hangs the root's height off. Stamped rather than required of the app,
85
+ // because an app that forgot it would get a page whose `flex: 1` silently resolved to zero.
86
+ rootElement.setAttribute('data-rn-root', '');
87
+ // What `@ng-native/tailwind`'s `web:` variant matches beneath, as `platform-ios` does on a phone.
88
+ rootElement.classList.add('platform-web');
89
+ const engine = new BrowserEngine(document);
90
+ const factory = new BrowserRendererFactory(engine, document);
91
+ const rootNode = engine.wrapRoot(rootElement);
92
+ const own = hostProviders(engine, factory, document.defaultView);
93
+ const mounted = host
94
+ ? mountInside(host, rootElement, rootNode, component, [...own, ...extraProviders], inputs, {
95
+ factory,
96
+ engine,
97
+ })
98
+ : mountAlone(rootNode, component, [...own, ...extraProviders], inputs, document, {
99
+ factory,
100
+ engine,
101
+ });
102
+ // The engine listens on the whole document, so it has to stop once its app is gone, however
103
+ // the app went: through `destroy()` or straight through the component ref.
104
+ mounted.componentRef.onDestroy(() => engine.dispose());
105
+ return mounted;
106
+ }
107
+ /**
108
+ * What an island has to have of its own, whichever way it is mounted: the renderer and engine
109
+ * that turn `<view>` into a `<div>`, and the device capabilities answered by the browser.
110
+ */
111
+ function hostProviders(engine, factory, view) {
112
+ return [
113
+ { provide: RendererFactory2, useValue: factory },
114
+ // The one seam the shared packages inject. See the file doc for why `Engine` itself is not
115
+ // also provided here.
116
+ { provide: HostEngine, useValue: engine },
117
+ // The device capabilities, from the browser rather than from React Native. Without these
118
+ // `Screen` falls back to its off-device answer of a zero-sized window, and every component
119
+ // that branches on `compact()` takes the phone tree. See `device-sources.ts`.
120
+ ...(view
121
+ ? [
122
+ { provide: Screen.SOURCE, useValue: browserScreenSource(view) },
123
+ { provide: ColorScheme.SOURCE, useValue: browserColorSchemeSource(view) },
124
+ { provide: Direction.SOURCE, useValue: browserDirectionSource(view) },
125
+ ]
126
+ : []),
127
+ // A tab has no hardware back button, so this is the same inert fallback
128
+ // `hardwareBackSource()`'s own off-device branch answers with - provided directly rather
129
+ // than left to reach it, because its guard is `typeof require === 'function'`, and a
130
+ // bundler that externalises `react-native` for the browser (`rollupOptions.external` in a
131
+ // production build) leaves `require` defined as a stub that throws when called rather than
132
+ // absent. `HardwareBack` is the one of these five capabilities an anchored overlay actually
133
+ // constructs - `Overlay`'s dismiss-on-back wiring injects it - so it is the one this had to
134
+ // stop before reaching that guard at all.
135
+ { provide: HardwareBack.SOURCE, useValue: { subscribe: () => () => { } } },
136
+ // A tab has no status bar either, and for the same reason this cannot be left to
137
+ // `statusBarSource()`: an app that asks for dark icons over a light screen is ordinary, and
138
+ // without this its component throws on that stub and never renders.
139
+ {
140
+ provide: StatusBar.SOURCE,
141
+ useValue: {
142
+ setStyle: () => { },
143
+ setHidden: () => { },
144
+ setBackgroundColor: () => { },
145
+ setTranslucent: () => { },
146
+ height: undefined,
147
+ },
148
+ },
149
+ ];
150
+ }
151
+ /** An app of its own: its own root injector, change detection and `ApplicationRef`. */
152
+ function mountAlone(rootNode, component, providers, inputs, document, host) {
153
+ // Parent the app injector to the platform injector, exactly as `internalCreateApplication`
154
+ // does and `mount()` documents: some Angular services are `providedIn: 'platform'`, and with a
155
+ // null parent they simply do not exist.
156
+ const platformInjector = createOrReusePlatformInjector();
157
+ const injector = createEnvironmentInjector([
158
+ { provide: INJECTOR_SCOPE, useValue: 'root' },
159
+ provideZonelessChangeDetectionInternal(),
160
+ { provide: DOCUMENT, useValue: document },
161
+ // A DOM is what this is running in, so libraries that check isPlatformBrowser() are right to
162
+ // use it. An island inside an app is the app's own and inherits its value instead.
163
+ { provide: PLATFORM_ID, useValue: 'browser' },
164
+ { provide: ErrorHandler, useClass: ErrorHandler },
165
+ ...providers,
166
+ ], platformInjector);
167
+ const componentRef = createComponent(component, {
168
+ environmentInjector: injector,
169
+ hostElement: rootNode,
170
+ });
171
+ setInputs(componentRef, inputs);
172
+ const applicationRef = injector.get(ApplicationRef);
173
+ // Mirrors `ApplicationRef.bootstrap()`, which is not used directly because it wants a DOM
174
+ // selector rather than an element `mount`'s own caller already resolved.
175
+ applicationRef.componentTypes.push(component);
176
+ applicationRef.attachView(componentRef.hostView);
177
+ applicationRef.tick();
178
+ // Load-bearing, not bookkeeping: the router's bootstrap listener returns early unless the ref
179
+ // it is handed is `ApplicationRef.components[0]`.
180
+ applicationRef.components.push(componentRef);
181
+ componentRef.onDestroy(() => {
182
+ applicationRef.detachView(componentRef.hostView);
183
+ const at = applicationRef.components.indexOf(componentRef);
184
+ if (at !== -1)
185
+ applicationRef.components.splice(at, 1);
186
+ });
187
+ for (const listener of injector.get(APP_BOOTSTRAP_LISTENER, [])) {
188
+ listener(componentRef);
189
+ }
190
+ return {
191
+ componentRef,
192
+ applicationRef,
193
+ ...host,
194
+ destroy: () => {
195
+ componentRef.destroy();
196
+ applicationRef.destroy();
197
+ },
198
+ };
199
+ }
200
+ /**
201
+ * An island inside a running app. Its environment injector is a child of the host's, without a
202
+ * root scope of its own, so anything it does not provide - a `providedIn: 'root'` service, the
203
+ * host's `ApplicationRef` and scheduler, its `ErrorHandler` - resolves from the host, once, for
204
+ * both. What it does provide is only what has to differ: the renderer and engine, the browser's
205
+ * device sources, and the five device services that read them. Those five are provided here as
206
+ * classes so they are built in the island, against its sources, rather than in the host's root
207
+ * against the phone defaults.
208
+ *
209
+ * The host's element injector goes in too, so a service a component above the island provides
210
+ * is visible to it as well as one the app does.
211
+ */
212
+ function mountInside(hostInjector, rootElement, rootNode, component, providers, inputs, host) {
213
+ const injector = createEnvironmentInjector([Screen, ColorScheme, Direction, HardwareBack, StatusBar, ...providers], hostInjector.get(EnvironmentInjector));
214
+ const componentRef = createComponent(component, {
215
+ environmentInjector: injector,
216
+ elementInjector: hostInjector,
217
+ hostElement: rootNode,
218
+ });
219
+ setInputs(componentRef, inputs);
220
+ // The host's own change detection checks the island from here on, like any view of its own.
221
+ const applicationRef = hostInjector.get(ApplicationRef);
222
+ applicationRef.attachView(componentRef.hostView);
223
+ componentRef.changeDetectorRef.detectChanges();
224
+ return {
225
+ componentRef,
226
+ applicationRef,
227
+ ...host,
228
+ destroy: () => {
229
+ componentRef.destroy();
230
+ injector.destroy();
231
+ rootElement.removeAttribute('data-rn-root');
232
+ rootElement.classList.remove('platform-web');
233
+ },
234
+ };
235
+ }
236
+ function setInputs(componentRef, inputs) {
237
+ for (const [name, value] of Object.entries(inputs))
238
+ componentRef.setInput(name, value);
239
+ }
240
+ //# sourceMappingURL=mount.js.map