p5 2.2.2 → 2.2.3-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 (98) hide show
  1. package/dist/accessibility/color_namer.js +5 -5
  2. package/dist/accessibility/index.js +5 -5
  3. package/dist/app.js +5 -5
  4. package/dist/color/color_conversion.js +5 -5
  5. package/dist/color/index.js +1 -1
  6. package/dist/color/setting.js +1 -1
  7. package/dist/{constants-BxjhKpTv.js → constants-BUwWryrh.js} +1 -1
  8. package/dist/core/constants.js +1 -1
  9. package/dist/core/environment.js +7 -3
  10. package/dist/core/filterShaders.js +1 -1
  11. package/dist/core/friendly_errors/fes_core.js +1 -1
  12. package/dist/core/friendly_errors/file_errors.js +1 -1
  13. package/dist/core/friendly_errors/index.js +1 -1
  14. package/dist/core/friendly_errors/param_validator.js +2063 -2014
  15. package/dist/core/friendly_errors/sketch_verifier.js +1 -1
  16. package/dist/core/helpers.js +1 -1
  17. package/dist/core/init.js +5 -5
  18. package/dist/core/internationalization.js +1 -1
  19. package/dist/core/legacy.js +5 -5
  20. package/dist/core/main.js +5 -5
  21. package/dist/core/p5.Graphics.js +3 -3
  22. package/dist/core/p5.Renderer.js +2 -2
  23. package/dist/core/p5.Renderer2D.js +5 -5
  24. package/dist/core/p5.Renderer3D.js +3 -3
  25. package/dist/core/rendering.js +3 -3
  26. package/dist/dom/dom.js +1 -1
  27. package/dist/dom/index.js +1 -1
  28. package/dist/dom/p5.Element.js +1 -1
  29. package/dist/dom/p5.MediaElement.js +11 -4
  30. package/dist/events/pointer.js +4 -0
  31. package/dist/image/const.js +1 -1
  32. package/dist/image/filterRenderer2D.js +4 -4
  33. package/dist/image/image.js +3 -3
  34. package/dist/image/index.js +3 -3
  35. package/dist/image/loading_displaying.js +3 -3
  36. package/dist/image/p5.Image.js +2 -2
  37. package/dist/io/files.js +3 -3
  38. package/dist/io/index.js +3 -3
  39. package/dist/{ir_builders-w12-GSxu.js → ir_builders-Cd6rU9Vm.js} +48 -14
  40. package/dist/{main-DDs4QOnh.js → main-DFpoFdvM.js} +126 -36
  41. package/dist/math/Matrices/Matrix.js +1 -1
  42. package/dist/math/Matrices/MatrixNumjs.js +1 -1
  43. package/dist/math/index.js +1 -1
  44. package/dist/math/p5.Matrix.js +1 -1
  45. package/dist/math/p5.Vector.js +1 -1
  46. package/dist/math/trigonometry.js +1 -1
  47. package/dist/{p5.Renderer-BSGddFv7.js → p5.Renderer-D-EuAodU.js} +9 -2
  48. package/dist/{rendering-C9g7uSQ5.js → rendering-DE9-Hl7Y.js} +103 -78
  49. package/dist/shape/2d_primitives.js +1 -1
  50. package/dist/shape/attributes.js +1 -1
  51. package/dist/shape/custom_shapes.js +1 -1
  52. package/dist/shape/index.js +1 -1
  53. package/dist/strands/ir_builders.js +1 -1
  54. package/dist/strands/ir_dag.js +32 -2
  55. package/dist/strands/ir_types.js +18 -11
  56. package/dist/strands/p5.strands.js +24 -35
  57. package/dist/strands/strands_api.js +86 -41
  58. package/dist/strands/strands_codegen.js +0 -12
  59. package/dist/strands/strands_conditionals.js +1 -1
  60. package/dist/strands/strands_for.js +1 -1
  61. package/dist/strands/strands_node.js +1 -1
  62. package/dist/strands/strands_phi_utils.js +27 -9
  63. package/dist/strands/strands_transpiler.js +1237 -831
  64. package/dist/type/index.js +2 -2
  65. package/dist/type/p5.Font.js +7 -5
  66. package/dist/type/textCore.js +2 -2
  67. package/dist/webgl/3d_primitives.js +3 -3
  68. package/dist/webgl/GeometryBuilder.js +1 -1
  69. package/dist/webgl/ShapeBuilder.js +1 -1
  70. package/dist/webgl/enums.js +1 -1
  71. package/dist/webgl/index.js +4 -4
  72. package/dist/webgl/interaction.js +1 -1
  73. package/dist/webgl/light.js +3 -3
  74. package/dist/webgl/loading.js +41 -35
  75. package/dist/webgl/material.js +3 -3
  76. package/dist/webgl/p5.Camera.js +3 -3
  77. package/dist/webgl/p5.Framebuffer.js +3 -3
  78. package/dist/webgl/p5.Geometry.js +1 -1
  79. package/dist/webgl/p5.Quat.js +1 -1
  80. package/dist/webgl/p5.RendererGL.js +4 -4
  81. package/dist/webgl/p5.Shader.js +14 -6
  82. package/dist/webgl/p5.Texture.js +3 -3
  83. package/dist/webgl/strands_glslBackend.js +1 -1
  84. package/dist/webgl/text.js +3 -3
  85. package/dist/webgl/utils.js +3 -3
  86. package/dist/webgpu/index.js +2 -2
  87. package/dist/webgpu/p5.RendererWebGPU.js +2 -2
  88. package/dist/webgpu/strands_wgslBackend.js +13 -4
  89. package/lib/p5.esm.js +3670 -2951
  90. package/lib/p5.esm.min.js +1 -1
  91. package/lib/p5.js +3670 -2951
  92. package/lib/p5.min.js +1 -1
  93. package/lib/p5.webgpu.esm.js +43 -21
  94. package/lib/p5.webgpu.js +43 -21
  95. package/lib/p5.webgpu.min.js +1 -1
  96. package/package.json +1 -1
  97. package/types/global.d.ts +1283 -1301
  98. package/types/p5.d.ts +655 -657
