q5 2.10.6 → 2.10.8

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/deno.json +35 -0
  2. package/package.json +3 -6
  3. package/q5-deno-server.js +38 -0
  4. package/q5-server.js +3 -3
  5. package/q5.js +20 -11
  6. package/q5.min.js +1 -1
  7. package/src/q5-2d-drawing.js +2 -2
  8. package/src/q5-canvas.js +14 -8
  9. package/src/q5-input.js +1 -1
  10. package/src/q5-webgpu-canvas.js +3 -0
  11. package/test/core.test.js +33 -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,340 +0,0 @@
1
- suite('Core', function () {
2
- suite('p5.prototype.registerMethod', function () {
3
- teardown(function() {
4
- p5.prototype._registeredMethods = Q5.methods;
5
-
6
- p5.prototype._registeredMethods.init = [];
7
- p5.prototype._registeredMethods.beforePreload = [];
8
- p5.prototype._registeredMethods.preload = [];
9
- p5.prototype._registeredMethods.afterPreload = [];
10
- p5.prototype._registeredMethods.beforeSetup = [];
11
- p5.prototype._registeredMethods.setup = [];
12
- p5.prototype._registeredMethods.afterSetup = [];
13
- p5.prototype._registeredMethods.pre = [];
14
- p5.prototype._registeredMethods.draw = [];
15
- p5.prototype._registeredMethods.post = [];
16
- });
17
- test('should register and call "init" methods', function () {
18
- var myp5, myInitCalled;
19
- p5.prototype.registerMethod('init', function myInit() {
20
- assert(
21
- !myInitCalled,
22
- 'myInit should only be called once during test suite'
23
- );
24
- myInitCalled = true;
25
-
26
- this.myInitCalled = true;
27
- });
28
-
29
- myp5 = new p5(function (sketch) {
30
- assert(sketch.hasOwnProperty('myInitCalled'));
31
- assert(sketch.myInitCalled);
32
-
33
- sketch.sketchFunctionCalled = true;
34
- });
35
-
36
- assert(myp5.sketchFunctionCalled);
37
- });
38
- test('should register and call before and after "preload" hooks', function () {
39
- return new Promise(resolve => {
40
- let beforePreloadCalled = false;
41
- let preloadCalled = false;
42
- let afterPreloadCalled = false;
43
-
44
- p5.prototype.registerMethod('beforePreload', () => {
45
- beforePreloadCalled = true;
46
- });
47
-
48
- p5.prototype.registerMethod('preload', () => {
49
- assert.equal(beforePreloadCalled, true);
50
- preloadCalled = true;
51
- });
52
-
53
- p5.prototype.registerMethod('afterPreload', () => {
54
- if (beforePreloadCalled && preloadCalled) afterPreloadCalled = true;
55
- });
56
-
57
- myp5 = new p5(function (sketch) {
58
- sketch.preload = () => {};
59
- sketch.setup = () => {
60
- assert.equal(afterPreloadCalled, true);
61
- resolve();
62
- };
63
- });
64
- });
65
- });
66
- test('should register and call before and after "setup" hooks', function () {
67
- return new Promise(resolve => {
68
- let beforeSetupCalled = false;
69
- let setupCalled = false;
70
- let afterSetupCalled = false;
71
-
72
- p5.prototype.registerMethod('beforeSetup', () => {
73
- beforeSetupCalled = true;
74
- });
75
-
76
- p5.prototype.registerMethod('setup', () => {
77
- assert.equal(beforeSetupCalled, true);
78
- setupCalled = true;
79
- });
80
-
81
- p5.prototype.registerMethod('afterSetup', () => {
82
- if (beforeSetupCalled && setupCalled) afterSetupCalled = true;
83
- });
84
-
85
- myp5 = new p5(function (sketch) {
86
- sketch.setup = () => {};
87
- sketch.draw = () => {
88
- assert.equal(afterSetupCalled, true);
89
- resolve();
90
- };
91
- });
92
- });
93
- });
94
- test('should register and call pre and post "draw" hooks', function () {
95
- return new Promise(resolve => {
96
- let preDrawCalled = false;
97
- let drawCalled = false;
98
- let postDrawCalled = false;
99
-
100
- p5.prototype.registerMethod('pre', () => {
101
- preDrawCalled = true;
102
- });
103
-
104
- p5.prototype.registerMethod('draw', () => {
105
- assert.equal(preDrawCalled, true);
106
- drawCalled = true;
107
- });
108
-
109
- p5.prototype.registerMethod('post', () => {
110
- if (preDrawCalled && drawCalled) postDrawCalled = true;
111
- });
112
-
113
- myp5 = new p5(function (sketch) {
114
- sketch.draw = () => {
115
- if (sketch.frameCount === 2) {
116
- assert.equal(postDrawCalled, true);
117
- resolve();
118
- }
119
- };
120
- });
121
- });
122
- });
123
- });
124
-
125
- suite('new p5() / global mode', function () {
126
- var iframe;
127
-
128
- teardown(function () {
129
- if (iframe) {
130
- iframe.teardown();
131
- iframe = null;
132
- }
133
- });
134
-
135
- test('is triggered when "setup" is in window', function () {
136
- return new Promise(function (resolve, reject) {
137
- iframe = createP5Iframe();
138
- iframe.elt.contentWindow.setup = function () {
139
- resolve();
140
- };
141
- });
142
- });
143
-
144
- test('is triggered when "draw" is in window', function () {
145
- return new Promise(function (resolve, reject) {
146
- iframe = createP5Iframe();
147
- iframe.elt.contentWindow.draw = function () {
148
- resolve();
149
- };
150
- });
151
- });
152
-
153
- test('works when p5.js is loaded asynchronously', function () {
154
- return new Promise(function (resolve, reject) {
155
- iframe = createP5Iframe(`
156
- <script>
157
- window.onload = function() {
158
- var script = document.createElement('script');
159
- script.setAttribute('src', '${P5_SCRIPT_URL}');
160
-
161
- document.body.appendChild(script);
162
- }
163
- </script>`);
164
-
165
- iframe.elt.contentWindow.setup = resolve;
166
- });
167
- });
168
-
169
- test('works on-demand', function () {
170
- return new Promise(function (resolve, reject) {
171
- iframe = createP5Iframe(
172
- [
173
- P5_SCRIPT_TAG,
174
- '<script>',
175
- 'new p5();',
176
- 'originalP5Instance = p5.instance',
177
- 'myURL = p5.prototype.getURL();',
178
- 'function setup() { setupCalled = true; }',
179
- 'window.addEventListener("load", onDoneLoading, false);',
180
- '</script>'
181
- ].join('\n')
182
- );
183
- iframe.elt.contentWindow.onDoneLoading = resolve;
184
- }).then(function () {
185
- var win = iframe.elt.contentWindow;
186
- assert.equal(typeof win.myURL, 'string');
187
- assert.strictEqual(win.setupCalled, true);
188
- assert.strictEqual(win.originalP5Instance, win.p5.instance);
189
- });
190
- });
191
- });
192
-
193
- suite('p5.prototype._createFriendlyGlobalFunctionBinder', function () {
194
- var noop = function () {};
195
- var createBinder = p5.prototype._createFriendlyGlobalFunctionBinder;
196
- var logMsg, globalObject, bind, iframe;
197
-
198
- teardown(function () {
199
- if (iframe) {
200
- iframe.teardown();
201
- iframe = null;
202
- }
203
- });
204
-
205
- setup(function () {
206
- globalObject = {};
207
- logMsg = undefined;
208
- bind = createBinder({
209
- globalObject: globalObject,
210
- log: function (msg) {
211
- if (logMsg !== undefined) {
212
- // For simplicity, we'll write each test so it's expected to
213
- // log a message at most once.
214
- throw new Error('log() was called more than once');
215
- }
216
- logMsg = msg;
217
- }
218
- });
219
- });
220
- if (!window.IS_TESTING_MINIFIED_VERSION) {
221
- test('should warn when globals already exist', function () {
222
- const _friendlyErrorStub = sinon.stub(p5, '_friendlyError');
223
- try {
224
- globalObject.text = 'hi';
225
- bind('text', noop);
226
- expect(
227
- _friendlyErrorStub.calledOnce,
228
- 'p5._friendlyError was not called'
229
- ).to.be.true;
230
- } finally {
231
- _friendlyErrorStub.restore();
232
- }
233
- });
234
-
235
- test('should warn when globals are overwritten', function () {
236
- bind('text', noop);
237
- globalObject.text = 'boop';
238
-
239
- assert.match(logMsg, /You just changed the value of "text"/);
240
- assert.equal(globalObject.text, 'boop');
241
- assert.deepEqual(Object.keys(globalObject), ['text']);
242
- });
243
- } else {
244
- test('should NOT warn when globals already exist', function () {
245
- const _friendlyErrorStub = sinon.stub(p5, '_friendlyError');
246
- try {
247
- globalObject.text = 'hi';
248
- bind('text', noop);
249
- expect(
250
- _friendlyErrorStub.calledOnce,
251
- 'p5._friendlyError was called in minified p5.js'
252
- ).to.be.false;
253
- } finally {
254
- _friendlyErrorStub.restore();
255
- }
256
- });
257
-
258
- test('should NOT warn when globals are overwritten', function () {
259
- bind('text', noop);
260
- globalObject.text = 'boop';
261
-
262
- assert.isUndefined(logMsg);
263
- assert.equal(globalObject.text, 'boop');
264
- assert.deepEqual(Object.keys(globalObject), ['text']);
265
- });
266
- }
267
-
268
- test('should allow overwritten globals to be overwritten', function () {
269
- bind('text', noop);
270
- globalObject.text = 'boop';
271
- globalObject.text += 'blap';
272
- assert.equal(globalObject.text, 'boopblap');
273
- });
274
-
275
- test('should allow globals to be deleted', function () {
276
- bind('text', noop);
277
- delete globalObject.text;
278
- assert.isUndefined(globalObject.text);
279
- assert.isUndefined(logMsg);
280
- });
281
-
282
- test('should create enumerable globals', function () {
283
- bind('text', noop);
284
- assert.deepEqual(Object.keys(globalObject), ['text']);
285
- });
286
-
287
- test('should not warn about overwriting print()', function () {
288
- globalObject.print = window.print;
289
- bind('print', noop);
290
- assert.equal(globalObject.print, noop);
291
- assert.isUndefined(logMsg);
292
- });
293
-
294
- // This is a regression test for
295
- // https://github.com/processing/p5.js/issues/1350.
296
- test('should not warn about overwriting preload methods', function () {
297
- globalObject.loadJSON = function () {
298
- throw new Error();
299
- };
300
- bind('loadJSON', noop);
301
- assert.equal(globalObject.loadJSON, noop);
302
- assert.isUndefined(logMsg);
303
- });
304
-
305
- test('should not warn about overwriting non-functions', function () {
306
- bind('mouseX', 5);
307
- globalObject.mouseX = 50;
308
- assert.equal(globalObject.mouseX, 50);
309
- assert.isUndefined(logMsg);
310
- });
311
-
312
- test('instance preload is independent of window', function () {
313
- // callback for p5 instance mode.
314
- // It does not define a preload.
315
- // This tests that we don't call the global preload accidentally.
316
- function cb(s) {
317
- s.setup = function () {
318
- window.afterSetup();
319
- };
320
- }
321
- return new Promise(function (resolve) {
322
- iframe = createP5Iframe(
323
- [
324
- P5_SCRIPT_TAG,
325
- '<script>',
326
- 'globalPreloads = 0;',
327
- 'function setup() { }',
328
- 'function preload() { window.globalPreloads++; }',
329
- 'new p5(' + cb.toString() + ');',
330
- '</script>'
331
- ].join('\n')
332
- );
333
- iframe.elt.contentWindow.afterSetup = resolve;
334
- }).then(function () {
335
- var win = iframe.elt.contentWindow;
336
- assert.strictEqual(win.globalPreloads, 1);
337
- });
338
- });
339
- });
340
- });