@ng-native/web 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-engine.d.ts +25 -1
- package/dist/browser-engine.js +79 -26
- package/dist/browser-engine.js.map +1 -1
- package/dist/device-sources.d.ts +4 -2
- package/dist/device-sources.js +23 -8
- package/dist/device-sources.js.map +1 -1
- package/dist/dom-node.d.ts +10 -0
- package/dist/dom-node.js +14 -0
- package/dist/dom-node.js.map +1 -1
- package/dist/elements.d.ts +13 -8
- package/dist/elements.js +19 -1
- package/dist/elements.js.map +1 -1
- package/dist/jsdom-env.js +1 -0
- package/dist/jsdom-env.js.map +1 -1
- package/dist/mount.d.ts +7 -0
- package/dist/mount.js +23 -14
- package/dist/mount.js.map +1 -1
- package/dist/props.js +32 -4
- package/dist/props.js.map +1 -1
- package/dist/reset-css.d.ts +1 -1
- package/dist/reset-css.js +142 -2
- package/dist/reset-css.js.map +1 -1
- package/dist/reset.css +167 -7
- package/package.json +13 -10
- package/vite.d.mts +7 -0
- package/vite.mjs +84 -7
package/dist/reset.css
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* one does), but this is written from this project's own assumptions rather than copied from it:
|
|
18
18
|
* it targets `[data-rn]`, the marker `elements.ts` puts on every node this package creates
|
|
19
19
|
* (`data-rn="<template name>"`) rather than the tag itself, because two elements - `text-input`
|
|
20
|
-
* and `switch` - commit as a real `<
|
|
20
|
+
* and `switch` - commit as a real `<input>` (or `<textarea>`) rather than their own tag (see
|
|
21
21
|
* `elements.ts`'s doc comment for why), and a tag selector would miss them.
|
|
22
22
|
*
|
|
23
23
|
* `box-sizing: border-box` matches Yoga, where a node's `width`/`height` already includes its
|
|
@@ -124,16 +124,166 @@ body {
|
|
|
124
124
|
-moz-osx-font-smoothing: grayscale;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
/*
|
|
128
|
+
* HTML's text elements (`span`, `p`, `h1` and the rest), which the engine decides between text and
|
|
129
|
+
* a view by what each holds: text when it holds only text and other text elements, a view when it
|
|
130
|
+
* holds anything else. `:has()` asks the same question here, of any depth, since a text element
|
|
131
|
+
* that holds a view is a view to the one around it as well.
|
|
132
|
+
*
|
|
133
|
+
* Inside `:where()`, so the two rules weigh what they weighed before these elements were known.
|
|
134
|
+
*/
|
|
135
|
+
[data-rn]:not([data-rn='text']):not(
|
|
136
|
+
:where(
|
|
137
|
+
:is(
|
|
138
|
+
[data-rn='span'],
|
|
139
|
+
[data-rn='p'],
|
|
140
|
+
[data-rn='h1'],
|
|
141
|
+
[data-rn='h2'],
|
|
142
|
+
[data-rn='h3'],
|
|
143
|
+
[data-rn='h4'],
|
|
144
|
+
[data-rn='h5'],
|
|
145
|
+
[data-rn='h6'],
|
|
146
|
+
[data-rn='label'],
|
|
147
|
+
[data-rn='strong'],
|
|
148
|
+
[data-rn='b'],
|
|
149
|
+
[data-rn='em'],
|
|
150
|
+
[data-rn='i'],
|
|
151
|
+
[data-rn='u'],
|
|
152
|
+
[data-rn='s'],
|
|
153
|
+
[data-rn='small'],
|
|
154
|
+
[data-rn='code'],
|
|
155
|
+
[data-rn='mark'],
|
|
156
|
+
[data-rn='abbr'],
|
|
157
|
+
[data-rn='cite'],
|
|
158
|
+
[data-rn='time']
|
|
159
|
+
):not(
|
|
160
|
+
:has(
|
|
161
|
+
[data-rn]:not(
|
|
162
|
+
[data-rn='text'],
|
|
163
|
+
[data-rn='span'],
|
|
164
|
+
[data-rn='p'],
|
|
165
|
+
[data-rn='h1'],
|
|
166
|
+
[data-rn='h2'],
|
|
167
|
+
[data-rn='h3'],
|
|
168
|
+
[data-rn='h4'],
|
|
169
|
+
[data-rn='h5'],
|
|
170
|
+
[data-rn='h6'],
|
|
171
|
+
[data-rn='label'],
|
|
172
|
+
[data-rn='strong'],
|
|
173
|
+
[data-rn='b'],
|
|
174
|
+
[data-rn='em'],
|
|
175
|
+
[data-rn='i'],
|
|
176
|
+
[data-rn='u'],
|
|
177
|
+
[data-rn='s'],
|
|
178
|
+
[data-rn='small'],
|
|
179
|
+
[data-rn='code'],
|
|
180
|
+
[data-rn='mark'],
|
|
181
|
+
[data-rn='abbr'],
|
|
182
|
+
[data-rn='cite'],
|
|
183
|
+
[data-rn='time']
|
|
184
|
+
)
|
|
185
|
+
)
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
) {
|
|
128
189
|
display: flex;
|
|
129
190
|
flex-direction: column;
|
|
130
191
|
align-items: stretch;
|
|
131
192
|
}
|
|
132
193
|
|
|
133
|
-
[data-rn='text']
|
|
194
|
+
[data-rn='text'],
|
|
195
|
+
:where(
|
|
196
|
+
:is(
|
|
197
|
+
[data-rn='span'],
|
|
198
|
+
[data-rn='p'],
|
|
199
|
+
[data-rn='h1'],
|
|
200
|
+
[data-rn='h2'],
|
|
201
|
+
[data-rn='h3'],
|
|
202
|
+
[data-rn='h4'],
|
|
203
|
+
[data-rn='h5'],
|
|
204
|
+
[data-rn='h6'],
|
|
205
|
+
[data-rn='label'],
|
|
206
|
+
[data-rn='strong'],
|
|
207
|
+
[data-rn='b'],
|
|
208
|
+
[data-rn='em'],
|
|
209
|
+
[data-rn='i'],
|
|
210
|
+
[data-rn='u'],
|
|
211
|
+
[data-rn='s'],
|
|
212
|
+
[data-rn='small'],
|
|
213
|
+
[data-rn='code'],
|
|
214
|
+
[data-rn='mark'],
|
|
215
|
+
[data-rn='abbr'],
|
|
216
|
+
[data-rn='cite'],
|
|
217
|
+
[data-rn='time']
|
|
218
|
+
):not(
|
|
219
|
+
:has(
|
|
220
|
+
[data-rn]:not(
|
|
221
|
+
[data-rn='text'],
|
|
222
|
+
[data-rn='span'],
|
|
223
|
+
[data-rn='p'],
|
|
224
|
+
[data-rn='h1'],
|
|
225
|
+
[data-rn='h2'],
|
|
226
|
+
[data-rn='h3'],
|
|
227
|
+
[data-rn='h4'],
|
|
228
|
+
[data-rn='h5'],
|
|
229
|
+
[data-rn='h6'],
|
|
230
|
+
[data-rn='label'],
|
|
231
|
+
[data-rn='strong'],
|
|
232
|
+
[data-rn='b'],
|
|
233
|
+
[data-rn='em'],
|
|
234
|
+
[data-rn='i'],
|
|
235
|
+
[data-rn='u'],
|
|
236
|
+
[data-rn='s'],
|
|
237
|
+
[data-rn='small'],
|
|
238
|
+
[data-rn='code'],
|
|
239
|
+
[data-rn='mark'],
|
|
240
|
+
[data-rn='abbr'],
|
|
241
|
+
[data-rn='cite'],
|
|
242
|
+
[data-rn='time']
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
)[data-rn] {
|
|
134
247
|
display: inline;
|
|
135
248
|
}
|
|
136
249
|
|
|
250
|
+
/*
|
|
251
|
+
* What a browser gives these elements that the engine does not, taken away, and the few styles
|
|
252
|
+
* the engine does give them (`packages/fabric/src/element-styles.ts`), said here too: a heading
|
|
253
|
+
* and a paragraph are plain text with no margin, a list has no markers or indent, and `strong`,
|
|
254
|
+
* `small`, `code` and `mark` look as they do on a device. `em`, `i`, `cite`, `u` and `s` are a
|
|
255
|
+
* browser's own already. All inside `:where()`, so any rule of the app's wins.
|
|
256
|
+
*/
|
|
257
|
+
:where(h1, h2, h3, h4, h5, h6, p)[data-rn] {
|
|
258
|
+
font-size: inherit;
|
|
259
|
+
font-weight: inherit;
|
|
260
|
+
margin: 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
:where(ul, ol)[data-rn] {
|
|
264
|
+
list-style: none;
|
|
265
|
+
margin: 0;
|
|
266
|
+
padding: 0;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
:where(strong, b)[data-rn] {
|
|
270
|
+
font-weight: bold;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
:where(small)[data-rn] {
|
|
274
|
+
font-size: 80%;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
:where(code)[data-rn] {
|
|
278
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
279
|
+
font-size: 1em;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
:where(mark)[data-rn] {
|
|
283
|
+
background-color: rgb(255, 255, 0);
|
|
284
|
+
color: rgb(0, 0, 0);
|
|
285
|
+
}
|
|
286
|
+
|
|
137
287
|
/*
|
|
138
288
|
* `ScrollView.js`'s own base style (`engine.ts`'s `DEFAULT_PROPS.ScrollView`): a native scroll
|
|
139
289
|
* view does not clip its content on its own, so without this the content spills straight out of
|
|
@@ -190,6 +340,16 @@ body {
|
|
|
190
340
|
height: var(--rn-intrinsic-height, auto);
|
|
191
341
|
}
|
|
192
342
|
|
|
343
|
+
/*
|
|
344
|
+
* `<gesture-root>`'s own `flex: 1`, the base style `@ng-native/components/gestures` gives it on a
|
|
345
|
+
* device, where Yoga reads it as a grow of 1 from a basis of 0 (the shrink stays the 0 above).
|
|
346
|
+
* `:where` keeps it below any class the app writes, as a default prop is below a style on a device.
|
|
347
|
+
*/
|
|
348
|
+
:where([data-rn='gesture-root']) {
|
|
349
|
+
flex-grow: 1;
|
|
350
|
+
flex-basis: 0%;
|
|
351
|
+
}
|
|
352
|
+
|
|
193
353
|
/*
|
|
194
354
|
* `Modal.js`'s base style is `{position: 'absolute'}`, sized to fill RN's window because that is
|
|
195
355
|
* what an absolutely-positioned view with no other constraint does inside it. A web page has no
|
|
@@ -259,10 +419,10 @@ body {
|
|
|
259
419
|
* cascade - meaning near-white theme text on a white ground, i.e. an invisible value in an
|
|
260
420
|
* apparently blank field. Transparent is both the faithful behaviour and the fix.
|
|
261
421
|
*
|
|
262
|
-
* The rest of a browser's field chrome goes for the same reason. A
|
|
263
|
-
*
|
|
264
|
-
* it, as `<text>` does, and a platform font at 14 when there are none. It also adds
|
|
265
|
-
* resize handle that a device's field does not have.
|
|
422
|
+
* The rest of a browser's field chrome goes for the same reason. A field sets its own font, at
|
|
423
|
+
* 13.33px in Chromium and monospace in a `<textarea>`, where a device's field takes the text
|
|
424
|
+
* styles around it, as `<text>` does, and a platform font at 14 when there are none. It also adds
|
|
425
|
+
* padding, and a textarea a resize handle, that a device's field does not have.
|
|
266
426
|
*/
|
|
267
427
|
[data-rn='text-input'] {
|
|
268
428
|
background-color: transparent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ng-native/web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A browser host for Angular Native: the same components, rendered into the DOM instead of native views.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@ng-native/
|
|
40
|
-
"@
|
|
38
|
+
"@ng-native/device": "0.4.0",
|
|
39
|
+
"@ng-native/fabric": "0.4.0",
|
|
40
|
+
"@oxc-angular/vite": "0.0.38"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@angular/core": "^22.0.0",
|
|
@@ -53,22 +53,25 @@
|
|
|
53
53
|
"@angular/compiler": "22.2.0",
|
|
54
54
|
"@angular/platform-browser": "22.2.0",
|
|
55
55
|
"@ng-icons/core": "^36.0.0",
|
|
56
|
+
"@ng-native/components": "0.4.0",
|
|
57
|
+
"@ng-native/icons": "0.4.0",
|
|
58
|
+
"@ng-native/metro": "0.4.0",
|
|
59
|
+
"@ng-native/tailwind": "0.4.0",
|
|
60
|
+
"@ng-native/testing": "0.4.0",
|
|
56
61
|
"@tailwindcss/vite": "^4.3.3",
|
|
57
62
|
"@types/jsdom": "^27.0.0",
|
|
58
63
|
"@vitest/browser": "^5.0.2",
|
|
59
64
|
"@vitest/browser-playwright": "^5.0.2",
|
|
60
65
|
"@vitest/coverage-v8": "^5.0.2",
|
|
66
|
+
"chokidar": "^5.0.0",
|
|
67
|
+
"jiti": "^2.7.0",
|
|
61
68
|
"jsdom": "^27.0.0",
|
|
62
69
|
"playwright": "^1.63.0",
|
|
63
70
|
"rxjs": "^7.8.2",
|
|
64
71
|
"tailwindcss": "^4.3.3",
|
|
72
|
+
"tailwindcss-v3": "npm:tailwindcss@^3.4.19",
|
|
65
73
|
"vite": "^8.3.1",
|
|
66
|
-
"vitest": "^5.0.2"
|
|
67
|
-
"@ng-native/components": "0.2.0",
|
|
68
|
-
"@ng-native/icons": "0.2.0",
|
|
69
|
-
"@ng-native/metro": "0.2.0",
|
|
70
|
-
"@ng-native/tailwind": "0.2.0",
|
|
71
|
-
"@ng-native/testing": "0.2.0"
|
|
74
|
+
"vitest": "^5.0.2"
|
|
72
75
|
},
|
|
73
76
|
"nx": {
|
|
74
77
|
"tags": [
|
package/vite.d.mts
CHANGED
|
@@ -9,3 +9,10 @@ import type { Plugin } from 'vite';
|
|
|
9
9
|
* `emitClassMetadata: false`.
|
|
10
10
|
*/
|
|
11
11
|
export declare function ngNativeWeb(options?: PluginOptions): Plugin[];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `ngNativeWeb()` without the compiler, for an app whose own Angular plugin compiles its
|
|
15
|
+
* components, as Analog's does: the resolution, and `@oxc-angular/vite`'s linker for the
|
|
16
|
+
* `@ng-native/*` packages.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ngNativeWebLink(): Plugin[];
|
package/vite.mjs
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
* - `ng-native:config`, the resolution a browser build needs. React Native and Expo are reachable
|
|
8
8
|
* from the packages behind guards a browser never passes, but a bundler still resolves every
|
|
9
|
-
* specifier it sees, and React Native's source is Flow.
|
|
9
|
+
* specifier it sees, and React Native's source is Flow. Both resolve to an empty module, and a
|
|
10
|
+
* Expo module a package `require`s, such as `expo-battery`, to one that throws. Reanimated,
|
|
11
|
+
* worklets and gesture-handler resolve to inert stand-ins, so a component that builds a gesture
|
|
12
|
+
* or an animation builds for the browser too.
|
|
10
13
|
* - `@oxc-angular/vite`'s own plugins, for the app's components and for the linker, which handles
|
|
11
14
|
* the `@ng-native/*` packages as it handles every partial-compiled Angular library on npm.
|
|
12
15
|
*/
|
|
@@ -17,17 +20,73 @@ import { angular } from '@oxc-angular/vite';
|
|
|
17
20
|
* import of anything else native-only is a module a browser build really would need, so it fails
|
|
18
21
|
* the build rather than the page.
|
|
19
22
|
*/
|
|
20
|
-
const NATIVE_ONLY =
|
|
21
|
-
const
|
|
23
|
+
const NATIVE_ONLY = /^(react-native|expo)(\/|$)/;
|
|
24
|
+
const EMPTY = '\0ng-native:native-only';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The native modules `@ng-native/expo` reaches through a `require` inside a `catch`:
|
|
28
|
+
* `expo-battery`, `expo-modules-core`, `@react-native-async-storage/async-storage`,
|
|
29
|
+
* `react-native-watch-connectivity`. Not every `react-native-*`: `@ng-native/components` requires
|
|
30
|
+
* Reanimated and gesture-handler outside any `catch`, where a module that throws would fail the
|
|
31
|
+
* page rather than the build. A `require` of one resolves to a module that throws when it is
|
|
32
|
+
* evaluated, so the `catch` answers as it does where the module is missing, and the service is
|
|
33
|
+
* inert. An `import` of one still resolves as usual, and fails the build when it is not installed.
|
|
34
|
+
*/
|
|
35
|
+
const NATIVE_MODULE =
|
|
36
|
+
/^(expo-|@expo\/|@react-native-async-storage\/|react-native-watch-connectivity$)/;
|
|
37
|
+
const MISSING = '\0ng-native:missing:';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The libraries an app imports itself for gestures and worklet animations, and the stand-in each
|
|
41
|
+
* resolves to in a browser, where there is no native recogniser and no UI-thread runtime: an
|
|
42
|
+
* animation lands where it ends, a gesture recognises nothing, and work scheduled for either
|
|
43
|
+
* runtime runs at once. Installed or not, since the libraries reach React Native's source.
|
|
44
|
+
*/
|
|
45
|
+
const STAND_INS = {
|
|
46
|
+
'react-native-reanimated': '@ng-native/components/stand-ins/reanimated',
|
|
47
|
+
'react-native-worklets': '@ng-native/components/stand-ins/worklets',
|
|
48
|
+
'react-native-gesture-handler': '@ng-native/components/stand-ins/gesture-handler',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolves `react-native` and `expo` to an empty module, and a `require` of an Expo module to one
|
|
53
|
+
* that throws, in the build and in the dependency pre-bundle alike.
|
|
54
|
+
*
|
|
55
|
+
* Not `optimizeDeps.exclude` and `build.rolldownOptions.external`. The pre-bundle turns an
|
|
56
|
+
* excluded package's `require` into a top-level import, so the page loaded React Native's Flow
|
|
57
|
+
* source and failed on it. And an `external` of ours has to merge with one the app or a tool sets,
|
|
58
|
+
* such as Storybook's array, which a function cannot join.
|
|
59
|
+
*
|
|
60
|
+
* @returns {import('vite').Plugin}
|
|
61
|
+
*/
|
|
62
|
+
function nativeOnly() {
|
|
63
|
+
return {
|
|
64
|
+
name: 'ng-native:native-only',
|
|
65
|
+
resolveId(id, importer, options) {
|
|
66
|
+
// From the importer: `@ng-native/components` is the app's, not this package's.
|
|
67
|
+
// As resolved, so the dependency scan takes the stand-in as a dependency to pre-bundle.
|
|
68
|
+
if (Object.hasOwn(STAND_INS, id))
|
|
69
|
+
return this.resolve(STAND_INS[id], importer, { skipSelf: true });
|
|
70
|
+
if (NATIVE_ONLY.test(id)) return EMPTY;
|
|
71
|
+
if (options?.kind === 'require-call' && NATIVE_MODULE.test(id)) return MISSING + id;
|
|
72
|
+
return null;
|
|
73
|
+
},
|
|
74
|
+
load: (id) => {
|
|
75
|
+
if (id === EMPTY) return 'export {};';
|
|
76
|
+
if (!id.startsWith(MISSING)) return null;
|
|
77
|
+
const message = `${id.slice(MISSING.length)} is native-only, so not in a browser build`;
|
|
78
|
+
return `throw new Error(${JSON.stringify(message)});`;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
22
82
|
|
|
23
83
|
/** @returns {import('vite').Plugin} */
|
|
24
84
|
function config() {
|
|
25
85
|
return {
|
|
86
|
+
...nativeOnly(),
|
|
26
87
|
name: 'ng-native:config',
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
build: { rolldownOptions: { external: (id) => NATIVE_ONLY_PATTERN.test(id) } },
|
|
30
|
-
}),
|
|
88
|
+
enforce: 'pre',
|
|
89
|
+
config: () => ({ optimizeDeps: { rolldownOptions: { plugins: [nativeOnly()] } } }),
|
|
31
90
|
};
|
|
32
91
|
}
|
|
33
92
|
|
|
@@ -39,3 +98,21 @@ function config() {
|
|
|
39
98
|
export function ngNativeWeb(options = {}) {
|
|
40
99
|
return [config(), ...angular({ zoneless: true, emitClassMetadata: false, ...options })];
|
|
41
100
|
}
|
|
101
|
+
|
|
102
|
+
/** The plugins of `ngNativeWeb()` that `ngNativeWebLink()` keeps. */
|
|
103
|
+
const LINK = new Set(['ng-native:config', '@oxc-angular/vite-linker']);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `ngNativeWeb()` without the compiler, for an app whose own Angular plugin compiles its
|
|
107
|
+
* components, as Analog's does: the resolution, and `@oxc-angular/vite`'s linker.
|
|
108
|
+
*
|
|
109
|
+
* The linker is the part such an app lacks. Analog's runs only on paths with `/fesm20` in them,
|
|
110
|
+
* where `@angular/*` ship their bundles, and the `@ng-native/*` packages ship `ngc` output in
|
|
111
|
+
* `dist/` instead. `@oxc-angular/vite`'s goes by what a file holds, so it links them wherever they
|
|
112
|
+
* are, and leaves a file it finds nothing to link in alone.
|
|
113
|
+
*
|
|
114
|
+
* @returns {import('vite').Plugin[]}
|
|
115
|
+
*/
|
|
116
|
+
export function ngNativeWebLink() {
|
|
117
|
+
return ngNativeWeb().filter((plugin) => LINK.has(plugin.name));
|
|
118
|
+
}
|