@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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Numbers into CSS values.
|
|
3
|
+
*
|
|
4
|
+
* React Native styles are unitless: `top: 116` means 116 points, and Yoga needs no more than the
|
|
5
|
+
* number. CSS is not, and `top: 116` is not a length at all - the browser rejects the declaration
|
|
6
|
+
* and silently keeps whatever was there before. Every numeric `[style]` binding in this library
|
|
7
|
+
* was being dropped that way: a popover computed the right place and stayed pinned to the corner,
|
|
8
|
+
* an accordion computed its measured height and never opened.
|
|
9
|
+
*
|
|
10
|
+
* It hid because the one property that *is* valid unitless is the one bound beside them. A
|
|
11
|
+
* popover writes `{ top, left, opacity }` together, `opacity: 1` applied, and the card became
|
|
12
|
+
* visible exactly on time in exactly the wrong place - which reads as a positioning bug rather
|
|
13
|
+
* than as a units bug.
|
|
14
|
+
*
|
|
15
|
+
* The list is React DOM's `isUnitlessNumber`, with one deliberate removal. `line-height` is
|
|
16
|
+
* unitless in CSS, where a bare number is a multiple of the font size, and is *points* in React
|
|
17
|
+
* Native, where `lineHeight: 24` means 24. Keeping it here would have made every line height in
|
|
18
|
+
* the library a multiplier, so it gets `px` like any other length. That is the one place these
|
|
19
|
+
* two style languages use the same property name for two different things.
|
|
20
|
+
*/
|
|
21
|
+
const UNITLESS = new Set([
|
|
22
|
+
'animation-iteration-count',
|
|
23
|
+
'aspect-ratio',
|
|
24
|
+
'border-image-outset',
|
|
25
|
+
'border-image-slice',
|
|
26
|
+
'border-image-width',
|
|
27
|
+
'column-count',
|
|
28
|
+
'columns',
|
|
29
|
+
'flex',
|
|
30
|
+
'flex-grow',
|
|
31
|
+
'flex-shrink',
|
|
32
|
+
'font-weight',
|
|
33
|
+
'grid-area',
|
|
34
|
+
'grid-column',
|
|
35
|
+
'grid-column-end',
|
|
36
|
+
'grid-column-start',
|
|
37
|
+
'grid-row',
|
|
38
|
+
'grid-row-end',
|
|
39
|
+
'grid-row-start',
|
|
40
|
+
'opacity',
|
|
41
|
+
'order',
|
|
42
|
+
'orphans',
|
|
43
|
+
'tab-size',
|
|
44
|
+
'widows',
|
|
45
|
+
'z-index',
|
|
46
|
+
'zoom',
|
|
47
|
+
'fill-opacity',
|
|
48
|
+
'flood-opacity',
|
|
49
|
+
'stop-opacity',
|
|
50
|
+
'stroke-dasharray',
|
|
51
|
+
'stroke-dashoffset',
|
|
52
|
+
'stroke-miterlimit',
|
|
53
|
+
'stroke-opacity',
|
|
54
|
+
'stroke-width',
|
|
55
|
+
]);
|
|
56
|
+
/**
|
|
57
|
+
* `116` becomes `116px`, `1` on an opacity stays `1`, and anything already a string is left alone.
|
|
58
|
+
*
|
|
59
|
+
* Zero is given units too. A bare `0` is legal CSS, but writing `0px` keeps one rule here rather
|
|
60
|
+
* than two, and a custom property holding `0` would not be legal in every place it lands.
|
|
61
|
+
*/
|
|
62
|
+
export function cssValue(property, value) {
|
|
63
|
+
// A custom property's value is whatever it was set to: `3` for a column count is not `3px`.
|
|
64
|
+
if (property.startsWith('--'))
|
|
65
|
+
return String(value);
|
|
66
|
+
if (property === 'transform' && Array.isArray(value))
|
|
67
|
+
return transformList(value);
|
|
68
|
+
// `fontVariant: ['small-caps', 'tabular-nums']`, or a `transformOrigin` list. `String()` would
|
|
69
|
+
// join them with commas, which neither property accepts.
|
|
70
|
+
if (Array.isArray(value))
|
|
71
|
+
return value.map((item) => cssValue(property, item)).join(' ');
|
|
72
|
+
if (typeof value === 'number' && Number.isFinite(value) && !UNITLESS.has(property)) {
|
|
73
|
+
return `${value}px`;
|
|
74
|
+
}
|
|
75
|
+
return String(value);
|
|
76
|
+
}
|
|
77
|
+
/** Idempotent on an already-dash-cased name, which is what a compiled template binding gives. */
|
|
78
|
+
export const dashCase = (name) => name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
79
|
+
/**
|
|
80
|
+
* React Native's transform list, `[{ translateY: 10 }, { rotate: '45deg' }]`, as the CSS function
|
|
81
|
+
* list it stands for. Translations and perspective are lengths and get units; angles arrive as
|
|
82
|
+
* strings already; a 6-value `matrix` is CSS's `matrix()`, a 16-value one `matrix3d()`.
|
|
83
|
+
*/
|
|
84
|
+
function transformList(list) {
|
|
85
|
+
if (list.length === 0)
|
|
86
|
+
return 'none';
|
|
87
|
+
return list
|
|
88
|
+
.flatMap((entry) => Object.entries(entry))
|
|
89
|
+
.map(([fn, arg]) => {
|
|
90
|
+
if (fn === 'matrix' && Array.isArray(arg)) {
|
|
91
|
+
return `${arg.length === 16 ? 'matrix3d' : 'matrix'}(${arg.join(', ')})`;
|
|
92
|
+
}
|
|
93
|
+
const length = fn.startsWith('translate') || fn === 'perspective';
|
|
94
|
+
return `${fn}(${length && typeof arg === 'number' ? `${arg}px` : String(arg)})`;
|
|
95
|
+
})
|
|
96
|
+
.join(' ');
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=css-units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-units.js","sourceRoot":"","sources":["../src/css-units.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,2BAA2B;IAC3B,cAAc;IACd,qBAAqB;IACrB,oBAAoB;IACpB,oBAAoB;IACpB,cAAc;IACd,SAAS;IACT,MAAM;IACN,WAAW;IACX,aAAa;IACb,aAAa;IACb,WAAW;IACX,aAAa;IACb,iBAAiB;IACjB,mBAAmB;IACnB,UAAU;IACV,cAAc;IACd,gBAAgB;IAChB,SAAS;IACT,OAAO;IACP,SAAS;IACT,UAAU;IACV,QAAQ;IACR,SAAS;IACT,MAAM;IACN,cAAc;IACd,eAAe;IACf,cAAc;IACd,kBAAkB;IAClB,mBAAmB;IACnB,mBAAmB;IACnB,gBAAgB;IAChB,cAAc;CACf,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,KAAc;IACvD,4FAA4F;IAC5F,IAAI,QAAQ,CAAC,UAAU,CAAC,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AG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3E,CAAC;QACD,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,aAAa,CAAC;QAClE,OAAO,GAAG,EAAE,IAAI,MAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;IAClF,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC","sourcesContent":["/**\n * Numbers into CSS values.\n *\n * React Native styles are unitless: `top: 116` means 116 points, and Yoga needs no more than the\n * number. CSS is not, and `top: 116` is not a length at all - the browser rejects the declaration\n * and silently keeps whatever was there before. Every numeric `[style]` binding in this library\n * was being dropped that way: a popover computed the right place and stayed pinned to the corner,\n * an accordion computed its measured height and never opened.\n *\n * It hid because the one property that *is* valid unitless is the one bound beside them. A\n * popover writes `{ top, left, opacity }` together, `opacity: 1` applied, and the card became\n * visible exactly on time in exactly the wrong place - which reads as a positioning bug rather\n * than as a units bug.\n *\n * The list is React DOM's `isUnitlessNumber`, with one deliberate removal. `line-height` is\n * unitless in CSS, where a bare number is a multiple of the font size, and is *points* in React\n * Native, where `lineHeight: 24` means 24. Keeping it here would have made every line height in\n * the library a multiplier, so it gets `px` like any other length. That is the one place these\n * two style languages use the same property name for two different things.\n */\nconst UNITLESS = new Set([\n 'animation-iteration-count',\n 'aspect-ratio',\n 'border-image-outset',\n 'border-image-slice',\n 'border-image-width',\n 'column-count',\n 'columns',\n 'flex',\n 'flex-grow',\n 'flex-shrink',\n 'font-weight',\n 'grid-area',\n 'grid-column',\n 'grid-column-end',\n 'grid-column-start',\n 'grid-row',\n 'grid-row-end',\n 'grid-row-start',\n 'opacity',\n 'order',\n 'orphans',\n 'tab-size',\n 'widows',\n 'z-index',\n 'zoom',\n 'fill-opacity',\n 'flood-opacity',\n 'stop-opacity',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke-width',\n]);\n\n/**\n * `116` becomes `116px`, `1` on an opacity stays `1`, and anything already a string is left alone.\n *\n * Zero is given units too. A bare `0` is legal CSS, but writing `0px` keeps one rule here rather\n * than two, and a custom property holding `0` would not be legal in every place it lands.\n */\nexport function cssValue(property: string, value: unknown): string {\n // A custom property's value is whatever it was set to: `3` for a column count is not `3px`.\n if (property.startsWith('--')) return String(value);\n if (property === 'transform' && Array.isArray(value)) return transformList(value);\n // `fontVariant: ['small-caps', 'tabular-nums']`, or a `transformOrigin` list. `String()` would\n // join them with commas, which neither property accepts.\n if (Array.isArray(value)) return value.map((item) => cssValue(property, item)).join(' ');\n if (typeof value === 'number' && Number.isFinite(value) && !UNITLESS.has(property)) {\n return `${value}px`;\n }\n return String(value);\n}\n\n/** Idempotent on an already-dash-cased name, which is what a compiled template binding gives. */\nexport const dashCase = (name: string): string =>\n name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n\n/**\n * React Native's transform list, `[{ translateY: 10 }, { rotate: '45deg' }]`, as the CSS function\n * list it stands for. Translations and perspective are lengths and get units; angles arrive as\n * strings already; a 6-value `matrix` is CSS's `matrix()`, a 16-value one `matrix3d()`.\n */\nfunction transformList(list: readonly unknown[]): string {\n if (list.length === 0) return 'none';\n return list\n .flatMap((entry) => Object.entries(entry as Record<string, unknown>))\n .map(([fn, arg]) => {\n if (fn === 'matrix' && Array.isArray(arg)) {\n return `${arg.length === 16 ? 'matrix3d' : 'matrix'}(${arg.join(', ')})`;\n }\n const length = fn.startsWith('translate') || fn === 'perspective';\n return `${fn}(${length && typeof arg === 'number' ? `${arg}px` : String(arg)})`;\n })\n .join(' ');\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The device capabilities, answered by the browser.
|
|
3
|
+
*
|
|
4
|
+
* `@ng-native/device` reaches React Native for these, and its factories all fall back to
|
|
5
|
+
* doing nothing off a device - which is what makes that package importable by a test suite, and
|
|
6
|
+
* what made it quietly wrong here. Nothing was provided in place of the fallbacks, so on the web
|
|
7
|
+
* `Screen` reported a window of **zero by zero**, permanently.
|
|
8
|
+
*
|
|
9
|
+
* That is not a cosmetic gap. `Screen.compact()` is `width < 768`, so every component that
|
|
10
|
+
* branches on it took the phone tree: the sidebar rendered its mobile sheet instead of its rail
|
|
11
|
+
* in a 1200pt browser window. `anchored-overlay.ts` clamps a popover against `screen.window()`,
|
|
12
|
+
* so every anchored overlay was being fitted into a zero-sized screen. Neither failed loudly.
|
|
13
|
+
*
|
|
14
|
+
* Found by opening the gallery rather than by reading, and it could only have been found that
|
|
15
|
+
* way: jsdom reports a window too, and the tests that mount through `mount` never asked what
|
|
16
|
+
* size it was.
|
|
17
|
+
*/
|
|
18
|
+
import type { ColorSchemeSource, DirectionSource, ScreenSource } from '@ng-native/device';
|
|
19
|
+
/**
|
|
20
|
+
* `Screen`, from the browser's own viewport.
|
|
21
|
+
*
|
|
22
|
+
* `window` is what the app can draw in and `screen` is the display, which is the same distinction
|
|
23
|
+
* React Native draws - on Android the window excludes the system bars, and here it excludes the
|
|
24
|
+
* browser's own chrome. `resize` covers a rotation, a window drag and a devtools pane opening,
|
|
25
|
+
* all of which are the same event as far as a layout is concerned.
|
|
26
|
+
*/
|
|
27
|
+
export declare function browserScreenSource(view: Window): ScreenSource;
|
|
28
|
+
/**
|
|
29
|
+
* `ColorScheme`, from `prefers-color-scheme`.
|
|
30
|
+
*
|
|
31
|
+
* The same thing the native source reads off the OS, and the reason `Theme` can default to the
|
|
32
|
+
* system scheme on both platforms rather than always starting light.
|
|
33
|
+
*/
|
|
34
|
+
export declare function browserColorSchemeSource(view: Window): ColorSchemeSource;
|
|
35
|
+
/**
|
|
36
|
+
* `Direction`, from the document.
|
|
37
|
+
*
|
|
38
|
+
* `<html dir>` is where a web app says this, and `<body dir>` is where a framework that could not
|
|
39
|
+
* reach the `<html>` element says it instead - so body wins, which is the order CDK reads them in
|
|
40
|
+
* and the order the cascade itself resolves them in.
|
|
41
|
+
*
|
|
42
|
+
* Unlike the native source this one really can change: `dir` is an attribute, and an app with a
|
|
43
|
+
* language switcher flips it without reloading. A `MutationObserver` on the two elements is what
|
|
44
|
+
* makes the signal follow, so a component that placed a popover to the left redraws it to the
|
|
45
|
+
* right rather than waiting for a refresh.
|
|
46
|
+
*
|
|
47
|
+
* The parameter is `Window & typeof globalThis` rather than `Window`, unlike the two sources
|
|
48
|
+
* above: the observer is constructed off the view rather than off the ambient global, so a page
|
|
49
|
+
* hosting a second document - an iframe, or the jsdom the tests mount into - observes with its
|
|
50
|
+
* own. `Window` alone does not declare the constructor; `document.defaultView` already has this
|
|
51
|
+
* type, so no caller notices.
|
|
52
|
+
*/
|
|
53
|
+
export declare function browserDirectionSource(view: Window & typeof globalThis): DirectionSource;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Screen`, from the browser's own viewport.
|
|
3
|
+
*
|
|
4
|
+
* `window` is what the app can draw in and `screen` is the display, which is the same distinction
|
|
5
|
+
* React Native draws - on Android the window excludes the system bars, and here it excludes the
|
|
6
|
+
* browser's own chrome. `resize` covers a rotation, a window drag and a devtools pane opening,
|
|
7
|
+
* all of which are the same event as far as a layout is concerned.
|
|
8
|
+
*/
|
|
9
|
+
export function browserScreenSource(view) {
|
|
10
|
+
const sizes = () => ({
|
|
11
|
+
window: { width: view.innerWidth, height: view.innerHeight },
|
|
12
|
+
screen: {
|
|
13
|
+
width: view.screen?.width ?? view.innerWidth,
|
|
14
|
+
height: view.screen?.height ?? view.innerHeight,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
current: sizes,
|
|
19
|
+
subscribe: (listener) => {
|
|
20
|
+
const onResize = () => listener(sizes());
|
|
21
|
+
view.addEventListener('resize', onResize);
|
|
22
|
+
return () => view.removeEventListener('resize', onResize);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `ColorScheme`, from `prefers-color-scheme`.
|
|
28
|
+
*
|
|
29
|
+
* The same thing the native source reads off the OS, and the reason `Theme` can default to the
|
|
30
|
+
* system scheme on both platforms rather than always starting light.
|
|
31
|
+
*/
|
|
32
|
+
export function browserColorSchemeSource(view) {
|
|
33
|
+
const query = view.matchMedia?.('(prefers-color-scheme: dark)');
|
|
34
|
+
return {
|
|
35
|
+
current: () => (query?.matches ? 'dark' : 'light'),
|
|
36
|
+
subscribe: (listener) => {
|
|
37
|
+
if (!query)
|
|
38
|
+
return () => { };
|
|
39
|
+
const onChange = (event) => listener(event.matches ? 'dark' : 'light');
|
|
40
|
+
query.addEventListener('change', onChange);
|
|
41
|
+
return () => query.removeEventListener('change', onChange);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Locales written right to left, by language subtag or by script subtag.
|
|
47
|
+
*
|
|
48
|
+
* Lifted from CDK's `directionality.ts`, which lifted it from Closure's `goog.i18n.bidi`. It only
|
|
49
|
+
* has to answer `dir="auto"`, which is HTML for "work it out": the browser works it out from the
|
|
50
|
+
* *content*, which means walking the text of the page, and CDK settled long ago that the language
|
|
51
|
+
* is a good enough approximation to be worth the four lines. Same trade here.
|
|
52
|
+
*/
|
|
53
|
+
const RTL_LOCALE = /^(ar|ckb|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Adlm|Arab|Hebr|Nkoo|Rohg|Thaa))(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)/i;
|
|
54
|
+
function resolve(raw, view) {
|
|
55
|
+
const value = raw?.toLowerCase() ?? '';
|
|
56
|
+
if (value === 'auto')
|
|
57
|
+
return RTL_LOCALE.test(view.navigator?.language ?? '') ? 'rtl' : 'ltr';
|
|
58
|
+
return value === 'rtl' ? 'rtl' : 'ltr';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* `Direction`, from the document.
|
|
62
|
+
*
|
|
63
|
+
* `<html dir>` is where a web app says this, and `<body dir>` is where a framework that could not
|
|
64
|
+
* reach the `<html>` element says it instead - so body wins, which is the order CDK reads them in
|
|
65
|
+
* and the order the cascade itself resolves them in.
|
|
66
|
+
*
|
|
67
|
+
* Unlike the native source this one really can change: `dir` is an attribute, and an app with a
|
|
68
|
+
* language switcher flips it without reloading. A `MutationObserver` on the two elements is what
|
|
69
|
+
* makes the signal follow, so a component that placed a popover to the left redraws it to the
|
|
70
|
+
* right rather than waiting for a refresh.
|
|
71
|
+
*
|
|
72
|
+
* The parameter is `Window & typeof globalThis` rather than `Window`, unlike the two sources
|
|
73
|
+
* above: the observer is constructed off the view rather than off the ambient global, so a page
|
|
74
|
+
* hosting a second document - an iframe, or the jsdom the tests mount into - observes with its
|
|
75
|
+
* own. `Window` alone does not declare the constructor; `document.defaultView` already has this
|
|
76
|
+
* type, so no caller notices.
|
|
77
|
+
*/
|
|
78
|
+
export function browserDirectionSource(view) {
|
|
79
|
+
const document = view.document;
|
|
80
|
+
const read = () => resolve(document.body?.getAttribute('dir') ?? document.documentElement?.getAttribute('dir'), view);
|
|
81
|
+
return {
|
|
82
|
+
current: read,
|
|
83
|
+
subscribe: (listener) => {
|
|
84
|
+
if (typeof view.MutationObserver !== 'function')
|
|
85
|
+
return () => { };
|
|
86
|
+
const observer = new view.MutationObserver(() => listener(read()));
|
|
87
|
+
const options = { attributes: true, attributeFilter: ['dir'] };
|
|
88
|
+
if (document.documentElement)
|
|
89
|
+
observer.observe(document.documentElement, options);
|
|
90
|
+
if (document.body)
|
|
91
|
+
observer.observe(document.body, options);
|
|
92
|
+
return () => observer.disconnect();
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=device-sources.js.map
|
|
@@ -0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,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YACnE,MAAM,OAAO,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/D,IAAI,QAAQ,CAAC,eAAe;gBAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YAClF,IAAI,QAAQ,CAAC,IAAI;gBAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC5D,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * The device capabilities, answered by the browser.\n *\n * `@ng-native/device` reaches React Native for these, and its factories all fall back to\n * doing nothing off a device - which is what makes that package importable by a test suite, and\n * what made it quietly wrong here. Nothing was provided in place of the fallbacks, so on the web\n * `Screen` reported a window of **zero by zero**, permanently.\n *\n * That is not a cosmetic gap. `Screen.compact()` is `width < 768`, so every component that\n * branches on it took the phone tree: the sidebar rendered its mobile sheet instead of its rail\n * in a 1200pt browser window. `anchored-overlay.ts` clamps a popover against `screen.window()`,\n * so every anchored overlay was being fitted into a zero-sized screen. Neither failed loudly.\n *\n * Found by opening the gallery rather than by reading, and it could only have been found that\n * way: jsdom reports a window too, and the tests that mount through `mount` never asked what\n * size it was.\n */\nimport type {\n ColorSchemeSource,\n DirectionSource,\n LayoutDirection,\n ScreenSource,\n Sizes,\n} from '@ng-native/device';\n\n/**\n * `Screen`, from the browser's own viewport.\n *\n * `window` is what the app can draw in and `screen` is the display, which is the same distinction\n * React Native draws - on Android the window excludes the system bars, and here it excludes the\n * browser's own chrome. `resize` covers a rotation, a window drag and a devtools pane opening,\n * all of which are the same event as far as a layout is concerned.\n */\nexport function browserScreenSource(view: Window): ScreenSource {\n const sizes = (): Sizes => ({\n window: { width: view.innerWidth, height: view.innerHeight },\n screen: {\n width: view.screen?.width ?? view.innerWidth,\n height: view.screen?.height ?? view.innerHeight,\n },\n });\n return {\n current: sizes,\n subscribe: (listener) => {\n const onResize = () => listener(sizes());\n view.addEventListener('resize', onResize);\n return () => view.removeEventListener('resize', onResize);\n },\n };\n}\n\n/**\n * `ColorScheme`, from `prefers-color-scheme`.\n *\n * The same thing the native source reads off the OS, and the reason `Theme` can default to the\n * system scheme on both platforms rather than always starting light.\n */\nexport function browserColorSchemeSource(view: Window): ColorSchemeSource {\n const query = view.matchMedia?.('(prefers-color-scheme: dark)');\n return {\n current: () => (query?.matches ? 'dark' : 'light'),\n subscribe: (listener) => {\n if (!query) return () => {};\n const onChange = (event: MediaQueryListEvent) => listener(event.matches ? 'dark' : 'light');\n query.addEventListener('change', onChange);\n return () => query.removeEventListener('change', onChange);\n },\n };\n}\n\n/**\n * Locales written right to left, by language subtag or by script subtag.\n *\n * Lifted from CDK's `directionality.ts`, which lifted it from Closure's `goog.i18n.bidi`. It only\n * has to answer `dir=\"auto\"`, which is HTML for \"work it out\": the browser works it out from the\n * *content*, which means walking the text of the page, and CDK settled long ago that the language\n * is a good enough approximation to be worth the four lines. Same trade here.\n */\nconst RTL_LOCALE =\n /^(ar|ckb|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Adlm|Arab|Hebr|Nkoo|Rohg|Thaa))(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)/i;\n\nfunction resolve(raw: string | null | undefined, view: Window): LayoutDirection {\n const value = raw?.toLowerCase() ?? '';\n if (value === 'auto') return RTL_LOCALE.test(view.navigator?.language ?? '') ? 'rtl' : 'ltr';\n return value === 'rtl' ? 'rtl' : 'ltr';\n}\n\n/**\n * `Direction`, from the document.\n *\n * `<html dir>` is where a web app says this, and `<body dir>` is where a framework that could not\n * reach the `<html>` element says it instead - so body wins, which is the order CDK reads them in\n * and the order the cascade itself resolves them in.\n *\n * Unlike the native source this one really can change: `dir` is an attribute, and an app with a\n * language switcher flips it without reloading. A `MutationObserver` on the two elements is what\n * makes the signal follow, so a component that placed a popover to the left redraws it to the\n * right rather than waiting for a refresh.\n *\n * The parameter is `Window & typeof globalThis` rather than `Window`, unlike the two sources\n * above: the observer is constructed off the view rather than off the ambient global, so a page\n * hosting a second document - an iframe, or the jsdom the tests mount into - observes with its\n * own. `Window` alone does not declare the constructor; `document.defaultView` already has this\n * type, so no caller notices.\n */\nexport function browserDirectionSource(view: Window & typeof globalThis): DirectionSource {\n const document = view.document;\n const read = () =>\n resolve(\n document.body?.getAttribute('dir') ?? document.documentElement?.getAttribute('dir'),\n view,\n );\n\n return {\n current: read,\n subscribe: (listener) => {\n if (typeof view.MutationObserver !== 'function') return () => {};\n const observer = new view.MutationObserver(() => listener(read()));\n const options = { attributes: true, attributeFilter: ['dir'] };\n if (document.documentElement) observer.observe(document.documentElement, options);\n if (document.body) observer.observe(document.body, options);\n return () => observer.disconnect();\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The retained node this package hands Angular as `ElementRef.nativeElement`, and the thing every
|
|
3
|
+
* `HostEngine` method actually operates on.
|
|
4
|
+
*
|
|
5
|
+
* `packages/fabric/src/engine.ts`'s `EngineNode` is not reusable here (its constructor-free shape
|
|
6
|
+
* still carries Fabric-only bookkeeping - `committed`, `styleCache`, `sheet`...), but the shared
|
|
7
|
+
* packages never ask for that: they ask for `HostNode`'s five fields, plus whatever a component
|
|
8
|
+
* reads directly off `this.node` after `inject(ElementRef).nativeElement as EngineNode` casts it
|
|
9
|
+
* back. Grepping every such read (`view-base.ts`, `pressable.ts`'s `TouchableBase`, `scroll-view.ts`,
|
|
10
|
+
* `select.ts`'s `textOf`) turns up exactly `kind`, `props`, `text`, `children` and `parent` - so a
|
|
11
|
+
* class that implements `HostNode` honestly, backed by a real DOM node, satisfies every one of
|
|
12
|
+
* them without a cast.
|
|
13
|
+
*
|
|
14
|
+
* `children`/`parent` are maintained by hand rather than read live off the DOM (`el.parentElement`,
|
|
15
|
+
* `el.childNodes`) for the same reason `Engine` keeps its own tree: a live DOM walk would have to
|
|
16
|
+
* filter out nodes this package did not create (there are none today, but a consumer's own
|
|
17
|
+
* `document.createElement` inside a projected template is not this package's to assume against),
|
|
18
|
+
* and `select.ts`'s `textOf` recursion wants exactly the nodes Angular put here, in order.
|
|
19
|
+
*/
|
|
20
|
+
import type { HostNode } from '@ng-native/fabric';
|
|
21
|
+
export type BrowserNodeKind = 'element' | 'text' | 'anchor';
|
|
22
|
+
export interface BrowserNode extends HostNode {
|
|
23
|
+
readonly kind: BrowserNodeKind;
|
|
24
|
+
/** The real DOM node this wraps. An `Element` for `element`, a `Text` for `text`. */
|
|
25
|
+
readonly el: Element | Text | Comment;
|
|
26
|
+
/** Lowercase template spelling, e.g. `view`. Mirrors `EngineNode.name`; never the DOM tag. */
|
|
27
|
+
readonly name: string;
|
|
28
|
+
/** `name` again on an element, for Angular 22.0, which reads it on a component's host element. */
|
|
29
|
+
readonly tagName?: string;
|
|
30
|
+
props: Record<string, unknown>;
|
|
31
|
+
text: string;
|
|
32
|
+
children: BrowserNode[];
|
|
33
|
+
parent: BrowserNode | null;
|
|
34
|
+
/**
|
|
35
|
+
* Registered listeners, by top-level type (`topTouchStart`, `topChange`, ...). `null` until
|
|
36
|
+
* the first one, so a node nothing ever listens to costs one field rather than one `Map`.
|
|
37
|
+
*/
|
|
38
|
+
listeners: Map<string, Set<(event: unknown) => void>> | null;
|
|
39
|
+
/**
|
|
40
|
+
* Which opt-in event types (`topLayout`, `topPointerEnter`, `topPointerLeave`) already have
|
|
41
|
+
* their real DOM listener installed - `browser-engine.ts`'s `wireOptIn` guard. `null` until
|
|
42
|
+
* the first one, matching `listeners` above.
|
|
43
|
+
*/
|
|
44
|
+
optedIn: Set<string> | null;
|
|
45
|
+
}
|
|
46
|
+
export declare function makeElementNode(name: string, el: Element): BrowserNode;
|
|
47
|
+
export declare function makeTextNode(text: Text): BrowserNode;
|
|
48
|
+
/** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */
|
|
49
|
+
export declare function makeAnchorNode(comment: Comment): BrowserNode;
|
|
50
|
+
/** The `BrowserNode` a real DOM node was created with, or `null` for one this package did not make. */
|
|
51
|
+
export declare function nodeOf(el: Element | Text | Comment | null): BrowserNode | null;
|
|
52
|
+
/**
|
|
53
|
+
* The nearest `BrowserNode` starting at a real `Element` and walking up `parentElement`.
|
|
54
|
+
*
|
|
55
|
+
* Used to resolve `event.target` for events this package listens for on `document` rather than
|
|
56
|
+
* per-node (the responder system's pointer events, focus/blur, selection change): the physical
|
|
57
|
+
* hit is always a real element this package created, but it is not always one with its own
|
|
58
|
+
* listeners, so the search has to climb past any that are not tracked before it gets to `body`
|
|
59
|
+
* and turns up nothing.
|
|
60
|
+
*/
|
|
61
|
+
export declare function nearestNodeOf(el: Element | null): BrowserNode | null;
|
|
62
|
+
/** Root-first path from the tree's root to `node`, inclusive. Mirrors `Engine`'s own `pathTo`. */
|
|
63
|
+
export declare function pathTo(node: BrowserNode): BrowserNode[];
|
package/dist/dom-node.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** `event.target`, and anything else holding a real DOM node, back to the `BrowserNode` for it. */
|
|
2
|
+
const registry = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* The SVG names whose `fill`/`stroke` need a seeded `props` entry from the moment they are
|
|
5
|
+
* created - see the block below for why. `svg-line` is left out: a `<line>` has no fill of its
|
|
6
|
+
* own to paint (react-native-svg's `Line` never reads `fill` either), so there is nothing an
|
|
7
|
+
* explicit `fill="none"` there could mean.
|
|
8
|
+
*/
|
|
9
|
+
const SVG_BRUSH_ELEMENTS = new Set(['svg-g', 'svg-path', 'svg-circle', 'svg-ellipse', 'svg-rect']);
|
|
10
|
+
export function makeElementNode(name, el) {
|
|
11
|
+
const props = {};
|
|
12
|
+
// `packages/icons/src/svg-props.ts`'s `brushOf` turns a literal `fill="none"`/`stroke="none"`
|
|
13
|
+
// into `null` - a real, meaningful value ("paint nothing"), not an absent one. But
|
|
14
|
+
// `BrowserEngine.setProp` treats `null` exactly like `undefined` on a key it has never seen
|
|
15
|
+
// before: `if (!(key in node.props)) return;`, its fast path for "nothing to remove, so nothing
|
|
16
|
+
// changed". That path is right for almost everything a `null` prop could mean, and wrong here -
|
|
17
|
+
// it would skip `applyProp` entirely on a chart line's `fill="none"` (`chart-line.ts`,
|
|
18
|
+
// `chart-area.ts`), leaving the attribute unset, and an unset `fill` defaults to opaque black in
|
|
19
|
+
// a browser (the real SVG initial value) rather than to unpainted (what react-native-svg's own
|
|
20
|
+
// `propList` convention, and every one of these charts, is relying on). Seeding the key here -
|
|
21
|
+
// present, value `undefined` - costs nothing on a shape that never touches the prop again, and
|
|
22
|
+
// is what lets that first `null` reach `props.ts`'s real translation instead of being dropped by
|
|
23
|
+
// the fast path. See `props.ts`'s `applyBrush` for the other half: it is what turns a seeded
|
|
24
|
+
// key's `null` into a written `fill="none"`/`stroke="none"` rather than a removed attribute.
|
|
25
|
+
if (SVG_BRUSH_ELEMENTS.has(name)) {
|
|
26
|
+
props['fill'] = undefined;
|
|
27
|
+
props['stroke'] = undefined;
|
|
28
|
+
}
|
|
29
|
+
const node = {
|
|
30
|
+
kind: 'element',
|
|
31
|
+
el,
|
|
32
|
+
name,
|
|
33
|
+
tagName: name,
|
|
34
|
+
props,
|
|
35
|
+
text: '',
|
|
36
|
+
children: [],
|
|
37
|
+
parent: null,
|
|
38
|
+
listeners: null,
|
|
39
|
+
optedIn: null,
|
|
40
|
+
};
|
|
41
|
+
registry.set(el, node);
|
|
42
|
+
return node;
|
|
43
|
+
}
|
|
44
|
+
export function makeTextNode(text) {
|
|
45
|
+
const node = {
|
|
46
|
+
kind: 'text',
|
|
47
|
+
el: text,
|
|
48
|
+
name: '#text',
|
|
49
|
+
props: {},
|
|
50
|
+
text: text.data,
|
|
51
|
+
children: [],
|
|
52
|
+
parent: null,
|
|
53
|
+
listeners: null,
|
|
54
|
+
optedIn: null,
|
|
55
|
+
};
|
|
56
|
+
registry.set(text, node);
|
|
57
|
+
return node;
|
|
58
|
+
}
|
|
59
|
+
/** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */
|
|
60
|
+
export function makeAnchorNode(comment) {
|
|
61
|
+
const node = {
|
|
62
|
+
kind: 'anchor',
|
|
63
|
+
el: comment,
|
|
64
|
+
name: '#anchor',
|
|
65
|
+
props: {},
|
|
66
|
+
text: '',
|
|
67
|
+
children: [],
|
|
68
|
+
parent: null,
|
|
69
|
+
listeners: null,
|
|
70
|
+
optedIn: null,
|
|
71
|
+
};
|
|
72
|
+
registry.set(comment, node);
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
/** The `BrowserNode` a real DOM node was created with, or `null` for one this package did not make. */
|
|
76
|
+
export function nodeOf(el) {
|
|
77
|
+
return el ? (registry.get(el) ?? null) : null;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The nearest `BrowserNode` starting at a real `Element` and walking up `parentElement`.
|
|
81
|
+
*
|
|
82
|
+
* Used to resolve `event.target` for events this package listens for on `document` rather than
|
|
83
|
+
* per-node (the responder system's pointer events, focus/blur, selection change): the physical
|
|
84
|
+
* hit is always a real element this package created, but it is not always one with its own
|
|
85
|
+
* listeners, so the search has to climb past any that are not tracked before it gets to `body`
|
|
86
|
+
* and turns up nothing.
|
|
87
|
+
*/
|
|
88
|
+
export function nearestNodeOf(el) {
|
|
89
|
+
for (let current = el; current; current = current.parentElement) {
|
|
90
|
+
const node = registry.get(current);
|
|
91
|
+
if (node)
|
|
92
|
+
return node;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
/** Root-first path from the tree's root to `node`, inclusive. Mirrors `Engine`'s own `pathTo`. */
|
|
97
|
+
export function pathTo(node) {
|
|
98
|
+
const path = [];
|
|
99
|
+
for (let current = node; current; current = current.parent)
|
|
100
|
+
path.push(current);
|
|
101
|
+
return path.reverse();
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=dom-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-node.js","sourceRoot":"","sources":["../src/dom-node.ts"],"names":[],"mappings":"AAgDA,mGAAmG;AACnG,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAyC,CAAC;AAEtE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC;AAEnG,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,EAAW;IACvD,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,8FAA8F;IAC9F,mFAAmF;IACnF,4FAA4F;IAC5F,gGAAgG;IAChG,gGAAgG;IAChG,uFAAuF;IACvF,iGAAiG;IACjG,+FAA+F;IAC/F,+FAA+F;IAC/F,+FAA+F;IAC/F,iGAAiG;IACjG,6FAA6F;IAC7F,6FAA6F;IAC7F,IAAI,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;QAC1B,KAAK,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;IAC9B,CAAC;IACD,MAAM,IAAI,GAAgB;QACxB,IAAI,EAAE,SAAS;QACf,EAAE;QACF,IAAI;QACJ,OAAO,EAAE,IAAI;QACb,KAAK;QACL,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;KACd,CAAC;IACF,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACvB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAU;IACrC,MAA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,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,MAAM,CAAC,IAAiB;IACtC,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,KAAK,IAAI,OAAO,GAAuB,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM;QAC5E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC","sourcesContent":["/**\n * The retained node this package hands Angular as `ElementRef.nativeElement`, and the thing every\n * `HostEngine` method actually operates on.\n *\n * `packages/fabric/src/engine.ts`'s `EngineNode` is not reusable here (its constructor-free shape\n * still carries Fabric-only bookkeeping - `committed`, `styleCache`, `sheet`...), but the shared\n * packages never ask for that: they ask for `HostNode`'s five fields, plus whatever a component\n * reads directly off `this.node` after `inject(ElementRef).nativeElement as EngineNode` casts it\n * back. Grepping every such read (`view-base.ts`, `pressable.ts`'s `TouchableBase`, `scroll-view.ts`,\n * `select.ts`'s `textOf`) turns up exactly `kind`, `props`, `text`, `children` and `parent` - so a\n * class that implements `HostNode` honestly, backed by a real DOM node, satisfies every one of\n * them without a cast.\n *\n * `children`/`parent` are maintained by hand rather than read live off the DOM (`el.parentElement`,\n * `el.childNodes`) for the same reason `Engine` keeps its own tree: a live DOM walk would have to\n * filter out nodes this package did not create (there are none today, but a consumer's own\n * `document.createElement` inside a projected template is not this package's to assume against),\n * and `select.ts`'s `textOf` recursion wants exactly the nodes Angular put here, in order.\n */\nimport type { HostNode } from '@ng-native/fabric';\n\nexport type BrowserNodeKind = 'element' | 'text' | 'anchor';\n\nexport interface BrowserNode extends HostNode {\n readonly kind: BrowserNodeKind;\n /** The real DOM node this wraps. An `Element` for `element`, a `Text` for `text`. */\n readonly el: Element | Text | Comment;\n /** Lowercase template spelling, e.g. `view`. Mirrors `EngineNode.name`; never the DOM tag. */\n readonly name: string;\n /** `name` again on an element, for Angular 22.0, which reads it on a component's host element. */\n readonly tagName?: string;\n props: Record<string, unknown>;\n text: string;\n children: BrowserNode[];\n parent: BrowserNode | null;\n /**\n * Registered listeners, by top-level type (`topTouchStart`, `topChange`, ...). `null` until\n * the first one, so a node nothing ever listens to costs one field rather than one `Map`.\n */\n listeners: Map<string, Set<(event: unknown) => void>> | null;\n /**\n * Which opt-in event types (`topLayout`, `topPointerEnter`, `topPointerLeave`) already have\n * their real DOM listener installed - `browser-engine.ts`'s `wireOptIn` guard. `null` until\n * the first one, matching `listeners` above.\n */\n optedIn: Set<string> | null;\n}\n\n/** `event.target`, and anything else holding a real DOM node, back to the `BrowserNode` for it. */\nconst registry = new WeakMap<Element | Text | Comment, BrowserNode>();\n\n/**\n * The SVG names whose `fill`/`stroke` need a seeded `props` entry from the moment they are\n * created - see the block below for why. `svg-line` is left out: a `<line>` has no fill of its\n * own to paint (react-native-svg's `Line` never reads `fill` either), so there is nothing an\n * explicit `fill=\"none\"` there could mean.\n */\nconst SVG_BRUSH_ELEMENTS = new Set(['svg-g', 'svg-path', 'svg-circle', 'svg-ellipse', 'svg-rect']);\n\nexport function makeElementNode(name: string, el: Element): BrowserNode {\n const props: Record<string, unknown> = {};\n // `packages/icons/src/svg-props.ts`'s `brushOf` turns a literal `fill=\"none\"`/`stroke=\"none\"`\n // into `null` - a real, meaningful value (\"paint nothing\"), not an absent one. But\n // `BrowserEngine.setProp` treats `null` exactly like `undefined` on a key it has never seen\n // before: `if (!(key in node.props)) return;`, its fast path for \"nothing to remove, so nothing\n // changed\". That path is right for almost everything a `null` prop could mean, and wrong here -\n // it would skip `applyProp` entirely on a chart line's `fill=\"none\"` (`chart-line.ts`,\n // `chart-area.ts`), leaving the attribute unset, and an unset `fill` defaults to opaque black in\n // a browser (the real SVG initial value) rather than to unpainted (what react-native-svg's own\n // `propList` convention, and every one of these charts, is relying on). Seeding the key here -\n // present, value `undefined` - costs nothing on a shape that never touches the prop again, and\n // is what lets that first `null` reach `props.ts`'s real translation instead of being dropped by\n // the fast path. See `props.ts`'s `applyBrush` for the other half: it is what turns a seeded\n // key's `null` into a written `fill=\"none\"`/`stroke=\"none\"` rather than a removed attribute.\n if (SVG_BRUSH_ELEMENTS.has(name)) {\n props['fill'] = undefined;\n props['stroke'] = undefined;\n }\n const node: BrowserNode = {\n kind: 'element',\n el,\n name,\n tagName: name,\n props,\n text: '',\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(el, node);\n return node;\n}\n\nexport function makeTextNode(text: Text): BrowserNode {\n const node: BrowserNode = {\n kind: 'text',\n el: text,\n name: '#text',\n props: {},\n text: text.data,\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(text, node);\n return node;\n}\n\n/** Angular's `@if`/`@for`/`ViewContainerRef` markers, backed by a real `Comment`. */\nexport function makeAnchorNode(comment: Comment): BrowserNode {\n const node: BrowserNode = {\n kind: 'anchor',\n el: comment,\n name: '#anchor',\n props: {},\n text: '',\n children: [],\n parent: null,\n listeners: null,\n optedIn: null,\n };\n registry.set(comment, node);\n return node;\n}\n\n/** The `BrowserNode` a real DOM node was created with, or `null` for one this package did not make. */\nexport function nodeOf(el: Element | Text | Comment | null): BrowserNode | null {\n return el ? (registry.get(el) ?? null) : null;\n}\n\n/**\n * The nearest `BrowserNode` starting at a real `Element` and walking up `parentElement`.\n *\n * Used to resolve `event.target` for events this package listens for on `document` rather than\n * per-node (the responder system's pointer events, focus/blur, selection change): the physical\n * hit is always a real element this package created, but it is not always one with its own\n * listeners, so the search has to climb past any that are not tracked before it gets to `body`\n * and turns up nothing.\n */\nexport function nearestNodeOf(el: Element | null): BrowserNode | null {\n for (let current = el; current; current = current.parentElement) {\n const node = registry.get(current);\n if (node) return node;\n }\n return null;\n}\n\n/** Root-first path from the tree's root to `node`, inclusive. Mirrors `Engine`'s own `pathTo`. */\nexport function pathTo(node: BrowserNode): BrowserNode[] {\n const path: BrowserNode[] = [];\n for (let current: BrowserNode | null = node; current; current = current.parent)\n path.push(current);\n return path.reverse();\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DOM tag each element name commits as.
|
|
3
|
+
*
|
|
4
|
+
* Every name Angular ever creates a host element for - `view`, `text`, `pressable`, and also
|
|
5
|
+
* every component's own selector (a caller's own `x-widget`, say) - becomes a real element with
|
|
6
|
+
* exactly that tag. A browser accepts any tag name and gives it no built-in
|
|
7
|
+
* unregistered name to a plain `View`, because native only has a fixed set of *real* native views
|
|
8
|
+
* to commit as and an arbitrary string is not one of them. A browser has no such list - there is
|
|
9
|
+
* nothing to fall back from - so this file does not reproduce that fallback; the reason for it on
|
|
10
|
+
* native does not exist on the web. `data-rn="<name>"` still goes on every element regardless (it
|
|
11
|
+
* is what `reset.css` selects on, and what the two exceptions below need it for), but the tag
|
|
12
|
+
* itself is always the literal name unless this table says otherwise.
|
|
13
|
+
*
|
|
14
|
+
* ## The two exceptions
|
|
15
|
+
*
|
|
16
|
+
* `ViewBase`'s own prop writes (a real ARIA `role`, `tabindex`, `aria-*`) are enough accessible
|
|
17
|
+
* behaviour for a view, a piece of text, or a scroll container - no amount of them makes a
|
|
18
|
+
* `<view>` accept a text cursor or a space-bar toggle, though, because those are behaviours the
|
|
19
|
+
* browser's own form controls implement in C++, not CSS or JavaScript this package could add. So:
|
|
20
|
+
*
|
|
21
|
+
* - `text-input` commits as a real `<textarea>`. A `<textarea>` rather than an `<input>` because
|
|
22
|
+
* `multiline` is a prop set *after* creation (an Angular host binding, run on the first change
|
|
23
|
+
* detection pass, not known at `createElement`), and a `<textarea>` can stand in for a
|
|
24
|
+
* single-line field by intercepting `Enter` (see `browser-engine.ts`) in a way an `<input>`
|
|
25
|
+
* cannot stand in for a multi-line one. `secureTextEntry` is approximated with the
|
|
26
|
+
* non-standard `-webkit-text-security` (see `props.ts`); Firefox has no equivalent and shows
|
|
27
|
+
* the text in the clear, which is the one place this package's accessibility parity is
|
|
28
|
+
* actually worse than a wrong guess would be quieter about.
|
|
29
|
+
* - `switch` commits as a real `<input type="checkbox">`. Its accessible role still comes from
|
|
30
|
+
* `ViewBase`'s normal prop pipeline (`Switch.roleByDefault()` returns `'switch'`, which
|
|
31
|
+
* `props.ts`'s `ROLE_MAP` turns into `role="switch"`) - this file only has to make the element
|
|
32
|
+
* a genuine, keyboard- and screen-reader-operable checkbox underneath that role.
|
|
33
|
+
*
|
|
34
|
+
* `image` stays a plain `data-rn="image"` element rather than a real `<img>`, on purpose: RN's
|
|
35
|
+
* `Image` is a box that a picture fills, sized by flex like any other view, not a replaced
|
|
36
|
+
* inline element with its own intrinsic size fighting the layout. `browser-engine.ts` paints the
|
|
37
|
+
* picture with `background-image`, which is what lets `resizeMode` map straight onto
|
|
38
|
+
* `background-size` instead of needing a wrapper element `object-fit` does not.
|
|
39
|
+
*
|
|
40
|
+
* ## The third exception: SVG
|
|
41
|
+
*
|
|
42
|
+
* `packages/icons/src/svg-elements.ts` registers `svg-g`/`svg-path`/`svg-circle`/`svg-ellipse`/
|
|
43
|
+
* `svg-rect`/`svg-line` and its root (`ng-icon`) against Fabric view names (`RNSVGPath` and so
|
|
44
|
+
* on) so that native drives `react-native-svg` directly with no React component of its own in
|
|
45
|
+
* between - see that file's doc comment. A tag created with `document.createElement` is not
|
|
46
|
+
* enough to make that work here: an element born outside the SVG namespace never paints as SVG no
|
|
47
|
+
* matter what tag string it is given (`document.createElement` always mints an
|
|
48
|
+
* `HTMLUnknownElement` for a name a browser does not recognise, SVG names very much included), so
|
|
49
|
+
* these seven names are the only ones in this file that need `ns` - everything else is content
|
|
50
|
+
* HTML has no opinion on and is happy to create by string alone.
|
|
51
|
+
*/
|
|
52
|
+
export interface ElementSpec {
|
|
53
|
+
readonly tag: string;
|
|
54
|
+
/** Attributes set once, at creation, because the DOM tag needs them to behave at all. */
|
|
55
|
+
readonly attrs?: Readonly<Record<string, string>>;
|
|
56
|
+
/** The element's creation namespace, when it is not HTML's. `createDomElement` reads this to
|
|
57
|
+
* choose `createElementNS` over `createElement` - see "The third exception: SVG" above. */
|
|
58
|
+
readonly ns?: string;
|
|
59
|
+
}
|
|
60
|
+
/** The one non-HTML namespace this package ever needs. */
|
|
61
|
+
export declare const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
62
|
+
/**
|
|
63
|
+
* Register a name that needs a real DOM tag or baseline attributes beyond the default (its own
|
|
64
|
+
* name, no attributes) - the web counterpart to `engine.ts`'s `registerViewName`. Nothing in this
|
|
65
|
+
* package needs to guess at an unknown name the way `viewNameOf` does; see the file doc comment
|
|
66
|
+
* for why.
|
|
67
|
+
*/
|
|
68
|
+
export declare function registerElementName(name: string, spec: ElementSpec): void;
|
|
69
|
+
export declare function specFor(name: string): ElementSpec;
|
|
70
|
+
/**
|
|
71
|
+
* Create the real DOM element for a template tag name, with its `data-rn` marker and attrs.
|
|
72
|
+
*
|
|
73
|
+
* `createElementNS` rather than `createElement` whenever a spec names a namespace - see "The
|
|
74
|
+
* third exception: SVG" above. `setAttribute`, on the other hand, is namespace-agnostic either
|
|
75
|
+
* way (an attribute has no namespace of its own unless explicitly qualified, which `data-rn` and
|
|
76
|
+
* every attribute this package writes never is), so nothing below the element's own creation
|
|
77
|
+
* needs to change for it.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createDomElement(document: Document, name: string): Element;
|
package/dist/elements.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** The one non-HTML namespace this package ever needs. */
|
|
2
|
+
export const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
3
|
+
const SPECS = {
|
|
4
|
+
'text-input': { tag: 'textarea', attrs: { rows: '1' } },
|
|
5
|
+
switch: { tag: 'input', attrs: { type: 'checkbox' } },
|
|
6
|
+
'activity-indicator': { tag: 'activity-indicator', attrs: { role: 'progressbar' } },
|
|
7
|
+
// The shapes `@ng-native/icons`' `svg-elements.ts` registers. Real SVG tag names, not the prefixed
|
|
8
|
+
// template names - `svg-path` would otherwise ask the DOM for an element literally called
|
|
9
|
+
// `<svg-path>`, which the SVG namespace has no such thing as and so mints as an unstyled,
|
|
10
|
+
// unpainted `SVGUnknownElement` instead of a `<path>`.
|
|
11
|
+
'svg-g': { tag: 'g', ns: SVG_NAMESPACE },
|
|
12
|
+
'svg-path': { tag: 'path', ns: SVG_NAMESPACE },
|
|
13
|
+
'svg-circle': { tag: 'circle', ns: SVG_NAMESPACE },
|
|
14
|
+
'svg-ellipse': { tag: 'ellipse', ns: SVG_NAMESPACE },
|
|
15
|
+
'svg-rect': { tag: 'rect', ns: SVG_NAMESPACE },
|
|
16
|
+
'svg-line': { tag: 'line', ns: SVG_NAMESPACE },
|
|
17
|
+
// The root. Commits as the same Fabric view natively (`svg-elements.ts`'s own doc comment); a
|
|
18
|
+
// plain `<svg>` here too; `props.ts`'s `SVG_ROOT_HANDLERS` is what reads `NgIcon`'s own host
|
|
19
|
+
// bindings into its `viewBox`/size.
|
|
20
|
+
'ng-icon': { tag: 'svg', ns: SVG_NAMESPACE },
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Register a name that needs a real DOM tag or baseline attributes beyond the default (its own
|
|
24
|
+
* name, no attributes) - the web counterpart to `engine.ts`'s `registerViewName`. Nothing in this
|
|
25
|
+
* package needs to guess at an unknown name the way `viewNameOf` does; see the file doc comment
|
|
26
|
+
* for why.
|
|
27
|
+
*/
|
|
28
|
+
export function registerElementName(name, spec) {
|
|
29
|
+
SPECS[name] = spec;
|
|
30
|
+
}
|
|
31
|
+
export function specFor(name) {
|
|
32
|
+
return SPECS[name] ?? { tag: name };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create the real DOM element for a template tag name, with its `data-rn` marker and attrs.
|
|
36
|
+
*
|
|
37
|
+
* `createElementNS` rather than `createElement` whenever a spec names a namespace - see "The
|
|
38
|
+
* third exception: SVG" above. `setAttribute`, on the other hand, is namespace-agnostic either
|
|
39
|
+
* way (an attribute has no namespace of its own unless explicitly qualified, which `data-rn` and
|
|
40
|
+
* every attribute this package writes never is), so nothing below the element's own creation
|
|
41
|
+
* needs to change for it.
|
|
42
|
+
*/
|
|
43
|
+
export function createDomElement(document, name) {
|
|
44
|
+
const spec = specFor(name);
|
|
45
|
+
const el = spec.ns
|
|
46
|
+
? document.createElementNS(spec.ns, spec.tag)
|
|
47
|
+
: document.createElement(spec.tag);
|
|
48
|
+
el.setAttribute('data-rn', name);
|
|
49
|
+
for (const [attr, value] of Object.entries(spec.attrs ?? {}))
|
|
50
|
+
el.setAttribute(attr, value);
|
|
51
|
+
return el;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=elements.js.map
|
|
@@ -0,0 +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,EAAE,GAAG,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,mBAAmB,CAAC,IAAY,EAAE,IAAiB;IACjE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACtC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAkB,EAAE,IAAY;IAC/D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,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"]}
|