mce 0.13.16 → 0.14.1

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
@@ -1,5 +1,5 @@
1
1
  import { Node as Node$1, Element2D, Timeline, Engine, Camera2D, DrawboardEffect, IN_BROWSER, clamp, assets, TimelineNode, Transform2D, DEG_TO_RAD, render, Animation, IN_MAC_OS } from "modern-canvas";
2
- import { ref, computed, watch, markRaw, reactive, warn, shallowRef, onBeforeUnmount, defineComponent, createElementBlock, createCommentVNode, unref, openBlock, normalizeStyle, toDisplayString, createVNode, useAttrs, createBlock, resolveDynamicComponent, normalizeClass, mergeProps, createElementVNode, inject, toValue, getCurrentInstance, provide, readonly, toRef, onMounted, useId, onDeactivated, onActivated, onScopeDispose, useModel, useTemplateRef, withDirectives, vShow, vModelText, nextTick, Fragment, renderList, renderSlot, mergeModels, resolveComponent, withCtx, withModifiers, Teleport, createTextVNode, createSlots, normalizeProps, guardReactiveProps, onBeforeMount, isRef, h, useSlots } from "vue";
2
+ import { reactive, computed, watch, markRaw, ref, warn, shallowRef, onBeforeUnmount, defineComponent, createElementBlock, createCommentVNode, unref, openBlock, normalizeStyle, toDisplayString, createVNode, useAttrs, createBlock, resolveDynamicComponent, normalizeClass, mergeProps, createElementVNode, inject, toValue, getCurrentInstance, provide, readonly, toRef, onMounted, useId, onDeactivated, onActivated, onScopeDispose, useModel, useTemplateRef, withDirectives, vShow, vModelText, nextTick, Fragment, renderList, renderSlot, mergeModels, resolveComponent, withCtx, withModifiers, Teleport, createTextVNode, createSlots, normalizeProps, guardReactiveProps, onBeforeMount, isRef, h, useSlots } from "vue";
3
3
  import { useFileDialog, useEventListener, isClient, onClickOutside, useDebounceFn, useResizeObserver as useResizeObserver$1, useLocalStorage, useImage } from "@vueuse/core";
4
4
  import { getObjectValueByPath, setObjectValueByPath, Observable, Reactivable, idGenerator, property, normalizeElement, normalizeTextContent, normalizeCRLF, isEqualObject } from "modern-idoc";
5
5
  import { saveAs } from "file-saver";
@@ -17,23 +17,23 @@ const _0_command = defineMixin((editor) => {
17
17
  const {
18
18
  emit
19
19
  } = editor;
20
- const commands = ref(/* @__PURE__ */ new Map());
20
+ const commands = reactive(/* @__PURE__ */ new Map());
21
21
  const registerCommand = (value) => {
22
22
  if (Array.isArray(value)) {
23
23
  value.forEach((item) => registerCommand(item));
24
24
  } else {
25
- commands.value.set(value.command, value);
25
+ commands.set(value.command, value);
26
26
  }
27
27
  };
28
28
  const unregisterCommand = (command) => {
29
- commands.value.delete(command);
29
+ commands.delete(command);
30
30
  };
31
31
  const exec = (command, ...args) => {
32
32
  const [name, arg1] = command.split(":");
33
33
  if (arg1 !== void 0) {
34
34
  args.unshift(arg1);
35
35
  }
36
- const item = commands.value.get(name);
36
+ const item = commands.get(name);
37
37
  if (!item) {
38
38
  throw new Error(`Command "${name}" not found`);
39
39
  }
@@ -847,7 +847,7 @@ class Doc extends Model {
847
847
  });
848
848
  node._text = markRaw(node._text);
849
849
  node.text.update();
850
- node.requestRedraw();
850
+ node.requestRender();
851
851
  }
852
852
  this._proxyChildren(node, yEle.get("childrenIds"));
853
853
  }
