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

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 (135) hide show
  1. package/README.md +21 -1
  2. package/assets/fonts/dejavu/DejaVuSans-Bold.ttf +0 -0
  3. package/assets/fonts/dejavu/DejaVuSans-ExtraLight.ttf +0 -0
  4. package/assets/fonts/dejavu/DejaVuSans-Oblique.ttf +0 -0
  5. package/assets/fonts/dejavu/DejaVuSans.ttf +0 -0
  6. package/assets/fonts/dejavu/DejaVuSansMono-Bold.ttf +0 -0
  7. package/assets/fonts/dejavu/DejaVuSansMono.ttf +0 -0
  8. package/assets/fonts/dejavu/LICENSE +187 -0
  9. package/assets/fonts/dejavu/README.md +49 -0
  10. package/dist/cli.d.ts +2 -0
  11. package/dist/cli.js +74 -0
  12. package/dist/engine-index.js +2 -0
  13. package/dist/preview/build-program.d.ts +7 -1
  14. package/dist/preview/build-program.js +94 -15
  15. package/dist/preview/host-gfx.d.ts +3 -0
  16. package/dist/preview/host-gfx.js +30 -3
  17. package/dist/preview/host-ui-runtime.d.ts +115 -0
  18. package/dist/preview/host-ui-runtime.js +928 -46
  19. package/dist/ui-engine/block-layout.js +25 -11
  20. package/dist/ui-engine/color.d.ts +6 -0
  21. package/dist/ui-engine/color.js +80 -2
  22. package/dist/ui-engine/compat-report.d.ts +8 -0
  23. package/dist/ui-engine/compat-report.js +124 -0
  24. package/dist/ui-engine/css-imports.d.ts +4 -0
  25. package/dist/ui-engine/css-imports.js +70 -0
  26. package/dist/ui-engine/css-parser.js +58 -14
  27. package/dist/ui-engine/default-font.d.ts +25 -0
  28. package/dist/ui-engine/default-font.js +80 -0
  29. package/dist/ui-engine/font-assets.d.ts +2 -2
  30. package/dist/ui-engine/font-assets.js +22 -5
  31. package/dist/ui-engine/html-parser.d.ts +4 -0
  32. package/dist/ui-engine/html-parser.js +241 -26
  33. package/dist/ui-engine/image-assets.d.ts +8 -1
  34. package/dist/ui-engine/image-assets.js +35 -2
  35. package/dist/ui-engine/image-decode.d.ts +22 -0
  36. package/dist/ui-engine/image-decode.js +194 -0
  37. package/dist/ui-engine/inline-parser.js +1 -1
  38. package/dist/ui-engine/layout-engine.d.ts +19 -0
  39. package/dist/ui-engine/layout-engine.js +59 -3
  40. package/dist/ui-engine/model.d.ts +18 -0
  41. package/dist/ui-engine/model.js +76 -8
  42. package/dist/ui-engine/runtime-header/blend-bodies.js +29 -9
  43. package/dist/ui-engine/runtime-header/canvas-helpers.js +5 -2
  44. package/dist/ui-engine/runtime-header/canvas-scrollbar.js +115 -111
  45. package/dist/ui-engine/runtime-header/cuttlefish-gfx.js +21 -0
  46. package/dist/ui-engine/runtime-header/dirty-scroll-mutators.js +182 -179
  47. package/dist/ui-engine/runtime-header/forward-decls.js +215 -167
  48. package/dist/ui-engine/runtime-header/init-press-input.js +138 -135
  49. package/dist/ui-engine/runtime-header/keyboard.js +682 -380
  50. package/dist/ui-engine/runtime-header/node-draw-body.js +1656 -1377
  51. package/dist/ui-engine/runtime-header/paint-order-coords.js +259 -214
  52. package/dist/ui-engine/runtime-header/paint-rects-repair.js +736 -568
  53. package/dist/ui-engine/runtime-header/scroll-physics.js +25 -1
  54. package/dist/ui-engine/runtime-header/state-bindings-nav.js +9 -0
  55. package/dist/ui-engine/runtime-header/structs.js +228 -216
  56. package/dist/ui-engine/runtime-header/text-rendering.js +888 -770
  57. package/dist/ui-engine/runtime-header/tick/bindings-phase.js +118 -116
  58. package/dist/ui-engine/runtime-header/tick/dirty-draw-phase.js +897 -633
  59. package/dist/ui-engine/runtime-header/tick/scroll-canvas-phase.js +24 -25
  60. package/dist/ui-engine/runtime-header/touch-keyboard-fwd.js +79 -23
  61. package/dist/ui-engine/runtime-header/types-defines.js +110 -93
  62. package/dist/ui-engine/shadcn-kit.d.ts +1 -0
  63. package/dist/ui-engine/shadcn-kit.js +502 -0
  64. package/dist/ui-engine/style-resolver.d.ts +4 -0
  65. package/dist/ui-engine/style-resolver.js +58 -6
  66. package/dist/ui-engine/transpile-ui.js +12 -5
  67. package/dist/ui-engine/ua-stylesheet.d.ts +22 -1
  68. package/dist/ui-engine/ua-stylesheet.js +119 -32
  69. package/dist/ui-engine/ui-lowering.js +37 -3
  70. package/dist/ui-engine/ui-registry.js +32 -4
  71. package/dist/ui-engine/yoga-layout.js +57 -52
  72. package/dist/wizard/config-writer.d.ts +49 -0
  73. package/dist/wizard/config-writer.js +366 -0
  74. package/dist/wizard/display-catalog.d.ts +75 -0
  75. package/dist/wizard/display-catalog.js +207 -0
  76. package/dist/wizard/index.d.ts +7 -0
  77. package/dist/wizard/index.js +10 -0
  78. package/dist/wizard/integration-wizard.d.ts +15 -0
  79. package/dist/wizard/integration-wizard.js +486 -0
  80. package/dist/wizard/prompts.d.ts +32 -0
  81. package/dist/wizard/prompts.js +95 -0
  82. package/dist/wizard/starter-ui.d.ts +1 -0
  83. package/dist/wizard/starter-ui.js +56 -0
  84. package/package.json +18 -5
  85. package/src/cli.ts +87 -0
  86. package/src/engine-index.ts +53 -51
  87. package/src/preview/build-program.ts +810 -734
  88. package/src/preview/host-gfx.ts +30 -3
  89. package/src/preview/host-ui-runtime.ts +4133 -3289
  90. package/src/ui-engine/block-layout.ts +24 -11
  91. package/src/ui-engine/color.ts +77 -2
  92. package/src/ui-engine/compat-report.ts +139 -0
  93. package/src/ui-engine/css-imports.ts +69 -0
  94. package/src/ui-engine/css-parser.ts +64 -15
  95. package/src/ui-engine/default-font.ts +95 -0
  96. package/src/ui-engine/font-assets.ts +545 -525
  97. package/src/ui-engine/html-parser.ts +615 -397
  98. package/src/ui-engine/image-assets.ts +37 -2
  99. package/src/ui-engine/image-decode.ts +244 -0
  100. package/src/ui-engine/inline-parser.ts +1 -1
  101. package/src/ui-engine/layout-engine.ts +61 -3
  102. package/src/ui-engine/model.ts +1317 -1230
  103. package/src/ui-engine/runtime-header/blend-bodies.ts +29 -9
  104. package/src/ui-engine/runtime-header/canvas-helpers.ts +5 -2
  105. package/src/ui-engine/runtime-header/canvas-scrollbar.ts +121 -117
  106. package/src/ui-engine/runtime-header/cuttlefish-gfx.ts +21 -0
  107. package/src/ui-engine/runtime-header/dirty-scroll-mutators.ts +188 -185
  108. package/src/ui-engine/runtime-header/forward-decls.ts +227 -179
  109. package/src/ui-engine/runtime-header/init-press-input.ts +144 -141
  110. package/src/ui-engine/runtime-header/keyboard.ts +689 -386
  111. package/src/ui-engine/runtime-header/node-draw-body.ts +1681 -1402
  112. package/src/ui-engine/runtime-header/paint-order-coords.ts +265 -220
  113. package/src/ui-engine/runtime-header/paint-rects-repair.ts +742 -574
  114. package/src/ui-engine/runtime-header/scroll-physics.ts +25 -1
  115. package/src/ui-engine/runtime-header/state-bindings-nav.ts +9 -0
  116. package/src/ui-engine/runtime-header/structs.ts +234 -222
  117. package/src/ui-engine/runtime-header/text-rendering.ts +894 -776
  118. package/src/ui-engine/runtime-header/tick/bindings-phase.ts +124 -122
  119. package/src/ui-engine/runtime-header/tick/dirty-draw-phase.ts +902 -638
  120. package/src/ui-engine/runtime-header/tick/scroll-canvas-phase.ts +30 -31
  121. package/src/ui-engine/runtime-header/touch-keyboard-fwd.ts +79 -23
  122. package/src/ui-engine/runtime-header/types-defines.ts +116 -99
  123. package/src/ui-engine/shadcn-kit.ts +503 -0
  124. package/src/ui-engine/style-resolver.ts +471 -416
  125. package/src/ui-engine/transpile-ui.ts +12 -5
  126. package/src/ui-engine/ua-stylesheet.ts +137 -31
  127. package/src/ui-engine/ui-lowering.ts +486 -452
  128. package/src/ui-engine/ui-registry.ts +556 -524
  129. package/src/ui-engine/yoga-layout.ts +307 -309
  130. package/src/wizard/config-writer.ts +404 -0
  131. package/src/wizard/display-catalog.ts +273 -0
  132. package/src/wizard/index.ts +38 -0
  133. package/src/wizard/integration-wizard.ts +619 -0
  134. package/src/wizard/prompts.ts +145 -0
  135. package/src/wizard/starter-ui.ts +58 -0
