@codehz/draw-call 0.1.1 → 0.1.2
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/{canvas-BYrCq8eS.d.mts → canvas.d.cts} +104 -34
- package/{canvas-CkpP3RNK.d.cts → canvas.d.mts} +104 -34
- package/index.cjs +69 -9
- package/index.d.cts +32 -2
- package/index.d.mts +32 -2
- package/index.mjs +60 -3
- package/node.cjs +6 -5
- package/node.d.cts +1 -1
- package/node.d.mts +1 -1
- package/node.mjs +3 -2
- package/package.json +1 -1
- package/render.cjs +1312 -0
- package/render.mjs +1288 -0
- package/engine-C88lMGbX.mjs +0 -606
- package/engine-OyKoV7Gn.cjs +0 -636
|
@@ -101,6 +101,13 @@ interface ComputedLayout {
|
|
|
101
101
|
contentWidth: number;
|
|
102
102
|
contentHeight: number;
|
|
103
103
|
}
|
|
104
|
+
interface LayoutNode {
|
|
105
|
+
element: Element;
|
|
106
|
+
layout: ComputedLayout;
|
|
107
|
+
children: LayoutNode[];
|
|
108
|
+
lines?: string[];
|
|
109
|
+
lineOffsets?: number[];
|
|
110
|
+
}
|
|
104
111
|
interface LayoutConstraints {
|
|
105
112
|
minWidth: number;
|
|
106
113
|
maxWidth: number;
|
|
@@ -109,7 +116,7 @@ interface LayoutConstraints {
|
|
|
109
116
|
}
|
|
110
117
|
//#endregion
|
|
111
118
|
//#region src/types/components.d.ts
|
|
112
|
-
type ElementType = "box" | "text" | "image" | "
|
|
119
|
+
type ElementType = "box" | "text" | "image" | "svg" | "stack";
|
|
113
120
|
interface ElementBase {
|
|
114
121
|
type: ElementType;
|
|
115
122
|
}
|
|
@@ -141,7 +148,7 @@ interface TextElement extends ElementBase, TextProps {
|
|
|
141
148
|
type: "text";
|
|
142
149
|
}
|
|
143
150
|
interface ImageProps extends LayoutProps {
|
|
144
|
-
src:
|
|
151
|
+
src: ImageBitmap | CanvasImageSource;
|
|
145
152
|
fit?: "contain" | "cover" | "fill" | "none" | "scale-down";
|
|
146
153
|
position?: {
|
|
147
154
|
x?: "left" | "center" | "right" | number;
|
|
@@ -154,50 +161,112 @@ interface ImageProps extends LayoutProps {
|
|
|
154
161
|
interface ImageElement extends ElementBase, ImageProps {
|
|
155
162
|
type: "image";
|
|
156
163
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
shape: ShapeType;
|
|
160
|
-
fill?: Color;
|
|
164
|
+
interface SvgStyleProps {
|
|
165
|
+
fill?: Color | "none";
|
|
161
166
|
stroke?: StrokeProps;
|
|
167
|
+
opacity?: number;
|
|
168
|
+
}
|
|
169
|
+
interface SvgTransformProps {
|
|
170
|
+
transform?: {
|
|
171
|
+
translate?: [number, number];
|
|
172
|
+
rotate?: number | [number, number, number];
|
|
173
|
+
scale?: number | [number, number];
|
|
174
|
+
skewX?: number;
|
|
175
|
+
skewY?: number;
|
|
176
|
+
matrix?: [number, number, number, number, number, number];
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
interface SvgRectChild extends SvgStyleProps, SvgTransformProps {
|
|
180
|
+
type: "rect";
|
|
181
|
+
x?: number;
|
|
182
|
+
y?: number;
|
|
183
|
+
width: number;
|
|
184
|
+
height: number;
|
|
185
|
+
rx?: number;
|
|
186
|
+
ry?: number;
|
|
187
|
+
}
|
|
188
|
+
interface SvgCircleChild extends SvgStyleProps, SvgTransformProps {
|
|
189
|
+
type: "circle";
|
|
190
|
+
cx: number;
|
|
191
|
+
cy: number;
|
|
192
|
+
r: number;
|
|
193
|
+
}
|
|
194
|
+
interface SvgEllipseChild extends SvgStyleProps, SvgTransformProps {
|
|
195
|
+
type: "ellipse";
|
|
196
|
+
cx: number;
|
|
197
|
+
cy: number;
|
|
198
|
+
rx: number;
|
|
199
|
+
ry: number;
|
|
200
|
+
}
|
|
201
|
+
interface SvgLineChild extends SvgStyleProps, SvgTransformProps {
|
|
202
|
+
type: "line";
|
|
203
|
+
x1: number;
|
|
204
|
+
y1: number;
|
|
205
|
+
x2: number;
|
|
206
|
+
y2: number;
|
|
207
|
+
}
|
|
208
|
+
interface SvgPolylineChild extends SvgStyleProps, SvgTransformProps {
|
|
209
|
+
type: "polyline";
|
|
210
|
+
points: [number, number][];
|
|
211
|
+
}
|
|
212
|
+
interface SvgPolygonChild extends SvgStyleProps, SvgTransformProps {
|
|
213
|
+
type: "polygon";
|
|
214
|
+
points: [number, number][];
|
|
215
|
+
}
|
|
216
|
+
interface SvgPathChild extends SvgStyleProps, SvgTransformProps {
|
|
217
|
+
type: "path";
|
|
218
|
+
d: string;
|
|
219
|
+
}
|
|
220
|
+
interface SvgTextChild extends SvgStyleProps, SvgTransformProps {
|
|
221
|
+
type: "text";
|
|
222
|
+
x?: number;
|
|
223
|
+
y?: number;
|
|
224
|
+
content: string;
|
|
225
|
+
font?: FontProps;
|
|
226
|
+
textAnchor?: "start" | "middle" | "end";
|
|
227
|
+
dominantBaseline?: "auto" | "middle" | "hanging";
|
|
228
|
+
}
|
|
229
|
+
interface SvgGroupChild extends SvgStyleProps, SvgTransformProps {
|
|
230
|
+
type: "g";
|
|
231
|
+
children: SvgChild[];
|
|
232
|
+
}
|
|
233
|
+
type SvgChild = SvgRectChild | SvgCircleChild | SvgEllipseChild | SvgLineChild | SvgPolylineChild | SvgPolygonChild | SvgPathChild | SvgTextChild | SvgGroupChild;
|
|
234
|
+
type SvgAlign = "none" | "xMinYMin" | "xMidYMin" | "xMaxYMin" | "xMinYMid" | "xMidYMid" | "xMaxYMid" | "xMinYMax" | "xMidYMax" | "xMaxYMax";
|
|
235
|
+
interface SvgProps extends LayoutProps {
|
|
236
|
+
viewBox?: {
|
|
237
|
+
x?: number;
|
|
238
|
+
y?: number;
|
|
239
|
+
width: number;
|
|
240
|
+
height: number;
|
|
241
|
+
};
|
|
242
|
+
preserveAspectRatio?: {
|
|
243
|
+
align?: SvgAlign;
|
|
244
|
+
meetOrSlice?: "meet" | "slice";
|
|
245
|
+
};
|
|
246
|
+
children: SvgChild[];
|
|
247
|
+
background?: Color;
|
|
162
248
|
shadow?: Shadow;
|
|
163
|
-
points?: [number, number][];
|
|
164
|
-
path?: string;
|
|
165
249
|
}
|
|
166
|
-
interface
|
|
167
|
-
type: "
|
|
250
|
+
interface SvgElement extends ElementBase, SvgProps {
|
|
251
|
+
type: "svg";
|
|
168
252
|
}
|
|
169
|
-
|
|
253
|
+
type StackAlign = "start" | "end" | "center";
|
|
254
|
+
interface StackProps extends LayoutProps {
|
|
170
255
|
children: Element[];
|
|
171
256
|
background?: Color;
|
|
172
257
|
border?: Border;
|
|
173
258
|
shadow?: Shadow;
|
|
174
259
|
opacity?: number;
|
|
175
260
|
clip?: boolean;
|
|
261
|
+
/** 水平对齐方式(默认 start) */
|
|
262
|
+
align?: StackAlign;
|
|
263
|
+
/** 垂直对齐方式(默认 start) */
|
|
264
|
+
justify?: StackAlign;
|
|
176
265
|
}
|
|
177
266
|
interface StackElement extends ElementBase, StackProps {
|
|
178
267
|
type: "stack";
|
|
179
268
|
}
|
|
180
|
-
type Element = BoxElement | TextElement | ImageElement |
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/layout/measure.d.ts
|
|
183
|
-
interface MeasureContext {
|
|
184
|
-
measureText(text: string, font: FontProps): {
|
|
185
|
-
width: number;
|
|
186
|
-
height: number;
|
|
187
|
-
offset: number;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
declare function createCanvasMeasureContext(ctx: CanvasRenderingContext2D): MeasureContext;
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/layout/engine.d.ts
|
|
193
|
-
interface LayoutNode {
|
|
194
|
-
element: Element;
|
|
195
|
-
layout: ComputedLayout;
|
|
196
|
-
children: LayoutNode[];
|
|
197
|
-
lines?: string[];
|
|
198
|
-
lineOffsets?: number[];
|
|
199
|
-
}
|
|
200
|
-
declare function computeLayout(element: Element, ctx: MeasureContext, constraints: LayoutConstraints, x?: number, y?: number): LayoutNode;
|
|
269
|
+
type Element = BoxElement | TextElement | ImageElement | SvgElement | StackElement;
|
|
201
270
|
//#endregion
|
|
202
271
|
//#region src/canvas.d.ts
|
|
203
272
|
interface CanvasOptions {
|
|
@@ -218,11 +287,12 @@ interface DrawCallCanvas {
|
|
|
218
287
|
readonly width: number;
|
|
219
288
|
readonly height: number;
|
|
220
289
|
readonly pixelRatio: number;
|
|
290
|
+
readonly canvas: HTMLCanvasElement;
|
|
221
291
|
render(element: Element): LayoutNode;
|
|
222
292
|
clear(): void;
|
|
223
293
|
getContext(): CanvasRenderingContext2D;
|
|
224
294
|
toDataURL(type?: string, quality?: number): string;
|
|
225
|
-
toBuffer(type?: "image/png" | "image/jpeg"):
|
|
295
|
+
toBuffer(type?: "image/png" | "image/jpeg"): Buffer;
|
|
226
296
|
}
|
|
227
297
|
/**
|
|
228
298
|
* 创建适用于浏览器环境的 Canvas
|
|
@@ -231,4 +301,4 @@ interface DrawCallCanvas {
|
|
|
231
301
|
*/
|
|
232
302
|
declare function createCanvas(options: CanvasOptions): DrawCallCanvas;
|
|
233
303
|
//#endregion
|
|
234
|
-
export {
|
|
304
|
+
export { AlignItems as A, Color as B, SvgProps as C, SvgTransformProps as D, SvgTextChild as E, LayoutConstraints as F, RadialGradientDescriptor as G, FontProps as H, LayoutNode as I, Spacing as J, Shadow as K, LayoutProps as L, ContainerLayoutProps as M, FlexDirection as N, TextElement as O, JustifyContent as P, Border as R, SvgPolylineChild as S, SvgStyleProps as T, GradientDescriptor as U, ColorStop as V, LinearGradientDescriptor as W, linearGradient as X, StrokeProps as Y, radialGradient as Z, SvgEllipseChild as _, BoxElement as a, SvgPathChild as b, ImageElement as c, StackElement as d, StackProps as f, SvgElement as g, SvgCircleChild as h, createCanvas as i, AlignSelf as j, TextProps as k, ImageProps as l, SvgChild as m, DrawCallCanvas as n, BoxProps as o, SvgAlign as p, Size as q, LayoutSize as r, Element as s, CanvasOptions as t, StackAlign as u, SvgGroupChild as v, SvgRectChild as w, SvgPolygonChild as x, SvgLineChild as y, Bounds as z };
|
|
@@ -101,6 +101,13 @@ interface ComputedLayout {
|
|
|
101
101
|
contentWidth: number;
|
|
102
102
|
contentHeight: number;
|
|
103
103
|
}
|
|
104
|
+
interface LayoutNode {
|
|
105
|
+
element: Element;
|
|
106
|
+
layout: ComputedLayout;
|
|
107
|
+
children: LayoutNode[];
|
|
108
|
+
lines?: string[];
|
|
109
|
+
lineOffsets?: number[];
|
|
110
|
+
}
|
|
104
111
|
interface LayoutConstraints {
|
|
105
112
|
minWidth: number;
|
|
106
113
|
maxWidth: number;
|
|
@@ -109,7 +116,7 @@ interface LayoutConstraints {
|
|
|
109
116
|
}
|
|
110
117
|
//#endregion
|
|
111
118
|
//#region src/types/components.d.ts
|
|
112
|
-
type ElementType = "box" | "text" | "image" | "
|
|
119
|
+
type ElementType = "box" | "text" | "image" | "svg" | "stack";
|
|
113
120
|
interface ElementBase {
|
|
114
121
|
type: ElementType;
|
|
115
122
|
}
|
|
@@ -141,7 +148,7 @@ interface TextElement extends ElementBase, TextProps {
|
|
|
141
148
|
type: "text";
|
|
142
149
|
}
|
|
143
150
|
interface ImageProps extends LayoutProps {
|
|
144
|
-
src:
|
|
151
|
+
src: ImageBitmap | CanvasImageSource;
|
|
145
152
|
fit?: "contain" | "cover" | "fill" | "none" | "scale-down";
|
|
146
153
|
position?: {
|
|
147
154
|
x?: "left" | "center" | "right" | number;
|
|
@@ -154,50 +161,112 @@ interface ImageProps extends LayoutProps {
|
|
|
154
161
|
interface ImageElement extends ElementBase, ImageProps {
|
|
155
162
|
type: "image";
|
|
156
163
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
shape: ShapeType;
|
|
160
|
-
fill?: Color;
|
|
164
|
+
interface SvgStyleProps {
|
|
165
|
+
fill?: Color | "none";
|
|
161
166
|
stroke?: StrokeProps;
|
|
167
|
+
opacity?: number;
|
|
168
|
+
}
|
|
169
|
+
interface SvgTransformProps {
|
|
170
|
+
transform?: {
|
|
171
|
+
translate?: [number, number];
|
|
172
|
+
rotate?: number | [number, number, number];
|
|
173
|
+
scale?: number | [number, number];
|
|
174
|
+
skewX?: number;
|
|
175
|
+
skewY?: number;
|
|
176
|
+
matrix?: [number, number, number, number, number, number];
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
interface SvgRectChild extends SvgStyleProps, SvgTransformProps {
|
|
180
|
+
type: "rect";
|
|
181
|
+
x?: number;
|
|
182
|
+
y?: number;
|
|
183
|
+
width: number;
|
|
184
|
+
height: number;
|
|
185
|
+
rx?: number;
|
|
186
|
+
ry?: number;
|
|
187
|
+
}
|
|
188
|
+
interface SvgCircleChild extends SvgStyleProps, SvgTransformProps {
|
|
189
|
+
type: "circle";
|
|
190
|
+
cx: number;
|
|
191
|
+
cy: number;
|
|
192
|
+
r: number;
|
|
193
|
+
}
|
|
194
|
+
interface SvgEllipseChild extends SvgStyleProps, SvgTransformProps {
|
|
195
|
+
type: "ellipse";
|
|
196
|
+
cx: number;
|
|
197
|
+
cy: number;
|
|
198
|
+
rx: number;
|
|
199
|
+
ry: number;
|
|
200
|
+
}
|
|
201
|
+
interface SvgLineChild extends SvgStyleProps, SvgTransformProps {
|
|
202
|
+
type: "line";
|
|
203
|
+
x1: number;
|
|
204
|
+
y1: number;
|
|
205
|
+
x2: number;
|
|
206
|
+
y2: number;
|
|
207
|
+
}
|
|
208
|
+
interface SvgPolylineChild extends SvgStyleProps, SvgTransformProps {
|
|
209
|
+
type: "polyline";
|
|
210
|
+
points: [number, number][];
|
|
211
|
+
}
|
|
212
|
+
interface SvgPolygonChild extends SvgStyleProps, SvgTransformProps {
|
|
213
|
+
type: "polygon";
|
|
214
|
+
points: [number, number][];
|
|
215
|
+
}
|
|
216
|
+
interface SvgPathChild extends SvgStyleProps, SvgTransformProps {
|
|
217
|
+
type: "path";
|
|
218
|
+
d: string;
|
|
219
|
+
}
|
|
220
|
+
interface SvgTextChild extends SvgStyleProps, SvgTransformProps {
|
|
221
|
+
type: "text";
|
|
222
|
+
x?: number;
|
|
223
|
+
y?: number;
|
|
224
|
+
content: string;
|
|
225
|
+
font?: FontProps;
|
|
226
|
+
textAnchor?: "start" | "middle" | "end";
|
|
227
|
+
dominantBaseline?: "auto" | "middle" | "hanging";
|
|
228
|
+
}
|
|
229
|
+
interface SvgGroupChild extends SvgStyleProps, SvgTransformProps {
|
|
230
|
+
type: "g";
|
|
231
|
+
children: SvgChild[];
|
|
232
|
+
}
|
|
233
|
+
type SvgChild = SvgRectChild | SvgCircleChild | SvgEllipseChild | SvgLineChild | SvgPolylineChild | SvgPolygonChild | SvgPathChild | SvgTextChild | SvgGroupChild;
|
|
234
|
+
type SvgAlign = "none" | "xMinYMin" | "xMidYMin" | "xMaxYMin" | "xMinYMid" | "xMidYMid" | "xMaxYMid" | "xMinYMax" | "xMidYMax" | "xMaxYMax";
|
|
235
|
+
interface SvgProps extends LayoutProps {
|
|
236
|
+
viewBox?: {
|
|
237
|
+
x?: number;
|
|
238
|
+
y?: number;
|
|
239
|
+
width: number;
|
|
240
|
+
height: number;
|
|
241
|
+
};
|
|
242
|
+
preserveAspectRatio?: {
|
|
243
|
+
align?: SvgAlign;
|
|
244
|
+
meetOrSlice?: "meet" | "slice";
|
|
245
|
+
};
|
|
246
|
+
children: SvgChild[];
|
|
247
|
+
background?: Color;
|
|
162
248
|
shadow?: Shadow;
|
|
163
|
-
points?: [number, number][];
|
|
164
|
-
path?: string;
|
|
165
249
|
}
|
|
166
|
-
interface
|
|
167
|
-
type: "
|
|
250
|
+
interface SvgElement extends ElementBase, SvgProps {
|
|
251
|
+
type: "svg";
|
|
168
252
|
}
|
|
169
|
-
|
|
253
|
+
type StackAlign = "start" | "end" | "center";
|
|
254
|
+
interface StackProps extends LayoutProps {
|
|
170
255
|
children: Element[];
|
|
171
256
|
background?: Color;
|
|
172
257
|
border?: Border;
|
|
173
258
|
shadow?: Shadow;
|
|
174
259
|
opacity?: number;
|
|
175
260
|
clip?: boolean;
|
|
261
|
+
/** 水平对齐方式(默认 start) */
|
|
262
|
+
align?: StackAlign;
|
|
263
|
+
/** 垂直对齐方式(默认 start) */
|
|
264
|
+
justify?: StackAlign;
|
|
176
265
|
}
|
|
177
266
|
interface StackElement extends ElementBase, StackProps {
|
|
178
267
|
type: "stack";
|
|
179
268
|
}
|
|
180
|
-
type Element = BoxElement | TextElement | ImageElement |
|
|
181
|
-
//#endregion
|
|
182
|
-
//#region src/layout/measure.d.ts
|
|
183
|
-
interface MeasureContext {
|
|
184
|
-
measureText(text: string, font: FontProps): {
|
|
185
|
-
width: number;
|
|
186
|
-
height: number;
|
|
187
|
-
offset: number;
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
declare function createCanvasMeasureContext(ctx: CanvasRenderingContext2D): MeasureContext;
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/layout/engine.d.ts
|
|
193
|
-
interface LayoutNode {
|
|
194
|
-
element: Element;
|
|
195
|
-
layout: ComputedLayout;
|
|
196
|
-
children: LayoutNode[];
|
|
197
|
-
lines?: string[];
|
|
198
|
-
lineOffsets?: number[];
|
|
199
|
-
}
|
|
200
|
-
declare function computeLayout(element: Element, ctx: MeasureContext, constraints: LayoutConstraints, x?: number, y?: number): LayoutNode;
|
|
269
|
+
type Element = BoxElement | TextElement | ImageElement | SvgElement | StackElement;
|
|
201
270
|
//#endregion
|
|
202
271
|
//#region src/canvas.d.ts
|
|
203
272
|
interface CanvasOptions {
|
|
@@ -218,11 +287,12 @@ interface DrawCallCanvas {
|
|
|
218
287
|
readonly width: number;
|
|
219
288
|
readonly height: number;
|
|
220
289
|
readonly pixelRatio: number;
|
|
290
|
+
readonly canvas: HTMLCanvasElement;
|
|
221
291
|
render(element: Element): LayoutNode;
|
|
222
292
|
clear(): void;
|
|
223
293
|
getContext(): CanvasRenderingContext2D;
|
|
224
294
|
toDataURL(type?: string, quality?: number): string;
|
|
225
|
-
toBuffer(type?: "image/png" | "image/jpeg"):
|
|
295
|
+
toBuffer(type?: "image/png" | "image/jpeg"): Buffer;
|
|
226
296
|
}
|
|
227
297
|
/**
|
|
228
298
|
* 创建适用于浏览器环境的 Canvas
|
|
@@ -231,4 +301,4 @@ interface DrawCallCanvas {
|
|
|
231
301
|
*/
|
|
232
302
|
declare function createCanvas(options: CanvasOptions): DrawCallCanvas;
|
|
233
303
|
//#endregion
|
|
234
|
-
export {
|
|
304
|
+
export { AlignItems as A, Color as B, SvgProps as C, SvgTransformProps as D, SvgTextChild as E, LayoutConstraints as F, RadialGradientDescriptor as G, FontProps as H, LayoutNode as I, Spacing as J, Shadow as K, LayoutProps as L, ContainerLayoutProps as M, FlexDirection as N, TextElement as O, JustifyContent as P, Border as R, SvgPolylineChild as S, SvgStyleProps as T, GradientDescriptor as U, ColorStop as V, LinearGradientDescriptor as W, linearGradient as X, StrokeProps as Y, radialGradient as Z, SvgEllipseChild as _, BoxElement as a, SvgPathChild as b, ImageElement as c, StackElement as d, StackProps as f, SvgElement as g, SvgCircleChild as h, createCanvas as i, AlignSelf as j, TextProps as k, ImageProps as l, SvgChild as m, DrawCallCanvas as n, BoxProps as o, SvgAlign as p, Size as q, LayoutSize as r, Element as s, CanvasOptions as t, StackAlign as u, SvgGroupChild as v, SvgRectChild as w, SvgPolygonChild as x, SvgLineChild as y, Bounds as z };
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_render = require('./render.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/canvas.ts
|
|
4
4
|
/**
|
|
@@ -19,19 +19,20 @@ function createCanvas(options) {
|
|
|
19
19
|
const ctx = canvas.getContext("2d");
|
|
20
20
|
if (!ctx) throw new Error("Failed to get 2d context");
|
|
21
21
|
if (pixelRatio !== 1) ctx.scale(pixelRatio, pixelRatio);
|
|
22
|
-
const measureCtx =
|
|
22
|
+
const measureCtx = require_render.createCanvasMeasureContext(ctx);
|
|
23
23
|
return {
|
|
24
24
|
width,
|
|
25
25
|
height,
|
|
26
26
|
pixelRatio,
|
|
27
|
+
canvas,
|
|
27
28
|
render(element) {
|
|
28
|
-
const layoutTree =
|
|
29
|
+
const layoutTree = require_render.computeLayout(element, measureCtx, {
|
|
29
30
|
minWidth: 0,
|
|
30
31
|
maxWidth: width,
|
|
31
32
|
minHeight: 0,
|
|
32
33
|
maxHeight: height
|
|
33
34
|
});
|
|
34
|
-
|
|
35
|
+
require_render.renderNode(ctx, layoutTree);
|
|
35
36
|
return layoutTree;
|
|
36
37
|
},
|
|
37
38
|
clear() {
|
|
@@ -44,7 +45,7 @@ function createCanvas(options) {
|
|
|
44
45
|
if ("toDataURL" in canvas && typeof canvas.toDataURL === "function") return canvas.toDataURL(type, quality);
|
|
45
46
|
throw new Error("toDataURL not supported");
|
|
46
47
|
},
|
|
47
|
-
|
|
48
|
+
toBuffer(type = "image/png") {
|
|
48
49
|
if ("toBuffer" in canvas && typeof canvas.toBuffer === "function") return canvas.toBuffer(type);
|
|
49
50
|
throw new Error("toBuffer not supported in this environment");
|
|
50
51
|
}
|
|
@@ -60,6 +61,15 @@ function Box(props) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/components/Image.ts
|
|
66
|
+
function Image(props) {
|
|
67
|
+
return {
|
|
68
|
+
type: "image",
|
|
69
|
+
...props
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
63
73
|
//#endregion
|
|
64
74
|
//#region src/components/Stack.ts
|
|
65
75
|
function Stack(props) {
|
|
@@ -69,6 +79,53 @@ function Stack(props) {
|
|
|
69
79
|
};
|
|
70
80
|
}
|
|
71
81
|
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/components/Svg.ts
|
|
84
|
+
function Svg(props) {
|
|
85
|
+
return {
|
|
86
|
+
type: "svg",
|
|
87
|
+
...props
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const svg = {
|
|
91
|
+
rect: (props) => ({
|
|
92
|
+
type: "rect",
|
|
93
|
+
...props
|
|
94
|
+
}),
|
|
95
|
+
circle: (props) => ({
|
|
96
|
+
type: "circle",
|
|
97
|
+
...props
|
|
98
|
+
}),
|
|
99
|
+
ellipse: (props) => ({
|
|
100
|
+
type: "ellipse",
|
|
101
|
+
...props
|
|
102
|
+
}),
|
|
103
|
+
line: (props) => ({
|
|
104
|
+
type: "line",
|
|
105
|
+
...props
|
|
106
|
+
}),
|
|
107
|
+
polyline: (props) => ({
|
|
108
|
+
type: "polyline",
|
|
109
|
+
...props
|
|
110
|
+
}),
|
|
111
|
+
polygon: (props) => ({
|
|
112
|
+
type: "polygon",
|
|
113
|
+
...props
|
|
114
|
+
}),
|
|
115
|
+
path: (props) => ({
|
|
116
|
+
type: "path",
|
|
117
|
+
...props
|
|
118
|
+
}),
|
|
119
|
+
text: (props) => ({
|
|
120
|
+
type: "text",
|
|
121
|
+
...props
|
|
122
|
+
}),
|
|
123
|
+
g: (props) => ({
|
|
124
|
+
type: "g",
|
|
125
|
+
...props
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
|
|
72
129
|
//#endregion
|
|
73
130
|
//#region src/components/Text.ts
|
|
74
131
|
function Text(props) {
|
|
@@ -80,10 +137,13 @@ function Text(props) {
|
|
|
80
137
|
|
|
81
138
|
//#endregion
|
|
82
139
|
exports.Box = Box;
|
|
140
|
+
exports.Image = Image;
|
|
83
141
|
exports.Stack = Stack;
|
|
142
|
+
exports.Svg = Svg;
|
|
84
143
|
exports.Text = Text;
|
|
85
|
-
exports.computeLayout =
|
|
144
|
+
exports.computeLayout = require_render.computeLayout;
|
|
86
145
|
exports.createCanvas = createCanvas;
|
|
87
|
-
exports.createCanvasMeasureContext =
|
|
88
|
-
exports.linearGradient =
|
|
89
|
-
exports.radialGradient =
|
|
146
|
+
exports.createCanvasMeasureContext = require_render.createCanvasMeasureContext;
|
|
147
|
+
exports.linearGradient = require_render.linearGradient;
|
|
148
|
+
exports.radialGradient = require_render.radialGradient;
|
|
149
|
+
exports.svg = svg;
|
package/index.d.cts
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as AlignItems, B as Color, C as SvgProps, D as SvgTransformProps, E as SvgTextChild, F as LayoutConstraints, G as RadialGradientDescriptor, H as FontProps, I as LayoutNode, J as Spacing, K as Shadow, L as LayoutProps, M as ContainerLayoutProps, N as FlexDirection, O as TextElement, P as JustifyContent, R as Border, S as SvgPolylineChild, T as SvgStyleProps, U as GradientDescriptor, V as ColorStop, W as LinearGradientDescriptor, X as linearGradient, Y as StrokeProps, Z as radialGradient, _ as SvgEllipseChild, a as BoxElement, b as SvgPathChild, c as ImageElement, d as StackElement, f as StackProps, g as SvgElement, h as SvgCircleChild, i as createCanvas, j as AlignSelf, k as TextProps, l as ImageProps, m as SvgChild, n as DrawCallCanvas, o as BoxProps, p as SvgAlign, q as Size, r as LayoutSize, s as Element, t as CanvasOptions, u as StackAlign, v as SvgGroupChild, w as SvgRectChild, x as SvgPolygonChild, y as SvgLineChild, z as Bounds } from "./canvas.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/components/Box.d.ts
|
|
4
4
|
declare function Box(props: BoxProps): BoxElement;
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region src/components/Image.d.ts
|
|
7
|
+
declare function Image(props: ImageProps): ImageElement;
|
|
8
|
+
//#endregion
|
|
6
9
|
//#region src/components/Stack.d.ts
|
|
7
10
|
declare function Stack(props: StackProps): StackElement;
|
|
8
11
|
//#endregion
|
|
12
|
+
//#region src/components/Svg.d.ts
|
|
13
|
+
declare function Svg(props: SvgProps): SvgElement;
|
|
14
|
+
declare const svg: {
|
|
15
|
+
rect: (props: Omit<SvgRectChild, "type">) => SvgRectChild;
|
|
16
|
+
circle: (props: Omit<SvgCircleChild, "type">) => SvgCircleChild;
|
|
17
|
+
ellipse: (props: Omit<SvgEllipseChild, "type">) => SvgEllipseChild;
|
|
18
|
+
line: (props: Omit<SvgLineChild, "type">) => SvgLineChild;
|
|
19
|
+
polyline: (props: Omit<SvgPolylineChild, "type">) => SvgPolylineChild;
|
|
20
|
+
polygon: (props: Omit<SvgPolygonChild, "type">) => SvgPolygonChild;
|
|
21
|
+
path: (props: Omit<SvgPathChild, "type">) => SvgPathChild;
|
|
22
|
+
text: (props: Omit<SvgTextChild, "type">) => SvgTextChild;
|
|
23
|
+
g: (props: Omit<SvgGroupChild, "type">) => SvgGroupChild;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
9
26
|
//#region src/components/Text.d.ts
|
|
10
27
|
declare function Text(props: TextProps): TextElement;
|
|
11
28
|
//#endregion
|
|
12
|
-
|
|
29
|
+
//#region src/layout/utils/measure.d.ts
|
|
30
|
+
interface MeasureContext {
|
|
31
|
+
measureText(text: string, font: FontProps): {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
offset: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare function createCanvasMeasureContext(ctx: CanvasRenderingContext2D): MeasureContext;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/layout/engine.d.ts
|
|
40
|
+
declare function computeLayout(element: Element, ctx: MeasureContext, constraints: LayoutConstraints, x?: number, y?: number): LayoutNode;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { type AlignItems, type AlignSelf, type Border, type Bounds, Box, type BoxElement, type BoxProps, type CanvasOptions, type Color, type ColorStop, type ContainerLayoutProps, type DrawCallCanvas, type Element, type FlexDirection, type FontProps, type GradientDescriptor, Image, type JustifyContent, type LayoutNode, type LayoutProps, type LayoutSize, type LinearGradientDescriptor, type MeasureContext, type RadialGradientDescriptor, type Shadow, type Size, type Spacing, Stack, type StackAlign, type StackElement, type StackProps, type StrokeProps, Svg, type SvgAlign, type SvgChild, type SvgCircleChild, type SvgElement, type SvgEllipseChild, type SvgGroupChild, type SvgLineChild, type SvgPathChild, type SvgPolygonChild, type SvgPolylineChild, type SvgProps, type SvgRectChild, type SvgStyleProps, type SvgTextChild, type SvgTransformProps, Text, type TextElement, type TextProps, computeLayout, createCanvas, createCanvasMeasureContext, linearGradient, radialGradient, svg };
|
package/index.d.mts
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as AlignItems, B as Color, C as SvgProps, D as SvgTransformProps, E as SvgTextChild, F as LayoutConstraints, G as RadialGradientDescriptor, H as FontProps, I as LayoutNode, J as Spacing, K as Shadow, L as LayoutProps, M as ContainerLayoutProps, N as FlexDirection, O as TextElement, P as JustifyContent, R as Border, S as SvgPolylineChild, T as SvgStyleProps, U as GradientDescriptor, V as ColorStop, W as LinearGradientDescriptor, X as linearGradient, Y as StrokeProps, Z as radialGradient, _ as SvgEllipseChild, a as BoxElement, b as SvgPathChild, c as ImageElement, d as StackElement, f as StackProps, g as SvgElement, h as SvgCircleChild, i as createCanvas, j as AlignSelf, k as TextProps, l as ImageProps, m as SvgChild, n as DrawCallCanvas, o as BoxProps, p as SvgAlign, q as Size, r as LayoutSize, s as Element, t as CanvasOptions, u as StackAlign, v as SvgGroupChild, w as SvgRectChild, x as SvgPolygonChild, y as SvgLineChild, z as Bounds } from "./canvas.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/components/Box.d.ts
|
|
4
4
|
declare function Box(props: BoxProps): BoxElement;
|
|
5
5
|
//#endregion
|
|
6
|
+
//#region src/components/Image.d.ts
|
|
7
|
+
declare function Image(props: ImageProps): ImageElement;
|
|
8
|
+
//#endregion
|
|
6
9
|
//#region src/components/Stack.d.ts
|
|
7
10
|
declare function Stack(props: StackProps): StackElement;
|
|
8
11
|
//#endregion
|
|
12
|
+
//#region src/components/Svg.d.ts
|
|
13
|
+
declare function Svg(props: SvgProps): SvgElement;
|
|
14
|
+
declare const svg: {
|
|
15
|
+
rect: (props: Omit<SvgRectChild, "type">) => SvgRectChild;
|
|
16
|
+
circle: (props: Omit<SvgCircleChild, "type">) => SvgCircleChild;
|
|
17
|
+
ellipse: (props: Omit<SvgEllipseChild, "type">) => SvgEllipseChild;
|
|
18
|
+
line: (props: Omit<SvgLineChild, "type">) => SvgLineChild;
|
|
19
|
+
polyline: (props: Omit<SvgPolylineChild, "type">) => SvgPolylineChild;
|
|
20
|
+
polygon: (props: Omit<SvgPolygonChild, "type">) => SvgPolygonChild;
|
|
21
|
+
path: (props: Omit<SvgPathChild, "type">) => SvgPathChild;
|
|
22
|
+
text: (props: Omit<SvgTextChild, "type">) => SvgTextChild;
|
|
23
|
+
g: (props: Omit<SvgGroupChild, "type">) => SvgGroupChild;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
9
26
|
//#region src/components/Text.d.ts
|
|
10
27
|
declare function Text(props: TextProps): TextElement;
|
|
11
28
|
//#endregion
|
|
12
|
-
|
|
29
|
+
//#region src/layout/utils/measure.d.ts
|
|
30
|
+
interface MeasureContext {
|
|
31
|
+
measureText(text: string, font: FontProps): {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
offset: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare function createCanvasMeasureContext(ctx: CanvasRenderingContext2D): MeasureContext;
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/layout/engine.d.ts
|
|
40
|
+
declare function computeLayout(element: Element, ctx: MeasureContext, constraints: LayoutConstraints, x?: number, y?: number): LayoutNode;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { type AlignItems, type AlignSelf, type Border, type Bounds, Box, type BoxElement, type BoxProps, type CanvasOptions, type Color, type ColorStop, type ContainerLayoutProps, type DrawCallCanvas, type Element, type FlexDirection, type FontProps, type GradientDescriptor, Image, type JustifyContent, type LayoutNode, type LayoutProps, type LayoutSize, type LinearGradientDescriptor, type MeasureContext, type RadialGradientDescriptor, type Shadow, type Size, type Spacing, Stack, type StackAlign, type StackElement, type StackProps, type StrokeProps, Svg, type SvgAlign, type SvgChild, type SvgCircleChild, type SvgElement, type SvgEllipseChild, type SvgGroupChild, type SvgLineChild, type SvgPathChild, type SvgPolygonChild, type SvgPolylineChild, type SvgProps, type SvgRectChild, type SvgStyleProps, type SvgTextChild, type SvgTransformProps, Text, type TextElement, type TextProps, computeLayout, createCanvas, createCanvasMeasureContext, linearGradient, radialGradient, svg };
|