@xrubik/fabric-to-leafer 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +62 -2
- package/dist/index.cjs +2137 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +86 -0
- package/dist/index.mjs +2094 -0
- package/dist/index.mjs.map +1 -0
- package/dist/leafer.cjs +1512 -0
- package/dist/leafer.cjs.map +1 -0
- package/dist/leafer.d.ts +13 -0
- package/dist/leafer.mjs +1484 -0
- package/dist/leafer.mjs.map +1 -0
- package/leafer.js +4 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rubik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @rubik/fabric-to-leafer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fabric JSON → Leafer JSON 转换器。纯数据转换,不依赖 `leafer-ui`,可在浏览器、Node、Worker、CLI 中运行。
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import { convert, convertSync } from '@rubik/fabric-to-leafer'
|
|
7
|
+
|
|
8
|
+
const { document, warnings } = await convert(fabricJson, {
|
|
9
|
+
resolveAsset: (path) => '/assets/' + path,
|
|
10
|
+
// lib 只保存 libName 时,由宿主提供页面定义
|
|
11
|
+
loadLib: (libName) => fetch('/mmi/' + libName + '.json').then((res) => res.json())
|
|
12
|
+
})
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
反向转换(Leafer JSON → Fabric JSON),返回结构和 `convertSync` 一致:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { convertSync, leaferToFabric } from '@rubik/fabric-to-leafer'
|
|
19
|
+
|
|
20
|
+
const { document: leafer } = convertSync(fabricJson)
|
|
21
|
+
const { document: fabric, warnings } = leaferToFabric(leafer, { version: '5.5.2' })
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 结构
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
src/
|
|
28
|
+
convert.js 主流程:遍历 objects → children
|
|
29
|
+
context.js 配置、告警、资源解析
|
|
30
|
+
document.js 根文档 header / param
|
|
31
|
+
nodes.js 纯对象节点工厂
|
|
32
|
+
colors.js 颜色归一化
|
|
33
|
+
gradient.js 渐变转换
|
|
34
|
+
pattern.js Pattern 填充/描边 → Leafer 图片 paint
|
|
35
|
+
geometry.js 定位、翻转、点集、path 字符串
|
|
36
|
+
assets.js 图片地址 → resolveAsset
|
|
37
|
+
lib.js lib 参数替换、页面动作清理、lib 引用水合 / 剥离
|
|
38
|
+
leafer2fabric.js Leafer JSON → Fabric JSON(反向转换)
|
|
39
|
+
elements/ 每种 Fabric 类型一个文件
|
|
40
|
+
attributes/ 公共属性:变换 / 填充 / 文本 / 元数据
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 加一种元素
|
|
44
|
+
|
|
45
|
+
1. 新建 `src/elements/xxx.js`,导出 `convertXxx(object, ctx, parent)`
|
|
46
|
+
2. 在 `src/elements/index.js` 的类型表里登记
|
|
47
|
+
|
|
48
|
+
## 加一个公共属性
|
|
49
|
+
|
|
50
|
+
放到 `src/attributes/` 对应文件,由 `applyCommon` 统一调用,不要写进各个元素。
|
|
51
|
+
|
|
52
|
+
## 与 leafer-ui 配合
|
|
53
|
+
|
|
54
|
+
应用启动时注册一次自定义字段,否则 `toJSON()` / 保存时 `type`、`param`、`action` 会被丢掉:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { registerFabricAttrs } from '@rubik/fabric-to-leafer/leafer'
|
|
58
|
+
registerFabricAttrs()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
- 已有 JSON:`leafer.add(document.children)`
|
|
62
|
+
- 需要节点实例:`const { children } = await convertToNodes(fabricJson)`
|
|
63
|
+
- lib 会输出 `tag: 'Lib'` 自定义元素,实例化前需要先导入 `@rubik/fabric-to-leafer-elements`
|