@typecad/ui 1.0.0-alpha.13 → 1.0.0-alpha.15

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 (60) hide show
  1. package/README.md +1457 -1469
  2. package/dist/cli.js +22 -19
  3. package/dist/preview/host-ui-runtime.js +0 -1
  4. package/dist/ui-engine/model.js +7 -1
  5. package/dist/ui-engine/runtime-header/canvas-scrollbar.js +115 -115
  6. package/dist/ui-engine/runtime-header/dirty-scroll-mutators.js +182 -182
  7. package/dist/ui-engine/runtime-header/forward-decls.js +227 -216
  8. package/dist/ui-engine/runtime-header/init-press-input.js +138 -138
  9. package/dist/ui-engine/runtime-header/keyboard.js +676 -676
  10. package/dist/ui-engine/runtime-header/node-draw-body.js +1658 -1656
  11. package/dist/ui-engine/runtime-header/paint-order-coords.js +259 -259
  12. package/dist/ui-engine/runtime-header/paint-rects-repair.js +736 -736
  13. package/dist/ui-engine/runtime-header/scroll-physics.js +4 -4
  14. package/dist/ui-engine/runtime-header/structs.js +228 -228
  15. package/dist/ui-engine/runtime-header/text-rendering.js +888 -888
  16. package/dist/ui-engine/runtime-header/tick/bindings-phase.js +118 -118
  17. package/dist/ui-engine/runtime-header/tick/dirty-draw-phase.js +896 -896
  18. package/dist/ui-engine/runtime-header/tick/scroll-canvas-phase.js +24 -24
  19. package/dist/ui-engine/runtime-header/touch-keyboard-fwd.js +11 -11
  20. package/dist/ui-engine/runtime-header/types-defines.js +110 -110
  21. package/dist/ui-engine/shadcn-kit.d.ts +1 -1
  22. package/dist/ui-engine/shadcn-kit.js +4 -0
  23. package/dist/ui-engine/ui-lowering.d.ts +1 -1
  24. package/dist/ui-engine/ui-lowering.js +14 -5
  25. package/dist/ui-engine/ui-registry.js +9 -1
  26. package/dist/wizard/display-catalog.d.ts +0 -3
  27. package/dist/wizard/display-catalog.js +3 -12
  28. package/dist/wizard/index.d.ts +2 -0
  29. package/dist/wizard/index.js +1 -0
  30. package/dist/wizard/integration-wizard.d.ts +3 -0
  31. package/dist/wizard/integration-wizard.js +69 -20
  32. package/dist/wizard/package-writer.d.ts +20 -0
  33. package/dist/wizard/package-writer.js +79 -0
  34. package/package.json +4 -4
  35. package/src/cli.ts +90 -87
  36. package/src/preview/host-ui-runtime.ts +0 -1
  37. package/src/ui-engine/model.ts +6 -1
  38. package/src/ui-engine/runtime-header/canvas-scrollbar.ts +121 -121
  39. package/src/ui-engine/runtime-header/dirty-scroll-mutators.ts +188 -188
  40. package/src/ui-engine/runtime-header/forward-decls.ts +238 -227
  41. package/src/ui-engine/runtime-header/init-press-input.ts +144 -144
  42. package/src/ui-engine/runtime-header/keyboard.ts +689 -689
  43. package/src/ui-engine/runtime-header/node-draw-body.ts +1683 -1681
  44. package/src/ui-engine/runtime-header/paint-order-coords.ts +265 -265
  45. package/src/ui-engine/runtime-header/paint-rects-repair.ts +742 -742
  46. package/src/ui-engine/runtime-header/scroll-physics.ts +4 -4
  47. package/src/ui-engine/runtime-header/structs.ts +234 -234
  48. package/src/ui-engine/runtime-header/text-rendering.ts +894 -894
  49. package/src/ui-engine/runtime-header/tick/bindings-phase.ts +124 -124
  50. package/src/ui-engine/runtime-header/tick/dirty-draw-phase.ts +902 -902
  51. package/src/ui-engine/runtime-header/tick/scroll-canvas-phase.ts +30 -30
  52. package/src/ui-engine/runtime-header/touch-keyboard-fwd.ts +11 -11
  53. package/src/ui-engine/runtime-header/types-defines.ts +116 -116
  54. package/src/ui-engine/shadcn-kit.ts +4 -0
  55. package/src/ui-engine/ui-lowering.ts +12 -4
  56. package/src/ui-engine/ui-registry.ts +9 -1
  57. package/src/wizard/display-catalog.ts +261 -273
  58. package/src/wizard/index.ts +46 -38
  59. package/src/wizard/integration-wizard.ts +679 -619
  60. package/src/wizard/package-writer.ts +98 -0
