@visactor/vrender-core 0.22.2 → 0.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/cjs/animate/custom-animate.js +2 -1
  2. package/cjs/animate/timeline.js +1 -2
  3. package/cjs/canvas/empty-context.js +1 -2
  4. package/cjs/color-string/store.js +2 -1
  5. package/cjs/common/bezier-utils.js +1 -2
  6. package/cjs/common/matrix.js +1 -1
  7. package/cjs/common/morphing-utils.js +1 -1
  8. package/cjs/common/path-svg.js +1 -1
  9. package/cjs/common/polygon.js +2 -2
  10. package/cjs/common/rect-utils.js +1 -1
  11. package/cjs/common/render-area.js +2 -1
  12. package/cjs/common/render-command-list.js +1 -1
  13. package/cjs/common/render-curve.js +1 -1
  14. package/cjs/common/render-utils.js +1 -1
  15. package/cjs/common/seg-context.js +1 -1
  16. package/cjs/common/simplify.js +1 -1
  17. package/cjs/common/sort.js +1 -1
  18. package/cjs/common/split-path.js +1 -1
  19. package/cjs/core/application.js +1 -1
  20. package/cjs/core/camera.js +1 -1
  21. package/cjs/core/constants.js +1 -1
  22. package/cjs/core/core-modules.js +1 -1
  23. package/cjs/core/global-module.js +0 -2
  24. package/cjs/core/global.js +1 -1
  25. package/cjs/core/graphic-utils.js +1 -1
  26. package/cjs/core/index.js +1 -1
  27. package/cjs/core/layer-service.js +1 -1
  28. package/cjs/core/layer.js +1 -1
  29. package/cjs/core/light.js +1 -1
  30. package/cjs/core/stage.js +1 -1
  31. package/cjs/core/window.js +1 -1
  32. package/cjs/plugins/builtin-plugin/edit-module.js +5 -4
  33. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  34. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +4 -4
  35. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  36. package/dist/index.es.js +6 -5
  37. package/es/animate/custom-animate.js +2 -1
  38. package/es/animate/timeline.js +1 -2
  39. package/es/canvas/empty-context.js +1 -2
  40. package/es/color-string/store.js +2 -1
  41. package/es/common/bezier-utils.js +1 -2
  42. package/es/common/matrix.js +1 -1
  43. package/es/common/morphing-utils.js +1 -1
  44. package/es/common/path-svg.js +1 -1
  45. package/es/common/polygon.js +1 -1
  46. package/es/common/rect-utils.js +1 -1
  47. package/es/common/render-area.js +2 -1
  48. package/es/common/render-command-list.js +1 -1
  49. package/es/common/render-curve.js +1 -1
  50. package/es/common/render-utils.js +1 -1
  51. package/es/common/seg-context.js +1 -1
  52. package/es/common/simplify.js +1 -1
  53. package/es/common/sort.js +1 -1
  54. package/es/common/split-path.js +1 -1
  55. package/es/core/application.js +1 -1
  56. package/es/core/camera.js +1 -1
  57. package/es/core/constants.js +1 -1
  58. package/es/core/core-modules.js +1 -1
  59. package/es/core/global-module.js +0 -2
  60. package/es/core/global.js +1 -1
  61. package/es/core/graphic-utils.js +1 -1
  62. package/es/core/index.js +1 -1
  63. package/es/core/layer-service.js +1 -1
  64. package/es/core/layer.js +1 -1
  65. package/es/core/light.js +1 -1
  66. package/es/core/stage.js +1 -1
  67. package/es/core/window.js +1 -1
  68. package/es/plugins/builtin-plugin/edit-module.js +5 -4
  69. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  70. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +4 -4
  71. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  72. package/package.json +1 -1
@@ -719,4 +719,5 @@ class AnimateGroup1 extends animate_1.ACustomAnimate {
719
719
  }
720
720
  }
721
721
 
722
- exports.AnimateGroup1 = AnimateGroup1;
722
+ exports.AnimateGroup1 = AnimateGroup1;
723
+ //# sourceMappingURL=custom-animate.js.map
@@ -42,5 +42,4 @@ class DefaultTimeline {
42
42
  }
43
43
  }
44
44
 
45
- exports.DefaultTimeline = DefaultTimeline, exports.defaultTimeline = new DefaultTimeline;
46
- //# sourceMappingURL=timeline.js.map
45
+ exports.DefaultTimeline = DefaultTimeline, exports.defaultTimeline = new DefaultTimeline;
@@ -209,5 +209,4 @@ let EmptyContext2d = class {
209
209
  };
210
210
 
211
211
  EmptyContext2d = __decorate([ (0, inversify_lite_1.injectable)(), __metadata("design:paramtypes", [ Object, Number ]) ], EmptyContext2d),
212
- exports.EmptyContext2d = EmptyContext2d;
213
- //# sourceMappingURL=empty-context.js.map
212
+ exports.EmptyContext2d = EmptyContext2d;
@@ -50,4 +50,5 @@ class ColorStore {
50
50
  }
51
51
  }
52
52
 
