@nmmty/lazycanvas 1.0.0-dev.7 → 1.0.0-dev.8
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.
|
@@ -132,6 +132,16 @@ export declare class Div extends BaseLayer<IDivProps> implements IDiv {
|
|
|
132
132
|
* @param {number} time - Current time in seconds
|
|
133
133
|
*/
|
|
134
134
|
updateState(time: number): void;
|
|
135
|
+
/**
|
|
136
|
+
* Renders a single layer or group of layers.
|
|
137
|
+
* @param {AnyLayer | Div} [layer] - The layer or group to render.
|
|
138
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
139
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
140
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
141
|
+
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
142
|
+
* @returns {Promise<SKRSContext2D>} The canvas rendering context after rendering.
|
|
143
|
+
*/
|
|
144
|
+
private renderLayer;
|
|
135
145
|
draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
136
146
|
/**
|
|
137
147
|
* Converts the group to a JSON representation.
|
|
@@ -120,6 +120,50 @@ class Div extends BaseLayer_1.BaseLayer {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Renders a single layer or group of layers.
|
|
125
|
+
* @param {AnyLayer | Div} [layer] - The layer or group to render.
|
|
126
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
127
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
128
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
129
|
+
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
130
|
+
* @returns {Promise<SKRSContext2D>} The canvas rendering context after rendering.
|
|
131
|
+
*/
|
|
132
|
+
async renderLayer(layer, ctx, canvas, manager, debug) {
|
|
133
|
+
if (debug)
|
|
134
|
+
LazyUtil_1.LazyLog.log("info", `Rendering ${layer.id}...\nData:`, layer.toJSON());
|
|
135
|
+
if (layer.visible) {
|
|
136
|
+
ctx.globalCompositeOperation = layer.props?.globalComposite || "source-over";
|
|
137
|
+
await layer.draw(ctx, canvas, manager, debug);
|
|
138
|
+
// Draw children if any (and not a Div, as Div handles its own children)
|
|
139
|
+
// Actually, if we want to support children on any layer, we should handle it here.
|
|
140
|
+
// But Div.draw already handles children.
|
|
141
|
+
// If we handle it here for Div, we get double rendering.
|
|
142
|
+
// So we skip Div.
|
|
143
|
+
const children = layer.children;
|
|
144
|
+
if (!(layer instanceof Div) && children && Array.isArray(children) && children.length > 0) {
|
|
145
|
+
ctx.save();
|
|
146
|
+
// Apply parent position offset
|
|
147
|
+
// LayoutManager sets position relative to parent.
|
|
148
|
+
// We need to translate context to parent's position so children are drawn relative to it.
|
|
149
|
+
// However, layer.draw() might have already drawn the layer at that position.
|
|
150
|
+
// And layer.draw() usually restores context.
|
|
151
|
+
// So we are back at parent's parent coordinate system.
|
|
152
|
+
// We need to translate to layer's position.
|
|
153
|
+
if (layer.props.position) {
|
|
154
|
+
const x = typeof layer.props.position.x === "number" ? layer.props.position.x : 0;
|
|
155
|
+
const y = typeof layer.props.position.y === "number" ? layer.props.position.y : 0;
|
|
156
|
+
ctx.translate(x, y);
|
|
157
|
+
}
|
|
158
|
+
for (const child of children) {
|
|
159
|
+
await this.renderLayer(child, ctx, canvas, manager, debug);
|
|
160
|
+
}
|
|
161
|
+
ctx.restore();
|
|
162
|
+
}
|
|
163
|
+
ctx.shadowColor = "transparent";
|
|
164
|
+
}
|
|
165
|
+
return ctx;
|
|
166
|
+
}
|
|
123
167
|
async draw(ctx, canvas, manager, debug) {
|
|
124
168
|
ctx.save();
|
|
125
169
|
// Apply position translation if available (from layout)
|
|
@@ -132,19 +176,7 @@ class Div extends BaseLayer_1.BaseLayer {
|
|
|
132
176
|
if (debug)
|
|
133
177
|
LazyUtil_1.LazyLog.log("info", `Rendering ${subLayer.id}...\nData:`, subLayer.toJSON());
|
|
134
178
|
if (subLayer.visible) {
|
|
135
|
-
|
|
136
|
-
await subLayer.draw(ctx, canvas, manager, debug);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
if ("globalComposite" in subLayer.props && subLayer.props.globalComposite) {
|
|
140
|
-
ctx.globalCompositeOperation = subLayer.props.globalComposite;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
ctx.globalCompositeOperation = "source-over";
|
|
144
|
-
}
|
|
145
|
-
await subLayer.draw(ctx, canvas, manager, debug);
|
|
146
|
-
ctx.shadowColor = "transparent";
|
|
147
|
-
}
|
|
179
|
+
await this.renderLayer(subLayer, ctx, canvas, manager, debug);
|
|
148
180
|
}
|
|
149
181
|
}
|
|
150
182
|
ctx.restore();
|
|
Binary file
|
package/package.json
CHANGED
package/static-jsx.png
ADDED
|
Binary file
|