p5 2.0.0 → 2.0.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 (188) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +2 -2
  3. package/{src → dist}/accessibility/gridOutput.js +2 -2
  4. package/dist/accessibility/index.js +60 -0
  5. package/{src → dist}/accessibility/outputs.js +2 -2
  6. package/{src → dist}/accessibility/textOutput.js +2 -2
  7. package/dist/app.js +120 -0
  8. package/{src → dist}/color/color_conversion.js +48 -10
  9. package/{src → dist}/color/color_spaces/hsb.js +3 -1
  10. package/dist/color/creating_reading.js +3 -0
  11. package/dist/color/index.js +13 -0
  12. package/dist/color/p5.Color.culori.js +1 -0
  13. package/dist/color/p5.Color.js +3 -0
  14. package/{src → dist}/color/setting.js +9 -6
  15. package/{src/core/constants.js → dist/constants-C-g_eAdC.js} +266 -130
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +7 -6
  19. package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
  20. package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
  21. package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
  22. package/dist/core/friendly_errors/index.js +23 -0
  23. package/dist/core/friendly_errors/param_validator.js +5455 -0
  24. package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
  25. package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
  26. package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
  27. package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
  28. package/{src → dist}/core/helpers.js +9 -6
  29. package/dist/core/init.js +105 -0
  30. package/dist/core/internationalization.js +302 -0
  31. package/dist/core/legacy.js +73 -0
  32. package/dist/core/main.js +44 -0
  33. package/dist/core/noop.js +3 -0
  34. package/dist/core/p5.Graphics.js +40 -0
  35. package/dist/core/p5.Renderer.js +11 -0
  36. package/dist/core/p5.Renderer2D.js +44 -0
  37. package/dist/core/reference.js +1 -0
  38. package/dist/core/rendering.js +40 -0
  39. package/{src → dist}/core/structure.js +3 -3
  40. package/{src → dist}/core/transform.js +2 -2
  41. package/{src/color/creating_reading.js → dist/creating_reading-D4AAKRbx.js} +841 -13
  42. package/{src → dist}/data/index.js +3 -1
  43. package/{src → dist}/data/local_storage.js +2 -8
  44. package/{src → dist}/dom/dom.js +11 -5
  45. package/dist/dom/index.js +18 -0
  46. package/{src → dist}/dom/p5.Element.js +14 -12
  47. package/{src → dist}/dom/p5.File.js +4 -4
  48. package/{src → dist}/dom/p5.MediaElement.js +10 -4
  49. package/{src → dist}/events/acceleration.js +2 -2
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -11
  52. package/{src → dist}/events/pointer.js +16 -17
  53. package/dist/image/const.js +9 -0
  54. package/{src → dist}/image/filterRenderer2D.js +57 -37
  55. package/{src → dist}/image/filters.js +1 -3
  56. package/dist/image/image.js +40 -0
  57. package/dist/image/index.js +51 -0
  58. package/dist/image/loading_displaying.js +40 -0
  59. package/dist/image/p5.Image.js +11 -0
  60. package/{src → dist}/image/pixels.js +4 -3
  61. package/{src → dist}/io/csv.js +72 -70
  62. package/dist/io/files.js +40 -0
  63. package/dist/io/index.js +51 -0
  64. package/{src → dist}/io/p5.Table.js +6 -6
  65. package/{src → dist}/io/p5.TableRow.js +3 -4
  66. package/{src → dist}/io/p5.XML.js +2 -5
  67. package/{src → dist}/io/utilities.js +1 -1
  68. package/{src/core/p5.Renderer2D.js → dist/main-s72KWcUy.js} +735 -57
  69. package/{src → dist}/math/Matrices/Matrix.js +10 -8
  70. package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
  71. package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
  72. package/{src → dist}/math/calculation.js +2 -2
  73. package/{src → dist}/math/index.js +6 -3
  74. package/{src → dist}/math/math.js +2 -2
  75. package/{src → dist}/math/noise.js +2 -2
  76. package/{src → dist}/math/p5.Matrix.js +7 -4
  77. package/{src → dist}/math/p5.Vector.js +6 -6
  78. package/{src → dist}/math/random.js +2 -2
  79. package/{src → dist}/math/trigonometry.js +16 -15
  80. package/{src/image/p5.Image.js → dist/p5.Renderer-CwAYZOC2.js} +390 -19
  81. package/dist/rendering--aAe5aq3.js +24925 -0
  82. package/{src → dist}/shape/2d_primitives.js +18 -17
  83. package/{src → dist}/shape/attributes.js +18 -17
  84. package/{src → dist}/shape/curves.js +2 -2
  85. package/{src → dist}/shape/custom_shapes.js +44 -64
  86. package/{src → dist}/shape/index.js +10 -2
  87. package/{src → dist}/shape/vertex.js +2 -3
  88. package/dist/type/index.js +25 -0
  89. package/{src → dist}/type/lib/Typr.js +76 -94
  90. package/{src → dist}/type/p5.Font.js +37 -61
  91. package/{src → dist}/type/textCore.js +34 -57
  92. package/{src → dist}/type/unicodeRanges.js +3 -1
  93. package/{src → dist}/utilities/conversion.js +2 -2
  94. package/{src → dist}/utilities/index.js +3 -1
  95. package/{src → dist}/utilities/time_date.js +6 -7
  96. package/{src → dist}/utilities/utility_functions.js +2 -2
  97. package/dist/webgl/3d_primitives.js +40 -0
  98. package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
  99. package/{src → dist}/webgl/GeometryBuilder.js +12 -8
  100. package/{src → dist}/webgl/ShaderGenerator.js +79 -82
  101. package/{src → dist}/webgl/ShapeBuilder.js +26 -23
  102. package/dist/webgl/index.js +76 -0
  103. package/{src → dist}/webgl/interaction.js +7 -6
  104. package/dist/webgl/light.js +40 -0
  105. package/{src → dist}/webgl/loading.js +45 -12
  106. package/dist/webgl/material.js +40 -0
  107. package/dist/webgl/p5.Camera.js +40 -0
  108. package/{src → dist}/webgl/p5.DataArray.js +3 -5
  109. package/dist/webgl/p5.Framebuffer.js +40 -0
  110. package/{src → dist}/webgl/p5.Geometry.js +12 -15
  111. package/{src → dist}/webgl/p5.Quat.js +5 -4
  112. package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
  113. package/dist/webgl/p5.RendererGL.js +40 -0
  114. package/dist/webgl/p5.Shader.js +40 -0
  115. package/dist/webgl/p5.Texture.js +40 -0
  116. package/{src → dist}/webgl/text.js +51 -9
  117. package/lib/p5.esm.js +102 -48
  118. package/lib/p5.js +102 -48
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -16
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/src/README.md +0 -27
  124. package/src/accessibility/index.js +0 -13
  125. package/src/app.js +0 -61
  126. package/src/color/index.js +0 -9
  127. package/src/color/p5.Color.culori.js +0 -66
  128. package/src/color/p5.Color.js +0 -851
  129. package/src/core/README.md +0 -91
  130. package/src/core/friendly_errors/index.js +0 -13
  131. package/src/core/friendly_errors/param_validator.js +0 -561
  132. package/src/core/init.js +0 -58
  133. package/src/core/internationalization.js +0 -195
  134. package/src/core/legacy.js +0 -29
  135. package/src/core/main.js +0 -689
  136. package/src/core/noop.js +0 -1
  137. package/src/core/p5.Graphics.js +0 -696
  138. package/src/core/p5.Renderer.js +0 -408
  139. package/src/core/reference.js +0 -2060
  140. package/src/core/rendering.js +0 -697
  141. package/src/dom/index.js +0 -11
  142. package/src/image/const.js +0 -6
  143. package/src/image/image.js +0 -731
  144. package/src/image/index.js +0 -15
  145. package/src/image/loading_displaying.js +0 -1431
  146. package/src/io/files.js +0 -2210
  147. package/src/io/index.js +0 -11
  148. package/src/math/README.md +0 -40
  149. package/src/type/index.js +0 -9
  150. package/src/webgl/3d_primitives.js +0 -2741
  151. package/src/webgl/index.js +0 -37
  152. package/src/webgl/light.js +0 -1851
  153. package/src/webgl/material.js +0 -3854
  154. package/src/webgl/p5.Camera.js +0 -4010
  155. package/src/webgl/p5.Framebuffer.js +0 -1865
  156. package/src/webgl/p5.RendererGL.js +0 -2867
  157. package/src/webgl/p5.Shader.js +0 -1505
  158. package/src/webgl/p5.Texture.js +0 -541
  159. package/src/webgl/shaders/basic.frag +0 -6
  160. package/src/webgl/shaders/filters/base.frag +0 -22
  161. package/src/webgl/shaders/filters/base.vert +0 -19
  162. package/src/webgl/shaders/filters/blur.frag +0 -60
  163. package/src/webgl/shaders/filters/default.vert +0 -18
  164. package/src/webgl/shaders/filters/dilate.frag +0 -39
  165. package/src/webgl/shaders/filters/erode.frag +0 -39
  166. package/src/webgl/shaders/filters/gray.frag +0 -16
  167. package/src/webgl/shaders/filters/invert.frag +0 -15
  168. package/src/webgl/shaders/filters/opaque.frag +0 -12
  169. package/src/webgl/shaders/filters/posterize.frag +0 -29
  170. package/src/webgl/shaders/filters/threshold.frag +0 -23
  171. package/src/webgl/shaders/font.frag +0 -216
  172. package/src/webgl/shaders/font.vert +0 -44
  173. package/src/webgl/shaders/imageLight.vert +0 -33
  174. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  175. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  176. package/src/webgl/shaders/light.vert +0 -37
  177. package/src/webgl/shaders/light_texture.frag +0 -26
  178. package/src/webgl/shaders/lighting.glsl +0 -227
  179. package/src/webgl/shaders/line.frag +0 -74
  180. package/src/webgl/shaders/line.vert +0 -294
  181. package/src/webgl/shaders/normal.frag +0 -6
  182. package/src/webgl/shaders/normal.vert +0 -72
  183. package/src/webgl/shaders/phong.frag +0 -84
  184. package/src/webgl/shaders/phong.vert +0 -87
  185. package/src/webgl/shaders/point.frag +0 -29
  186. package/src/webgl/shaders/point.vert +0 -19
  187. package/src/webgl/shaders/sphereMapping.frag +0 -26
  188. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
