@ng-native/web 0.10.0 → 0.12.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.
@@ -22,7 +22,7 @@
22
22
  * would read whatever was there before Angular's *first* style write, forever.
23
23
  */
24
24
  import { RendererStyleFlags2, ViewEncapsulation, type Renderer2, type RendererFactory2 } from '@angular/core';
25
- import type { BrowserNode } from './dom-node.ts';
25
+ import { type BrowserNode } from './dom-node.ts';
26
26
  import type { BrowserEngine } from './browser-engine.ts';
27
27
  export declare class BrowserRenderer implements Renderer2 {
28
28
  readonly data: Record<string, unknown>;
@@ -23,6 +23,7 @@
23
23
  */
24
24
  import { RendererStyleFlags2, ViewEncapsulation, } from '@angular/core';
25
25
  import { reportUnboundFormsInput } from '@ng-native/fabric';
26
+ import { letBrowserNodesPassAsNodes } from "./dom-node.js";
26
27
  import { dashCase } from "./css-units.js";
27
28
  import { writeStyleKey } from "./native-style.js";
28
29
  /** `(touchEnd)` -> `topTouchEnd`. No alias for `press`; see `packages/platform/src/adapter.ts`. */
@@ -254,6 +255,7 @@ export class BrowserRendererFactory {
254
255
  this.engine = engine;
255
256
  this.document = document;
256
257
  this.renderer = new BrowserRenderer(engine, document);
258
+ letBrowserNodesPassAsNodes();
257
259
  }
258
260
  /**
259
261
  * One shared renderer for every component without styles of its own, and one per component
@@ -1 +1 @@
1
- {"version":3,"file":"browser-renderer.js","sourceRoot":"","sources":["../src/browser-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,mGAAmG;AACnG,SAAS,YAAY,CAAC,SAAiB;IAC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C,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;YACrE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,IAAI;YAAE,QAAQ,CAAC,WAAW,CAAC,IAAmB,CAAC,CAAC;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,SAAS,CAAC,EAAU,EAAE,MAAyB;QACrD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO;QAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACnD,KAAK,CAAC,YAAY,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC;QACnD,KAAK,CAAC,WAAW,GAAG,MAAM;aACvB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;aAC1E,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["/**\n * `Renderer2`/`RendererFactory2` over `BrowserEngine`, the browser counterpart to\n * `packages/platform/src/adapter.ts`'s `NativeRenderer`/`NativeRendererFactory`.\n *\n * Much smaller than that file, and for the reason its own doc comment gives: a real DOM already\n * does attribute, class and style writes, and there is no style resolver here at all - the class\n * strings Angular writes with `addClass`/`removeClass` are matched by a real stylesheet loaded\n * into the page, the way they would be in any other Angular app. What is not smaller is\n * `setProperty`/`setAttribute`: those still delegate to `BrowserEngine.setProp`, not to a raw DOM\n * write, because a component's own host bindings (`text-input.ts`'s forty-odd, `switch.ts`'s\n * handful) are *logical* props with a translation `props.ts` owns - exactly the reason\n * `NativeRenderer.setProperty` delegates to `engine.setProp` rather than writing a native prop\n * directly. `class` and `style` are the two genuine exceptions, because a browser's own cascade is\n * what resolves them and nothing here needs to get in front of that.\n *\n * `setStyle`/`removeStyle` do one thing beyond the real DOM write: they keep `node.props['style']`\n * in sync as a plain object, mirroring `NativeRenderer`'s own `OWN_STYLES`-owned-object trick.\n * Three components read `this.node.props['style']` directly rather than going through the\n * engine - `touchable-opacity.ts` (the resting opacity a fade eases back to),\n * `image-background.ts` (the outer view's width/height, copied onto the absolutely-filled\n * image), `animated-style.ts` (the style an animation frame merges into) - and without this they\n * would read whatever was there before Angular's *first* style write, forever.\n */\nimport {\n RendererStyleFlags2,\n ViewEncapsulation,\n type Renderer2,\n type RendererFactory2,\n} from '@angular/core';\nimport { reportUnboundFormsInput } from '@ng-native/fabric';\nimport type { BrowserNode } from './dom-node.ts';\nimport type { BrowserEngine } from './browser-engine.ts';\nimport { dashCase } from './css-units.ts';\nimport { writeStyleKey } from './native-style.ts';\n\n/** `(touchEnd)` -> `topTouchEnd`. No alias for `press`; see `packages/platform/src/adapter.ts`. */\nfunction topLevelType(eventName: string): string {\n return 'top' + eventName.charAt(0).toUpperCase() + eventName.slice(1);\n}\n\n/** The style objects this renderer made, and may therefore mutate in place. See the file doc. */\nconst OWN_STYLES = new WeakSet<object>();\n\nexport class BrowserRenderer implements Renderer2 {\n readonly data: Record<string, unknown> = Object.create(null);\n /** Nothing here needs teardown beyond garbage collection; matches the native adapter's null. */\n readonly destroyNode: ((node: unknown) => void) | null = null;\n\n private readonly engine: BrowserEngine;\n private readonly document: Document;\n\n constructor(engine: BrowserEngine, document: Document) {\n this.engine = engine;\n this.document = document;\n }\n\n destroy(): void {}\n\n createElement(name: string): BrowserNode {\n return this.engine.createElementNode(name);\n }\n\n createComment(): BrowserNode {\n return this.engine.createAnchorNode();\n }\n\n createText(value: string): BrowserNode {\n return this.engine.createTextNode(value);\n }\n\n appendChild(parent: BrowserNode, child: BrowserNode): void {\n this.detach(child);\n child.parent = parent;\n parent.children.push(child);\n (parent.el as Element).appendChild(child.el);\n }\n\n insertBefore(parent: BrowserNode, child: BrowserNode, refChild: BrowserNode | null): void {\n if (!parent) return;\n this.detach(child);\n child.parent = parent;\n const at = refChild ? parent.children.indexOf(refChild) : -1;\n if (at === -1) parent.children.push(child);\n else parent.children.splice(at, 0, child);\n (parent.el as Element).insertBefore(child.el, refChild?.el ?? null);\n }\n\n removeChild(parent: BrowserNode | null, child: BrowserNode): void {\n // Angular removes a root component's host element when the component is destroyed. Here that\n // element is the one `mount` was given - a `<div>` of the caller's, or an `<ng-native-island>`\n // in a host app's template - and it is not this app's to take out of the page. What was\n // rendered into it goes; the element stays, empty, for its owner.\n if (this.engine.isRoot(child)) {\n for (const node of [...child.children]) this.removeChild(child, node);\n // A root is always an element: `wrapRoot` only ever wraps one.\n (child.el as Element).replaceChildren();\n return;\n }\n const actualParent = parent ?? child.parent;\n if (actualParent) {\n const at = actualParent.children.indexOf(child);\n if (at !== -1) actualParent.children.splice(at, 1);\n }\n child.el.parentNode?.removeChild(child.el);\n child.parent = null;\n }\n\n private detach(child: BrowserNode): void {\n if (child.parent) this.removeChild(child.parent, child);\n }\n\n selectRootElement(selectorOrNode: string | BrowserNode): BrowserNode {\n if (typeof selectorOrNode !== 'string') return selectorOrNode;\n const found = this.document.querySelector(selectorOrNode);\n if (!found) throw new Error(`BrowserRenderer: no element matches '${selectorOrNode}'`);\n found.textContent = '';\n return this.engine.wrapRoot(found);\n }\n\n parentNode(node: BrowserNode): BrowserNode | null {\n return node.parent;\n }\n\n nextSibling(node: BrowserNode): BrowserNode | null {\n const siblings = node.parent?.children;\n if (!siblings) return null;\n return siblings[siblings.indexOf(node) + 1] ?? null;\n }\n\n setAttribute(node: BrowserNode, name: string, value: string): void {\n // `class` drives real CSS selector matching; nothing about it goes through `props.ts`.\n //\n // `setAttribute('class', ...)`, not `.className =`: an SVG element's `className` is a\n // read-only `SVGAnimatedString` - only `.baseVal` is writable - so a direct assignment throws\n // in strict mode (every file in this package is a module, so every file is strict mode).\n // `setAttribute` is the one spelling that commits a class list on both an `HTMLElement` and\n // an `SVGElement`, which is what a static `class=\"...\"` on an icon's `<svg>`/`<path>` needs -\n // found by every test that opens a dialog with its default close button, an icon with a\n // static class the compiler writes through this exact path.\n if (name === 'class') {\n (node.el as Element).setAttribute('class', value);\n return;\n }\n this.engine.setProp(node, name, value);\n }\n\n removeAttribute(node: BrowserNode, name: string): void {\n if (name === 'class') {\n (node.el as Element).removeAttribute('class');\n return;\n }\n this.engine.setProp(node, name, null);\n }\n\n addClass(node: BrowserNode, name: string): void {\n (node.el as Element).classList.add(name);\n }\n\n removeClass(node: BrowserNode, name: string): void {\n (node.el as Element).classList.remove(name);\n }\n\n setStyle(node: BrowserNode, style: string, value: unknown, flags?: RendererStyleFlags2): void {\n if (value === null || value === undefined) {\n this.removeStyle(node, style);\n return;\n }\n const key = styleName(style);\n const important = !!(flags && flags & RendererStyleFlags2.Important);\n this.mirrorStyle(node, key, value);\n this.writeStyle(node, key, important ? 'important' : '');\n }\n\n removeStyle(node: BrowserNode, style: string): void {\n const key = styleName(style);\n this.mirrorStyle(node, key, undefined);\n this.writeStyle(node, key, '');\n }\n\n /** From the mirror, which is the whole style: see `native-style.ts` for why one key needs it. */\n private writeStyle(node: BrowserNode, key: string, priority: string): void {\n const style = (node.props['style'] ?? {}) as Record<string, unknown>;\n writeStyleKey((node.el as HTMLElement).style, key, style, priority);\n }\n\n /** Keeps `node.props['style']` an accurate mirror of the real inline style. See the file doc. */\n private mirrorStyle(node: BrowserNode, key: string, value: unknown): void {\n const current = node.props['style'] as Record<string, unknown> | undefined;\n if (current && OWN_STYLES.has(current)) {\n if (value === undefined) delete current[key];\n else current[key] = value;\n return;\n }\n if (value === undefined && (!current || !(key in current))) return;\n const next = { ...current };\n if (value === undefined) delete next[key];\n else next[key] = value;\n OWN_STYLES.add(next);\n node.props['style'] = next;\n }\n\n setProperty(node: BrowserNode, name: string, value: unknown): void {\n // `ngDevMode`, not a build-time flag: this package ships to a browser bundler rather than\n // through Metro, so there is no `__DEV__` to fold away - `ngDevMode` is the one dev/release\n // signal Angular itself sets the same way here as it does natively. See\n // `packages/platform/src/adapter.ts`'s `NativeRenderer.setProperty` for the native check this\n // mirrors, and `@ng-native/fabric`'s `forms-inputs.ts` for the table and report both share.\n if (typeof ngDevMode !== 'undefined' && ngDevMode)\n reportUnboundFormsInput(this.engine, node, name);\n this.engine.setProp(node, name, value);\n }\n\n setValue(node: BrowserNode, value: string): void {\n node.text = value;\n (node.el as Text).data = value;\n }\n\n listen(\n target: BrowserNode,\n eventName: string,\n callback: (event: unknown) => boolean | void,\n ): () => void {\n return this.engine.setEventListener(target, topLevelType(eventName), callback);\n }\n}\n\n/**\n * A component with emulated encapsulation: every element its template creates carries\n * `_ngcontent-<id>`, and its host carries `_nghost-<id>`, which is what the selectors Angular's\n * compiler rewrote (`.card[_ngcontent-%COMP%]`, `[_nghost-%COMP%]`) match. These are the\n * attributes `@angular/platform-browser`'s own emulated renderer writes, so a component's CSS is\n * scoped here exactly as in any other Angular app - and as on a device, where a component's\n * renderer only ever matches its own elements against its own sheet.\n */\nclass EmulatedRenderer extends BrowserRenderer {\n private readonly contentAttr: string;\n private readonly hostAttr: string;\n\n constructor(engine: BrowserEngine, document: Document, id: string) {\n super(engine, document);\n this.contentAttr = `_ngcontent-${id}`;\n this.hostAttr = `_nghost-${id}`;\n }\n\n applyToHost(host: BrowserNode): void {\n if (host.kind === 'element') (host.el as Element).setAttribute(this.hostAttr, '');\n }\n\n override createElement(name: string): BrowserNode {\n const node = super.createElement(name);\n (node.el as Element).setAttribute(this.contentAttr, '');\n return node;\n }\n}\n\n/** The slice of Angular's component definition `createRenderer` is handed that matters here. */\ninterface ComponentDefLike {\n readonly id: string;\n readonly styles?: readonly string[];\n readonly encapsulation?: ViewEncapsulation;\n}\n\n/** The placeholder Angular's compiler writes into scoped selectors, for the renderer to resolve. */\nconst COMPONENT_ID = /%COMP%/g;\n\n/**\n * The placeholder Angular 22's compiler writes into every custom property in a component's\n * styles, `--%NS%tint`, for a renderer to fill with the app's CSS variable namespace. This host\n * has no namespace, as platform-browser has none by default, so it is filled with nothing: left\n * in, `var(--tint)` never finds `--%NS%tint` and every custom property silently does nothing.\n */\nconst CSS_VAR_NAMESPACE = /%NS%/g;\n\n/**\n * The property a style binding names. A bound custom property, `[style.--tint]`, arrives with the\n * same placeholder as `--%NS%tint`, filled with nothing for the same reason, and keeps its case:\n * `--brandTint` and `--brand-tint` are two different properties.\n */\nfunction styleName(style: string): string {\n return style.startsWith('--') ? style.replace(CSS_VAR_NAMESPACE, '') : dashCase(style);\n}\n\nexport class BrowserRendererFactory implements RendererFactory2 {\n private readonly renderer: BrowserRenderer;\n /** One renderer per component with scoped styles, because each stamps its own attribute. */\n private readonly byComponent = new Map<string, EmulatedRenderer>();\n /** Component ids whose stylesheet is already in the document. */\n private readonly styled = new Set<string>();\n private readonly document: Document;\n readonly engine: BrowserEngine;\n\n constructor(engine: BrowserEngine, document: Document) {\n this.engine = engine;\n this.document = document;\n this.renderer = new BrowserRenderer(engine, document);\n }\n\n /**\n * One shared renderer for every component without styles of its own, and one per component\n * with them. A component's `styles` go into the document once, the first time it renders, with\n * the compiler's `%COMP%` placeholder resolved to its id. `ViewEncapsulation.None` adds them as\n * written and needs no attributes. Shadow DOM encapsulation is treated as emulated: a native\n * view has no shadow root either, and emulated scoping is what the device's matcher does.\n *\n * The compiler already turns `Emulated` into `None` for a component with no styles, so the\n * shared renderer is still what nearly every component here gets.\n */\n createRenderer(host: unknown, type: ComponentDefLike | null): Renderer2 {\n if (!type?.styles?.length) return this.renderer;\n this.addStyles(type.id, type.styles);\n if (type.encapsulation === ViewEncapsulation.None) return this.renderer;\n\n let renderer = this.byComponent.get(type.id);\n if (!renderer) {\n renderer = new EmulatedRenderer(this.engine, this.document, type.id);\n this.byComponent.set(type.id, renderer);\n }\n if (host) renderer.applyToHost(host as BrowserNode);\n return renderer;\n }\n\n private addStyles(id: string, styles: readonly string[]): void {\n if (this.styled.has(id)) return;\n this.styled.add(id);\n const style = this.document.createElement('style');\n style.setAttribute('data-ng-native-component', id);\n style.textContent = styles\n .map((css) => css.replace(COMPONENT_ID, id).replace(CSS_VAR_NAMESPACE, ''))\n .join('\\n');\n this.document.head.appendChild(style);\n }\n}\n"]}
1
+ {"version":3,"file":"browser-renderer.js","sourceRoot":"","sources":["../src/browser-renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAGlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,0BAA0B,EAAoB,MAAM,eAAe,CAAC;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,mGAAmG;AACnG,SAAS,YAAY,CAAC,SAAiB;IACrC,OAAO,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,GAAG,IAAI,OAAO,EAAU,CAAC;AAEzC,MAAM,OAAO,eAAe;IACjB,IAAI,GAA4B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC7D,gGAAgG;IACvF,WAAW,GAAqC,IAAI,CAAC;IAE7C,MAAM,CAAgB;IACtB,QAAQ,CAAW;IAEpC,YAAY,MAAqB,EAAE,QAAkB;QACnD,IAA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SAAS,CAAC,EAAU,EAAE,MAAyB;QACrD,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO;QAChC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACnD,KAAK,CAAC,YAAY,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC;QACnD,KAAK,CAAC,WAAW,GAAG,MAAM;aACvB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;aAC1E,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["/**\n * `Renderer2`/`RendererFactory2` over `BrowserEngine`, the browser counterpart to\n * `packages/platform/src/adapter.ts`'s `NativeRenderer`/`NativeRendererFactory`.\n *\n * Much smaller than that file, and for the reason its own doc comment gives: a real DOM already\n * does attribute, class and style writes, and there is no style resolver here at all - the class\n * strings Angular writes with `addClass`/`removeClass` are matched by a real stylesheet loaded\n * into the page, the way they would be in any other Angular app. What is not smaller is\n * `setProperty`/`setAttribute`: those still delegate to `BrowserEngine.setProp`, not to a raw DOM\n * write, because a component's own host bindings (`text-input.ts`'s forty-odd, `switch.ts`'s\n * handful) are *logical* props with a translation `props.ts` owns - exactly the reason\n * `NativeRenderer.setProperty` delegates to `engine.setProp` rather than writing a native prop\n * directly. `class` and `style` are the two genuine exceptions, because a browser's own cascade is\n * what resolves them and nothing here needs to get in front of that.\n *\n * `setStyle`/`removeStyle` do one thing beyond the real DOM write: they keep `node.props['style']`\n * in sync as a plain object, mirroring `NativeRenderer`'s own `OWN_STYLES`-owned-object trick.\n * Three components read `this.node.props['style']` directly rather than going through the\n * engine - `touchable-opacity.ts` (the resting opacity a fade eases back to),\n * `image-background.ts` (the outer view's width/height, copied onto the absolutely-filled\n * image), `animated-style.ts` (the style an animation frame merges into) - and without this they\n * would read whatever was there before Angular's *first* style write, forever.\n */\nimport {\n RendererStyleFlags2,\n ViewEncapsulation,\n type Renderer2,\n type RendererFactory2,\n} from '@angular/core';\nimport { reportUnboundFormsInput } from '@ng-native/fabric';\nimport { letBrowserNodesPassAsNodes, type BrowserNode } from './dom-node.ts';\nimport type { BrowserEngine } from './browser-engine.ts';\nimport { dashCase } from './css-units.ts';\nimport { writeStyleKey } from './native-style.ts';\n\n/** `(touchEnd)` -> `topTouchEnd`. No alias for `press`; see `packages/platform/src/adapter.ts`. */\nfunction topLevelType(eventName: string): string {\n return 'top' + eventName.charAt(0).toUpperCase() + eventName.slice(1);\n}\n\n/** The style objects this renderer made, and may therefore mutate in place. See the file doc. */\nconst OWN_STYLES = new WeakSet<object>();\n\nexport class BrowserRenderer implements Renderer2 {\n readonly data: Record<string, unknown> = Object.create(null);\n /** Nothing here needs teardown beyond garbage collection; matches the native adapter's null. */\n readonly destroyNode: ((node: unknown) => void) | null = null;\n\n private readonly engine: BrowserEngine;\n private readonly document: Document;\n\n constructor(engine: BrowserEngine, document: Document) {\n this.engine = engine;\n this.document = document;\n }\n\n destroy(): void {}\n\n createElement(name: string): BrowserNode {\n return this.engine.createElementNode(name);\n }\n\n createComment(): BrowserNode {\n return this.engine.createAnchorNode();\n }\n\n createText(value: string): BrowserNode {\n return this.engine.createTextNode(value);\n }\n\n appendChild(parent: BrowserNode, child: BrowserNode): void {\n this.detach(child);\n child.parent = parent;\n parent.children.push(child);\n (parent.el as Element).appendChild(child.el);\n }\n\n insertBefore(parent: BrowserNode, child: BrowserNode, refChild: BrowserNode | null): void {\n if (!parent) return;\n this.detach(child);\n child.parent = parent;\n const at = refChild ? parent.children.indexOf(refChild) : -1;\n if (at === -1) parent.children.push(child);\n else parent.children.splice(at, 0, child);\n (parent.el as Element).insertBefore(child.el, refChild?.el ?? null);\n }\n\n removeChild(parent: BrowserNode | null, child: BrowserNode): void {\n // Angular removes a root component's host element when the component is destroyed. Here that\n // element is the one `mount` was given - a `<div>` of the caller's, or an `<ng-native-island>`\n // in a host app's template - and it is not this app's to take out of the page. What was\n // rendered into it goes; the element stays, empty, for its owner.\n if (this.engine.isRoot(child)) {\n for (const node of [...child.children]) this.removeChild(child, node);\n // A root is always an element: `wrapRoot` only ever wraps one.\n (child.el as Element).replaceChildren();\n return;\n }\n const actualParent = parent ?? child.parent;\n if (actualParent) {\n const at = actualParent.children.indexOf(child);\n if (at !== -1) actualParent.children.splice(at, 1);\n }\n child.el.parentNode?.removeChild(child.el);\n child.parent = null;\n }\n\n private detach(child: BrowserNode): void {\n if (child.parent) this.removeChild(child.parent, child);\n }\n\n selectRootElement(selectorOrNode: string | BrowserNode): BrowserNode {\n if (typeof selectorOrNode !== 'string') return selectorOrNode;\n const found = this.document.querySelector(selectorOrNode);\n if (!found) throw new Error(`BrowserRenderer: no element matches '${selectorOrNode}'`);\n found.textContent = '';\n return this.engine.wrapRoot(found);\n }\n\n parentNode(node: BrowserNode): BrowserNode | null {\n return node.parent;\n }\n\n nextSibling(node: BrowserNode): BrowserNode | null {\n const siblings = node.parent?.children;\n if (!siblings) return null;\n return siblings[siblings.indexOf(node) + 1] ?? null;\n }\n\n setAttribute(node: BrowserNode, name: string, value: string): void {\n // `class` drives real CSS selector matching; nothing about it goes through `props.ts`.\n //\n // `setAttribute('class', ...)`, not `.className =`: an SVG element's `className` is a\n // read-only `SVGAnimatedString` - only `.baseVal` is writable - so a direct assignment throws\n // in strict mode (every file in this package is a module, so every file is strict mode).\n // `setAttribute` is the one spelling that commits a class list on both an `HTMLElement` and\n // an `SVGElement`, which is what a static `class=\"...\"` on an icon's `<svg>`/`<path>` needs -\n // found by every test that opens a dialog with its default close button, an icon with a\n // static class the compiler writes through this exact path.\n if (name === 'class') {\n (node.el as Element).setAttribute('class', value);\n return;\n }\n this.engine.setProp(node, name, value);\n }\n\n removeAttribute(node: BrowserNode, name: string): void {\n if (name === 'class') {\n (node.el as Element).removeAttribute('class');\n return;\n }\n this.engine.setProp(node, name, null);\n }\n\n addClass(node: BrowserNode, name: string): void {\n (node.el as Element).classList.add(name);\n }\n\n removeClass(node: BrowserNode, name: string): void {\n (node.el as Element).classList.remove(name);\n }\n\n setStyle(node: BrowserNode, style: string, value: unknown, flags?: RendererStyleFlags2): void {\n if (value === null || value === undefined) {\n this.removeStyle(node, style);\n return;\n }\n const key = styleName(style);\n const important = !!(flags && flags & RendererStyleFlags2.Important);\n this.mirrorStyle(node, key, value);\n this.writeStyle(node, key, important ? 'important' : '');\n }\n\n removeStyle(node: BrowserNode, style: string): void {\n const key = styleName(style);\n this.mirrorStyle(node, key, undefined);\n this.writeStyle(node, key, '');\n }\n\n /** From the mirror, which is the whole style: see `native-style.ts` for why one key needs it. */\n private writeStyle(node: BrowserNode, key: string, priority: string): void {\n const style = (node.props['style'] ?? {}) as Record<string, unknown>;\n writeStyleKey((node.el as HTMLElement).style, key, style, priority);\n }\n\n /** Keeps `node.props['style']` an accurate mirror of the real inline style. See the file doc. */\n private mirrorStyle(node: BrowserNode, key: string, value: unknown): void {\n const current = node.props['style'] as Record<string, unknown> | undefined;\n if (current && OWN_STYLES.has(current)) {\n if (value === undefined) delete current[key];\n else current[key] = value;\n return;\n }\n if (value === undefined && (!current || !(key in current))) return;\n const next = { ...current };\n if (value === undefined) delete next[key];\n else next[key] = value;\n OWN_STYLES.add(next);\n node.props['style'] = next;\n }\n\n setProperty(node: BrowserNode, name: string, value: unknown): void {\n // `ngDevMode`, not a build-time flag: this package ships to a browser bundler rather than\n // through Metro, so there is no `__DEV__` to fold away - `ngDevMode` is the one dev/release\n // signal Angular itself sets the same way here as it does natively. See\n // `packages/platform/src/adapter.ts`'s `NativeRenderer.setProperty` for the native check this\n // mirrors, and `@ng-native/fabric`'s `forms-inputs.ts` for the table and report both share.\n if (typeof ngDevMode !== 'undefined' && ngDevMode)\n reportUnboundFormsInput(this.engine, node, name);\n this.engine.setProp(node, name, value);\n }\n\n setValue(node: BrowserNode, value: string): void {\n node.text = value;\n (node.el as Text).data = value;\n }\n\n listen(\n target: BrowserNode,\n eventName: string,\n callback: (event: unknown) => boolean | void,\n ): () => void {\n return this.engine.setEventListener(target, topLevelType(eventName), callback);\n }\n}\n\n/**\n * A component with emulated encapsulation: every element its template creates carries\n * `_ngcontent-<id>`, and its host carries `_nghost-<id>`, which is what the selectors Angular's\n * compiler rewrote (`.card[_ngcontent-%COMP%]`, `[_nghost-%COMP%]`) match. These are the\n * attributes `@angular/platform-browser`'s own emulated renderer writes, so a component's CSS is\n * scoped here exactly as in any other Angular app - and as on a device, where a component's\n * renderer only ever matches its own elements against its own sheet.\n */\nclass EmulatedRenderer extends BrowserRenderer {\n private readonly contentAttr: string;\n private readonly hostAttr: string;\n\n constructor(engine: BrowserEngine, document: Document, id: string) {\n super(engine, document);\n this.contentAttr = `_ngcontent-${id}`;\n this.hostAttr = `_nghost-${id}`;\n }\n\n applyToHost(host: BrowserNode): void {\n if (host.kind === 'element') (host.el as Element).setAttribute(this.hostAttr, '');\n }\n\n override createElement(name: string): BrowserNode {\n const node = super.createElement(name);\n (node.el as Element).setAttribute(this.contentAttr, '');\n return node;\n }\n}\n\n/** The slice of Angular's component definition `createRenderer` is handed that matters here. */\ninterface ComponentDefLike {\n readonly id: string;\n readonly styles?: readonly string[];\n readonly encapsulation?: ViewEncapsulation;\n}\n\n/** The placeholder Angular's compiler writes into scoped selectors, for the renderer to resolve. */\nconst COMPONENT_ID = /%COMP%/g;\n\n/**\n * The placeholder Angular 22's compiler writes into every custom property in a component's\n * styles, `--%NS%tint`, for a renderer to fill with the app's CSS variable namespace. This host\n * has no namespace, as platform-browser has none by default, so it is filled with nothing: left\n * in, `var(--tint)` never finds `--%NS%tint` and every custom property silently does nothing.\n */\nconst CSS_VAR_NAMESPACE = /%NS%/g;\n\n/**\n * The property a style binding names. A bound custom property, `[style.--tint]`, arrives with the\n * same placeholder as `--%NS%tint`, filled with nothing for the same reason, and keeps its case:\n * `--brandTint` and `--brand-tint` are two different properties.\n */\nfunction styleName(style: string): string {\n return style.startsWith('--') ? style.replace(CSS_VAR_NAMESPACE, '') : dashCase(style);\n}\n\nexport class BrowserRendererFactory implements RendererFactory2 {\n private readonly renderer: BrowserRenderer;\n /** One renderer per component with scoped styles, because each stamps its own attribute. */\n private readonly byComponent = new Map<string, EmulatedRenderer>();\n /** Component ids whose stylesheet is already in the document. */\n private readonly styled = new Set<string>();\n private readonly document: Document;\n readonly engine: BrowserEngine;\n\n constructor(engine: BrowserEngine, document: Document) {\n this.engine = engine;\n this.document = document;\n this.renderer = new BrowserRenderer(engine, document);\n letBrowserNodesPassAsNodes();\n }\n\n /**\n * One shared renderer for every component without styles of its own, and one per component\n * with them. A component's `styles` go into the document once, the first time it renders, with\n * the compiler's `%COMP%` placeholder resolved to its id. `ViewEncapsulation.None` adds them as\n * written and needs no attributes. Shadow DOM encapsulation is treated as emulated: a native\n * view has no shadow root either, and emulated scoping is what the device's matcher does.\n *\n * The compiler already turns `Emulated` into `None` for a component with no styles, so the\n * shared renderer is still what nearly every component here gets.\n */\n createRenderer(host: unknown, type: ComponentDefLike | null): Renderer2 {\n if (!type?.styles?.length) return this.renderer;\n this.addStyles(type.id, type.styles);\n if (type.encapsulation === ViewEncapsulation.None) return this.renderer;\n\n let renderer = this.byComponent.get(type.id);\n if (!renderer) {\n renderer = new EmulatedRenderer(this.engine, this.document, type.id);\n this.byComponent.set(type.id, renderer);\n }\n if (host) renderer.applyToHost(host as BrowserNode);\n return renderer;\n }\n\n private addStyles(id: string, styles: readonly string[]): void {\n if (this.styled.has(id)) return;\n this.styled.add(id);\n const style = this.document.createElement('style');\n style.setAttribute('data-ng-native-component', id);\n style.textContent = styles\n .map((css) => css.replace(COMPONENT_ID, id).replace(CSS_VAR_NAMESPACE, ''))\n .join('\\n');\n this.document.head.appendChild(style);\n }\n}\n"]}
@@ -51,6 +51,7 @@ export interface BrowserNode extends HostNode {
51
51
  */
52
52
  optedIn: Set<string> | null;
53
53
  }
54
+ export declare function letBrowserNodesPassAsNodes(): void;
54
55
  export declare function makeElementNode(name: string, el: Element): BrowserNode;
55
56
  export declare function makeTextNode(text: Text): BrowserNode;
56
57
  /** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */
package/dist/dom-node.js CHANGED
@@ -1,5 +1,26 @@
1
1
  /** `event.target`, and anything else holding a real DOM node, back to the `BrowserNode` for it. */
2
2
  const registry = new WeakMap();
3
+ const made = new WeakSet();
4
+ const answered = new WeakSet();
5
+ export function letBrowserNodesPassAsNodes() {
6
+ const node = globalThis.Node;
7
+ if (typeof node !== 'function' || answered.has(node))
8
+ return;
9
+ answered.add(node);
10
+ const own = node[Symbol.hasInstance];
11
+ Object.defineProperty(node, Symbol.hasInstance, {
12
+ configurable: true,
13
+ value(value) {
14
+ return (this === node && made.has(value)) || own.call(this, value);
15
+ },
16
+ });
17
+ }
18
+ /**
19
+ * The prototype of every element node. Angular's development build reports a binding as an unknown
20
+ * property (NG0303) unless `name in element` is true, and every binding on an element here goes to
21
+ * `setProperty`, whatever its name.
22
+ */
23
+ const anyProperty = new Proxy({}, { has: (_, name) => typeof name === 'string' });
3
24
  /**
4
25
  * The SVG names whose `fill`/`stroke` need a seeded `props` entry from the moment they are
5
26
  * created - see the block below for why. `svg-line` is left out: a `<line>` has no fill of its
@@ -54,7 +75,9 @@ export function makeElementNode(name, el) {
54
75
  listeners: null,
55
76
  optedIn: null,
56
77
  };
78
+ Object.setPrototypeOf(node, anyProperty);
57
79
  registry.set(el, node);
80
+ made.add(node);
58
81
  return node;
59
82
  }
60
83
  export function makeTextNode(text) {
@@ -70,6 +93,7 @@ export function makeTextNode(text) {
70
93
  optedIn: null,
71
94
  };
72
95
  registry.set(text, node);
96
+ made.add(node);
73
97
  return node;
74
98
  }
75
99
  /** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */
@@ -86,6 +110,7 @@ export function makeAnchorNode(comment) {
86
110
  optedIn: null,
87
111
  };
88
112
  registry.set(comment, node);
113
+ made.add(node);
89
114
  return node;
90
115
  }
91
116
  /** Puts `el` in place of the element `node` wraps, so `nodeOf` finds the node from either. */
@@ -1 +1 @@
1
- {"version":3,"file":"dom-node.js","sourceRoot":"","sources":["../src/dom-node.ts"],"names":[],"mappings":"AAwDA,mGAAmG;AACnG,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;IACjC,OAAO;IACP,UAAU;IACV,YAAY;IACZ,aAAa;IACb,UAAU;IACV,UAAU;IACV,WAAW;CACZ,CAAC,CAAC;AAEH,SAAS,YAAY,CAAoB,IAAY;IACnD,OAAQ,IAAI,CAAC,EAAc,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,YAAY,CAAoB,IAAY;IACnD,OAAQ,IAAI,CAAC,EAAc,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,EAAW;IACvD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,8FAA8F;IAC9F,mFAAmF;IACnF,4FAA4F;IAC5F,gGAAgG;IAChG,gGAAgG;IAChG,uFAAuF;IACvF,iGAAiG;IACjG,+FAA+F;IAC/F,+FAA+F;IAC/F,+FAA+F;IAC/F,iGAAiG;IACjG,6FAA6F;IAC7F,6FAA6F;IAC7F,IAAI,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;QAC1B,KAAK,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAC9B,CAAC;IACD,MAAM,IAAI,GAAgB;QACxB,IAAI,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B,IAAyC,CAAC,EAAE,GAAG,EAAE,CAAC;IACnD,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACzB,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,MAAM,CAAC,EAAmC;IACxD,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,EAAkB;IAC9C,KAAK,IAAI,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAChE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,MAAM,CAAC,IAAiB;IACtC,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,KAAK,IAAI,OAAO,GAAuB,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM;QAC5E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC","sourcesContent":["/**\n * The retained node this package hands Angular as `ElementRef.nativeElement`, and the thing every\n * `HostEngine` method actually operates on.\n *\n * `packages/fabric/src/engine.ts`'s `EngineNode` is not reusable here (its constructor-free shape\n * still carries Fabric-only bookkeeping - `committed`, `styleCache`, `sheet`...), but the shared\n * packages never ask for that: they ask for `HostNode`'s five fields, plus whatever a component\n * reads directly off `this.node` after `inject(ElementRef).nativeElement as EngineNode` casts it\n * back. Grepping every such read (`view-base.ts`, `pressable.ts`'s `TouchableBase`, `scroll-view.ts`,\n * `select.ts`'s `textOf`) turns up exactly `kind`, `props`, `text`, `children` and `parent` - so a\n * class that implements `HostNode` honestly, backed by a real DOM node, satisfies every one of\n * them without a cast.\n *\n * `children`/`parent` are maintained by hand rather than read live off the DOM (`el.parentElement`,\n * `el.childNodes`) for the same reason `Engine` keeps its own tree: a live DOM walk would have to\n * filter out nodes this package did not create (there are none today, but a consumer's own\n * `document.createElement` inside a projected template is not this package's to assume against),\n * and `select.ts`'s `textOf` recursion wants exactly the nodes Angular put here, in order.\n */\nimport type { HostNode } from '@ng-native/fabric';\n\nexport type BrowserNodeKind = 'element' | 'text' | 'anchor';\n\nexport interface BrowserNode extends HostNode {\n readonly kind: BrowserNodeKind;\n /** The real DOM node this wraps. An `Element` for `element`, a `Text` for `text`. */\n readonly el: Element | Text | Comment;\n /** Lowercase template spelling, e.g. `view`. Mirrors `EngineNode.name`; never the DOM tag. */\n readonly name: string;\n /** `name` again on an element, for Angular 22.0, which reads it on a component's host element. */\n readonly tagName?: string;\n /**\n * The wrapped element's attributes, on an element, for Angular's hydration. Once an app on the\n * page calls `provideClientHydration()`, every component's host element is asked for\n * `ngSkipHydration` and `ngh`, an island's included, whatever renderer created it. See\n * `BrowserEngine.wrapRoot` for the answer that keeps hydration out of an island.\n */\n readonly hasAttribute?: (this: BrowserNode, name: string) => boolean;\n readonly getAttribute?: (this: BrowserNode, name: string) => string | null;\n props: Record<string, unknown>;\n text: string;\n children: BrowserNode[];\n parent: BrowserNode | null;\n /**\n * Registered listeners, by top-level type (`topTouchStart`, `topChange`, ...). `null` until\n * the first one, so a node nothing ever listens to costs one field rather than one `Map`.\n */\n listeners: Map<string, Set<(event: unknown) => void>> | null;\n /**\n * Which opt-in event types (`topLayout`, `topPointerEnter`, `topPointerLeave`) already have\n * their real DOM listener installed - `browser-engine.ts`'s `wireOptIn` guard. `null` until\n * the first one, matching `listeners` above.\n */\n optedIn: Set<string> | null;\n}\n\n/** `event.target`, and anything else holding a real DOM node, back to the `BrowserNode` for it. */\nconst registry = new WeakMap<Element | Text | Comment, BrowserNode>();\n\n/**\n * The SVG names whose `fill`/`stroke` need a seeded `props` entry from the moment they are\n * created - see the block below for why. `svg-line` is left out: a `<line>` has no fill of its\n * own to paint (react-native-svg's `Line` never reads `fill` either), so there is nothing an\n * explicit `fill=\"none\"` there could mean.\n */\nconst SVG_BRUSH_ELEMENTS = new Set([\n 'svg-g',\n 'svg-path',\n 'svg-circle',\n 'svg-ellipse',\n 'svg-rect',\n 'svg-text',\n 'svg-tspan',\n]);\n\nfunction hasAttribute(this: BrowserNode, name: string): boolean {\n return (this.el as Element).hasAttribute(name);\n}\n\nfunction getAttribute(this: BrowserNode, name: string): string | null {\n return (this.el as Element).getAttribute(name);\n}\n\nexport function makeElementNode(name: string, el: Element): BrowserNode {\n const props: Record<string, unknown> = {};\n // `packages/icons/src/svg-props.ts`'s `brushOf` turns a literal `fill=\"none\"`/`stroke=\"none\"`\n // into `null` - a real, meaningful value (\"paint nothing\"), not an absent one. But\n // `BrowserEngine.setProp` treats `null` exactly like `undefined` on a key it has never seen\n // before: `if (!(key in node.props)) return;`, its fast path for \"nothing to remove, so nothing\n // changed\". That path is right for almost everything a `null` prop could mean, and wrong here -\n // it would skip `applyProp` entirely on a chart line's `fill=\"none\"` (`chart-line.ts`,\n // `chart-area.ts`), leaving the attribute unset, and an unset `fill` defaults to opaque black in\n // a browser (the real SVG initial value) rather than to unpainted (what react-native-svg's own\n // `propList` convention, and every one of these charts, is relying on). Seeding the key here -\n // present, value `undefined` - costs nothing on a shape that never touches the prop again, and\n // is what lets that first `null` reach `props.ts`'s real translation instead of being dropped by\n // the fast path. See `props.ts`'s `applyBrush` for the other half: it is what turns a seeded\n // key's `null` into a written `fill=\"none\"`/`stroke=\"none\"` rather than a removed attribute.\n if (SVG_BRUSH_ELEMENTS.has(name)) {\n props['fill'] = undefined;\n props['stroke'] = undefined;\n }\n const node: BrowserNode = {\n kind: 'element',\n el,\n name,\n tagName: name,\n hasAttribute,\n getAttribute,\n props,\n text: '',\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(el, node);\n return node;\n}\n\nexport function makeTextNode(text: Text): BrowserNode {\n const node: BrowserNode = {\n kind: 'text',\n el: text,\n name: '#text',\n props: {},\n text: text.data,\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(text, node);\n return node;\n}\n\n/** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */\nexport function makeAnchorNode(comment: Comment): BrowserNode {\n const node: BrowserNode = {\n kind: 'anchor',\n el: comment,\n name: '#anchor',\n props: {},\n text: '',\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(comment, node);\n return node;\n}\n\n/** Puts `el` in place of the element `node` wraps, so `nodeOf` finds the node from either. */\nexport function rebindElement(node: BrowserNode, el: Element): void {\n registry.delete(node.el);\n (node as { el: Element | Text | Comment }).el = el;\n registry.set(el, node);\n}\n\n/** The `BrowserNode` a real DOM node was created with, or `null` for one this package did not make. */\nexport function nodeOf(el: Element | Text | Comment | null): BrowserNode | null {\n return el ? (registry.get(el) ?? null) : null;\n}\n\n/**\n * The nearest `BrowserNode` starting at a real `Element` and walking up `parentElement`.\n *\n * Used to resolve `event.target` for events this package listens for on `document` rather than\n * per-node (the responder system's pointer events, focus/blur, selection change): the physical\n * hit is always a real element this package created, but it is not always one with its own\n * listeners, so the search has to climb past any that are not tracked before it gets to `body`\n * and turns up nothing.\n */\nexport function nearestNodeOf(el: Element | null): BrowserNode | null {\n for (let current = el; current; current = current.parentElement) {\n const node = registry.get(current);\n if (node) return node;\n }\n return null;\n}\n\n/** Root-first path from the tree's root to `node`, inclusive. Mirrors `Engine`'s own `pathTo`. */\nexport function pathTo(node: BrowserNode): BrowserNode[] {\n const path: BrowserNode[] = [];\n for (let current: BrowserNode | null = node; current; current = current.parent)\n path.push(current);\n return path.reverse();\n}\n"]}
1
+ {"version":3,"file":"dom-node.js","sourceRoot":"","sources":["../src/dom-node.ts"],"names":[],"mappings":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AI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACxB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,MAAM,CAAC,IAAiB;IACtC,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,KAAK,IAAI,OAAO,GAAuB,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM;QAC5E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC","sourcesContent":["/**\n * The retained node this package hands Angular as `ElementRef.nativeElement`, and the thing every\n * `HostEngine` method actually operates on.\n *\n * `packages/fabric/src/engine.ts`'s `EngineNode` is not reusable here (its constructor-free shape\n * still carries Fabric-only bookkeeping - `committed`, `styleCache`, `sheet`...), but the shared\n * packages never ask for that: they ask for `HostNode`'s five fields, plus whatever a component\n * reads directly off `this.node` after `inject(ElementRef).nativeElement as EngineNode` casts it\n * back. Grepping every such read (`view-base.ts`, `pressable.ts`'s `TouchableBase`, `scroll-view.ts`,\n * `select.ts`'s `textOf`) turns up exactly `kind`, `props`, `text`, `children` and `parent` - so a\n * class that implements `HostNode` honestly, backed by a real DOM node, satisfies every one of\n * them without a cast.\n *\n * `children`/`parent` are maintained by hand rather than read live off the DOM (`el.parentElement`,\n * `el.childNodes`) for the same reason `Engine` keeps its own tree: a live DOM walk would have to\n * filter out nodes this package did not create (there are none today, but a consumer's own\n * `document.createElement` inside a projected template is not this package's to assume against),\n * and `select.ts`'s `textOf` recursion wants exactly the nodes Angular put here, in order.\n */\nimport type { HostNode } from '@ng-native/fabric';\n\nexport type BrowserNodeKind = 'element' | 'text' | 'anchor';\n\nexport interface BrowserNode extends HostNode {\n readonly kind: BrowserNodeKind;\n /** The real DOM node this wraps. An `Element` for `element`, a `Text` for `text`. */\n readonly el: Element | Text | Comment;\n /** Lowercase template spelling, e.g. `view`. Mirrors `EngineNode.name`; never the DOM tag. */\n readonly name: string;\n /** `name` again on an element, for Angular 22.0, which reads it on a component's host element. */\n readonly tagName?: string;\n /**\n * The wrapped element's attributes, on an element, for Angular's hydration. Once an app on the\n * page calls `provideClientHydration()`, every component's host element is asked for\n * `ngSkipHydration` and `ngh`, an island's included, whatever renderer created it. See\n * `BrowserEngine.wrapRoot` for the answer that keeps hydration out of an island.\n */\n readonly hasAttribute?: (this: BrowserNode, name: string) => boolean;\n readonly getAttribute?: (this: BrowserNode, name: string) => string | null;\n props: Record<string, unknown>;\n text: string;\n children: BrowserNode[];\n parent: BrowserNode | null;\n /**\n * Registered listeners, by top-level type (`topTouchStart`, `topChange`, ...). `null` until\n * the first one, so a node nothing ever listens to costs one field rather than one `Map`.\n */\n listeners: Map<string, Set<(event: unknown) => void>> | null;\n /**\n * Which opt-in event types (`topLayout`, `topPointerEnter`, `topPointerLeave`) already have\n * their real DOM listener installed - `browser-engine.ts`'s `wireOptIn` guard. `null` until\n * the first one, matching `listeners` above.\n */\n optedIn: Set<string> | null;\n}\n\n/** `event.target`, and anything else holding a real DOM node, back to the `BrowserNode` for it. */\nconst registry = new WeakMap<Element | Text | Comment, BrowserNode>();\n\nconst made = new WeakSet<object>();\nconst answered = new WeakSet<object>();\n\ntype Constructor = abstract new (...args: never[]) => object;\n\nexport function letBrowserNodesPassAsNodes(): void {\n const node = (globalThis as { Node?: Constructor }).Node;\n if (typeof node !== 'function' || answered.has(node)) return;\n answered.add(node);\n const own = node[Symbol.hasInstance];\n Object.defineProperty(node, Symbol.hasInstance, {\n configurable: true,\n value(this: Constructor, value: unknown): boolean {\n return (this === node && made.has(value as object)) || own.call(this, value);\n },\n });\n}\n\n/**\n * The prototype of every element node. Angular's development build reports a binding as an unknown\n * property (NG0303) unless `name in element` is true, and every binding on an element here goes to\n * `setProperty`, whatever its name.\n */\nconst anyProperty = new Proxy({}, { has: (_, name) => typeof name === 'string' });\n\n/**\n * The SVG names whose `fill`/`stroke` need a seeded `props` entry from the moment they are\n * created - see the block below for why. `svg-line` is left out: a `<line>` has no fill of its\n * own to paint (react-native-svg's `Line` never reads `fill` either), so there is nothing an\n * explicit `fill=\"none\"` there could mean.\n */\nconst SVG_BRUSH_ELEMENTS = new Set([\n 'svg-g',\n 'svg-path',\n 'svg-circle',\n 'svg-ellipse',\n 'svg-rect',\n 'svg-text',\n 'svg-tspan',\n]);\n\nfunction hasAttribute(this: BrowserNode, name: string): boolean {\n return (this.el as Element).hasAttribute(name);\n}\n\nfunction getAttribute(this: BrowserNode, name: string): string | null {\n return (this.el as Element).getAttribute(name);\n}\n\nexport function makeElementNode(name: string, el: Element): BrowserNode {\n const props: Record<string, unknown> = {};\n // `packages/icons/src/svg-props.ts`'s `brushOf` turns a literal `fill=\"none\"`/`stroke=\"none\"`\n // into `null` - a real, meaningful value (\"paint nothing\"), not an absent one. But\n // `BrowserEngine.setProp` treats `null` exactly like `undefined` on a key it has never seen\n // before: `if (!(key in node.props)) return;`, its fast path for \"nothing to remove, so nothing\n // changed\". That path is right for almost everything a `null` prop could mean, and wrong here -\n // it would skip `applyProp` entirely on a chart line's `fill=\"none\"` (`chart-line.ts`,\n // `chart-area.ts`), leaving the attribute unset, and an unset `fill` defaults to opaque black in\n // a browser (the real SVG initial value) rather than to unpainted (what react-native-svg's own\n // `propList` convention, and every one of these charts, is relying on). Seeding the key here -\n // present, value `undefined` - costs nothing on a shape that never touches the prop again, and\n // is what lets that first `null` reach `props.ts`'s real translation instead of being dropped by\n // the fast path. See `props.ts`'s `applyBrush` for the other half: it is what turns a seeded\n // key's `null` into a written `fill=\"none\"`/`stroke=\"none\"` rather than a removed attribute.\n if (SVG_BRUSH_ELEMENTS.has(name)) {\n props['fill'] = undefined;\n props['stroke'] = undefined;\n }\n const node: BrowserNode = {\n kind: 'element',\n el,\n name,\n tagName: name,\n hasAttribute,\n getAttribute,\n props,\n text: '',\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n Object.setPrototypeOf(node, anyProperty);\n registry.set(el, node);\n made.add(node);\n return node;\n}\n\nexport function makeTextNode(text: Text): BrowserNode {\n const node: BrowserNode = {\n kind: 'text',\n el: text,\n name: '#text',\n props: {},\n text: text.data,\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(text, node);\n made.add(node);\n return node;\n}\n\n/** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */\nexport function makeAnchorNode(comment: Comment): BrowserNode {\n const node: BrowserNode = {\n kind: 'anchor',\n el: comment,\n name: '#anchor',\n props: {},\n text: '',\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(comment, node);\n made.add(node);\n return node;\n}\n\n/** Puts `el` in place of the element `node` wraps, so `nodeOf` finds the node from either. */\nexport function rebindElement(node: BrowserNode, el: Element): void {\n registry.delete(node.el);\n (node as { el: Element | Text | Comment }).el = el;\n registry.set(el, node);\n}\n\n/** The `BrowserNode` a real DOM node was created with, or `null` for one this package did not make. */\nexport function nodeOf(el: Element | Text | Comment | null): BrowserNode | null {\n return el ? (registry.get(el) ?? null) : null;\n}\n\n/**\n * The nearest `BrowserNode` starting at a real `Element` and walking up `parentElement`.\n *\n * Used to resolve `event.target` for events this package listens for on `document` rather than\n * per-node (the responder system's pointer events, focus/blur, selection change): the physical\n * hit is always a real element this package created, but it is not always one with its own\n * listeners, so the search has to climb past any that are not tracked before it gets to `body`\n * and turns up nothing.\n */\nexport function nearestNodeOf(el: Element | null): BrowserNode | null {\n for (let current = el; current; current = current.parentElement) {\n const node = registry.get(current);\n if (node) return node;\n }\n return null;\n}\n\n/** Root-first path from the tree's root to `node`, inclusive. Mirrors `Engine`'s own `pathTo`. */\nexport function pathTo(node: BrowserNode): BrowserNode[] {\n const path: BrowserNode[] = [];\n for (let current: BrowserNode | null = node; current; current = current.parent)\n path.push(current);\n return path.reverse();\n}\n"]}
package/dist/mount.js CHANGED
@@ -33,7 +33,7 @@
33
33
  * Refresh's fallback path specifically; a browser dev server has its own, unrelated story for
34
34
  * picking up an edit, so wiring `__angularNativeReload` here would install a hook nothing calls.
35
35
  */
36
- import { APP_BOOTSTRAP_LISTENER, ApplicationRef, DOCUMENT, PLATFORM_ID, EnvironmentInjector, ErrorHandler, RendererFactory2, createComponent, effect, createEnvironmentInjector, ɵcreateOrReusePlatformInjector as createOrReusePlatformInjector, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵprovideZonelessChangeDetectionInternal as provideZonelessChangeDetectionInternal, } from '@angular/core';
36
+ import { APP_BOOTSTRAP_LISTENER, ApplicationRef, DOCUMENT, PLATFORM_ID, EnvironmentInjector, ErrorHandler, LOCALE_ID, RendererFactory2, createComponent, effect, createEnvironmentInjector, ɵcreateOrReusePlatformInjector as createOrReusePlatformInjector, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵprovideZonelessChangeDetectionInternal as provideZonelessChangeDetectionInternal, ɵsetLocaleId as setLocaleId, } from '@angular/core';
37
37
  import { HostEngine } from '@ng-native/fabric';
38
38
  import { ColorScheme, Direction, HardwareBack, Screen, StatusBar } from '@ng-native/device';
39
39
  import { browserColorSchemeSource, browserDirectionSource, browserScreenSource, } from "./device-sources.js";
@@ -169,6 +169,7 @@ function mountAlone(rootNode, component, providers, inputs, document, host) {
169
169
  { provide: ErrorHandler, useClass: ErrorHandler },
170
170
  ...providers,
171
171
  ], platformInjector);
172
+ setLocaleId(injector.get(LOCALE_ID) || 'en-US');
172
173
  const componentRef = createComponent(component, {
173
174
  environmentInjector: injector,
174
175
  hostElement: rootNode,
package/dist/mount.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,g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CAAC,CAAC;;gBACtE,WAAW,CAAC,YAAY,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;YAChE,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QAC/C,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,YAAmC,EAAE,MAAyC;IAC/F,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/**\n * Put an Angular application on a page.\n *\n * The browser counterpart to `@ng-native/platform`'s `mount()`, and named the same on\n * purpose: an app imports one or the other, never both, and which one it gets is the import path's\n * job to say rather than the identifier's. Reading the native one first is worth it - this follows\n * its shape and its documented distinction\n * between `ApplicationRef` and the root `ComponentRef` (`createComponent` resolves the latter;\n * `applicationRef.components` needs it pushed by hand, the same bookkeeping\n * `ApplicationRef.bootstrap()` would otherwise do, for the same reason - a routed app's initial\n * navigation checks `applicationRef.components[0]` before it will run at all).\n *\n * What is different from the native `mount()`, and why:\n *\n * - **The first argument is a real `Element`, not a numeric root tag.** Fabric addresses its root\n * by the tag React Native's host gave it; a browser page has no such number, only the element\n * an app mounts into (`document.getElementById('app-root')`, or one `document.body` itself).\n * - **No `FabricUIManager`, and no `Engine` provided under its own token.** Only `HostEngine` is\n * provided. `worklet-style`, `worklet-scroll` and `native-gesture`\n * `inject(Engine)` directly (see `packages/fabric/src/host.ts`'s doc comment for why that is\n * the honest place to draw the line) - on native `Engine` is provided under both tokens so both\n * paths resolve; here it is provided under neither, so an app that uses one of those three on\n * the web gets Angular's own `NullInjectorError` at the point it tries to inject `Engine`,\n * which names exactly what is unsupported rather than rendering something silently wrong.\n * - **`DOCUMENT` is the real `document`**, not the stub the native `mount()` builds for\n * `TransferState`'s\n * `getElementById`. A browser host already has one.\n * - **No dev-mode animation warning, no HMR reload hook.** The native check exists\n * because `@angular/core` reads whether `animate.enter`/`animate.leave` do anything from a\n * global a Metro polyfill has to set before `@angular/core` first evaluates; a real browser\n * already has `document.documentElement.getAnimations`, which is the same thing that global\n * stands in for on native, so there is nothing to warn about. The reload hook is Metro Fast\n * Refresh's fallback path specifically; a browser dev server has its own, unrelated story for\n * picking up an edit, so wiring `__angularNativeReload` here would install a hook nothing calls.\n */\nimport {\n APP_BOOTSTRAP_LISTENER,\n ApplicationRef,\n DOCUMENT,\n PLATFORM_ID,\n EnvironmentInjector,\n ErrorHandler,\n RendererFactory2,\n createComponent,\n effect,\n createEnvironmentInjector,\n type ComponentRef,\n type EnvironmentProviders,\n type Injector,\n type Provider,\n type Type,\n ɵcreateOrReusePlatformInjector as createOrReusePlatformInjector,\n ɵINJECTOR_SCOPE as INJECTOR_SCOPE,\n ɵprovideZonelessChangeDetectionInternal as provideZonelessChangeDetectionInternal,\n} from '@angular/core';\nimport { HostEngine } from '@ng-native/fabric';\nimport { ColorScheme, Direction, HardwareBack, Screen, StatusBar } from '@ng-native/device';\nimport {\n browserColorSchemeSource,\n browserDirectionSource,\n browserScreenSource,\n} from './device-sources.ts';\nimport { BrowserEngine } from './browser-engine.ts';\nimport { BrowserRendererFactory } from './browser-renderer.ts';\nimport { ISLAND_RESET_CSS, RESET_CSS } from './reset-css.ts';\n\nconst RESET_STYLE_ID = 'angular-native-web-reset';\nconst ISLAND_RESET_STYLE_ID = 'angular-native-web-island-reset';\n\n/**\n * Injects `reset.css`'s content as a `<style>` in `document.head`, once per document. Idempotent,\n * so an app free to call it itself (or to load `reset.css` through its own bundler instead, and\n * pass `injectReset: false` to `mount`) never ends up with the rule twice.\n */\nexport function injectResetStylesheet(document: Document): void {\n injectStyle(document, RESET_STYLE_ID, RESET_CSS);\n}\n\n/**\n * The same for an island inside someone else's page: `ISLAND_RESET_CSS`, which leaves the host's\n * `html` and `body` alone. Its own id, so it sits beside a full reset if the page has both kinds.\n */\nexport function injectIslandResetStylesheet(document: Document): void {\n injectStyle(document, ISLAND_RESET_STYLE_ID, ISLAND_RESET_CSS);\n}\n\nfunction injectStyle(document: Document, id: string, css: string): void {\n if (document.getElementById(id)) return;\n const style = document.createElement('style');\n style.id = id;\n // In Tailwind's `base` layer, below every utility, as `@import '@ng-native/web/reset.css'\n // layer(base)` puts it. Injected unlayered after the app's stylesheet, a reset rule is as\n // specific as a class and later, so it beat `border-2`, `flex-row` and `hidden` alike. With no\n // Tailwind on the page, a layered rule still loses to every unlayered one, as a reset should.\n style.textContent = `@layer base {\\n${css}\\n}`;\n // First in the head: a layer is ordered by where it is first declared, and the documented entry\n // (theme.css and utilities.css) declares no `base`. Declared after it, `base` came after\n // `utilities` and beat every utility again.\n document.head.insertBefore(style, document.head.firstChild);\n}\n\nexport interface MountOptions {\n readonly providers?: (Provider | EnvironmentProviders)[];\n /**\n * The component's inputs, by their public name, set before its first render - so an\n * `input.required()` has its value from the start rather than throwing on the first check.\n * Change them afterwards with `componentRef.setInput`.\n */\n readonly inputs?: Readonly<Record<string, unknown>>;\n /**\n * Injects the reset stylesheet into `document.head` before mounting. Defaults to `true`. With\n * `injector` it is the island reset, which leaves the host page's `html` and `body` alone.\n */\n readonly injectReset?: boolean;\n /**\n * Mount inside an existing Angular app instead of as an app of its own: pass an injector from\n * that app - `inject(Injector)` in the component that owns `rootElement` is the usual one.\n *\n * The island then shares the host app's services (anything `providedIn: 'root'`, and anything\n * its `bootstrapApplication` or a component above it provides) and is checked by the host's\n * change detection. Only what the island has to render differently is its own: the renderer,\n * the engine, and the device services that read the browser rather than a phone. See\n * `packages/web/islands.md` in the documentation.\n */\n readonly injector?: Injector;\n /**\n * Keeps a `dark` class on `rootElement` in step with `ColorScheme`, which is what\n * `@ng-native/tailwind`'s `dark:` variant and a theme's `.dark` block match beneath: the system's\n * `prefers-color-scheme`, or what `ColorScheme.set()` chose over it. Defaults to `true`, as\n * `watchConditions` does on a device. An app that puts `dark` on its own root view turns it off.\n */\n readonly darkClass?: boolean;\n}\n\nexport interface MountResult {\n readonly componentRef: ComponentRef<unknown>;\n /** The island's own app, or with `injector` the host app it was mounted into. */\n readonly applicationRef: ApplicationRef;\n readonly factory: BrowserRendererFactory;\n readonly engine: BrowserEngine;\n /**\n * Takes the island down: its component, and whatever it owns. With `injector` that is only the\n * island - the host app it was mounted into keeps running - so call this rather than\n * `applicationRef.destroy()`, which there would destroy the host.\n */\n destroy(): void;\n}\n\nexport function mount(\n rootElement: Element,\n component: Type<unknown>,\n options: MountOptions = {},\n): MountResult {\n const {\n providers: extraProviders = [],\n inputs = {},\n injectReset = true,\n injector: host,\n darkClass = true,\n } = options;\n const document = rootElement.ownerDocument;\n if (injectReset) {\n if (host) injectIslandResetStylesheet(document);\n else injectResetStylesheet(document);\n }\n // What `reset.css` hangs the root's height off. Stamped rather than required of the app,\n // because an app that forgot it would get a page whose `flex: 1` silently resolved to zero.\n rootElement.setAttribute('data-rn-root', '');\n // What `@ng-native/tailwind`'s `web:` variant matches beneath, as `platform-ios` does on a phone.\n rootElement.classList.add('platform-web');\n\n const engine = new BrowserEngine(document);\n const factory = new BrowserRendererFactory(engine, document);\n // `wrapRoot` marks the element `ngSkipHydration`; an island gives back what it had on unmount.\n const skipHydration = rootElement.getAttribute('ngSkipHydration');\n const rootNode = engine.wrapRoot(rootElement) as unknown as Element;\n const own = hostProviders(engine, factory, document.defaultView);\n\n const mounted = host\n ? mountInside(\n host,\n rootElement,\n rootNode,\n component,\n [...own, ...extraProviders],\n inputs,\n {\n factory,\n engine,\n },\n skipHydration,\n )\n : mountAlone(rootNode, component, [...own, ...extraProviders], inputs, document, {\n factory,\n engine,\n });\n // The engine listens on the whole document, so it has to stop once its app is gone, however\n // the app went: through `destroy()` or straight through the component ref.\n mounted.componentRef.onDestroy(() => engine.dispose());\n if (darkClass) keepDarkClass(rootElement, mounted.componentRef);\n return mounted;\n}\n\n/** The `darkClass` option: the class now, and again whenever `ColorScheme` changes. */\nfunction keepDarkClass(rootElement: Element, componentRef: ComponentRef<unknown>): void {\n const scheme = componentRef.injector.get(ColorScheme);\n const apply = () => rootElement.classList.toggle('dark', scheme.current() === 'dark');\n apply();\n effect(apply, { injector: componentRef.injector });\n componentRef.onDestroy(() => rootElement.classList.remove('dark'));\n}\n\n/**\n * What an island has to have of its own, whichever way it is mounted: the renderer and engine\n * that turn `<view>` into a `<div>`, and the device capabilities answered by the browser.\n */\nfunction hostProviders(\n engine: BrowserEngine,\n factory: BrowserRendererFactory,\n view: Document['defaultView'],\n): (Provider | EnvironmentProviders)[] {\n return [\n { provide: RendererFactory2, useValue: factory },\n // The one seam the shared packages inject. See the file doc for why `Engine` itself is not\n // also provided here.\n { provide: HostEngine, useValue: engine },\n // The device capabilities, from the browser rather than from React Native. Without these\n // `Screen` falls back to its off-device answer of a zero-sized window, and every component\n // that branches on `compact()` takes the phone tree. See `device-sources.ts`.\n ...(view\n ? [\n { provide: Screen.SOURCE, useValue: browserScreenSource(view) },\n { provide: ColorScheme.SOURCE, useValue: browserColorSchemeSource(view) },\n { provide: Direction.SOURCE, useValue: browserDirectionSource(view) },\n ]\n : []),\n // A tab has no hardware back button, so this is the same inert fallback\n // `hardwareBackSource()`'s own off-device branch answers with, provided here so the browser\n // host says so itself rather than relying on that branch.\n { provide: HardwareBack.SOURCE, useValue: { subscribe: () => () => {} } },\n // A tab has no status bar either.\n {\n provide: StatusBar.SOURCE,\n useValue: {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n },\n },\n ];\n}\n\n/** An app of its own: its own root injector, change detection and `ApplicationRef`. */\nfunction mountAlone(\n rootNode: Element,\n component: Type<unknown>,\n providers: (Provider | EnvironmentProviders)[],\n inputs: Readonly<Record<string, unknown>>,\n document: Document,\n host: { factory: BrowserRendererFactory; engine: BrowserEngine },\n): MountResult {\n // Parent the app injector to the platform injector, exactly as `internalCreateApplication`\n // does and `mount()` documents: some Angular services are `providedIn: 'platform'`, and with a\n // null parent they simply do not exist.\n const platformInjector = createOrReusePlatformInjector();\n\n const injector = createEnvironmentInjector(\n [\n { provide: INJECTOR_SCOPE, useValue: 'root' },\n provideZonelessChangeDetectionInternal(),\n { provide: DOCUMENT, useValue: document },\n // A DOM is what this is running in, so libraries that check isPlatformBrowser() are right to\n // use it. An island inside an app is the app's own and inherits its value instead.\n { provide: PLATFORM_ID, useValue: 'browser' },\n { provide: ErrorHandler, useClass: ErrorHandler },\n ...providers,\n ],\n platformInjector as EnvironmentInjector,\n );\n\n const componentRef = createComponent(component, {\n environmentInjector: injector,\n hostElement: rootNode,\n });\n setInputs(componentRef, inputs);\n\n const applicationRef = injector.get(ApplicationRef);\n\n // Mirrors `ApplicationRef.bootstrap()`, which is not used directly because it wants a DOM\n // selector rather than an element `mount`'s own caller already resolved.\n applicationRef.componentTypes.push(component);\n applicationRef.attachView(componentRef.hostView);\n applicationRef.tick();\n // Load-bearing, not bookkeeping: the router's bootstrap listener returns early unless the ref\n // it is handed is `ApplicationRef.components[0]`.\n applicationRef.components.push(componentRef);\n componentRef.onDestroy(() => {\n applicationRef.detachView(componentRef.hostView);\n const at = applicationRef.components.indexOf(componentRef);\n if (at !== -1) applicationRef.components.splice(at, 1);\n });\n\n for (const listener of injector.get(APP_BOOTSTRAP_LISTENER, [])) {\n listener(componentRef);\n }\n\n return {\n componentRef,\n applicationRef,\n ...host,\n destroy: () => {\n componentRef.destroy();\n applicationRef.destroy();\n },\n };\n}\n\n/**\n * An island inside a running app. Its environment injector is a child of the host's, without a\n * root scope of its own, so anything it does not provide - a `providedIn: 'root'` service, the\n * host's `ApplicationRef` and scheduler, its `ErrorHandler` - resolves from the host, once, for\n * both. What it does provide is only what has to differ: the renderer and engine, the browser's\n * device sources, and the five device services that read them. Those five are provided here as\n * classes so they are built in the island, against its sources, rather than in the host's root\n * against the phone defaults.\n *\n * The host's element injector goes in too, so a service a component above the island provides\n * is visible to it as well as one the app does.\n */\nfunction mountInside(\n hostInjector: Injector,\n rootElement: Element,\n rootNode: Element,\n component: Type<unknown>,\n providers: (Provider | EnvironmentProviders)[],\n inputs: Readonly<Record<string, unknown>>,\n host: { factory: BrowserRendererFactory; engine: BrowserEngine },\n skipHydration: string | null,\n): MountResult {\n const injector = createEnvironmentInjector(\n [Screen, ColorScheme, Direction, HardwareBack, StatusBar, ...providers],\n hostInjector.get(EnvironmentInjector),\n );\n\n const componentRef = createComponent(component, {\n environmentInjector: injector,\n elementInjector: hostInjector,\n hostElement: rootNode,\n });\n setInputs(componentRef, inputs);\n\n // The host's own change detection checks the island from here on, like any view of its own.\n const applicationRef = hostInjector.get(ApplicationRef);\n applicationRef.attachView(componentRef.hostView);\n componentRef.changeDetectorRef.detectChanges();\n\n return {\n componentRef,\n applicationRef,\n ...host,\n destroy: () => {\n componentRef.destroy();\n injector.destroy();\n rootElement.removeAttribute('data-rn-root');\n if (skipHydration === null) rootElement.removeAttribute('ngSkipHydration');\n else rootElement.setAttribute('ngSkipHydration', skipHydration);\n rootElement.classList.remove('platform-web');\n },\n };\n}\n\nfunction setInputs(componentRef: ComponentRef<unknown>, inputs: Readonly<Record<string, unknown>>) {\n for (const [name, value] of Object.entries(inputs)) componentRef.setInput(name, value);\n}\n"]}
1
+ {"version":3,"file":"mount.js","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,yBAAyB,EAMzB,8BAA8B,IAAI,6BAA6B,EAC/D,eAAe,IAAI,cAAc,EACjC,uCAAuC,IAAI,sCAAsC,EACjF,YAAY,IAAI,WAAW,GAC5B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAA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AC;AAED,SAAS,SAAS,CAAC,YAAmC,EAAE,MAAyC;IAC/F,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,YAAY,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/**\n * Put an Angular application on a page.\n *\n * The browser counterpart to `@ng-native/platform`'s `mount()`, and named the same on\n * purpose: an app imports one or the other, never both, and which one it gets is the import path's\n * job to say rather than the identifier's. Reading the native one first is worth it - this follows\n * its shape and its documented distinction\n * between `ApplicationRef` and the root `ComponentRef` (`createComponent` resolves the latter;\n * `applicationRef.components` needs it pushed by hand, the same bookkeeping\n * `ApplicationRef.bootstrap()` would otherwise do, for the same reason - a routed app's initial\n * navigation checks `applicationRef.components[0]` before it will run at all).\n *\n * What is different from the native `mount()`, and why:\n *\n * - **The first argument is a real `Element`, not a numeric root tag.** Fabric addresses its root\n * by the tag React Native's host gave it; a browser page has no such number, only the element\n * an app mounts into (`document.getElementById('app-root')`, or one `document.body` itself).\n * - **No `FabricUIManager`, and no `Engine` provided under its own token.** Only `HostEngine` is\n * provided. `worklet-style`, `worklet-scroll` and `native-gesture`\n * `inject(Engine)` directly (see `packages/fabric/src/host.ts`'s doc comment for why that is\n * the honest place to draw the line) - on native `Engine` is provided under both tokens so both\n * paths resolve; here it is provided under neither, so an app that uses one of those three on\n * the web gets Angular's own `NullInjectorError` at the point it tries to inject `Engine`,\n * which names exactly what is unsupported rather than rendering something silently wrong.\n * - **`DOCUMENT` is the real `document`**, not the stub the native `mount()` builds for\n * `TransferState`'s\n * `getElementById`. A browser host already has one.\n * - **No dev-mode animation warning, no HMR reload hook.** The native check exists\n * because `@angular/core` reads whether `animate.enter`/`animate.leave` do anything from a\n * global a Metro polyfill has to set before `@angular/core` first evaluates; a real browser\n * already has `document.documentElement.getAnimations`, which is the same thing that global\n * stands in for on native, so there is nothing to warn about. The reload hook is Metro Fast\n * Refresh's fallback path specifically; a browser dev server has its own, unrelated story for\n * picking up an edit, so wiring `__angularNativeReload` here would install a hook nothing calls.\n */\nimport {\n APP_BOOTSTRAP_LISTENER,\n ApplicationRef,\n DOCUMENT,\n PLATFORM_ID,\n EnvironmentInjector,\n ErrorHandler,\n LOCALE_ID,\n RendererFactory2,\n createComponent,\n effect,\n createEnvironmentInjector,\n type ComponentRef,\n type EnvironmentProviders,\n type Injector,\n type Provider,\n type Type,\n ɵcreateOrReusePlatformInjector as createOrReusePlatformInjector,\n ɵINJECTOR_SCOPE as INJECTOR_SCOPE,\n ɵprovideZonelessChangeDetectionInternal as provideZonelessChangeDetectionInternal,\n ɵsetLocaleId as setLocaleId,\n} from '@angular/core';\nimport { HostEngine } from '@ng-native/fabric';\nimport { ColorScheme, Direction, HardwareBack, Screen, StatusBar } from '@ng-native/device';\nimport {\n browserColorSchemeSource,\n browserDirectionSource,\n browserScreenSource,\n} from './device-sources.ts';\nimport { BrowserEngine } from './browser-engine.ts';\nimport { BrowserRendererFactory } from './browser-renderer.ts';\nimport { ISLAND_RESET_CSS, RESET_CSS } from './reset-css.ts';\n\nconst RESET_STYLE_ID = 'angular-native-web-reset';\nconst ISLAND_RESET_STYLE_ID = 'angular-native-web-island-reset';\n\n/**\n * Injects `reset.css`'s content as a `<style>` in `document.head`, once per document. Idempotent,\n * so an app free to call it itself (or to load `reset.css` through its own bundler instead, and\n * pass `injectReset: false` to `mount`) never ends up with the rule twice.\n */\nexport function injectResetStylesheet(document: Document): void {\n injectStyle(document, RESET_STYLE_ID, RESET_CSS);\n}\n\n/**\n * The same for an island inside someone else's page: `ISLAND_RESET_CSS`, which leaves the host's\n * `html` and `body` alone. Its own id, so it sits beside a full reset if the page has both kinds.\n */\nexport function injectIslandResetStylesheet(document: Document): void {\n injectStyle(document, ISLAND_RESET_STYLE_ID, ISLAND_RESET_CSS);\n}\n\nfunction injectStyle(document: Document, id: string, css: string): void {\n if (document.getElementById(id)) return;\n const style = document.createElement('style');\n style.id = id;\n // In Tailwind's `base` layer, below every utility, as `@import '@ng-native/web/reset.css'\n // layer(base)` puts it. Injected unlayered after the app's stylesheet, a reset rule is as\n // specific as a class and later, so it beat `border-2`, `flex-row` and `hidden` alike. With no\n // Tailwind on the page, a layered rule still loses to every unlayered one, as a reset should.\n style.textContent = `@layer base {\\n${css}\\n}`;\n // First in the head: a layer is ordered by where it is first declared, and the documented entry\n // (theme.css and utilities.css) declares no `base`. Declared after it, `base` came after\n // `utilities` and beat every utility again.\n document.head.insertBefore(style, document.head.firstChild);\n}\n\nexport interface MountOptions {\n readonly providers?: (Provider | EnvironmentProviders)[];\n /**\n * The component's inputs, by their public name, set before its first render - so an\n * `input.required()` has its value from the start rather than throwing on the first check.\n * Change them afterwards with `componentRef.setInput`.\n */\n readonly inputs?: Readonly<Record<string, unknown>>;\n /**\n * Injects the reset stylesheet into `document.head` before mounting. Defaults to `true`. With\n * `injector` it is the island reset, which leaves the host page's `html` and `body` alone.\n */\n readonly injectReset?: boolean;\n /**\n * Mount inside an existing Angular app instead of as an app of its own: pass an injector from\n * that app - `inject(Injector)` in the component that owns `rootElement` is the usual one.\n *\n * The island then shares the host app's services (anything `providedIn: 'root'`, and anything\n * its `bootstrapApplication` or a component above it provides) and is checked by the host's\n * change detection. Only what the island has to render differently is its own: the renderer,\n * the engine, and the device services that read the browser rather than a phone. See\n * `packages/web/islands.md` in the documentation.\n */\n readonly injector?: Injector;\n /**\n * Keeps a `dark` class on `rootElement` in step with `ColorScheme`, which is what\n * `@ng-native/tailwind`'s `dark:` variant and a theme's `.dark` block match beneath: the system's\n * `prefers-color-scheme`, or what `ColorScheme.set()` chose over it. Defaults to `true`, as\n * `watchConditions` does on a device. An app that puts `dark` on its own root view turns it off.\n */\n readonly darkClass?: boolean;\n}\n\nexport interface MountResult {\n readonly componentRef: ComponentRef<unknown>;\n /** The island's own app, or with `injector` the host app it was mounted into. */\n readonly applicationRef: ApplicationRef;\n readonly factory: BrowserRendererFactory;\n readonly engine: BrowserEngine;\n /**\n * Takes the island down: its component, and whatever it owns. With `injector` that is only the\n * island - the host app it was mounted into keeps running - so call this rather than\n * `applicationRef.destroy()`, which there would destroy the host.\n */\n destroy(): void;\n}\n\nexport function mount(\n rootElement: Element,\n component: Type<unknown>,\n options: MountOptions = {},\n): MountResult {\n const {\n providers: extraProviders = [],\n inputs = {},\n injectReset = true,\n injector: host,\n darkClass = true,\n } = options;\n const document = rootElement.ownerDocument;\n if (injectReset) {\n if (host) injectIslandResetStylesheet(document);\n else injectResetStylesheet(document);\n }\n // What `reset.css` hangs the root's height off. Stamped rather than required of the app,\n // because an app that forgot it would get a page whose `flex: 1` silently resolved to zero.\n rootElement.setAttribute('data-rn-root', '');\n // What `@ng-native/tailwind`'s `web:` variant matches beneath, as `platform-ios` does on a phone.\n rootElement.classList.add('platform-web');\n\n const engine = new BrowserEngine(document);\n const factory = new BrowserRendererFactory(engine, document);\n // `wrapRoot` marks the element `ngSkipHydration`; an island gives back what it had on unmount.\n const skipHydration = rootElement.getAttribute('ngSkipHydration');\n const rootNode = engine.wrapRoot(rootElement) as unknown as Element;\n const own = hostProviders(engine, factory, document.defaultView);\n\n const mounted = host\n ? mountInside(\n host,\n rootElement,\n rootNode,\n component,\n [...own, ...extraProviders],\n inputs,\n {\n factory,\n engine,\n },\n skipHydration,\n )\n : mountAlone(rootNode, component, [...own, ...extraProviders], inputs, document, {\n factory,\n engine,\n });\n // The engine listens on the whole document, so it has to stop once its app is gone, however\n // the app went: through `destroy()` or straight through the component ref.\n mounted.componentRef.onDestroy(() => engine.dispose());\n if (darkClass) keepDarkClass(rootElement, mounted.componentRef);\n return mounted;\n}\n\n/** The `darkClass` option: the class now, and again whenever `ColorScheme` changes. */\nfunction keepDarkClass(rootElement: Element, componentRef: ComponentRef<unknown>): void {\n const scheme = componentRef.injector.get(ColorScheme);\n const apply = () => rootElement.classList.toggle('dark', scheme.current() === 'dark');\n apply();\n effect(apply, { injector: componentRef.injector });\n componentRef.onDestroy(() => rootElement.classList.remove('dark'));\n}\n\n/**\n * What an island has to have of its own, whichever way it is mounted: the renderer and engine\n * that turn `<view>` into a `<div>`, and the device capabilities answered by the browser.\n */\nfunction hostProviders(\n engine: BrowserEngine,\n factory: BrowserRendererFactory,\n view: Document['defaultView'],\n): (Provider | EnvironmentProviders)[] {\n return [\n { provide: RendererFactory2, useValue: factory },\n // The one seam the shared packages inject. See the file doc for why `Engine` itself is not\n // also provided here.\n { provide: HostEngine, useValue: engine },\n // The device capabilities, from the browser rather than from React Native. Without these\n // `Screen` falls back to its off-device answer of a zero-sized window, and every component\n // that branches on `compact()` takes the phone tree. See `device-sources.ts`.\n ...(view\n ? [\n { provide: Screen.SOURCE, useValue: browserScreenSource(view) },\n { provide: ColorScheme.SOURCE, useValue: browserColorSchemeSource(view) },\n { provide: Direction.SOURCE, useValue: browserDirectionSource(view) },\n ]\n : []),\n // A tab has no hardware back button, so this is the same inert fallback\n // `hardwareBackSource()`'s own off-device branch answers with, provided here so the browser\n // host says so itself rather than relying on that branch.\n { provide: HardwareBack.SOURCE, useValue: { subscribe: () => () => {} } },\n // A tab has no status bar either.\n {\n provide: StatusBar.SOURCE,\n useValue: {\n setStyle: () => {},\n setHidden: () => {},\n setBackgroundColor: () => {},\n setTranslucent: () => {},\n height: undefined,\n },\n },\n ];\n}\n\n/** An app of its own: its own root injector, change detection and `ApplicationRef`. */\nfunction mountAlone(\n rootNode: Element,\n component: Type<unknown>,\n providers: (Provider | EnvironmentProviders)[],\n inputs: Readonly<Record<string, unknown>>,\n document: Document,\n host: { factory: BrowserRendererFactory; engine: BrowserEngine },\n): MountResult {\n // Parent the app injector to the platform injector, exactly as `internalCreateApplication`\n // does and `mount()` documents: some Angular services are `providedIn: 'platform'`, and with a\n // null parent they simply do not exist.\n const platformInjector = createOrReusePlatformInjector();\n\n const injector = createEnvironmentInjector(\n [\n { provide: INJECTOR_SCOPE, useValue: 'root' },\n provideZonelessChangeDetectionInternal(),\n { provide: DOCUMENT, useValue: document },\n // A DOM is what this is running in, so libraries that check isPlatformBrowser() are right to\n // use it. An island inside an app is the app's own and inherits its value instead.\n { provide: PLATFORM_ID, useValue: 'browser' },\n { provide: ErrorHandler, useClass: ErrorHandler },\n ...providers,\n ],\n platformInjector as EnvironmentInjector,\n );\n setLocaleId(injector.get(LOCALE_ID) || 'en-US');\n\n const componentRef = createComponent(component, {\n environmentInjector: injector,\n hostElement: rootNode,\n });\n setInputs(componentRef, inputs);\n\n const applicationRef = injector.get(ApplicationRef);\n\n // Mirrors `ApplicationRef.bootstrap()`, which is not used directly because it wants a DOM\n // selector rather than an element `mount`'s own caller already resolved.\n applicationRef.componentTypes.push(component);\n applicationRef.attachView(componentRef.hostView);\n applicationRef.tick();\n // Load-bearing, not bookkeeping: the router's bootstrap listener returns early unless the ref\n // it is handed is `ApplicationRef.components[0]`.\n applicationRef.components.push(componentRef);\n componentRef.onDestroy(() => {\n applicationRef.detachView(componentRef.hostView);\n const at = applicationRef.components.indexOf(componentRef);\n if (at !== -1) applicationRef.components.splice(at, 1);\n });\n\n for (const listener of injector.get(APP_BOOTSTRAP_LISTENER, [])) {\n listener(componentRef);\n }\n\n return {\n componentRef,\n applicationRef,\n ...host,\n destroy: () => {\n componentRef.destroy();\n applicationRef.destroy();\n },\n };\n}\n\n/**\n * An island inside a running app. Its environment injector is a child of the host's, without a\n * root scope of its own, so anything it does not provide - a `providedIn: 'root'` service, the\n * host's `ApplicationRef` and scheduler, its `ErrorHandler` - resolves from the host, once, for\n * both. What it does provide is only what has to differ: the renderer and engine, the browser's\n * device sources, and the five device services that read them. Those five are provided here as\n * classes so they are built in the island, against its sources, rather than in the host's root\n * against the phone defaults.\n *\n * The host's element injector goes in too, so a service a component above the island provides\n * is visible to it as well as one the app does.\n */\nfunction mountInside(\n hostInjector: Injector,\n rootElement: Element,\n rootNode: Element,\n component: Type<unknown>,\n providers: (Provider | EnvironmentProviders)[],\n inputs: Readonly<Record<string, unknown>>,\n host: { factory: BrowserRendererFactory; engine: BrowserEngine },\n skipHydration: string | null,\n): MountResult {\n const injector = createEnvironmentInjector(\n [Screen, ColorScheme, Direction, HardwareBack, StatusBar, ...providers],\n hostInjector.get(EnvironmentInjector),\n );\n\n const componentRef = createComponent(component, {\n environmentInjector: injector,\n elementInjector: hostInjector,\n hostElement: rootNode,\n });\n setInputs(componentRef, inputs);\n\n // The host's own change detection checks the island from here on, like any view of its own.\n const applicationRef = hostInjector.get(ApplicationRef);\n applicationRef.attachView(componentRef.hostView);\n componentRef.changeDetectorRef.detectChanges();\n\n return {\n componentRef,\n applicationRef,\n ...host,\n destroy: () => {\n componentRef.destroy();\n injector.destroy();\n rootElement.removeAttribute('data-rn-root');\n if (skipHydration === null) rootElement.removeAttribute('ngSkipHydration');\n else rootElement.setAttribute('ngSkipHydration', skipHydration);\n rootElement.classList.remove('platform-web');\n },\n };\n}\n\nfunction setInputs(componentRef: ComponentRef<unknown>, inputs: Readonly<Record<string, unknown>>) {\n for (const [name, value] of Object.entries(inputs)) componentRef.setInput(name, value);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/web",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "A browser host for Angular Native: the same components, rendered into the DOM instead of native views.",
5
5
  "keywords": [
6
6
  "angular",
@@ -35,8 +35,8 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@ng-native/device": "0.10.0",
39
- "@ng-native/fabric": "0.10.0",
38
+ "@ng-native/device": "0.12.0",
39
+ "@ng-native/fabric": "0.12.0",
40
40
  "@oxc-angular/vite": "0.0.40"
41
41
  },
42
42
  "peerDependencies": {
@@ -51,13 +51,14 @@
51
51
  "devDependencies": {
52
52
  "@angular/common": "22.2.0",
53
53
  "@angular/compiler": "22.2.0",
54
+ "@angular/localize": "22.2.0",
54
55
  "@angular/platform-browser": "22.2.0",
55
56
  "@ng-icons/core": "^36.0.0",
56
- "@ng-native/components": "0.10.0",
57
- "@ng-native/icons": "0.10.0",
58
- "@ng-native/metro": "0.10.0",
59
- "@ng-native/tailwind": "0.10.0",
60
- "@ng-native/testing": "0.10.0",
57
+ "@ng-native/components": "0.12.0",
58
+ "@ng-native/icons": "0.12.0",
59
+ "@ng-native/metro": "0.12.0",
60
+ "@ng-native/tailwind": "0.12.0",
61
+ "@ng-native/testing": "0.12.0",
61
62
  "@tailwindcss/vite": "^4.3.3",
62
63
  "@types/jsdom": "^27.0.0",
63
64
  "@vitest/browser": "^5.0.2",
@@ -71,6 +72,7 @@
71
72
  "rxjs": "^7.8.2",
72
73
  "tailwindcss": "^4.3.3",
73
74
  "tailwindcss-v3": "npm:tailwindcss@^3.4.19",
75
+ "typescript": "~6.0.3",
74
76
  "vite": "^8.3.1",
75
77
  "vitest": "^5.0.2"
76
78
  },