mce 0.15.28 → 0.15.29

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.css CHANGED
@@ -298,7 +298,7 @@
298
298
  inset: 0;
299
299
  pointer-events: none;
300
300
  }
301
- .mce-overlay > * {
301
+ .mce-overlay-content > * {
302
302
  pointer-events: auto;
303
303
  }.mce-menu {
304
304
  user-select: none;
@@ -1123,10 +1123,10 @@
1123
1123
  .mce-transform-controls--resizing .mce-transform-controls__diagonal {
1124
1124
  visibility: visible;
1125
1125
  }
1126
- .mce-transform-controls--moving .mce-transform-controls__handle {
1127
- visibility: hidden;
1128
- }
1129
- .mce-transform-controls--moving .mce-transform-controls__handle-rect {
1126
+ .mce-transform-controls--moving .mce-transform-controls__handle,
1127
+ .mce-transform-controls--moving .mce-transform-controls__handle-rect,
1128
+ .mce-transform-controls--moving .mce-transform-controls__rotator,
1129
+ .mce-transform-controls--moving .mce-transform-controls__tip {
1130
1130
  visibility: hidden;
1131
1131
  }
1132
1132
  .mce-transform-controls--moving .mce-transform-controls__rect {
@@ -1137,13 +1137,11 @@
1137
1137
  opacity: 0.4;
1138
1138
  stroke-width: 0.5px;
1139
1139
  }
1140
- .mce-transform-controls--hide-ui .mce-transform-controls__handle {
1141
- visibility: hidden;
1142
- }
1143
- .mce-transform-controls--hide-ui .mce-transform-controls__handle-rect {
1144
- visibility: hidden;
1145
- }
1146
- .mce-transform-controls--hide-ui .mce-transform-controls__rect {
1140
+ .mce-transform-controls--hide-ui .mce-transform-controls__handle,
1141
+ .mce-transform-controls--hide-ui .mce-transform-controls__handle-rect,
1142
+ .mce-transform-controls--hide-ui .mce-transform-controls__rect,
1143
+ .mce-transform-controls--hide-ui .mce-transform-controls__rotator,
1144
+ .mce-transform-controls--hide-ui .mce-transform-controls__tip {
1147
1145
  visibility: hidden;
1148
1146
  }.mce-cropper {
1149
1147
  pointer-events: auto;
package/dist/index.js CHANGED
@@ -942,7 +942,7 @@ const _0_context = defineMixin((editor) => {
942
942
  return value.meta.inEditorIs === inEditorIs2;
943
943
  }
944
944
  function isFrame(value) {
945
- return isElement(value) && inEditorIs(value, "Frame");
945
+ return inEditorIs(value, "Frame");
946
946
  }
947
947
  function isTopFrame(value) {
948
948
  return isFrame(value) && Boolean(value.parent?.equal(root.value));
@@ -3449,10 +3449,8 @@ const _4_1_text = defineMixin((editor) => {
3449
3449
  });
3450
3450
  const _4_2_frame = defineMixin((editor) => {
3451
3451
  const {
3452
- root,
3453
3452
  frames,
3454
3453
  isTopFrame,
3455
- exec,
3456
3454
  selection,
3457
3455
  getAncestorFrame
3458
3456
  } = editor;
@@ -3480,100 +3478,9 @@ const _4_2_frame = defineMixin((editor) => {
3480
3478
  }
3481
3479
  return frames.value[index];
3482
3480
  }
3483
- function handleDragOutReparent(element, options) {
3484
- const pointer = options?.pointer;
3485
- const frame1 = element.findAncestor((node) => isTopFrame(node));
3486
- const aabb1 = element.getGlobalAabb();
3487
- const area1 = aabb1.getArea();
3488
- let flag = true;
3489
- for (let i = 0, len = frames.value.length; i < len; i++) {
3490
- const frame2 = frames.value[i];
3491
- if (frame2.equal(element)) {
3492
- continue;
3493
- }
3494
- const aabb2 = frame2.getGlobalAabb();
3495
- if (pointer ? aabb2.contains(pointer) : aabb1 && aabb1.getIntersectionRect(aabb2).getArea() > area1 * 0.5) {
3496
- if (!frame2.equal(frame1)) {
3497
- let index = frame2.children.length;
3498
- if (frame2.equal(options?.parent)) {
3499
- index = options.index;
3500
- }
3501
- frame2.moveChild(element, index);
3502
- element.style.left = aabb1.x - aabb2.x;
3503
- element.style.top = aabb1.y - aabb2.y;
3504
- element.updateGlobalTransform();
3505
- exec("layerScrollIntoView");
3506
- }
3507
- flag = false;
3508
- break;
3509
- }
3510
- }
3511
- if (flag && frame1) {
3512
- let index = root.value.children.length;
3513
- if (root.value.equal(options?.parent)) {
3514
- index = options.index;
3515
- }
3516
- root.value.moveChild(element, index);
3517
- element.style.left = aabb1.x;
3518
- element.style.top = aabb1.y;
3519
- element.updateGlobalTransform();
3520
- exec("layerScrollIntoView");
3521
- }
3522
- }
3523
3481
  Object.assign(editor, {
3524
- findFrame,
3525
- handleDragOutReparent
3482
+ findFrame
3526
3483
  });
3527
- return () => {
3528
- const {
3529
- on,
3530
- getGlobalPointer
3531
- } = editor;
3532
- let startFrame;
3533
- let startContext = {};
3534
- on("selectionTransformStart", ({ elements }) => {
3535
- const pointer = getGlobalPointer();
3536
- startFrame = frames.value.find((frame) => frame.getGlobalAabb().contains(pointer));
3537
- const ctx = {};
3538
- elements.forEach((el) => {
3539
- ctx[el.instanceId] = {
3540
- parent: el.getParent(),
3541
- index: el.getIndex()
3542
- };
3543
- });
3544
- startContext = ctx;
3545
- });
3546
- on("selectionTransforming", ({ handle, startEvent, elements }) => {
3547
- if (handle === "move" && !startEvent?.__FROM__) {
3548
- const idSet = /* @__PURE__ */ new Set();
3549
- elements.forEach((el) => {
3550
- const frame = isTopFrame(el) ? el : el.findAncestor(isTopFrame);
3551
- if (frame) {
3552
- if (frame.equal(startFrame)) {
3553
- idSet.add(frame.instanceId);
3554
- }
3555
- } else {
3556
- idSet.add(0);
3557
- }
3558
- });
3559
- if (idSet.size === 1) {
3560
- elements.forEach((element) => {
3561
- handleDragOutReparent(
3562
- element,
3563
- {
3564
- ...startContext[element.instanceId],
3565
- pointer: getGlobalPointer()
3566
- }
3567
- );
3568
- });
3569
- }
3570
- }
3571
- });
3572
- on("selectionTransformEnd", () => {
3573
- startContext = {};
3574
- startFrame = void 0;
3575
- });
3576
- };
3577
3484
  });
3578
3485
  const _4_3_element = defineMixin((editor) => {
3579
3486
  const {
@@ -3584,7 +3491,7 @@ const _4_3_element = defineMixin((editor) => {
3584
3491
  log,
3585
3492
  root,
3586
3493
  isElement,
3587
- isFrame,
3494
+ inEditorIs,
3588
3495
  isLock,
3589
3496
  getObb,
3590
3497
  config,
@@ -3594,7 +3501,7 @@ const _4_3_element = defineMixin((editor) => {
3594
3501
  selection,
3595
3502
  camera,
3596
3503
  parseAnchor,
3597
- handleDragOutReparent
3504
+ exec
3598
3505
  } = editor;
3599
3506
  function addElement(value, options = {}) {
3600
3507
  log("addElement", value, options);
@@ -3752,7 +3659,7 @@ const _4_3_element = defineMixin((editor) => {
3752
3659
  selection.value = elements;
3753
3660
  }
3754
3661
  if (!isArray && !parent) {
3755
- handleDragOutReparent(elements[0]);
3662
+ exec("nestIntoFrame", elements[0]);
3756
3663
  }
3757
3664
  return isArray ? elements : elements[0];
3758
3665
  }
@@ -3782,7 +3689,7 @@ const _4_3_element = defineMixin((editor) => {
3782
3689
  function selectArea(areaInDrawboard) {
3783
3690
  const area2 = new Obb2D(areaInDrawboard);
3784
3691
  const selected = root.value?.children.flatMap((node) => {
3785
- if (isFrame(node) && node.parent?.equal(root.value)) {
3692
+ if (inEditorIs(node, "Frame") && node.parent?.equal(root.value)) {
3786
3693
  return node.children;
3787
3694
  }
3788
3695
  return [node];
@@ -4174,14 +4081,14 @@ const _snapshot = defineMixin((editor) => {
4174
4081
  const {
4175
4082
  on,
4176
4083
  config,
4177
- isFrame
4084
+ inEditorIs
4178
4085
  } = editor;
4179
4086
  on("setDoc", (doc) => {
4180
4087
  if (config.value.frameScreenshot) {
4181
4088
  snapshot();
4182
4089
  }
4183
4090
  function onAddChild(node, _newIndex) {
4184
- if (config.value.frameScreenshot && isFrame(node)) {
4091
+ if (config.value.frameScreenshot && inEditorIs(node, "Frame")) {
4185
4092
  const index = frames.value.findIndex((f) => f.equal(node));
4186
4093
  frameThumbs.value.splice(index, 0, {
4187
4094
  instanceId: -1,
@@ -4193,7 +4100,7 @@ const _snapshot = defineMixin((editor) => {
4193
4100
  }
4194
4101
  }
4195
4102
  function onRemoveChild(node, _oldIndex) {
4196
- if (config.value.frameScreenshot && isFrame(node)) {
4103
+ if (config.value.frameScreenshot && inEditorIs(node, "Frame")) {
4197
4104
  frameThumbs.value.splice(
4198
4105
  frameThumbs.value.findIndex((v) => v.instanceId === node.instanceId),
4199
4106
  1
@@ -4480,21 +4387,105 @@ const _arrange = definePlugin((editor) => {
4480
4387
  ]
4481
4388
  };
4482
4389
  });
4483
- const _cancel = definePlugin((editor) => {
4390
+ const _autoNest = definePlugin((editor) => {
4484
4391
  const {
4485
- state
4392
+ getGlobalPointer,
4393
+ frames,
4394
+ isTopFrame,
4395
+ exec,
4396
+ root
4486
4397
  } = editor;
4487
- function cancel() {
4488
- state.value = void 0;
4398
+ let startFrame;
4399
+ let startContext = {};
4400
+ function nestIntoFrame(element, options) {
4401
+ const pointer = options?.pointer;
4402
+ const frame1 = element.findAncestor((node) => isTopFrame(node));
4403
+ const aabb1 = element.getGlobalAabb();
4404
+ const area1 = aabb1.getArea();
4405
+ let flag = true;
4406
+ for (let i = 0, len = frames.value.length; i < len; i++) {
4407
+ const frame2 = frames.value[i];
4408
+ if (frame2.equal(element)) {
4409
+ continue;
4410
+ }
4411
+ const aabb2 = frame2.getGlobalAabb();
4412
+ if (pointer ? aabb2.contains(pointer) : aabb1 && aabb1.getIntersectionRect(aabb2).getArea() > area1 * 0.5) {
4413
+ if (!frame2.equal(frame1)) {
4414
+ let index = frame2.children.length;
4415
+ if (frame2.equal(options?.parent)) {
4416
+ index = options.index;
4417
+ }
4418
+ frame2.moveChild(element, index);
4419
+ element.style.left = aabb1.x - aabb2.x;
4420
+ element.style.top = aabb1.y - aabb2.y;
4421
+ element.updateGlobalTransform();
4422
+ exec("layerScrollIntoView");
4423
+ }
4424
+ flag = false;
4425
+ break;
4426
+ }
4427
+ }
4428
+ if (flag && frame1) {
4429
+ let index = root.value.children.length;
4430
+ if (root.value.equal(options?.parent)) {
4431
+ index = options.index;
4432
+ }
4433
+ root.value.moveChild(element, index);
4434
+ element.style.left = aabb1.x;
4435
+ element.style.top = aabb1.y;
4436
+ element.updateGlobalTransform();
4437
+ exec("layerScrollIntoView");
4438
+ }
4489
4439
  }
4490
4440
  return {
4491
- name: "mce:cancel",
4441
+ name: "mce:autoNest",
4492
4442
  commands: [
4493
- { command: "cancel", handle: cancel }
4443
+ { command: "nestIntoFrame", handle: nestIntoFrame }
4494
4444
  ],
4495
- hotkeys: [
4496
- { command: "cancel", key: "escape", editable: false }
4497
- ]
4445
+ events: {
4446
+ selectionTransformStart: ({ elements }) => {
4447
+ const pointer = getGlobalPointer();
4448
+ startFrame = frames.value.find((frame) => frame.getGlobalAabb().contains(pointer));
4449
+ const ctx = {};
4450
+ elements.forEach((el) => {
4451
+ ctx[el.instanceId] = {
4452
+ parent: el.getParent(),
4453
+ index: el.getIndex()
4454
+ };
4455
+ });
4456
+ startContext = ctx;
4457
+ },
4458
+ selectionTransforming: ({ handle, startEvent, elements }) => {
4459
+ if (handle === "move" && !startEvent?.__FROM__) {
4460
+ const idSet = /* @__PURE__ */ new Set();
4461
+ elements.forEach((el) => {
4462
+ const frame = isTopFrame(el) ? el : el.findAncestor(isTopFrame);
4463
+ if (frame) {
4464
+ if (frame.equal(startFrame)) {
4465
+ idSet.add(frame.instanceId);
4466
+ }
4467
+ } else {
4468
+ idSet.add(0);
4469
+ }
4470
+ });
4471
+ if (idSet.size === 1) {
4472
+ elements.forEach((element) => {
4473
+ nestIntoFrame(
4474
+ element,
4475
+ {
4476
+ ...startContext[element.instanceId],
4477
+ pointer: getGlobalPointer()
4478
+ }
4479
+ );
4480
+ });
4481
+ }
4482
+ }
4483
+ },
4484
+ selectionTransformEnd: () => {
4485
+ startContext = {};
4486
+ startFrame = void 0;
4487
+ }
4488
+ }
4498
4489
  };
4499
4490
  });
4500
4491
  const _copyAs = definePlugin((editor) => {
@@ -4521,31 +4512,6 @@ const _copyAs = definePlugin((editor) => {
4521
4512
  ]
4522
4513
  };
4523
4514
  });
4524
- const _delete = definePlugin((editor) => {
4525
- const {
4526
- selection,
4527
- hoverElement
4528
- } = editor;
4529
- function _delete2() {
4530
- if (selection.value.length) {
4531
- selection.value.forEach((node) => {
4532
- node.remove();
4533
- });
4534
- selection.value = [];
4535
- }
4536
- hoverElement.value = void 0;
4537
- }
4538
- const when = () => Boolean(selection.value.length > 0);
4539
- return {
4540
- name: "mce:delete",
4541
- commands: [
4542
- { command: "delete", handle: _delete2 }
4543
- ],
4544
- hotkeys: [
4545
- { command: "delete", key: ["Backspace", "Delete"], when }
4546
- ]
4547
- };
4548
- });
4549
4515
  const _hoisted_1$n = {
4550
4516
  key: 0,
4551
4517
  class: "mce-drawing__tip"
@@ -4589,14 +4555,28 @@ const _drawingTool = definePlugin((editor) => {
4589
4555
  });
4590
4556
  const _edit = definePlugin((editor, options) => {
4591
4557
  const {
4558
+ state,
4592
4559
  selection,
4593
4560
  exec,
4594
4561
  canLoad,
4595
4562
  load,
4596
- addElements
4563
+ addElements,
4564
+ hoverElement
4597
4565
  } = editor;
4598
4566
  const copiedData = ref();
4599
4567
  const useClipboard = options.clipboard !== false && SUPPORTS_CLIPBOARD;
4568
+ const cancel = () => {
4569
+ state.value = void 0;
4570
+ };
4571
+ const _delete = () => {
4572
+ if (selection.value.length) {
4573
+ selection.value.forEach((node) => {
4574
+ node.remove();
4575
+ });
4576
+ selection.value = [];
4577
+ }
4578
+ hoverElement.value = void 0;
4579
+ };
4600
4580
  const copy = async (source) => {
4601
4581
  if (typeof source === "string") {
4602
4582
  if (useClipboard) {
@@ -4808,12 +4788,16 @@ const _edit = definePlugin((editor, options) => {
4808
4788
  return {
4809
4789
  name: "mce:edit",
4810
4790
  commands: [
4791
+ { command: "cancel", handle: cancel },
4792
+ { command: "delete", handle: _delete },
4811
4793
  { command: "copy", handle: copy },
4812
4794
  { command: "cut", handle: cut },
4813
4795
  { command: "paste", handle: paste },
4814
4796
  { command: "duplicate", handle: duplicate }
4815
4797
  ],
4816
4798
  hotkeys: [
4799
+ { command: "cancel", key: "escape", editable: false },
4800
+ { command: "delete", key: ["Backspace", "Delete"], when: () => Boolean(selection.value.length > 0) },
4817
4801
  { command: "copy", key: "CmdOrCtrl+C", editable: false },
4818
4802
  { command: "cut", key: "CmdOrCtrl+X", editable: false },
4819
4803
  { command: "paste", key: "CmdOrCtrl+V", editable: false, preventDefault: false },
@@ -5465,10 +5449,16 @@ const defaultActiveStrategy = (context) => {
5465
5449
  if (!element) {
5466
5450
  return void 0;
5467
5451
  }
5468
- const { isRoot, isFrame, isElement, elementSelection } = editor;
5452
+ const {
5453
+ isRoot,
5454
+ inEditorIs,
5455
+ isElement,
5456
+ elementSelection
5457
+ } = editor;
5469
5458
  const activeElement = elementSelection.value[0];
5470
5459
  const cb = (node) => {
5471
- if (isElement(node) && (node.equal(activeElement) || node.parent?.equal(activeElement) || node.parent?.equal(activeElement?.parent) || isFrame(node.parent) && isRoot(node.parent.parent) || isRoot(node.parent))) {
5460
+ const parent = node.parent;
5461
+ if (isElement(node) && (node.equal(activeElement) || parent?.equal(activeElement) || parent?.equal(activeElement?.parent) || parent && inEditorIs(parent, "Frame") && isRoot(parent.parent) || isRoot(parent))) {
5472
5462
  return true;
5473
5463
  }
5474
5464
  return false;
@@ -5492,10 +5482,16 @@ const defaultHoverStrategy = (context) => {
5492
5482
  if (!element) {
5493
5483
  return void 0;
5494
5484
  }
5495
- const { isRoot, isFrame, isElement, elementSelection } = editor;
5485
+ const {
5486
+ isRoot,
5487
+ inEditorIs,
5488
+ isElement,
5489
+ elementSelection
5490
+ } = editor;
5496
5491
  const activeElement = elementSelection.value[0];
5497
5492
  const cb = (node) => {
5498
- if (isElement(node) && (node.equal(activeElement) || node.parent?.equal(activeElement) || node.parent?.equal(activeElement?.parent) || isFrame(node.parent) && isRoot(node.parent.parent) || isRoot(node.parent))) {
5493
+ const parent = node.parent;
5494
+ if (isElement(node) && (node.equal(activeElement) || parent?.equal(activeElement) || parent?.equal(activeElement?.parent) || parent && inEditorIs(parent, "Frame") && isRoot(parent.parent) || isRoot(parent))) {
5499
5495
  return true;
5500
5496
  }
5501
5497
  return false;
@@ -5818,7 +5814,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
5818
5814
  } = useEditor();
5819
5815
  const hoverElementObb = computed(() => getObb(hoverElement.value, "drawboard"));
5820
5816
  return (_ctx, _cache) => {
5821
- return unref(hoverElement) && !unref(hoverElement).equal(unref(selection)[0]) ? (openBlock(), createElementBlock("div", {
5817
+ return unref(hoverElement) && !unref(selection).some((node) => node.equal(unref(hoverElement))) ? (openBlock(), createElementBlock("div", {
5822
5818
  key: 0,
5823
5819
  class: "mce-hover",
5824
5820
  "data-name": unref(hoverElement).name,
@@ -5835,7 +5831,7 @@ const _hover = definePlugin(() => {
5835
5831
  return {
5836
5832
  name: "mce:hover",
5837
5833
  components: [
5838
- { type: "overlay", component: _sfc_main$z }
5834
+ { type: "overlay", component: _sfc_main$z, order: "before" }
5839
5835
  ]
5840
5836
  };
5841
5837
  });
@@ -6162,7 +6158,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
6162
6158
  const props = __props;
6163
6159
  const {
6164
6160
  isElement,
6165
- isFrame,
6161
+ inEditorIs,
6166
6162
  isVisible,
6167
6163
  setVisible,
6168
6164
  isLock,
@@ -6199,7 +6195,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
6199
6195
  const editValue = ref();
6200
6196
  const thumbnailIcon = computed(() => {
6201
6197
  const node = props.node;
6202
- if (isFrame(node)) {
6198
+ if (inEditorIs(node, "Frame")) {
6203
6199
  return "$frame";
6204
6200
  } else if (node.children.filter(isElement).length) {
6205
6201
  return "$group";
@@ -6221,7 +6217,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
6221
6217
  const node = props.node;
6222
6218
  let value = node.name;
6223
6219
  if (!value) {
6224
- if (isFrame(node)) {
6220
+ if (inEditorIs(node, "Frame")) {
6225
6221
  return t("frame");
6226
6222
  } else if (node.children.filter(isElement).length) {
6227
6223
  value = t("group");
@@ -13734,87 +13730,100 @@ const _smartGuides = definePlugin((editor) => {
13734
13730
  };
13735
13731
  return areas;
13736
13732
  }
13737
- const linePairs = computed(() => {
13738
- const { vLines, hLines } = store.value;
13733
+ const linePairs = ref([]);
13734
+ function updateSmartGuides() {
13735
+ const _linePairs = [];
13739
13736
  const box = activeBox.value;
13740
- if (!box) {
13741
- return [];
13742
- }
13743
- const areaLine = {
13744
- vt: [],
13745
- vb: [],
13746
- hl: [],
13747
- hr: []
13748
- };
13749
- const linePairs2 = [];
13750
- [
13751
- { sources: [box.vt, box.vm, box.vb], targets: vLines },
13752
- { sources: [box.hl, box.hm, box.hr], targets: hLines }
13753
- ].forEach(({ targets, sources }) => {
13754
- for (const source of sources) {
13755
- const target = targets.searchClosest(source, (a, b, c) => {
13756
- return !c || Math.abs(a.pos - b.pos) < Math.abs(a.pos - c.pos);
13757
- });
13758
- if (!target)
13759
- continue;
13760
- const distance2 = Math.abs(target.pos - source.pos);
13761
- if (distance2 >= snapThreshold.value)
13762
- continue;
13763
- linePairs2.push({ source, target, type: "alignment", distance: distance2 });
13764
- }
13765
- });
13766
- [
13767
- { sources: [box.vt, box.vb], targets: vLines },
13768
- { sources: [box.hl, box.hr], targets: hLines }
13769
- ].forEach(({ sources, targets }) => {
13770
- for (const source of sources) {
13771
- areaLine[source.type] = findLines(targets, source);
13772
- }
13773
- });
13774
- areaLine.vt = areaLine.vt.sort((a, b) => b.pos - a.pos);
13775
- areaLine.hl = areaLine.hl.sort((a, b) => b.pos - a.pos);
13776
- [
13777
- { targets: [areaLine.vt, areaLine.vb], sources: [box.vt, box.vb] },
13778
- { targets: [areaLine.hl, areaLine.hr], sources: [box.hl, box.hr] }
13779
- ].forEach(({ sources, targets }) => {
13780
- const targetA = targets[0][0];
13781
- const sourceA = sources[0];
13782
- const targetB = targets[1][0];
13783
- const sourceB = sources[1];
13784
- if (targetA && targetB && (!isCanvasLine(targetA) || !isCanvasLine(targetB))) {
13785
- const distanceA = Math.abs(sourceA.pos - targetA.pos);
13786
- const distanceB = Math.abs(sourceB.pos - targetB.pos);
13787
- if (Math.abs(distanceA - distanceB) < snapThreshold.value) {
13788
- const isLeftTop = isLeftTopLine(sourceA);
13789
- linePairs2.push({
13790
- target: targetA,
13791
- source: sourceA,
13792
- type: "area",
13793
- distance: distanceA,
13794
- _ctx: {
13795
- type: sourceA.type,
13796
- pos: isLeftTop ? targetA.pos + (distanceA + distanceB) / 2 : targetA.pos - (distanceA + distanceB) / 2
13797
- }
13798
- });
13799
- linePairs2.push({
13800
- target: targetB,
13801
- source: sourceB,
13802
- type: "area",
13803
- distance: distanceB
13737
+ if (box) {
13738
+ const {
13739
+ vLines,
13740
+ hLines
13741
+ } = store.value;
13742
+ const areaLine = {
13743
+ vt: [],
13744
+ vb: [],
13745
+ hl: [],
13746
+ hr: []
13747
+ };
13748
+ const alignmentItems = [
13749
+ { sources: [box.vt, box.vm, box.vb], targets: vLines },
13750
+ { sources: [box.hl, box.hm, box.hr], targets: hLines }
13751
+ ];
13752
+ alignmentItems.forEach(({ targets, sources }) => {
13753
+ const items = [];
13754
+ for (const source of sources) {
13755
+ const target = targets.searchClosest(source, (a, b, c) => {
13756
+ return !c || Math.abs(a.pos - b.pos) < Math.abs(a.pos - c.pos);
13804
13757
  });
13805
- return;
13758
+ if (!target) {
13759
+ continue;
13760
+ }
13761
+ const distance2 = Math.abs(target.pos - source.pos);
13762
+ if (distance2 >= snapThreshold.value) {
13763
+ continue;
13764
+ }
13765
+ items.push({ source, target, type: "alignment", distance: distance2 });
13806
13766
  }
13807
- }
13808
- for (const i in sources) {
13809
- const areas = findAreas(targets[i], sources[i]);
13810
- if (areas.length) {
13811
- linePairs2.push(...areas);
13812
- break;
13767
+ items.sort((a, b) => a.distance - b.distance);
13768
+ if (items.length) {
13769
+ _linePairs.push(items[0]);
13813
13770
  }
13814
- }
13815
- });
13816
- return linePairs2;
13817
- });
13771
+ });
13772
+ const areaLineItems = [
13773
+ { sources: [box.vt, box.vb], targets: vLines },
13774
+ { sources: [box.hl, box.hr], targets: hLines }
13775
+ ];
13776
+ areaLineItems.forEach(({ sources, targets }) => {
13777
+ for (const source of sources) {
13778
+ areaLine[source.type] = findLines(targets, source);
13779
+ }
13780
+ });
13781
+ areaLine.vt = areaLine.vt.sort((a, b) => b.pos - a.pos);
13782
+ areaLine.hl = areaLine.hl.sort((a, b) => b.pos - a.pos);
13783
+ const areaItems = [
13784
+ { targets: [areaLine.vt, areaLine.vb], sources: [box.vt, box.vb] },
13785
+ { targets: [areaLine.hl, areaLine.hr], sources: [box.hl, box.hr] }
13786
+ ];
13787
+ areaItems.forEach(({ sources, targets }) => {
13788
+ const targetA = targets[0][0];
13789
+ const sourceA = sources[0];
13790
+ const targetB = targets[1][0];
13791
+ const sourceB = sources[1];
13792
+ if (targetA && targetB && (!isCanvasLine(targetA) || !isCanvasLine(targetB))) {
13793
+ const distanceA = Math.abs(sourceA.pos - targetA.pos);
13794
+ const distanceB = Math.abs(sourceB.pos - targetB.pos);
13795
+ if (Math.abs(distanceA - distanceB) < snapThreshold.value) {
13796
+ const isLeftTop = isLeftTopLine(sourceA);
13797
+ _linePairs.push({
13798
+ target: targetA,
13799
+ source: sourceA,
13800
+ type: "area",
13801
+ distance: distanceA,
13802
+ _ctx: {
13803
+ type: sourceA.type,
13804
+ pos: isLeftTop ? targetA.pos + (distanceA + distanceB) / 2 : targetA.pos - (distanceA + distanceB) / 2
13805
+ }
13806
+ });
13807
+ _linePairs.push({
13808
+ target: targetB,
13809
+ source: sourceB,
13810
+ type: "area",
13811
+ distance: distanceB
13812
+ });
13813
+ return;
13814
+ }
13815
+ }
13816
+ for (const i in sources) {
13817
+ const areas = findAreas(targets[i], sources[i]);
13818
+ if (areas.length) {
13819
+ _linePairs.push(...areas);
13820
+ break;
13821
+ }
13822
+ }
13823
+ });
13824
+ }
13825
+ linePairs.value = _linePairs;
13826
+ }
13818
13827
  const snapLines = computed(() => {
13819
13828
  if (state.value !== "transforming")
13820
13829
  return [];
@@ -13938,7 +13947,10 @@ const _smartGuides = definePlugin((editor) => {
13938
13947
  name: "mce:smartGuides",
13939
13948
  components: [
13940
13949
  { type: "overlay", component: _sfc_main$k }
13941
- ]
13950
+ ],
13951
+ events: {
13952
+ selectionTransforming: updateSmartGuides
13953
+ }
13942
13954
  };
13943
13955
  });
13944
13956
  function createLine(pos, type, box) {
@@ -13967,6 +13979,11 @@ function flipType(type) {
13967
13979
  function isLeftTopLine(line) {
13968
13980
  return ["vt", "hl"].includes(line.type);
13969
13981
  }
13982
+ const _smartSelection = definePlugin((_editor) => {
13983
+ return {
13984
+ name: "mce:smartSelection"
13985
+ };
13986
+ });
13970
13987
  const _state = definePlugin((editor) => {
13971
13988
  const {
13972
13989
  state
@@ -14921,9 +14938,8 @@ const _zoom = definePlugin((editor) => {
14921
14938
  });
14922
14939
  const plugins = [
14923
14940
  _arrange,
14924
- _cancel,
14941
+ _autoNest,
14925
14942
  _copyAs,
14926
- _delete,
14927
14943
  _drawingTool,
14928
14944
  _edit,
14929
14945
  _frame,
@@ -14953,6 +14969,7 @@ const plugins = [
14953
14969
  _shape,
14954
14970
  _slice,
14955
14971
  _smartGuides,
14972
+ _smartSelection,
14956
14973
  _state,
14957
14974
  _statusbar,
14958
14975
  _text,
@@ -15126,7 +15143,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
15126
15143
  const {
15127
15144
  elementSelection,
15128
15145
  selectionAabbInDrawboard,
15129
- isFrame
15146
+ inEditorIs
15130
15147
  } = useEditor();
15131
15148
  const overlay = useTemplateRef("overlayTpl");
15132
15149
  const style = computed(() => {
@@ -15144,7 +15161,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
15144
15161
  return {};
15145
15162
  });
15146
15163
  const offset2 = computed(() => {
15147
- if (elementSelection.value.some((v) => isFrame(v)) || props.location?.startsWith("bottom")) {
15164
+ if (elementSelection.value.some((v) => inEditorIs(v, "Frame")) || props.location?.startsWith("bottom")) {
15148
15165
  return 32;
15149
15166
  }
15150
15167
  return 8;
@@ -16024,7 +16041,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
16024
16041
  getObb,
16025
16042
  registerCommand,
16026
16043
  unregisterCommand,
16027
- isFrame,
16044
+ inEditorIs,
16028
16045
  isLock,
16029
16046
  config,
16030
16047
  snapThreshold,
@@ -16165,7 +16182,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
16165
16182
  element,
16166
16183
  newStyle.width / element.style.width,
16167
16184
  newStyle.height / element.style.height,
16168
- isFrame(element) ? void 0 : shape.isValid() ? { deep: true } : handle.split("-")[1].length > 1 ? { deep: true, textFontSizeToFit: true } : { deep: true, textToFit: true }
16185
+ inEditorIs(element, "Frame") ? void 0 : shape.isValid() ? { deep: true } : handle.split("-")[1].length > 1 ? { deep: true, textFontSizeToFit: true } : { deep: true, textToFit: true }
16169
16186
  );
16170
16187
  newStyle.width = element.style.width;
16171
16188
  newStyle.height = element.style.height;
@@ -16173,7 +16190,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
16173
16190
  Object.assign(style, newStyle);
16174
16191
  element.updateGlobalTransform();
16175
16192
  element.findAncestor((ancestor) => {
16176
- if (isElement(ancestor) && !isFrame(ancestor)) {
16193
+ if (isElement(ancestor) && !inEditorIs(ancestor, "Frame")) {
16177
16194
  obbToFit(ancestor);
16178
16195
  }
16179
16196
  return false;
@@ -1,14 +1,8 @@
1
- import type { Element2D, Vector2Like } from 'modern-canvas';
1
+ import type { Element2D } from 'modern-canvas';
2
2
  declare global {
3
3
  namespace Mce {
4
- interface HandleDragOutReparentOptions {
5
- pointer: Vector2Like;
6
- parent: Element2D;
7
- index: number;
8
- }
9
4
  interface Editor {
10
5
  findFrame: (target: 'next' | 'previous') => Element2D | undefined;
11
- handleDragOutReparent: (element: Element2D, context?: HandleDragOutReparentOptions) => void;
12
6
  }
13
7
  }
14
8
  }
@@ -0,0 +1,15 @@
1
+ import type { Element2D, Vector2Like } from 'modern-canvas';
2
+ declare global {
3
+ namespace Mce {
4
+ interface NestIntoFrameOptions {
5
+ pointer: Vector2Like;
6
+ parent: Element2D;
7
+ index: number;
8
+ }
9
+ interface Commands {
10
+ nestIntoFrame: (element: Element2D, options?: NestIntoFrameOptions) => void;
11
+ }
12
+ }
13
+ }
14
+ declare const _default: import("..").Plugin;
15
+ export default _default;
@@ -1,20 +1,24 @@
1
1
  import type { Ref } from 'vue';
2
2
  declare global {
3
3
  namespace Mce {
4
- interface Hotkeys {
5
- copy: [event: KeyboardEvent];
6
- cut: [event: KeyboardEvent];
7
- paste: [event: KeyboardEvent];
8
- duplicate: [event: KeyboardEvent];
9
- }
10
4
  type CopySource = string | Blob | Blob[] | Record<string, any>[];
11
5
  type PasteSource = DataTransfer | ClipboardItem[];
12
6
  interface Commands {
7
+ cancel: () => void;
8
+ delete: () => void;
13
9
  copy: (source?: CopySource) => Promise<void>;
14
10
  cut: () => Promise<void>;
15
11
  paste: (source?: PasteSource) => Promise<void>;
16
12
  duplicate: () => void;
17
13
  }
14
+ interface Hotkeys {
15
+ cancel: [event: KeyboardEvent];
16
+ delete: [event: KeyboardEvent];
17
+ copy: [event: KeyboardEvent];
18
+ cut: [event: KeyboardEvent];
19
+ paste: [event: KeyboardEvent];
20
+ duplicate: [event: KeyboardEvent];
21
+ }
18
22
  interface Editor {
19
23
  copiedData: Ref<any | undefined>;
20
24
  }
@@ -1,7 +1,6 @@
1
1
  declare global {
2
2
  namespace Mce {
3
- interface Commands {
4
- cancel: () => void;
3
+ interface Editor {
5
4
  }
6
5
  }
7
6
  }
@@ -28,9 +28,8 @@ import './mixins/scroll'
28
28
  import './mixins/snapshot'
29
29
  import './mixins/zoom'
30
30
  import './plugins/arrange'
31
- import './plugins/cancel'
31
+ import './plugins/autoNest'
32
32
  import './plugins/copyAs'
33
- import './plugins/delete'
34
33
  import './plugins/drawingTool'
35
34
  import './plugins/edit'
36
35
  import './plugins/frame'
@@ -60,6 +59,7 @@ import './plugins/selection'
60
59
  import './plugins/shape'
61
60
  import './plugins/slice'
62
61
  import './plugins/smartGuides'
62
+ import './plugins/smartSelection'
63
63
  import './plugins/state'
64
64
  import './plugins/statusbar'
65
65
  import './plugins/text'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.15.28",
4
+ "version": "0.15.29",
5
5
  "description": "The headless canvas editor framework. only the ESM.",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -1,12 +0,0 @@
1
- declare global {
2
- namespace Mce {
3
- interface Commands {
4
- delete: () => void;
5
- }
6
- interface Hotkeys {
7
- delete: [event: KeyboardEvent];
8
- }
9
- }
10
- }
11
- declare const _default: import("..").Plugin;
12
- export default _default;