@@ -0,0 +1,56 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Starter .ui file emitted by the integration wizard when the config's entry
3
+ // file does not exist yet. Uses only README-documented syntax: the Svelte-
4
+ // style single-file component shape, ui.mount(screen), a ui.signal, an
5
+ // on:click handler, and {signal} interpolation in the template.
6
+ // ---------------------------------------------------------------------------
7
+ export function renderStarterUi(displayWidth = 320, displayHeight = 240) {
8
+ // Keep text sizes sane on small mono panels (128×64 OLEDs).
9
+ const compact = displayWidth <= 160 || displayHeight <= 160;
10
+ const titleSize = compact ? 12 : 22;
11
+ const countSize = compact ? 10 : 16;
12
+ const buttonSize = compact ? 10 : 16;
13
+ return [
14
+ "<script>",
15
+ " // Starter screen generated by `npx @typecad/ui --config`.",
16
+ " // Edit freely — this is ordinary cuttlefish source, not generated output.",
17
+ "",
18
+ " import { ui } from '@typecad/ui';",
19
+ "",
20
+ " ui.mount(screen);",
21
+ "",
22
+ " export const taps = ui.signal(0);",
23
+ "",
24
+ " export function onTap() {",
25
+ " taps.set(taps() + 1);",
26
+ " }",
27
+ "</script>",
28
+ "",
29
+ "<style>",
30
+ " screen {",
31
+ " background: #101418;",
32
+ " display: flex;",
33
+ " flex-direction: column;",
34
+ " align-items: center;",
35
+ " justify-content: center;",
36
+ " gap: 16px;",
37
+ " }",
38
+ ` #title { color: #e8eef2; font-size: ${titleSize}px; }`,
39
+ ` #count { color: #38bdf8; font-size: ${countSize}px; }`,
40
+ " #tap {",
41
+ ` padding: 10px 24px;`,
42
+ " border-radius: 8px;",
43
+ " background: #1f6feb;",
44
+ " color: #ffffff;",
45
+ ` font-size: ${buttonSize}px;`,
46
+ " }",
47
+ "</style>",
48
+ "",
49
+ "<screen>",
50
+ " <text id=\"title\">@typecad/ui is running</text>",
51
+ " <text id=\"count\">taps: {taps}</text>",
52
+ " <button id=\"tap\" on:click={onTap}>Tap me</button>",
53
+ "</screen>",
54
+ "",
55
+ ].join("\n");
56
+ }
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@typecad/ui",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.13",
4
4
  "description": "TypeCAD UI authoring library — HTML/CSS-driven graphics for microcontrollers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "typecad-ui": "dist/cli.js"