53
- exports.ColorStore = ColorStore, ColorStore.store255 = {}, ColorStore.store1 = {};
53
+ exports.ColorStore = ColorStore, ColorStore.store255 = {}, ColorStore.store1 = {};
54
+ //# sourceMappingURL=store.js.map
@@ -46,5 +46,4 @@ function quadLength(p0, p1, p2, iterationCount) {
46
46
 
47
47
  exports.snapLength = snapLength, exports.cubicLength = cubicLength, exports.cubicCalc = cubicCalc,
48
48
  exports.cubicPointAt = cubicPointAt, exports.quadCalc = quadCalc, exports.quadPointAt = quadPointAt,
49
- exports.quadLength = quadLength;
50
- //# sourceMappingURL=bezier-utils.js.map
49
+ exports.quadLength = quadLength;
@@ -129,4 +129,4 @@ exports.identityMat4 = identityMat4, exports.rotateX = rotateX, exports.rotateY
129
129
  exports.rotateZ = rotateZ, exports.translate = translate, exports.mat3Tomat4 = mat3Tomat4,
130
130
  exports.multiplyMat4Mat3 = multiplyMat4Mat3, exports.scaleMat4 = scaleMat4, exports.multiplyMat4Mat4 = multiplyMat4Mat4,
131
131
  exports.lookAt = lookAt, exports.ortho = ortho, exports.transformMat4 = transformMat4;
132
- //# sourceMappingURL=matrix.js.map
132
+ //# sourceMappingURL=matrix.js.map
@@ -292,4 +292,4 @@ function bezierCurversToPath(bezierCurves) {
292
292
 
293
293
  exports.pathToBezierCurves = pathToBezierCurves, exports.applyTransformOnBezierCurves = applyTransformOnBezierCurves,
294
294
  exports.bezierCurversToPath = bezierCurversToPath;
295
- //# sourceMappingURL=morphing-utils.js.map
295
+ //# sourceMappingURL=morphing-utils.js.map
@@ -61,4 +61,4 @@ exports.enumCommandMap = {
61
61
  Q: 7,
62
62
  R: 8
63
63
  }, exports.parseSvgPath = parseSvgPath;
64
- //# sourceMappingURL=path-svg.js.map
64
+ //# sourceMappingURL=path-svg.js.map
@@ -39,8 +39,8 @@ function getProportionPoint(point, segment, length, dx, dy) {
39
39
  };
40
40
  }
41
41
 
42
- //# sourceMappingURL=polygon.js.map
43
42
  Object.defineProperty(exports, "__esModule", {
44
43
  value: !0
45
44
  }), exports.drawRoundedPolygon = exports.drawPolygon = void 0, exports.drawPolygon = drawPolygon,
46
- exports.drawRoundedPolygon = drawRoundedPolygon;
45
+ exports.drawRoundedPolygon = drawRoundedPolygon;
46
+ //# sourceMappingURL=polygon.js.map
@@ -24,4 +24,4 @@ const vutils_1 = require("@visactor/vutils"), normalizeRectAttributes = attribut
24
24
  };
25
25
 
26
26
  exports.normalizeRectAttributes = normalizeRectAttributes;
27
- //# sourceMappingURL=rect-utils.js.map
27
+ //# sourceMappingURL=rect-utils.js.map
@@ -61,4 +61,5 @@ function drawAreaBlock(path, topList, bottomList, params) {
61
61
  path.closePath();
62
62
  }
63
63
 
64
- exports.drawAreaSegments = drawAreaSegments;
64
+ exports.drawAreaSegments = drawAreaSegments;
65
+ //# sourceMappingURL=render-area.js.map
@@ -14,4 +14,4 @@ function renderCommandList(commandList, context, x = 0, y = 0, sx = 1, sy = 1, z
14
14
  }
15
15
 
16
16
  exports.renderCommandList = renderCommandList;
17
- //# sourceMappingURL=render-command-list.js.map
17
+ //# sourceMappingURL=render-command-list.js.map
@@ -99,4 +99,4 @@ function drawIncrementalAreaSegments(path, lastSeg, segments, params) {
99
99
 
100
100
  exports.drawSegments = drawSegments, exports.drawIncrementalSegments = drawIncrementalSegments,
101
101
  exports.drawIncrementalAreaSegments = drawIncrementalAreaSegments;
102
- //# sourceMappingURL=render-curve.js.map
102
+ //# sourceMappingURL=render-curve.js.map
@@ -19,4 +19,4 @@ function drawSegItem(ctx, curve, endPercent, params) {
19
19
  }
20
20
 
21
21
  exports.drawSegItem = drawSegItem;
22
- //# sourceMappingURL=render-utils.js.map
22
+ //# sourceMappingURL=render-utils.js.map
@@ -95,4 +95,4 @@ class ReflectSegContext extends SegContext {
95
95
  }
96
96
 
97
97
  exports.ReflectSegContext = ReflectSegContext;
98
- //# sourceMappingURL=seg-context.js.map
98
+ //# sourceMappingURL=seg-context.js.map
@@ -36,4 +36,4 @@ function flatten_simplify(points, tolerance, highestQuality) {
36
36
  Object.defineProperty(exports, "__esModule", {
37
37
  value: !0
38
38
  }), exports.flatten_simplify = void 0, exports.flatten_simplify = flatten_simplify;
39
- //# sourceMappingURL=simplify.js.map
39
+ //# sourceMappingURL=simplify.js.map
@@ -101,4 +101,4 @@ Object.defineProperty(exports, "__esModule", {
101
101
  value: !0
102
102
  }), exports.findNextGraphic = exports.foreachAsync = exports.foreach = void 0, exports.foreach = foreach,
103
103
  exports.foreachAsync = foreachAsync, exports.findNextGraphic = findNextGraphic;
104
- //# sourceMappingURL=sort.js.map
104
+ //# sourceMappingURL=sort.js.map
@@ -269,4 +269,4 @@ const splitPath = (path, count) => {
269
269
  };
270
270
 
271
271
  exports.splitPath = splitPath;
272
- //# sourceMappingURL=split-path.js.map
272
+ //# sourceMappingURL=split-path.js.map
@@ -3,4 +3,4 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: !0
5
5
  }), exports.ApplicationContribution = void 0, exports.ApplicationContribution = Symbol("ApplicationContribution");