@@ -1,24 +1,25 @@
1
+ import { parse } from 'acorn';
2
+ import { ancestor } from 'acorn-walk';
3
+ import escodegen from 'escodegen';
4
+
1
5
  /**
2
6
  * @module 3D
3
7
  * @submodule ShaderGenerator
4
8
  * @for p5
5
9
  * @requires core
6
10
  */
7
- import { parse } from 'acorn';
8
- import { ancestor } from 'acorn-walk';
9
- import escodegen from 'escodegen';
10
11
 
11
12
  function shadergenerator(p5, fn) {
12
13
  let GLOBAL_SHADER;
13
14
  let BRANCH;
14
15
 
15
- const oldModify = p5.Shader.prototype.modify
16
+ const oldModify = p5.Shader.prototype.modify;
16
17
 
17
18
  p5.Shader.prototype.modify = function(shaderModifier, options = { parser: true, srcLocations: false }) {
18
19
  if (shaderModifier instanceof Function) {
19
20
  let generatorFunction;
20
21
  if (options.parser) {
21
- const sourceString = shaderModifier.toString()
22
+ const sourceString = shaderModifier.toString();
22
23
  const ast = parse(sourceString, {
23
24
  ecmaVersion: 2021,
24
25
  locations: options.srcLocations
@@ -42,7 +43,7 @@ function shadergenerator(p5, fn) {
42
43
  else {
43
44
  return oldModify.call(this, shaderModifier)
44
45
  }
45
- }
46
+ };
46
47
 
47
48
  // AST Transpiler Callbacks and helper functions
48
49
  function replaceBinaryOperator(codeSource) {
@@ -75,16 +76,16 @@ function shadergenerator(p5, fn) {
75
76
  const signNode = {
76
77
  type: 'Literal',
77
78
  value: node.operator,
78
- }
79
+ };
79
80
 
80
81
  const standardReplacement = (node) => {
81
- node.type = 'CallExpression'
82
+ node.type = 'CallExpression';
82
83
  node.callee = {
83
84
  type: 'Identifier',
84
85
  name: 'unaryNode',
85
- }
86
- node.arguments = [node.argument, signNode]
87
- }
86
+ };
87
+ node.arguments = [node.argument, signNode];
88
+ };
88
89
 
89
90
  if (node.type === 'MemberExpression') {
90
91
  const property = node.argument.property.name;
@@ -126,14 +127,14 @@ function shadergenerator(p5, fn) {
126
127
  const uniformNameLiteral = {
127
128
  type: 'Literal',
128
129
  value: node.id.name
129
- }
130
+ };
130
131
  node.init.arguments.unshift(uniformNameLiteral);
131
132
  }
132
133
  if (node.init.callee && node.init.callee.name?.startsWith('varying')) {
133
134
  const varyingNameLiteral = {
134
135
  type: 'Literal',
135
136
  value: node.id.name
136
- }
137
+ };
137
138
  node.init.arguments.unshift(varyingNameLiteral);
138
139
  _state.varyings[node.id.name] = varyingNameLiteral;
139
140
  }
@@ -156,7 +157,7 @@ function shadergenerator(p5, fn) {
156
157
  },
157
158
  },
158
159
  arguments: [],
159
- }
160
+ };
160
161
  }
