算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
design-to-react-algorithms【设计与创意】Reverse-engineering a Sketch file (or Figma export with similar shape) into pixel-perfect React + CSS — the iteration mental model, tree reconstruction, layout inference algorithms, geometry math, visual-regression diffing, and the style/typography/path conversions that make "improvement without regression" enforceable. Trigger even if the user doesn…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
The reverse-engineering pipeline that converts Sketch files into pixel-perfect React + CSS, with regression-safe iteration as the load-bearing constraint. The skill is organized around the cascade effect of design-to-code conversion: a wrong call in stage N corrupts every output from stage N+1 onward, so categories are ordered by how much downstream they own.
The user's primary requirement — "each improvement doesn't cause regressions" — is enforceable only if the iteration loop, the layer tree, and the layout solver are correct before you start polishing styles. Read the rules in priority order.
.sketch file (or equivalent design source) and emits React + CSSMSImmutableFlexGroupLayout, attributedString, curvePoint, MSImmutableStyleCorners) into idiomatic CSSThe ordering is the cascade — fix earlier stages first; later-stage fixes are wasted if the upstream tree is wrong.
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Reverse-Engineering Iteration Strategy | CRITICAL | iter- |
| 2 | Tree Reconstruction & Symbol Resolution | CRITICAL | tree- |
| 3 | Layout Algorithms (Flex/Freeform Inference) | CRITICAL | layout- |
| 4 | Coordinate & Geometry Math | HIGH | geom- |
| 5 | Visual Regression & Diff Algorithms | HIGH | diff- |
| 6 | Style Translation (Color, Gradient, Shadow, Border) | MEDIUM-HIGH | style- |
| 7 | Typography Math | MEDIUM | type- |
| 8 | Path & Shape Rendering | MEDIUM | path- |
iter-bisect-from-root — Convert top-down, bisect bottom-up to localize regressions in O(log n)iter-baseline-snapshot-gate — Every change must pass committed baselines before mergeiter-convert-symbols-before-instances — Topologically sort symbols → instances; never inline duplicatesiter-freeze-design-tokens-first — Extract sharedSwatches/layerStyles to CSS variables BEFORE any componentiter-one-family-per-pr — Scope conversions to one component family per iterationiter-keep-known-good-branch — Maintain a baseline branch as a three-way regression triage anchortree-resolve-overrides-before-emit — Apply overrideValues against master into named propstree-hash-subtrees-for-componentization — Structural hashing finds repetition designers missedtree-collapse-passthrough-groups — Drop no-style single-child groups; preserve world coordstree-hoist-shared-style-via-subtree-equivalence — Subtree equivalence + modifier classes, not per-property deduptree-clipping-mask-is-stacking-context — hasClippingMask requires isolation: isolate + clip-pathtree-foreign-symbols-become-library-imports — Foreign symbols are package imports, not duplicateslayout-flex-group-enum-mapping — Map MSImmutableFlexGroupLayout enums 1:1 to CSS flex propertieslayout-infer-flex-from-axis-projection-overlap — 1D separating-axis test for freeform → flex row/columnlayout-detect-grid-via-2d-coordinate-clustering — Cluster edge coordinates with ε to detect CSS Gridlayout-promote-freeform-when-equal-gaps — Equal gaps within tolerance → display: flex; gap: Npxlayout-reverse-engineer-padding-not-margin — Insets become parent padding; rebase childrenlayout-preserve-wrapping-enabled — wrappingEnabled is the only way the source signals responsive intentlayout-ignore-layout-is-absolute-escape — flexItem.ignoreLayout: true → position: absolute over position: relative parentgeom-compose-parent-transforms-before-emit — Compose 2D affine matrices, don't concatenate raw x/ygeom-round-only-at-leaves — Carry floats through; round once at the CSS boundarygeom-rotation-is-css-transform — Frame is unrotated AABB; emit transform: rotate()geom-shape-group-bounds-via-union — Bounds = axis-aligned union of children, rebase to origingeom-clipping-bounds-intersect-not-union — Nested clips intersect; never union or replacediff-use-ssim-for-aa-content — SSIM for antialiased content; raw pixel diff false-positives on every retestdiff-region-budgeted-tolerances — Per-region SSIM floors (text 0.99, gradient 0.95, image 1.0)diff-antialias-aware-pixelmatch-threshold — Pixelmatch includeAA: false for icon defect detectiondiff-perceptual-hash-for-wrong-component-detection — Hamming distance buckets route triage automaticallydiff-subtree-bisection-to-localize-regression — Disable subtrees in binary search to find the offending nodediff-baseline-per-component-not-per-page — Storybook per-story snapshots; scope = blast radiusstyle-srgb-float-to-hex-via-gamma-correct-path — Sketch sRGB floats are already gamma-encoded; direct conversion onlystyle-preserve-display-p3 — colorSpace: 1 → emit color(display-p3 …) with sRGB fallbackstyle-gradient-angle-via-atan2 — atan2(dx, -dy) reframes Sketch vector to CSS gradient anglestyle-stack-multi-shadow-in-paint-order — Reverse shadow array — Sketch paints last-first, CSS first-laststyle-reconcile-border-position — Border position 0/1/2 → frame expansion or outline for outsidestyle-per-corner-radii-shorthand — Per-corner radii map to TL TR BR BL clockwise (not Sketch's row order)type-split-attributed-string-runs-only-when-differ — Coalesce identical adjacent attribute runs; single-run case needs no inner spantype-pt-lineheight-to-unitless — lineHeight / fontSize → CSS unitless that scales with the fonttype-kerning-pt-to-em-letter-spacing — kerning / fontSize → em-relative letter-spacingtype-build-font-fallback-ladder — Sketch family → web stack; SF Pro needs -apple-system, BlinkMacSystemFont, …type-paragraph-spacing-between-not-after — Use gap on the parent, not margin-bottom with :last-childpath-curve-point-to-svg-cubic-bezier — M + per-segment C from curveFrom/curveTopath-rectangle-with-fixed-radius-is-css — Detect axis-aligned rounded rects early; emit <div> not <svg>path-apple-smooth-corners-via-superellipse — Apple smooth corners are superellipses (n≈5), not circular arcspath-flatten-boolean-ops-at-parse-time — Resolve union/subtract via paper.js in Node; ship one flat pathpath-honor-winding-rule — windingRule 0/1 → SVG fill-rule nonzero/evenodd; explicit, not defaultreferences/_sections.md for category definitions and the cascade rationaleiter-*) — without the regression gate, every other rule is just techniquestree-*) and layout (layout-*) — these are the load-bearing structural decisionsgeom-*) and diff (diff-*) — these are the precision and validation layersFor a brand-new converter, follow the rules in priority order. For an existing converter, identify which stage owns the regression you're seeing (use [[diff-subtree-bisection-to-localize-regression]] + [[diff-perceptual-hash-for-wrong-component-detection]] to triage) and fix at the highest stage that owns it.
| File | Description |
|---|---|
| references/_sections.md | Category definitions, impact levels, cascade rationale |
| assets/templates/_template.md | Template for adding new rules to this skill |
| metadata.json | Version, discipline, references |
| AGENTS.md | Auto-built TOC (regenerate via scripts/build-agents-md.js) |