@oxy.so/bloom-language-codemod 0.1.0 → 0.2.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/CHANGELOG.md +18 -0
- package/lib/components.d.ts +27 -2
- package/lib/components.js +63 -8
- package/lib/corpus.js +24 -17
- package/lib/resolve.js +43 -8
- package/lib/style.d.ts +49 -5
- package/lib/style.js +314 -12
- package/lib/table.d.ts +13 -1
- package/lib/table.js +8 -1
- package/lib/transform.d.ts +2 -0
- package/lib/transform.js +1868 -97
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- A `VirtualList`'s `stickyHeaderIndices` is `.stickyIndices()`. A row arrow that returns `toElement(chain)` is that chain, so the language draws each row with no boundary of its own.
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Compatibility
|
|
12
|
+
|
|
13
|
+
- Its peer is `@oxy.so/bloom-language` 1.1.0 or newer, the language it writes.
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- Converts more of an app: `TouchableOpacity` as `.pressFade()`, the accessibility state, value and live region, auto margins, a gap per axis and border lines, a style's radius, stacking level and aspect ratio by value, inset as its edges, a hit slop per side, a ref and a layout handler.
|
|
18
|
+
- Bloom components: a `Button`'s runtime look, glyph size, press, spinner, open state, inks and static style; a `Card`'s and a `Tabs`' style; a `Chip`'s variant, accent colour and views beside its label; a `Field` of several controls; a `DropdownMenu` tree as `Menu(trigger, ...rows).menuStyle('dropdown')`; `Fab` as `FAB(...).glass(identity)`; `PageFooter`; a `Dialog`'s `onDismissed`; a `VirtualList`'s content style, refreshing and `onRefresh`, and a `RefreshControl`, as one refresh.
|
|
19
|
+
- `screen()` wraps a component whose every return is a `Screen`; a padding by `useSafeAreaInsets()` as `.safeAreaPadding()`; `useColorTokens()` reads, style constants, flex triples, a `Pressable`'s pressed style as `.when('pressed')`, `StyleSheet.absoluteFill`, a text's `fontSize`, `lineHeight` and `fontWeight`, geometry computed at render as points, and React Native's edge precedence.
|
|
20
|
+
|
|
3
21
|
## 0.1.0
|
|
4
22
|
|
|
5
23
|
First release. Moves an app's NativeWind `className` JSX and Bloom JSX to the Bloom language only where the rendered result stays the same, keeps everything else as JSX with its reason, and writes a report. See `docs/bloom-language-codemod.mdx` in the Bloom repository.
|
package/lib/components.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { type Arg } from './table';
|
|
|
12
12
|
* - `icon`: a Bloom icon component, by name;
|
|
13
13
|
* - `literal`: a boolean literal (bare is `true`), through the rule's map (`'true'`, `'false'`);
|
|
14
14
|
* - `refresh`: React Native's `RefreshControl` element, as a pull to refresh's
|
|
15
|
-
*
|
|
15
|
+
* value, action and tint (`.refreshable({ refreshing, onRefresh }, tint)`);
|
|
16
16
|
* - `contentStyle`: a static content container style of paddings and a gap, as
|
|
17
17
|
* `.contentMargins(edge, token)` and `.spacing(token)`;
|
|
18
18
|
* - `items`: an array of data (any expression but an element or a string), carried as it is;
|
|
@@ -23,14 +23,27 @@ import { type Arg } from './table';
|
|
|
23
23
|
* parameter as written; an element its view, any other expression embedded), or a named function, carried
|
|
24
24
|
* as it is (`VirtualList(posts, renderPost)`), its identity kept;
|
|
25
25
|
* - `empty`: an empty object literal (`screen={{}}`), as the bare modifier;
|
|
26
|
+
* - `style`: a static style (an object literal, a module StyleSheet's style, or
|
|
27
|
+
* a list of them) as the node's box, each declaration through the className
|
|
28
|
+
* table as a View's, for a component that draws `style` on its outer view
|
|
29
|
+
* (the modifier name is unused);
|
|
26
30
|
* - `className`: a static className laid out in a view of its own, as the
|
|
27
31
|
* modifiers of that view's build function (`.contentView((v) => v.padding('lg'))`),
|
|
28
32
|
* each class through the className table;
|
|
33
|
+
* - `textStyle`: a part's label style of a `fontSize`, `lineHeight` and
|
|
34
|
+
* `fontWeight` (a weight chosen by a plain condition included), as `.font()`,
|
|
35
|
+
* `.leading()` and `.weight()` (the modifier name is unused);
|
|
36
|
+
* - `content`: a text (as `string`), or an element as a view (as `view`): a
|
|
37
|
+
* header's title or subtitle;
|
|
29
38
|
* - `placement`: Bloom's responsive placement, a static token
|
|
30
39
|
* (`placement="bottom"`) or an object of them (`{ base: 'bottom', md: 'center' }`),
|
|
31
40
|
* as `.presentAt(base, tiers)`.
|
|
32
41
|
*/
|
|
33
|
-
export type Form = 'string' | 'token' | 'flag' | 'boolean' | 'mark' | 'number' | 'handler' | 'view' | 'icon' | 'literal' | 'refresh' | 'contentStyle' | 'items' | 'element' | 'row' | 'placement' | 'empty' | 'className'
|
|
42
|
+
export type Form = 'string' | 'token' | 'flag' | 'boolean' | 'mark' | 'number' | 'handler' | 'view' | 'icon' | 'literal' | 'refresh' | 'contentStyle' | 'items' | 'element' | 'row' | 'placement' | 'empty' | 'className' | 'style' | 'textStyle' | 'content'
|
|
43
|
+
/** A style that is its fill alone (`{ backgroundColor }`): a role or an app colour. */
|
|
44
|
+
| 'fill'
|
|
45
|
+
/** Bloom Screen's `reselect` handler: `.onReselect(refresh)` and `.reselectTop(isAtTop, scrollToTop)`. */
|
|
46
|
+
| 'reselect';
|
|
34
47
|
/** A prop as a modifier: its name and form, and for a token, Bloom's value to the language's. */
|
|
35
48
|
export interface PropRule {
|
|
36
49
|
readonly modifier: string;
|
|
@@ -46,6 +59,11 @@ export interface PropRule {
|
|
|
46
59
|
* to `.onEndReached(action, threshold)`); given without this prop, it is a reason.
|
|
47
60
|
*/
|
|
48
61
|
readonly with?: readonly [prop: string, form: Form];
|
|
62
|
+
/**
|
|
63
|
+
* A token whose modifier takes `undefined` as no value of its own (a Chip's
|
|
64
|
+
* `.tint()`): a token or none chosen by a plain condition is that choice.
|
|
65
|
+
*/
|
|
66
|
+
readonly unset?: boolean;
|
|
49
67
|
/** Fixed arguments after the value (`showsVerticalScrollIndicator` to `.scrollIndicators(value, 'vertical')`). */
|
|
50
68
|
readonly args?: readonly Arg[];
|
|
51
69
|
/**
|
|
@@ -95,9 +113,16 @@ export type Param = {
|
|
|
95
113
|
} | {
|
|
96
114
|
readonly options: Readonly<Record<string, Form | readonly [key: string, form: Form]>>;
|
|
97
115
|
} | {
|
|
116
|
+
/**
|
|
117
|
+
* Its label from its text, with a glyph before or after it (an icon prop),
|
|
118
|
+
* or a view there (an element prop, each of the names given: Bloom reads
|
|
119
|
+
* either into the same slot).
|
|
120
|
+
*/
|
|
98
121
|
readonly label: {
|
|
99
122
|
readonly leading?: string;
|
|
100
123
|
readonly trailing?: string;
|
|
124
|
+
readonly leadingViews?: readonly string[];
|
|
125
|
+
readonly trailingViews?: readonly string[];
|
|
101
126
|
};
|
|
102
127
|
};
|
|
103
128
|
export interface ComponentRule {
|
package/lib/components.js
CHANGED
|
@@ -83,6 +83,18 @@ const TEXT_INPUT = {
|
|
|
83
83
|
autoFocus: p('autoFocus', 'mark'),
|
|
84
84
|
maxLength: p('maxLength', 'number'),
|
|
85
85
|
};
|
|
86
|
+
/** Bloom's accent tones as the Bloom tones they paint in (`appearance/colors.ts`, `PALETTE` read backwards). */
|
|
87
|
+
const ACCENT_TONE = {
|
|
88
|
+
default: 'neutral',
|
|
89
|
+
primary: 'accent',
|
|
90
|
+
vivid: 'vivid',
|
|
91
|
+
secondary: 'support',
|
|
92
|
+
tertiary: 'action',
|
|
93
|
+
success: 'success',
|
|
94
|
+
warning: 'warning',
|
|
95
|
+
error: 'danger',
|
|
96
|
+
info: 'info',
|
|
97
|
+
};
|
|
86
98
|
/** The props a node takes from its press and name (`d.props()`). */
|
|
87
99
|
const NAMED = {
|
|
88
100
|
accessibilityLabel: p('label', 'string'),
|
|
@@ -112,6 +124,7 @@ exports.COMPONENT_RULES = {
|
|
|
112
124
|
children: true,
|
|
113
125
|
props: {
|
|
114
126
|
open: { ...p('presented', 'boolean'), closedBy: 'onClose' },
|
|
127
|
+
onDismissed: p('onDismissed', 'handler'),
|
|
115
128
|
title: p('title', 'string'),
|
|
116
129
|
description: p('message', 'string'),
|
|
117
130
|
label: p('label', 'string'),
|
|
@@ -189,6 +202,17 @@ exports.COMPONENT_RULES = {
|
|
|
189
202
|
testID: p('testID', 'string'),
|
|
190
203
|
},
|
|
191
204
|
},
|
|
205
|
+
// parity/navigation.cases.tsx: the page's footer, its actions its toolbar.
|
|
206
|
+
'@oxy.so/bloom/page-footer#PageFooter': {
|
|
207
|
+
node: 'PageFooter',
|
|
208
|
+
children: true,
|
|
209
|
+
props: {
|
|
210
|
+
actions: p('toolbar', 'view'),
|
|
211
|
+
position: p('pinning', 'token', tokens('footerPinning')),
|
|
212
|
+
scrim: p('scrollEdge', 'token', tokens('scrollEdge')),
|
|
213
|
+
testID: p('testID', 'string'),
|
|
214
|
+
},
|
|
215
|
+
},
|
|
192
216
|
// parity/settings.cases.tsx.
|
|
193
217
|
'@oxy.so/bloom/settings-modal#SettingsSection': {
|
|
194
218
|
node: 'SettingsSection',
|
|
@@ -224,6 +248,8 @@ exports.COMPONENT_RULES = {
|
|
|
224
248
|
invalid: p('invalid', 'flag'),
|
|
225
249
|
disabled: p('disabled', 'flag'),
|
|
226
250
|
floatingLabel: p('floatingLabel', 'mark'),
|
|
251
|
+
multiline: p('multiline', 'flag'),
|
|
252
|
+
editable: p('editable', 'boolean'),
|
|
227
253
|
...TEXT_INPUT,
|
|
228
254
|
accessibilityHint: p('hint', 'string'),
|
|
229
255
|
testID: p('testID', 'string'),
|
|
@@ -256,6 +282,7 @@ exports.COMPONENT_RULES = {
|
|
|
256
282
|
clipContent: p('clipped', 'mark'),
|
|
257
283
|
disabled: p('disabled', 'flag'),
|
|
258
284
|
onPress: p('onPress', 'handler'),
|
|
285
|
+
style: p('box', 'style'),
|
|
259
286
|
...NAMED,
|
|
260
287
|
},
|
|
261
288
|
},
|
|
@@ -306,6 +333,9 @@ exports.COMPONENT_RULES = {
|
|
|
306
333
|
error: p('error', 'string'),
|
|
307
334
|
required: p('required', 'flag'),
|
|
308
335
|
disabled: p('disabled', 'flag'),
|
|
336
|
+
multiple: p('multiple', 'flag'),
|
|
337
|
+
// Bloom's Field draws its `style` on its outer view, the node's box (`{ flex: 1 }` is `.grow()`).
|
|
338
|
+
style: p('box', 'style'),
|
|
309
339
|
testID: p('testID', 'string'),
|
|
310
340
|
},
|
|
311
341
|
},
|
|
@@ -464,12 +494,25 @@ exports.COMPONENT_RULES = {
|
|
|
464
494
|
// parity/containers.cases.tsx, Chip: an `Icon` before its `Text` leads it, one after trails it.
|
|
465
495
|
'@oxy.so/bloom/chip#Chip': {
|
|
466
496
|
node: 'Chip',
|
|
467
|
-
|
|
497
|
+
// Bloom draws `leading` (or `startIcon`) and `trailing` (or `endIcon`) in the glyph's slot.
|
|
498
|
+
params: [
|
|
499
|
+
{
|
|
500
|
+
label: {
|
|
501
|
+
leading: 'leadingIcon',
|
|
502
|
+
trailing: 'trailingIcon',
|
|
503
|
+
leadingViews: ['leading', 'startIcon'],
|
|
504
|
+
trailingViews: ['trailing', 'endIcon'],
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
],
|
|
468
508
|
props: {
|
|
469
|
-
// `inverted` is Bloom's chip variant; the appearances are its `appearance
|
|
470
|
-
variant
|
|
509
|
+
// `inverted` is Bloom's chip variant; the appearances are its `appearance`, which
|
|
510
|
+
// Bloom reads over a variant of the same name (`solid`, `subtle`).
|
|
511
|
+
variant: p('style', 'token', { inverted: 'inverted', solid: 'solid', subtle: 'subtle' }),
|
|
471
512
|
appearance: p('style', 'token', tokens('appearance')),
|
|
472
|
-
tone: p('tint', 'token', tokens('tone')),
|
|
513
|
+
tone: { ...p('tint', 'token', tokens('tone')), unset: true },
|
|
514
|
+
// An accent tone is the Bloom tone Bloom's Chip paints it in (`bloomToneOf`).
|
|
515
|
+
color: { ...p('tint', 'token', ACCENT_TONE), unset: true },
|
|
473
516
|
size: p('size', 'token', tokens('chipSize')),
|
|
474
517
|
hue: p('hue', 'token', tokens('chipHue')),
|
|
475
518
|
selected: p('selected', 'flag'),
|
|
@@ -491,10 +534,10 @@ exports.COMPONENT_RULES = {
|
|
|
491
534
|
// parity/screen.cases.tsx and header cases: Bloom's PageHeader, in the page on every platform.
|
|
492
535
|
'@oxy.so/bloom/page-header#PageHeader': {
|
|
493
536
|
node: 'Header',
|
|
494
|
-
params: [{ prop: 'title', form: '
|
|
537
|
+
params: [{ prop: 'title', form: 'content', optional: true }],
|
|
495
538
|
always: ['inPage'],
|
|
496
539
|
props: {
|
|
497
|
-
subtitle: p('subtitle', '
|
|
540
|
+
subtitle: p('subtitle', 'content'),
|
|
498
541
|
actions: p('toolbar', 'view'),
|
|
499
542
|
leading: p('toolbarLeading', 'view'),
|
|
500
543
|
onBack: p('onBack', 'handler'),
|
|
@@ -544,8 +587,10 @@ exports.COMPONENT_RULES = {
|
|
|
544
587
|
variant: p('style', 'token', tokens('tabsStyle')),
|
|
545
588
|
fullWidth: p('fullWidth', 'flag'),
|
|
546
589
|
onReorder: p('onReorder', 'handler'),
|
|
590
|
+
pressOpenTab: p('pressOpenTab', 'token', tokens('pressOpenTab')),
|
|
547
591
|
label: p('label', 'string'),
|
|
548
592
|
testID: p('testID', 'string'),
|
|
593
|
+
style: p('box', 'style'),
|
|
549
594
|
},
|
|
550
595
|
},
|
|
551
596
|
'@oxy.so/bloom/tabs#TabsTrigger': {
|
|
@@ -564,6 +609,8 @@ exports.COMPONENT_RULES = {
|
|
|
564
609
|
trailing: p('trailing', 'view'),
|
|
565
610
|
onLongPress: p('onLongPress', 'handler'),
|
|
566
611
|
testID: p('testID', 'string'),
|
|
612
|
+
style: p('box', 'style'),
|
|
613
|
+
textStyle: p('label', 'textStyle'),
|
|
567
614
|
},
|
|
568
615
|
},
|
|
569
616
|
// parity/inputs.cases.tsx, Segmented (SegmentedControl): its items are its options.
|
|
@@ -641,12 +688,17 @@ exports.COMPONENT_RULES = {
|
|
|
641
688
|
keyExtractor: p('itemKey', 'handler'),
|
|
642
689
|
getItemType: p('itemType', 'handler'),
|
|
643
690
|
estimatedItemSize: p('estimatedItemSize', 'number'),
|
|
691
|
+
contentContainerStyle: p('contentMargins', 'contentStyle'),
|
|
644
692
|
numColumns: p('columns', 'number'),
|
|
645
693
|
onEndReached: { ...p('onEndReached', 'handler'), with: ['onEndReachedThreshold', 'number'] },
|
|
646
694
|
restorationKey: p('restorationKey', 'string'),
|
|
695
|
+
stickyHeaderIndices: p('stickyIndices', 'items'),
|
|
647
696
|
ListHeaderComponent: p('headerContent', 'element'),
|
|
648
697
|
ListFooterComponent: p('footerContent', 'element'),
|
|
649
698
|
ListEmptyComponent: p('emptyState', 'element'),
|
|
699
|
+
// A query-driven pull to refresh: `.refreshable({ refreshing, onRefresh })`, as written.
|
|
700
|
+
refreshing: { ...p('refreshable', 'boolean'), key: 'refreshing' },
|
|
701
|
+
onRefresh: { ...p('refreshable', 'handler'), key: 'onRefresh' },
|
|
650
702
|
screen: { ...p('screen', 'empty'), within: '@oxy.so/bloom/screen#Screen' },
|
|
651
703
|
scrollbar: p('scrollbar', 'token', tokens('scrollbarVisibility')),
|
|
652
704
|
keyboardShouldPersistTaps: p('keyboardTaps', 'token', tokens('keyboardTaps')),
|
|
@@ -723,8 +775,9 @@ exports.REMOVED = {
|
|
|
723
775
|
* draws them, but not as a node a region can hold in their place.
|
|
724
776
|
*/
|
|
725
777
|
exports.KEPT = {
|
|
726
|
-
'@oxy.so/bloom/
|
|
727
|
-
'@oxy.so/bloom/
|
|
778
|
+
'@oxy.so/bloom/fab#Fab': 'a Bloom Fab is the language’s `FAB(Icon(icon), Text(label)).glass(identity)`, its solid fill: it converts with its icon and label props (`convertFab`)',
|
|
779
|
+
'@oxy.so/bloom/dropdown-menu#DropdownMenu': "a Bloom DropdownMenu is the language’s `Menu(trigger, ...rows).menuStyle('dropdown')`: it converts with its trigger and its rows (`convertDropdownMenu`)",
|
|
780
|
+
'@oxy.so/bloom/screen#Screen': 'a Bloom Screen is what a `screen()` body returns in the language, its chrome the modifiers of what each branch returns: a component whose every return is a Screen converts whole (`SCREEN`)',
|
|
728
781
|
'@oxy.so/bloom/app-shell#AppShell': 'a Bloom AppShell is a layout route’s `AppLayout(navigator)` in the language (`.shellLayout()`, `.panels(Panel(…))`); no node a region holds draws one',
|
|
729
782
|
'@oxy.so/bloom/app-shell#AppShellPanels': 'Bloom’s AppShellPanels are an `AppLayout`’s `.panels(Panel(…))` in the language, not a node a region holds',
|
|
730
783
|
'@oxy.so/bloom/app-shell#AppShellPanel': 'a Bloom AppShellPanel is a `Panel(id, content)` of an `AppLayout`’s `.panels()` in the language, not a node a region holds',
|
|
@@ -759,6 +812,8 @@ exports.SCREEN = {
|
|
|
759
812
|
contentClearance: p('contentClearance', 'token', exports.SPACE),
|
|
760
813
|
navigationScope: p('navigationScope', 'token', tokens('navigationScope')),
|
|
761
814
|
colorPreset: p('colorPreset', 'token', tokens('colorPreset')),
|
|
815
|
+
style: p('screenBackground', 'fill'),
|
|
816
|
+
reselect: p('onReselect', 'reselect'),
|
|
762
817
|
testID: p('testID', 'string'),
|
|
763
818
|
},
|
|
764
819
|
};
|
package/lib/corpus.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.corpusModule = corpusModule;
|
|
|
7
7
|
* The parity corpus as a module: each fixture's two sides as functions. The
|
|
8
8
|
* before side is the app as it draws today: React Native's components as
|
|
9
9
|
* NativeWind's own (react-native-css, as the app's Babel preset rewrites React
|
|
10
|
-
* Native's imports
|
|
11
|
-
*
|
|
10
|
+
* Native's imports, its Text among them, which names no face of its own) and
|
|
11
|
+
* Bloom's. The after side is the language over this checkout's
|
|
12
12
|
* Bloom. `parity/corpus.*.test.tsx` renders them.
|
|
13
13
|
*
|
|
14
14
|
* Bloom 23 has no `className`: a region whose before side hands a class to a
|
|
@@ -20,7 +20,6 @@ exports.corpusModule = corpusModule;
|
|
|
20
20
|
const node_path_1 = require("node:path");
|
|
21
21
|
const parser_1 = require("@babel/parser");
|
|
22
22
|
const table_1 = require("./table");
|
|
23
|
-
const APP_TEXT = (0, node_path_1.join)(__dirname, '../parity/support/app-text');
|
|
24
23
|
/** What `screen()` draws a body's root with. */
|
|
25
24
|
const SCREEN_HOST = (0, node_path_1.join)(table_1.LANGUAGE_PACKAGE, 'src/router/screen-host');
|
|
26
25
|
/**
|
|
@@ -31,8 +30,7 @@ exports.BEFORE_BLOOM = 'bloom-22';
|
|
|
31
30
|
const NATIVEWIND = {
|
|
32
31
|
View: 'react-native-css/components/View',
|
|
33
32
|
Pressable: 'react-native-css/components/Pressable',
|
|
34
|
-
|
|
35
|
-
Text: APP_TEXT,
|
|
33
|
+
Text: 'react-native-css/components/Text',
|
|
36
34
|
Image: 'react-native-css/components/Image',
|
|
37
35
|
};
|
|
38
36
|
/** A module path relative to the corpus written to `dir`. */
|
|
@@ -89,8 +87,6 @@ function handsBloomAClass(fixture) {
|
|
|
89
87
|
function origin(source, dir, side) {
|
|
90
88
|
if (source.module === 'react-native') {
|
|
91
89
|
const module = NATIVEWIND[source.imported];
|
|
92
|
-
if (module === APP_TEXT)
|
|
93
|
-
return { module: relativeTo(dir, module), name: source.imported };
|
|
94
90
|
if (module)
|
|
95
91
|
return { module, name: source.imported };
|
|
96
92
|
}
|
|
@@ -120,23 +116,29 @@ function corpusModule(fixtures, dir) {
|
|
|
120
116
|
const bindings = (side) => Object.entries(fixture.bindings)
|
|
121
117
|
.map(([local, source]) => `const ${local} = ${alias(source, side)};`)
|
|
122
118
|
.join(' ');
|
|
123
|
-
|
|
119
|
+
// A language name the file already imports (a file partly in the language) is bound once, as a binding.
|
|
120
|
+
const names = fixture.language.filter((entry) => !(entry.split(':').pop().trim() in fixture.bindings));
|
|
121
|
+
const language = names.length ? `const { ${names.join(', ')} } = L;` : '';
|
|
124
122
|
// A node drawn only inside a Bloom component (a screen's scroll view in a Screen) is, on both sides.
|
|
125
123
|
const within = (side) => fixture.within.map((key) => {
|
|
126
124
|
const [module, imported] = key.split('#');
|
|
127
125
|
return alias({ module, imported }, side);
|
|
128
126
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
// A region that pads by the device's insets is drawn under the corpus's, on both sides.
|
|
128
|
+
const open = (side) => [
|
|
129
|
+
...(fixture.insets ? ['<SafeAreaInsetsContext.Provider value={PARITY_INSETS}>{'] : []),
|
|
130
|
+
...within(side).map((local) => `<${local}>{`),
|
|
131
|
+
].join('');
|
|
132
|
+
const close = (side) => [
|
|
133
|
+
...within(side)
|
|
134
|
+
.map((local) => `}</${local}>`)
|
|
135
|
+
.reverse(),
|
|
136
|
+
...(fixture.insets ? ['}</SafeAreaInsetsContext.Provider>'] : []),
|
|
137
|
+
].join('');
|
|
136
138
|
// A before side that reads the theme is a component, so it reads it where it is drawn.
|
|
137
139
|
const theme = bloom22 ? 'useParityTheme22' : 'useParityTheme';
|
|
138
140
|
const before = fixture.themed
|
|
139
|
-
? `function Before() { const parityTheme = ${theme}(); ${bindings(beforeSide)} return (${fixture.before}); } return (${open(beforeSide)}<Before />${close(beforeSide)});`
|
|
141
|
+
? `function Before() { const parityTheme = ${theme}(); const parityTokens = useParityTokens(); const paritySurface = useParitySurface(); ${bindings(beforeSide)} return (${fixture.before}); } return (${open(beforeSide)}<Before />${close(beforeSide)});`
|
|
140
142
|
: `${bindings(beforeSide)} return (${open(beforeSide)}${fixture.before}${close(beforeSide)});`;
|
|
141
143
|
let colors = '';
|
|
142
144
|
if (fixture.appColors) {
|
|
@@ -158,8 +160,10 @@ function corpusModule(fixtures, dir) {
|
|
|
158
160
|
"import * as RN from 'react-native';",
|
|
159
161
|
"import * as L from '@oxy.so/bloom-language';",
|
|
160
162
|
"import { toElement } from '@oxy.so/bloom-language';",
|
|
161
|
-
"import { useTheme as useParityTheme } from '@oxy.so/bloom/theme';",
|
|
163
|
+
"import { useColorTokens as useParityTokens, useTheme as useParityTheme } from '@oxy.so/bloom/theme';",
|
|
162
164
|
`import { useTheme as useParityTheme22 } from '${exports.BEFORE_BLOOM}/theme';`,
|
|
165
|
+
"import { useSurfaceFill as useParitySurface } from '@oxy.so/bloom/styles';",
|
|
166
|
+
"import { SafeAreaInsetsContext } from 'react-native-safe-area-context';",
|
|
163
167
|
`import { ScreenHost } from '${relativeTo(dir, SCREEN_HOST)}';`,
|
|
164
168
|
...[...imports].map(([key, local]) => {
|
|
165
169
|
const [module, name] = key.split('#');
|
|
@@ -167,6 +171,9 @@ function corpusModule(fixtures, dir) {
|
|
|
167
171
|
}),
|
|
168
172
|
'',
|
|
169
173
|
...(tables.length ? [...tables, ''] : []),
|
|
174
|
+
'/** The insets of a phone with a notch and a home bar. */',
|
|
175
|
+
'const PARITY_INSETS = { top: 47, bottom: 34, left: 0, right: 0 };',
|
|
176
|
+
'',
|
|
170
177
|
'function Hole({ n }: { n: string }) {',
|
|
171
178
|
" return <RN.View testID={'hole-' + n} />;",
|
|
172
179
|
'}',
|
package/lib/resolve.js
CHANGED
|
@@ -26,6 +26,37 @@ spec.layers.forEach((names, index) => {
|
|
|
26
26
|
LAYER.set(name, index);
|
|
27
27
|
});
|
|
28
28
|
const TRAITS = new Set(spec.environment.traits);
|
|
29
|
+
/** A frame side's Tailwind prefix, as the frame key the language names. */
|
|
30
|
+
const FRAME_PREFIX = {
|
|
31
|
+
w: 'width',
|
|
32
|
+
h: 'height',
|
|
33
|
+
'min-w': 'minWidth',
|
|
34
|
+
'min-h': 'minHeight',
|
|
35
|
+
'max-w': 'maxWidth',
|
|
36
|
+
'max-h': 'maxHeight',
|
|
37
|
+
};
|
|
38
|
+
/** The spec's space tokens by points, a named rung over a numeric token of the same value. */
|
|
39
|
+
const SPACE_BY_POINTS = new Map();
|
|
40
|
+
for (const [name, points] of Object.entries(spec.scales.space ?? {}))
|
|
41
|
+
if (typeof points === 'number' && (!/^\d/.test(name) || !SPACE_BY_POINTS.has(points)))
|
|
42
|
+
SPACE_BY_POINTS.set(points, name);
|
|
43
|
+
/**
|
|
44
|
+
* A frame length of Tailwind's spacing scale that no app writes as a class
|
|
45
|
+
* (so the table has no row for it) but a style writes (`height: 38` is
|
|
46
|
+
* `h-9.5`), whose points are a space token: the frame the table writes for
|
|
47
|
+
* the steps it holds (`h-11` is `.frame({ height: '44' })`).
|
|
48
|
+
*/
|
|
49
|
+
function frameStep(utility) {
|
|
50
|
+
const match = /^(min-w|min-h|max-w|max-h|w|h)-(\d+(?:\.\d+)?)$/.exec(utility);
|
|
51
|
+
const token = match ? SPACE_BY_POINTS.get(Number(match[2]) * 4) : undefined;
|
|
52
|
+
if (!match || token === undefined)
|
|
53
|
+
return undefined;
|
|
54
|
+
const frame = { [FRAME_PREFIX[match[1]]]: token };
|
|
55
|
+
const mods = [{ name: 'frame', args: [frame] }];
|
|
56
|
+
return { status: 'mapped', language: `.frame({ ${Object.keys(frame)[0]}: '${token}' })`, mods };
|
|
57
|
+
}
|
|
58
|
+
/** The faces `.font()` takes beside a size (`mono`, `display`). */
|
|
59
|
+
const FONT_FAMILY = new Set(spec.enums.fontFamily);
|
|
29
60
|
/** The modifiers a `when()` variant can change; any other is left out of it. */
|
|
30
61
|
const VARIES = new Set(spec.variants.modifiers);
|
|
31
62
|
/** Conditions that hold, or not, as the view renders: a platform. */
|
|
@@ -223,7 +254,7 @@ function resolveClassName(className, kind, table, options = {}) {
|
|
|
223
254
|
fail(token, 'physical-edge', 'a physical side: the language’s edges follow the reading direction');
|
|
224
255
|
continue;
|
|
225
256
|
}
|
|
226
|
-
const entry = table.utilities.get(utility);
|
|
257
|
+
const entry = table.utilities.get(utility) ?? frameStep(utility);
|
|
227
258
|
if (!entry) {
|
|
228
259
|
fail(token, 'unknown', 'not in the className table');
|
|
229
260
|
continue;
|
|
@@ -314,8 +345,9 @@ function resolveClassName(className, kind, table, options = {}) {
|
|
|
314
345
|
const subject = unconditional?.subjects.get(mod) ?? '';
|
|
315
346
|
if (!inline.has(subject))
|
|
316
347
|
continue;
|
|
317
|
-
|
|
318
|
-
|
|
348
|
+
// A variant the style writes itself (a Pressable's pressed style) is inline too, and wins as the JSX's does.
|
|
349
|
+
for (const [key, g] of groups)
|
|
350
|
+
if (key && g.mods.some((m) => m.name === mod.name && !inline.has(g.subjects.get(m) ?? '')))
|
|
319
351
|
fail(subject, 'style-variant', `a style a variant of the className sets too (.${mod.name}()): inline, the style wins`);
|
|
320
352
|
}
|
|
321
353
|
if (reasons.length > 0)
|
|
@@ -400,15 +432,17 @@ function finish(g, kind, fail) {
|
|
|
400
432
|
if (prior)
|
|
401
433
|
fail(`${subject(prior)} ${subject(mod)}`, 'corner-overlap', 'two corners of one corner');
|
|
402
434
|
});
|
|
403
|
-
// Any other modifier twice is decided by Tailwind's rule order.
|
|
435
|
+
// Any other modifier twice is decided by Tailwind's rule order. (A safe-area padding is one per side, from its style key;
|
|
436
|
+
// a face, `.font('mono')`, and a size, `.font('96')`, are two things a text keeps both of.)
|
|
404
437
|
const seen = new Map();
|
|
405
438
|
for (const mod of mods) {
|
|
406
|
-
if (['padding', 'margin', 'border', 'corner', 'when'].includes(mod.name))
|
|
439
|
+
if (['padding', 'margin', 'border', 'corner', 'when', 'safeAreaPadding'].includes(mod.name))
|
|
407
440
|
continue;
|
|
408
|
-
const
|
|
441
|
+
const key = mod.name === 'font' && FONT_FAMILY.has(mod.args[0]) ? 'font family' : mod.name;
|
|
442
|
+
const prior = seen.get(key);
|
|
409
443
|
if (prior)
|
|
410
444
|
fail(`${subject(prior)} ${subject(mod)}`, 'conflict', `two classes set .${mod.name}()`);
|
|
411
|
-
seen.set(
|
|
445
|
+
seen.set(key, mod);
|
|
412
446
|
}
|
|
413
447
|
const measuredFrom = kind === 'text' ? unsized(mods) : undefined;
|
|
414
448
|
if (measuredFrom)
|
|
@@ -429,10 +463,11 @@ function finish(g, kind, fail) {
|
|
|
429
463
|
return [...layered, ...rest];
|
|
430
464
|
}
|
|
431
465
|
function mergeObjects(list, name, subject, fail) {
|
|
466
|
+
// A key's token, or points computed at render (`{ width: itemSize }`).
|
|
432
467
|
const out = {};
|
|
433
468
|
for (const mod of list) {
|
|
434
469
|
const value = mod.args[0];
|
|
435
|
-
if (typeof value !== 'object' || mod.args.length !== 1) {
|
|
470
|
+
if (typeof value !== 'object' || (0, table_1.isPoints)(value) || mod.args.length !== 1) {
|
|
436
471
|
fail(subject(mod), name, `an unexpected .${name}() form`);
|
|
437
472
|
return null;
|
|
438
473
|
}
|
package/lib/style.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Mod } from './table';
|
|
2
|
+
/**
|
|
3
|
+
* A text's own `fontSize` and `lineHeight` written out, as the language's
|
|
4
|
+
* size and line: `fontSize: 15` is `.font('md')` (a named rung over a numeric
|
|
5
|
+
* token of the same points, `fontSize: 14` `.font('14')`), `lineHeight: 20`
|
|
6
|
+
* `.leading('20px')`. A size or a line no token holds stays a reason.
|
|
7
|
+
*/
|
|
8
|
+
export declare function textDeclaration(key: string, value: AnyNode): Mod | undefined;
|
|
2
9
|
type AnyNode = any;
|
|
3
|
-
/** A declaration the caller reads as
|
|
4
|
-
export type StyleRead = (key: string, value: AnyNode) => Mod | undefined;
|
|
10
|
+
/** A declaration the caller reads as modifiers (a theme colour as its role, an inset's padding), or undefined. */
|
|
11
|
+
export type StyleRead = (key: string, value: AnyNode) => Mod | readonly Mod[] | undefined;
|
|
5
12
|
export type StyleResult = {
|
|
6
13
|
readonly ok: true;
|
|
7
14
|
readonly classes: readonly string[];
|
|
@@ -11,14 +18,51 @@ export type StyleResult = {
|
|
|
11
18
|
readonly mod: Mod;
|
|
12
19
|
}[];
|
|
13
20
|
readonly literal: string;
|
|
21
|
+
/**
|
|
22
|
+
* Points the chain draws without carrying them (a half-square radius's
|
|
23
|
+
* side, drawn as `'full'`): the parity's before side writes their hole.
|
|
24
|
+
*/
|
|
25
|
+
readonly held: readonly AnyNode[];
|
|
14
26
|
} | {
|
|
15
27
|
readonly ok: false;
|
|
16
28
|
readonly subject: string;
|
|
17
29
|
readonly why: string;
|
|
18
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* React Native's `StyleSheet.absoluteFill`: pinned to every edge of its parent
|
|
33
|
+
* (`absolute inset-0`), and the declarations it holds, written out for the
|
|
34
|
+
* parity's before side.
|
|
35
|
+
*/
|
|
36
|
+
export declare const ABSOLUTE_FILL: {
|
|
37
|
+
readonly classes: readonly ["absolute", "top-0", "right-0", "bottom-0", "left-0"];
|
|
38
|
+
readonly literal: "position: 'absolute', left: 0, right: 0, top: 0, bottom: 0";
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A spread in a style the caller reads: the utilities and modifiers it writes,
|
|
42
|
+
* and what it is on the before side (`StyleSheet.absoluteFill` is its
|
|
43
|
+
* declarations written out; a Bloom call such as `fontFamilyStyle('display')`
|
|
44
|
+
* stays as written, its function bound there).
|
|
45
|
+
*/
|
|
46
|
+
export interface SpreadStyle {
|
|
47
|
+
readonly classes: readonly string[];
|
|
48
|
+
readonly mods: readonly Mod[];
|
|
49
|
+
/** The spread's declarations, written out on the before side; unset: the spread as written. */
|
|
50
|
+
readonly literal?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface StyleReaders {
|
|
53
|
+
/** Declarations the caller reads as modifiers (a theme colour as its role). */
|
|
54
|
+
readonly read?: StyleRead;
|
|
55
|
+
/** A spread the caller reads (`StyleSheet.absoluteFill`, `fontFamilyStyle('mono')`). */
|
|
56
|
+
readonly spreadOf?: (node: AnyNode) => SpreadStyle | undefined;
|
|
57
|
+
/** A value that is a number the codemod knows (Bloom's `tokens.space.sm`), or undefined. */
|
|
58
|
+
readonly numberOf?: (node: AnyNode) => number | undefined;
|
|
59
|
+
/** Whether a value is a number the view computes as it renders (geometry's points). */
|
|
60
|
+
readonly computed?: (node: AnyNode) => boolean;
|
|
61
|
+
}
|
|
19
62
|
/**
|
|
20
63
|
* An object literal of a style as utilities, and the literal itself (for the
|
|
21
|
-
* parity's before side, where `styles.x` is not in scope).
|
|
64
|
+
* parity's before side, where `styles.x` is not in scope). A spread `spreadOf`
|
|
65
|
+
* reads is what it writes; any other is a style built at runtime.
|
|
22
66
|
*/
|
|
23
|
-
export declare function styleUtilities(object: AnyNode, read?:
|
|
67
|
+
export declare function styleUtilities(object: AnyNode, { read, spreadOf, numberOf, computed }?: StyleReaders): StyleResult;
|
|
24
68
|
export {};
|