fabricjs-document-engine 1.0.1 → 1.1.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/README.md +277 -36
- package/README.zh-CN.md +697 -0
- package/dist/assets/asset-manifest.d.cts +3 -0
- package/dist/assets/asset-manifest.d.ts +3 -0
- package/dist/assets/asset-pipeline.cjs +22 -10
- package/dist/assets/asset-pipeline.d.cts +5 -1
- package/dist/assets/asset-pipeline.d.ts +5 -1
- package/dist/assets/asset-pipeline.js +22 -10
- package/dist/assets/font-check.cjs +9 -1
- package/dist/assets/font-check.js +9 -1
- package/dist/assets/image-check.cjs +88 -6
- package/dist/assets/image-check.d.cts +17 -0
- package/dist/assets/image-check.d.ts +17 -0
- package/dist/assets/image-check.js +88 -7
- package/dist/commands/clipboard.cjs +136 -0
- package/dist/commands/clipboard.d.cts +47 -0
- package/dist/commands/clipboard.d.ts +47 -0
- package/dist/commands/clipboard.js +135 -0
- package/dist/commands/layers.cjs +97 -0
- package/dist/commands/layers.d.cts +39 -0
- package/dist/commands/layers.d.ts +39 -0
- package/dist/commands/layers.js +92 -0
- package/dist/engine/create-document-engine.cjs +85 -14
- package/dist/engine/create-document-engine.d.cts +20 -1
- package/dist/engine/create-document-engine.d.ts +20 -1
- package/dist/engine/create-document-engine.js +86 -15
- package/dist/engine/errors.d.cts +1 -1
- package/dist/engine/errors.d.ts +1 -1
- package/dist/export/batch-render.cjs +172 -0
- package/dist/export/batch-render.d.cts +43 -0
- package/dist/export/batch-render.d.ts +43 -0
- package/dist/export/batch-render.js +171 -0
- package/dist/export/export-options.cjs +18 -1
- package/dist/export/export-options.d.cts +23 -0
- package/dist/export/export-options.d.ts +23 -0
- package/dist/export/export-options.js +18 -2
- package/dist/export/preflight-export.cjs +11 -2
- package/dist/export/preflight-export.d.cts +1 -1
- package/dist/export/preflight-export.d.ts +1 -1
- package/dist/export/preflight-export.js +11 -2
- package/dist/export/render-export.cjs +18 -3
- package/dist/export/render-export.js +18 -4
- package/dist/export/svg/embed-assets.cjs +249 -0
- package/dist/export/svg/embed-assets.js +249 -0
- package/dist/export/svg/overrides.cjs +32 -0
- package/dist/export/svg/overrides.js +32 -0
- package/dist/export/svg/text-on-path.cjs +252 -0
- package/dist/export/svg/text-on-path.js +249 -0
- package/dist/fabric/fabric-adapter.cjs +46 -5
- package/dist/fabric/fabric-adapter.js +46 -5
- package/dist/fabric/object-registry.cjs +1 -1
- package/dist/fabric/object-registry.js +1 -1
- package/dist/import/svg-import.cjs +256 -0
- package/dist/import/svg-import.d.cts +50 -0
- package/dist/import/svg-import.d.ts +50 -0
- package/dist/import/svg-import.js +256 -0
- package/dist/index.cjs +12 -0
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +4 -1
- package/dist/pdf/export-pdf.cjs +440 -0
- package/dist/pdf/export-pdf.d.cts +73 -0
- package/dist/pdf/export-pdf.d.ts +73 -0
- package/dist/pdf/export-pdf.js +440 -0
- package/dist/pdf/fonts.cjs +115 -0
- package/dist/pdf/fonts.d.cts +12 -0
- package/dist/pdf/fonts.d.ts +12 -0
- package/dist/pdf/fonts.js +112 -0
- package/dist/pdf/page-layout.cjs +79 -0
- package/dist/pdf/page-layout.d.cts +51 -0
- package/dist/pdf/page-layout.d.ts +51 -0
- package/dist/pdf/page-layout.js +76 -0
- package/dist/pdf/text-decorations.cjs +108 -0
- package/dist/pdf/text-decorations.js +107 -0
- package/dist/pdf.cjs +7 -0
- package/dist/pdf.d.cts +4 -0
- package/dist/pdf.d.ts +4 -0
- package/dist/pdf.js +3 -0
- package/dist/react/use-layers.cjs +53 -0
- package/dist/react/use-layers.d.cts +10 -0
- package/dist/react/use-layers.d.ts +10 -0
- package/dist/react/use-layers.js +53 -0
- package/dist/react.cjs +2 -0
- package/dist/react.d.cts +3 -1
- package/dist/react.d.ts +3 -1
- package/dist/react.js +2 -1
- package/dist/util/concurrency.cjs +28 -0
- package/dist/util/concurrency.js +27 -0
- package/package.json +55 -14
package/dist/react.js
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
import { useDocumentEngine } from "./react/use-document-engine.js";
|
|
3
3
|
import { useDocumentState } from "./react/use-document-state.js";
|
|
4
4
|
import { useDocumentEvent } from "./react/use-document-event.js";
|
|
5
|
+
import { useLayers } from "./react/use-layers.js";
|
|
5
6
|
import { DocumentEngineProvider, useEngine } from "./react/engine-context.js";
|
|
6
|
-
export { DocumentEngineProvider, useDocumentEngine, useDocumentEvent, useDocumentState, useEngine };
|
|
7
|
+
export { DocumentEngineProvider, useDocumentEngine, useDocumentEvent, useDocumentState, useEngine, useLayers };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/util/concurrency.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runs `work` for every item with at most `limit` running at once, and
|
|
4
|
+
* returns the results in the order of `items`.
|
|
5
|
+
*/
|
|
6
|
+
async function mapWithConcurrency(items, limit, work) {
|
|
7
|
+
const results = new Array(items.length);
|
|
8
|
+
const workers = Math.max(1, Math.min(Math.floor(limit) || 1, items.length));
|
|
9
|
+
let next = 0;
|
|
10
|
+
async function runWorker() {
|
|
11
|
+
while (next < items.length) {
|
|
12
|
+
const index = next;
|
|
13
|
+
next += 1;
|
|
14
|
+
results[index] = await work(items[index], index);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
await Promise.all(Array.from({ length: workers }, runWorker));
|
|
18
|
+
return results;
|
|
19
|
+
}
|
|
20
|
+
/** Lets the browser paint and handle input before the next piece of work. */
|
|
21
|
+
function yieldToEventLoop() {
|
|
22
|
+
const scheduler = globalThis.scheduler;
|
|
23
|
+
if (typeof scheduler?.yield === "function") return scheduler.yield();
|
|
24
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.mapWithConcurrency = mapWithConcurrency;
|
|
28
|
+
exports.yieldToEventLoop = yieldToEventLoop;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/util/concurrency.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runs `work` for every item with at most `limit` running at once, and
|
|
4
|
+
* returns the results in the order of `items`.
|
|
5
|
+
*/
|
|
6
|
+
async function mapWithConcurrency(items, limit, work) {
|
|
7
|
+
const results = new Array(items.length);
|
|
8
|
+
const workers = Math.max(1, Math.min(Math.floor(limit) || 1, items.length));
|
|
9
|
+
let next = 0;
|
|
10
|
+
async function runWorker() {
|
|
11
|
+
while (next < items.length) {
|
|
12
|
+
const index = next;
|
|
13
|
+
next += 1;
|
|
14
|
+
results[index] = await work(items[index], index);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
await Promise.all(Array.from({ length: workers }, runWorker));
|
|
18
|
+
return results;
|
|
19
|
+
}
|
|
20
|
+
/** Lets the browser paint and handle input before the next piece of work. */
|
|
21
|
+
function yieldToEventLoop() {
|
|
22
|
+
const scheduler = globalThis.scheduler;
|
|
23
|
+
if (typeof scheduler?.yield === "function") return scheduler.yield();
|
|
24
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { mapWithConcurrency, yieldToEventLoop };
|
package/package.json
CHANGED
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fabricjs-document-engine",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Fabric.js save and load, undo and redo, and autosave for an existing canvas: stable object ids, custom objects, copy and paste, SVG import, PNG, SVG and PDF export, and recovery.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"fabric",
|
|
7
6
|
"fabricjs",
|
|
8
7
|
"fabric.js",
|
|
8
|
+
"fabric",
|
|
9
|
+
"fabric js",
|
|
9
10
|
"canvas",
|
|
10
11
|
"canvas editor",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"serialization",
|
|
12
|
+
"fabricjs editor",
|
|
13
|
+
"design editor",
|
|
14
|
+
"image editor",
|
|
15
|
+
"undo redo",
|
|
16
16
|
"undo",
|
|
17
17
|
"redo",
|
|
18
|
+
"history",
|
|
19
|
+
"save canvas json",
|
|
20
|
+
"load from json",
|
|
21
|
+
"tojson",
|
|
22
|
+
"loadfromjson",
|
|
23
|
+
"serialization",
|
|
18
24
|
"autosave",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
25
|
+
"custom objects",
|
|
26
|
+
"custom properties",
|
|
27
|
+
"object id",
|
|
28
|
+
"export svg",
|
|
29
|
+
"export image",
|
|
30
|
+
"text on path",
|
|
31
|
+
"import svg",
|
|
32
|
+
"layers",
|
|
33
|
+
"copy paste",
|
|
34
|
+
"pdf",
|
|
35
|
+
"export pdf",
|
|
22
36
|
"recovery",
|
|
37
|
+
"indexeddb",
|
|
23
38
|
"react",
|
|
24
|
-
"react hooks"
|
|
39
|
+
"react hooks",
|
|
40
|
+
"nextjs",
|
|
41
|
+
"vue",
|
|
42
|
+
"svelte",
|
|
43
|
+
"typescript"
|
|
25
44
|
],
|
|
26
45
|
"license": "MIT",
|
|
27
46
|
"author": "Sohail Khan (https://me.jscrate.dev)",
|
|
@@ -31,6 +50,7 @@
|
|
|
31
50
|
"dist",
|
|
32
51
|
"schema",
|
|
33
52
|
"README.md",
|
|
53
|
+
"README.zh-CN.md",
|
|
34
54
|
"LICENSE"
|
|
35
55
|
],
|
|
36
56
|
"main": "./dist/index.cjs",
|
|
@@ -77,6 +97,16 @@
|
|
|
77
97
|
"default": "./dist/react.cjs"
|
|
78
98
|
}
|
|
79
99
|
},
|
|
100
|
+
"./pdf": {
|
|
101
|
+
"import": {
|
|
102
|
+
"types": "./dist/pdf.d.ts",
|
|
103
|
+
"default": "./dist/pdf.js"
|
|
104
|
+
},
|
|
105
|
+
"require": {
|
|
106
|
+
"types": "./dist/pdf.d.cts",
|
|
107
|
+
"default": "./dist/pdf.cjs"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
80
110
|
"./schema/document-v1.json": "./schema/document-v1.schema.json",
|
|
81
111
|
"./package.json": "./package.json"
|
|
82
112
|
},
|
|
@@ -95,7 +125,9 @@
|
|
|
95
125
|
},
|
|
96
126
|
"peerDependencies": {
|
|
97
127
|
"fabric": "^6.0.0 || ^7.0.0",
|
|
98
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
128
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
129
|
+
"jspdf": "^4.0.0",
|
|
130
|
+
"svg2pdf.js": "^2.7.0"
|
|
99
131
|
},
|
|
100
132
|
"publishConfig": {
|
|
101
133
|
"access": "public",
|
|
@@ -108,7 +140,7 @@
|
|
|
108
140
|
"type": "git",
|
|
109
141
|
"url": "git+https://github.com/re-sohail/fabricjs-document-engine.git"
|
|
110
142
|
},
|
|
111
|
-
"homepage": "https://
|
|
143
|
+
"homepage": "https://fabricjs-document-engine.jscrate.dev",
|
|
112
144
|
"bugs": {
|
|
113
145
|
"url": "https://github.com/re-sohail/fabricjs-document-engine/issues"
|
|
114
146
|
},
|
|
@@ -122,10 +154,13 @@
|
|
|
122
154
|
"ajv": "^8.20.0",
|
|
123
155
|
"fabric": "^7.4.0",
|
|
124
156
|
"fabric6": "npm:fabric@^6.9.1",
|
|
157
|
+
"jspdf": "^4.2.1",
|
|
158
|
+
"pdfjs-dist": "^6.3.289",
|
|
125
159
|
"playwright": "^1.63.0",
|
|
126
160
|
"publint": "^0.3.24",
|
|
127
161
|
"react": "^19.3.0",
|
|
128
162
|
"react-dom": "^19.3.0",
|
|
163
|
+
"svg2pdf.js": "^2.8.1",
|
|
129
164
|
"tsdown": "^0.23.0",
|
|
130
165
|
"typescript": "^5.9.3",
|
|
131
166
|
"vitest": "^5.0.2"
|
|
@@ -133,6 +168,12 @@
|
|
|
133
168
|
"peerDependenciesMeta": {
|
|
134
169
|
"react": {
|
|
135
170
|
"optional": true
|
|
171
|
+
},
|
|
172
|
+
"jspdf": {
|
|
173
|
+
"optional": true
|
|
174
|
+
},
|
|
175
|
+
"svg2pdf.js": {
|
|
176
|
+
"optional": true
|
|
136
177
|
}
|
|
137
178
|
}
|
|
138
179
|
}
|