@rangular-framework/compiler 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 (68) hide show
  1. package/dist/compiler/src/catalog.d.ts +63 -0
  2. package/dist/compiler/src/catalog.js +198 -0
  3. package/dist/compiler/src/class/formInit.d.ts +119 -0
  4. package/dist/compiler/src/class/formInit.js +370 -0
  5. package/dist/compiler/src/class/parseComponent.d.ts +232 -0
  6. package/dist/compiler/src/class/parseComponent.js +430 -0
  7. package/dist/compiler/src/class/parseDirective.d.ts +42 -0
  8. package/dist/compiler/src/class/parseDirective.js +227 -0
  9. package/dist/compiler/src/class/parseRoutes.d.ts +59 -0
  10. package/dist/compiler/src/class/parseRoutes.js +163 -0
  11. package/dist/compiler/src/codegen/generate.d.ts +166 -0
  12. package/dist/compiler/src/codegen/generate.js +3466 -0
  13. package/dist/compiler/src/codegen/methods.d.ts +148 -0
  14. package/dist/compiler/src/codegen/methods.js +975 -0
  15. package/dist/compiler/src/codegen/sourceMap.d.ts +42 -0
  16. package/dist/compiler/src/codegen/sourceMap.js +77 -0
  17. package/dist/compiler/src/compile.d.ts +101 -0
  18. package/dist/compiler/src/compile.js +775 -0
  19. package/dist/compiler/src/diagnostics.d.ts +37 -0
  20. package/dist/compiler/src/diagnostics.js +113 -0
  21. package/dist/compiler/src/doctor.d.ts +35 -0
  22. package/dist/compiler/src/doctor.js +144 -0
  23. package/dist/compiler/src/fix.d.ts +21 -0
  24. package/dist/compiler/src/fix.js +44 -0
  25. package/dist/compiler/src/index.d.ts +22 -0
  26. package/dist/compiler/src/index.js +38 -0
  27. package/dist/compiler/src/preview/renderPreview.d.ts +101 -0
  28. package/dist/compiler/src/preview/renderPreview.js +7158 -0
  29. package/dist/compiler/src/preview/styleSnapshot.d.ts +36 -0
  30. package/dist/compiler/src/preview/styleSnapshot.js +268 -0
  31. package/dist/compiler/src/propTable.d.ts +22 -0
  32. package/dist/compiler/src/propTable.js +107 -0
  33. package/dist/compiler/src/style/css.d.ts +23 -0
  34. package/dist/compiler/src/style/css.js +161 -0
  35. package/dist/compiler/src/template/ast.d.ts +66 -0
  36. package/dist/compiler/src/template/ast.js +19 -0
  37. package/dist/compiler/src/template/evaluate.d.ts +45 -0
  38. package/dist/compiler/src/template/evaluate.js +151 -0
  39. package/dist/compiler/src/template/expr.d.ts +94 -0
  40. package/dist/compiler/src/template/expr.js +360 -0
  41. package/dist/compiler/src/template/forms.d.ts +42 -0
  42. package/dist/compiler/src/template/forms.js +80 -0
  43. package/dist/compiler/src/template/literal.d.ts +38 -0
  44. package/dist/compiler/src/template/literal.js +248 -0
  45. package/dist/compiler/src/template/parser.d.ts +14 -0
  46. package/dist/compiler/src/template/parser.js +230 -0
  47. package/dist/compiler/src/template/pipes.d.ts +48 -0
  48. package/dist/compiler/src/template/pipes.js +225 -0
  49. package/dist/compiler/src/template/printAst.d.ts +3 -0
  50. package/dist/compiler/src/template/printAst.js +38 -0
  51. package/dist/compiler/src/template/structural.d.ts +27 -0
  52. package/dist/compiler/src/template/structural.js +51 -0
  53. package/dist/runtime/src/index.d.ts +486 -0
  54. package/dist/runtime/src/index.js +1197 -0
  55. package/dist/ui/src/chart.d.ts +81 -0
  56. package/dist/ui/src/chart.js +196 -0
  57. package/dist/ui/src/datetime.d.ts +92 -0
  58. package/dist/ui/src/datetime.js +240 -0
  59. package/dist/ui/src/icons.d.ts +63 -0
  60. package/dist/ui/src/icons.js +310 -0
  61. package/dist/ui/src/mask.d.ts +38 -0
  62. package/dist/ui/src/mask.js +103 -0
  63. package/dist/ui/src/palette.d.ts +66 -0
  64. package/dist/ui/src/palette.js +141 -0
  65. package/dist/ui/src/tokens.d.ts +129 -0
  66. package/dist/ui/src/tokens.js +173 -0
  67. package/package.json +24 -4
  68. package/README.md +0 -3
