@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.
Files changed (36) hide show
  1. package/dist/cli/src/cli.js +1229 -0
  2. package/dist/compiler/src/catalog.js +198 -0
  3. package/dist/compiler/src/class/formInit.js +370 -0
  4. package/dist/compiler/src/class/parseComponent.js +430 -0
  5. package/dist/compiler/src/class/parseDirective.js +227 -0
  6. package/dist/compiler/src/class/parseRoutes.js +163 -0
  7. package/dist/compiler/src/codegen/generate.js +3466 -0
  8. package/dist/compiler/src/codegen/methods.js +975 -0
  9. package/dist/compiler/src/codegen/sourceMap.js +77 -0
  10. package/dist/compiler/src/compile.js +775 -0
  11. package/dist/compiler/src/diagnostics.js +113 -0
  12. package/dist/compiler/src/doctor.js +144 -0
  13. package/dist/compiler/src/fix.js +44 -0
  14. package/dist/compiler/src/index.js +38 -0
  15. package/dist/compiler/src/preview/renderPreview.js +7158 -0
  16. package/dist/compiler/src/preview/styleSnapshot.js +268 -0
  17. package/dist/compiler/src/propTable.js +107 -0
  18. package/dist/compiler/src/style/css.js +161 -0
  19. package/dist/compiler/src/template/ast.js +19 -0
  20. package/dist/compiler/src/template/evaluate.js +151 -0
  21. package/dist/compiler/src/template/expr.js +360 -0
  22. package/dist/compiler/src/template/forms.js +80 -0
  23. package/dist/compiler/src/template/literal.js +248 -0
  24. package/dist/compiler/src/template/parser.js +230 -0
  25. package/dist/compiler/src/template/pipes.js +225 -0
  26. package/dist/compiler/src/template/printAst.js +38 -0
  27. package/dist/compiler/src/template/structural.js +51 -0
  28. package/dist/runtime/src/index.js +1197 -0
  29. package/dist/ui/src/chart.js +196 -0
  30. package/dist/ui/src/datetime.js +240 -0
  31. package/dist/ui/src/icons.js +310 -0
  32. package/dist/ui/src/mask.js +103 -0
  33. package/dist/ui/src/palette.js +141 -0
  34. package/dist/ui/src/tokens.js +173 -0
  35. package/package.json +28 -4
  36. package/README.md +0 -3
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ /**
3
+ * Chart geometry (Stage 15), pure TypeScript with no imports: the
4
+ * one small engine the RgChart primitive, the compiler's preview
5
+ * paint and the preview page runtime all share. The page runtime
6
+ * mirrors these functions in plain JavaScript; the two are
7
+ * parity-tested against the same case tables in tests/stage15.test.ts.
8
+ *
9
+ * The data shape is one documented form, an array of label and
10
+ * value pairs:
11
+ *
12
+ * [ { label: 'Mon', value: 12 }, { label: 'Tue', value: 19 } ]
13
+ *
14
+ * A point may carry its own `color` (a hex string); without one it
15
+ * takes the next colour of the palette the caller passes in. The
16
+ * engine returns a model of plain shapes (rects, paths, circles,
17
+ * texts) in a width by height box, and each surface serializes the
18
+ * same model: react-native-svg in the app, inline SVG in both
19
+ * preview renderers. Coordinates are rounded to two decimals in the
20
+ * model itself, so the three serializations agree byte for byte on
21
+ * the geometry.
22
+ *
23
+ * Scope, stated plainly: three chart types (bar, line, pie), one
24
+ * series, no axes lines, no gridlines, no animation, no interaction.
25
+ * Bar and pie values are counts: a negative value reads as 0. A
26
+ * line scales between the data's own minimum and maximum.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.CHART_TYPES = void 0;
30
+ exports.normalizeChartData = normalizeChartData;
31
+ exports.mixHex = mixHex;
32
+ exports.chartModel = chartModel;
33
+ exports.CHART_TYPES = ['bar', 'line', 'pie'];
34
+ /** Coerce unknown input into chart points; anything unusable drops out. */
35
+ function normalizeChartData(data) {
36
+ if (!Array.isArray(data))
37
+ return [];
38
+ const out = [];
39
+ for (const item of data) {
40
+ if (item === null || typeof item !== 'object')
41
+ continue;
42
+ const rec = item;
43
+ const value = Number(rec['value']);
44
+ if (!Number.isFinite(value))
45
+ continue;
46
+ out.push({
47
+ label: rec['label'] === undefined || rec['label'] === null ? '' : String(rec['label']),
48
+ value,
49
+ ...(typeof rec['color'] === 'string' ? { color: rec['color'] } : {}),
50
+ });
51
+ }
52
+ return out;
53
+ }
54
+ function r2(n) {
55
+ return Math.round(n * 100) / 100;
56
+ }
57
+ function colorOf(point, index, palette) {
58
+ return point.color ?? palette[index % Math.max(palette.length, 1)] ?? '#000000';
59
+ }
60
+ /**
61
+ * Mix two #rrggbb colours: `frac` of the second colour into the
62
+ * first. A colour that is not a plain six-digit hex passes
63
+ * through unchanged, so a data colour the mixer cannot read
64
+ * still paints.
65
+ */
66
+ function mixHex(hex, other, frac) {
67
+ const m = /^#([0-9a-fA-F]{6})$/.exec(hex);
68
+ const o = /^#([0-9a-fA-F]{6})$/.exec(other);
69
+ if (!m || !o)
70
+ return hex;
71
+ const a = parseInt(m[1], 16);
72
+ const b = parseInt(o[1], 16);
73
+ const ch = (shift) => Math.round(((a >> shift) & 255) * (1 - frac) + ((b >> shift) & 255) * frac);
74
+ return `#${((1 << 24) + (ch(16) << 16) + (ch(8) << 8) + ch(0)).toString(16).slice(1)}`;
75
+ }
76
+ const LABEL_STRIP = 18;
77
+ const LEGEND_ROW = 18;
78
+ /**
79
+ * Build the shape model for one chart. `width` is the chart's full
80
+ * width; `height` is the plotting height the author asked for (the
81
+ * returned model's height adds the label strip, and for pie the
82
+ * legend rows, below it).
83
+ */
84
+ function chartModel(type, data, width, height, palette, labelColor) {
85
+ const points = normalizeChartData(data);
86
+ const w = Math.max(40, Math.floor(width) || 40);
87
+ const plotH = Math.max(40, Math.floor(height) || 40);
88
+ const shapes = [];
89
+ if (!points.length)
90
+ return { width: w, height: plotH, shapes };
91
+ if (type === 'pie') {
92
+ const total = points.reduce((sum, p) => sum + Math.max(0, p.value), 0);
93
+ const r = Math.min(w, plotH) / 2;
94
+ const cx = w / 2;
95
+ const cy = plotH / 2;
96
+ let angle = -90;
97
+ points.forEach((p, i) => {
98
+ const frac = total > 0 ? Math.max(0, p.value) / total : 0;
99
+ const sweep = frac * 360;
100
+ const fill = colorOf(p, i, palette);
101
+ if (frac > 0) {
102
+ if (frac >= 0.9999) {
103
+ shapes.push({ kind: 'circle', cx: r2(cx), cy: r2(cy), r: r2(r), fill });
104
+ }
105
+ else {
106
+ const a0 = (angle * Math.PI) / 180;
107
+ const a1 = ((angle + sweep) * Math.PI) / 180;
108
+ const x0 = cx + r * Math.cos(a0);
109
+ const y0 = cy + r * Math.sin(a0);
110
+ const x1 = cx + r * Math.cos(a1);
111
+ const y1 = cy + r * Math.sin(a1);
112
+ const large = sweep > 180 ? 1 : 0;
113
+ shapes.push({
114
+ kind: 'path',
115
+ d: `M ${r2(cx)} ${r2(cy)} L ${r2(x0)} ${r2(y0)} A ${r2(r)} ${r2(r)} 0 ${large} 1 ${r2(x1)} ${r2(y1)} Z`,
116
+ fill,
117
+ });
118
+ }
119
+ }
120
+ angle += sweep;
121
+ });
122
+ // The legend lives in the model (one swatch rect and one text
123
+ // per point) so all three surfaces lay it out identically.
124
+ points.forEach((p, i) => {
125
+ const y = plotH + 6 + i * LEGEND_ROW;
126
+ shapes.push({ kind: 'rect', x: 0, y: r2(y), width: 10, height: 10, fill: colorOf(p, i, palette) });
127
+ shapes.push({
128
+ kind: 'text', x: 16, y: r2(y + 10), text: `${p.label} ${p.value}`,
129
+ fill: labelColor, size: 12, anchor: 'start',
130
+ });
131
+ });
132
+ return { width: w, height: plotH + 6 + points.length * LEGEND_ROW, shapes };
133
+ }
134
+ if (type === 'line') {
135
+ let min = Math.min(...points.map((p) => p.value));
136
+ let max = Math.max(...points.map((p) => p.value));
137
+ if (min === max) {
138
+ min -= 1;
139
+ max += 1;
140
+ }
141
+ const stroke = colorOf(points[0], 0, palette);
142
+ const coords = points.map((p, i) => {
143
+ const x = points.length === 1 ? w / 2 : (i * w) / (points.length - 1);
144
+ const y = plotH - ((p.value - min) / (max - min)) * (plotH - 8) - 4;
145
+ return { x: r2(x), y: r2(y) };
146
+ });
147
+ const d = coords.map((c, i) => `${i === 0 ? 'M' : 'L'} ${c.x} ${c.y}`).join(' ');
148
+ shapes.push({ kind: 'path', d, stroke, strokeWidth: 2 });
149
+ coords.forEach((c) => shapes.push({ kind: 'circle', cx: c.x, cy: c.y, r: 3, fill: stroke }));
150
+ points.forEach((p, i) => {
151
+ shapes.push({
152
+ kind: 'text', x: coords[i].x, y: plotH + 14, text: p.label,
153
+ fill: labelColor, size: 12, anchor: 'middle',
154
+ });
155
+ });
156
+ return { width: w, height: plotH + LABEL_STRIP, shapes };
157
+ }
158
+ // bar (the default; an unknown type is a compile error long
159
+ // before the engine sees it, GEN_CHART_TYPE).
160
+ const max = Math.max(1, ...points.map((p) => Math.max(0, p.value)));
161
+ const slot = w / points.length;
162
+ const barW = slot * 0.6;
163
+ points.forEach((p, i) => {
164
+ const v = Math.max(0, p.value);
165
+ const h = (v / max) * (plotH - 4);
166
+ const x = slot * i + slot * 0.2;
167
+ const y = plotH - h;
168
+ const colour = colorOf(p, i, palette);
169
+ if (h > 0) {
170
+ // Frosted glass (Bigyan's pick for the History week chart,
171
+ // 2026-11-24, keeping the per-bar palette colours): the
172
+ // bar's own colour stands at its edge, the body is that
173
+ // colour mixed toward white, and a paler gloss band lies
174
+ // over the top. The top corners round; the base stays
175
+ // square on the axis line.
176
+ const r = Math.min(6, barW / 2, h / 2);
177
+ const top = `M ${r2(x)} ${r2(y + h)} L ${r2(x)} ${r2(y + r)} Q ${r2(x)} ${r2(y)} ${r2(x + r)} ${r2(y)} L ${r2(x + barW - r)} ${r2(y)} Q ${r2(x + barW)} ${r2(y)} ${r2(x + barW)} ${r2(y + r)}`;
178
+ shapes.push({
179
+ kind: 'path', d: `${top} L ${r2(x + barW)} ${r2(y + h)} Z`,
180
+ fill: mixHex(colour, '#ffffff', 0.45), stroke: colour, strokeWidth: 1,
181
+ });
182
+ const gh = Math.max(0, h * 0.45);
183
+ if (gh > 1) {
184
+ shapes.push({
185
+ kind: 'path', d: `${top} L ${r2(x + barW)} ${r2(y + gh)} L ${r2(x)} ${r2(y + gh)} Z`,
186
+ fill: mixHex(colour, '#ffffff', 0.72),
187
+ });
188
+ }
189
+ }
190
+ shapes.push({
191
+ kind: 'text', x: r2(slot * i + slot / 2), y: plotH + 14, text: p.label,
192
+ fill: labelColor, size: 12, anchor: 'middle',
193
+ });
194
+ });
195
+ return { width: w, height: plotH + LABEL_STRIP, shapes };
196
+ }
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ /**
3
+ * Date and time value helpers for the Rangular date-time picker
4
+ * (Stage 10), pure TypeScript with no imports: the value model the
5
+ * RgDateTimePicker primitive, the compiler's preview paint and the
6
+ * preview page runtime all share. The page runtime mirrors these
7
+ * functions in plain JavaScript; the two implementations are
8
+ * parity-tested against the same case tables in tests/stage10.test.ts.
9
+ *
10
+ * The value that crosses the template boundary is an ISO string in
11
+ * local time with no zone suffix, `YYYY-MM-DDTHH:mm:00`, the string
12
+ * form of the parts. A `Date` is also accepted on the way in (a
13
+ * component may hold one), its local fields are read. Composition
14
+ * always produces the ISO string, which is what the picker's
15
+ * `(change)` event emits as `$event`.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MONTH_SHORT = exports.PICKER_MODES = void 0;
19
+ exports.daysInMonth = daysInMonth;
20
+ exports.clampDateTimeParts = clampDateTimeParts;
21
+ exports.parseDateTimeValue = parseDateTimeValue;
22
+ exports.composeDateTimeIso = composeDateTimeIso;
23
+ exports.nowParts = nowParts;
24
+ exports.hour12Of = hour12Of;
25
+ exports.ampmOf = ampmOf;
26
+ exports.formatDateTimeValue = formatDateTimeValue;
27
+ exports.pickerYears = pickerYears;
28
+ exports.pickerMinutes = pickerMinutes;
29
+ exports.dateTimeWheels = dateTimeWheels;
30
+ exports.applyWheelValue = applyWheelValue;
31
+ exports.PICKER_MODES = ['date', 'time', 'datetime'];
32
+ exports.MONTH_SHORT = [
33
+ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
34
+ 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
35
+ ];
36
+ /** Days in a month, leap years handled (1900 is not, 2000 is). */
37
+ function daysInMonth(year, month) {
38
+ const lengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
39
+ if (month === 2) {
40
+ const leap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
41
+ return leap ? 29 : 28;
42
+ }
43
+ return lengths[month - 1] ?? 31;
44
+ }
45
+ /** Clamp parts into range: month 1 to 12, day into its month, hour 0 to 23, minute 0 to 59. */
46
+ function clampDateTimeParts(parts) {
47
+ const month = Math.min(12, Math.max(1, Math.trunc(parts.month) || 1));
48
+ const year = Math.trunc(parts.year) || 2000;
49
+ const day = Math.min(daysInMonth(year, month), Math.max(1, Math.trunc(parts.day) || 1));
50
+ const hour = Math.min(23, Math.max(0, Math.trunc(parts.hour) || 0));
51
+ const minute = Math.min(59, Math.max(0, Math.trunc(parts.minute) || 0));
52
+ return { year, month, day, hour, minute };
53
+ }
54
+ function pad2(n) {
55
+ return n < 10 ? `0${n}` : `${n}`;
56
+ }
57
+ const ISO_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d+)?)?)?\s*(?:Z)?$/;
58
+ /**
59
+ * Parse a picker value (an ISO string as produced here, a date-only
60
+ * ISO string, or a Date) into parts. Returns null for anything else,
61
+ * including out-of-range fields like month 13 or February 30.
62
+ */
63
+ function parseDateTimeValue(value) {
64
+ if (value instanceof Date) {
65
+ if (Number.isNaN(value.getTime()))
66
+ return null;
67
+ return {
68
+ year: value.getFullYear(),
69
+ month: value.getMonth() + 1,
70
+ day: value.getDate(),
71
+ hour: value.getHours(),
72
+ minute: value.getMinutes(),
73
+ };
74
+ }
75
+ if (typeof value !== 'string')
76
+ return null;
77
+ const m = ISO_RE.exec(value.trim());
78
+ if (!m)
79
+ return null;
80
+ const parts = {
81
+ year: Number(m[1]),
82
+ month: Number(m[2]),
83
+ day: Number(m[3]),
84
+ hour: m[4] === undefined ? 0 : Number(m[4]),
85
+ minute: m[5] === undefined ? 0 : Number(m[5]),
86
+ };
87
+ if (parts.month < 1 || parts.month > 12)
88
+ return null;
89
+ if (parts.day < 1 || parts.day > daysInMonth(parts.year, parts.month))
90
+ return null;
91
+ if (parts.hour < 0 || parts.hour > 23 || parts.minute < 0 || parts.minute > 59)
92
+ return null;
93
+ return parts;
94
+ }
95
+ /** Compose parts into the ISO string form the picker emits. */
96
+ function composeDateTimeIso(parts) {
97
+ const p = clampDateTimeParts(parts);
98
+ return `${p.year}-${pad2(p.month)}-${pad2(p.day)}T${pad2(p.hour)}:${pad2(p.minute)}:00`;
99
+ }
100
+ /** The current local date and time as parts (the picker's fallback value). */
101
+ function nowParts() {
102
+ const d = new Date();
103
+ return {
104
+ year: d.getFullYear(),
105
+ month: d.getMonth() + 1,
106
+ day: d.getDate(),
107
+ hour: d.getHours(),
108
+ minute: d.getMinutes(),
109
+ };
110
+ }
111
+ /** The 12-hour clock hour of parts (1 to 12); iOS wheels use this form. */
112
+ function hour12Of(parts) {
113
+ const h = parts.hour % 12;
114
+ return h === 0 ? 12 : h;
115
+ }
116
+ /** 'AM' or 'PM' for parts. */
117
+ function ampmOf(parts) {
118
+ return parts.hour < 12 ? 'AM' : 'PM';
119
+ }
120
+ /**
121
+ * The field display text of a value, the same text in the generated
122
+ * app and the preview: `Nov 13, 2026` for date mode, `9:00 AM` for
123
+ * time mode, both joined for datetime mode.
124
+ */
125
+ function formatDateTimeValue(parts, mode) {
126
+ const p = clampDateTimeParts(parts);
127
+ const date = `${exports.MONTH_SHORT[p.month - 1]} ${p.day}, ${p.year}`;
128
+ const time = `${hour12Of(p)}:${pad2(p.minute)} ${ampmOf(p)}`;
129
+ if (mode === 'date')
130
+ return date;
131
+ if (mode === 'time')
132
+ return time;
133
+ return `${date} ${time}`;
134
+ }
135
+ /** The year wheel of date mode: a FIXED range, 150 years either
136
+ * side of the current year (301 entries), extended only to
137
+ * include the value's year when that lies outside it. The range
138
+ * never follows the pending value. A value-centred list rebuilt
139
+ * itself under the scroll offset on every selection, so the
140
+ * year wheel jumped several years per flick and could move
141
+ * against the scroll direction (his phone report, 2026-11-20).
142
+ * A fixed list makes one notch exactly one year. */
143
+ function pickerYears(valueYear, todayYear) {
144
+ const start = Math.min(todayYear - 150, valueYear);
145
+ const end = Math.max(todayYear + 150, valueYear);
146
+ const years = [];
147
+ for (let y = start; y <= end; y++)
148
+ years.push(y);
149
+ return years;
150
+ }
151
+ /** The minute wheel values for a minute interval (1 or 5 in this version). */
152
+ function pickerMinutes(minuteInterval) {
153
+ const step = minuteInterval === 5 ? 5 : 1;
154
+ const minutes = [];
155
+ for (let m = 0; m < 60; m += step)
156
+ minutes.push(m);
157
+ return minutes;
158
+ }
159
+ /**
160
+ * The wheels of one picker mode for a pending value:
161
+ * - date: year, month, day wheels;
162
+ * - time: hour (1 to 12), minute, AM/PM wheels, the iOS form;
163
+ * - datetime: the same year, month and day wheels, then hour,
164
+ * minute and AM/PM wheels. The picker shows them in two separate
165
+ * steps, date first, time second (the overhaul of 2026-11-20: a
166
+ * single combined day list scrolled wildly and gave no precise
167
+ * control; separate wheels are the Apple Calendar form).
168
+ */
169
+ function dateTimeWheels(parts, mode, minuteInterval) {
170
+ const p = clampDateTimeParts(parts);
171
+ const wheels = [];
172
+ if (mode === 'date' || mode === 'datetime') {
173
+ // Order is year, month, day (his word, 2026-11-20).
174
+ wheels.push({
175
+ name: 'year',
176
+ options: pickerYears(p.year, new Date().getFullYear()).map((y) => ({ value: `${y}`, label: `${y}` })),
177
+ value: `${p.year}`,
178
+ });
179
+ wheels.push({
180
+ name: 'month',
181
+ options: exports.MONTH_SHORT.map((label, i) => ({ value: `${i + 1}`, label })),
182
+ value: `${p.month}`,
183
+ });
184
+ const days = [];
185
+ for (let d = 1; d <= daysInMonth(p.year, p.month); d++)
186
+ days.push({ value: `${d}`, label: `${d}` });
187
+ wheels.push({ name: 'day', options: days, value: `${p.day}` });
188
+ }
189
+ if (mode === 'time' || mode === 'datetime') {
190
+ const hours = [];
191
+ for (let h = 1; h <= 12; h++)
192
+ hours.push({ value: `${h}`, label: `${h}` });
193
+ wheels.push({ name: 'hour', options: hours, value: `${hour12Of(p)}` });
194
+ // A value between steps (9:03 with a 5 minute interval) selects
195
+ // the nearest step, the way the iOS wheel settles; picking any
196
+ // step then sets the minute exactly.
197
+ const step = minuteInterval === 5 ? 5 : 1;
198
+ const snappedMinute = Math.min(60 - step, Math.round(p.minute / step) * step);
199
+ wheels.push({
200
+ name: 'minute',
201
+ options: pickerMinutes(minuteInterval).map((m) => ({ value: `${m}`, label: pad2(m) })),
202
+ value: `${snappedMinute}`,
203
+ });
204
+ wheels.push({
205
+ name: 'ampm',
206
+ options: [{ value: 'AM', label: 'AM' }, { value: 'PM', label: 'PM' }],
207
+ value: ampmOf(p),
208
+ });
209
+ }
210
+ return wheels;
211
+ }
212
+ /**
213
+ * Apply one wheel selection to a pending value and return the new
214
+ * pending value. Day clamps into its month (January 31 to February
215
+ * becomes February 28 or 29); hour and AM/PM compose the 24-hour
216
+ * hour between them.
217
+ */
218
+ function applyWheelValue(parts, wheel, value) {
219
+ const p = clampDateTimeParts(parts);
220
+ switch (wheel) {
221
+ case 'month': return clampDateTimeParts({ ...p, month: Number(value) });
222
+ case 'day': return clampDateTimeParts({ ...p, day: Number(value) });
223
+ case 'year': return clampDateTimeParts({ ...p, year: Number(value) });
224
+ case 'hour': {
225
+ const h12 = Number(value);
226
+ if (!Number.isFinite(h12))
227
+ return p;
228
+ return { ...p, hour: (h12 % 12) + (p.hour >= 12 ? 12 : 0) };
229
+ }
230
+ case 'minute': return { ...p, minute: Number(value) || 0 };
231
+ case 'ampm': {
232
+ const wantPm = value === 'PM';
233
+ const isPm = p.hour >= 12;
234
+ if (wantPm === isPm)
235
+ return p;
236
+ return { ...p, hour: wantPm ? p.hour + 12 : p.hour - 12 };
237
+ }
238
+ default: return p;
239
+ }
240
+ }