@ng-native/web 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +79 -1
- package/dist/browser-engine.d.ts +146 -0
- package/dist/browser-engine.js +585 -0
- package/dist/browser-engine.js.map +1 -0
- package/dist/browser-renderer.d.ts +87 -0
- package/dist/browser-renderer.js +295 -0
- package/dist/browser-renderer.js.map +1 -0
- package/dist/css-units.d.ts +9 -0
- package/dist/css-units.js +98 -0
- package/dist/css-units.js.map +1 -0
- package/dist/device-sources.d.ts +53 -0
- package/dist/device-sources.js +96 -0
- package/dist/device-sources.js.map +1 -0
- package/dist/dom-node.d.ts +63 -0
- package/dist/dom-node.js +103 -0
- package/dist/dom-node.js.map +1 -0
- package/dist/elements.d.ts +79 -0
- package/dist/elements.js +53 -0
- package/dist/elements.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/island.d.ts +46 -0
- package/dist/island.js +109 -0
- package/dist/island.js.map +1 -0
- package/dist/jsdom-env.d.ts +4 -0
- package/dist/jsdom-env.js +67 -0
- package/dist/jsdom-env.js.map +1 -0
- package/dist/mount.d.ts +88 -0
- package/dist/mount.js +240 -0
- package/dist/mount.js.map +1 -0
- package/dist/native-style.d.ts +8 -0
- package/dist/native-style.js +108 -0
- package/dist/native-style.js.map +1 -0
- package/dist/props.d.ts +54 -0
- package/dist/props.js +608 -0
- package/dist/props.js.map +1 -0
- package/dist/reset-css.d.ts +26 -0
- package/dist/reset-css.js +163 -0
- package/dist/reset-css.js.map +1 -0
- package/dist/reset.css +282 -0
- package/dist/responder.d.ts +55 -0
- package/dist/responder.js +137 -0
- package/dist/responder.js.map +1 -0
- package/dist/web-view.d.ts +46 -0
- package/dist/web-view.js +93 -0
- package/dist/web-view.js.map +1 -0
- package/package.json +92 -3
- package/vite.d.mts +11 -0
- package/vite.mjs +41 -0
|
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,IAAgE;IAEhE,MAAM,QAAQ,GAAG,yBAAyB,CACxC,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC,EACvE,YAAY,CAAC,GAAG,CAAC,mBAAmB,CAAC,CACtC,CAAC;IAEF,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,EAAE;QAC9C,mBAAmB,EAAE,QAAQ;QAC7B,eAAe,EAAE,YAAY;QAC7B,WAAW,EAAE,QAAQ;KACtB,CAAC,CAAC;IACH,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAEhC,4FAA4F;IAC5F,MAAM,cAAc,GAAG,YAAY,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxD,cAAc,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACjD,YAAY,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC;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 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"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type Style = Readonly<Record<string, unknown>>;
|
|
2
|
+
/**
|
|
3
|
+
* Write what one changed key means, given the whole style it is now part of, and return the CSS
|
|
4
|
+
* properties that covers so a caller replacing a whole object knows what it wrote. `key` is
|
|
5
|
+
* dash-cased and `style` keyed the same way.
|
|
6
|
+
*/
|
|
7
|
+
export declare function writeStyleKey(declaration: CSSStyleDeclaration, key: string, style: Style, priority?: string): readonly string[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The React Native style keys CSS has no property of the same name for, written as the CSS they
|
|
3
|
+
* stand for.
|
|
4
|
+
*
|
|
5
|
+
* Everything else in a style reaches the browser dash-cased and in units (`css-units.ts`), and
|
|
6
|
+
* the browser does the rest. These were handed over the same way and dropped without a word,
|
|
7
|
+
* because `padding-horizontal` and `shadow-offset` are not CSS properties and `{ width: 0,
|
|
8
|
+
* height: 6 }` is not a length. Now each is resolved from the whole style it belongs to, which is
|
|
9
|
+
* what two of the three kinds here need:
|
|
10
|
+
*
|
|
11
|
+
* - `paddingHorizontal` and its three siblings stand for two edges each, and in Yoga a single
|
|
12
|
+
* edge beats them whichever was written first. So `padding-left` is resolved from
|
|
13
|
+
* `padding-left`, falling back to `padding-horizontal`, and either key changing re-resolves it.
|
|
14
|
+
* - `shadowColor`, `shadowOffset`, `shadowOpacity` and `shadowRadius` are four halves of one
|
|
15
|
+
* `box-shadow`, and the three `textShadow*` keys of one `text-shadow`. A `boxShadow` named
|
|
16
|
+
* outright in the same style wins over them.
|
|
17
|
+
*
|
|
18
|
+
* One order is not Yoga's: a `padding` written after `paddingHorizontal` resets both edges, since
|
|
19
|
+
* the browser expands the shorthand over them, where Yoga keeps the more specific key.
|
|
20
|
+
*
|
|
21
|
+
* - `start`, `marginStart`, `paddingEnd` and the rest of Yoga's inline edges are the logical
|
|
22
|
+
* properties. Where one meets a physical edge the browser goes by which was written last, where
|
|
23
|
+
* Yoga always lets the logical one win.
|
|
24
|
+
*
|
|
25
|
+
* What is left alone: `elevation`, Android's own shadow, which has no geometry to translate.
|
|
26
|
+
*/
|
|
27
|
+
import { cssValue } from "./css-units.js";
|
|
28
|
+
const EDGES = { horizontal: ['left', 'right'], vertical: ['top', 'bottom'] };
|
|
29
|
+
/** Each shorthand-like key, to the CSS properties it feeds. Any other key feeds only itself. */
|
|
30
|
+
const FEEDS = {
|
|
31
|
+
'shadow-color': ['box-shadow'],
|
|
32
|
+
'shadow-offset': ['box-shadow'],
|
|
33
|
+
'shadow-opacity': ['box-shadow'],
|
|
34
|
+
'shadow-radius': ['box-shadow'],
|
|
35
|
+
'text-shadow-color': ['text-shadow'],
|
|
36
|
+
'text-shadow-offset': ['text-shadow'],
|
|
37
|
+
'text-shadow-radius': ['text-shadow'],
|
|
38
|
+
};
|
|
39
|
+
/** How each fed property is resolved from the whole style. */
|
|
40
|
+
const RESOLVE = {
|
|
41
|
+
'box-shadow': (style) => style['box-shadow'] ?? boxShadow(style),
|
|
42
|
+
'text-shadow': (style) => style['text-shadow'] ?? textShadow(style),
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Yoga's `start` and `end` edges, which the CSS compiler writes for a logical inline edge, as the
|
|
46
|
+
* logical properties they are. Dash-cased, `margin-start` and a bare `start` are not CSS.
|
|
47
|
+
*/
|
|
48
|
+
const INLINE_EDGES = {
|
|
49
|
+
start: 'inset-inline-start',
|
|
50
|
+
end: 'inset-inline-end',
|
|
51
|
+
'margin-start': 'margin-inline-start',
|
|
52
|
+
'margin-end': 'margin-inline-end',
|
|
53
|
+
'padding-start': 'padding-inline-start',
|
|
54
|
+
'padding-end': 'padding-inline-end',
|
|
55
|
+
};
|
|
56
|
+
for (const [key, property] of Object.entries(INLINE_EDGES)) {
|
|
57
|
+
FEEDS[key] = [property];
|
|
58
|
+
RESOLVE[property] = (style) => style[key];
|
|
59
|
+
}
|
|
60
|
+
for (const family of ['padding', 'margin']) {
|
|
61
|
+
for (const [axis, sides] of Object.entries(EDGES)) {
|
|
62
|
+
FEEDS[`${family}-${axis}`] = sides.map((side) => `${family}-${side}`);
|
|
63
|
+
for (const side of sides) {
|
|
64
|
+
const edge = `${family}-${side}`;
|
|
65
|
+
RESOLVE[edge] = (style) => style[edge] ?? style[`${family}-${axis}`];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const length = (value) => typeof value === 'number' ? `${value}px` : String(value ?? '0px');
|
|
70
|
+
/**
|
|
71
|
+
* iOS's layer shadow. Its opacity defaults to zero there, so a shadow with no `shadowOpacity` is
|
|
72
|
+
* not drawn on a device and is not drawn here either. The opacity scales the colour's own alpha,
|
|
73
|
+
* which `color-mix` against `transparent` does for a colour in any notation.
|
|
74
|
+
*/
|
|
75
|
+
function boxShadow(style) {
|
|
76
|
+
const opacity = style['shadow-opacity'];
|
|
77
|
+
if (typeof opacity !== 'number' || opacity <= 0)
|
|
78
|
+
return undefined;
|
|
79
|
+
const offset = (style['shadow-offset'] ?? {});
|
|
80
|
+
const colour = typeof style['shadow-color'] === 'string' ? style['shadow-color'] : 'black';
|
|
81
|
+
const painted = opacity >= 1 ? colour : `color-mix(in srgb, ${colour} ${opacity * 100}%, transparent)`;
|
|
82
|
+
return `${length(offset.width)} ${length(offset.height)} ${length(style['shadow-radius'])} ${painted}`;
|
|
83
|
+
}
|
|
84
|
+
/** A text shadow is drawn once it has a colour, which is what React Native waits for too. */
|
|
85
|
+
function textShadow(style) {
|
|
86
|
+
const colour = style['text-shadow-color'];
|
|
87
|
+
if (typeof colour !== 'string')
|
|
88
|
+
return undefined;
|
|
89
|
+
const offset = (style['text-shadow-offset'] ?? {});
|
|
90
|
+
return `${length(offset.width)} ${length(offset.height)} ${length(style['text-shadow-radius'])} ${colour}`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Write what one changed key means, given the whole style it is now part of, and return the CSS
|
|
94
|
+
* properties that covers so a caller replacing a whole object knows what it wrote. `key` is
|
|
95
|
+
* dash-cased and `style` keyed the same way.
|
|
96
|
+
*/
|
|
97
|
+
export function writeStyleKey(declaration, key, style, priority = '') {
|
|
98
|
+
const properties = FEEDS[key] ?? [key];
|
|
99
|
+
for (const property of properties) {
|
|
100
|
+
const value = RESOLVE[property] ? RESOLVE[property](style) : style[property];
|
|
101
|
+
if (value === undefined || value === null)
|
|
102
|
+
declaration.removeProperty(property);
|
|
103
|
+
else
|
|
104
|
+
declaration.setProperty(property, cssValue(property, value), priority);
|
|
105
|
+
}
|
|
106
|
+
return properties;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=native-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-style.js","sourceRoot":"","sources":["../src/native-style.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,MAAM,KAAK,GAAG,EAAE,UAAU,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAW,CAAC;AAEtF,gGAAgG;AAChG,MAAM,KAAK,GAAsC;IAC/C,cAAc,EAAE,CAAC,YAAY,CAAC;IAC9B,eAAe,EAAE,CAAC,YAAY,CAAC;IAC/B,gBAAgB,EAAE,CAAC,YAAY,CAAC;IAChC,eAAe,EAAE,CAAC,YAAY,CAAC;IAC/B,mBAAmB,EAAE,CAAC,aAAa,CAAC;IACpC,oBAAoB,EAAE,CAAC,aAAa,CAAC;IACrC,oBAAoB,EAAE,CAAC,aAAa,CAAC;CACtC,CAAC;AAEF,8DAA8D;AAC9D,MAAM,OAAO,GAA8C;IACzD,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC;IAChE,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC;CACpE,CAAC;AAEF;;;GAGG;AACH,MAAM,YAAY,GAA2B;IAC3C,KAAK,EAAE,oBAAoB;IAC3B,GAAG,EAAE,kBAAkB;IACvB,cAAc,EAAE,qBAAqB;IACrC,YAAY,EAAE,mBAAmB;IACj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CAAC;IACvC,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC7E,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;;YAC3E,WAAW,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/**\n * The React Native style keys CSS has no property of the same name for, written as the CSS they\n * stand for.\n *\n * Everything else in a style reaches the browser dash-cased and in units (`css-units.ts`), and\n * the browser does the rest. These were handed over the same way and dropped without a word,\n * because `padding-horizontal` and `shadow-offset` are not CSS properties and `{ width: 0,\n * height: 6 }` is not a length. Now each is resolved from the whole style it belongs to, which is\n * what two of the three kinds here need:\n *\n * - `paddingHorizontal` and its three siblings stand for two edges each, and in Yoga a single\n * edge beats them whichever was written first. So `padding-left` is resolved from\n * `padding-left`, falling back to `padding-horizontal`, and either key changing re-resolves it.\n * - `shadowColor`, `shadowOffset`, `shadowOpacity` and `shadowRadius` are four halves of one\n * `box-shadow`, and the three `textShadow*` keys of one `text-shadow`. A `boxShadow` named\n * outright in the same style wins over them.\n *\n * One order is not Yoga's: a `padding` written after `paddingHorizontal` resets both edges, since\n * the browser expands the shorthand over them, where Yoga keeps the more specific key.\n *\n * - `start`, `marginStart`, `paddingEnd` and the rest of Yoga's inline edges are the logical\n * properties. Where one meets a physical edge the browser goes by which was written last, where\n * Yoga always lets the logical one win.\n *\n * What is left alone: `elevation`, Android's own shadow, which has no geometry to translate.\n */\nimport { cssValue } from './css-units.ts';\n\ntype Style = Readonly<Record<string, unknown>>;\n\nconst EDGES = { horizontal: ['left', 'right'], vertical: ['top', 'bottom'] } as const;\n\n/** Each shorthand-like key, to the CSS properties it feeds. Any other key feeds only itself. */\nconst FEEDS: Record<string, readonly string[]> = {\n 'shadow-color': ['box-shadow'],\n 'shadow-offset': ['box-shadow'],\n 'shadow-opacity': ['box-shadow'],\n 'shadow-radius': ['box-shadow'],\n 'text-shadow-color': ['text-shadow'],\n 'text-shadow-offset': ['text-shadow'],\n 'text-shadow-radius': ['text-shadow'],\n};\n\n/** How each fed property is resolved from the whole style. */\nconst RESOLVE: Record<string, (style: Style) => unknown> = {\n 'box-shadow': (style) => style['box-shadow'] ?? boxShadow(style),\n 'text-shadow': (style) => style['text-shadow'] ?? textShadow(style),\n};\n\n/**\n * Yoga's `start` and `end` edges, which the CSS compiler writes for a logical inline edge, as the\n * logical properties they are. Dash-cased, `margin-start` and a bare `start` are not CSS.\n */\nconst INLINE_EDGES: Record<string, string> = {\n start: 'inset-inline-start',\n end: 'inset-inline-end',\n 'margin-start': 'margin-inline-start',\n 'margin-end': 'margin-inline-end',\n 'padding-start': 'padding-inline-start',\n 'padding-end': 'padding-inline-end',\n};\n\nfor (const [key, property] of Object.entries(INLINE_EDGES)) {\n FEEDS[key] = [property];\n RESOLVE[property] = (style) => style[key];\n}\n\nfor (const family of ['padding', 'margin']) {\n for (const [axis, sides] of Object.entries(EDGES)) {\n FEEDS[`${family}-${axis}`] = sides.map((side) => `${family}-${side}`);\n for (const side of sides) {\n const edge = `${family}-${side}`;\n RESOLVE[edge] = (style) => style[edge] ?? style[`${family}-${axis}`];\n }\n }\n}\n\nconst length = (value: unknown): string =>\n typeof value === 'number' ? `${value}px` : String(value ?? '0px');\n\ninterface Offset {\n readonly width?: number;\n readonly height?: number;\n}\n\n/**\n * iOS's layer shadow. Its opacity defaults to zero there, so a shadow with no `shadowOpacity` is\n * not drawn on a device and is not drawn here either. The opacity scales the colour's own alpha,\n * which `color-mix` against `transparent` does for a colour in any notation.\n */\nfunction boxShadow(style: Style): string | undefined {\n const opacity = style['shadow-opacity'];\n if (typeof opacity !== 'number' || opacity <= 0) return undefined;\n const offset = (style['shadow-offset'] ?? {}) as Offset;\n const colour = typeof style['shadow-color'] === 'string' ? style['shadow-color'] : 'black';\n const painted =\n opacity >= 1 ? colour : `color-mix(in srgb, ${colour} ${opacity * 100}%, transparent)`;\n return `${length(offset.width)} ${length(offset.height)} ${length(style['shadow-radius'])} ${painted}`;\n}\n\n/** A text shadow is drawn once it has a colour, which is what React Native waits for too. */\nfunction textShadow(style: Style): string | undefined {\n const colour = style['text-shadow-color'];\n if (typeof colour !== 'string') return undefined;\n const offset = (style['text-shadow-offset'] ?? {}) as Offset;\n return `${length(offset.width)} ${length(offset.height)} ${length(style['text-shadow-radius'])} ${colour}`;\n}\n\n/**\n * Write what one changed key means, given the whole style it is now part of, and return the CSS\n * properties that covers so a caller replacing a whole object knows what it wrote. `key` is\n * dash-cased and `style` keyed the same way.\n */\nexport function writeStyleKey(\n declaration: CSSStyleDeclaration,\n key: string,\n style: Style,\n priority = '',\n): readonly string[] {\n const properties = FEEDS[key] ?? [key];\n for (const property of properties) {\n const value = RESOLVE[property] ? RESOLVE[property](style) : style[property];\n if (value === undefined || value === null) declaration.removeProperty(property);\n else declaration.setProperty(property, cssValue(property, value), priority);\n }\n return properties;\n}\n"]}
|
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every prop `BrowserEngine.setProp` gives a DOM or ARIA meaning to, keyed by prop name and
|
|
3
|
+
* (where two elements use the same prop name differently) by the node's own template name.
|
|
4
|
+
*
|
|
5
|
+
* `packages/components/src/view-base.ts` is the biggest source of these - roughly forty
|
|
6
|
+
* accessibility and identity inputs every host primitive carries - plus a smaller set each of
|
|
7
|
+
* `text-input.ts`, `switch.ts`, `image.ts`, `safe-area-view.ts` and `modal.ts` layers on top for
|
|
8
|
+
* their own element. A lookup table rather than a `switch`, for the same reason the prototype
|
|
9
|
+
* (`examples/web-button/src/browser-engine.ts`) gives: this reads as data instead of control
|
|
10
|
+
* flow, and it is where a review can see, at a glance, what the file's own comments below say in
|
|
11
|
+
* prose - which props got a translated DOM meaning and which did not.
|
|
12
|
+
*
|
|
13
|
+
* ## The fallback for everything not in a table
|
|
14
|
+
*
|
|
15
|
+
* A prop with no handler here does not disappear the way it would if this file's tables were the
|
|
16
|
+
* whole story: `applyProp`'s fallback writes any remaining string, number or boolean prop as a
|
|
17
|
+
* plain attribute under its own name. This is not a guess - it is what a real prop reaches native
|
|
18
|
+
* as too. `engine.ts`'s `Engine.setProp` puts *everything* in `node.props`, unconditionally, and
|
|
19
|
+
* the whole bag is what a commit sends to the native view; native ignores what it does not
|
|
20
|
+
* recognise rather than this package having to know in advance which of Tailwind's compiled
|
|
21
|
+
* `data-*` attribute selectors (`data-slot`, `data-variant`, `data-state`, and whatever a future
|
|
22
|
+
* component invents) a class string will need to match against. The fallback is what makes that
|
|
23
|
+
* true here too, without enumerating every one.
|
|
24
|
+
*
|
|
25
|
+
* What genuinely gets nothing, because a plain attribute could not carry it or would be actively
|
|
26
|
+
* wrong: an object or array prop with no scalar form (`hitSlop`'s insets, `accessibilityActions`,
|
|
27
|
+
* the Android-drawable props), and iOS-only accessibility surfaces with no ARIA equivalent at all
|
|
28
|
+
* (`accessibilityIgnoresInvertColors`, `accessibilityLargeContentTitle`,
|
|
29
|
+
* `accessibilityShowsLargeContentViewer`, `accessibilityRespondsToUserInteraction`) - these last
|
|
30
|
+
* four are strings/booleans that *would* fall through to the generic attribute write and sit
|
|
31
|
+
* inertly in the DOM if not named here, which is harmless but worth being honest about rather
|
|
32
|
+
* than implying they did something. Named in this comment rather than omitted from it, for the
|
|
33
|
+
* reason `host.ts` gives for its own exclusions: a divergence that is not written down is the
|
|
34
|
+
* failure this project cares about.
|
|
35
|
+
*/
|
|
36
|
+
import type { BrowserNode } from './dom-node.ts';
|
|
37
|
+
/**
|
|
38
|
+
* `accessibilityRole`/`role` values with a direct ARIA `role`. Not every RN role has one -
|
|
39
|
+
* `pager`, `scrollview`, `horizontalscrollview`, `webview`, `drawerlayout`, `slidingdrawer`,
|
|
40
|
+
* `keyboardkey` and `text` name platform widgets ARIA has no vocabulary for - those fall through
|
|
41
|
+
* to the literal value, an unrecognised `role` an assistive technology ignores rather than a wrong
|
|
42
|
+
* one it acts on. `element-props.test.ts` holds this list against `view-base.ts`'s own.
|
|
43
|
+
*/
|
|
44
|
+
export declare const ROLE_MAP: Readonly<Record<string, string>>;
|
|
45
|
+
/**
|
|
46
|
+
* Apply one prop to its node. `clear` is `value === undefined || value === null`.
|
|
47
|
+
*
|
|
48
|
+
* A key with a handler - either element-specific or from `ViewBase`'s own set - runs exactly
|
|
49
|
+
* that translation. Everything else falls to the generic attribute write the file doc comment
|
|
50
|
+
* describes, which is why a `noop` entry (`hitSlop`, `accessibilityActions`, ...) has to be a
|
|
51
|
+
* real entry rather than an absent one: an absent key falls through and gets written as a raw
|
|
52
|
+
* attribute, a `noop` key is claimed and genuinely does nothing.
|
|
53
|
+
*/
|
|
54
|
+
export declare function applyProp(node: BrowserNode, key: string, value: unknown, clear: boolean): void;
|