p5 2.2.3 → 2.3.0-rc.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.
Files changed (137) hide show
  1. package/dist/accessibility/color_namer.js +9 -11
  2. package/dist/accessibility/describe.js +0 -1
  3. package/dist/accessibility/gridOutput.js +0 -1
  4. package/dist/accessibility/index.js +9 -10
  5. package/dist/accessibility/outputs.js +0 -1
  6. package/dist/accessibility/textOutput.js +0 -1
  7. package/dist/app.js +11 -10
  8. package/dist/app.node.js +122 -0
  9. package/dist/color/color_conversion.js +9 -11
  10. package/dist/color/creating_reading.js +1 -1
  11. package/dist/color/index.js +2 -2
  12. package/dist/color/p5.Color.js +1 -1
  13. package/dist/color/setting.js +25 -12
  14. package/dist/{constants-BdTiYOQI.js → constants-0wkVUfqa.js} +2 -2
  15. package/dist/core/States.js +1 -1
  16. package/dist/core/constants.js +1 -1
  17. package/dist/core/environment.js +28 -29
  18. package/dist/core/filterShaders.js +1 -1
  19. package/dist/core/friendly_errors/fes_core.js +9 -8
  20. package/dist/core/friendly_errors/file_errors.js +1 -2
  21. package/dist/core/friendly_errors/index.js +1 -1
  22. package/dist/core/friendly_errors/param_validator.js +737 -640
  23. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  24. package/dist/core/friendly_errors/stacktrace.js +0 -1
  25. package/dist/core/helpers.js +3 -4
  26. package/dist/core/init.js +24 -21
  27. package/dist/core/internationalization.js +1 -1
  28. package/dist/core/legacy.js +9 -11
  29. package/dist/core/main.js +9 -10
  30. package/dist/core/p5.Graphics.js +5 -5
  31. package/dist/core/p5.Renderer.js +3 -3
  32. package/dist/core/p5.Renderer2D.js +9 -10
  33. package/dist/core/p5.Renderer3D.js +5 -5
  34. package/dist/core/rendering.js +5 -5
  35. package/dist/core/structure.js +0 -1
  36. package/dist/core/transform.js +7 -16
  37. package/dist/{creating_reading-C7hu6sg1.js → creating_reading-DLkHH80h.js} +11 -8
  38. package/dist/data/local_storage.js +0 -1
  39. package/dist/dom/dom.js +2 -3
  40. package/dist/dom/index.js +2 -2
  41. package/dist/dom/p5.Element.js +2 -2
  42. package/dist/dom/p5.MediaElement.js +2 -2
  43. package/dist/events/acceleration.js +5 -3
  44. package/dist/events/keyboard.js +0 -1
  45. package/dist/events/pointer.js +0 -2
  46. package/dist/image/const.js +1 -1
  47. package/dist/image/filterRenderer2D.js +19 -12
  48. package/dist/image/image.js +5 -5
  49. package/dist/image/index.js +5 -5
  50. package/dist/image/loading_displaying.js +5 -5
  51. package/dist/image/p5.Image.js +3 -3
  52. package/dist/image/pixels.js +0 -1
  53. package/dist/io/files.js +5 -5
  54. package/dist/io/index.js +5 -5
  55. package/dist/io/p5.Table.js +0 -1
  56. package/dist/io/p5.TableRow.js +0 -1
  57. package/dist/io/p5.XML.js +0 -1
  58. package/dist/{ir_builders-Cd6rU9Vm.js → ir_builders-C2ebb6Lu.js} +234 -1
  59. package/dist/{main-H_nu4eDs.js → main-D2kqeMXM.js} +107 -136
  60. package/dist/math/Matrices/Matrix.js +1 -1
  61. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  62. package/dist/math/calculation.js +0 -1
  63. package/dist/math/index.js +3 -1
  64. package/dist/math/math.js +3 -17
  65. package/dist/math/noise.js +0 -1
  66. package/dist/math/p5.Matrix.js +1 -2
  67. package/dist/math/p5.Vector.js +237 -279
  68. package/dist/math/patch-vector.js +75 -0
  69. package/dist/math/random.js +0 -1
  70. package/dist/math/trigonometry.js +3 -4
  71. package/dist/{p5.Renderer-BmD2P6Wv.js → p5.Renderer-CQI8PO1F.js} +31 -24
  72. package/dist/{rendering-CC8JNTwG.js → rendering-ltTIxpF2.js} +732 -44
  73. package/dist/shape/2d_primitives.js +1 -4
  74. package/dist/shape/attributes.js +43 -8
  75. package/dist/shape/curves.js +0 -1
  76. package/dist/shape/custom_shapes.js +260 -5
  77. package/dist/shape/index.js +2 -2
  78. package/dist/shape/vertex.js +0 -2
  79. package/dist/strands/ir_builders.js +1 -1
  80. package/dist/strands/ir_types.js +5 -1
  81. package/dist/strands/p5.strands.js +286 -31
  82. package/dist/strands/strands_api.js +179 -8
  83. package/dist/strands/strands_codegen.js +26 -8
  84. package/dist/strands/strands_conditionals.js +1 -1
  85. package/dist/strands/strands_for.js +1 -1
  86. package/dist/strands/strands_node.js +1 -1
  87. package/dist/strands/strands_ternary.js +56 -0
  88. package/dist/strands/strands_transpiler.js +416 -251
  89. package/dist/strands_glslBackend-i-ReKgZo.js +423 -0
  90. package/dist/type/index.js +3 -3
  91. package/dist/type/lib/Typr.js +1 -1
  92. package/dist/type/p5.Font.js +3 -3
  93. package/dist/type/textCore.js +31 -24
  94. package/dist/utilities/conversion.js +0 -1
  95. package/dist/utilities/time_date.js +0 -1
  96. package/dist/utilities/utility_functions.js +0 -1
  97. package/dist/webgl/3d_primitives.js +5 -5
  98. package/dist/webgl/GeometryBuilder.js +1 -1
  99. package/dist/webgl/ShapeBuilder.js +26 -1
  100. package/dist/webgl/enums.js +1 -1
  101. package/dist/webgl/index.js +8 -9
  102. package/dist/webgl/interaction.js +8 -4
  103. package/dist/webgl/light.js +5 -5
  104. package/dist/webgl/loading.js +60 -21
  105. package/dist/webgl/material.js +5 -5
  106. package/dist/webgl/p5.Camera.js +5 -5
  107. package/dist/webgl/p5.Framebuffer.js +5 -5
  108. package/dist/webgl/p5.Geometry.js +3 -5
  109. package/dist/webgl/p5.Quat.js +1 -1
  110. package/dist/webgl/p5.RendererGL.js +17 -21
  111. package/dist/webgl/p5.Shader.js +129 -36
  112. package/dist/webgl/p5.Texture.js +5 -5
  113. package/dist/webgl/strands_glslBackend.js +5 -386
  114. package/dist/webgl/text.js +5 -5
  115. package/dist/webgl/utils.js +5 -5
  116. package/dist/webgl2Compatibility-DA7DLMuq.js +7 -0
  117. package/dist/webgpu/index.js +7 -3
  118. package/dist/webgpu/p5.RendererWebGPU.js +1146 -180
  119. package/dist/webgpu/shaders/color.js +1 -1
  120. package/dist/webgpu/shaders/compute.js +32 -0
  121. package/dist/webgpu/shaders/functions/randomComputeWGSL.js +31 -0
  122. package/dist/webgpu/shaders/functions/randomVertWGSL.js +30 -0
  123. package/dist/webgpu/shaders/functions/randomWGSL.js +30 -0
  124. package/dist/webgpu/shaders/line.js +1 -1
  125. package/dist/webgpu/shaders/material.js +3 -3
  126. package/dist/webgpu/strands_wgslBackend.js +137 -15
  127. package/lib/p5.esm.js +4092 -1950
  128. package/lib/p5.esm.min.js +1 -1
  129. package/lib/p5.js +4092 -1950
  130. package/lib/p5.min.js +1 -1
  131. package/lib/p5.webgpu.esm.js +1748 -306
  132. package/lib/p5.webgpu.js +1747 -305
  133. package/lib/p5.webgpu.min.js +1 -1
  134. package/package.json +6 -1
  135. package/types/global.d.ts +4182 -2441
  136. package/types/p5.d.ts +2776 -1675
  137. package/dist/noise3DGLSL-Bwrdi4gi.js +0 -9
