q5 2.10.7 → 2.11.0

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 (72) hide show
  1. package/README.md +8 -1
  2. package/deno.json +36 -0
  3. package/package.json +3 -6
  4. package/q5-deno-server.js +45 -0
  5. package/q5-server.js +6 -7
  6. package/q5.js +19 -13
  7. package/q5.min.js +2 -2
  8. package/src/q5-2d-image.js +1 -1
  9. package/src/q5-canvas.js +16 -10
  10. package/src/q5-core.js +2 -2
  11. package/test/core.test.js +30 -0
  12. package/test/readme.md +5 -0
  13. package/.vscode/launch.json +0 -26
  14. package/.vscode/settings.json +0 -3
  15. package/bun.lockb +0 -0
  16. package/p5-tests/js/chai_helpers.js +0 -20
  17. package/p5-tests/js/mocha_setup.js +0 -2
  18. package/p5-tests/js/modernizr.js +0 -5
  19. package/p5-tests/js/p5_helpers.js +0 -135
  20. package/p5-tests/js/sinon.js +0 -5949
  21. package/p5-tests/mocha.css +0 -289
  22. package/p5-tests/test.html +0 -71
  23. package/p5-tests/unit/color/color_conversion.js +0 -68
  24. package/p5-tests/unit/color/creating_reading.js +0 -217
  25. package/p5-tests/unit/color/p5.Color.js +0 -1000
  26. package/p5-tests/unit/color/setting.js +0 -289
  27. package/p5-tests/unit/core/2d_primitives.js +0 -490
  28. package/p5-tests/unit/core/attributes.js +0 -115
  29. package/p5-tests/unit/core/curves.js +0 -139
  30. package/p5-tests/unit/core/environment.js +0 -248
  31. package/p5-tests/unit/core/error_helpers.js +0 -1158
  32. package/p5-tests/unit/core/main.js +0 -340
  33. package/p5-tests/unit/core/p5.Element.js +0 -773
  34. package/p5-tests/unit/core/p5.Graphics.js +0 -179
  35. package/p5-tests/unit/core/preload.js +0 -285
  36. package/p5-tests/unit/core/rendering.js +0 -116
  37. package/p5-tests/unit/core/structure.js +0 -293
  38. package/p5-tests/unit/core/transform.js +0 -144
  39. package/p5-tests/unit/core/version.js +0 -28
  40. package/p5-tests/unit/core/vertex.js +0 -137
  41. package/p5-tests/unit/dom/dom.js +0 -2146
  42. package/p5-tests/unit/events/acceleration.js +0 -213
  43. package/p5-tests/unit/events/keyboard.js +0 -179
  44. package/p5-tests/unit/events/mouse.js +0 -487
  45. package/p5-tests/unit/events/touch.js +0 -180
  46. package/p5-tests/unit/image/downloading.js +0 -379
  47. package/p5-tests/unit/image/filters.js +0 -92
  48. package/p5-tests/unit/image/loading.js +0 -413
  49. package/p5-tests/unit/image/p5.Image.js +0 -201
  50. package/p5-tests/unit/image/pixels.js +0 -234
  51. package/p5-tests/unit/io/files.js +0 -378
  52. package/p5-tests/unit/io/loadBytes.js +0 -149
  53. package/p5-tests/unit/io/loadImage.js +0 -123
  54. package/p5-tests/unit/io/loadJSON.js +0 -185
  55. package/p5-tests/unit/io/loadModel.js +0 -215
  56. package/p5-tests/unit/io/loadShader.js +0 -176
  57. package/p5-tests/unit/io/loadStrings.js +0 -140
  58. package/p5-tests/unit/io/loadTable.js +0 -183
  59. package/p5-tests/unit/io/loadXML.js +0 -127
  60. package/p5-tests/unit/io/saveModel.js +0 -113
  61. package/p5-tests/unit/io/saveTable.js +0 -142
  62. package/p5-tests/unit/math/calculation.js +0 -452
  63. package/p5-tests/unit/math/noise.js +0 -66
  64. package/p5-tests/unit/math/p5.Vector.js +0 -1886
  65. package/p5-tests/unit/math/random.js +0 -177
  66. package/p5-tests/unit/math/trigonometry.js +0 -144
  67. package/p5-tests/unit/spec.js +0 -50
  68. package/p5-tests/unit/typography/attributes.js +0 -120
  69. package/p5-tests/unit/typography/loadFont.js +0 -162
  70. package/p5-tests/unit/typography/p5.Font.js +0 -63
  71. package/p5-tests/unit/utilities/conversion.js +0 -329
  72. package/p5-tests/unit/utilities/time_date.js +0 -133
