q5 2.9.21 → 2.9.23

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.
Files changed (77) hide show
  1. package/.vscode/launch.json +26 -0
  2. package/bun.lockb +0 -0
  3. package/p5-tests/js/chai_helpers.js +20 -0
  4. package/p5-tests/js/mocha_setup.js +2 -0
  5. package/p5-tests/js/modernizr.js +5 -0
  6. package/p5-tests/js/p5_helpers.js +135 -0
  7. package/p5-tests/js/sinon.js +5949 -0
  8. package/p5-tests/mocha.css +289 -0
  9. package/p5-tests/test.html +71 -0
  10. package/p5-tests/unit/color/color_conversion.js +68 -0
  11. package/p5-tests/unit/color/creating_reading.js +217 -0
  12. package/p5-tests/unit/color/p5.Color.js +1000 -0
  13. package/p5-tests/unit/color/setting.js +289 -0
  14. package/p5-tests/unit/core/2d_primitives.js +490 -0
  15. package/p5-tests/unit/core/attributes.js +115 -0
  16. package/p5-tests/unit/core/curves.js +139 -0
  17. package/p5-tests/unit/core/environment.js +248 -0
  18. package/p5-tests/unit/core/error_helpers.js +1158 -0
  19. package/p5-tests/unit/core/main.js +340 -0
  20. package/p5-tests/unit/core/p5.Element.js +773 -0
  21. package/p5-tests/unit/core/p5.Graphics.js +179 -0
  22. package/p5-tests/unit/core/preload.js +285 -0
  23. package/p5-tests/unit/core/rendering.js +116 -0
  24. package/p5-tests/unit/core/structure.js +293 -0
  25. package/p5-tests/unit/core/transform.js +144 -0
  26. package/p5-tests/unit/core/version.js +28 -0
  27. package/p5-tests/unit/core/vertex.js +137 -0
  28. package/p5-tests/unit/dom/dom.js +2146 -0
  29. package/p5-tests/unit/events/acceleration.js +213 -0
  30. package/p5-tests/unit/events/keyboard.js +179 -0
  31. package/p5-tests/unit/events/mouse.js +487 -0
  32. package/p5-tests/unit/events/touch.js +180 -0
  33. package/p5-tests/unit/image/downloading.js +379 -0
  34. package/p5-tests/unit/image/filters.js +92 -0
  35. package/p5-tests/unit/image/loading.js +413 -0
  36. package/p5-tests/unit/image/p5.Image.js +201 -0
  37. package/p5-tests/unit/image/pixels.js +234 -0
  38. package/p5-tests/unit/io/files.js +378 -0
  39. package/p5-tests/unit/io/loadBytes.js +149 -0
  40. package/p5-tests/unit/io/loadImage.js +123 -0
  41. package/p5-tests/unit/io/loadJSON.js +185 -0
  42. package/p5-tests/unit/io/loadModel.js +215 -0
  43. package/p5-tests/unit/io/loadShader.js +176 -0
  44. package/p5-tests/unit/io/loadStrings.js +140 -0
  45. package/p5-tests/unit/io/loadTable.js +183 -0
  46. package/p5-tests/unit/io/loadXML.js +127 -0
  47. package/p5-tests/unit/io/saveModel.js +113 -0
  48. package/p5-tests/unit/io/saveTable.js +142 -0
  49. package/p5-tests/unit/math/calculation.js +452 -0
  50. package/p5-tests/unit/math/noise.js +66 -0
  51. package/p5-tests/unit/math/p5.Vector.js +1886 -0
  52. package/p5-tests/unit/math/random.js +177 -0
  53. package/p5-tests/unit/math/trigonometry.js +144 -0
  54. package/p5-tests/unit/spec.js +50 -0
  55. package/p5-tests/unit/typography/attributes.js +120 -0
  56. package/p5-tests/unit/typography/loadFont.js +162 -0
  57. package/p5-tests/unit/typography/p5.Font.js +63 -0
  58. package/p5-tests/unit/utilities/conversion.js +329 -0
  59. package/p5-tests/unit/utilities/time_date.js +133 -0
  60. package/package.json +1 -1
  61. package/q5.js +158 -54
  62. package/q5.min.js +1 -1
  63. package/src/q5-2d-canvas.js +8 -2
  64. package/src/q5-2d-drawing.js +20 -7
  65. package/src/q5-2d-image.js +4 -1
  66. package/src/q5-2d-text.js +7 -0
  67. package/src/q5-canvas.js +6 -5
  68. package/src/q5-color.js +5 -0
  69. package/src/q5-core.js +3 -1
  70. package/src/q5-input.js +12 -0
  71. package/src/q5-math.js +11 -3
  72. package/src/q5-record.js +2 -0
  73. package/src/q5-vector.js +33 -0
  74. package/src/q5-webgpu-canvas.js +11 -7
  75. package/src/q5-webgpu-drawing.js +15 -12
  76. package/src/q5-webgpu-image.js +1 -1
  77. package/src/q5-webgpu-text.js +22 -15
@@ -114,6 +114,7 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
114
114
  mipmapFilter: 'linear',
115
115
  maxAnisotropy: 16
116
116
  });
