@ng-native/web 0.2.0 → 0.3.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/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: 'textarea', attrs: { rows: '1' } },
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
@@ -1 +1 @@
1
- {"version":3,"file":"elements.js","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AA4DA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG,4BAA4B,CAAC;AAE1D,MAAM,KAAK,GAAgC;IACzC,YAAY,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,IAAI,EAA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MAAM,EAAE,GAAG,IAAI,CAAC,EAAE;QAChB,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC;QAC7C,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACjC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3F,OAAO,EAAE,CAAC;AACZ,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 `<textarea>`. A `<textarea>` rather than an `<input>` because\n * `multiline` is a prop set *after* creation (an Angular host binding, run on the first change\n * detection pass, not known at `createElement`), and a `<textarea>` can stand in for a\n * single-line field by intercepting `Enter` (see `browser-engine.ts`) in a way an `<input>`\n * cannot stand in for a multi-line one. `secureTextEntry` is approximated with the\n * non-standard `-webkit-text-security` (see `props.ts`); Firefox has no equivalent and shows\n * the text in the clear, which is the one place this package's accessibility parity is\n * actually worse than a wrong guess would be quieter about.\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: 'textarea', attrs: { rows: '1' } },\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"]}
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,EAAE,EAAE,aAAa,EAAE;IAC9C,8FAA8F;IAC9F,6FAA6F;IAC7F,oCAAoC;IACpC,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,mBAA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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/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)
@@ -102,8 +102,18 @@ export function mount(rootElement, component, options = {}) {
102
102
  // The engine listens on the whole document, so it has to stop once its app is gone, however
103
103
  // the app went: through `destroy()` or straight through the component ref.
104
104
  mounted.componentRef.onDestroy(() => engine.dispose());
105
+ if (darkClass)
106
+ keepDarkClass(rootElement, mounted.componentRef);
105
107
  return mounted;
106
108
  }
109
+ /** The `darkClass` option: the class now, and again whenever `ColorScheme` changes. */
110
+ function keepDarkClass(rootElement, componentRef) {
111
+ const scheme = componentRef.injector.get(ColorScheme);
112
+ const apply = () => rootElement.classList.toggle('dark', scheme.current() === 'dark');
113
+ apply();
114
+ effect(apply, { injector: componentRef.injector });
115
+ componentRef.onDestroy(() => rootElement.classList.remove('dark'));
116
+ }
107
117
  /**
108
118
  * What an island has to have of its own, whichever way it is mounted: the renderer and engine
109
119
  * that turn `<view>` into a `<div>`, and the device capabilities answered by the browser.
@@ -125,17 +135,10 @@ function hostProviders(engine, factory, view) {
125
135
  ]
126
136
  : []),
127
137
  // A tab has no hardware back button, so this is the same inert fallback
128
- // `hardwareBackSource()`'s own off-device branch answers with - provided directly rather
129
- // than left to reach it, because its guard is `typeof require === 'function'`, and a
130
- // bundler that externalises `react-native` for the browser (`rollupOptions.external` in a
131
- // production build) leaves `require` defined as a stub that throws when called rather than
132
- // absent. `HardwareBack` is the one of these five capabilities an anchored overlay actually
133
- // constructs - `Overlay`'s dismiss-on-back wiring injects it - so it is the one this had to
134
- // stop before reaching that guard at all.
138
+ // `hardwareBackSource()`'s own off-device branch answers with, provided here so the browser
139
+ // host says so itself rather than relying on that branch.
135
140
  { provide: HardwareBack.SOURCE, useValue: { subscribe: () => () => { } } },
136
- // A tab has no status bar either, and for the same reason this cannot be left to
137
- // `statusBarSource()`: an app that asks for dark icons over a light screen is ordinary, and
138
- // without this its component throws on that stub and never renders.
141
+ // A tab has no status bar either.
139
142
  {
140
143
  provide: StatusBar.SOURCE,
141
144
  useValue: {
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,GAA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;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 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,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,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;IAE/C,OAAO;QACL,YAAY;QACZ,cAAc;QACd,GAAG,IAAI;QACP,OAAO,EAAE,GAAG,EAAE;YACZ,YAAY,CAAC,OAAO,EAAE,CAAC;YACvB,QAAQ,CAAC,OAAO,EAAE,CAAC;YACnB,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;YAC5C,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 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 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): 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"]}
package/dist/props.js CHANGED
@@ -238,7 +238,24 @@ const VIEW_BASE_HANDLERS = {
238
238
  accessibilityShowsLargeContentViewer: noop,
239
239
  accessibilityRespondsToUserInteraction: noop,
240
240
  };
241
- /** `text-input.ts`'s own props, applied to the `<textarea>` `elements.ts` creates for it. */
241
+ /**
242
+ * A one-line field's `type`: a password while `secureTextEntry` is on, `tel` for a phone keyboard,
243
+ * and `text` otherwise. The other keyboards stay `inputmode` only, which is what picks the
244
+ * on-screen keyboard. In Chromium, `type="email"` throws from `setSelectionRange`, reads null for
245
+ * `selectionStart`, trims the value the app set, and hides the spaces the user types from its
246
+ * value, so `changeText` would report something other than what is on screen. `type="url"` trims
247
+ * the value the app set. `type="number"` has no selection API, and `type="search"` draws a clear
248
+ * button of its own and empties itself on Escape.
249
+ */
250
+ function setInputType(n) {
251
+ const field = el(n);
252
+ if (field.tagName !== 'INPUT')
253
+ return;
254
+ const secure = n.props['secureTextEntry'] === true;
255
+ const phone = n.props['keyboardType'] === 'phone-pad';
256
+ field.type = secure ? 'password' : phone ? 'tel' : 'text';
257
+ }
258
+ /** `text-input.ts`'s own props, applied to the `<input>` or `<textarea>` it commits as. */
242
259
  const TEXT_INPUT_HANDLERS = {
243
260
  text: (n, v, c) => {
244
261
  const textarea = el(n);
@@ -261,16 +278,25 @@ const TEXT_INPUT_HANDLERS = {
261
278
  'email-address': 'email',
262
279
  'phone-pad': 'tel',
263
280
  url: 'url',
281
+ 'web-search': 'search',
264
282
  };
265
283
  const mode = typeof v === 'string' ? map[v] : undefined;
266
284
  setOrRemove(n, 'inputmode', mode, c || mode === undefined);
285
+ setInputType(n);
267
286
  },
268
287
  returnKeyType: (n, v, c) => {
269
288
  const known = new Set(['done', 'go', 'next', 'search', 'send', 'previous']);
270
289
  const hint = typeof v === 'string' && known.has(v) ? v : undefined;
271
290
  setOrRemove(n, 'enterkeyhint', hint, c || hint === undefined);
272
291
  },
273
- secureTextEntry: (n, v, c) => setStyleProp(n, '-webkit-text-security', v ? 'disc' : '', c || !v),
292
+ // A password field where there can be one. A textarea has no password type, so a multiline
293
+ // field masks with the non-standard property, which Firefox does not have.
294
+ secureTextEntry: (n, v, c) => {
295
+ if (el(n).tagName === 'INPUT')
296
+ setInputType(n);
297
+ else
298
+ setStyleProp(n, '-webkit-text-security', v ? 'disc' : '', c || !v);
299
+ },
274
300
  autoCapitalize: (n, v, c) => setOrRemove(n, 'autocapitalize', v === 'none' ? 'off' : v, c),
275
301
  autoCorrect: (n, v, c) => setOrRemove(n, 'autocorrect', v ? 'on' : 'off', c),
276
302
  autoFocus: (n, v, c) => {