kritzel-stencil 0.0.159 → 0.0.160

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.
Files changed (29) hide show
  1. package/dist/cjs/{default-text-tool.config-BySzvIox.js → default-text-tool.config-D10FksvZ.js} +139 -50
  2. package/dist/cjs/default-text-tool.config-D10FksvZ.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/kritzel-color_22.cjs.entry.js +1 -1
  5. package/dist/collection/classes/handlers/resize.handler.js +46 -32
  6. package/dist/collection/classes/handlers/resize.handler.js.map +1 -1
  7. package/dist/collection/classes/objects/selection-group.class.js +91 -16
  8. package/dist/collection/classes/objects/selection-group.class.js.map +1 -1
  9. package/dist/components/index.js +2 -2
  10. package/dist/components/kritzel-editor.js +1 -1
  11. package/dist/components/kritzel-engine.js +1 -1
  12. package/dist/components/{p-BAplhrRJ.js → p-DTHqEUDc.js} +139 -50
  13. package/dist/components/p-DTHqEUDc.js.map +1 -0
  14. package/dist/esm/{default-text-tool.config-2YFQA3SF.js → default-text-tool.config-DzqpOikl.js} +139 -50
  15. package/dist/esm/default-text-tool.config-DzqpOikl.js.map +1 -0
  16. package/dist/esm/index.js +2 -2
  17. package/dist/esm/kritzel-color_22.entry.js +1 -1
  18. package/dist/stencil/index.esm.js +1 -1
  19. package/dist/stencil/{p-2e85a4af.entry.js → p-5475442e.entry.js} +3 -3
  20. package/dist/stencil/{p-2YFQA3SF.js → p-DzqpOikl.js} +2 -2
  21. package/dist/stencil/p-DzqpOikl.js.map +1 -0
  22. package/dist/stencil/stencil.esm.js +1 -1
  23. package/dist/types/classes/objects/selection-group.class.d.ts +1 -0
  24. package/package.json +1 -1
  25. package/dist/cjs/default-text-tool.config-BySzvIox.js.map +0 -1
  26. package/dist/components/p-BAplhrRJ.js.map +0 -1
  27. package/dist/esm/default-text-tool.config-2YFQA3SF.js.map +0 -1
  28. package/dist/stencil/p-2YFQA3SF.js.map +0 -1
  29. /package/dist/stencil/{p-2e85a4af.entry.js.map → p-5475442e.entry.js.map} +0 -0
@@ -15186,32 +15186,42 @@ class KritzelResizeHandler extends KritzelBaseHandler {
15186
15186
  if (!this.hasResized) {
15187
15187
  return;
15188
15188
  }
15189
+ const rotation = selectionGroup.rotation;
15190
+ const sin = Math.sin(rotation);
15191
+ const cos = Math.cos(rotation);
15192
+ const activeScale = selectionGroup.scale || this._core.store.state.scale;
15193
+ // Calculate delta in local unrotated space
15194
+ // We rotate the screen delta by -rotation to align with the object's axes
15195
+ const localDx = dx * cos + dy * sin;
15196
+ const localDy = -dx * sin + dy * cos;
15197
+ // Calculate the center of the selection group before resize
15198
+ const initialCenterX = this.initialSize.x + this.initialSize.width / activeScale / 2;
15199
+ const initialCenterY = this.initialSize.y + this.initialSize.height / activeScale / 2;
15200
+ // The center moves by half of the screen delta (scaled)
15201
+ // This is true regardless of rotation because the resize happens symmetrically around the center
15202
+ // relative to the fixed point logic
15203
+ const newCenterX = initialCenterX + dx / activeScale / 2;
15204
+ const newCenterY = initialCenterY + dy / activeScale / 2;
15189
15205
  switch (this._core.store.state.resizeHandleType) {
15190
15206
  case KritzelHandleType.TopLeft:
15191
- this.newSize.width = this.initialSize.width - dx;
15192
- this.newSize.height = this.initialSize.height - dy;
15193
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
15194
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
15207
+ this.newSize.width = this.initialSize.width - localDx;
15208
+ this.newSize.height = this.initialSize.height - localDy;
15195
15209
  break;
15196
15210
  case KritzelHandleType.TopRight:
15197
- this.newSize.width = this.initialSize.width + dx;
15198
- this.newSize.height = this.initialSize.height - dy;
15199
- this.newSize.x = this.initialSize.x;
15200
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
15211
+ this.newSize.width = this.initialSize.width + localDx;
15212
+ this.newSize.height = this.initialSize.height - localDy;
15201
15213
  break;
15202
15214
  case KritzelHandleType.BottomLeft:
15203
- this.newSize.width = this.initialSize.width - dx;
15204
- this.newSize.height = this.initialSize.height + dy;
15205
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
15206
- this.newSize.y = this.initialSize.y;
15215
+ this.newSize.width = this.initialSize.width - localDx;
15216
+ this.newSize.height = this.initialSize.height + localDy;
15207
15217
  break;
15208
15218
  case KritzelHandleType.BottomRight:
15209
- this.newSize.width = this.initialSize.width + dx;
15210
- this.newSize.height = this.initialSize.height + dy;
15211
- this.newSize.x = this.initialSize.x;
15212
- this.newSize.y = this.initialSize.y;
15219
+ this.newSize.width = this.initialSize.width + localDx;
15220
+ this.newSize.height = this.initialSize.height + localDy;
15213
15221
  break;
15214
15222
  }
15223
+ this.newSize.x = newCenterX - this.newSize.width / activeScale / 2;
15224
+ this.newSize.y = newCenterY - this.newSize.height / activeScale / 2;
15215
15225
  selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
15216
15226
  }