6
- //# sourceMappingURL=application.js.map
6
+ //# sourceMappingURL=application.js.map
@@ -71,4 +71,4 @@ const registerOrthoCamera = () => {
71
71
  };
72
72
 
73
73
  exports.registerOrthoCamera = registerOrthoCamera;
74
- //# sourceMappingURL=camera.js.map
74
+ //# sourceMappingURL=camera.js.map
@@ -7,4 +7,4 @@ exports.TransformUtil = Symbol.for("TransformUtil"), exports.GraphicUtil = Symbo
7
7
  exports.LayerService = Symbol.for("LayerService"), exports.StaticLayerHandlerContribution = Symbol.for("StaticLayerHandlerContribution"),
8
8
  exports.DynamicLayerHandlerContribution = Symbol.for("DynamicLayerHandlerContribution"),
9
9
  exports.VirtualLayerHandlerContribution = Symbol.for("VirtualLayerHandlerContribution");
10
- //# sourceMappingURL=constants.js.map
10
+ //# sourceMappingURL=constants.js.map
@@ -12,4 +12,4 @@ exports.default = new inversify_lite_1.ContainerModule((bind => {
12
12
  bind(constants_1.TransformUtil).to(graphic_utils_1.DefaultTransformUtil).inSingletonScope(),
13
13
  bind(constants_1.LayerService).to(layer_service_1.DefaultLayerService).inSingletonScope();
14
14
  }));
15
- //# sourceMappingURL=core-modules.js.map
15
+ //# sourceMappingURL=core-modules.js.map
@@ -1,3 +1 @@
1
-
2
-
3
1
  //# sourceMappingURL=global-module.js.map
@@ -220,4 +220,4 @@ DefaultGlobal = __decorate([ (0, inversify_lite_1.injectable)(), __param(0, (0,
220
220
  inversify_lite_1.inject)(contribution_provider_1.ContributionProvider)), __param(0, (0,
221
221
  inversify_lite_1.named)(constants_1.EnvContribution)), __metadata("design:paramtypes", [ Object ]) ], DefaultGlobal),
222
222
  exports.DefaultGlobal = DefaultGlobal;
