@ptengine/lp-editor-core 1.0.0-alpha.0
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/LICENSE +3 -0
- package/README.md +84 -0
- package/dist/golden/manifest.json +173 -0
- package/dist/index.d.ts +678 -0
- package/dist/index.js +1426 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# @ptengine/lp-editor-core
|
|
2
|
+
|
|
3
|
+
Ptengine 落地页编辑器 v4 的核心逻辑:v4 源格式契约、`EditOp` 的应用与回退、规范序列化、
|
|
4
|
+
Tailwind 编译封装。
|
|
5
|
+
|
|
6
|
+
> **内部契约包,不是通用库。** 它为 Ptengine 的编辑器与 AI 服务而存在,接口随产品需要变动,
|
|
7
|
+
> 不面向外部使用者。可以公开安装,但不对外提供支持。
|
|
8
|
+
|
|
9
|
+
## 它为什么存在
|
|
10
|
+
|
|
11
|
+
页面样式用 Tailwind class 表达,两端差别靠 `md:` / `max-md:`。围绕这个格式,有两个实现方
|
|
12
|
+
需要对同一份文档做同样的事:编辑器在浏览器里应用 `EditOp`,AI 服务在 Node 里对自己的页面
|
|
13
|
+
缓存应用同一组 `EditOp`。
|
|
14
|
+
|
|
15
|
+
**两侧必须逐字节相同。** 否则两份文档会逐轮分叉,AI 最终会引用到已被删除的元素,而且不报错。
|
|
16
|
+
这个包就是那条不变量的载体 —— 一份实现,两侧共用。
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @ptengine/lp-editor-core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
ESM only,需要 Node ≥ 20。`tailwindcss` 是它的依赖并**锁在精确版本**上:两侧必须用同一个
|
|
25
|
+
编译器版本,否则产物会漂。
|
|
26
|
+
|
|
27
|
+
## 用法
|
|
28
|
+
|
|
29
|
+
DOM 由宿主注入 —— 这个包不读任何浏览器全局,所以同一份代码在浏览器与 Node 里行为一致。
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createCore } from '@ptengine/lp-editor-core';
|
|
33
|
+
|
|
34
|
+
// 浏览器
|
|
35
|
+
const core = createCore({ DOMParser: window.DOMParser });
|
|
36
|
+
|
|
37
|
+
// Node
|
|
38
|
+
import { JSDOM } from 'jsdom';
|
|
39
|
+
const core = createCore({ DOMParser: new JSDOM('').window.DOMParser });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const doc = core.parse(sourceHtml);
|
|
44
|
+
core.normalize(doc); // 唯一分配元素 id 的地方
|
|
45
|
+
|
|
46
|
+
const { ok, issues } = core.validate(doc, { profile: core.KIND_PROFILES.page });
|
|
47
|
+
|
|
48
|
+
const result = core.apply(doc, ops, { profile: core.KIND_PROFILES.page });
|
|
49
|
+
if (result.ok) {
|
|
50
|
+
const html = core.serialize(doc); // 规范序列化,两侧同字节
|
|
51
|
+
const undo = result.inverse; // 逆操作,喂给撤销栈
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 主要导出
|
|
56
|
+
|
|
57
|
+
| 导出 | 作用 |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `createCore({ DOMParser })` | 注入 DOM,拿到一组行为 |
|
|
60
|
+
| `parse` / `parseFragment` / `serialize` | 解析与**规范**序列化 |
|
|
61
|
+
| `normalize` | 补元素 id、老格式转换。**唯一允许生成 id 的地方**,且幂等 |
|
|
62
|
+
| `validate` | 格式 / 结构 / id / 变体 / 占位五类规则,返回不含文案的结构化条目 |
|
|
63
|
+
| `apply` | 应用 `EditOp[]` 并产出逆操作。任一条失败则整个事务不生效 |
|
|
64
|
+
| `compile.{incremental,fresh,warm}` | Tailwind 编译。`fresh` 的输出只取决于内容 |
|
|
65
|
+
| `collectClasses` | 收集文档用到的 class |
|
|
66
|
+
| `guards` | AI 护栏:id 命中、片段 id 齐全、禁脚本与事件属性 |
|
|
67
|
+
| `rules` / `KIND_PROFILES` | 规则数据表与两种文档类型的能力档 |
|
|
68
|
+
| `VERSION` / `COMPILER_VERSION` | 包版本 / **编译产物版本**(两者独立,见下) |
|
|
69
|
+
|
|
70
|
+
### 两个版本号
|
|
71
|
+
|
|
72
|
+
`VERSION` 按语义化版本走。`COMPILER_VERSION` **只在编译、导出、组件渲染或规范序列化的输出
|
|
73
|
+
可能改变时**递增 —— 下游按它判断已有成品要不要重新生成。改一条规则数据不应该让所有成品
|
|
74
|
+
失效,所以这两个号有意分开。
|
|
75
|
+
|
|
76
|
+
### golden 摘要清单
|
|
77
|
+
|
|
78
|
+
包里带 `dist/golden/manifest.json`:`{ fixture, COMPILER_VERSION, sha256 }`。下游可以在 Node
|
|
79
|
+
侧跑一遍样例、算 sha256 与它比对,确认自己这一侧与发布时的产物一致,不需要装浏览器。
|
|
80
|
+
完整快照留在源码仓里,不随包发布。
|
|
81
|
+
|
|
82
|
+
## 许可
|
|
83
|
+
|
|
84
|
+
ISC
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
{
|
|
2
|
+
"COMPILER_VERSION": "1",
|
|
3
|
+
"fixtures": [
|
|
4
|
+
{
|
|
5
|
+
"fixture": "canonical/01-tailwind-landing.txt",
|
|
6
|
+
"sha256": "c70beb2e085d0c538f0b6852c763735d119e0a065f2bb450d5dfe5ec7c17539f"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"fixture": "canonical/02-table-foster-parenting.txt",
|
|
10
|
+
"sha256": "3b723af0670b8a9edf275e77a0da643ed7b8ca4bd1dc93514a3dda0a69171408"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"fixture": "canonical/03-p-block-nesting.txt",
|
|
14
|
+
"sha256": "687bb7d4090da2a23d1397dca02c2480992bd3e4f586c5b18469b94b4308ff64"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"fixture": "canonical/04-unclosed-misnested.txt",
|
|
18
|
+
"sha256": "f5e1b7beb75b6cd7204f28600e4038fedc4543877c93eeff7310bcd7844a6d1b"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"fixture": "canonical/05-attr-quotes-entities-unicode.txt",
|
|
22
|
+
"sha256": "151fcfd19531f5491a2a628cc323df28ab92ac1d01c38cd27e64290a2db36cfc"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"fixture": "canonical/06-comments-rawtext.txt",
|
|
26
|
+
"sha256": "0bc41478abce7a088bf37fc3c82ef706bbbfab556b30795aeff4b5669ac903fa"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"fixture": "canonical/07-boolean-empty-attrs.txt",
|
|
30
|
+
"sha256": "eaf96016ae7d765d66c6e561c8cd2ea9b5e26e665a32a732c94b6e86847fc92b"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"fixture": "canonical/08-mega-class-list.txt",
|
|
34
|
+
"sha256": "9c3e9f876500a5b678c36677b5baa75c580c61eb2b222769f1ab10a73b24caf9"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"fixture": "canonical/09-legacy-doctype.txt",
|
|
38
|
+
"sha256": "4fab52be1ccb9c0c985dd98b808178147084beac769aebb355d576156c1422f1"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"fixture": "canonical/10-foreign-template-pre.txt",
|
|
42
|
+
"sha256": "c015da23781fc7f5fb26f6054f57d3c37e513944c0b368ba406f26c551531d9b"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"fixture": "canonical/11-adoption-agency-deep.txt",
|
|
46
|
+
"sha256": "fcb0a5ec78511e2f2039d764ff90b8b9b11b9368efb4e535053749fc7ae96cac"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"fixture": "canonical/12-charrefs-control-chars.txt",
|
|
50
|
+
"sha256": "b24a1c4c1f51183485639739fa69bcc451dca7a100de6990e7c510cf66269d42"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"fixture": "canonical/13-namespaces-custom-dup-attrs.txt",
|
|
54
|
+
"sha256": "951f97adc5eeec527d830fb7b6a3b28b4f13192f2cec1cffdfa802b146efdce0"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"fixture": "popup-canonical/01-jp-coupon-line-tall.txt",
|
|
58
|
+
"sha256": "f4d6fce08b3413a4bb1a2d8f7be2dbe45d869f29332f536a90ea05a05ef3560e"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"fixture": "popup-canonical/02-jp-webinar-doctor.txt",
|
|
62
|
+
"sha256": "87e56b79f3514678419cf33fd4d8d159f12382548091d3c67cc4a8a50717e4cc"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"fixture": "popup-canonical/03-jp-model-recruit.txt",
|
|
66
|
+
"sha256": "48b3451d6ecfd3e79ec23ad8ded08d66a137e55828f6eb4e96521ad9f52292f3"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"fixture": "popup-canonical/04-jp-shinpi-campaign.txt",
|
|
70
|
+
"sha256": "8b866af5f1d2de37eba363b94a567d9a41f6451fbe0a46859588b6b33abe203a"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"fixture": "popup-canonical/05-jp-jal-course.txt",
|
|
74
|
+
"sha256": "919a66d964e775905c2e9c05f61f1e0cd4e36fde5d962aacf25d691aa1cd67b8"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"fixture": "popup-canonical/06-jp-training-two-cta.txt",
|
|
78
|
+
"sha256": "caf43139254da316f841c1b09df8714482a6d3c939c861df5e465c4dc3839394"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"fixture": "popup-canonical/07-vivaia-lightweight-shoes.txt",
|
|
82
|
+
"sha256": "acd60830a6231d4680cb0de2ca9ad0f182953761f2524158d0364ea87aac5372"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"fixture": "popup-canonical/08-sticky-black-friday-countdown.txt",
|
|
86
|
+
"sha256": "92965e1fbfab27aeff9d98d0359e15820bafa3e78eaa6553b5a937fd6db97dd7"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"fixture": "popup-canonical/09-sticky-line-coupon-countdown.txt",
|
|
90
|
+
"sha256": "8209face5ae705167ef14f21bfccb3d7d2c708aa3f7b6371b87879468fe3b2f9"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"fixture": "popup-canonical/10-sticky-coupon-code-countdown.txt",
|
|
94
|
+
"sha256": "06594d8504a65a3a45ee3fbe10fb5046b5d1b071eaf21fe28ff62c9a60b98fab"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"fixture": "popup-canonical/11-sticky-anniversary-countdown.txt",
|
|
98
|
+
"sha256": "51da066020a1e32537842c93be8518e0d665af8fdc94e0339e63bf46bd6828fa"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"fixture": "popup-canonical/12-vivaia-product-grid.txt",
|
|
102
|
+
"sha256": "db02805b296c0a054a3c0265bcd59caf904ea113aef9da448412b7d1222e2f79"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"fixture": "popup-canonical/13-vivaia-restock-split.txt",
|
|
106
|
+
"sha256": "02c5f27ff8f09fd884e98a7b95fa60407be25441657746bcf8c1a7f6b17e4caa"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"fixture": "popup-canonical/14-back-to-school-email-form.txt",
|
|
110
|
+
"sha256": "5df1fa26566773acfa8e33417b84014a90b79e03619062bc7029674056af3954"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"fixture": "popup-canonical/15-xtool-ebook-split-form.txt",
|
|
114
|
+
"sha256": "6bc46c4e35677bcdbbeb93aad8a42c4b95f7039890ff07b80eda1eeed43cb759"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"fixture": "popup-canonical/16-880-off-gradient-form.txt",
|
|
118
|
+
"sha256": "0b0e431349b51ec3eb0aad65da385d69a255cafbc3179af8b9abbe78bbe491cd"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"fixture": "popup-canonical/17-holiday-sale-price-swatch.txt",
|
|
122
|
+
"sha256": "5b8b71bbf145753e095e044b2616ab1df7434878a87f0b2739f15819b996b09d"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"fixture": "popup-canonical/18-solar-battery-dark-specs.txt",
|
|
126
|
+
"sha256": "4601802f37e663159e9b58a0fe9d2617b53bd80f88bc15aea55876fdc18886c7"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"fixture": "popup-canonical/19-jp-clinic-coupon-placeholder.txt",
|
|
130
|
+
"sha256": "6b56860a22d361f1cca4419ce5ff0d974fbe08cd00b92ab6c1d48e190ca4c3ef"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"fixture": "apply-golden/01-set-attrs-classes.txt",
|
|
134
|
+
"sha256": "3309bb2a6959b472e28b5fba4120c1905725d532d1ea1a8363c1662507b66a36"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"fixture": "apply-golden/02-rich-text-and-theme.txt",
|
|
138
|
+
"sha256": "0a71c74fdcdd85dfe10312ff49d7e2adc27ba5c45ef86b4ac522c6184a70b450"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"fixture": "apply-golden/03-insert-delete-whitespace.txt",
|
|
142
|
+
"sha256": "65b7772ac8e507869030071be9e0febb664657a07aa10729482b352b1289777e"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"fixture": "apply-golden/04-sequential-index-semantics.txt",
|
|
146
|
+
"sha256": "acc91eb6f761f0fe5f35136e4eaa03cfb130ff33add9d5313438a653479e51df"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"fixture": "apply-golden/05-delete-cascade.txt",
|
|
150
|
+
"sha256": "60beed20aac09149c67b786e58b66f8501849810d4cac0ea3d2ce7908f8e1f90"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"fixture": "apply-golden/06-replace-keeps-id.txt",
|
|
154
|
+
"sha256": "c594bb2cbabe05984dced5b5fe14579a815abcefcd7bb0e6fbca69e49d70bb27"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"fixture": "apply-golden/07-opaque-table-text-edit.txt",
|
|
158
|
+
"sha256": "f73439f9454d39caa43470f921f2f5dd0be7934fbb60c9fe27fb95cd99965b7e"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"fixture": "apply-golden/08-picture-and-placeholder.txt",
|
|
162
|
+
"sha256": "9f708b74065b9afe078100a50c15549e756fca1e81f9bb299796b1cfa4eaeadf"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"fixture": "apply-golden/09-move-across-containers.txt",
|
|
166
|
+
"sha256": "91ab24e869d3082abfc6cb41eda17693bff6621fdf870a53dedd4e3ca10eb05b"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"fixture": "apply-golden/10-insert-section-into-root.txt",
|
|
170
|
+
"sha256": "7131403b7dc6e97f947d7b57a0ae6123d73c0d3648308ee12744831b69f3bb19"
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|