161
162
  },
162
163
  // The callbacks for AssignmentExpression and BinaryExpression handle
@@ -184,7 +185,7 @@ function shadergenerator(p5, fn) {
184
185
  },
185
186
  },
186
187
  arguments: [node.right]
187
- }
188
+ };
188
189
  node.operator = '=';
189
190
  node.right = rightReplacementNode;
190
191
  }
@@ -204,7 +205,7 @@ function shadergenerator(p5, fn) {
204
205
  }
205
206
  },
206
207
  arguments: [node.right],
207
- }
208
+ };
208
209
  }
209
210
  },
210
211
  BinaryExpression(node, _state, _ancestors) {
@@ -222,7 +223,7 @@ function shadergenerator(p5, fn) {
222
223
  name: 'dynamicNode',
223
224
  },
224
225
  arguments: [node.left]
225
- }
226
+ };
226
227
  node.left = leftReplacementNode;
227
228
  }
228
229
  // Replace the binary operator with a call expression
@@ -238,7 +239,7 @@ function shadergenerator(p5, fn) {
238
239
  };
239
240
  node.arguments = [node.right];
240
241
  },
241
- }
242
+ };
242
243
 
243
244
  // Javascript Node API.
244
245
  class BaseNode {
@@ -262,8 +263,7 @@ function shadergenerator(p5, fn) {
262
263
  } catch (e) {
263
264
  const lines = e.stack.split('\n');
264
265
  let userSketchLineIndex = 5;
265
- if (isBinaryExpressionNode(this)) { userSketchLineIndex--; };
266
- this.srcLine = lines[userSketchLineIndex].trim();
266
+ if (isBinaryExpressionNode(this)) { userSketchLineIndex--; } this.srcLine = lines[userSketchLineIndex].trim();
267
267
  }
268
268
  }
269
269
  }
@@ -287,7 +287,7 @@ function shadergenerator(p5, fn) {
287
287
  value = newValue;
288
288
  }
289
289
  }
290
- })
290
+ });
291
291
  }
292
292
  }
293
293
  }
