pts 0.10.5 → 0.10.9

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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * pts.js 0.10.5 - Copyright © 2017-2021 William Ngan and contributors.
2
+ * pts.js 0.10.9 - Copyright © 2017-2021 William Ngan and contributors.
3
3
  * Licensed under Apache 2.0 License.
4
4
  * See https://github.com/williamngan/pts for details.
5
5
  */
@@ -110,7 +110,7 @@ return /******/ (function(modules) { // webpackBootstrap
110
110
 
111
111
  "use strict";
112
112
 
113
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
113
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
114
114
  Object.defineProperty(exports, "__esModule", { value: true });
115
115
  exports.CanvasForm = exports.CanvasSpace = void 0;
116
116
  const Space_1 = __webpack_require__(/*! ./Space */ "./src/Space.ts");
@@ -202,6 +202,9 @@ class CanvasSpace extends Space_1.MultiTouchSpace {
202
202
  else {
203
203
  this._offscreen = false;
204
204
  }
205
+ if (opt.pixelDensity) {
206
+ this._pixelScale = opt.pixelDensity;
207
+ }
205
208
  return this;
206
209
  }
207
210
  set autoResize(auto) {
@@ -218,13 +221,13 @@ class CanvasSpace extends Space_1.MultiTouchSpace {
218
221
  get autoResize() { return this._autoResize; }
219
222
  resize(b, evt) {
220
223
  this.bound = b;
221
- this._canvas.width = this.bound.size.x * this._pixelScale;
222
- this._canvas.height = this.bound.size.y * this._pixelScale;
223
- this._canvas.style.width = Math.floor(this.bound.size.x) + "px";
224
- this._canvas.style.height = Math.floor(this.bound.size.y) + "px";
224
+ this._canvas.width = Math.ceil(this.bound.size.x) * this._pixelScale;
225
+ this._canvas.height = Math.ceil(this.bound.size.y) * this._pixelScale;
226
+ this._canvas.style.width = Math.ceil(this.bound.size.x) + "px";
227
+ this._canvas.style.height = Math.ceil(this.bound.size.y) + "px";
225
228
  if (this._offscreen) {
226
- this._offCanvas.width = this.bound.size.x * this._pixelScale;
227
- this._offCanvas.height = this.bound.size.y * this._pixelScale;
229
+ this._offCanvas.width = Math.ceil(this.bound.size.x) * this._pixelScale;
230
+ this._offCanvas.height = Math.ceil(this.bound.size.y) * this._pixelScale;
228
231
  }
229
232
  if (this._pixelScale != 1) {
230
233
  this._ctx.scale(this._pixelScale, this._pixelScale);
@@ -279,27 +282,29 @@ class CanvasSpace extends Space_1.MultiTouchSpace {
279
282
  if (bg)
280
283
  this._bgcolor = bg;
281
284
  const lastColor = this._ctx.fillStyle;
285
+ const px = Math.ceil(this.pixelScale);
282
286
  if (!this._bgcolor || this._bgcolor === "transparent") {
283
- this._ctx.clearRect(-1, -1, this._canvas.width + 1, this._canvas.height + 1);
287
+ this._ctx.clearRect(-px, -px, this._canvas.width + px, this._canvas.height + px);
284
288
  }
285
289
  else {
286
290
  if (this._bgcolor.indexOf("rgba") === 0 || (this._bgcolor.length === 9 && this._bgcolor.indexOf("#") === 0)) {
287
- this._ctx.clearRect(-1, -1, this._canvas.width + 1, this._canvas.height + 1);
291
+ this._ctx.clearRect(-px, -px, this._canvas.width + px, this._canvas.height + px);
288
292
  }
289
293
  this._ctx.fillStyle = this._bgcolor;
290
- this._ctx.fillRect(-1, -1, this._canvas.width + 1, this._canvas.height + 1);
294
+ this._ctx.fillRect(-px, -px, this._canvas.width + px, this._canvas.height + px);
291
295
  }
292
296
  this._ctx.fillStyle = lastColor;
293
297
  return this;
294
298
  }
295
299
  clearOffscreen(bg) {
296
300
  if (this._offscreen) {
301
+ const px = Math.ceil(this.pixelScale);
297
302
  if (bg) {
298
303
  this._offCtx.fillStyle = bg;
299
- this._offCtx.fillRect(-1, -1, this._canvas.width + 1, this._canvas.height + 1);
304
+ this._offCtx.fillRect(-px, -px, this._canvas.width + px, this._canvas.height + px);
300
305
  }
301
306
  else {
302
- this._offCtx.clearRect(-1, -1, this._offCanvas.width + 1, this._offCanvas.height + 1);
307
+ this._offCtx.clearRect(-px, -px, this._offCanvas.width + px, this._offCanvas.height + px);
303
308
  }
304
309
  }
305
310
  return this;
@@ -352,6 +357,8 @@ class CanvasForm extends Form_1.VisualForm {
352
357
  lineWidth: 1, lineJoin: "bevel", lineCap: "butt",
353
358
  globalAlpha: 1
354
359
  };
360
+ if (!space)
361
+ return this;
355
362
  const _setup = (ctx) => {
356
363
  this._ctx = ctx;
357
364
  this._ctx.fillStyle = this._style.fillStyle;
@@ -422,6 +429,19 @@ class CanvasForm extends Form_1.VisualForm {
422
429
  }
423
430
  return this;
424
431
  }
432
+ applyFillStroke(filled = true, stroked = true, strokeWidth = 1) {
433
+ if (filled) {
434
+ if (typeof filled === 'string')
435
+ this.fill(filled);
436
+ this._ctx.fill();
437
+ }
438
+ if (stroked) {
439
+ if (typeof stroked === 'string')
440
+ this.stroke(stroked, strokeWidth);
441
+ this._ctx.stroke();
442
+ }
443
+ return this;
444
+ }
425
445
  gradient(stops) {
426
446
  let vals = [];
427
447
  if (stops.length < 2)
@@ -790,7 +810,7 @@ exports.CanvasForm = CanvasForm;
790
810
 
791
811
  "use strict";
792
812
 
793
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
813
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
794
814
  Object.defineProperty(exports, "__esModule", { value: true });
795
815
  exports.Color = void 0;
796
816
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -1046,12 +1066,12 @@ class Color extends Pt_1.Pt {
1046
1066
  static XYZtoRGB(xyz, normalizedInput = false, normalizedOutput = false) {
1047
1067
  let [x, y, z] = (!normalizedInput) ? xyz.$normalize() : xyz;
1048
1068
  let rgb = [
1049
- x * 3.2404542 + y * -1.5371385 + z * -0.4985314,
1050
- x * -0.9692660 + y * 1.8760108 + z * 0.0415560,
1051
- x * 0.0556434 + y * -0.2040259 + z * 1.0572252
1069
+ x * 3.2406254773200533 + y * -1.5372079722103187 + z * -0.4986285986982479,
1070
+ x * -0.9689307147293197 + y * 1.8757560608852415 + z * 0.041517523842953964,
1071
+ x * 0.055710120445510616 + y * -0.2040210505984867 + z * 1.0569959422543882
1052
1072
  ];
1053
1073
  for (let i = 0; i < 3; i++) {
1054
- rgb[i] = (rgb[i] < 0) ? 0 : (rgb[i] > 0.0031308) ? (1.055 * Math.pow(rgb[i], 1 / 2.4) - 0.055) : (12.92 * rgb[i]);
1074
+ rgb[i] = (rgb[i] > 0.0031308) ? (1.055 * Math.pow(rgb[i], 1 / 2.4) - 0.055) : (12.92 * rgb[i]);
1055
1075
  rgb[i] = Math.max(0, Math.min(1, rgb[i]));
1056
1076
  if (!normalizedOutput)
1057
1077
  rgb[i] = Math.round(rgb[i] * 255);
@@ -1061,8 +1081,10 @@ class Color extends Pt_1.Pt {
1061
1081
  }
1062
1082
  static XYZtoLAB(xyz, normalizedInput = false, normalizedOutput = false) {
1063
1083
  let c = (normalizedInput) ? xyz.$normalize(false) : xyz.clone();
1084
+ const eps = 0.00885645167;
1085
+ const kap = 903.296296296;
1064
1086
  c.divide(Color.D65);
1065
- let fn = (n) => (n > 0.008856) ? Math.pow(n, 1 / 3) : (7.787 * n) + 16 / 116;
1087
+ let fn = (n) => (n > eps) ? Math.pow(n, 1 / 3) : (kap * n + 16) / 116;
1066
1088
  let cy = fn(c[1]);
1067
1089
  let cc = Color.lab((116 * cy) - 16, 500 * (fn(c[0]) - cy), 200 * (cy - fn(c[2])), xyz.alpha);
1068
1090
  return (normalizedOutput) ? cc.normalize() : cc;
@@ -1072,12 +1094,12 @@ class Color extends Pt_1.Pt {
1072
1094
  let y = (c[0] + 16) / 116;
1073
1095
  let x = (c[1] / 500) + y;
1074
1096
  let z = y - c[2] / 200;
1075
- let fn = (n) => {
1076
- let nnn = n * n * n;
1077
- return (nnn > 0.008856) ? nnn : (n - 16 / 116) / 7.787;
1078
- };
1097
+ const eps = 0.00885645167;
1098
+ const kap = 903.296296296;
1079
1099
  let d = Color.D65;
1080
- let cc = Color.xyz(Math.max(0, d[0] * fn(x)), Math.max(0, d[1] * fn(y)), Math.max(0, d[2] * fn(z)), lab.alpha);
1100
+ const xxx = Math.pow(x, 3);
1101
+ const zzz = Math.pow(z, 3);
1102
+ let cc = Color.xyz(d[0] * ((xxx > eps) ? xxx : (116 * x - 16) / kap), d[1] * ((c[0] > kap * eps) ? Math.pow((c[0] + 16) / 116, 3) : c[0] / kap), d[2] * ((zzz > eps) ? zzz : (116 * z - 16) / kap), lab.alpha);
1081
1103
  return (normalizedOutput) ? cc.normalize() : cc;
1082
1104
  }
1083
1105
  static XYZtoLUV(xyz, normalizedInput = false, normalizedOutput = false) {
@@ -1140,7 +1162,7 @@ Color.ranges = {
1140
1162
 
1141
1163
  "use strict";
1142
1164
 
1143
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
1165
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
1144
1166
  Object.defineProperty(exports, "__esModule", { value: true });
1145
1167
  exports.Delaunay = exports.Noise = exports.Create = void 0;
1146
1168
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -1152,11 +1174,11 @@ class Create {
1152
1174
  static distributeRandom(bound, count, dimensions = 2) {
1153
1175
  let pts = new Pt_1.Group();
1154
1176
  for (let i = 0; i < count; i++) {
1155
- let p = [bound.x + Math.random() * bound.width];
1177
+ let p = [bound.x + Num_1.Num.random() * bound.width];
1156
1178
  if (dimensions > 1)
1157
- p.push(bound.y + Math.random() * bound.height);
1179
+ p.push(bound.y + Num_1.Num.random() * bound.height);
1158
1180
  if (dimensions > 2)
1159
- p.push(bound.z + Math.random() * bound.depth);
1181
+ p.push(bound.z + Num_1.Num.random() * bound.depth);
1160
1182
  pts.push(new Pt_1.Pt(p));
1161
1183
  }
1162
1184
  return pts;
@@ -1202,7 +1224,7 @@ class Create {
1202
1224
  return g;
1203
1225
  }
1204
1226
  static noisePts(pts, dx = 0.01, dy = 0.01, rows = 0, columns = 0) {
1205
- let seed = Math.random();
1227
+ let seed = Num_1.Num.random();
1206
1228
  let g = new Pt_1.Group();
1207
1229
  let i = 0;
1208
1230
  for (let p of pts) {
@@ -1432,7 +1454,7 @@ exports.Delaunay = Delaunay;
1432
1454
 
1433
1455
  "use strict";
1434
1456
 
1435
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
1457
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
1436
1458
  Object.defineProperty(exports, "__esModule", { value: true });
1437
1459
  exports.HTMLForm = exports.HTMLSpace = exports.DOMSpace = void 0;
1438
1460
  const Space_1 = __webpack_require__(/*! ./Space */ "./src/Space.ts");
@@ -1897,7 +1919,7 @@ HTMLForm.domID = 0;
1897
1919
 
1898
1920
  "use strict";
1899
1921
 
1900
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
1922
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
1901
1923
  Object.defineProperty(exports, "__esModule", { value: true });
1902
1924
  exports.Font = exports.VisualForm = exports.Form = void 0;
1903
1925
  class Form {
@@ -2163,7 +2185,7 @@ exports.Img = Img;
2163
2185
 
2164
2186
  "use strict";
2165
2187
 
2166
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
2188
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
2167
2189
  Object.defineProperty(exports, "__esModule", { value: true });
2168
2190
  exports.Mat = exports.Vec = void 0;
2169
2191
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -2430,13 +2452,14 @@ exports.Mat = Mat;
2430
2452
 
2431
2453
  "use strict";
2432
2454
 
2433
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
2455
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
2434
2456
  Object.defineProperty(exports, "__esModule", { value: true });
2435
2457
  exports.Range = exports.Shaping = exports.Geom = exports.Num = void 0;
2436
2458
  const Util_1 = __webpack_require__(/*! ./Util */ "./src/Util.ts");
2437
2459
  const Op_1 = __webpack_require__(/*! ./Op */ "./src/Op.ts");
2438
2460
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
2439
2461
  const LinearAlgebra_1 = __webpack_require__(/*! ./LinearAlgebra */ "./src/LinearAlgebra.ts");
2462
+ const uheprng_1 = __webpack_require__(/*! ./uheprng */ "./src/uheprng.ts");
2440
2463
  class Num {
2441
2464
  static equals(a, b, threshold = 0.00001) {
2442
2465
  return Math.abs(a - b) < threshold;
@@ -2461,14 +2484,14 @@ class Num {
2461
2484
  }
2462
2485
  static randomRange(a, b = 0) {
2463
2486
  let r = (a > b) ? (a - b) : (b - a);
2464
- return a + Math.random() * r;
2487
+ return a + Num.random() * r;
2465
2488
  }
2466
2489
  static randomPt(a, b) {
2467
2490
  let p = new Pt_1.Pt(a.length);
2468
2491
  let range = b ? LinearAlgebra_1.Vec.subtract(b, a) : a;
2469
2492
  let start = b ? a : new Pt_1.Pt(a.length).fill(0);
2470
2493
  for (let i = 0, len = p.length; i < len; i++) {
2471
- p[i] = Math.random() * range[i] + start[i];
2494
+ p[i] = Num.random() * range[i] + start[i];
2472
2495
  }
2473
2496
  return p;
2474
2497
  }
@@ -2499,6 +2522,14 @@ class Num {
2499
2522
  let max = Math.max(targetA, targetB);
2500
2523
  return Num.normalizeValue(n, currA, currB) * (max - min) + min;
2501
2524
  }
2525
+ static seed(seed) {
2526
+ this.generator = uheprng_1.default(seed);
2527
+ }
2528
+ static random() {
2529
+ return this.generator
2530
+ ? this.generator.random()
2531
+ : Math.random();
2532
+ }
2502
2533
  }
2503
2534
  exports.Num = Num;
2504
2535
  class Geom {
@@ -2916,7 +2947,7 @@ exports.Range = Range;
2916
2947
 
2917
2948
  "use strict";
2918
2949
 
2919
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
2950
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
2920
2951
  Object.defineProperty(exports, "__esModule", { value: true });
2921
2952
  exports.Curve = exports.Polygon = exports.Triangle = exports.Circle = exports.Rectangle = exports.Line = void 0;
2922
2953
  const Util_1 = __webpack_require__(/*! ./Util */ "./src/Util.ts");
@@ -3914,7 +3945,7 @@ exports.Curve = Curve;
3914
3945
 
3915
3946
  "use strict";
3916
3947
 
3917
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
3948
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
3918
3949
  Object.defineProperty(exports, "__esModule", { value: true });
3919
3950
  exports.Body = exports.Particle = exports.World = void 0;
3920
3951
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -4669,7 +4700,7 @@ exports.Sound = Sound;
4669
4700
 
4670
4701
  "use strict";
4671
4702
 
4672
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
4703
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
4673
4704
  Object.defineProperty(exports, "__esModule", { value: true });
4674
4705
  exports.Bound = exports.Group = exports.Pt = void 0;
4675
4706
  const Util_1 = __webpack_require__(/*! ./Util */ "./src/Util.ts");
@@ -4690,7 +4721,7 @@ class Pt extends Float32Array {
4690
4721
  p.fill(defaultValue);
4691
4722
  if (randomize) {
4692
4723
  for (let i = 0, len = p.length; i < len; i++) {
4693
- p[i] = p[i] * Math.random();
4724
+ p[i] = p[i] * Num_1.Num.random();
4694
4725
  }
4695
4726
  }
4696
4727
  return new Pt(p);
@@ -5146,7 +5177,7 @@ exports.Bound = Bound;
5146
5177
 
5147
5178
  "use strict";
5148
5179
 
5149
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5180
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5150
5181
  Object.defineProperty(exports, "__esModule", { value: true });
5151
5182
  exports.MultiTouchSpace = exports.Space = void 0;
5152
5183
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -5241,7 +5272,7 @@ class Space {
5241
5272
  this._time.end = t;
5242
5273
  return this;
5243
5274
  }
5244
- playOnce(duration = 5000) {
5275
+ playOnce(duration = 0) {
5245
5276
  this.play();
5246
5277
  this.stop(duration);
5247
5278
  return this;
@@ -5278,44 +5309,51 @@ class MultiTouchSpace extends Space {
5278
5309
  bindCanvas(evt, callback, options = {}) {
5279
5310
  this._canvas.addEventListener(evt, callback, options);
5280
5311
  }
5281
- unbindCanvas(evt, callback) {
5282
- this._canvas.removeEventListener(evt, callback);
5312
+ unbindCanvas(evt, callback, options = {}) {
5313
+ this._canvas.removeEventListener(evt, callback, options);
5283
5314
  }
5284
5315
  bindMouse(_bind = true) {
5285
5316
  if (_bind) {
5286
- this.bindCanvas("mousedown", this._mouseDown.bind(this));
5287
- this.bindCanvas("mouseup", this._mouseUp.bind(this));
5288
- this.bindCanvas("mouseover", this._mouseOver.bind(this));
5289
- this.bindCanvas("mouseout", this._mouseOut.bind(this));
5290
- this.bindCanvas("mousemove", this._mouseMove.bind(this));
5291
- this.bindCanvas("click", this._mouseClick.bind(this));
5292
- this.bindCanvas("contextmenu", this._contextMenu.bind(this));
5317
+ this._mouseDown = this._mouseDown.bind(this);
5318
+ this._mouseUp = this._mouseUp.bind(this);
5319
+ this._mouseOver = this._mouseOver.bind(this);
5320
+ this._mouseOut = this._mouseOut.bind(this);
5321
+ this._mouseMove = this._mouseMove.bind(this);
5322
+ this._mouseClick = this._mouseClick.bind(this);
5323
+ this._contextMenu = this._contextMenu.bind(this);
5324
+ this.bindCanvas("mousedown", this._mouseDown);
5325
+ this.bindCanvas("mouseup", this._mouseUp);
5326
+ this.bindCanvas("mouseover", this._mouseOver);
5327
+ this.bindCanvas("mouseout", this._mouseOut);
5328
+ this.bindCanvas("mousemove", this._mouseMove);
5329
+ this.bindCanvas("click", this._mouseClick);
5330
+ this.bindCanvas("contextmenu", this._contextMenu);
5293
5331
  this._hasMouse = true;
5294
5332
  }
5295
5333
  else {
5296
- this.unbindCanvas("mousedown", this._mouseDown.bind(this));
5297
- this.unbindCanvas("mouseup", this._mouseUp.bind(this));
5298
- this.unbindCanvas("mouseover", this._mouseOver.bind(this));
5299
- this.unbindCanvas("mouseout", this._mouseOut.bind(this));
5300
- this.unbindCanvas("mousemove", this._mouseMove.bind(this));
5301
- this.unbindCanvas("click", this._mouseClick.bind(this));
5302
- this.unbindCanvas("contextmenu", this._contextMenu.bind(this));
5334
+ this.unbindCanvas("mousedown", this._mouseDown);
5335
+ this.unbindCanvas("mouseup", this._mouseUp);
5336
+ this.unbindCanvas("mouseover", this._mouseOver);
5337
+ this.unbindCanvas("mouseout", this._mouseOut);
5338
+ this.unbindCanvas("mousemove", this._mouseMove);
5339
+ this.unbindCanvas("click", this._mouseClick);
5340
+ this.unbindCanvas("contextmenu", this._contextMenu);
5303
5341
  this._hasMouse = false;
5304
5342
  }
5305
5343
  return this;
5306
5344
  }
5307
- bindTouch(_bind = true) {
5308
- if (_bind) {
5309
- this.bindCanvas("touchstart", this._touchStart.bind(this), { passive: true });
5345
+ bindTouch(bind = true, passive = false) {
5346
+ if (bind) {
5347
+ this.bindCanvas("touchstart", this._touchStart.bind(this), { passive: passive });
5310
5348
  this.bindCanvas("touchend", this._mouseUp.bind(this));
5311
- this.bindCanvas("touchmove", this._touchMove.bind(this), { passive: true });
5349
+ this.bindCanvas("touchmove", this._touchMove.bind(this), { passive: passive });
5312
5350
  this.bindCanvas("touchcancel", this._mouseOut.bind(this));
5313
5351
  this._hasTouch = true;
5314
5352
  }
5315
5353
  else {
5316
- this.unbindCanvas("touchstart", this._touchStart.bind(this));
5354
+ this.unbindCanvas("touchstart", this._touchStart.bind(this), { passive: passive });
5317
5355
  this.unbindCanvas("touchend", this._mouseUp.bind(this));
5318
- this.unbindCanvas("touchmove", this._touchMove.bind(this));
5356
+ this.unbindCanvas("touchmove", this._touchMove.bind(this), { passive: passive });
5319
5357
  this.unbindCanvas("touchcancel", this._mouseOut.bind(this));
5320
5358
  this._hasTouch = false;
5321
5359
  }
@@ -5432,7 +5470,7 @@ exports.MultiTouchSpace = MultiTouchSpace;
5432
5470
 
5433
5471
  "use strict";
5434
5472
 
5435
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5473
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5436
5474
  Object.defineProperty(exports, "__esModule", { value: true });
5437
5475
  exports.SVGForm = exports.SVGSpace = void 0;
5438
5476
  const Form_1 = __webpack_require__(/*! ./Form */ "./src/Form.ts");
@@ -5815,7 +5853,7 @@ SVGForm.domID = 0;
5815
5853
 
5816
5854
  "use strict";
5817
5855
 
5818
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5856
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5819
5857
  Object.defineProperty(exports, "__esModule", { value: true });
5820
5858
  exports.Typography = void 0;
5821
5859
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -5870,7 +5908,7 @@ exports.Typography = Typography;
5870
5908
 
5871
5909
  "use strict";
5872
5910
 
5873
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5911
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
5874
5912
  Object.defineProperty(exports, "__esModule", { value: true });
5875
5913
  exports.UIDragger = exports.UIButton = exports.UI = exports.UIPointerActions = exports.UIShape = void 0;
5876
5914
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
@@ -6156,9 +6194,10 @@ exports.UIDragger = UIDragger;
6156
6194
 
6157
6195
  "use strict";
6158
6196
 
6159
- /*! Source code licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
6197
+ /*! Pts.js is licensed under Apache License 2.0. Copyright © 2017-current William Ngan and contributors. (https://github.com/williamngan/pts) */
6160
6198
  Object.defineProperty(exports, "__esModule", { value: true });
6161
6199
  exports.Util = exports.Const = void 0;
6200
+ const Num_1 = __webpack_require__(/*! ./Num */ "./src/Num.ts");
6162
6201
  const Pt_1 = __webpack_require__(/*! ./Pt */ "./src/Pt.ts");
6163
6202
  exports.Const = {
6164
6203
  xy: "xy",
@@ -6230,7 +6269,7 @@ class Util {
6230
6269
  }
6231
6270
  static randomInt(range, start = 0) {
6232
6271
  Util.warn("Util.randomInt is deprecated. Please use `Num.randomRange`");
6233
- return Math.floor(Math.random() * range) + start;
6272
+ return Math.floor(Num_1.Num.random() * range) + start;
6234
6273
  }
6235
6274
  static split(pts, size, stride, loopBack = false, matchSize = true) {
6236
6275
  let chunks = [];
@@ -6384,6 +6423,89 @@ __exportStar(__webpack_require__(/*! ./Typography */ "./src/Typography.ts"), exp
6384
6423
  __exportStar(__webpack_require__(/*! ./Physics */ "./src/Physics.ts"), exports);
6385
6424
  __exportStar(__webpack_require__(/*! ./Play */ "./src/Play.ts"), exports);
6386
6425
  __exportStar(__webpack_require__(/*! ./UI */ "./src/UI.ts"), exports);
6426
+ __exportStar(__webpack_require__(/*! ./Image */ "./src/Image.ts"), exports);
6427
+
6428
+
6429
+ /***/ }),
6430
+
6431
+ /***/ "./src/uheprng.ts":
6432
+ /*!************************!*\
6433
+ !*** ./src/uheprng.ts ***!
6434
+ \************************/
6435
+ /*! no static exports found */
6436
+ /***/ (function(module, exports, __webpack_require__) {
6437
+
6438
+ "use strict";
6439
+
6440
+ Object.defineProperty(exports, "__esModule", { value: true });
6441
+ function Mash() {
6442
+ var n = 0xefc8249d;
6443
+ var mash = function (data) {
6444
+ if (data) {
6445
+ data = data.toString();
6446
+ for (var i = 0; i < data.length; i++) {
6447
+ n += data.charCodeAt(i);
6448
+ var h = 0.02519603282416938 * n;
6449
+ n = h >>> 0;
6450
+ h -= n;
6451
+ h *= n;
6452
+ n = h >>> 0;
6453
+ h -= n;
6454
+ n += h * 0x100000000;
6455
+ }
6456
+ return (n >>> 0) * 2.3283064365386963e-10;
6457
+ }
6458
+ else
6459
+ n = 0xefc8249d;
6460
+ };
6461
+ return mash;
6462
+ }
6463
+ function default_1(seed) {
6464
+ var o = 48;
6465
+ var c = 1;
6466
+ var p = o;
6467
+ var s = new Array(o);
6468
+ var i, j, k = 0;
6469
+ var mash = Mash();
6470
+ for (i = 0; i < o; i++)
6471
+ s[i] = mash(Math.random().toString());
6472
+ function initState() {
6473
+ mash();
6474
+ for (i = 0; i < o; i++)
6475
+ s[i] = mash(' ');
6476
+ c = 1;
6477
+ p = o;
6478
+ }
6479
+ function cleanString(inStr) {
6480
+ inStr = inStr.replace(/(^\s*)|(\s*$)/gi, '');
6481
+ inStr = inStr.replace(/[\x00-\x1F]/gi, '');
6482
+ inStr = inStr.replace(/\n /, '\n');
6483
+ return inStr;
6484
+ }
6485
+ function hashString(inStr) {
6486
+ inStr = cleanString(inStr);
6487
+ mash(inStr);
6488
+ for (i = 0; i < inStr.length; i++) {
6489
+ k = inStr.charCodeAt(i);
6490
+ for (j = 0; j < o; j++) {
6491
+ s[j] -= mash(k.toString());
6492
+ if (s[j] < 0)
6493
+ s[j] += 1;
6494
+ }
6495
+ }
6496
+ }
6497
+ initState();
6498
+ hashString(seed);
6499
+ return {
6500
+ random() {
6501
+ if (++p >= o)
6502
+ p = 0;
6503
+ var t = 1768863 * s[p] + c * 2.3283064365386963e-10;
6504
+ return (s[p] = t - (c = t | 0));
6505
+ }
6506
+ };
6507
+ }
6508
+ exports.default = default_1;
6387
6509
 
6388
6510
 
6389
6511
  /***/ })
package/dist/pts.d.ts CHANGED
@@ -16,12 +16,7 @@ export class CanvasSpace extends MultiTouchSpace {
16
16
  protected _initialResize: boolean;
17
17
  constructor(elem: string | Element, callback?: Function);
18
18
  protected _createElement(elem: string, id: any): HTMLElement;
19
- setup(opt: {
20
- bgcolor?: string;
21
- resize?: boolean;
22
- retina?: boolean;
23
- offscreen?: boolean;
24
- }): this;
19
+ setup(opt: CanvasSpaceOptions): this;
25
20
  set autoResize(auto: boolean);
26
21
  get autoResize(): boolean;
27
22
  resize(b: Bound, evt?: Event): this;
@@ -56,6 +51,7 @@ export class CanvasForm extends VisualForm {
56
51
  alpha(a: number): this;
57
52
  fill(c: string | boolean | CanvasGradient | CanvasPattern): this;
58
53
  stroke(c: string | boolean | CanvasGradient | CanvasPattern, width?: number, linejoin?: CanvasLineJoin, linecap?: CanvasLineCap): this;
54
+ applyFillStroke(filled?: boolean | string, stroked?: boolean | string, strokeWidth?: number): this;
59
55
  gradient(stops: [number, string][] | string[]): ((area1: GroupLike, area2?: GroupLike) => CanvasGradient);
60
56
  composite(mode?: string): this;
61
57
  clip(): this;
@@ -410,6 +406,7 @@ export class Mat {
410
406
  }
411
407
 
412
408
  export class Num {
409
+ static generator: any;
413
410
  static equals(a: number, b: number, threshold?: number): boolean;
414
411
  static lerp(a: number, b: number, t: number): number;
415
412
  static clamp(val: number, min: number, max: number): number;
@@ -422,6 +419,8 @@ export class Num {
422
419
  static average(pts: PtLikeIterable): Pt;
423
420
  static cycle(t: number, method?: (t: number) => number): number;
424
421
  static mapToRange(n: number, currA: number, currB: number, targetA: number, targetB: number): number;
422
+ static seed(seed: string): void;
423
+ static random(): number;
425
424
  }
426
425
  export class Geom {
427
426
  static boundAngle(angle: number): number;
@@ -962,9 +961,9 @@ export abstract class MultiTouchSpace extends Space {
962
961
  protected _canvas: EventTarget;
963
962
  get pointer(): Pt;
964
963
  bindCanvas(evt: string, callback: EventListener, options?: any): void;
965
- unbindCanvas(evt: string, callback: EventListener): void;
964
+ unbindCanvas(evt: string, callback: EventListener, options?: any): void;
966
965
  bindMouse(_bind?: boolean): this;
967
- bindTouch(_bind?: boolean): this;
966
+ bindTouch(bind?: boolean, passive?: boolean): this;
968
967
  touchesToPoints(evt: TouchEvent, which?: TouchPointsKey): Pt[];
969
968
  protected _mouseAction(type: string, evt: MouseEvent | TouchEvent): void;
970
969
  protected _mouseDown(evt: MouseEvent | TouchEvent): boolean;
@@ -1081,6 +1080,13 @@ export interface PtsCanvasRenderingContext2D extends CanvasRenderingContext2D {
1081
1080
  oBackingStorePixelRatio?: number;
1082
1081
  backingStorePixelRatio?: number;
1083
1082
  }
1083
+ export type CanvasSpaceOptions = {
1084
+ bgcolor?: string;
1085
+ resize?: boolean;
1086
+ retina?: boolean;
1087
+ offscreen?: boolean;
1088
+ pixelDensity?: number;
1089
+ };
1084
1090
  export type ColorType = "rgb" | "hsl" | "hsb" | "lab" | "lch" | "luv" | "xyz";
1085
1091
  export type DelaunayShape = {
1086
1092
  i: number;
@@ -1148,6 +1154,10 @@ export class Typography {
1148
1154
  static fontSizeToThreshold(threshold: number, direction?: number): (a: number, b: number) => number;
1149
1155
  }
1150
1156
 
1157
+ export default function (seed: string): {
1158
+ random(): number;
1159
+ };
1160
+
1151
1161
  export const UIShape: {
1152
1162
  rectangle: string;
1153
1163
  circle: string;