@@ -1,12 +1,12 @@
1
- import { P as P2D, ac as WEBGL, B as BLEND, al as _DEFAULT_FILL, am as _DEFAULT_STROKE, w as ROUND, b as REMOVE, S as SUBTRACT, D as DARKEST, L as LIGHTEST, an as DIFFERENCE, M as MULTIPLY, E as EXCLUSION, a as SCREEN, R as REPLACE, ao as OVERLAY, ap as HARD_LIGHT, aq as SOFT_LIGHT, ar as DODGE, as as BURN, A as ADD, at as PIE, au as CHORD, q as TWO_PI, x as SQUARE, y as PROJECT, z as BEVEL, I as MITER, a9 as RIGHT, v as CENTER, av as LEFT, aw as BOTTOM, ax as BASELINE, ay as TOP, Q as OPEN, az as VERSION, a3 as constants } from './constants-BdTiYOQI.js';
1
+ import { P as P2D, ad as WEBGL, B as BLEND, an as _DEFAULT_FILL, ao as _DEFAULT_STROKE, u as ROUND, b as REMOVE, S as SUBTRACT, D as DARKEST, L as LIGHTEST, ap as DIFFERENCE, M as MULTIPLY, E as EXCLUSION, a as SCREEN, R as REPLACE, aq as OVERLAY, ar as HARD_LIGHT, as as SOFT_LIGHT, at as DODGE, au as BURN, A as ADD, o as TWO_PI, v as SQUARE, w as PROJECT, x as BEVEL, y as MITER, aa as RIGHT, t as CENTER, av as LEFT, aw as BOTTOM, ax as BASELINE, ay as TOP, az as VERSION, am as constants } from './constants-0wkVUfqa.js';
2
2
  import transform from './core/transform.js';