@@ -345,7 +345,7 @@ function shadergenerator(p5, fn) {
345
345
  } else {
346
346
  result = this.toGLSL(context);
347
347
  }
348
- this.checkConditionalDependencies(context)
348
+ this.checkConditionalDependencies(context);
349
349
  return result;
350
350
  }
351
351
 
@@ -453,7 +453,7 @@ function shadergenerator(p5, fn) {
453
453
  x = x[0];
454
454
  }
455
455
  if (_parent) {
456
- const { parent, name } = _parent
456
+ const { parent, name } = _parent;
457
457
  this.name = name;
458
458
  this.parent = parent;
459
459
  }
@@ -500,7 +500,7 @@ function shadergenerator(p5, fn) {
500
500
  value = isFloatNode(newValue) ? newValue : new FloatNode(newValue, true, info);
501
501
  }
502
502
  }
503
- })
503
+ });
504
504
  });
505
505
  this.originalValues = this.componentNames.map(name => this[name]);
506
506
  }
@@ -531,16 +531,15 @@ function shadergenerator(p5, fn) {
531
531
  if (expectedArgType === 'genType') {
532
532
  // We allow conversions from float -> vec if one argument is a vector.
533
533
  if (genType === undefined || (genType === 'float' && userType.startsWith('vec'))) {
534
- genType = userType
535
- };
536
- expectedArgType = genType;
534
+ genType = userType;
535
+ } expectedArgType = genType;
537
536
  }
538
537
  similarity += (userType === expectedArgType);
539
538
  return userType === expectedArgType || (userType === 'float' && expectedArgType.startsWith('vec'));
540
- })
539
+ });
541
540
 
542
541
  return { ...props, valid, similarity, genType }
543
- }
542
+ };
544
543
 
545
544
  if (Array.isArray(properties)) {
546
545
  // Check if the right number of parameters were provided
@@ -560,7 +559,7 @@ function shadergenerator(p5, fn) {
560
559
  best = current;
561
560
  }
562
561
  return best;
563
- }
562
+ };
564
563
  functionSignature = possibleOverloads.reduce(findBestOverload, null);
565
564
  } else {
566
565
  functionSignature = determineFunctionSignature(properties);
@@ -588,7 +587,7 @@ function shadergenerator(p5, fn) {
588
587
  arg = nodeConstructors[functionSignature.genType](arg);
589
588
  }
590
589
  return arg;
591
- })
590
+ });
592
591
 
593
592
  if (functionSignature.returnType === 'genType') {
594
593
  functionSignature.returnType = functionSignature.genType;
@@ -665,7 +664,7 @@ function shadergenerator(p5, fn) {
665
664
  let { value } = val;
666
665
  context.declarations.push(` ${this.name} = ${value.toGLSLBase(context)};`);
667
666
  if (i === values.length - 1) {
668
- const tempName = `${this.name}_${this.tempVars++}`
667
+ const tempName = `${this.name}_${this.tempVars++}`;
669
668
  snapshot = dynamicAddSwizzleTrap(new VariableNode(tempName, this.type, true));
670
669
  context.declarations.push(` ${this.type} ${tempName} = ${this.name};`);
671
670
  }
@@ -677,10 +676,10 @@ function shadergenerator(p5, fn) {
677
676
 
678
677
  bridge(value) {
679
678
  if (!isShaderNode(value) || this.type.startsWith('vec') && getType(value) === 'float') {
680
- value = nodeConstructors[this.type](value)
679
+ value = nodeConstructors[this.type](value);
681
680
  }
682
681
  GLOBAL_SHADER.registerVarying(this, value);
683
- this.timesChanged += 1
682
+ this.timesChanged += 1;
684
683
  }
685
684
  }
686
685
 
@@ -755,7 +754,7 @@ function shadergenerator(p5, fn) {
755
754
 
756
755
  class UnaryExpressionNode extends BaseNode {
757
756
  constructor(node, operator, isInternal = false) {
758
- super(isInternal, node.type)
757
+ super(isInternal, node.type);
759
758
  this.node = node;
760
759
  this.operator = operator;
761
760
  }
@@ -763,7 +762,7 @@ function shadergenerator(p5, fn) {
763
762
  toGLSL(context) {
764
763
  let mainStr = this.node.toGLSLBase(context);
765
764
  if (!isVariableNode(this.node) && !hasTemporaryVariable(this.node) && !isPrimitiveNode(this.node)) {
766
- mainStr = `(${mainStr})`
765
+ mainStr = `(${mainStr})`;
767
766
  }
768
767
  return `${this.operator}${mainStr}`
769
768
  }
@@ -772,34 +771,34 @@ function shadergenerator(p5, fn) {
772
771
  // Conditions and logical modifiers
773
772
  BaseNode.prototype.equalTo = function(other) {
774
773
  return binaryExpressionNodeConstructor(this, this.enforceType(other), '==');
775
- }
774
+ };
776
775
 
777
776
  BaseNode.prototype.greaterThan = function(other) {
778
777
  return binaryExpressionNodeConstructor(this, this.enforceType(other), '>');
779
- }
778
+ };
780
779
 
781
780
  BaseNode.prototype.greaterThanEqualTo = function(other) {
782
781
  return binaryExpressionNodeConstructor(this, this.enforceType(other), '>=');
783
- }
782
+ };
784
783
 
785
784
  BaseNode.prototype.lessThan = function(other) {
786
785
  return binaryExpressionNodeConstructor(this, this.enforceType(other), '<');
787
- }
786
+ };
788
787
 
789
788
  BaseNode.prototype.lessThanEqualTo = function(other) {
790
- return binaryExpressionNodeConstructor(this, this.enforceType(other), '<='); }
789
+ return binaryExpressionNodeConstructor(this, this.enforceType(other), '<='); };
791
790
 
792
791
  BaseNode.prototype.not = function() {
793
792
  return new UnaryExpressionNode(this.condition, '!', true);
794
- }
793
+ };
795
794
 