10
+ },
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
@@ -22,23 +25,33 @@
22
25
  "types": "./dist/ui-engine/*.d.ts",
23
26
  "default": "./dist/ui-engine/*.js"
24
27
  },
28
+ "./themes/*": {
29
+ "default": "./themes/*"
30
+ },
25
31
  "./preview/*": {
26
32
  "types": "./dist/preview/*.d.ts",
27
33
  "default": "./dist/preview/*.js"
34
+ },
35
+ "./wizard": {
36
+ "types": "./dist/wizard/index.d.ts",
37
+ "default": "./dist/wizard/index.js"
28
38
  }
29
39
  },
30
40
  "sideEffects": false,
31
41
  "files": [
32
42
  "dist",
33
- "src"
43
+ "src",
44
+ "assets"
34
45
  ],
35
- "peerDependencies": {
36
- "@typecad/cuttlefish": "1.0.0-alpha.11"
37
- },
38
46
  "dependencies": {
47
+ "@typecad/cuttlefish": "1.0.0-alpha.13",
48
+ "chalk": "^4.1.2",
39
49
  "css-tree": "^3.2.1",
50
+ "decode-ico": "^0.4.1",
40
51
  "linkedom": "^0.18.12",
41
52
  "opentype.js": "^2.0.0",
53
+ "sharp": "^0.35.3",
54
+ "typescript": "^5.7.3",
42
55
  "yoga-layout": "^3.2.1"
43
56
  },