@@ -1088,6 +1088,7 @@ const en = {
1088
1088
  "polygon": "Polygon",
1089
1089
  "star": "Star",
1090
1090
  "image": "Image",
1091
+ "pen": "Pen",
1091
1092
  "pencil": "Pencil",
1092
1093
  "file": "File",
1093
1094
  "new": "New",
@@ -1188,6 +1189,7 @@ const zhHans = {
1188
1189
  "polygon": "多边形",
1189
1190
  "star": "星形",
1190
1191
  "image": "图片",
1192
+ "pen": "钢笔",
1191
1193
  "pencil": "铅笔",
1192
1194
  "file": "文件",
1193
1195
  "new": "新建",
@@ -1631,7 +1633,7 @@ const _1_hotkey = defineMixin((editor) => {
1631
1633
  registerConfig
1632
1634
  } = editor;
1633
1635
  const hotkeysData = registerConfig("hotkeys", []);
1634
- const hotkeys = ref(/* @__PURE__ */ new Map());
1636
+ const hotkeys = reactive(/* @__PURE__ */ new Map());
1635
1637
  function registerHotkey(value) {
1636
1638
  if (Array.isArray(value)) {
1637
1639
  value.forEach((item) => registerHotkey(item));
@@ -1648,7 +1650,7 @@ const _1_hotkey = defineMixin((editor) => {
1648
1650
  ...hotkeysData.value.filter((v) => v.command !== command),
1649
1651
  hotkeyData
1650
1652
  ];
1651
- hotkeys.value.set(command, value);
1653
+ hotkeys.set(command, value);
1652
1654
  }
1653
1655
  }
1654
1656
  function unregisterHotkey(command) {
@@ -1734,7 +1736,7 @@ const _1_hotkey = defineMixin((editor) => {
1734
1736
  ].filter(Boolean).map((v) => v.toLowerCase()).sort().join("+");
1735
1737
  hotkeysData.value.forEach((hotkeyData) => {
1736
1738
  const command = hotkeyData.command;
1737
- const hotkey = hotkeys.value.get(command);
1739
+ const hotkey = hotkeys.get(command);
1738
1740
  const keys = Array.isArray(hotkeyData.key) ? hotkeyData.key : [hotkeyData.key];
1739
1741
  keys.forEach((key) => {
1740
1742
  const tKey = key.split("+").map((v) => {
@@ -2091,21 +2093,21 @@ const _2_box = defineMixin((editor) => {
2091
2093
  });
2092
2094
  });
2093
2095
  const _2_export = defineMixin((editor) => {
2094
- const exporters = ref(/* @__PURE__ */ new Map());
2096
+ const exporters = reactive(/* @__PURE__ */ new Map());
2095
2097
  const exporting = ref(false);
2096
2098
  const exportProgress = ref(0);
2097
2099
  const registerExporter = (value) => {
2098
2100
  if (Array.isArray(value)) {
2099
2101
  value.forEach((item) => registerExporter(item));
2100
2102
  } else {
2101
- exporters.value.set(value.name, value);
2103
+ exporters.set(value.name, value);
2102
2104
  }
2103
2105
  };
2104
2106
  const unregisterExporter = (name) => {
2105
- exporters.value.delete(name);
2107
+ exporters.delete(name);
2106
2108
  };
2107
2109
  const to = (name, options = {}) => {
2108
- const res = exporters.value.get(name)?.handle({
2110
+ const res = exporters.get(name)?.handle({
2109
2111
  ...options,
2110
2112
  onProgress: (progress) => {
2111
2113
  exportProgress.value = progress;
@@ -2136,19 +2138,19 @@ const _2_load = defineMixin((editor) => {
2136
2138
  const {
2137
2139
  state
2138
2140
  } = editor;
2139
- const loaders = ref(/* @__PURE__ */ new Map());
2141
+ const loaders = reactive(/* @__PURE__ */ new Map());
2140
2142
  const registerLoader = (value) => {
2141
2143
  if (Array.isArray(value)) {
2142
2144
  value.forEach((v) => registerLoader(v));
2143
2145
  } else {
2144
- loaders.value.set(value.name, value);
2146
+ loaders.set(value.name, value);
2145
2147
  }
2146
2148
  };
2147
2149
  const unregisterLoader = (key) => {
2148
- loaders.value.delete(key);
2150
+ loaders.delete(key);
2149
2151
  };
2150
2152
  const canLoad = async (source) => {
2151
- for (const loader of loaders.value.values()) {
2153
+ for (const loader of loaders.values()) {
2152
2154
  if (await loader.test(source)) {
2153
2155
  return true;
2154
2156
  }
@@ -2159,7 +2161,7 @@ const _2_load = defineMixin((editor) => {
2159
2161
  state.value = "loading";
2160
2162
  const items = [];
2161
2163
  try {
2162
- for (const loader of loaders.value.values()) {
2164
+ for (const loader of loaders.values()) {
2163
2165
  if (await loader.test(source)) {
2164
2166
  const res = await loader.load(source);
2165
2167
  if (Array.isArray(res)) {
@@ -2184,7 +2186,7 @@ const _2_load = defineMixin((editor) => {
2184
2186
  } = options;
2185
2187
  return new Promise((resolve) => {
2186
2188
  const accepts = [];
2187
- for (const loader of loaders.value.values()) {
2189
+ for (const loader of loaders.values()) {
2188
2190
  if (loader.accept) {
2189
2191
  accepts.push(loader.accept);
2190
2192
  }
@@ -2342,7 +2344,7 @@ const _4_0_text = defineMixin((editor) => {
2342
2344
  });
2343
2345
  });
2344
2346
  }
2345
- element3.requestRedraw();
2347
+ element3.requestRender();
2346
2348
  }
2347
2349
  _handle(element2);
2348
2350
  element2.findOne((descendant) => {
@@ -2380,7 +2382,7 @@ const _4_0_text = defineMixin((editor) => {
2380
2382
  if (element3.style.width !== boundingBox.width || element3.style.height !== boundingBox.height) {
2381
2383
  element3.style.width = boundingBox.width;
2382
2384
  element3.style.height = boundingBox.height;
2383
- element3.requestRedraw();
2385
+ element3.requestRender();
2384
2386
  }
2385
2387
  }
2386
2388
  _handle(element2);
@@ -2528,7 +2530,7 @@ const _4_0_text = defineMixin((editor) => {
2528
2530
  });
2529
2531
  el.text.content = content;
2530
2532
  }
2531
- element.value.requestRedraw();
2533
+ element.value.requestRender();
2532
2534
  textToFit(element.value);
2533
2535
  }
2534
2536
  function getTextFill() {
@@ -2779,7 +2781,7 @@ const _4_2_element = defineMixin((editor) => {
2779
2781
  style.top = style.top * scaleY;
2780
2782
  style.width = style.width * scaleX;
2781
2783
  style.height = style.height * scaleY;
2782
- element2?.requestRedraw?.();
2784
+ element2?.requestRender?.();
2783
2785
  }
2784
2786
  handle(element);
2785
2787
  function deepHandle(element2) {
@@ -3568,7 +3570,7 @@ const _copyAs = definePlugin((editor) => {
3568
3570
  selected: true,
3569
3571
  ...options
3570
3572
  });
3571
- const exporter = exporters.value.get(key);
3573
+ const exporter = exporters.get(key);
3572
3574
  if (exporter && typeof exporter.copyAs === "function") {
3573
3575
  res = exporter.copyAs(res);
3574
3576
  }
@@ -3773,6 +3775,7 @@ const aliases = {
3773
3775
  unvisible: "m16.1 13.3l-1.45-1.45q.225-1.175-.675-2.2t-2.325-.8L10.2 7.4q.425-.2.863-.3T12 7q1.875 0 3.188 1.313T16.5 11.5q0 .5-.1.938t-.3.862m3.2 3.15l-1.45-1.4q.95-.725 1.688-1.587T20.8 11.5q-1.25-2.525-3.588-4.012T12 6q-.725 0-1.425.1T9.2 6.4L7.65 4.85q1.025-.425 2.1-.638T12 4q3.775 0 6.725 2.087T23 11.5q-.575 1.475-1.513 2.738T19.3 16.45m.5 6.15l-4.2-4.15q-.875.275-1.762.413T12 19q-3.775 0-6.725-2.087T1 11.5q.525-1.325 1.325-2.463T4.15 7L1.4 4.2l1.4-1.4l18.4 18.4zM5.55 8.4q-.725.65-1.325 1.425T3.2 11.5q1.25 2.525 3.588 4.013T12 17q.5 0 .975-.062t.975-.138l-.9-.95q-.275.075-.525.113T12 16q-1.875 0-3.188-1.312T7.5 11.5q0-.275.038-.525t.112-.525zm4.2 4.2",
3774
3776
  move: "M10.07 14.27a.997.997 0 0 1 1.33.48l2.3 4.99l1.8-.85l-2.31-4.98c-.24-.5-.02-1.1.48-1.33l.28-.08l2.3-.45L8 5.12V15.9l1.82-1.47zm3.57 7.7a.99.99 0 0 1-1.33-.47l-2.18-4.74l-2.51 2.02c-.17.14-.38.22-.62.22a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1c.24 0 .47.09.64.23l.01-.01l11.49 9.64a1.001 1.001 0 0 1-.44 1.75l-3.16.62l2.2 4.73c.26.5.02 1.09-.48 1.32z",
3775
3777
  hand: "M21 7a2.5 2.5 0 0 0-2.5-2.5c-.17 0-.34 0-.5.05V4a2.5 2.5 0 0 0-3.17-2.41A2.51 2.51 0 0 0 12.5 0c-1.23 0-2.25.89-2.46 2.06C9.87 2 9.69 2 9.5 2A2.5 2.5 0 0 0 7 4.5v5.89c-.34-.31-.76-.54-1.22-.66L5 9.5c-.82-.21-1.69.11-2.18.85c-.38.57-.4 1.31-.15 1.95l2.56 6.43A8.36 8.36 0 0 0 13 24c4.42 0 8-3.58 8-8zm-2 9c0 3.31-2.69 6-6 6a6.36 6.36 0 0 1-5.91-4L4.5 11.45l.5.14c.5.12.85.46 1 .91L7 15h2V4.5c0-.28.22-.5.5-.5s.5.22.5.5V12h2V2.5c0-.28.22-.5.5-.5s.5.22.5.5V12h2V4c0-.28.22-.5.5-.5s.5.22.5.5v8h2V7c0-.28.22-.5.5-.5s.5.22.5.5z",
3778
+ pen: "m15.54 3.5l4.96 4.97l-1.43 1.41l-4.95-4.95zM3.5 19.78l6.5-6.47c-.1-.31-.03-.7.23-.96c.39-.39 1.03-.39 1.42 0c.39.4.39 1.03 0 1.42c-.26.26-.65.33-.96.23l-6.47 6.5l10.61-3.55l3.53-6.36l-4.94-4.95l-6.37 3.53z",
3776
3779
  pencil: "m14.06 9l.94.94L5.92 19H5v-.92zm3.6-6c-.25 0-.51.1-.7.29l-1.83 1.83l3.75 3.75l1.83-1.83c.39-.39.39-1.04 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z",
3777
3780
  rectangle: "M4 6v13h16V6zm14 11H6V8h12z",
3778
3781
  line: "M15 3v4.59L7.59 15H3v6h6v-4.58L16.42 9H21V3m-4 2h2v2h-2M5 17h2v2H5",
@@ -4391,8 +4394,14 @@ const _frame = definePlugin((editor) => {
4391
4394
  el.style.backgroundColor = "#ffffff";
4392
4395
  return {
4393
4396
  move: (move) => {
4394
- el.style.width = Math.abs(move.x - start.x);
4395
- el.style.height = Math.abs(move.y - start.y);
4397
+ const minX = Math.min(move.x, start.x);
4398
+ const minY = Math.min(move.y, start.y);
4399
+ const maxX = Math.max(move.x, start.x);
4400
+ const maxY = Math.max(move.y, start.y);
4401
+ el.style.left = minX;
4402
+ el.style.top = minY;
4403
+ el.style.width = maxX - minX;
4404
+ el.style.height = maxY - minY;
4396
4405
  },
4397
4406
  end: () => {
4398
4407
  setActiveDrawingTool(void 0);
@@ -5010,7 +5019,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5010
5019
  }
5011
5020
  });
5012
5021
  const _hoisted_1$k = { class: "mce-layer__name" };
5013
- const _hoisted_2$a = { class: "mce-layer__action" };
5022
+ const _hoisted_2$b = { class: "mce-layer__action" };
5014
5023
  const _sfc_main$w = /* @__PURE__ */ defineComponent({
5015
5024
  ...{
5016
5025
  name: "MceLayer",
@@ -5249,7 +5258,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5249
5258
  style: normalizeStyle({ visibility: editing.value ? "hidden" : void 0 })
5250
5259
  }, toDisplayString(editValue.value || props.node.name || props.node.id), 5)
5251
5260
  ]),
5252
- createElementVNode("div", _hoisted_2$a, [
5261
+ createElementVNode("div", _hoisted_2$b, [
5253
5262
  props.root ? (openBlock(), createBlock(_sfc_main$x, {
5254
5263
  key: 0,
5255
5264
  class: normalizeClass(["mce-layer__btn", {
@@ -5307,7 +5316,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
5307
5316
  }
5308
5317
  });
5309
5318
  const _hoisted_1$j = { class: "mce-layers" };
5310
- const _hoisted_2$9 = { class: "mce-layers__wrapper" };
5319
+ const _hoisted_2$a = { class: "mce-layers__wrapper" };
5311
5320
  const _sfc_main$v = /* @__PURE__ */ defineComponent({
5312
5321
  __name: "Layers",
5313
5322
  setup(__props) {
@@ -5357,7 +5366,7 @@ const _sfc_main$v = /* @__PURE__ */ defineComponent({
5357
5366
  });
5358
5367
  return (_ctx, _cache) => {
5359
5368
  return openBlock(), createElementBlock("div", _hoisted_1$j, [
5360
- createElementVNode("div", _hoisted_2$9, [
5369
+ createElementVNode("div", _hoisted_2$a, [
5361
5370
  createVNode(_sfc_main$w, {
5362
5371
  root: true,
5363
5372
  node: unref(root),
@@ -5548,8 +5557,8 @@ const _sfc_main$t = /* @__PURE__ */ defineComponent({
5548
5557
  }
5549
5558
  });
5550
5559
  const _hoisted_1$h = ["onMouseenter"];
5551
- const _hoisted_2$8 = ["onClick"];
5552
- const _hoisted_3$8 = {
5560
+ const _hoisted_2$9 = ["onClick"];
5561
+ const _hoisted_3$9 = {
5553
5562
  key: 0,
5554
5563
  class: "mce-list-item__checked"
5555
5564
  };
@@ -5693,7 +5702,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5693
5702
  ]]),
5694
5703
  onClick: (e) => onClickItem(item, index, e)
5695
5704
  }, [
5696
- hasPrepend.value ? (openBlock(), createElementBlock("div", _hoisted_3$8, [
5705
+ hasPrepend.value ? (openBlock(), createElementBlock("div", _hoisted_3$9, [
5697
5706
  item.checked ? (openBlock(), createBlock(unref(_sfc_main$B), {
5698
5707
  key: 0,
5699
5708
  icon: "$check"
@@ -5717,7 +5726,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5717
5726
  icon: "$arrowRight"
5718
5727
  })) : createCommentVNode("", true)
5719
5728
  ])) : createCommentVNode("", true)
5720
- ], 10, _hoisted_2$8)
5729
+ ], 10, _hoisted_2$9)
5721
5730
  ], 40, _hoisted_1$h))
5722
5731
  ], 64);
5723
5732
  }), 128)),
@@ -5870,7 +5879,7 @@ const _menu = definePlugin((editor, options) => {
5870
5879
  const hasSelected = computed(() => selection.value.length > 0);
5871
5880
  const exportMenu = computed(() => ({
5872
5881
  key: "export",
5873
- children: [...exporters.value.values()].filter((v) => Boolean(v.saveAs)).map((v) => ({ key: `saveAs:${v.name}` }))
5882
+ children: [...exporters.values()].filter((v) => Boolean(v.saveAs)).map((v) => ({ key: `saveAs:${v.name}` }))
5874
5883
  }));
5875
5884
  const fileMenu = computed(() => ({
5876
5885
  key: "file",
@@ -5889,7 +5898,7 @@ const _menu = definePlugin((editor, options) => {
5889
5898
  const copyAsMenu = computed(() => ({
5890
5899
  key: "copyAs",
5891
5900
  disabled: !hasSelected.value,
5892
- children: [...exporters.value.values()].filter((v) => Boolean(v.copyAs)).map((v) => ({ key: `copyAs:${v.name}` }))
5901
+ children: [...exporters.values()].filter((v) => Boolean(v.copyAs)).map((v) => ({ key: `copyAs:${v.name}` }))
5893
5902
  }));
5894
5903
  const editMenus1 = computed(() => [
5895
5904
  { key: "copy", disabled: !hasSelected.value },
@@ -8272,7 +8281,7 @@ function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
8272
8281
  }
8273
8282
  class Curve {
8274
8283
  arcLengthDivision = 200;
8275
- _arcLengths;
8284
+ _lengths = [];
8276
8285
  getPointAt(u, output = new Vector2()) {
8277
8286
  return this.getPoint(this.getUToTMapping(u), output);
8278
8287
  }
@@ -8350,10 +8359,10 @@ class Curve {
8350
8359
  return lengths[lengths.length - 1];
8351
8360
  }
8352
8361
  getLengths() {
8353
- if (!this._arcLengths || this._arcLengths.length !== this.arcLengthDivision + 1) {
8362
+ if (this._lengths.length !== this.arcLengthDivision + 1) {
8354
8363
  this.updateLengths();
8355
8364
  }
8356
- return this._arcLengths;
8365
+ return this._lengths;
8357
8366
  }
8358
8367
  updateLengths() {
8359
8368
  const divisions = this.arcLengthDivision;
@@ -8364,7 +8373,7 @@ class Curve {
8364
8373
  arcLengths.push(sum);
8365
8374
  prev = current;
8366
8375
  }
8367
- this._arcLengths = arcLengths;
8376
+ this._lengths = arcLengths;
8368
8377
  }
8369
8378
  getUToTMapping(u, distance2) {
8370
8379
  const lengths = this.getLengths();
@@ -8389,14 +8398,14 @@ class Curve {
8389
8398
  break;
8390
8399
  }
8391
8400
  }
8392
- i = high;
8401
+ i = Math.max(0, high);
8393
8402
  if (lengths[i] === targetLen) {
8394
8403
  return i / (lengthsLen - 1);
8395
8404
  }
8396
8405
  const before = lengths[i];
8397
8406
  const after = lengths[i + 1];
8398
8407
  const segmentLength = after - before;
8399
- const segmentFraction = (targetLen - before) / segmentLength;
8408
+ const segmentFraction = Math.max(0, (targetLen - before) / segmentLength);
8400
8409
  return (i + segmentFraction) / (lengthsLen - 1);
8401
8410
  }
8402
8411
  getTangent(t, output = new Vector2()) {
@@ -9058,13 +9067,19 @@ class CompositeCurve extends Curve {
9058
9067
  }
9059
9068
  return output;
9060
9069
  }
9070
+ getLengths() {
9071
+ if (this._lengths.length !== this.curves.length) {
9072
+ this.updateLengths();
9073
+ }
9074
+ return this._lengths;
9075
+ }
9061
9076
  updateLengths() {
9062
- const arcLengths = [];
9077
+ const lengths = [];
9063
9078
  for (let i = 0, sum = 0, len = this.curves.length; i < len; i++) {
9064
9079
  sum += this.curves[i].getLength();
9065
- arcLengths.push(sum);
9080
+ lengths.push(sum);
9066
9081
  }
9067
- this._arcLengths = arcLengths;
9082
+ this._lengths = lengths;
9068
9083
  }
9069
9084
  getControlPointRefs() {
9070
9085
  return this.curves.flatMap((curve) => curve.getControlPointRefs());
@@ -9736,9 +9751,11 @@ class Path2D extends CompositeCurve {
9736
9751
  return this;
9737
9752
  }
9738
9753
  addPath(path) {
9739
- const index = this.curves.findIndex((v) => v === this.currentCurve);
9740
- if (index > -1) {
9741
- this.curves.splice(index, 1);
9754
+ if (!this.currentCurve.curves.length) {
9755
+ const index = this.curves.findIndex((v) => v === this.currentCurve);
9756
+ if (index > -1) {
9757
+ this.curves.splice(index, 1);
9758
+ }
9742
9759
  }
9743
9760
  if (path instanceof Path2D) {
9744
9761
  this.curves.push(
@@ -9747,17 +9764,15 @@ class Path2D extends CompositeCurve {
9747
9764
  } else if (path.curves.length) {
9748
9765
  this.curves.push(path);
9749
9766
  }
9750
- this.curves.push(this.currentCurve);
9767
+ this.currentCurve = this.curves[this.curves.length - 1];
9751
9768
  return this;
9752
9769
  }
9753
9770
  closePath() {
9754
9771
  const startPoint = this.startPoint;
9755
- if (startPoint) {
9772
+ if (startPoint && this.currentCurve.curves.length) {
9756
9773
  this.currentCurve.closePath();
9757
- if (this.currentCurve.curves.length) {
9758
- this.currentCurve = new CurvePath().moveTo(startPoint.x, startPoint.y);
9759
- this.curves.push(this.currentCurve);
9760
- }
9774
+ this.currentCurve = new CurvePath().moveTo(startPoint.x, startPoint.y);
9775
+ this.curves.push(this.currentCurve);
9761
9776
  }
9762
9777
  return this;
9763
9778
  }
@@ -10070,15 +10085,86 @@ class Path2D extends CompositeCurve {
10070
10085
  }
10071
10086
  const _pen = definePlugin((editor) => {
10072
10087
  const {
10073
- addElement
10088
+ addElement,
10089
+ renderEngine,
10090
+ activeDrawingTool,
10091
+ getGlobalPointer,
10092
+ state
10074
10093
  } = editor;
10094
+ let el;
10095
+ let currentPath;
10096
+ let currentLine;
10097
+ const update = () => {
10098
+ if (el && currentPath) {
10099
+ el.shape.paths = [
10100
+ { data: currentPath.toData() }
10101
+ ];
10102
+ const box = currentPath.getBoundingBox();
10103
+ el.style.left = box.left;
10104
+ el.style.top = box.top;
10105
+ el.style.width = box.width;
10106
+ el.style.height = box.height;
10107
+ }
10108
+ };
10075
10109
  return {
10076
10110
  name: "mce:pen",
10077
10111
  drawingTools: [
10112
+ {
10113
+ name: "pen",
10114
+ handle: (start) => {
10115
+ if (el) {
10116
+ if (currentPath) {
10117
+ currentLine = new LineCurve(
10118
+ new Vector2(start.x, start.y),
10119
+ new Vector2(start.x, start.y)
10120
+ );
10121
+ currentPath.currentCurve.addCurve(currentLine);
10122
+ update();
10123
+ }
10124
+ } else {
10125
+ el = addElement({
10126
+ name: "pen",
10127
+ outline: {
10128
+ color: "#d9d9d9",
10129
+ width: 5,
10130
+ lineCap: "round",
10131
+ lineJoin: "round"
10132
+ },
10133
+ meta: {
10134
+ inPptIs: "Shape"
10135
+ }
10136
+ }, {
10137
+ position: start
10138
+ });
10139
+ currentPath = new Path2D();
10140
+ currentLine = new LineCurve(
10141
+ new Vector2(start.x, start.y),
10142
+ new Vector2(start.x, start.y)
10143
+ );
10144
+ currentPath.currentCurve.addCurve(currentLine);
10145
+ const onMove = () => {
10146
+ const move = getGlobalPointer();
10147
+ if (currentLine && move) {
10148
+ currentLine.p2.x = move.x;
10149
+ currentLine.p2.y = move.y;
10150
+ update();
10151
+ }
10152
+ };
10153
+ renderEngine.value.on("pointermove", onMove);
10154
+ const stop = watch([state, activeDrawingTool], () => {
10155
+ renderEngine.value.off("pointermove", onMove);
10156
+ stop();
10157
+ el = void 0;
10158
+ currentPath = void 0;
10159
+ currentLine = void 0;
10160
+ });
10161
+ }
10162
+ }
10163
+ },
10078
10164
  {
10079
10165
  name: "pencil",
10080
10166
  handle: (start) => {
10081
- const el = addElement({
10167
+ const el2 = addElement({
10082
10168
  name: "pencil",
10083
10169
  outline: {
10084
10170
  color: "#d9d9d9",
@@ -10098,29 +10184,33 @@ const _pen = definePlugin((editor) => {
10098
10184
  move: (move) => {
10099
10185
  path.lineTo(move.x, move.y);
10100
10186
  path.moveTo(move.x, move.y);
10101
- el.shape.paths = [
10187
+ el2.shape.paths = [
10102
10188
  { data: path.toData() }
10103
10189
  ];
10104
10190
  const box = path.getBoundingBox();
10105
- el.style.left = box.left;
10106
- el.style.top = box.top;
10107
- el.style.width = box.width;
10108
- el.style.height = box.height;
10109
- },
10110
- end: () => {
10191
+ el2.style.left = box.left;
10192
+ el2.style.top = box.top;
10193
+ el2.style.width = box.width;
10194
+ el2.style.height = box.height;
10111
10195
  }
10112
10196
  };
10113
10197
  }
10114
10198
  }
10115
10199
  ],
10116
10200
  hotkeys: [
10201
+ { command: "setActiveDrawingTool:pen", key: "p" },
10117
10202
  { command: "setActiveDrawingTool:pencil", key: "Shift+p" }
10118
10203
  ]
10119
10204
  };
10120
10205
  });
10121
10206
  const _hoisted_1$g = {
10122
10207
  key: 0,
10123
- class: "mce-tooltip__content"
10208
+ class: "mce-tooltip__arrow"
10209
+ };
10210
+ const _hoisted_2$8 = { class: "mce-tooltip__content" };
10211
+ const _hoisted_3$8 = {
10212
+ key: 0,
10213
+ class: "mce-tooltip__kbd"
10124
10214
  };
10125
10215
  const _sfc_main$q = /* @__PURE__ */ defineComponent({
10126
10216
  __name: "Tooltip",
@@ -10128,7 +10218,8 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10128
10218
  ...makeMceOverlayProps({
10129
10219
  location: "right",
10130
10220
  offset: 8
10131
- })
10221
+ }),
10222
+ showArrow: Boolean
10132
10223
  }, {
10133
10224
  "modelValue": { type: Boolean },
10134
10225
  "modelModifiers": {}
@@ -10138,6 +10229,13 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10138
10229
  const props = __props;
10139
10230
  const isActive = useModel(__props, "modelValue");
10140
10231
  const overlay = useTemplateRef("overlayTpl");
10232
+ const classes = computed(() => {
10233
+ const [side, align = "center"] = props.location.split("-");
10234
+ return [
10235
+ `mce-tooltip--side-${side}`,
10236
+ `mce-tooltip--align-${align}`
10237
+ ];
10238
+ });
10141
10239
  function updateLocation() {
10142
10240
  overlay.value?.updateLocation();
10143
10241
  }
@@ -10149,16 +10247,22 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10149
10247
  ref: "overlayTpl",
10150
10248
  modelValue: isActive.value,
10151
10249
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => isActive.value = $event),
10152
- class: "mce-tooltip",
10250
+ class: normalizeClass(["mce-tooltip", classes.value]),
10153
10251
  location: props.location,
10154
10252
  offset: props.offset,
10155
10253
  target: props.target,
10156
10254
  attach: props.attach
10157
10255
  }, createSlots({
10158
10256
  default: withCtx(() => [
10159
- isActive.value ? (openBlock(), createElementBlock("div", _hoisted_1$g, [
10160
- renderSlot(_ctx.$slots, "default")
10161
- ])) : createCommentVNode("", true)
10257
+ isActive.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
10258
+ __props.showArrow ? (openBlock(), createElementBlock("div", _hoisted_1$g)) : createCommentVNode("", true),
10259
+ createElementVNode("div", _hoisted_2$8, [
10260
+ renderSlot(_ctx.$slots, "default"),
10261
+ _ctx.$slots.kbd ? (openBlock(), createElementBlock("div", _hoisted_3$8, [
10262
+ renderSlot(_ctx.$slots, "kbd")
10263
+ ])) : createCommentVNode("", true)
10264
+ ])
10265
+ ], 64)) : createCommentVNode("", true)
10162
10266
  ]),
10163
10267
  _: 2
10164
10268
  }, [
@@ -10175,13 +10279,13 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10175
10279
  ]),
10176
10280
  key: "0"
10177
10281
  } : void 0
10178
- ]), 1032, ["modelValue", "location", "offset", "target", "attach"]);
10282
+ ]), 1032, ["modelValue", "class", "location", "offset", "target", "attach"]);
10179
10283
  };
10180
10284
  }
10181
10285
  });
10182
10286
  const _hoisted_1$f = ["width", "height"];
10183
10287
  const _hoisted_2$7 = ["onDblclick", "onMousedown", "onMousemove"];
10184
- const _hoisted_3$7 = { style: { "font-size": "12px", "text-wrap": "nowrap" } };
10288
+ const _hoisted_3$7 = { style: { "font-size": "0.75rem", "text-wrap": "nowrap" } };
10185
10289
  const _sfc_main$p = /* @__PURE__ */ defineComponent({
10186
10290
  ...{
10187
10291
  inheritAttrs: false
@@ -10543,7 +10647,7 @@ const _saveAs = definePlugin((editor) => {
10543
10647
  selected: true,
10544
10648
  ...restOptions
10545
10649
  });
10546
- const exporter = exporters.value.get(key);
10650
+ const exporter = exporters.get(key);
10547
10651
  if (exporter && typeof exporter.saveAs === "function") {
10548
10652
  res = exporter.saveAs(res);
10549
10653
  }
@@ -10866,8 +10970,14 @@ const _shape = definePlugin((editor) => {
10866
10970
  });
10867
10971
  return {
10868
10972
  move: (move) => {
10869
- el.style.width = Math.abs(move.x - start.x);
10870
- el.style.height = Math.abs(move.y - start.y);
10973
+ const minX = Math.min(move.x, start.x);
10974
+ const minY = Math.min(move.y, start.y);
10975
+ const maxX = Math.max(move.x, start.x);
10976
+ const maxY = Math.max(move.y, start.y);
10977
+ el.style.left = minX;
10978
+ el.style.top = minY;
10979
+ el.style.width = maxX - minX;
10980
+ el.style.height = maxY - minY;
10871
10981
  },
10872
10982
  end: () => {
10873
10983
  setActiveDrawingTool(void 0);
@@ -12358,7 +12468,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
12358
12468
  };
12359
12469
  }
12360
12470
  });
12361
- const ProgressIndicator = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-c4234331"]]);
12471
+ const ProgressIndicator = /* @__PURE__ */ _export_sfc(_sfc_main$j, [["__scopeId", "data-v-3b286483"]]);
12362
12472
  const _hoisted_1$a = { class: "mce-statusbar" };
12363
12473
  const _hoisted_2$5 = { class: "mce-statusbar__main" };
12364
12474
  const _hoisted_3$5 = { class: "mce-statusbar__item" };
@@ -12456,7 +12566,7 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
12456
12566
  };
12457
12567
  }
12458
12568
  });
12459
- const Statusbar = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["__scopeId", "data-v-51df67c3"]]);
12569
+ const Statusbar = /* @__PURE__ */ _export_sfc(_sfc_main$i, [["__scopeId", "data-v-a57093aa"]]);
12460
12570
  const _statusbar = definePlugin((editor) => {
12461
12571
  const {
12462
12572
  registerConfig
@@ -12840,14 +12950,8 @@ const _timeline = definePlugin((editor) => {
12840
12950
  };
12841
12951
  });
12842
12952
  const _hoisted_1$5 = { class: "mce-toolbelt" };
12843
- const _hoisted_2$2 = {
12844
- key: 0,
12845
- class: "mce-toolbelt__kbd"
12846
- };
12847
- const _hoisted_3$2 = {
12848
- key: 1,
12849
- class: "mce-toolbelt__kbd"
12850
- };
12953
+ const _hoisted_2$2 = { key: 0 };
12954
+ const _hoisted_3$2 = { key: 1 };
12851
12955
  const _sfc_main$c = /* @__PURE__ */ defineComponent({
12852
12956
  __name: "Toolbelt",
12853
12957
  setup(__props) {
@@ -12859,9 +12963,10 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12859
12963
  hotkeys,
12860
12964
  getKbd
12861
12965
  } = useEditor();
12862
- const activeShapeIndex = ref(0);
12966
+ const activeShape = ref(0);
12967
+ const activePen = ref(0);
12863
12968
  const shapeItems = computed(() => {
12864
- const shapes = [
12969
+ const keys = [
12865
12970
  "rectangle",
12866
12971
  "line",
12867
12972
  "arrow",
@@ -12870,11 +12975,11 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12870
12975
  "star"
12871
12976
  ];
12872
12977
  return [
12873
- ...shapes.map((key, index) => {
12978
+ ...keys.map((key, index) => {
12874
12979
  return {
12875
12980
  key,
12876
12981
  handle: () => {
12877
- activeShapeIndex.value = index;
12982
+ activeShape.value = index;
12878
12983
  setActiveDrawingTool(key);
12879
12984
  },
12880
12985
  checked: activeDrawingTool.value?.name === key
@@ -12887,6 +12992,24 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12887
12992
  }
12888
12993
  ];
12889
12994
  });
12995
+ const penItems = computed(() => {
12996
+ const keys = [
12997
+ "pen",
12998
+ "pencil"
12999
+ ];
13000
+ return [
13001
+ ...keys.map((key, index) => {
13002
+ return {
13003
+ key,
13004
+ handle: () => {
13005
+ activePen.value = index;
13006
+ setActiveDrawingTool(key);
13007
+ },
13008
+ checked: activeDrawingTool.value?.name === key
13009
+ };
13010
+ })
13011
+ ];
13012
+ });
12890
13013
  const items = computed(() => {
12891
13014
  return [
12892
13015
  {
@@ -12909,7 +13032,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12909
13032
  handle: () => setActiveDrawingTool("frame")
12910
13033
  },
12911
13034
  {
12912
- ...shapeItems.value.find((v) => v.checked) ?? shapeItems.value[0],
13035
+ ...shapeItems.value.find((v) => v.checked) ?? shapeItems.value[activeShape.value],
12913
13036
  children: shapeItems.value
12914
13037
  },
12915
13038
  {
@@ -12918,9 +13041,8 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12918
13041
  handle: () => setActiveDrawingTool("text")
12919
13042
  },
12920
13043
  {
12921
- key: "pencil",
12922
- active: activeDrawingTool.value?.name === "pencil",
12923
- handle: () => setActiveDrawingTool("pencil")
13044
+ ...penItems.value.find((v) => v.checked) ?? penItems.value[activePen.value],
13045
+ children: penItems.value
12924
13046
  }
12925
13047
  ];
12926
13048
  });
@@ -12931,7 +13053,11 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12931
13053
  key,
12932
13054
  class: "mce-toolbelt__group"
12933
13055
  }, [
12934
- createVNode(_sfc_main$q, { location: "top" }, {
13056
+ createVNode(_sfc_main$q, {
13057
+ location: "top",
13058
+ offset: 12,
13059
+ "show-arrow": ""
13060
+ }, {
12935
13061
  activator: withCtx(({ props: slotProps }) => [
12936
13062
  createVNode(_sfc_main$x, mergeProps({
12937
13063
  class: "mce-toolbelt__btn",
@@ -12948,7 +13074,9 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
12948
13074
  }, 1040, ["active", "onClick"])
12949
13075
  ]),
12950
13076
  default: withCtx(() => [
12951
- createElementVNode("span", null, toDisplayString(unref(t)(tool.key)), 1),
13077
+ createElementVNode("span", null, toDisplayString(unref(t)(tool.key)), 1)
13078
+ ]),
13079
+ kbd: withCtx(() => [
12952
13080
  unref(hotkeys).has(`setState:${tool.key}`) ? (openBlock(), createElementBlock("span", _hoisted_2$2, toDisplayString(unref(getKbd)(`setState:${tool.key}`)), 1)) : unref(hotkeys).has(`setActiveDrawingTool:${tool.key}`) ? (openBlock(), createElementBlock("span", _hoisted_3$2, toDisplayString(unref(getKbd)(`setActiveDrawingTool:${tool.key}`)), 1)) : createCommentVNode("", true)
12953
13081
  ]),
12954
13082
  _: 2
@@ -15031,7 +15159,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15031
15159
  return (_ctx, _cache) => {
15032
15160
  return openBlock(), createBlock(_sfc_main$5, {
15033
15161
  class: normalizeClass(["mce-editor", [
15034
- `mce-editor--${unref(state)}`,
15162
+ unref(state) && `mce-editor--${unref(state)}`,
15163
+ unref(activeDrawingTool) && `mce-editor--drawing-tool-${unref(activeDrawingTool).name}`,
15035
15164
  grabbing.value && `mce-editor--grabbing`
15036
15165
  ]])
15037
15166
  }, {