mce 0.15.16 → 0.15.18

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
@@ -41,6 +41,9 @@
41
41
  .mce-frame--outline {
42
42
  outline: 1px solid rgba(0, 0, 0, 0.168627451);
43
43
  }
44
+ .mce-frame--lock {
45
+ pointer-events: none;
46
+ }
44
47
  .mce-frame--hover .mce-frame__name > div, .mce-frame--selected .mce-frame__name > div {
45
48
  opacity: 1;
46
49
  }
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { Node as Node$1, Element2D, Timeline, Engine, Camera2D, DrawboardEffect, Aabb2D, IN_BROWSER, clamp, assets, TimelineNode, Video2D, Transform2D, Obb2D, render, Vector2 as Vector2$1, Lottie2D, customNodes, Animation, IN_MAC_OS } from "modern-canvas";
2
- import { reactive, computed, watch, markRaw, isReactive, ref, warn, shallowRef, onBeforeUnmount, defineComponent, createElementBlock, createCommentVNode, unref, openBlock, normalizeStyle, toDisplayString, createVNode, useAttrs, createBlock, resolveDynamicComponent, normalizeClass, mergeProps, createElementVNode, inject, toValue, getCurrentInstance, provide, useId, readonly, toRef, onMounted, onDeactivated, onActivated, onScopeDispose, useModel, useTemplateRef, withDirectives, withModifiers, vShow, vModelText, nextTick, Fragment, renderList, renderSlot, mergeModels, resolveComponent, withCtx, Teleport, createTextVNode, createSlots, normalizeProps, guardReactiveProps, onBeforeMount, h, isRef, useSlots } from "vue";
2
+ import { reactive, computed, watch, markRaw, isReactive, ref, warn, shallowRef, onBeforeUnmount, defineComponent, createElementBlock, createCommentVNode, unref, openBlock, normalizeStyle as normalizeStyle$1, toDisplayString, createVNode, useAttrs, createBlock, resolveDynamicComponent, normalizeClass, mergeProps, createElementVNode, inject, toValue, getCurrentInstance, provide, useId, readonly, toRef, onMounted, onDeactivated, onActivated, onScopeDispose, useModel, useTemplateRef, withDirectives, withModifiers, vShow, vModelText, nextTick, Fragment, renderList, renderSlot, mergeModels, resolveComponent, withCtx, Teleport, createTextVNode, createSlots, normalizeProps, guardReactiveProps, onBeforeMount, h, isRef, useSlots } from "vue";
3
3
  import { useFileDialog, useEventListener, isClient, onClickOutside, useDebounceFn, useResizeObserver as useResizeObserver$1, useLocalStorage, useImage } from "@vueuse/core";
4
- import { getObjectValueByPath, setObjectValueByPath, Observable, Reactivable, idGenerator, property, normalizeTextContent, normalizeCRLF, isEqualObject } from "modern-idoc";
4
+ import { getObjectValueByPath, setObjectValueByPath, Observable, Reactivable, idGenerator, property, normalizeTextContent, isCRLF, textContentToString, normalizeCRLF, isEqualObject } from "modern-idoc";
5
5
  import { saveAs } from "file-saver";
6
6
  import { Fonts } from "modern-font";
7
7
  import * as Y from "yjs";
8
8
  import { merge, throttle, cloneDeep } from "lodash-es";
9
- import { measureText } from "modern-text";
10
- import { TextEditor } from "modern-text/web-components";
9
+ import { measureText, Text } from "modern-text";
10
+ import { diffChars } from "diff";
11
11
  import { vResizeObserver } from "@vueuse/components";
12
12
  import { useFloating, offset, flip, shift, autoUpdate } from "@floating-ui/vue";
13
13
  function defineMixin(cb) {
@@ -486,13 +486,13 @@ class Model extends Reactivable {
486
486
  };
487
487
  }
488
488
  }
489
- var __defProp = Object.defineProperty;
490
- var __decorateClass = (decorators, target, key, kind) => {
489
+ var __defProp$1 = Object.defineProperty;
490
+ var __decorateClass$1 = (decorators, target, key, kind) => {
491
491
  var result = void 0;
492
492
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
493
493
  if (decorator = decorators[i])
494
494
  result = decorator(target, key, result) || result;
495
- if (result) __defProp(target, key, result);
495
+ if (result) __defProp$1(target, key, result);
496
496
  return result;
497
497
  };
498
498
  class Doc extends Model {
@@ -867,7 +867,7 @@ class Doc extends Model {
867
867
  };
868
868
  }
869
869
  }
