cardbuddy 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -5
- package/dist/cli.js +51 -1
- package/dist/config.js +51 -16
- package/dist/core.js +2 -2
- package/dist/init.js +425 -0
- package/dist/preview-editor/assets/index-CHuGGIR3.js +276 -0
- package/dist/preview-editor/assets/{index-B4VZgNSK.css → index-CQScMhyg.css} +1 -1
- package/dist/preview-editor/index.html +2 -2
- package/dist/standalone.js +8 -0
- package/dist/vendored/mcp/client.mjs +537 -0
- package/dist/vendored/mcp/tools.mjs +268 -0
- package/dist/vendored/preview/assets/default-image.png +0 -0
- package/dist/{server-core → vendored/server/core}/ai-chat.js +82 -38
- package/dist/{server-core → vendored/server/core}/browser.js +1 -1
- package/dist/{server-core → vendored/server/core}/cardSave.js +8 -3
- package/dist/{server-core → vendored/server/core}/cardSync.js +6 -14
- package/dist/{server-core → vendored/server/core}/cardValidate.js +11 -8
- package/dist/{server-core → vendored/server/core}/index.js +5 -3
- package/dist/vendored/server/core/skillPaths.js +124 -0
- package/dist/{server-core → vendored/server/core}/sliceUpload.js +5 -8
- package/dist/vendored/skills/README.md +93 -0
- package/dist/vendored/skills/card-doctor/SKILL.md +52 -0
- package/dist/vendored/skills/card-skill-trainer/SKILL.md +312 -0
- package/dist/vendored/skills/card-skill-trainer/baselines/v3-r038n.json +43 -0
- package/dist/vendored/skills/card-skill-trainer/baselines/v3-r039n.json +47 -0
- package/dist/vendored/skills/card-skill-trainer/baselines/v3-r050n.json +48 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/build_dataset.py +472 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/build_sample.mjs +162 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/diagnose_case.mjs +241 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/lib/scoring.mjs +525 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/round_diff.mjs +133 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/run_round.mjs +1043 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/score_round.mjs +195 -0
- package/dist/vendored/skills/card-skill-trainer/scripts/test_missing_slice.py +122 -0
- package/dist/vendored/skills/dsl-card-ai/SKILL.md +191 -0
- package/dist/vendored/skills/dsl-card-generator/SKILL.md +480 -0
- package/dist/vendored/skills/dsl-card-generator/config/render-contract.json +11 -0
- package/dist/vendored/skills/dsl-card-generator/references/amount_formatting.md +138 -0
- package/dist/vendored/skills/dsl-card-generator/references/card_index.json +1597 -0
- package/dist/vendored/skills/dsl-card-generator/references/card_templates.json +384 -0
- package/dist/vendored/skills/dsl-card-generator/references/card_to_summary.md +56 -0
- package/dist/vendored/skills/dsl-card-generator/references/component_rules.md +76 -0
- package/dist/vendored/skills/dsl-card-generator/references/component_specs.md +393 -0
- package/dist/vendored/skills/dsl-card-generator/references/dsl_structure.md +208 -0
- package/dist/vendored/skills/dsl-card-generator/references/event_patterns.md +287 -0
- package/dist/vendored/skills/dsl-card-generator/references/expression_engine.md +121 -0
- package/dist/vendored/skills/dsl-card-generator/references/field_name_dict.json +34 -0
- package/dist/vendored/skills/dsl-card-generator/references/field_naming.md +101 -0
- package/dist/vendored/skills/dsl-card-generator/references/generation_pitfalls.md +928 -0
- package/dist/vendored/skills/dsl-card-generator/references/handcrafted/README.md +69 -0
- package/dist/vendored/skills/dsl-card-generator/references/handcrafted/examples_index.json +2967 -0
- package/dist/vendored/skills/dsl-card-generator/references/handcrafted/patterns.json +2835 -0
- package/dist/vendored/skills/dsl-card-generator/references/handcrafted/recipes_v2.json +648 -0
- package/dist/vendored/skills/dsl-card-generator/references/handcrafted/recipes_v2_schema.md +295 -0
- package/dist/vendored/skills/dsl-card-generator/references/image_diff.md +48 -0
- package/dist/vendored/skills/dsl-card-generator/references/image_to_card.md +129 -0
- package/dist/vendored/skills/dsl-card-generator/references/ir-format.md +212 -0
- package/dist/vendored/skills/dsl-card-generator/references/message-center-pattern.md +149 -0
- package/dist/vendored/skills/dsl-card-generator/references/platform_jsapi.md +196 -0
- package/dist/vendored/skills/dsl-card-generator/references/previewer_contract.md +54 -0
- package/dist/vendored/skills/dsl-card-generator/references/quickref.md +197 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/absolute-badge.json +84 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/accordion-group-toggle.json +18 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/alertCard-pair.json +12 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/alertDialog-call.json +12 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/canvas-countdown.json +15 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/canvas-donut.json +15 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/canvas-gauge-score.json +11 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/canvas-radar.json +10 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/canvas-title-head.json +13 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/globalSet.json +12 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/label-col-modes.json +21 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/list-expand-collapse.json +17 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/money-format.json +11 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/opacity-switch.json +130 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/progress-bar.json +25 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/tab-billMode.json +15 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipe_snippets/title-underline-overlay.json +21 -0
- package/dist/vendored/skills/dsl-card-generator/references/recipes.md +797 -0
- package/dist/vendored/skills/dsl-card-generator/references/rules.md +235 -0
- package/dist/vendored/skills/dsl-card-generator/references/slices_convention.md +177 -0
- package/dist/vendored/skills/dsl-card-generator/references/spec_to_schema_patterns.md +609 -0
- package/dist/vendored/skills/dsl-card-generator/references/ui_fidelity_rules.md +131 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/add_component.mjs +118 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/analyze_component_usage.mjs +153 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/apply_opacity_pattern.mjs +343 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/build_card_index.mjs +108 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/build_card_templates.mjs +190 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/check_fidelity.mjs +257 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/check_magic_values.mjs +79 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/crop_slices.mjs +98 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/describe_card.mjs +265 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/diff_bands.mjs +257 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/diff_card.mjs +316 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/expand_ir.mjs +873 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/extract_handcrafted.py +1199 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/extract_subtree.mjs +191 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/generate_cards.mjs +389 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/inventory_schemas.py +160 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/iterate.mjs +700 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/design_image.mjs +56 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/design_sample.mjs +328 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/layout-tokens.mjs +79 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/paths.mjs +103 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/scaffold.mjs +575 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/slicePath.mjs +81 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lib/slice_dedupe.mjs +147 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lint_autofix.mjs +363 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/lint_card.mjs +1399 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/preflight.mjs +249 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/register_card_template.mjs +208 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/render_baseline.mjs +231 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/render_card.mjs +801 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/render_diff.mjs +239 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/resolve_card_template.mjs +73 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/route_input.mjs +447 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/scaffold_card.mjs +81 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/slices_normalize.mjs +316 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/spec_audit.mjs +462 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/spec_to_schema_v3.mjs +7735 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/spec_tree.mjs +355 -0
- package/dist/vendored/skills/dsl-card-generator/scripts/validate_all_schemas.py +71 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/assets/default-image-wzZYQ86K.png +0 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/assets/standalone-C9k-07y7.css +1 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/assets/standalone-oFRM4f4V.js +55 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/assets/svg-symbols-B2exBrAr.svg +118 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/meta/component-meta.json +2714 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/meta/directive-meta.json +40 -0
- package/dist/vendored/skills/dsl-card-generator/vendor/preview/meta/style-meta.json +1086 -0
- package/dist/vendored/{standalone.html → skills/dsl-card-generator/vendor/preview/standalone.html} +2 -1
- package/dist/vendored/skills/finmall-card-sync/SKILL.md +262 -0
- package/dist/vendored/skills/finmall-session-navigator/SKILL.md +169 -0
- package/dist/vendored/skills/finmall-session-navigator/scripts/finmall_login.mjs +882 -0
- package/dist/vendored/skills/finmall-session-navigator/scripts/package-lock.json +59 -0
- package/dist/vendored/skills/finmall-session-navigator/scripts/package.json +10 -0
- package/dist/vendored/skills/finmall-session-navigator/scripts/session-manager.mjs +96 -0
- package/dist/vendored/skills/shared/README.md +55 -0
- package/dist/vendored/skills/shared/auth-model.md +79 -0
- package/dist/vendored/skills/sketch-spec-to-card/SKILL.md +329 -0
- package/dist/vendored/skills/sketch-spec-to-card/references/boundary.json +14 -0
- package/dist/vendored/skills/sketch-spec-to-card/references/card_refs.json +13 -0
- package/dist/vendored/skills/sketch-spec-to-card/references/spec-schema.md +103 -0
- package/dist/vendored/skills/sketch-spec-to-card/scripts/build_prompt.py +797 -0
- package/dist/vendored/skills/sketch-spec-to-card/scripts/card_refs.py +94 -0
- package/dist/vendored/skills/sketch-spec-to-card/scripts/cluster_states.py +706 -0
- package/dist/vendored/skills/sketch-spec-to-card/scripts/parse_meaxure.py +1781 -0
- package/dist/vendored/skills/sketch-spec-to-card/scripts/png_utils.py +318 -0
- package/dist/vendored/skills/sketch-spec-to-card/scripts/vision.py +1118 -0
- package/dist/vendored/templates/helloCard/data.json +10 -0
- package/dist/vendored/templates/helloCard/schema.json +238 -0
- package/dist/vendored/tools/link-skills.mjs +485 -0
- package/package.json +2 -1
- package/dist/preview-editor/assets/index-jl4YJzKv.js +0 -180
- package/dist/vendored/App.vue +0 -2858
- package/dist/vendored/ansi.js +0 -185
- package/dist/vendored/assets/apple-touch-icon.png +0 -0
- package/dist/vendored/assets/default-image.png +0 -0
- package/dist/vendored/assets/favicon-16.png +0 -0
- package/dist/vendored/assets/favicon-32.png +0 -0
- package/dist/vendored/assets/site-icon.png +0 -0
- package/dist/vendored/assets/svgIcons/icons.svg +0 -87
- package/dist/vendored/assets/svgIcons/index.js +0 -39
- package/dist/vendored/components/AiSettings.vue +0 -392
- package/dist/vendored/components/AlertCardInstance.vue +0 -58
- package/dist/vendored/components/AlertCardLayer.vue +0 -59
- package/dist/vendored/components/ApiCallPanel.vue +0 -127
- package/dist/vendored/components/ApiPayloadTree.vue +0 -201
- package/dist/vendored/components/AppToast.vue +0 -37
- package/dist/vendored/components/CardGallery.vue +0 -291
- package/dist/vendored/components/CardPreview.vue +0 -72
- package/dist/vendored/components/CardSelect.vue +0 -206
- package/dist/vendored/components/ChatComposer.vue +0 -413
- package/dist/vendored/components/ChatMessage.vue +0 -383
- package/dist/vendored/components/ChatPanel.vue +0 -937
- package/dist/vendored/components/ComponentPalette.vue +0 -301
- package/dist/vendored/components/ConfirmDialog.vue +0 -54
- package/dist/vendored/components/DatePickerOverlay.vue +0 -345
- package/dist/vendored/components/DebugPanel.vue +0 -1734
- package/dist/vendored/components/DeviceOverlay.vue +0 -70
- package/dist/vendored/components/Dropdown.vue +0 -193
- package/dist/vendored/components/EventEditor.vue +0 -273
- package/dist/vendored/components/HoverGuides.vue +0 -122
- package/dist/vendored/components/JsonTree.vue +0 -547
- package/dist/vendored/components/LogValue.vue +0 -52
- package/dist/vendored/components/MarkdownBody.vue +0 -64
- package/dist/vendored/components/NewCardDialog.vue +0 -132
- package/dist/vendored/components/NodeInspector.vue +0 -295
- package/dist/vendored/components/NumberStepper.vue +0 -125
- package/dist/vendored/components/PickerOverlay.vue +0 -131
- package/dist/vendored/components/PropControl.vue +0 -245
- package/dist/vendored/components/PropTree.vue +0 -128
- package/dist/vendored/components/RemotePreview.vue +0 -173
- package/dist/vendored/components/SelectionOverlay.vue +0 -105
- package/dist/vendored/components/StructureTree.vue +0 -1002
- package/dist/vendored/components/Switch.vue +0 -38
- package/dist/vendored/components/setters/SetBgPosition.vue +0 -64
- package/dist/vendored/components/setters/SetBgSize.vue +0 -90
- package/dist/vendored/components/setters/SetCode.vue +0 -198
- package/dist/vendored/components/setters/SetColor.vue +0 -244
- package/dist/vendored/components/setters/SetCustomSelect.vue +0 -58
- package/dist/vendored/components/setters/SetExpr.vue +0 -107
- package/dist/vendored/components/setters/SetGradient.vue +0 -125
- package/dist/vendored/components/setters/SetGrid9.vue +0 -68
- package/dist/vendored/components/setters/SetIconSelect.vue +0 -67
- package/dist/vendored/components/setters/SetIfForm.vue +0 -61
- package/dist/vendored/components/setters/SetImage.vue +0 -43
- package/dist/vendored/components/setters/SetList.vue +0 -139
- package/dist/vendored/components/setters/SetNumber.vue +0 -118
- package/dist/vendored/components/setters/SetNumberStyle.vue +0 -113
- package/dist/vendored/components/setters/SetPadding.vue +0 -77
- package/dist/vendored/components/setters/SetSegment.vue +0 -160
- package/dist/vendored/components/setters/SetSelect.vue +0 -51
- package/dist/vendored/components/setters/SetSwitch.vue +0 -49
- package/dist/vendored/components/setters/SetText.vue +0 -52
- package/dist/vendored/components/setters/props.js +0 -23
- package/dist/vendored/fidelity/baseline-messageOverview.json +0 -87
- package/dist/vendored/fidelity/calibration.json +0 -29
- package/dist/vendored/fidelity/fidelity-messageOverview-after.html +0 -114
- package/dist/vendored/fidelity/fidelity-messageOverview-after.json +0 -272
- package/dist/vendored/fidelity/fidelity-messageOverview.html +0 -185
- package/dist/vendored/fidelity/fidelity-messageOverview.json +0 -336
- package/dist/vendored/fidelity/fidelity-messageOverview_v2.html +0 -262
- package/dist/vendored/fidelity/fidelity-messageOverview_v2.json +0 -502
- package/dist/vendored/fidelity/fidelity-messageOverview_v3.html +0 -201
- package/dist/vendored/fidelity/fidelity-messageOverview_v3.json +0 -417
- package/dist/vendored/fidelity/fidelity-messageOverview_visual.html +0 -125
- package/dist/vendored/fidelity/fidelity-messageOverview_visual.json +0 -338
- package/dist/vendored/index.html +0 -16
- package/dist/vendored/main.js +0 -37
- package/dist/vendored/runtime/ai-api.js +0 -165
- package/dist/vendored/runtime/alert-card.js +0 -125
- package/dist/vendored/runtime/app-toast.js +0 -33
- package/dist/vendored/runtime/clipboard-node.js +0 -78
- package/dist/vendored/runtime/clipboard.js +0 -29
- package/dist/vendored/runtime/event-model.js +0 -300
- package/dist/vendored/runtime/hoverGuide.js +0 -31
- package/dist/vendored/runtime/jsapi-mock.js +0 -256
- package/dist/vendored/runtime/markdown.js +0 -140
- package/dist/vendored/runtime/node-model.js +0 -217
- package/dist/vendored/skills/.manifest.json +0 -1101
- package/dist/vendored/standalone-main.js +0 -36
- package/dist/vendored/styles/ai-chat.css +0 -1850
- package/dist/vendored/styles/app.css +0 -3648
- package/dist/vendored/styles/card-gallery.css +0 -285
- package/dist/vendored/styles/card-select.css +0 -288
- package/dist/vendored/styles/components.css +0 -383
- package/dist/vendored/styles/dropdown.css +0 -324
- package/dist/vendored/styles/json-tree.css +0 -308
- package/dist/vendored/styles/node-inspector.css +0 -800
- package/dist/vendored/styles/setters.css +0 -1050
- package/dist/vendored/styles/standalone.css +0 -27
- package/dist/vendored/styles/structure-tree.css +0 -460
- /package/dist/vendored/{api.js → preview/api.js} +0 -0
- /package/dist/vendored/{assets → preview/assets}/svg-symbols.svg +0 -0
- /package/dist/vendored/{components → preview/components}/AbsoluteLayout.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Button.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Canvas.vue +0 -0
- /package/dist/vendored/{components → preview/components}/CheckGroup.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Column.vue +0 -0
- /package/dist/vendored/{components → preview/components}/CustomPlaceholder.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Divider.vue +0 -0
- /package/dist/vendored/{components → preview/components}/GridLayout.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Icon.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Image.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Input.vue +0 -0
- /package/dist/vendored/{components → preview/components}/ListLayout.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Map.vue +0 -0
- /package/dist/vendored/{components → preview/components}/MultiColumn.vue +0 -0
- /package/dist/vendored/{components → preview/components}/MultiText.vue +0 -0
- /package/dist/vendored/{components → preview/components}/ProgressSlider.vue +0 -0
- /package/dist/vendored/{components → preview/components}/RadioButton.vue +0 -0
- /package/dist/vendored/{components → preview/components}/RenderTree.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Root.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Row.vue +0 -0
- /package/dist/vendored/{components → preview/components}/SvgCode.vue +0 -0
- /package/dist/vendored/{components → preview/components}/SvgSymbols.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Text.vue +0 -0
- /package/dist/vendored/{components → preview/components}/Video.vue +0 -0
- /package/dist/vendored/{components → preview/components}/ViewContainer.vue +0 -0
- /package/dist/vendored/{components → preview/components}/base.js +0 -0
- /package/dist/vendored/{components → preview/components}/icons.js +0 -0
- /package/dist/vendored/{components → preview/components}/index.js +0 -0
- /package/dist/vendored/{meta → preview/meta}/component-meta.json +0 -0
- /package/dist/vendored/{meta → preview/meta}/directive-meta.json +0 -0
- /package/dist/vendored/{meta → preview/meta}/style-meta.json +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/StyleParser.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/adapter.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/assets.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/canvas-context.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/card-runtime.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/evaluate.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/property.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/selectionOverlay.js +0 -0
- /package/dist/vendored/{runtime → preview/runtime}/toPreview.js +0 -0
- /package/dist/{server-core → vendored/server/core}/assetProxy.js +0 -0
- /package/dist/{server-core → vendored/server/core}/bbox.js +0 -0
- /package/dist/{server-core → vendored/server/core}/buildDataFromSchema.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardFiles.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardHistory.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardImage.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardImportMeta.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardListCache.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardOpenFolder.js +0 -0
- /package/dist/{server-core → vendored/server/core}/cardSidecar.js +0 -0
- /package/dist/{server-core → vendored/server/core}/codeBridge.js +0 -0
- /package/dist/{server-core → vendored/server/core}/logStream.js +0 -0
- /package/dist/{server-core → vendored/server/core}/logger.js +0 -0
- /package/dist/{server-core → vendored/server/core}/nodeModels.js +0 -0
- /package/dist/{server-core → vendored/server/core}/renderStatus.js +0 -0
- /package/dist/{server-core → vendored/server/core}/screenshot.js +0 -0
- /package/dist/{server-core → vendored/server/core}/sliceStatic.js +0 -0
- /package/dist/vendored/{meta → skills/dsl-card-generator/vendor/preview/meta}/action-meta.json +0 -0
- /package/dist/{server-core/_vendor → vendored/tools}/finmall-env.mjs +0 -0
|
@@ -0,0 +1,873 @@
|
|
|
1
|
+
#/** Cross-platform Python detection */
|
|
2
|
+
function findPython() {
|
|
3
|
+
if (process.env.DSL_CARD_PYTHON) return process.env.DSL_CARD_PYTHON;
|
|
4
|
+
if (process.env.WORKBUDDY_PYTHON) return process.env.WORKBUDDY_PYTHON;
|
|
5
|
+
return "python3";
|
|
6
|
+
}
|
|
7
|
+
!/usr/bin/env node
|
|
8
|
+
/**
|
|
9
|
+
* expand_ir.mjs — 紧凑 IR(Intermediate Representation)⇄ 完整 schema 双向转换。
|
|
10
|
+
*
|
|
11
|
+
* 解决的问题:schema.json 是「编辑器持久化格式」,单卡可达 600KB+(96 节点 666KB),
|
|
12
|
+
* 因为每个属性都写满 itemId/itemKey/itemValueFrom/itemValue/itemDefaultValue,并全量写出
|
|
13
|
+
* 空 directives/eventactions/slots。AI 直接输出完整 schema 会爆炸(36.9x 冗余)。
|
|
14
|
+
*
|
|
15
|
+
* 本脚本让 AI 只输出**最小语义 IR**(className / 主值 / 属性 / 样式 / 指令 / 事件 / 子节点),
|
|
16
|
+
* 由脚本复用 vendor/preview/meta 的 itemId 映射展开成完整 schema(与现有卡片同构、过 validate+lint)。
|
|
17
|
+
*
|
|
18
|
+
* 用法:
|
|
19
|
+
* node expand_ir.mjs --ir <IR.json> --out <dir>/ # IR → schema.json + data.json(写盘并 autofix+validate)
|
|
20
|
+
* [--slices-dir <dir>] # 引用切图的来源目录(默认 IR 同目录 slices/)
|
|
21
|
+
* node expand_ir.mjs --to-ir <schema.json> # 完整 schema → 紧凑 IR(stdout,用于验证/二次编辑)
|
|
22
|
+
* node expand_ir.mjs --self-test [--card DepositHolding] # round-trip 无损 + validate + lint 自检
|
|
23
|
+
*
|
|
24
|
+
* IR 字段契约(详见 references/ir-format.md):
|
|
25
|
+
* 节点:{ c, id?, name?, t?, v?, p?, pi?, s?, d?, e?, children?|slots? }
|
|
26
|
+
* c className(必填)
|
|
27
|
+
* t 常量主值(等价于 p.value 常量) v 变量主值(等价于 p.value 变量,互斥)
|
|
28
|
+
* p 其他常量属性 {key: value} pi 图片属性 {key: value}(itemValueFrom=2)
|
|
29
|
+
* s 样式 {groupKey: {childKey: value} | scalar}
|
|
30
|
+
* d 指令 {key: {childKey:value} | value}
|
|
31
|
+
* e 事件 ["click"] 或 [{key, action, code?, props?}]
|
|
32
|
+
* children 默认插槽子节点(简写);slots {slotKey: [ir...]} 多插槽(listScope 插槽 slotScope=true)
|
|
33
|
+
* 顶层:{ id?, name?, platform?, width?, viewId?, dictionary?, children: [ir...] }
|
|
34
|
+
*/
|
|
35
|
+
import fs from 'node:fs'
|
|
36
|
+
import path from 'node:path'
|
|
37
|
+
import { execFileSync } from 'node:child_process'
|
|
38
|
+
import { fileURLToPath } from 'node:url'
|
|
39
|
+
import { copyCardDesignImage } from './lib/design_image.mjs'
|
|
40
|
+
import { metaDir, skillRoot } from './lib/paths.mjs'
|
|
41
|
+
import { buildContentIndex, rewriteSliceRefs, sha256File } from './lib/slice_dedupe.mjs'
|
|
42
|
+
|
|
43
|
+
/* ------------------------------------------------------------------ */
|
|
44
|
+
/* 加载 meta → itemId 映射(与 validate_schema.py 同源,零偏离) */
|
|
45
|
+
/* ------------------------------------------------------------------ */
|
|
46
|
+
function loadJSON(f) {
|
|
47
|
+
return JSON.parse(fs.readFileSync(path.join(metaDir, f), 'utf8'))
|
|
48
|
+
}
|
|
49
|
+
const CM = loadJSON('component-meta.json')
|
|
50
|
+
const SM = loadJSON('style-meta.json')
|
|
51
|
+
const DM = loadJSON('directive-meta.json')
|
|
52
|
+
const AM = loadJSON('action-meta.json')
|
|
53
|
+
|
|
54
|
+
// 组件属性 itemId: compPropId[className][itemKey] = itemId
|
|
55
|
+
const compPropId = {}
|
|
56
|
+
for (const [cn, meta] of Object.entries(CM.components || {})) {
|
|
57
|
+
compPropId[cn] = {}
|
|
58
|
+
for (const p of meta.properties || []) compPropId[cn][p.itemKey] = p.itemId
|
|
59
|
+
}
|
|
60
|
+
// style group / child itemId
|
|
61
|
+
const styleGroupId = {}
|
|
62
|
+
const styleChildId = {}
|
|
63
|
+
for (const g of SM.properties || []) {
|
|
64
|
+
styleGroupId[g.itemKey] = g.itemId
|
|
65
|
+
styleChildId[g.itemKey] = {}
|
|
66
|
+
for (const c of g.itemChildren || []) styleChildId[g.itemKey][c.itemKey] = c.itemId
|
|
67
|
+
}
|
|
68
|
+
// Alias resolution: common abbreviated IR style keys → actual style-meta itemKey.
|
|
69
|
+
// Safety net for AI writing shorthand (e.g. `shrink` instead of `flexShrink`).
|
|
70
|
+
const STYLE_ALIAS = {
|
|
71
|
+
size: 'fontSize',
|
|
72
|
+
bold: 'fontWeight',
|
|
73
|
+
lh: 'lineHeight',
|
|
74
|
+
align: 'textAlign',
|
|
75
|
+
shrink: 'flexShrink',
|
|
76
|
+
dir: 'flexDirection',
|
|
77
|
+
justify: 'justifyContent',
|
|
78
|
+
items: 'alignItems',
|
|
79
|
+
radius: 'borderRadius',
|
|
80
|
+
bg: 'backgroundColor',
|
|
81
|
+
bgType: 'backgroundType',
|
|
82
|
+
pad: 'padding',
|
|
83
|
+
padT: 'paddingTop',
|
|
84
|
+
padB: 'paddingBottom',
|
|
85
|
+
padL: 'paddingLeft',
|
|
86
|
+
padR: 'paddingRight',
|
|
87
|
+
marT: 'marginTop',
|
|
88
|
+
marB: 'marginBottom',
|
|
89
|
+
marL: 'marginLeft',
|
|
90
|
+
marR: 'marginRight',
|
|
91
|
+
w: 'width',
|
|
92
|
+
h: 'height',
|
|
93
|
+
}
|
|
94
|
+
function resolveStyleKey(groupKey, childKey) {
|
|
95
|
+
if (styleChildId[groupKey]?.[childKey] !== undefined) return childKey
|
|
96
|
+
const resolved = STYLE_ALIAS[childKey]
|
|
97
|
+
if (resolved && styleChildId[groupKey]?.[resolved] !== undefined) return resolved
|
|
98
|
+
return childKey // no match — let it pass through (validate will catch)
|
|
99
|
+
}
|
|
100
|
+
// directive itemId + child
|
|
101
|
+
const dirId = {}
|
|
102
|
+
const dirChildId = {}
|
|
103
|
+
const dirIsGroup = {}
|
|
104
|
+
for (const d of DM.properties || []) {
|
|
105
|
+
dirId[d.itemKey] = d.itemId
|
|
106
|
+
dirChildId[d.itemKey] = {}
|
|
107
|
+
const childKeys = (d.itemChildren || []).map((c) => c.itemKey)
|
|
108
|
+
for (const c of d.itemChildren || []) dirChildId[d.itemKey][c.itemKey] = c.itemId
|
|
109
|
+
// Group 指令(如 v-show):必须有 itemValueFrom:'0' + itemChildren,不能用裸字符串表达式
|
|
110
|
+
dirIsGroup[d.itemKey] = childKeys.length > 0
|
|
111
|
+
}
|
|
112
|
+
// 把「裸表达式字符串」提升为 Group 指令的标准对象结构(仅当指令确为 Group 类型时)
|
|
113
|
+
// 例:d:{ "v-show": "$_index != $list.length - 1" } → { itemValueFrom:'0', itemChildren:{ showType:'01', condition:{name,expression} } }
|
|
114
|
+
// 否则会被 onPreview 当成 itemValueFrom:'1' 丢弃(指令条件失效、永远显示)。
|
|
115
|
+
// R52: v-show 显隐设置显示名(condition.name)必填——表达式 <15 字符与表达式一致;>=15 字符必须显式给合适命名(不得抄表达式)
|
|
116
|
+
function normalizeVshow(dv) {
|
|
117
|
+
const cond = dv && dv.condition
|
|
118
|
+
if (!cond || typeof cond !== 'object' || !cond.expression) return dv
|
|
119
|
+
const expr = String(cond.expression)
|
|
120
|
+
const name = cond.name == null ? '' : String(cond.name).trim()
|
|
121
|
+
if (name) return dv
|
|
122
|
+
if (expr.length < 15) return { ...dv, condition: { ...cond, name: expr } }
|
|
123
|
+
throw new Error(`IR v-show 条件表达式 ${expr.length} 字符(>=15):显隐设置显示名 condition.name 必填且应设合适命名(不得抄表达式),请在 IR 的 condition 里补 name:${expr}`)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function groupDirectiveFromExpr(dk, expr) {
|
|
127
|
+
const childKeys = Object.keys(dirChildId[dk] || {})
|
|
128
|
+
const props = []
|
|
129
|
+
if (childKeys.includes('showType')) props.push(makeProp(dirChildId[dk].showType, 'showType', '01', '0'))
|
|
130
|
+
const condKey = childKeys.includes('condition') ? 'condition' : childKeys[0]
|
|
131
|
+
if (condKey) props.push(makeProp(dirChildId[dk][condKey], condKey, { name: expr, expression: expr }, '0'))
|
|
132
|
+
return {
|
|
133
|
+
itemId: dirId[dk] ?? '',
|
|
134
|
+
itemKey: dk,
|
|
135
|
+
itemName: dk,
|
|
136
|
+
itemType: '',
|
|
137
|
+
itemValueFrom: '0',
|
|
138
|
+
itemValue: {},
|
|
139
|
+
itemDefaultValue: {},
|
|
140
|
+
itemChildren: { properties: props },
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// action property itemId: actPropId[actionType][itemKey] = itemId
|
|
144
|
+
const actPropId = {}
|
|
145
|
+
for (const a of AM.actions || []) {
|
|
146
|
+
actPropId[a.actionType] = {}
|
|
147
|
+
for (const p of a.properties || []) actPropId[a.actionType][p.itemKey] = p.itemId
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const isVar = (v) => typeof v === 'string' && v.startsWith('$')
|
|
151
|
+
|
|
152
|
+
/* ------------------------------------------------------------------ */
|
|
153
|
+
/* IR → 完整节点 */
|
|
154
|
+
/* ------------------------------------------------------------------ */
|
|
155
|
+
function makeProp(itemId, key, val, from) {
|
|
156
|
+
const v = val === undefined ? null : val
|
|
157
|
+
const varFlag = from === '1' || from === '2'
|
|
158
|
+
return {
|
|
159
|
+
itemId: itemId ?? '',
|
|
160
|
+
itemKey: key,
|
|
161
|
+
itemName: key,
|
|
162
|
+
itemType: '',
|
|
163
|
+
itemValueFrom: String(from),
|
|
164
|
+
itemValue: v,
|
|
165
|
+
itemDefaultValue: varFlag ? '' : v,
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const EVENT_NAMES = { click: '点击', onMeasured: 'onMeasured', input: '输入', change: '变化' }
|
|
170
|
+
function eventName(ek) { return EVENT_NAMES[ek] || ek }
|
|
171
|
+
|
|
172
|
+
function makeEvent(evSpec) {
|
|
173
|
+
if (typeof evSpec === 'string') {
|
|
174
|
+
return {
|
|
175
|
+
event: { eventKey: evSpec, eventName: eventName(evSpec) },
|
|
176
|
+
action: {
|
|
177
|
+
actionType: 'customAction',
|
|
178
|
+
properties: [makeProp(actPropId.customAction?.function, 'function', { code: '// TODO: 处理点击' }, '0')],
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const actionType = evSpec.action || 'customAction'
|
|
183
|
+
const ek = evSpec.key || 'click'
|
|
184
|
+
const props = []
|
|
185
|
+
if (actionType === 'customAction') {
|
|
186
|
+
const code = evSpec.code ?? evSpec.props?.function ?? '// TODO'
|
|
187
|
+
props.push(makeProp(actPropId.customAction?.function, 'function', { code }, '0'))
|
|
188
|
+
} else {
|
|
189
|
+
for (const p of (AM.actions.find((a) => a.actionType === actionType)?.properties || [])) {
|
|
190
|
+
const raw = evSpec[p.itemKey] ?? evSpec.props?.[p.itemKey]
|
|
191
|
+
const v = raw !== undefined ? raw : (p.itemDefaultValue ?? '')
|
|
192
|
+
props.push(makeProp(actPropId[actionType]?.[p.itemKey], p.itemKey, v, '0'))
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { event: { eventKey: ek, eventName: eventName(ek) }, action: { actionType, properties: props } }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 根节点核心样式默认值:gap=0、background=透明、padding=0、borderRadius=0
|
|
199
|
+
// 只对根节点(view)生效,子节点样式由 IR 按需设置
|
|
200
|
+
function ensureRootDefaults(view) {
|
|
201
|
+
const props = view.style.properties
|
|
202
|
+
const hasGroup = (key) => props.some((p) => p.itemKey === key)
|
|
203
|
+
|
|
204
|
+
function makeChild(itemId, key, val) {
|
|
205
|
+
return { itemId: itemId ?? '', itemKey: key, itemName: key, itemType: '', itemValueFrom: '0', itemValue: val, itemDefaultValue: val }
|
|
206
|
+
}
|
|
207
|
+
function makeGroup(gid, gkey, children) {
|
|
208
|
+
return { itemId: gid, itemKey: gkey, itemName: gkey, itemType: 'group', itemValueFrom: '0', itemValue: {}, itemDefaultValue: {}, itemChildren: { properties: children } }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!hasGroup('background')) {
|
|
212
|
+
props.push(makeGroup('300', 'background', [makeChild('001', 'backgroundType', '00')]))
|
|
213
|
+
}
|
|
214
|
+
if (!hasGroup('borderRadius')) {
|
|
215
|
+
props.push(makeGroup('600', 'borderRadius', [makeChild('001', 'borderRadiusType', '0'), makeChild('002', 'borderRadius', '0')]))
|
|
216
|
+
}
|
|
217
|
+
if (!hasGroup('padding')) {
|
|
218
|
+
props.push(makeGroup('400', 'padding', [
|
|
219
|
+
makeChild('001', 'paddingType', '1'), makeChild('003', 'paddingLeft', '0'),
|
|
220
|
+
makeChild('004', 'paddingTop', '0'), makeChild('005', 'paddingRight', '0'), makeChild('006', 'paddingBottom', '0'),
|
|
221
|
+
]))
|
|
222
|
+
}
|
|
223
|
+
const flexGrp = props.find((p) => p.itemKey === 'flex')
|
|
224
|
+
if (flexGrp && !(flexGrp.itemChildren?.properties || []).some((c) => c.itemKey === 'gap')) {
|
|
225
|
+
flexGrp.itemChildren.properties.push(makeChild(styleChildId.flex?.gap, 'gap', '0'))
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** 把 IR 的属性/样式/指令/事件填进节点(不含 children/slots,供 Root 与子节点共用)。 */
|
|
229
|
+
function applyProps(node, ir) {
|
|
230
|
+
const className = node.className
|
|
231
|
+
// 主值 value(t / v)
|
|
232
|
+
if (ir.t !== undefined && ir.v !== undefined) {
|
|
233
|
+
// 实测事故:--set 给已有 t 的节点补 v 后,t 被当主值、from 却按绑定标 "1",
|
|
234
|
+
// 渲染器把字面量当表达式求值 → 静默显示占位文案「这是一个文本」。二者互斥,响亮报错。
|
|
235
|
+
throw new Error(`节点 "${ir.id || className}" 同时给了 t(字面量主值)与 v(绑定主值):二者互斥。要绑定只留 v:"$key",要字面量只留 t;请删掉其中一个(--set 不能删键时直接改 IR 文件)`)
|
|
236
|
+
}
|
|
237
|
+
if (ir.t !== undefined || ir.v !== undefined) {
|
|
238
|
+
const raw = ir.t !== undefined ? ir.t : ir.v
|
|
239
|
+
const from = ir.v !== undefined || isVar(raw) ? '1' : '0'
|
|
240
|
+
node.properties.push(makeProp(compPropId[className]?.value, 'value', raw, from))
|
|
241
|
+
}
|
|
242
|
+
// 其他常量属性 p
|
|
243
|
+
for (const [k, val] of Object.entries(ir.p || {})) {
|
|
244
|
+
node.properties.push(makeProp(compPropId[className]?.[k], k, val, isVar(val) ? '1' : '0'))
|
|
245
|
+
}
|
|
246
|
+
// 图片属性 pi(itemValueFrom=2)
|
|
247
|
+
for (const [k, val] of Object.entries(ir.pi || {})) {
|
|
248
|
+
node.properties.push(makeProp(compPropId[className]?.[k], k, val, '2'))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 背景自动补 backgroundType(防止「设了 backgroundColor 但渲染透明」)
|
|
252
|
+
if (ir.s?.background && typeof ir.s.background === 'object') {
|
|
253
|
+
if (ir.s.background.backgroundColor && !ir.s.background.backgroundType) {
|
|
254
|
+
ir.s.background.backgroundType = '01'
|
|
255
|
+
}
|
|
256
|
+
if (ir.s.background.backgroundGradient && !ir.s.background.backgroundType) {
|
|
257
|
+
ir.s.background.backgroundType = '03'
|
|
258
|
+
}
|
|
259
|
+
if (ir.s.background.backgroundImage && !ir.s.background.backgroundType) {
|
|
260
|
+
ir.s.background.backgroundType = '02'
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 外/内边距自动补 marginType / paddingType(防止「设了 marginTop 但渲染器按默认类型忽略」)
|
|
265
|
+
// 实测事故:6 处 margin 组漏 marginType:"1" → 渲染器整组忽略 → 卡片塌掉 86px,
|
|
266
|
+
// 模型连调 9 轮 iterate 都没定位到(散文铁律在步数压力下不会被读到,只有机械兜底才靠得住)。
|
|
267
|
+
for (const [gk, typeKey] of [['margin', 'marginType'], ['padding', 'paddingType']]) {
|
|
268
|
+
const g = ir.s?.[gk]
|
|
269
|
+
if (!g || typeof g !== 'object' || Array.isArray(g)) continue
|
|
270
|
+
const hasSide = ['Top', 'Right', 'Bottom', 'Left'].some((d) => g[`${gk}${d}`] !== undefined)
|
|
271
|
+
if (hasSide && !g[typeKey]) g[typeKey] = '1'
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 圆角自动补 borderRadiusType(防止「设了 borderRadius 但渲染无圆角」)
|
|
275
|
+
if (ir.s?.borderRadius && typeof ir.s.borderRadius === 'object') {
|
|
276
|
+
if (ir.s.borderRadius.borderRadius && !ir.s.borderRadius.borderRadiusType) {
|
|
277
|
+
ir.s.borderRadius.borderRadiusType = '0'
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// 边框自动补 isBorder(防止「设了 borderColor 但渲染无边框」)
|
|
282
|
+
if (ir.s?.border && typeof ir.s.border === 'object') {
|
|
283
|
+
if ((ir.s.border.borderColor || ir.s.border.borderWidth) && !ir.s.border.isBorder) {
|
|
284
|
+
ir.s.border.isBorder = '1'
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 阴影自动补 isShadow(防止「设了 shadowColor 但渲染无阴影」)
|
|
289
|
+
if (ir.s?.shadow && typeof ir.s.shadow === 'object') {
|
|
290
|
+
if (ir.s.shadow.shadowColor && !ir.s.shadow.isShadow) {
|
|
291
|
+
ir.s.shadow.isShadow = '1'
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// 样式 s:group → {child: value} 或标量
|
|
296
|
+
for (const [gk, gv] of Object.entries(ir.s || {})) {
|
|
297
|
+
const isObj = gv && typeof gv === 'object' && !Array.isArray(gv)
|
|
298
|
+
const gnode = {
|
|
299
|
+
itemId: styleGroupId[gk] ?? '',
|
|
300
|
+
itemKey: gk,
|
|
301
|
+
itemName: gk,
|
|
302
|
+
itemType: 'group',
|
|
303
|
+
itemValueFrom: '0',
|
|
304
|
+
itemValue: isObj ? {} : gv,
|
|
305
|
+
itemDefaultValue: isObj ? {} : gv,
|
|
306
|
+
}
|
|
307
|
+
if (isObj) {
|
|
308
|
+
gnode.itemChildren = {
|
|
309
|
+
properties: Object.entries(gv).map(([ck, cv]) => {
|
|
310
|
+
const rk = resolveStyleKey(gk, ck)
|
|
311
|
+
return makeProp(styleChildId[gk]?.[rk], rk, cv, isVar(cv) ? '1' : '0')
|
|
312
|
+
}),
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
node.style.properties.push(gnode)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// 指令 d
|
|
319
|
+
for (const [dk, dv] of Object.entries(ir.d || {})) {
|
|
320
|
+
if (dv && typeof dv === 'object' && !Array.isArray(dv)) {
|
|
321
|
+
const dvv = dk === 'v-show' ? normalizeVshow(dv) : dv
|
|
322
|
+
node.directives.push({
|
|
323
|
+
itemId: dirId[dk] ?? '',
|
|
324
|
+
itemKey: dk,
|
|
325
|
+
itemName: dk,
|
|
326
|
+
itemType: '',
|
|
327
|
+
itemValueFrom: '0',
|
|
328
|
+
itemValue: {},
|
|
329
|
+
itemDefaultValue: {},
|
|
330
|
+
itemChildren: {
|
|
331
|
+
properties: Object.entries(dvv).map(([ck, cv]) => makeProp(dirChildId[dk]?.[ck], ck, cv, isVar(cv) ? '1' : '0')),
|
|
332
|
+
},
|
|
333
|
+
})
|
|
334
|
+
} else if (dirIsGroup[dk]) {
|
|
335
|
+
// Group 指令被写成裸表达式字符串:自动升级为对象结构,避免 itemValueFrom:'1' 被渲染器丢弃
|
|
336
|
+
node.directives.push(groupDirectiveFromExpr(dk, dv))
|
|
337
|
+
} else {
|
|
338
|
+
node.directives.push(makeProp(dirId[dk], dk, dv, isVar(dv) ? '1' : '0'))
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 事件 e
|
|
343
|
+
for (const ev of ir.e || []) node.eventactions.push(makeEvent(ev))
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function expandNode(ir, ctx) {
|
|
347
|
+
const className = ir.c
|
|
348
|
+
if (!className) throw new Error('IR 节点缺少 className (c)')
|
|
349
|
+
const node = {
|
|
350
|
+
componentId: ir.id || ctx.nextId(),
|
|
351
|
+
className,
|
|
352
|
+
name: ir.name || className,
|
|
353
|
+
style: { properties: [] },
|
|
354
|
+
properties: [],
|
|
355
|
+
directives: [],
|
|
356
|
+
eventactions: [],
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
applyProps(node, ir)
|
|
360
|
+
|
|
361
|
+
// 插槽 / 子节点
|
|
362
|
+
const slotMap = ir.slots || (ir.children ? { default: ir.children } : {})
|
|
363
|
+
const isScopeContainer = className === 'ListLayout' || className === 'GridLayout'
|
|
364
|
+
const slotDefs = []
|
|
365
|
+
for (const [sk, kids] of Object.entries(slotMap)) {
|
|
366
|
+
if (!Array.isArray(kids)) continue
|
|
367
|
+
const scope = sk === 'listScope' || isScopeContainer
|
|
368
|
+
slotDefs.push({
|
|
369
|
+
slotKey: sk === 'listScope' ? 'default' : sk,
|
|
370
|
+
slotName: sk === 'default' ? '默认插槽' : sk,
|
|
371
|
+
slotSwitch: '1',
|
|
372
|
+
...(scope ? { slotScope: true } : {}),
|
|
373
|
+
components: kids.map((k) => expandNode(k, ctx)),
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
if (slotDefs.length) node.slots = slotDefs
|
|
377
|
+
return node
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/* ---- 根作用域 $ 绑定收集(排除 slotScope 子树)→ inputParams ---- */
|
|
381
|
+
function collectRootBindings(node, inScopeSlot, out) {
|
|
382
|
+
if (!node || typeof node !== 'object') return
|
|
383
|
+
if (!inScopeSlot) {
|
|
384
|
+
const scan = (v) => {
|
|
385
|
+
if (typeof v === 'string') {
|
|
386
|
+
const re = /\$([A-Za-z_][A-Za-z0-9_]*)/g
|
|
387
|
+
let m
|
|
388
|
+
while ((m = re.exec(v))) out.add(m[1])
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
for (const p of node.properties || []) if (p.itemValueFrom === '1') scan(p.itemValue)
|
|
392
|
+
for (const p of node.style?.properties || []) if (p.itemValueFrom === '1') scan(p.itemValue)
|
|
393
|
+
for (const d of node.directives || []) if (d.itemValueFrom === '1') scan(d.itemValue)
|
|
394
|
+
for (const ea of node.eventactions || []) {
|
|
395
|
+
for (const p of ea?.action?.properties || []) {
|
|
396
|
+
if (p.itemKey === 'function' && p.itemValue && p.itemValue.code) scan(p.itemValue.code)
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const children = []
|
|
401
|
+
if (Array.isArray(node.components)) {
|
|
402
|
+
for (const c of node.components) children.push([c, inScopeSlot])
|
|
403
|
+
}
|
|
404
|
+
for (const s of node.slots || []) {
|
|
405
|
+
const scopeForChildren = inScopeSlot || !!s.slotScope
|
|
406
|
+
for (const c of s.components || []) children.push([c, scopeForChildren])
|
|
407
|
+
}
|
|
408
|
+
for (const [c, scope] of children) collectRootBindings(c, scope, out)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function inferInputParams(bindings) {
|
|
412
|
+
const params = []
|
|
413
|
+
for (const key of bindings) {
|
|
414
|
+
let type = 'string'
|
|
415
|
+
let defaultValue = '示例' + key
|
|
416
|
+
if (/list$/i.test(key)) {
|
|
417
|
+
type = 'array'
|
|
418
|
+
defaultValue = key === 'detailList' ? [{ label: '示例标签', value: '示例值' }] : [{ name: '示例项', icon: 'angle_right' }]
|
|
419
|
+
} else if (key === 'showAll') {
|
|
420
|
+
type = 'boolean'
|
|
421
|
+
defaultValue = false
|
|
422
|
+
}
|
|
423
|
+
params.push({ key, name: key, type, defaultValue, desc: '', rule: { type: '', options: {} }, children: [] })
|
|
424
|
+
}
|
|
425
|
+
return params
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// 规范化 inputParams:确保每个字段都有完整的 key/name/type/defaultValue/desc/rule/children
|
|
429
|
+
const PARAM_TEMPLATE = { key: '', name: '', type: '', defaultValue: '', desc: '', rule: { type: '', options: {} }, children: [] }
|
|
430
|
+
function normalizeInputParams(params) {
|
|
431
|
+
if (!Array.isArray(params)) return []
|
|
432
|
+
return params.map((p) => {
|
|
433
|
+
const merged = { ...PARAM_TEMPLATE, ...p }
|
|
434
|
+
// 确保 rule 是完整对象(type + options)
|
|
435
|
+
if (!merged.rule || typeof merged.rule !== 'object') {
|
|
436
|
+
merged.rule = { type: '', options: {} }
|
|
437
|
+
} else {
|
|
438
|
+
if (!('type' in merged.rule)) merged.rule.type = ''
|
|
439
|
+
if (!('options' in merged.rule)) merged.rule.options = {}
|
|
440
|
+
}
|
|
441
|
+
// 确保 children 是数组
|
|
442
|
+
if (!Array.isArray(merged.children)) merged.children = []
|
|
443
|
+
// 编辑器别名兜底:paramName / paramType 回填空的 key / type(模型照编辑器字段名写 IR 时常见)
|
|
444
|
+
if (!merged.key && p.paramName) merged.key = String(p.paramName)
|
|
445
|
+
if (!merged.type && p.paramType) merged.type = String(p.paramType)
|
|
446
|
+
// 确保 name 不缺(缺则用 key 兜底)
|
|
447
|
+
if (!merged.name) merged.name = merged.key || ''
|
|
448
|
+
// 空 type 会被 validate 直接拒(inputParams[i] type='' is not valid):按命名习惯兜底
|
|
449
|
+
if (!merged.type) merged.type = /list$/i.test(merged.key) ? 'array' : merged.key === 'showAll' ? 'boolean' : 'string'
|
|
450
|
+
return merged
|
|
451
|
+
})
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* IR → 完整 schema + data。
|
|
456
|
+
* @param {object} ir 顶层 IR
|
|
457
|
+
* @returns {{schema:object, data:object}}
|
|
458
|
+
*/
|
|
459
|
+
export function expandIR(ir) {
|
|
460
|
+
const ctx = { n: 0, nextId: () => `comp_${++ctx.n}` }
|
|
461
|
+
const viewChildren = (ir.children || []).map((k) => expandNode(k, ctx))
|
|
462
|
+
const dictionary = ir.dictionary
|
|
463
|
+
? ir.dictionary
|
|
464
|
+
: { dictionaryList: [], inputParams: [], mocks: {} }
|
|
465
|
+
|
|
466
|
+
const schema = {
|
|
467
|
+
version: '1.0.0',
|
|
468
|
+
pageId: ir.id || 'new-card',
|
|
469
|
+
name: ir.name || '新建卡片',
|
|
470
|
+
desc: '',
|
|
471
|
+
platform: ir.platform || '002',
|
|
472
|
+
dictionary,
|
|
473
|
+
view: {
|
|
474
|
+
componentId: ir.viewId || `view_${ctx.nextId()}`,
|
|
475
|
+
width: ir.width || '375',
|
|
476
|
+
className: 'Root',
|
|
477
|
+
style: { properties: [] },
|
|
478
|
+
properties: [],
|
|
479
|
+
directives: [],
|
|
480
|
+
eventactions: [],
|
|
481
|
+
components: viewChildren,
|
|
482
|
+
},
|
|
483
|
+
}
|
|
484
|
+
// Root(view)自身的样式/属性/指令/事件(IR 顶层 s/p/pi/d/e)
|
|
485
|
+
applyProps(schema.view, { t: ir.t, v: ir.v, p: ir.p, pi: ir.pi, s: ir.s, d: ir.d, e: ir.e })
|
|
486
|
+
|
|
487
|
+
// 根节点核心样式默认值(gap/background/padding/borderRadius 只对根节点保证)
|
|
488
|
+
ensureRootDefaults(schema.view)
|
|
489
|
+
|
|
490
|
+
if (!ir.dictionary) {
|
|
491
|
+
const bindings = new Set()
|
|
492
|
+
collectRootBindings(schema.view, false, bindings)
|
|
493
|
+
schema.dictionary.inputParams = inferInputParams(bindings)
|
|
494
|
+
}
|
|
495
|
+
// 规范化所有 inputParams(补全缺失的 name/desc/rule/children)
|
|
496
|
+
schema.dictionary.inputParams = normalizeInputParams(schema.dictionary.inputParams)
|
|
497
|
+
const data = {}
|
|
498
|
+
for (const p of schema.dictionary.inputParams || []) data[p.key] = p.defaultValue
|
|
499
|
+
return { schema, data }
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/* ------------------------------------------------------------------ */
|
|
503
|
+
/* 完整 schema → 紧凑 IR(用于验证 round-trip / 二次编辑) */
|
|
504
|
+
/* ------------------------------------------------------------------ */
|
|
505
|
+
function nodeToIR(node) {
|
|
506
|
+
const ir = { c: node.className }
|
|
507
|
+
if (node.componentId) ir.id = node.componentId
|
|
508
|
+
if (node.name && node.name !== node.className) ir.name = node.name
|
|
509
|
+
|
|
510
|
+
for (const p of node.properties || []) {
|
|
511
|
+
const k = p.itemKey
|
|
512
|
+
if (!k) continue // 跳过空 property(冗余)
|
|
513
|
+
const from = p.itemValueFrom
|
|
514
|
+
const val = p.itemValue
|
|
515
|
+
if (k === 'value') {
|
|
516
|
+
if (from === '1' || isVar(val)) ir.v = val
|
|
517
|
+
else ir.t = val
|
|
518
|
+
} else if (from === '2') {
|
|
519
|
+
ir.pi = ir.pi || {}
|
|
520
|
+
ir.pi[k] = val
|
|
521
|
+
} else {
|
|
522
|
+
ir.p = ir.p || {}
|
|
523
|
+
ir.p[k] = val
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
for (const g of node.style?.properties || []) {
|
|
528
|
+
const gk = g.itemKey
|
|
529
|
+
if (!gk) continue
|
|
530
|
+
const kids = g.itemChildren?.properties || []
|
|
531
|
+
if (kids.length) {
|
|
532
|
+
const obj = {}
|
|
533
|
+
for (const c of kids) if (c.itemKey) obj[c.itemKey] = c.itemValue
|
|
534
|
+
ir.s = ir.s || {}
|
|
535
|
+
ir.s[gk] = obj
|
|
536
|
+
} else {
|
|
537
|
+
ir.s = ir.s || {}
|
|
538
|
+
ir.s[gk] = g.itemValue
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
for (const d of node.directives || []) {
|
|
543
|
+
const dk = d.itemKey
|
|
544
|
+
if (!dk) continue
|
|
545
|
+
const kids = d.itemChildren?.properties || []
|
|
546
|
+
if (kids.length) {
|
|
547
|
+
const obj = {}
|
|
548
|
+
for (const c of kids) if (c.itemKey) obj[c.itemKey] = c.itemValue
|
|
549
|
+
ir.d = ir.d || {}
|
|
550
|
+
ir.d[dk] = obj
|
|
551
|
+
} else {
|
|
552
|
+
ir.d = ir.d || {}
|
|
553
|
+
ir.d[dk] = d.itemValue
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
for (const ea of node.eventactions || []) {
|
|
558
|
+
const ek = ea.event?.eventKey
|
|
559
|
+
if (!ek) continue
|
|
560
|
+
const at = ea.action?.actionType
|
|
561
|
+
const props = {}
|
|
562
|
+
for (const p of ea.action?.properties || []) if (p.itemKey) props[p.itemKey] = p.itemValue
|
|
563
|
+
ir.e = ir.e || []
|
|
564
|
+
if (at === 'customAction' && props.function && Object.keys(props).length === 1) {
|
|
565
|
+
ir.e.push({ key: ek, action: at, code: props.function?.code })
|
|
566
|
+
} else {
|
|
567
|
+
ir.e.push({ key: ek, action: at, props })
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
for (const s of node.slots || []) {
|
|
572
|
+
const sk = s.slotKey || 'default'
|
|
573
|
+
const kids = (s.components || []).map(nodeToIR)
|
|
574
|
+
if (kids.length) {
|
|
575
|
+
ir.slots = ir.slots || {}
|
|
576
|
+
ir.slots[sk] = kids
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return ir
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export function schemaToIR(schema) {
|
|
583
|
+
const view = schema.view
|
|
584
|
+
// Root(view)自身的 s/p/pi/d/e(nodeToIR 仅遍历 slots,不会把 view.components 当 children 重复提取)
|
|
585
|
+
const rootIR = nodeToIR(view)
|
|
586
|
+
const ir = {
|
|
587
|
+
id: schema.pageId,
|
|
588
|
+
name: schema.name,
|
|
589
|
+
platform: schema.platform,
|
|
590
|
+
width: view?.width,
|
|
591
|
+
viewId: view?.componentId,
|
|
592
|
+
dictionary: schema.dictionary,
|
|
593
|
+
}
|
|
594
|
+
if (rootIR.s) ir.s = rootIR.s
|
|
595
|
+
if (rootIR.p) ir.p = rootIR.p
|
|
596
|
+
if (rootIR.pi) ir.pi = rootIR.pi
|
|
597
|
+
if (rootIR.d) ir.d = rootIR.d
|
|
598
|
+
if (rootIR.e) ir.e = rootIR.e
|
|
599
|
+
ir.children = (view?.components || []).map(nodeToIR)
|
|
600
|
+
return ir
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/* ------------------------------------------------------------------ */
|
|
604
|
+
/* 语义无损比对(忽略 componentId / 空 field,聚焦 className+属性值+样式值+子节点) */
|
|
605
|
+
/* ------------------------------------------------------------------ */
|
|
606
|
+
function collectChildren(n) {
|
|
607
|
+
const out = []
|
|
608
|
+
if (Array.isArray(n.components)) out.push(...n.components)
|
|
609
|
+
for (const s of n.slots || []) out.push(...(s.components || []))
|
|
610
|
+
return out
|
|
611
|
+
}
|
|
612
|
+
function normProps(node) {
|
|
613
|
+
const m = {}
|
|
614
|
+
for (const p of node.properties || []) {
|
|
615
|
+
if (!p.itemKey) continue
|
|
616
|
+
m[p.itemKey] = p.itemValue
|
|
617
|
+
}
|
|
618
|
+
return m
|
|
619
|
+
}
|
|
620
|
+
function normStyle(node) {
|
|
621
|
+
const m = {}
|
|
622
|
+
for (const g of node.style?.properties || []) {
|
|
623
|
+
if (!g.itemKey) continue
|
|
624
|
+
const kids = g.itemChildren?.properties || []
|
|
625
|
+
if (kids.length) {
|
|
626
|
+
const obj = {}
|
|
627
|
+
for (const c of kids) if (c.itemKey) obj[c.itemKey] = c.itemValue
|
|
628
|
+
m[g.itemKey] = obj
|
|
629
|
+
} else {
|
|
630
|
+
m[g.itemKey] = g.itemValue
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return m
|
|
634
|
+
}
|
|
635
|
+
function compareNodes(a, b, p) {
|
|
636
|
+
const errs = []
|
|
637
|
+
if (a.className !== b.className) errs.push(`${p}: className ${a.className} != ${b.className}`)
|
|
638
|
+
const pa = normProps(a)
|
|
639
|
+
const pb = normProps(b)
|
|
640
|
+
for (const k of new Set([...Object.keys(pa), ...Object.keys(pb)])) {
|
|
641
|
+
if (JSON.stringify(pa[k]) !== JSON.stringify(pb[k])) errs.push(`${p}.p.${k}: ${JSON.stringify(pa[k])} != ${JSON.stringify(pb[k])}`)
|
|
642
|
+
}
|
|
643
|
+
const sa = normStyle(a)
|
|
644
|
+
const sb = normStyle(b)
|
|
645
|
+
for (const k of new Set([...Object.keys(sa), ...Object.keys(sb)])) {
|
|
646
|
+
if (JSON.stringify(sa[k]) !== JSON.stringify(sb[k])) errs.push(`${p}.s.${k}: ${JSON.stringify(sa[k])} != ${JSON.stringify(sb[k])}`)
|
|
647
|
+
}
|
|
648
|
+
const ca = collectChildren(a)
|
|
649
|
+
const cb = collectChildren(b)
|
|
650
|
+
if (ca.length !== cb.length) errs.push(`${p}: child count ${ca.length} != ${cb.length}`)
|
|
651
|
+
const n = Math.min(ca.length, cb.length)
|
|
652
|
+
for (let i = 0; i < n; i++) errs.push(...compareNodes(ca[i], cb[i], `${p}/${ca[i].className}#${i}`))
|
|
653
|
+
return errs
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/* ------------------------------------------------------------------ */
|
|
657
|
+
/* CLI */
|
|
658
|
+
/* ------------------------------------------------------------------ */
|
|
659
|
+
function collectSliceRefs(node, out = new Set()) {
|
|
660
|
+
if (!node || typeof node !== 'object') return out
|
|
661
|
+
for (const p of node.properties || []) {
|
|
662
|
+
const value = p.itemValue
|
|
663
|
+
if (typeof value === 'string' && value.startsWith('/slices/')) out.add(value)
|
|
664
|
+
}
|
|
665
|
+
for (const child of node.components || []) collectSliceRefs(child, out)
|
|
666
|
+
for (const slot of node.slots || []) for (const child of slot.components || []) collectSliceRefs(child, out)
|
|
667
|
+
return out
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function syncReferencedSlices(schema, irPath, slicesDir) {
|
|
671
|
+
const result = { copied: 0, reused: 0, rewrites: [] }
|
|
672
|
+
const refs = collectSliceRefs(schema.view)
|
|
673
|
+
if (!refs.size) return result
|
|
674
|
+
const repoRoot = path.resolve(skillRoot, '..', '..')
|
|
675
|
+
const targetDir = path.join(repoRoot, 'src', 'slices')
|
|
676
|
+
fs.mkdirSync(targetDir, { recursive: true })
|
|
677
|
+
// 切图来源:--slices-dir 显式指定(要素包 slices/)优先,其次 IR 同目录 slices/
|
|
678
|
+
const sourceDirs = [...(slicesDir ? [path.resolve(slicesDir)] : []), path.join(path.dirname(path.resolve(irPath)), 'slices')]
|
|
679
|
+
let hitDir = null
|
|
680
|
+
// 落地前判重(slices_convention.md §3.1):内容 sha256 一致即同一张图 → 复用既有文件,
|
|
681
|
+
// 不新增副本,并把 schema 引用改写到既有文件名(避免「同图多名」堆重复素材)。
|
|
682
|
+
const contentIndex = buildContentIndex(targetDir)
|
|
683
|
+
|
|
684
|
+
for (const ref of refs) {
|
|
685
|
+
let name = ref.slice('/slices/'.length)
|
|
686
|
+
try { name = decodeURIComponent(name) } catch {}
|
|
687
|
+
const target = path.join(targetDir, name)
|
|
688
|
+
if (fs.existsSync(target)) continue
|
|
689
|
+
const source = sourceDirs.map((d) => path.join(d, name)).find((f) => fs.existsSync(f))
|
|
690
|
+
if (!source) {
|
|
691
|
+
throw new Error(`IR 引用的切图不存在:${ref}(已查找 ${sourceDirs.join(' / ')};可用 --slices-dir 指向要素包的 slices 目录)`)
|
|
692
|
+
}
|
|
693
|
+
hitDir = path.dirname(source)
|
|
694
|
+
const sha = sha256File(source)
|
|
695
|
+
const twin = (contentIndex.get(sha) || [])[0]
|
|
696
|
+
if (twin && twin !== path.basename(name)) {
|
|
697
|
+
result.rewrites.push([ref, `/slices/${twin}`])
|
|
698
|
+
result.reused++
|
|
699
|
+
continue
|
|
700
|
+
}
|
|
701
|
+
fs.mkdirSync(path.dirname(target), { recursive: true }) // 引用可能是嵌套路径(/slices/a/b/x.png)
|
|
702
|
+
fs.copyFileSync(source, target)
|
|
703
|
+
const list = contentIndex.get(sha)
|
|
704
|
+
if (list) list.push(path.basename(name))
|
|
705
|
+
else contentIndex.set(sha, [path.basename(name)])
|
|
706
|
+
result.copied++
|
|
707
|
+
}
|
|
708
|
+
if (result.rewrites.length) {
|
|
709
|
+
rewriteSliceRefs(schema, result.rewrites)
|
|
710
|
+
for (const [from, to] of result.rewrites) console.log(`[slices] 内容已存在 → 复用 ${to}(引用改写 ${from} → ${to},不重复导入)`)
|
|
711
|
+
}
|
|
712
|
+
if (result.copied) console.log(`[slices] 已从 ${hitDir} 汇聚 ${result.copied} 个引用切图 → ${targetDir}`)
|
|
713
|
+
return result
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function parseArgs(argv) {
|
|
717
|
+
const out = {}
|
|
718
|
+
for (let i = 0; i < argv.length; i++) {
|
|
719
|
+
const a = argv[i]
|
|
720
|
+
if (!a.startsWith('--')) continue
|
|
721
|
+
const key = a.slice(2)
|
|
722
|
+
const next = argv[i + 1]
|
|
723
|
+
if (next && !next.startsWith('--')) { out[key] = next; i++ } else out[key] = true
|
|
724
|
+
}
|
|
725
|
+
return out
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/** 覆盖已有卡片前,把旧 schema 快照进 .history/(与编辑器撤销快照同命名,可回滚) */
|
|
729
|
+
function snapshotBeforeOverwrite(schemaPath) {
|
|
730
|
+
if (!fs.existsSync(schemaPath)) return null
|
|
731
|
+
const histDir = path.join(path.dirname(schemaPath), '.history')
|
|
732
|
+
fs.mkdirSync(histDir, { recursive: true })
|
|
733
|
+
let ts = Date.now()
|
|
734
|
+
let file = `schema-${ts}.json`
|
|
735
|
+
while (fs.existsSync(path.join(histDir, file))) {
|
|
736
|
+
ts += 1
|
|
737
|
+
file = `schema-${ts}.json`
|
|
738
|
+
}
|
|
739
|
+
fs.copyFileSync(schemaPath, path.join(histDir, file))
|
|
740
|
+
const kept = fs.readdirSync(histDir).filter((f) => /^schema-(\d+)\.json$/.test(f)).sort()
|
|
741
|
+
while (kept.length > 30) {
|
|
742
|
+
const drop = kept.shift()
|
|
743
|
+
try { fs.unlinkSync(path.join(histDir, drop)) } catch {}
|
|
744
|
+
}
|
|
745
|
+
return file
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/** 跑 python 脚本:非零退出码是「正常结果」(autofix / validate 在有错误时 exit 1),
|
|
749
|
+
* 只有二进制缺失(ENOENT)才算「这个 python 不可用」。返回 {stdout, code}。 */
|
|
750
|
+
function runPyScript(py, script, args) {
|
|
751
|
+
try {
|
|
752
|
+
const stdout = execFileSync(py, [path.join(skillRoot, 'scripts', script), ...args], {
|
|
753
|
+
encoding: 'utf8',
|
|
754
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
755
|
+
})
|
|
756
|
+
return { stdout, code: 0 }
|
|
757
|
+
} catch (e) {
|
|
758
|
+
if (e && (e.code === 'ENOENT' || e.errno === -2)) throw e
|
|
759
|
+
return { stdout: typeof e.stdout === 'string' ? e.stdout : '', code: e.status == null ? 1 : e.status }
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/** autofix(机械修复,exit 1 仅代表「仍有非机械错误」)+ validate(真门禁)。
|
|
764
|
+
* 历史 bug:autofix 的 exit 1 曾被当成致命异常,导致 validate 从未执行、
|
|
765
|
+
* 报出误导性的「validate 未执行(未找到 python)」,模型转而信任无校验的旁路。 */
|
|
766
|
+
export function runAutofixAndValidate(schemaPath) {
|
|
767
|
+
const PY = findPython()
|
|
768
|
+
const candidates = [PY, 'python3']
|
|
769
|
+
let lastOut = ''
|
|
770
|
+
for (const py of candidates) {
|
|
771
|
+
let autofix
|
|
772
|
+
try {
|
|
773
|
+
autofix = runPyScript(py, 'autofix_schema.py', [schemaPath])
|
|
774
|
+
} catch {
|
|
775
|
+
continue // 该 python 二进制不存在,换下一个候选
|
|
776
|
+
}
|
|
777
|
+
const v = runPyScript(py, 'validate_schema.py', [schemaPath, '--json'])
|
|
778
|
+
const out = v.stdout || autofix.stdout
|
|
779
|
+
if (out) {
|
|
780
|
+
const m = out.match(/\{[\s\S]*\}/)
|
|
781
|
+
if (m) {
|
|
782
|
+
try {
|
|
783
|
+
return JSON.parse(m[0])
|
|
784
|
+
} catch {
|
|
785
|
+
lastOut = out.slice(0, 200)
|
|
786
|
+
}
|
|
787
|
+
} else lastOut = out.slice(0, 200)
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return { ok: false, errors: [`validate 未执行(python 不可用${lastOut ? `:${lastOut}` : ''})`], warnings: [] }
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function main() {
|
|
794
|
+
const args = parseArgs(process.argv.slice(2))
|
|
795
|
+
if (args['to-ir']) {
|
|
796
|
+
const schema = JSON.parse(fs.readFileSync(args['to-ir'], 'utf8'))
|
|
797
|
+
const ir = schemaToIR(schema)
|
|
798
|
+
process.stdout.write(JSON.stringify(ir, null, 2) + '\n')
|
|
799
|
+
return
|
|
800
|
+
}
|
|
801
|
+
if (args['self-test']) {
|
|
802
|
+
const card = args.card || 'DepositHolding'
|
|
803
|
+
const schemaPath = path.join(skillRoot, '..', '..', 'src', 'cards', card, 'schema.json')
|
|
804
|
+
if (!fs.existsSync(schemaPath)) { console.error(`[self-test] 找不到 ${schemaPath}`); process.exit(1) }
|
|
805
|
+
const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8'))
|
|
806
|
+
const ir = schemaToIR(schema)
|
|
807
|
+
const { schema: rebuilt } = expandIR(ir)
|
|
808
|
+
const errs = compareNodes(schema.view, rebuilt.view, 'view')
|
|
809
|
+
console.log(`\n[self-test] round-trip 语义比对:节点树 = ${errs.length === 0 ? '无损 ✅' : `${errs.length} 处差异 ❌`}`)
|
|
810
|
+
errs.slice(0, 20).forEach((e) => console.log(' DIFF ' + e))
|
|
811
|
+
|
|
812
|
+
// 写临时卡跑 validate + lint
|
|
813
|
+
const repoRoot = path.resolve(skillRoot, '..', '..')
|
|
814
|
+
const tmpId = '__ir_selftest__'
|
|
815
|
+
const tmpDir = path.join(repoRoot, 'src', 'cards', tmpId)
|
|
816
|
+
fs.mkdirSync(tmpDir, { recursive: true })
|
|
817
|
+
fs.writeFileSync(path.join(tmpDir, 'schema.json'), JSON.stringify(rebuilt, null, 2) + '\n')
|
|
818
|
+
fs.writeFileSync(path.join(tmpDir, 'data.json'), JSON.stringify({}) + '\n')
|
|
819
|
+
const v = runAutofixAndValidate(path.join(tmpDir, 'schema.json'))
|
|
820
|
+
console.log(`[self-test] validate: ok=${v.ok} errors=${v.errors.length} warnings=${v.warnings.length}`)
|
|
821
|
+
v.errors.slice(0, 10).forEach((e) => console.log(' ERR ' + e))
|
|
822
|
+
// lint(显式指定项目根,避免 cwd 解析偏差)
|
|
823
|
+
try {
|
|
824
|
+
const lo = execFileSync(process.execPath, [path.join(skillRoot, 'scripts', 'lint_card.mjs'), '--id', tmpId], {
|
|
825
|
+
encoding: 'utf8',
|
|
826
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
827
|
+
env: { ...process.env, DSL_CARD_PROJECT_ROOT: repoRoot },
|
|
828
|
+
})
|
|
829
|
+
console.log('[self-test] lint 输出(前 12 行):')
|
|
830
|
+
lo.split('\n').slice(0, 12).forEach((l) => console.log(' ' + l))
|
|
831
|
+
} catch (e) {
|
|
832
|
+
console.log('[self-test] lint 调用失败:' + (e.message || e))
|
|
833
|
+
}
|
|
834
|
+
fs.rmSync(tmpDir, { recursive: true, force: true })
|
|
835
|
+
process.exit(errs.length === 0 && v.ok ? 0 : 1)
|
|
836
|
+
}
|
|
837
|
+
if (args.ir && args.out) {
|
|
838
|
+
const ir = JSON.parse(fs.readFileSync(args.ir, 'utf8'))
|
|
839
|
+
const { schema, data } = expandIR(ir)
|
|
840
|
+
fs.mkdirSync(args.out, { recursive: true })
|
|
841
|
+
const sp = path.join(args.out, 'schema.json')
|
|
842
|
+
const dp = path.join(args.out, 'data.json')
|
|
843
|
+
const snap = snapshotBeforeOverwrite(sp)
|
|
844
|
+
if (snap) console.log(`[history] 已快照旧 schema → .history/${snap}(覆盖前备份,可回滚)`)
|
|
845
|
+
fs.writeFileSync(sp, JSON.stringify(schema, null, 2) + '\n')
|
|
846
|
+
fs.writeFileSync(dp, JSON.stringify(data, null, 2) + '\n')
|
|
847
|
+
const sliceSync = syncReferencedSlices(schema, args.ir, args['slices-dir'])
|
|
848
|
+
if (sliceSync.rewrites.length) {
|
|
849
|
+
// 去重改写发生在 schema 落盘之后 → 回写 schema/data,保证盘上引用与 src/slices 一致
|
|
850
|
+
rewriteSliceRefs(data, sliceSync.rewrites)
|
|
851
|
+
fs.writeFileSync(sp, JSON.stringify(schema, null, 2) + '\n')
|
|
852
|
+
fs.writeFileSync(dp, JSON.stringify(data, null, 2) + '\n')
|
|
853
|
+
console.log(`[slices] 同内容切图去重:改写 ${sliceSync.rewrites.length} 处引用,已回写 schema/data`)
|
|
854
|
+
}
|
|
855
|
+
const cardId = ir.id || path.basename(path.resolve(args.out))
|
|
856
|
+
const designImage = copyCardDesignImage({ designPath: args.design, outDir: args.out, cardId })
|
|
857
|
+
if (designImage) console.log(`[design] 已归档设计稿 → ${designImage}`)
|
|
858
|
+
const v = runAutofixAndValidate(sp)
|
|
859
|
+
console.log(`[ok] 已展开 IR → ${sp}`)
|
|
860
|
+
console.log(`[validate] ok=${v.ok} errors=${v.errors.length} warnings=${v.warnings.length}`)
|
|
861
|
+
v.errors.slice(0, 10).forEach((e) => console.log(' ERR ' + e))
|
|
862
|
+
process.exit(v.ok ? 0 : 1)
|
|
863
|
+
}
|
|
864
|
+
console.error('Usage:\n node expand_ir.mjs --ir <IR.json> --out <dir>/ [--slices-dir <要素包 slices 目录>]\n node expand_ir.mjs --to-ir <schema.json>\n node expand_ir.mjs --self-test [--card X]')
|
|
865
|
+
process.exit(1)
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// 仅当作为 CLI 直接运行时才启动 main()(被 import 时不执行)
|
|
869
|
+
const _thisScript = fs.realpathSync(fileURLToPath(import.meta.url))
|
|
870
|
+
const _invokedAs = (process.argv[1] && fs.existsSync(process.argv[1]))
|
|
871
|
+
? fs.realpathSync(process.argv[1])
|
|
872
|
+
: process.argv[1]
|
|
873
|
+
if (_invokedAs === _thisScript) main()
|