117
+
117
118
  let fontBindGroupLayout = Q5.device.createBindGroupLayout({
118
119
  label: 'MSDF font group layout',
119
120
  entries: [
@@ -151,6 +152,7 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
151
152
  primitive: { topology: 'triangle-strip', stripIndexFormat: 'uint32' },
152
153
  multisample: { count: 4 }
153
154
  };
155
+
154
156
  $._pipelines[2] = Q5.device.createRenderPipeline($._pipelineConfigs[2]);
155
157
 
156
158
  class MsdfFont {
@@ -166,8 +168,9 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
166
168
  getChar(charCode) {
167
169
  return this.chars[charCode] ?? this.defaultChar;
168
170
  }
169
- // Gets the distance in pixels a line should advance for a given character code. If the upcoming
170
- // character code is given any kerning between the two characters will be taken into account.
171
+ // Gets the distance in pixels a line should advance for a given
172
+ // character code. If the upcoming character code is given any
173
+ // kerning between the two characters will be taken into account.
171
174
  getXAdvance(charCode, nextCharCode = -1) {
172
175
  let char = this.getChar(charCode);
173
176
  if (nextCharCode >= 0) {
@@ -209,8 +212,8 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
209
212
  });
210
213
  Q5.device.queue.copyExternalImageToTexture({ source: img }, { texture }, imgSize);
211
214
 
212
- // to make q5's default font file smaller,
213
- // the chars and kernings are stored as csv strings
215
+ // chars and kernings can be stored as csv strings, making the file
216
+ // size smaller, but they need to be parsed into arrays of objects
214
217
  if (typeof atlas.chars == 'string') {
215
218
  atlas.chars = $.CSV.parse(atlas.chars, ' ');
216
219
  atlas.kernings = $.CSV.parse(atlas.kernings, ' ');
@@ -299,6 +302,7 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
299
302
  $.textFont = (fontName) => {
300
303
  $._font = fonts[fontName];
301
304
  };
305
+
302
306
  $.textSize = (size) => {
303
307
  $._textSize = size;
304
308
  if (!leadingSet) {
@@ -306,12 +310,14 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
306
310
  leadDiff = leading - size;
307
311
  }
308
312
  };
313
+
309
314
  $.textLeading = (lineHeight) => {
310
315
  $._font.lineHeight = leading = lineHeight;
311
316
  leadDiff = leading - $._textSize;
312
317
  leadPercent = leading / $._textSize;
313
318
  leadingSet = true;
314
319
  };
320
+
315
321
  $.textAlign = (horiz, vert) => {
316
322
  $._textAlign = horiz;
317
323
  if (vert) $._textBaseline = vert;
@@ -333,7 +339,7 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
333
339
  let charCode = nextCharCode;
334
340
  nextCharCode = i < text.length - 1 ? text.charCodeAt(i + 1) : -1;
335
341
  switch (charCode) {
336
- case 10: // Newline
342
+ case 10: // newline
337
343
  lineWidths.push(offsetX);
338
344
  line++;
339
345
  maxWidth = Math.max(maxWidth, offsetX);
@@ -342,11 +348,11 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
342
348
  break;
343
349
  case 13: // CR
344
350
  break;
345
- case 32: // Space
351
+ case 32: // space
346
352
  // advance the offset without actually adding a character
347
353
  offsetX += font.getXAdvance(charCode);
348
354
  break;
349
- case 9: // Tab
355
+ case 9: // tab
350
356
  offsetX += font.getXAdvance(charCode) * 2;
351
357
  break;
352
358
  default:
@@ -371,7 +377,8 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
371
377
 
372
378
  $.text = (str, x, y, w, h) => {
373
379
  if (!$._font) {
374
- // check if online and loading the default font hasn't been attempted yet
380
+ // check if online and loading the default font
381
+ // hasn't been attempted yet
375
382
  if (navigator.onLine && !initLoadDefaultFont) {
376
383
  initLoadDefaultFont = true;
377
384
  $.loadFont('https://q5js.org/fonts/YaHei-msdf.json');
@@ -530,27 +537,27 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
530
537
  $._hooks.preRender.push(() => {
531
538
  if (!$._charStack.length) return;
532
539
 
533
- // Calculate total buffer size for text data
540
+ // calculate total buffer size for text data
534
541
  let totalTextSize = 0;
535
542
  for (let charsData of $._charStack) {
536
543
  totalTextSize += charsData.length * 4;
537
544
  }
538
545
 
539
- // Create a single buffer for all char data
546
+ // create a single buffer for all the char data
540
547
  let charBuffer = Q5.device.createBuffer({
541
548
  size: totalTextSize,
542
549
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
543
550
  mappedAtCreation: true
544
551
  });
545
552
 
546
- // Copy all text data into the buffer
553
+ // copy all the text data into the buffer
547
554
  new Float32Array(charBuffer.getMappedRange()).set($._charStack.flat());
548
555
  charBuffer.unmap();
549
556
 
550
- // Calculate total buffer size for metadata
557
+ // calculate total buffer size for metadata
551
558
  let totalMetadataSize = $._textStack.length * 6 * 4;
552
559
 
553
- // Create a single buffer for all metadata
560
+ // create a single buffer for all metadata
554
561
  let textBuffer = Q5.device.createBuffer({
555
562
  label: 'textBuffer',
556
563
  size: totalMetadataSize,
@@ -558,11 +565,11 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
558
565
  mappedAtCreation: true
559
566
  });
560
567
 
561
- // Copy all metadata into the buffer
568
+ // copy all metadata into the buffer
562
569
  new Float32Array(textBuffer.getMappedRange()).set($._textStack.flat());
563
570
  textBuffer.unmap();
564
571
 
565
- // Create a single bind group for the text buffer and metadata buffer
572
+ // create a single bind group for the text buffer and metadata buffer
566
573
  $._textBindGroup = Q5.device.createBindGroup({
567
574
  label: 'msdf text bind group',
568
575
  layout: textBindGroupLayout,