@@ -0,0 +1,98 @@
1
+ // ---------------------------------------------------------------------------
2
+ // package.json script writer for the @typecad/ui integration wizard.
3
+ //
4
+ // package.json is plain JSON (no comments, no expressions), so unlike
5
+ // cuttlefish.config.ts (see config-writer.ts) this needs no AST surgery —
6
+ // parse, compare, set, and re-serialize with the 2-space formatting npm and
7
+ // `cuttlefish create` both write. An unchanged script is a no-op: the
8
+ // original text is returned verbatim so a re-run never reformats the file.
9
+ // ---------------------------------------------------------------------------
10
+
11
+ import fs from "node:fs";
12
+ import path from "node:path";
13
+
14
+ const PACKAGE_FILENAME = "package.json";
15
+
16
+ /** Walk up from `startDir` looking for package.json. */
17
+ export function findPackageJson(startDir: string): string | undefined {
18
+ let dir = path.resolve(startDir);
19
+ for (;;) {
20
+ const candidate = path.join(dir, PACKAGE_FILENAME);
21
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
22
+ return candidate;
23
+ }
24
+ const parent = path.dirname(dir);
25
+ if (parent === dir) return undefined;
26
+ dir = parent;
27
+ }
28
+ }
29
+
30
+ function parsePackageJson(sourceText: string): Record<string, unknown> {
31
+ try {
32
+ return JSON.parse(sourceText) as Record<string, unknown>;
33
+ } catch (err) {
34
+ throw new Error(
35
+ `package.json is not valid JSON: ${err instanceof Error ? err.message : String(err)}`,
36
+ );
37
+ }
38
+ }
39
+
40
+ function scriptsOf(pkg: Record<string, unknown>): Record<string, string> | undefined {
41
+ const scripts = pkg.scripts;
42
+ return typeof scripts === "object" && scripts !== null && !Array.isArray(scripts)
43
+ ? (scripts as Record<string, string>)
44
+ : undefined;
45
+ }
46
+
47
+ /** Read a single npm script; undefined when missing. Throws on invalid JSON. */
48
+ export function readPackageScript(sourceText: string, name: string): string | undefined {
49
+ const scripts = scriptsOf(parsePackageJson(sourceText));
50
+ const value = scripts?.[name];
51
+ return typeof value === "string" ? value : undefined;
52
+ }
53
+
54
+ export interface UpsertScriptResult {
55
+ text: string;
56
+ /** false — the script already had this exact command; text is unchanged. */
57
+ changed: boolean;
58
+ /** The command that was replaced, when a different script existed. */
59
+ previous?: string;
60
+ }
61
+
62
+ /** Insert or update one npm script, preserving every other key and their order. */
63
+ export function upsertPackageScript(
64
+ sourceText: string,
65
+ name: string,
66
+ command: string,
67
+ ): UpsertScriptResult {
68
+ const pkg = parsePackageJson(sourceText);
69
+ const scripts = scriptsOf(pkg);
70
+ const previous = scripts?.[name];
71
+ if (previous === command) {
72
+ return { text: sourceText, changed: false };
73
+ }
74
+ if (!scripts) {
75
+ pkg.scripts = {};
76
+ }
77
+ (pkg.scripts as Record<string, string>)[name] = command;
78
+ // Keep the file's trailing-newline convention (npm writes LF; a missing
79
+ // final newline stays missing so the diff is one line, not two).
80
+ const eol = sourceText.endsWith("\r\n") ? "\r\n" : sourceText.endsWith("\n") ? "\n" : "";
81
+ return {
82
+ text: `${JSON.stringify(pkg, null, 2)}${eol}`,
83
+ changed: true,
84
+ ...(previous !== undefined ? { previous } : {}),
85
+ };
86
+ }
87
+
88
+ /**
89
+ * The `cuttlefish preview` command the wizard writes as the `preview` npm
90
+ * script. The --config path is made relative to the package.json directory
91
+ * (npm scripts run there), posix-separated, and explicitly ./-prefixed so
92
+ * sibling configs render as `./cuttlefish.config.ts`.
93
+ */
94
+ export function previewScriptCommand(packageJsonPath: string, configPath: string): string {
95
+ let rel = path.relative(path.dirname(packageJsonPath), configPath).split(path.sep).join("/");
96
+ if (!rel.startsWith(".")) rel = `./${rel}`;
97
+ return `cuttlefish preview --config ${rel}`;
98
+ }