mce 0.17.8 → 0.17.10

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.
@@ -13,6 +13,7 @@ type __VLS_Props = {
13
13
  borderColor?: string;
14
14
  textColor?: string;
15
15
  lineColor?: string;
16
+ boxColor?: string;
16
17
  locked?: boolean;
17
18
  labelFormat?: (tick: number) => string;
18
19
  };
package/dist/index.js CHANGED
@@ -3454,6 +3454,9 @@ const _edit = definePlugin((editor, options) => {
3454
3454
  let html = "";
3455
3455
  if (!source) {
3456
3456
  const selected = selection.value;
3457
+ if (!selected.length) {
3458
+ return;
3459
+ }
3457
3460
  html += `<mce-clipboard>${JSON.stringify(selected.map((v) => {
3458
3461
  const json = v.toJSON();
3459
3462
  if (json.style) {
@@ -3489,7 +3492,11 @@ const _edit = definePlugin((editor, options) => {
3489
3492
  ]);
3490
3493
  } else {
3491
3494
  if (source === void 0) {
3492
- source = selection.value.map((v) => {
3495
+ const selected = selection.value;
3496
+ if (!selected.length) {
3497
+ return;
3498
+ }
3499
+ source = selected.map((v) => {
3493
3500
  const json = v.toJSON();
3494
3501
  delete json.style.left;
3495
3502
  delete json.style.top;
@@ -3652,7 +3659,7 @@ const _edit = definePlugin((editor, options) => {
3652
3659
  hotkeys: [
3653
3660
  { command: "cancel", key: "escape", editable: false },
3654
3661
  { command: "delete", key: ["Backspace", "Delete"], when: () => Boolean(selection.value.length > 0) },
3655
- { command: "copy", key: "CmdOrCtrl+C", editable: false },
3662
+ { command: "copy", key: "CmdOrCtrl+C", editable: false, preventDefault: false },
3656
3663
  { command: "cut", key: "CmdOrCtrl+X", editable: false },
3657
3664
  { command: "paste", key: "CmdOrCtrl+V", editable: false, preventDefault: false },
3658
3665
  { command: "duplicate", key: "CmdOrCtrl+D", editable: false }
@@ -10563,6 +10570,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
10563
10570
  borderColor: {},
10564
10571
  textColor: {},
10565
10572
  lineColor: {},
10573
+ boxColor: {},
10566
10574
  locked: { type: Boolean },
10567
10575
  labelFormat: { type: Function, default: (tick) => String(tick) }
10568
10576
  }, {
@@ -10582,15 +10590,17 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
10582
10590
  const box = ref();
10583
10591
  const colors = reactive({
10584
10592
  text: "#000",
10585
- border: "#000"
10593
+ border: "#000",
10594
+ box: "#0000002E"
10586
10595
  });
10587
10596
  const borderColor = computed(() => props.borderColor ?? colors.border);
10588
10597
  const textColor = computed(() => props.textColor ?? colors.text);
10589
10598
  const lineColor = computed(() => props.lineColor ?? "rgb(var(--m-theme-secondary))");
10599
+ const boxColor = computed(() => props.boxColor ?? colors.box);
10590
10600
  function drawSelected() {
10591
10601
  if (!props.selected?.width || !props.selected?.height)
10592
10602
  return;
10593
- ctx.fillStyle = "#6165FD20";
10603
+ ctx.fillStyle = boxColor.value;
10594
10604
  const offset2 = props.vertical ? props.selected.top : props.selected.left;
10595
10605
  const length = props.vertical ? props.selected.height : props.selected.width;
10596
10606
  ctx.fillRect(offset2, 0, length, props.size);
@@ -10739,6 +10749,7 @@ const _sfc_main$r = /* @__PURE__ */ defineComponent({
10739
10749
  const style = window.getComputedStyle(dom);
10740
10750
  colors.text = style.getPropertyValue("--text-color").trim();
10741
10751
  colors.border = style.getPropertyValue("--border-color").trim();
10752
+ colors.box = `rgba(${style.getPropertyValue("--m-theme-primary").trim()}, 0.18)`;
10742
10753
  }
10743
10754
  });
10744
10755
  onBeforeUnmount(() => {
@@ -10899,8 +10910,9 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10899
10910
  axis: "",
10900
10911
  size: 16,
10901
10912
  "line-color": unref(config).lineColor,
10913
+ "box-color": unref(config).boxColor,
10902
10914
  locked: unref(config).locked
10903
- }, null, 8, ["modelValue", "zoom", "position", "selected", "line-color", "locked"]),
10915
+ }, null, 8, ["modelValue", "zoom", "position", "selected", "line-color", "box-color", "locked"]),
10904
10916
  createVNode(_sfc_main$r, {
10905
10917
  modelValue: refLines.value.y,
10906
10918
  "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => refLines.value.y = $event),
@@ -10912,8 +10924,9 @@ const _sfc_main$q = /* @__PURE__ */ defineComponent({
10912
10924
  vertical: "",
10913
10925
  size: 16,
10914
10926
  "line-color": unref(config).lineColor,
10927
+ "box-color": unref(config).boxColor,
10915
10928
  locked: unref(config).locked
10916
- }, null, 8, ["modelValue", "zoom", "position", "selected", "line-color", "locked"]),
10929
+ }, null, 8, ["modelValue", "zoom", "position", "selected", "line-color", "box-color", "locked"]),
10917
10930
  _cache[2] || (_cache[2] = createElementVNode("div", { class: "m-rulers__left-top" }, null, -1))
10918
10931
  ]);
10919
10932
  };
@@ -11611,7 +11624,6 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
11611
11624
  }
11612
11625
  const handleObj = index === void 0 ? { type: "move", x: 0, y: 0, width: 0, height: 0 } : computedHandles.value[index];
11613
11626
  const handle = handleObj.type;
11614
- activeHandle.value = handle;
11615
11627
  const handleArr = handle.split("-");
11616
11628
  const last = handleArr.length > 1 ? handleArr.pop() || "" : "";
11617
11629
  const key = handleArr.join("-");
@@ -11649,6 +11661,7 @@ const _sfc_main$m = /* @__PURE__ */ defineComponent({
11649
11661
  threshold: props.threshold,
11650
11662
  start: (ctx) => {
11651
11663
  transforming.value = true;
11664
+ activeHandle.value = handle;
11652
11665
  ctx.handle = handle;
11653
11666
  ctx.value = ctx.oldValue = getRawModel();
11654
11667
  emit("start", ctx);
@@ -17904,7 +17917,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17904
17917
  bind();
17905
17918
  return unbind;
17906
17919
  }
17907
- function onHover(event) {
17920
+ function onEnginePointerHover(event) {
17908
17921
  let cursor;
17909
17922
  let hovered;
17910
17923
  if (elementSelection.value.length > 1 && selectionAabbInDrawboard.value.contains({
@@ -17933,8 +17946,17 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17933
17946
  hoverElement.value = hovered;
17934
17947
  setCursor(cursor);
17935
17948
  }
17949
+ let _lastClickTime = 0;
17950
+ let _lastClickPos = { x: 0, y: 0 };
17936
17951
  function onEnginePointerDown(downEvent, options = {}) {
17937
- if (downEvent.srcElement && downEvent.srcElement !== drawboardDom.value && downEvent.srcElement.dataset?.pointerdown_to_drawboard === void 0 || camera.value.spaceKey || ![0, 2].includes(downEvent.button)) {
17952
+ const {
17953
+ srcElement,
17954
+ button,
17955
+ target: element,
17956
+ clientX,
17957
+ clientY
17958
+ } = downEvent;
17959
+ if (srcElement && srcElement !== drawboardDom.value && srcElement.dataset?.pointerdown_to_drawboard === void 0 || camera.value.spaceKey || ![0, 2].includes(button)) {
17938
17960
  return;
17939
17961
  }
17940
17962
  const {
@@ -17943,22 +17965,16 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17943
17965
  function isIncluded(node) {
17944
17966
  return isElement(node) && !isLock(node) && (allowTopFrame || (!node.children.some((node2) => isElement(node2)) || !isFrameNode(node, true))) && !node.findAncestor((ancestor) => isLock(ancestor));
17945
17967
  }
17946
- const drawing = state.value === "drawing";
17947
- const hand = state.value === "hand";
17948
- const element = downEvent.target;
17949
- const start = { x: downEvent.clientX, y: downEvent.clientY };
17950
- let current = { ...start };
17951
- let prev = { ...current };
17952
- let dragging = false;
17953
- let selecting = false;
17954
- let isUp = false;
17968
+ const downState = state.value;
17969
+ const startPos = { x: clientX, y: clientY };
17970
+ let currentPos = { ...startPos };
17971
+ let prevPos = { ...currentPos };
17955
17972
  let selected = [];
17956
- let ctxState;
17957
17973
  const inSelection = allowTopFrame && elementSelection.value.some((node) => node.equal(element)) || selectionAabbInDrawboard.value.contains({
17958
- x: start.x - drawboardAabb.value.left,
17959
- y: start.y - drawboardAabb.value.top
17974
+ x: startPos.x - drawboardAabb.value.left,
17975
+ y: startPos.y - drawboardAabb.value.top
17960
17976
  });
17961
- if (downEvent.button === 2) {
17977
+ if (button === 2) {
17962
17978
  if (!inSelection) {
17963
17979
  const result = props.activeStrategy({
17964
17980
  element,
@@ -17974,16 +17990,35 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
17974
17990
  }
17975
17991
  return;
17976
17992
  }
17993
+ const now = Date.now();
17994
+ let dragging = false;
17995
+ let selecting = false;
17996
+ let isUp = false;
17997
+ let ctxState;
17998
+ const _dx = Math.abs(currentPos.x - _lastClickPos.x);
17999
+ const _dy = Math.abs(currentPos.y - _lastClickPos.y);
18000
+ const isDoubleClick = now - _lastClickTime < 300 && _dx < 5 && _dy < 5;
18001
+ if (isDoubleClick) {
18002
+ _lastClickTime = 0;
18003
+ props.doubleclickStrategy({ event: downEvent, editor });
18004
+ return;
18005
+ } else {
18006
+ _lastClickTime = now;
18007
+ _lastClickPos = { ...currentPos };
18008
+ }
17977
18009
  let drawingTool;
17978
- if (drawing) {
17979
- drawingTool = activeTool.value?.handle?.(
17980
- camera.value.toGlobal({
17981
- x: current.x - drawboardAabb.value.left,
17982
- y: current.y - drawboardAabb.value.top
17983
- })
17984
- );
17985
- } else if (hand) {
17986
- grabbing.value = true;
18010
+ switch (downState) {
18011
+ case "drawing":
18012
+ drawingTool = activeTool.value?.handle?.(
18013
+ camera.value.toGlobal({
18014
+ x: currentPos.x - drawboardAabb.value.left,
18015
+ y: currentPos.y - drawboardAabb.value.top
18016
+ })
18017
+ );
18018
+ break;
18019
+ case "hand":
18020
+ grabbing.value = true;
18021
+ break;
17987
18022
  }
17988
18023
  function onDrag(event) {
17989
18024
  const result = props.activeStrategy({
@@ -18000,13 +18035,13 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
18000
18035
  }
18001
18036
  function onSelectArea() {
18002
18037
  selecting = true;
18003
- if (state.value !== "painting" && state.value !== "selecting") {
18038
+ if (downState !== "painting" && downState !== "selecting") {
18004
18039
  state.value = "selecting";
18005
18040
  }
18006
- selectionMarquee.value.x = Math.min(start.x, current.x) - drawboardAabb.value.left;
18007
- selectionMarquee.value.y = Math.min(start.y, current.y) - drawboardAabb.value.top;
18008
- selectionMarquee.value.width = Math.abs(start.x - current.x);
18009
- selectionMarquee.value.height = Math.abs(start.y - current.y);
18041
+ selectionMarquee.value.x = Math.min(startPos.x, currentPos.x) - drawboardAabb.value.left;
18042
+ selectionMarquee.value.y = Math.min(startPos.y, currentPos.y) - drawboardAabb.value.top;
18043
+ selectionMarquee.value.width = Math.abs(startPos.x - currentPos.x);
18044
+ selectionMarquee.value.height = Math.abs(startPos.y - currentPos.y);
18010
18045
  exec("marqueeSelect");
18011
18046
  selected = elementSelection.value;
18012
18047
  }
@@ -18037,93 +18072,115 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
18037
18072
  }
18038
18073
  }
18039
18074
  function canStartDrag() {
18040
- return !dragging && state.value !== "painting" && (Math.abs(current.x - start.x) >= 3 || Math.abs(current.y - start.y) >= 3);
18075
+ return !dragging && downState !== "painting" && (Math.abs(currentPos.x - startPos.x) >= 3 || Math.abs(currentPos.y - startPos.y) >= 3);
18041
18076
  }
18042
18077
  function _onEnginePointerMove(moveEvent) {
18043
- if (drawing || hand) ;
18044
- else {
18045
- if (inSelection) {
18046
- if (canStartDrag()) {
18047
- dragging = true;
18048
- exec("startTransform", downEvent);
18049
- }
18050
- } else {
18051
- if (element) {
18078
+ switch (downState) {
18079
+ case "drawing":
18080
+ case "hand":
18081
+ break;
18082
+ default:
18083
+ if (inSelection) {
18052
18084
  if (canStartDrag()) {
18053
18085
  dragging = true;
18054
- onDrag(moveEvent);
18055
- nextTick(() => {
18056
- if (!isUp) {
18057
- exec("startTransform", downEvent);
18058
- }
18059
- });
18086
+ exec("startTransform", downEvent);
18087
+ }
18088
+ } else {
18089
+ if (element) {
18090
+ if (canStartDrag()) {
18091
+ dragging = true;
18092
+ onDrag(moveEvent);
18093
+ nextTick(() => {
18094
+ if (!isUp) {
18095
+ exec("startTransform", downEvent);
18096
+ }
18097
+ });
18098
+ }
18060
18099
  }
18061
18100
  }
18062
- }
18101
+ break;
18063
18102
  }
18064
18103
  }
18065
18104
  function _onPointerMove(moveEvent) {
18066
- current = { x: moveEvent.clientX, y: moveEvent.clientY };
18067
- if (drawing) {
18068
- drawingTool?.move?.(
18069
- camera.value.toGlobal({
18070
- x: current.x - drawboardAabb.value.left,
18071
- y: current.y - drawboardAabb.value.top
18072
- })
18073
- );
18074
- } else if (hand) {
18075
- camera.value.position.add({
18076
- x: Math.round(prev.x - current.x),
18077
- y: Math.round(prev.y - current.y)
18078
- });
18079
- } else {
18080
- if (!inSelection) {
18081
- if (!isIncluded(element)) {
18082
- onSelectArea();
18105
+ currentPos = { x: moveEvent.clientX, y: moveEvent.clientY };
18106
+ switch (downState) {
18107
+ case "drawing":
18108
+ drawingTool?.move?.(
18109
+ camera.value.toGlobal({
18110
+ x: currentPos.x - drawboardAabb.value.left,
18111
+ y: currentPos.y - drawboardAabb.value.top
18112
+ })
18113
+ );
18114
+ break;
18115
+ case "hand":
18116
+ camera.value.position.add({
18117
+ x: Math.round(prevPos.x - currentPos.x),
18118
+ y: Math.round(prevPos.y - currentPos.y)
18119
+ });
18120
+ break;
18121
+ default:
18122
+ if (!inSelection) {
18123
+ if (!isIncluded(element)) {
18124
+ onSelectArea();
18125
+ }
18083
18126
  }
18084
- }
18127
+ break;
18085
18128
  }
18086
- prev = { ...current };
18129
+ prevPos = { ...currentPos };
18087
18130
  }
18088
18131
  async function _onPointerUp(upEvent) {
18089
- current = { x: upEvent.clientX, y: upEvent.clientY };
18090
- if (drawing) {
18091
- drawingTool?.end?.(
18092
- camera.value.toGlobal({
18093
- x: current.x - drawboardAabb.value.left,
18094
- y: current.y - drawboardAabb.value.top
18095
- })
18096
- );
18097
- } else if (hand) {
18098
- grabbing.value = false;
18099
- } else {
18100
- if (!dragging) {
18101
- if (element && !selecting) {
18102
- onActivate();
18103
- }
18104
- elementSelection.value = selected;
18105
- if (ctxState) {
18106
- if (selected[0] && !isLock(selected[0])) {
18107
- switch (ctxState) {
18108
- case "typing": {
18109
- await exec("startTyping", upEvent);
18110
- break;
18132
+ currentPos = { x: upEvent.clientX, y: upEvent.clientY };
18133
+ switch (downState) {
18134
+ case "drawing":
18135
+ drawingTool?.end?.(
18136
+ camera.value.toGlobal({
18137
+ x: currentPos.x - drawboardAabb.value.left,
18138
+ y: currentPos.y - drawboardAabb.value.top
18139
+ })
18140
+ );
18141
+ break;
18142
+ case "hand":
18143
+ grabbing.value = false;
18144
+ break;
18145
+ default: {
18146
+ if (!dragging) {
18147
+ if (element && !selecting) {
18148
+ onActivate();
18149
+ }
18150
+ elementSelection.value = selected;
18151
+ if (ctxState) {
18152
+ if (selected[0] && !isLock(selected[0])) {
18153
+ switch (ctxState) {
18154
+ case "typing": {
18155
+ await exec("startTyping", upEvent);
18156
+ break;
18157
+ }
18111
18158
  }
18112
18159
  }
18113
18160
  }
18161
+ onEnginePointerHover(downEvent);
18114
18162
  }
18115
- onHover(downEvent);
18116
- }
18117
- if (state.value === "painting" || state.value === "selecting") {
18118
- selectionMarquee.value = new Aabb2D({ x: -1, y: -1, width: 0, height: 0 });
18119
- }
18120
- if (state.value === "painting") {
18121
- exec("applyFormatPaint", selected);
18122
- if (!(upEvent?.ctrlKey || upEvent?.shiftKey || upEvent?.metaKey)) {
18123
- exec("exitFormatPaint");
18163
+ switch (state.value) {
18164
+ case "selecting":
18165
+ selectionMarquee.value = new Aabb2D({ x: -1, y: -1, width: 0, height: 0 });
18166
+ if (state.value) {
18167
+ state.value = void 0;
18168
+ }
18169
+ break;
18170
+ case "painting":
18171
+ selectionMarquee.value = new Aabb2D({ x: -1, y: -1, width: 0, height: 0 });
18172
+ exec("applyFormatPaint", selected);
18173
+ if (!(upEvent?.ctrlKey || upEvent?.shiftKey || upEvent?.metaKey)) {
18174
+ exec("exitFormatPaint");
18175
+ }
18176
+ break;
18177
+ default:
18178
+ if (state.value) {
18179
+ state.value = void 0;
18180
+ }
18181
+ break;
18124
18182
  }
18125
- } else if (state.value) {
18126
- state.value = void 0;
18183
+ break;
18127
18184
  }
18128
18185
  }
18129
18186
  renderEngine.value.off("pointermove", _onEnginePointerMove);
@@ -18143,7 +18200,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
18143
18200
  if (camera.value.grabbing || event.button === 1 || state.value && state.value !== "typing") {
18144
18201
  return;
18145
18202
  }
18146
- onHover(event);
18203
+ onEnginePointerHover(event);
18147
18204
  }
18148
18205
  function onEnginePointerOver(event) {
18149
18206
  if (event.srcElement !== drawboardDom.value) {
@@ -18161,12 +18218,6 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
18161
18218
  }
18162
18219
  }
18163
18220
  }
18164
- async function onDoubleclick(event) {
18165
- props.doubleclickStrategy({
18166
- event,
18167
- editor
18168
- });
18169
- }
18170
18221
  function setComponentRef(ref2, item) {
18171
18222
  if (!componentRefs[item.plugin]) {
18172
18223
  componentRefs[item.plugin] = [];
@@ -18209,9 +18260,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
18209
18260
  ref: drawboardDom,
18210
18261
  class: "m-editor__drawboard",
18211
18262
  "data-pixel-ratio": unref(renderEngine).pixelRatio,
18212
- onDblclick: _cache[0] || (_cache[0] = ($event) => onDoubleclick($event)),
18213
18263
  onScroll,
18214
- onWheel: _cache[1] || (_cache[1] = withModifiers(() => {
18264
+ onWheel: _cache[0] || (_cache[0] = withModifiers(() => {
18215
18265
  }, ["prevent"]))
18216
18266
  }, [
18217
18267
  createElementVNode("canvas", _hoisted_2, null, 512),
@@ -7,6 +7,7 @@ declare global {
7
7
  visible: boolean;
8
8
  adsorbed: boolean;
9
9
  lineColor?: string;
10
+ boxColor?: string;
10
11
  locked: boolean;
11
12
  }
12
13
  interface Commands {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.17.8",
4
+ "version": "0.17.10",
5
5
  "description": "A headless infinite canvas editor framework built on WebGL rendering, supports exporting to image, video, and PPT. Only the ESM.",
6
6
  "author": "wxm",
7
7
  "license": "MIT",