@ptengine/lp-editor-core 1.0.0-alpha.0 → 1.0.0-alpha.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 +14 -4
- package/dist/golden/fixtures/html/01-tailwind-landing.html +92 -0
- package/dist/golden/fixtures/html/02-table-foster-parenting.html +29 -0
- package/dist/golden/fixtures/html/03-p-block-nesting.html +20 -0
- package/dist/golden/fixtures/html/04-unclosed-misnested.html +29 -0
- package/dist/golden/fixtures/html/05-attr-quotes-entities-unicode.html +19 -0
- package/dist/golden/fixtures/html/06-comments-rawtext.html +46 -0
- package/dist/golden/fixtures/html/07-boolean-empty-attrs.html +46 -0
- package/dist/golden/fixtures/html/08-mega-class-list.html +11 -0
- package/dist/golden/fixtures/html/09-legacy-doctype.html +17 -0
- package/dist/golden/fixtures/html/10-foreign-template-pre.html +40 -0
- package/dist/golden/fixtures/html/11-adoption-agency-deep.html +28 -0
- package/dist/golden/fixtures/html/12-charrefs-control-chars.html +23 -0
- package/dist/golden/fixtures/html/13-namespaces-custom-dup-attrs.html +25 -0
- package/dist/golden/fixtures/popup/01-jp-coupon-line-tall.html +10 -0
- package/dist/golden/fixtures/popup/02-jp-webinar-doctor.html +17 -0
- package/dist/golden/fixtures/popup/03-jp-model-recruit.html +17 -0
- package/dist/golden/fixtures/popup/04-jp-shinpi-campaign.html +12 -0
- package/dist/golden/fixtures/popup/05-jp-jal-course.html +17 -0
- package/dist/golden/fixtures/popup/06-jp-training-two-cta.html +17 -0
- package/dist/golden/fixtures/popup/07-vivaia-lightweight-shoes.html +12 -0
- package/dist/golden/fixtures/popup/08-sticky-black-friday-countdown.html +8 -0
- package/dist/golden/fixtures/popup/09-sticky-line-coupon-countdown.html +6 -0
- package/dist/golden/fixtures/popup/10-sticky-coupon-code-countdown.html +9 -0
- package/dist/golden/fixtures/popup/11-sticky-anniversary-countdown.html +5 -0
- package/dist/golden/fixtures/popup/12-vivaia-product-grid.html +29 -0
- package/dist/golden/fixtures/popup/13-vivaia-restock-split.html +9 -0
- package/dist/golden/fixtures/popup/14-back-to-school-email-form.html +14 -0
- package/dist/golden/fixtures/popup/15-xtool-ebook-split-form.html +9 -0
- package/dist/golden/fixtures/popup/16-880-off-gradient-form.html +8 -0
- package/dist/golden/fixtures/popup/17-holiday-sale-price-swatch.html +18 -0
- package/dist/golden/fixtures/popup/18-solar-battery-dark-specs.html +14 -0
- package/dist/golden/fixtures/popup/19-jp-clinic-coupon-placeholder.html +8 -0
- package/dist/golden/fixtures/popup/README.md +31 -0
- package/dist/golden/manifest.json +84 -0
- package/dist/golden/ops-cases.json +179 -0
- package/dist/golden/verify.mjs +101 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 下游用的 golden 校验。随包发布到 `dist/golden/verify.mjs`。
|
|
4
|
+
*
|
|
5
|
+
* node node_modules/@ptengine/lp-editor-core/dist/golden/verify.mjs
|
|
6
|
+
*
|
|
7
|
+
* 它做的事:拿包里发的 fixture 输入,用**你这一侧的 DOM 实现**跑一遍
|
|
8
|
+
* parse / apply / serialize,算 sha256,与清单里的期望值比。
|
|
9
|
+
*
|
|
10
|
+
* 为什么要这一步:core 的核心不变量是「浏览器 apply == Node apply」。core 自己的
|
|
11
|
+
* CI 已经在两个引擎里各验过一遍;但下游装的是**你环境里的** jsdom、你的 Node 版本。
|
|
12
|
+
* 这个脚本确认那套组合产出的字节与发布时一致 —— 不一致的话,你的页面缓存会和
|
|
13
|
+
* 编辑器逐轮分叉,而且不报错。
|
|
14
|
+
*
|
|
15
|
+
* 校验脚本随包发而不是让下游自己写,是因为「同一个判断两份实现」正是这套设计
|
|
16
|
+
* 一路在防的东西。
|
|
17
|
+
*
|
|
18
|
+
* 需要 jsdom 在场(core 自己不依赖它 —— DOM 由宿主注入)。
|
|
19
|
+
*/
|
|
20
|
+
import { createHash } from 'node:crypto';
|
|
21
|
+
import { readFileSync } from 'node:fs';
|
|
22
|
+
import { dirname, join } from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
|
|
25
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
|
|
27
|
+
let JSDOM;
|
|
28
|
+
try {
|
|
29
|
+
({ JSDOM } = await import('jsdom'));
|
|
30
|
+
} catch {
|
|
31
|
+
console.error(
|
|
32
|
+
'golden-verify: 需要 jsdom。core 自己不依赖它(DOM 由宿主注入),\n' +
|
|
33
|
+
'请在你的项目里安装:pnpm add -D jsdom'
|
|
34
|
+
);
|
|
35
|
+
process.exit(2);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const core = await import(join(here, '..', 'index.js'));
|
|
39
|
+
const manifest = JSON.parse(readFileSync(join(here, 'manifest.json'), 'utf8'));
|
|
40
|
+
const opsData = JSON.parse(readFileSync(join(here, 'ops-cases.json'), 'utf8'));
|
|
41
|
+
const opsByName = new Map(opsData.cases.map(c => [c.name, c]));
|
|
42
|
+
|
|
43
|
+
const DOMParser = new JSDOM('').window.DOMParser;
|
|
44
|
+
const { parse } = core.createCore({ DOMParser });
|
|
45
|
+
const hostDoc = parse('<!DOCTYPE html><body>');
|
|
46
|
+
|
|
47
|
+
const sha = s => createHash('sha256').update(s, 'utf8').digest('hex');
|
|
48
|
+
|
|
49
|
+
function compute(entry) {
|
|
50
|
+
if (entry.kind === 'document') {
|
|
51
|
+
return core.serialize(parse(readFileSync(join(here, entry.input), 'utf8')));
|
|
52
|
+
}
|
|
53
|
+
if (entry.kind === 'fragment') {
|
|
54
|
+
return core.serialize(
|
|
55
|
+
core.parseFragment(hostDoc, readFileSync(join(here, entry.input), 'utf8'))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
if (entry.kind === 'apply') {
|
|
59
|
+
const name = entry.input.split('#')[1];
|
|
60
|
+
const c = opsByName.get(name);
|
|
61
|
+
if (!c) throw new Error(`ops-cases.json 里找不到用例 ${name}`);
|
|
62
|
+
const html = opsData.wrapper.replace('{{HEAD_EXTRA}}', '').replace('{{BODY}}', c.body);
|
|
63
|
+
const doc = parse(html);
|
|
64
|
+
const r = core.apply(doc, c.ops, { profile: core.KIND_PROFILES.page });
|
|
65
|
+
if (!r.ok) throw new Error(`apply 失败 ${r.error.code} @${r.failedIndex}`);
|
|
66
|
+
return core.serialize(doc);
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`未知的 kind: ${entry.kind}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let failed = 0;
|
|
72
|
+
for (const entry of manifest.fixtures) {
|
|
73
|
+
let actual;
|
|
74
|
+
try {
|
|
75
|
+
actual = sha(compute(entry));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.error(`✗ ${entry.fixture} — ${e.message}`);
|
|
78
|
+
failed++;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (actual !== entry.sha256) {
|
|
82
|
+
console.error(`✗ ${entry.fixture}\n 期望 ${entry.sha256}\n 实际 ${actual}`);
|
|
83
|
+
failed++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const total = manifest.fixtures.length;
|
|
88
|
+
if (failed > 0) {
|
|
89
|
+
console.error(
|
|
90
|
+
`\ngolden-verify: ${failed}/${total} 不一致(core ${core.VERSION}, ` +
|
|
91
|
+
`COMPILER_VERSION ${manifest.COMPILER_VERSION})\n` +
|
|
92
|
+
'这一侧的产出与发布时不同 —— 先别接上去,它会让两端的文档逐轮分叉。\n' +
|
|
93
|
+
'常见原因:DOM 实现不是 HTML5 规范解析器(如 node-html-parser)、\n' +
|
|
94
|
+
'或 core 版本与清单不匹配。'
|
|
95
|
+
);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
console.log(
|
|
99
|
+
`golden-verify: ${total}/${total} 一致 ` +
|
|
100
|
+
`(core ${core.VERSION}, COMPILER_VERSION ${manifest.COMPILER_VERSION})`
|
|
101
|
+
);
|
package/dist/index.d.ts
CHANGED
|
@@ -564,7 +564,7 @@ declare function checkVariants(className: string): VariantCheck;
|
|
|
564
564
|
* 护栏:export golden 断言「输出变了而 COMPILER_VERSION 没变就红」。
|
|
565
565
|
* 递增它是一次显式动作,不要顺手跟着包版本一起改。
|
|
566
566
|
*/
|
|
567
|
-
declare const VERSION = "1.0.0-alpha.
|
|
567
|
+
declare const VERSION = "1.0.0-alpha.1";
|
|
568
568
|
declare const COMPILER_VERSION = "1";
|
|
569
569
|
|
|
570
570
|
/**
|