@rangular-framework/cli 0.0.0-stage → 1.0.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/dist/cli/src/cli.js +1229 -0
- package/dist/compiler/src/catalog.js +198 -0
- package/dist/compiler/src/class/formInit.js +370 -0
- package/dist/compiler/src/class/parseComponent.js +430 -0
- package/dist/compiler/src/class/parseDirective.js +227 -0
- package/dist/compiler/src/class/parseRoutes.js +163 -0
- package/dist/compiler/src/codegen/generate.js +3466 -0
- package/dist/compiler/src/codegen/methods.js +975 -0
- package/dist/compiler/src/codegen/sourceMap.js +77 -0
- package/dist/compiler/src/compile.js +775 -0
- package/dist/compiler/src/diagnostics.js +113 -0
- package/dist/compiler/src/doctor.js +144 -0
- package/dist/compiler/src/fix.js +44 -0
- package/dist/compiler/src/index.js +38 -0
- package/dist/compiler/src/preview/renderPreview.js +7158 -0
- package/dist/compiler/src/preview/styleSnapshot.js +268 -0
- package/dist/compiler/src/propTable.js +107 -0
- package/dist/compiler/src/style/css.js +161 -0
- package/dist/compiler/src/template/ast.js +19 -0
- package/dist/compiler/src/template/evaluate.js +151 -0
- package/dist/compiler/src/template/expr.js +360 -0
- package/dist/compiler/src/template/forms.js +80 -0
- package/dist/compiler/src/template/literal.js +248 -0
- package/dist/compiler/src/template/parser.js +230 -0
- package/dist/compiler/src/template/pipes.js +225 -0
- package/dist/compiler/src/template/printAst.js +38 -0
- package/dist/compiler/src/template/structural.js +51 -0
- package/dist/runtime/src/index.js +1197 -0
- package/dist/ui/src/chart.js +196 -0
- package/dist/ui/src/datetime.js +240 -0
- package/dist/ui/src/icons.js +310 -0
- package/dist/ui/src/mask.js +103 -0
- package/dist/ui/src/palette.js +141 -0
- package/dist/ui/src/tokens.js +173 -0
- package/package.json +28 -4
- package/README.md +0 -3
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildStyleSnapshot = buildStyleSnapshot;
|
|
4
|
+
exports.renderStyleSnapshot = renderStyleSnapshot;
|
|
5
|
+
const tokens_1 = require("../../../ui/src/tokens");
|
|
6
|
+
/** Resolved styles for every role the preview knows, for one theme mode. */
|
|
7
|
+
function allRoles(mode) {
|
|
8
|
+
const t = (0, tokens_1.theme)(mode);
|
|
9
|
+
const c = t.colors;
|
|
10
|
+
const ty = t.typography;
|
|
11
|
+
return {
|
|
12
|
+
screen: { background: c.background, color: c.text },
|
|
13
|
+
appbar: { background: c.surfaceVariant, borderRadius: t.radius.full, gap: t.spacing.md },
|
|
14
|
+
avatar: { background: c.avatar, color: c.onAvatar },
|
|
15
|
+
rowAvatar: { background: c.primary, color: c.onPrimary },
|
|
16
|
+
card: {
|
|
17
|
+
background: c.surfaceVariant, borderColor: c.border,
|
|
18
|
+
borderRadius: t.radius.lg, padding: t.spacing.lg,
|
|
19
|
+
},
|
|
20
|
+
button: { background: c.primary, color: c.onPrimary, borderRadius: t.radius.full, minHeight: 48 },
|
|
21
|
+
list: { borderColor: c.border },
|
|
22
|
+
row: {
|
|
23
|
+
// A row carries no horizontal padding of its own (default
|
|
24
|
+
// polish pass): its inset comes from the container grid
|
|
25
|
+
// (the screen's spacing.lg padding, a card's padding, and
|
|
26
|
+
// so on), so the row's own recorded padding is 0.
|
|
27
|
+
borderColor: c.border, gap: t.spacing.md,
|
|
28
|
+
paddingLeft: 0, paddingRight: 0,
|
|
29
|
+
},
|
|
30
|
+
badge: {
|
|
31
|
+
background: c.primaryContainer, color: c.onPrimaryContainer,
|
|
32
|
+
borderRadius: t.radius.full, fontSize: ty.caption.fontSize, fontWeight: 700,
|
|
33
|
+
},
|
|
34
|
+
icon: { color: c.text },
|
|
35
|
+
iconButton: { minWidth: 48, minHeight: 48 },
|
|
36
|
+
fab: { background: c.primaryContainer, color: c.onPrimaryContainer, borderRadius: t.radius.lg },
|
|
37
|
+
switch: {
|
|
38
|
+
background: c.surfaceVariant, borderColor: c.outline, knobBackground: c.onSurfaceVariant,
|
|
39
|
+
checkedBackground: c.primary, checkedKnobBackground: c.onPrimary,
|
|
40
|
+
borderRadius: t.radius.full, width: 52, height: 32,
|
|
41
|
+
},
|
|
42
|
+
checkbox: {
|
|
43
|
+
background: c.primary, borderColor: c.primary, color: c.onPrimary,
|
|
44
|
+
borderRadius: t.radius.sm, width: 24, height: 24,
|
|
45
|
+
},
|
|
46
|
+
switcher: {
|
|
47
|
+
background: c.surfaceVariant, borderColor: c.border, borderRadius: t.radius.full,
|
|
48
|
+
selectedBackground: c.primaryContainer, selectedColor: c.onPrimaryContainer,
|
|
49
|
+
padding: t.spacing.xs, minHeight: 40,
|
|
50
|
+
},
|
|
51
|
+
radio: {
|
|
52
|
+
borderColor: c.outline, selectedBorderColor: c.primary, dotBackground: c.primary,
|
|
53
|
+
borderRadius: t.radius.full, width: 24, height: 24, dotWidth: 12, dotHeight: 12,
|
|
54
|
+
},
|
|
55
|
+
input: {
|
|
56
|
+
background: c.surface, borderColor: c.outline, borderRadius: t.radius.sm,
|
|
57
|
+
color: c.text, fontSize: ty.bodyLarge.fontSize,
|
|
58
|
+
},
|
|
59
|
+
inputError: { color: c.error, fontSize: ty.caption.fontSize },
|
|
60
|
+
// Code block (tutorial round, 2026-11-13): the editor surface,
|
|
61
|
+
// dark in both themes by design.
|
|
62
|
+
code: {
|
|
63
|
+
background: c.codeSurface, color: c.codeText,
|
|
64
|
+
borderRadius: t.radius.md, fontSize: ty.body.fontSize,
|
|
65
|
+
},
|
|
66
|
+
sheet: { background: c.surface, borderRadius: t.radius.xl },
|
|
67
|
+
dialog: { background: c.surface, borderRadius: t.radius.xl },
|
|
68
|
+
picker: {
|
|
69
|
+
background: c.surface, borderColor: c.outline, borderRadius: t.radius.sm,
|
|
70
|
+
color: c.text, fontSize: ty.bodyLarge.fontSize,
|
|
71
|
+
},
|
|
72
|
+
wheel: { color: c.text, mutedColor: c.textMuted, borderColor: c.border },
|
|
73
|
+
// Data display (Stage 11): the badge dot role is badgeDot (the
|
|
74
|
+
// badge role above stays the showcase pill's).
|
|
75
|
+
tabs: {
|
|
76
|
+
borderColor: c.border, color: c.textMuted,
|
|
77
|
+
selectedColor: c.primary, indicatorBackground: c.primary, minHeight: 48,
|
|
78
|
+
},
|
|
79
|
+
panel: {
|
|
80
|
+
borderColor: c.border, titleColor: c.text, subtitleColor: c.textMuted,
|
|
81
|
+
fontSize: ty.body.fontSize, minHeight: 48,
|
|
82
|
+
},
|
|
83
|
+
table: {
|
|
84
|
+
borderColor: c.border, color: c.text,
|
|
85
|
+
headColor: c.textMuted, headFontSize: ty.label.fontSize, fontSize: ty.body.fontSize,
|
|
86
|
+
},
|
|
87
|
+
slider: {
|
|
88
|
+
trackBackground: c.surfaceVariant, fillBackground: c.primary,
|
|
89
|
+
thumbBackground: c.primary, borderRadius: t.radius.full, height: 4, thumbSize: 20,
|
|
90
|
+
},
|
|
91
|
+
progress: {
|
|
92
|
+
trackBackground: c.surfaceVariant, fillBackground: c.primary,
|
|
93
|
+
borderRadius: t.radius.full, height: 4,
|
|
94
|
+
},
|
|
95
|
+
spinner: { color: c.primary, size: 24 },
|
|
96
|
+
chip: {
|
|
97
|
+
background: c.surfaceVariant, borderColor: c.border, color: c.text,
|
|
98
|
+
borderRadius: t.radius.full, fontSize: ty.label.fontSize,
|
|
99
|
+
},
|
|
100
|
+
badgeDot: {
|
|
101
|
+
background: c.error, color: c.onError,
|
|
102
|
+
borderRadius: t.radius.full, fontSize: ty.caption.fontSize, fontWeight: 700, minWidth: 18, height: 18,
|
|
103
|
+
},
|
|
104
|
+
// Stage 14 roles: the components the audit found missing.
|
|
105
|
+
divider: { borderColor: c.border },
|
|
106
|
+
menu: { background: c.surface, borderRadius: t.radius.md },
|
|
107
|
+
menuItem: { color: c.text, fontSize: ty.body.fontSize, minHeight: 48 },
|
|
108
|
+
drawer: { background: c.surface },
|
|
109
|
+
select: { background: c.surface, borderColor: c.outline, borderRadius: t.radius.sm, minHeight: 48 },
|
|
110
|
+
stepper: { activeBackground: c.primary, activeColor: c.onPrimary, doneBackground: c.primaryContainer, borderColor: c.outline },
|
|
111
|
+
gridTile: { background: c.surfaceVariant, borderRadius: t.radius.lg, padding: t.spacing.md },
|
|
112
|
+
treeNode: { color: c.text, fontSize: ty.body.fontSize, minHeight: 40 },
|
|
113
|
+
textDisplay: { fontSize: ty.display.fontSize, lineHeight: ty.display.lineHeight, fontWeight: 700 },
|
|
114
|
+
textHeading: { fontSize: ty.heading.fontSize, lineHeight: ty.heading.lineHeight, fontWeight: 700 },
|
|
115
|
+
textTitle: { fontSize: ty.title.fontSize, lineHeight: ty.title.lineHeight, fontWeight: 600 },
|
|
116
|
+
textBody: { fontSize: ty.bodyLarge.fontSize, lineHeight: ty.bodyLarge.lineHeight, color: c.text },
|
|
117
|
+
textLabel: { fontSize: ty.label.fontSize, lineHeight: ty.label.lineHeight, fontWeight: 600 },
|
|
118
|
+
// Stage 15 roles: the beyond-Angular pieces. Token values
|
|
119
|
+
// only, mirroring the primitive styles of the same names.
|
|
120
|
+
bottomNav: { background: c.surface, borderColor: c.border },
|
|
121
|
+
navItem: { color: c.textMuted, selectedColor: c.primary, fontSize: ty.caption.fontSize },
|
|
122
|
+
skeleton: { background: c.surfaceVariant, borderRadius: t.radius.lg },
|
|
123
|
+
swipeAction: { background: c.primary, color: c.onPrimary, width: 72 },
|
|
124
|
+
rating: { color: c.primary, size: 28 },
|
|
125
|
+
otp: {
|
|
126
|
+
borderColor: c.outline, activeBorderColor: c.primary, borderRadius: t.radius.sm,
|
|
127
|
+
width: 44, height: 52, fontSize: ty.heading.fontSize,
|
|
128
|
+
},
|
|
129
|
+
carousel: { dotBackground: c.border, activeDotBackground: c.primary, dotSize: 8 },
|
|
130
|
+
timeline: { dotBackground: c.primary, lineBackground: c.border, dotSize: 12 },
|
|
131
|
+
calendar: {
|
|
132
|
+
selectedBackground: c.primary, selectedColor: c.onPrimary,
|
|
133
|
+
todayColor: c.primary, fontSize: ty.body.fontSize,
|
|
134
|
+
},
|
|
135
|
+
avatarFace: { background: c.avatar, color: c.onAvatar },
|
|
136
|
+
avatarGroup: { ringColor: c.background, overlap: -10 },
|
|
137
|
+
emptyState: { iconBackground: c.surfaceVariant, titleColor: c.text, textColor: c.textMuted },
|
|
138
|
+
editor: { borderColor: c.border, background: c.surface, minHeight: 96 },
|
|
139
|
+
image: { borderRadius: t.radius.md },
|
|
140
|
+
lightbox: { closeBackground: c.surface, closeColor: c.text },
|
|
141
|
+
colorPicker: { borderColor: c.outline, borderRadius: t.radius.sm, swatchSize: 44 },
|
|
142
|
+
breadcrumbs: { color: c.primary, currentColor: c.text, separatorColor: c.textMuted },
|
|
143
|
+
chart: { labelColor: c.textMuted, labelFontSize: 12 },
|
|
144
|
+
masonry: { gap: t.spacing.sm },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Element tag to the roles it exercises in the preview. */
|
|
148
|
+
function rolesForElement(el) {
|
|
149
|
+
switch (el.tag) {
|
|
150
|
+
case 'screen': return ['screen'];
|
|
151
|
+
case 'appbar': return ['appbar', 'avatar'];
|
|
152
|
+
case 'card': return ['card'];
|
|
153
|
+
case 'button': return ['button'];
|
|
154
|
+
case 'list': return ['list'];
|
|
155
|
+
case 'row': {
|
|
156
|
+
const roles = el.booleanAttrs.includes('avatar') ? ['row', 'rowAvatar'] : ['row'];
|
|
157
|
+
if (el.children.some((n) => n.type === 'element' && n.tag === 'row-action'))
|
|
158
|
+
roles.push('swipeAction');
|
|
159
|
+
return roles;
|
|
160
|
+
}
|
|
161
|
+
case 'h1': return ['textDisplay'];
|
|
162
|
+
case 'h2': return ['textHeading'];
|
|
163
|
+
case 'h3': return ['textTitle'];
|
|
164
|
+
case 'p': return ['textBody'];
|
|
165
|
+
case 'label': return ['textLabel'];
|
|
166
|
+
case 'code': return ['code'];
|
|
167
|
+
case 'icon': return ['icon'];
|
|
168
|
+
case 'icon-button': return ['iconButton', 'icon'];
|
|
169
|
+
case 'fab': return ['fab'];
|
|
170
|
+
case 'switch': return ['switch'];
|
|
171
|
+
case 'checkbox': return ['checkbox'];
|
|
172
|
+
case 'switcher': return ['switcher'];
|
|
173
|
+
case 'radio-group': return ['radio'];
|
|
174
|
+
case 'input': return ['input', 'inputError'];
|
|
175
|
+
case 'sheet': return ['sheet'];
|
|
176
|
+
case 'dialog': return ['dialog'];
|
|
177
|
+
case 'datetime-picker': return ['picker', 'wheel'];
|
|
178
|
+
case 'tabs': return ['tabs'];
|
|
179
|
+
case 'panel': return ['panel'];
|
|
180
|
+
case 'table': return ['table'];
|
|
181
|
+
case 'slider': return ['slider'];
|
|
182
|
+
case 'progress-bar': return ['progress'];
|
|
183
|
+
case 'spinner': return ['spinner'];
|
|
184
|
+
case 'chip': return ['chip'];
|
|
185
|
+
case 'divider': return ['divider'];
|
|
186
|
+
case 'menu': return ['menu'];
|
|
187
|
+
case 'menu-item': return ['menuItem'];
|
|
188
|
+
case 'drawer': return ['drawer'];
|
|
189
|
+
case 'select': return ['select'];
|
|
190
|
+
case 'stepper': return ['stepper'];
|
|
191
|
+
case 'grid-tile': return ['gridTile'];
|
|
192
|
+
case 'tree-node': return ['treeNode'];
|
|
193
|
+
case 'span': return el.attrs['class'] === 'badge' ? ['badge'] : [];
|
|
194
|
+
// Stage 15 roles.
|
|
195
|
+
case 'bottom-nav': return ['bottomNav', 'navItem'];
|
|
196
|
+
case 'skeleton': return ['skeleton'];
|
|
197
|
+
case 'rating': return ['rating'];
|
|
198
|
+
case 'otp': return ['otp'];
|
|
199
|
+
case 'carousel': return ['carousel'];
|
|
200
|
+
case 'timeline-item': return ['timeline'];
|
|
201
|
+
case 'calendar': return ['calendar'];
|
|
202
|
+
case 'avatar': return ['avatarFace'];
|
|
203
|
+
case 'avatar-group': return ['avatarGroup', 'avatarFace'];
|
|
204
|
+
case 'empty-state': return ['emptyState'];
|
|
205
|
+
case 'editor': return ['editor', 'input'];
|
|
206
|
+
case 'image': return ['image'];
|
|
207
|
+
case 'lightbox': return ['lightbox'];
|
|
208
|
+
case 'color-picker': return ['colorPicker', 'picker'];
|
|
209
|
+
case 'breadcrumbs': return ['breadcrumbs'];
|
|
210
|
+
case 'chart': return ['chart'];
|
|
211
|
+
case 'grid-list': return el.attrs['mode'] === 'masonry' ? ['masonry', 'gridTile'] : [];
|
|
212
|
+
case 'file-picker': return ['picker'];
|
|
213
|
+
default: return [];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function collectRoles(nodes, into) {
|
|
217
|
+
for (const node of nodes) {
|
|
218
|
+
if (node.type !== 'element')
|
|
219
|
+
continue;
|
|
220
|
+
for (const role of rolesForElement(node))
|
|
221
|
+
into.add(role);
|
|
222
|
+
// A badge on one of the three hosts (Stage 11) exercises the dot.
|
|
223
|
+
if ((node.tag === 'button' || node.tag === 'row' || node.tag === 'icon')
|
|
224
|
+
&& (node.attrs['badge'] !== undefined || node.propBindings.some((b) => b.name === 'badge'))) {
|
|
225
|
+
into.add('badgeDot');
|
|
226
|
+
}
|
|
227
|
+
collectRoles(node.children, into);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function sortedRecord(entries) {
|
|
231
|
+
const out = {};
|
|
232
|
+
for (const [k, v] of entries.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
233
|
+
out[k] = v;
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Build the style snapshot for one compiled example. Deterministic: role
|
|
238
|
+
* and style keys are sorted, so the JSON file is stable byte for byte.
|
|
239
|
+
*/
|
|
240
|
+
function buildStyleSnapshot(example, component, ast, css, children = []) {
|
|
241
|
+
void component;
|
|
242
|
+
const used = new Set();
|
|
243
|
+
collectRoles(ast.children, used);
|
|
244
|
+
const allStyles = {};
|
|
245
|
+
const mergeStyles = (parsed) => {
|
|
246
|
+
for (const [selector, style] of Object.entries(parsed.styles)) {
|
|
247
|
+
allStyles[selector] = { ...(allStyles[selector] ?? {}), ...style };
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
mergeStyles(css);
|
|
251
|
+
for (const child of children) {
|
|
252
|
+
collectRoles(child.ast.children, used);
|
|
253
|
+
mergeStyles(child.css);
|
|
254
|
+
}
|
|
255
|
+
const themes = {};
|
|
256
|
+
for (const mode of ['light', 'dark']) {
|
|
257
|
+
const all = allRoles(mode);
|
|
258
|
+
themes[mode] = {
|
|
259
|
+
roles: sortedRecord([...used].filter((r) => all[r]).map((r) => [r, all[r]])),
|
|
260
|
+
styles: sortedRecord(Object.entries(allStyles)),
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return { example, themes };
|
|
264
|
+
}
|
|
265
|
+
/** Render a snapshot as the committed JSON file content. */
|
|
266
|
+
function renderStyleSnapshot(snapshot) {
|
|
267
|
+
return JSON.stringify(snapshot, null, 2) + '\n';
|
|
268
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ELEMENT_EXTRA_PROPS = exports.CODEGEN_ATTRS = exports.GLOBAL_ATTRS = exports.ELEMENT_PROPS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The template-facing props of every framework element, generated
|
|
6
|
+
* from the primitives by scripts/gen-prop-table (see the catalog).
|
|
7
|
+
* Do not edit by hand: a test re-derives this table from
|
|
8
|
+
* packages/ui/src/primitives.tsx and fails when the two disagree.
|
|
9
|
+
* Event props (onPress, onChange, ...) are absent on purpose: they
|
|
10
|
+
* reach the element through event bindings, not attributes.
|
|
11
|
+
*/
|
|
12
|
+
exports.ELEMENT_PROPS = {
|
|
13
|
+
'accordion': ['style'],
|
|
14
|
+
'actions': ['style'],
|
|
15
|
+
'appbar': ['actionIcon', 'actionIcon2', 'avatar', 'back', 'menu', 'pin', 'progress', 'search', 'title', 'titleAlign', 'tone'],
|
|
16
|
+
'avatar': ['size', 'src', 'style', 'text'],
|
|
17
|
+
'avatar-group': ['max', 'style'],
|
|
18
|
+
'bottom-nav': ['haptic', 'index', 'style'],
|
|
19
|
+
'breadcrumbs': ['style'],
|
|
20
|
+
'button': ['badge', 'color', 'disabled', 'style', 'tooltip', 'variant'],
|
|
21
|
+
'calendar': ['style', 'value'],
|
|
22
|
+
'card': ['style'],
|
|
23
|
+
'carousel': ['index', 'style'],
|
|
24
|
+
'chart': ['data', 'height', 'style', 'type', 'width'],
|
|
25
|
+
'checkbox': ['checked', 'disabled', 'style'],
|
|
26
|
+
'chip': ['icon', 'removable', 'style'],
|
|
27
|
+
'chips': ['style'],
|
|
28
|
+
'code': ['style'],
|
|
29
|
+
'color-picker': ['disabled', 'label', 'placeholder', 'style', 'value'],
|
|
30
|
+
'column': ['header', 'name', 'sortable'],
|
|
31
|
+
'crumb': [],
|
|
32
|
+
'datetime-picker': ['label', 'minuteInterval', 'mode', 'style', 'value'],
|
|
33
|
+
'dialog': ['open', 'style', 'title'],
|
|
34
|
+
'div': ['icon', 'label', 'meta', 'plain', 'style'],
|
|
35
|
+
'divider': ['style'],
|
|
36
|
+
'drawer': ['open', 'style'],
|
|
37
|
+
'editor': ['disabled', 'label', 'placeholder', 'style', 'value'],
|
|
38
|
+
'empty-state': ['icon', 'style', 'text', 'title'],
|
|
39
|
+
'fab': ['label'],
|
|
40
|
+
'file-picker': ['disabled', 'kind', 'label', 'multiple', 'placeholder', 'style'],
|
|
41
|
+
'form': ['icon', 'label', 'meta', 'plain', 'style'],
|
|
42
|
+
'gradient': ['style'],
|
|
43
|
+
'grid-list': ['cols', 'mode', 'style'],
|
|
44
|
+
'grid-tile': ['__widthPct', 'style'],
|
|
45
|
+
'h1': ['style', 'variant'],
|
|
46
|
+
'h2': ['style', 'variant'],
|
|
47
|
+
'h3': ['style', 'variant'],
|
|
48
|
+
'header': ['icon', 'label', 'meta', 'plain', 'style'],
|
|
49
|
+
'icon': ['badge', 'color', 'name', 'size', 'style'],
|
|
50
|
+
'icon-button': ['color', 'name', 'size', 'style', 'tooltip'],
|
|
51
|
+
'image': ['height', 'resize', 'src', 'style', 'width'],
|
|
52
|
+
'input': ['avatarText', 'disabled', 'error', 'keyboardType', 'label', 'leadingIcon', 'mask', 'options', 'pillTone', 'placeholder', 'secure', 'style', 'value', 'variant'],
|
|
53
|
+
'label': ['style', 'variant'],
|
|
54
|
+
'lightbox': ['open', 'src', 'style'],
|
|
55
|
+
'list': ['data', 'haptic', 'keyExtractor', 'refreshing', 'renderItem'],
|
|
56
|
+
'menu': ['open', 'style'],
|
|
57
|
+
'menu-item': ['disabled', 'icon', 'style'],
|
|
58
|
+
'nav-item': ['badge', 'icon', 'label'],
|
|
59
|
+
'option': ['value'],
|
|
60
|
+
'otp': ['disabled', 'length', 'style', 'value'],
|
|
61
|
+
'p': ['style', 'variant'],
|
|
62
|
+
'panel': ['__groupExpanded', '__groupToggle', 'expanded', 'style', 'subtitle', 'title'],
|
|
63
|
+
'progress-bar': ['mode', 'style', 'value'],
|
|
64
|
+
'radio': ['value'],
|
|
65
|
+
'radio-group': ['disabled', 'style', 'value'],
|
|
66
|
+
'rating': ['disabled', 'max', 'style', 'value'],
|
|
67
|
+
'router-outlet': [],
|
|
68
|
+
'row': ['actionIcon', 'avatar', 'avatarText', 'avatarTone', 'badge', 'detail', 'icon', 'lastInList', 'selected', 'subtitle', 'time', 'title', 'tooltip'],
|
|
69
|
+
'row-action': ['color', 'icon', 'label'],
|
|
70
|
+
'screen': ['fade', 'haptic', 'refreshing', 'scrollKey', 'style', 'theme'],
|
|
71
|
+
'section': ['icon', 'label', 'meta', 'plain', 'style'],
|
|
72
|
+
'select': ['disabled', 'label', 'placeholder', 'style', 'value'],
|
|
73
|
+
'sheet': ['open', 'style'],
|
|
74
|
+
'skeleton': ['height', 'shape', 'size', 'style', 'width'],
|
|
75
|
+
'slider': ['disabled', 'max', 'min', 'step', 'style', 'value'],
|
|
76
|
+
'spinner': ['color', 'size', 'style'],
|
|
77
|
+
'step': ['label'],
|
|
78
|
+
'stepper': ['index', 'style'],
|
|
79
|
+
'switch': ['checked', 'color', 'disabled', 'haptic', 'style'],
|
|
80
|
+
'switcher': ['disabled', 'style', 'value'],
|
|
81
|
+
'tab': ['label'],
|
|
82
|
+
'table': ['data', 'emptyText', 'pageSize', 'style'],
|
|
83
|
+
'tabs': ['index', 'style'],
|
|
84
|
+
'timeline': ['style'],
|
|
85
|
+
'timeline-item': ['__last', 'style', 'time', 'title'],
|
|
86
|
+
'tree': ['style'],
|
|
87
|
+
'tree-node': ['expanded', 'label', 'style'],
|
|
88
|
+
};
|
|
89
|
+
/** Attributes the compiler itself consumes, valid on any element. */
|
|
90
|
+
exports.GLOBAL_ATTRS = ['class', 'id'];
|
|
91
|
+
/** Names codegen consumes specially, per the forms and routing passes. */
|
|
92
|
+
exports.CODEGEN_ATTRS = ['formControlName', 'formGroup', 'formGroupName', 'formArrayName', 'ngModel', 'routerLink'];
|
|
93
|
+
/**
|
|
94
|
+
* Names codegen consumes per element, hand-kept because each is read
|
|
95
|
+
* from the attributes by a specific pass (the forms pass reads the
|
|
96
|
+
* validator attributes and ngModelOptions on <input>; the submit pass
|
|
97
|
+
* reads type on <button>; the table pass reads key on <column> as the
|
|
98
|
+
* alias of its name). Each entry traces to a read in generate.ts or
|
|
99
|
+
* template/forms.ts.
|
|
100
|
+
*/
|
|
101
|
+
exports.ELEMENT_EXTRA_PROPS = {
|
|
102
|
+
button: ['type'],
|
|
103
|
+
input: ['type', 'required', 'minlength', 'maxlength', 'pattern', 'email', 'ngModelOptions'],
|
|
104
|
+
textarea: ['required', 'minlength', 'maxlength'],
|
|
105
|
+
select: ['required'],
|
|
106
|
+
column: ['key'],
|
|
107
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUPPORTED_STYLE_PROPERTIES = void 0;
|
|
4
|
+
exports.nearestOnScale = nearestOnScale;
|
|
5
|
+
exports.snapForProp = snapForProp;
|
|
6
|
+
exports.parseCss = parseCss;
|
|
7
|
+
const tokens_1 = require("../../../ui/src/tokens");
|
|
8
|
+
const diagnostics_1 = require("../diagnostics");
|
|
9
|
+
/** RN style properties Rangular's CSS subset supports in Stage 0+1. */
|
|
10
|
+
const SUPPORTED = new Set([
|
|
11
|
+
'color', 'backgroundColor', 'fontSize', 'fontWeight', 'fontStyle', 'lineHeight',
|
|
12
|
+
'letterSpacing', 'textAlign', 'margin', 'marginTop', 'marginBottom', 'marginLeft',
|
|
13
|
+
'marginRight', 'marginHorizontal', 'marginVertical', 'padding', 'paddingTop',
|
|
14
|
+
'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingHorizontal',
|
|
15
|
+
'paddingVertical', 'borderRadius', 'borderWidth', 'borderColor', 'opacity',
|
|
16
|
+
'flex', 'flexDirection', 'alignItems', 'justifyContent', 'gap', 'width', 'height',
|
|
17
|
+
'minWidth', 'minHeight', 'maxWidth', 'maxHeight',
|
|
18
|
+
'top', 'left', 'right', 'bottom',
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* Token snapping (Stage 4, docs/UI_POLISH.md part 1): spacing-like values,
|
|
22
|
+
* border-radius and font sizes resolve to the NEAREST design-token scale
|
|
23
|
+
* value at compile time. An off-scale value still compiles, with the
|
|
24
|
+
* snapped value in the generated StyleSheet, but earns a STYLE_OFF_SCALE
|
|
25
|
+
* warning whose fix names the snapped value. On-scale values (and 0,
|
|
26
|
+
* "no spacing") pass silently. Colours are never snapped.
|
|
27
|
+
*/
|
|
28
|
+
const SPACING_PROPS = new Set([
|
|
29
|
+
'margin', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight',
|
|
30
|
+
'marginHorizontal', 'marginVertical', 'padding', 'paddingTop',
|
|
31
|
+
'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingHorizontal',
|
|
32
|
+
'paddingVertical', 'gap', 'top', 'left', 'right', 'bottom',
|
|
33
|
+
]);
|
|
34
|
+
const RADIUS_PROPS = new Set(['borderRadius']);
|
|
35
|
+
const TYPE_SCALE_SIZES = [...new Set(Object.values(tokens_1.typeScale).map((s) => s.fontSize))].sort((a, b) => a - b);
|
|
36
|
+
const TYPE_STEP_BY_SIZE = new Map(Object.entries(tokens_1.typeScale).map(([name, step]) => [step.fontSize, name]));
|
|
37
|
+
/** Nearest value in an ascending scale; ties resolve to the LOWER value. */
|
|
38
|
+
function nearestOnScale(scale, value) {
|
|
39
|
+
let best = scale[0];
|
|
40
|
+
for (const candidate of scale) {
|
|
41
|
+
if (Math.abs(candidate - value) < Math.abs(best - value))
|
|
42
|
+
best = candidate;
|
|
43
|
+
}
|
|
44
|
+
return best;
|
|
45
|
+
}
|
|
46
|
+
/** The supported CSS property set, exported for doctor and the parity guard. */
|
|
47
|
+
exports.SUPPORTED_STYLE_PROPERTIES = SUPPORTED;
|
|
48
|
+
/**
|
|
49
|
+
* The value the snapper would produce for a property, or undefined when
|
|
50
|
+
* the property is not snapped at all (colours, width, height and friends
|
|
51
|
+
* never snap) or the value is exempt (spacing 0, radius full). Doctor
|
|
52
|
+
* reuses this so its DOC_OFF_SCALE check can never drift from the
|
|
53
|
+
* compiler's own snapping behaviour.
|
|
54
|
+
*/
|
|
55
|
+
function snapForProp(prop, value) {
|
|
56
|
+
if (SPACING_PROPS.has(prop)) {
|
|
57
|
+
if (value === 0)
|
|
58
|
+
return undefined;
|
|
59
|
+
return value < 0 ? -nearestOnScale(tokens_1.spacingScale, -value) : nearestOnScale(tokens_1.spacingScale, value);
|
|
60
|
+
}
|
|
61
|
+
if (RADIUS_PROPS.has(prop)) {
|
|
62
|
+
if (value === 9999)
|
|
63
|
+
return undefined;
|
|
64
|
+
return nearestOnScale(tokens_1.radiusScale.filter((n) => n < 9000), value);
|
|
65
|
+
}
|
|
66
|
+
if (prop === 'fontSize')
|
|
67
|
+
return nearestOnScale(TYPE_SCALE_SIZES, value);
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
function snapValue(prop, rawProp, value, diagnostics) {
|
|
71
|
+
if (typeof value !== 'number')
|
|
72
|
+
return value;
|
|
73
|
+
let scale;
|
|
74
|
+
let scaleName;
|
|
75
|
+
let scaleList;
|
|
76
|
+
if (SPACING_PROPS.has(prop)) {
|
|
77
|
+
if (value === 0)
|
|
78
|
+
return value;
|
|
79
|
+
scale = tokens_1.spacingScale;
|
|
80
|
+
scaleName = 'spacing scale';
|
|
81
|
+
scaleList = tokens_1.spacingScale.join(', ');
|
|
82
|
+
}
|
|
83
|
+
else if (RADIUS_PROPS.has(prop)) {
|
|
84
|
+
if (value === 9999)
|
|
85
|
+
return value; // radius.full, on-scale by definition
|
|
86
|
+
scale = tokens_1.radiusScale.filter((n) => n < 9000);
|
|
87
|
+
scaleName = 'radius scale';
|
|
88
|
+
scaleList = `${scale.join(', ')}, full`;
|
|
89
|
+
}
|
|
90
|
+
else if (prop === 'fontSize') {
|
|
91
|
+
scale = TYPE_SCALE_SIZES;
|
|
92
|
+
scaleName = 'type scale';
|
|
93
|
+
scaleList = TYPE_SCALE_SIZES.map((n) => `${n} (${TYPE_STEP_BY_SIZE.get(n)})`).join(', ');
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
const snapped = value < 0 ? -nearestOnScale(scale, -value) : nearestOnScale(scale, value);
|
|
99
|
+
if (snapped === value)
|
|
100
|
+
return value;
|
|
101
|
+
diagnostics.push((0, diagnostics_1.warning)('STYLE_OFF_SCALE', `${rawProp}: ${value}px is off the ${scaleName}, snapped to ${snapped}`, undefined, undefined, `Use an on-scale value from the ${scaleName} (${scaleList}), e.g. ${rawProp}: ${snapped}px`));
|
|
102
|
+
return snapped;
|
|
103
|
+
}
|
|
104
|
+
function camelCase(prop) {
|
|
105
|
+
return prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
106
|
+
}
|
|
107
|
+
function convertValue(raw) {
|
|
108
|
+
const px = raw.match(/^(-?\d+(?:\.\d+)?)px$/);
|
|
109
|
+
if (px)
|
|
110
|
+
return Number(px[1]);
|
|
111
|
+
if (/^-?\d+(?:\.\d+)?$/.test(raw))
|
|
112
|
+
return Number(raw);
|
|
113
|
+
return raw;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Tiny CSS-subset parser: `selector { prop: value; }` rules for element and
|
|
117
|
+
* .class selectors only. Unsupported properties become warnings, not crashes.
|
|
118
|
+
*/
|
|
119
|
+
function parseCss(cssText) {
|
|
120
|
+
const styles = {};
|
|
121
|
+
const diagnostics = [];
|
|
122
|
+
const text = cssText.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
123
|
+
const ruleRe = /([^{}]+)\{([^{}]*)\}/g;
|
|
124
|
+
let match;
|
|
125
|
+
while ((match = ruleRe.exec(text)) !== null) {
|
|
126
|
+
const selectors = match[1].split(',').map((s) => s.trim()).filter(Boolean);
|
|
127
|
+
const declarations = match[2].split(';').map((d) => d.trim()).filter(Boolean);
|
|
128
|
+
for (const selector of selectors) {
|
|
129
|
+
const isClass = selector.startsWith('.');
|
|
130
|
+
const key = isClass ? selector.slice(1) : selector;
|
|
131
|
+
// Class keys are emitted as StyleSheet property names and object
|
|
132
|
+
// keys in generated code, so they must be plain identifiers, the
|
|
133
|
+
// same discipline element selectors already get below.
|
|
134
|
+
if (isClass && !/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(key)) {
|
|
135
|
+
diagnostics.push((0, diagnostics_1.warning)('CSS_SELECTOR', `Unsupported selector '${selector}', only element and .class selectors are supported`, undefined, undefined, `Rewrite '${selector}' as an element selector (h1) or a single class (.card-note); descendant, id and pseudo selectors are not supported`));
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (!isClass && !/^[a-z][a-z0-9-]*$/i.test(selector)) {
|
|
139
|
+
diagnostics.push((0, diagnostics_1.warning)('CSS_SELECTOR', `Unsupported selector '${selector}', only element and .class selectors are supported`, undefined, undefined, `Rewrite '${selector}' as an element selector (h1) or a single class (.card-note); descendant, id and pseudo selectors are not supported`));
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const styleObj = (styles[key] ??= {});
|
|
143
|
+
for (const decl of declarations) {
|
|
144
|
+
const colon = decl.indexOf(':');
|
|
145
|
+
if (colon === -1) {
|
|
146
|
+
diagnostics.push((0, diagnostics_1.warning)('CSS_DECL', `Malformed declaration '${decl}'`, undefined, undefined, "Write each declaration as 'property: value', e.g. 'color: #5f6368;'"));
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const rawProp = decl.slice(0, colon).trim();
|
|
150
|
+
const rawValue = decl.slice(colon + 1).trim();
|
|
151
|
+
const prop = camelCase(rawProp);
|
|
152
|
+
if (!SUPPORTED.has(prop)) {
|
|
153
|
+
diagnostics.push((0, diagnostics_1.warning)('CSS_UNSUPPORTED', `Unsupported CSS property '${rawProp}' in '${selector}', dropped`, undefined, undefined, `Remove '${rawProp}' or use a supported property (color, background-color, font-size, font-weight, margin/padding, border-radius, border-width/color, opacity, flex, flex-direction, align-items, justify-content, gap, width/height)`));
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
styleObj[prop] = snapValue(prop, rawProp, convertValue(rawValue), diagnostics);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { styles, diagnostics };
|
|
161
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** AST types for Rangular templates. */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.isElement = isElement;
|
|
5
|
+
exports.isText = isText;
|
|
6
|
+
exports.staticText = staticText;
|
|
7
|
+
function isElement(node) {
|
|
8
|
+
return node.type === 'element';
|
|
9
|
+
}
|
|
10
|
+
function isText(node) {
|
|
11
|
+
return node.type === 'text';
|
|
12
|
+
}
|
|
13
|
+
/** The full text of a TextNode if it is purely static, else undefined. */
|
|
14
|
+
function staticText(node) {
|
|
15
|
+
if (node.parts.every((p) => p.type === 'static')) {
|
|
16
|
+
return node.parts.map((p) => p.value).join('');
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|