@@ -0,0 +1,37 @@
1
+ /** A compiler diagnostic. Bad input produces diagnostics, never a thrown exception. */
2
+ export interface Diagnostic {
3
+ severity: 'error' | 'warning';
4
+ code: string;
5
+ message: string;
6
+ /** 1-based line in the offending source, when known. */
7
+ line?: number;
8
+ /** 1-based column in the offending source, when known. */
9
+ column?: number;
10
+ /**
11
+ * The source file the diagnostic belongs to (Stage 5): the template
12
+ * (.html) path for template diagnostics, the .ts path for class
13
+ * diagnostics, and the file holding the styles for style diagnostics.
14
+ * Optional: pipeline stages that do not know the origin leave it unset,
15
+ * and compile.ts fills it in where the origin is known.
16
+ */
17
+ file?: string;
18
+ /**
19
+ * A concrete corrected pattern the author (human or AI) can apply.
20
+ * Stage 2.5: diagnostics teach the fix, not just name the problem.
21
+ */
22
+ fix?: string;
23
+ /**
24
+ * The full list of valid icon names (Stage 7). Only GEN_ICON_UNKNOWN
25
+ * carries it, so a JSON consumer can offer or check the whole set
26
+ * without parsing the human readable message.
27
+ */
28
+ validIcons?: string[];
29
+ }
30
+ export declare function error(code: string, message: string, line?: number, column?: number, fix?: string): Diagnostic;
31
+ export declare function warning(code: string, message: string, line?: number, column?: number, fix?: string): Diagnostic;
32
+ export declare function formatDiagnostic(d: Diagnostic, entryFile?: string): string;
33
+ /**
34
+ * Every diagnostic code the compiler can emit, with its meaning.
35
+ * Single source of truth: the catalog is generated from this list.
36
+ */
37
+ export declare const DIAGNOSTIC_CODES: Record<string, string>;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DIAGNOSTIC_CODES = void 0;
4
+ exports.error = error;
5
+ exports.warning = warning;
6
+ exports.formatDiagnostic = formatDiagnostic;
7
+ function error(code, message, line, column, fix) {
8
+ return { severity: 'error', code, message, line, column, fix };
9
+ }
10
+ function warning(code, message, line, column, fix) {
11
+ return { severity: 'warning', code, message, line, column, fix };
12
+ }
13
+ function formatDiagnostic(d, entryFile) {
14
+ const where = d.line !== undefined ? ` (${d.line}:${d.column ?? 1})` : '';
15
+ // The file is printed only when it differs from the file the user asked
16
+ // about, so single-file output stays as terse as before (Stage 5).
17
+ const fileNote = d.file && d.file !== entryFile ? ` [in ${d.file}]` : '';
18
+ const head = `${d.severity.toUpperCase()} ${d.code}${where}: ${d.message}${fileNote}`;
19
+ return d.fix ? `${head}\n fix: ${d.fix}` : head;
20
+ }
21
+ /**
22
+ * Every diagnostic code the compiler can emit, with its meaning.
23
+ * Single source of truth: the catalog is generated from this list.
24
+ */
25
+ exports.DIAGNOSTIC_CODES = {
26
+ TPL_INTERPOLATION: 'A {{ interpolation in a template is never closed with }}.',
27
+ TPL_TAG: 'A "<" in a template is not followed by a tag name.',
28
+ TPL_UNCLOSED: 'An element is opened but never closed.',
29
+ TPL_ATTR: 'An attribute in a template could not be parsed.',
30
+ TPL_CLOSE: 'A closing tag appears with no matching opening element.',
31
+ TPL_MISMATCH: 'A closing tag does not match the currently open element.',
32
+ TPL_NGFOR: 'The *ngFor microsyntax could not be parsed.',
33
+ TPL_NGFOR_SEGMENT: 'A segment of *ngFor microsyntax is not supported and was ignored.',
34
+ TPL_STRUCTURAL_MULTIPLE: 'An element carries more than one structural directive (*ngIf, *ngFor, ...); only the first is kept and each later one is dropped. One structural directive per element: nest one element inside the other.',
35
+ CLS_NO_COMPONENT: 'No class decorated with @Component was found in the source file.',
36
+ CLS_PARSE: 'The TypeScript source has a syntax error. TypeScript reads on with error recovery, so classes and fields after the error can be silently missing or misread; the compiler reports the parse error itself instead of guessing.',
37
+ GEN_SETTER_COLLISION: 'A component method has the same name as a generated state setter (set + a field name, or a form field touched setter). The generated code would declare the name twice and one would overwrite the other, so the method must be renamed.',
38
+ GEN_IMPORT_CLASSLESS: 'A relative import binds names from a file that declares no component, service, pipe or directive. Exported constants with literal values in such a file are carried into the generated code (0.6.5); any other name used from it would be undefined at run time, so the compiler reports the import instead of dropping it silently.',
39
+ CMP_TEMPLATE: 'The component template could not be resolved (missing inline template and templateUrl).',
40
+ CSS_SELECTOR: 'A CSS selector is not an element or .class selector; the rule was skipped.',
41
+ CSS_DECL: 'A CSS declaration is malformed (expected "property: value").',
42
+ CSS_UNSUPPORTED: 'A CSS property is outside the supported subset; the declaration was dropped.',
43
+ STYLE_OFF_SCALE: 'A spacing, radius or font-size value is off its design-token scale; the generated style uses the nearest on-scale value.',
44
+ GEN_UNKNOWN_TAG: 'A template tag is not a known Rangular block; it was emitted as <View>.',
45
+ TPL_HANDLER: 'A template event binding names a method the component does not have; the handler would fail when the event fires.',
46
+ TPL_NESTED_SCREEN: 'A screen sits inside another screen in the same template; it renders embedded, as a flat themed region with no scroller of its own, so its scroll, refresh and end-reached settings have no effect.',
47
+ GEN_UNKNOWN_PROP: 'An attribute or binding on a known element is not one of that element\'s props; it would be passed through and ignored.',
48
+ GEN_FIELD_REREAD: 'A method assigns a field, reads it, then assigns it again; the read sees the value from before the method ran, not the assigned value.',
49
+ GEN_TIMER_STALE: 'A timer created in ngOnInit or the constructor keeps the first render\'s field values; a callback that reads a component field reads the first value forever, so the display freezes or acts on stale state.',
50
+ GEN_DEEP_MUTATION: 'An assignment into a field\'s insides (an index or a property of the field) changes the data without the generated setter, so the view never re-renders; assign a new array or object to the field instead.',
51
+ GEN_LIST_CONTRACT_CLASH: 'A list that declares both (refresh) and (endReached) keeps only the end-reached contract; its pull-to-refresh never engages.',
52
+ GEN_LIST_DUPLICATE: 'Two lists in one template declare the same scroll contract; a screen lends its refresh and end-reached handling to one list each, and the last one registered wins in silence.',
53
+ GEN_NAV_UNDECLARED: 'A navigate call names a path no route declares; with no wildcard route the tap lands on a blank page.',
54
+ GEN_ROUTER_NO_OUTLET: 'The root component template carries a <screen> and routing is on, but no <router-outlet>; the generated screen reads the current route for its scroll key, and only the outlet creates that route value, so the app throws at startup and shows a blank page.',
55
+ GEN_FIELD: 'A field has a non-literal initializer that cannot be emitted verbatim into the generated component (it references this, or the field is assigned in a method); it is declared as undefined there so the output still compiles. A never-assigned non-literal initializer without this (new Date(), Date.now(), an expression over literals) is emitted verbatim and does not warn.',
56
+ GEN_FIELD_STATE: 'A field is assigned in a method but has a non-literal initializer, so it cannot become useState yet.',
57
+ GEN_SIGNAL_SCOPE: 'A computed() initializer reads something other than signal or computed fields and injected services (a plain field, a method, or anything else on this); the computed value cannot track those, so the field is declared as undefined in the generated component. Read signals and service signals inside computed; derive from plain fields with a method instead.',
58
+ GEN_SIGNAL_EFFECT_CONTEXT: 'effect() is called outside the constructor or ngOnInit; the effect still runs, but it is not destroyed when the component is destroyed, so it keeps running for the life of the app. Create effects in the constructor or ngOnInit so they are destroyed with the component.',
59
+ GEN_NGIF_ELSE_TODO: '*ngIf with else/then microsyntax is not generated yet; the element was emitted unconditionally.',
60
+ GEN_STRUCTURAL_TODO: 'A structural directive other than *ngIf/*ngFor is not supported yet; the element was emitted unconditionally.',
61
+ GEN_CONTROL_NESTING: 'A declaration is nested in the wrong parent; option belongs in switcher or select, radio belongs in radio-group, tab belongs in tabs, column belongs in table, step belongs in stepper, menu-item belongs in menu, grid-tile belongs in grid-list, tree-node belongs in tree or another tree-node, nav-item belongs in bottom-nav, row-action belongs in row, timeline-item belongs in timeline, avatar belongs in avatar-group, and crumb belongs in breadcrumbs, and those groups (plus accordion, which takes panels only, and menu, which also takes dividers) accept only their own declarations.',
62
+ GEN_ICON_UNKNOWN: 'An <icon> names an icon that is not in the Rangular icon set; the JSON form of this diagnostic carries the full valid list in validIcons.',
63
+ GEN_ICON_NAME: 'An <icon> element has no name attribute and no [name] binding, so there is nothing to draw.',
64
+ GEN_ICON_SIZE: 'An <icon> size is off the icon size scale (20, 24, 28); the generated code uses the nearest on-scale size.',
65
+ GEN_NGMODEL_TARGET: 'ngModel (two-way, [ngModel] or (ngModelChange)) is used on an element other than <input>; in this version ngModel binds text inputs only.',
66
+ GEN_NGMODEL_EXPR: 'An ngModel binding does not target a plain component field with a literal initial value, so no write-back or validation state could be generated; the value is bound one way.',
67
+ GEN_FORM_CONTROL: 'A formControlName cannot be bound: the input is not inside a <form> with a [formGroup], the control name is not one of the group\'s controls, or formControlName was written as a [binding] instead of a static attribute.',
68
+ GEN_FORMGROUP_TYPE: 'A [formGroup] binding does not name a field initialised with new FormGroup(...), so the reactive form cannot be wired.',
69
+ GEN_FORM_INITIALIZER: 'A field initialised with a form tree (new FormGroup/FormControl/FormArray(...) or a FormBuilder group/control/array call) uses a shape the preview cannot evaluate (only literal values, Validators references and calls, nested groups and arrays, and builder tuples are supported); the generated app runs the initializer as written.',
70
+ GEN_FORM_ARRAY: 'A formArrayName cannot be bound: it is not inside a <form> with a [formGroup], the name is not one of the group\'s controls, or that control is not a FormArray; or a static formControlName inside a formArrayName container names a row instead of numbering it.',
71
+ GEN_ROUTES_MISSING: 'A template uses <router-outlet> or routerLink, or a component injects Router or ActivatedRoute, but no routes file was resolved: the compiler looks for app.routes.ts next to the root component, or the file named by the CLI --routes flag.',
72
+ GEN_ROUTE_COMPONENT: 'A route entry names a component class that is not an @Component class resolved in this compilation.',
73
+ GEN_ROUTE_DUPLICATE: 'Two route entries declare the same path; matching tries entries in order, so the first one wins and the later one never renders.',
74
+ GEN_ROUTE_UNSUPPORTED: 'A route entry or routing construct uses an Angular routing feature Rangular does not support yet (child routes, guards, resolvers, lazy loading, nested outlets, routerLink on a component tag), or a route entry is not a plain object literal with a string path.',
75
+ GEN_PICKER_MODE: 'A <datetime-picker> mode is not one of the three picker modes (date, time, datetime).',
76
+ GEN_PICKER_PRESENTATION: 'A <datetime-picker> carries a presentation attribute; the picker always opens in a modal and takes no presentation.',
77
+ GEN_BUTTON_COLOR: 'A <button> color is not one of the six colour roles (primary, secondary, danger, warning, success, neutral); the button keeps the primary colour.',
78
+ GEN_SWITCH_COLOR: 'A <switch> color is not one of the two colour roles (primary, success); the switch keeps the primary colour.',
79
+ GEN_CHART_TYPE: 'A <chart> type is not one of the three chart types (bar, line, pie); the chart would draw bars instead.',
80
+ GEN_OTP_LENGTH: 'An <otp> length is outside the supported 4 to 8; the generated control clamps it to the nearest of the two.',
81
+ GEN_PICKER_INTERVAL: 'A <datetime-picker> minuteInterval is not 1 or 5; the generated code uses the nearest of the two.',
82
+ GEN_OVERLAY_OPEN: 'A <sheet>, <dialog>, <menu>, <drawer> or <lightbox> has no [open] binding, so it cannot be opened or closed from the component; it renders statically open.',
83
+ GEN_TOOLTIP_HOST: 'A tooltip attribute or [tooltip] binding sits on an element that cannot host a tooltip in this version (button, row and icon-button can); the tooltip was dropped.',
84
+ GEN_EVENT_ASSIGNMENT: 'An event binding holds an assignment statement (for example (close)="sheetOpen = false"); template event bindings take a method call, never an assignment, so the binding was dropped.',
85
+ GEN_TABLE_COLUMN: 'A <column> has no name attribute (or key alias) naming the row property it displays, so the table cannot read its cells.',
86
+ GEN_SLIDER_RANGE: 'A <slider> range is unusable: min must be below max (an error, checked when both are statically known), and step must be above zero (a warning; the generated code uses 1).',
87
+ GEN_PROGRESS_RANGE: 'A <progress-bar> value is statically known to sit outside 0 to 100; the generated code clamps it into range.',
88
+ GEN_SPINNER_SIZE: 'A <spinner> size is off the icon size scale (20, 24, 28); the generated code uses the nearest on-scale size.',
89
+ GEN_BADGE_HOST: 'A badge attribute or [badge] binding sits on an element that cannot host a badge in this version (button, row, icon and nav-item can); the badge was dropped.',
90
+ GEN_CLASS_BINDING: 'A class binding Rangular cannot honour was dropped: [class] and [ngClass] bind a whole dynamic class value, which cannot be resolved to StyleSheet entries at compile time, and [class.name] only works when the component styles declare that class and the block takes a style. The supported toggle is [class.name]="cond" over a class declared in the component styles; the other working pattern is named classes in the component styles with the plain class attribute, swapped with *ngIf.',
91
+ GEN_STYLE_BINDING: 'A style binding or static style attribute was dropped: [style], [style.prop] (with or without a unit) and [ngStyle] bind raw CSS values, which bypass the token-snapped component styles, and a static style="..." attribute has no StyleSheet entry to attach to. Styles live in the component styles block under a class, applied with the plain class attribute or toggled with [class.name].',
92
+ GEN_ATTR_BINDING: 'An [attr.x] binding was dropped: it targets an HTML attribute, and React Native elements have no arbitrary attributes. Use the plain attribute when the block supports one, or the specific [prop] binding the block documents.',
93
+ GEN_IMPORT_COLLISION: 'A third-party import binding was dropped because its local name is already taken in the generated module: by the same name imported from a different module, or by a name the generated module itself defines (a generated class or component function, or one of its own framework imports). Emitting it would duplicate the name and break the module; the first binding of the name wins.',
94
+ METHOD_UNSUPPORTED: 'A statement in a component method is outside the supported translation subset; it was left as a TODO.',
95
+ CMP_IMPORT_UNRESOLVED: 'A relative import in a compiled file could not be resolved to a source file.',
96
+ CMP_IMPORT_FORM: 'An import = require(...) (or import = Some.Name) declaration sits in a file that contributes classes to the generated module; the generated module is an ES module and cannot carry that form, so the declaration was dropped. Write the import as an ES module import instead.',
97
+ CMP_PATH_ESCAPE: 'A templateUrl, styleUrl or relative import resolved to a file outside the project root; the file was not read.',
98
+ CMP_IMPORT_CYCLE: 'Two or more source files import each other in a cycle; the cycle was broken at the repeated file, whose classes were already registered.',
99
+ CMP_DUP_SELECTOR: 'Two different component classes declare the same selector in one compilation.',
100
+ DI_UNKNOWN_TOKEN: 'A constructor dependency names a type that is not a known @Injectable({ providedIn: \'root\' }) service in this compilation and not a built-in token (HttpClient, Router / ActivatedRoute in a routed app, or SnackBar in a component).',
101
+ DI_CYCLE: 'Injectable services depend on each other in a cycle; container registrations could not be ordered.',
102
+ DOC_HEX_COLOR: 'Doctor: a hex colour literal appears in the component styles instead of a colour role token.',
103
+ DOC_OFF_SCALE: 'Doctor: a spacing, radius or font-size value in the styles is off its design-token scale (the compiler would snap it).',
104
+ DOC_RAW_TEXT: 'Doctor: loose text sits directly inside a container element instead of a text element.',
105
+ DOC_TAP_TARGET: 'Doctor: an element with a (click) binding is sized below the 44 by 44 minimum tap target.',
106
+ DOC_IMG_SIZE: 'Doctor: an image element has no declared width and height.',
107
+ CLI_INIT_NOT_EMPTY: 'The rg init command was pointed at a directory that is not empty.',
108
+ PIPE_UNKNOWN: 'A template uses a pipe that is neither a built-in pipe nor a @Pipe class resolved in this compilation; the JSON form lists the known pipes in the fix.',
109
+ GEN_VALIDATOR_ARG: 'A static minlength or maxlength attribute value is not a plain number; the validator was dropped instead of emitting the text into generated code.',
110
+ DIR_UNSUPPORTED: 'An attribute directive is outside the supported subset (a bracket selector, @Input fields, an ElementRef, and ngOnInit or setter bodies made only of this.el.nativeElement.style.<prop> assignments), or it is used on a host the subset cannot style; the directive applied no styles.',
111
+ PROJECTION_SELECT_UNSUPPORTED: 'An <ng-content> carries a select attribute; multi-slot projection is not supported yet, so the element behaves as the default slot and receives all projected children.',
112
+ CLI_INIT_UNSAFE: 'The rg init target name is not a safe directory name (letters, digits, dot, underscore and hyphen only, and not . or ..); nothing was written.',
113
+ };
@@ -0,0 +1,35 @@
1
+ import { CompileResult } from './compile';
2
+ import { Diagnostic } from './diagnostics';
3
+ /**
4
+ * `rg doctor` (Stage 5): the polish linter from docs/UI_POLISH.md
5
+ * part 4. It reads the same compiled artefacts the compiler produced
6
+ * (template ASTs, parsed styles) plus the raw style texts (for line
7
+ * numbers and the suppression comment), and reports findings as ordinary
8
+ * diagnostics with DOC_ codes. Doctor never changes anything.
9
+ *
10
+ * Severities: DOC_TAP_TARGET is an error (a too-small target is a real
11
+ * usability defect); the rest are warnings.
12
+ *
13
+ * Suppression: a CSS comment containing `doctor: allow-hex` anywhere in
14
+ * a style text disables DOC_HEX_COLOR for that file's styles. It exists
15
+ * for app-specific brand colours that are deliberately not Material
16
+ * roles (the Awaken Me gold in examples/dinacharya-row is the case in
17
+ * point). The suppression is per file and covers hex only.
18
+ */
19
+ export interface DoctorStyleText {
20
+ /** File the style text came from (the .ts for inline styles, else the .css). */
21
+ file: string;
22
+ text: string;
23
+ }
24
+ export interface DoctorInput {
25
+ /** The finished compilation to inspect. */
26
+ result: CompileResult;
27
+ /** Absolute or display path of the entry component file. */
28
+ entryFile: string;
29
+ /** Raw style texts: inline styles plus each resolved styleUrl file. */
30
+ styleTexts: DoctorStyleText[];
31
+ }
32
+ export declare const ALLOW_HEX_MARKER = "doctor: allow-hex";
33
+ /** Style texts for a compilation: inline styles live in the .ts file. */
34
+ export declare function doctorStyleTexts(result: CompileResult, entryFile: string, readFile: (absPath: string) => string | undefined): DoctorStyleText[];
35
+ export declare function runDoctor(input: DoctorInput): Diagnostic[];
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALLOW_HEX_MARKER = void 0;
4
+ exports.doctorStyleTexts = doctorStyleTexts;
5
+ exports.runDoctor = runDoctor;
6
+ const compile_1 = require("./compile");
7
+ const generate_1 = require("./codegen/generate");
8
+ const diagnostics_1 = require("./diagnostics");
9
+ const css_1 = require("./style/css");
10
+ const CONTAINER_TAGS = new Set(['screen', 'card', 'list', 'sheet', 'dialog', 'tab', 'panel']);
11
+ const HEX_RE = /#[0-9a-fA-F]{3,8}\b/g;
12
+ const DECL_RE = /([a-zA-Z-]+)\s*:\s*(-?\d+(?:\.\d+)?)px/g;
13
+ exports.ALLOW_HEX_MARKER = 'doctor: allow-hex';
14
+ function lineAt(text, index) {
15
+ let line = 1;
16
+ for (let i = 0; i < index; i++)
17
+ if (text[i] === '\n')
18
+ line++;
19
+ return line;
20
+ }
21
+ function camelCase(prop) {
22
+ return prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
23
+ }
24
+ /** Style texts for a compilation: inline styles live in the .ts file. */
25
+ function doctorStyleTexts(result, entryFile, readFile) {
26
+ const texts = [];
27
+ const component = result.component;
28
+ if (!component)
29
+ return texts;
30
+ if (component.styles)
31
+ texts.push({ file: entryFile, text: component.styles });
32
+ for (const url of component.styleUrls) {
33
+ const file = (0, compile_1.resolveSiblingPath)(entryFile, url);
34
+ const text = readFile(file);
35
+ if (text !== undefined)
36
+ texts.push({ file, text });
37
+ }
38
+ return texts;
39
+ }
40
+ function runDoctor(input) {
41
+ const { result, entryFile } = input;
42
+ const findings = [];
43
+ const component = result.component;
44
+ if (!component || !result.ast)
45
+ return findings;
46
+ const entryTemplateFile = component.templateUrl
47
+ ? (0, compile_1.resolveSiblingPath)(entryFile, component.templateUrl)
48
+ : entryFile;
49
+ // --- Style text checks: DOC_HEX_COLOR + DOC_OFF_SCALE --------------------
50
+ for (const { file, text } of input.styleTexts) {
51
+ const allowHex = text.includes(exports.ALLOW_HEX_MARKER);
52
+ if (!allowHex) {
53
+ for (const m of text.matchAll(HEX_RE)) {
54
+ findings.push({
55
+ ...(0, diagnostics_1.warning)('DOC_HEX_COLOR', `Hex colour ${m[0]} in styles; raw hex values do not follow the theme`, lineAt(text, m.index ?? 0), undefined, `Use a colour role instead (primary, surface, onSurface, error, and the other roles in @rangular-framework/ui tokens), or, for a deliberate brand colour, add a CSS comment containing "${exports.ALLOW_HEX_MARKER}" to this style text`),
56
+ file,
57
+ });
58
+ }
59
+ }
60
+ for (const m of text.matchAll(DECL_RE)) {
61
+ const rawProp = m[1];
62
+ const value = Number(m[2]);
63
+ const snapped = (0, css_1.snapForProp)(camelCase(rawProp), value);
64
+ if (snapped !== undefined && snapped !== value) {
65
+ findings.push({
66
+ ...(0, diagnostics_1.warning)('DOC_OFF_SCALE', `${rawProp}: ${value}px is off its design-token scale; the compiler snaps it to ${snapped}`, lineAt(text, m.index ?? 0), undefined, `Change ${rawProp} to ${snapped}px so the source says what the generated style will be`),
67
+ file,
68
+ });
69
+ }
70
+ }
71
+ }
72
+ // --- Template checks -------------------------------------------------------
73
+ const styleFor = (el, styles) => {
74
+ const merged = { ...(styles[el.tag] ?? {}) };
75
+ for (const cls of (el.attrs['class'] ?? '').split(/\s+/).filter(Boolean)) {
76
+ Object.assign(merged, styles[cls] ?? {});
77
+ }
78
+ return merged;
79
+ };
80
+ const walk = (nodes, templateFile, styles) => {
81
+ for (const node of nodes) {
82
+ if (node.type !== 'element')
83
+ continue;
84
+ const el = node;
85
+ // DOC_RAW_TEXT: loose text directly inside a container.
86
+ if (CONTAINER_TAGS.has(el.tag)) {
87
+ for (const child of el.children) {
88
+ if (child.type !== 'text')
89
+ continue;
90
+ const loose = child.parts.some((p) => (p.type === 'static' && p.value.trim() !== '') || p.type === 'expr');
91
+ if (loose) {
92
+ findings.push({
93
+ ...(0, diagnostics_1.warning)('DOC_RAW_TEXT', `Loose text sits directly inside <${el.tag}>; on React Native all text must live inside a text element`, child.pos.line, child.pos.column, `Wrap the text in <p>, <span>, <h1> to <h3> or <label> (whichever fits) instead of placing it directly inside <${el.tag}>`),
94
+ file: templateFile,
95
+ });
96
+ }
97
+ }
98
+ }
99
+ // DOC_TAP_TARGET: a (click) element sized below 44 in either dimension.
100
+ if (el.eventBindings.some((ev) => ev.name === 'click')) {
101
+ const style = styleFor(el, styles);
102
+ const width = typeof style.width === 'number' ? style.width : undefined;
103
+ const height = typeof style.height === 'number' ? style.height : undefined;
104
+ const attrWidth = el.attrs['width'] !== undefined ? Number(el.attrs['width']) : undefined;
105
+ const attrHeight = el.attrs['height'] !== undefined ? Number(el.attrs['height']) : undefined;
106
+ const w = width ?? (Number.isFinite(attrWidth) ? attrWidth : undefined);
107
+ const h = height ?? (Number.isFinite(attrHeight) ? attrHeight : undefined);
108
+ if ((w !== undefined && w < 44) || (h !== undefined && h < 44)) {
109
+ findings.push({
110
+ ...(0, diagnostics_1.error)('DOC_TAP_TARGET', `<${el.tag}> has a (click) binding but is sized ${w !== undefined ? `${w}` : '?'} by ${h !== undefined ? `${h}` : '?'}; below the 44 by 44 minimum tap target`, el.pos.line, el.pos.column, 'Give the element width and height of at least 44 (44px or more in its styles) so the tap target is comfortably tappable'),
111
+ file: templateFile,
112
+ });
113
+ }
114
+ }
115
+ walk(el.children, templateFile, styles);
116
+ }
117
+ };
118
+ walk(result.ast.children, entryTemplateFile, result.css?.styles ?? {});
119
+ for (const child of result.children) {
120
+ walk(child.ast.children, child.templateFile ?? entryFile, child.css.styles);
121
+ }
122
+ // DOC_IMG_SIZE: only when an image tag is part of the tag contract.
123
+ // Stage 15 added <image> to TAG_MAP, so this check is live: an
124
+ // <image> must declare width and height so the layout does not
125
+ // jump when the picture lands.
126
+ const imageTags = ['img', 'image'].filter((t) => t in generate_1.TAG_MAP);
127
+ if (imageTags.length) {
128
+ const checkImages = (nodes, templateFile) => {
129
+ for (const node of nodes) {
130
+ if (node.type !== 'element')
131
+ continue;
132
+ if (imageTags.includes(node.tag) && (!node.attrs['width'] || !node.attrs['height'])) {
133
+ findings.push({
134
+ ...(0, diagnostics_1.error)('DOC_IMG_SIZE', `<${node.tag}> has no declared width and height; images must declare their size so layout does not jump`, node.pos.line, node.pos.column, 'Add width and height attributes with the image size in px, e.g. width="120" height="80"'),
135
+ file: templateFile,
136
+ });
137
+ }
138
+ checkImages(node.children, templateFile);
139
+ }
140
+ };
141
+ checkImages(result.ast.children, entryTemplateFile);
142
+ }
143
+ return findings;
144
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The mechanical fixes (verification fortification, 2026-11-26): the
3
+ * repairs whose correct outcome the compiler already knows, applied
4
+ * to source text. Everything here is per-declaration and preserves
5
+ * the rest of the text byte for byte. Anything that needs judgment
6
+ * is never touched; it is reported by the caller instead.
7
+ */
8
+ export interface StyleFix {
9
+ code: 'STYLE_OFF_SCALE' | 'CSS_UNSUPPORTED';
10
+ detail: string;
11
+ }
12
+ /**
13
+ * Rewrite one style text: off-scale numeric values are written back
14
+ * at their snapped value (the same snap the compiler would apply,
15
+ * via snapForProp), and unsupported properties are removed with a
16
+ * comment naming what was taken out and why.
17
+ */
18
+ export declare function fixStyleText(text: string): {
19
+ text: string;
20
+ fixes: StyleFix[];
21
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixStyleText = fixStyleText;
4
+ const css_1 = require("./style/css");
5
+ function camelCase(prop) {
6
+ return prop.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
7
+ }
8
+ /**
9
+ * Rewrite one style text: off-scale numeric values are written back
10
+ * at their snapped value (the same snap the compiler would apply,
11
+ * via snapForProp), and unsupported properties are removed with a
12
+ * comment naming what was taken out and why.
13
+ */
14
+ function fixStyleText(text) {
15
+ const fixes = [];
16
+ const out = text.replace(/([^{}]+)\{([^{}]*)\}/g, (whole, selector, body) => {
17
+ const decls = body.split(';').map((decl) => {
18
+ const m = /^(\s*)([a-zA-Z-]+)(\s*:\s*)(-?\d+(?:\.\d+)?)(px)?(\s*)$/.exec(decl);
19
+ if (!m) {
20
+ const bare = /^(\s*)([a-zA-Z-]+)\s*:/.exec(decl);
21
+ if (bare && !css_1.SUPPORTED_STYLE_PROPERTIES.has(camelCase(bare[2]))) {
22
+ fixes.push({ code: 'CSS_UNSUPPORTED', detail: `removed '${bare[2]}' from '${selector.trim()}'` });
23
+ return `${bare[1]}/* rg fix: removed '${bare[2]}' (CSS_UNSUPPORTED: not a supported property) */`;
24
+ }
25
+ return decl;
26
+ }
27
+ const [, lead, rawProp, mid, numText, px, tail] = m;
28
+ const prop = camelCase(rawProp);
29
+ if (!css_1.SUPPORTED_STYLE_PROPERTIES.has(prop)) {
30
+ fixes.push({ code: 'CSS_UNSUPPORTED', detail: `removed '${rawProp}' from '${selector.trim()}'` });
31
+ return `${lead}/* rg fix: removed '${rawProp}' (CSS_UNSUPPORTED: not a supported property) */${tail}`;
32
+ }
33
+ const value = Number(numText);
34
+ const snapped = (0, css_1.snapForProp)(prop, value);
35
+ if (snapped !== undefined && snapped !== value) {
36
+ fixes.push({ code: 'STYLE_OFF_SCALE', detail: `'${selector.trim()}' ${rawProp}: ${value} -> ${snapped}` });
37
+ return `${lead}${rawProp}${mid}${snapped}${px ?? ''}${tail}`;
38
+ }
39
+ return decl;
40
+ });
41
+ return `${selector}{${decls.join(';')}}`;
42
+ });
43
+ return { text: out, fixes };
44
+ }
@@ -0,0 +1,22 @@
1
+ export * from './diagnostics';
2
+ export * from './template/ast';
3
+ export * from './template/parser';
4
+ export * from './template/printAst';
5
+ export * from './template/expr';
6
+ export * from './template/evaluate';
7
+ export * from './template/pipes';
8
+ export * from './template/literal';
9
+ export * from './template/structural';
10
+ export * from './class/parseComponent';
11
+ export * from './class/parseDirective';
12
+ export * from './class/parseRoutes';
13
+ export * from './style/css';
14
+ export * from './codegen/generate';
15
+ export * from './codegen/methods';
16
+ export * from './preview/renderPreview';
17
+ export * from './preview/styleSnapshot';
18
+ export * from './codegen/sourceMap';
19
+ export * from './doctor';
20
+ export * from './compile';
21
+ export * from './catalog';
22
+ export * from './fix';
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./diagnostics"), exports);
18
+ __exportStar(require("./template/ast"), exports);
19
+ __exportStar(require("./template/parser"), exports);
20
+ __exportStar(require("./template/printAst"), exports);
21
+ __exportStar(require("./template/expr"), exports);
22
+ __exportStar(require("./template/evaluate"), exports);
23
+ __exportStar(require("./template/pipes"), exports);
24
+ __exportStar(require("./template/literal"), exports);
25
+ __exportStar(require("./template/structural"), exports);
26
+ __exportStar(require("./class/parseComponent"), exports);
27
+ __exportStar(require("./class/parseDirective"), exports);
28
+ __exportStar(require("./class/parseRoutes"), exports);
29
+ __exportStar(require("./style/css"), exports);
30
+ __exportStar(require("./codegen/generate"), exports);
31
+ __exportStar(require("./codegen/methods"), exports);
32
+ __exportStar(require("./preview/renderPreview"), exports);
33
+ __exportStar(require("./preview/styleSnapshot"), exports);
34
+ __exportStar(require("./codegen/sourceMap"), exports);
35
+ __exportStar(require("./doctor"), exports);
36
+ __exportStar(require("./compile"), exports);
37
+ __exportStar(require("./catalog"), exports);
38
+ __exportStar(require("./fix"), exports);
@@ -0,0 +1,101 @@
1
+ import { ComponentInfo, DirectiveInfo, PipeInfo, ServiceInfo } from '../class/parseComponent';
2
+ import { DirectiveStyleAssign } from '../class/parseDirective';
3
+ import { ResolvedRoute } from '../class/parseRoutes';
4
+ import { ChildUnitInput } from '../codegen/generate';
5
+ import { TemplateRoot } from '../template/ast';
6
+ /**
7
+ * Stage 3 preview data: the child components and services the compiler
8
+ * resolved through the entry component's imports. Child components render
9
+ * recursively (inputs evaluated in the parent scope, outputs wired to the
10
+ * parent handler), and every component that injects a service sees the
11
+ * same singleton service object, in the server paint and in the page.
12
+ */
13
+ export interface PreviewData {
14
+ children?: ChildUnitInput[];
15
+ services?: ServiceInfo[];
16
+ /**
17
+ * The resolved route table (Stage 9). The server paint renders the
18
+ * initial route (the match for the empty path, redirects followed)
19
+ * into the shell's <router-outlet>; the page runtime navigates.
20
+ */
21
+ routes?: ResolvedRoute[];
22
+ /** Custom @Pipe classes resolved in this compilation (Stage 12). */
23
+ pipes?: PipeInfo[];
24
+ /** Attribute @Directive classes resolved in this compilation (Stage 12). */
25
+ directives?: DirectiveInfo[];
26
+ }
27
+ /**
28
+ * Dev preview renderer (Stage 2: interactive).
29
+ *
30
+ * Renders the same template AST the codegen consumes into a standalone
31
+ * HTML page that mimics the React Native screen, using the Rangular
32
+ * Material tokens. The page is a working preview:
33
+ *
34
+ * - the component's literal field values become a JS `state` object;
35
+ * - its methods are translated (same subset as codegen, state mode) into
36
+ * JS functions that mutate `state` and trigger a re-render;
37
+ * - the template AST is embedded as JSON and re-rendered by a small
38
+ * in-page runtime (parser + evaluator + DOM builder, generated below),
39
+ * so (click) handlers, *ngIf and *ngFor behave like they will in RN.
40
+ *
41
+ * The initial HTML is also server-rendered with the compiler's own
42
+ * expression evaluator, so the page is correct before the script runs.
43
+ * Arbitrary expressions are never executed at compile time beyond the
44
+ * safe AST evaluator, no eval/Function anywhere.
45
+ */
46
+ /** Evaluate a literal initializer (now including nested arrays/objects). */
47
+ export declare function evaluateLiteral(initializer: string): unknown;
48
+ /** The preview state: every field whose initializer is a literal structure. */
49
+ export declare function componentState(component: ComponentInfo): Record<string, unknown>;
50
+ /** Colour role name to CSS variable suffix: onPrimaryContainer -> on-primary-container. */
51
+ export declare function kebabRole(role: string): string;
52
+ /**
53
+ * One icon as inline SVG (Stage 7). The path data is ICON_PATHS itself,
54
+ * the same data RgIcon draws in a generated app through
55
+ * react-native-svg, so the preview and the app show the identical
56
+ * drawing. The fill is currentColor; a colour role wraps the SVG in a
57
+ * span coloured by that role's CSS variable, so the theme toggle
58
+ * recolours icons exactly like every other role.
59
+ */
60
+ export declare function iconSvg(name: string, size: number, colorRole?: string): string;
61
+ /**
62
+ * The spinner arc path (Stage 11): a 270 degree arc in the 24 by 24
63
+ * icon box. This is the same constant RgSpinner exports as
64
+ * SPINNER_ARC in @rangular-framework/ui and the page runtime draws, so all
65
+ * three renderers show the identical arc; a test pins the three
66
+ * copies together.
67
+ */
68
+ export declare const SPINNER_ARC_PATH = "M 12 3 A 9 9 0 1 1 3 12";
69
+ /**
70
+ * The badge display text (Stage 11), mirroring badgeTextOf in
71
+ * @rangular-framework/ui: 0 or empty hides the badge, a number above 99 shows
72
+ * as 99+, a non-numeric string shows as itself; null means no badge.
73
+ */
74
+ export declare function badgeTextOf(value: unknown): string | null;
75
+ /** One resolved directive for the painters: extraction shared with codegen. */
76
+ export interface PreviewDirective {
77
+ attr: string;
78
+ info: DirectiveInfo;
79
+ assignments: DirectiveStyleAssign[];
80
+ unsupported?: string;
81
+ }
82
+ export declare function previewDirectives(directives: DirectiveInfo[] | undefined): PreviewDirective[];
83
+ /** The theme a component declares on its root <screen theme="..."> (default light). */
84
+ export declare function declaredThemeOf(ast: TemplateRoot): 'light' | 'dark';
85
+ export declare function renderPreview(component: ComponentInfo, ast: TemplateRoot, data?: PreviewData): string;
86
+ /**
87
+ * Serialize a value as JSON that is safe to embed in an inline <script>
88
+ * block (security audit, 2026-11-12). Plain JSON.stringify leaves a
89
+ * string like "</script>" untouched, which would end the script block
90
+ * and let a field value inject markup and script into the preview page.
91
+ * Escaping "<" (plus the two JS line terminators) keeps the JSON valid
92
+ * and identical in meaning: the page parses the same values. Values
93
+ * without "<" serialize exactly as before.
94
+ */
95
+ export declare function jsonForScript(value: unknown): string;
96
+ /**
97
+ * The interactive part of the page: serialized template + state + translated
98
+ * methods + a compact in-page runtime (expression parser/evaluator and DOM
99
+ * renderer supporting the same subset as the compiler).
100
+ */
101
+ export declare function previewScript(component: ComponentInfo, ast: TemplateRoot, state: Record<string, unknown>, data?: PreviewData): string;