@@ -1,9 +1,9 @@
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-BxjhKpTv.js';
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-BUwWryrh.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-C9g7uSQ5.js';
6
- import { R as Renderer, I as Image, r as renderer } from './p5.Renderer-BSGddFv7.js';
5
+ import { G as Graphics, k as rendering, n as graphics } from './rendering-DE9-Hl7Y.js';
6
+ import { R as Renderer, I as Image, r as renderer } from './p5.Renderer-D-EuAodU.js';
7
7
  import { Element } from './dom/p5.Element.js';
8
8
  import { MediaElement } from './dom/p5.MediaElement.js';
9
9
  import { b as RGBHDR } from './creating_reading-C7hu6sg1.js';
@@ -1304,30 +1304,7 @@ class p5 {
1304
1304
  constructor(sketch, node) {
1305
1305
  // Apply addon defined decorations
1306
1306
  if(p5.decorations.size > 0){
1307
- for (const [patternArray, decoration] of p5.decorations) {
1308
- for(const member in p5.prototype) {
1309
- // Member must be a function
1310
- if (typeof p5.prototype[member] !== 'function') continue;
1311
-
1312
- if (!patternArray.some(pattern => {
1313
- if (typeof pattern === 'string') {
1314
- return pattern === member;
1315
- } else if (pattern instanceof RegExp) {
1316
- return pattern.test(member);
1317
- }
1318
- })) continue;
1319
-
1320
- p5.prototype[member] = decoration(p5.prototype[member], {
1321
- kind: 'method',
1322
- name: member,
1323
- access: {},
1324
- static: false,
1325
- private: false,
1326
- addInitializer(initializer){}
1327
- });
1328
- }
1329
- }
1330
-
1307
+ decorateClass(p5, p5.decorations);
1331
1308
  p5.decorations.clear();
1332
1309
  }
1333
1310
 
@@ -1419,11 +1396,11 @@ class p5 {
1419
1396
  }
1420
1397
 
1421
1398
  get pixels(){
1422
- return this._renderer.pixels;
1399
+ return this._renderer?.pixels;
1423
1400
  }
1424
1401
 
1425
1402
  get drawingContext(){
1426
- return this._renderer.drawingContext;
1403
+ return this._renderer?.drawingContext;
1427
1404
  }
1428
1405
 
1429
1406
  static _registeredAddons = new Set();
@@ -1447,10 +1424,20 @@ class p5 {
1447
1424
  }
1448
1425
 
1449
1426
  static decorations = new Map();
1450
- static decorateHelper(pattern, decoration){
1451
- let patternArray = pattern;
1452
- if (!Array.isArray(pattern)) patternArray = [pattern];
1453
- p5.decorations.set(patternArray, decoration);
1427
+ static registerDecorator(pattern, decoration){
1428
+ if(typeof pattern === 'string'){
1429
+ const patternStr = pattern;
1430
+ pattern = ({ path }) => patternStr === path;
1431
+ }else if(
1432
+ Array.isArray(pattern) &&
1433
+ pattern.every(value => typeof value === 'string')
1434
+ ){
1435
+ const patternArray = pattern;
1436
+ pattern = ({ path }) => patternArray.includes(path);
1437
+ }else if(typeof pattern !== 'function'){
1438
+ throw new Error('Decorator matching pattern must be a function, a string, or an array of strings');
1439
+ }
1440
+ p5.decorations.set(pattern, decoration);
1454
1441
  }
1455
1442
 
1456
1443
  #customActions = {};
@@ -1691,6 +1678,11 @@ class p5 {
1691
1678
  }
1692
1679
  }
1693
1680
 
1681
+ // Attach constants to p5 prototype
1682
+ for (const k in constants) {
1683
+ p5.prototype[k] = constants[k];
1684
+ }
1685
+
1694
1686
  // Global helper function for binding properties to window in global mode
1695
1687
  function createBindGlobal(instance) {
1696
1688
  return function bindGlobal(property) {
@@ -1781,9 +1773,107 @@ function createBindGlobal(instance) {
1781
1773
  };
1782
1774
  }
1783
1775
 
1784
- // Attach constants to p5 prototype
1785
- for (const k in constants) {
1786
- p5.prototype[k] = constants[k];
1776
+ // Generic function to decorate classes
1777
+ function decorateClass(Target, decorations, path){
1778
+ path ??= Target.name;
1779
+ // Static properties
1780
+ for(const key in Target){
1781
+ if(!key.startsWith('_')){
1782
+ for (const [pattern, decorator] of decorations) {
1783
+ if(pattern({ path: `${path}.${key}` })){
1784
+ // Check if method or accessor
1785
+ if(typeof Target[key] === 'function'){
1786
+ const result = decorator(Target[key], {
1787
+ kind: 'method',
1788
+ name: key,
1789
+ static: true
1790
+ });
1791
+ if(result){
1792
+ Object.defineProperty(Target, key, {
1793
+ enumerable: true,
1794
+ writable: true,
1795
+ value: result
1796
+ });
1797
+ }
1798
+ }else {
1799
+ const result = decorator(undefined, {
1800
+ kind: 'field',
1801
+ name: key,
1802
+ static: true
1803
+ });
1804
+ if(result && typeof result === 'function'){
1805
+ Target[key] = result(Target[key]);
1806
+ }
1807
+ }
1808
+ }
1809
+ }
1810
+
1811
+ if(typeof Target[key] === 'function' && Target[key].prototype){
1812
+ decorateClass(Target[key], decorations, `${path}.${key}`);
1813
+ }
1814
+ }
1815
+ }
1816
+
1817
+ // Member properties
1818
+ for(const member of Object.getOwnPropertyNames(Target.prototype)){
1819
+ if(member !== 'constructor' && !member.startsWith('_')){
1820
+ for (const [pattern, decorator] of decorations) {
1821
+ if(pattern({ path: `${path}.prototype.${member}` })){
1822
+ // Check if method or accessor
1823
+ if(typeof Target.prototype[member] === 'function'){
1824
+ const result = decorator(Target.prototype[member], {
1825
+ kind: 'method',
1826
+ name: member,
1827
+ static: false
1828
+ });
1829
+ if(result) {
1830
+ Object.defineProperty(Target.prototype, member, {
1831
+ enumerable: true,
1832
+ writable: true,
1833
+ value: result
1834
+ });
1835
+ }
1836
+ }else {
1837
+ const descriptor = Object.getOwnPropertyDescriptor(
1838
+ Target.prototype,
1839
+ member
1840
+ );
1841
+ if(descriptor.hasOwnProperty('value')){
1842
+ const result = decorator(undefined, {
1843
+ kind: 'field',
1844
+ name: member,
1845
+ static: false
1846
+ });
1847
+ Object.defineProperty(Target.prototype, member, {
1848
+ enumerable: true,
1849
+ writable: true,
1850
+ value: result && typeof result === 'function' ?
1851
+ result(Target.prototype[member]) :
1852
+ Target.prototype[member]
1853
+ });
1854
+ }else {
1855
+ const { get, set } = descriptor;
1856
+ const getterResult = decorator(get, {
1857
+ kind: 'getter',
1858
+ name: member,
1859
+ static: false
1860
+ });
1861
+ const setterResult = decorator(set, {
1862
+ kind: 'setter',
1863
+ name: member,
1864
+ static: false
1865
+ });
1866
+ Object.defineProperty(Target.prototype, member, {
1867
+ enumerable: true,
1868
+ get: getterResult ?? get,
1869
+ set: setterResult ?? set
1870
+ });
1871
+ }
1872
+ }
1873
+ }
1874
+ }
1875
+ }
1876
+ }
1787
1877
  }
1788
1878
 
1789
1879
  p5.registerAddon(transform);
@@ -1,6 +1,6 @@
1
1
  import { Vector } from '../p5.Vector.js';
2
2
  import { MatrixInterface } from './MatrixInterface.js';
3
- import '../../constants-BxjhKpTv.js';
3
+ import '../../constants-BUwWryrh.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-BxjhKpTv.js';
4
+ import '../../constants-BUwWryrh.js';
5
5
 
6
6
  let isMatrixArray = x => Array.isArray(x);
7
7
  if (typeof Float32Array !== 'undefined') {
@@ -4,7 +4,7 @@ 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-BxjhKpTv.js';
7
+ import '../constants-BUwWryrh.js';
8
8
 
9
9
  function math(p5){
10
10
  p5.registerAddon(calculation);
@@ -1,6 +1,6 @@
1
1
  import { Matrix } from './Matrices/Matrix.js';
2
2
  import './p5.Vector.js';
3
- import '../constants-BxjhKpTv.js';
3
+ import '../constants-BUwWryrh.js';
4
4
  import './Matrices/MatrixInterface.js';
5
5
 
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { q as TWO_PI } from '../constants-BxjhKpTv.js';
1
+ import { q as TWO_PI } from '../constants-BUwWryrh.js';
2
2
 
3
3
  /**
4
4
  * @module Math
@@ -1,4 +1,4 @@
1
- import { a5 as RAD_TO_DEG, a6 as DEG_TO_RAD } from '../constants-BxjhKpTv.js';
1
+ import { a5 as RAD_TO_DEG, a6 as DEG_TO_RAD } from '../constants-BUwWryrh.js';
2
2
 
3
3
  /**
4
4
  * @module Math
@@ -1,5 +1,5 @@
1
1
  import { C as Color } from './creating_reading-C7hu6sg1.js';
2
- import { a2 as NORMAL, aA as WORD, ax as BASELINE, av as LEFT, v as CENTER, p as CORNER, J as INCLUDE } from './constants-BxjhKpTv.js';
2
+ import { a2 as NORMAL, aA as WORD, ax as BASELINE, av as LEFT, v as CENTER, p as CORNER, J as INCLUDE } from './constants-BUwWryrh.js';
3
3
  import Filters from './image/filters.js';
4
4
  import { Vector } from './math/p5.Vector.js';
5
5
  import { Shape } from './shape/custom_shapes.js';
@@ -2317,7 +2317,14 @@ class Renderer {
2317
2317
  this._pInst = pInst;
2318
2318
  this._isMainCanvas = isMainCanvas;
2319
2319
  this.pixels = [];
2320
- this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1;
2320
+
2321
+ if (isMainCanvas) {
2322
+ this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1;
2323
+ } else {
2324
+
2325
+ const parentDensity = pInst._pInst?._renderer?._pixelDensity;
2326
+ this._pixelDensity = parentDensity || Math.ceil(window.devicePixelRatio) || 1;
2327
+ }
2321
2328
 
2322
2329
  this.width = w;
2323
2330
  this.height = h;