796
795
  BaseNode.prototype.or = function(other) {
797
796
  return new binaryExpressionNodeConstructor(this, this.enforceType(other), '||', true);
798
- }
797
+ };
799
798
 
800
799
  BaseNode.prototype.and = function(other) {
801
800
  return new binaryExpressionNodeConstructor(this, this.enforceType(other), '&&', true);
802
- }
801
+ };
803
802
 
804
803
  function branch(callback) {
805
804
  const branch = new BranchNode();
@@ -838,7 +837,7 @@ function shadergenerator(p5, fn) {
838
837
 
839
838
  else(branchCallback) {
840
839
  this.elseBranch = branch(branchCallback);
841
- this.elseBranch.parent = this
840
+ this.elseBranch.parent = this;
842
841
  return this;
843
842
  }
844
843
 
@@ -874,7 +873,7 @@ function shadergenerator(p5, fn) {
874
873
  codelines.push(` else if (${condition.toGLSL(context)}) {`);
875
874
  codelines.push(`\n ${elseBranch.toGLSL(context)}`);
876
875
  codelines.push(`\n }`);
877
- })
876
+ });
878
877
  }
879
878
 
880
879
  if (this.elseBranch) {
@@ -885,14 +884,13 @@ function shadergenerator(p5, fn) {
885
884
  codelines.push('\n');
886
885
  return codelines.flat().join('');
887
886
  }
888
- };
889
-
887
+ }
890
888
  fn.assign = function(node, value) {
891
889
  if (!BRANCH) {
892
890
  throw new error('assign() is supposed to be used inside of conditional branchs. Use the "=" operator as normal otherwise.');
893
891
  }
894
892
  BRANCH.assign(node, value);
895
- }
893
+ };
896
894
 
897
895
  class BranchNode {
898
896
  constructor() {
@@ -907,10 +905,10 @@ function shadergenerator(p5, fn) {
907
905
  return parent;
908
906
  },
909
907
  set(newParent) {
910
- newParent.dependsOn.push(...this.dependsOn)
908
+ newParent.dependsOn.push(...this.dependsOn);
911
909
  parent = newParent;
912
910
  }
913
- })
911
+ });
914
912
  }
915
913
 
916
914
  assign(node, value) {
@@ -927,7 +925,7 @@ function shadergenerator(p5, fn) {
927
925
  return;
928
926
  }
929
927
  node.assertUsedInConditional(this);
930
- this.dependsOn.push(makeDependencyObject(node))
928
+ this.dependsOn.push(makeDependencyObject(node));
931
929
  if (value.shouldUseTemporaryVariable()) {
932
930
  value.assertUsedInConditional(this);
933
931
  this.dependsOn.push(makeDependencyObject(value));
@@ -960,11 +958,11 @@ function shadergenerator(p5, fn) {
960
958
  }
961
959
  else {
962
960
  node.temporaryVariable = `temp_${context.getNextID()}`;
963
- statement = `${node.type} ${node.toGLSLBase(context)} = ${result};`
961
+ statement = `${node.type} ${node.toGLSLBase(context)} = ${result};`;
964
962
  }
965
963
 
966
964
  this.statements.push(statement);
967
- })
965
+ });
968
966
 
969
967
  return this.statements.join(`\n `);
970
968
  }
@@ -1018,13 +1016,13 @@ function shadergenerator(p5, fn) {
1018
1016
  else if (Array.isArray(input)) {
1019
1017
  return nodeConstructors.dynamicVector(input);
1020
1018
  }
1021
- }
1019
+ };
1022
1020
 
1023
1021
  // For replacing unary expressions
1024
1022
  fn.unaryNode = function(input, sign) {
1025
1023
  input = dynamicNode(input);
1026
1024
  return dynamicAddSwizzleTrap(new UnaryExpressionNode(input, sign));
1027
- }
1025
+ };
1028
1026
 
1029
1027
  function isShaderNode(node) {
1030
1028
  return (node instanceof BaseNode);
@@ -1099,7 +1097,7 @@ function shadergenerator(p5, fn) {
1099
1097
  vertexDeclarations: new Set(),
1100
1098
  fragmentDeclarations: new Set(),
1101
1099
  uniforms: {},
1102
- }
1100
+ };
1103
1101
  this.uniformNodes = [];
1104
1102
  this.resetGLSLContext();
1105
1103
  this.isGenerating = false;
@@ -1126,7 +1124,7 @@ function shadergenerator(p5, fn) {
1126
1124
  const availableHooks = {
1127
1125
  ...originalShader.hooks.vertex,
1128
1126
  ...originalShader.hooks.fragment,
1129
- }
1127
+ };
1130
1128
 
