pts 0.11.4 → 0.11.5

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.d.ts CHANGED
@@ -619,14 +619,16 @@ declare class CanvasForm extends VisualForm {
619
619
  protected _ctx: CanvasRenderingContext2D;
620
620
  protected _estimateTextWidth: (string: any) => number;
621
621
  protected _style: DefaultFormStyle;
622
- constructor(space: CanvasSpace | CanvasRenderingContext2D);
622
+ constructor(space?: CanvasSpace | CanvasRenderingContext2D);
623
623
  get space(): CanvasSpace;
624
624
  get ctx(): PtsCanvasRenderingContext2D;
625
625
  useOffscreen(off?: boolean, clear?: boolean | string): this;
626
626
  renderOffscreen(offset?: PtLike): void;
627
627
  alpha(a: number): this;
628
628
  fill(c: string | boolean | CanvasGradient | CanvasPattern): this;
629
+ fillOnly(c: string | boolean | CanvasGradient | CanvasPattern): this;
629
630
  stroke(c: string | boolean | CanvasGradient | CanvasPattern, width?: number, linejoin?: CanvasLineJoin, linecap?: CanvasLineCap): this;
631
+ strokeOnly(c: string | boolean | CanvasGradient | CanvasPattern, width?: number, linejoin?: CanvasLineJoin, linecap?: CanvasLineCap): this;
630
632
  applyFillStroke(filled?: boolean | string, stroked?: boolean | string, strokeWidth?: number): this;
631
633
  gradient(stops: [number, string][] | string[]): ((area1: GroupLike, area2?: GroupLike) => CanvasGradient);
632
634
  composite(mode?: GlobalCompositeOperation): this;
package/dist/index.js CHANGED
@@ -2178,7 +2178,7 @@ var Num = class {
2178
2178
  */
2179
2179
  static randomPt(a, b) {
2180
2180
  let p = new Pt(a.length);
2181
- let range = b ? Vec.subtract(b, a) : a;
2181
+ let range = b ? Vec.subtract(b.slice(), a) : a;
2182
2182
  let start = b ? a : new Pt(a.length).fill(0);
2183
2183
  for (let i = 0, len = p.length; i < len; i++) {
2184
2184
  p[i] = Num.random() * range[i] + start[i];
@@ -6254,6 +6254,14 @@ var CanvasForm = class extends VisualForm {
6254
6254
  return this;
6255
6255
  }
6256
6256
  /**
6257
+ * Set current fill style and remove stroke style.
6258
+ * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6259
+ */
6260
+ fillOnly(c) {
6261
+ this.stroke(false);
6262
+ return this.fill(c);
6263
+ }
6264
+ /**
6257
6265
  * Set current stroke style. Provide a valid color string or `false` to specify no stroke color.
6258
6266
  * @example `form.stroke("#F90")`, `form.stroke("rgba(0,0,0,.5")`, `form.stroke(false)`, `form.stroke("#000", 0.5, 'round', 'square')`
6259
6267
  * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
@@ -6283,6 +6291,17 @@ var CanvasForm = class extends VisualForm {
6283
6291
  }
6284
6292
  return this;
6285
6293
  }
6294
+ /**
6295
+ * Set stroke style and remove fill style.
6296
+ * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6297
+ * @param width Optional value (can be floating point) to set line width
6298
+ * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6299
+ * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6300
+ */
6301
+ strokeOnly(c, width, linejoin, linecap) {
6302
+ this.fill(false);
6303
+ return this.stroke(c, width, linejoin, linecap);
6304
+ }
6286
6305
  /**
6287
6306
  * A convenient function to apply fill and/or stroke after custom drawings using canvas context (eg, `form.ctx.ellipse(...)`).
6288
6307
  * You don't need to call this function if you're using Pts' drawing functions like `form.point` or `form.rect`
@@ -10302,7 +10321,9 @@ var Sound = class {
10302
10321
  reject("Error loading sound");
10303
10322
  });
10304
10323
  s._source.addEventListener("canplaythrough", function() {
10305
- s._node = s._ctx.createMediaElementSource(s._source);
10324
+ if (!s._node) {
10325
+ s._node = s._ctx.createMediaElementSource(s._source);
10326
+ }
10306
10327
  resolve(s);
10307
10328
  });
10308
10329
  });
package/dist/index.mjs CHANGED
@@ -2110,7 +2110,7 @@ var Num = class {
2110
2110
  */
2111
2111
  static randomPt(a, b) {
2112
2112
  let p = new Pt(a.length);
2113
- let range = b ? Vec.subtract(b, a) : a;
2113
+ let range = b ? Vec.subtract(b.slice(), a) : a;
2114
2114
  let start = b ? a : new Pt(a.length).fill(0);
2115
2115
  for (let i = 0, len = p.length; i < len; i++) {
2116
2116
  p[i] = Num.random() * range[i] + start[i];
@@ -6186,6 +6186,14 @@ var CanvasForm = class extends VisualForm {
6186
6186
  return this;
6187
6187
  }
6188
6188
  /**
6189
+ * Set current fill style and remove stroke style.
6190
+ * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6191
+ */
6192
+ fillOnly(c) {
6193
+ this.stroke(false);
6194
+ return this.fill(c);
6195
+ }
6196
+ /**
6189
6197
  * Set current stroke style. Provide a valid color string or `false` to specify no stroke color.
6190
6198
  * @example `form.stroke("#F90")`, `form.stroke("rgba(0,0,0,.5")`, `form.stroke(false)`, `form.stroke("#000", 0.5, 'round', 'square')`
6191
6199
  * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
@@ -6215,6 +6223,17 @@ var CanvasForm = class extends VisualForm {
6215
6223
  }
6216
6224
  return this;
6217
6225
  }
6226
+ /**
6227
+ * Set stroke style and remove fill style.
6228
+ * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6229
+ * @param width Optional value (can be floating point) to set line width
6230
+ * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6231
+ * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6232
+ */
6233
+ strokeOnly(c, width, linejoin, linecap) {
6234
+ this.fill(false);
6235
+ return this.stroke(c, width, linejoin, linecap);
6236
+ }
6218
6237
  /**
6219
6238
  * A convenient function to apply fill and/or stroke after custom drawings using canvas context (eg, `form.ctx.ellipse(...)`).
6220
6239
  * You don't need to call this function if you're using Pts' drawing functions like `form.point` or `form.rect`
@@ -10234,7 +10253,9 @@ var Sound = class {
10234
10253
  reject("Error loading sound");
10235
10254
  });
10236
10255
  s._source.addEventListener("canplaythrough", function() {
10237
- s._node = s._ctx.createMediaElementSource(s._source);
10256
+ if (!s._node) {
10257
+ s._node = s._ctx.createMediaElementSource(s._source);
10258
+ }
10238
10259
  resolve(s);
10239
10260
  });
10240
10261
  });
package/dist/pts.js CHANGED
@@ -2188,7 +2188,7 @@ See https://github.com/williamngan/pts for details. */
2188
2188
  */
2189
2189
  static randomPt(a, b) {
2190
2190
  let p = new Pt(a.length);
2191
- let range = b ? Vec.subtract(b, a) : a;
2191
+ let range = b ? Vec.subtract(b.slice(), a) : a;
2192
2192
  let start = b ? a : new Pt(a.length).fill(0);
2193
2193
  for (let i = 0, len = p.length; i < len; i++) {
2194
2194
  p[i] = Num.random() * range[i] + start[i];
@@ -6286,6 +6286,14 @@ See https://github.com/williamngan/pts for details. */
6286
6286
  return this;
6287
6287
  }
6288
6288
  /**
6289
+ * Set current fill style and remove stroke style.
6290
+ * @param c fill color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/fillStyle))
6291
+ */
6292
+ fillOnly(c) {
6293
+ this.stroke(false);
6294
+ return this.fill(c);
6295
+ }
6296
+ /**
6289
6297
  * Set current stroke style. Provide a valid color string or `false` to specify no stroke color.
6290
6298
  * @example `form.stroke("#F90")`, `form.stroke("rgba(0,0,0,.5")`, `form.stroke(false)`, `form.stroke("#000", 0.5, 'round', 'square')`
6291
6299
  * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
@@ -6315,6 +6323,17 @@ See https://github.com/williamngan/pts for details. */
6315
6323
  }
6316
6324
  return this;
6317
6325
  }
6326
+ /**
6327
+ * Set stroke style and remove fill style.
6328
+ * @param c stroke color which can be as color, gradient, or pattern. (See [canvas documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/strokeStyle))
6329
+ * @param width Optional value (can be floating point) to set line width
6330
+ * @param linejoin Optional string to set line joint style. Can be "miter", "bevel", or "round".
6331
+ * @param linecap Optional string to set line cap style. Can be "butt", "round", or "square".
6332
+ */
6333
+ strokeOnly(c, width, linejoin, linecap) {
6334
+ this.fill(false);
6335
+ return this.stroke(c, width, linejoin, linecap);
6336
+ }
6318
6337
  /**
6319
6338
  * A convenient function to apply fill and/or stroke after custom drawings using canvas context (eg, `form.ctx.ellipse(...)`).
6320
6339
  * You don't need to call this function if you're using Pts' drawing functions like `form.point` or `form.rect`
@@ -10366,7 +10385,9 @@ See https://github.com/williamngan/pts for details. */
10366
10385
  reject("Error loading sound");
10367
10386
  });
10368
10387
  s._source.addEventListener("canplaythrough", function() {
10369
- s._node = s._ctx.createMediaElementSource(s._source);
10388
+ if (!s._node) {
10389
+ s._node = s._ctx.createMediaElementSource(s._source);
10390
+ }
10370
10391
  resolve(s);
10371
10392
  });
10372
10393
  });