@visactor/vrender-core 0.21.7 → 0.22.0-vstory.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/animate/Ticker/default-ticker.d.ts +2 -0
- package/cjs/animate/Ticker/default-ticker.js +7 -1
- package/cjs/animate/Ticker/default-ticker.js.map +1 -1
- package/cjs/animate/animate.js +1 -1
- package/cjs/animate/animate.js.map +1 -1
- package/cjs/animate/custom-animate.js +14 -25
- package/cjs/animate/custom-animate.js.map +1 -1
- package/cjs/animate/easing-func.d.ts +1 -0
- package/cjs/animate/easing-func.js +16 -0
- package/cjs/animate/easing-func.js.map +1 -0
- package/cjs/animate/easing.d.ts +4 -0
- package/cjs/animate/easing.js +24 -1
- package/cjs/animate/easing.js.map +1 -1
- package/cjs/animate/index.d.ts +1 -0
- package/cjs/animate/index.js +1 -1
- package/cjs/animate/index.js.map +1 -1
- package/cjs/color-string/store.js +1 -2
- package/cjs/common/3d-interceptor.js +2 -1
- package/cjs/common/bezier-utils.d.ts +3 -0
- package/cjs/common/bezier-utils.js +17 -2
- package/cjs/common/bezier-utils.js.map +1 -1
- package/cjs/common/custom-path2d.d.ts +4 -0
- package/cjs/common/custom-path2d.js +43 -11
- package/cjs/common/custom-path2d.js.map +1 -1
- package/cjs/common/render-area.js +0 -1
- package/cjs/common/render-command-list.js +2 -1
- package/cjs/common/segment/curve/arc.d.ts +4 -1
- package/cjs/common/segment/curve/arc.js +10 -1
- package/cjs/common/segment/curve/arc.js.map +1 -1
- package/cjs/common/segment/curve/base.d.ts +4 -1
- package/cjs/common/segment/curve/base.js.map +1 -1
- package/cjs/common/segment/curve/cubic-bezier.d.ts +5 -1
- package/cjs/common/segment/curve/cubic-bezier.js +24 -3
- package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
- package/cjs/common/segment/curve/curve-context.js +5 -4
- package/cjs/common/segment/curve/curve-context.js.map +1 -1
- package/cjs/common/segment/curve/ellipse.d.ts +4 -1
- package/cjs/common/segment/curve/ellipse.js +9 -0
- package/cjs/common/segment/curve/ellipse.js.map +1 -1
- package/cjs/common/segment/curve/line.d.ts +4 -1
- package/cjs/common/segment/curve/line.js +18 -0
- package/cjs/common/segment/curve/line.js.map +1 -1
- package/cjs/common/segment/curve/move.d.ts +4 -1
- package/cjs/common/segment/curve/move.js +9 -0
- package/cjs/common/segment/curve/move.js.map +1 -1
- package/cjs/common/segment/curve/path.d.ts +2 -1
- package/cjs/common/segment/curve/path.js +5 -2
- package/cjs/common/segment/curve/path.js.map +1 -1
- package/cjs/common/segment/curve/quadratic-bezier.d.ts +6 -2
- package/cjs/common/segment/curve/quadratic-bezier.js +23 -5
- package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
- package/cjs/common/shape/rect.d.ts +1 -1
- package/cjs/common/shape/rect.js +30 -25
- package/cjs/common/shape/rect.js.map +1 -1
- package/cjs/common/store.js +1 -1
- package/cjs/core/contributions/env/base-contribution.d.ts +2 -0
- package/cjs/core/contributions/env/base-contribution.js +6 -0
- package/cjs/core/contributions/env/base-contribution.js.map +1 -1
- package/cjs/core/global.d.ts +5 -0
- package/cjs/core/global.js +13 -1
- package/cjs/core/global.js.map +1 -1
- package/cjs/graphic/builtin-symbol/rect.d.ts +2 -1
- package/cjs/graphic/builtin-symbol/rect.js +28 -0
- package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
- package/cjs/graphic/builtin-symbol/utils.d.ts +2 -1
- package/cjs/graphic/builtin-symbol/utils.js +5 -0
- package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
- package/cjs/graphic/config.js +19 -5
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.js +15 -1
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/richtext/line.js +1 -1
- package/cjs/graphic/richtext/line.js.map +1 -1
- package/cjs/graphic/richtext/paragraph.d.ts +1 -1
- package/cjs/graphic/richtext/paragraph.js +9 -4
- package/cjs/graphic/richtext/paragraph.js.map +1 -1
- package/cjs/graphic/richtext/utils.d.ts +4 -0
- package/cjs/graphic/richtext/utils.js +19 -6
- package/cjs/graphic/richtext/utils.js.map +1 -1
- package/cjs/graphic/richtext/wrapper.d.ts +1 -0
- package/cjs/graphic/richtext/wrapper.js +1 -1
- package/cjs/graphic/richtext/wrapper.js.map +1 -1
- package/cjs/graphic/richtext.d.ts +7 -2
- package/cjs/graphic/richtext.js +33 -3
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/cjs/interface/animate.d.ts +5 -39
- package/cjs/interface/animate.js.map +1 -1
- package/cjs/interface/context.d.ts +1 -0
- package/cjs/interface/context.js.map +1 -1
- package/cjs/interface/global.d.ts +5 -0
- package/cjs/interface/global.js.map +1 -1
- package/cjs/interface/graphic/group.d.ts +1 -0
- package/cjs/interface/graphic/group.js.map +1 -1
- package/cjs/interface/graphic/image.d.ts +1 -0
- package/cjs/interface/graphic/image.js.map +1 -1
- package/cjs/interface/graphic/path.d.ts +1 -0
- package/cjs/interface/graphic/path.js.map +1 -1
- package/cjs/interface/graphic/rect.d.ts +1 -0
- package/cjs/interface/graphic/rect.js.map +1 -1
- package/cjs/interface/graphic/richText.d.ts +2 -0
- package/cjs/interface/graphic/richText.js.map +1 -1
- package/cjs/interface/graphic/symbol.d.ts +2 -0
- package/cjs/interface/graphic/symbol.js.map +1 -1
- package/cjs/interface/graphic.d.ts +11 -2
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/interface/path.d.ts +5 -0
- package/cjs/interface/path.js.map +1 -1
- package/cjs/interface/picker.d.ts +13 -0
- package/cjs/interface/picker.js.map +1 -1
- package/cjs/picker/constants.d.ts +2 -0
- package/cjs/picker/constants.js +3 -2
- package/cjs/picker/constants.js.map +1 -1
- package/cjs/picker/pick-interceptor.d.ts +7 -2
- package/cjs/picker/pick-interceptor.js +19 -2
- package/cjs/picker/pick-interceptor.js.map +1 -1
- package/cjs/picker/pick-modules.js +7 -4
- package/cjs/picker/pick-modules.js.map +1 -1
- package/cjs/picker/picker-service.d.ts +4 -2
- package/cjs/picker/picker-service.js +13 -12
- package/cjs/picker/picker-service.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.d.ts +15 -5
- package/cjs/plugins/builtin-plugin/edit-module.js +123 -42
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +62 -29
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +346 -212
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/cjs/render/contributions/render/arc3d-render.js.map +1 -1
- package/cjs/render/contributions/render/base-render.d.ts +1 -0
- package/cjs/render/contributions/render/base-render.js +20 -2
- package/cjs/render/contributions/render/base-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
- package/cjs/render/contributions/render/contributions/base-contribution-render.js +16 -8
- package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/group-contribution-render.js +8 -3
- package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
- package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
- package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/rect-contribution-render.js +4 -4
- package/cjs/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +30 -2
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/text-contribution-render.js +5 -3
- package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/group-render.js +2 -2
- package/cjs/render/contributions/render/group-render.js.map +1 -1
- package/cjs/render/contributions/render/image-render.js +3 -3
- package/cjs/render/contributions/render/image-render.js.map +1 -1
- package/cjs/render/contributions/render/path-render.js.map +1 -1
- package/cjs/render/contributions/render/polygon-render.js.map +1 -1
- package/cjs/render/contributions/render/rect-render.js +2 -2
- package/cjs/render/contributions/render/rect-render.js.map +1 -1
- package/cjs/render/contributions/render/richtext-render.js +1 -1
- package/cjs/render/contributions/render/richtext-render.js.map +1 -1
- package/cjs/render/contributions/render/symbol-render.js +15 -13
- package/cjs/render/contributions/render/symbol-render.js.map +1 -1
- package/cjs/render/contributions/render/utils.d.ts +1 -2
- package/cjs/render/contributions/render/utils.js +4 -20
- package/cjs/render/contributions/render/utils.js.map +1 -1
- package/cjs/resource-loader/loader.js +1 -1
- package/cjs/resource-loader/loader.js.map +1 -1
- package/dist/index.es.js +8652 -7685
- package/es/animate/Ticker/default-ticker.d.ts +2 -0
- package/es/animate/Ticker/default-ticker.js +7 -1
- package/es/animate/Ticker/default-ticker.js.map +1 -1
- package/es/animate/animate.js +1 -1
- package/es/animate/animate.js.map +1 -1
- package/es/animate/custom-animate.js +14 -25
- package/es/animate/custom-animate.js.map +1 -1
- package/es/animate/easing-func.d.ts +1 -0
- package/es/animate/easing-func.js +10 -0
- package/es/animate/easing-func.js.map +1 -0
- package/es/animate/easing.d.ts +4 -0
- package/es/animate/easing.js +24 -1
- package/es/animate/easing.js.map +1 -1
- package/es/animate/index.d.ts +1 -0
- package/es/animate/index.js +2 -0
- package/es/animate/index.js.map +1 -1
- package/es/color-string/store.js +1 -2
- package/es/common/3d-interceptor.js +2 -1
- package/es/common/bezier-utils.d.ts +3 -0
- package/es/common/bezier-utils.js +14 -0
- package/es/common/bezier-utils.js.map +1 -1
- package/es/common/custom-path2d.d.ts +4 -0
- package/es/common/custom-path2d.js +44 -12
- package/es/common/custom-path2d.js.map +1 -1
- package/es/common/render-area.js +1 -2
- package/es/common/render-command-list.js +2 -1
- package/es/common/segment/curve/arc.d.ts +4 -1
- package/es/common/segment/curve/arc.js +10 -1
- package/es/common/segment/curve/arc.js.map +1 -1
- package/es/common/segment/curve/base.d.ts +4 -1
- package/es/common/segment/curve/base.js.map +1 -1
- package/es/common/segment/curve/cubic-bezier.d.ts +5 -1
- package/es/common/segment/curve/cubic-bezier.js +22 -1
- package/es/common/segment/curve/cubic-bezier.js.map +1 -1
- package/es/common/segment/curve/curve-context.js +6 -3
- package/es/common/segment/curve/curve-context.js.map +1 -1
- package/es/common/segment/curve/ellipse.d.ts +4 -1
- package/es/common/segment/curve/ellipse.js +9 -0
- package/es/common/segment/curve/ellipse.js.map +1 -1
- package/es/common/segment/curve/line.d.ts +4 -1
- package/es/common/segment/curve/line.js +18 -0
- package/es/common/segment/curve/line.js.map +1 -1
- package/es/common/segment/curve/move.d.ts +4 -1
- package/es/common/segment/curve/move.js +9 -0
- package/es/common/segment/curve/move.js.map +1 -1
- package/es/common/segment/curve/path.d.ts +2 -1
- package/es/common/segment/curve/path.js +5 -2
- package/es/common/segment/curve/path.js.map +1 -1
- package/es/common/segment/curve/quadratic-bezier.d.ts +6 -2
- package/es/common/segment/curve/quadratic-bezier.js +28 -5
- package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
- package/es/common/shape/rect.d.ts +1 -1
- package/es/common/shape/rect.js +30 -25
- package/es/common/shape/rect.js.map +1 -1
- package/es/common/store.js +1 -1
- package/es/core/contributions/env/base-contribution.d.ts +2 -0
- package/es/core/contributions/env/base-contribution.js +6 -0
- package/es/core/contributions/env/base-contribution.js.map +1 -1
- package/es/core/global.d.ts +5 -0
- package/es/core/global.js +14 -1
- package/es/core/global.js.map +1 -1
- package/es/graphic/builtin-symbol/rect.d.ts +2 -1
- package/es/graphic/builtin-symbol/rect.js +28 -0
- package/es/graphic/builtin-symbol/rect.js.map +1 -1
- package/es/graphic/builtin-symbol/utils.d.ts +2 -1
- package/es/graphic/builtin-symbol/utils.js +5 -0
- package/es/graphic/builtin-symbol/utils.js.map +1 -1
- package/es/graphic/config.js +19 -5
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.js +15 -1
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/richtext/line.js +1 -1
- package/es/graphic/richtext/line.js.map +1 -1
- package/es/graphic/richtext/paragraph.d.ts +1 -1
- package/es/graphic/richtext/paragraph.js +9 -4
- package/es/graphic/richtext/paragraph.js.map +1 -1
- package/es/graphic/richtext/utils.d.ts +4 -0
- package/es/graphic/richtext/utils.js +15 -2
- package/es/graphic/richtext/utils.js.map +1 -1
- package/es/graphic/richtext/wrapper.d.ts +1 -0
- package/es/graphic/richtext/wrapper.js +1 -1
- package/es/graphic/richtext/wrapper.js.map +1 -1
- package/es/graphic/richtext.d.ts +7 -2
- package/es/graphic/richtext.js +33 -4
- package/es/graphic/richtext.js.map +1 -1
- package/es/index.d.ts +2 -0
- package/es/index.js +4 -0
- package/es/index.js.map +1 -1
- package/es/interface/animate.d.ts +5 -39
- package/es/interface/animate.js.map +1 -1
- package/es/interface/context.d.ts +1 -0
- package/es/interface/context.js.map +1 -1
- package/es/interface/global.d.ts +5 -0
- package/es/interface/global.js.map +1 -1
- package/es/interface/graphic/group.d.ts +1 -0
- package/es/interface/graphic/group.js.map +1 -1
- package/es/interface/graphic/image.d.ts +1 -0
- package/es/interface/graphic/image.js.map +1 -1
- package/es/interface/graphic/path.d.ts +1 -0
- package/es/interface/graphic/path.js.map +1 -1
- package/es/interface/graphic/rect.d.ts +1 -0
- package/es/interface/graphic/rect.js.map +1 -1
- package/es/interface/graphic/richText.d.ts +2 -0
- package/es/interface/graphic/richText.js.map +1 -1
- package/es/interface/graphic/symbol.d.ts +2 -0
- package/es/interface/graphic/symbol.js.map +1 -1
- package/es/interface/graphic.d.ts +11 -2
- package/es/interface/graphic.js.map +1 -1
- package/es/interface/path.d.ts +5 -0
- package/es/interface/path.js.map +1 -1
- package/es/interface/picker.d.ts +13 -0
- package/es/interface/picker.js.map +1 -1
- package/es/picker/constants.d.ts +2 -0
- package/es/picker/constants.js +4 -0
- package/es/picker/constants.js.map +1 -1
- package/es/picker/pick-interceptor.d.ts +7 -2
- package/es/picker/pick-interceptor.js +19 -1
- package/es/picker/pick-interceptor.js.map +1 -1
- package/es/picker/pick-modules.js +5 -3
- package/es/picker/pick-modules.js.map +1 -1
- package/es/picker/picker-service.d.ts +4 -2
- package/es/picker/picker-service.js +13 -13
- package/es/picker/picker-service.js.map +1 -1
- package/es/plugins/builtin-plugin/edit-module.d.ts +15 -5
- package/es/plugins/builtin-plugin/edit-module.js +119 -40
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +62 -29
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +349 -211
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
- package/es/render/contributions/render/arc3d-render.js.map +1 -1
- package/es/render/contributions/render/base-render.d.ts +1 -0
- package/es/render/contributions/render/base-render.js +21 -2
- package/es/render/contributions/render/base-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
- package/es/render/contributions/render/contributions/base-contribution-render.js +16 -8
- package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/group-contribution-render.js +8 -3
- package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
- package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
- package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/rect-contribution-render.js +4 -4
- package/es/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
- package/es/render/contributions/render/contributions/symbol-contribution-render.js +26 -0
- package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/text-contribution-render.js +5 -3
- package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
- package/es/render/contributions/render/group-render.js +2 -2
- package/es/render/contributions/render/group-render.js.map +1 -1
- package/es/render/contributions/render/image-render.js +3 -2
- package/es/render/contributions/render/image-render.js.map +1 -1
- package/es/render/contributions/render/path-render.js.map +1 -1
- package/es/render/contributions/render/polygon-render.js.map +1 -1
- package/es/render/contributions/render/rect-render.js +2 -2
- package/es/render/contributions/render/rect-render.js.map +1 -1
- package/es/render/contributions/render/richtext-render.js +1 -1
- package/es/render/contributions/render/richtext-render.js.map +1 -1
- package/es/render/contributions/render/symbol-render.js +16 -14
- package/es/render/contributions/render/symbol-render.js.map +1 -1
- package/es/render/contributions/render/utils.d.ts +1 -2
- package/es/render/contributions/render/utils.js +0 -18
- package/es/render/contributions/render/utils.js.map +1 -1
- package/es/resource-loader/loader.js +1 -1
- package/es/resource-loader/loader.js.map +1 -1
- package/package.json +3 -3
|
@@ -4,76 +4,106 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.RichTextEditPlugin = exports.FORMAT_ELEMENT_COMMAND = exports.FORMAT_TEXT_COMMAND = void 0;
|
|
6
6
|
|
|
7
|
-
const vutils_1 = require("@visactor/vutils"), generator_1 = require("../../common/generator"), graphic_1 = require("../../graphic"), edit_module_1 = require("./edit-module");
|
|
7
|
+
const vutils_1 = require("@visactor/vutils"), generator_1 = require("../../common/generator"), graphic_1 = require("../../graphic"), animate_1 = require("../../animate"), edit_module_1 = require("./edit-module"), application_1 = require("../../application"), utils_1 = require("../../graphic/richtext/utils");
|
|
8
8
|
|
|
9
9
|
class Selection {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(selectionStartCursorIdx, curCursorIdx, rt) {
|
|
11
11
|
this.curCursorIdx = curCursorIdx, this.selectionStartCursorIdx = selectionStartCursorIdx,
|
|
12
|
-
this.cacheCurCursorIdx = cacheCurCursorIdx, this.cacheSelectionStartCursorIdx = cacheSelectionStartCursorIdx,
|
|
13
12
|
this.rt = rt;
|
|
14
13
|
}
|
|
14
|
+
isEmpty() {
|
|
15
|
+
return this.selectionStartCursorIdx === this.curCursorIdx;
|
|
16
|
+
}
|
|
17
|
+
getSelectionPureText() {
|
|
18
|
+
const minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
|
|
19
|
+
if (minCursorIdx === maxCursorIdx) return "";
|
|
20
|
+
const config = this.rt.attribute.textConfig, startIdx = (0, edit_module_1.findConfigIndexByCursorIdx)(config, Math.ceil(minCursorIdx)), endIdx = (0,
|
|
21
|
+
edit_module_1.findConfigIndexByCursorIdx)(config, Math.floor(maxCursorIdx));
|
|
22
|
+
let str = "";
|
|
23
|
+
for (let i = startIdx; i <= endIdx; i++) str += config[i].text;
|
|
24
|
+
return str;
|
|
25
|
+
}
|
|
15
26
|
hasFormat(key) {
|
|
16
27
|
return null != this.getFormat(key);
|
|
17
28
|
}
|
|
18
|
-
|
|
29
|
+
_getFormat(key, cursorIdx) {
|
|
30
|
+
var _a;
|
|
19
31
|
if (!this.rt) return null;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
for (let i =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
let idx = Math.round(cursorIdx);
|
|
33
|
+
const config = this.rt.attribute.textConfig;
|
|
34
|
+
for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
|
|
35
|
+
return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
|
|
36
|
+
}
|
|
37
|
+
getFormat(key) {
|
|
38
|
+
return this.getAllFormat(key)[0];
|
|
26
39
|
}
|
|
27
40
|
getAllFormat(key) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
set.add(item[key]);
|
|
41
|
+
const valSet = new Set, minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
|
|
42
|
+
if (minCursorIdx === maxCursorIdx) return [ this._getFormat(key, minCursorIdx) ];
|
|
43
|
+
for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
|
|
44
|
+
const val = this._getFormat(key, i);
|
|
45
|
+
val && valSet.add(val);
|
|
34
46
|
}
|
|
35
|
-
return Array.from(
|
|
47
|
+
return Array.from(valSet.values());
|
|
36
48
|
}
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
exports.FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND", exports.FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
|
|
40
52
|
|
|
41
53
|
class RichTextEditPlugin {
|
|
54
|
+
static tryUpdateRichtext(richtext) {
|
|
55
|
+
const cache = richtext.getFrameCache();
|
|
56
|
+
if (!graphic_1.RichText.AllSingleCharacter(cache)) {
|
|
57
|
+
const tc = graphic_1.RichText.TransformTextConfig2SingleCharacter(richtext.attribute.textConfig);
|
|
58
|
+
richtext.setAttributes({
|
|
59
|
+
textConfig: tc
|
|
60
|
+
}), richtext.doUpdateFrameCache(tc);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
static CreateSelection(rt) {
|
|
64
|
+
if (!rt) return null;
|
|
65
|
+
const {textConfig: textConfig = []} = rt.attribute;
|
|
66
|
+
return new Selection(0, textConfig.length - 1, rt);
|
|
67
|
+
}
|
|
42
68
|
constructor() {
|
|
43
69
|
this.name = "RichTextEditPlugin", this.activeEvent = "onRegister", this._uid = generator_1.Generator.GenAutoIncrementId(),
|
|
44
|
-
this.key = this.name + this._uid, this.editing = !1, this.pointerDown = !1, this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx
|
|
50
|
-
|
|
70
|
+
this.key = this.name + this._uid, this.editing = !1, this.pointerDown = !1, this.handleKeyDown = e => {
|
|
71
|
+
this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
|
|
72
|
+
}, this.handleInput = (text, isComposing, cursorIdx, rt) => {
|
|
73
|
+
this.hideSelection(), this.updateCbs.forEach((cb => cb("input", this)));
|
|
74
|
+
}, this.handleChange = (text, isComposing, cursorIdx, rt) => {
|
|
75
|
+
this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx;
|
|
76
|
+
const p = this.computedCursorPosByCursorIdx(cursorIdx, rt);
|
|
77
|
+
this.setCursorAndTextArea(p.x, p.y1, p.y2, rt), this.hideSelection(), this.updateCbs.forEach((cb => cb("change", this)));
|
|
78
|
+
}, this.handleFocusIn = () => {}, this.handleFocusOut = () => {
|
|
79
|
+
this.editing = !1, this.deFocus(), this.pointerDown = !1, this.triggerRender(),
|
|
80
|
+
this.updateCbs.forEach((cb => cb("defocus", this)));
|
|
51
81
|
}, this.handleMove = e => {
|
|
52
82
|
this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave),
|
|
53
|
-
this.
|
|
54
|
-
}, this.handlePointerDown = e => {
|
|
55
|
-
this.editing ? this.onFocus(e) : this.deFocus(e), this.applyUpdate(), this.pointerDown = !0,
|
|
56
|
-
this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
|
|
57
|
-
}, this.handlePointerUp = e => {
|
|
58
|
-
this.pointerDown = !1;
|
|
83
|
+
this.tryShowSelection(e, !1));
|
|
59
84
|
}, this.handleEnter = e => {
|
|
60
85
|
this.editing = !0, this.pluginService.stage.setCursor("text");
|
|
61
86
|
}, this.handleLeave = e => {
|
|
62
87
|
this.editing = !1, this.pluginService.stage.setCursor("default");
|
|
88
|
+
}, this.handlePointerDown = e => {
|
|
89
|
+
this.editing ? this.onFocus(e) : this.deFocus(), this.triggerRender(), this.pointerDown = !0,
|
|
90
|
+
this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
|
|
91
|
+
}, this.handlePointerUp = e => {
|
|
92
|
+
this.pointerDown = !1;
|
|
93
|
+
}, this.handleDBLClick = e => {
|
|
94
|
+
this.editing && this.tryShowSelection(e, !0);
|
|
63
95
|
}, this.commandCbs = new Map, this.commandCbs.set(exports.FORMAT_TEXT_COMMAND, [ this.formatTextCommandCb ]),
|
|
64
|
-
this.updateCbs = []
|
|
65
|
-
|
|
66
|
-
getSelection() {
|
|
67
|
-
return this.selectionStartCursorIdx && this.curCursorIdx && this.selectionStartCursorIdx !== this.curCursorIdx && this.currRt ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, (0,
|
|
68
|
-
edit_module_1.findCursorIndexIgnoreLinebreak)(this.currRt.attribute.textConfig, this.selectionStartCursorIdx), (0,
|
|
69
|
-
edit_module_1.findCursorIndexIgnoreLinebreak)(this.currRt.attribute.textConfig, this.curCursorIdx), this.currRt) : null;
|
|
96
|
+
this.updateCbs = [], this.timeline = new animate_1.DefaultTimeline, this.ticker = new animate_1.DefaultTicker([ this.timeline ]),
|
|
97
|
+
this.deltaX = 0, this.deltaY = 0;
|
|
70
98
|
}
|
|
71
99
|
formatTextCommandCb(payload, p) {
|
|
72
100
|
const rt = p.currRt;
|
|
73
101
|
if (!rt) return;
|
|
74
102
|
const selectionData = p.getSelection();
|
|
75
103
|
if (!selectionData) return;
|
|
76
|
-
const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData,
|
|
104
|
+
const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx), maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx), minConfigIdx = (0,
|
|
105
|
+
edit_module_1.findConfigIndexByCursorIdx)(rt.attribute.textConfig, minCursorIdx), maxConfigIdx = (0,
|
|
106
|
+
edit_module_1.findConfigIndexByCursorIdx)(rt.attribute.textConfig, maxCursorIdx), config = rt.attribute.textConfig.slice(minConfigIdx, maxConfigIdx);
|
|
77
107
|
"bold" === payload ? config.forEach((item => item.fontWeight = "bold")) : "italic" === payload ? config.forEach((item => item.fontStyle = "italic")) : "underline" === payload ? config.forEach((item => item.underline = !0)) : "lineThrough" === payload ? config.forEach((item => item.lineThrough = !0)) : (0,
|
|
78
108
|
vutils_1.isObject)(payload) && config.forEach((item => (0, vutils_1.merge)(item, payload))),
|
|
79
109
|
rt.setAttributes(rt.attribute);
|
|
@@ -91,125 +121,104 @@ class RichTextEditPlugin {
|
|
|
91
121
|
activate(context) {
|
|
92
122
|
this.pluginService = context, this.editModule = new edit_module_1.EditModule, context.stage.on("pointermove", this.handleMove),
|
|
93
123
|
context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
|
|
94
|
-
context.stage.on("pointerleave", this.handlePointerUp),
|
|
95
|
-
|
|
124
|
+
context.stage.on("pointerleave", this.handlePointerUp), context.stage.on("dblclick", this.handleDBLClick),
|
|
125
|
+
application_1.application.global.addEventListener("keydown", this.handleKeyDown),
|
|
126
|
+
this.editModule.onInput(this.handleInput), this.editModule.onChange(this.handleChange),
|
|
127
|
+
this.editModule.onFocusOut(this.handleFocusOut);
|
|
96
128
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
let x = column1.left + column1.width, cursorIndex = this.getColumnIndex(cache, column1);
|
|
103
|
-
p1.x < column1.left + column1.width / 2 && (x = column1.left, cursorIndex -= 1),
|
|
104
|
-
p1.x = x, p1.y = (y1 + y2) / 2;
|
|
105
|
-
let line0Info = this.getLineByPoint(cache, p0);
|
|
106
|
-
if ((p0.y > p1.y || p0.y === p1.y && p0.x > p1.x) && ([p0, p1] = [ p1, p0 ], [line1Info, line0Info] = [ line0Info, line1Info ]),
|
|
107
|
-
this.editBg.removeAllChild(), line0Info === line1Info) {
|
|
108
|
-
const column0 = this.getColumnByLinePoint(line0Info, p0);
|
|
109
|
-
this.editBg.setAttributes({
|
|
110
|
-
x: p0.x,
|
|
111
|
-
y: line0Info.top,
|
|
112
|
-
width: p1.x - p0.x,
|
|
113
|
-
height: column0.height,
|
|
114
|
-
fill: "#336df4",
|
|
115
|
-
fillOpacity: .2
|
|
116
|
-
});
|
|
117
|
-
} else {
|
|
118
|
-
this.editBg.setAttributes({
|
|
119
|
-
x: 0,
|
|
120
|
-
y: line0Info.top,
|
|
121
|
-
width: 0,
|
|
122
|
-
height: 0
|
|
123
|
-
});
|
|
124
|
-
const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
|
|
125
|
-
let y = 0;
|
|
126
|
-
for (let i = startIdx; i <= endIdx; i++) {
|
|
127
|
-
const line = cache.lines[i];
|
|
128
|
-
if (i === startIdx) {
|
|
129
|
-
const p = line.paragraphs[line.paragraphs.length - 1];
|
|
130
|
-
this.editBg.add((0, graphic_1.createRect)({
|
|
131
|
-
x: p0.x,
|
|
132
|
-
y: y,
|
|
133
|
-
width: p.left + p.width - p0.x,
|
|
134
|
-
height: line.height,
|
|
135
|
-
fill: "#336df4",
|
|
136
|
-
fillOpacity: .2
|
|
137
|
-
}));
|
|
138
|
-
} else if (i === endIdx) {
|
|
139
|
-
const p = line.paragraphs[0];
|
|
140
|
-
this.editBg.add((0, graphic_1.createRect)({
|
|
141
|
-
x: p.left,
|
|
142
|
-
y: y,
|
|
143
|
-
width: p1.x - p.left,
|
|
144
|
-
height: line.height,
|
|
145
|
-
fill: "#336df4",
|
|
146
|
-
fillOpacity: .2
|
|
147
|
-
}));
|
|
148
|
-
} else {
|
|
149
|
-
const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
|
|
150
|
-
this.editBg.add((0, graphic_1.createRect)({
|
|
151
|
-
x: p0.left,
|
|
152
|
-
y: y,
|
|
153
|
-
width: p1.left + p1.width - p0.left,
|
|
154
|
-
height: line.height,
|
|
155
|
-
fill: "#336df4",
|
|
156
|
-
fillOpacity: .2
|
|
157
|
-
}));
|
|
158
|
-
}
|
|
159
|
-
y += line.height;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
this.curCursorIdx = cursorIndex, this.setCursorAndTextArea(x, y1 + 2, y2 - 2, e.target),
|
|
163
|
-
this.applyUpdate(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
129
|
+
copyToClipboard(e) {
|
|
130
|
+
if (application_1.application.global.isMacOS() && e.metaKey && "c" === e.key || !application_1.application.global.isMacOS() && e.ctrlKey && "c" === e.key) {
|
|
131
|
+
const text = this.getSelection().getSelectionPureText();
|
|
132
|
+
return application_1.application.global.copyToClipBoard(text), e.preventDefault(),
|
|
133
|
+
!0;
|
|
164
134
|
}
|
|
135
|
+
return !1;
|
|
165
136
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
137
|
+
selectionRange(startIdx, endIdx) {
|
|
138
|
+
const currRt = this.currRt;
|
|
139
|
+
if (!currRt) return;
|
|
140
|
+
const cache = currRt.getFrameCache();
|
|
141
|
+
if (!cache) return;
|
|
142
|
+
const {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
143
|
+
startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), startIdx = Math.min(Math.max(startIdx, -.1), totalCursorCount + .1),
|
|
144
|
+
endIdx = Math.min(Math.max(endIdx, -.1), totalCursorCount + .1), this.curCursorIdx = endIdx,
|
|
145
|
+
this.selectionStartCursorIdx = startIdx;
|
|
146
|
+
const {x: x, y1: y1, y2: y2} = this.computedCursorPosByCursorIdx(this.selectionStartCursorIdx, this.currRt);
|
|
147
|
+
this.startCursorPos = {
|
|
148
|
+
x: x,
|
|
149
|
+
y: (y1 + y2) / 2
|
|
178
150
|
};
|
|
179
|
-
|
|
151
|
+
const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
|
|
152
|
+
this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
|
|
180
153
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
154
|
+
fullSelection(e) {
|
|
155
|
+
if (application_1.application.global.isMacOS() && e.metaKey && "a" === e.key || !application_1.application.global.isMacOS() && e.ctrlKey && "a" === e.key) {
|
|
156
|
+
const currRt = this.currRt;
|
|
157
|
+
if (!currRt) return;
|
|
158
|
+
const cache = currRt.getFrameCache();
|
|
159
|
+
if (!cache) return;
|
|
160
|
+
const {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
161
|
+
return this.selectionRange(-.1, totalCursorCount + .1), e.preventDefault(), !0;
|
|
162
|
+
}
|
|
163
|
+
return !1;
|
|
164
|
+
}
|
|
165
|
+
directKey(e) {
|
|
166
|
+
if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
|
|
167
|
+
const cache = this.currRt.getFrameCache();
|
|
168
|
+
if (!cache) return !1;
|
|
169
|
+
let x = 0, y = 0;
|
|
170
|
+
"ArrowUp" === e.key ? y = -1 : "ArrowDown" === e.key ? y = 1 : "ArrowLeft" === e.key ? x = -1 : "ArrowRight" === e.key && (x = 1);
|
|
171
|
+
const {lineInfo: lineInfo, columnInfo: columnInfo} = this.getColumnByIndex(cache, Math.round(this.curCursorIdx)), {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
|
|
172
|
+
if (x) {
|
|
173
|
+
x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 2] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + .2 : x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 1] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + 1 - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - 1 + .2 : this.curCursorIdx += x,
|
|
174
|
+
this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
|
|
175
|
+
const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
|
|
176
|
+
this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
|
|
177
|
+
}
|
|
178
|
+
if (y) {
|
|
179
|
+
if (y > 0 && lineInfo === cache.lines[cache.lines.length - 1]) return;
|
|
180
|
+
if (y < 0 && lineInfo === cache.lines[0]) return;
|
|
181
|
+
const lineIdx = cache.lines.findIndex((item => item === lineInfo)) + y;
|
|
182
|
+
if (lineIdx < 0 || lineIdx >= cache.lines.length) return;
|
|
183
|
+
const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt), posX = pos.x;
|
|
184
|
+
let posY = (pos.y1 + pos.y2) / 2;
|
|
185
|
+
posY += y * lineInfo.height;
|
|
186
|
+
const nextLineInfo = cache.lines[lineIdx], {columnInfo: columnInfo, delta: delta} = this.getColumnAndIndexByLinePoint(nextLineInfo, {
|
|
187
|
+
x: posX,
|
|
188
|
+
y: posY
|
|
189
|
+
});
|
|
190
|
+
if (!columnInfo) return;
|
|
191
|
+
let cursorIdx = this.getColumnIndex(cache, columnInfo) + delta;
|
|
192
|
+
const data = this.computedCursorPosByCursorIdx(cursorIdx, this.currRt);
|
|
193
|
+
cursorIdx < -.1 ? cursorIdx = -.1 : cursorIdx > totalCursorCount + .1 && (cursorIdx = totalCursorCount + .1),
|
|
194
|
+
this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx, this.setCursorAndTextArea(data.x, data.y1, data.y2, this.currRt);
|
|
195
|
+
}
|
|
196
|
+
return !0;
|
|
185
197
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
198
|
+
deactivate(context) {
|
|
199
|
+
context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
|
|
200
|
+
context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
|
|
201
|
+
context.stage.off("dblclick", this.handleDBLClick), application_1.application.global.addEventListener("keydown", this.handleKeyDown);
|
|
190
202
|
}
|
|
191
203
|
onFocus(e) {
|
|
192
|
-
this.deFocus(e
|
|
204
|
+
this.deFocus(), this.currRt = e.target;
|
|
193
205
|
const target = e.target;
|
|
194
|
-
|
|
195
|
-
const shadowRoot = target.attachShadow();
|
|
196
|
-
shadowRoot.setAttributes({
|
|
197
|
-
shadowRootIdx: -1
|
|
198
|
-
});
|
|
199
|
-
const cache = target.getFrameCache();
|
|
206
|
+
RichTextEditPlugin.tryUpdateRichtext(target);
|
|
207
|
+
const shadowRoot = target.attachShadow(), cache = target.getFrameCache();
|
|
200
208
|
if (!cache) return;
|
|
201
|
-
if (
|
|
209
|
+
if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
|
|
210
|
+
shadowRootIdx: 1,
|
|
211
|
+
pickable: !1,
|
|
212
|
+
x: this.deltaX,
|
|
213
|
+
y: this.deltaY
|
|
214
|
+
}), !this.editLine) {
|
|
202
215
|
const line = (0, graphic_1.createLine)({
|
|
203
216
|
x: 0,
|
|
204
217
|
y: 0,
|
|
205
218
|
lineWidth: 1,
|
|
206
219
|
stroke: "black"
|
|
207
220
|
});
|
|
208
|
-
|
|
209
|
-
opacity: 1
|
|
210
|
-
}, 10, "linear").wait(700).to({
|
|
211
|
-
opacity: 0
|
|
212
|
-
}, 10, "linear").wait(700).loop(1 / 0), this.editLine = line;
|
|
221
|
+
this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
|
|
213
222
|
const g = (0, graphic_1.createGroup)({
|
|
214
223
|
x: 0,
|
|
215
224
|
y: 0,
|
|
@@ -218,28 +227,141 @@ class RichTextEditPlugin {
|
|
|
218
227
|
});
|
|
219
228
|
this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
|
|
220
229
|
}
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height, x = columnInfo.left + columnInfo.width;
|
|
226
|
-
y1 += 2, y2 -= 2;
|
|
227
|
-
let cursorIndex = this.getColumnIndex(cache, columnInfo);
|
|
228
|
-
p1.x < columnInfo.left + columnInfo.width / 2 && (x = columnInfo.left, cursorIndex -= 1),
|
|
229
|
-
this.lastPoint = {
|
|
230
|
+
const data = this.computedCursorPosByEvent(e, cache);
|
|
231
|
+
if (data) {
|
|
232
|
+
const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
|
|
233
|
+
this.startCursorPos = {
|
|
230
234
|
x: x,
|
|
231
235
|
y: (y1 + y2) / 2
|
|
232
236
|
}, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
|
|
233
237
|
this.setCursorAndTextArea(x, y1, y2, target);
|
|
234
238
|
}
|
|
235
239
|
}
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
deFocus() {
|
|
241
|
+
const target = this.currRt;
|
|
242
|
+
target && (target.detachShadow(), this.currRt = null, this.editLine && (this.editLine.parent.removeChild(this.editLine),
|
|
243
|
+
this.editLine.release(), this.editLine = null, this.editBg.parent.removeChild(this.editBg),
|
|
244
|
+
this.editBg.release(), this.editBg = null));
|
|
245
|
+
}
|
|
246
|
+
addAnimateToLine(line) {
|
|
247
|
+
line.animates && line.animates.forEach((animate => {
|
|
248
|
+
animate.stop(), animate.release();
|
|
249
|
+
}));
|
|
250
|
+
const animate = line.animate();
|
|
251
|
+
animate.setTimeline(this.timeline), animate.to({
|
|
252
|
+
opacity: 1
|
|
253
|
+
}, 10, "linear").wait(700).to({
|
|
254
|
+
opacity: 0
|
|
255
|
+
}, 10, "linear").wait(700).loop(1 / 0);
|
|
256
|
+
}
|
|
257
|
+
tryShowSelection(e, dblclick) {
|
|
258
|
+
const cache = e.target.getFrameCache();
|
|
259
|
+
if (cache && this.editBg && this.startCursorPos) if (dblclick) {
|
|
260
|
+
const currCursorData = this.computedCursorPosByEvent(e, cache);
|
|
261
|
+
if (!currCursorData) return;
|
|
262
|
+
const lineInfo = currCursorData.lineInfo, columnIndex = lineInfo.paragraphs.findIndex((item => item === currCursorData.columnInfo));
|
|
263
|
+
if (columnIndex < 0) return;
|
|
264
|
+
const str = lineInfo.paragraphs.reduce(((str, item) => str + item.text), "");
|
|
265
|
+
let idx = 0;
|
|
266
|
+
for (let i = 0; i < cache.lines.length; i++) {
|
|
267
|
+
const line = cache.lines[i];
|
|
268
|
+
if (line === lineInfo) break;
|
|
269
|
+
idx += line.paragraphs.length;
|
|
270
|
+
}
|
|
271
|
+
const {startIdx: startIdx, endIdx: endIdx} = (0, utils_1.getWordStartEndIdx)(str, columnIndex);
|
|
272
|
+
this.selectionRange(idx + startIdx - .1, idx + endIdx - .1);
|
|
273
|
+
} else if (this.pointerDown) {
|
|
274
|
+
const currCursorData = this.computedCursorPosByEvent(e, cache);
|
|
275
|
+
if (!currCursorData) return;
|
|
276
|
+
this.curCursorIdx = currCursorData.cursorIndex, this._tryShowSelection(currCursorData, cache);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
_tryShowSelection(currCursorData, cache) {
|
|
280
|
+
let startCursorPos = this.startCursorPos, endCursorPos = {
|
|
281
|
+
x: currCursorData.x,
|
|
282
|
+
y: (currCursorData.y1 + currCursorData.y2) / 2
|
|
283
|
+
}, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
|
|
284
|
+
if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
|
|
285
|
+
[line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
|
|
286
|
+
x: startCursorPos.x,
|
|
287
|
+
y: line0Info.top,
|
|
288
|
+
width: endCursorPos.x - startCursorPos.x,
|
|
289
|
+
height: line0Info.height,
|
|
290
|
+
fill: "#336df4",
|
|
291
|
+
fillOpacity: .2
|
|
292
|
+
}); else {
|
|
293
|
+
this.editBg.setAttributes({
|
|
294
|
+
x: 0,
|
|
295
|
+
y: line0Info.top,
|
|
296
|
+
width: 0,
|
|
297
|
+
height: 0
|
|
298
|
+
});
|
|
299
|
+
const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
|
|
300
|
+
let y = 0;
|
|
301
|
+
for (let i = startIdx; i <= endIdx; i++) {
|
|
302
|
+
const line = cache.lines[i];
|
|
303
|
+
if (i === startIdx) {
|
|
304
|
+
const p = line.paragraphs[line.paragraphs.length - 1];
|
|
305
|
+
this.editBg.add((0, graphic_1.createRect)({
|
|
306
|
+
x: startCursorPos.x,
|
|
307
|
+
y: y,
|
|
308
|
+
width: p.left + p.width - startCursorPos.x,
|
|
309
|
+
height: line.height,
|
|
310
|
+
fill: "#336df4",
|
|
311
|
+
fillOpacity: .2
|
|
312
|
+
}));
|
|
313
|
+
} else if (i === endIdx) {
|
|
314
|
+
const p = line.paragraphs[0];
|
|
315
|
+
this.editBg.add((0, graphic_1.createRect)({
|
|
316
|
+
x: p.left,
|
|
317
|
+
y: y,
|
|
318
|
+
width: endCursorPos.x - p.left,
|
|
319
|
+
height: line.height,
|
|
320
|
+
fill: "#336df4",
|
|
321
|
+
fillOpacity: .2
|
|
322
|
+
}));
|
|
323
|
+
} else {
|
|
324
|
+
const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
|
|
325
|
+
this.editBg.add((0, graphic_1.createRect)({
|
|
326
|
+
x: p0.left,
|
|
327
|
+
y: y,
|
|
328
|
+
width: p1.left + p1.width - p0.left,
|
|
329
|
+
height: line.height,
|
|
330
|
+
fill: "#336df4",
|
|
331
|
+
fillOpacity: .2
|
|
332
|
+
}));
|
|
333
|
+
}
|
|
334
|
+
y += line.height;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
this.setCursorAndTextArea(currCursorData.x, currCursorData.y1 + 2, currCursorData.y2 - 2, this.currRt),
|
|
338
|
+
this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
|
|
339
|
+
}
|
|
340
|
+
hideSelection() {
|
|
341
|
+
this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
|
|
342
|
+
fill: "transparent"
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
getLineByPoint(cache, p1) {
|
|
346
|
+
let lineInfo = cache.lines[0];
|
|
347
|
+
for (let i = 0; i < cache.lines.length && !(lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y); i++) lineInfo = cache.lines[i + 1];
|
|
348
|
+
return lineInfo;
|
|
349
|
+
}
|
|
350
|
+
getColumnAndIndexByLinePoint(lineInfo, p1) {
|
|
351
|
+
let columnInfo = lineInfo.paragraphs[0], delta = 0;
|
|
352
|
+
if (lineInfo.paragraphs.length) {
|
|
353
|
+
const start = lineInfo.paragraphs[0], end = lineInfo.paragraphs[lineInfo.paragraphs.length - 1];
|
|
354
|
+
p1.x <= start.left ? (delta = -.1, columnInfo = start) : p1.x >= end.left + end.width && (delta = .1,
|
|
355
|
+
columnInfo = end);
|
|
356
|
+
}
|
|
357
|
+
if (!delta) for (let i = 0; i < lineInfo.paragraphs.length; i++) if (columnInfo = lineInfo.paragraphs[i],
|
|
358
|
+
columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x) {
|
|
359
|
+
delta = p1.x > columnInfo.left + columnInfo.width / 2 ? .1 : -.1;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
columnInfo: columnInfo,
|
|
364
|
+
delta: delta
|
|
243
365
|
};
|
|
244
366
|
}
|
|
245
367
|
getColumnIndex(cache, cInfo) {
|
|
@@ -250,19 +372,25 @@ class RichTextEditPlugin {
|
|
|
250
372
|
}
|
|
251
373
|
return -1;
|
|
252
374
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
375
|
+
isRichtext(e) {
|
|
376
|
+
return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
|
|
377
|
+
}
|
|
378
|
+
triggerRender() {
|
|
379
|
+
this.pluginService.stage.renderNextFrame();
|
|
380
|
+
}
|
|
381
|
+
computeGlobalDelta(cache) {
|
|
382
|
+
this.deltaX = 0, this.deltaY = 0;
|
|
383
|
+
const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
|
|
384
|
+
"center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
|
|
385
|
+
"middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
|
|
386
|
+
}
|
|
387
|
+
getEventPosition(e) {
|
|
388
|
+
const p = this.pluginService.stage.eventPointTransform(e), p1 = {
|
|
389
|
+
x: 0,
|
|
390
|
+
y: 0
|
|
391
|
+
};
|
|
392
|
+
return e.target.globalTransMatrix.transformPoint(p, p1), p1.x -= this.deltaX, p1.y -= this.deltaY,
|
|
393
|
+
p1;
|
|
266
394
|
}
|
|
267
395
|
setCursorAndTextArea(x, y1, y2, rt) {
|
|
268
396
|
this.editLine.setAttributes({
|
|
@@ -273,7 +401,7 @@ class RichTextEditPlugin {
|
|
|
273
401
|
x: x,
|
|
274
402
|
y: y2
|
|
275
403
|
} ]
|
|
276
|
-
});
|
|
404
|
+
}), this.addAnimateToLine(this.editLine);
|
|
277
405
|
const out = {
|
|
278
406
|
x: 0,
|
|
279
407
|
y: 0
|
|
@@ -285,53 +413,59 @@ class RichTextEditPlugin {
|
|
|
285
413
|
const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
|
|
286
414
|
out.x += left, out.y += top, this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
|
|
287
415
|
}
|
|
288
|
-
|
|
289
|
-
this.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
416
|
+
computedCursorPosByEvent(e, cache) {
|
|
417
|
+
const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
|
|
418
|
+
if (!lineInfo) return;
|
|
419
|
+
const {columnInfo: columnInfo, delta: delta} = this.getColumnAndIndexByLinePoint(lineInfo, p1);
|
|
420
|
+
if (!columnInfo) return;
|
|
421
|
+
let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
|
|
422
|
+
y1 += 2, y2 -= 2;
|
|
423
|
+
let cursorIndex = this.getColumnIndex(cache, columnInfo);
|
|
424
|
+
cursorIndex += delta;
|
|
425
|
+
return {
|
|
426
|
+
x: columnInfo.left + (delta > 0 ? columnInfo.width : 0),
|
|
427
|
+
y1: y1,
|
|
428
|
+
y2: y2,
|
|
429
|
+
cursorIndex: cursorIndex,
|
|
430
|
+
lineInfo: lineInfo,
|
|
431
|
+
columnInfo: columnInfo
|
|
432
|
+
};
|
|
301
433
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
434
|
+
computedCursorPosByCursorIdx(cursorIdx, rt) {
|
|
435
|
+
var _a, _b, _c;
|
|
436
|
+
const idx = Math.round(cursorIdx), leftRight = cursorIdx - idx, cache = rt.getFrameCache(), column = this.getColumnByIndex(cache, idx), height = null !== (_a = rt.attribute.fontSize) && void 0 !== _a ? _a : null === (_c = null === (_b = rt.attribute.textConfig) || void 0 === _b ? void 0 : _b[0]) || void 0 === _c ? void 0 : _c.fontSize;
|
|
437
|
+
if (!column) return {
|
|
438
|
+
x: 0,
|
|
439
|
+
y1: 0,
|
|
440
|
+
y2: height
|
|
441
|
+
};
|
|
442
|
+
const {lineInfo: lineInfo, columnInfo: columnInfo} = column;
|
|
443
|
+
let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
|
|
444
|
+
return y1 += 2, y2 -= 2, {
|
|
445
|
+
x: columnInfo.left + (leftRight < 0 ? 0 : columnInfo.width),
|
|
446
|
+
y1: y1,
|
|
447
|
+
y2: y2
|
|
448
|
+
};
|
|
307
449
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
tc.push(Object.assign(Object.assign({}, item), {
|
|
320
|
-
text: t
|
|
321
|
-
}));
|
|
322
|
-
} else tc.push(item);
|
|
323
|
-
})), richtext.setAttributes({
|
|
324
|
-
textConfig: tc
|
|
325
|
-
}), richtext.doUpdateFrameCache(tc);
|
|
450
|
+
getColumnByIndex(cache, index) {
|
|
451
|
+
for (let i = 0, inputIndex = 0; i < cache.lines.length; i++) {
|
|
452
|
+
const lineInfo = cache.lines[i];
|
|
453
|
+
for (let j = 0; j < lineInfo.paragraphs.length; j++) {
|
|
454
|
+
const columnInfo = lineInfo.paragraphs[j];
|
|
455
|
+
if (inputIndex === index) return {
|
|
456
|
+
lineInfo: lineInfo,
|
|
457
|
+
columnInfo: columnInfo
|
|
458
|
+
};
|
|
459
|
+
inputIndex++;
|
|
460
|
+
}
|
|
326
461
|
}
|
|
327
|
-
|
|
328
|
-
onSelect() {}
|
|
329
|
-
deactivate(context) {
|
|
330
|
-
context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
|
|
331
|
-
context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp);
|
|
462
|
+
return null;
|
|
332
463
|
}
|
|
333
464
|
release() {
|
|
334
|
-
this.editModule.release();
|
|
465
|
+
this.deactivate(this.pluginService), this.editModule.release();
|
|
466
|
+
}
|
|
467
|
+
getSelection(defaultAll = !1) {
|
|
468
|
+
return this.currRt ? null != this.selectionStartCursorIdx && null != this.curCursorIdx ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, this.currRt) : defaultAll ? RichTextEditPlugin.CreateSelection(this.currRt) : null : null;
|
|
335
469
|
}
|
|
336
470
|
}
|
|
337
471
|
|