1131
1129
  const windowOverrides = {};
1132
1130
 
@@ -1137,7 +1135,7 @@ function shadergenerator(p5, fn) {
1137
1135
  this[hookTypes.name] = function(userCallback) {
1138
1136
  // Create the initial nodes which are passed to the user callback
1139
1137
  // Also generate a string of the arguments for the code generation
1140
- const argNodes = []
1138
+ const argNodes = [];
1141
1139
  const argsArray = [];
1142
1140
 
1143
1141
  hookTypes.parameters.forEach((parameter) => {
@@ -1154,8 +1152,8 @@ function shadergenerator(p5, fn) {
1154
1152
  );
1155
1153
  }
1156
1154
  const qualifiers = parameter.type.qualifiers.length > 0 ? parameter.type.qualifiers.join(' ') : '';
1157
- argsArray.push(`${qualifiers} ${parameter.type.typeName} ${parameter.name}`.trim())
1158
- })
1155
+ argsArray.push(`${qualifiers} ${parameter.type.typeName} ${parameter.name}`.trim());
1156
+ });
1159
1157
 
1160
1158
  let returnedValue = userCallback(...argNodes);
1161
1159
  const expectedReturnType = hookTypes.returnType;
@@ -1170,7 +1168,7 @@ function shadergenerator(p5, fn) {
1170
1168
  });
1171
1169
  } else {
1172
1170
  if (!isShaderNode(returnedValue)) {
1173
- returnedValue = nodeConstructors[expectedReturnType.typeName](returnedValue)
1171
+ returnedValue = nodeConstructors[expectedReturnType.typeName](returnedValue);
1174
1172
  } else if (isFloatType(returnedValue) && expectedReturnType.typeName.startsWith('vec')) {
1175
1173
  returnedValue = nodeConstructors[expectedReturnType.typeName](returnedValue);
1176
1174
  }
@@ -1182,7 +1180,7 @@ function shadergenerator(p5, fn) {
1182
1180
  if (statement.usedIn.length === 0) { return; }
1183
1181
  const lines = statement.toGLSL(this.context);
1184
1182
  this.context.declarations.splice(statement.insertionPoint, 0, lines);
1185
- })
1183
+ });
1186
1184
  // Build the final GLSL string.
1187
1185
  // The order of this code is a bit confusing, we need to call toGLSLBase
1188
1186
  let codeLines = [
@@ -1193,7 +1191,7 @@ function shadergenerator(p5, fn) {
1193
1191
 
1194
1192
  Object.entries(toGLSLResults).forEach(([propertyName, result]) => {
1195
1193
  const propString = expectedReturnType.properties ? `.${propertyName}` : '';
1196
- codeLines.push(` finalReturnValue${propString} = ${result};`)
1194
+ codeLines.push(` finalReturnValue${propString} = ${result};`);
1197
1195
  });
1198
1196
 
1199
1197
  this.context.declarations = [];
@@ -1202,7 +1200,7 @@ function shadergenerator(p5, fn) {
1202
1200
  const finalVaryingAssignments = [];
1203
1201
  declArray.forEach(obj => {
1204
1202
  const { node, value } = obj;
1205
- finalVaryingAssignments.push(` ${node.name} = ${value.toGLSLBase(this.context)};`)
1203
+ finalVaryingAssignments.push(` ${node.name} = ${value.toGLSLBase(this.context)};`);
1206
1204
  finalVaryingAssignments.unshift(...this.context.declarations);
1207
1205
  node.timesChanged = 0;
1208
1206
  });
@@ -1212,7 +1210,7 @@ function shadergenerator(p5, fn) {
1212
1210
  codeLines.push(' return finalReturnValue;', '}');
1213
1211
  this.output[hookName] = codeLines.join('\n');
1214
1212
  this.resetGLSLContext();
1215
- }
1213
+ };
1216
1214
  windowOverrides[hookTypes.name] = window[hookTypes.name];
1217
1215
 
1218
1216
  // Expose the Functions to global scope for users to use
@@ -1269,18 +1267,18 @@ function shadergenerator(p5, fn) {
1269
1267
  return node[name]
1270
1268
  });
1271
1269
  const replacement = nodeConstructors[node.type](components);
1272
- const line = ` ${node.temporaryVariable} = ${replacement.toGLSLBase(this)};`
1270
+ const line = ` ${node.temporaryVariable} = ${replacement.toGLSLBase(this)};`;
1273
1271
  lines.push(line);
1274
1272
  }
1275
1273
  if (_emplaceAt) {
1276
- this.declarations.splice(_emplaceAt, 0, ...lines)
1274
+ this.declarations.splice(_emplaceAt, 0, ...lines);
1277
1275
  } else {
1278
1276
  this.declarations.push(...lines);
1279
1277
  }
1280
1278
  node.componentsChanged = false;
1281
1279
  }
1282
1280
  }
1283
- }
1281
+ };
1284
1282
  this.uniformNodes = [];
1285
1283
  }
1286
1284
  }
