@ng-native/web 0.2.0 → 0.4.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.
- package/dist/browser-engine.d.ts +25 -1
- package/dist/browser-engine.js +79 -26
- package/dist/browser-engine.js.map +1 -1
- package/dist/device-sources.d.ts +4 -2
- package/dist/device-sources.js +23 -8
- package/dist/device-sources.js.map +1 -1
- package/dist/dom-node.d.ts +10 -0
- package/dist/dom-node.js +14 -0
- package/dist/dom-node.js.map +1 -1
- package/dist/elements.d.ts +13 -8
- package/dist/elements.js +19 -1
- package/dist/elements.js.map +1 -1
- package/dist/jsdom-env.js +1 -0
- package/dist/jsdom-env.js.map +1 -1
- package/dist/mount.d.ts +7 -0
- package/dist/mount.js +23 -14
- package/dist/mount.js.map +1 -1
- package/dist/props.js +32 -4
- package/dist/props.js.map +1 -1
- package/dist/reset-css.d.ts +1 -1
- package/dist/reset-css.js +142 -2
- package/dist/reset-css.js.map +1 -1
- package/dist/reset.css +167 -7
- package/package.json +13 -10
- package/vite.d.mts +7 -0
- package/vite.mjs +84 -7
package/dist/dom-node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom-node.js","sourceRoot":"","sources":["../src/dom-node.ts"],"names":[],"mappings":"AAgDA,mGAAmG;AACnG,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC;AAEnG,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;I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AAE,IAAI;KACd,CAAC;IACF,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC;AACd,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 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(['svg-g', 'svg-path', 'svg-circle', 'svg-ellipse', 'svg-rect']);\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 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/** 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":"AAwDA,mGAAmG;AACnG,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC;AAEnG,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,4FAA4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AE,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(['svg-g', 'svg-path', 'svg-circle', 'svg-ellipse', 'svg-rect']);\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"]}
|
package/dist/elements.d.ts
CHANGED
|
@@ -18,14 +18,12 @@
|
|
|
18
18
|
* `<view>` accept a text cursor or a space-bar toggle, though, because those are behaviours the
|
|
19
19
|
* browser's own form controls implement in C++, not CSS or JavaScript this package could add. So:
|
|
20
20
|
*
|
|
21
|
-
* - `text-input` commits as a real `<
|
|
22
|
-
* `multiline` is a prop set *after* creation (an Angular
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* non-standard `-webkit-text-security` (see `props.ts`)
|
|
27
|
-
* the text in the clear, which is the one place this package's accessibility parity is
|
|
28
|
-
* actually worse than a wrong guess would be quieter about.
|
|
21
|
+
* - `text-input` commits as a real `<input>`, and as a `<textarea>` while `multiline` is on. The
|
|
22
|
+
* tag a field needs is not known here: `multiline` is a prop set *after* creation (an Angular
|
|
23
|
+
* host binding, run on the first change detection pass), so `browser-engine.ts` swaps the
|
|
24
|
+
* element when it arrives. Only an `<input>` centres its line in a taller box, as a device's
|
|
25
|
+
* one-line field does, and only an `<input>` can be `type="password"` for `secureTextEntry`. A
|
|
26
|
+
* multiline field masks with the non-standard `-webkit-text-security` instead (see `props.ts`).
|
|
29
27
|
* - `switch` commits as a real `<input type="checkbox">`. Its accessible role still comes from
|
|
30
28
|
* `ViewBase`'s normal prop pipeline (`Switch.roleByDefault()` returns `'switch'`, which
|
|
31
29
|
* `props.ts`'s `ROLE_MAP` turns into `role="switch"`) - this file only has to make the element
|
|
@@ -77,3 +75,10 @@ export declare function specFor(name: string): ElementSpec;
|
|
|
77
75
|
* needs to change for it.
|
|
78
76
|
*/
|
|
79
77
|
export declare function createDomElement(document: Document, name: string): Element;
|
|
78
|
+
/**
|
|
79
|
+
* A `<textarea>` for a multiline `text-input`, or an `<input>` for a one-line one, standing in for
|
|
80
|
+
* `old`: its attributes (inline style and scoping attributes among them) and its value. What the
|
|
81
|
+
* two tags do differently (`type`, `rows` and a textarea's masking) is left for the caller to
|
|
82
|
+
* write again.
|
|
83
|
+
*/
|
|
84
|
+
export declare function textFieldLike(old: HTMLInputElement | HTMLTextAreaElement, multiline: boolean): HTMLInputElement | HTMLTextAreaElement;
|
package/dist/elements.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** The one non-HTML namespace this package ever needs. */
|
|
2
2
|
export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
3
3
|
const SPECS = {
|
|
4
|
-
'text-input': { tag: '
|
|
4
|
+
'text-input': { tag: 'input', attrs: { type: 'text' } },
|
|
5
5
|
switch: { tag: 'input', attrs: { type: 'checkbox' } },
|
|
6
6
|
'activity-indicator': { tag: 'activity-indicator', attrs: { role: 'progressbar' } },
|
|
7
7
|
// The shapes `@ng-native/icons`' `svg-elements.ts` registers. Real SVG tag names, not the prefixed
|
|
@@ -50,4 +50,22 @@ export function createDomElement(document, name) {
|
|
|
50
50
|
el.setAttribute(attr, value);
|
|
51
51
|
return el;
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* A `<textarea>` for a multiline `text-input`, or an `<input>` for a one-line one, standing in for
|
|
55
|
+
* `old`: its attributes (inline style and scoping attributes among them) and its value. What the
|
|
56
|
+
* two tags do differently (`type`, `rows` and a textarea's masking) is left for the caller to
|
|
57
|
+
* write again.
|
|
58
|
+
*/
|
|
59
|
+
export function textFieldLike(old, multiline) {
|
|
60
|
+
const field = old.ownerDocument.createElement(multiline ? 'textarea' : 'input');
|
|
61
|
+
for (const { name, value } of old.attributes) {
|
|
62
|
+
if (name !== 'type' && name !== 'rows')
|
|
63
|
+
field.setAttribute(name, value);
|
|
64
|
+
}
|
|
65
|
+
field.style.removeProperty('-webkit-text-security');
|
|
66
|
+
if (multiline)
|
|
67
|
+
field.setAttribute('rows', '1');
|
|
68
|
+
field.value = old.value;
|
|
69
|
+
return field;
|
|
70
|
+
}
|
|
53
71
|
//# sourceMappingURL=elements.js.map
|
package/dist/elements.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AA0DA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG,4BAA4B,CAAC;AAE1D,MAAM,KAAK,GAAgC;IACzC,YAAY,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;IACvD,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;IACrD,oBAAoB,EAAE,EAAE,GAAG,EAAE,oBAAoB,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE;IACnF,mGAAmG;IACnG,0FAA0F;IAC1F,0FAA0F;IAC1F,uDAAuD;IACvD,OAAO,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,aAAa,EAAE;IACxC,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE;IAC9C,YAAY,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,EAAE;IAClD,aAAa,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,aAAa,EAAE;IACpD,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE;IAC9C,UAAU,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE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E,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;QAC7C,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM;YAAE,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1E,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC;IACpD,IAAI,SAAS;QAAE,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/C,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IACxB,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * The DOM tag each element name commits as.\n *\n * Every name Angular ever creates a host element for - `view`, `text`, `pressable`, and also\n * every component's own selector (a caller's own `x-widget`, say) - becomes a real element with\n * exactly that tag. A browser accepts any tag name and gives it no built-in\n * unregistered name to a plain `View`, because native only has a fixed set of *real* native views\n * to commit as and an arbitrary string is not one of them. A browser has no such list - there is\n * nothing to fall back from - so this file does not reproduce that fallback; the reason for it on\n * native does not exist on the web. `data-rn=\"<name>\"` still goes on every element regardless (it\n * is what `reset.css` selects on, and what the two exceptions below need it for), but the tag\n * itself is always the literal name unless this table says otherwise.\n *\n * ## The two exceptions\n *\n * `ViewBase`'s own prop writes (a real ARIA `role`, `tabindex`, `aria-*`) are enough accessible\n * behaviour for a view, a piece of text, or a scroll container - no amount of them makes a\n * `<view>` accept a text cursor or a space-bar toggle, though, because those are behaviours the\n * browser's own form controls implement in C++, not CSS or JavaScript this package could add. So:\n *\n * - `text-input` commits as a real `<input>`, and as a `<textarea>` while `multiline` is on. The\n * tag a field needs is not known here: `multiline` is a prop set *after* creation (an Angular\n * host binding, run on the first change detection pass), so `browser-engine.ts` swaps the\n * element when it arrives. Only an `<input>` centres its line in a taller box, as a device's\n * one-line field does, and only an `<input>` can be `type=\"password\"` for `secureTextEntry`. A\n * multiline field masks with the non-standard `-webkit-text-security` instead (see `props.ts`).\n * - `switch` commits as a real `<input type=\"checkbox\">`. Its accessible role still comes from\n * `ViewBase`'s normal prop pipeline (`Switch.roleByDefault()` returns `'switch'`, which\n * `props.ts`'s `ROLE_MAP` turns into `role=\"switch\"`) - this file only has to make the element\n * a genuine, keyboard- and screen-reader-operable checkbox underneath that role.\n *\n * `image` stays a plain `data-rn=\"image\"` element rather than a real `<img>`, on purpose: RN's\n * `Image` is a box that a picture fills, sized by flex like any other view, not a replaced\n * inline element with its own intrinsic size fighting the layout. `browser-engine.ts` paints the\n * picture with `background-image`, which is what lets `resizeMode` map straight onto\n * `background-size` instead of needing a wrapper element `object-fit` does not.\n *\n * ## The third exception: SVG\n *\n * `packages/icons/src/svg-elements.ts` registers `svg-g`/`svg-path`/`svg-circle`/`svg-ellipse`/\n * `svg-rect`/`svg-line` and its root (`ng-icon`) against Fabric view names (`RNSVGPath` and so\n * on) so that native drives `react-native-svg` directly with no React component of its own in\n * between - see that file's doc comment. A tag created with `document.createElement` is not\n * enough to make that work here: an element born outside the SVG namespace never paints as SVG no\n * matter what tag string it is given (`document.createElement` always mints an\n * `HTMLUnknownElement` for a name a browser does not recognise, SVG names very much included), so\n * these seven names are the only ones in this file that need `ns` - everything else is content\n * HTML has no opinion on and is happy to create by string alone.\n */\nexport interface ElementSpec {\n readonly tag: string;\n /** Attributes set once, at creation, because the DOM tag needs them to behave at all. */\n readonly attrs?: Readonly<Record<string, string>>;\n /** The element's creation namespace, when it is not HTML's. `createDomElement` reads this to\n * choose `createElementNS` over `createElement` - see \"The third exception: SVG\" above. */\n readonly ns?: string;\n}\n\n/** The one non-HTML namespace this package ever needs. */\nexport const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n\nconst SPECS: Record<string, ElementSpec> = {\n 'text-input': { tag: 'input', attrs: { type: 'text' } },\n switch: { tag: 'input', attrs: { type: 'checkbox' } },\n 'activity-indicator': { tag: 'activity-indicator', attrs: { role: 'progressbar' } },\n // The shapes `@ng-native/icons`' `svg-elements.ts` registers. Real SVG tag names, not the prefixed\n // template names - `svg-path` would otherwise ask the DOM for an element literally called\n // `<svg-path>`, which the SVG namespace has no such thing as and so mints as an unstyled,\n // unpainted `SVGUnknownElement` instead of a `<path>`.\n 'svg-g': { tag: 'g', ns: SVG_NAMESPACE },\n 'svg-path': { tag: 'path', ns: SVG_NAMESPACE },\n 'svg-circle': { tag: 'circle', ns: SVG_NAMESPACE },\n 'svg-ellipse': { tag: 'ellipse', ns: SVG_NAMESPACE },\n 'svg-rect': { tag: 'rect', ns: SVG_NAMESPACE },\n 'svg-line': { tag: 'line', ns: SVG_NAMESPACE },\n // The root. Commits as the same Fabric view natively (`svg-elements.ts`'s own doc comment); a\n // plain `<svg>` here too; `props.ts`'s `SVG_ROOT_HANDLERS` is what reads `NgIcon`'s own host\n // bindings into its `viewBox`/size.\n 'ng-icon': { tag: 'svg', ns: SVG_NAMESPACE },\n};\n\n/**\n * Register a name that needs a real DOM tag or baseline attributes beyond the default (its own\n * name, no attributes) - the web counterpart to `engine.ts`'s `registerViewName`. Nothing in this\n * package needs to guess at an unknown name the way `viewNameOf` does; see the file doc comment\n * for why.\n */\nexport function registerElementName(name: string, spec: ElementSpec): void {\n SPECS[name] = spec;\n}\n\nexport function specFor(name: string): ElementSpec {\n return SPECS[name] ?? { tag: name };\n}\n\n/**\n * Create the real DOM element for a template tag name, with its `data-rn` marker and attrs.\n *\n * `createElementNS` rather than `createElement` whenever a spec names a namespace - see \"The\n * third exception: SVG\" above. `setAttribute`, on the other hand, is namespace-agnostic either\n * way (an attribute has no namespace of its own unless explicitly qualified, which `data-rn` and\n * every attribute this package writes never is), so nothing below the element's own creation\n * needs to change for it.\n */\nexport function createDomElement(document: Document, name: string): Element {\n const spec = specFor(name);\n const el = spec.ns\n ? document.createElementNS(spec.ns, spec.tag)\n : document.createElement(spec.tag);\n el.setAttribute('data-rn', name);\n for (const [attr, value] of Object.entries(spec.attrs ?? {})) el.setAttribute(attr, value);\n return el;\n}\n\n/**\n * A `<textarea>` for a multiline `text-input`, or an `<input>` for a one-line one, standing in for\n * `old`: its attributes (inline style and scoping attributes among them) and its value. What the\n * two tags do differently (`type`, `rows` and a textarea's masking) is left for the caller to\n * write again.\n */\nexport function textFieldLike(\n old: HTMLInputElement | HTMLTextAreaElement,\n multiline: boolean,\n): HTMLInputElement | HTMLTextAreaElement {\n const field = old.ownerDocument.createElement(multiline ? 'textarea' : 'input');\n for (const { name, value } of old.attributes) {\n if (name !== 'type' && name !== 'rows') field.setAttribute(name, value);\n }\n field.style.removeProperty('-webkit-text-security');\n if (multiline) field.setAttribute('rows', '1');\n field.value = old.value;\n return field;\n}\n"]}
|
package/dist/jsdom-env.js
CHANGED
|
@@ -49,6 +49,7 @@ export function installJsdomEnvironment() {
|
|
|
49
49
|
HTMLElement: window.HTMLElement,
|
|
50
50
|
Text: window.Text,
|
|
51
51
|
Comment: window.Comment,
|
|
52
|
+
NodeFilter: window.NodeFilter,
|
|
52
53
|
Event: window.Event,
|
|
53
54
|
PointerEvent: window.PointerEvent ?? window.MouseEvent,
|
|
54
55
|
KeyboardEvent: window.KeyboardEvent,
|
package/dist/jsdom-env.js.map
CHANGED
|
@@ -1 +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,CAA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,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"]}
|
|
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;gBAC5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AAC,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 NodeFilter: window.NodeFilter,\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"]}
|
package/dist/mount.d.ts
CHANGED
|
@@ -71,6 +71,13 @@ export interface MountOptions {
|
|
|
71
71
|
* `packages/web/islands.md` in the documentation.
|
|
72
72
|
*/
|
|
73
73
|
readonly injector?: Injector;
|
|
74
|
+
/**
|
|
75
|
+
* Keeps a `dark` class on `rootElement` in step with `ColorScheme`, which is what
|
|
76
|
+
* `@ng-native/tailwind`'s `dark:` variant and a theme's `.dark` block match beneath: the system's
|
|
77
|
+
* `prefers-color-scheme`, or what `ColorScheme.set()` chose over it. Defaults to `true`, as
|
|
78
|
+
* `watchConditions` does on a device. An app that puts `dark` on its own root view turns it off.
|
|
79
|
+
*/
|
|
80
|
+
readonly darkClass?: boolean;
|
|
74
81
|
}
|
|
75
82
|
export interface MountResult {
|
|
76
83
|
readonly componentRef: ComponentRef<unknown>;
|
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, 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, RendererFactory2, createComponent, effect, createEnvironmentInjector, ɵcreateOrReusePlatformInjector as createOrReusePlatformInjector, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵprovideZonelessChangeDetectionInternal as provideZonelessChangeDetectionInternal, } 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";
|
|
@@ -73,7 +73,7 @@ function injectStyle(document, id, css) {
|
|
|
73
73
|
document.head.insertBefore(style, document.head.firstChild);
|
|
74
74
|
}
|
|
75
75
|
export function mount(rootElement, component, options = {}) {
|
|
76
|
-
const { providers: extraProviders = [], inputs = {}, injectReset = true, injector: host, } = options;
|
|
76
|
+
const { providers: extraProviders = [], inputs = {}, injectReset = true, injector: host, darkClass = true, } = options;
|
|
77
77
|
const document = rootElement.ownerDocument;
|
|
78
78
|
if (injectReset) {
|
|
79
79
|
if (host)
|
|
@@ -88,13 +88,15 @@ export function mount(rootElement, component, options = {}) {
|
|
|
88
88
|
rootElement.classList.add('platform-web');
|
|
89
89
|
const engine = new BrowserEngine(document);
|
|
90
90
|
const factory = new BrowserRendererFactory(engine, document);
|
|
91
|
+
// `wrapRoot` marks the element `ngSkipHydration`; an island gives back what it had on unmount.
|
|
92
|
+
const skipHydration = rootElement.getAttribute('ngSkipHydration');
|
|
91
93
|
const rootNode = engine.wrapRoot(rootElement);
|
|
92
94
|
const own = hostProviders(engine, factory, document.defaultView);
|
|
93
95
|
const mounted = host
|
|
94
96
|
? mountInside(host, rootElement, rootNode, component, [...own, ...extraProviders], inputs, {
|
|
95
97
|
factory,
|
|
96
98
|
engine,
|
|
97
|
-
})
|
|
99
|
+
}, skipHydration)
|
|
98
100
|
: mountAlone(rootNode, component, [...own, ...extraProviders], inputs, document, {
|
|
99
101
|
factory,
|
|
100
102
|
engine,
|
|
@@ -102,8 +104,18 @@ export function mount(rootElement, component, options = {}) {
|
|
|
102
104
|
// The engine listens on the whole document, so it has to stop once its app is gone, however
|
|
103
105
|
// the app went: through `destroy()` or straight through the component ref.
|
|
104
106
|
mounted.componentRef.onDestroy(() => engine.dispose());
|
|
107
|
+
if (darkClass)
|
|
108
|
+
keepDarkClass(rootElement, mounted.componentRef);
|
|
105
109
|
return mounted;
|
|
106
110
|
}
|
|
111
|
+
/** The `darkClass` option: the class now, and again whenever `ColorScheme` changes. */
|
|
112
|
+
function keepDarkClass(rootElement, componentRef) {
|
|
113
|
+
const scheme = componentRef.injector.get(ColorScheme);
|
|
114
|
+
const apply = () => rootElement.classList.toggle('dark', scheme.current() === 'dark');
|
|
115
|
+
apply();
|
|
116
|
+
effect(apply, { injector: componentRef.injector });
|
|
117
|
+
componentRef.onDestroy(() => rootElement.classList.remove('dark'));
|
|
118
|
+
}
|
|
107
119
|
/**
|
|
108
120
|
* What an island has to have of its own, whichever way it is mounted: the renderer and engine
|
|
109
121
|
* that turn `<view>` into a `<div>`, and the device capabilities answered by the browser.
|
|
@@ -125,17 +137,10 @@ function hostProviders(engine, factory, view) {
|
|
|
125
137
|
]
|
|
126
138
|
: []),
|
|
127
139
|
// A tab has no hardware back button, so this is the same inert fallback
|
|
128
|
-
// `hardwareBackSource()`'s own off-device branch answers with
|
|
129
|
-
//
|
|
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.
|
|
140
|
+
// `hardwareBackSource()`'s own off-device branch answers with, provided here so the browser
|
|
141
|
+
// host says so itself rather than relying on that branch.
|
|
135
142
|
{ provide: HardwareBack.SOURCE, useValue: { subscribe: () => () => { } } },
|
|
136
|
-
// A tab has no status bar either
|
|
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.
|
|
143
|
+
// A tab has no status bar either.
|
|
139
144
|
{
|
|
140
145
|
provide: StatusBar.SOURCE,
|
|
141
146
|
useValue: {
|
|
@@ -209,7 +214,7 @@ function mountAlone(rootNode, component, providers, inputs, document, host) {
|
|
|
209
214
|
* The host's element injector goes in too, so a service a component above the island provides
|
|
210
215
|
* is visible to it as well as one the app does.
|
|
211
216
|
*/
|
|
212
|
-
function mountInside(hostInjector, rootElement, rootNode, component, providers, inputs, host) {
|
|
217
|
+
function mountInside(hostInjector, rootElement, rootNode, component, providers, inputs, host, skipHydration) {
|
|
213
218
|
const injector = createEnvironmentInjector([Screen, ColorScheme, Direction, HardwareBack, StatusBar, ...providers], hostInjector.get(EnvironmentInjector));
|
|
214
219
|
const componentRef = createComponent(component, {
|
|
215
220
|
environmentInjector: injector,
|
|
@@ -229,6 +234,10 @@ function mountInside(hostInjector, rootElement, rootNode, component, providers,
|
|
|
229
234
|
componentRef.destroy();
|
|
230
235
|
injector.destroy();
|
|
231
236
|
rootElement.removeAttribute('data-rn-root');
|
|
237
|
+
if (skipHydration === null)
|
|
238
|
+
rootElement.removeAttribute('ngSkipHydration');
|
|
239
|
+
else
|
|
240
|
+
rootElement.setAttribute('ngSkipHydration', skipHydration);
|
|
232
241
|
rootElement.classList.remove('platform-web');
|
|
233
242
|
},
|
|
234
243
|
};
|
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,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EAMzB,8BAA8B,IAAI,6BAA6B,EAC/D,eAAe,IAAI,cAAc,EACjC,uCAAuC,IAAI,sCAAsC,GAClF,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE7D,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAClD,MAAM,qBAAqB,GAAG,iCAAiC,CAAC;AAEhE;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAkB;IACtD,WAAW,CAAC,QAAQ,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAkB;IAC5D,WAAW,CAAC,QAAQ,EAAE,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;AAC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ular 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 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\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 } = 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 const rootNode = engine.wrapRoot(rootElement) as unknown as Element;\n const own = hostProviders(engine, factory, document.defaultView);\n\n const mounted = host\n ? mountInside(host, rootElement, rootNode, component, [...own, ...extraProviders], inputs, {\n factory,\n engine,\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 return mounted;\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 directly rather\n // than left to reach it, because its guard is `typeof require === 'function'`, and a\n // bundler that externalises `react-native` for the browser (`rollupOptions.external` in a\n // production build) leaves `require` defined as a stub that throws when called rather than\n // absent. `HardwareBack` is the one of these five capabilities an anchored overlay actually\n // constructs - `Overlay`'s dismiss-on-back wiring injects it - so it is the one this had to\n // stop before reaching that guard at all.\n { provide: HardwareBack.SOURCE, useValue: { subscribe: () => () => {} } },\n // A tab has no status bar either, and for the same reason this cannot be left to\n // `statusBarSource()`: an app that asks for dark icons over a light screen is ordinary, and\n // without this its component throws on that stub and never renders.\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): 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 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;;;;;;;;;;;;;;;;;;;;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B,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;YAC5C,IAAI,aAAa,KAAK,IAAI;gBAAE,WAAW,CAAC,eAAe,CAAC,iBAAiB,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"]}
|
package/dist/props.js
CHANGED
|
@@ -57,9 +57,11 @@ export const ROLE_MAP = {
|
|
|
57
57
|
viewgroup: 'group',
|
|
58
58
|
iconmenu: 'menu',
|
|
59
59
|
};
|
|
60
|
-
function applyRole(node
|
|
60
|
+
function applyRole(node) {
|
|
61
|
+
// Whichever of the two changed, `role` is the one read where an element has both, as on native.
|
|
62
|
+
const value = node.props['role'] ?? node.props['accessibilityRole'];
|
|
61
63
|
const role = typeof value === 'string' ? (ROLE_MAP[value] ?? value) : undefined;
|
|
62
|
-
setOrRemove(node, 'role', role,
|
|
64
|
+
setOrRemove(node, 'role', role, role === undefined);
|
|
63
65
|
// Which attribute `checked` goes to depends on the role, and the two arrive in either order.
|
|
64
66
|
const state = node.props['accessibilityState'];
|
|
65
67
|
applyAccessibilityState(node, state, state === undefined || state === null);
|
|
@@ -238,7 +240,24 @@ const VIEW_BASE_HANDLERS = {
|
|
|
238
240
|
accessibilityShowsLargeContentViewer: noop,
|
|
239
241
|
accessibilityRespondsToUserInteraction: noop,
|
|
240
242
|
};
|
|
241
|
-
/**
|
|
243
|
+
/**
|
|
244
|
+
* A one-line field's `type`: a password while `secureTextEntry` is on, `tel` for a phone keyboard,
|
|
245
|
+
* and `text` otherwise. The other keyboards stay `inputmode` only, which is what picks the
|
|
246
|
+
* on-screen keyboard. In Chromium, `type="email"` throws from `setSelectionRange`, reads null for
|
|
247
|
+
* `selectionStart`, trims the value the app set, and hides the spaces the user types from its
|
|
248
|
+
* value, so `changeText` would report something other than what is on screen. `type="url"` trims
|
|
249
|
+
* the value the app set. `type="number"` has no selection API, and `type="search"` draws a clear
|
|
250
|
+
* button of its own and empties itself on Escape.
|
|
251
|
+
*/
|
|
252
|
+
function setInputType(n) {
|
|
253
|
+
const field = el(n);
|
|
254
|
+
if (field.tagName !== 'INPUT')
|
|
255
|
+
return;
|
|
256
|
+
const secure = n.props['secureTextEntry'] === true;
|
|
257
|
+
const phone = n.props['keyboardType'] === 'phone-pad';
|
|
258
|
+
field.type = secure ? 'password' : phone ? 'tel' : 'text';
|
|
259
|
+
}
|
|
260
|
+
/** `text-input.ts`'s own props, applied to the `<input>` or `<textarea>` it commits as. */
|
|
242
261
|
const TEXT_INPUT_HANDLERS = {
|
|
243
262
|
text: (n, v, c) => {
|
|
244
263
|
const textarea = el(n);
|
|
@@ -261,16 +280,25 @@ const TEXT_INPUT_HANDLERS = {
|
|
|
261
280
|
'email-address': 'email',
|
|
262
281
|
'phone-pad': 'tel',
|
|
263
282
|
url: 'url',
|
|
283
|
+
'web-search': 'search',
|
|
264
284
|
};
|
|
265
285
|
const mode = typeof v === 'string' ? map[v] : undefined;
|
|
266
286
|
setOrRemove(n, 'inputmode', mode, c || mode === undefined);
|
|
287
|
+
setInputType(n);
|
|
267
288
|
},
|
|
268
289
|
returnKeyType: (n, v, c) => {
|
|
269
290
|
const known = new Set(['done', 'go', 'next', 'search', 'send', 'previous']);
|
|
270
291
|
const hint = typeof v === 'string' && known.has(v) ? v : undefined;
|
|
271
292
|
setOrRemove(n, 'enterkeyhint', hint, c || hint === undefined);
|
|
272
293
|
},
|
|
273
|
-
|
|
294
|
+
// A password field where there can be one. A textarea has no password type, so a multiline
|
|
295
|
+
// field masks with the non-standard property, which Firefox does not have.
|
|
296
|
+
secureTextEntry: (n, v, c) => {
|
|
297
|
+
if (el(n).tagName === 'INPUT')
|
|
298
|
+
setInputType(n);
|
|
299
|
+
else
|
|
300
|
+
setStyleProp(n, '-webkit-text-security', v ? 'disc' : '', c || !v);
|
|
301
|
+
},
|
|
274
302
|
autoCapitalize: (n, v, c) => setOrRemove(n, 'autocapitalize', v === 'none' ? 'off' : v, c),
|
|
275
303
|
autoCorrect: (n, v, c) => setOrRemove(n, 'autocorrect', v ? 'on' : 'off', c),
|
|
276
304
|
autoFocus: (n, v, c) => {
|