3
3
  import structure from './core/structure.js';
4
4
  import environment from './core/environment.js';
5
- import { G as Graphics, k as rendering, n as graphics } from './rendering-CC8JNTwG.js';
6
- import { R as Renderer, I as Image, r as renderer } from './p5.Renderer-BmD2P6Wv.js';
5
+ import { G as Graphics, k as rendering, n as graphics } from './rendering-ltTIxpF2.js';
6
+ import { R as Renderer, I as Image, r as renderer } from './p5.Renderer-CQI8PO1F.js';
7
7
  import { Element } from './dom/p5.Element.js';
8
8
  import { MediaElement } from './dom/p5.MediaElement.js';
9
- import { b as RGBHDR } from './creating_reading-C7hu6sg1.js';
9
+ import { b as RGBHDR } from './creating_reading-DLkHH80h.js';
10
10
  import FilterRenderer2D from './image/filterRenderer2D.js';
11
11
  import './math/p5.Matrix.js';
12
12
  import { PrimitiveToPath2DConverter } from './shape/custom_shapes.js';
@@ -14,7 +14,6 @@ import { DefaultFill, textCoreConstants } from './type/textCore.js';
14
14
  import { Matrix } from './math/Matrices/Matrix.js';
15
15
 
16
16
  const styleEmpty = 'rgba(0,0,0,0)';
17
- // const alphaThreshold = 0.00125; // minimum visible
18
17
 