@@ -1366,7 +1364,6 @@ function shadergenerator(p5, fn) {
1366
1364
  propertyCharArray.forEach((char, i) => {
1367
1365
  const index = set.indexOf(char);
1368
1366
  const realProperty = swizzleSets[0][index];
1369
- const descriptor = Object.getOwnPropertyDescriptor(target, realProperty);
1370
1367
  Reflect.set(target, realProperty, newValues[i], receiver);
1371
1368
  });
1372
1369
  return true;
@@ -1380,16 +1377,16 @@ function shadergenerator(p5, fn) {
1380
1377
  // User functions
1381
1378
  fn.If = function (condition, branch) {
1382
1379
  return new ConditionalNode(condition, branch);
1383
- }
1380
+ };
1384
1381
 
1385
1382
  fn.instanceID = function() {
1386
1383
  return variableConstructor('gl_InstanceID', 'int');
1387
- }
1384
+ };
1388
1385
 
1389
1386
  fn.getTexture = function(...userArgs) {
1390
1387
  const props = { args: ['sampler2D', 'vec2'], returnType: 'vec4', isp5Function: true };
1391
1388
  return fnNodeConstructor('getTexture', userArgs, props);
1392
- }
1389
+ };
1393
1390
 
1394
1391
  // Generating uniformFloat, uniformVec, createFloat, etc functions
1395
1392
  // Maps a GLSL type to the name suffix for method names
@@ -1404,7 +1401,7 @@ function shadergenerator(p5, fn) {
1404
1401
 
1405
1402
  function dynamicAddSwizzleTrap(node, _size) {
1406
1403
  if (node.type.startsWith('vec') || _size) {
1407
- const size = _size ? _size : parseInt(node.type.slice(3));
1404
+ const size = parseInt(node.type.slice(3));
1408
1405
  node = new Proxy(node, swizzleTrap(size));
1409
1406
  node.addVectorComponents();
1410
1407
  }
@@ -1487,7 +1484,7 @@ function shadergenerator(p5, fn) {
1487
1484
  const varyingMethodName = `varying${typeIdentifier}`;
1488
1485
  ShaderGenerator.prototype[varyingMethodName] = function(name) {
1489
1486
  return dynamicAddSwizzleTrap(new VaryingNode(name, glslType, false));
1490
- }
1487
+ };
1491
1488
 
1492
1489
  fn[varyingMethodName] = function (name) {
1493
1490
  return GLOBAL_SHADER[varyingMethodName](name);
@@ -1593,7 +1590,7 @@ function shadergenerator(p5, fn) {
1593
1590
 
1594
1591
  ////////// Texture sampling //////////
1595
1592
  'texture': {args: ['sampler2D', 'vec2'], returnType: 'vec4', isp5Function: true},
1596
- }
1593
+ };
1597
1594
 
1598
1595
  Object.entries(builtInGLSLFunctions).forEach(([functionName, properties]) => {
1599
1596
  const isp5Function = Array.isArray(properties) ? properties[0].isp5Function : properties.isp5Function;
@@ -1605,7 +1602,7 @@ function shadergenerator(p5, fn) {
1605
1602
  } else {
1606
1603
  return originalFn.apply(this, args);
1607
1604
  }
1608
- }
1605
+ };
1609
1606
  } else {
1610
1607
  fn[functionName] = function (...args) {
1611
1608
  if (GLOBAL_SHADER?.isGenerating) {
@@ -1615,13 +1612,13 @@ function shadergenerator(p5, fn) {
1615
1612
  `It looks like you've called ${functionName} outside of a shader's modify() function.`
1616
1613
  );
1617
1614
  }
1618
- }
1615
+ };
1619
1616
  }
1620
- })
1617
+ });
1621
1618
  }
1622
1619
 
1623
- export default shadergenerator;
1624
-
1625
1620
  if (typeof p5 !== 'undefined') {
1626
- p5.registerAddon(shadergenerator)
1621
+ p5.registerAddon(shadergenerator);
1627
1622
  }
1623
+
1624
+ export { shadergenerator as default };
@@ -1,8 +1,9 @@
1
- import * as constants from '../core/constants';
2
- import { Geometry } from './p5.Geometry';
3
- import libtess from 'libtess'; // Fixed with exporting module from libtess
4
- import { Vector } from '../math/p5.Vector';
5
- import { RenderBuffer } from './p5.RenderBuffer';
1
+ import { m as PATH, Q as QUADS, s as QUAD_STRIP, r as TRIANGLE_STRIP, p as TRIANGLES, a1 as IMAGE, L as LINES, q as TRIANGLE_FAN } from '../constants-C-g_eAdC.js';
2
+ import { Geometry } from './p5.Geometry.js';
3
+ import libtess from 'libtess';
4
+ import { Vector } from '../math/p5.Vector.js';
5
+ import { RenderBuffer } from './p5.RenderBuffer.js';
6
+ import './p5.DataArray.js';
6
7
 
