@solidtv/renderer 1.0.0 → 1.0.1
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/dist/src/core/CoreNode.js +13 -11
- package/dist/src/core/CoreNode.js.map +1 -1
- package/dist/src/core/CoreTextNode.js +2 -1
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/lib/utils.d.ts +2 -2
- package/dist/src/core/lib/utils.js +21 -21
- package/dist/src/core/lib/utils.js.map +1 -1
- package/dist/src/core/renderers/CoreRenderer.d.ts +0 -30
- package/dist/src/core/renderers/CoreRenderer.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +1 -1
- package/dist/src/core/renderers/canvas/CanvasRenderer.js +22 -38
- package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
- package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +1 -2
- package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -1
- package/dist/src/core/renderers/webgl/SdfRenderOp.d.ts +5 -5
- package/dist/src/core/renderers/webgl/SdfRenderOp.js +8 -8
- package/dist/src/core/renderers/webgl/SdfRenderOp.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +3 -4
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
- package/dist/src/core/shaders/canvas/Border.js +8 -11
- package/dist/src/core/shaders/canvas/Border.js.map +1 -1
- package/dist/src/core/shaders/canvas/HolePunch.js +2 -1
- package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -1
- package/dist/src/core/shaders/canvas/LinearGradient.js +23 -4
- package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -1
- package/dist/src/core/shaders/canvas/RadialGradient.js +7 -5
- package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -1
- package/dist/src/core/shaders/canvas/Rounded.js +2 -2
- package/dist/src/core/shaders/canvas/Rounded.js.map +1 -1
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js +2 -2
- package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -1
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +5 -4
- package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -1
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js +5 -4
- package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -1
- package/dist/src/core/shaders/canvas/Shadow.js +4 -2
- package/dist/src/core/shaders/canvas/Shadow.js.map +1 -1
- package/dist/src/core/shaders/canvas/utils/render.js +0 -15
- package/dist/src/core/shaders/canvas/utils/render.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/CoreNode.test.ts +2 -2
- package/src/core/CoreNode.ts +13 -11
- package/src/core/CoreTextNode.ts +3 -1
- package/src/core/lib/utils.ts +23 -25
- package/src/core/renderers/CoreRenderer.ts +0 -31
- package/src/core/renderers/canvas/CanvasRenderer.ts +24 -42
- package/src/core/renderers/canvas/CanvasShaderNode.ts +1 -2
- package/src/core/renderers/webgl/SdfRenderOp.ts +7 -7
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +3 -6
- package/src/core/shaders/canvas/Border.ts +11 -15
- package/src/core/shaders/canvas/HolePunch.ts +2 -1
- package/src/core/shaders/canvas/LinearGradient.ts +26 -7
- package/src/core/shaders/canvas/RadialGradient.ts +7 -10
- package/src/core/shaders/canvas/Rounded.ts +5 -5
- package/src/core/shaders/canvas/RoundedWithBorder.ts +5 -5
- package/src/core/shaders/canvas/RoundedWithBorderAndShadow.ts +9 -8
- package/src/core/shaders/canvas/RoundedWithShadow.ts +6 -5
- package/src/core/shaders/canvas/Shadow.ts +7 -5
- package/src/core/shaders/canvas/utils/render.ts +0 -18
|
@@ -2,11 +2,7 @@ import type { CoreNode } from '../../CoreNode.js';
|
|
|
2
2
|
import { SubTexture } from '../../textures/SubTexture.js';
|
|
3
3
|
import { TextureType, type Texture } from '../../textures/Texture.js';
|
|
4
4
|
import type { CoreContextTexture } from '../CoreContextTexture.js';
|
|
5
|
-
import {
|
|
6
|
-
CoreRenderer,
|
|
7
|
-
type CoreRendererOptions,
|
|
8
|
-
type QuadOptions,
|
|
9
|
-
} from '../CoreRenderer.js';
|
|
5
|
+
import { CoreRenderer, type CoreRendererOptions } from '../CoreRenderer.js';
|
|
10
6
|
import { CanvasTexture } from './CanvasTexture.js';
|
|
11
7
|
import { parseColor } from '../../lib/colorParser.js';
|
|
12
8
|
import { CanvasShaderNode, type CanvasShaderType } from './CanvasShaderNode.js';
|
|
@@ -52,7 +48,7 @@ export class CanvasRenderer extends CoreRenderer {
|
|
|
52
48
|
const ctx = this.context;
|
|
53
49
|
const { tx, ty, ta, tb, tc, td } = node.globalTransform!;
|
|
54
50
|
const clippingRect = node.clippingRect;
|
|
55
|
-
let texture = node.
|
|
51
|
+
let texture = (node.props.texture || this.stage.defaultTexture) as Texture;
|
|
56
52
|
// The Canvas2D renderer only supports image textures, no textures are used for color blocks
|
|
57
53
|
if (texture !== null) {
|
|
58
54
|
const textureType = texture.type;
|
|
@@ -67,7 +63,7 @@ export class CanvasRenderer extends CoreRenderer {
|
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
const hasTransform = ta !== 1;
|
|
70
|
-
const hasClipping = clippingRect.
|
|
66
|
+
const hasClipping = clippingRect.w !== 0 && clippingRect.h !== 0;
|
|
71
67
|
const shader = node.props.shader;
|
|
72
68
|
const hasShader = shader !== null;
|
|
73
69
|
|
|
@@ -82,8 +78,8 @@ export class CanvasRenderer extends CoreRenderer {
|
|
|
82
78
|
|
|
83
79
|
if (hasClipping === true) {
|
|
84
80
|
const path = new Path2D();
|
|
85
|
-
const { x, y,
|
|
86
|
-
path.rect(x, y,
|
|
81
|
+
const { x, y, w, h } = clippingRect;
|
|
82
|
+
path.rect(x, y, w, h);
|
|
87
83
|
ctx.clip(path);
|
|
88
84
|
}
|
|
89
85
|
|
|
@@ -104,40 +100,13 @@ export class CanvasRenderer extends CoreRenderer {
|
|
|
104
100
|
|
|
105
101
|
if (hasShader === true) {
|
|
106
102
|
let renderContext: (() => void) | null = () => {
|
|
107
|
-
this.renderContext(node);
|
|
108
|
-
};
|
|
109
|
-
const quad: QuadOptions = {
|
|
110
|
-
width: node.props.w,
|
|
111
|
-
height: node.props.h,
|
|
112
|
-
colorTl: node.premultipliedColorTl,
|
|
113
|
-
colorTr: node.premultipliedColorTr,
|
|
114
|
-
colorBl: node.premultipliedColorBl,
|
|
115
|
-
colorBr: node.premultipliedColorBr,
|
|
116
|
-
texture: texture,
|
|
117
|
-
textureOptions: node.props.textureOptions,
|
|
118
|
-
textureCoords: node.renderTextureCoords,
|
|
119
|
-
zIndex: node.zIndex, // zIndex usage?
|
|
120
|
-
shader: shader,
|
|
121
|
-
alpha: node.worldAlpha,
|
|
122
|
-
clippingRect: clippingRect,
|
|
123
|
-
tx,
|
|
124
|
-
ty,
|
|
125
|
-
ta,
|
|
126
|
-
tb,
|
|
127
|
-
tc,
|
|
128
|
-
td,
|
|
129
|
-
renderCoords: node.renderCoords,
|
|
130
|
-
rtt: node.props.rtt,
|
|
131
|
-
parentHasRenderTexture: node.parentHasRenderTexture,
|
|
132
|
-
framebufferDimensions: node.parentHasRenderTexture
|
|
133
|
-
? node.parentFramebufferDimensions
|
|
134
|
-
: null,
|
|
103
|
+
this.renderContext(node, texture);
|
|
135
104
|
};
|
|
136
105
|
|
|
137
|
-
(shader as CanvasShaderNode).render(ctx,
|
|
106
|
+
(shader as CanvasShaderNode).render(ctx, node, renderContext);
|
|
138
107
|
renderContext = null;
|
|
139
108
|
} else {
|
|
140
|
-
this.renderContext(node);
|
|
109
|
+
this.renderContext(node, texture);
|
|
141
110
|
}
|
|
142
111
|
|
|
143
112
|
if (saveAndRestore) {
|
|
@@ -145,9 +114,8 @@ export class CanvasRenderer extends CoreRenderer {
|
|
|
145
114
|
}
|
|
146
115
|
}
|
|
147
116
|
|
|
148
|
-
renderContext(node: CoreNode) {
|
|
117
|
+
renderContext(node: CoreNode, texture: Texture) {
|
|
149
118
|
const color = node.premultipliedColorTl;
|
|
150
|
-
const texture = node.renderTexture!;
|
|
151
119
|
const textureType = texture.type;
|
|
152
120
|
const tx = node.globalTransform!.tx;
|
|
153
121
|
const ty = node.globalTransform!.ty;
|
|
@@ -201,8 +169,22 @@ export class CanvasRenderer extends CoreRenderer {
|
|
|
201
169
|
endY = ty;
|
|
202
170
|
endColor = node.premultipliedColorTr;
|
|
203
171
|
}
|
|
172
|
+
|
|
173
|
+
let startColor = color;
|
|
174
|
+
const startAlpha = (startColor >>> 24) & 0xff;
|
|
175
|
+
const endAlpha = (endColor >>> 24) & 0xff;
|
|
176
|
+
|
|
177
|
+
// if one of the colors has 0 alpha, we want to match the RGB channels
|
|
178
|
+
// to the other color to prevent white bleed during zero alpha interpolation.
|
|
179
|
+
if (startAlpha === 0 && endAlpha > 0) {
|
|
180
|
+
startColor =
|
|
181
|
+
((startColor & 0xff000000) | (endColor & 0x00ffffff)) >>> 0;
|
|
182
|
+
} else if (endAlpha === 0 && startAlpha > 0) {
|
|
183
|
+
endColor = ((endColor & 0xff000000) | (startColor & 0x00ffffff)) >>> 0;
|
|
184
|
+
}
|
|
185
|
+
|
|
204
186
|
const gradient = this.context.createLinearGradient(tx, ty, endX, endY);
|
|
205
|
-
gradient.addColorStop(0, normalizeCanvasColor(
|
|
187
|
+
gradient.addColorStop(0, normalizeCanvasColor(startColor));
|
|
206
188
|
gradient.addColorStop(1, normalizeCanvasColor(endColor));
|
|
207
189
|
this.context.fillStyle = gradient;
|
|
208
190
|
this.context.fillRect(tx, ty, width, height);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { CoreNode } from '../../CoreNode.js';
|
|
2
2
|
import { normalizeCanvasColor } from '../../lib/colorCache.js';
|
|
3
3
|
import type { Stage } from '../../Stage.js';
|
|
4
|
-
import type { QuadOptions } from '../CoreRenderer.js';
|
|
5
4
|
import { CoreShaderNode, type CoreShaderType } from '../CoreShaderNode.js';
|
|
6
5
|
|
|
7
6
|
export type CanvasShaderType<
|
|
@@ -11,7 +10,7 @@ export type CanvasShaderType<
|
|
|
11
10
|
render: (
|
|
12
11
|
this: CanvasShaderNode<T, C>,
|
|
13
12
|
ctx: CanvasRenderingContext2D,
|
|
14
|
-
|
|
13
|
+
node: CoreNode,
|
|
15
14
|
renderContext: () => void,
|
|
16
15
|
) => void;
|
|
17
16
|
update?: (this: CanvasShaderNode<T, C>, node: CoreNode) => void;
|
|
@@ -33,10 +33,10 @@ export class SdfRenderOp extends CoreRenderOp {
|
|
|
33
33
|
readonly renderer: WebGlRenderer,
|
|
34
34
|
readonly shader: WebGlShaderNode,
|
|
35
35
|
readonly quadBufferCollection: BufferCollection,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
readonly
|
|
39
|
-
readonly
|
|
36
|
+
readonly worldAlpha: number,
|
|
37
|
+
readonly clippingRect: RectWithValid,
|
|
38
|
+
readonly w: number,
|
|
39
|
+
readonly h: number,
|
|
40
40
|
readonly rtt: boolean,
|
|
41
41
|
public parentHasRenderTexture: boolean,
|
|
42
42
|
public framebufferDimensions: Dimensions | null,
|
|
@@ -70,8 +70,8 @@ export class SdfRenderOp extends CoreRenderOp {
|
|
|
70
70
|
const pixelRatio =
|
|
71
71
|
USE_RTT && this.parentHasRenderTexture ? 1 : stage.pixelRatio;
|
|
72
72
|
const clipX = Math.round(this.clippingRect.x * pixelRatio);
|
|
73
|
-
const clipWidth = Math.round(this.clippingRect.
|
|
74
|
-
const clipHeight = Math.round(this.clippingRect.
|
|
73
|
+
const clipWidth = Math.round(this.clippingRect.w * pixelRatio);
|
|
74
|
+
const clipHeight = Math.round(this.clippingRect.h * pixelRatio);
|
|
75
75
|
let clipY = Math.round(
|
|
76
76
|
options.canvas.height - clipHeight - this.clippingRect.y * pixelRatio,
|
|
77
77
|
);
|
|
@@ -79,7 +79,7 @@ export class SdfRenderOp extends CoreRenderOp {
|
|
|
79
79
|
// to be relative to the parent's framebuffer
|
|
80
80
|
if (USE_RTT && this.parentHasRenderTexture) {
|
|
81
81
|
clipY = this.framebufferDimensions
|
|
82
|
-
? this.framebufferDimensions.h - this.
|
|
82
|
+
? this.framebufferDimensions.h - this.h
|
|
83
83
|
: 0;
|
|
84
84
|
}
|
|
85
85
|
|
|
@@ -134,7 +134,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
134
134
|
return this.lifecycle.canBatch(node, currentRenderOp);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
const { time, worldAlpha,
|
|
137
|
+
const { time, worldAlpha, w, h } = node;
|
|
138
138
|
|
|
139
139
|
if (this.useTimeValue === true) {
|
|
140
140
|
if (time !== currentRenderOp.time) {
|
|
@@ -149,10 +149,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
if (this.useSystemDimensions === true) {
|
|
152
|
-
if (
|
|
153
|
-
width !== currentRenderOp.width ||
|
|
154
|
-
height !== currentRenderOp.height
|
|
155
|
-
) {
|
|
152
|
+
if (w !== currentRenderOp.w || h !== currentRenderOp.h) {
|
|
156
153
|
return false;
|
|
157
154
|
}
|
|
158
155
|
}
|
|
@@ -235,7 +232,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
|
|
|
235
232
|
}
|
|
236
233
|
|
|
237
234
|
if (this.useSystemDimensions === true) {
|
|
238
|
-
this.glw.uniform2f('u_dimensions', renderOp.
|
|
235
|
+
this.glw.uniform2f('u_dimensions', renderOp.w, renderOp.h);
|
|
239
236
|
}
|
|
240
237
|
|
|
241
238
|
const shader = renderOp.shader as WebGlShaderNode;
|
|
@@ -72,39 +72,35 @@ export const Border: CanvasShaderType<BorderProps, ComputedBorderValues> = {
|
|
|
72
72
|
this.computed.innerW = outerW - l - r;
|
|
73
73
|
this.computed.innerH = outerH - t - b;
|
|
74
74
|
},
|
|
75
|
-
render(ctx,
|
|
75
|
+
render(ctx, node, renderContext) {
|
|
76
76
|
renderContext();
|
|
77
77
|
const computed = this.computed as ComputedBorderValues;
|
|
78
|
+
const { tx, ty } = node.globalTransform!;
|
|
79
|
+
const { w, h } = node.props;
|
|
78
80
|
ctx.strokeStyle = computed.borderColor!;
|
|
79
81
|
if (computed.borderAsym === false && this.props!.w[0] > 0) {
|
|
80
82
|
ctx.lineWidth = this.props!.w[0];
|
|
81
83
|
ctx.beginPath();
|
|
82
84
|
ctx.strokeRect(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
tx + computed.outerX,
|
|
86
|
+
ty + computed.outerY,
|
|
87
|
+
w + computed.outerW,
|
|
88
|
+
h + computed.outerH,
|
|
87
89
|
);
|
|
88
90
|
return;
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
// Pre-calculate common values
|
|
92
|
-
const tx = quad.tx;
|
|
93
|
-
const ty = quad.ty;
|
|
94
|
-
const width = quad.width;
|
|
95
|
-
const height = quad.height;
|
|
96
|
-
|
|
97
93
|
// Calculate outer rectangle (including border)
|
|
98
94
|
const outerX = tx + computed.outerX;
|
|
99
95
|
const outerY = ty + computed.outerY;
|
|
100
|
-
const outerW =
|
|
101
|
-
const outerH =
|
|
96
|
+
const outerW = w + computed.outerW;
|
|
97
|
+
const outerH = h + computed.outerH;
|
|
102
98
|
|
|
103
99
|
// Calculate inner rectangle (excluding border)
|
|
104
100
|
const innerX = tx + computed.innerX;
|
|
105
101
|
const innerY = ty + computed.innerY;
|
|
106
|
-
const innerW =
|
|
107
|
-
const innerH =
|
|
102
|
+
const innerW = w + computed.innerW;
|
|
103
|
+
const innerH = h + computed.innerH;
|
|
108
104
|
|
|
109
105
|
// Use clip to subtract inner from outer
|
|
110
106
|
ctx.save();
|
|
@@ -27,8 +27,9 @@ export const HolePunch: CanvasShaderType<
|
|
|
27
27
|
ctx.save();
|
|
28
28
|
renderContext();
|
|
29
29
|
const { x, y, w, h } = this.props!;
|
|
30
|
+
const gt = quad.globalTransform!;
|
|
30
31
|
ctx.beginPath();
|
|
31
|
-
roundRect(ctx,
|
|
32
|
+
roundRect(ctx, gt.tx + x, gt.ty + y, w, h, this.computed.radius!);
|
|
32
33
|
ctx.closePath();
|
|
33
34
|
ctx.fillStyle = 'black';
|
|
34
35
|
ctx.globalCompositeOperation = 'destination-out';
|
|
@@ -31,17 +31,36 @@ export const LinearGradient: CanvasShaderType<
|
|
|
31
31
|
y0: line * Math.sin(angle) + nHeight * 0.5,
|
|
32
32
|
x1: line * Math.cos(angle + Math.PI) + nWidth * 0.5,
|
|
33
33
|
y1: line * Math.sin(angle + Math.PI) + nHeight * 0.5,
|
|
34
|
-
colors: this.props!.colors.map((value) =>
|
|
34
|
+
colors: this.props!.colors.map((value, i, arr) => {
|
|
35
|
+
const alpha = (value >>> 24) & 0xff;
|
|
36
|
+
if (alpha === 0) {
|
|
37
|
+
let nearestRGB = value & 0x00ffffff;
|
|
38
|
+
for (let step = 1; step < arr.length; step++) {
|
|
39
|
+
if (i - step >= 0 && ((arr[i - step]! >>> 24) & 0xff) > 0) {
|
|
40
|
+
nearestRGB = arr[i - step]! & 0x00ffffff;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
if (i + step < arr.length && ((arr[i + step]! >>> 24) & 0xff) > 0) {
|
|
44
|
+
nearestRGB = arr[i + step]! & 0x00ffffff;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
value = (value & 0xff000000) | nearestRGB;
|
|
49
|
+
}
|
|
50
|
+
return this.toColorString(value);
|
|
51
|
+
}),
|
|
35
52
|
};
|
|
36
53
|
},
|
|
37
|
-
render(ctx,
|
|
54
|
+
render(ctx, node, renderContext) {
|
|
38
55
|
renderContext();
|
|
39
56
|
const computed = this.computed as ComputedLinearGradientValues;
|
|
57
|
+
const { tx, ty } = node.globalTransform!;
|
|
58
|
+
const { w, h } = node.props;
|
|
40
59
|
const gradient = ctx.createLinearGradient(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
tx + computed.x0,
|
|
61
|
+
ty + computed.y0,
|
|
62
|
+
tx + computed.x1,
|
|
63
|
+
ty + computed.y1,
|
|
45
64
|
);
|
|
46
65
|
const colors = computed.colors;
|
|
47
66
|
const stops = this.props!.stops;
|
|
@@ -49,6 +68,6 @@ export const LinearGradient: CanvasShaderType<
|
|
|
49
68
|
gradient.addColorStop(stops[i]!, colors[i]!);
|
|
50
69
|
}
|
|
51
70
|
ctx.fillStyle = gradient;
|
|
52
|
-
ctx.fillRect(
|
|
71
|
+
ctx.fillRect(tx, ty, w, h);
|
|
53
72
|
},
|
|
54
73
|
};
|
|
@@ -39,12 +39,14 @@ export const RadialGradient: CanvasShaderType<
|
|
|
39
39
|
colors: props.colors.map((value) => this.toColorString(value)),
|
|
40
40
|
};
|
|
41
41
|
},
|
|
42
|
-
render(ctx,
|
|
42
|
+
render(ctx, node, renderContext) {
|
|
43
43
|
renderContext();
|
|
44
44
|
const { scaleX, scaleY, pivotX, pivotY, colors, size } = this
|
|
45
45
|
.computed as ComputedRadialGradientValues;
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const { tx, ty } = node.globalTransform!;
|
|
47
|
+
const { w, h } = node.props;
|
|
48
|
+
let x = tx + pivotX;
|
|
49
|
+
let y = ty + pivotY;
|
|
48
50
|
const stops = this.props!.stops;
|
|
49
51
|
|
|
50
52
|
if (scaleX === scaleY) {
|
|
@@ -55,7 +57,7 @@ export const RadialGradient: CanvasShaderType<
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
ctx.fillStyle = gradient;
|
|
58
|
-
ctx.fillRect(
|
|
60
|
+
ctx.fillRect(tx, ty, w, h);
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -70,12 +72,7 @@ export const RadialGradient: CanvasShaderType<
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
ctx.fillStyle = gradient;
|
|
73
|
-
ctx.fillRect(
|
|
74
|
-
quad.tx / scaleX,
|
|
75
|
-
quad.ty / scaleY,
|
|
76
|
-
quad.width / scaleX,
|
|
77
|
-
quad.height / scaleY,
|
|
78
|
-
);
|
|
75
|
+
ctx.fillRect(tx / scaleX, ty / scaleY, w / scaleX, h / scaleY);
|
|
79
76
|
|
|
80
77
|
ctx.restore();
|
|
81
78
|
},
|
|
@@ -21,14 +21,14 @@ export const Rounded: CanvasShaderType<RoundedProps, ComputedRoundedValues> = {
|
|
|
21
21
|
node.h,
|
|
22
22
|
);
|
|
23
23
|
},
|
|
24
|
-
render(ctx,
|
|
24
|
+
render(ctx, node, renderContext) {
|
|
25
25
|
const path = new Path2D();
|
|
26
26
|
roundRect(
|
|
27
27
|
path,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
node.globalTransform!.tx,
|
|
29
|
+
node.globalTransform!.ty,
|
|
30
|
+
node.props.w,
|
|
31
|
+
node.props.h,
|
|
32
32
|
this.computed.radius!,
|
|
33
33
|
);
|
|
34
34
|
ctx.clip(path);
|
|
@@ -78,14 +78,14 @@ export const RoundedWithBorder: CanvasShaderType<
|
|
|
78
78
|
Math.max(0.0, this.computed.outerBorderRadius[3] - Math.max(l, r)),
|
|
79
79
|
];
|
|
80
80
|
},
|
|
81
|
-
render(ctx,
|
|
81
|
+
render(ctx, node, renderContext) {
|
|
82
82
|
const computed = this.computed as ComputedRoundedWithBorderValues;
|
|
83
83
|
roundedRectWithBorder(
|
|
84
84
|
ctx,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
node.globalTransform!.tx,
|
|
86
|
+
node.globalTransform!.ty,
|
|
87
|
+
node.props.w,
|
|
88
|
+
node.props.h,
|
|
89
89
|
computed.radius,
|
|
90
90
|
this.props!['border-gap'] as number,
|
|
91
91
|
computed.outerX,
|
|
@@ -79,15 +79,16 @@ export const RoundedWithBorderAndShadow: CanvasShaderType<
|
|
|
79
79
|
(value) => value + props['shadow-blur'],
|
|
80
80
|
) as Vec4;
|
|
81
81
|
},
|
|
82
|
-
render(ctx,
|
|
83
|
-
const { tx, ty
|
|
82
|
+
render(ctx, node, renderContext) {
|
|
83
|
+
const { tx, ty } = node.globalTransform!;
|
|
84
|
+
const { w, h } = node.props;
|
|
84
85
|
const computed = this.computed as ComputedValues;
|
|
85
86
|
render.shadow(
|
|
86
87
|
ctx,
|
|
87
88
|
tx + computed.outerX,
|
|
88
89
|
ty + computed.outerY,
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
w + computed.outerW,
|
|
91
|
+
h + computed.outerH,
|
|
91
92
|
computed.shadowColor,
|
|
92
93
|
this.props!['shadow-projection'],
|
|
93
94
|
computed.shadowRadius,
|
|
@@ -95,10 +96,10 @@ export const RoundedWithBorderAndShadow: CanvasShaderType<
|
|
|
95
96
|
);
|
|
96
97
|
render.roundedRectWithBorder(
|
|
97
98
|
ctx,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
tx,
|
|
100
|
+
ty,
|
|
101
|
+
w,
|
|
102
|
+
h,
|
|
102
103
|
computed.radius,
|
|
103
104
|
this.props!['border-gap'] as number,
|
|
104
105
|
computed.outerX,
|
|
@@ -30,8 +30,9 @@ export const RoundedWithShadow: CanvasShaderType<
|
|
|
30
30
|
(value) => value + props['shadow-blur'],
|
|
31
31
|
) as Vec4;
|
|
32
32
|
},
|
|
33
|
-
render(ctx,
|
|
34
|
-
const { tx, ty
|
|
33
|
+
render(ctx, node, renderContext) {
|
|
34
|
+
const { tx, ty } = node.globalTransform!;
|
|
35
|
+
const { w, h } = node.props;
|
|
35
36
|
const computed = this.computed as ComputedValues;
|
|
36
37
|
|
|
37
38
|
if (this.props!['shadow-color'] !== 0) {
|
|
@@ -39,8 +40,8 @@ export const RoundedWithShadow: CanvasShaderType<
|
|
|
39
40
|
ctx,
|
|
40
41
|
tx,
|
|
41
42
|
ty,
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
w,
|
|
44
|
+
h,
|
|
44
45
|
computed.shadowColor,
|
|
45
46
|
this.props!['shadow-projection'],
|
|
46
47
|
computed.shadowRadius,
|
|
@@ -49,7 +50,7 @@ export const RoundedWithShadow: CanvasShaderType<
|
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
const path = new Path2D();
|
|
52
|
-
render.roundRect(path, tx, ty,
|
|
53
|
+
render.roundRect(path, tx, ty, w, h, computed.radius);
|
|
53
54
|
ctx.clip(path);
|
|
54
55
|
renderContext();
|
|
55
56
|
},
|
|
@@ -18,13 +18,15 @@ export const Shadow: CanvasShaderType<ShadowProps, ComputedShadowValues> = {
|
|
|
18
18
|
const blur = this.props!['blur'];
|
|
19
19
|
this.computed.shadowRadius = [blur, blur, blur, blur];
|
|
20
20
|
},
|
|
21
|
-
render(ctx,
|
|
21
|
+
render(ctx, node, renderContext) {
|
|
22
|
+
const { tx, ty } = node.globalTransform!;
|
|
23
|
+
const { w, h } = node.props;
|
|
22
24
|
shadow(
|
|
23
25
|
ctx,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
tx,
|
|
27
|
+
ty,
|
|
28
|
+
w,
|
|
29
|
+
h,
|
|
28
30
|
this.computed.shadowColor!,
|
|
29
31
|
this.props!['projection'],
|
|
30
32
|
this.computed.shadowRadius!,
|
|
@@ -55,24 +55,6 @@ export function roundedRectWithBorder(
|
|
|
55
55
|
innerW += width;
|
|
56
56
|
innerH += height;
|
|
57
57
|
|
|
58
|
-
// no gap render strategy - to avoid artifacts between border and node
|
|
59
|
-
if (borderGap === 0) {
|
|
60
|
-
//draw outer border rounded rect
|
|
61
|
-
ctx.beginPath();
|
|
62
|
-
roundRect(ctx, outerX, outerY, outerW, outerH, outerBorderRadius);
|
|
63
|
-
ctx.fillStyle = borderColor;
|
|
64
|
-
ctx.fill();
|
|
65
|
-
ctx.closePath();
|
|
66
|
-
|
|
67
|
-
const path = new Path2D();
|
|
68
|
-
roundRect(path, innerX, innerY, innerW, innerH, innerBorderRadius as Vec4);
|
|
69
|
-
ctx.clip(path);
|
|
70
|
-
renderContext();
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// with gap render strategy
|
|
75
|
-
|
|
76
58
|
//draw node content first
|
|
77
59
|
ctx.save();
|
|
78
60
|
const path = new Path2D();
|