@newtil/drawing 0.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/LICENSE +9 -0
- package/README.md +21 -0
- package/dist/index.cjs +1235 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +1224 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
type Lang = "ko" | "en";
|
|
2
|
+
interface Messages {
|
|
3
|
+
title: string;
|
|
4
|
+
toolSelect: string;
|
|
5
|
+
toolPen: string;
|
|
6
|
+
toolHighlighter: string;
|
|
7
|
+
toolLine: string;
|
|
8
|
+
toolArrow: string;
|
|
9
|
+
toolArrow2: string;
|
|
10
|
+
toolRect: string;
|
|
11
|
+
toolEllipse: string;
|
|
12
|
+
toolText: string;
|
|
13
|
+
toolBadge: string;
|
|
14
|
+
color: string;
|
|
15
|
+
customColor: string;
|
|
16
|
+
strokeWidth: string;
|
|
17
|
+
fillNone: string;
|
|
18
|
+
fillTranslucent: string;
|
|
19
|
+
fillSolid: string;
|
|
20
|
+
dashed: string;
|
|
21
|
+
opacity: string;
|
|
22
|
+
undo: string;
|
|
23
|
+
redo: string;
|
|
24
|
+
delete: string;
|
|
25
|
+
duplicate: string;
|
|
26
|
+
bringForward: string;
|
|
27
|
+
sendBackward: string;
|
|
28
|
+
background: string;
|
|
29
|
+
clearBackground: string;
|
|
30
|
+
zoomFit: string;
|
|
31
|
+
done: string;
|
|
32
|
+
cancel: string;
|
|
33
|
+
saving: string;
|
|
34
|
+
textPrompt: string;
|
|
35
|
+
pasteHint: string;
|
|
36
|
+
discardConfirm: string;
|
|
37
|
+
exportFailed: string;
|
|
38
|
+
saveFailed: (reason: string) => string;
|
|
39
|
+
}
|
|
40
|
+
declare const ko: Messages;
|
|
41
|
+
declare const en: Messages;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 그림 데이터 — 편집기(@newtil/editor)가 곁파일로 저장하던 DrawingData v1 과 같은 모양이라 기존 곁파일이 그대로 열린다.
|
|
45
|
+
* 좌표는 항상 "판 크기(width×height)" 기준. 화면 확대/축소는 표시일 뿐이다.
|
|
46
|
+
*/
|
|
47
|
+
type ToolName = "select" | "pen" | "highlighter" | "line" | "arrow" | "arrow2" | "rect" | "ellipse" | "text" | "badge";
|
|
48
|
+
type Fill = "translucent" | "solid";
|
|
49
|
+
interface ShapeBase {
|
|
50
|
+
id: string;
|
|
51
|
+
color: string;
|
|
52
|
+
stroke: number;
|
|
53
|
+
/** 채우기 — 사각형·타원·배지 */
|
|
54
|
+
fill?: Fill | null;
|
|
55
|
+
/** 점선 */
|
|
56
|
+
dashed?: boolean;
|
|
57
|
+
/** 전체 투명도 0~1. 없으면 1 */
|
|
58
|
+
opacity?: number;
|
|
59
|
+
}
|
|
60
|
+
type Shape = (ShapeBase & {
|
|
61
|
+
type: "rect";
|
|
62
|
+
x1: number;
|
|
63
|
+
y1: number;
|
|
64
|
+
x2: number;
|
|
65
|
+
y2: number;
|
|
66
|
+
radius?: number;
|
|
67
|
+
}) | (ShapeBase & {
|
|
68
|
+
type: "ellipse";
|
|
69
|
+
x1: number;
|
|
70
|
+
y1: number;
|
|
71
|
+
x2: number;
|
|
72
|
+
y2: number;
|
|
73
|
+
}) | (ShapeBase & {
|
|
74
|
+
type: "line" | "arrow" | "arrow2";
|
|
75
|
+
x1: number;
|
|
76
|
+
y1: number;
|
|
77
|
+
x2: number;
|
|
78
|
+
y2: number;
|
|
79
|
+
}) | (ShapeBase & {
|
|
80
|
+
type: "pen" | "highlighter";
|
|
81
|
+
points: number[];
|
|
82
|
+
}) | (ShapeBase & {
|
|
83
|
+
type: "text";
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
text: string;
|
|
87
|
+
size: number;
|
|
88
|
+
}) | (ShapeBase & {
|
|
89
|
+
type: "badge";
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
n: number;
|
|
93
|
+
size: number;
|
|
94
|
+
});
|
|
95
|
+
interface Drawing {
|
|
96
|
+
version: 1;
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
/** 배경 캡처 — data URL. 없으면 흰 판 */
|
|
100
|
+
background: string | null;
|
|
101
|
+
shapes: Shape[];
|
|
102
|
+
}
|
|
103
|
+
type Box = {
|
|
104
|
+
x: number;
|
|
105
|
+
y: number;
|
|
106
|
+
w: number;
|
|
107
|
+
h: number;
|
|
108
|
+
};
|
|
109
|
+
declare function emptyDrawing(width?: number, height?: number): Drawing;
|
|
110
|
+
/** 도형의 바깥 상자 — 선택 표시·손잡이 자리. 글자는 대략(폰트 폭 0.6em 어림) */
|
|
111
|
+
declare function bounds(s: Shape): Box;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 그림판 팝업 — 캡처(배경) 위에 도형을 그리고 PNG + 데이터(재편집용)로 돌려준다.
|
|
115
|
+
*
|
|
116
|
+
* 자기 shadow root 안에 뜬다(스타일 격리). 좌표는 판 크기 기준이고 화면은 scale 로만 줄인다.
|
|
117
|
+
* 선택 도구: 클릭·Shift 클릭·러버밴드로 고르고, 끌어 옮기고, 손잡이(상자 8개 / 선 양 끝)로 고친다. 고른 채로 색·굵기·채우기·점선·투명도를 바꾸면 그 도형들이 바뀐다.
|
|
118
|
+
* 글자는 판 위에서 바로 친다(textarea 겹침), 두 번 클릭해 다시 고친다.
|
|
119
|
+
* 완료 = 굽기 + (있으면) 저장 훅까지 팝업 안에서. 실패하면 이유를 알리고 열어 둔다 — 조용히 다른 형태로 넘기지 않는다.
|
|
120
|
+
*/
|
|
121
|
+
interface OpenOptions {
|
|
122
|
+
/** 다시 고칠 그림. 없으면 빈 판 */
|
|
123
|
+
initial?: Drawing | null;
|
|
124
|
+
/** 시작 배경 — 캡처 파일(Blob) 또는 같은 출처 이미지 주소. initial 이 있으면 무시 */
|
|
125
|
+
background?: Blob | string | null;
|
|
126
|
+
/** 완료 때 부른다 — 저장하고 문서에 넣을 주소 등을 돌려준다. 던지면 팝업이 열린 채 이유를 보인다 */
|
|
127
|
+
save?: (png: Blob, data: Drawing) => Promise<string | void>;
|
|
128
|
+
/** 열 때 잠깐 보일 안내 */
|
|
129
|
+
notice?: string;
|
|
130
|
+
lang?: string;
|
|
131
|
+
messages?: Partial<Messages>;
|
|
132
|
+
/** 팝업을 붙일 자리. 기본 document.body */
|
|
133
|
+
mount?: HTMLElement;
|
|
134
|
+
}
|
|
135
|
+
interface OpenResult {
|
|
136
|
+
data: Drawing;
|
|
137
|
+
png: Blob; /** save 가 돌려준 값(주소 등) */
|
|
138
|
+
saved?: string;
|
|
139
|
+
}
|
|
140
|
+
declare class DrawingBoard {
|
|
141
|
+
private readonly opts;
|
|
142
|
+
private readonly host;
|
|
143
|
+
private readonly backdrop;
|
|
144
|
+
private readonly dialog;
|
|
145
|
+
private readonly stage;
|
|
146
|
+
private readonly canvasEl;
|
|
147
|
+
private readonly bgImg;
|
|
148
|
+
private readonly svg;
|
|
149
|
+
private readonly hintEl;
|
|
150
|
+
private readonly noticeEl;
|
|
151
|
+
private readonly statusEl;
|
|
152
|
+
private readonly toolBtns;
|
|
153
|
+
private readonly colorBtns;
|
|
154
|
+
private readonly fillBtns;
|
|
155
|
+
private colorInput;
|
|
156
|
+
private strokeRange;
|
|
157
|
+
private strokePreview;
|
|
158
|
+
private opacityRange;
|
|
159
|
+
private dashedBtn;
|
|
160
|
+
private undoBtn;
|
|
161
|
+
private redoBtn;
|
|
162
|
+
private deleteBtn;
|
|
163
|
+
private dupBtn;
|
|
164
|
+
private fwdBtn;
|
|
165
|
+
private backBtn;
|
|
166
|
+
private doneBtn;
|
|
167
|
+
private textEdit;
|
|
168
|
+
private data;
|
|
169
|
+
private tool;
|
|
170
|
+
private color;
|
|
171
|
+
private stroke;
|
|
172
|
+
private fill;
|
|
173
|
+
private dashed;
|
|
174
|
+
private opacity;
|
|
175
|
+
private scale;
|
|
176
|
+
private selected;
|
|
177
|
+
private drag;
|
|
178
|
+
/** 두 번 클릭 판정 — pointerdown 을 preventDefault 하면 브라우저가 click/dblclick 을 안 만들어 직접 잰다 */
|
|
179
|
+
private lastDown;
|
|
180
|
+
private past;
|
|
181
|
+
private future;
|
|
182
|
+
private dirty;
|
|
183
|
+
private saving;
|
|
184
|
+
private readonly m;
|
|
185
|
+
private done;
|
|
186
|
+
private readonly onResize;
|
|
187
|
+
constructor(opts: OpenOptions);
|
|
188
|
+
open(): Promise<OpenResult | null>;
|
|
189
|
+
private buildToolbar;
|
|
190
|
+
/** 툴바가 지금 값(또는 고른 도형의 값)을 비추게 */
|
|
191
|
+
private reflectStyle;
|
|
192
|
+
private fit;
|
|
193
|
+
private applyBackground;
|
|
194
|
+
private showNotice;
|
|
195
|
+
private setTool;
|
|
196
|
+
private selectedShapes;
|
|
197
|
+
/** 고른 도형들에 스타일을 적용 — 고른 게 없으면 다음 도형의 기본값만 바뀐다 */
|
|
198
|
+
private applyStyle;
|
|
199
|
+
private setColor;
|
|
200
|
+
private setStroke;
|
|
201
|
+
private setFill;
|
|
202
|
+
private setDashed;
|
|
203
|
+
private setOpacity;
|
|
204
|
+
private select;
|
|
205
|
+
private commit;
|
|
206
|
+
private undo;
|
|
207
|
+
private redo;
|
|
208
|
+
private deleteSelected;
|
|
209
|
+
private duplicate;
|
|
210
|
+
/** 앞으로/뒤로 — 고른 도형들의 그리는 순서를 한 칸 옮긴다 */
|
|
211
|
+
private reorder;
|
|
212
|
+
private nudge;
|
|
213
|
+
private updateButtons;
|
|
214
|
+
private pickBackground;
|
|
215
|
+
private setBackground;
|
|
216
|
+
private onPaste;
|
|
217
|
+
private toPoint;
|
|
218
|
+
private shapeAt;
|
|
219
|
+
private handleAt;
|
|
220
|
+
private onPointerDown;
|
|
221
|
+
private onPointerMove;
|
|
222
|
+
private onPointerUp;
|
|
223
|
+
private onKeyDown;
|
|
224
|
+
private startTextEdit;
|
|
225
|
+
private commitTextEdit;
|
|
226
|
+
private render;
|
|
227
|
+
private renderShape;
|
|
228
|
+
/** 고른 도형의 점선 상자 + 손잡이(하나만 골랐을 때: 상자 8개 / 선 양 끝) */
|
|
229
|
+
private renderSelection;
|
|
230
|
+
private cancel;
|
|
231
|
+
private finish;
|
|
232
|
+
private close;
|
|
233
|
+
}
|
|
234
|
+
/** 그림판을 연다 — 완료면 데이터·PNG(·저장 결과), 취소면 null */
|
|
235
|
+
declare function openDrawing(opts?: OpenOptions): Promise<OpenResult | null>;
|
|
236
|
+
|
|
237
|
+
/** 이미지 로드 — data URL 또는 같은 출처 주소. 교차 출처는 캔버스에 못 굽는다(tainted) */
|
|
238
|
+
declare function loadImage(src: string): Promise<HTMLImageElement>;
|
|
239
|
+
declare function blobToDataURL(blob: Blob): Promise<string>;
|
|
240
|
+
/** 그림 전체를 PNG 로 — 배경 + 도형. 배경이 없으면 흰 판 */
|
|
241
|
+
declare function renderToPng(data: Drawing): Promise<Blob>;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @newtil/drawing — 캡처 위에 화살표·상자·글자를 그리는 그림판. 프레임워크 없음, 순수 DOM, 자기 shadow root 에 뜬다.
|
|
245
|
+
*
|
|
246
|
+
* import { openDrawing } from "@newtil/drawing";
|
|
247
|
+
* const r = await openDrawing({ background: file }); // 새로 그리기 → { data, png } | null
|
|
248
|
+
* const r2 = await openDrawing({ initial: r.data }); // 다시 고치기(도형 살아 있음)
|
|
249
|
+
*
|
|
250
|
+
* data(Drawing)는 자기 완결적(배경도 data URL)이라 어디든 저장해 두면 다시 열린다. png 는 독자용 결과물.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
declare const VERSION = "0.1.0";
|
|
254
|
+
|
|
255
|
+
export { type Drawing, DrawingBoard, type Fill, type Lang, type Messages, type OpenOptions, type OpenResult, type Shape, type ToolName, VERSION, blobToDataURL, bounds, emptyDrawing, loadImage, en as messagesEn, ko as messagesKo, openDrawing, renderToPng };
|