7
8
  const INITIAL_BUFFER_STRIDES = {
8
9
  vertices: 1,
@@ -17,10 +18,10 @@ const INITIAL_BUFFER_STRIDES = {
17
18
  const INITIAL_VERTEX_SIZE =
18
19
  Object.values(INITIAL_BUFFER_STRIDES).reduce((acc, next) => acc + next);
19
20
 
20
- export class ShapeBuilder {
21
+ class ShapeBuilder {
21
22
  constructor(renderer) {
22
23
  this.renderer = renderer;
23
- this.shapeMode = constants.PATH;
24
+ this.shapeMode = PATH;
24
25
  this.geometry = new Geometry(undefined, undefined, undefined, this.renderer);
25
26
  this.geometry.gid = '__IMMEDIATE_MODE_GEOMETRY__';
26
27
 
@@ -74,7 +75,7 @@ export class ShapeBuilder {
74
75
  // QUADS into TRIANGLES and QUAD_STRIP into TRIANGLE_STRIP. (There is no extra
75
76
  // work to convert QUAD_STRIP here, since the only difference is in how edges
76
77
  // are rendered.)
77
- if (this.shapeMode === constants.QUADS) {
78
+ if (this.shapeMode === QUADS) {
78
79
  // A finished quad turned into triangles should leave 6 vertices in the
79
80
  // buffer:
80
81
  // 0--3 0 3--5
@@ -126,25 +127,25 @@ export class ShapeBuilder {
126
127
  this.geometry._edgesToVertices();
127
128
  }
128
129
 
129
- if (this.shapeMode === constants.PATH) {
130
+ if (this.shapeMode === PATH) {
130
131
  this.isProcessingVertices = true;
131
132
  this._tesselateShape();
132
133
  this.isProcessingVertices = false;
133
- } else if (this.shapeMode === constants.QUAD_STRIP) {
134
+ } else if (this.shapeMode === QUAD_STRIP) {
134
135
  // The only difference between these two modes is which edges are
135
136
  // displayed, so after we've updated the edges, we switch the mode
136
137
  // to one that native WebGL knows how to render.
137
- this.shapeMode = constants.TRIANGLE_STRIP;
138
- } else if (this.shapeMode === constants.QUADS) {
138
+ this.shapeMode = TRIANGLE_STRIP;
139
+ } else if (this.shapeMode === QUADS) {
139
140
  // We translate QUADS to TRIANGLES when vertices are being added,
140
141
  // since QUADS is just a p5 mode, whereas TRIANGLES is also a mode
141
142
  // that native WebGL knows how to render. Once we've processed edges,
142
143
  // everything should be set up for TRIANGLES mode.
143
- this.shapeMode = constants.TRIANGLES;
144
+ this.shapeMode = TRIANGLES;
144
145
  }
145
146
 
146
147
  if (
147
- this.renderer.states.textureMode === constants.IMAGE &&
148
+ this.renderer.states.textureMode === IMAGE &&
148
149
  this.renderer.states._tex !== null &&
149
150
  this.renderer.states._tex.width > 0 &&
150
151
  this.renderer.states._tex.height > 0
@@ -155,7 +156,7 @@ export class ShapeBuilder {
155
156
  } else {
156
157
  return val / this.renderer.states._tex.height;
157
158
  }
158
- })
159
+ });
159
160
  }
160
161
  }
161
162
 
@@ -186,33 +187,33 @@ export class ShapeBuilder {
186
187
  const contourIndices = this.contourIndices.slice();
187
188
  let contourStart = -1;
188
189
  switch (shapeMode) {
189
- case constants.TRIANGLE_STRIP:
190
+ case TRIANGLE_STRIP:
190
191
  for (i = 0; i < verts.length - 2; i++) {
191
192
  res.push([i, i + 1]);
192
193
  res.push([i, i + 2]);
193
194
  }
194
195
  res.push([i, i + 1]);
195
196
  break;
196
- case constants.TRIANGLE_FAN:
197
+ case TRIANGLE_FAN:
197
198
  for (i = 1; i < verts.length - 1; i++) {
198
199
  res.push([0, i]);
199
200
  res.push([i, i + 1]);
200
201
  }
201
202
  res.push([0, verts.length - 1]);
202
203
  break;
203
- case constants.TRIANGLES:
204
+ case TRIANGLES:
204
205
  for (i = 0; i < verts.length - 2; i = i + 3) {
205
206
  res.push([i, i + 1]);
206
207
  res.push([i + 1, i + 2]);
207
208
  res.push([i + 2, i]);
208
209
  }
209
210
  break;
210
- case constants.LINES:
211
+ case LINES:
211
212
  for (i = 0; i < verts.length - 1; i = i + 2) {
212
213
  res.push([i, i + 1]);
213
214
  }
214
215
  break;
215
- case constants.QUADS:
216
+ case QUADS:
216
217
  // Quads have been broken up into two triangles by `vertex()`:
217
218
  // 0 3--5
218
219
  // | \ \ |
@@ -224,7 +225,7 @@ export class ShapeBuilder {
224
225
  res.push([i + 5, i]);
225
226
  }
226
227
  break;
227
- case constants.QUAD_STRIP:
228
+ case QUAD_STRIP:
228
229
  // 0---2---4
229
230
  // | | |
230
231
  // 1---3---5
@@ -260,7 +261,7 @@ export class ShapeBuilder {
260
261
  */
261
262
  _tesselateShape() {
262
263
  // TODO: handle non-PATH shape modes that have contours
263
- this.shapeMode = constants.TRIANGLES;
264
+ this.shapeMode = TRIANGLES;
264
265
  // const contours = [[]];
265
266
  const contours = [];
266
267
  for (let i = 0; i < this.geometry.vertices.length; i++) {
@@ -481,4 +482,6 @@ export class ShapeBuilder {
481
482
 
482
483
  return triangleVerts;
483
484
  }
484
- };
485
+ }
486
+
487
+ export { ShapeBuilder };