{"record":{"id":"529277afd2b4f7b4","repo":"BigPizzaV3/CodexPlusPlus","slug":"theme-css-skin-api-data-ds-part","errorCode":null,"errorMessage":"theme.css 只能选择 Skin API 注册的 data-ds-part","messagePattern":"theme\\.css 只能选择 Skin API 注册的 data-ds-part","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_package.rs","lineNumber":329,"sourceCode":"        let open = rest.find('{').context(\"theme.css 规则缺少开始括号\")?;\n        let selector = rest[..open].trim();\n        if selector.is_empty()\n            || selector.contains([',', '@', ';', '}'])\n            || rest[open + 1..].find('{').is_some_and(|nested| {\n                rest[open + 1..]\n                    .find('}')\n                    .is_none_or(|close| nested < close)\n            })\n        {\n            bail!(\"theme.css 选择器或规则语法无效\");\n        }\n        let close = open\n            + 1\n            + rest[open + 1..]\n                .find('}')\n                .context(\"theme.css 规则缺少结束括号\")?;\n        let Some(after_prefix) = selector.strip_prefix(\"[data-ds-part=\\\"\") else {\n            bail!(\"theme.css 只能选择 Skin API 注册的 data-ds-part\");\n        };\n        let (part, suffix) = after_prefix\n            .split_once(\"\\\"]\")\n            .context(\"theme.css data-ds-part 语法无效\")?;\n        if !allowed_parts.contains(&part)\n            || (!suffix.is_empty() && suffix != \":hover\" && suffix != \":focus-visible\")\n        {\n            bail!(\"theme.css 使用了未注册的 Skin API part 或状态\");\n        }\n\n        let mut rule_declarations = Vec::new();\n        let mut seen = HashSet::new();\n        for declaration in rest[open + 1..close]\n            .split(';')\n            .map(str::trim)\n            .filter(|value| !value.is_empty())\n        {\n            let (property, value) = declaration","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L311-L347","documentation":"Safe CSS only allows selectors of the exact form [data-ds-part=\"NAME\"] targeting parts registered by the Skin API. parse_safe_css requires every selector to literally start with the prefix `[data-ds-part=\"` ; if it does not, it bails with 'theme.css 只能选择 Skin API 注册的 data-ds-part'. Class, id, element or attribute selectors of any other shape are rejected before the part whitelist is even consulted.","triggerScenarios":"Selecting with `body {`, `.sidebar {`, `#root {`, `[data-ds-part='main']` (single quotes), or `[data-ds-part=\"main\"] .child` — anything that does not begin with the exact `[data-ds-part=\"` prefix.","commonSituations":"Theme authors writing regular CSS out of habit; converting an existing web theme into a Dream Skin package without rewriting selectors; examples copied from generic CSS docs.","solutions":["Rewrite every selector to exactly `[data-ds-part=\"<registered-part>\"] { ... }` with double quotes","Ensure the selector starts at the beginning of the rule — no leading combinators, elements or classes","Target descendant styling only via the dedicated parts (root, sidebar, main, header, home, home-hero, project-list, thread, message, composer, composer-toolbar, dialog)"],"exampleFix":"// before\n.sidebar { background-color: #222; }\n// after\n[data-ds-part=\"sidebar\"] { background-color: #222222; }","handlingStrategy":"validation","validationCode":"fn selectors_are_ds_part_only(css: &str) -> bool {\n    css.split('{').filter(|s| !s.contains('}')).all(|sel| {\n        let sel = sel.trim();\n        sel.starts_with(\"[data-ds-part=\\\"\") && sel.ends_with(\"]\")\n    })\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = validate_safe_css(&css) {\n    if e.to_string().contains(\"data-ds-part\") {\n        return Err(\"rewrite selectors to the exact form [data-ds-part=\\\"part\\\"]\".into());\n    }\n    return Err(e.into());\n}","preventionTips":["Only ever emit selectors of the form [data-ds-part=\"name\"] with double quotes","Do not attempt element/class/id selectors — the renderer only applies rules via data-ds-part attributes","Test each rule against the Skin API part registry before packaging"],"tags":["css","selector","skin-api"],"backgroundTag":"invalid-argument-format","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}