q5 2.7.6 → 2.9.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/.prettierignore +1 -0
- package/package.json +1 -1
- package/q5.d.ts +260 -155
- package/q5.js +122 -77
- package/q5.min.js +2 -2
- package/q5js_icon.png +0 -0
- package/src/q5-2d-canvas.js +8 -2
- package/src/q5-2d-drawing.js +14 -13
- package/src/q5-2d-image.js +18 -10
- package/src/q5-ai.js +3 -2
- package/src/q5-canvas.js +19 -0
- package/src/q5-core.js +8 -1
- package/src/q5-display.js +2 -2
- package/src/q5-math.js +1 -1
- package/src/q5-webgpu-canvas.js +2 -2
- package/src/q5-webgpu-drawing.js +40 -39
- package/src/q5-webgpu-image.js +8 -6
package/src/q5-webgpu-drawing.js
CHANGED
|
@@ -97,29 +97,6 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
97
97
|
vertIndex = i;
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
-
const addTri = (x1, y1, x2, y2, x3, y3, ci, ti) => {
|
|
101
|
-
let v = vertexStack,
|
|
102
|
-
i = vertIndex;
|
|
103
|
-
|
|
104
|
-
v[i++] = x1;
|
|
105
|
-
v[i++] = y1;
|
|
106
|
-
v[i++] = ci;
|
|
107
|
-
v[i++] = ti;
|
|
108
|
-
|
|
109
|
-
v[i++] = x2;
|
|
110
|
-
v[i++] = y2;
|
|
111
|
-
v[i++] = ci;
|
|
112
|
-
v[i++] = ti;
|
|
113
|
-
|
|
114
|
-
v[i++] = x3;
|
|
115
|
-
v[i++] = y3;
|
|
116
|
-
v[i++] = ci;
|
|
117
|
-
v[i++] = ti;
|
|
118
|
-
|
|
119
|
-
vertIndex = i;
|
|
120
|
-
drawStack.push(0, 3);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
100
|
const addRect = (x1, y1, x2, y2, x3, y3, x4, y4, ci, ti) => {
|
|
124
101
|
let v = vertexStack,
|
|
125
102
|
i = vertIndex;
|
|
@@ -203,21 +180,40 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
203
180
|
if ($._doStroke) {
|
|
204
181
|
ci = $._strokeIndex;
|
|
205
182
|
|
|
206
|
-
//
|
|
183
|
+
// stroke weight adjustment
|
|
207
184
|
let sw = $._strokeWeight / 2;
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
185
|
+
|
|
186
|
+
if ($._doFill) {
|
|
187
|
+
// existing behavior: draw stroke as one big rectangle
|
|
188
|
+
let to = t + sw,
|
|
189
|
+
bo = b - sw,
|
|
190
|
+
lo = l - sw,
|
|
191
|
+
ro = r + sw;
|
|
192
|
+
|
|
193
|
+
// draw stroke rectangle
|
|
194
|
+
addRect(lo, to, ro, to, ro, bo, lo, bo, ci, ti);
|
|
195
|
+
|
|
196
|
+
// adjust inner rectangle coordinates
|
|
197
|
+
t -= sw;
|
|
198
|
+
b += sw;
|
|
199
|
+
l += sw;
|
|
200
|
+
r -= sw;
|
|
201
|
+
} else {
|
|
202
|
+
// new behavior: draw stroke as four rectangles (sides)
|
|
203
|
+
let lsw = l - sw,
|
|
204
|
+
rsw = r + sw,
|
|
205
|
+
tsw = t + sw,
|
|
206
|
+
bsw = b - sw,
|
|
207
|
+
lpsw = l + sw,
|
|
208
|
+
rpsw = r - sw,
|
|
209
|
+
tpsw = t - sw,
|
|
210
|
+
bpsw = b + sw;
|
|
211
|
+
|
|
212
|
+
addRect(lsw, tpsw, rsw, tpsw, rsw, tsw, lsw, tsw, ci, ti); // top
|
|
213
|
+
addRect(lsw, bsw, rsw, bsw, rsw, bpsw, lsw, bpsw, ci, ti); // bottom
|
|
214
|
+
addRect(lsw, tsw, lpsw, tsw, lpsw, bsw, lsw, bsw, ci, ti); // left
|
|
215
|
+
addRect(rpsw, tsw, rsw, tsw, rsw, bsw, rpsw, bsw, ci, ti); // right
|
|
216
|
+
}
|
|
221
217
|
}
|
|
222
218
|
|
|
223
219
|
if ($._doFill) {
|
|
@@ -392,11 +388,16 @@ fn fragmentMain(@location(0) color: vec4f) -> @location(0) vec4f {
|
|
|
392
388
|
$.vertex(x1, y1);
|
|
393
389
|
$.vertex(x2, y2);
|
|
394
390
|
$.vertex(x3, y3);
|
|
395
|
-
$.endShape();
|
|
391
|
+
$.endShape(true);
|
|
396
392
|
};
|
|
397
393
|
|
|
398
394
|
$.quad = (x1, y1, x2, y2, x3, y3, x4, y4) => {
|
|
399
|
-
|
|
395
|
+
$.beginShape();
|
|
396
|
+
$.vertex(x1, y1);
|
|
397
|
+
$.vertex(x2, y2);
|
|
398
|
+
$.vertex(x3, y3);
|
|
399
|
+
$.vertex(x4, y4);
|
|
400
|
+
$.endShape(true);
|
|
400
401
|
};
|
|
401
402
|
|
|
402
403
|
$.background = (r, g, b, a) => {
|
package/src/q5-webgpu-image.js
CHANGED
|
@@ -89,7 +89,7 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
|
|
|
89
89
|
entryPoint: 'fragmentMain',
|
|
90
90
|
targets: [{ format: 'bgra8unorm', blend: $.blendConfigs.normal }]
|
|
91
91
|
},
|
|
92
|
-
primitive: { topology: 'triangle-
|
|
92
|
+
primitive: { topology: 'triangle-strip', stripIndexFormat: 'uint32' },
|
|
93
93
|
multisample: { count: 4 }
|
|
94
94
|
};
|
|
95
95
|
|
|
@@ -121,7 +121,6 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
|
|
|
121
121
|
{
|
|
122
122
|
texture,
|
|
123
123
|
colorSpace: $.canvas.colorSpace
|
|
124
|
-
// premultipliedAlpha: true
|
|
125
124
|
},
|
|
126
125
|
textureSize
|
|
127
126
|
);
|
|
@@ -153,6 +152,11 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
|
|
|
153
152
|
const img = new Image();
|
|
154
153
|
img.crossOrigin = 'Anonymous';
|
|
155
154
|
img.onload = () => {
|
|
155
|
+
// calculate the default width and height that the image
|
|
156
|
+
// should be drawn at if the user doesn't specify a display size
|
|
157
|
+
img.defaultWidth = img.width * $._defaultImageScale;
|
|
158
|
+
img.defaultHeight = img.height * $._defaultImageScale;
|
|
159
|
+
|
|
156
160
|
$._createTexture(img);
|
|
157
161
|
q._preloadCount--;
|
|
158
162
|
};
|
|
@@ -169,8 +173,8 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
|
|
|
169
173
|
if ($._matrixDirty) $._saveMatrix();
|
|
170
174
|
let ti = $._transformIndex;
|
|
171
175
|
|
|
172
|
-
w ??= img.
|
|
173
|
-
h ??= img.
|
|
176
|
+
w ??= img.defaultWidth;
|
|
177
|
+
h ??= img.defaultHeight;
|
|
174
178
|
|
|
175
179
|
let [l, r, t, b] = $._calcBox(x, y, w, h, $._imageMode);
|
|
176
180
|
|
|
@@ -179,8 +183,6 @@ fn fragmentMain(@location(0) texCoord: vec2f) -> @location(0) vec4f {
|
|
|
179
183
|
l, t, 0, 0, ti,
|
|
180
184
|
r, t, 1, 0, ti,
|
|
181
185
|
l, b, 0, 1, ti,
|
|
182
|
-
r, t, 1, 0, ti,
|
|
183
|
-
l, b, 0, 1, ti,
|
|
184
186
|
r, b, 1, 1, ti
|
|
185
187
|
);
|
|
186
188
|
|