@edv4h/usketch-shape-utils 1.0.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/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/bounds.d.ts +3 -0
- package/dist/bounds.d.ts.map +1 -0
- package/dist/bounds.js +4 -0
- package/dist/bounds.js.map +1 -0
- package/dist/gpu.d.ts +6 -0
- package/dist/gpu.d.ts.map +1 -0
- package/dist/gpu.js +50 -0
- package/dist/gpu.js.map +1 -0
- package/dist/hit-test.d.ts +6 -0
- package/dist/hit-test.d.ts.map +1 -0
- package/dist/hit-test.js +50 -0
- package/dist/hit-test.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/resize.d.ts +3 -0
- package/dist/resize.d.ts.map +1 -0
- package/dist/resize.js +49 -0
- package/dist/resize.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 EdV4H
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @edv4h/usketch-shape-utils
|
|
2
|
+
|
|
3
|
+
uSketch v2 の shape プラグインを書くときに使う共通ユーティリティ集。
|
|
4
|
+
サードパーティが `@acme/usketch-plugin-shape-foo` のような独自 shape プラグインを実装する際、bounds 計算・ヒットテスト・リサイズ・GPU primitive の差し込みをここから取ってくる想定。
|
|
5
|
+
|
|
6
|
+
React に依存しない純粋な関数群なので、サーバサイドでの shape データ処理にも使える。
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @edv4h/usketch-shape-utils @edv4h/usketch-shared
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 公開 API
|
|
15
|
+
|
|
16
|
+
### `getBounds(data: ShapeData): BoundingBox`
|
|
17
|
+
|
|
18
|
+
shape の AABB を返す。ほとんどの shape はこれをそのまま `ShapeDefinition.getBounds` に指定すれば OK。
|
|
19
|
+
|
|
20
|
+
### Hit test
|
|
21
|
+
|
|
22
|
+
| 関数 | 用途 |
|
|
23
|
+
|------|------|
|
|
24
|
+
| `aabbHitTest(data, point)` | 矩形 AABB との当たり判定 |
|
|
25
|
+
| `ellipseHitTest(data, point)` | 楕円との当たり判定 |
|
|
26
|
+
| `lineHitTest(data, point, tolerance?)` | 線分との距離判定(デフォルト tolerance: 4px) |
|
|
27
|
+
| `pointInPolygon(point, polygon)` | 任意多角形との当たり判定(三角形・六角形・星形など) |
|
|
28
|
+
|
|
29
|
+
回転に対応したい場合は、`@edv4h/usketch-shared` の `withRotation(hitTest)` でラップする。
|
|
30
|
+
|
|
31
|
+
### `createResize(minW, minH): ResizeFn`
|
|
32
|
+
|
|
33
|
+
8 方向(`se` / `nw` / `ne` / `sw` / `e` / `w` / `n` / `s`)のリサイズハンドルに対応した resize 関数を生成する。最小幅・最小高を渡す。
|
|
34
|
+
|
|
35
|
+
### GPU primitive
|
|
36
|
+
|
|
37
|
+
WebGPU レンダラが有効な場合に使われる低レベル primitive を返すヘルパ。
|
|
38
|
+
|
|
39
|
+
| 関数 | 返す kind |
|
|
40
|
+
|------|----------|
|
|
41
|
+
| `rectGpuPrimitive(data)` | `rect` |
|
|
42
|
+
| `roundedRectGpuPrimitive(data)` | `rect`(cornerRadius 自動計算) |
|
|
43
|
+
| `ellipseGpuPrimitive(data)` | `ellipse` |
|
|
44
|
+
| `lineGpuPrimitive(data)` | `polyline` |
|
|
45
|
+
|
|
46
|
+
## 使用例
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { DEFAULT_STYLE, type ShapeData, withRotation } from "@edv4h/usketch-shared";
|
|
50
|
+
import { createResize, getBounds, pointInPolygon } from "@edv4h/usketch-shape-utils";
|
|
51
|
+
|
|
52
|
+
function getHexagonPoints(data: ShapeData) {
|
|
53
|
+
const cx = data.x + data.width / 2;
|
|
54
|
+
const cy = data.y + data.height / 2;
|
|
55
|
+
return Array.from({ length: 6 }, (_, i) => {
|
|
56
|
+
const angle = (Math.PI / 3) * i - Math.PI / 2;
|
|
57
|
+
return {
|
|
58
|
+
x: cx + (data.width / 2) * Math.cos(angle),
|
|
59
|
+
y: cy + (data.height / 2) * Math.sin(angle),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const hexagonDefinition = {
|
|
65
|
+
render: (data: ShapeData) => (
|
|
66
|
+
<polygon
|
|
67
|
+
points={getHexagonPoints(data).map((p) => `${p.x},${p.y}`).join(" ")}
|
|
68
|
+
fill={data.style.fill}
|
|
69
|
+
/>
|
|
70
|
+
),
|
|
71
|
+
getBounds,
|
|
72
|
+
hitTest: withRotation((data, point) => pointInPolygon(point, getHexagonPoints(data))),
|
|
73
|
+
resize: createResize(10, 10),
|
|
74
|
+
createDefault: ({ id, x, y }) => ({
|
|
75
|
+
id,
|
|
76
|
+
type: "hexagon",
|
|
77
|
+
x,
|
|
78
|
+
y,
|
|
79
|
+
width: 120,
|
|
80
|
+
height: 104,
|
|
81
|
+
style: { ...DEFAULT_STYLE },
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
プラグインとしての組み込み方は [`apps/docs` の Plugin authoring ガイド](https://github.com/EdV4H/usketch/blob/main/apps/docs/src/content/docs/plugins/authoring.md) を参照。
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT
|
package/dist/bounds.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../src/bounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEpE,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,WAAW,CAEtD"}
|
package/dist/bounds.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bounds.js","sourceRoot":"","sources":["../src/bounds.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS,CAAC,IAAe;IACxC,OAAO,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AACzE,CAAC"}
|
package/dist/gpu.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type GpuPrimitive, type ShapeData } from "@edv4h/usketch-shared";
|
|
2
|
+
export declare function rectGpuPrimitive(data: ShapeData): GpuPrimitive;
|
|
3
|
+
export declare function roundedRectGpuPrimitive(data: ShapeData): GpuPrimitive;
|
|
4
|
+
export declare function ellipseGpuPrimitive(data: ShapeData): GpuPrimitive;
|
|
5
|
+
export declare function lineGpuPrimitive(data: ShapeData): GpuPrimitive;
|
|
6
|
+
//# sourceMappingURL=gpu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu.d.ts","sourceRoot":"","sources":["../src/gpu.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEnG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAW9D;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAYrE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAUjE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAW9D"}
|
package/dist/gpu.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { cssColorToRgbaOrDefault } from "@edv4h/usketch-shared";
|
|
2
|
+
export function rectGpuPrimitive(data) {
|
|
3
|
+
return {
|
|
4
|
+
kind: "rect",
|
|
5
|
+
bounds: { x: data.x, y: data.y, width: data.width, height: data.height },
|
|
6
|
+
cornerRadius: data.cornerRadius ?? 0,
|
|
7
|
+
fill: cssColorToRgbaOrDefault(data.style.fill),
|
|
8
|
+
stroke: cssColorToRgbaOrDefault(data.style.stroke),
|
|
9
|
+
strokeWidth: data.style.strokeWidth,
|
|
10
|
+
opacity: data.style.opacity,
|
|
11
|
+
rotation: data.rotation,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function roundedRectGpuPrimitive(data) {
|
|
15
|
+
const cornerRadius = Math.min(data.width, data.height) / 4;
|
|
16
|
+
return {
|
|
17
|
+
kind: "rect",
|
|
18
|
+
bounds: { x: data.x, y: data.y, width: data.width, height: data.height },
|
|
19
|
+
cornerRadius,
|
|
20
|
+
fill: cssColorToRgbaOrDefault(data.style.fill),
|
|
21
|
+
stroke: cssColorToRgbaOrDefault(data.style.stroke),
|
|
22
|
+
strokeWidth: data.style.strokeWidth,
|
|
23
|
+
opacity: data.style.opacity,
|
|
24
|
+
rotation: data.rotation,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function ellipseGpuPrimitive(data) {
|
|
28
|
+
return {
|
|
29
|
+
kind: "ellipse",
|
|
30
|
+
bounds: { x: data.x, y: data.y, width: data.width, height: data.height },
|
|
31
|
+
fill: cssColorToRgbaOrDefault(data.style.fill),
|
|
32
|
+
stroke: cssColorToRgbaOrDefault(data.style.stroke),
|
|
33
|
+
strokeWidth: data.style.strokeWidth,
|
|
34
|
+
opacity: data.style.opacity,
|
|
35
|
+
rotation: data.rotation,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export function lineGpuPrimitive(data) {
|
|
39
|
+
const vertices = new Float32Array([data.x, data.y, data.x + data.width, data.y + data.height]);
|
|
40
|
+
return {
|
|
41
|
+
kind: "polyline",
|
|
42
|
+
bounds: { x: data.x, y: data.y, width: data.width, height: data.height },
|
|
43
|
+
vertices,
|
|
44
|
+
fill: [0, 0, 0, 0],
|
|
45
|
+
stroke: cssColorToRgbaOrDefault(data.style.stroke),
|
|
46
|
+
strokeWidth: data.style.strokeWidth,
|
|
47
|
+
opacity: data.style.opacity,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=gpu.js.map
|
package/dist/gpu.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu.js","sourceRoot":"","sources":["../src/gpu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAqC,MAAM,uB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O,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;KAC3B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Point, ShapeData } from "@edv4h/usketch-shared";
|
|
2
|
+
export declare function aabbHitTest(data: ShapeData, point: Point): boolean;
|
|
3
|
+
export declare function ellipseHitTest(data: ShapeData, point: Point): boolean;
|
|
4
|
+
export declare function pointInPolygon(point: Point, polygon: Point[]): boolean;
|
|
5
|
+
export declare function lineHitTest(data: ShapeData, point: Point, tolerance?: number): boolean;
|
|
6
|
+
//# sourceMappingURL=hit-test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit-test.d.ts","sourceRoot":"","sources":["../src/hit-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE9D,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAOlE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CASrE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAYtE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,SAAI,GAAG,OAAO,CAsBjF"}
|
package/dist/hit-test.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function aabbHitTest(data, point) {
|
|
2
|
+
return (point.x >= data.x &&
|
|
3
|
+
point.x <= data.x + data.width &&
|
|
4
|
+
point.y >= data.y &&
|
|
5
|
+
point.y <= data.y + data.height);
|
|
6
|
+
}
|
|
7
|
+
export function ellipseHitTest(data, point) {
|
|
8
|
+
const rx = data.width / 2;
|
|
9
|
+
const ry = data.height / 2;
|
|
10
|
+
if (rx === 0 || ry === 0)
|
|
11
|
+
return false;
|
|
12
|
+
const cx = data.x + rx;
|
|
13
|
+
const cy = data.y + ry;
|
|
14
|
+
const dx = (point.x - cx) / rx;
|
|
15
|
+
const dy = (point.y - cy) / ry;
|
|
16
|
+
return dx * dx + dy * dy <= 1;
|
|
17
|
+
}
|
|
18
|
+
export function pointInPolygon(point, polygon) {
|
|
19
|
+
let inside = false;
|
|
20
|
+
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
21
|
+
const xi = polygon[i].x;
|
|
22
|
+
const yi = polygon[i].y;
|
|
23
|
+
const xj = polygon[j].x;
|
|
24
|
+
const yj = polygon[j].y;
|
|
25
|
+
const intersect = yi > point.y !== yj > point.y && point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi;
|
|
26
|
+
if (intersect)
|
|
27
|
+
inside = !inside;
|
|
28
|
+
}
|
|
29
|
+
return inside;
|
|
30
|
+
}
|
|
31
|
+
export function lineHitTest(data, point, tolerance = 4) {
|
|
32
|
+
const x1 = data.x;
|
|
33
|
+
const y1 = data.y;
|
|
34
|
+
const x2 = data.x + data.width;
|
|
35
|
+
const y2 = data.y + data.height;
|
|
36
|
+
const dx = x2 - x1;
|
|
37
|
+
const dy = y2 - y1;
|
|
38
|
+
const lengthSq = dx * dx + dy * dy;
|
|
39
|
+
if (lengthSq === 0) {
|
|
40
|
+
const d = Math.hypot(point.x - x1, point.y - y1);
|
|
41
|
+
return d <= tolerance;
|
|
42
|
+
}
|
|
43
|
+
let t = ((point.x - x1) * dx + (point.y - y1) * dy) / lengthSq;
|
|
44
|
+
t = Math.max(0, Math.min(1, t));
|
|
45
|
+
const nearestX = x1 + t * dx;
|
|
46
|
+
const nearestY = y1 + t * dy;
|
|
47
|
+
const dist = Math.hypot(point.x - nearestX, point.y - nearestY);
|
|
48
|
+
return dist <= tolerance;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=hit-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|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KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACjD,OAAO,CAAC,IAAI,SAAS,CAAC;IACvB,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC;IAC/D,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEhC,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC;IAChE,OAAO,IAAI,IAAI,SAAS,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getBounds } from "./bounds.js";
|
|
2
|
+
export { ellipseGpuPrimitive, lineGpuPrimitive, rectGpuPrimitive, roundedRectGpuPrimitive, } from "./gpu.js";
|
|
3
|
+
export { aabbHitTest, ellipseHitTest, lineHitTest, pointInPolygon } from "./hit-test.js";
|
|
4
|
+
export { createResize } from "./resize.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getBounds } from "./bounds.js";
|
|
2
|
+
export { ellipseGpuPrimitive, lineGpuPrimitive, rectGpuPrimitive, roundedRectGpuPrimitive, } from "./gpu.js";
|
|
3
|
+
export { aabbHitTest, ellipseHitTest, lineHitTest, pointInPolygon } from "./hit-test.js";
|
|
4
|
+
export { createResize } from "./resize.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/resize.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.d.ts","sourceRoot":"","sources":["../src/resize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAE5E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAC9C,MAAM,SAAS,EAAE,QAAQ,YAAY,EAAE,OAAO,KAAK,KAAG,SAAS,CA8CvE"}
|
package/dist/resize.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function createResize(minW, minH) {
|
|
2
|
+
return (data, handle, delta) => {
|
|
3
|
+
let { x, y, width, height } = data;
|
|
4
|
+
switch (handle) {
|
|
5
|
+
case "se":
|
|
6
|
+
width += delta.x;
|
|
7
|
+
height += delta.y;
|
|
8
|
+
break;
|
|
9
|
+
case "nw":
|
|
10
|
+
x += delta.x;
|
|
11
|
+
y += delta.y;
|
|
12
|
+
width -= delta.x;
|
|
13
|
+
height -= delta.y;
|
|
14
|
+
break;
|
|
15
|
+
case "ne":
|
|
16
|
+
y += delta.y;
|
|
17
|
+
width += delta.x;
|
|
18
|
+
height -= delta.y;
|
|
19
|
+
break;
|
|
20
|
+
case "sw":
|
|
21
|
+
x += delta.x;
|
|
22
|
+
width -= delta.x;
|
|
23
|
+
height += delta.y;
|
|
24
|
+
break;
|
|
25
|
+
case "e":
|
|
26
|
+
width += delta.x;
|
|
27
|
+
break;
|
|
28
|
+
case "w":
|
|
29
|
+
x += delta.x;
|
|
30
|
+
width -= delta.x;
|
|
31
|
+
break;
|
|
32
|
+
case "n":
|
|
33
|
+
y += delta.y;
|
|
34
|
+
height -= delta.y;
|
|
35
|
+
break;
|
|
36
|
+
case "s":
|
|
37
|
+
height += delta.y;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
...data,
|
|
42
|
+
x,
|
|
43
|
+
y,
|
|
44
|
+
width: Math.max(minW, width),
|
|
45
|
+
height: Math.max(minH, height),
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.js","sourceRoot":"","sources":["../src/resize.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAY;IACtD,OAAO,CAAC,IAAe,EAAE,MAAoB,EAAE,KAAY,EAAa,EAAE;QACzE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EA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CAAC,IAAI,EAAE,MAAM,CAAC;SAC9B,CAAC;IACH,CAAC,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edv4h/usketch-shape-utils",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@edv4h/usketch-shared": "1.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "5.9.3",
|
|
19
|
+
"vitest": "3.2.4"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/EdV4H/usketch.git",
|
|
32
|
+
"directory": "packages/usketch-shape-utils"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/EdV4H/usketch#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/EdV4H/usketch/issues"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -p tsconfig.json",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run --passWithNoTests",
|
|
42
|
+
"clean": "rm -rf dist"
|
|
43
|
+
}
|
|
44
|
+
}
|