223
- //# sourceMappingURL=global.js.map
223
+ //# sourceMappingURL=global.js.map
@@ -172,4 +172,4 @@ let DefaultTransformUtil = class {
172
172
 
173
173
  DefaultTransformUtil = __decorate([ (0, inversify_lite_1.injectable)(), __metadata("design:paramtypes", []) ], DefaultTransformUtil),
174
174
  exports.DefaultTransformUtil = DefaultTransformUtil;
175
- //# sourceMappingURL=graphic-utils.js.map
175
+ //# sourceMappingURL=graphic-utils.js.map
package/cjs/core/index.js CHANGED
@@ -22,4 +22,4 @@ __exportStar(require("./layer"), exports), __exportStar(require("./stage"), expo
22
22
  __exportStar(require("./graphic-utils"), exports), __exportStar(require("./contributions"), exports),
23
23
  __exportStar(require("./layer-service"), exports), __exportStar(require("./constants"), exports),
24
24
  __exportStar(require("../interface/core"), exports);
25
- //# sourceMappingURL=index.js.map
25
+ //# sourceMappingURL=index.js.map
@@ -80,4 +80,4 @@ let DefaultLayerService = DefaultLayerService_1 = class {
80
80
  DefaultLayerService.idprefix = "visactor_layer", DefaultLayerService.prefix_count = 0,
81
81
  DefaultLayerService = DefaultLayerService_1 = __decorate([ (0, inversify_lite_1.injectable)(), __metadata("design:paramtypes", []) ], DefaultLayerService),
82
82
  exports.DefaultLayerService = DefaultLayerService;
83
- //# sourceMappingURL=layer-service.js.map
83
+ //# sourceMappingURL=layer-service.js.map
package/cjs/core/layer.js CHANGED
@@ -116,4 +116,4 @@ class Layer extends group_1.Group {
116
116
  }
117
117
 
118
118
  exports.Layer = Layer;
119
- //# sourceMappingURL=layer.js.map
119
+ //# sourceMappingURL=layer.js.map
package/cjs/core/light.js CHANGED
@@ -29,4 +29,4 @@ const registerDirectionalLight = () => {
29
29
  };
30
30
 
31
31
  exports.registerDirectionalLight = registerDirectionalLight;
32
- //# sourceMappingURL=light.js.map
32
+ //# sourceMappingURL=light.js.map
package/cjs/core/stage.js CHANGED
@@ -516,4 +516,4 @@ class Stage extends group_1.Group {
516
516
  }
517
517
 
518
518
  exports.Stage = Stage;
519
- //# sourceMappingURL=stage.js.map
519
+ //# sourceMappingURL=stage.js.map
@@ -153,4 +153,4 @@ let DefaultWindow = class {
153
153
 
154
154
  DefaultWindow = __decorate([ (0, inversify_lite_1.injectable)(), __metadata("design:paramtypes", []) ], DefaultWindow),
155
155
  exports.DefaultWindow = DefaultWindow;
156
- //# sourceMappingURL=window.js.map
156
+ //# sourceMappingURL=window.js.map
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", {
17
17
  const application_1 = require("../../application");
18
18
 
19
19
  function getDefaultCharacterConfig(attribute) {
20
- const {fill: fill = "black", stroke: stroke = !1, fontWeight: fontWeight = "normal", lineHeight: lineHeight, fontFamily: fontFamily = "Arial"} = attribute;
20
+ const {fill: fill = "black", stroke: stroke = !1, fontWeight: fontWeight = "normal", lineHeight: lineHeight, fontFamily: fontFamily = "Arial", textAlign: textAlign} = attribute;
21
21
  let {fontSize: fontSize = 12} = attribute;
22
22
  return isFinite(fontSize) || (fontSize = 12), {
23
23
  fill: fill,
@@ -25,7 +25,8 @@ function getDefaultCharacterConfig(attribute) {
25
25
  fontSize: fontSize,
26
26
  fontWeight: fontWeight,
27
27
  fontFamily: fontFamily,
28
- lineHeight: lineHeight
28
+ lineHeight: lineHeight,
29
+ textAlign: textAlign
29
30
  };
30
31
  }
31
32
 
@@ -80,9 +81,9 @@ class EditModule {
80
81
  }));
81
82
  } else {
82
83
  const configIdx = this.composingConfigIdx, lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];
83
- textConfig.splice(configIdx, 0, Object.assign(Object.assign({
84
+ textConfig.splice(configIdx, 0, Object.assign(Object.assign(Object.assign({
84
85
  fill: "black"
85
- }, lastConfig), {
86
+ }, getDefaultCharacterConfig(this.currRt.attribute)), lastConfig), {
86
87
  text: ""
87
88
  }));
88
89
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mDAAgD;AAmBhD,SAAgB,yBAAyB,CAAC,SAAoC;IAC5E,MAAM,EAAE,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,GAAG,QAAQ,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC;IAC9G,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACvB,QAAQ,GAAG,EAAE,CAAC;KACf;IACD,OAAO;QACL,IAAI;QACJ,MAAM;QACN,QAAQ;QACR,UAAU;QACV,UAAU;QACV,UAAU;KACJ,CAAC;AACX,CAAC;AAdD,8DAcC;AAQD,SAAgB,0BAA0B,CAAC,UAAgC,EAAE,WAAmB;IAC9F,IAAI,WAAW,GAAG,CAAC,EAAE;QACnB,OAAO,CAAC,CAAC;KACV;IAGD,MAAM,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AC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC;QACtC,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;IACzD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACnE,yBAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF;AAnRD,gCAmRC","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type {\n IRichText,\n IRichTextCharacter,\n IRichTextGraphicAttribute,\n IRichTextParagraphCharacter\n} from '../../interface';\n\n// function getMaxConfigIndexIgnoreLinebreak(textConfig: IRichTextCharacter[]) {\n// let idx = 0;\n// for (let i = 0; i < textConfig.length; i++) {\n// const c = textConfig[i] as IRichTextParagraphCharacter;\n// if (c.text !== '\\n') {\n// idx++;\n// }\n// }\n// return Math.max(idx - 1, 0);\n// }\n\nexport function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute) {\n const { fill = 'black', stroke = false, fontWeight = 'normal', lineHeight, fontFamily = 'Arial' } = attribute;\n let { fontSize = 12 } = attribute;\n if (!isFinite(fontSize)) {\n fontSize = 12;\n }\n return {\n fill,\n stroke,\n fontSize,\n fontWeight,\n fontFamily,\n lineHeight\n } as any;\n}\n\n/**\n * 找到cursorIndex所在的textConfig的位置,给出的index就是要插入的准确位置\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndexByCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n if (cursorIndex < 0) {\n return 0;\n }\n\n // 排序找到对应的元素\n const intCursorIndex = Math.round(cursorIndex);\n let tempCursorIndex = intCursorIndex;\n // 跳过连续换行符中的第一个换行符\n let lineBreak = false;\n let configIdx = 0;\n for (configIdx = 0; configIdx < textConfig.length && tempCursorIndex >= 0; configIdx++) {\n const c = textConfig[configIdx] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n tempCursorIndex -= Number(lineBreak);\n lineBreak = true;\n } else {\n tempCursorIndex--;\n lineBreak = false;\n }\n }\n // 说明过限了\n if (tempCursorIndex >= 0) {\n return textConfig.length;\n }\n configIdx -= 1;\n\n // 如果有换行,一定在换行符左边写\n if (cursorIndex > intCursorIndex && !lineBreak) {\n configIdx += 1;\n }\n return configIdx;\n}\n\n/**\n * 根据configIndex找到cursorIndex的位置,忽略单个换行符,连续换行符的时候只忽略第一个\n * @param textConfig\n * @param configIndex\n * @returns\n */\nexport function findCursorIdxByConfigIndex(textConfig: IRichTextCharacter[], configIndex: number): number {\n let cursorIndex = 0;\n if (configIndex < 0) {\n return -0.1;\n }\n // 仅有一个\\n,那不算\n // 如果有连续的\\n,那就少算一个\n let lastLineBreak = false;\n\n for (let i = 0; i <= configIndex && i < textConfig.length; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n cursorIndex += Number(lastLineBreak);\n lastLineBreak = true;\n } else {\n cursorIndex++;\n lastLineBreak = false;\n }\n }\n cursorIndex = Math.max(cursorIndex - 1, 0);\n\n // 超出区间了直接设置到尾部,configIndex超过区间,cursorIndex不会超过\n if (configIndex > textConfig.length - 1) {\n // 如果最后一行是一个换行符,那么就得是xx.9否则就是xx.1\n if ((textConfig[textConfig.length - 1] as any)?.text === '\\n') {\n return cursorIndex + 0.9;\n }\n return cursorIndex + 0.1;\n }\n\n // 如果是这个configIdx对应到的是单个换行的话,那么算到下一个字符上\n const lineBreak = (textConfig[configIndex] as any)?.text === '\\n';\n if (configIndex >= textConfig.length - 1 && lineBreak) {\n return cursorIndex + 1 - 0.1;\n }\n const singleLineBreak = lineBreak && (textConfig[configIndex - 1] as any)?.text !== '\\n';\n\n // 光标往左放\n cursorIndex -= 0.1;\n\n // 如果是单行,那么这一个换行符没有算字符,光标要往右放\n if (singleLineBreak) {\n cursorIndex += 0.2;\n }\n return cursorIndex;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n composingConfigIdx: number;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n onFocusInList: Array<() => void>;\n onFocusOutList: Array<() => void>;\n focusOutTimer: number;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.composingConfigIdx = -1;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n this.onFocusInList = [];\n this.onFocusOutList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onChangeCbList.push(cb);\n }\n\n onFocusIn(cb: () => void) {\n this.onFocusInList.push(cb);\n }\n\n onFocusOut(cb: () => void) {\n this.onFocusOutList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n // 监听焦点\n textAreaDom.addEventListener('focusin', this.handleFocusIn);\n textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleFocusIn = () => {\n // this.focusOutTimer && clearTimeout(this.focusOutTimer);\n // this.focusOutTimer = 0;\n // this.onFocusInList && this.onFocusInList.forEach(cb => cb());\n };\n handleFocusOut = () => {\n // 暂时注释,会导致非期待情况下的误关闭\n // // 延时触发,避免误关闭\n // this.focusOutTimer = setTimeout(() => {\n // this.onFocusOutList && this.onFocusOutList.forEach(cb => cb());\n // }, 100);\n };\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n this.isComposing = true;\n const { textConfig = [] } = this.currRt.attribute;\n this.composingConfigIdx = this.cursorIndex < 0 ? 0 : findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ fill: 'black', ...getDefaultCharacterConfig(this.currRt.attribute), ...config, text: '' });\n } else {\n const configIdx = this.composingConfigIdx;\n const lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];\n textConfig.splice(configIdx, 0, { fill: 'black', ...lastConfig, text: '' });\n }\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n\n const text = this.parseCompositionStr(this.composingConfigIdx);\n // 拆分上一次的内容\n // const { textConfig = [] } = this.currRt.attribute;\n // const configIdx = this.composingConfigIdx;\n\n // const lastConfig = textConfig[configIdx];\n // textConfig.splice(configIdx, 1);\n // const text = (lastConfig as any).text;\n // const textList: string[] = text ? Array.from(text.toString()) : [];\n // for (let i = 0; i < textList.length; i++) {\n // textConfig.splice(i + configIdx, 0, { ...lastConfig, isComposing: false, text: textList[i] } as any);\n // }\n // this.currRt.setAttributes({ textConfig });\n // const nextConfigIdx = configIdx + textList.length;\n // this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n this.composingConfigIdx = -1;\n\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n this.cursorIndex,\n this.currRt\n );\n });\n };\n\n /**\n * 复合输入以及粘贴,都会复制出一大段内容,这时候需要重新处理textConfig和cursorIndex\n * 1. 拆分text到textConfig\n * 2. 计算新的cursorIndex\n * @param configIdx\n */\n parseCompositionStr(configIdx: number) {\n const { textConfig = [] } = this.currRt.attribute;\n\n const lastConfig = textConfig[configIdx] ?? {};\n textConfig.splice(configIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = text ? Array.from(text.toString()) : [];\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + configIdx, 0, {\n fill: 'black',\n ...lastConfig,\n isComposing: false,\n text: textList[i]\n } as any);\n }\n this.currRt.setAttributes({ textConfig });\n const nextConfigIdx = configIdx + textList.length;\n this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n return text;\n }\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n if (ev.inputType === 'historyUndo') {\n return;\n }\n const { textConfig = [], ...rest } = this.currRt.attribute;\n // 删完了,直接返回\n if (ev.type === 'Backspace' && !textConfig.length) {\n return;\n }\n\n let str = (ev as any).data;\n if (!this.isComposing && ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n\n // 处理正反选\n if (this.selectionStartCursorIdx > this.cursorIndex) {\n [this.cursorIndex, this.selectionStartCursorIdx] = [this.selectionStartCursorIdx, this.cursorIndex];\n }\n\n const startIdx = findConfigIndexByCursorIdx(textConfig, this.selectionStartCursorIdx);\n const endIdx = findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n\n // composing的话会插入一个字符,所以往右加一个\n const lastConfigIdx = this.isComposing ? this.composingConfigIdx : Math.max(startIdx - 1, 0);\n // 算一个默认属性\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n lastConfig = getDefaultCharacterConfig(rest);\n }\n let nextConfig = lastConfig;\n\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx, endIdx - startIdx);\n if (this.isComposing) {\n this.composingConfigIdx = startIdx;\n }\n }\n\n let nextConfigIdx = startIdx;\n\n // 删除键\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx === endIdx) {\n if (startIdx <= 0) {\n return;\n }\n // 删除\n textConfig.splice(startIdx - 1, 1);\n nextConfigIdx = Math.max(startIdx - 1, 0);\n } else {\n // 不插入内容\n }\n } else {\n // 插入\n if (!this.isComposing) {\n nextConfig = { fill: 'black', ...lastConfig, text: '' };\n textConfig.splice(startIdx, 0, nextConfig);\n nextConfigIdx++;\n }\n // 插入\n nextConfig.text = str;\n // 标记isComposing,用来判定是否应该拆分成单个字符\n nextConfig.isComposing = this.isComposing;\n }\n\n this.currRt.setAttributes({ textConfig });\n // 重新计算cursorIdx\n // nextConfigIdx = Math.min(nextConfigIdx, textConfig.length - 1);\n\n let cursorIndex = this.cursorIndex;\n if (str && str.length > 1 && !this.isComposing) {\n // 如果字符长度大于1且不是composing,那说明是粘贴\n // 拆分\n this.parseCompositionStr(nextConfigIdx - 1);\n cursorIndex = this.cursorIndex;\n } else {\n // composing的时候不偏移,只有完整输入后才偏移\n cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n if (!this.isComposing) {\n this.cursorIndex = cursorIndex;\n } else {\n this.cursorIndex = this.selectionStartCursorIdx;\n }\n }\n\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n this.textAreaDom.addEventListener('focusin', this.handleFocusOut);\n this.textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mDAAgD;AAmBhD,SAAgB,yBAAyB,CAAC,SAAoC;IAC5E,MAAM,EACJ,IAAI,GAAG,OAAO,EACd,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,QAAQ,EACrB,UAAU,EACV,UAAU,GAAG,OAAO,EACpB,SAAS,EACV,GAAG,SAAS,CAAC;IACd,IAAI,EAAE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AAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACnE,yBAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF;AAxRD,gCAwRC","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type {\n IRichText,\n IRichTextCharacter,\n IRichTextGraphicAttribute,\n IRichTextParagraphCharacter\n} from '../../interface';\n\n// function getMaxConfigIndexIgnoreLinebreak(textConfig: IRichTextCharacter[]) {\n// let idx = 0;\n// for (let i = 0; i < textConfig.length; i++) {\n// const c = textConfig[i] as IRichTextParagraphCharacter;\n// if (c.text !== '\\n') {\n// idx++;\n// }\n// }\n// return Math.max(idx - 1, 0);\n// }\n\nexport function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute) {\n const {\n fill = 'black',\n stroke = false,\n fontWeight = 'normal',\n lineHeight,\n fontFamily = 'Arial',\n textAlign\n } = attribute;\n let { fontSize = 12 } = attribute;\n if (!isFinite(fontSize)) {\n fontSize = 12;\n }\n return {\n fill,\n stroke,\n fontSize,\n fontWeight,\n fontFamily,\n lineHeight,\n textAlign\n } as any;\n}\n\n/**\n * 找到cursorIndex所在的textConfig的位置,给出的index就是要插入的准确位置\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndexByCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n if (cursorIndex < 0) {\n return 0;\n }\n\n // 排序找到对应的元素\n const intCursorIndex = Math.round(cursorIndex);\n let tempCursorIndex = intCursorIndex;\n // 跳过连续换行符中的第一个换行符\n let lineBreak = false;\n let configIdx = 0;\n for (configIdx = 0; configIdx < textConfig.length && tempCursorIndex >= 0; configIdx++) {\n const c = textConfig[configIdx] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n tempCursorIndex -= Number(lineBreak);\n lineBreak = true;\n } else {\n tempCursorIndex--;\n lineBreak = false;\n }\n }\n // 说明过限了\n if (tempCursorIndex >= 0) {\n return textConfig.length;\n }\n configIdx -= 1;\n\n // 如果有换行,一定在换行符左边写\n if (cursorIndex > intCursorIndex && !lineBreak) {\n configIdx += 1;\n }\n return configIdx;\n}\n\n/**\n * 根据configIndex找到cursorIndex的位置,忽略单个换行符,连续换行符的时候只忽略第一个\n * @param textConfig\n * @param configIndex\n * @returns\n */\nexport function findCursorIdxByConfigIndex(textConfig: IRichTextCharacter[], configIndex: number): number {\n let cursorIndex = 0;\n if (configIndex < 0) {\n return -0.1;\n }\n // 仅有一个\\n,那不算\n // 如果有连续的\\n,那就少算一个\n let lastLineBreak = false;\n\n for (let i = 0; i <= configIndex && i < textConfig.length; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n cursorIndex += Number(lastLineBreak);\n lastLineBreak = true;\n } else {\n cursorIndex++;\n lastLineBreak = false;\n }\n }\n cursorIndex = Math.max(cursorIndex - 1, 0);\n\n // 超出区间了直接设置到尾部,configIndex超过区间,cursorIndex不会超过\n if (configIndex > textConfig.length - 1) {\n // 如果最后一行是一个换行符,那么就得是xx.9否则就是xx.1\n if ((textConfig[textConfig.length - 1] as any)?.text === '\\n') {\n return cursorIndex + 0.9;\n }\n return cursorIndex + 0.1;\n }\n\n // 如果是这个configIdx对应到的是单个换行的话,那么算到下一个字符上\n const lineBreak = (textConfig[configIndex] as any)?.text === '\\n';\n if (configIndex >= textConfig.length - 1 && lineBreak) {\n return cursorIndex + 1 - 0.1;\n }\n const singleLineBreak = lineBreak && (textConfig[configIndex - 1] as any)?.text !== '\\n';\n\n // 光标往左放\n cursorIndex -= 0.1;\n\n // 如果是单行,那么这一个换行符没有算字符,光标要往右放\n if (singleLineBreak) {\n cursorIndex += 0.2;\n }\n return cursorIndex;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n composingConfigIdx: number;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n onFocusInList: Array<() => void>;\n onFocusOutList: Array<() => void>;\n focusOutTimer: number;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.composingConfigIdx = -1;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n this.onFocusInList = [];\n this.onFocusOutList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onChangeCbList.push(cb);\n }\n\n onFocusIn(cb: () => void) {\n this.onFocusInList.push(cb);\n }\n\n onFocusOut(cb: () => void) {\n this.onFocusOutList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n // 监听焦点\n textAreaDom.addEventListener('focusin', this.handleFocusIn);\n textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleFocusIn = () => {\n // this.focusOutTimer && clearTimeout(this.focusOutTimer);\n // this.focusOutTimer = 0;\n // this.onFocusInList && this.onFocusInList.forEach(cb => cb());\n };\n handleFocusOut = () => {\n // 暂时注释,会导致非期待情况下的误关闭\n // // 延时触发,避免误关闭\n // this.focusOutTimer = setTimeout(() => {\n // this.onFocusOutList && this.onFocusOutList.forEach(cb => cb());\n // }, 100);\n };\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n this.isComposing = true;\n const { textConfig = [] } = this.currRt.attribute;\n this.composingConfigIdx = this.cursorIndex < 0 ? 0 : findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ fill: 'black', ...getDefaultCharacterConfig(this.currRt.attribute), ...config, text: '' });\n } else {\n const configIdx = this.composingConfigIdx;\n const lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];\n textConfig.splice(configIdx, 0, {\n fill: 'black',\n ...getDefaultCharacterConfig(this.currRt.attribute),\n ...lastConfig,\n text: ''\n });\n }\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n\n const text = this.parseCompositionStr(this.composingConfigIdx);\n // 拆分上一次的内容\n // const { textConfig = [] } = this.currRt.attribute;\n // const configIdx = this.composingConfigIdx;\n\n // const lastConfig = textConfig[configIdx];\n // textConfig.splice(configIdx, 1);\n // const text = (lastConfig as any).text;\n // const textList: string[] = text ? Array.from(text.toString()) : [];\n // for (let i = 0; i < textList.length; i++) {\n // textConfig.splice(i + configIdx, 0, { ...lastConfig, isComposing: false, text: textList[i] } as any);\n // }\n // this.currRt.setAttributes({ textConfig });\n // const nextConfigIdx = configIdx + textList.length;\n // this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n this.composingConfigIdx = -1;\n\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n this.cursorIndex,\n this.currRt\n );\n });\n };\n\n /**\n * 复合输入以及粘贴,都会复制出一大段内容,这时候需要重新处理textConfig和cursorIndex\n * 1. 拆分text到textConfig\n * 2. 计算新的cursorIndex\n * @param configIdx\n */\n parseCompositionStr(configIdx: number) {\n const { textConfig = [] } = this.currRt.attribute;\n\n const lastConfig = textConfig[configIdx] ?? {};\n textConfig.splice(configIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = text ? Array.from(text.toString()) : [];\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + configIdx, 0, {\n fill: 'black',\n ...lastConfig,\n isComposing: false,\n text: textList[i]\n } as any);\n }\n this.currRt.setAttributes({ textConfig });\n const nextConfigIdx = configIdx + textList.length;\n this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n return text;\n }\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n if (ev.inputType === 'historyUndo') {\n return;\n }\n const { textConfig = [], ...rest } = this.currRt.attribute;\n // 删完了,直接返回\n if (ev.type === 'Backspace' && !textConfig.length) {\n return;\n }\n\n let str = (ev as any).data;\n if (!this.isComposing && ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n\n // 处理正反选\n if (this.selectionStartCursorIdx > this.cursorIndex) {\n [this.cursorIndex, this.selectionStartCursorIdx] = [this.selectionStartCursorIdx, this.cursorIndex];\n }\n\n const startIdx = findConfigIndexByCursorIdx(textConfig, this.selectionStartCursorIdx);\n const endIdx = findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n\n // composing的话会插入一个字符,所以往右加一个\n const lastConfigIdx = this.isComposing ? this.composingConfigIdx : Math.max(startIdx - 1, 0);\n // 算一个默认属性\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n lastConfig = getDefaultCharacterConfig(rest);\n }\n let nextConfig = lastConfig;\n\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx, endIdx - startIdx);\n if (this.isComposing) {\n this.composingConfigIdx = startIdx;\n }\n }\n\n let nextConfigIdx = startIdx;\n\n // 删除键\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx === endIdx) {\n if (startIdx <= 0) {\n return;\n }\n // 删除\n textConfig.splice(startIdx - 1, 1);\n nextConfigIdx = Math.max(startIdx - 1, 0);\n } else {\n // 不插入内容\n }\n } else {\n // 插入\n if (!this.isComposing) {\n nextConfig = { fill: 'black', ...lastConfig, text: '' };\n textConfig.splice(startIdx, 0, nextConfig);\n nextConfigIdx++;\n }\n // 插入\n nextConfig.text = str;\n // 标记isComposing,用来判定是否应该拆分成单个字符\n nextConfig.isComposing = this.isComposing;\n }\n\n this.currRt.setAttributes({ textConfig });\n // 重新计算cursorIdx\n // nextConfigIdx = Math.min(nextConfigIdx, textConfig.length - 1);\n\n let cursorIndex = this.cursorIndex;\n if (str && str.length > 1 && !this.isComposing) {\n // 如果字符长度大于1且不是composing,那说明是粘贴\n // 拆分\n this.parseCompositionStr(nextConfigIdx - 1);\n cursorIndex = this.cursorIndex;\n } else {\n // composing的时候不偏移,只有完整输入后才偏移\n cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n if (!this.isComposing) {\n this.cursorIndex = cursorIndex;\n } else {\n this.cursorIndex = this.selectionStartCursorIdx;\n }\n }\n\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n this.textAreaDom.addEventListener('focusin', this.handleFocusOut);\n this.textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
@@ -275,6 +275,7 @@ class RichTextEditPlugin {
275
275
  if (!this.currRt || !this.focusing) return;
276
276
  const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
277
277
  if (!editOptions || !boundsStrokeWhenInput) return;
278
+ this.offsetShadowRoot();
278
279
  const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
279
280
  this.shadowBounds = this.shadowBounds || (0, graphic_1.createRect)({}), this.shadowBounds.setAttributes({
280
281
  x: 0,
@@ -287,8 +288,7 @@ class RichTextEditPlugin {
287
288
  zIndex: -1
288
289
  });
289
290
  const shadow = this.getShadow(this.currRt);
290
- this.addEditLineOrBgOrBounds(this.shadowBounds, shadow), this.offsetLineBgAndShadowBounds(),
291
- this.offsetShadowRoot();
291
+ this.addEditLineOrBgOrBounds(this.shadowBounds, shadow), this.offsetLineBgAndShadowBounds();
292
292
  }
293
293
  trySyncPlaceholderToTextConfig() {
294
294
  if (!this.currRt) return;
@@ -532,8 +532,8 @@ class RichTextEditPlugin {
532
532
  getShadow(rt) {
533
533
  const sr = rt.shadowRoot || rt.attachShadow();
534
534
  return sr.setAttributes({
535
- width: 1,
536
- height: 1
535
+ width: 0,
536
+ height: 0
537
537
  }), sr;
538
538
  }
539
539
  getLineByPoint(cache, p1) {