@@ -1,179 +0,0 @@
1
- suite('Graphics', function() {
2
- var myp5;
3
-
4
- setup(function(done) {
5
- new p5(function(p) {
6
- p.setup = function() {
7
- myp5 = p;
8
- done();
9
- };
10
- });
11
- });
12
-
13
- teardown(function() {
14
- myp5.remove();
15
- });
16
-
17
- function assertValidGraphSizes(graph, w, h, density) {
18
- assert.strictEqual(graph.pixelDensity(), density, 'invalid pixel density');
19
- assert.strictEqual(graph.width, w, 'invalid width');
20
- assert.strictEqual(graph.height, h, 'invalid height');
21
- }
22
-
23
- function assertValidCanvasSizes(canvas, w, h, density) {
24
- assert.strictEqual(canvas.width, w * density, 'canvas.width');
25
- assert.strictEqual(canvas.height, h * density, 'canvas.height');
26
- assert.strictEqual(
27
- canvas.style.width,
28
- '' + w + 'px',
29
- 'invalid canvas.style.width'
30
- );
31
- assert.strictEqual(
32
- canvas.style.height,
33
- '' + h + 'px',
34
- 'invalid canvas.style.height'
35
- );
36
- }
37
-
38
- function assertValidPixels(graph, w, h, density) {
39
- graph.loadPixels();
40
- var real = graph.pixels.length;
41
- var expected = w * density * h * density * 4;
42
- assert.strictEqual(real, expected, 'invalid number of pixels');
43
- }
44
-
45
- suite('p5.prototype.createGraphics', function() {
46
- test('it creates a graphics', function() {
47
- var graph = myp5.createGraphics(10, 17);
48
- assert.isObject(graph);
49
- });
50
-
51
- });
52
-
53
- suite('p5.Graphics', function() {
54
- test('it has necessary properties', function() {
55
- var graph = myp5.createGraphics(10, 17);
56
- assert.property(graph, 'width');
57
- assert.property(graph, 'height');
58
- assert.property(graph, 'canvas');
59
- assert.property(graph, 'pixelDensity');
60
- assert.property(graph, 'loadPixels');
61
- assert.property(graph, 'pixels');
62
- });
63
-
64
- test('it has consistent sizes', function() {
65
- var graph = myp5.createGraphics(10, 17);
66
- graph.pixelDensity(1);
67
- assertValidGraphSizes(graph, 10, 17, 1);
68
- });
69
-
70
- test('its canvas has consistent sizes', function() {
71
- var graph = myp5.createGraphics(10, 17);
72
- graph.pixelDensity(1);
73
- assertValidCanvasSizes(graph.canvas, 10, 17, 1);
74
- });
75
-
76
- test('it has a valid pixels array', function() {
77
- var graph = myp5.createGraphics(10, 17);
78
- graph.pixelDensity(1);
79
- assertValidPixels(graph, 10, 17, 1);
80
- });
81
- });
82
-
83
- suite('p5.Graphics.pixelDensity', function() {
84
- test('it can change density', function() {
85
- var graph = myp5.createGraphics(10, 17);
86
- graph.pixelDensity(1);
87
- assert.strictEqual(graph.pixelDensity(), 1);
88
- graph.pixelDensity(3);
89
- assert.strictEqual(graph.pixelDensity(), 3);
90
- });
91
-
92
- test('it keeps valid sizes after change', function() {
93
- var graph = myp5.createGraphics(10, 17);
94
- graph.pixelDensity(1);
95
- assertValidGraphSizes(graph, 10, 17, 1);
96
- graph.pixelDensity(3);
97
- assertValidGraphSizes(graph, 10, 17, 3);
98
- });
99
-
100
- test('its canvas keeps valid sizes after change', function() {
101
- var graph = myp5.createGraphics(10, 17);
102
- graph.pixelDensity(1);
103
- assertValidCanvasSizes(graph.canvas, 10, 17, 1);
104
- graph.pixelDensity(3);
105
- assertValidCanvasSizes(graph.canvas, 10, 17, 3);
106
- });
107
-
108
- test('it keeps a valid pixel array after change', function() {
109
- var graph = myp5.createGraphics(10, 17);
110
- graph.pixelDensity(1);
111
- assertValidPixels(graph, 10, 17, 1);
112
-
113
- graph.pixelDensity(3);
114
- assertValidPixels(graph, 10, 17, 3);
115
- });
116
- });
117
-
118
- suite('p5.Graphics.resizeCanvas', function() {
119
- test('it can call resizeCanvas', function() {
120
- var graph = myp5.createGraphics(10, 17);
121
- var resize = function() {
122
- graph.resizeCanvas(19, 16);
123
- };
124
- assert.doesNotThrow(resize);
125
- });
126
-
127
- test('it resizes properly with pixelDensity 1', function() {
128
- var graph = myp5.createGraphics(10, 17);
129
- graph.pixelDensity(1);
130
- graph.resizeCanvas(19, 16);
131
- assertValidGraphSizes(graph, 19, 16, 1);
132
- });
133
-
134
- test('its canvas resizes properly with pixelDensity 1', function() {
135
- var graph = myp5.createGraphics(10, 17);
136
- graph.pixelDensity(1);
137
- graph.resizeCanvas(19, 16);
138
- assertValidCanvasSizes(graph.canvas, 19, 16, 1);
139
- });
140
-
141
- test('it resizes properly the pixels array with density 1', function() {
142
- var graph = myp5.createGraphics(10, 17);
143
- graph.pixelDensity(1);
144
- graph.resizeCanvas(19, 16);
145
- assertValidPixels(graph, 19, 16, 1);
146
- });
147
-
148
- test('it resizes properly with pixelDensity 2', function() {
149
- var graph = myp5.createGraphics(10, 17);
150
- graph.pixelDensity(2);
151
- graph.resizeCanvas(19, 16);
152
- assertValidGraphSizes(graph, 19, 16, 2);
153
- });
154
-
155
- test('its canvas resizes properly with pixelDensity 2', function() {
156
- var graph = myp5.createGraphics(10, 17);
157
- graph.pixelDensity(2);
158
- graph.resizeCanvas(19, 16);
159
- assertValidCanvasSizes(graph.canvas, 19, 16, 2);
160
- });
161
-
162
- test('it resizes properly the pixels array with density 2', function() {
163
- var graph = myp5.createGraphics(10, 17);
164
- graph.pixelDensity(2);
165
- graph.resizeCanvas(19, 16);
166
- assertValidPixels(graph, 19, 16, 2);
167
- });
168
- });
169
-
170
- suite('p5.Graphics.remove()', function() {
171
- test('it sets properties to undefined after removal', function() {
172
- var graph = myp5.createGraphics(10, 17);
173
- graph.remove();
174
- assert.isUndefined(graph.canvas);
175
- assert.isUndefined(graph._renderer);
176
- assert.isUndefined(graph.elt);
177
- });
178
- });
179
- });
@@ -1,285 +0,0 @@
1
- suite('preloads', () => {
2
- let preloadCache = null;
3
- setup(() => {
4
- preloadCache = p5.prototype._promisePreloads;
5
- p5.prototype._promisePreloads = [...preloadCache];
6
- });
7
-
8
- teardown(() => {
9
- p5.prototype._promisePreloads = preloadCache;
10
- });
11
-
12
- suite('From external sources', () => {
13
- test('Extension preload causes setup to wait', () => {
14
- let resolved = false;
15
- const target = {
16
- async testPreloadFunction() {
17
- await new Promise(res => setTimeout(res, 10));
18
- resolved = true;
19
- }
20
- };
21
-
22
- p5.prototype._promisePreloads.push({
23
- target,
24
- method: 'testPreloadFunction'
25
- });
26
-
27
- return promisedSketch((sketch, resolve, reject) => {
28
- sketch.preload = () => {
29
- target.testPreloadFunction();
30
- };
31
-
32
- sketch.setup = () => {
33
- if (resolved) {
34
- resolve();
35
- } else {
36
- reject(new Error('Sketch enetered setup too early.'));
37
- }
38
- };
39
- });
40
- });
41
-
42
- test('Extension preload error causes setup to not execute', () => {
43
- const target = {
44
- async testPreloadFunction() {
45
- throw new Error('Testing Error');
46
- }
47
- };
48
-
49
- p5.prototype._promisePreloads.push({
50
- target,
51
- method: 'testPreloadFunction'
52
- });
53
-
54
- return promisedSketch((sketch, resolve, reject) => {
55
- sketch.preload = () => {
56
- target.testPreloadFunction();
57
- setTimeout(resolve, 10);
58
- };
59
-
60
- sketch.setup = () => {
61
- reject('Sketch should not enter setup');
62
- };
63
- });
64
- });
65
-
66
- suite('addCallbacks', () => {
67
- test('Extension is passed all arguments when not using addCallbacks', () => {
68
- const target = {
69
- async testPreloadFunction(...args) {
70
- assert.lengthOf(args, 3);
71
- }
72
- };
73
-
74
- p5.prototype._promisePreloads.push({
75
- target,
76
- method: 'testPreloadFunction',
77
- addCallbacks: false
78
- });
79
-
80
- return promisedSketch((sketch, resolve, reject) => {
81
- sketch.preload = () => {
82
- target
83
- .testPreloadFunction(() => {}, () => {}, () => {})
84
- .catch(reject);
85
- };
86
-
87
- sketch.setup = resolve;
88
- });
89
- });
90
-
91
- test('Extension gets stripped arguments when using addCallbacks', () => {
92
- const target = {
93
- async testPreloadFunction(...args) {
94
- assert.lengthOf(args, 1);
95
- }
96
- };
97
-
98
- p5.prototype._promisePreloads.push({
99
- target,
100
- method: 'testPreloadFunction',
101
- addCallbacks: true
102
- });
103
-
104
- return promisedSketch((sketch, resolve, reject) => {
105
- sketch.preload = () => {
106
- target
107
- .testPreloadFunction(() => {}, () => {}, () => {})
108
- .catch(reject);
109
- };
110
-
111
- sketch.setup = resolve;
112
- });
113
- });
114
-
115
- test('Extension with addCallbacks supports success callback', () => {
116
- const target = {
117
- async testPreloadFunction(...args) {
118
- assert.lengthOf(args, 1);
119
- }
120
- };
121
-
122
- p5.prototype._promisePreloads.push({
123
- target,
124
- method: 'testPreloadFunction',
125
- addCallbacks: true
126
- });
127
-
128
- let success = 0;
129
-
130
- return promisedSketch((sketch, resolve, reject) => {
131
- sketch.preload = () => {
132
- target
133
- .testPreloadFunction(0, () => {
134
- success++;
135
- })
136
- .catch(reject);
137
- target
138
- .testPreloadFunction(
139
- () => {},
140
- () => {
141
- success++;
142
- },
143
- () => {
144
- reject(new Error('Failure callback executed'));
145
- }
146
- )
147
- .catch(reject);
148
- };
149
-
150
- sketch.setup = () => {
151
- if (success !== 2) {
152
- reject(
153
- new Error(`Not all success callbacks were run: ${success}/2`)
154
- );
155
- }
156
- resolve();
157
- };
158
- });
159
- });
160
- });
161
-
162
- suite('legacyPreload', () => {
163
- test('Extension legacy preload causes setup to wait', () => {
164
- let resolved = false;
165
- const target = {
166
- async testPreloadFunction() {
167
- await new Promise(res => setTimeout(res, 10));
168
- resolved = true;
169
- }
170
- };
171
-
172
- p5.prototype._promisePreloads.push({
173
- target,
174
- method: 'testPreloadFunction',
175
- legacyPreloadSetup: {
176
- method: 'testPreloadLegacy'
177
- }
178
- });
179
-
180
- return promisedSketch((sketch, resolve, reject) => {
181
- sketch.preload = () => {
182
- target.testPreloadLegacy();
183
- };
184
-
185
- sketch.setup = () => {
186
- if (resolved) {
187
- resolve();
188
- } else {
189
- reject(new Error('Sketch enetered setup too early.'));
190
- }
191
- };
192
- });
193
- });
194
-
195
- test('Extension legacy preload error causes setup to not execute', () => {
196
- const target = {
197
- async testPreloadFunction() {
198
- throw new Error('Testing Error');
199
- }
200
- };
201
-
202
- p5.prototype._promisePreloads.push({
203
- target,
204
- method: 'testPreloadFunction',
205
- legacyPreloadSetup: {
206
- method: 'testPreloadLegacy'
207
- }
208
- });
209
-
210
- return promisedSketch((sketch, resolve, reject) => {
211
- sketch.preload = () => {
212
- target.testPreloadLegacy();
213
- setTimeout(resolve, 10);
214
- };
215
-
216
- sketch.setup = () => {
217
- reject('Sketch should not enter setup');
218
- };
219
- });
220
- });
221
-
222
- test('Extension legacy preload returns objects correctly', async () => {
223
- let testItem = {
224
- test: true,
225
- otherTest: []
226
- };
227
- const target = {
228
- async testPreloadFunction() {
229
- return testItem;
230
- }
231
- };
232
-
233
- p5.prototype._promisePreloads.push({
234
- target,
235
- method: 'testPreloadFunction',
236
- legacyPreloadSetup: {
237
- method: 'testPreloadLegacy'
238
- }
239
- });
240
-
241
- let testResult;
242
-
243
- await promisedSketch((sketch, resolve, reject) => {
244
- sketch.preload = () => {
245
- testResult = target.testPreloadLegacy();
246
- };
247
-
248
- sketch.setup = resolve();
249
- });
250
-
251
- assert.deepEqual(testResult, testItem);
252
- });
253
-
254
- test('Extension legacy preload returns arrays correctly', async () => {
255
- let testItem = [true, [], {}];
256
- const target = {
257
- async testPreloadFunction() {
258
- return testItem;
259
- }
260
- };
261
-
262
- p5.prototype._promisePreloads.push({
263
- target,
264
- method: 'testPreloadFunction',
265
- legacyPreloadSetup: {
266
- method: 'testPreloadLegacy',
267
- createBaseObject: () => []
268
- }
269
- });
270
-
271
- let testResult;
272
-
273
- await promisedSketch((sketch, resolve, reject) => {
274
- sketch.preload = () => {
275
- testResult = target.testPreloadLegacy();
276
- };
277
-
278
- sketch.setup = resolve();
279
- });
280
-
281
- assert.deepEqual(testResult, testItem);
282
- });
283
- });
284
- });
285
- });
@@ -1,116 +0,0 @@
1
- suite('Rendering', function() {
2
- var myp5;
3
-
4
- setup(function(done) {
5
- new p5(function(p) {
6
- p.setup = function() {
7
- myp5 = p;
8
- done();
9
- };
10
- });
11
- });
12
-
13
- teardown(function() {
14
- myp5.remove();
15
- });
16
-
17
- suite('p5.prototype.createCanvas', function() {
18
- test('should have correct initial colors', function() {
19
- var white = myp5.color(255, 255, 255).levels;
20
- var black = myp5.color(0, 0, 0).levels;
21
- assert.deepEqual(myp5.color(myp5._renderer._getFill()).levels, white);
22
- assert.deepEqual(myp5.color(myp5._renderer._getStroke()).levels, black);
23
- assert.deepEqual(myp5.color(myp5.drawingContext.fillStyle).levels, white);
24
- assert.deepEqual(
25
- myp5.color(myp5.drawingContext.strokeStyle).levels,
26
- black
27
- );
28
- myp5.createCanvas(100, 100);
29
- assert.deepEqual(myp5.color(myp5._renderer._getFill()).levels, white);
30
- assert.deepEqual(myp5.color(myp5._renderer._getStroke()).levels, black);
31
- assert.deepEqual(myp5.color(myp5.drawingContext.fillStyle).levels, white);
32
- assert.deepEqual(
33
- myp5.color(myp5.drawingContext.strokeStyle).levels,
34
- black
35
- );
36
- });
37
- });
38
-
39
- suite('p5.prototype.resizeCanvas', function() {
40
- // let glStub;
41
-
42
- // afterEach(() => {
43
- // if (glStub) {
44
- // glStub.restore();
45
- // glStub = null;
46
- // }
47
- // });
48
-
49
- test('should resize canvas', function() {
50
- myp5.resizeCanvas(10, 20);
51
- assert.equal(myp5.canvas.width, 10 * myp5.pixelDensity());
52
- assert.equal(myp5.canvas.height, 20 * myp5.pixelDensity());
53
- });
54
-
55
- test('should restore fill color', function() {
56
- myp5.fill('#f0f0f0');
57
- myp5.resizeCanvas(10, 10);
58
- assert.equal(myp5.drawingContext.fillStyle, '#f0f0f0');
59
- });
60
-
61
- test('should restore stroke color', function() {
62
- myp5.stroke('#f0f0f0');
63
- myp5.resizeCanvas(10, 10);
64
- assert.equal(myp5.drawingContext.strokeStyle, '#f0f0f0');
65
- });
66
-
67
- test('should restore stroke weight', function() {
68
- myp5.strokeWeight(323);
69
- myp5.resizeCanvas(10, 10);
70
- assert.equal(myp5.drawingContext.lineWidth, 323);
71
- });
72
-
73
- test('should restore stroke cap', function() {
74
- myp5.strokeCap(myp5.PROJECT);
75
- myp5.resizeCanvas(10, 10);
76
- assert.equal(myp5.drawingContext.lineCap, myp5.PROJECT);
77
- });
78
- });
79
-
80
- suite('p5.prototype.blendMode', function() {
81
- var drawX = function() {
82
- myp5.strokeWeight(30);
83
- myp5.stroke(80, 150, 255);
84
- myp5.line(25, 25, 75, 75);
85
- myp5.stroke(255, 50, 50);
86
- myp5.line(75, 25, 25, 75);
87
- };
88
- test('should be a function', function() {
89
- assert.ok(myp5.blendMode);
90
- assert.typeOf(myp5.blendMode, 'function');
91
- });
92
- test('should be able to ADD', function() {
93
- myp5.blendMode(myp5.ADD);
94
- drawX();
95
- });
96
- test('should be able to MULTIPLY', function() {
97
- myp5.blendMode(myp5.MULTIPLY);
98
- drawX();
99
- });
100
- });
101
-
102
- suite('p5.prototype.setAttributes', function() {
103
- test('_glAttributes should be null at start', function() {
104
- assert.deepEqual(myp5._glAttributes, null);
105
- });
106
- test('_glAttributes should modify with setAttributes', function() {
107
- myp5.setAttributes({ antialias: false, perPixelLighting: true });
108
- assert.deepEqual(myp5._glAttributes.antialias, false);
109
- assert.deepEqual(myp5._glAttributes.perPixelLighting, true);
110
- });
111
- test('_glAttributes.antialias modify with smooth()', function() {
112
- myp5.smooth();
113
- assert.deepEqual(myp5._glAttributes.antialias, true);
114
- });
115
- });
116
- });