From 0cb56ecd9ee92a0b024a3cd9cd1019fd2e08c107 Mon Sep 17 00:00:00 2001 From: Kayshen-X Date: Sat, 16 May 2026 23:14:45 +0800 Subject: [PATCH] refactor: extract op-codegen crate Relocate codegen.rs + codegen_targets.rs out of openpencil-shell-core into a dedicated op-codegen crate. The code generators only depend on jian-ops-schema + op-editor-core, so they form a clean leaf crate. codegen.rs becomes the crate's lib.rs; crate::codegen:: paths in codegen_targets.rs collapse to crate::. Pure relocation, no behaviour change; tests move with their code. --- crates/op-codegen/Cargo.toml | 15 +++++++++++++++ .../src/codegen_targets.rs | 8 ++++---- .../src/codegen.rs => op-codegen/src/lib.rs} | 2 ++ crates/openpencil-shell-core/src/lib.rs | 2 -- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 crates/op-codegen/Cargo.toml rename crates/{openpencil-shell-core => op-codegen}/src/codegen_targets.rs (98%) rename crates/{openpencil-shell-core/src/codegen.rs => op-codegen/src/lib.rs} (99%) diff --git a/crates/op-codegen/Cargo.toml b/crates/op-codegen/Cargo.toml new file mode 100644 index 000000000..930da3489 --- /dev/null +++ b/crates/op-codegen/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "op-codegen" +version.workspace = true +edition.workspace = true +rust-version.workspace = true +license.workspace = true +description = "OpenPencil code generators — emit HTML/Vue/Svelte/React/Flutter/SwiftUI/Compose/RN from a PenDocument" + +[lib] +name = "op_codegen" +path = "src/lib.rs" + +[dependencies] +jian-ops-schema = { path = "../../vendor/jian/crates/jian-ops-schema" } +op-editor-core = { path = "../op-editor-core" } diff --git a/crates/openpencil-shell-core/src/codegen_targets.rs b/crates/op-codegen/src/codegen_targets.rs similarity index 98% rename from crates/openpencil-shell-core/src/codegen_targets.rs rename to crates/op-codegen/src/codegen_targets.rs index 727021842..489caf9de 100644 --- a/crates/openpencil-shell-core/src/codegen_targets.rs +++ b/crates/op-codegen/src/codegen_targets.rs @@ -1,13 +1,13 @@ //! Per-framework markup generators — the React / Vue / Svelte / HTML //! / Flutter / SwiftUI / Compose / React Native targets carved off -//! `codegen.rs` to keep both files under the 800-line cap. +//! `lib.rs` to keep both files under the 800-line cap. //! //! All generators consume the canonical `jian_ops_schema::PenDocument` -//! and walk `PenNode` through the flat-view accessors in the parent -//! `codegen` module (`node_origin` / `node_size` / `node_fill_css` / +//! and walk `PenNode` through the flat-view accessors in the crate +//! root (`node_origin` / `node_size` / `node_fill_css` / //! …) so the per-target emit logic stays variant-agnostic. -use crate::codegen::{ +use crate::{ color_to_css, fmt_num, html_escape, node_children, node_corner_radius, node_fill_css, node_hidden, node_is_ellipse, node_is_text, node_origin, node_rotation_deg, node_size, node_stroke_css, node_text, parse_color, root_nodes, Codegen, CssVariables, diff --git a/crates/openpencil-shell-core/src/codegen.rs b/crates/op-codegen/src/lib.rs similarity index 99% rename from crates/openpencil-shell-core/src/codegen.rs rename to crates/op-codegen/src/lib.rs index 1a0aa7f1e..2cfff42f4 100644 --- a/crates/openpencil-shell-core/src/codegen.rs +++ b/crates/op-codegen/src/lib.rs @@ -12,6 +12,8 @@ //! node-accessor helpers, and the test suite; per-framework markup //! generators live in the sibling `codegen_targets` module. +mod codegen_targets; + pub use crate::codegen_targets::{ Compose, Flutter, Html, React, ReactNative, Svelte, SwiftUi, Vue, }; diff --git a/crates/openpencil-shell-core/src/lib.rs b/crates/openpencil-shell-core/src/lib.rs index eaa5fd35f..16c99ed1e 100644 --- a/crates/openpencil-shell-core/src/lib.rs +++ b/crates/openpencil-shell-core/src/lib.rs @@ -19,8 +19,6 @@ pub mod agent_settings_state; pub mod chat_models; pub mod chat_provider; -pub mod codegen; -mod codegen_targets; pub mod figma; // Phase 3 strangler reorg: i18n extracted into the op-i18n crate. Re-exported // as `i18n` so `crate::i18n::translate` / `crate::i18n::Locale` paths still resolve.