@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,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Built-in pipes (Stage 12): the canonical implementation.
|
|
4
|
+
*
|
|
5
|
+
* One semantics, three homes: this module is what the compiler's own
|
|
6
|
+
* expression evaluator uses (template/evaluate.ts); the runtime
|
|
7
|
+
* `pipe()` in @rangular-framework/runtime carries the same code for generated
|
|
8
|
+
* apps; and the preview page runtime carries a plain-JS mirror. A
|
|
9
|
+
* parity test in tests/stage12.test.ts runs one case table through
|
|
10
|
+
* all three and fails if they drift.
|
|
11
|
+
*
|
|
12
|
+
* Semantics follow Angular's built-in pipes, narrowed where the brief
|
|
13
|
+
* narrows them (the date token set, the currency symbol set). Values a
|
|
14
|
+
* pipe cannot make sense of pass through unchanged, the identity-safe
|
|
15
|
+
* rule the earlier pipes already used.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.CURRENCY_SYMBOLS = exports.DATE_FORMATS = exports.BUILTIN_PIPES = void 0;
|
|
19
|
+
exports.isBuiltinPipe = isBuiltinPipe;
|
|
20
|
+
exports.parseDigitsInfo = parseDigitsInfo;
|
|
21
|
+
exports.formatNumber = formatNumber;
|
|
22
|
+
exports.toDateValue = toDateValue;
|
|
23
|
+
exports.formatDateValue = formatDateValue;
|
|
24
|
+
exports.asyncSnapshot = asyncSnapshot;
|
|
25
|
+
exports.applyBuiltinPipe = applyBuiltinPipe;
|
|
26
|
+
exports.BUILTIN_PIPES = [
|
|
27
|
+
'uppercase', 'lowercase', 'titlecase', 'json',
|
|
28
|
+
'date', 'number', 'percent', 'currency', 'slice', 'keyvalue', 'async',
|
|
29
|
+
];
|
|
30
|
+
function isBuiltinPipe(name) {
|
|
31
|
+
return exports.BUILTIN_PIPES.includes(name);
|
|
32
|
+
}
|
|
33
|
+
/** Parse Angular's digitsInfo shape: `1.0-2` means minInt.minFrac-maxFrac. */
|
|
34
|
+
function parseDigitsInfo(info, fallback = { minInt: 1, minFrac: 0, maxFrac: 3 }) {
|
|
35
|
+
if (typeof info !== 'string')
|
|
36
|
+
return fallback;
|
|
37
|
+
const m = /^(\d+)\.(\d+)-(\d+)$/.exec(info.trim());
|
|
38
|
+
if (!m)
|
|
39
|
+
return fallback;
|
|
40
|
+
const minInt = Number(m[1]);
|
|
41
|
+
const minFrac = Number(m[2]);
|
|
42
|
+
const maxFrac = Number(m[3]);
|
|
43
|
+
if (maxFrac < minFrac)
|
|
44
|
+
return fallback;
|
|
45
|
+
return { minInt, minFrac, maxFrac };
|
|
46
|
+
}
|
|
47
|
+
/** Format a number with grouping, integer padding and fraction bounds. */
|
|
48
|
+
function formatNumber(value, digits) {
|
|
49
|
+
if (!Number.isFinite(value))
|
|
50
|
+
return String(value);
|
|
51
|
+
const negative = value < 0;
|
|
52
|
+
const fixed = Math.abs(value).toFixed(digits.maxFrac);
|
|
53
|
+
const dot = fixed.indexOf('.');
|
|
54
|
+
let intPart = dot >= 0 ? fixed.slice(0, dot) : fixed;
|
|
55
|
+
let fracPart = dot >= 0 ? fixed.slice(dot + 1) : '';
|
|
56
|
+
while (fracPart.length > digits.minFrac && fracPart.endsWith('0')) {
|
|
57
|
+
fracPart = fracPart.slice(0, -1);
|
|
58
|
+
}
|
|
59
|
+
while (fracPart.length < digits.minFrac)
|
|
60
|
+
fracPart += '0';
|
|
61
|
+
while (intPart.length < digits.minInt)
|
|
62
|
+
intPart = '0' + intPart;
|
|
63
|
+
const grouped = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
64
|
+
return (negative ? '-' : '') + grouped + (fracPart ? '.' + fracPart : '');
|
|
65
|
+
}
|
|
66
|
+
// --- date ---------------------------------------------------------------------
|
|
67
|
+
const MONTH_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
68
|
+
exports.DATE_FORMATS = {
|
|
69
|
+
shortDate: 'M/d/yy',
|
|
70
|
+
mediumDate: 'MMM d, yyyy',
|
|
71
|
+
shortTime: 'h:mm a',
|
|
72
|
+
medium: 'MMM d, yyyy, h:mm:ss a',
|
|
73
|
+
short: 'M/d/yy, h:mm a',
|
|
74
|
+
};
|
|
75
|
+
/** Coerce a pipe input to a Date: Date objects, ISO strings and timestamps. */
|
|
76
|
+
function toDateValue(value) {
|
|
77
|
+
if (value instanceof Date)
|
|
78
|
+
return Number.isNaN(value.getTime()) ? undefined : value;
|
|
79
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
80
|
+
return new Date(value);
|
|
81
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
82
|
+
const d = new Date(value);
|
|
83
|
+
return Number.isNaN(d.getTime()) ? undefined : d;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
const pad2 = (n) => String(n).padStart(2, '0');
|
|
88
|
+
/**
|
|
89
|
+
* Format with the Stage 12 token set: yyyy, yy, MMM, MM, M, dd, d,
|
|
90
|
+
* HH, H, hh, h, mm, ss, a. Local time, like Angular's default (no
|
|
91
|
+
* timezone argument in this version). Longest tokens win.
|
|
92
|
+
*/
|
|
93
|
+
function formatDateValue(d, format = 'mediumDate') {
|
|
94
|
+
format = exports.DATE_FORMATS[format] ?? format;
|
|
95
|
+
const hours = d.getHours();
|
|
96
|
+
const hour12 = hours % 12 === 0 ? 12 : hours % 12;
|
|
97
|
+
const tokens = [
|
|
98
|
+
['yyyy', String(d.getFullYear())],
|
|
99
|
+
['MMM', MONTH_SHORT[d.getMonth()]],
|
|
100
|
+
['yy', pad2(d.getFullYear() % 100)],
|
|
101
|
+
['MM', pad2(d.getMonth() + 1)],
|
|
102
|
+
['dd', pad2(d.getDate())],
|
|
103
|
+
['HH', pad2(hours)],
|
|
104
|
+
['hh', pad2(hour12)],
|
|
105
|
+
['mm', pad2(d.getMinutes())],
|
|
106
|
+
['ss', pad2(d.getSeconds())],
|
|
107
|
+
['M', String(d.getMonth() + 1)],
|
|
108
|
+
['d', String(d.getDate())],
|
|
109
|
+
['H', String(hours)],
|
|
110
|
+
['h', String(hour12)],
|
|
111
|
+
['a', hours < 12 ? 'AM' : 'PM'],
|
|
112
|
+
];
|
|
113
|
+
let out = '';
|
|
114
|
+
let i = 0;
|
|
115
|
+
while (i < format.length) {
|
|
116
|
+
const hit = tokens.find(([tok]) => format.startsWith(tok, i));
|
|
117
|
+
if (hit) {
|
|
118
|
+
out += hit[1];
|
|
119
|
+
i += hit[0].length;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
out += format[i];
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
// --- currency -------------------------------------------------------------------
|
|
129
|
+
/** The Stage 12 symbol table; any other code displays the code itself. */
|
|
130
|
+
exports.CURRENCY_SYMBOLS = {
|
|
131
|
+
USD: '$',
|
|
132
|
+
EUR: '€',
|
|
133
|
+
GBP: '£',
|
|
134
|
+
INR: '₹',
|
|
135
|
+
NPR: 'Rs',
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* The async pipe's pure-evaluator semantics: subscribe, keep whatever
|
|
139
|
+
* arrives synchronously, unsubscribe, return the latest value (null
|
|
140
|
+
* when nothing has arrived yet, which is also Angular's initial
|
|
141
|
+
* value). Live surfaces (generated code, the interactive preview)
|
|
142
|
+
* keep the subscription open across renders; a one-shot pure
|
|
143
|
+
* evaluation cannot, and this is the documented difference.
|
|
144
|
+
*/
|
|
145
|
+
function asyncSnapshot(value) {
|
|
146
|
+
if (value === null || value === undefined)
|
|
147
|
+
return null;
|
|
148
|
+
const sub = value;
|
|
149
|
+
if (typeof sub.subscribe !== 'function')
|
|
150
|
+
return value;
|
|
151
|
+
let latest = null;
|
|
152
|
+
try {
|
|
153
|
+
const handle = sub.subscribe((v) => { latest = v; });
|
|
154
|
+
if (handle && typeof handle.unsubscribe === 'function')
|
|
155
|
+
handle.unsubscribe();
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return latest;
|
|
159
|
+
}
|
|
160
|
+
return latest;
|
|
161
|
+
}
|
|
162
|
+
/** Apply a built-in pipe by name. Unknown names throw, like before. */
|
|
163
|
+
function applyBuiltinPipe(name, value, args) {
|
|
164
|
+
switch (name) {
|
|
165
|
+
case 'uppercase':
|
|
166
|
+
return typeof value === 'string' ? value.toUpperCase() : value;
|
|
167
|
+
case 'lowercase':
|
|
168
|
+
return typeof value === 'string' ? value.toLowerCase() : value;
|
|
169
|
+
case 'titlecase':
|
|
170
|
+
return typeof value === 'string'
|
|
171
|
+
? value.replace(/\w\S*/g, (w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
172
|
+
: value;
|
|
173
|
+
case 'json':
|
|
174
|
+
return JSON.stringify(value);
|
|
175
|
+
case 'date': {
|
|
176
|
+
const d = toDateValue(value);
|
|
177
|
+
if (!d)
|
|
178
|
+
return value;
|
|
179
|
+
const named = typeof args[0] === 'string' ? args[0] : 'mediumDate';
|
|
180
|
+
return formatDateValue(d, named);
|
|
181
|
+
}
|
|
182
|
+
case 'number': {
|
|
183
|
+
if (typeof value !== 'number')
|
|
184
|
+
return value;
|
|
185
|
+
return formatNumber(value, parseDigitsInfo(args[0], { minInt: 1, minFrac: 0, maxFrac: 3 }));
|
|
186
|
+
}
|
|
187
|
+
case 'percent': {
|
|
188
|
+
if (typeof value !== 'number')
|
|
189
|
+
return value;
|
|
190
|
+
return formatNumber(value * 100, parseDigitsInfo(args[0], { minInt: 1, minFrac: 0, maxFrac: 3 })) + '%';
|
|
191
|
+
}
|
|
192
|
+
case 'currency': {
|
|
193
|
+
if (typeof value !== 'number')
|
|
194
|
+
return value;
|
|
195
|
+
const code = typeof args[0] === 'string' && args[0] !== '' ? args[0] : 'USD';
|
|
196
|
+
const display = typeof args[1] === 'string' ? args[1] : 'symbol';
|
|
197
|
+
const digits = parseDigitsInfo(args[2], { minInt: 1, minFrac: 2, maxFrac: 2 });
|
|
198
|
+
const symbol = display === 'code' ? undefined : exports.CURRENCY_SYMBOLS[code];
|
|
199
|
+
const formatted = formatNumber(Math.abs(value), digits);
|
|
200
|
+
const sign = value < 0 ? '-' : '';
|
|
201
|
+
return symbol !== undefined
|
|
202
|
+
? `${sign}${symbol}${formatted}`
|
|
203
|
+
: `${sign}${code} ${formatted}`;
|
|
204
|
+
}
|
|
205
|
+
case 'slice': {
|
|
206
|
+
if (typeof value !== 'string' && !Array.isArray(value))
|
|
207
|
+
return value;
|
|
208
|
+
const start = typeof args[0] === 'number' ? args[0] : 0;
|
|
209
|
+
const end = typeof args[1] === 'number' ? args[1] : undefined;
|
|
210
|
+
return value.slice(start, end);
|
|
211
|
+
}
|
|
212
|
+
case 'keyvalue': {
|
|
213
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
214
|
+
return value;
|
|
215
|
+
const rec = value;
|
|
216
|
+
return Object.keys(rec)
|
|
217
|
+
.map((key) => ({ key, value: rec[key] }))
|
|
218
|
+
.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
|
|
219
|
+
}
|
|
220
|
+
case 'async':
|
|
221
|
+
return asyncSnapshot(value);
|
|
222
|
+
default:
|
|
223
|
+
throw new Error(`Unknown pipe '${name}'`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printAst = printAst;
|
|
4
|
+
/** M0: print a template AST as an indented tree, for eyeballing and tests. */
|
|
5
|
+
function printAst(root) {
|
|
6
|
+
const lines = [];
|
|
7
|
+
const walk = (nodes, depth) => {
|
|
8
|
+
for (const node of nodes) {
|
|
9
|
+
const indent = ' '.repeat(depth);
|
|
10
|
+
if (node.type === 'text') {
|
|
11
|
+
const body = node.parts
|
|
12
|
+
.map((p) => (p.type === 'static' ? p.value : `{{ ${p.expression} }}`))
|
|
13
|
+
.join('');
|
|
14
|
+
lines.push(`${indent}text "${body}"`);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const bits = [`<${node.tag}>`];
|
|
18
|
+
for (const [k, v] of Object.entries(node.attrs))
|
|
19
|
+
bits.push(`${k}="${v}"`);
|
|
20
|
+
for (const b of node.booleanAttrs)
|
|
21
|
+
bits.push(b);
|
|
22
|
+
for (const p of node.propBindings)
|
|
23
|
+
bits.push(`[${p.name}]="${p.expression}"`);
|
|
24
|
+
for (const p of node.twoWayBindings)
|
|
25
|
+
bits.push(`[(${p.name})]="${p.expression}"`);
|
|
26
|
+
for (const e of node.eventBindings)
|
|
27
|
+
bits.push(`(${e.name})="${e.expression}"`);
|
|
28
|
+
if (node.structural)
|
|
29
|
+
bits.push(`*${node.structural.name}="${node.structural.expression}"`);
|
|
30
|
+
if (node.ref)
|
|
31
|
+
bits.push(node.refExport ? `#${node.ref}="${node.refExport}"` : `#${node.ref}`);
|
|
32
|
+
lines.push(indent + bits.join(' '));
|
|
33
|
+
walk(node.children, depth + 1);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
walk(root.children, 0);
|
|
37
|
+
return lines.join('\n');
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseNgIf = parseNgIf;
|
|
4
|
+
exports.parseNgFor = parseNgFor;
|
|
5
|
+
const diagnostics_1 = require("../diagnostics");
|
|
6
|
+
function parseNgIf(expression) {
|
|
7
|
+
const segments = expression.split(';').map((s) => s.trim()).filter(Boolean);
|
|
8
|
+
const parts = { condition: segments[0] ?? '' };
|
|
9
|
+
for (const seg of segments.slice(1)) {
|
|
10
|
+
const elseMatch = /^else\s+(\S+)$/.exec(seg);
|
|
11
|
+
if (elseMatch) {
|
|
12
|
+
parts.elseRef = elseMatch[1];
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const thenMatch = /^then\s+(\S+)$/.exec(seg);
|
|
16
|
+
if (thenMatch) {
|
|
17
|
+
parts.thenRef = thenMatch[1];
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
// Angular also allows `let x` / `as y` segments in ngIf; Stage 2 ignores them.
|
|
21
|
+
}
|
|
22
|
+
return parts;
|
|
23
|
+
}
|
|
24
|
+
function parseNgFor(expression, line, column) {
|
|
25
|
+
const diagnostics = [];
|
|
26
|
+
const segments = expression.split(';').map((s) => s.trim()).filter(Boolean);
|
|
27
|
+
const first = segments[0] ?? '';
|
|
28
|
+
const head = /^let\s+([A-Za-z_$][\w$]*)\s+of\s+(.+)$/.exec(first);
|
|
29
|
+
if (!head) {
|
|
30
|
+
diagnostics.push((0, diagnostics_1.warning)('TPL_NGFOR', `Could not parse *ngFor microsyntax "${expression}", expected "let item of items"`, line, column, 'Use the form *ngFor="let item of items; let i = index" (optionally "; trackBy: trackByFn")'));
|
|
31
|
+
return { diagnostics };
|
|
32
|
+
}
|
|
33
|
+
const parts = { itemVar: head[1], source: head[2].trim(), locals: {} };
|
|
34
|
+
for (const seg of segments.slice(1)) {
|
|
35
|
+
const letMatch = /^let\s+([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)$/.exec(seg);
|
|
36
|
+
if (letMatch) {
|
|
37
|
+
if (letMatch[2] === 'index')
|
|
38
|
+
parts.indexVar = letMatch[1];
|
|
39
|
+
else
|
|
40
|
+
parts.locals[letMatch[1]] = letMatch[2];
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const trackMatch = /^trackBy\s*:\s*(.+)$/.exec(seg);
|
|
44
|
+
if (trackMatch) {
|
|
45
|
+
parts.trackBy = trackMatch[1].trim();
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
diagnostics.push((0, diagnostics_1.warning)('TPL_NGFOR_SEGMENT', `Unsupported *ngFor segment "${seg}", ignored`, line, column, 'Supported segments: "let i = index" and "trackBy: fnName", remove or rewrite this segment'));
|
|
49
|
+
}
|
|
50
|
+
return { parts, diagnostics };
|
|
51
|
+
}
|