15217
15227
  }
@@ -15237,32 +15247,36 @@ class KritzelResizeHandler extends KritzelBaseHandler {
15237
15247
  if (!this.hasResized) {
15238
15248
  return;
15239
15249
  }
15250
+ const rotation = selectionGroup.rotation;
15251
+ const sin = Math.sin(rotation);
15252
+ const cos = Math.cos(rotation);
15253
+ const activeScale = selectionGroup.scale || this._core.store.state.scale;
15254
+ const localDx = dx * cos + dy * sin;
15255
+ const localDy = -dx * sin + dy * cos;
15256
+ const initialCenterX = this.initialSize.x + this.initialSize.width / activeScale / 2;
15257
+ const initialCenterY = this.initialSize.y + this.initialSize.height / activeScale / 2;
15258
+ const newCenterX = initialCenterX + dx / activeScale / 2;
15259
+ const newCenterY = initialCenterY + dy / activeScale / 2;
15240
15260
  switch (this._core.store.state.resizeHandleType) {
15241
15261
  case KritzelHandleType.TopLeft:
15242
- this.newSize.width = this.initialSize.width - dx;
15243
- this.newSize.height = this.initialSize.height - dy;
15244
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
15245
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
15262
+ this.newSize.width = this.initialSize.width - localDx;
15263
+ this.newSize.height = this.initialSize.height - localDy;
15246
15264
  break;
15247
15265
  case KritzelHandleType.TopRight:
15248
- this.newSize.width = this.initialSize.width + dx;
15249
- this.newSize.height = this.initialSize.height - dy;
15250
- this.newSize.x = this.initialSize.x;
15251
- this.newSize.y = dy / this._core.store.state.scale + this.initialSize.y;
15266
+ this.newSize.width = this.initialSize.width + localDx;
15267
+ this.newSize.height = this.initialSize.height - localDy;
15252
15268
  break;
15253
15269
  case KritzelHandleType.BottomLeft:
15254
- this.newSize.width = this.initialSize.width - dx;
15255
- this.newSize.height = this.initialSize.height + dy;
15256
- this.newSize.x = dx / this._core.store.state.scale + this.initialSize.x;
15257
- this.newSize.y = this.initialSize.y;
15270
+ this.newSize.width = this.initialSize.width - localDx;
15271
+ this.newSize.height = this.initialSize.height + localDy;
15258
15272
  break;
15259
15273
  case KritzelHandleType.BottomRight:
15260
- this.newSize.width = this.initialSize.width + dx;
15261
- this.newSize.height = this.initialSize.height + dy;
15262
- this.newSize.x = this.initialSize.x;
15263
- this.newSize.y = this.initialSize.y;
15274
+ this.newSize.width = this.initialSize.width + localDx;
15275
+ this.newSize.height = this.initialSize.height + localDy;
15264
15276
  break;
15265
15277
  }
15278
+ this.newSize.x = newCenterX - this.newSize.width / activeScale / 2;
15279
+ this.newSize.y = newCenterY - this.newSize.height / activeScale / 2;
15266
15280
  selectionGroup.resize(this.newSize.x, this.newSize.y, this.newSize.width, this.newSize.height);
15267
15281
  }
