@edv4h/usketch-plugin-export 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/dist/exporter.d.ts +19 -0
- package/dist/exporter.d.ts.map +1 -0
- package/dist/exporter.js +144 -0
- package/dist/exporter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +34 -0
- package/dist/plugin.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EdV4H
|
|
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.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ShapeData, ShapeRegistry } from "@edv4h/usketch-shared";
|
|
2
|
+
export interface ExportOptions {
|
|
3
|
+
format: "png" | "svg";
|
|
4
|
+
pixelRatio?: number;
|
|
5
|
+
background?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* シェイプデータからSVG文字列を構築してエクスポートする。
|
|
9
|
+
* SVGシェイプ → renderToStaticMarkup、HTMLシェイプ → Satori(PNG) / foreignObject(SVG)
|
|
10
|
+
*/
|
|
11
|
+
export declare function exportCanvas(shapes: Map<string, ShapeData>, shapeRegistry: ShapeRegistry, options: ExportOptions): Promise<Blob>;
|
|
12
|
+
/**
|
|
13
|
+
* ストアの全シェイプデータをJSON形式でエクスポートする。
|
|
14
|
+
* Yjsドキュメントの"shapes" Mapと同等のプレーンオブジェクト構造。
|
|
15
|
+
*/
|
|
16
|
+
export declare function exportJson(shapes: Map<string, ShapeData>): Blob;
|
|
17
|
+
/** Blobをファイルとしてダウンロードする */
|
|
18
|
+
export declare function downloadBlob(blob: Blob, filename: string): void;
|
|
19
|
+
//# sourceMappingURL=exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exporter.d.ts","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAgCtE,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE,KAAK,GAAG,KAAK,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AA4BD;;;GAGG;AACH,wBAAsB,YAAY,CACjC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAC9B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,IAAI,CAAC,CA+Ef;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAI,CAQ/D;AAED,2BAA2B;AAC3B,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAOxD"}
|
package/dist/exporter.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
+
import satori from "satori";
|
|
3
|
+
/** シェイプ全体のバウンディングボックスを計算 */
|
|
4
|
+
function computeBounds(shapes) {
|
|
5
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
6
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
7
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
8
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
9
|
+
for (const shape of shapes.values()) {
|
|
10
|
+
minX = Math.min(minX, shape.x);
|
|
11
|
+
minY = Math.min(minY, shape.y);
|
|
12
|
+
maxX = Math.max(maxX, shape.x + shape.width);
|
|
13
|
+
maxY = Math.max(maxY, shape.y + shape.height);
|
|
14
|
+
}
|
|
15
|
+
if (!Number.isFinite(minX)) {
|
|
16
|
+
return { minX: 0, minY: 0, width: 100, height: 100 };
|
|
17
|
+
}
|
|
18
|
+
const padding = 20;
|
|
19
|
+
return {
|
|
20
|
+
minX: minX - padding,
|
|
21
|
+
minY: minY - padding,
|
|
22
|
+
width: maxX - minX + padding * 2,
|
|
23
|
+
height: maxY - minY + padding * 2,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
let fontCache = null;
|
|
27
|
+
async function loadFont() {
|
|
28
|
+
if (fontCache)
|
|
29
|
+
return fontCache;
|
|
30
|
+
const res = await fetch("https://cdn.jsdelivr.net/fontsource/fonts/inter@5.1.1/latin-400-normal.ttf");
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
throw new Error(`Failed to load font: ${res.status}`);
|
|
33
|
+
}
|
|
34
|
+
fontCache = await res.arrayBuffer();
|
|
35
|
+
return fontCache;
|
|
36
|
+
}
|
|
37
|
+
/** HTMLシェイプをSatoriでSVG文字列に変換(foreignObject不使用、taint安全) */
|
|
38
|
+
async function htmlShapeToSvg(element, shape) {
|
|
39
|
+
const fontData = await loadFont();
|
|
40
|
+
const svg = await satori(element, {
|
|
41
|
+
width: shape.width,
|
|
42
|
+
height: shape.height,
|
|
43
|
+
fonts: [{ name: "Inter", data: fontData, weight: 400, style: "normal" }],
|
|
44
|
+
});
|
|
45
|
+
const inner = svg.replace(/<svg[^>]*>/, "").replace(/<\/svg>$/, "");
|
|
46
|
+
return `<g transform="translate(${shape.x}, ${shape.y})">${inner}</g>`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* シェイプデータからSVG文字列を構築してエクスポートする。
|
|
50
|
+
* SVGシェイプ → renderToStaticMarkup、HTMLシェイプ → Satori(PNG) / foreignObject(SVG)
|
|
51
|
+
*/
|
|
52
|
+
export async function exportCanvas(shapes, shapeRegistry, options) {
|
|
53
|
+
if (shapes.size === 0) {
|
|
54
|
+
throw new Error("No shapes to export");
|
|
55
|
+
}
|
|
56
|
+
const bounds = computeBounds(shapes);
|
|
57
|
+
const background = options.background ?? "#ffffff";
|
|
58
|
+
const useSatori = options.format === "png";
|
|
59
|
+
const shapeElements = [];
|
|
60
|
+
for (const shape of shapes.values()) {
|
|
61
|
+
const def = shapeRegistry.get(shape.type);
|
|
62
|
+
if (!def)
|
|
63
|
+
continue;
|
|
64
|
+
const element = def.render(shape);
|
|
65
|
+
if (def.renderTarget === "html") {
|
|
66
|
+
if (useSatori) {
|
|
67
|
+
const svgMarkup = await htmlShapeToSvg(element, shape);
|
|
68
|
+
shapeElements.push(svgMarkup);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const markup = renderToStaticMarkup(element);
|
|
72
|
+
shapeElements.push(`<foreignObject x="${shape.x}" y="${shape.y}" width="${shape.width}" height="${shape.height}">
|
|
73
|
+
<div xmlns="http://www.w3.org/1999/xhtml">${markup}</div>
|
|
74
|
+
</foreignObject>`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const markup = renderToStaticMarkup(element);
|
|
79
|
+
shapeElements.push(markup);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" width="${bounds.width}" height="${bounds.height}" viewBox="${bounds.minX} ${bounds.minY} ${bounds.width} ${bounds.height}">
|
|
83
|
+
<rect x="${bounds.minX}" y="${bounds.minY}" width="${bounds.width}" height="${bounds.height}" fill="${background}" />
|
|
84
|
+
${shapeElements.join("\n")}
|
|
85
|
+
</svg>`;
|
|
86
|
+
if (options.format === "svg") {
|
|
87
|
+
return new Blob([svgContent], { type: "image/svg+xml" });
|
|
88
|
+
}
|
|
89
|
+
// PNG: SVGをCanvasに描画してBlobに変換
|
|
90
|
+
const pixelRatio = options.pixelRatio ?? 2;
|
|
91
|
+
const img = new Image();
|
|
92
|
+
const svgBlob = new Blob([svgContent], { type: "image/svg+xml" });
|
|
93
|
+
const url = URL.createObjectURL(svgBlob);
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
img.onload = () => {
|
|
96
|
+
const canvas = document.createElement("canvas");
|
|
97
|
+
canvas.width = Math.ceil(bounds.width * pixelRatio);
|
|
98
|
+
canvas.height = Math.ceil(bounds.height * pixelRatio);
|
|
99
|
+
const ctx = canvas.getContext("2d");
|
|
100
|
+
if (!ctx) {
|
|
101
|
+
URL.revokeObjectURL(url);
|
|
102
|
+
reject(new Error("Failed to get canvas context"));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
ctx.scale(pixelRatio, pixelRatio);
|
|
106
|
+
ctx.drawImage(img, 0, 0, bounds.width, bounds.height);
|
|
107
|
+
URL.revokeObjectURL(url);
|
|
108
|
+
canvas.toBlob((blob) => {
|
|
109
|
+
if (blob)
|
|
110
|
+
resolve(blob);
|
|
111
|
+
else
|
|
112
|
+
reject(new Error("Failed to create PNG blob"));
|
|
113
|
+
}, "image/png", 1);
|
|
114
|
+
};
|
|
115
|
+
img.onerror = () => {
|
|
116
|
+
URL.revokeObjectURL(url);
|
|
117
|
+
reject(new Error("Failed to load SVG for PNG conversion"));
|
|
118
|
+
};
|
|
119
|
+
img.src = url;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* ストアの全シェイプデータをJSON形式でエクスポートする。
|
|
124
|
+
* Yjsドキュメントの"shapes" Mapと同等のプレーンオブジェクト構造。
|
|
125
|
+
*/
|
|
126
|
+
export function exportJson(shapes) {
|
|
127
|
+
const data = {};
|
|
128
|
+
for (const [id, shape] of shapes) {
|
|
129
|
+
// ShapeDataをプレーンオブジェクトに変換(循環参照回避)
|
|
130
|
+
data[id] = JSON.parse(JSON.stringify(shape));
|
|
131
|
+
}
|
|
132
|
+
const json = JSON.stringify(data, null, 2);
|
|
133
|
+
return new Blob([json], { type: "application/json" });
|
|
134
|
+
}
|
|
135
|
+
/** Blobをファイルとしてダウンロードする */
|
|
136
|
+
export function downloadBlob(blob, filename) {
|
|
137
|
+
const url = URL.createObjectURL(blob);
|
|
138
|
+
const a = document.createElement("a");
|
|
139
|
+
a.href = url;
|
|
140
|
+
a.download = filename;
|
|
141
|
+
a.click();
|
|
142
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exporter.js","sourceRoot":"","sources":["../src/exporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,4BAA4B;AAC5B,SAAS,aAAa,CAAC,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,CAAC,CAAC;IACtC,MAAM,CAAC,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC,CAAC,IAAI,GAAG,GAAG,CAAC;IACb,CAAC,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACtB,CAAC,CAAC,KAAK,EAAE,CAAC;IACV,UAAU,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAsB,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAG1E,eAAO,MAAM,YAAY,EAAE,aAsC1B,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { downloadBlob, exportCanvas, exportJson } from "./exporter.js";
|
|
2
|
+
export const exportPlugin = {
|
|
3
|
+
id: "usketch-plugin-export",
|
|
4
|
+
name: "エクスポート",
|
|
5
|
+
setup(ctx) {
|
|
6
|
+
const unsub1 = ctx.shortcuts.register("ctrl+shift+e", () => {
|
|
7
|
+
const shapes = new Map(ctx.store.getShapes());
|
|
8
|
+
exportCanvas(shapes, ctx.shapes, { format: "png" })
|
|
9
|
+
.then((blob) => downloadBlob(blob, "usketch-export.png"))
|
|
10
|
+
.catch((e) => console.error("PNG export failed:", e));
|
|
11
|
+
});
|
|
12
|
+
const unsub2 = ctx.shortcuts.register("ctrl+shift+alt+e", () => {
|
|
13
|
+
const shapes = new Map(ctx.store.getShapes());
|
|
14
|
+
exportCanvas(shapes, ctx.shapes, { format: "svg" })
|
|
15
|
+
.then((blob) => downloadBlob(blob, "usketch-export.svg"))
|
|
16
|
+
.catch((e) => console.error("SVG export failed:", e));
|
|
17
|
+
});
|
|
18
|
+
const unsub3 = ctx.shortcuts.register("ctrl+shift+j", () => {
|
|
19
|
+
const shapes = new Map(ctx.store.getShapes());
|
|
20
|
+
const blob = exportJson(shapes);
|
|
21
|
+
downloadBlob(blob, "usketch-export.json");
|
|
22
|
+
});
|
|
23
|
+
this._cleanup = () => {
|
|
24
|
+
unsub1();
|
|
25
|
+
unsub2();
|
|
26
|
+
unsub3();
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
teardown() {
|
|
30
|
+
const cleanup = this._cleanup;
|
|
31
|
+
cleanup?.();
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEvE,MAAM,CAAC,MAAM,YAAY,GAAkB;IAC1C,EAAE,EAAE,uBAAuB;IAC3B,IAAI,EAAE,QAAQ;IAEd,KAAK,CAAC,GAAkB;QACvB,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC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C,CAAC,CAAC;QAEF,IAA2C,CAAC,QAAQ,GAAG,GAAG,EAAE;YAC5D,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,CAAC;YACT,MAAM,EAAE,CAAC;QACV,CAAC,CAAC;IACH,CAAC;IAED,QAAQ;QACP,MAAM,OAAO,GAAI,IAA2C,CAAC,QAEjD,CAAC;QACb,OAAO,EAAE,EAAE,CAAC;IACb,CAAC;CACD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edv4h/usketch-plugin-export",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"satori": "0.26.0",
|
|
15
|
+
"@edv4h/usketch-core": "1.0.0",
|
|
16
|
+
"@edv4h/usketch-shared": "1.0.0"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": ">=19",
|
|
20
|
+
"react-dom": ">=19"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/react": "19.2.14",
|
|
24
|
+
"@types/react-dom": "19.2.3",
|
|
25
|
+
"typescript": "5.9.3",
|
|
26
|
+
"vitest": "3.2.4"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/EdV4H/usketch.git",
|
|
39
|
+
"directory": "plugins/usketch-plugin-export"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/EdV4H/usketch#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/EdV4H/usketch/issues"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "tsc -p tsconfig.json",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"test": "vitest run --passWithNoTests",
|
|
49
|
+
"clean": "rm -rf dist"
|
|
50
|
+
}
|
|
51
|
+
}
|