44
57
  "scripts": {
package/src/cli.ts ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ // ---------------------------------------------------------------------------
3
+ // @typecad/ui CLI — display integration wizard.
4
+ //
5
+ // npx @typecad/ui --config Run the interactive integration wizard
6
+ // npx @typecad/ui --help Show usage
7
+ // npx @typecad/ui --version Show the installed version
8
+ // ---------------------------------------------------------------------------
9
+
10
+ import { runIntegrationWizard } from "./wizard/integration-wizard.js";
11
+
12
+ const USAGE = `
13
+ @typecad/ui — HTML/CSS-driven graphics for microcontrollers
14
+
15
+ Usage:
16
+ npx @typecad/ui --config Configure a display (+ touch) for your
17
+ cuttlefish project interactively. Writes the
18
+ \`display\` section of cuttlefish.config.ts.
19
+
20
+ Options:
21
+ --config Run the integration wizard
22
+ --help, -h Show this help
23
+ --version, -v Print the installed @typecad/ui version
24
+
25
+ The wizard asks which display module you are using (ILI9341 / ST7796S SPI TFT,
26
+ SSD1309 I2C OLED, desktop simulator, or custom), then walks through bus pins,
27
+ SPI/I2C speed, rotation, and touch controller wiring with hardware-aware
28
+ defaults. It never touches the rest of your cuttlefish.config.ts.
29
+
30
+ Docs: https://github.com/justind000/typecode/tree/main/packages/ui
31
+ `.trim();
32
+
33
+ function printUsage(): void {
34
+ console.log(USAGE);
35
+ }
36
+
37
+ async function main(argv: string[]): Promise<number> {
38
+ const args = argv.slice(2);
39
+
40
+ if (args.includes("--help") || args.includes("-h")) {
41
+ printUsage();
42
+ return 0;
43
+ }
44
+
45
+ if (args.includes("--version") || args.includes("-v")) {
46
+ // Lazily read the version so importing this module stays side-effect free.
47
+ const { readFile } = await import("node:fs/promises");
48
+ const { fileURLToPath } = await import("node:url");
49
+ const { dirname, join } = await import("node:path");
50
+ try {
51
+ const packageJson = JSON.parse(
52
+ await readFile(join(dirname(dirname(fileURLToPath(import.meta.url))), "package.json"), "utf-8"),
53
+ ) as { version?: string };
54
+ console.log(packageJson.version ?? "unknown");
55
+ return 0;
56
+ } catch {
57
+ console.log("unknown");
58
+ return 0;
59
+ }
60
+ }
61
+
62
+ if (args.length === 0 || (args.length === 1 && (args[0] === "--config" || args[0] === "config"))) {
63
+ if (!process.stdin.isTTY) {
64
+ console.error("The integration wizard is interactive and needs a terminal.");
65
+ console.error("Run `npx @typecad/ui --config` from your project directory, or configure");
66
+ console.error("the `display` section of cuttlefish.config.ts manually:");
67
+ console.error("https://github.com/justind000/typecode/tree/main/packages/ui#display-configuration");
68
+ return 1;
69
+ }
70
+ const result = await runIntegrationWizard(process.cwd());
71
+ return result.exitCode;
72
+ }
73
+
74
+ console.error(`Unknown option${args.length > 1 ? "s" : ""}: ${args.join(" ")}\n`);
75
+ printUsage();
76
+ return 2;
77
+ }
78
+
79
+ main(process.argv).then(
80
+ (code) => {
81
+ process.exitCode = code;
82
+ },
83
+ (error) => {
84
+ console.error(error instanceof Error ? error.message : error);
85
+ process.exitCode = 1;
86
+ },
87
+ );
@@ -1,51 +1,53 @@
1
- // ---------------------------------------------------------------------------
2
- // Engine entry point for @typecad/ui.
3
- //
4
- // Cuttlefish dynamically imports this module when UI usage is detected:
5
- // const engine = await import("@typecad/ui/engine");
6
- // const hook = await engine.registerTranspilerUI();
7
- //
8
- // registerTranspilerUI() returns an object implementing the TranspilerUIHook
9
- // interface defined in @typecad/cuttlefish. This is the single runtime
10
- // contract between the two packages.
11
- // ---------------------------------------------------------------------------
12
-
13
- import type { TranspilerUIHook } from "@typecad/cuttlefish/ui-hook";
14
- import {
15
- resetUIRegistry, loadUIModule, loadUIModuleFromText, getUIModule,
16
- hasUIModule, allUIModules, allLoweredUIModules,
17
- markEntryHasUI, entryHasUI, clearEntryHasUI, lowerOnMount,
18
- generateProjectUITypeDeclarations,
19
- } from "./ui-engine/ui-registry.js";
20
- import { resolveColor, resolveColorInternal } from "./ui-engine/color.js";
21
- import { emitRuntimeHeader } from "./ui-engine/runtime-header.js";
22
- import { emitCuttlefishGfx } from "./ui-engine/runtime-header/cuttlefish-gfx.js";
23
- import { splitUiFile } from "./ui-engine/ui-file-splitter.js";
24
-
25
- export type { TranspilerUIHook };
26
-
27
- /**
28
- * Build and return the TranspilerUIHook — the object cuttlefish core uses
29
- * to access all UI capabilities (parsing, layout, lowering, emission).
30
- */
31
- export function registerTranspilerUI(): TranspilerUIHook {
32
- return {
33
- resetUIRegistry,
34
- loadUIModule,
35
- loadUIModuleFromText,
36
- getUIModule,
37
- hasUIModule,
38
- allUIModules,
39
- allLoweredUIModules,
40
- markEntryHasUI,
41
- entryHasUI,
42
- clearEntryHasUI,
43
- lowerOnMount,
44
- resolveColor,
45
- resolveColorInternal,
46
- emitRuntimeHeader,
47
- emitCuttlefishGfx,
48
- splitUiFile,
49
- generateProjectUITypeDeclarations,
50
- };
51
- }
1
+ // ---------------------------------------------------------------------------
2
+ // Engine entry point for @typecad/ui.
3
+ //
4
+ // Cuttlefish dynamically imports this module when UI usage is detected:
5
+ // const engine = await import("@typecad/ui/engine");
6
+ // const hook = await engine.registerTranspilerUI();
7
+ //
8
+ // registerTranspilerUI() returns an object implementing the TranspilerUIHook
9
+ // interface defined in @typecad/cuttlefish. This is the single runtime
10
+ // contract between the two packages.
11
+ // ---------------------------------------------------------------------------
12
+
13
+ import type { TranspilerUIHook } from "@typecad/cuttlefish/ui-hook";
14
+ import {
15
+ resetUIRegistry, loadUIModule, loadUIModuleFromText, getUIModule,
16
+ hasUIModule, allUIModules, allLoweredUIModules,
17
+ markEntryHasUI, entryHasUI, clearEntryHasUI, lowerOnMount,
18
+ generateProjectUITypeDeclarations,
19
+ } from "./ui-engine/ui-registry.js";
20
+ import { resolveColor, resolveColorInternal } from "./ui-engine/color.js";
21
+ import { emitRuntimeHeader } from "./ui-engine/runtime-header.js";
22
+ import { emitCuttlefishGfx } from "./ui-engine/runtime-header/cuttlefish-gfx.js";
23
+ import { splitUiFile } from "./ui-engine/ui-file-splitter.js";
24
+ import { warmUpImageDecoding } from "./ui-engine/image-decode.js";
25
+
26
+ export type { TranspilerUIHook };
27
+
28
+ /**
29
+ * Build and return the TranspilerUIHook the object cuttlefish core uses
30
+ * to access all UI capabilities (parsing, layout, lowering, emission).
31
+ */
32
+ export function registerTranspilerUI(): TranspilerUIHook {
33
+ return {
34
+ resetUIRegistry,
35
+ loadUIModule,
36
+ loadUIModuleFromText,
37
+ getUIModule,
38
+ hasUIModule,
39
+ allUIModules,
40
+ allLoweredUIModules,
41
+ markEntryHasUI,
42
+ entryHasUI,
43
+ clearEntryHasUI,
44
+ lowerOnMount,
45
+ resolveColor,
46
+ resolveColorInternal,
47
+ emitRuntimeHeader,
48
+ emitCuttlefishGfx,
49
+ splitUiFile,
50
+ warmUpImageDecoding,
51
+ generateProjectUITypeDeclarations,
52
+ };
53
+ }