15268
15282
  }
@@ -15432,6 +15446,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
15432
15446
  objectIds = [];
15433
15447
  // Store snapshots of object state for transformations (rotation, resize)
15434
15448
  unchangedObjectSnapshots = new Map();
15449
+ snapshotRotation = 0;
15435
15450
  minX;
15436
15451
  maxX;
15437
15452
  minY;
@@ -15502,6 +15517,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
15502
15517
  */
15503
15518
  captureUnchangedSnapshots() {
15504
15519
  this.unchangedObjectSnapshots.clear();
15520
+ this.snapshotRotation = this.rotation;
15505
15521
  this.objects.forEach(obj => {
15506
15522
  this.unchangedObjectSnapshots.set(obj.id, {
15507
15523
  id: obj.id,
@@ -15561,14 +15577,56 @@ class KritzelSelectionGroup extends KritzelBaseObject {
15561
15577
  resize(x, y, width, height) {
15562
15578
  const widthScaleFactor = width / this.width;
15563
15579
  const heightScaleFactor = height / this.height;
15564
- const deltaX = x - this.translateX;
15565
- const deltaY = y - this.translateY;
15580
+ // Calculate old center
15581
+ const oldCenterX = this.translateX + this.totalWidth / 2 / this.scale;
15582
+ const oldCenterY = this.translateY + this.totalHeight / 2 / this.scale;
15583
+ // Calculate new center
15584
+ const newTotalWidth = width + this.padding * 2;
15585
+ const newTotalHeight = height + this.padding * 2;
15586
+ const newCenterX = x + newTotalWidth / 2 / this.scale;
15587
+ const newCenterY = y + newTotalHeight / 2 / this.scale;
15588
+ const rotation = this.rotation;
15589
+ const cos = Math.cos(-rotation);
15590
+ const sin = Math.sin(-rotation);
15591
+ const cosR = Math.cos(rotation);
15592
+ const sinR = Math.sin(rotation);
15566
15593
  this._core.store.state.objects.transaction(() => {
15567
15594
  this.objects.forEach(child => {
15568
- const updatedWidth = child.width * widthScaleFactor;
15569
- const updatedHeight = child.height * heightScaleFactor;
15570
- const updatedX = child.translateX + deltaX + (child.translateX - this.translateX) * (widthScaleFactor - 1);
15571
- const updatedY = child.translateY + deltaY + (child.translateY - this.translateY) * (heightScaleFactor - 1);
15595
+ // Calculate child center
15596
+ const childCenterX = child.translateX + child.totalWidth / 2 / child.scale;
15597
+ const childCenterY = child.translateY + child.totalHeight / 2 / child.scale;
15598
+ // Vector from old group center to child center
15599
+ const dx = childCenterX - oldCenterX;
15600
+ const dy = childCenterY - oldCenterY;
15601
+ // Rotate to local space (align with group axes)
15602
+ const localX = dx * cos - dy * sin;
15603
+ const localY = dx * sin + dy * cos;
15604
+ // Scale in local space
15605
+ const scaledLocalX = localX * widthScaleFactor;
15606
+ const scaledLocalY = localY * heightScaleFactor;
15607
+ // Rotate back to world space
15608
+ const rotatedX = scaledLocalX * cosR - scaledLocalY * sinR;
15609
+ const rotatedY = scaledLocalX * sinR + scaledLocalY * cosR;
15610
+ // New child center
15611
+ const newChildCenterX = newCenterX + rotatedX;
15612
+ const newChildCenterY = newCenterY + rotatedY;
15613
+ // New child top-left
15614
+ // Calculate relative rotation
15615
+ const relativeRotation = child.rotation - rotation;
15616
+ const cosRel = Math.cos(relativeRotation);
15617
+ const sinRel = Math.sin(relativeRotation);
15618
+ // Project the group's scale factors onto the child's local axes
15619
+ // We use absolute values because scaling is magnitude-based
15620
+ // If the child is aligned (0 deg), cos=1, sin=0 -> scales match
15621
+ // If the child is 90 deg, cos=0, sin=1 -> scales swap
15622
+ const newChildWidthScale = Math.sqrt(Math.pow(widthScaleFactor * cosRel, 2) + Math.pow(heightScaleFactor * sinRel, 2));
15623
+ const newChildHeightScale = Math.sqrt(Math.pow(widthScaleFactor * sinRel, 2) + Math.pow(heightScaleFactor * cosRel, 2));
15624
+ const updatedWidth = child.width * newChildWidthScale;
15625
+ const updatedHeight = child.height * newChildHeightScale;
15626
+ const updatedTotalWidth = updatedWidth + child.padding * 2;
15627
+ const updatedTotalHeight = updatedHeight + child.padding * 2;
15628
+ const updatedX = newChildCenterX - updatedTotalWidth / 2 / child.scale;
15629
+ const updatedY = newChildCenterY - updatedTotalHeight / 2 / child.scale;
15572
15630
  child.resize(updatedX, updatedY, updatedWidth, updatedHeight);
15573
15631
  });
15574
15632
  // Refresh dimensions and update the SelectionGroup to propagate changes to other tabs
@@ -15581,7 +15639,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
15581
15639
  this.rotation = value;
15582
15640
  const centerX = this.translateX + this.totalWidth / 2 / this.scale;
15583
15641
  const centerY = this.translateY + this.totalHeight / 2 / this.scale;
15584
- const angle = value;
15642
+ const angle = value - this.snapshotRotation;
15585
15643
  const cos = Math.cos(angle);
15586
15644
  const sin = Math.sin(angle);
15587
15645
  this._core.store.state.objects.transaction(() => {
@@ -15597,7 +15655,7 @@ class KritzelSelectionGroup extends KritzelBaseObject {
15597
15655
  const rotatedY = sin * offsetX + cos * offsetY;
15598
15656
  child.translateX = centerX + rotatedX - child.totalWidth / 2 / child.scale;
15599
15657
  child.translateY = centerY + rotatedY - child.totalHeight / 2 / child.scale;
15600
- child.rotate(this.objects.length === 1 ? value : value + unchangedSnapshot.rotation);
15658
+ child.rotate(this.objects.length === 1 ? value : unchangedSnapshot.rotation + angle);
15601
15659
  });
15602
15660
  });
15603
15661
  }
@@ -15628,14 +15686,45 @@ class KritzelSelectionGroup extends KritzelBaseObject {
15628
15686
  this.height = (this.maxY - this.minY - this.padding) * this.scale;
15629
15687
  }
15630
15688
  else {
15631
- this.minX = Math.min(...this.objects.map(obj => obj.minXRotated));
15632
- this.maxX = Math.max(...this.objects.map(obj => obj.maxXRotated));
15633
- this.minY = Math.min(...this.objects.map(obj => obj.minYRotated));
15634
- this.maxY = Math.max(...this.objects.map(obj => obj.maxYRotated));
15635
- this.translateX = this.minX - this.padding;
15636
- this.translateY = this.minY - this.padding;
15637
- this.width = (this.maxX - this.minX - this.padding) * this.scale;
15638
- this.height = (this.maxY - this.minY - this.padding) * this.scale;
15689
+ const rotation = this.rotation;
15690
+ const cos = Math.cos(-rotation);
15691
+ const sin = Math.sin(-rotation);
15692
+ let minX = Infinity;
15693
+ let maxX = -Infinity;
15694
+ let minY = Infinity;
15695
+ let maxY = -Infinity;
15696
+ this.objects.forEach(obj => {
15697
+ const polygon = obj.rotatedPolygon;
15698
+ const corners = [polygon.topLeft, polygon.topRight, polygon.bottomRight, polygon.bottomLeft];
15699
+ corners.forEach(corner => {
15700
+ // Rotate corner into local space (aligned with group rotation)
15701
+ const rx = corner.x * cos - corner.y * sin;
15702
+ const ry = corner.x * sin + corner.y * cos;
15703
+ if (rx < minX)
15704
+ minX = rx;
15705
+ if (rx > maxX)
15706
+ maxX = rx;
15707
+ if (ry < minY)
15708
+ minY = ry;
15709
+ if (ry > maxY)
15710
+ maxY = ry;
15711
+ });
15712
+ });
15713
+ // Dimensions in world units (unrotated)
15714
+ const worldWidth = maxX - minX;
15715
+ const worldHeight = maxY - minY;
15716
+ this.width = (worldWidth - this.padding) * this.scale;
15717
+ this.height = (worldHeight - this.padding) * this.scale;
15718
+ // Center of the box in rotated space
15719
+ const cRx = (minX + maxX) / 2;
15720
+ const cRy = (minY + maxY) / 2;
15721
+ // Rotate center back to world space
15722
+ const cosR = Math.cos(rotation);
15723
+ const sinR = Math.sin(rotation);
15724
+ const cx = cRx * cosR - cRy * sinR;
15725
+ const cy = cRx * sinR + cRy * cosR;
15726
+ this.translateX = cx - (this.width / this.scale + 2 * this.padding) / 2;
15727
+ this.translateY = cy - (this.height / this.scale + 2 * this.padding) / 2;
15639
15728
  }
15640
15729
  this._core.store.state.objects.update(this);
15641
15730
  }
@@ -31203,6 +31292,6 @@ const DEFAULT_TEXT_CONFIG = {
31203
31292
  };
31204
31293
 
31205
31294
  export { Doc as $, isNode as A, min$2 as B, pow as C, HocuspocusProviderWebsocket as D, KritzelPath as E, KritzelImage as F, KritzelBrushTool as G, HocuspocusProvider as H, KritzelEraserTool as I, KritzelImageTool as J, KritzelText as K, KritzelTextTool as L, KritzelSelectionTool as M, IndexedDBSyncProvider as N, Observable$1 as O, KritzelAppStateMap as P, KritzelWorkspace as Q, DEFAULT_BRUSH_CONFIG as R, DEFAULT_TEXT_CONFIG as S, KritzelDevicesHelper as T, KritzelMouseButton as U, KritzelKeyboardHelper as V, KritzelBaseHandler as W, KritzelToolRegistry as X, KritzelSelectionBox as Y, KritzelSelectionGroup as Z, KritzelBaseObject as _, writeVarUint8Array$2 as a, DEFAULT_SYNC_CONFIG as a0, UndoManager as a1, ObjectHelper as a2, KritzelEventHelper as a3, KritzelBaseTool as a4, readVarUint8Array$2 as b, applyUpdate as c, encodeStateVector as d, encodeStateAsUpdate as e, createEncoder$1 as f, createDecoder$1 as g, create$8 as h, fromBase64 as i, toBase64 as j, createUint8ArrayFromArrayBuffer as k, offChange as l, readVarString$2 as m, floor$2 as n, onChange as o, getUnixTime$1 as p, equalityDeep$1 as q, readVarUint$2 as r, setIfUndefined$1 as s, toUint8Array$1 as t, writeVarString$2 as u, varStorage as v, writeVarUint$2 as w, map as x, ObservableV2 as y, length$3 as z };
31206
- //# sourceMappingURL=default-text-tool.config-2YFQA3SF.js.map
31295
+ //# sourceMappingURL=default-text-tool.config-DzqpOikl.js.map
31207
31296
 
31208
- //# sourceMappingURL=default-text-tool.config-2YFQA3SF.js.map
31297
+ //# sourceMappingURL=default-text-tool.config-DzqpOikl.js.map