@widgetic/canvas 0.5.31 → 0.5.32
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/canvas/Canvas.svelte +64 -2
- package/package.json +4 -4
|
@@ -1926,6 +1926,10 @@
|
|
|
1926
1926
|
// Option is used for frame children, and a stuck altKey used to explode scales.
|
|
1927
1927
|
canvas.centeredScaling = false;
|
|
1928
1928
|
(canvas as any).centeredKey = null;
|
|
1929
|
+
for (const cornerKey of ['tl', 'tr', 'bl', 'br']) {
|
|
1930
|
+
const cornerControl = FabricObject.prototype.controls?.[cornerKey];
|
|
1931
|
+
if (cornerControl) cornerControl.actionHandler = scaleCornerFromGrab;
|
|
1932
|
+
}
|
|
1929
1933
|
|
|
1930
1934
|
// Set 'move' cursor as default hover cursor on ALL objects.
|
|
1931
1935
|
// Set on both canvas level and prototype level for full coverage.
|
|
@@ -2136,7 +2140,7 @@
|
|
|
2136
2140
|
}
|
|
2137
2141
|
// Alt key is now tracked globally via window keydown/keyup events
|
|
2138
2142
|
|
|
2139
|
-
if ('strokeUniform' in target) {
|
|
2143
|
+
if ('strokeUniform' in target && !target.strokeUniform) {
|
|
2140
2144
|
target.set({ strokeUniform: true });
|
|
2141
2145
|
}
|
|
2142
2146
|
|
|
@@ -6675,6 +6679,53 @@
|
|
|
6675
6679
|
}
|
|
6676
6680
|
}
|
|
6677
6681
|
|
|
6682
|
+
/**
|
|
6683
|
+
* Corner resize follows how far the pointer moved from the grab, not the
|
|
6684
|
+
* handle's offset from the corner. Measuring from the corner made a diagonal
|
|
6685
|
+
* drag jump, while the side handles (already on the edge) stayed smooth.
|
|
6686
|
+
*/
|
|
6687
|
+
const scaleCornerFromGrab = controlsUtils.wrapWithFireEvent(
|
|
6688
|
+
'scale',
|
|
6689
|
+
controlsUtils.wrapWithFixedAnchor((eventData: any, transform: any, x: number, y: number) => {
|
|
6690
|
+
const target = transform?.target;
|
|
6691
|
+
if (!target) return false;
|
|
6692
|
+
const local = controlsUtils.getLocalPoint(transform, transform.originX, transform.originY, x, y);
|
|
6693
|
+
if (!transform._grabScale) {
|
|
6694
|
+
transform._grabScale = {
|
|
6695
|
+
x: local.x || 1,
|
|
6696
|
+
y: local.y || 1,
|
|
6697
|
+
scaleX: target.scaleX || 1,
|
|
6698
|
+
scaleY: target.scaleY || 1
|
|
6699
|
+
};
|
|
6700
|
+
}
|
|
6701
|
+
const grab = transform._grabScale;
|
|
6702
|
+
let ratioX = local.x / grab.x;
|
|
6703
|
+
let ratioY = local.y / grab.y;
|
|
6704
|
+
if (!Number.isFinite(ratioX)) ratioX = 1;
|
|
6705
|
+
if (!Number.isFinite(ratioY)) ratioY = 1;
|
|
6706
|
+
const proportional = !!(
|
|
6707
|
+
eventData?.shiftKey
|
|
6708
|
+
|| target.type === 'textbox'
|
|
6709
|
+
|| target._lockAspectRatio
|
|
6710
|
+
|| target._forceLockAspectRatio
|
|
6711
|
+
);
|
|
6712
|
+
if (proportional) {
|
|
6713
|
+
const ratio = Math.abs(ratioX) >= Math.abs(ratioY) ? ratioX : ratioY;
|
|
6714
|
+
ratioX = ratio;
|
|
6715
|
+
ratioY = ratio;
|
|
6716
|
+
}
|
|
6717
|
+
const minRatio = 0.02;
|
|
6718
|
+
if (ratioX < minRatio) ratioX = minRatio;
|
|
6719
|
+
if (ratioY < minRatio) ratioY = minRatio;
|
|
6720
|
+
const nextX = grab.scaleX * ratioX;
|
|
6721
|
+
const nextY = grab.scaleY * ratioY;
|
|
6722
|
+
const changed = target.scaleX !== nextX || target.scaleY !== nextY;
|
|
6723
|
+
target.scaleX = nextX;
|
|
6724
|
+
target.scaleY = nextY;
|
|
6725
|
+
return changed;
|
|
6726
|
+
})
|
|
6727
|
+
);
|
|
6728
|
+
|
|
6678
6729
|
/**
|
|
6679
6730
|
* Locked top/bottom scale follows the pointer on that axis and keeps the
|
|
6680
6731
|
* other axis in step, so the edge stays under the mouse. Unlocked top/bottom
|
|
@@ -6740,7 +6791,7 @@
|
|
|
6740
6791
|
for (const key of corners) {
|
|
6741
6792
|
const control = tb.controls[key];
|
|
6742
6793
|
if (!control) continue;
|
|
6743
|
-
control.actionHandler =
|
|
6794
|
+
control.actionHandler = scaleCornerFromGrab;
|
|
6744
6795
|
control.render = control._widgeticDefaultRender;
|
|
6745
6796
|
}
|
|
6746
6797
|
tb.setControlsVisibility({
|
|
@@ -7802,6 +7853,17 @@ function checkAndAddNewShapeToFrame(shape: any) {
|
|
|
7802
7853
|
return;
|
|
7803
7854
|
}
|
|
7804
7855
|
|
|
7856
|
+
const isWidgetShape = (object: any): boolean => {
|
|
7857
|
+
if (!object) return false;
|
|
7858
|
+
if (object._isWidgetImage || object.type === 'WidgetShape') return true;
|
|
7859
|
+
const children = object._objects;
|
|
7860
|
+
return Array.isArray(children) && children.some((child: any) => isWidgetShape(child));
|
|
7861
|
+
};
|
|
7862
|
+
if (isWidgetShape(target)) {
|
|
7863
|
+
canvasLog('Erase tool skipped widget shape', { ObjectType: target.type });
|
|
7864
|
+
return;
|
|
7865
|
+
}
|
|
7866
|
+
|
|
7805
7867
|
try {
|
|
7806
7868
|
canvas.remove(target);
|
|
7807
7869
|
canvas.requestRenderAll();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/canvas",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.32",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"svelte": "./dist/index.js",
|
|
@@ -70,6 +70,8 @@
|
|
|
70
70
|
"@sveltejs/package": "^2.5.8",
|
|
71
71
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
72
72
|
"@tailwindcss/postcss": "^4.1.4",
|
|
73
|
+
"@widgetic/design-system": "^0.5.21",
|
|
74
|
+
"@widgetic/dev-tools": "^0.3.0",
|
|
73
75
|
"eslint": "^9.18.0",
|
|
74
76
|
"eslint-config-prettier": "^10.0.1",
|
|
75
77
|
"eslint-plugin-svelte": "^3.0.0",
|
|
@@ -85,9 +87,7 @@
|
|
|
85
87
|
"tailwindcss": "^4.1.4",
|
|
86
88
|
"typescript": "^5.8.3",
|
|
87
89
|
"typescript-eslint": "^8.20.0",
|
|
88
|
-
"vite": "^6.2.6"
|
|
89
|
-
"@widgetic/design-system": "^0.5.12",
|
|
90
|
-
"@widgetic/dev-tools": "^0.3.0"
|
|
90
|
+
"vite": "^6.2.6"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@tailwindcss/typography": "^0.5.19",
|