diff --git a/audit-posters.html b/audit-posters.html
index 6303eac..f52e356 100644
--- a/audit-posters.html
+++ b/audit-posters.html
@@ -15,9 +15,9 @@ h1{font-size:16px}h2{font-size:14px}
支持参数:?only=源1,源2 定向审计;?max=N 每源最多素材数;?size=N 渲染尺寸;?compare=1 开启「原始 vs 下载」逐像素对比。
-
-
-
+
+
+
-
+
-
+
-
-
+
+
diff --git a/scripts/build-posters.js b/scripts/build-posters.js
index ae424bf..b748b28 100644
--- a/scripts/build-posters.js
+++ b/scripts/build-posters.js
@@ -309,6 +309,43 @@ async function downloadDirFiles(src) {
return { items, ok, fail };
}
+/**
+ * 本地源:读取 js/data/posters/{id}/files 下预先生成的素材(不联网)
+ * 用于从 CSS 提取的图案、渐变与配色 JSON 等无独立文件的开源资源
+ */
+async function readLocalFiles(src) {
+ const items = [];
+ let ok = 0, fail = 0;
+ const ROOT = path.join(__dirname, '..');
+ const exts = (Array.isArray(src.ext) ? src.ext : (src.ext ? String(src.ext).split(',') : ['.svg']))
+ .map(e => e.trim().toLowerCase());
+ const dir = path.join(ROOT, 'js', 'data', 'posters', src.id, 'files');
+ if (!fs.existsSync(dir)) throw new Error('本地目录不存在: ' + dir);
+ const walk = (d, prefix) => {
+ let out = [];
+ for (const f of fs.readdirSync(d, { withFileTypes: true })) {
+ if (f.isDirectory()) out = out.concat(walk(path.join(d, f.name), prefix + f.name + '/'));
+ else if (exts.some(e => f.name.toLowerCase().endsWith(e))) out.push(prefix + f.name);
+ }
+ return out;
+ };
+ let picked = walk(dir, '');
+ picked = dropNonAssets(picked);
+ if (src.exclude) picked = picked.filter(p => !new RegExp(src.exclude).test(p));
+ const cap = Number(src.maxItems) > 0 ? Math.min(Number(src.maxItems), picked.length) : picked.length;
+ picked = picked.slice(0, cap);
+ for (const p of picked) {
+ try {
+ const buf = fs.readFileSync(path.join(dir, p));
+ const name = path.basename(p, path.extname(p));
+ const c = classifyPoster(name);
+ const it = await buildItem(src, name, 'posters/' + src.id + '/files/' + p, buf, c);
+ if (it) { items.push(it); ok++; } else fail++;
+ } catch (e) { fail++; }
+ }
+ return { items, ok, fail };
+}
+
/**
* hero-patterns 专用转换:ES module 函数模板 → 静态 SVG 字符串
* 源码形如:
@@ -487,6 +524,11 @@ async function main() {
const r = await downloadDirFiles(src);
items = r.items; fail = r.fail; expected = r.ok + r.fail;
usedUrl = 'unpkg.com/' + src.npm;
+ } else if (src.format === 'local') {
+ console.log(`读取 ${src.name}(本地预生成 ${src.id})…`);
+ const r = await readLocalFiles(src);
+ items = r.items; fail = r.fail; expected = r.ok + r.fail;
+ usedUrl = 'local';
} else {
throw new Error(`不支持的 format: ${src.format}`);
}
diff --git a/scripts/import-css-assets.js b/scripts/import-css-assets.js
new file mode 100644
index 0000000..e1916a4
--- /dev/null
+++ b/scripts/import-css-assets.js
@@ -0,0 +1,233 @@
+#!/usr/bin/env node
+/**
+ * 从开源 CSS 库提取静态素材(图案 / 配色),生成本地海报源
+ *
+ * 产物:
+ * js/data/posters/patterncss/files/*.svg ← pattern.css(MIT)图案
+ * js/data/posters/radix-colors/files/*.json ← Radix Colors(MIT)色阶
+ *
+ * pattern.css 的图案由 CSS 渐变定义(无 data URI SVG),
+ * 本脚本按各家族几何规则还原为等价的可平铺 SVG(currentColor 着色)。
+ *
+ * 用法:node scripts/import-css-assets.js
+ */
+'use strict';
+
+const fs = require('fs');
+const path = require('path');
+const https = require('https');
+
+const ROOT = path.resolve(__dirname, '..');
+const OUT = path.join(ROOT, 'js', 'data', 'posters');
+
+function fetchText(url) {
+ return new Promise((resolve, reject) => {
+ https.get(url, { headers: { 'User-Agent': 'drawlogo' }, timeout: 60000 }, res => {
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
+ return fetchText(res.headers.location).then(resolve, reject);
+ }
+ let d = '';
+ res.on('data', c => { d += c; });
+ res.on('end', () => resolve(d));
+ }).on('error', reject);
+ });
+}
+
+function writeFile(rel, content) {
+ const p = path.join(OUT, rel);
+ fs.mkdirSync(path.dirname(p), { recursive: true });
+ fs.writeFileSync(p, content);
+}
+
+/* ================= 1. pattern.css 图案 → SVG ================= */
+/** 尺寸档位(与 pattern.css 的 sm/md/lg/xl 对应) */
+const SIZES = { sm: 10, md: 25, lg: 50, xl: 100 };
+
+/** 圆点半径(pattern.css 中 sm/md/lg/xl 对应 0.5 / 1 / 1.5 / 2px,间距 = 10 倍半径) */
+const DOT_R = { sm: 0.5, md: 1, lg: 1.5, xl: 2 };
+
+/** 数值去尾零(避免 0.00 这类非法/冗余输出) */
+function n(v) {
+ return String(Math.round(v * 1000) / 1000);
+}
+
+/** 组装可平铺 SVG 预览(4 个重复单元) */
+function wrap(w, h, body) {
+ return ``;
+}
+
+const FAMILIES = {
+ /* 棋盘格:2s 单元内对角填充 */
+ checks(s) {
+ const area = 4 * s, out = [];
+ for (let i = 0; i < 4; i++) {
+ for (let j = 0; j < 4; j++) {
+ if ((i + j) % 2 === 0) out.push(``);
+ }
+ }
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 网格线:每 s 一条 1px 线 */
+ grid(s) {
+ const area = 4 * s, out = [];
+ for (let k = 0; k <= 4; k++) {
+ out.push(``);
+ }
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 圆点阵:间距 = 10r */
+ dots(s, key) {
+ const r = DOT_R[key], sp = 10 * r, area = 4 * sp, out = [];
+ for (let i = 0; i < 4; i++) {
+ for (let j = 0; j < 4; j++) {
+ out.push(``);
+ }
+ }
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 交错圆点:间距 20r,第二组偏移 10r */
+ 'cross-dots'(s, key) {
+ const r = DOT_R[key], sp = 20 * r, area = 2 * sp, out = [];
+ for (let i = 0; i < 2; i++) {
+ for (let j = 0; j < 2; j++) {
+ const x = r + i * sp, y = r + j * sp;
+ out.push(``);
+ out.push(``);
+ }
+ }
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 竖线:每 s 一条 1px 线 */
+ 'vertical-lines'(s) {
+ const area = 4 * s, out = [];
+ for (let k = 0; k <= 4; k++) out.push(``);
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 横线:每 s 一条 1px 线 */
+ 'horizontal-lines'(s) {
+ const area = 4 * s, out = [];
+ for (let k = 0; k <= 4; k++) out.push(``);
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 斜线:45°,水平间距 s */
+ 'diagonal-lines'(s) {
+ const area = 4 * s, out = [];
+ for (let k = -4; k <= 4; k++) {
+ const x = k * s;
+ out.push(``);
+ }
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 竖条纹:每 s 内半宽填充 */
+ 'vertical-stripes'(s) {
+ const area = 4 * s, out = [];
+ for (let k = 0; k < 4; k++) out.push(``);
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 横条纹:每 s 内半高填充 */
+ 'horizontal-stripes'(s) {
+ const area = 4 * s, out = [];
+ for (let k = 0; k < 4; k++) out.push(``);
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 斜条纹:45°,带宽 s、水平周期 2s */
+ 'diagonal-stripes'(s) {
+ const area = 4 * s, out = [];
+ for (let k = -4; k <= 4; k++) {
+ const x = k * 2 * s;
+ out.push(``);
+ }
+ return wrap(area, area, out.join(''));
+ },
+
+ /* 锯齿:两条上下起伏的折线带 */
+ zigzag(s) {
+ const w = 4 * s, h = 2 * s, out = [];
+ for (const y0 of [s / 2, (3 * s) / 2]) {
+ out.push(``);
+ }
+ return wrap(w, h, out.join(''));
+ },
+
+ /* 三角:每 s 单元半格三角 */
+ triangles(s) {
+ const area = 4 * s, out = [];
+ for (let i = 0; i < 4; i++) {
+ for (let j = 0; j < 4; j++) {
+ const x = i * s, y = j * s;
+ out.push(``);
+ }
+ }
+ return wrap(area, area, out.join(''));
+ }
+};
+
+/** 从 pattern.css 提取图案类名(依据真实 CSS 校验,避免收录不存在/工具类) */
+function patternNames(css) {
+ const names = [...css.matchAll(/\.pattern-([a-z0-9-]+)\s*\{/g)].map(m => m[1]);
+ const out = [];
+ for (const name of names) {
+ const m = name.match(/^([a-z-]+)-(sm|md|lg|xl)$/);
+ if (!m) continue; // 过滤 pattern-w-* / pattern-h-* 等尺寸工具类
+ if (!FAMILIES[m[1]]) continue; // 未知家族跳过
+ if (out.indexOf(name) === -1) out.push(name);
+ }
+ return out;
+}
+
+async function importPatternCss() {
+ const css = await fetchText('https://unpkg.com/pattern.css@1.0.0/dist/pattern.css');
+ const names = patternNames(css);
+ let ok = 0;
+ for (const name of names) {
+ const m = name.match(/^([a-z-]+)-(sm|md|lg|xl)$/);
+ const svg = FAMILIES[m[1]](SIZES[m[2]], m[2]);
+ if (!/^