@zseven-w/pen-sdk 0.7.0 → 0.7.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/LICENSE +21 -0
- package/README.md +115 -24
- package/package.json +21 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ZSeven—W
|
|
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,56 +1,147 @@
|
|
|
1
1
|
# @zseven-w/pen-sdk
|
|
2
2
|
|
|
3
|
-
The umbrella SDK for [OpenPencil](https://github.com/
|
|
3
|
+
The umbrella SDK for [OpenPencil](https://github.com/ZSeven-W/openpencil). One import gives you everything — types, document operations, headless engine, React components, code generation, Figma import, and GPU rendering.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install @zseven-w/pen-sdk
|
|
9
|
+
# or
|
|
10
|
+
bun add @zseven-w/pen-sdk
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
`pen-sdk` re-exports all OpenPencil packages through a single entry point. Use it when you want the full stack without managing individual dependencies. For smaller bundles, install only the packages you need.
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
## What's Included
|
|
14
18
|
|
|
15
|
-
| Package
|
|
16
|
-
|
|
|
17
|
-
| `@zseven-w/pen-types`
|
|
18
|
-
| `@zseven-w/pen-core`
|
|
19
|
-
| `@zseven-w/pen-
|
|
20
|
-
| `@zseven-w/pen-
|
|
21
|
-
| `@zseven-w/pen-renderer` | CanvasKit/Skia GPU renderer
|
|
19
|
+
| Package | Provides |
|
|
20
|
+
| ------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
21
|
+
| [`@zseven-w/pen-types`](../pen-types) | TypeScript types for the document model (`PenDocument`, `PenNode`, `PenFill`, etc.) |
|
|
22
|
+
| [`@zseven-w/pen-core`](../pen-core) | Tree operations, layout engine, variables, boolean ops, normalization, 3-way merge |
|
|
23
|
+
| [`@zseven-w/pen-engine`](../pen-engine) | Headless design engine — document, selection, history, viewport, spatial index |
|
|
24
|
+
| [`@zseven-w/pen-react`](../pen-react) | React UI SDK — `DesignProvider`, `DesignCanvas`, 10 hooks, 39 components |
|
|
25
|
+
| [`@zseven-w/pen-renderer`](../pen-renderer) | CanvasKit/Skia GPU renderer with viewport, hit testing, font/image management |
|
|
26
|
+
| [`@zseven-w/pen-figma`](../pen-figma) | Figma `.fig` binary parser and converter |
|
|
22
27
|
|
|
23
28
|
## Usage
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
### Build a full editor
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import {
|
|
34
|
+
DesignProvider,
|
|
35
|
+
DesignCanvas,
|
|
36
|
+
CoreToolbar,
|
|
37
|
+
LayerPanel,
|
|
38
|
+
PropertyPanel,
|
|
39
|
+
useDocument,
|
|
40
|
+
useSelection,
|
|
41
|
+
useHistory,
|
|
42
|
+
} from '@zseven-w/pen-sdk';
|
|
43
|
+
|
|
44
|
+
function Editor() {
|
|
45
|
+
return (
|
|
46
|
+
<DesignProvider initialDocument={myDoc}>
|
|
47
|
+
<CoreToolbar />
|
|
48
|
+
<DesignCanvas />
|
|
49
|
+
<LayerPanel />
|
|
50
|
+
<PropertyPanel />
|
|
51
|
+
</DesignProvider>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Document operations
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
26
59
|
import {
|
|
27
|
-
// Types
|
|
28
60
|
type PenDocument,
|
|
29
61
|
type PenNode,
|
|
30
|
-
|
|
31
|
-
// Document operations
|
|
32
62
|
createEmptyDocument,
|
|
33
63
|
findNodeInTree,
|
|
34
64
|
insertNodeInTree,
|
|
65
|
+
flattenNodes,
|
|
35
66
|
normalizePenDocument,
|
|
67
|
+
resolveNodeForCanvas,
|
|
68
|
+
} from '@zseven-w/pen-sdk';
|
|
69
|
+
|
|
70
|
+
const doc = createEmptyDocument();
|
|
71
|
+
const node = findNodeInTree(doc.children, 'header');
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Headless engine (no React)
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { DesignEngine } from '@zseven-w/pen-sdk';
|
|
78
|
+
|
|
79
|
+
const engine = new DesignEngine();
|
|
80
|
+
engine.loadDocument(doc);
|
|
81
|
+
engine.addNode(null, { type: 'frame', name: 'Page', width: 1200, height: 800 });
|
|
82
|
+
engine.select(['node-1']);
|
|
83
|
+
engine.undo();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Code generation
|
|
36
87
|
|
|
37
|
-
|
|
88
|
+
```typescript
|
|
89
|
+
import {
|
|
38
90
|
generateReactFromDocument,
|
|
39
91
|
generateHTMLFromDocument,
|
|
40
92
|
generateFlutterFromDocument,
|
|
93
|
+
generateVueFromDocument,
|
|
94
|
+
generateSvelteFromDocument,
|
|
95
|
+
generateSwiftUIFromDocument,
|
|
96
|
+
} from '@zseven-w/pen-sdk';
|
|
41
97
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
98
|
+
const reactCode = generateReactFromDocument(doc);
|
|
99
|
+
const htmlCode = generateHTMLFromDocument(doc);
|
|
100
|
+
```
|
|
45
101
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} from '@zseven-w/pen-sdk';
|
|
102
|
+
### Figma import
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { parseFigFile, figmaAllPagesToPenDocument, isFigmaClipboardHtml } from '@zseven-w/pen-sdk';
|
|
106
|
+
|
|
107
|
+
const figFile = parseFigFile(buffer);
|
|
108
|
+
const document = figmaAllPagesToPenDocument(figFile);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### GPU rendering (headless)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { loadCanvasKit, PenRenderer } from '@zseven-w/pen-sdk';
|
|
115
|
+
|
|
116
|
+
await loadCanvasKit();
|
|
117
|
+
const renderer = new PenRenderer(canvas, document);
|
|
118
|
+
renderer.render();
|
|
50
119
|
```
|
|
51
120
|
|
|
52
|
-
|
|
121
|
+
## Individual Packages
|
|
122
|
+
|
|
123
|
+
For smaller bundles, install only what you need:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Types only (zero runtime)
|
|
127
|
+
npm install @zseven-w/pen-types
|
|
128
|
+
|
|
129
|
+
# Document operations (no rendering)
|
|
130
|
+
npm install @zseven-w/pen-core
|
|
131
|
+
|
|
132
|
+
# Headless engine (no React)
|
|
133
|
+
npm install @zseven-w/pen-engine
|
|
134
|
+
|
|
135
|
+
# React components
|
|
136
|
+
npm install @zseven-w/pen-react
|
|
137
|
+
|
|
138
|
+
# GPU renderer
|
|
139
|
+
npm install @zseven-w/pen-renderer canvaskit-wasm
|
|
140
|
+
|
|
141
|
+
# Figma import
|
|
142
|
+
npm install @zseven-w/pen-figma
|
|
143
|
+
```
|
|
53
144
|
|
|
54
145
|
## License
|
|
55
146
|
|
|
56
|
-
MIT
|
|
147
|
+
[MIT](./LICENSE)
|
package/package.json
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zseven-w/pen-sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "OpenPencil SDK — parse, manipulate, and generate code from .op design files",
|
|
5
|
+
"homepage": "https://github.com/ZSeven-W/openpencil/tree/main/packages/pen-sdk",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/ZSeven-W/openpencil/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "ZSeven-W",
|
|
12
|
+
"email": "xkayshen@gmail.com"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/ZSeven-W/openpencil.git",
|
|
17
|
+
"directory": "packages/pen-sdk"
|
|
18
|
+
},
|
|
5
19
|
"files": [
|
|
6
20
|
"src"
|
|
7
21
|
],
|
|
@@ -16,12 +30,12 @@
|
|
|
16
30
|
"typecheck": "tsc --noEmit"
|
|
17
31
|
},
|
|
18
32
|
"dependencies": {
|
|
19
|
-
"@zseven-w/pen-core": "0.7.
|
|
20
|
-
"@zseven-w/pen-engine": "0.7.
|
|
21
|
-
"@zseven-w/pen-figma": "0.7.
|
|
22
|
-
"@zseven-w/pen-react": "0.7.
|
|
23
|
-
"@zseven-w/pen-renderer": "0.7.
|
|
24
|
-
"@zseven-w/pen-types": "0.7.
|
|
33
|
+
"@zseven-w/pen-core": "0.7.1",
|
|
34
|
+
"@zseven-w/pen-engine": "0.7.1",
|
|
35
|
+
"@zseven-w/pen-figma": "0.7.1",
|
|
36
|
+
"@zseven-w/pen-react": "0.7.1",
|
|
37
|
+
"@zseven-w/pen-renderer": "0.7.1",
|
|
38
|
+
"@zseven-w/pen-types": "0.7.1"
|
|
25
39
|
},
|
|
26
40
|
"devDependencies": {
|
|
27
41
|
"typescript": "^5.7.2"
|