@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/lib/style.js
CHANGED
|
@@ -33,6 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ABSOLUTE_FILL = void 0;
|
|
37
|
+
exports.textDeclaration = textDeclaration;
|
|
36
38
|
exports.styleUtilities = styleUtilities;
|
|
37
39
|
/**
|
|
38
40
|
* A static `style` as the Tailwind utilities that write the same declarations,
|
|
@@ -42,7 +44,53 @@ exports.styleUtilities = styleUtilities;
|
|
|
42
44
|
* scale (`gap: 12` is `gap-3`, 0.25rem steps at the preset's 16px rem), `100%`,
|
|
43
45
|
* and the flex keywords. Anything else is a reason.
|
|
44
46
|
*/
|
|
47
|
+
const node_fs_1 = require("node:fs");
|
|
48
|
+
const node_path_1 = require("node:path");
|
|
45
49
|
const recast = __importStar(require("recast"));
|
|
50
|
+
const table_1 = require("./table");
|
|
51
|
+
const { scales, enums } = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(table_1.LANGUAGE_PACKAGE, 'spec/language.json'), 'utf8'));
|
|
52
|
+
/** A frame's length relative to its parent by its percentage (`'50%'` is `'1/2'`, `'90%'` itself). */
|
|
53
|
+
const LENGTH_BY_PERCENT = new Map(Object.entries(scales.length)
|
|
54
|
+
.filter(([name, value]) => name !== '$comment' && typeof value === 'string')
|
|
55
|
+
.map(([name, value]) => [value, name]));
|
|
56
|
+
/** The percentages a pinned view's edge takes (`top: '25%'`). */
|
|
57
|
+
const INSET_PERCENT = new Set(enums.insetPercent);
|
|
58
|
+
/** A scale's tokens by value, a named rung over a numeric token of the same value. */
|
|
59
|
+
function byValue(scale) {
|
|
60
|
+
const out = new Map();
|
|
61
|
+
for (const [name, value] of Object.entries(scale)) {
|
|
62
|
+
if (typeof value !== 'number')
|
|
63
|
+
continue;
|
|
64
|
+
const named = !/^-?\d/.test(name);
|
|
65
|
+
if (named || !out.has(value))
|
|
66
|
+
out.set(value, name);
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
const CORNER = byValue(scales.corner);
|
|
71
|
+
const Z_INDEX = byValue(scales.zIndex);
|
|
72
|
+
const FONT_SIZE = byValue(scales.fontSize);
|
|
73
|
+
const LEADING_PX = byValue(scales.leadingPx);
|
|
74
|
+
/**
|
|
75
|
+
* A text's own `fontSize` and `lineHeight` written out, as the language's
|
|
76
|
+
* size and line: `fontSize: 15` is `.font('md')` (a named rung over a numeric
|
|
77
|
+
* token of the same points, `fontSize: 14` `.font('14')`), `lineHeight: 20`
|
|
78
|
+
* `.leading('20px')`. A size or a line no token holds stays a reason.
|
|
79
|
+
*/
|
|
80
|
+
function textDeclaration(key, value) {
|
|
81
|
+
if (!n.NumericLiteral.check(value))
|
|
82
|
+
return undefined;
|
|
83
|
+
const number = value.value;
|
|
84
|
+
if (key === 'fontSize') {
|
|
85
|
+
const token = FONT_SIZE.get(number);
|
|
86
|
+
return token === undefined ? undefined : { name: 'font', args: [token] };
|
|
87
|
+
}
|
|
88
|
+
if (key === 'lineHeight') {
|
|
89
|
+
const token = LEADING_PX.get(number);
|
|
90
|
+
return token === undefined ? undefined : { name: 'leading', args: [token] };
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
46
94
|
const n = recast.types.namedTypes;
|
|
47
95
|
/** A style key whose numeric value is a spacing-scale step: its utility prefix. */
|
|
48
96
|
const LENGTH = {
|
|
@@ -102,7 +150,25 @@ const KEYWORD = {
|
|
|
102
150
|
'space-evenly': 'justify-evenly',
|
|
103
151
|
},
|
|
104
152
|
position: { absolute: 'absolute', relative: 'relative' },
|
|
105
|
-
|
|
153
|
+
// A view draws what overflows it by default: the className table drops `overflow-visible`.
|
|
154
|
+
overflow: { hidden: 'overflow-hidden', visible: 'overflow-visible' },
|
|
155
|
+
// An auto margin takes the free space on its side (the language's `.margin(edge, 'auto')`).
|
|
156
|
+
marginTop: { auto: 'mt-auto' },
|
|
157
|
+
marginBottom: { auto: 'mb-auto' },
|
|
158
|
+
marginLeft: { auto: 'ml-auto' },
|
|
159
|
+
marginRight: { auto: 'mr-auto' },
|
|
160
|
+
borderStyle: { solid: 'border-solid', dashed: 'border-dashed', dotted: 'border-dotted' },
|
|
161
|
+
// A text's weight, as Tailwind's `font-*` writes it.
|
|
162
|
+
fontWeight: {
|
|
163
|
+
'300': 'font-light',
|
|
164
|
+
'400': 'font-normal',
|
|
165
|
+
'500': 'font-medium',
|
|
166
|
+
'600': 'font-semibold',
|
|
167
|
+
'700': 'font-bold',
|
|
168
|
+
'800': 'font-extrabold',
|
|
169
|
+
bold: 'font-bold',
|
|
170
|
+
normal: 'font-normal',
|
|
171
|
+
},
|
|
106
172
|
};
|
|
107
173
|
/**
|
|
108
174
|
* A numeric key whose value is a utility of its own. (React Native's `flex: 1`
|
|
@@ -114,11 +180,50 @@ const NUMERIC = {
|
|
|
114
180
|
flexGrow: { 1: 'grow', 0: 'grow-0' },
|
|
115
181
|
flexShrink: { 1: 'shrink', 0: 'shrink-0' },
|
|
116
182
|
};
|
|
117
|
-
/** A
|
|
183
|
+
/** A corner's own radius key as the language's corner side. */
|
|
184
|
+
const CORNER_SIDE = {
|
|
185
|
+
borderTopLeftRadius: 'top-left',
|
|
186
|
+
borderTopRightRadius: 'top-right',
|
|
187
|
+
borderBottomLeftRadius: 'bottom-left',
|
|
188
|
+
borderBottomRightRadius: 'bottom-right',
|
|
189
|
+
borderTopStartRadius: 'top-leading',
|
|
190
|
+
borderTopEndRadius: 'top-trailing',
|
|
191
|
+
borderBottomStartRadius: 'bottom-leading',
|
|
192
|
+
borderBottomEndRadius: 'bottom-trailing',
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* A style key and value the language writes itself, as its modifier: React
|
|
196
|
+
* Native's `flex: 1` is `.grow()`; a radius, a stacking level and an aspect
|
|
197
|
+
* ratio are the tokens (or number) of their exact value, a corner's own
|
|
198
|
+
* radius (`borderTopLeftRadius`) its side's. A radius of 999 is `full` (9999):
|
|
199
|
+
* both round any box under 1998pt fully, so they draw alike.
|
|
200
|
+
*/
|
|
118
201
|
function direct(key, value) {
|
|
119
|
-
|
|
120
|
-
?
|
|
121
|
-
:
|
|
202
|
+
const number = n.NumericLiteral.check(value)
|
|
203
|
+
? value.value
|
|
204
|
+
: n.UnaryExpression.check(value) &&
|
|
205
|
+
value.operator === '-' &&
|
|
206
|
+
n.NumericLiteral.check(value.argument)
|
|
207
|
+
? -value.argument.value
|
|
208
|
+
: undefined;
|
|
209
|
+
if (number === undefined)
|
|
210
|
+
return undefined;
|
|
211
|
+
if (key === 'flex' && number === 1)
|
|
212
|
+
return { name: 'grow', args: [] };
|
|
213
|
+
if (key === 'borderRadius' || CORNER_SIDE[key]) {
|
|
214
|
+
const token = number === 999 ? 'full' : CORNER.get(number);
|
|
215
|
+
const side = CORNER_SIDE[key];
|
|
216
|
+
return token === undefined
|
|
217
|
+
? undefined
|
|
218
|
+
: { name: 'corner', args: side ? [token, side] : [token] };
|
|
219
|
+
}
|
|
220
|
+
if (key === 'zIndex') {
|
|
221
|
+
const token = Z_INDEX.get(number);
|
|
222
|
+
return token === undefined ? undefined : { name: 'zIndex', args: [token] };
|
|
223
|
+
}
|
|
224
|
+
if (key === 'aspectRatio' && number > 0)
|
|
225
|
+
return { name: 'aspectRatio', args: [number] };
|
|
226
|
+
return undefined;
|
|
122
227
|
}
|
|
123
228
|
/** One declaration as its utility, or undefined. */
|
|
124
229
|
function utility(key, value) {
|
|
@@ -140,27 +245,224 @@ function utility(key, value) {
|
|
|
140
245
|
}
|
|
141
246
|
return undefined;
|
|
142
247
|
}
|
|
248
|
+
const FLEX_KEYS = ['flexGrow', 'flexShrink', 'flexBasis'];
|
|
249
|
+
const FLEX = Object.entries(scales.flex).filter(([name]) => name !== '$comment');
|
|
250
|
+
/** A style's literal grow, shrink and basis, all three, as the flex token that writes them, or undefined. */
|
|
251
|
+
function flexToken(object) {
|
|
252
|
+
const values = new Map();
|
|
253
|
+
for (const property of object.properties)
|
|
254
|
+
if ((n.ObjectProperty.check(property) || n.Property.check(property)) &&
|
|
255
|
+
n.Identifier.check(property.key) &&
|
|
256
|
+
FLEX_KEYS.includes(property.key.name) &&
|
|
257
|
+
(n.NumericLiteral.check(property.value) || n.StringLiteral.check(property.value)))
|
|
258
|
+
values.set(property.key.name, property.value.value);
|
|
259
|
+
if (values.size !== 3)
|
|
260
|
+
return undefined;
|
|
261
|
+
return FLEX.find(([, [grow, shrink, basis]]) => grow === values.get('flexGrow') &&
|
|
262
|
+
shrink === values.get('flexShrink') &&
|
|
263
|
+
basis === values.get('flexBasis'))?.[0];
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* React Native's `StyleSheet.absoluteFill`: pinned to every edge of its parent
|
|
267
|
+
* (`absolute inset-0`), and the declarations it holds, written out for the
|
|
268
|
+
* parity's before side.
|
|
269
|
+
*/
|
|
270
|
+
exports.ABSOLUTE_FILL = {
|
|
271
|
+
classes: ['absolute', 'top-0', 'right-0', 'bottom-0', 'left-0'],
|
|
272
|
+
literal: "position: 'absolute', left: 0, right: 0, top: 0, bottom: 0",
|
|
273
|
+
};
|
|
274
|
+
/** Each physical side a padding or margin key sets, and how specific it is (React Native's precedence). */
|
|
275
|
+
const EDGE_KEYS = {
|
|
276
|
+
'': { sides: ['Top', 'Bottom', 'Left', 'Right'], rank: 0 },
|
|
277
|
+
Horizontal: { sides: ['Left', 'Right'], rank: 1 },
|
|
278
|
+
Vertical: { sides: ['Top', 'Bottom'], rank: 1 },
|
|
279
|
+
Top: { sides: ['Top'], rank: 2 },
|
|
280
|
+
Bottom: { sides: ['Bottom'], rank: 2 },
|
|
281
|
+
Left: { sides: ['Left'], rank: 2 },
|
|
282
|
+
Right: { sides: ['Right'], rank: 2 },
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* A style's paddings and margins as React Native resolves them when keys of
|
|
286
|
+
* one side meet (`marginHorizontal: 8, marginLeft: 4`): a side's own key over
|
|
287
|
+
* its axis's, an axis's over the whole, whatever their order. Where they
|
|
288
|
+
* meet, a key overridden on a side is the sides it still holds, each its own
|
|
289
|
+
* (`marginLeft: 4, marginRight: 8`), so no two utilities set one side; every
|
|
290
|
+
* other key stays as written. A
|
|
291
|
+
* `Start` or `End` key beside them is left to the conflict it is.
|
|
292
|
+
*/
|
|
293
|
+
function sidesResolved(properties) {
|
|
294
|
+
const out = [...properties];
|
|
295
|
+
for (const prefix of ['padding', 'margin']) {
|
|
296
|
+
const own = out.filter((property) => (n.ObjectProperty.check(property) || n.Property.check(property)) &&
|
|
297
|
+
!property.computed &&
|
|
298
|
+
n.Identifier.check(property.key) &&
|
|
299
|
+
property.key.name.startsWith(prefix) &&
|
|
300
|
+
EDGE_KEYS[property.key.name.slice(prefix.length)] !== undefined);
|
|
301
|
+
const set = new Map();
|
|
302
|
+
let meet = false;
|
|
303
|
+
for (const property of own) {
|
|
304
|
+
const { sides, rank } = EDGE_KEYS[property.key.name.slice(prefix.length)];
|
|
305
|
+
for (const side of sides) {
|
|
306
|
+
const prior = set.get(side);
|
|
307
|
+
if (prior)
|
|
308
|
+
meet = true;
|
|
309
|
+
if (!prior || rank >= prior.rank)
|
|
310
|
+
set.set(side, { rank, value: property.value });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (!meet)
|
|
314
|
+
continue;
|
|
315
|
+
// A key that holds every side it names stays; one a more specific key overrides is the
|
|
316
|
+
// sides it still holds, each its own key.
|
|
317
|
+
for (const property of own) {
|
|
318
|
+
const { sides } = EDGE_KEYS[property.key.name.slice(prefix.length)];
|
|
319
|
+
const held = sides.filter((side) => set.get(side)?.value === property.value);
|
|
320
|
+
if (held.length === sides.length)
|
|
321
|
+
continue;
|
|
322
|
+
const keys = held.map((side) => recast.types.builders.objectProperty(recast.types.builders.identifier(`${prefix}${side}`), property.value));
|
|
323
|
+
out.splice(out.indexOf(property), 1, ...keys);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
/** A frame's own length keys (spec `objects.frame`). */
|
|
329
|
+
const FRAME_KEYS = new Set(['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight']);
|
|
330
|
+
/** A pinned view's physical edges, as React Native's keys (spec `objects.edges`). */
|
|
331
|
+
const PINNED_EDGES = new Set(['top', 'bottom', 'left', 'right']);
|
|
332
|
+
/**
|
|
333
|
+
* Geometry computed at render as the language's points (spec `points`):
|
|
334
|
+
* `width: itemSize` is `.frame({ width: itemSize })`, `top: insets.top + 8`
|
|
335
|
+
* `.position({ top: insets.top + 8 })` (which joins the view's `absolute`),
|
|
336
|
+
* `zIndex: count - index` `.zIndex(count - index)`. Only a value `computed`
|
|
337
|
+
* says the view works out as it renders; a number written out is a token.
|
|
338
|
+
*/
|
|
339
|
+
function pointsDeclaration(key, value) {
|
|
340
|
+
const points = { node: value, hole: 'points' };
|
|
341
|
+
if (FRAME_KEYS.has(key))
|
|
342
|
+
return { name: 'frame', args: [{ [key]: points }] };
|
|
343
|
+
if (PINNED_EDGES.has(key))
|
|
344
|
+
return { name: 'position', args: [{ [key]: points }] };
|
|
345
|
+
if (key === 'zIndex')
|
|
346
|
+
return { name: 'zIndex', args: [points] };
|
|
347
|
+
return undefined;
|
|
348
|
+
}
|
|
349
|
+
/** A style's own declaration by its key, or undefined. */
|
|
350
|
+
function declared(object, key) {
|
|
351
|
+
return object.properties.find((property) => (n.ObjectProperty.check(property) || n.Property.check(property)) &&
|
|
352
|
+
!property.computed &&
|
|
353
|
+
n.Identifier.check(property.key) &&
|
|
354
|
+
property.key.name === key)?.value;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* The side of a square a radius is half of (`width: size, height: size,
|
|
358
|
+
* borderRadius: size / 2`), which is `.corner('full')`: the box is a circle
|
|
359
|
+
* either way, since a radius over half the side draws as half of it. The
|
|
360
|
+
* style sets the side twice as one expression and no minimum that could grow
|
|
361
|
+
* the box past it.
|
|
362
|
+
*/
|
|
363
|
+
function halfSquareSide(object, value) {
|
|
364
|
+
const [width, height] = [declared(object, 'width'), declared(object, 'height')];
|
|
365
|
+
if (!width ||
|
|
366
|
+
!height ||
|
|
367
|
+
declared(object, 'minWidth') ||
|
|
368
|
+
declared(object, 'minHeight') ||
|
|
369
|
+
!n.BinaryExpression.check(value) ||
|
|
370
|
+
value.operator !== '/' ||
|
|
371
|
+
!n.NumericLiteral.check(value.right) ||
|
|
372
|
+
value.right.value !== 2)
|
|
373
|
+
return undefined;
|
|
374
|
+
const side = recast.print(value.left).code;
|
|
375
|
+
return recast.print(width).code === side && recast.print(height).code === side
|
|
376
|
+
? value.left
|
|
377
|
+
: undefined;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* A percentage of the parent the language names: a frame's length token of
|
|
381
|
+
* that percentage (`maxHeight: '90%'` is `.frame({ maxHeight: '90%' })`,
|
|
382
|
+
* `width: '50%'` `.frame({ width: '1/2' })`), a pinned view's edge
|
|
383
|
+
* (`left: '25%'` is `.position({ left: '25%' })`).
|
|
384
|
+
*/
|
|
385
|
+
function percentDeclaration(key, value) {
|
|
386
|
+
if (!n.StringLiteral.check(value))
|
|
387
|
+
return undefined;
|
|
388
|
+
const length = LENGTH_BY_PERCENT.get(value.value);
|
|
389
|
+
if (FRAME_KEYS.has(key) && length !== undefined)
|
|
390
|
+
return { name: 'frame', args: [{ [key]: length }] };
|
|
391
|
+
if (PINNED_EDGES.has(key) && INSET_PERCENT.has(value.value))
|
|
392
|
+
return { name: 'position', args: [{ [key]: value.value }] };
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
143
395
|
/**
|
|
144
396
|
* An object literal of a style as utilities, and the literal itself (for the
|
|
145
|
-
* parity's before side, where `styles.x` is not in scope).
|
|
397
|
+
* parity's before side, where `styles.x` is not in scope). A spread `spreadOf`
|
|
398
|
+
* reads is what it writes; any other is a style built at runtime.
|
|
146
399
|
*/
|
|
147
|
-
function styleUtilities(object, read) {
|
|
400
|
+
function styleUtilities(object, { read, spreadOf, numberOf, computed } = {}) {
|
|
148
401
|
if (!n.ObjectExpression.check(object))
|
|
149
402
|
return { ok: false, subject: 'style', why: 'a style that is no object literal' };
|
|
150
403
|
const classes = [];
|
|
151
404
|
const mods = [];
|
|
152
|
-
|
|
405
|
+
const held = [];
|
|
406
|
+
let literal = recast.print(object).code;
|
|
407
|
+
// A grow, shrink and basis that are one of Tailwind's flex utilities (`flex-1`) are `.flex()`.
|
|
408
|
+
const flex = flexToken(object);
|
|
409
|
+
if (flex)
|
|
410
|
+
mods.push({ subject: 'flexBasis', mod: { name: 'flex', args: [flex] } });
|
|
411
|
+
for (const property of sidesResolved(object.properties)) {
|
|
412
|
+
if (flex &&
|
|
413
|
+
(n.ObjectProperty.check(property) || n.Property.check(property)) &&
|
|
414
|
+
n.Identifier.check(property.key) &&
|
|
415
|
+
FLEX_KEYS.includes(property.key.name))
|
|
416
|
+
continue;
|
|
417
|
+
const spread = n.SpreadElement.check(property) ? spreadOf?.(property.argument) : undefined;
|
|
418
|
+
if (spread) {
|
|
419
|
+
classes.push(...spread.classes);
|
|
420
|
+
for (const mod of spread.mods)
|
|
421
|
+
mods.push({ subject: 'fontFamily', mod });
|
|
422
|
+
if (spread.literal !== undefined)
|
|
423
|
+
literal = literal.replace(recast.print(property).code, spread.literal);
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
153
426
|
if (!(n.ObjectProperty.check(property) || n.Property.check(property)) ||
|
|
154
427
|
property.computed ||
|
|
155
428
|
!n.Identifier.check(property.key))
|
|
156
429
|
return { ok: false, subject: 'style', why: 'a style built at runtime' };
|
|
157
430
|
const key = property.key.name;
|
|
158
|
-
const
|
|
431
|
+
const known = numberOf?.(property.value);
|
|
432
|
+
const value = known === undefined
|
|
433
|
+
? property.value
|
|
434
|
+
: known < 0
|
|
435
|
+
? recast.types.builders.unaryExpression('-', recast.types.builders.numericLiteral(-known))
|
|
436
|
+
: recast.types.builders.numericLiteral(known);
|
|
437
|
+
const side = key === 'borderRadius' ? halfSquareSide(object, value) : undefined;
|
|
438
|
+
if (side) {
|
|
439
|
+
mods.push({ subject: key, mod: { name: 'corner', args: ['full'] } });
|
|
440
|
+
if (computed?.(side))
|
|
441
|
+
held.push(side);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const mod = direct(key, value) ??
|
|
445
|
+
read?.(key, value) ??
|
|
446
|
+
(computed?.(value) ? pointsDeclaration(key, value) : undefined);
|
|
159
447
|
if (mod) {
|
|
160
|
-
|
|
448
|
+
for (const one of Array.isArray(mod) ? mod : [mod])
|
|
449
|
+
mods.push({ subject: key, mod: one });
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
// `inset` is its four edges, as React Native resolves it.
|
|
453
|
+
if (key === 'inset') {
|
|
454
|
+
const edges = ['top', 'right', 'bottom', 'left'].map((edge) => utility(edge, value));
|
|
455
|
+
if (edges.every((edge) => edge !== undefined)) {
|
|
456
|
+
classes.push(...edges);
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const found = utility(key, value);
|
|
461
|
+
const percent = found ? undefined : percentDeclaration(key, value);
|
|
462
|
+
if (percent) {
|
|
463
|
+
mods.push({ subject: key, mod: percent });
|
|
161
464
|
continue;
|
|
162
465
|
}
|
|
163
|
-
const found = utility(key, property.value);
|
|
164
466
|
if (!found)
|
|
165
467
|
return {
|
|
166
468
|
ok: false,
|
|
@@ -169,5 +471,5 @@ function styleUtilities(object, read) {
|
|
|
169
471
|
};
|
|
170
472
|
classes.push(found);
|
|
171
473
|
}
|
|
172
|
-
return { ok: true, classes, mods, literal
|
|
474
|
+
return { ok: true, classes, mods, literal, held };
|
|
173
475
|
}
|
package/lib/table.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A number of points the view computes as it renders (`itemSize`,
|
|
3
|
+
* `insets.top + 8`), carried over as written: geometry only, a frame's
|
|
4
|
+
* lengths, a pinned view's edges and its stacking order (spec `points`).
|
|
5
|
+
*/
|
|
6
|
+
export interface PointsArg {
|
|
7
|
+
readonly node: unknown;
|
|
8
|
+
readonly hole: 'points';
|
|
9
|
+
}
|
|
10
|
+
export type Arg = string | number | boolean | PointsArg | Readonly<Record<string, string | PointsArg>>;
|
|
11
|
+
export declare const isPoints: (arg: unknown) => arg is PointsArg;
|
|
12
|
+
/** Modifiers (or variants of them) as a comparable string, each points value by where it is written. */
|
|
13
|
+
export declare const modKey: (mods: unknown) => string;
|
|
2
14
|
/** One modifier call, as the codemod writes it. */
|
|
3
15
|
export interface Mod {
|
|
4
16
|
readonly name: string;
|
package/lib/table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LANGUAGE_PACKAGE = void 0;
|
|
3
|
+
exports.LANGUAGE_PACKAGE = exports.modKey = exports.isPoints = void 0;
|
|
4
4
|
exports.chainOf = chainOf;
|
|
5
5
|
exports.loadTable = loadTable;
|
|
6
6
|
/**
|
|
@@ -13,6 +13,13 @@ const node_fs_1 = require("node:fs");
|
|
|
13
13
|
const node_module_1 = require("node:module");
|
|
14
14
|
const node_path_1 = require("node:path");
|
|
15
15
|
const parser_1 = require("@babel/parser");
|
|
16
|
+
const isPoints = (arg) => typeof arg === 'object' && arg !== null && arg.hole === 'points';
|
|
17
|
+
exports.isPoints = isPoints;
|
|
18
|
+
/** Modifiers (or variants of them) as a comparable string, each points value by where it is written. */
|
|
19
|
+
const modKey = (mods) => JSON.stringify(mods, (_, value) => (0, exports.isPoints)(value)
|
|
20
|
+
? `#${value.node.start}:${value.node.end}`
|
|
21
|
+
: value);
|
|
22
|
+
exports.modKey = modKey;
|
|
16
23
|
/**
|
|
17
24
|
* The Bloom language package the codemod writes for: the one installed beside
|
|
18
25
|
* it (its peer), whose spec, exports and className table it reads.
|
package/lib/transform.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface Fixture {
|
|
|
24
24
|
readonly within: readonly string[];
|
|
25
25
|
/** The before side reads Bloom's theme (`parityTheme`, its `useTheme()`): a fill the chain names by role. */
|
|
26
26
|
readonly themed: boolean;
|
|
27
|
+
/** The before side pads by the device's insets: both sides are drawn under the corpus's (`PARITY_INSETS`). */
|
|
28
|
+
readonly insets: boolean;
|
|
27
29
|
/** The after side is a route's body root, drawn by the language's `ScreenHost` as `screen()` draws it. */
|
|
28
30
|
readonly screen: boolean;
|
|
29
31
|
/** The app colours the chain paints with: the table's local name and each token's colour. */
|