870
- __decorateClass([
870
+ __decorateClass$1([
871
871
  property()
872
872
  ], Doc.prototype, "name");
873
873
  const _0_context = defineMixin((editor) => {
@@ -2257,6 +2257,724 @@ const _4_0_node = defineMixin((editor) => {
2257
2257
  addNode
2258
2258
  });
2259
2259
  });
2260
+ var __defProp = Object.defineProperty;
2261
+ var __decorateClass = (decorators, target, key, kind) => {
2262
+ var result = void 0;
2263
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2264
+ if (decorator = decorators[i])
2265
+ result = decorator(target, key, result) || result;
2266
+ if (result) __defProp(target, key, result);
2267
+ return result;
2268
+ };
2269
+ function normalizeStyle(style) {
2270
+ const newStyle = {};
2271
+ for (const key in style) {
2272
+ if (key !== "id" && style[key] !== void 0 && style[key] !== "") {
2273
+ newStyle[key] = style[key];
2274
+ }
2275
+ }
2276
+ return newStyle;
2277
+ }
2278
+ function textContentToCharStyles(textContent) {
2279
+ return textContent.flatMap((p) => {
2280
+ const { fragments } = p;
2281
+ const res = fragments.flatMap((f) => {
2282
+ const { content, ...fStyle } = f;
2283
+ return Array.from(normalizeCRLF(content)).map(() => ({ ...fStyle }));
2284
+ });
2285
+ if (isCRLF(normalizeCRLF(fragments[fragments.length - 1]?.content ?? ""))) {
2286
+ return res;
2287
+ }
2288
+ return [...res, {}];
2289
+ });
2290
+ }
2291
+ function isEqualStyle(style1, style2) {
2292
+ const keys1 = Object.keys(style1);
2293
+ const keys2 = Object.keys(style2);
2294
+ const keys = Array.from(/* @__PURE__ */ new Set([...keys1, ...keys2]));
2295
+ return !keys.length || keys.every((key) => style1[key] === style2[key]);
2296
+ }
2297
+ const emojiRE = /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
2298
+ function parseHTML(html) {
2299
+ const template = document.createElement("template");
2300
+ template.innerHTML = html;
2301
+ return template.content.cloneNode(true);
2302
+ }
2303
+ const SUPPORTS_POINTER_EVENTS = "PointerEvent" in globalThis;
2304
+ class TextEditor extends HTMLElement {
2305
+ _prevSelection;
2306
+ _composition = false;
2307
+ get composition() {
2308
+ return this._composition;
2309
+ }
2310
+ static _defined = false;
2311
+ static register() {
2312
+ if (!this._defined) {
2313
+ this._defined = true;
2314
+ customElements.define("text-editor", this);
2315
+ }
2316
+ }
2317
+ _text = new Text();
2318
+ get text() {
2319
+ return this._text;
2320
+ }
2321
+ set text(newText) {
2322
+ if (newText) {
2323
+ this._text?.off("update", this._update);
2324
+ this.reset();
2325
+ newText.on("update", this._update);
2326
+ this._text = newText;
2327
+ this._setTextInput(this.getPlaintext());
2328
+ this.text.update();
2329
+ this._update();
2330
+ }
2331
+ }
2332
+ _oldText = "";
2333
+ _container;
2334
+ _selection;
2335
+ _textarea;
2336
+ _cursor;
2337
+ constructor() {
2338
+ super();
2339
+ const shadowRoot = this.attachShadow({ mode: "open" });
2340
+ shadowRoot.appendChild(
2341
+ parseHTML(`
2342
+ <style>
2343
+ :host {
2344
+ position: absolute;
2345
+ left: 0;
2346
+ top: 0;
2347
+ width: 0;
2348
+ height: 0;
2349
+ z-index: 1;
2350
+ }
2351
+
2352
+ .container {
2353
+ position: absolute;
2354
+ }
2355
+
2356
+ textarea {
2357
+ position: absolute;
2358
+ opacity: 0;
2359
+ caret-color: transparent;
2360
+ left: 0;
2361
+ top: 0;
2362
+ width: 100%;
2363
+ height: 100%;
2364
+ padding: 0;
2365
+ border: 0;
2366
+ resize: none;
2367
+ overflow: hidden;
2368
+ }
2369
+
2370
+ .selection {
2371
+ position: absolute;
2372
+ left: 0;
2373
+ top: 0;
2374
+ pointer-events: none;
2375
+ }
2376
+
2377
+ .selection > * {
2378
+ position: absolute;
2379
+ left: 0;
2380
+ top: 0;
2381
+ background: rgba(var(--color, 0, 0, 0), 0.4);
2382
+ }
2383
+
2384
+ .cursor {
2385
+ position: absolute;
2386
+ left: 0;
2387
+ top: 0;
2388
+ pointer-events: none;
2389
+ }
2390
+
2391
+ .cursor.blink {
2392
+ animation: cursor-blink 1s steps(2, start) infinite;
2393
+ }
2394
+
2395
+ @keyframes cursor-blink {
2396
+ 100% {
2397
+ visibility: hidden;
2398
+ }
2399
+ }
2400
+ </style>
2401
+
2402
+ <div class="container">
2403
+ <textarea></textarea>
2404
+ <div class="selection"></div>
2405
+ <div class="cursor blink"></div>
2406
+ </div>
2407
+ `)
2408
+ );
2409
+ this._container = shadowRoot.querySelector(".container");
2410
+ this._selection = shadowRoot.querySelector(".selection");
2411
+ this._textarea = shadowRoot.querySelector("textarea");
2412
+ this._cursor = shadowRoot.querySelector(".cursor");
2413
+ this._bindEventListeners();
2414
+ this._update = this._update.bind(this);
2415
+ }
2416
+ connectedCallback() {
2417
+ this._emit("init");
2418
+ }
2419
+ moveToDom(target) {
2420
+ const style = getComputedStyle(target);
2421
+ const host = this.shadowRoot.host;
2422
+ host.style.width = `${target.clientWidth}px`;
2423
+ host.style.height = `${target.clientHeight}px`;
2424
+ host.style.transform = "";
2425
+ const hostRect = host.getBoundingClientRect();
2426
+ const hostCenter = { x: hostRect.x + hostRect.width / 2, y: hostRect.y + hostRect.height / 2 };
2427
+ const targetRect = target.getBoundingClientRect();
2428
+ const targetCenter = { x: targetRect.x + targetRect.width / 2, y: targetRect.y + targetRect.height / 2 };
2429
+ this.left = targetCenter.x - hostCenter.x;
2430
+ this.top = targetCenter.y - hostCenter.y;
2431
+ const m = new DOMMatrixReadOnly(style.transform);
2432
+ this.rotate = Math.atan2(m.b, m.a) * (180 / Math.PI);
2433
+ this._update();
2434
+ }
2435
+ set(text) {
2436
+ this.text = text;
2437
+ }
2438
+ onUpdateProperty(key, _newValue, _oldValue) {
2439
+ switch (key) {
2440
+ case "selection":
2441
+ if (this.selection) {
2442
+ this._selectionMinMax = {
2443
+ min: Math.min(...this.selection),
2444
+ max: Math.max(...this.selection)
2445
+ };
2446
+ this._showCursor = true;
2447
+ } else {
2448
+ this._selectionMinMax = {
2449
+ min: -1,
2450
+ max: -1
2451
+ };
2452
+ this._showCursor = false;
2453
+ }
2454
+ break;
2455
+ case "_selectionMinMax":
2456
+ case "_chars":
2457
+ this._updateSelectedChars();
2458
+ this._updateCursorPosition();
2459
+ break;
2460
+ case "_showCursor":
2461
+ case "_cursorPosition":
2462
+ this._renderCursor();
2463
+ break;
2464
+ case "_selectedChars":
2465
+ this._renderCursor();
2466
+ this._renderSelectRange();
2467
+ break;
2468
+ case "left":
2469
+ case "top":
2470
+ case "rotate":
2471
+ this._update();
2472
+ break;
2473
+ }
2474
+ }
2475
+ _updateChars() {
2476
+ const paragraphs = [];
2477
+ this.text.paragraphs.forEach((p, paragraphIndex) => {
2478
+ p.fragments.forEach((f, fragmentIndex) => {
2479
+ f.characters.forEach((c) => {
2480
+ if (!paragraphs[paragraphIndex])
2481
+ paragraphs[paragraphIndex] = [];
2482
+ if (!paragraphs[paragraphIndex][fragmentIndex])
2483
+ paragraphs[paragraphIndex][fragmentIndex] = [];
2484
+ paragraphs[paragraphIndex][fragmentIndex].push(c);
2485
+ });
2486
+ });
2487
+ });
2488
+ const toIndexChar = (c) => {
2489
+ return {
2490
+ paragraphIndex: -1,
2491
+ fragmentIndex: -1,
2492
+ charIndex: -1,
2493
+ color: c.computedStyle.color,
2494
+ left: c.inlineBox.left,
2495
+ top: c.inlineBox.top,
2496
+ width: c.inlineBox.width,
2497
+ height: c.inlineBox.height,
2498
+ content: c.content
2499
+ };
2500
+ };
2501
+ const chars = [];
2502
+ let pos = 0;
2503
+ paragraphs.forEach((p, paragraphIndex) => {
2504
+ if (p.length === 1 && p[0].length === 1 && isCRLF(p[0][0].content)) {
2505
+ const c = p[0][0];
2506
+ chars[pos] = {
2507
+ ...toIndexChar(c),
2508
+ paragraphIndex,
2509
+ fragmentIndex: 0,
2510
+ charIndex: 0,
2511
+ isCrlf: true
2512
+ };
2513
+ } else {
2514
+ p.forEach((f, fragmentIndex) => {
2515
+ f.forEach((c, charIndex) => {
2516
+ const char = toIndexChar(c);
2517
+ chars[pos] = {
2518
+ ...char,
2519
+ paragraphIndex,
2520
+ fragmentIndex,
2521
+ charIndex
2522
+ };
2523
+ pos++;
2524
+ if (!isCRLF(c.content)) {
2525
+ chars[pos] = {
2526
+ ...char,
2527
+ paragraphIndex,
2528
+ fragmentIndex,
2529
+ charIndex,
2530
+ content: " ",
2531
+ isLastSelected: true
2532
+ };
2533
+ }
2534
+ });
2535
+ });
2536
+ }
2537
+ pos++;
2538
+ });
2539
+ if (chars[0]) {
2540
+ chars[0].isFirst = true;
2541
+ }
2542
+ if (chars[chars.length - 1]) {
2543
+ chars[chars.length - 1].isLast = true;
2544
+ }
2545
+ this._chars = chars;
2546
+ }
2547
+ _updateSelectedChars() {
2548
+ this._selectedChars = this._chars.filter((_char, index) => {
2549
+ return index >= this._selectionMinMax.min && index < this._selectionMinMax.max;
2550
+ });
2551
+ if (this._selectionMinMax.min > -1) {
2552
+ this._emit("selected", [
2553
+ this._chars[this._selectionMinMax.min],
2554
+ this._chars[this._selectionMinMax.max]
2555
+ ]);
2556
+ } else {
2557
+ this._emit("selected", void 0);
2558
+ }
2559
+ }
2560
+ _updateCursorPosition() {
2561
+ let left = 0;
2562
+ let top = 0;
2563
+ const char = this._chars[this._selectionMinMax.min];
2564
+ if (char?.isLastSelected) {
2565
+ if (this.text.isVertical) {
2566
+ top += char?.height ?? 0;
2567
+ } else {
2568
+ left += char?.width ?? 0;
2569
+ }
2570
+ }
2571
+ left += char?.left ?? 0;
2572
+ top += char?.top ?? 0;
2573
+ this._cursorPosition = {
2574
+ color: char?.color,
2575
+ left,
2576
+ top,
2577
+ height: char?.height ?? 0,
2578
+ width: char?.width ?? 0
2579
+ };
2580
+ }
2581
+ getPlaintext() {
2582
+ return textContentToString(
2583
+ this._getNewContent(
2584
+ this.text.content
2585
+ )
2586
+ );
2587
+ }
2588
+ _getNewContent(content, newString = textContentToString(content), oldString = newString) {
2589
+ newString = normalizeCRLF(newString);
2590
+ newString = newString.replace(emojiRE, (emoji) => {
2591
+ if (Array.from(emoji).length > 1) {
2592
+ return "?";
2593
+ }
2594
+ return emoji;
2595
+ });
2596
+ oldString = normalizeCRLF(oldString);
2597
+ const oldStyles = textContentToCharStyles(content);
2598
+ const styles = [];
2599
+ let styleIndex = 0;
2600
+ let oldStyleIndex = 0;
2601
+ let prevOldStyle = {};
2602
+ const changes = diffChars(oldString, newString);
2603
+ changes.forEach((change) => {
2604
+ const chars = Array.from(change.value);
2605
+ if (change.removed) {
2606
+ oldStyleIndex += chars.length;
2607
+ } else {
2608
+ chars.forEach(() => {
2609
+ if (change.added) {
2610
+ styles[styleIndex] = { ...prevOldStyle };
2611
+ } else {
2612
+ prevOldStyle = normalizeStyle(oldStyles[oldStyleIndex]);
2613
+ styles[styleIndex] = { ...prevOldStyle };
2614
+ oldStyleIndex++;
2615
+ }
2616
+ styleIndex++;
2617
+ });
2618
+ }
2619
+ });
2620
+ let charIndex = 0;
2621
+ const newContents = [];
2622
+ normalizeTextContent(newString).forEach((p, pI) => {
2623
+ const { fragments: _, ...pStyle } = content[pI] ?? {};
2624
+ let newParagraph = { ...pStyle, fragments: [] };
2625
+ let newFragment;
2626
+ p.fragments.forEach((f) => {
2627
+ Array.from(f.content).forEach((char) => {
2628
+ const style = styles[charIndex] ?? {};
2629
+ if (newFragment) {
2630
+ const { content: _2, ..._style } = newFragment;
2631
+ if (isEqualStyle(style, _style)) {
2632
+ newFragment.content += char;
2633
+ } else {
2634
+ newParagraph.fragments.push(newFragment);
2635
+ newFragment = { ...style, content: char };
2636
+ }
2637
+ } else {
2638
+ newFragment = { ...style, content: char };
2639
+ }
2640
+ charIndex++;
2641
+ });
2642
+ });
2643
+ if (!isCRLF(p.fragments[p.fragments.length - 1]?.content ?? "")) {
2644
+ charIndex++;
2645
+ }
2646
+ if (newFragment) {
2647
+ newParagraph.fragments.push(newFragment);
2648
+ }
2649
+ if (newParagraph.fragments.length) {
2650
+ newContents.push(newParagraph);
2651
+ newParagraph = { ...pStyle, fragments: [] };
2652
+ }
2653
+ });
2654
+ return newContents;
2655
+ }
2656
+ _setTextInput(newText) {
2657
+ this._textarea.value = newText;
2658
+ this._oldText = newText;
2659
+ }
2660
+ _onInput() {
2661
+ const newText = this._textarea.value;
2662
+ this.text.content = this._getNewContent(
2663
+ this.text.content,
2664
+ newText,
2665
+ this._oldText
2666
+ );
2667
+ this._oldText = newText;
2668
+ this.text.update();
2669
+ this._emit("update");
2670
+ }
2671
+ _timer;
2672
+ _onKeydown(e) {
2673
+ e.stopPropagation();
2674
+ switch (e.key) {
2675
+ case "Escape":
2676
+ this.selection = void 0;
2677
+ return this._textarea.blur();
2678
+ }
2679
+ this._updateSelectionByDom();
2680
+ setTimeout(() => this._updateSelectionByDom(), 0);
2681
+ setTimeout(() => this._updateSelectionByDom(), 100);
2682
+ }
2683
+ _findNearest(options) {
2684
+ const isVertical = this.text.isVertical;
2685
+ const {
2686
+ x,
2687
+ y,
2688
+ xWeight = 1,
2689
+ yWeight = 1
2690
+ } = options;
2691
+ const char = this._chars.reduce(
2692
+ (prev, current, index) => {
2693
+ const diff = Math.abs(current.left + current.width / 2 - x) * xWeight + Math.abs(current.top + current.height / 2 - y) * yWeight;
2694
+ if (diff < prev.diff) {
2695
+ return {
2696
+ diff,
2697
+ index,
2698
+ value: current
2699
+ };
2700
+ }
2701
+ return prev;
2702
+ },
2703
+ {
2704
+ diff: Number.MAX_SAFE_INTEGER,
2705
+ index: -1,
2706
+ value: void 0
2707
+ }
2708
+ );
2709
+ if (char?.value) {
2710
+ if ((isVertical ? y > char.value.top + char.value.height / 2 : x > char.value.left + char.value.width / 2) && !char.value.isCrlf && !char.value.isLastSelected) {
2711
+ return char.index + 1;
2712
+ }
2713
+ return char.index;
2714
+ }
2715
+ return -1;
2716
+ }
2717
+ _updateSelectionByDom() {
2718
+ if (this._composition) {
2719
+ this.selection = this._prevSelection;
2720
+ } else {
2721
+ const { selectionStart, selectionEnd } = this._textarea;
2722
+ let count2 = 0;
2723
+ const _selection = [-1, -1];
2724
+ this._chars.forEach((char, index) => {
2725
+ if (count2 <= selectionStart) {
2726
+ _selection[0] = index;
2727
+ }
2728
+ if (count2 <= selectionEnd) {
2729
+ _selection[1] = index;
2730
+ }
2731
+ count2 += char.content.length;
2732
+ });
2733
+ const oldSelection = this.selection;
2734
+ this.selection = _selection;
2735
+ this._prevSelection = oldSelection;
2736
+ }
2737
+ }
2738
+ _updateDomSelection() {
2739
+ let start = 0;
2740
+ let end = 0;
2741
+ this._chars.forEach((char, index) => {
2742
+ if (index < this._selectionMinMax.min) {
2743
+ start += char.content.length;
2744
+ end = start;
2745
+ } else if (index < this._selectionMinMax.max) {
2746
+ end += char.content.length;
2747
+ }
2748
+ });
2749
+ this._textarea.selectionStart = start;
2750
+ this._textarea.selectionEnd = end;
2751
+ }
2752
+ _update() {
2753
+ this._updateChars();
2754
+ const { boundingBox, lineBox } = this.text;
2755
+ const host = this.shadowRoot.host;
2756
+ const radian = this.rotate * Math.PI / 180;
2757
+ const cos = Math.cos(radian);
2758
+ const sin = Math.sin(radian);
2759
+ host.style.transform = `matrix(${cos}, ${sin}, ${-sin}, ${cos}, ${this.left}, ${this.top})`;
2760
+ host.style.width = `${boundingBox.width}px`;
2761
+ host.style.height = `${boundingBox.height}px`;
2762
+ this._container.style.left = `${-boundingBox.left}px`;
2763
+ this._container.style.top = `${-boundingBox.top}px`;
2764
+ this._container.style.width = `${lineBox.width}px`;
2765
+ this._container.style.height = `${lineBox.height}px`;
2766
+ this._textarea.style.fontSize = `${this.text.computedStyle.fontSize}px`;
2767
+ this._textarea.style.writingMode = this.text.computedStyle.writingMode;
2768
+ this._renderSelectRange();
2769
+ this._renderCursor();
2770
+ }
2771
+ _bindEventListeners() {
2772
+ this._textarea.addEventListener("compositionstart", () => this._composition = true);
2773
+ this._textarea.addEventListener("compositionend", () => this._composition = false);
2774
+ this._textarea.addEventListener("keydown", this._onKeydown.bind(this));
2775
+ this._textarea.addEventListener("input", this._onInput.bind(this));
2776
+ if (SUPPORTS_POINTER_EVENTS) {
2777
+ this._textarea.addEventListener("pointerdown", this.pointerDown.bind(this));
2778
+ } else {
2779
+ this._textarea.addEventListener("mousedown", this.pointerDown.bind(this));
2780
+ }
2781
+ ["keyup", "mouseup", "input", "paste", "cut"].forEach((key) => {
2782
+ this._textarea.addEventListener(key, () => {
2783
+ this._updateSelectionByDom();
2784
+ });
2785
+ });
2786
+ }
2787
+ pointerDown(e) {
2788
+ if (e && e.button !== 0) {
2789
+ e.preventDefault();
2790
+ e.stopPropagation();
2791
+ return false;
2792
+ }
2793
+ const isVertical = this.text.isVertical;
2794
+ const host = this.shadowRoot.host;
2795
+ const clientRect = host.getBoundingClientRect();
2796
+ const { clientWidth: width, clientHeight: height } = host;
2797
+ const scaleX = clientRect.width / width;
2798
+ const scaleY = clientRect.height / height;
2799
+ const radian = this.rotate * Math.PI / 180;
2800
+ const cos = Math.cos(radian);
2801
+ const sin = Math.sin(radian);
2802
+ const m = new DOMMatrixReadOnly([cos, sin, -sin, cos, 0, 0]).inverse();
2803
+ const clientCenter = { x: clientRect.x + clientRect.width / 2, y: clientRect.y + clientRect.height / 2 };
2804
+ const center = { x: clientCenter.x / scaleX, y: clientCenter.y / scaleY };
2805
+ let x = 0;
2806
+ let y = 0;
2807
+ const getXy = (e2) => {
2808
+ const _p = m.transformPoint({
2809
+ x: e2.clientX - clientCenter.x,
2810
+ y: e2.clientY - clientCenter.y
2811
+ });
2812
+ const p = {
2813
+ x: (_p.x + clientCenter.x) / scaleX,
2814
+ y: (_p.y + clientCenter.y) / scaleY
2815
+ };
2816
+ if (isVertical) {
2817
+ return {
2818
+ x: center.x + width / 2 - p.x,
2819
+ y: p.y - (center.y - height / 2)
2820
+ };
2821
+ } else {
2822
+ return {
2823
+ x: p.x - (center.x - width / 2),
2824
+ y: p.y - (center.y - height / 2)
2825
+ };
2826
+ }
2827
+ };
2828
+ if (e) {
2829
+ ({ x, y } = getXy(e));
2830
+ e.preventDefault();
2831
+ e.stopPropagation();
2832
+ }
2833
+ const index = this._findNearest({ x, y });
2834
+ this.selection = [index, index];
2835
+ this._updateDomSelection();
2836
+ if (e && ["mousedown", "pointerdown"].includes(e.type)) {
2837
+ const onMove = (e2) => {
2838
+ this.selection = [
2839
+ index,
2840
+ this._findNearest(getXy(e2))
2841
+ ];
2842
+ this._updateDomSelection();
2843
+ };
2844
+ const onUp = () => {
2845
+ if (SUPPORTS_POINTER_EVENTS) {
2846
+ document.removeEventListener("pointermove", onMove);
2847
+ document.removeEventListener("pointerup", onUp);
2848
+ } else {
2849
+ document.removeEventListener("mousemove", onMove);
2850
+ document.removeEventListener("mouseup", onUp);
2851
+ }
2852
+ };
2853
+ if (SUPPORTS_POINTER_EVENTS) {
2854
+ document.addEventListener("pointermove", onMove);
2855
+ document.addEventListener("pointerup", onUp);
2856
+ } else {
2857
+ document.addEventListener("mousemove", onMove);
2858
+ document.addEventListener("mouseup", onUp);
2859
+ }
2860
+ }
2861
+ this._textarea.focus();
2862
+ return true;
2863
+ }
2864
+ selectAll() {
2865
+ this._textarea.focus();
2866
+ this._textarea.select();
2867
+ this._updateSelectionByDom();
2868
+ }
2869
+ attributeChangedCallback(name, _oldValue, newValue) {
2870
+ this[name] = newValue;
2871
+ }
2872
+ _emit(type, detail) {
2873
+ return this.dispatchEvent(
2874
+ new CustomEvent(type, {
2875
+ bubbles: true,
2876
+ cancelable: true,
2877
+ composed: true,
2878
+ detail
2879
+ })
2880
+ );
2881
+ }
2882
+ _renderSelectRange() {
2883
+ const isVertical = this.text.isVertical;
2884
+ const boxesGroupsMap = {};
2885
+ this._selectedChars.forEach((char) => {
2886
+ if (char.isLastSelected) {
2887
+ return;
2888
+ }
2889
+ const key = isVertical ? char.left : char.top;
2890
+ if (!boxesGroupsMap[key]) {
2891
+ boxesGroupsMap[key] = [];
2892
+ }
2893
+ boxesGroupsMap[key].push({
2894
+ x: char.left,
2895
+ y: char.top,
2896
+ w: char.width,
2897
+ h: char.height
2898
+ });
2899
+ });
2900
+ const boxesGroups = Object.values(boxesGroupsMap);
2901
+ const sourceLen = this._selection.children.length;
2902
+ const targetLen = boxesGroups.length;
2903
+ const len = Math.max(sourceLen, targetLen);
2904
+ const deleted = [];
2905
+ for (let i = 0; i < len; i++) {
2906
+ let element = this._selection.children.item(i);
2907
+ const boxes = boxesGroups[i];
2908
+ if (!boxes) {
2909
+ deleted.push(element);
2910
+ continue;
2911
+ } else if (!element) {
2912
+ element = document.createElement("div");
2913
+ this._selection.append(element);
2914
+ }
2915
+ const min = {
2916
+ x: Math.min(...boxes.map((v) => v.x)),
2917
+ y: Math.min(...boxes.map((v) => v.y))
2918
+ };
2919
+ const max = {
2920
+ x: Math.max(...boxes.map((v) => v.x + v.w)),
2921
+ y: Math.max(...boxes.map((v) => v.y + v.h))
2922
+ };
2923
+ element.style.width = `${max.x - min.x}px`;
2924
+ element.style.height = `${max.y - min.y}px`;
2925
+ element.style.transform = `translate(${min.x}px, ${min.y}px)`;
2926
+ }
2927
+ deleted.forEach((el) => el?.remove());
2928
+ }
2929
+ _renderCursor() {
2930
+ if (this._showCursor && this._cursorPosition && this._selectedChars.length === 0) {
2931
+ const _cursorPosition = this._cursorPosition;
2932
+ this._cursor.style.display = "block";
2933
+ this._cursor.style.backgroundColor = _cursorPosition.color ?? "rgba(var(--color))";
2934
+ this._cursor.style.left = `${_cursorPosition.left}px`;
2935
+ this._cursor.style.top = `${_cursorPosition.top}px`;
2936
+ this._cursor.style.height = this.text.isVertical ? "1px" : `${_cursorPosition.height}px`;
2937
+ this._cursor.style.width = this.text.isVertical ? `${_cursorPosition.width}px` : "1px";
2938
+ } else {
2939
+ this._cursor.style.display = "none";
2940
+ }
2941
+ this._cursor.classList.remove("blink");
2942
+ if (this._timer) {
2943
+ clearTimeout(this._timer);
2944
+ }
2945
+ this._timer = setTimeout(() => this._cursor.classList.add("blink"), 500);
2946
+ }
2947
+ reset() {
2948
+ this.selection = void 0;
2949
+ }
2950
+ }
2951
+ __decorateClass([
2952
+ property({ fallback: 0 })
2953
+ ], TextEditor.prototype, "left");
2954
+ __decorateClass([
2955
+ property({ fallback: 0 })
2956
+ ], TextEditor.prototype, "top");
2957
+ __decorateClass([
2958
+ property({ fallback: 0 })
2959
+ ], TextEditor.prototype, "rotate");
2960
+ __decorateClass([
2961
+ property()
2962
+ ], TextEditor.prototype, "selection");
2963
+ __decorateClass([
2964
+ property({ internal: true, fallback: () => ({ min: -1, max: -1 }) })
2965
+ ], TextEditor.prototype, "_selectionMinMax");
2966
+ __decorateClass([
2967
+ property({ internal: true, fallback: () => [] })
2968
+ ], TextEditor.prototype, "_chars");
2969
+ __decorateClass([
2970
+ property({ internal: true, fallback: () => [] })
2971
+ ], TextEditor.prototype, "_selectedChars");
2972
+ __decorateClass([
2973
+ property({ internal: true })
2974
+ ], TextEditor.prototype, "_cursorPosition");
2975
+ __decorateClass([
2976
+ property({ internal: true, fallback: false })
2977
+ ], TextEditor.prototype, "_showCursor");
2260
2978
  const _4_1_text = defineMixin((editor) => {
2261
2979
  const {
2262
2980
  isElement,
@@ -2856,7 +3574,7 @@ const _4_3_element = defineMixin((editor) => {
2856
3574
  }
2857
3575
  return [node];
2858
3576
  }).filter((node) => {
2859
- return "isVisibleInTree" in node && node.isVisibleInTree() && getObb(node, "drawboard").overlapsOnAxis(area2) && !isLock(node);
3577
+ return "isVisibleInTree" in node && node.isVisibleInTree() && getObb(node, "drawboard").overlapsOnAxis(area2) && !isLock(node) && !node.findAncestor((ancestor) => isLock(ancestor));
2860
3578
  }) ?? [];
2861
3579
  selection.value = selected;
2862
3580
  return selected;
@@ -3556,7 +4274,7 @@ const _clipboard = definePlugin((editor, options) => {
3556
4274
  }),
3557
4275
  {
3558
4276
  parent: selection.value[0].parent,
3559
- index: selection.value[0].getIndex(),
4277
+ index: selection.value[0].getIndex() + 1,
3560
4278
  active: true,
3561
4279
  regenId: true
3562
4280
  }
@@ -3661,7 +4379,7 @@ const _sfc_main$D = /* @__PURE__ */ defineComponent({
3661
4379
  return unref(state) === "drawing" && unref(drawboardPointer) ? (openBlock(), createElementBlock("div", {
3662
4380
  key: 0,
3663
4381
  class: "mce-drawing",
3664
- style: normalizeStyle({
4382
+ style: normalizeStyle$1({
3665
4383
  left: `${unref(drawboardPointer).x}px`,
3666
4384
  top: `${unref(drawboardPointer).y}px`
3667
4385
  })
@@ -4394,7 +5112,8 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4394
5112
  config,
4395
5113
  exec,
4396
5114
  renderEngine,
4397
- drawboardDom
5115
+ drawboardDom,
5116
+ isLock
4398
5117
  } = useEditor();
4399
5118
  const editing = ref(false);
4400
5119
  async function onDblclick() {
@@ -4417,19 +5136,20 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4417
5136
  }
4418
5137
  return (_ctx, _cache) => {
4419
5138
  return withDirectives((openBlock(), createElementBlock("div", {
4420
- style: normalizeStyle(unref(getObb)(frame.value, "drawboard").toCssStyle()),
5139
+ style: normalizeStyle$1(unref(getObb)(frame.value, "drawboard").toCssStyle()),
4421
5140
  class: normalizeClass(["mce-frame", [
4422
5141
  unref(config).frameOutline && "mce-frame--outline",
4423
5142
  unref(hoverElement)?.equal(frame.value) && "mce-frame--hover",
4424
- unref(selection).some((v) => v.equal(frame.value)) && "mce-frame--selected"
5143
+ unref(selection).some((v) => v.equal(frame.value)) && "mce-frame--selected",
5144
+ unref(isLock)(frame.value) && "mce-frame--lock"
4425
5145
  ]])
4426
5146
  }, [
4427
- withDirectives(createElementVNode("div", {
5147
+ createElementVNode("div", {
4428
5148
  class: "mce-frame__name",
4429
5149
  onDblclick: withModifiers(onDblclick, ["prevent", "stop"]),
4430
5150
  onPointerdown,
4431
- onPointerenter: _cache[2] || (_cache[2] = ($event) => !unref(state) && (hoverElement.value = frame.value)),
4432
- onPointerleave: _cache[3] || (_cache[3] = ($event) => !unref(state) && (hoverElement.value = void 0))
5151
+ onPointerenter: _cache[2] || (_cache[2] = ($event) => !unref(state) && !unref(isLock)(frame.value) && (hoverElement.value = frame.value)),
5152
+ onPointerleave: _cache[3] || (_cache[3] = ($event) => !unref(state) && !unref(isLock)(frame.value) && (hoverElement.value = void 0))
4433
5153
  }, [
4434
5154
  createElementVNode("div", null, toDisplayString(frame.value.name), 1),
4435
5155
  withDirectives(createElementVNode("input", {
@@ -4440,9 +5160,7 @@ const _sfc_main$B = /* @__PURE__ */ defineComponent({
4440
5160
  [vShow, editing.value],
4441
5161
  [vModelText, frame.value.name]
4442
5162
  ])
4443
- ], 544), [
4444
- [vShow, unref(config).viewMode === "edgeless"]
4445
- ])
5163
+ ], 32)
4446
5164
  ], 6)), [
4447
5165
  [vShow, frame.value.visible]
4448
5166
  ]);
@@ -4482,6 +5200,9 @@ const _frame = definePlugin((editor) => {
4482
5200
  handle: (start) => {
4483
5201
  const el = addElement({
4484
5202
  name: t("frame"),
5203
+ style: {
5204
+ overflow: "hidden"
5205
+ },
4485
5206
  meta: {
4486
5207
  inPptIs: "GroupShape",
4487
5208
  inEditorIs: "Frame",
@@ -4688,7 +5409,7 @@ const _sfc_main$z = /* @__PURE__ */ defineComponent({
4688
5409
  key: 0,
4689
5410
  class: "mce-hover",
4690
5411
  "data-name": unref(hoverElement).name,
4691
- style: normalizeStyle({
5412
+ style: normalizeStyle$1({
4692
5413
  borderColor: "currentcolor",
4693
5414
  borderRadius: `${(unref(hoverElement).style.borderRadius ?? 0) * unref(camera).zoom.x}px`,
4694
5415
  ...hoverElementObb.value.toCssStyle()
@@ -5338,7 +6059,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5338
6059
  isHoverElement.value && "mce-layer--hover",
5339
6060
  unref(dropping) && "mce-layer--dropping"
5340
6061
  ]]),
5341
- style: normalizeStyle({
6062
+ style: normalizeStyle$1({
5342
6063
  "--indent-padding": `${props.indent * 16}px`
5343
6064
  }),
5344
6065
  "data-id": unref(id),
@@ -5385,7 +6106,7 @@ const _sfc_main$x = /* @__PURE__ */ defineComponent({
5385
6106
  [vModelText, editValue.value]
5386
6107
  ]),
5387
6108
  createElementVNode("div", {
5388
- style: normalizeStyle({ visibility: editing.value ? "hidden" : void 0 })
6109
+ style: normalizeStyle$1({ visibility: editing.value ? "hidden" : void 0 })
5389
6110
  }, toDisplayString(editValue.value || thumbnailName.value), 5)
5390
6111
  ], 32),
5391
6112
  createElementVNode("div", {
@@ -5970,7 +6691,7 @@ const _sfc_main$s = /* @__PURE__ */ defineComponent({
5970
6691
  target: position.value,
5971
6692
  location: "bottom-start",
5972
6693
  items: unref(contextMenu),
5973
- style: normalizeStyle({
6694
+ style: normalizeStyle$1({
5974
6695
  maxHeight: `${unref(drawboardAabb).height * 0.8}px`
5975
6696
  }),
5976
6697
  "onClick:item": onClickItem
@@ -10913,7 +11634,7 @@ const _sfc_main$p = /* @__PURE__ */ defineComponent({
10913
11634
  "mce-ruler-refline--horizontal": !props.vertical,
10914
11635
  "mce-ruler-refline--temp": item === tempLine.value
10915
11636
  }]),
10916
- style: normalizeStyle({
11637
+ style: normalizeStyle$1({
10917
11638
  [props.vertical ? "height" : "width"]: "0",
10918
11639
  [props.vertical ? "width" : "height"]: "100%",
10919
11640
  [props.vertical ? "top" : "left"]: `${numToPx(item)}px`,
@@ -11107,7 +11828,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
11107
11828
  "mce-scrollbar--vertical": props.vertical,
11108
11829
  "mce-scrollbar--horizontal": !props.vertical
11109
11830
  }]),
11110
- style: normalizeStyle({
11831
+ style: normalizeStyle$1({
11111
11832
  [props.vertical ? "height" : "width"]: `calc(100% - ${props.size + props.offset}px)`,
11112
11833
  [props.vertical ? "width" : "height"]: `${props.size}px`,
11113
11834
  [props.vertical ? "top" : "left"]: `${props.offset}px`
@@ -11119,7 +11840,7 @@ const _sfc_main$n = /* @__PURE__ */ defineComponent({
11119
11840
  class: normalizeClass(["mce-scrollbar__thumb", {
11120
11841
  "mce-scrollbar__thumb--active": isActive.value
11121
11842
  }]),
11122
- style: normalizeStyle({
11843
+ style: normalizeStyle$1({
11123
11844
  top: thumbTop.value,
11124
11845
  bottom: thumbBottom.value,
11125
11846
  left: thumbLeft.value,
@@ -11453,7 +12174,7 @@ const _sfc_main$k = /* @__PURE__ */ defineComponent({
11453
12174
  return openBlock(), createElementBlock("div", {
11454
12175
  key,
11455
12176
  class: normalizeClass(item.class.map((v) => `mce-smart-guides__${v}`)),
11456
- style: normalizeStyle({
12177
+ style: normalizeStyle$1({
11457
12178
  left: `${item.style.left}px`,
11458
12179
  top: `${item.style.top}px`,
11459
12180
  width: `${item.style.width}px`,
@@ -12819,7 +13540,7 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
12819
13540
  !__props.indeterminate ? (openBlock(), createElementBlock("div", {
12820
13541
  key: 0,
12821
13542
  class: "progress-indicator__bar-fill",
12822
- style: normalizeStyle({ width: `${progress.value * 100}%` })
13543
+ style: normalizeStyle$1({ width: `${progress.value * 100}%` })
12823
13544
  }, null, 4)) : (openBlock(), createElementBlock("div", _hoisted_4$3))
12824
13545
  ])
12825
13546
  ]);
@@ -13092,13 +13813,13 @@ const _sfc_main$g = /* @__PURE__ */ defineComponent({
13092
13813
  `mce-segment--${(__props.node.meta.inEditorIs ?? "none").toLowerCase()}`,
13093
13814
  __props.active && `mce-segment--active`
13094
13815
  ]]),
13095
- style: normalizeStyle(style.value)
13816
+ style: normalizeStyle$1(style.value)
13096
13817
  }, [
13097
13818
  (openBlock(true), createElementBlock(Fragment, null, renderList(blocks.value, (block, index) => {
13098
13819
  return openBlock(), createElementBlock("div", {
13099
13820
  key: index,
13100
13821
  class: "mce-segment__block",
13101
- style: normalizeStyle(block.style)
13822
+ style: normalizeStyle$1(block.style)
13102
13823
  }, toDisplayString(block.name), 5);
13103
13824
  }), 128)),
13104
13825
  __props.active ? (openBlock(), createElementBlock("div", _hoisted_1$8)) : createCommentVNode("", true),
@@ -13128,7 +13849,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
13128
13849
  return (_ctx, _cache) => {
13129
13850
  return openBlock(), createElementBlock("div", {
13130
13851
  class: "mce-trackhead",
13131
- style: normalizeStyle({
13852
+ style: normalizeStyle$1({
13132
13853
  height: `var(--timeline-track-height__${__props.node.meta.inEditorIs}, 22px)`
13133
13854
  })
13134
13855
  }, toDisplayString(__props.node.meta.inEditorIs), 5);
@@ -13257,7 +13978,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
13257
13978
  createElementVNode("div", _hoisted_3$3, [
13258
13979
  createElementVNode("div", _hoisted_4$1, [
13259
13980
  createElementVNode("div", {
13260
- style: normalizeStyle({
13981
+ style: normalizeStyle$1({
13261
13982
  transform: `translateY(${offset2.value[1]}px)`
13262
13983
  })
13263
13984
  }, [
@@ -13289,7 +14010,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
13289
14010
  ]),
13290
14011
  createElementVNode("div", _hoisted_7$1, [
13291
14012
  createElementVNode("div", {
13292
- style: normalizeStyle({
14013
+ style: normalizeStyle$1({
13293
14014
  width: `${unref(endTime) / unref(msPerPx)}px`,
13294
14015
  transform: `translate(${offset2.value[0]}px, ${offset2.value[1]}px)`
13295
14016
  })
@@ -13310,7 +14031,7 @@ const _sfc_main$d = /* @__PURE__ */ defineComponent({
13310
14031
  ], 4)
13311
14032
  ]),
13312
14033
  createVNode(_sfc_main$h, {
13313
- style: normalizeStyle({
14034
+ style: normalizeStyle$1({
13314
14035
  transform: `translate(${offset2.value[0] + Math.ceil(unref(currentTime) / unref(msPerPx))}px, 0px)`
13315
14036
  })
13316
14037
  }, null, 8, ["style"])
@@ -13913,7 +14634,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
13913
14634
  return (_ctx, _cache) => {
13914
14635
  return openBlock(), createBlock(_sfc_main$u, {
13915
14636
  ref: "overlayTpl",
13916
- style: normalizeStyle(style.value),
14637
+ style: normalizeStyle$1(style.value),
13917
14638
  class: "mce-floatbar",
13918
14639
  location: props.location,
13919
14640
  middlewares: props.middlewares,
@@ -14438,7 +15159,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
14438
15159
  activeHandle.value?.startsWith("rotate") && "mce-transformable--rotateing",
14439
15160
  props.borderStyle && `mce-transformable--${props.borderStyle}`
14440
15161
  ]]),
14441
- style: normalizeStyle(style.value)
15162
+ style: normalizeStyle$1(style.value)
14442
15163
  }, {
14443
15164
  default: withCtx(() => [
14444
15165
  renderSlot(_ctx.$slots, "default", {
@@ -14659,7 +15380,7 @@ const _sfc_main$9 = /* @__PURE__ */ defineComponent({
14659
15380
  return withDirectives((openBlock(), createElementBlock("div", _hoisted_1$3, [
14660
15381
  createElementVNode("div", {
14661
15382
  class: "mce-cropper__source",
14662
- style: normalizeStyle(sourceStyle.value)
15383
+ style: normalizeStyle$1(sourceStyle.value)
14663
15384
  }, [
14664
15385
  createElementVNode("canvas", {
14665
15386
  ref_key: "canvasRef",
@@ -14702,7 +15423,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
14702
15423
  key: 0,
14703
15424
  modelValue: element.value.foreground.cropRect,
14704
15425
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => element.value.foreground.cropRect = $event),
14705
- style: normalizeStyle(element.value.style.toJSON()),
15426
+ style: normalizeStyle$1(element.value.style.toJSON()),
14706
15427
  image: element.value.foreground.image,
14707
15428
  class: "pointer-events-auto",
14708
15429
  "onUpdate:style": _cache[1] || (_cache[1] = (val) => element.value.style.setProperties(val)),
@@ -14911,7 +15632,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
14911
15632
  return openBlock(), createElementBlock("div", {
14912
15633
  key: index,
14913
15634
  class: "mce-selector__parent-element",
14914
- style: normalizeStyle({
15635
+ style: normalizeStyle$1({
14915
15636
  borderColor: "currentColor",
14916
15637
  ...style
14917
15638
  })
@@ -14920,7 +15641,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
14920
15641
  unref(state) === "selecting" ? (openBlock(), createElementBlock("div", {
14921
15642
  key: 0,
14922
15643
  class: "mce-selector__selected-area",
14923
- style: normalizeStyle({
15644
+ style: normalizeStyle$1({
14924
15645
  borderColor: "currentcolor",
14925
15646
  ...props.selectedArea.toCssStyle()
14926
15647
  })
@@ -14929,7 +15650,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
14929
15650
  return openBlock(), createElementBlock("div", {
14930
15651
  key: index,
14931
15652
  class: "mce-selector__element",
14932
- style: normalizeStyle({
15653
+ style: normalizeStyle$1({
14933
15654
  borderColor: "currentcolor",
14934
15655
  ...style
14935
15656
  })
@@ -14963,7 +15684,7 @@ const _sfc_main$7 = /* @__PURE__ */ defineComponent({
14963
15684
  transform.value.width && transform.value.height && _ctx.$slots.default ? (openBlock(), createElementBlock("div", {
14964
15685
  key: 2,
14965
15686
  class: "mce-selector__slot",
14966
- style: normalizeStyle(unref(boundingBoxToStyle)(transform.value))
15687
+ style: normalizeStyle$1(unref(boundingBoxToStyle)(transform.value))
14967
15688
  }, [
14968
15689
  renderSlot(_ctx.$slots, "default", { box: transform.value })
14969
15690
  ], 4)) : createCommentVNode("", true)
@@ -15062,7 +15783,7 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
15062
15783
  return openBlock(), createElementBlock("div", {
15063
15784
  ref: unref(layoutRef),
15064
15785
  class: normalizeClass(normalizeClass([unref(layoutClasses), props.class])),
15065
- style: normalizeStyle(normalizeStyle([unref(layoutStyles), props.style]))
15786
+ style: normalizeStyle$1(normalizeStyle$1([unref(layoutStyles), props.style]))
15066
15787
  }, [
15067
15788
  renderSlot(_ctx.$slots, "default")
15068
15789
  ], 6);
@@ -15108,7 +15829,7 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
15108
15829
  `mce-layout-item--${props.position}`,
15109
15830
  props.class
15110
15831
  ])),
15111
- style: normalizeStyle(normalizeStyle([unref(layoutItemStyles), props.style]))
15832
+ style: normalizeStyle$1(normalizeStyle$1([unref(layoutItemStyles), props.style]))
15112
15833
  }, [
15113
15834
  renderSlot(_ctx.$slots, "default")
15114
15835
  ], 6);
@@ -15132,7 +15853,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
15132
15853
  class: normalizeClass(["mce-main", [
15133
15854
  { "mce-main--scrollable": props.scrollable }
15134
15855
  ]]),
15135
- style: normalizeStyle([unref(mainStyles)])
15856
+ style: normalizeStyle$1([unref(mainStyles)])
15136
15857
  }, [
15137
15858
  props.scrollable ? (openBlock(), createElementBlock("div", _hoisted_1$1, [
15138
15859
  renderSlot(_ctx.$slots, "default")
@@ -15213,13 +15934,13 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
15213
15934
  return (_ctx, _cache) => {
15214
15935
  return withDirectives((openBlock(), createElementBlock("div", {
15215
15936
  class: "mce-text-editor",
15216
- style: normalizeStyle({
15937
+ style: normalizeStyle$1({
15217
15938
  ...mainStyleWithScale.value
15218
15939
  })
15219
15940
  }, [
15220
15941
  createElementVNode("div", {
15221
15942
  class: "mce-text-editor__wrapper",
15222
- style: normalizeStyle({
15943
+ style: normalizeStyle$1({
15223
15944
  ...textEditorStyle.value
15224
15945
  })
15225
15946
  }, [
@@ -15355,7 +16076,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15355
16076
  hovered = result;
15356
16077
  }
15357
16078
  }
15358
- if (!(isElement(hovered) && !isLock(hovered) && !isTopLevelFrame(hovered))) {
16079
+ if (!(isElement(hovered) && !isLock(hovered) && !hovered.findAncestor((ancestor) => isLock(ancestor)) && !isTopLevelFrame(hovered))) {
15359
16080
  hovered = void 0;
15360
16081
  cursor = void 0;
15361
16082
  }
@@ -15370,7 +16091,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
15370
16091
  allowRootFrame = false
15371
16092
  } = options;
15372
16093
  function isIncluded(node) {
15373
- return isElement(node) && !isLock(node) && (allowRootFrame || !isTopLevelFrame(node));
16094
+ return isElement(node) && !isLock(node) && (allowRootFrame || !isTopLevelFrame(node)) && !node.findAncestor((ancestor) => isLock(ancestor));
15374
16095
  }
15375
16096
  const drawing = state.value === "drawing";
15376
16097
  const hand = state.value === "hand";
@@ -0,0 +1,81 @@
1
+ import type { NormalizedTextContent, PropertyAccessor } from 'modern-idoc';
2
+ import { Text } from 'modern-text';
3
+ export interface IndexCharacter {
4
+ paragraphIndex: number;
5
+ fragmentIndex: number;
6
+ charIndex: number;
7
+ color: string;
8
+ left: number;
9
+ top: number;
10
+ width: number;
11
+ height: number;
12
+ content: string;
13
+ isFirst?: boolean;
14
+ isLast?: boolean;
15
+ isLastSelected?: boolean;
16
+ isCrlf?: boolean;
17
+ }
18
+ export declare class TextEditor extends HTMLElement implements PropertyAccessor {
19
+ left: number;
20
+ top: number;
21
+ rotate: number;
22
+ selection: [number, number] | undefined;
23
+ protected _selectionMinMax: {
24
+ min: number;
25
+ max: number;
26
+ };
27
+ protected _chars: IndexCharacter[];
28
+ protected _selectedChars: IndexCharacter[];
29
+ protected _cursorPosition?: {
30
+ left: number;
31
+ top: number;
32
+ width: number;
33
+ height: number;
34
+ color: string;
35
+ };
36
+ protected _showCursor: boolean;
37
+ protected _prevSelection: [number, number] | undefined;
38
+ protected _composition: boolean;
39
+ get composition(): boolean;
40
+ protected static _defined: boolean;
41
+ static register(): void;
42
+ protected _text: Text;
43
+ get text(): Text;
44
+ set text(newText: Text);
45
+ protected _oldText: string;
46
+ protected _container: HTMLDivElement;
47
+ protected _selection: HTMLDivElement;
48
+ protected _textarea: HTMLTextAreaElement;
49
+ protected _cursor: HTMLElement;
50
+ constructor();
51
+ connectedCallback(): void;
52
+ moveToDom(target: HTMLElement): void;
53
+ set(text: Text): void;
54
+ onUpdateProperty(key: string, _newValue: unknown, _oldValue: unknown): void;
55
+ protected _updateChars(): void;
56
+ protected _updateSelectedChars(): void;
57
+ protected _updateCursorPosition(): void;
58
+ getPlaintext(): string;
59
+ protected _getNewContent(content: NormalizedTextContent, newString?: string, oldString?: string): NormalizedTextContent;
60
+ protected _setTextInput(newText: string): void;
61
+ protected _onInput(): void;
62
+ protected _timer?: any;
63
+ protected _onKeydown(e: KeyboardEvent): void;
64
+ protected _findNearest(options: {
65
+ x: number;
66
+ y: number;
67
+ xWeight?: number;
68
+ yWeight?: number;
69
+ }): number;
70
+ protected _updateSelectionByDom(): void;
71
+ protected _updateDomSelection(): void;
72
+ protected _update(): void;
73
+ protected _bindEventListeners(): void;
74
+ pointerDown(e?: MouseEvent | PointerEvent): boolean;
75
+ selectAll(): void;
76
+ attributeChangedCallback(name: string, _oldValue: any, newValue: any): void;
77
+ protected _emit(type: string, detail?: any): boolean;
78
+ protected _renderSelectRange(): void;
79
+ protected _renderCursor(): void;
80
+ reset(): void;
81
+ }
@@ -0,0 +1 @@
1
+ export * from './TextEditor';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mce",
3
3
  "type": "module",
4
- "version": "0.15.16",
4
+ "version": "0.15.18",
5
5
  "description": "The headless canvas editor framework. only the ESM.",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -61,7 +61,7 @@
61
61
  "diff": "^8.0.2",
62
62
  "file-saver": "^2.0.5",
63
63
  "lodash-es": "^4.17.22",
64
- "modern-canvas": "^0.14.32",
64
+ "modern-canvas": "^0.14.35",
65
65
  "modern-font": "^0.4.4",
66
66
  "modern-idoc": "^0.10.8",
67
67
  "modern-text": "^1.10.15",