@ng-native/web 0.3.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/reset.css CHANGED
@@ -124,16 +124,166 @@ body {
124
124
  -moz-osx-font-smoothing: grayscale;
125
125
  }
126
126
 
127
- [data-rn]:not([data-rn='text']) {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/web",
3
- "version": "0.3.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,8 +35,8 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@ng-native/device": "0.3.0",
39
- "@ng-native/fabric": "0.3.0",
38
+ "@ng-native/device": "0.4.0",
39
+ "@ng-native/fabric": "0.4.0",
40
40
  "@oxc-angular/vite": "0.0.38"
41
41
  },
42
42
  "peerDependencies": {
@@ -53,11 +53,11 @@
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.3.0",
57
- "@ng-native/icons": "0.3.0",
58
- "@ng-native/metro": "0.3.0",
59
- "@ng-native/tailwind": "0.3.0",
60
- "@ng-native/testing": "0.3.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",
61
61
  "@tailwindcss/vite": "^4.3.3",
62
62
  "@types/jsdom": "^27.0.0",
63
63
  "@vitest/browser": "^5.0.2",
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
@@ -7,7 +7,9 @@
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
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.
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.
11
13
  * - `@oxc-angular/vite`'s own plugins, for the app's components and for the linker, which handles
12
14
  * the `@ng-native/*` packages as it handles every partial-compiled Angular library on npm.
13
15
  */
@@ -34,6 +36,18 @@ const NATIVE_MODULE =
34
36
  /^(expo-|@expo\/|@react-native-async-storage\/|react-native-watch-connectivity$)/;
35
37
  const MISSING = '\0ng-native:missing:';
36
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
+
37
51
  /**
38
52
  * Resolves `react-native` and `expo` to an empty module, and a `require` of an Expo module to one
39
53
  * that throws, in the build and in the dependency pre-bundle alike.
@@ -48,7 +62,11 @@ const MISSING = '\0ng-native:missing:';
48
62
  function nativeOnly() {
49
63
  return {
50
64
  name: 'ng-native:native-only',
51
- resolveId: (id, _importer, options) => {
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 });
52
70
  if (NATIVE_ONLY.test(id)) return EMPTY;
53
71
  if (options?.kind === 'require-call' && NATIVE_MODULE.test(id)) return MISSING + id;
54
72
  return null;
@@ -80,3 +98,21 @@ function config() {
80
98
  export function ngNativeWeb(options = {}) {
81
99
  return [config(), ...angular({ zoneless: true, emitClassMetadata: false, ...options })];
82
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
+ }