modern-canvas 0.18.3 → 0.19.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.
package/dist/index.js CHANGED
@@ -775,18 +775,18 @@ var pt = class {
775
775
  hueRotate(e = 0) {
776
776
  let t = Math.sin(e), n = Math.cos(e), r = .213, i = .715, a = .072;
777
777
  return this.multiply([
778
- r + n * (1 - r) + t * -r,
779
- i + n * -i + t * -i,
780
- a + n * -a + t * (1 - a),
778
+ r + n * (1 - r) + t * -.213,
779
+ i + n * -.715 + t * -.715,
780
+ a + n * -.072 + t * (1 - a),
781
781
  0,
782
782
  0,
783
- r + n * -r + t * .143,
783
+ r + n * -.213 + t * .143,
784
784
  i + n * (1 - i) + t * .14,
785
- a + n * -a + t * -.283,
785
+ a + n * -.072 + t * -.283,
786
786
  0,
787
787
  0,
788
- r + n * -r + t * -(1 - r),
789
- i + n * -i + t * i,
788
+ r + n * -.213 + t * -.787,
789
+ i + n * -.715 + t * i,
790
790
  a + n * (1 - a) + t * a,
791
791
  0,
792
792
  0,
@@ -1077,12 +1077,12 @@ var pt = class {
1077
1077
  }
1078
1078
  };
1079
1079
  //#endregion
1080
- //#region \0@oxc-project+runtime@0.130.0/helpers/decorateMetadata.js
1080
+ //#region \0@oxc-project+runtime@0.132.0/helpers/decorateMetadata.js
1081
1081
  function D(e, t) {
1082
1082
  if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
1083
1083
  }
1084
1084
  //#endregion
1085
- //#region \0@oxc-project+runtime@0.130.0/helpers/decorate.js
1085
+ //#region \0@oxc-project+runtime@0.132.0/helpers/decorate.js
1086
1086
  function O(e, t, n, r) {
1087
1087
  var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
1088
1088
  if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
@@ -6410,6 +6410,9 @@ var Ri = class extends C {
6410
6410
  _parent;
6411
6411
  _path2DSet = new se();
6412
6412
  _localPath;
6413
+ _hitPath2DSet;
6414
+ _hitWidth = 0;
6415
+ _hitHeight = 0;
6413
6416
  constructor(e) {
6414
6417
  super(), this._parent = e, this._updatePath2DSet();
6415
6418
  }
@@ -6435,6 +6438,30 @@ var Ri = class extends C {
6435
6438
  isValid() {
6436
6439
  return !!(this.enabled && this._path2DSet.paths.some((e) => e.getLength()));
6437
6440
  }
6441
+ isPointInside(e, t) {
6442
+ let n = t?.strokeWidth ?? 1, r = t?.tolerance ?? 0, i = this._localPath;
6443
+ if (i && i.getLength()) return i.isPointInStroke(e, {
6444
+ strokeWidth: n,
6445
+ tolerance: r,
6446
+ closed: !1
6447
+ });
6448
+ let a = this._getHitPath2DSet();
6449
+ return a ? !!a.hitTest(e, {
6450
+ stroke: !0,
6451
+ tolerance: r + n / 2
6452
+ }) : !1;
6453
+ }
6454
+ _getHitPath2DSet() {
6455
+ if (!this.isValid()) return;
6456
+ let { width: e, height: t } = this._parent.size;
6457
+ if (!(!e || !t)) {
6458
+ if (!this._hitPath2DSet || this._hitWidth !== e || this._hitHeight !== t) {
6459
+ let n = new v().scale(e, t);
6460
+ this._hitPath2DSet = new se(this._path2DSet.paths.map((e) => e.clone().applyTransform(n))), this._hitWidth = e, this._hitHeight = t;
6461
+ }
6462
+ return this._hitPath2DSet;
6463
+ }
6464
+ }
6438
6465
  _updatePath2DSet() {
6439
6466
  let e;
6440
6467
  if (this.svg) {
@@ -6461,7 +6488,7 @@ var Ri = class extends C {
6461
6488
  let [t, n, r, i] = e;
6462
6489
  this._path2DSet.paths.forEach((e) => {
6463
6490
  e.applyTransform(new v().translate(-t, -n).scale(1 / r, 1 / i));
6464
- });
6491
+ }), this._hitPath2DSet = void 0;
6465
6492
  }
6466
6493
  draw(e = !1) {
6467
6494
  if (!e && this._localPath && this._localPath.getLength()) this._parent.context.addPath(this._localPath.clone());
@@ -7166,8 +7193,8 @@ var Z = {
7166
7193
  this.isVisibleInTree() && this._input(e, t);
7167
7194
  }
7168
7195
  _positionInput(e, t) {
7169
- let { width: n, height: r } = this.size;
7170
- return e.x >= 0 && e.x < n && e.y >= 0 && e.y < r;
7196
+ let { width: n, height: r } = this.size, i = (Number(this._outline.width) || 0) / 2 + 1;
7197
+ return e.x < -i || e.x >= n + i || e.y < -i || e.y >= r + i ? !1 : this._shape.isValid() || this._shape.localPath ? this._shape.isPointInside(e, { strokeWidth: Number(this._outline.width) || 1 }) : e.x >= 0 && e.x < n && e.y >= 0 && e.y < r;
7171
7198
  }
7172
7199
  _input(e, t) {
7173
7200
  switch (t) {
@@ -1,4 +1,5 @@
1
1
  import type { NormalizedShape } from 'modern-idoc';
2
+ import type { Vector2Like } from 'modern-path2d';
2
3
  import type { Element2D } from './Element2D';
3
4
  import { Path2D, Path2DSet } from 'modern-path2d';
4
5
  import { CoreObject } from '../../../core';
@@ -17,6 +18,14 @@ export declare class Element2DShape extends CoreObject implements NormalizedShap
17
18
  * the normalize→size scaling would distort the stroke width non-uniformly.
18
19
  */
19
20
  protected _localPath?: Path2D;
21
+ /**
22
+ * Pixel-space copy of `_path2DSet` (scaled to the element size), used for hit
23
+ * testing so fill/stroke slack stay in pixel units. Rebuilt when the size
24
+ * changes; cleared by `_updatePath2DSet` when the paths themselves change.
25
+ */
26
+ protected _hitPath2DSet?: Path2DSet;
27
+ protected _hitWidth: number;
28
+ protected _hitHeight: number;
20
29
  constructor(_parent: Element2D);
21
30
  /** Set/clear the local-space derived path (e.g. a connection route). */
22
31
  setLocalPath(path: Path2D | undefined): void;
@@ -24,6 +33,27 @@ export declare class Element2DShape extends CoreObject implements NormalizedShap
24
33
  setProperties(properties?: Record<string, any>): this;
25
34
  protected _updateProperty(key: string, value: any, oldValue: any): void;
26
35
  isValid(): boolean;
36
+ /**
37
+ * Hit-test a point given in the element's local pixel space against the real
38
+ * geometry, mirroring {@link draw}'s path selection:
39
+ *
40
+ * - a connection route (`_localPath`, already in pixel space) → stroke hit
41
+ * - a normalized shape (`_path2DSet`) → fill hit, falling back to stroke for
42
+ * `fill: none` outlines (handled by {@link Path2DSet.hitTest})
43
+ *
44
+ * `strokeWidth` should be the element's outline width (pixels) so line/stroke
45
+ * hits line up with what's drawn. Returns `false` when there's no valid geometry
46
+ * — callers then fall back to the element's rectangle.
47
+ */
48
+ isPointInside(localPos: Vector2Like, options?: {
49
+ strokeWidth?: number;
50
+ tolerance?: number;
51
+ }): boolean;
52
+ /**
53
+ * Lazily build the pixel-space path set. `_path2DSet` is normalized to the unit
54
+ * box, so it's scaled to the element size here. Rebuilt only on size change.
55
+ */
56
+ protected _getHitPath2DSet(): Path2DSet | undefined;
27
57
  protected _updatePath2DSet(): void;
28
58
  draw(rect?: boolean): void;
29
59
  protected _drawRect(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.18.3",
4
+ "version": "0.19.0",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",
@@ -62,10 +62,10 @@
62
62
  "dependencies": {
63
63
  "colord": "^2.9.3",
64
64
  "earcut": "^3.0.2",
65
- "modern-font": "^0.5.0",
65
+ "modern-font": "^0.6.0",
66
66
  "modern-idoc": "^0.11.5",
67
- "modern-path2d": "^1.6.0",
68
- "modern-text": "^1.12.0"
67
+ "modern-path2d": "^1.7.0",
68
+ "modern-text": "^2.0.2"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "lottie-web": "^5",
@@ -94,7 +94,7 @@
94
94
  "modern-gif": "^2.1.0",
95
95
  "typescript": "^6.0.3",
96
96
  "unbuild": "^3.6.1",
97
- "vite": "^8.0.13",
97
+ "vite": "^8.0.14",
98
98
  "vitest": "^4.1.7",
99
99
  "yoga-layout": "^3.2.1"
100
100
  }