@typecad/cuttlefish 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.
- package/README.md +82 -79
- package/assets/editor-extensions/typecad-debug/README.md +141 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js +347 -0
- package/assets/editor-extensions/typecad-debug/out/extension.js.map +1 -0
- package/assets/editor-extensions/typecad-debug/package.json +76 -0
- package/assets/editor-extensions/typecad-ui/LICENSE +27 -0
- package/assets/editor-extensions/typecad-ui/README.md +52 -0
- package/assets/editor-extensions/typecad-ui/file-icon-dark.png +0 -0
- package/assets/editor-extensions/typecad-ui/file-icon-light.png +0 -0
- package/assets/editor-extensions/typecad-ui/icon.png +0 -0
- package/assets/editor-extensions/typecad-ui/language-configuration.json +43 -0
- package/assets/editor-extensions/typecad-ui/package.json +54 -0
- package/assets/editor-extensions/typecad-ui/snippets/typecad-ui.json +80 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/markdown-ui.json +45 -0
- package/assets/editor-extensions/typecad-ui/syntaxes/typecad-ui.tmLanguage.json +1269 -0
- package/dist/api/config.d.ts +30 -27
- package/dist/api/schema/types.d.ts +20 -3
- package/dist/api/shared/async-runtime-static.d.ts +1 -1
- package/dist/api/shared/async-runtime-static.js +5 -5
- package/dist/api/shared/async-types.d.ts +3 -2
- package/dist/api/shared/board-catalog.d.ts +2 -0
- package/dist/api/shared/board-catalog.js +6 -0
- package/dist/api/shared/board-resolver.d.ts +4 -7
- package/dist/api/shared/board-resolver.js +2 -1
- package/dist/api/shared/coop-scheduler.d.ts +1 -1
- package/dist/api/shared/coop-scheduler.js +1 -1
- package/dist/api/shared/cpp-type-ir.d.ts +1 -1
- package/dist/api/shared/cpp-type-ir.js +1 -1
- package/dist/api/shared/display-profile.d.ts +1 -1
- package/dist/api/shared/display-profile.js +3 -5
- package/dist/api/shared/framework-manifest-registry.d.ts +1 -1
- package/dist/api/shared/framework-manifest-registry.js +0 -1
- package/dist/api/shared/framework-manifest.d.ts +65 -507
- package/dist/api/shared/framework-manifest.js +6 -11
- package/dist/api/shared/hal-op-ir.d.ts +294 -685
- package/dist/api/shared/hal-op-ir.js +31 -65
- package/dist/api/shared/index.d.ts +0 -4
- package/dist/api/shared/index.js +1 -7
- package/dist/api/shared/ir-core.d.ts +6 -0
- package/dist/api/shared/ir-declarations.d.ts +4 -0
- package/dist/api/shared/ir.d.ts +1 -3
- package/dist/api/shared/platform-strategy.d.ts +14 -37
- package/dist/api/shared/polyfill-helper-registry.js +0 -5
- package/dist/api/shared/polyfill-types.js +0 -27
- package/dist/api/shared/promise-runtime.js +3 -3
- package/dist/api/shared/spdx-licenses.d.ts +12 -10
- package/dist/api/shared/spdx-licenses.js +1 -1
- package/dist/api/shared/toolchain-types.d.ts +1 -1
- package/dist/api/shared/toolchain-types.js +3 -3
- package/dist/api/shared/types.d.ts +0 -3
- package/dist/api/shared/validate-framework-manifest.js +13 -33
- package/dist/board-catalog/dts-reader.d.ts +220 -0
- package/dist/board-catalog/dts-reader.js +1052 -0
- package/dist/board-catalog/index.d.ts +11 -0
- package/dist/board-catalog/index.js +12 -0
- package/dist/board-catalog/pinconfig.d.ts +48 -0
- package/dist/board-catalog/pinconfig.js +263 -0
- package/dist/board-catalog/sdk.d.ts +82 -0
- package/dist/board-catalog/sdk.js +180 -0
- package/dist/board-catalog/store.d.ts +196 -0
- package/dist/board-catalog/store.js +363 -0
- package/dist/board-catalog/types.d.ts +233 -0
- package/dist/board-catalog/types.js +7 -0
- package/dist/board-catalog/walker.d.ts +112 -0
- package/dist/board-catalog/walker.js +1101 -0
- package/dist/cli-utils.d.ts +2 -2
- package/dist/cli-utils.js +5 -5
- package/dist/cli.js +227 -244
- package/dist/config-loader.d.ts +14 -19
- package/dist/config-loader.js +242 -78
- package/dist/config-schema.d.ts +19 -227
- package/dist/config-schema.js +9 -8
- package/dist/contract/board-generator.d.ts +4 -4
- package/dist/contract/board-generator.js +16 -5
- package/dist/contract/contract-parser.d.ts +36 -127
- package/dist/contract/contract-parser.js +76 -0
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.js +70 -21
- package/dist/create/active-board-catalog.d.ts +9 -0
- package/dist/create/active-board-catalog.js +94 -0
- package/dist/create/board-catalog.generated.d.ts +96 -0
- package/dist/create/board-catalog.generated.js +128737 -0
- package/dist/create/board-search.d.ts +23 -0
- package/dist/create/board-search.js +88 -0
- package/dist/create/editor-integration.d.ts +32 -0
- package/dist/create/editor-integration.js +257 -0
- package/dist/create/eslint-rules-template.d.ts +2 -2
- package/dist/create/framework-catalog.d.ts +48 -8
- package/dist/create/framework-catalog.js +58 -44
- package/dist/create/index.d.ts +8 -13
- package/dist/create/index.js +5 -9
- package/dist/create/mcu-target.d.ts +39 -0
- package/dist/create/mcu-target.js +80 -0
- package/dist/create/pack-targets.d.ts +19 -0
- package/dist/create/pack-targets.js +56 -0
- package/dist/create/{init-scaffold.d.ts → scaffold.d.ts} +8 -11
- package/dist/create/{init-scaffold.js → scaffold.js} +28 -87
- package/dist/create/templates.d.ts +51 -0
- package/dist/create/{init-templates.js → templates.js} +135 -116
- package/dist/create/wizard.d.ts +19 -0
- package/dist/create/wizard.js +314 -0
- package/dist/debug/preprocessor.d.ts +5 -0
- package/dist/debug/preprocessor.js +31 -7
- package/dist/diagnostics/diagnostics-report.d.ts +1 -1
- package/dist/diagnostics/diagnostics-report.js +3 -11
- package/dist/diagnostics/json-schema.d.ts +1 -1
- package/dist/diagnostics/md-writer.js +2 -2
- package/dist/diagnostics/mermaid-builder.d.ts +1 -1
- package/dist/diagnostics/mermaid-builder.js +1 -1
- package/dist/emit/cpp-emitter.js +4 -1
- package/dist/emit/emitters/class-emitter.js +32 -4
- package/dist/emit/emitters/emitter-context.d.ts +11 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +1 -1
- package/dist/emit/emitters/function-emitter-impl.js +33 -17
- package/dist/emit/emitters/output-finalizer.d.ts +7 -0
- package/dist/emit/emitters/output-finalizer.js +31 -23
- package/dist/emit/emitters/setup.js +147 -63
- package/dist/emit/emitters/top-level-prep.js +1 -1
- package/dist/emit/emitters/type-decl-emitter.js +13 -8
- package/dist/emit/emitters/ui-emitter.js +1 -1
- package/dist/emit/expression-renderer.d.ts +3 -3
- package/dist/emit/expression-renderer.js +17 -7
- package/dist/emit/route-hal-op.js +17 -48
- package/dist/emit/snprintf-helpers.d.ts +1 -3
- package/dist/emit/snprintf-helpers.js +1 -39
- package/dist/emit/statement-renderer.d.ts +0 -4
- package/dist/emit/statement-renderer.js +54 -45
- package/dist/emit/utils/async-state-machine.d.ts +16 -9
- package/dist/emit/utils/async-state-machine.js +56 -54
- package/dist/emit/utils/comment-helpers.d.ts +0 -8
- package/dist/emit/utils/comment-helpers.js +1 -1
- package/dist/emit/utils/cpp-helpers.d.ts +2 -2
- package/dist/emit/utils/cpp-helpers.js +2 -2
- package/dist/emit/utils/hal-op-cpp-type.js +4 -6
- package/dist/emit/utils/index.d.ts +3 -3
- package/dist/emit/utils/index.js +3 -3
- package/dist/emit/utils/type-inference.d.ts +1 -29
- package/dist/emit/utils/type-inference.js +0 -75
- package/dist/framework-package.d.ts +3 -0
- package/dist/framework-package.js +23 -6
- package/dist/framework-registry.d.ts +5 -5
- package/dist/frameworks/native/graphics/terminal-preview.d.ts +5 -0
- package/dist/frameworks/native/graphics/terminal-preview.js +33 -0
- package/dist/frameworks/native/index.d.ts +3 -0
- package/dist/frameworks/native/index.js +15 -0
- package/dist/frameworks/native/native-compile.d.ts +17 -0
- package/dist/frameworks/native/native-compile.js +170 -0
- package/dist/frameworks/native/native-config.d.ts +41 -0
- package/dist/frameworks/native/native-config.js +7 -0
- package/dist/frameworks/native/strategy.d.ts +97 -0
- package/dist/frameworks/native/strategy.js +664 -0
- package/dist/ir/board-resolver.d.ts +18 -23
- package/dist/ir/board-resolver.js +43 -401
- package/dist/ir/build-ir-state.d.ts +3 -0
- package/dist/ir/build-ir-state.js +42 -0
- package/dist/ir/build-ir.d.ts +1 -1
- package/dist/ir/build-ir.js +64 -45
- package/dist/ir/declaration-builders.js +1 -0
- package/dist/ir/expression-to-ir.js +17 -10
- package/dist/ir/hal/hal-emitter.d.ts +0 -2
- package/dist/ir/hal/hal-emitter.js +92 -41
- package/dist/ir/hal/hal-parser.d.ts +5 -5
- package/dist/ir/hal/hal-parser.js +128 -36
- package/dist/ir/hal/hal-plugins.d.ts +0 -1
- package/dist/ir/hal/hal-plugins.js +425 -716
- package/dist/ir/heap-analysis.js +2 -41
- package/dist/ir/identifier-collector.js +32 -20
- package/dist/ir/network-validation.js +7 -11
- package/dist/ir/ownership-analysis.js +75 -13
- package/dist/ir/peripheral-usage.d.ts +8 -2
- package/dist/ir/peripheral-usage.js +78 -149
- package/dist/ir/peripheral-validation.js +23 -3
- package/dist/ir/pin-capability-validation.d.ts +12 -0
- package/dist/ir/pin-capability-validation.js +61 -97
- package/dist/ir/pin-mode-validation.js +5 -5
- package/dist/ir/program-analysis.d.ts +8 -15
- package/dist/ir/program-analysis.js +140 -323
- package/dist/ir/pulldown-validation.js +11 -4
- package/dist/ir/resource-analysis.js +15 -3
- package/dist/ir/statement-to-ir.js +0 -6
- package/dist/ir/timing-validation.js +1 -1
- package/dist/ir/transformers/array-methods.js +11 -5
- package/dist/ir/transformers/call-statement.js +20 -87
- package/dist/ir/transformers/callback-context-registry.d.ts +1 -1
- package/dist/ir/transformers/callback-context-registry.js +8 -16
- package/dist/ir/transformers/control-flow.js +0 -13
- package/dist/ir/transformers/expressions.js +10 -9
- package/dist/ir/transformers/hal-call-resolver.d.ts +2 -2
- package/dist/ir/transformers/hal-call-resolver.js +24 -10
- package/dist/ir/transformers/hal-emit-helpers.d.ts +2 -2
- package/dist/ir/transformers/hal-emit-helpers.js +2 -2
- package/dist/ir/transformers/namespace-methods.js +1 -1
- package/dist/ir/transformers/ui-callback-lowering.d.ts +0 -2
- package/dist/ir/transformers/ui-callback-lowering.js +0 -24
- package/dist/ir/transformers/variables.js +338 -42
- package/dist/ir/try-catch-validation.js +4 -3
- package/dist/ir/type-resolution.js +15 -4
- package/dist/ir/validation-orchestrator.js +0 -9
- package/dist/libdef/cpp-to-decl.d.ts +0 -9
- package/dist/libdef/cpp-to-decl.js +0 -72
- package/dist/libdef/registry.d.ts +0 -1
- package/dist/libdef/registry.js +1 -24
- package/dist/library/catalog.d.ts +35 -0
- package/dist/library/catalog.js +67 -0
- package/dist/library/cli.d.ts +2 -0
- package/dist/library/cli.js +168 -0
- package/dist/library/init.d.ts +25 -0
- package/dist/library/init.js +397 -0
- package/dist/library/install.d.ts +9 -0
- package/dist/library/install.js +80 -0
- package/dist/library/registry-search.d.ts +34 -0
- package/dist/library/registry-search.js +50 -0
- package/dist/library/validate.d.ts +17 -0
- package/dist/library/validate.js +175 -0
- package/dist/library-packages.d.ts +95 -0
- package/dist/library-packages.js +275 -0
- package/dist/mapping/peripheral-names.js +9 -4
- package/dist/mapping/source-map.d.ts +3 -4
- package/dist/mapping/source-map.js +12 -18
- package/dist/orchestrator/graph-builder.d.ts +3 -3
- package/dist/orchestrator/graph-builder.js +29 -12
- package/dist/orchestrator/type-checker.d.ts +3 -3
- package/dist/orchestrator/type-checker.js +3 -3
- package/dist/platform/async-runtime.js +1 -1
- package/dist/platform/coop-scheduler-runtime.js +2 -2
- package/dist/platform/generic-debug-codegen.d.ts +36 -0
- package/dist/platform/generic-debug-codegen.js +185 -0
- package/dist/platform/generic-strategy.d.ts +3 -4
- package/dist/platform/generic-strategy.js +5 -80
- package/dist/platform/index.js +1 -1
- package/dist/platform/registry.d.ts +2 -2
- package/dist/platform/registry.js +2 -2
- package/dist/preview/client.js +17 -3
- package/dist/safety/asil-decorators.d.ts +32 -0
- package/dist/safety/asil-decorators.js +32 -0
- package/dist/safety/authoring.d.ts +85 -0
- package/dist/safety/authoring.js +61 -0
- package/dist/safety/engine.d.ts +3 -0
- package/dist/safety/engine.js +83 -0
- package/dist/safety/hal/ops.d.ts +48 -0
- package/dist/safety/hal/ops.js +46 -0
- package/dist/safety/iso26262/analyze.d.ts +13 -0
- package/dist/safety/iso26262/analyze.js +29 -0
- package/dist/safety/iso26262/asil.d.ts +10 -0
- package/dist/safety/iso26262/asil.js +22 -0
- package/dist/safety/iso26262/collect.d.ts +14 -0
- package/dist/safety/iso26262/collect.js +137 -0
- package/dist/safety/iso26262/goto-checker.d.ts +10 -0
- package/dist/safety/iso26262/goto-checker.js +72 -0
- package/dist/safety/iso26262/heap-checker.d.ts +7 -0
- package/dist/safety/iso26262/heap-checker.js +57 -0
- package/dist/safety/iso26262/init-checker.d.ts +13 -0
- package/dist/safety/iso26262/init-checker.js +127 -0
- package/dist/safety/iso26262/loop-checker.d.ts +7 -0
- package/dist/safety/iso26262/loop-checker.js +86 -0
- package/dist/safety/iso26262/recursion-checker.d.ts +9 -0
- package/dist/safety/iso26262/recursion-checker.js +134 -0
- package/dist/safety/iso26262/sidecar-writer.d.ts +25 -0
- package/dist/safety/iso26262/sidecar-writer.js +13 -0
- package/dist/safety/passes/pinMode-intercept.d.ts +3 -0
- package/dist/safety/passes/pinMode-intercept.js +60 -0
- package/dist/safety/runtime/mode-table.d.ts +5 -0
- package/dist/safety/runtime/mode-table.js +55 -0
- package/dist/safety/runtime/polyfills.d.ts +6 -0
- package/dist/safety/runtime/polyfills.js +12 -0
- package/dist/safety/runtime/result-struct.d.ts +11 -0
- package/dist/safety/runtime/result-struct.js +98 -0
- package/dist/safety/runtime/safe-int.d.ts +33 -0
- package/dist/safety/runtime/safe-int.js +170 -0
- package/dist/safety/runtime/safe-traits.d.ts +4 -0
- package/dist/safety/runtime/safe-traits.js +95 -0
- package/dist/safety/runtime/safe-variable.d.ts +39 -0
- package/dist/safety/runtime/safe-variable.js +226 -0
- package/dist/safety/runtime/vote.d.ts +8 -0
- package/dist/safety/runtime/vote.js +92 -0
- package/dist/safety/runtime/write-verify.d.ts +8 -0
- package/dist/safety/runtime/write-verify.js +71 -0
- package/dist/safety/safe-int-types.d.ts +45 -0
- package/dist/safety/safe-int-types.js +25 -0
- package/dist/safety/safe-variable-types.d.ts +29 -0
- package/dist/safety/safe-variable-types.js +19 -0
- package/dist/safety/safety-bridge.d.ts +5 -6
- package/dist/safety/safety-bridge.js +15 -28
- package/dist/safety/sidecar-bridge.d.ts +1 -3
- package/dist/safety/sidecar-bridge.js +3 -20
- package/dist/safety/specifiers.d.ts +6 -0
- package/dist/safety/specifiers.js +14 -0
- package/dist/safety-hook.d.ts +8 -7
- package/dist/safety-hook.js +12 -13
- package/dist/testing.d.ts +5 -6
- package/dist/testing.js +5 -5
- package/dist/transpile/resolution.d.ts +1 -1
- package/dist/transpile/resolution.js +18 -9
- package/dist/transpile/test-pins.d.ts +18 -0
- package/dist/transpile/test-pins.js +142 -0
- package/dist/transpile.d.ts +1 -2
- package/dist/transpile.js +90 -29
- package/dist/types.d.ts +45 -26
- package/dist/ui-hook.d.ts +1 -1
- package/dist/utils/cli.d.ts +2 -2
- package/dist/utils/cli.js +160 -157
- package/dist/utils/fs.d.ts +3 -4
- package/dist/utils/fs.js +4 -5
- package/dist/utils/strings.d.ts +0 -1
- package/dist/utils/strings.js +0 -8
- package/dist/utils/ui.d.ts +5 -2
- package/dist/utils/ui.js +13 -3
- package/package.json +158 -149
- package/dist/add-preset.d.ts +0 -4
- package/dist/add-preset.js +0 -74
- package/dist/api/shared/async-symbol-detector.d.ts +0 -11
- package/dist/api/shared/async-symbol-detector.js +0 -140
- package/dist/api/shared/native-display-op-resolver.d.ts +0 -10
- package/dist/api/shared/native-display-op-resolver.js +0 -64
- package/dist/create/board-checklist.d.ts +0 -2
- package/dist/create/board-checklist.js +0 -52
- package/dist/create/board-codegen.d.ts +0 -9
- package/dist/create/board-codegen.js +0 -238
- package/dist/create/board-generators.d.ts +0 -12
- package/dist/create/board-generators.js +0 -651
- package/dist/create/board-spec.d.ts +0 -637
- package/dist/create/board-spec.js +0 -214
- package/dist/create/init-templates.d.ts +0 -28
- package/dist/create/init-wizard.d.ts +0 -8
- package/dist/create/init-wizard.js +0 -182
- package/dist/install/framework-catalog.d.ts +0 -53
- package/dist/install/framework-catalog.js +0 -107
- package/dist/install/handle-install.d.ts +0 -35
- package/dist/install/handle-install.js +0 -177
- package/dist/install/index.d.ts +0 -4
- package/dist/install/index.js +0 -3
- package/dist/ir/pin-state-tracking.d.ts +0 -58
- package/dist/ir/pin-state-tracking.js +0 -182
- package/dist/ir/pwm-timer-sharing.d.ts +0 -4
- package/dist/ir/pwm-timer-sharing.js +0 -94
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +0 -4
- package/dist/ir/timer0-pwm-timing-conflict.js +0 -72
- package/dist/libdef/component-decls.d.ts +0 -2
- package/dist/libdef/component-decls.js +0 -6
- package/dist/libdef/component-discovery.d.ts +0 -43
- package/dist/libdef/component-discovery.js +0 -83
- package/dist/theme-tokens.d.ts +0 -22
- package/dist/theme-tokens.js +0 -172
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
/** Walk a directory recursively, returning all .h files. */
|
|
4
|
-
function walkHeaders(dir) {
|
|
5
|
-
if (!existsSync(dir))
|
|
6
|
-
return [];
|
|
7
|
-
const out = [];
|
|
8
|
-
const stack = [dir];
|
|
9
|
-
while (stack.length > 0) {
|
|
10
|
-
const cur = stack.pop();
|
|
11
|
-
let entries;
|
|
12
|
-
try {
|
|
13
|
-
entries = readdirSync(cur);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
for (const name of entries) {
|
|
19
|
-
const full = join(cur, name);
|
|
20
|
-
try {
|
|
21
|
-
const st = statSync(full);
|
|
22
|
-
if (st.isDirectory()) {
|
|
23
|
-
stack.push(full);
|
|
24
|
-
}
|
|
25
|
-
else if (name.toLowerCase().endsWith('.h')) {
|
|
26
|
-
out.push(full);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// Stat failed (race); skip.
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Find all .h files for the declared components.
|
|
38
|
-
*
|
|
39
|
-
* - managed: scan `managed_components/<name>/include/` (falling back to the
|
|
40
|
-
* component dir if no include/ exists). Populated by `idf.py reconfigure`.
|
|
41
|
-
* - local: scan `<path>/include/` (or `<path>/`).
|
|
42
|
-
* - builtin: scan `<idfRoot>/components/<name>/include/` (IDF ships with these).
|
|
43
|
-
*
|
|
44
|
-
* For builtins the output .d.ts goes to `<projectDir>/.cuttlefish/component-decls/<component>/`
|
|
45
|
-
* — never into `$IDF_PATH/components/`, which would pollute the IDF install.
|
|
46
|
-
*
|
|
47
|
-
* Returned entries are unsorted — the caller decides ordering.
|
|
48
|
-
*/
|
|
49
|
-
export function discoverComponentHeaders(projectDir, roots) {
|
|
50
|
-
const headers = [];
|
|
51
|
-
for (const name of roots.managed) {
|
|
52
|
-
const base = join(projectDir, 'managed_components', name);
|
|
53
|
-
const includeDir = join(base, 'include');
|
|
54
|
-
const dir = existsSync(includeDir) ? includeDir : base;
|
|
55
|
-
for (const h of walkHeaders(dir)) {
|
|
56
|
-
headers.push({ path: h, outputDir: dir });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
for (const localPath of roots.local) {
|
|
60
|
-
const includeDir = join(localPath, 'include');
|
|
61
|
-
const dir = existsSync(includeDir) ? includeDir : localPath;
|
|
62
|
-
for (const h of walkHeaders(dir)) {
|
|
63
|
-
headers.push({ path: h, outputDir: dir });
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (roots.idfRoot) {
|
|
67
|
-
for (const name of roots.builtin) {
|
|
68
|
-
const base = join(roots.idfRoot, 'components', name);
|
|
69
|
-
const includeDir = join(base, 'include');
|
|
70
|
-
const dir = existsSync(includeDir) ? includeDir : base;
|
|
71
|
-
// Project-local cache for builtins. Mirrors the include/ layout so
|
|
72
|
-
// imports can substitute `managed_components/<name>/include/X.d.ts`
|
|
73
|
-
// patterns. Each header's .d.ts is named after the header basename.
|
|
74
|
-
const outDir = join(projectDir, '.cuttlefish', 'component-decls', name);
|
|
75
|
-
if (!existsSync(outDir))
|
|
76
|
-
mkdirSync(outDir, { recursive: true });
|
|
77
|
-
for (const h of walkHeaders(dir)) {
|
|
78
|
-
headers.push({ path: h, outputDir: outDir });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return headers;
|
|
83
|
-
}
|
package/dist/theme-tokens.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** One declaration (`--token: value`), order-preserving. */
|
|
2
|
-
type Decl = [name: string, value: string];
|
|
3
|
-
export interface ShadcnTheme {
|
|
4
|
-
name: string;
|
|
5
|
-
light: Decl[];
|
|
6
|
-
dark: Decl[];
|
|
7
|
-
}
|
|
8
|
-
/** Where a project keeps its own themes: src/styles/themes/*.css next to
|
|
9
|
-
* the kit stylesheet. Project themes win over same-named package ones —
|
|
10
|
-
* pasting a theme is dropping a file into YOUR project, never node_modules. */
|
|
11
|
-
export declare function projectThemesDir(projectRoot: string): string;
|
|
12
|
-
/** Theme names, project-local (src/styles/themes/) first, then the ones
|
|
13
|
-
* shipped in the package (assets/shadcn/themes/). */
|
|
14
|
-
export declare function listShadcnThemes(projectRoot?: string): string[];
|
|
15
|
-
/** Load a theme by name — project-local directory first, then the package
|
|
16
|
-
* included set. Throws with the available names when missing. */
|
|
17
|
-
export declare function loadShadcnTheme(name: string, projectRoot?: string): ShadcnTheme;
|
|
18
|
-
/** Merge a theme's tokens into a kit stylesheet's :root/.dark blocks and
|
|
19
|
-
* return the rewritten text. Throws when a merged block is missing any
|
|
20
|
-
* token the kit's recipes reference. */
|
|
21
|
-
export declare function applyShadcnTheme(cssText: string, theme: ShadcnTheme): string;
|
|
22
|
-
export {};
|
package/dist/theme-tokens.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// shadcn kit themes — the included token sets under assets/shadcn/themes/.
|
|
3
|
-
//
|
|
4
|
-
// A theme file is two CSS blocks (:root = light tokens, .dark = dark tokens)
|
|
5
|
-
// plus an optional header comment. Selecting a theme MERGES each block into
|
|
6
|
-
// the kit's stylesheet: declarations the theme defines override the kit's,
|
|
7
|
-
// and kit-specific extras the theme lacks (notably --destructive-background,
|
|
8
|
-
// which stock shadcn themes don't carry) keep their current values — so any
|
|
9
|
-
// stock theme from ui.shadcn.com or tweakcn pastes cleanly.
|
|
10
|
-
//
|
|
11
|
-
// Used by `cuttlefish add shadcn --theme <name>` (scaffold time) and
|
|
12
|
-
// `cuttlefish theme <name>` (swap an existing project's kit stylesheet).
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
import fs from "node:fs";
|
|
15
|
-
import path from "node:path";
|
|
16
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
-
const THEMES_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../assets/shadcn/themes");
|
|
18
|
-
/** The tokens the kit's recipes reference; every merged theme must cover them. */
|
|
19
|
-
const REQUIRED_TOKENS = [
|
|
20
|
-
"--background", "--foreground",
|
|
21
|
-
"--card", "--card-foreground",
|
|
22
|
-
"--primary", "--primary-foreground",
|
|
23
|
-
"--secondary", "--secondary-foreground",
|
|
24
|
-
"--muted", "--muted-foreground",
|
|
25
|
-
"--accent", "--accent-foreground",
|
|
26
|
-
"--destructive", "--destructive-foreground", "--destructive-background",
|
|
27
|
-
"--border", "--input", "--radius",
|
|
28
|
-
];
|
|
29
|
-
/** Blank out /* … */ comment interiors (same length) so selector searches
|
|
30
|
-
* can't match inside a comment while byte offsets stay valid against the
|
|
31
|
-
* original text. The kit's header comment literally contains `.dark { ... }`
|
|
32
|
-
* as documentation — an unmasked search spliced tokens into the comment and
|
|
33
|
-
* left the real block untouched. */
|
|
34
|
-
function maskComments(css) {
|
|
35
|
-
return css.replace(/\/\*[\s\S]*?\*\//g, (m) => " ".repeat(m.length));
|
|
36
|
-
}
|
|
37
|
-
/** Locate `selector {` in css, skipping comment spans. Custom-property values
|
|
38
|
-
* contain no braces, so the block ends at the first `}` after the opening
|
|
39
|
-
* one. */
|
|
40
|
-
function blockRange(css, selector) {
|
|
41
|
-
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
42
|
-
const m = new RegExp(escaped + "\\s*\\{").exec(maskComments(css));
|
|
43
|
-
if (!m)
|
|
44
|
-
return null;
|
|
45
|
-
const open = m.index + m[0].length;
|
|
46
|
-
const close = css.indexOf("}", open);
|
|
47
|
-
if (close < 0)
|
|
48
|
-
return null;
|
|
49
|
-
return { selStart: m.index, open, close };
|
|
50
|
-
}
|
|
51
|
-
/** Parse a token block's declarations (line-oriented; one decl per line, the
|
|
52
|
-
* format both the kit and stock shadcn themes use). */
|
|
53
|
-
function parseDecls(block) {
|
|
54
|
-
const out = [];
|
|
55
|
-
for (const line of block.split("\n")) {
|
|
56
|
-
const m = /^\s*(--[\w-]+)\s*:\s*([^;]+);/.exec(line);
|
|
57
|
-
if (m)
|
|
58
|
-
out.push([m[1], m[2].trim()]);
|
|
59
|
-
}
|
|
60
|
-
return out;
|
|
61
|
-
}
|
|
62
|
-
function emitBlock(selector, decls) {
|
|
63
|
-
const body = decls.map(([k, v]) => ` ${k}: ${v};`).join("\n");
|
|
64
|
-
return `${selector} {\n${body}\n}`;
|
|
65
|
-
}
|
|
66
|
-
/** Order-preserving override merge: base order, overrides in place, theme-only
|
|
67
|
-
* declarations appended. */
|
|
68
|
-
function mergeDecls(base, override) {
|
|
69
|
-
const out = base.map(([k, v]) => [k, v]);
|
|
70
|
-
const indexByName = new Map(out.map(([k], i) => [k, i]));
|
|
71
|
-
for (const [k, v] of override) {
|
|
72
|
-
const existing = indexByName.get(k);
|
|
73
|
-
if (existing !== undefined)
|
|
74
|
-
out[existing][1] = v;
|
|
75
|
-
else {
|
|
76
|
-
indexByName.set(k, out.length);
|
|
77
|
-
out.push([k, v]);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return out;
|
|
81
|
-
}
|
|
82
|
-
/** Where a project keeps its own themes: src/styles/themes/*.css next to
|
|
83
|
-
* the kit stylesheet. Project themes win over same-named package ones —
|
|
84
|
-
* pasting a theme is dropping a file into YOUR project, never node_modules. */
|
|
85
|
-
export function projectThemesDir(projectRoot) {
|
|
86
|
-
return path.resolve(projectRoot, "src/styles/themes");
|
|
87
|
-
}
|
|
88
|
-
function themeNamesIn(dir) {
|
|
89
|
-
if (!fs.existsSync(dir))
|
|
90
|
-
return [];
|
|
91
|
-
return fs.readdirSync(dir)
|
|
92
|
-
.filter((f) => f.endsWith(".css") && !f.startsWith("_"))
|
|
93
|
-
.map((f) => f.replace(/\.css$/, ""))
|
|
94
|
-
.sort();
|
|
95
|
-
}
|
|
96
|
-
/** Theme names, project-local (src/styles/themes/) first, then the ones
|
|
97
|
-
* shipped in the package (assets/shadcn/themes/). */
|
|
98
|
-
export function listShadcnThemes(projectRoot) {
|
|
99
|
-
const local = projectRoot ? themeNamesIn(projectThemesDir(projectRoot)) : [];
|
|
100
|
-
const included = themeNamesIn(THEMES_DIR);
|
|
101
|
-
return [...new Set([...local, ...included])].sort();
|
|
102
|
-
}
|
|
103
|
-
function formatThemeList(projectRoot) {
|
|
104
|
-
const local = projectRoot ? themeNamesIn(projectThemesDir(projectRoot)) : [];
|
|
105
|
-
const included = themeNamesIn(THEMES_DIR);
|
|
106
|
-
const lines = [];
|
|
107
|
-
if (local.length > 0) {
|
|
108
|
-
lines.push("project (src/styles/themes/):");
|
|
109
|
-
for (const n of local)
|
|
110
|
-
lines.push(` ${n}`);
|
|
111
|
-
}
|
|
112
|
-
lines.push("included with cuttlefish:");
|
|
113
|
-
for (const n of included)
|
|
114
|
-
lines.push(` ${n}`);
|
|
115
|
-
lines.push("(paste your own: src/styles/themes/<name>.css in this project)");
|
|
116
|
-
return lines.join("\n");
|
|
117
|
-
}
|
|
118
|
-
/** Load a theme by name — project-local directory first, then the package
|
|
119
|
-
* included set. Throws with the available names when missing. */
|
|
120
|
-
export function loadShadcnTheme(name, projectRoot) {
|
|
121
|
-
if (!/^[a-z0-9-]+$/.test(name)) {
|
|
122
|
-
throw new Error(`Invalid theme name "${name}" — use letters, digits, and dashes.`);
|
|
123
|
-
}
|
|
124
|
-
const candidates = projectRoot
|
|
125
|
-
? [path.join(projectThemesDir(projectRoot), `${name}.css`), path.join(THEMES_DIR, `${name}.css`)]
|
|
126
|
-
: [path.join(THEMES_DIR, `${name}.css`)];
|
|
127
|
-
const file = candidates.find((c) => fs.existsSync(c));
|
|
128
|
-
if (!file) {
|
|
129
|
-
throw new Error(`Unknown theme "${name}". Available themes:\n${formatThemeList(projectRoot)}`);
|
|
130
|
-
}
|
|
131
|
-
const text = fs.readFileSync(file, "utf-8");
|
|
132
|
-
const rootRange = blockRange(text, ":root");
|
|
133
|
-
const darkRange = blockRange(text, ".dark");
|
|
134
|
-
if (!rootRange || !darkRange) {
|
|
135
|
-
throw new Error(`Theme "${name}" must define both a :root and a .dark token block.`);
|
|
136
|
-
}
|
|
137
|
-
const light = parseDecls(text.slice(rootRange.open, rootRange.close));
|
|
138
|
-
const dark = parseDecls(text.slice(darkRange.open, darkRange.close));
|
|
139
|
-
if (light.length === 0 || dark.length === 0) {
|
|
140
|
-
throw new Error(`Theme "${name}" has empty token blocks — paste the theme's :root and .dark declarations.`);
|
|
141
|
-
}
|
|
142
|
-
return { name, light, dark };
|
|
143
|
-
}
|
|
144
|
-
/** Merge a theme's tokens into a kit stylesheet's :root/.dark blocks and
|
|
145
|
-
* return the rewritten text. Throws when a merged block is missing any
|
|
146
|
-
* token the kit's recipes reference. */
|
|
147
|
-
export function applyShadcnTheme(cssText, theme) {
|
|
148
|
-
let out = cssText;
|
|
149
|
-
for (const [selector, themeDecls] of [[".dark", theme.dark], [":root", theme.light]]) {
|
|
150
|
-
const range = blockRange(out, selector);
|
|
151
|
-
if (!range) {
|
|
152
|
-
throw new Error(`The kit stylesheet has no ${selector} token block to replace.`);
|
|
153
|
-
}
|
|
154
|
-
const merged = mergeDecls(parseDecls(out.slice(range.open, range.close)), themeDecls);
|
|
155
|
-
out = out.slice(0, range.selStart) + emitBlock(selector, merged) + out.slice(range.close + 1);
|
|
156
|
-
}
|
|
157
|
-
// Validate AFTER both merges (a token can live in either block).
|
|
158
|
-
const rootRange = blockRange(out, ":root");
|
|
159
|
-
const darkRange = blockRange(out, ".dark");
|
|
160
|
-
const names = new Set();
|
|
161
|
-
if (rootRange)
|
|
162
|
-
for (const [k] of parseDecls(out.slice(rootRange.open, rootRange.close)))
|
|
163
|
-
names.add(k);
|
|
164
|
-
if (darkRange)
|
|
165
|
-
for (const [k] of parseDecls(out.slice(darkRange.open, darkRange.close)))
|
|
166
|
-
names.add(k);
|
|
167
|
-
const missing = REQUIRED_TOKENS.filter((t) => !names.has(t));
|
|
168
|
-
if (missing.length > 0) {
|
|
169
|
-
throw new Error(`Theme "${theme.name}" leaves required tokens unset: ${missing.join(", ")}`);
|
|
170
|
-
}
|
|
171
|
-
return out;
|
|
172
|
-
}
|