@oxy.so/bloom-language-codemod 0.3.0 → 0.5.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/CHANGELOG.md +38 -0
- package/lib/components.d.ts +11 -2
- package/lib/components.js +48 -6
- package/lib/resolve.d.ts +2 -5
- package/lib/resolve.js +51 -13
- package/lib/style.d.ts +5 -6
- package/lib/style.js +195 -3
- package/lib/table.d.ts +12 -1
- package/lib/transform.js +483 -21
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Compatibility
|
|
6
|
+
|
|
7
|
+
- Its peer is `@oxy.so/bloom-language` 1.7.0 or newer, the language it writes (an offset in points, the frame length `'auto'`, the stacking level `'1000'` and a border width with no colour).
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Maps a transform of translations alone as `.offset()` (a number written out as its space token, one computed at render as points), an `aspectRatio` computed at render, `width: 'auto'` and `w-auto`/`h-auto`/`size-auto` as the frame length `'auto'` (no longer dropped: on a Bloom component it takes back the component's own length), and `zIndex: 1000`/`z-[1000]` as `.zIndex('1000')`.
|
|
12
|
+
- Maps `absolute` with no inset (a class or `position: 'absolute'` in a style) to `.position({})`, a view taken out of the flow where it sits, where it gave up (`absolute-without-edges`); an edge computed at render stays the position on its own.
|
|
13
|
+
- Maps a border width with no colour, a style's `borderWidth` (or an edge's, `borderBottomWidth`…) beside no border colour and a `border` / `border-b-2` class beside no colour class, to `.border(undefined, width, edge?)`: the line in the platform's default colour, where it was left JSX. A sample-app pill and rule join the corpus.
|
|
14
|
+
- Maps a `pointerEvents` in a style where it draws. A StyleSheet's style is compiled by react-native-web into the prop's classes, so it is `.allowsHitTesting()` on every platform (`none` `false`, `box-none` `'children'`, `box-only` `'self'`, `auto` `true`); in an inline object or a module style constant react-native-web writes `box-none` and `box-only` as CSS the browser drops, so it is `.when('native', (v) => v.allowsHitTesting('children'))` (or `'self'`), as Mention's attachment move row draws. An inline `none` or `auto` stays JSX with its own reason (the browser keeps it, and what is inside inherits it instead of taking the prop's rule). A style modifier can hold on one platform, a variant as a `native:` class's.
|
|
15
|
+
- Maps a Text's (and a span's) `onPress` and `onLongPress` to `.onPress()` and `.onLongPress()`.
|
|
16
|
+
- An element inside a Text that the codemod does not convert (a router's `Link`, an app's component) is an element run, `Embed(element)`, so the Text converts around it; an embedded `asChild` element around one text it converts is `Embed((render) => <Link … asChild>{render(Text(…))}</Link>)`.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- The child of an `asChild` element is no longer made a `toElement` root outside a language view: the element hands its child its own props (expo-router's `Link asChild`: the href and the press), which a root took in place of its host and dropped. It stays JSX, with the reason `as-child`.
|
|
21
|
+
|
|
22
|
+
## 0.4.0
|
|
23
|
+
|
|
24
|
+
### Compatibility
|
|
25
|
+
|
|
26
|
+
- Its peer is `@oxy.so/bloom-language` 1.6.0 or newer, the language it writes.
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Maps the React Native props the language 1.6.0 takes: `accessible`, `tabIndex` 0 / -1, `collapsable`, a static `delayLongPress` with an `onLongPress`, a text shadow written out, `insetInline` / `insetBlock`, `sticky` with `top-0` / `bottom-0` (bare or `web:`), a `TextFieldInput`'s `textContentType`, a field's `inputMode` and `inputRef`, Search's `ref` and `onSelectionChange`, Item's `role="option"` and a view's `role`, and `{...hoverGroupProps}` as `.hoverGroup()`.
|
|
31
|
+
- Maps Bloom component props: Dialog's `control`, `detached` and a `panelStyle` of static frame lengths; an Avatar style that is its radius alone; AvatarGroup's `ringColor`, `variant` and a one-parameter `renderItemAction`; Avatar's and AvatarGroup's `motion`; Search's `editable`; `stickyHeaderIndices`; `Loading`'s `color` and `PageHeader`'s `scrimColor`.
|
|
32
|
+
- A handler or none chosen by a plain condition is mapped as written where the modifier takes `undefined`: `onEndReached`, a list's `onRefresh`, an `Item`'s `onPress`, and PageHeader's `onBack` between a handler, `undefined` and `null`.
|
|
33
|
+
- A padding computed at render is points; an inset read from `useContentSafeAreaInsets()` is `.safeAreaPadding(side, 'content')`; `flexShrink: 20` is `.shrink('20')`; the className table maps `cursor-*`, `shrink-[n]`, `bg-primary/5`, `bg-foreground/5` and `bg-white/5`.
|
|
34
|
+
- A glyph-alone render function (`(color) => <X fill={color} />`, or with a busy spinner as its other branch) is `Group(Icon(X))`; an icon's `style` of margins, and `fill="currentColor"` with its `color` as `.foreground(c)`.
|
|
35
|
+
- A style a component's caller hands in (`style={[styles.row, style]}`, `props.containerStyle`) is the reason `caller-style`, with the documented form.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- A `Pressable` whose children are a render function of its press state stays JSX (`render-children`): it wrote `Embed(({ pressed }) => …)`, but `Embed`'s function is handed the child, not the press state.
|
|
40
|
+
|
|
3
41
|
## 0.3.0
|
|
4
42
|
|
|
5
43
|
### Compatibility
|
package/lib/components.d.ts
CHANGED
|
@@ -42,6 +42,12 @@ import { type Arg } from './table';
|
|
|
42
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
43
|
/** A style that is its fill alone (`{ backgroundColor }`): a role or an app colour. */
|
|
44
44
|
| 'fill'
|
|
45
|
+
/** A colour value (`theme.colors.background`): a role or an app colour. */
|
|
46
|
+
| 'ink'
|
|
47
|
+
/** A style that is its corner radius alone (`{ borderRadius: 12 }`): the radius token. */
|
|
48
|
+
| 'radius'
|
|
49
|
+
/** A style of frame lengths alone (`{ maxWidth: 540 }`): an object of their space tokens. */
|
|
50
|
+
| 'frame'
|
|
45
51
|
/** Bloom Screen's `reselect` handler: `.onReselect(refresh)` and `.reselectTop(isAtTop, scrollToTop)`. */
|
|
46
52
|
| 'reselect'
|
|
47
53
|
/** A list header container style that keeps the header to its content (`{ flexGrow: 0, flexShrink: 0, alignSelf: 'stretch' }`): the bare modifier. */
|
|
@@ -62,8 +68,9 @@ export interface PropRule {
|
|
|
62
68
|
*/
|
|
63
69
|
readonly with?: readonly [prop: string, form: Form];
|
|
64
70
|
/**
|
|
65
|
-
* A token whose modifier takes `undefined` as no value of its own
|
|
66
|
-
* `.tint()`): a
|
|
71
|
+
* A token or a handler whose modifier takes `undefined` as no value of its own
|
|
72
|
+
* (a Chip's `.tint()`, a list's `.onEndReached()`): a value or none chosen by a
|
|
73
|
+
* plain condition is that choice.
|
|
67
74
|
*/
|
|
68
75
|
readonly unset?: boolean;
|
|
69
76
|
/** Fixed arguments after the value (`showsVerticalScrollIndicator` to `.scrollIndicators(value, 'vertical')`). */
|
|
@@ -84,6 +91,8 @@ export interface PropRule {
|
|
|
84
91
|
* a modifier that ends the chain (`.presented()`). Either alone is a reason.
|
|
85
92
|
*/
|
|
86
93
|
readonly closedBy?: string;
|
|
94
|
+
/** A modifier that ends the chain (`.control()`), drawn after every other. */
|
|
95
|
+
readonly last?: boolean;
|
|
87
96
|
/**
|
|
88
97
|
* Props that are the modifier's options object after its value
|
|
89
98
|
* (`bottomBarPlacement` to `.footer(view, { placement })`), each by its key
|
package/lib/components.js
CHANGED
|
@@ -82,6 +82,9 @@ const TEXT_INPUT = {
|
|
|
82
82
|
onSubmitEditing: p('onSubmit', 'handler'),
|
|
83
83
|
autoFocus: p('autoFocus', 'mark'),
|
|
84
84
|
maxLength: p('maxLength', 'number'),
|
|
85
|
+
inputMode: p('inputMode', 'token', tokens('inputMode')),
|
|
86
|
+
// React Native's own event, handed on as it is.
|
|
87
|
+
onSelectionChange: p('onSelectionChange', 'handler'),
|
|
85
88
|
};
|
|
86
89
|
/** Bloom's accent tones as the Bloom tones they paint in (`appearance/colors.ts`, `PALETTE` read backwards). */
|
|
87
90
|
const ACCENT_TONE = {
|
|
@@ -139,6 +142,10 @@ exports.COMPONENT_RULES = {
|
|
|
139
142
|
maxHeightRatio: p('maxHeightRatio', 'number'),
|
|
140
143
|
dismissOnBackdrop: p('dismissOnBackdrop', 'boolean'),
|
|
141
144
|
scrollable: p('scrollable', 'flag'),
|
|
145
|
+
detached: p('detached', 'flag'),
|
|
146
|
+
panelStyle: p('panelFrame', 'frame'),
|
|
147
|
+
// Bloom's dialog control (`useDialogControl()`): presented by it, the chain's end as `.presented()` is.
|
|
148
|
+
control: { ...p('control', 'handler'), last: true },
|
|
142
149
|
testID: p('testID', 'string'),
|
|
143
150
|
},
|
|
144
151
|
},
|
|
@@ -193,12 +200,17 @@ exports.COMPONENT_RULES = {
|
|
|
193
200
|
within: '@oxy.so/bloom/screen#Screen',
|
|
194
201
|
props: {
|
|
195
202
|
keyboardShouldPersistTaps: p('keyboardTaps', 'token', tokens('keyboardTaps')),
|
|
196
|
-
onEndReached: {
|
|
203
|
+
onEndReached: {
|
|
204
|
+
...p('onEndReached', 'handler'),
|
|
205
|
+
with: ['onEndReachedThreshold', 'number'],
|
|
206
|
+
unset: true,
|
|
207
|
+
},
|
|
197
208
|
refreshControl: p('refreshable', 'refresh'),
|
|
198
209
|
showsVerticalScrollIndicator: indicator('vertical'),
|
|
199
210
|
showsHorizontalScrollIndicator: indicator('horizontal'),
|
|
200
211
|
contentContainerStyle: p('contentMargins', 'contentStyle'),
|
|
201
212
|
contentContainerClassName: p('contentView', 'className'),
|
|
213
|
+
stickyHeaderIndices: p('stickyIndices', 'items'),
|
|
202
214
|
testID: p('testID', 'string'),
|
|
203
215
|
},
|
|
204
216
|
},
|
|
@@ -251,6 +263,8 @@ exports.COMPONENT_RULES = {
|
|
|
251
263
|
multiline: p('multiline', 'flag'),
|
|
252
264
|
editable: p('editable', 'boolean'),
|
|
253
265
|
...TEXT_INPUT,
|
|
266
|
+
inputRef: p('inputRef', 'handler'),
|
|
267
|
+
textContentType: p('textContentType', 'token', tokens('textContentType')),
|
|
254
268
|
accessibilityHint: p('hint', 'string'),
|
|
255
269
|
testID: p('testID', 'string'),
|
|
256
270
|
},
|
|
@@ -318,7 +332,10 @@ exports.COMPONENT_RULES = {
|
|
|
318
332
|
active: p('active', 'boolean'),
|
|
319
333
|
highlighted: p('highlighted', 'flag'),
|
|
320
334
|
contentDensity: p('density', 'token', densities('row')),
|
|
321
|
-
|
|
335
|
+
// A web role (Item's `role`): an option of a listbox is the language's `.role('option')`.
|
|
336
|
+
role: p('role', 'token', { option: 'option' }),
|
|
337
|
+
// A press or none chosen by a plain condition (`full ? undefined : add`): no press, no button.
|
|
338
|
+
onPress: { ...p('onPress', 'handler'), unset: true },
|
|
322
339
|
onLongPress: p('onLongPress', 'handler'),
|
|
323
340
|
...NAMED,
|
|
324
341
|
},
|
|
@@ -360,6 +377,8 @@ exports.COMPONENT_RULES = {
|
|
|
360
377
|
resize: p('resize', 'token', tokens('textareaResize')),
|
|
361
378
|
showCount: p('showCount', 'mark'),
|
|
362
379
|
...TEXT_INPUT,
|
|
380
|
+
// The ref of its TextInput, written as it is.
|
|
381
|
+
inputRef: p('inputRef', 'handler'),
|
|
363
382
|
accessibilityLabel: p('label', 'string'),
|
|
364
383
|
accessibilityHint: p('hint', 'string'),
|
|
365
384
|
testID: p('testID', 'string'),
|
|
@@ -377,6 +396,9 @@ exports.COMPONENT_RULES = {
|
|
|
377
396
|
disabled: p('disabled', 'flag'),
|
|
378
397
|
onClearText: p('onClearText', 'handler'),
|
|
379
398
|
...TEXT_INPUT,
|
|
399
|
+
// Bloom's Search hands its `ref` to its TextInput: the language's `.inputRef()`.
|
|
400
|
+
ref: p('inputRef', 'handler'),
|
|
401
|
+
editable: p('editable', 'boolean'),
|
|
380
402
|
testID: p('testID', 'string'),
|
|
381
403
|
},
|
|
382
404
|
},
|
|
@@ -413,6 +435,8 @@ exports.COMPONENT_RULES = {
|
|
|
413
435
|
variant: p('style', 'token', tokens('loadingStyle')),
|
|
414
436
|
size: p('size', 'token', tokens('controlSize')),
|
|
415
437
|
tone: p('tint', 'token', tokens('tone')),
|
|
438
|
+
// An app's own colour (`#fff` over a photo): the tint, as written.
|
|
439
|
+
color: p('tint', 'ink'),
|
|
416
440
|
...NAMED,
|
|
417
441
|
},
|
|
418
442
|
},
|
|
@@ -446,9 +470,11 @@ exports.COMPONENT_RULES = {
|
|
|
446
470
|
props: {
|
|
447
471
|
size: p('size', 'token', AVATAR_SIZE),
|
|
448
472
|
shape: p('shape', 'token', tokens('shapeName')),
|
|
473
|
+
motion: p('motion', 'token', tokens('avatarMotion')),
|
|
449
474
|
verified: p('verified', 'flag'),
|
|
450
475
|
live: p('live', 'flag'),
|
|
451
476
|
alt: p('label', 'string'),
|
|
477
|
+
style: p('cornerRadius', 'radius'),
|
|
452
478
|
testID: p('testID', 'string'),
|
|
453
479
|
},
|
|
454
480
|
},
|
|
@@ -540,7 +566,8 @@ exports.COMPONENT_RULES = {
|
|
|
540
566
|
subtitle: p('subtitle', 'content'),
|
|
541
567
|
actions: p('toolbar', 'view'),
|
|
542
568
|
leading: p('toolbarLeading', 'view'),
|
|
543
|
-
|
|
569
|
+
// Bloom's own back (`undefined`) or none (`null`), chosen at render as written.
|
|
570
|
+
onBack: { ...p('onBack', 'handler'), unset: true },
|
|
544
571
|
backLabel: p('backLabel', 'string'),
|
|
545
572
|
headingLevel: p('headingLevel', 'number'),
|
|
546
573
|
scrim: p('scrollEdge', 'token', tokens('scrollEdge')),
|
|
@@ -550,13 +577,20 @@ exports.COMPONENT_RULES = {
|
|
|
550
577
|
accessory: p('accessory', 'view'),
|
|
551
578
|
tone: p('tone', 'token', tokens('headerTone')),
|
|
552
579
|
scrimFalloff: p('scrimFalloff', 'token', tokens('scrimFalloff')),
|
|
580
|
+
// A theme colour as its role, an app colour (`#000000`) as its own.
|
|
581
|
+
scrimColor: p('scrimColor', 'ink'),
|
|
553
582
|
titleReveal: p('titleReveal', 'token', tokens('titleReveal')),
|
|
554
583
|
testID: p('testID', 'string'),
|
|
555
584
|
},
|
|
556
585
|
},
|
|
557
586
|
'@oxy.so/bloom/loading#SpinnerIcon': {
|
|
558
587
|
node: 'SpinnerIcon',
|
|
559
|
-
props: {
|
|
588
|
+
props: {
|
|
589
|
+
size: p('size', 'token', ICON_SIZE),
|
|
590
|
+
// A theme colour as its role, an app colour as its own (`ON_VIDEO_COLOR`).
|
|
591
|
+
color: p('tint', 'ink'),
|
|
592
|
+
testID: p('testID', 'string'),
|
|
593
|
+
},
|
|
560
594
|
},
|
|
561
595
|
// parity/slider.cases.tsx.
|
|
562
596
|
'@oxy.so/bloom/slider#Slider': {
|
|
@@ -649,6 +683,7 @@ exports.COMPONENT_RULES = {
|
|
|
649
683
|
layout: p('layout', 'token', tokens('avatarLayout')),
|
|
650
684
|
size: p('size', 'token', AVATAR_SIZE),
|
|
651
685
|
shape: p('shape', 'token', tokens('shapeName')),
|
|
686
|
+
motion: p('motion', 'token', tokens('avatarMotion')),
|
|
652
687
|
max: p('max', 'number'),
|
|
653
688
|
total: p('total', 'number'),
|
|
654
689
|
spacing: p('spacing', 'token', exports.SPACE),
|
|
@@ -656,6 +691,9 @@ exports.COMPONENT_RULES = {
|
|
|
656
691
|
showInitials: p('initials', 'mark'),
|
|
657
692
|
onPressItem: p('onPressItem', 'handler'),
|
|
658
693
|
hoverCard: p('hoverCard', 'flag'),
|
|
694
|
+
ringColor: p('ringColor', 'ink'),
|
|
695
|
+
renderItemAction: p('itemAction', 'row'),
|
|
696
|
+
variant: p('variant', 'string'),
|
|
659
697
|
accessibilityLabel: p('label', 'string'),
|
|
660
698
|
testID: p('testID', 'string'),
|
|
661
699
|
},
|
|
@@ -691,7 +729,11 @@ exports.COMPONENT_RULES = {
|
|
|
691
729
|
contentContainerStyle: p('contentMargins', 'contentStyle'),
|
|
692
730
|
numColumns: p('columns', 'number'),
|
|
693
731
|
overrideItemLayout: p('itemLayout', 'handler'),
|
|
694
|
-
onEndReached: {
|
|
732
|
+
onEndReached: {
|
|
733
|
+
...p('onEndReached', 'handler'),
|
|
734
|
+
with: ['onEndReachedThreshold', 'number'],
|
|
735
|
+
unset: true,
|
|
736
|
+
},
|
|
695
737
|
restorationKey: p('restorationKey', 'string'),
|
|
696
738
|
stickyHeaderIndices: p('stickyIndices', 'items'),
|
|
697
739
|
ListHeaderComponent: p('headerContent', 'element'),
|
|
@@ -700,7 +742,7 @@ exports.COMPONENT_RULES = {
|
|
|
700
742
|
ListEmptyComponent: p('emptyState', 'element'),
|
|
701
743
|
// A query-driven pull to refresh: `.refreshable({ refreshing, onRefresh })`, as written.
|
|
702
744
|
refreshing: { ...p('refreshable', 'boolean'), key: 'refreshing' },
|
|
703
|
-
onRefresh: { ...p('refreshable', 'handler'), key: 'onRefresh' },
|
|
745
|
+
onRefresh: { ...p('refreshable', 'handler'), key: 'onRefresh', unset: true },
|
|
704
746
|
screen: { ...p('screen', 'empty'), within: '@oxy.so/bloom/screen#Screen' },
|
|
705
747
|
scrollbar: p('scrollbar', 'token', tokens('scrollbarVisibility')),
|
|
706
748
|
keyboardShouldPersistTaps: p('keyboardTaps', 'token', tokens('keyboardTaps')),
|
package/lib/resolve.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Mod, type Table } from './table';
|
|
1
|
+
import { type Mod, type StyleMod, type Table } from './table';
|
|
2
2
|
/** What draws the className: a React Native View, Pressable or a Bloom Text. */
|
|
3
3
|
export type HostKind = 'view' | 'pressable' | 'text';
|
|
4
4
|
export interface Reason {
|
|
@@ -49,10 +49,7 @@ export interface ResolveOptions {
|
|
|
49
49
|
* as `.grow()`, a theme colour as its role), by the style key: they join the
|
|
50
50
|
* classes' modifiers, so a class setting the same thing is a conflict.
|
|
51
51
|
*/
|
|
52
|
-
readonly styleMods?: readonly
|
|
53
|
-
readonly subject: string;
|
|
54
|
-
readonly mod: Mod;
|
|
55
|
-
}[];
|
|
52
|
+
readonly styleMods?: readonly StyleMod[];
|
|
56
53
|
/** The classes a `style` was read as (`gap: 12` is `gap-3`): inline, so no variant overrides them. */
|
|
57
54
|
readonly styleClasses?: ReadonlySet<string>;
|
|
58
55
|
}
|
package/lib/resolve.js
CHANGED
|
@@ -220,7 +220,21 @@ function resolveClassName(className, kind, table, options = {}) {
|
|
|
220
220
|
groups.set(key, found);
|
|
221
221
|
return found;
|
|
222
222
|
};
|
|
223
|
-
|
|
223
|
+
const tokens = className.split(/\s+/).filter(Boolean);
|
|
224
|
+
const sticky = stickyOf(tokens);
|
|
225
|
+
if (sticky !== undefined) {
|
|
226
|
+
const into = group([]);
|
|
227
|
+
const mod = { name: 'sticky', args: [sticky.edge] };
|
|
228
|
+
into.mods.push(mod);
|
|
229
|
+
into.subjects.set(mod, sticky.tokens.join(' '));
|
|
230
|
+
}
|
|
231
|
+
for (const token of tokens) {
|
|
232
|
+
if (sticky?.tokens.includes(token))
|
|
233
|
+
continue;
|
|
234
|
+
if (splitVariants(token).utility === 'sticky') {
|
|
235
|
+
fail(token, 'sticky', 'a sticky position held at no edge but `top-0` or `bottom-0` of the same variant (web only)');
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
224
238
|
const { variants, utility: rawUtility } = splitVariants(token);
|
|
225
239
|
if (rawUtility.startsWith('!') || rawUtility.endsWith('!')) {
|
|
226
240
|
fail(token, 'important', 'an !important utility outranks every other rule');
|
|
@@ -323,8 +337,8 @@ function resolveClassName(className, kind, table, options = {}) {
|
|
|
323
337
|
fail(token, entry.status, entry.language);
|
|
324
338
|
}
|
|
325
339
|
}
|
|
326
|
-
for (const { subject, mod } of options.styleMods ?? []) {
|
|
327
|
-
const into = group([]);
|
|
340
|
+
for (const { subject, mod, conditions } of options.styleMods ?? []) {
|
|
341
|
+
const into = group([...(conditions ?? [])]);
|
|
328
342
|
into.mods.push(mod);
|
|
329
343
|
into.subjects.set(mod, subject);
|
|
330
344
|
}
|
|
@@ -358,6 +372,24 @@ function resolveClassName(className, kind, table, options = {}) {
|
|
|
358
372
|
.sort((a, b) => rank(a.conditions) - rank(b.conditions));
|
|
359
373
|
return { ok: true, value: { axis, mods: base, variants } };
|
|
360
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* `sticky` with `top-0` or `bottom-0`, both bare or both `web:`: the
|
|
377
|
+
* language's `.sticky(edge)`, which is the web's alone (NativeWind draws no
|
|
378
|
+
* sticky position natively, and a relative view's zero inset moves nothing),
|
|
379
|
+
* so the `web:` its classes are written under is the modifier's own.
|
|
380
|
+
*/
|
|
381
|
+
function stickyOf(tokens) {
|
|
382
|
+
for (const prefix of ['', 'web:']) {
|
|
383
|
+
if (!tokens.includes(`${prefix}sticky`))
|
|
384
|
+
continue;
|
|
385
|
+
const edges = ['top', 'bottom'].filter((edge) => tokens.includes(`${prefix}${edge}-0`));
|
|
386
|
+
if (edges.length !== 1)
|
|
387
|
+
return undefined;
|
|
388
|
+
const edge = edges[0];
|
|
389
|
+
return { edge, tokens: [`${prefix}sticky`, `${prefix}${edge}-0`] };
|
|
390
|
+
}
|
|
391
|
+
return undefined;
|
|
392
|
+
}
|
|
361
393
|
function rank(conditions) {
|
|
362
394
|
const first = conditions[0] ?? '';
|
|
363
395
|
const breakpoint = BREAKPOINTS.indexOf(first);
|
|
@@ -369,16 +401,21 @@ function finish(g, kind, fail) {
|
|
|
369
401
|
// A text size's own leading gives way to an explicit leading class.
|
|
370
402
|
if (g.impliedLeading && mods.filter((m) => m.name === 'leading').length > 1)
|
|
371
403
|
mods = mods.filter((m) => m !== g.impliedLeading);
|
|
372
|
-
// Border: a width class and a colour class are one modifier.
|
|
373
|
-
|
|
374
|
-
|
|
404
|
+
// Border: a width class and a colour class are one modifier. A border a style
|
|
405
|
+
// wrote whole (its width in the platform's colour, `.border(undefined, width)`) is one already.
|
|
406
|
+
const colors = mods.filter((m) => m.name === 'border' && m.args.length === 1);
|
|
407
|
+
mods = mods.filter((m) => m.name !== 'border' || m.args.length > 1);
|
|
375
408
|
if (g.widths.length > 0 || colors.length > 0) {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
409
|
+
// A width with no colour class: the platform's default colour (React Native's black,
|
|
410
|
+
// react-native-web's own on the web, over the preflight's), `.border(undefined, width)`.
|
|
411
|
+
if (colors.length === 0) {
|
|
412
|
+
for (const width of g.widths)
|
|
413
|
+
mods.push({ name: 'border', args: [undefined, ...width.args] });
|
|
414
|
+
}
|
|
415
|
+
else if (colors.length !== 1 || g.widths.length === 0) {
|
|
416
|
+
const what = g.widths.length === 0
|
|
417
|
+
? 'a border colour with no width class (no border is drawn)'
|
|
418
|
+
: 'two border colours';
|
|
382
419
|
fail([...g.widths.map((w) => w.subject), ...colors.map(subject)].join(' '), 'border', what);
|
|
383
420
|
}
|
|
384
421
|
else {
|
|
@@ -393,8 +430,9 @@ function finish(g, kind, fail) {
|
|
|
393
430
|
if (g.absolute || edges.length > 0) {
|
|
394
431
|
if (!g.absolute)
|
|
395
432
|
fail(edges.map(subject).join(' '), 'offset-without-absolute', 'an inset without `absolute` offsets the view in its flow');
|
|
433
|
+
// `absolute` alone takes the view out of the flow where it would sit: a position of no edge.
|
|
396
434
|
else if (edges.length === 0)
|
|
397
|
-
|
|
435
|
+
mods.push({ name: 'position', args: [{}] });
|
|
398
436
|
else {
|
|
399
437
|
const merged = mergeObjects(edges, 'position', subject, fail);
|
|
400
438
|
if (merged)
|
package/lib/style.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Mod } from './table';
|
|
1
|
+
import { type Mod, type StyleMod } from './table';
|
|
2
2
|
/**
|
|
3
3
|
* A text's own `fontSize` and `lineHeight` written out, as the language's
|
|
4
4
|
* size and line: `fontSize: 15` is `.font('md')` (a named rung over a numeric
|
|
@@ -13,10 +13,7 @@ export type StyleResult = {
|
|
|
13
13
|
readonly ok: true;
|
|
14
14
|
readonly classes: readonly string[];
|
|
15
15
|
/** What no utility writes, by its style key (`flex: 1` is `.grow()`). */
|
|
16
|
-
readonly mods: readonly
|
|
17
|
-
readonly subject: string;
|
|
18
|
-
readonly mod: Mod;
|
|
19
|
-
}[];
|
|
16
|
+
readonly mods: readonly StyleMod[];
|
|
20
17
|
readonly literal: string;
|
|
21
18
|
/**
|
|
22
19
|
* Points the chain draws without carrying them (a half-square radius's
|
|
@@ -58,11 +55,13 @@ export interface StyleReaders {
|
|
|
58
55
|
readonly numberOf?: (node: AnyNode) => number | undefined;
|
|
59
56
|
/** Whether a value is a number the view computes as it renders (geometry's points). */
|
|
60
57
|
readonly computed?: (node: AnyNode) => boolean;
|
|
58
|
+
/** Whether react-native-web compiles the style into classes (a StyleSheet's), not an inline object. */
|
|
59
|
+
readonly compiled?: boolean;
|
|
61
60
|
}
|
|
62
61
|
/**
|
|
63
62
|
* An object literal of a style as utilities, and the literal itself (for the
|
|
64
63
|
* parity's before side, where `styles.x` is not in scope). A spread `spreadOf`
|
|
65
64
|
* reads is what it writes; any other is a style built at runtime.
|
|
66
65
|
*/
|
|
67
|
-
export declare function styleUtilities(object: AnyNode, { read, spreadOf, numberOf, computed }?: StyleReaders): StyleResult;
|
|
66
|
+
export declare function styleUtilities(object: AnyNode, { read, spreadOf, numberOf, computed, compiled }?: StyleReaders): StyleResult;
|
|
68
67
|
export {};
|