19
18
  class Renderer2D extends Renderer {
20
19
  constructor(pInst, w, h, isMainCanvas, elt, attributes = {}) {
@@ -31,7 +30,9 @@ class Renderer2D extends Renderer {
31
30
  this.canvas.style.display = 'none';
32
31
  }
33
32
 
34
- this.elt.id = 'defaultCanvas0';
33
+ if(!this.elt.id){
34
+ this.elt.id = `defaultCanvas${p5.sketchCount++}`;
35
+ }
35
36
  this.elt.classList.add('p5Canvas');
36
37
 
37
38
  // Extend renderer with methods of p5.Element with getters
@@ -167,18 +168,18 @@ class Renderer2D extends Renderer {
167
168
  //////////////////////////////////////////////
168
169
 
169
170
  background(...args) {
171
+ if (args.length === 0) {
172
+ return this;// setter with no args does nothing
173
+ }
170
174
  this.push();
171
175
  this.resetMatrix();
172
-
173
176
  if (args[0] instanceof Image) {
177
+ const img = args[0];
174
178
  if (args[1] >= 0) {
175
179
  // set transparency of background
176
- const img = args[0];
177
180
  this.drawingContext.globalAlpha = args[1] / 255;
178
- this._pInst.image(img, 0, 0, this.width, this.height);
179
- } else {
180
- this._pInst.image(args[0], 0, 0, this.width, this.height);
181
181
  }
182
+ this._pInst.image(img, 0, 0, this.width, this.height);
182
183
  } else {
183
184
  // create background rect
184
185
  const color = this._pInst.color(...args);
@@ -203,6 +204,8 @@ class Renderer2D extends Renderer {
203
204
  }
204
205
  }
205
206
  this.pop();
207
+
208
+ return this;
206
209
  }
207
210
 
208
211
  clear() {
@@ -215,6 +218,9 @@ class Renderer2D extends Renderer {
215
218
  fill(...args) {
216
219
  super.fill(...args);
217
220
  const color = this.states.fillColor;
221
+ if (args.length === 0) {
222
+ return color; // getter
223
+ }
218
224
  this._setFill(color.toString());
219
225
 
220
226
  // Add accessible outputs if the method exists; on success,
@@ -227,6 +233,9 @@ class Renderer2D extends Renderer {
227
233
  stroke(...args) {
228
234
  super.stroke(...args);
229
235
  const color = this.states.strokeColor;
236
+ if (args.length === 0) {
237
+ return color; // getter
238
+ }
230
239
  this._setStroke(color.toString());
231
240
 
232
241
  // Add accessible outputs if the method exists; on success,
@@ -280,10 +289,10 @@ class Renderer2D extends Renderer {
280
289
  this.clipPath.closePath();
281
290
  } else {
282
291
  if (this.states.fillColor) {
283
- this.drawingContext.fill(visitor.path);
292
+ this.drawingContext.fill(visitor.fillPath || visitor.path);
284
293
  }
285
294
  if (this.states.strokeColor) {
286
- this.drawingContext.stroke(visitor.path);
295
+ this.drawingContext.stroke(visitor.strokePath || visitor.path);
287
296
  }
288
297
  }
289
298
  }
@@ -485,6 +494,9 @@ class Renderer2D extends Renderer {
485
494
  //////////////////////////////////////////////
486
495
 
487
496
  blendMode(mode) {
497
+ if (typeof mode === 'undefined') { // getter
498
+ return this._cachedBlendMode;
499
+ }
488
500
  if (mode === SUBTRACT) {
489
501
  console.warn('blendMode(SUBTRACT) only works in WEBGL mode.');
490
502
  } else if (
@@ -662,101 +674,35 @@ class Renderer2D extends Renderer {
662
674
  * start <= stop < start + TWO_PI
663
675
  */
664
676
  arc(x, y, w, h, start, stop, mode) {
665
- const ctx = this.drawingContext;
666
-
667
- const centerX = x + w / 2,
668
- centerY = y + h / 2,
669
- radiusX = w / 2,
670
- radiusY = h / 2;
671
- if (this._clipping) {
672
- const tempPath = new Path2D();
673
- tempPath.ellipse(centerX, centerY, radiusX, radiusY, 0, start, stop);
674
- const currentTransform = this.drawingContext.getTransform();
675
- const clipBaseTransform = this._clipBaseTransform.inverse();
676
- const relativeTransform = clipBaseTransform.multiply(currentTransform);
677
- this.clipPath.addPath(tempPath, relativeTransform);
678
- return this;
679
- }
680
- // Determines whether to add a line to the center, which should be done
681
- // when the mode is PIE or default; as well as when the start and end
682
- // angles do not form a full circle.
683
- const createPieSlice = ! (
684
- mode === CHORD ||
685
- mode === OPEN ||
686
- (stop - start) % TWO_PI === 0
677
+ const shape = new p5.Shape({ position: new p5.Vector(0, 0) });
678
+ shape.beginShape();
679
+ shape.arcPrimitive(
680
+ x,
681
+ y,
682
+ w,
683
+ h,
684
+ start,
685
+ stop,
686
+ mode
687
687
  );
688
-
689
- // Fill curves
690
- if (this.states.fillColor) {
691
- ctx.beginPath();
692
- ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, start, stop);
693
- if (createPieSlice) ctx.lineTo(centerX, centerY);
694
- ctx.closePath();
695
- ctx.fill();
696
- }
697
-
698
- // Stroke curves
699
- if (this.states.strokeColor) {
700
- ctx.beginPath();
701
- ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, start, stop);
702
-
703
- if (mode === PIE && createPieSlice) {
704
- // In PIE mode, stroke is added to the center and back to path,
705
- // unless the pie forms a complete ellipse (see: createPieSlice)
706
- ctx.lineTo(centerX, centerY);
707
- }
708
-
709
- if (mode === PIE || mode === CHORD) {
710
- // Stroke connects back to path begin for both PIE and CHORD
711
- ctx.closePath();
712
- }
713
- ctx.stroke();
714
- }
688
+ shape.endShape();
689
+ this.drawShape(shape);
715
690
 
716
691
  return this;
717
692
 
718
693
  }
719
694
 
720
695
  ellipse(args) {
721
- const ctx = this.drawingContext;
722
- const doFill = !!this.states.fillColor,
723
- doStroke = this.states.strokeColor;
724
696
  const x = parseFloat(args[0]),
725
697
  y = parseFloat(args[1]),
726
698
  w = parseFloat(args[2]),
727
699
  h = parseFloat(args[3]);
728
- if (doFill && !doStroke) {
729
- if (this._getFill() === styleEmpty) {
730
- return this;
731
- }
732
- } else if (!doFill && doStroke) {
733
- if (this._getStroke() === styleEmpty) {
734
- return this;
735
- }
736
- }
737
- const centerX = x + w / 2,
738
- centerY = y + h / 2,
739
- radiusX = w / 2,
740
- radiusY = h / 2;
741
- if (this._clipping) {
742
- const tempPath = new Path2D();
743
- tempPath.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
744
- const currentTransform = this.drawingContext.getTransform();
745
- const clipBaseTransform = this._clipBaseTransform.inverse();
746
- const relativeTransform = clipBaseTransform.multiply(currentTransform);
747
- this.clipPath.addPath(tempPath, relativeTransform);
748
- return this;
749
- }
750
- ctx.beginPath();
751
- ctx.ellipse(centerX, centerY, radiusX, radiusY, 0, 0, 2 * Math.PI);
752
- ctx.closePath();
753
- if (doFill) {
754
- ctx.fill();
755
- }
756
- if (doStroke) {
757
- ctx.stroke();
758
- }
759
700
 
701
+ const shape = new p5.Shape({ position: new p5.Vector(0, 0) });
702
+ shape.beginShape();
703
+ shape.ellipsePrimitive(x,y,w,h);
704
+ shape.endShape();
705
+ this.drawShape(shape);
760
706
  return this;
761
707
  }
762
708
 
@@ -1000,6 +946,9 @@ class Renderer2D extends Renderer {
1000
946
  //////////////////////////////////////////////
1001
947
 
1002
948
  strokeCap(cap) {
949
+ if (typeof cap === 'undefined') { // getter
950
+ return this.drawingContext.lineCap;
951
+ }
1003
952
  if (
1004
953
  cap === ROUND ||
1005
954
  cap === SQUARE ||
@@ -1011,6 +960,9 @@ class Renderer2D extends Renderer {
1011
960
  }
1012
961
 
1013
962
  strokeJoin(join) {
963
+ if (typeof join === 'undefined') { // getter
964
+ return this.drawingContext.lineJoin;
965
+ }
1014
966
  if (
1015
967
  join === ROUND ||
1016
968
  join === BEVEL ||
@@ -1023,7 +975,10 @@ class Renderer2D extends Renderer {
1023
975
 
1024
976
  strokeWeight(w) {
1025
977
  super.strokeWeight(w);
1026
- if (typeof w === 'undefined' || w === 0) {
978
+ if (typeof w === 'undefined') {
979
+ return this.states.strokeWeight;
980
+ }
981
+ if (w === 0) {
1027
982
  // hack because lineWidth 0 doesn't work
1028
983
  this.drawingContext.lineWidth = 0.0001;
1029
984
  } else {
@@ -1086,16 +1041,22 @@ class Renderer2D extends Renderer {
1086
1041
 
1087
1042
  rotate(rad) {
1088
1043
  this.drawingContext.rotate(rad);
1044
+ return this;
1089
1045
  }
1090
1046
 
1091
1047
  scale(x, y) {
1048
+ // support passing objects with x,y properties (including p5.Vector)
1049
+ if (typeof x === 'object' && 'x' in x && 'y' in x) {
1050
+ y = x.y;
1051
+ x = x.x;
1052
+ }
1092
1053
  this.drawingContext.scale(x, y);
1093
1054
  return this;
1094
1055
  }
1095
1056
 
1096
1057
  translate(x, y) {
1097
- // support passing a vector as the 1st parameter
1098
- if (x instanceof p5.Vector) {
1058
+ // support passing objects with x,y properties (including p5.Vector)
1059
+ if (typeof x === 'object' && 'x' in x && 'y' in x) {
1099
1060
  y = x.y;
1100
1061
  x = x.x;
1101
1062
  }
@@ -1257,7 +1218,6 @@ function renderer2D(p5, fn){
1257
1218
  * @module Structure
1258
1219
  * @submodule Structure
1259
1220
  * @for p5
1260
- * @requires constants
1261
1221
  */
1262
1222
 
1263
1223
 
@@ -1289,6 +1249,7 @@ class p5 {
1289
1249
  // This is a pointer to our global mode p5 instance, if we're in
1290
1250
  // global mode.
1291
1251
  static instance = null;
1252
+ static sketchCount = 0;
1292
1253
  static lifecycleHooks = {
1293
1254
  presetup: [],
1294
1255
  postsetup: [],
@@ -1304,7 +1265,7 @@ class p5 {
1304
1265
  constructor(sketch, node) {
1305
1266
  // Apply addon defined decorations
1306
1267
  if(p5.decorations.size > 0){
1307
- decorateClass(p5, p5.decorations);
1268
+ decorateClass(p5, p5.decorations, 'p5');
1308
1269
  p5.decorations.clear();
1309
1270
  }
1310
1271
 
@@ -1379,19 +1340,24 @@ class p5 {
1379
1340
  const blurHandler = () => {
1380
1341
  this.focused = false;
1381
1342
  };
1382
- window.addEventListener('focus', focusHandler);
1383
- window.addEventListener('blur', blurHandler);
1384
- p5.lifecycleHooks.remove.push(function() {
1385
- window.removeEventListener('focus', focusHandler);
1386
- window.removeEventListener('blur', blurHandler);
1387
- });
1388
1343
 
1389
- // Initialization complete, start runtime
1390
- if (document.readyState === 'complete') {
1344
+ if(typeof window !== 'undefined'){
1345
+ window.addEventListener('focus', focusHandler);
1346
+ window.addEventListener('blur', blurHandler);
1347
+ p5.lifecycleHooks.remove.push(function() {
1348
+ window.removeEventListener('focus', focusHandler);
1349
+ window.removeEventListener('blur', blurHandler);
1350
+ });
1351
+
1352
+ // Initialization complete, start runtime
1353
+ if (document.readyState === 'complete') {
1354
+ this.#_start();
1355
+ } else {
1356
+ this._startListener = this.#_start.bind(this);
1357
+ window.addEventListener('load', this._startListener, false);
1358
+ }
1359
+ }else {
1391
1360
  this.#_start();
1392
- } else {
1393
- this._startListener = this.#_start.bind(this);
1394
- window.addEventListener('load', this._startListener, false);
1395
1361
  }
1396
1362
  }
1397
1363
 
@@ -1478,15 +1444,17 @@ class p5 {
1478
1444
  // Always create a default canvas.
1479
1445
  // Later on if the user calls createCanvas, this default one
1480
1446
  // will be replaced
1481
- this.createCanvas(
1482
- 100,
1483
- 100,
1484
- P2D
1485
- );
1447
+ if(typeof window !== 'undefined'){
1448
+ this.createCanvas(
1449
+ 100,
1450
+ 100,
1451
+ P2D
1452
+ );
1453
+ }
1486
1454
 
1487
1455
  // Record the time when setup starts. millis() will start at 0 within
1488
1456
  // setup, but this isn't documented, locked-in behavior yet.
1489
- this._millisStart = window.performance.now();
1457
+ this._millisStart = globalThis.performance.now();
1490
1458
 
1491
1459
  const context = this._isGlobal ? window : this;
1492
1460
  if (typeof context.setup === 'function') {
@@ -1494,21 +1462,23 @@ class p5 {
1494
1462
  }
1495
1463
  if (this.hitCriticalError) return;
1496
1464
 
1497
- const canvases = document.getElementsByTagName('canvas');
1498
- for (const k of canvases) {
1499
- // Apply touchAction = 'none' to canvases to prevent scrolling
1500
- // when dragging on canvas elements
1501
- k.style.touchAction = 'none';
1502
-
1503
- // unhide any hidden canvases that were created
1504
- if (k.dataset.hidden === 'true') {
1505
- k.style.visibility = '';
1506
- delete k.dataset.hidden;
1465
+ if(typeof document !== 'undefined'){
1466
+ const canvases = document.getElementsByTagName('canvas');
1467
+ for (const k of canvases) {
1468
+ // Apply touchAction = 'none' to canvases to prevent scrolling
1469
+ // when dragging on canvas elements
1470
+ k.style.touchAction = 'none';
1471
+
1472
+ // unhide any hidden canvases that were created
1473
+ if (k.dataset.hidden === 'true') {
1474
+ k.style.visibility = '';
1475
+ delete k.dataset.hidden;
1476
+ }
1507
1477
  }
1508
1478
  }
1509
1479
 
1510
- this._lastTargetFrameTime = window.performance.now();
1511
- this._lastRealFrameTime = window.performance.now();
1480
+ this._lastTargetFrameTime = globalThis.performance.now();
1481
+ this._lastRealFrameTime = globalThis.performance.now();
1512
1482
  this._setupDone = true;
1513
1483
  if (this._accessibleOutputs.grid || this._accessibleOutputs.text) {
1514
1484
  this._updateAccsOutput();
@@ -1519,7 +1489,7 @@ class p5 {
1519
1489
 
1520
1490
  // Record the time when the draw loop starts so that millis() starts at 0
1521
1491
  // when the draw loop begins.
1522
- this._millisStart = window.performance.now();
1492
+ this._millisStart = globalThis.performance.now();
1523
1493
  }
1524
1494
 
1525
1495
  // While '#_draw' here is async, it is not awaited as 'requestAnimationFrame'
@@ -1529,7 +1499,7 @@ class p5 {
1529
1499
  // and 'postdraw'.
1530
1500
  async _draw(requestAnimationFrameTimestamp) {
1531
1501
  if (this.hitCriticalError) return;
1532
- const now = requestAnimationFrameTimestamp || window.performance.now();
1502
+ const now = requestAnimationFrameTimestamp || globalThis.performance.now();
1533
1503
  const timeSinceLastFrame = now - this._lastTargetFrameTime;
1534
1504
  const targetTimeBetweenFrames = 1000 / this._targetFrameRate;
1535
1505
 
@@ -1571,9 +1541,10 @@ class p5 {
1571
1541
  // get notified the next time the browser gives us
1572
1542
  // an opportunity to draw.
1573
1543
  if (this._loop) {
1574
- this._requestAnimId = window.requestAnimationFrame(
1575
- this._draw.bind(this)
1576
- );
1544
+ const boundDraw = this._draw.bind(this);
1545
+ this._requestAnimId = typeof window !== 'undefined' ?
1546
+ window.requestAnimationFrame(boundDraw) :
1547
+ setImmediate(boundDraw);
1577
1548
  }
1578
1549
  }
1579
1550
 
@@ -1775,7 +1746,6 @@ function createBindGlobal(instance) {
1775
1746
 
1776
1747
  // Generic function to decorate classes
1777
1748
  function decorateClass(Target, decorations, path){
1778
- path ??= Target.name;
1779
1749
  // Static properties
1780
1750
  for(const key in Target){
1781
1751
  if(!key.startsWith('_')){
@@ -1917,6 +1887,7 @@ p5.registerAddon(graphics);
1917
1887
  *
1918
1888
  * @method setup
1919
1889
  * @for p5
1890
+ * @return {void|Promise<void>}
1920
1891
  *
1921
1892
  * @example
1922
1893
  * function setup() {
@@ -1,6 +1,6 @@
1
1
  import { Vector } from '../p5.Vector.js';
2
2
  import { MatrixInterface } from './MatrixInterface.js';
3
- import '../../constants-BdTiYOQI.js';
3
+ import '../../constants-0wkVUfqa.js';
4
4
 
5
5
  /**
6
6
  * @module Math
@@ -1,7 +1,7 @@
1
1
  import nj from '@d4c/numjs/build/module/numjs.min.js';
2
2
  import { Vector } from '../p5.Vector.js';
3
3
  import { MatrixInterface } from './MatrixInterface.js';
4
- import '../../constants-BdTiYOQI.js';
4
+ import '../../constants-0wkVUfqa.js';
5
5
 
6
6
  let isMatrixArray = x => Array.isArray(x);
7
7
  if (typeof Float32Array !== 'undefined') {
@@ -2,7 +2,6 @@
2
2
  * @module Math
3
3
  * @submodule Calculation
4
4
  * @for p5
5
- * @requires core
6
5
  */
7
6
 
8
7
  function calculation(p5, fn){
@@ -4,7 +4,8 @@ import random from './random.js';
4
4
  import trigonometry from './trigonometry.js';
5
5
  import math$1 from './math.js';
6
6
  import vector from './p5.Vector.js';
7
- import '../constants-BdTiYOQI.js';
7
+ import vectorValidation from './patch-vector.js';
8
+ import '../constants-0wkVUfqa.js';
8
9
 
9
10
  function math(p5){
10
11
  p5.registerAddon(calculation);
@@ -13,6 +14,7 @@ function math(p5){
13
14
  p5.registerAddon(trigonometry);
14
15
  p5.registerAddon(math$1);
15
16
  p5.registerAddon(vector);
17
+ p5.registerAddon(vectorValidation);
16
18
  }
17
19
 
18
20
  export { math as default };
package/dist/math/math.js CHANGED
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * @module Math
3
3
  * @for p5
4
- * @requires core
5
4
  */
6
5
 
7
6
  function math(p5, fn) {
@@ -38,7 +37,7 @@ function math(p5, fn) {
38
37
  * <a href="#/p5.Vector">p5.Vector</a> class.
39
38
  *
40
39
  * @method createVector
41
- * @param {...Number} x Zero or more numbers, representing each component of the vector.
40
+ * @param {...Number} x List of numbers representing each component of the vector.
42
41
  * @return {p5.Vector} new <a href="#/p5.Vector">p5.Vector</a> object.
43
42
  *
44
43
  * @example
@@ -92,21 +91,8 @@ function math(p5, fn) {
92
91
  * point(pos);
93
92
  * }
94
93
  */
95
- fn.createVector = function (x, y, z) {
96
- if (arguments.length === 0) {
97
- p5._friendlyError(
98
- 'In 1.x, createVector() was a shortcut for createVector(0, 0, 0). In 2.x, p5.js has vectors of any dimension, so you must provide your desired number of zeros. Use createVector(0, 0) for a 2D vector and createVector(0, 0, 0) for a 3D vector.'
99
- );
100
- }
101
- if (this instanceof p5) {
102
- return new p5.Vector(
103
- this._fromRadians.bind(this),
104
- this._toRadians.bind(this),
105
- ...arguments
106
- );
107
- } else {
108
- return new p5.Vector(x, y, z);
109
- }
94
+ fn.createVector = function (...args) {
95
+ return new p5.Vector(...args);
110
96
  };
111
97
 
112
98
  /**
@@ -15,7 +15,6 @@
15
15
  * @module Math
16
16
  * @submodule Noise
17
17
  * @for p5
18
- * @requires core
19
18
  */
20
19
  function noise(p5, fn){
21
20
  const PERLIN_YWRAPB = 4;
@@ -1,11 +1,10 @@
1
1
  import { Matrix } from './Matrices/Matrix.js';
2
2
  import './p5.Vector.js';
3
- import '../constants-BdTiYOQI.js';
3
+ import '../constants-0wkVUfqa.js';
4
4
  import './Matrices/MatrixInterface.js';
5
5
 
6
6
  /**
7
7
  * @module Math
8
- * @requires constants
9
8
  * @todo see methods below needing further implementation.
10
9
  * future consideration: implement SIMD optimizations
11
10
  * when browser compatibility becomes available