q5 4.6.1 → 4.6.3
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/package.json +2 -2
- package/q5.d.ts +16 -9
- package/q5.js +71 -15
- package/q5.min.js +1 -1
- package/q5.min.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "q5",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.3",
|
|
4
4
|
"description": "Beginner friendly graphics powered by WebGPU, optimized for interactive art!",
|
|
5
5
|
"author": "quinton-ashley",
|
|
6
6
|
"license": "LGPL-3.0-only",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dist": "bun bundle && bun min",
|
|
47
47
|
"tests": "jest test",
|
|
48
48
|
"bld": "node lang/build.js",
|
|
49
|
-
"
|
|
49
|
+
"types": "node lang/types.js",
|
|
50
50
|
"v": "npm version patch --force",
|
|
51
51
|
"V": "npm version minor --force",
|
|
52
52
|
"version": "git add -A",
|
package/q5.d.ts
CHANGED
|
@@ -1875,10 +1875,18 @@ declare global {
|
|
|
1875
1875
|
function blendMode(val: string): void;
|
|
1876
1876
|
|
|
1877
1877
|
/** 💅
|
|
1878
|
-
* Set the line cap style to `
|
|
1879
|
-
*
|
|
1880
|
-
* Not available in q5 WebGPU.
|
|
1878
|
+
* Set the line cap style to `SQUARE` or `PROJECT`.
|
|
1881
1879
|
* @param {CanvasLineCap} val line cap style
|
|
1880
|
+
* @example
|
|
1881
|
+
* await Canvas(200);
|
|
1882
|
+
* background(0.8);
|
|
1883
|
+
* strokeWeight(20);
|
|
1884
|
+
*
|
|
1885
|
+
* strokeCap(SQUARE);
|
|
1886
|
+
* line(-50, -25, 50, -25);
|
|
1887
|
+
*
|
|
1888
|
+
* strokeCap(PROJECT);
|
|
1889
|
+
* line(-50, 25, 50, 25);
|
|
1882
1890
|
*/
|
|
1883
1891
|
function strokeCap(val: CanvasLineCap): void;
|
|
1884
1892
|
|
|
@@ -4073,12 +4081,13 @@ declare global {
|
|
|
4073
4081
|
/** ⚡
|
|
4074
4082
|
* Creates a shader that q5 can use to draw frames.
|
|
4075
4083
|
*
|
|
4076
|
-
* You must create a canvas before using this function.
|
|
4077
|
-
*
|
|
4078
4084
|
* Use this function to customize a copy of the
|
|
4079
4085
|
* [default frame shader](https://github.com/q5js/q5.js/blob/main/src/shaders/frame.wgsl).
|
|
4080
4086
|
* @example
|
|
4081
|
-
* await Canvas(200);
|
|
4087
|
+
* await Canvas(200, 400);
|
|
4088
|
+
* stroke(1);
|
|
4089
|
+
* strokeWeight(8);
|
|
4090
|
+
* strokeCap(PROJECT);
|
|
4082
4091
|
*
|
|
4083
4092
|
* let boxy = createFrameShader(`
|
|
4084
4093
|
* @fragment
|
|
@@ -4090,8 +4099,6 @@ declare global {
|
|
|
4090
4099
|
* }`);
|
|
4091
4100
|
*
|
|
4092
4101
|
* q5.draw = function () {
|
|
4093
|
-
* stroke(1);
|
|
4094
|
-
* strokeWeight(8);
|
|
4095
4102
|
* line(mouseX, mouseY, pmouseX, pmouseY);
|
|
4096
4103
|
* mouseIsPressed ? resetShaders() : shader(boxy);
|
|
4097
4104
|
* };
|
|
@@ -4106,7 +4113,7 @@ declare global {
|
|
|
4106
4113
|
* @param {string} code WGSL shader code excerpt
|
|
4107
4114
|
* @returns {GPUShaderModule} a shader program
|
|
4108
4115
|
* @example
|
|
4109
|
-
* await Canvas(200);
|
|
4116
|
+
* await Canvas(200, 400);
|
|
4110
4117
|
* imageMode(CENTER);
|
|
4111
4118
|
*
|
|
4112
4119
|
* let logo = loadImage('/q5js_logo.avif');
|
package/q5.js
CHANGED
|
@@ -6309,13 +6309,6 @@ fn fragMain(f: FragParams ) -> @location(0) vec4f {
|
|
|
6309
6309
|
}
|
|
6310
6310
|
|
|
6311
6311
|
Q5.device.queue.writeBuffer(imgVertBuff, 0, imgVertStack.subarray(0, imgVertIdx));
|
|
6312
|
-
|
|
6313
|
-
$._pass.setVertexBuffer(1, imgVertBuff);
|
|
6314
|
-
|
|
6315
|
-
if (vidFrames) {
|
|
6316
|
-
$._pass.setPipeline($._pipelines[3]); // video pipeline
|
|
6317
|
-
$._pass.setVertexBuffer(1, imgVertBuff);
|
|
6318
|
-
}
|
|
6319
6312
|
}
|
|
6320
6313
|
|
|
6321
6314
|
// prepare to render text
|
|
@@ -6415,6 +6408,12 @@ fn fragMain(f: FragParams ) -> @location(0) vec4f {
|
|
|
6415
6408
|
curPipelineIndex = drawStack[i];
|
|
6416
6409
|
pass.setPipeline($._pipelines[curPipelineIndex]);
|
|
6417
6410
|
|
|
6411
|
+
if (curPipelineIndex == 2 || curPipelineIndex == 3 || curPipelineIndex >= 2000) {
|
|
6412
|
+
pass.setVertexBuffer(0, imgVertBuff);
|
|
6413
|
+
} else if (curPipelineIndex == 1 || (curPipelineIndex >= 1000 && curPipelineIndex < 2000)) {
|
|
6414
|
+
pass.setVertexBuffer(0, shapesVertBuff);
|
|
6415
|
+
}
|
|
6416
|
+
|
|
6418
6417
|
if (curPipelineIndex == 5) {
|
|
6419
6418
|
pass.setIndexBuffer(rectIndexBuffer, 'uint16');
|
|
6420
6419
|
pass.setBindGroup(1, rectBindGroup);
|
|
@@ -7327,10 +7326,29 @@ fn vertexMain(v: VertexParams) -> FragParams {
|
|
|
7327
7326
|
|
|
7328
7327
|
let len = Math.sqrt(sqLen),
|
|
7329
7328
|
ratio = hsw / len,
|
|
7330
|
-
nx = -dy * ratio,
|
|
7331
|
-
ny = dx * ratio
|
|
7332
|
-
|
|
7333
|
-
|
|
7329
|
+
nx = -dy * ratio, // line thickness
|
|
7330
|
+
ny = dx * ratio,
|
|
7331
|
+
ex = 0,
|
|
7332
|
+
ey = 0;
|
|
7333
|
+
|
|
7334
|
+
if (_strokeCap[0] === 's') {
|
|
7335
|
+
// 'square' PROJECT
|
|
7336
|
+
ex = ny;
|
|
7337
|
+
ey = -nx;
|
|
7338
|
+
}
|
|
7339
|
+
|
|
7340
|
+
addQuad(
|
|
7341
|
+
x1 - ex + nx,
|
|
7342
|
+
y1 - ey + ny,
|
|
7343
|
+
x1 - ex - nx,
|
|
7344
|
+
y1 - ey - ny,
|
|
7345
|
+
x2 + ex - nx,
|
|
7346
|
+
y2 + ey - ny,
|
|
7347
|
+
x2 + ex + nx,
|
|
7348
|
+
y2 + ey + ny,
|
|
7349
|
+
strokeIdx,
|
|
7350
|
+
matrixIdx
|
|
7351
|
+
);
|
|
7334
7352
|
};
|
|
7335
7353
|
|
|
7336
7354
|
/* ELLIPSE */
|
|
@@ -7790,7 +7808,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
7790
7808
|
vertex: {
|
|
7791
7809
|
module: imageShader,
|
|
7792
7810
|
entryPoint: 'vertexMain',
|
|
7793
|
-
buffers: [
|
|
7811
|
+
buffers: [imgVertBuffLayout]
|
|
7794
7812
|
},
|
|
7795
7813
|
fragment: {
|
|
7796
7814
|
module: imageShader,
|
|
@@ -7809,7 +7827,7 @@ fn fragMain(f: FragParams) -> @location(0) vec4f {
|
|
|
7809
7827
|
vertex: {
|
|
7810
7828
|
module: videoShader,
|
|
7811
7829
|
entryPoint: 'vertexMain',
|
|
7812
|
-
buffers: [
|
|
7830
|
+
buffers: [imgVertBuffLayout]
|
|
7813
7831
|
},
|
|
7814
7832
|
fragment: {
|
|
7815
7833
|
module: videoShader,
|
|
@@ -9437,6 +9455,10 @@ const parseLangs = function (data, lang) {
|
|
|
9437
9455
|
return map;
|
|
9438
9456
|
};
|
|
9439
9457
|
|
|
9458
|
+
const unaccent = function (s) {
|
|
9459
|
+
return s.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
|
9460
|
+
};
|
|
9461
|
+
|
|
9440
9462
|
Object.defineProperty(Q5, 'lang', {
|
|
9441
9463
|
get: () => Q5._lang,
|
|
9442
9464
|
set: (val) => {
|
|
@@ -9502,6 +9524,40 @@ for (let l of supportedLangs) {
|
|
|
9502
9524
|
}
|
|
9503
9525
|
}
|
|
9504
9526
|
|
|
9527
|
+
Q5.applyLang = function (q, libs, classes) {
|
|
9528
|
+
let val = Q5._lang;
|
|
9529
|
+
if (val == 'en') return;
|
|
9530
|
+
|
|
9531
|
+
let map = parseLangs(libs, val);
|
|
9532
|
+
for (let name in map) {
|
|
9533
|
+
let translatedName = map[name];
|
|
9534
|
+
q[translatedName] = q[name];
|
|
9535
|
+
if (val == 'es') {
|
|
9536
|
+
let unaccentedName = unaccent(translatedName);
|
|
9537
|
+
if (unaccentedName != translatedName) q[unaccentedName] = q[name];
|
|
9538
|
+
}
|
|
9539
|
+
}
|
|
9540
|
+
|
|
9541
|
+
if (!classes) return;
|
|
9542
|
+
|
|
9543
|
+
for (let className in classes) {
|
|
9544
|
+
let target = q[className].prototype;
|
|
9545
|
+
let map = parseLangs(classes[className], val);
|
|
9546
|
+
for (let name in map) {
|
|
9547
|
+
let translatedName = map[name];
|
|
9548
|
+
if (target.hasOwnProperty(translatedName)) continue;
|
|
9549
|
+
Object.defineProperty(target, translatedName, {
|
|
9550
|
+
get: function () {
|
|
9551
|
+
return this[name];
|
|
9552
|
+
},
|
|
9553
|
+
set: function (v) {
|
|
9554
|
+
this[name] = v;
|
|
9555
|
+
}
|
|
9556
|
+
});
|
|
9557
|
+
}
|
|
9558
|
+
}
|
|
9559
|
+
};
|
|
9560
|
+
|
|
9505
9561
|
Q5.modules.lang = ($) => {
|
|
9506
9562
|
let userFnsMap = Q5._userFnsMap;
|
|
9507
9563
|
|
|
@@ -9526,7 +9582,7 @@ Q5.addHook('init', (q) => {
|
|
|
9526
9582
|
q[translatedName] = q[name];
|
|
9527
9583
|
|
|
9528
9584
|
if (Q5._lang == 'es') {
|
|
9529
|
-
let unaccentedName = translatedName
|
|
9585
|
+
let unaccentedName = unaccent(translatedName);
|
|
9530
9586
|
if (unaccentedName != translatedName) {
|
|
9531
9587
|
q[unaccentedName] = q[name];
|
|
9532
9588
|
}
|
|
@@ -9560,7 +9616,7 @@ Q5.addHook('predraw', (q) => {
|
|
|
9560
9616
|
if (!m[p]) continue;
|
|
9561
9617
|
q[m[p]] = q[p];
|
|
9562
9618
|
if (Q5._lang == 'es') {
|
|
9563
|
-
let unaccentedName = m[p]
|
|
9619
|
+
let unaccentedName = unaccent(m[p]);
|
|
9564
9620
|
if (unaccentedName != m[p]) {
|
|
9565
9621
|
q[unaccentedName] = q[p];
|
|
9566
9622
|
}
|