q5 2.9.22 → 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 (69) 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 +48 -37
  62. package/q5.min.js +1 -1
  63. package/src/q5-2d-image.js +3 -1
  64. package/src/q5-core.js +3 -1
  65. package/src/q5-math.js +1 -0
  66. package/src/q5-webgpu-canvas.js +8 -7
  67. package/src/q5-webgpu-drawing.js +15 -12
  68. package/src/q5-webgpu-image.js +1 -1
  69. package/src/q5-webgpu-text.js +17 -15
@@ -168,8 +168,9 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
168
168
  getChar(charCode) {
169
169
  return this.chars[charCode] ?? this.defaultChar;
170
170
  }
171
- // Gets the distance in pixels a line should advance for a given character code. If the upcoming
172
- // 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.
173
174
  getXAdvance(charCode, nextCharCode = -1) {
174
175
  let char = this.getChar(charCode);
175
176
  if (nextCharCode >= 0) {
@@ -211,8 +212,8 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
211
212
  });
212
213
  Q5.device.queue.copyExternalImageToTexture({ source: img }, { texture }, imgSize);
213
214
 
214
- // to make q5's default font file smaller,
215
- // 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
216
217
  if (typeof atlas.chars == 'string') {
217
218
  atlas.chars = $.CSV.parse(atlas.chars, ' ');
218
219
  atlas.kernings = $.CSV.parse(atlas.kernings, ' ');
@@ -338,7 +339,7 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
338
339
  let charCode = nextCharCode;
339
340
  nextCharCode = i < text.length - 1 ? text.charCodeAt(i + 1) : -1;
340
341
  switch (charCode) {
341
- case 10: // Newline
342
+ case 10: // newline
342
343
  lineWidths.push(offsetX);
343
344
  line++;
344
345
  maxWidth = Math.max(maxWidth, offsetX);
@@ -347,11 +348,11 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
347
348
  break;
348
349
  case 13: // CR
349
350
  break;
350
- case 32: // Space
351
+ case 32: // space
351
352
  // advance the offset without actually adding a character
352
353
  offsetX += font.getXAdvance(charCode);
353
354
  break;
354
- case 9: // Tab
355
+ case 9: // tab
355
356
  offsetX += font.getXAdvance(charCode) * 2;
356
357
  break;
357
358
  default:
@@ -376,7 +377,8 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
376
377
 
377
378
  $.text = (str, x, y, w, h) => {
378
379
  if (!$._font) {
379
- // 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
380
382
  if (navigator.onLine && !initLoadDefaultFont) {
381
383
  initLoadDefaultFont = true;
382
384
  $.loadFont('https://q5js.org/fonts/YaHei-msdf.json');
@@ -535,27 +537,27 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
535
537
  $._hooks.preRender.push(() => {
536
538
  if (!$._charStack.length) return;
537
539
 
538
- // Calculate total buffer size for text data
540
+ // calculate total buffer size for text data
539
541
  let totalTextSize = 0;
540
542
  for (let charsData of $._charStack) {
541
543
  totalTextSize += charsData.length * 4;
542
544
  }
543
545
 
544
- // Create a single buffer for all char data
546
+ // create a single buffer for all the char data
545
547
  let charBuffer = Q5.device.createBuffer({
546
548
  size: totalTextSize,
547
549
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
548
550
  mappedAtCreation: true
549
551
  });
550
552
 
551
- // Copy all text data into the buffer
553
+ // copy all the text data into the buffer
552
554
  new Float32Array(charBuffer.getMappedRange()).set($._charStack.flat());
553
555
  charBuffer.unmap();
554
556
 
555
- // Calculate total buffer size for metadata
557
+ // calculate total buffer size for metadata
556
558
  let totalMetadataSize = $._textStack.length * 6 * 4;
557
559
 
558
- // Create a single buffer for all metadata
560
+ // create a single buffer for all metadata
559
561
  let textBuffer = Q5.device.createBuffer({
560
562
  label: 'textBuffer',
561
563
  size: totalMetadataSize,
@@ -563,11 +565,11 @@ fn fragmentMain(input : VertexOutput) -> @location(0) vec4f {
563
565
  mappedAtCreation: true
564
566
  });
565
567
 
566
- // Copy all metadata into the buffer
568
+ // copy all metadata into the buffer
567
569
  new Float32Array(textBuffer.getMappedRange()).set($._textStack.flat());
568
570
  textBuffer.unmap();
569
571
 
570
- // 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
571
573
  $._textBindGroup = Q5.device.createBindGroup({
572
574
  label: 'msdf text bind group',
573
575
  layout: textBindGroupLayout,