@visactor/vrender-core 0.21.5-vstory.1 → 0.21.5
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 +0 -2
- package/cjs/animate/Ticker/default-ticker.js +1 -7
- 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/easing.d.ts +0 -4
- package/cjs/animate/easing.js +1 -12
- package/cjs/animate/easing.js.map +1 -1
- package/cjs/animate/index.d.ts +0 -1
- package/cjs/animate/index.js +1 -1
- package/cjs/animate/index.js.map +1 -1
- package/cjs/color-string/store.js +2 -1
- package/cjs/common/3d-interceptor.js +1 -2
- package/cjs/common/bezier-utils.d.ts +0 -3
- package/cjs/common/bezier-utils.js +2 -17
- package/cjs/common/bezier-utils.js.map +1 -1
- package/cjs/common/custom-path2d.d.ts +0 -4
- package/cjs/common/custom-path2d.js +11 -43
- package/cjs/common/custom-path2d.js.map +1 -1
- package/cjs/common/render-area.js +1 -0
- package/cjs/common/render-command-list.js +1 -2
- package/cjs/common/segment/curve/arc.d.ts +1 -4
- package/cjs/common/segment/curve/arc.js +1 -10
- package/cjs/common/segment/curve/arc.js.map +1 -1
- package/cjs/common/segment/curve/base.d.ts +1 -4
- package/cjs/common/segment/curve/base.js.map +1 -1
- package/cjs/common/segment/curve/cubic-bezier.d.ts +1 -5
- package/cjs/common/segment/curve/cubic-bezier.js +3 -24
- package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
- package/cjs/common/segment/curve/curve-context.js +4 -5
- package/cjs/common/segment/curve/curve-context.js.map +1 -1
- package/cjs/common/segment/curve/ellipse.d.ts +1 -4
- package/cjs/common/segment/curve/ellipse.js +0 -9
- package/cjs/common/segment/curve/ellipse.js.map +1 -1
- package/cjs/common/segment/curve/line.d.ts +1 -4
- package/cjs/common/segment/curve/line.js +0 -18
- package/cjs/common/segment/curve/line.js.map +1 -1
- package/cjs/common/segment/curve/move.d.ts +1 -4
- package/cjs/common/segment/curve/move.js +0 -9
- package/cjs/common/segment/curve/move.js.map +1 -1
- package/cjs/common/segment/curve/path.d.ts +1 -2
- package/cjs/common/segment/curve/path.js +2 -5
- package/cjs/common/segment/curve/path.js.map +1 -1
- package/cjs/common/segment/curve/quadratic-bezier.d.ts +2 -6
- package/cjs/common/segment/curve/quadratic-bezier.js +5 -23
- package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
- package/cjs/common/store.js +1 -1
- package/cjs/graphic/builtin-symbol/rect.d.ts +1 -2
- package/cjs/graphic/builtin-symbol/rect.js +0 -28
- package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
- package/cjs/graphic/builtin-symbol/utils.d.ts +1 -2
- package/cjs/graphic/builtin-symbol/utils.js +0 -5
- package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
- package/cjs/graphic/config.js +1 -6
- package/cjs/graphic/config.js.map +1 -1
- package/cjs/graphic/graphic.js +1 -2
- package/cjs/graphic/graphic.js.map +1 -1
- package/cjs/graphic/richtext/wrapper.d.ts +0 -1
- package/cjs/graphic/richtext/wrapper.js +1 -1
- package/cjs/graphic/richtext/wrapper.js.map +1 -1
- package/cjs/graphic/richtext.js +1 -2
- package/cjs/graphic/richtext.js.map +1 -1
- package/cjs/index.d.ts +0 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/interface/animate.d.ts +39 -5
- package/cjs/interface/animate.js.map +1 -1
- package/cjs/interface/graphic/path.d.ts +0 -1
- package/cjs/interface/graphic/path.js.map +1 -1
- package/cjs/interface/graphic/symbol.d.ts +0 -2
- package/cjs/interface/graphic/symbol.js.map +1 -1
- package/cjs/interface/graphic.d.ts +2 -6
- package/cjs/interface/graphic.js.map +1 -1
- package/cjs/interface/path.d.ts +0 -5
- package/cjs/interface/path.js.map +1 -1
- package/cjs/interface/picker.d.ts +0 -13
- package/cjs/interface/picker.js.map +1 -1
- package/cjs/picker/constants.d.ts +0 -2
- package/cjs/picker/constants.js +2 -3
- package/cjs/picker/constants.js.map +1 -1
- package/cjs/picker/pick-interceptor.d.ts +2 -7
- package/cjs/picker/pick-interceptor.js +2 -19
- package/cjs/picker/pick-interceptor.js.map +1 -1
- package/cjs/picker/pick-modules.js +4 -7
- package/cjs/picker/pick-modules.js.map +1 -1
- package/cjs/picker/picker-service.d.ts +2 -4
- package/cjs/picker/picker-service.js +12 -13
- package/cjs/picker/picker-service.js.map +1 -1
- package/cjs/plugins/builtin-plugin/edit-module.d.ts +5 -6
- package/cjs/plugins/builtin-plugin/edit-module.js +28 -84
- package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +30 -49
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +217 -280
- 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 +0 -1
- package/cjs/render/contributions/render/base-render.js +2 -20
- package/cjs/render/contributions/render/base-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +2 -29
- package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +2 -6
- package/cjs/render/contributions/render/contributions/image-contribution-render.js +3 -48
- package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +1 -8
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +2 -30
- package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
- package/cjs/render/contributions/render/image-render.js +12 -12
- 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/symbol-render.js +12 -15
- package/cjs/render/contributions/render/symbol-render.js.map +1 -1
- package/cjs/render/contributions/render/utils.d.ts +2 -1
- package/cjs/render/contributions/render/utils.js +20 -4
- package/cjs/render/contributions/render/utils.js.map +1 -1
- package/dist/index.es.js +7566 -8256
- package/es/animate/Ticker/default-ticker.d.ts +0 -2
- package/es/animate/Ticker/default-ticker.js +1 -7
- 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/easing.d.ts +0 -4
- package/es/animate/easing.js +1 -12
- package/es/animate/easing.js.map +1 -1
- package/es/animate/index.d.ts +0 -1
- package/es/animate/index.js +0 -2
- package/es/animate/index.js.map +1 -1
- package/es/color-string/store.js +2 -1
- package/es/common/3d-interceptor.js +1 -2
- package/es/common/bezier-utils.d.ts +0 -3
- package/es/common/bezier-utils.js +0 -14
- package/es/common/bezier-utils.js.map +1 -1
- package/es/common/custom-path2d.d.ts +0 -4
- package/es/common/custom-path2d.js +12 -44
- package/es/common/custom-path2d.js.map +1 -1
- package/es/common/render-area.js +2 -1
- package/es/common/render-command-list.js +1 -2
- package/es/common/segment/curve/arc.d.ts +1 -4
- package/es/common/segment/curve/arc.js +1 -10
- package/es/common/segment/curve/arc.js.map +1 -1
- package/es/common/segment/curve/base.d.ts +1 -4
- package/es/common/segment/curve/base.js.map +1 -1
- package/es/common/segment/curve/cubic-bezier.d.ts +1 -5
- package/es/common/segment/curve/cubic-bezier.js +1 -22
- package/es/common/segment/curve/cubic-bezier.js.map +1 -1
- package/es/common/segment/curve/curve-context.js +3 -6
- package/es/common/segment/curve/curve-context.js.map +1 -1
- package/es/common/segment/curve/ellipse.d.ts +1 -4
- package/es/common/segment/curve/ellipse.js +0 -9
- package/es/common/segment/curve/ellipse.js.map +1 -1
- package/es/common/segment/curve/line.d.ts +1 -4
- package/es/common/segment/curve/line.js +0 -18
- package/es/common/segment/curve/line.js.map +1 -1
- package/es/common/segment/curve/move.d.ts +1 -4
- package/es/common/segment/curve/move.js +0 -9
- package/es/common/segment/curve/move.js.map +1 -1
- package/es/common/segment/curve/path.d.ts +1 -2
- package/es/common/segment/curve/path.js +2 -5
- package/es/common/segment/curve/path.js.map +1 -1
- package/es/common/segment/curve/quadratic-bezier.d.ts +2 -6
- package/es/common/segment/curve/quadratic-bezier.js +5 -28
- package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
- package/es/common/store.js +1 -1
- package/es/graphic/builtin-symbol/rect.d.ts +1 -2
- package/es/graphic/builtin-symbol/rect.js +0 -28
- package/es/graphic/builtin-symbol/rect.js.map +1 -1
- package/es/graphic/builtin-symbol/utils.d.ts +1 -2
- package/es/graphic/builtin-symbol/utils.js +0 -5
- package/es/graphic/builtin-symbol/utils.js.map +1 -1
- package/es/graphic/config.js +1 -6
- package/es/graphic/config.js.map +1 -1
- package/es/graphic/graphic.js +1 -2
- package/es/graphic/graphic.js.map +1 -1
- package/es/graphic/richtext/wrapper.d.ts +0 -1
- package/es/graphic/richtext/wrapper.js +1 -1
- package/es/graphic/richtext/wrapper.js.map +1 -1
- package/es/graphic/richtext.js +1 -2
- package/es/graphic/richtext.js.map +1 -1
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -2
- package/es/index.js.map +1 -1
- package/es/interface/animate.d.ts +39 -5
- package/es/interface/animate.js.map +1 -1
- package/es/interface/graphic/path.d.ts +0 -1
- package/es/interface/graphic/path.js.map +1 -1
- package/es/interface/graphic/symbol.d.ts +0 -2
- package/es/interface/graphic/symbol.js.map +1 -1
- package/es/interface/graphic.d.ts +2 -6
- package/es/interface/graphic.js.map +1 -1
- package/es/interface/path.d.ts +0 -5
- package/es/interface/path.js.map +1 -1
- package/es/interface/picker.d.ts +0 -13
- package/es/interface/picker.js.map +1 -1
- package/es/picker/constants.d.ts +0 -2
- package/es/picker/constants.js +0 -4
- package/es/picker/constants.js.map +1 -1
- package/es/picker/pick-interceptor.d.ts +2 -7
- package/es/picker/pick-interceptor.js +1 -19
- package/es/picker/pick-interceptor.js.map +1 -1
- package/es/picker/pick-modules.js +3 -5
- package/es/picker/pick-modules.js.map +1 -1
- package/es/picker/picker-service.d.ts +2 -4
- 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 +5 -6
- package/es/plugins/builtin-plugin/edit-module.js +25 -79
- package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +30 -49
- package/es/plugins/builtin-plugin/richtext-edit-plugin.js +214 -283
- 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 +0 -1
- package/es/render/contributions/render/base-render.js +2 -21
- package/es/render/contributions/render/base-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js +2 -29
- package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/image-contribution-render.d.ts +2 -6
- package/es/render/contributions/render/contributions/image-contribution-render.js +2 -52
- package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
- package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +1 -8
- package/es/render/contributions/render/contributions/symbol-contribution-render.js +0 -26
- package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
- package/es/render/contributions/render/image-render.js +12 -12
- 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/symbol-render.js +13 -16
- package/es/render/contributions/render/symbol-render.js.map +1 -1
- package/es/render/contributions/render/utils.d.ts +2 -1
- package/es/render/contributions/render/utils.js +18 -0
- package/es/render/contributions/render/utils.js.map +1 -1
- package/package.json +1 -1
- package/cjs/animate/easing-func.d.ts +0 -1
- package/cjs/animate/easing-func.js +0 -16
- package/cjs/animate/easing-func.js.map +0 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +0 -1
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +0 -3
- package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +0 -1
- package/es/animate/easing-func.d.ts +0 -1
- package/es/animate/easing-func.js +0 -10
- package/es/animate/easing-func.js.map +0 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +0 -1
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +0 -3
- package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/picker.ts"],"names":[],"mappings":"","file":"picker.js","sourcesContent":["import type { IBounds, IMatrix, IPoint, IPointLike } from '@visactor/vutils';\nimport type { IGraphic } from './graphic';\nimport type { IContext2d } from './context';\nimport type { EnvType, IGlobal } from './global';\nimport type { IGroup } from './graphic/group';\nimport type { IDrawContribution } from './render';\n\ntype ISubPickEventParams =\n | boolean\n | {\n graphic?: any;\n group?: any;\n params: ISubPickEventParams;\n };\n\nexport type IPickEventParams =\n | {\n shadowTarget?: IGraphic;\n }\n | ISubPickEventParams;\n\nexport type PickResult = {\n graphic?: IGraphic | null;\n group?: IGroup | null;\n params?:\n | {\n shadowTarget?: IGraphic;\n }\n | ISubPickEventParams;\n};\n\nexport interface IGraphicPicker {\n type: string;\n numberType: number;\n\n contains: (graphic: IGraphic, point: IPointLike, params?: IPickParams) => boolean | any;\n}\n\nexport interface IPickParams {\n group?: boolean;\n graphic?: boolean;\n bounds?: IBounds;\n pickContext?: IContext2d;\n pickerService?: IPickerService;\n // 内部设置\n in3dInterceptor?: boolean;\n hack_pieFace?: string;\n}\n\nexport interface IPickerService {\n type: string;\n\n pickContext?: IContext2d;\n pickerMap: Map<number, IGraphicPicker>;\n configure: (global: IGlobal, env: EnvType) => void;\n pick: (group: IGraphic[], point: IPoint, params?: IPickParams) => PickResult;\n pickGroup: (group: IGroup, point: IPointLike, parentMatrix: IMatrix, params: IPickParams) => PickResult;\n pickItem: (\n graphic: IGraphic,\n point: IPointLike,\n parentMatrix: IMatrix | null,\n params?: IPickParams\n ) => PickResult | null;\n containsPoint: (graphic: IGraphic, point: IPointLike, params?: IPickParams) => boolean;\n drawContribution?: IDrawContribution;\n}\n\nexport interface IPickItemInterceptorContribution {\n order: number;\n // null代表没匹配到,boolean代表是否pick中\n beforePickItem?: (\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n drawContext: {\n in3dInterceptor?: boolean;\n },\n params?: {\n parentMatrix: IMatrix;\n }\n ) => PickResult | null;\n\n afterPickItem?: (\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n drawContext: {\n in3dInterceptor?: boolean;\n },\n params?: {\n parentMatrix: IMatrix;\n }\n ) => PickResult | null;\n // afterPickItem?: (\n // graphic: IGraphic,\n // pickerService: IPickerService,\n // ) => boolean;\n}\
|
|
1
|
+
{"version":3,"sources":["../src/interface/picker.ts"],"names":[],"mappings":"","file":"picker.js","sourcesContent":["import type { IBounds, IMatrix, IPoint, IPointLike } from '@visactor/vutils';\nimport type { IGraphic } from './graphic';\nimport type { IContext2d } from './context';\nimport type { EnvType, IGlobal } from './global';\nimport type { IGroup } from './graphic/group';\nimport type { IDrawContribution } from './render';\n\ntype ISubPickEventParams =\n | boolean\n | {\n graphic?: any;\n group?: any;\n params: ISubPickEventParams;\n };\n\nexport type IPickEventParams =\n | {\n shadowTarget?: IGraphic;\n }\n | ISubPickEventParams;\n\nexport type PickResult = {\n graphic?: IGraphic | null;\n group?: IGroup | null;\n params?:\n | {\n shadowTarget?: IGraphic;\n }\n | ISubPickEventParams;\n};\n\nexport interface IGraphicPicker {\n type: string;\n numberType: number;\n\n contains: (graphic: IGraphic, point: IPointLike, params?: IPickParams) => boolean | any;\n}\n\nexport interface IPickParams {\n group?: boolean;\n graphic?: boolean;\n bounds?: IBounds;\n pickContext?: IContext2d;\n pickerService?: IPickerService;\n // 内部设置\n in3dInterceptor?: boolean;\n hack_pieFace?: string;\n}\n\nexport interface IPickerService {\n type: string;\n\n pickContext?: IContext2d;\n pickerMap: Map<number, IGraphicPicker>;\n configure: (global: IGlobal, env: EnvType) => void;\n pick: (group: IGraphic[], point: IPoint, params?: IPickParams) => PickResult;\n pickGroup: (group: IGroup, point: IPointLike, parentMatrix: IMatrix, params: IPickParams) => PickResult;\n pickItem: (\n graphic: IGraphic,\n point: IPointLike,\n parentMatrix: IMatrix | null,\n params?: IPickParams\n ) => PickResult | null;\n containsPoint: (graphic: IGraphic, point: IPointLike, params?: IPickParams) => boolean;\n drawContribution?: IDrawContribution;\n}\n\nexport interface IPickItemInterceptorContribution {\n order: number;\n // null代表没匹配到,boolean代表是否pick中\n beforePickItem?: (\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n drawContext: {\n in3dInterceptor?: boolean;\n },\n params?: {\n parentMatrix: IMatrix;\n }\n ) => PickResult | null;\n\n afterPickItem?: (\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n drawContext: {\n in3dInterceptor?: boolean;\n },\n params?: {\n parentMatrix: IMatrix;\n }\n ) => PickResult | null;\n // afterPickItem?: (\n // graphic: IGraphic,\n // pickerService: IPickerService,\n // ) => boolean;\n}\n\nexport interface IBoundsPicker {\n type: string;\n numberType?: number;\n\n contains: (graphic: IGraphic, point: IPointLike, params?: IPickParams) => boolean;\n}\n"]}
|
package/es/picker/constants.d.ts
CHANGED
|
@@ -2,5 +2,3 @@ export declare const GraphicPicker: unique symbol;
|
|
|
2
2
|
export declare const PickerService: unique symbol;
|
|
3
3
|
export declare const BoundsPicker: unique symbol;
|
|
4
4
|
export declare const GlobalPickerService: unique symbol;
|
|
5
|
-
export declare const PickItemInterceptor: unique symbol;
|
|
6
|
-
export declare const PickServiceInterceptor: unique symbol;
|
package/es/picker/constants.js
CHANGED
|
@@ -5,8 +5,4 @@ export const PickerService = Symbol.for("PickerService");
|
|
|
5
5
|
export const BoundsPicker = Symbol.for("BoundsPicker");
|
|
6
6
|
|
|
7
7
|
export const GlobalPickerService = Symbol.for("GlobalPickerService");
|
|
8
|
-
|
|
9
|
-
export const PickItemInterceptor = Symbol.for("PickItemInterceptor");
|
|
10
|
-
|
|
11
|
-
export const PickServiceInterceptor = Symbol.for("PickServiceInterceptor");
|
|
12
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/picker/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC
|
|
1
|
+
{"version":3,"sources":["../src/picker/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC","file":"constants.js","sourcesContent":["export const GraphicPicker = Symbol.for('GraphicPicker');\nexport const PickerService = Symbol.for('PickerService');\n\nexport const BoundsPicker = Symbol.for('BoundsPicker');\nexport const GlobalPickerService = Symbol.for('GlobalPickerService');\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { IMatrix, IPointLike } from '@visactor/vutils';
|
|
2
|
-
import type { IContext2d, IGraphic, IPickItemInterceptorContribution, IPickParams,
|
|
3
|
-
export declare
|
|
4
|
-
order: number;
|
|
5
|
-
afterPickItem(result: PickResult, pickerService: IPickerService, point: IPointLike, pickParams: IPickParams, params?: {
|
|
6
|
-
parentMatrix: IMatrix;
|
|
7
|
-
}): null | PickResult;
|
|
8
|
-
}
|
|
2
|
+
import type { IContext2d, IGraphic, IPickItemInterceptorContribution, IPickParams, IPickerService, PickResult } from '../interface';
|
|
3
|
+
export declare const PickItemInterceptor: unique symbol;
|
|
9
4
|
export declare class ShadowRootPickItemInterceptorContribution implements IPickItemInterceptorContribution {
|
|
10
5
|
order: number;
|
|
11
6
|
afterPickItem(graphic: IGraphic, pickerService: IPickerService, point: IPointLike, pickParams: IPickParams, params?: {
|
|
@@ -14,25 +14,7 @@ import { draw3dItem } from "../common/3d-interceptor";
|
|
|
14
14
|
|
|
15
15
|
import { getTheme } from "../graphic";
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
this.order = 1;
|
|
20
|
-
}
|
|
21
|
-
afterPickItem(result, pickerService, point, pickParams, params) {
|
|
22
|
-
if (result.graphic) {
|
|
23
|
-
let g = result.graphic;
|
|
24
|
-
for (;g.parent; ) g = g.parent;
|
|
25
|
-
g.shadowHost && (result.params = {
|
|
26
|
-
shadowTarget: result.graphic
|
|
27
|
-
}, result.graphic = g.shadowHost);
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
ShadowPickServiceInterceptorContribution = __decorate([ injectable() ], ShadowPickServiceInterceptorContribution);
|
|
34
|
-
|
|
35
|
-
export { ShadowPickServiceInterceptorContribution };
|
|
17
|
+
export const PickItemInterceptor = Symbol.for("PickItemInterceptor");
|
|
36
18
|
|
|
37
19
|
let ShadowRootPickItemInterceptorContribution = class {
|
|
38
20
|
constructor() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/picker/pick-interceptor.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAWtD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG/B,IAAM,wCAAwC,GAA9C,MAAM,wCAAwC;IAA9C;QACL,UAAK,GAAW,CAAC,CAAC;IAwBpB,CAAC;IAvBC,aAAa,CACX,MAAkB,EAClB,aAA6B,EAC7B,KAAiB,EACjB,UAAuB,EACvB,MAEC;QAED,IAAI,MAAM,CAAC,OAAO,EAAE;YAClB,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;YACvB,OAAO,CAAC,CAAC,MAAM,EAAE;gBACf,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;aACd;YACD,IAAI,CAAC,CAAC,UAAU,EAAE;gBAChB,MAAM,CAAC,MAAM,GAAG;oBACd,YAAY,EAAE,MAAM,CAAC,OAAO;iBAC7B,CAAC;gBACF,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,UAAU,CAAC;aAC/B;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AAzBY,wCAAwC;IADpD,UAAU,EAAE;GACA,wCAAwC,CAyBpD;SAzBY,wCAAwC;AA+B9C,IAAM,yCAAyC,GAA/C,MAAM,yCAAyC;IAA/C;QACL,UAAK,GAAW,CAAC,CAAC;IAiFpB,CAAC;IAhFC,aAAa,CACX,OAAiB,EACjB,aAA6B,EAC7B,KAAiB,EACjB,UAAuB,EACvB,MAEC;QAED,IAAI,O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AAa,CAAC,SAAS,CAAC,OAAiB,EAAE,KAAK,EAAE,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;YAC5F,CAAC,EACD,UAAU,CACX,CAAC;YAEF,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YAEtB,UAAU,CAAC,eAAe,GAAG,KAAK,CAAC;YACnC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,MAAM,CAAC;SACf;QACD,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,OAAmB;QAC/B,OAAO,CAAC,sBAAsB,EAAE,CAAC;IACnC,CAAC;CACF,CAAA;AArDY,2BAA2B;IADvC,UAAU,EAAE;GACA,2BAA2B,CAqDvC;SArDY,2BAA2B","file":"pick-interceptor.js","sourcesContent":["import type { IMatrix, IPointLike } from '@visactor/vutils';\nimport { Point } from '@visactor/vutils';\nimport { injectable } from '../common/inversify-lite';\nimport type {\n IContext2d,\n IGraphic,\n IGroup,\n IPickItemInterceptorContribution,\n IPickParams,\n IPickServiceInterceptorContribution,\n IPickerService,\n PickResult\n} from '../interface';\nimport { matrixAllocate } from '../allocator/matrix-allocate';\nimport { draw3dItem } from '../common/3d-interceptor';\nimport { getTheme } from '../graphic';\n\n@injectable()\nexport class ShadowPickServiceInterceptorContribution implements IPickServiceInterceptorContribution {\n order: number = 1;\n afterPickItem(\n result: PickResult,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n if (result.graphic) {\n let g = result.graphic;\n while (g.parent) {\n g = g.parent;\n }\n if (g.shadowHost) {\n result.params = {\n shadowTarget: result.graphic\n };\n result.graphic = g.shadowHost;\n }\n }\n return result;\n }\n}\n\n/**\n * 影子节点拦截器,用于渲染影子节点\n */\n@injectable()\nexport class ShadowRootPickItemInterceptorContribution implements IPickItemInterceptorContribution {\n order: number = 1;\n afterPickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n if (graphic.attribute.shadowRootIdx > 0 || !graphic.attribute.shadowRootIdx) {\n return this._pickItem(graphic, pickerService, point, pickParams, params);\n }\n return null;\n }\n\n beforePickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n if (graphic.attribute.shadowRootIdx < 0) {\n return this._pickItem(graphic, pickerService, point, pickParams, params);\n }\n return null;\n }\n\n protected _pickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): PickResult | null {\n if (!graphic.shadowRoot) {\n return null;\n }\n const { parentMatrix } = params || {};\n if (!parentMatrix) {\n return null;\n }\n\n const context = pickerService.pickContext;\n context.highPerformanceSave();\n\n const theme = (getTheme(graphic) as any)?.[graphic.type];\n const { shadowPickMode = theme?.shadowPickMode } = graphic.attribute;\n const g = graphic.shadowRoot;\n const currentGroupMatrix = matrixAllocate.allocateByObj(parentMatrix);\n const newPoint = new Point(\n currentGroupMatrix.a * point.x + currentGroupMatrix.c * point.y + currentGroupMatrix.e,\n currentGroupMatrix.b * point.x + currentGroupMatrix.d * point.y + currentGroupMatrix.f\n );\n // const transMatrix = graphic.transMatrix;\n // currentGroupMatrix.multiply(\n // transMatrix.a,\n // transMatrix.b,\n // transMatrix.c,\n // transMatrix.d,\n // transMatrix.e,\n // transMatrix.f\n // );\n\n // currentGroupMatrix.transformPoint(newPoint, newPoint);\n const result = pickerService.pickGroup(g, newPoint, currentGroupMatrix, pickParams);\n\n context.highPerformanceRestore();\n\n // 影子节点pick到group也算pick到graphic\n if (!result.graphic && result.group && shadowPickMode === 'full') {\n result.graphic = result.group;\n }\n\n return result;\n }\n}\n\n@injectable()\nexport class InteractivePickItemInterceptorContribution implements IPickItemInterceptorContribution {\n order: number = 1;\n\n beforePickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n const originGraphic = graphic.baseGraphic;\n if (originGraphic && originGraphic.parent) {\n const newPoint = new Point(point.x, point.y);\n const context = pickerService.pickContext;\n context.highPerformanceSave();\n const parentMatrix = originGraphic.parent.globalTransMatrix;\n parentMatrix.transformPoint(newPoint, newPoint);\n\n const result = originGraphic.isContainer\n ? pickerService.pickGroup(originGraphic, newPoint.clone(), parentMatrix, pickParams)\n : pickerService.pickItem(originGraphic, newPoint.clone(), parentMatrix, pickParams);\n context.highPerformanceRestore();\n return result;\n }\n return null;\n }\n}\n\n/**\n * 3d拦截器,用于渲染3d视角\n */\n@injectable()\nexport class Canvas3DPickItemInterceptor implements IPickItemInterceptorContribution {\n // canvas?: ICanvas;\n order: number = 1;\n\n beforePickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ) {\n if (!graphic.in3dMode || pickParams.in3dInterceptor) {\n return null;\n }\n\n const context = pickerService.pickContext;\n const stage = graphic.stage;\n if (!(context && stage)) {\n return null;\n }\n pickParams.in3dInterceptor = true;\n\n // 使用3d模式渲染\n context.save();\n this.initCanvasCtx(context);\n context.camera = stage.camera;\n\n // 设置context的transform到上一个节点\n if (graphic.isContainer) {\n const result = draw3dItem(\n context,\n graphic,\n () => {\n return pickerService.pickGroup(graphic as IGroup, point, params.parentMatrix, pickParams);\n },\n pickParams\n );\n\n context.camera = null;\n\n pickParams.in3dInterceptor = false;\n context.restore();\n return result;\n }\n context.restore();\n return null;\n }\n\n initCanvasCtx(context: IContext2d) {\n context.setTransformForCurrent();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/picker/pick-interceptor.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EAAE,KA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AO,IAAI,CAAC;SACb;QAED,MAAM,OAAO,GAAG,aAAa,CAAC,WAAW,CAAC;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,CAAC,OAAO,IAAI,KAAK,CAAC,EAAE;YACvB,OAAO,IAAI,CAAC;SACb;QACD,UAAU,CAAC,eAAe,GAAG,IAAI,CAAC;QAGlC,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAG9B,IAAI,OAAO,CAAC,WAAW,EAAE;YACvB,MAAM,MAAM,GAAG,UAAU,CACvB,OAAO,EACP,OAAO,EACP,GAAG,EAAE;gBACH,OAAO,aAAa,CAAC,SAAS,CAAC,OAAiB,EAAE,KAAK,EAAE,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;YAC5F,CAAC,EACD,UAAU,CACX,CAAC;YAEF,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;YAEtB,UAAU,CAAC,eAAe,GAAG,KAAK,CAAC;YACnC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,MAAM,CAAC;SACf;QACD,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,aAAa,CAAC,OAAmB;QAC/B,OAAO,CAAC,sBAAsB,EAAE,CAAC;IACnC,CAAC;CACF,CAAA;AArDY,2BAA2B;IADvC,UAAU,EAAE;GACA,2BAA2B,CAqDvC;SArDY,2BAA2B","file":"pick-interceptor.js","sourcesContent":["import type { IMatrix, IPointLike } from '@visactor/vutils';\nimport { Point } from '@visactor/vutils';\nimport { injectable } from '../common/inversify-lite';\nimport type {\n IContext2d,\n IGraphic,\n IGroup,\n IPickItemInterceptorContribution,\n IPickParams,\n IPickerService,\n PickResult\n} from '../interface';\nimport { matrixAllocate } from '../allocator/matrix-allocate';\nimport { draw3dItem } from '../common/3d-interceptor';\nimport { getTheme } from '../graphic';\n\n// 拦截器\nexport const PickItemInterceptor = Symbol.for('PickItemInterceptor');\n\n/**\n * 影子节点拦截器,用于渲染影子节点\n */\n@injectable()\nexport class ShadowRootPickItemInterceptorContribution implements IPickItemInterceptorContribution {\n order: number = 1;\n afterPickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n if (graphic.attribute.shadowRootIdx > 0 || !graphic.attribute.shadowRootIdx) {\n return this._pickItem(graphic, pickerService, point, pickParams, params);\n }\n return null;\n }\n\n beforePickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n if (graphic.attribute.shadowRootIdx < 0) {\n return this._pickItem(graphic, pickerService, point, pickParams, params);\n }\n return null;\n }\n\n protected _pickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): PickResult | null {\n if (!graphic.shadowRoot) {\n return null;\n }\n const { parentMatrix } = params || {};\n if (!parentMatrix) {\n return null;\n }\n\n const context = pickerService.pickContext;\n context.highPerformanceSave();\n\n const theme = (getTheme(graphic) as any)?.[graphic.type];\n const { shadowPickMode = theme?.shadowPickMode } = graphic.attribute;\n const g = graphic.shadowRoot;\n const currentGroupMatrix = matrixAllocate.allocateByObj(parentMatrix);\n const newPoint = new Point(\n currentGroupMatrix.a * point.x + currentGroupMatrix.c * point.y + currentGroupMatrix.e,\n currentGroupMatrix.b * point.x + currentGroupMatrix.d * point.y + currentGroupMatrix.f\n );\n // const transMatrix = graphic.transMatrix;\n // currentGroupMatrix.multiply(\n // transMatrix.a,\n // transMatrix.b,\n // transMatrix.c,\n // transMatrix.d,\n // transMatrix.e,\n // transMatrix.f\n // );\n\n // currentGroupMatrix.transformPoint(newPoint, newPoint);\n const result = pickerService.pickGroup(g, newPoint, currentGroupMatrix, pickParams);\n\n context.highPerformanceRestore();\n\n // 影子节点pick到group也算pick到graphic\n if (!result.graphic && result.group && shadowPickMode === 'full') {\n result.graphic = result.group;\n }\n\n return result;\n }\n}\n\n@injectable()\nexport class InteractivePickItemInterceptorContribution implements IPickItemInterceptorContribution {\n order: number = 1;\n\n beforePickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ): null | PickResult {\n const originGraphic = graphic.baseGraphic;\n if (originGraphic && originGraphic.parent) {\n const newPoint = new Point(point.x, point.y);\n const context = pickerService.pickContext;\n context.highPerformanceSave();\n const parentMatrix = originGraphic.parent.globalTransMatrix;\n parentMatrix.transformPoint(newPoint, newPoint);\n\n const result = originGraphic.isContainer\n ? pickerService.pickGroup(originGraphic, newPoint.clone(), parentMatrix, pickParams)\n : pickerService.pickItem(originGraphic, newPoint.clone(), parentMatrix, pickParams);\n context.highPerformanceRestore();\n return result;\n }\n return null;\n }\n}\n\n/**\n * 3d拦截器,用于渲染3d视角\n */\n@injectable()\nexport class Canvas3DPickItemInterceptor implements IPickItemInterceptorContribution {\n // canvas?: ICanvas;\n order: number = 1;\n\n beforePickItem(\n graphic: IGraphic,\n pickerService: IPickerService,\n point: IPointLike,\n pickParams: IPickParams,\n params?: {\n parentMatrix: IMatrix;\n }\n ) {\n if (!graphic.in3dMode || pickParams.in3dInterceptor) {\n return null;\n }\n\n const context = pickerService.pickContext;\n const stage = graphic.stage;\n if (!(context && stage)) {\n return null;\n }\n pickParams.in3dInterceptor = true;\n\n // 使用3d模式渲染\n context.save();\n this.initCanvasCtx(context);\n context.camera = stage.camera;\n\n // 设置context的transform到上一个节点\n if (graphic.isContainer) {\n const result = draw3dItem(\n context,\n graphic,\n () => {\n return pickerService.pickGroup(graphic as IGroup, point, params.parentMatrix, pickParams);\n },\n pickParams\n );\n\n context.camera = null;\n\n pickParams.in3dInterceptor = false;\n context.restore();\n return result;\n }\n context.restore();\n return null;\n }\n\n initCanvasCtx(context: IContext2d) {\n context.setTransformForCurrent();\n }\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ContainerModule } from "../common/inversify-lite";
|
|
2
2
|
|
|
3
|
-
import { PickerService, GlobalPickerService
|
|
3
|
+
import { PickerService, GlobalPickerService } from "./constants";
|
|
4
4
|
|
|
5
|
-
import { Canvas3DPickItemInterceptor, InteractivePickItemInterceptorContribution,
|
|
5
|
+
import { Canvas3DPickItemInterceptor, InteractivePickItemInterceptorContribution, PickItemInterceptor, ShadowRootPickItemInterceptorContribution } from "./pick-interceptor";
|
|
6
6
|
|
|
7
7
|
import { bindContributionProvider } from "../common/contribution-provider";
|
|
8
8
|
|
|
@@ -11,8 +11,6 @@ export default new ContainerModule(((bind, unbind, isBound) => {
|
|
|
11
11
|
bind(Canvas3DPickItemInterceptor).toSelf().inSingletonScope(), bind(PickItemInterceptor).toService(Canvas3DPickItemInterceptor),
|
|
12
12
|
bind(ShadowRootPickItemInterceptorContribution).toSelf().inSingletonScope(), bind(PickItemInterceptor).toService(ShadowRootPickItemInterceptorContribution),
|
|
13
13
|
bind(InteractivePickItemInterceptorContribution).toSelf().inSingletonScope(), bind(PickItemInterceptor).toService(InteractivePickItemInterceptorContribution),
|
|
14
|
-
bindContributionProvider(bind, PickItemInterceptor)
|
|
15
|
-
bind(PickServiceInterceptor).toService(ShadowPickServiceInterceptorContribution),
|
|
16
|
-
bindContributionProvider(bind, PickServiceInterceptor);
|
|
14
|
+
bindContributionProvider(bind, PickItemInterceptor);
|
|
17
15
|
}));
|
|
18
16
|
//# sourceMappingURL=pick-modules.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/picker/pick-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"sources":["../src/picker/pick-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIjE,OAAO,EACL,2BAA2B,EAC3B,0CAA0C,EAC1C,mBAAmB,EACnB,yCAAyC,EAC1C,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,eAAe,IAAI,eAAe,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE;IAC3D,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;QAC3B,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,EAAE,CAAC;QACnC,IAAI,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;KACpD;IAOD,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC9D,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAGjE,IAAI,CAAC,yCAAyC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC5E,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,yCAAyC,CAAC,CAAC;IAG/E,IAAI,CAAC,0CAA0C,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC7E,IAAI,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,0CAA0C,CAAC,CAAC;IAChF,wBAAwB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC","file":"pick-modules.js","sourcesContent":["import { ContainerModule } from '../common/inversify-lite';\nimport { PickerService, GlobalPickerService } from './constants';\nimport { DefaultGlobalPickerService } from './global-picker-service';\n// import { DefaultCanvasPickerService } from './canvas-picker-service';\n// import { DefaultMathPickerService } from './math-picker-service';\nimport {\n Canvas3DPickItemInterceptor,\n InteractivePickItemInterceptorContribution,\n PickItemInterceptor,\n ShadowRootPickItemInterceptorContribution\n} from './pick-interceptor';\nimport { bindContributionProvider } from '../common/contribution-provider';\n\nexport default new ContainerModule((bind, unbind, isBound) => {\n if (!isBound(PickerService)) {\n bind(GlobalPickerService).toSelf();\n bind(PickerService).toService(GlobalPickerService);\n }\n // bind(PickerService).toService(GlobalPickerService);\n\n // bind(DefaultGlobalPickerService).toSelf().inSingletonScope();\n // bind(GlobalPickerService).toService(DefaultGlobalPickerService);\n\n // interceptor\n bind(Canvas3DPickItemInterceptor).toSelf().inSingletonScope();\n bind(PickItemInterceptor).toService(Canvas3DPickItemInterceptor);\n\n // shadow root\n bind(ShadowRootPickItemInterceptorContribution).toSelf().inSingletonScope();\n bind(PickItemInterceptor).toService(ShadowRootPickItemInterceptorContribution);\n\n // interactive\n bind(InteractivePickItemInterceptorContribution).toSelf().inSingletonScope();\n bind(PickItemInterceptor).toService(InteractivePickItemInterceptorContribution);\n bindContributionProvider(bind, PickItemInterceptor);\n});\n"]}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { IMatrix, IPoint, IPointLike } from '@visactor/vutils';
|
|
2
|
-
import type { IContext2d, IGraphic, IGroup, EnvType, IGlobal, IPickerService, IGraphicPicker, IPickParams, PickResult, IPickItemInterceptorContribution, IContributionProvider
|
|
2
|
+
import type { IContext2d, IGraphic, IGroup, EnvType, IGlobal, IPickerService, IGraphicPicker, IPickParams, PickResult, IPickItemInterceptorContribution, IContributionProvider } from '../interface';
|
|
3
3
|
export declare abstract class DefaultPickService implements IPickerService {
|
|
4
4
|
protected readonly pickItemInterceptorContributions: IContributionProvider<IPickItemInterceptorContribution>;
|
|
5
|
-
protected readonly pickServiceInterceptorContributions: IContributionProvider<IPickServiceInterceptorContribution>;
|
|
6
5
|
type: string;
|
|
7
6
|
pickerMap: Map<number, IGraphicPicker>;
|
|
8
7
|
pickContext?: IContext2d;
|
|
9
8
|
InterceptorContributions: IPickItemInterceptorContribution[];
|
|
10
|
-
pickerServiceInterceptorContributions: IPickServiceInterceptorContribution[];
|
|
11
9
|
global: IGlobal;
|
|
12
|
-
constructor(pickItemInterceptorContributions: IContributionProvider<IPickItemInterceptorContribution
|
|
10
|
+
constructor(pickItemInterceptorContributions: IContributionProvider<IPickItemInterceptorContribution>);
|
|
13
11
|
protected _init(): void;
|
|
14
12
|
abstract configure(global: IGlobal, env: EnvType): void;
|
|
15
13
|
pick(graphics: IGraphic[], point: IPoint, params: IPickParams): PickResult;
|
|
@@ -26,18 +26,17 @@ import { mat3Tomat4, multiplyMat4Mat4 } from "../common/matrix";
|
|
|
26
26
|
|
|
27
27
|
import { mat4Allocate, matrixAllocate } from "../allocator/matrix-allocate";
|
|
28
28
|
|
|
29
|
-
import {
|
|
29
|
+
import { PickItemInterceptor } from "./pick-interceptor";
|
|
30
30
|
|
|
31
|
-
import {
|
|
31
|
+
import { application } from "../application";
|
|
32
32
|
|
|
33
33
|
let DefaultPickService = class {
|
|
34
|
-
constructor(pickItemInterceptorContributions
|
|
35
|
-
this.pickItemInterceptorContributions = pickItemInterceptorContributions, this.
|
|
36
|
-
this.
|
|
34
|
+
constructor(pickItemInterceptorContributions) {
|
|
35
|
+
this.pickItemInterceptorContributions = pickItemInterceptorContributions, this.type = "default",
|
|
36
|
+
this.global = application.global;
|
|
37
37
|
}
|
|
38
38
|
_init() {
|
|
39
|
-
this.InterceptorContributions = this.pickItemInterceptorContributions.getContributions().sort(((a, b) => a.order - b.order))
|
|
40
|
-
this.pickerServiceInterceptorContributions = this.pickServiceInterceptorContributions.getContributions().sort(((a, b) => a.order - b.order));
|
|
39
|
+
this.InterceptorContributions = this.pickItemInterceptorContributions.getContributions().sort(((a, b) => a.order - b.order));
|
|
41
40
|
}
|
|
42
41
|
pick(graphics, point, params) {
|
|
43
42
|
let result = {
|
|
@@ -54,11 +53,12 @@ let DefaultPickService = class {
|
|
|
54
53
|
for (let i = graphics.length - 1; i >= 0 && (result = graphics[i].isContainer ? this.pickGroup(graphics[i], point, parentMatrix, params) : this.pickItem(graphics[i], point, parentMatrix, params),
|
|
55
54
|
!result.graphic); i--) group || (group = result.group);
|
|
56
55
|
if (result.graphic || (result.group = group), this.pickContext && (this.pickContext.inuse = !1),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
result.graphic) {
|
|
57
|
+
let g = result.graphic;
|
|
58
|
+
for (;g.parent; ) g = g.parent;
|
|
59
|
+
g.shadowHost && (result.params = {
|
|
60
|
+
shadowTarget: result.graphic
|
|
61
|
+
}, result.graphic = g.shadowHost);
|
|
62
62
|
}
|
|
63
63
|
return result;
|
|
64
64
|
}
|
|
@@ -126,7 +126,7 @@ let DefaultPickService = class {
|
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
-
DefaultPickService = __decorate([ injectable(), __param(0, inject(ContributionProvider)), __param(0, named(PickItemInterceptor)),
|
|
129
|
+
DefaultPickService = __decorate([ injectable(), __param(0, inject(ContributionProvider)), __param(0, named(PickItemInterceptor)), __metadata("design:paramtypes", [ Object ]) ], DefaultPickService);
|
|
130
130
|
|
|
131
131
|
export { DefaultPickService };
|
|
132
132
|
//# sourceMappingURL=picker-service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/picker/picker-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,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C,MAAM,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YAC5C,CAAC,EACD,IAAI,EACJ,CAAC,CAAC,OAAO,CAAC,MAAM,CACjB,CAAC;SACH;QACD,IAAI,OAAO,CAAC,WAAW,KAAK,UAAU,EAAE;YACtC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SACxC;QACD,OAAO,CAAC,WAAW,GAAG,UAAU,CAAC;QAEjC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,WAAW,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE;YAC1E,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;SACtB;QACD,cAAc,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACxC,OAAO,MAAM,CAAC;IAChB,CAAC;IAUS,YAAY,CAAC,OAAiB;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,IAAI,CAAC;SACb;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA7OqB,kBAAkB;IADvC,UAAU,EAAE;IAYR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,mBAAmB,CAAC,CAAA;IAG1B,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,sBAAsB,CAAC,CAAA;;GAhBZ,kBAAkB,CA6OvC;SA7OqB,kBAAkB","file":"picker-service.js","sourcesContent":["import type { IMatrix, IPoint, IPointLike } from '@visactor/vutils';\nimport { AABBBounds, Matrix, Point } from '@visactor/vutils';\nimport { inject, injectable, named } from '../common/inversify-lite';\nimport { foreach } from '../common/sort';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport type {\n IContext2d,\n IGraphic,\n IGroup,\n EnvType,\n IGlobal,\n IPickerService,\n IGraphicPicker,\n IPickParams,\n PickResult,\n IPickItemInterceptorContribution,\n IContributionProvider,\n IPickServiceInterceptorContribution\n} from '../interface';\nimport { getTheme } from '../graphic/theme';\nimport { DefaultAttribute } from '../graphic/config';\nimport { mat3Tomat4, multiplyMat4Mat4 } from '../common/matrix';\nimport { mat4Allocate, matrixAllocate } from '../allocator/matrix-allocate';\nimport { application } from '../application';\nimport { PickItemInterceptor, PickServiceInterceptor } from './constants';\n\n@injectable()\nexport abstract class DefaultPickService implements IPickerService {\n type: string = 'default';\n declare pickerMap: Map<number, IGraphicPicker>;\n declare pickContext?: IContext2d;\n declare InterceptorContributions: IPickItemInterceptorContribution[];\n declare pickerServiceInterceptorContributions: IPickServiceInterceptorContribution[];\n declare global: IGlobal;\n\n constructor(\n // 拦截器\n // @ts-ignore\n @inject(ContributionProvider)\n @named(PickItemInterceptor)\n protected readonly pickItemInterceptorContributions: IContributionProvider<IPickItemInterceptorContribution>,\n // @ts-ignore\n @inject(ContributionProvider)\n @named(PickServiceInterceptor)\n protected readonly pickServiceInterceptorContributions: IContributionProvider<IPickServiceInterceptorContribution>\n ) {\n this.global = application.global;\n }\n\n protected _init() {\n this.InterceptorContributions = this.pickItemInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n this.pickerServiceInterceptorContributions = this.pickServiceInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n }\n\n abstract configure(global: IGlobal, env: EnvType): void;\n\n // todo: params支持\n // todo: 性能优化\n pick(graphics: IGraphic[], point: IPoint, params: IPickParams): PickResult {\n let result: PickResult = {\n graphic: null,\n group: null\n };\n // point变换\n params.pickerService = this;\n\n const w = params.bounds.width();\n const h = params.bounds.height();\n if (!new AABBBounds().setValue(0, 0, w, h).containsPoint(point)) {\n return result;\n }\n if (this.pickContext) {\n this.pickContext.inuse = true;\n }\n params.pickContext = this.pickContext;\n this.pickContext && this.pickContext.clearMatrix(true, 1);\n\n const parentMatrix = new Matrix(1, 0, 0, 1, 0, 0);\n let group: IGroup;\n for (let i = graphics.length - 1; i >= 0; i--) {\n if (graphics[i].isContainer) {\n result = this.pickGroup(graphics[i] as IGroup, point, parentMatrix, params);\n } else {\n result = this.pickItem(graphics[i], point, parentMatrix, params);\n }\n if (result.graphic) {\n break;\n }\n if (!group) {\n group = result.group;\n }\n }\n if (!result.graphic) {\n result.group = group;\n }\n if (this.pickContext) {\n this.pickContext.inuse = false;\n }\n\n if (this.pickerServiceInterceptorContributions.length) {\n for (let i = 0; i < this.pickerServiceInterceptorContributions.length; i++) {\n const drawContribution = this.pickerServiceInterceptorContributions[i];\n if (drawContribution.afterPickItem) {\n result = drawContribution.afterPickItem(result, this, point, params, { parentMatrix });\n }\n }\n }\n // // 判断是否有shadow-dom\n // if (result.graphic) {\n // let g = result.graphic;\n // while (g.parent) {\n // g = g.parent;\n // }\n // if (g.shadowHost) {\n // result.params = {\n // shadowTarget: result.graphic\n // };\n // result.graphic = g.shadowHost;\n // }\n // }\n\n return result;\n }\n\n containsPoint(graphic: IGraphic, point: IPointLike, params: IPickParams): boolean {\n return !!this.pickItem(graphic, point, null, params ?? { pickContext: this.pickContext, pickerService: this })\n ?.graphic;\n }\n\n // TODO: 支持3d模式的拾取和自定义path的拾取\n pickGroup(group: IGroup, point: IPointLike, parentMatrix: IMatrix, params: IPickParams): PickResult {\n let result: PickResult = {\n group: null,\n graphic: null\n };\n if (group.attribute.visibleAll === false) {\n return result;\n }\n const context = params.pickContext;\n const lastMatrix = context.modelMatrix;\n // 如果是3d,那么需要生成modelMatrix\n if (context.camera) {\n const m = group.transMatrix;\n const matrix = mat4Allocate.allocate();\n mat3Tomat4(matrix, m);\n if (lastMatrix) {\n if (matrix) {\n const m = mat4Allocate.allocate();\n context.modelMatrix = multiplyMat4Mat4(m, lastMatrix, matrix);\n mat4Allocate.free(matrix);\n }\n } else {\n // 转化context的matrix为lastMatrix\n mat3Tomat4(matrix, group.globalTransMatrix);\n context.modelMatrix = matrix;\n }\n }\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (drawContribution.beforePickItem) {\n const result = drawContribution.beforePickItem(group, this, point, params, { parentMatrix });\n if (result) {\n if (context.modelMatrix !== lastMatrix) {\n mat4Allocate.free(context.modelMatrix);\n }\n context.modelMatrix = lastMatrix;\n return result;\n }\n }\n }\n }\n // 转换坐标空间\n const transMatrix = group.transMatrix;\n const currentGroupMatrix = matrixAllocate.allocateByObj(parentMatrix);\n const newPoint: IPoint = new Point(point.x, point.y);\n currentGroupMatrix.transformPoint(newPoint, newPoint);\n // todo: 支持带有path的group的选中\n const insideGroup = group.AABBBounds.containsPoint(newPoint);\n // 如果group没有被选中,直接跳过(如果是3d模式,那么继续)\n if (!insideGroup && !group.stage.camera) {\n return result;\n }\n // pickGroup,Group目前只支持拦截模式(用于shadow节点)\n const pickedItem = this.pickItem(group, newPoint.clone(), parentMatrix, params);\n if (pickedItem && pickedItem.graphic) {\n result.graphic = pickedItem.graphic;\n result.params = pickedItem.params;\n }\n const groupPicked = group.attribute.pickable !== false && insideGroup;\n\n currentGroupMatrix.multiply(\n transMatrix.a,\n transMatrix.b,\n transMatrix.c,\n transMatrix.d,\n transMatrix.e,\n transMatrix.f\n );\n if (group.attribute.childrenPickable !== false && !(pickedItem && pickedItem.graphic)) {\n foreach(\n group,\n DefaultAttribute.zIndex,\n (graphic: IGraphic) => {\n if (graphic.isContainer) {\n // 偏移scrollX和scrollY\n const newPoint: IPoint = new Point(point.x, point.y);\n const theme = getTheme(group).group;\n const { scrollX = theme.scrollX, scrollY = theme.scrollY } = group.attribute;\n newPoint.x -= scrollX;\n newPoint.y -= scrollY;\n result = this.pickGroup(graphic as IGroup, newPoint, currentGroupMatrix, params);\n } else {\n const newPoint: IPoint = new Point(point.x, point.y);\n currentGroupMatrix.transformPoint(newPoint, newPoint);\n // 偏移scrollX和scrollY\n const theme = getTheme(group).group;\n const { scrollX = theme.scrollX, scrollY = theme.scrollY } = group.attribute;\n newPoint.x -= scrollX;\n newPoint.y -= scrollY;\n const pickedItem = this.pickItem(graphic, newPoint, parentMatrix, params);\n if (pickedItem && pickedItem.graphic) {\n result.graphic = pickedItem.graphic;\n result.params = pickedItem.params;\n }\n }\n return !!result.graphic || !!result.group;\n },\n true,\n !!context.camera\n );\n }\n if (context.modelMatrix !== lastMatrix) {\n mat4Allocate.free(context.modelMatrix);\n }\n context.modelMatrix = lastMatrix;\n\n if (!result.graphic && !result.group && groupPicked && !group.stage.camera) {\n result.group = group;\n }\n matrixAllocate.free(currentGroupMatrix);\n return result;\n }\n\n // todo: switch统一改为数字map\n abstract pickItem(\n graphic: IGraphic,\n point: IPointLike,\n parentMatrix: IMatrix | null,\n params: IPickParams\n ): PickResult | null;\n\n protected selectPicker(graphic: IGraphic): IGraphicPicker | null {\n const picker = this.pickerMap.get(graphic.numberType);\n if (!picker) {\n return null;\n }\n return picker;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/picker/picker-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAcvE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,8BAA8B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AUS,YAAY,CAAC,OAAiB;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,IAAI,CAAC;SACb;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAA;AA5NqB,kBAAkB;IADvC,UAAU,EAAE;IAWR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAC5B,WAAA,KAAK,CAAC,mBAAmB,CAAC,CAAA;;GAXT,kBAAkB,CA4NvC;SA5NqB,kBAAkB","file":"picker-service.js","sourcesContent":["import type { IMatrix, IPoint, IPointLike } from '@visactor/vutils';\nimport { AABBBounds, Matrix, Point } from '@visactor/vutils';\nimport { inject, injectable, named } from '../common/inversify-lite';\nimport { foreach } from '../common/sort';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport { ContributionProvider } from '../common/contribution-provider';\nimport type {\n IContext2d,\n IGraphic,\n IGroup,\n EnvType,\n IGlobal,\n IPickerService,\n IGraphicPicker,\n IPickParams,\n PickResult,\n IPickItemInterceptorContribution,\n IContributionProvider\n} from '../interface';\nimport { getTheme } from '../graphic/theme';\nimport { DefaultAttribute } from '../graphic/config';\nimport { mat3Tomat4, multiplyMat4Mat4 } from '../common/matrix';\nimport { mat4Allocate, matrixAllocate } from '../allocator/matrix-allocate';\nimport { PickItemInterceptor } from './pick-interceptor';\nimport { application } from '../application';\n\n@injectable()\nexport abstract class DefaultPickService implements IPickerService {\n type: string = 'default';\n declare pickerMap: Map<number, IGraphicPicker>;\n declare pickContext?: IContext2d;\n declare InterceptorContributions: IPickItemInterceptorContribution[];\n declare global: IGlobal;\n\n constructor(\n // 拦截器\n // @ts-ignore\n @inject(ContributionProvider)\n @named(PickItemInterceptor)\n protected readonly pickItemInterceptorContributions: IContributionProvider<IPickItemInterceptorContribution>\n ) {\n this.global = application.global;\n }\n\n protected _init() {\n this.InterceptorContributions = this.pickItemInterceptorContributions\n .getContributions()\n .sort((a, b) => a.order - b.order);\n }\n\n abstract configure(global: IGlobal, env: EnvType): void;\n\n // todo: params支持\n // todo: 性能优化\n pick(graphics: IGraphic[], point: IPoint, params: IPickParams): PickResult {\n let result: PickResult = {\n graphic: null,\n group: null\n };\n // point变换\n params.pickerService = this;\n\n const w = params.bounds.width();\n const h = params.bounds.height();\n if (!new AABBBounds().setValue(0, 0, w, h).containsPoint(point)) {\n return result;\n }\n if (this.pickContext) {\n this.pickContext.inuse = true;\n }\n params.pickContext = this.pickContext;\n this.pickContext && this.pickContext.clearMatrix(true, 1);\n\n const parentMatrix = new Matrix(1, 0, 0, 1, 0, 0);\n let group: IGroup;\n for (let i = graphics.length - 1; i >= 0; i--) {\n if (graphics[i].isContainer) {\n result = this.pickGroup(graphics[i] as IGroup, point, parentMatrix, params);\n } else {\n result = this.pickItem(graphics[i], point, parentMatrix, params);\n }\n if (result.graphic) {\n break;\n }\n if (!group) {\n group = result.group;\n }\n }\n if (!result.graphic) {\n result.group = group;\n }\n if (this.pickContext) {\n this.pickContext.inuse = false;\n }\n\n // 判断是否有shadow-dom\n if (result.graphic) {\n let g = result.graphic;\n while (g.parent) {\n g = g.parent;\n }\n if (g.shadowHost) {\n result.params = {\n shadowTarget: result.graphic\n };\n result.graphic = g.shadowHost;\n }\n }\n return result;\n }\n\n containsPoint(graphic: IGraphic, point: IPointLike, params: IPickParams): boolean {\n return !!this.pickItem(graphic, point, null, params ?? { pickContext: this.pickContext, pickerService: this })\n ?.graphic;\n }\n\n // TODO: 支持3d模式的拾取和自定义path的拾取\n pickGroup(group: IGroup, point: IPointLike, parentMatrix: IMatrix, params: IPickParams): PickResult {\n let result: PickResult = {\n group: null,\n graphic: null\n };\n if (group.attribute.visibleAll === false) {\n return result;\n }\n const context = params.pickContext;\n const lastMatrix = context.modelMatrix;\n // 如果是3d,那么需要生成modelMatrix\n if (context.camera) {\n const m = group.transMatrix;\n const matrix = mat4Allocate.allocate();\n mat3Tomat4(matrix, m);\n if (lastMatrix) {\n if (matrix) {\n const m = mat4Allocate.allocate();\n context.modelMatrix = multiplyMat4Mat4(m, lastMatrix, matrix);\n mat4Allocate.free(matrix);\n }\n } else {\n // 转化context的matrix为lastMatrix\n mat3Tomat4(matrix, group.globalTransMatrix);\n context.modelMatrix = matrix;\n }\n }\n // 添加拦截器\n if (this.InterceptorContributions.length) {\n for (let i = 0; i < this.InterceptorContributions.length; i++) {\n const drawContribution = this.InterceptorContributions[i];\n if (drawContribution.beforePickItem) {\n const result = drawContribution.beforePickItem(group, this, point, params, { parentMatrix });\n if (result) {\n if (context.modelMatrix !== lastMatrix) {\n mat4Allocate.free(context.modelMatrix);\n }\n context.modelMatrix = lastMatrix;\n return result;\n }\n }\n }\n }\n // 转换坐标空间\n const transMatrix = group.transMatrix;\n const currentGroupMatrix = matrixAllocate.allocateByObj(parentMatrix);\n const newPoint: IPoint = new Point(point.x, point.y);\n currentGroupMatrix.transformPoint(newPoint, newPoint);\n // todo: 支持带有path的group的选中\n const insideGroup = group.AABBBounds.containsPoint(newPoint);\n // 如果group没有被选中,直接跳过(如果是3d模式,那么继续)\n if (!insideGroup && !group.stage.camera) {\n return result;\n }\n // pickGroup,Group目前只支持拦截模式(用于shadow节点)\n const pickedItem = this.pickItem(group, newPoint.clone(), parentMatrix, params);\n if (pickedItem && pickedItem.graphic) {\n result.graphic = pickedItem.graphic;\n result.params = pickedItem.params;\n }\n const groupPicked = group.attribute.pickable !== false && insideGroup;\n\n currentGroupMatrix.multiply(\n transMatrix.a,\n transMatrix.b,\n transMatrix.c,\n transMatrix.d,\n transMatrix.e,\n transMatrix.f\n );\n if (group.attribute.childrenPickable !== false && !(pickedItem && pickedItem.graphic)) {\n foreach(\n group,\n DefaultAttribute.zIndex,\n (graphic: IGraphic) => {\n if (graphic.isContainer) {\n // 偏移scrollX和scrollY\n const newPoint: IPoint = new Point(point.x, point.y);\n const theme = getTheme(group).group;\n const { scrollX = theme.scrollX, scrollY = theme.scrollY } = group.attribute;\n newPoint.x -= scrollX;\n newPoint.y -= scrollY;\n result = this.pickGroup(graphic as IGroup, newPoint, currentGroupMatrix, params);\n } else {\n const newPoint: IPoint = new Point(point.x, point.y);\n currentGroupMatrix.transformPoint(newPoint, newPoint);\n // 偏移scrollX和scrollY\n const theme = getTheme(group).group;\n const { scrollX = theme.scrollX, scrollY = theme.scrollY } = group.attribute;\n newPoint.x -= scrollX;\n newPoint.y -= scrollY;\n const pickedItem = this.pickItem(graphic, newPoint, parentMatrix, params);\n if (pickedItem && pickedItem.graphic) {\n result.graphic = pickedItem.graphic;\n result.params = pickedItem.params;\n }\n }\n return !!result.graphic || !!result.group;\n },\n true,\n !!context.camera\n );\n }\n if (context.modelMatrix !== lastMatrix) {\n mat4Allocate.free(context.modelMatrix);\n }\n context.modelMatrix = lastMatrix;\n\n if (!result.graphic && !result.group && groupPicked && !group.stage.camera) {\n result.group = group;\n }\n matrixAllocate.free(currentGroupMatrix);\n return result;\n }\n\n // todo: switch统一改为数字map\n abstract pickItem(\n graphic: IGraphic,\n point: IPointLike,\n parentMatrix: IMatrix | null,\n params: IPickParams\n ): PickResult | null;\n\n protected selectPicker(graphic: IGraphic): IGraphicPicker | null {\n const picker = this.pickerMap.get(graphic.numberType);\n if (!picker) {\n return null;\n }\n return picker;\n }\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { IRichText, IRichTextCharacter } from '../../interface';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function textConfigIgnoreLinebreakIdxToCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number;
|
|
2
|
+
export declare function findCursorIndexIgnoreLinebreak(textConfig: IRichTextCharacter[], cursorIndex: number): number;
|
|
4
3
|
export declare class EditModule {
|
|
5
4
|
container: HTMLElement;
|
|
6
5
|
textAreaDom: HTMLTextAreaElement;
|
|
@@ -8,11 +7,11 @@ export declare class EditModule {
|
|
|
8
7
|
isComposing: boolean;
|
|
9
8
|
cursorIndex: number;
|
|
10
9
|
selectionStartCursorIdx: number;
|
|
11
|
-
onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;
|
|
12
|
-
onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;
|
|
10
|
+
onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void>;
|
|
11
|
+
onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void>;
|
|
13
12
|
constructor(container?: HTMLElement);
|
|
14
|
-
onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void): void;
|
|
15
|
-
onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void): void;
|
|
13
|
+
onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void): void;
|
|
14
|
+
onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void): void;
|
|
16
15
|
applyStyle(textAreaDom: HTMLTextAreaElement): void;
|
|
17
16
|
handleKeyDown: (e: KeyboardEvent) => void;
|
|
18
17
|
handleCompositionStart: () => void;
|
|
@@ -1,42 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
|
|
4
|
-
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
|
|
5
|
-
var i = 0;
|
|
6
|
-
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
import { application } from "../../application";
|
|
12
|
-
|
|
13
|
-
function getMaxConfigIndexIgnoreLinebreak(textConfig) {
|
|
14
|
-
let idx = 0;
|
|
15
|
-
for (let i = 0; i < textConfig.length; i++) {
|
|
16
|
-
"\n" !== textConfig[i].text && idx++;
|
|
17
|
-
}
|
|
18
|
-
return Math.max(idx - 1, 0);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function findConfigIndex(textConfig, cursorIndex) {
|
|
1
|
+
export function findCursorIndexIgnoreLinebreak(textConfig, cursorIndex) {
|
|
22
2
|
let index = 0;
|
|
23
|
-
if (cursorIndex < 0) return -1;
|
|
24
|
-
let idx = Math.round(cursorIndex);
|
|
25
3
|
for (index = 0; index < textConfig.length; index++) {
|
|
26
|
-
|
|
4
|
+
const c = textConfig[index];
|
|
5
|
+
if (c.text && "\n" === c.text || cursorIndex--, cursorIndex < 0) break;
|
|
27
6
|
}
|
|
28
|
-
return
|
|
29
|
-
Math.min(index, textConfig.length - 1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function textConfigIgnoreLinebreakIdxToCursorIdx(textConfig, cursorIndex) {
|
|
33
|
-
var _a;
|
|
34
|
-
let index = 0;
|
|
35
|
-
for (let i = 0; i < cursorIndex; i++) {
|
|
36
|
-
"\n" !== textConfig[i].text && index++;
|
|
37
|
-
}
|
|
38
|
-
return "\n" === (null === (_a = textConfig[cursorIndex]) || void 0 === _a ? void 0 : _a.text) ? index -= .1 : index += .1,
|
|
39
|
-
index;
|
|
7
|
+
return index;
|
|
40
8
|
}
|
|
41
9
|
|
|
42
10
|
export class EditModule {
|
|
@@ -47,67 +15,45 @@ export class EditModule {
|
|
|
47
15
|
type: "Backspace"
|
|
48
16
|
});
|
|
49
17
|
}, this.handleCompositionStart = () => {
|
|
50
|
-
const {textConfig: textConfig = []} = this.currRt.attribute;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
fill: "black"
|
|
55
|
-
}, config), {
|
|
56
|
-
text: ""
|
|
57
|
-
}));
|
|
58
|
-
} else {
|
|
59
|
-
const cursorIndex = findConfigIndex(textConfig, this.cursorIndex), lastConfig = textConfig[cursorIndex];
|
|
60
|
-
textConfig.splice(cursorIndex + 1, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
61
|
-
text: ""
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
this.isComposing = !0;
|
|
18
|
+
const {textConfig: textConfig = []} = this.currRt.attribute, cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex), lastConfig = textConfig[cursorIndex];
|
|
19
|
+
textConfig.splice(cursorIndex + 1, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
20
|
+
text: ""
|
|
21
|
+
})), this.isComposing = !0;
|
|
65
22
|
}, this.handleCompositionEnd = () => {
|
|
66
23
|
this.isComposing = !1;
|
|
67
|
-
const {textConfig: textConfig = []} = this.currRt.attribute,
|
|
68
|
-
textConfig.splice(
|
|
69
|
-
const text = lastConfig.text, textList =
|
|
70
|
-
for (let i = 0; i < textList.length; i++) textConfig.splice(i +
|
|
24
|
+
const {textConfig: textConfig = []} = this.currRt.attribute, curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1), lastConfig = textConfig[curIdx];
|
|
25
|
+
textConfig.splice(curIdx, 1);
|
|
26
|
+
const text = lastConfig.text, textList = Array.from(text.toString());
|
|
27
|
+
for (let i = 0; i < textList.length; i++) textConfig.splice(i + curIdx, 0, Object.assign(Object.assign({}, lastConfig), {
|
|
71
28
|
text: textList[i]
|
|
72
29
|
}));
|
|
73
30
|
this.currRt.setAttributes({
|
|
74
31
|
textConfig: textConfig
|
|
75
32
|
}), this.onChangeCbList.forEach((cb => {
|
|
76
|
-
cb(text, this.isComposing,
|
|
33
|
+
cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, "right");
|
|
77
34
|
}));
|
|
78
35
|
}, this.handleInput = ev => {
|
|
79
|
-
var _a, _b, _c, _d;
|
|
80
36
|
if (!this.currRt) return;
|
|
81
|
-
const _e = this.currRt.attribute, {textConfig: textConfig = []} = _e, rest = __rest(_e, [ "textConfig" ]);
|
|
82
|
-
if ("Backspace" === ev.type && !textConfig.length) return;
|
|
83
37
|
let str = ev.data;
|
|
84
|
-
|
|
38
|
+
"Backspace" === ev.type || str || (str = "\n");
|
|
39
|
+
const {textConfig: textConfig = []} = this.currRt.attribute;
|
|
85
40
|
let startIdx = this.selectionStartCursorIdx, endIdx = this.cursorIndex;
|
|
86
41
|
startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), this.selectionStartCursorIdx = startIdx,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
let lastConfig = textConfig[lastConfigIdx];
|
|
92
|
-
lastConfig || (lastConfig = 0 === textConfig.length ? {
|
|
93
|
-
fill: null !== (_a = rest.fill) && void 0 !== _a ? _a : "black",
|
|
94
|
-
stroke: null !== (_b = rest.stroke) && void 0 !== _b && _b,
|
|
95
|
-
fontSize: null !== (_c = rest.fontSize) && void 0 !== _c ? _c : 12,
|
|
96
|
-
fontWeight: null !== (_d = rest.fontWeight) && void 0 !== _d ? _d : "normal"
|
|
97
|
-
} : textConfig[lastConfigIdx - 1] || textConfig[lastConfigIdx + 1]);
|
|
42
|
+
this.cursorIndex = startIdx, startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);
|
|
43
|
+
const delta = this.selectionStartCursorIdx - startIdx;
|
|
44
|
+
endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);
|
|
45
|
+
const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];
|
|
98
46
|
let currConfig = lastConfig;
|
|
99
47
|
"Backspace" !== ev.type || this.isComposing ? (startIdx !== endIdx && textConfig.splice(startIdx + 1, endIdx - startIdx),
|
|
100
48
|
this.isComposing || (currConfig = Object.assign(Object.assign({}, lastConfig), {
|
|
101
49
|
text: ""
|
|
102
|
-
}), startIdx += 1, textConfig.splice(startIdx, 0, currConfig)), currConfig.text = str,
|
|
103
|
-
textConfig.length || textConfig.push(currConfig)) : startIdx !== endIdx ? textConfig.splice(startIdx + 1, endIdx - startIdx) : (textConfig.splice(startIdx, 1),
|
|
50
|
+
}), startIdx += 1, textConfig.splice(startIdx, 0, currConfig)), currConfig.text = str) : startIdx !== endIdx ? textConfig.splice(startIdx + 1, endIdx - startIdx) : (textConfig.splice(startIdx, 1),
|
|
104
51
|
startIdx -= 1), this.currRt.setAttributes({
|
|
105
52
|
textConfig: textConfig
|
|
106
|
-
}), this.
|
|
107
|
-
|
|
108
|
-
cb(str, this.isComposing, this.cursorIndex, this.currRt);
|
|
53
|
+
}), this.isComposing ? this.onInputCbList.forEach((cb => {
|
|
54
|
+
cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
|
|
109
55
|
})) : this.onChangeCbList.forEach((cb => {
|
|
110
|
-
cb(str, this.isComposing,
|
|
56
|
+
cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
|
|
111
57
|
}));
|
|
112
58
|
}, this.container = null != container ? container : document.body;
|
|
113
59
|
const textAreaDom = document.createElement("textarea");
|
|
@@ -124,7 +70,7 @@ export class EditModule {
|
|
|
124
70
|
applyStyle(textAreaDom) {
|
|
125
71
|
textAreaDom.setAttribute("style", "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;"),
|
|
126
72
|
textAreaDom.addEventListener("input", this.handleInput), textAreaDom.addEventListener("compositionstart", this.handleCompositionStart),
|
|
127
|
-
textAreaDom.addEventListener("compositionend", this.handleCompositionEnd),
|
|
73
|
+
textAreaDom.addEventListener("compositionend", this.handleCompositionEnd), window.addEventListener("keydown", this.handleKeyDown);
|
|
128
74
|
}
|
|
129
75
|
moveTo(x, y, rt, cursorIndex, selectionStartCursorIdx) {
|
|
130
76
|
this.textAreaDom.style.left = `${x}px`, this.textAreaDom.style.top = `${y}px`, setTimeout((() => {
|
|
@@ -134,7 +80,7 @@ export class EditModule {
|
|
|
134
80
|
release() {
|
|
135
81
|
this.textAreaDom.removeEventListener("input", this.handleInput), this.textAreaDom.removeEventListener("compositionstart", this.handleCompositionStart),
|
|
136
82
|
this.textAreaDom.removeEventListener("compositionend", this.handleCompositionEnd),
|
|
137
|
-
|
|
83
|
+
window.removeEventListener("keydown", this.handleKeyDown);
|
|
138
84
|
}
|
|
139
85
|
}
|
|
140
86
|
//# sourceMappingURL=edit-module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,SAAS,gCAAgC,CAAC,UAAgC;IACxE,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAgC,CAAC;QACvD,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,GAAG,EAAE,CAAC;SACP;KACF;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC;AAQD,MAAM,UAAU,eAAe,CAAC,UAAgC,EAAE,WAAmB;IACnF,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,IAAI,WAAW,GAAG,CAAC,EAAE;QACnB,OAAO,CAAC,CAAC,CAAC;KACX;IACD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAClC,KAAK,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAgC,CAAC;QAC3D,IAAI,CAAC,CAAC,IAAI,KAAK,I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AAS,EAAE,EAAa,EAAE,WAAmB,EAAE,uBAA+B;QAC9F,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,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,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type { IRichText, IRichTextCharacter, IRichTextParagraphCharacter } from '../../interface';\nimport { IRichTextIcon, IRichTextParagraph } from '../../interface';\n\nfunction 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\n/**\n * 找到cursorIndex所在的textConfig的位置,忽略换行符\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndex(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n // 小于0是在最前面了\n if (cursorIndex < 0) {\n return -1;\n }\n let idx = Math.round(cursorIndex);\n for (index = 0; index < textConfig.length; index++) {\n const c = textConfig[index] as IRichTextParagraphCharacter;\n if (c.text !== '\\n') {\n idx--;\n }\n if (idx < 0) {\n break;\n }\n }\n if (cursorIndex - Math.round(cursorIndex) < 0) {\n index--;\n }\n index = Math.max(index, 0);\n // 避免超过限度,最后一个字符可能是换行符,算一个字符\n return Math.min(index, textConfig.length - 1);\n}\n\nexport function textConfigIgnoreLinebreakIdxToCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n for (let i = 0; i < cursorIndex; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text !== '\\n') {\n index++;\n }\n }\n // 正常Cursor是放在右边的,但如果回退到换行符了,那就放在左侧\n if ((textConfig[cursorIndex] as any)?.text === '\\n') {\n index -= 0.1;\n } else {\n index += 0.1;\n }\n return index;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\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\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.onInputCbList = [];\n this.onChangeCbList = [];\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 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 application.global.addEventListener('keydown', this.handleKeyDown);\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 const { textConfig = [] } = this.currRt.attribute;\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ fill: 'black', ...config, text: '' });\n } else {\n const cursorIndex = findConfigIndex(textConfig, this.cursorIndex);\n const lastConfig = textConfig[cursorIndex];\n textConfig.splice(cursorIndex + 1, 0, { ...lastConfig, text: '' });\n }\n\n this.isComposing = true;\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n // 拆分上一次的内容\n const { textConfig = [] } = this.currRt.attribute;\n const configIdx = findConfigIndex(textConfig, this.cursorIndex + 1);\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, text: textList[i] });\n }\n this.currRt.setAttributes({ textConfig });\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n Math.min(this.cursorIndex + textList.length, getMaxConfigIndexIgnoreLinebreak(textConfig) + 0.1),\n this.currRt\n );\n });\n };\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n\n // 如果是回车,那就不往后+1\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 let startIdx = this.selectionStartCursorIdx;\n let endIdx = this.cursorIndex;\n if (startIdx > endIdx) {\n [startIdx, endIdx] = [endIdx, startIdx];\n }\n // 无论是否composition都立刻恢复到没有选中的idx状态\n this.selectionStartCursorIdx = startIdx;\n\n // 转换成基于textConfig的\n // let delta = 0;\n startIdx = findConfigIndex(textConfig, startIdx);\n // delta = this.selectionStartCursorIdx - startIdx;\n endIdx = findConfigIndex(textConfig, endIdx);\n // console.log(startIdx, delta, endIdx);\n\n let idxDelta = 0;\n // 如果是换行,得往回一格\n if (str === '\\n') {\n idxDelta = -0.2;\n }\n\n const lastConfigIdx = startIdx + (this.isComposing ? 1 : 0);\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n if (textConfig.length === 0) {\n lastConfig = {\n fill: rest.fill ?? 'black',\n stroke: rest.stroke ?? false,\n fontSize: rest.fontSize ?? 12,\n fontWeight: rest.fontWeight ?? 'normal'\n };\n } else {\n lastConfig = textConfig[lastConfigIdx - 1] || textConfig[lastConfigIdx + 1];\n }\n }\n let currConfig = lastConfig;\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n } else {\n textConfig.splice(startIdx, 1);\n startIdx -= 1;\n }\n } else {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n }\n\n if (!this.isComposing) {\n currConfig = { ...lastConfig, text: '' };\n startIdx += 1;\n textConfig.splice(startIdx, 0, currConfig);\n }\n (currConfig as any).text = str;\n if (!textConfig.length) {\n textConfig.push(currConfig);\n }\n }\n\n this.currRt.setAttributes({ textConfig });\n this.cursorIndex = textConfigIgnoreLinebreakIdxToCursorIdx(textConfig, startIdx);\n\n this.cursorIndex += idxDelta;\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, this.cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, this.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 application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,8BAA8B,CAAC,UAAgC,EAAE,WAAmB;IAClG,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAgC,CAAC;QAC3D,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,EAAE;YAChC,WAAW,EAAE,CAAC;SACf;QACD,IAAI,WAAW,GAAG,CAAC,EAAE;YACnB,MAAM;SACP;KACF;IACD,OAAO,KAAK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WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5D,CAAC;CACF","file":"edit-module.js","sourcesContent":["import type { IRichText, IRichTextCharacter, IRichTextParagraphCharacter } from '../../interface';\nimport { IRichTextIcon, IRichTextParagraph } from '../../interface';\n\nexport function findCursorIndexIgnoreLinebreak(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n for (index = 0; index < textConfig.length; index++) {\n const c = textConfig[index] as IRichTextParagraphCharacter;\n if (!(c.text && c.text === '\\n')) {\n cursorIndex--;\n }\n if (cursorIndex < 0) {\n break;\n }\n }\n return index;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<\n (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void\n >;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<\n (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void\n >;\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.onInputCbList = [];\n this.onChangeCbList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void) {\n this.onChangeCbList.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 window.addEventListener('keydown', this.handleKeyDown);\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 const { textConfig = [] } = this.currRt.attribute;\n const cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex);\n const lastConfig = textConfig[cursorIndex];\n textConfig.splice(cursorIndex + 1, 0, { ...lastConfig, text: '' });\n this.isComposing = true;\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n // 拆分上一次的内容\n const { textConfig = [] } = this.currRt.attribute;\n const curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1);\n\n const lastConfig = textConfig[curIdx];\n textConfig.splice(curIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = Array.from(text.toString());\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + curIdx, 0, { ...lastConfig, text: textList[i] });\n }\n this.currRt.setAttributes({ textConfig });\n this.onChangeCbList.forEach(cb => {\n cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, 'right');\n });\n };\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n let str = (ev as any).data;\n if (ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n // 如果是回车,那就不往后+1\n const { textConfig = [] } = this.currRt.attribute;\n\n // 如果有选中多个文字,那就先删除\n let startIdx = this.selectionStartCursorIdx;\n let endIdx = this.cursorIndex;\n if (startIdx > endIdx) {\n [startIdx, endIdx] = [endIdx, startIdx];\n }\n // 无论是否composition都立刻恢复到没有选中的idx状态\n this.selectionStartCursorIdx = startIdx;\n this.cursorIndex = startIdx;\n\n // 转换成基于textConfig的\n startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);\n const delta = this.selectionStartCursorIdx - startIdx;\n endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);\n\n const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];\n let currConfig = lastConfig;\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n } else {\n textConfig.splice(startIdx, 1);\n startIdx -= 1;\n }\n } else {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n }\n\n if (!this.isComposing) {\n currConfig = { ...lastConfig, text: '' };\n startIdx += 1;\n textConfig.splice(startIdx, 0, currConfig);\n }\n (currConfig as any).text = str;\n }\n\n this.currRt.setAttributes({ textConfig });\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, startIdx + delta, this.currRt, str === '\\n' ? 'left' : 'right');\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, startIdx + delta, this.currRt, str === '\\n' ? 'left' : 'right');\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 window.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
|