@ibiz-template/vue3-util 0.7.41-alpha.19 → 0.7.41-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/index.min.css +1 -1
  2. package/dist/index.system.min.js +1 -1
  3. package/es/common/index.d.ts +1 -0
  4. package/es/common/index.d.ts.map +1 -1
  5. package/es/common/index.mjs +1 -0
  6. package/es/common/signature-pad/signature-pad.css +1 -0
  7. package/es/common/signature-pad/signature-pad.d.ts +19 -0
  8. package/es/common/signature-pad/signature-pad.d.ts.map +1 -0
  9. package/es/common/signature-pad/signature-pad.mjs +165 -0
  10. package/es/common/signature-pad/util/bezier.d.ts +58 -0
  11. package/es/common/signature-pad/util/bezier.d.ts.map +1 -0
  12. package/es/common/signature-pad/util/bezier.mjs +109 -0
  13. package/es/common/signature-pad/util/point.d.ts +55 -0
  14. package/es/common/signature-pad/util/point.d.ts.map +1 -0
  15. package/es/common/signature-pad/util/point.mjs +51 -0
  16. package/es/common/signature-pad/util/signature_pad.d.ts +593 -0
  17. package/es/common/signature-pad/util/signature_pad.d.ts.map +1 -0
  18. package/es/common/signature-pad/util/signature_pad.mjs +1018 -0
  19. package/es/index.mjs +1 -0
  20. package/es/locale/en/index.d.ts +1 -0
  21. package/es/locale/en/index.d.ts.map +1 -1
  22. package/es/locale/en/index.mjs +2 -1
  23. package/es/locale/zh-CN/index.d.ts +1 -0
  24. package/es/locale/zh-CN/index.d.ts.map +1 -1
  25. package/es/locale/zh-CN/index.mjs +2 -1
  26. package/es/panel-component/nav-pos/nav-pos.controller.d.ts +1 -1
  27. package/es/panel-component/nav-pos/nav-pos.d.ts +1 -1
  28. package/es/panel-component/panel-container/panel-container.d.ts.map +1 -1
  29. package/es/panel-component/panel-container/panel-container.mjs +7 -3
  30. package/es/panel-component/panel-tab-page/panel-tab-page.d.ts +1 -1
  31. package/es/view/common/view.d.ts.map +1 -1
  32. package/es/view/common/view.mjs +14 -1
  33. package/lib/common/index.cjs +2 -0
  34. package/lib/common/signature-pad/signature-pad.cjs +167 -0
  35. package/lib/common/signature-pad/signature-pad.css +1 -0
  36. package/lib/common/signature-pad/util/bezier.cjs +111 -0
  37. package/lib/common/signature-pad/util/point.cjs +53 -0
  38. package/lib/common/signature-pad/util/signature_pad.cjs +1022 -0
  39. package/lib/index.cjs +2 -0
  40. package/lib/locale/en/index.cjs +2 -1
  41. package/lib/locale/zh-CN/index.cjs +2 -1
  42. package/lib/panel-component/panel-container/panel-container.cjs +7 -3
  43. package/lib/view/common/view.cjs +13 -0
  44. package/package.json +5 -5
package/es/index.mjs CHANGED
@@ -19,6 +19,7 @@ export { IBizCodeList } from './common/code-list/code-list.mjs';
19
19
  export { ControlLoadingPlaceholder } from './common/control-loading-placeholder/control-loading-placeholder.mjs';
20
20
  export { IBizBadge } from './common/badge/badge.mjs';
21
21
  export { IBizCustomRender } from './common/custom-render/custom-render.mjs';
22
+ export { IBizSignaturePad } from './common/signature-pad/signature-pad.mjs';
22
23
  export { PanelContainerState } from './panel-component/panel-container/panel-container.state.mjs';
23
24
  export { PanelContainerController } from './panel-component/panel-container/panel-container.controller.mjs';
24
25
  export { IBizPanelContainer } from './panel-component/panel-container/index.mjs';
@@ -5,6 +5,7 @@ export declare const en: {
5
5
  onFoundCorrespondingPart: string;
6
6
  noFoundViewModel: string;
7
7
  noSupportLoadingDynamic: string;
8
+ invalidPointCoordinates: string;
8
9
  };
9
10
  control: {
10
11
  unsupportedPanel: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/en/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwEd,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/en/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyEd,CAAC"}
@@ -5,7 +5,8 @@ const en = {
5
5
  undefined: "undefined",
6
6
  onFoundCorrespondingPart: "Undefined adapter with no corresponding part found",
7
7
  noFoundViewModel: "View model not found",
8
- noSupportLoadingDynamic: "{codeName}No entity, do not support loading dynamic models at this time"
8
+ noSupportLoadingDynamic: "{codeName}No entity, do not support loading dynamic models at this time",
9
+ invalidPointCoordinates: "Invalid point coordinates: ({x}, {y})"
9
10
  },
10
11
  control: {
11
12
  unsupportedPanel: "Unsupported panel items: {id} - {itemType}"
@@ -5,6 +5,7 @@ export declare const zhCn: {
5
5
  onFoundCorrespondingPart: string;
6
6
  noFoundViewModel: string;
7
7
  noSupportLoadingDynamic: string;
8
+ invalidPointCoordinates: string;
8
9
  };
9
10
  control: {
10
11
  unsupportedPanel: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/zh-CN/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgEhB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/locale/zh-CN/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiEhB,CAAC"}
@@ -5,7 +5,8 @@ const zhCn = {
5
5
  undefined: "\u672A\u5B9A\u4E49",
6
6
  onFoundCorrespondingPart: "\u672A\u5B9A\u4E49\u672A\u627E\u5230\u5BF9\u5E94\u90E8\u4EF6\u7684\u9002\u914D\u5668",
7
7
  noFoundViewModel: "\u672A\u627E\u5230\u89C6\u56FE\u6A21\u578B",
8
- noSupportLoadingDynamic: "{codeName}\u65E0\u5B9E\u4F53,\u6682\u4E0D\u652F\u6301\u52A0\u8F7D\u52A8\u6001\u6A21\u578B"
8
+ noSupportLoadingDynamic: "{codeName}\u65E0\u5B9E\u4F53,\u6682\u4E0D\u652F\u6301\u52A0\u8F7D\u52A8\u6001\u6A21\u578B",
9
+ invalidPointCoordinates: "\u70B9\u5750\u6807\u65E0\u6548: ({x}, {y})"
9
10
  },
10
11
  control: {
11
12
  unsupportedPanel: "\u6682\u672A\u652F\u6301\u7684\u9762\u677F\u9879: {id} - {itemType}"
@@ -11,7 +11,7 @@ import { NavPosState } from './nav-pos.state';
11
11
  */
12
12
  export declare class NavPosController extends PanelItemController<IPanelRawItem> implements IPanelItemNavPosController {
13
13
  /**
14
- * 导航占位状态
14
+ * @description 导航占位状态
15
15
  * @exposedoc
16
16
  * @type {NavPosState}
17
17
  * @memberof NavPosController
@@ -7,7 +7,7 @@ import './nav-pos.scss';
7
7
  * 导航占位
8
8
  * @primary
9
9
  * @description 面板中的导航视图占位组件,用于绘制导航视图,并存储导航视图信息与缓存。
10
- * @panelitemparams {name:expcache,parameterType:string,defaultvalue:-,description:当值为NO_CACHE时禁用缓存,即每次导航切换时都是重新绘制新的视图,否则使用keepAlive包裹绘制的导航视图}
10
+ * @panelitemparams {name:expcache,parameterType:'CACHE' | 'NO_CACHE',defaultvalue:-,description:当值为NO_CACHE时禁用缓存,即每次导航切换时都是重新绘制新的视图,否则使用keepAlive包裹绘制的导航视图}
11
11
  * @panelitemparams {name:ignoreembedkey,parameterType:boolean,defaultvalue:-,description:忽略嵌入视图key参数}
12
12
  * @panelitemparams {name:expmode,parameterType:'ROUTE' | 'NO_ROUTE',defaultvalue:-,description:导航模式,ROUTE为路由模式,NO_ROUTE为非路由模式,在路由模式下会通过路由打开视图,在非路由的模式下,则会通过视图模型去绘制视图}
13
13
  * @panelitemparams {"name":"routeattributekeys","parameterType":"string","defaultvalue":"-","description":"路由透传参数,参数值为上下文对象的key,多个值用竖线`|`分隔,透传的参数将会在路由组件进行解析,并显示声明在路由上进行传递"}
@@ -1 +1 @@
1
- {"version":3,"file":"panel-container.d.ts","sourceRoot":"","sources":["../../../src/panel-component/panel-container/panel-container.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAA6B,QAAQ,EAAS,MAAM,KAAK,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,cAAc;IAGvB;;OAEG;;;;;IAEH;;OAEG;;;;;;;;;IANH;;OAEG;;;;;IAEH;;OAEG;;;;;YAoGL,CAAC"}
1
+ {"version":3,"file":"panel-container.d.ts","sourceRoot":"","sources":["../../../src/panel-component/panel-container/panel-container.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAA6B,QAAQ,EAAS,MAAM,KAAK,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,wBAAwB,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,cAAc;IAGvB;;OAEG;;;;;IAEH;;OAEG;;;;;;;;;IANH;;OAEG;;;;;IAEH;;OAEG;;;;;YAuGL,CAAC"}
@@ -64,10 +64,14 @@ const PanelContainer = /* @__PURE__ */ defineComponent({
64
64
  });
65
65
  const attrs = (_c = this.$attrs) == null ? void 0 : _c.attrs;
66
66
  if (attrs && attrs.dynamictooltip) {
67
- return createVNode(resolveComponent("el-tooltip"), {
67
+ const attributes = {
68
+ ...attrs.dynamictooltip
69
+ };
70
+ delete attributes.content;
71
+ return createVNode(resolveComponent("el-tooltip"), mergeProps({
68
72
  "placement": "right",
69
73
  "popper-class": this.ns.e("dynamic-tooltip")
70
- }, {
74
+ }, attributes), {
71
75
  default: () => {
72
76
  return createVNode("div", mergeProps({
73
77
  "class": this.classArr,
@@ -81,7 +85,7 @@ const PanelContainer = /* @__PURE__ */ defineComponent({
81
85
  content: () => {
82
86
  return createVNode("div", {
83
87
  "class": this.ns.e("dynamic-tooltip-content"),
84
- "innerHTML": attrs.dynamictooltip
88
+ "innerHTML": attrs.dynamictooltip.content
85
89
  }, null);
86
90
  }
87
91
  });
@@ -4,7 +4,7 @@ import { PanelItemController } from '@ibiz-template/runtime';
4
4
  /**
5
5
  * 面板分页
6
6
  * @primary
7
- * @description 为分页容器下的分页子容器,此容器下才是面板成员
7
+ * @description 为分页面板下的分页子容器,此容器下才是面板成员。
8
8
  */
9
9
  export declare const PanelTabPage: import("vue").DefineComponent<{
10
10
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/view/common/view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,0BAA0B,EAC1B,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAGL,QAAQ,EAER,KAAK,EAIN,MAAM,KAAK,CAAC;AACb,OAAO,aAAa,CAAC;AAGrB,eAAO,MAAM,IAAI;IAGb;;OAEG;;;;IAEH;;;OAGG;;;;;IAEH;;OAEG;;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;;;;;;;uCAkDW,0BAA0B,KACrC,IAAI;yBAmBqB,QAAQ,cAAa,KAAK,KAAQ,OAAO;0BAkBxC,QAAQ,cAAa,KAAK,KAAQ,KAAK;+BA/DlC,QAAQ,KAAG,MAAM,GAAG,SAAS;;;IAhD/D;;OAEG;;;;IAEH;;;OAGG;;;;;IAEH;;OAEG;;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;;;MAgNL,CAAC"}
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/view/common/view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,0BAA0B,EAC1B,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAGL,QAAQ,EAER,KAAK,EAON,MAAM,KAAK,CAAC;AACb,OAAO,aAAa,CAAC;AAGrB,eAAO,MAAM,IAAI;IAGb;;OAEG;;;;IAEH;;;OAGG;;;;;IAEH;;OAEG;;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;;;;;;;uCAkDW,0BAA0B,KACrC,IAAI;yBAmBqB,QAAQ,cAAa,KAAK,KAAQ,OAAO;0BAkBxC,QAAQ,cAAa,KAAK,KAAQ,KAAK;+BA/DlC,QAAQ,KAAG,MAAM,GAAG,SAAS;;;IAhD/D;;OAEG;;;;IAEH;;;OAGG;;;;;IAEH;;OAEG;;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;IAEH;;OAEG;;;;;;MAuOL,CAAC"}
@@ -1,4 +1,4 @@
1
- import { isVNode, defineComponent, computed, renderSlot, resolveComponent, h, createVNode, Teleport, withDirectives, resolveDirective } from 'vue';
1
+ import { isVNode, defineComponent, computed, renderSlot, resolveComponent, h, onMounted, nextTick, onBeforeUnmount, createVNode, Teleport, withDirectives, resolveDirective } from 'vue';
2
2
  import { ViewController, getControlsByView, getCtrlTeleportParams, getErrorViewProvider } from '@ibiz-template/runtime';
3
3
  import './view.css';
4
4
  import '../../use/index.mjs';
@@ -127,6 +127,19 @@ const View = /* @__PURE__ */ defineComponent({
127
127
  }
128
128
  return h(comp, ctrlProps);
129
129
  };
130
+ let watermarkDestroy;
131
+ onMounted(() => {
132
+ nextTick(async () => {
133
+ const container = document.getElementById(c.id);
134
+ const appView = await ibiz.hub.config.view.get(c.model.id);
135
+ if (!container || !(appView == null ? void 0 : appView.waterMarkOption))
136
+ return;
137
+ watermarkDestroy = ibiz.util.watermark.mount(appView.waterMarkOption, container, c.context, c.params, c.state.srfactiveviewdata || {});
138
+ });
139
+ });
140
+ onBeforeUnmount(() => {
141
+ watermarkDestroy == null ? void 0 : watermarkDestroy();
142
+ });
130
143
  return {
131
144
  c,
132
145
  ns,
@@ -9,6 +9,7 @@ var codeList = require('./code-list/code-list.cjs');
9
9
  var controlLoadingPlaceholder = require('./control-loading-placeholder/control-loading-placeholder.cjs');
10
10
  var badge = require('./badge/badge.cjs');
11
11
  var customRender = require('./custom-render/custom-render.cjs');
12
+ var signaturePad = require('./signature-pad/signature-pad.cjs');
12
13
 
13
14
  "use strict";
14
15
 
@@ -21,3 +22,4 @@ exports.IBizCodeList = codeList.IBizCodeList;
21
22
  exports.ControlLoadingPlaceholder = controlLoadingPlaceholder.ControlLoadingPlaceholder;
22
23
  exports.IBizBadge = badge.IBizBadge;
23
24
  exports.IBizCustomRender = customRender.IBizCustomRender;
25
+ exports.IBizSignaturePad = signaturePad.IBizSignaturePad;
@@ -0,0 +1,167 @@
1
+ 'use strict';
2
+
3
+ var vue = require('vue');
4
+ var lodashEs = require('lodash-es');
5
+ require('../../use/index.cjs');
6
+ var signature_pad = require('./util/signature_pad.cjs');
7
+ require('./signature-pad.css');
8
+ var namespace = require('../../use/namespace/namespace.cjs');
9
+
10
+ "use strict";
11
+ const IBizSignaturePad = /* @__PURE__ */ vue.defineComponent({
12
+ name: "IBizSignaturePad",
13
+ props: {
14
+ options: {
15
+ type: Object
16
+ }
17
+ },
18
+ setup(props) {
19
+ const ns = namespace.useNamespace("signature-pad");
20
+ const signaturePadRef = vue.ref();
21
+ const canvasRef = vue.ref();
22
+ const signaturePad = vue.ref();
23
+ const getSignatureOptions = () => {
24
+ const _options = {};
25
+ if (props.options) {
26
+ const {
27
+ dotsize,
28
+ minwidth,
29
+ maxwidth,
30
+ pencolor,
31
+ velocityfilterweight,
32
+ compositeoperation,
33
+ mindistance,
34
+ backgroundcolor,
35
+ throttle,
36
+ canvascontextoptions
37
+ } = props.options;
38
+ if (dotsize) {
39
+ Object.assign(_options, {
40
+ dotSize: Number(dotsize)
41
+ });
42
+ }
43
+ if (minwidth) {
44
+ Object.assign(_options, {
45
+ minWidth: Number(minwidth)
46
+ });
47
+ }
48
+ if (maxwidth) {
49
+ Object.assign(_options, {
50
+ maxWidth: Number(maxwidth)
51
+ });
52
+ }
53
+ if (velocityfilterweight) {
54
+ Object.assign(_options, {
55
+ velocityFilterWeight: Number(velocityfilterweight)
56
+ });
57
+ }
58
+ if (mindistance) {
59
+ Object.assign(_options, {
60
+ minDistance: Number(mindistance)
61
+ });
62
+ }
63
+ if (throttle) {
64
+ Object.assign(_options, {
65
+ throttle: Number(throttle)
66
+ });
67
+ }
68
+ if (pencolor) {
69
+ Object.assign(_options, {
70
+ penColor: String(pencolor)
71
+ });
72
+ }
73
+ if (compositeoperation) {
74
+ Object.assign(_options, {
75
+ compositeOperation: String(compositeoperation)
76
+ });
77
+ }
78
+ if (backgroundcolor) {
79
+ Object.assign(_options, {
80
+ backgroundColor: String(backgroundcolor)
81
+ });
82
+ }
83
+ if (canvascontextoptions) {
84
+ let canvasContextOptions = canvascontextoptions;
85
+ if (lodashEs.isString(canvascontextoptions)) {
86
+ try {
87
+ canvasContextOptions = JSON.parse(canvascontextoptions);
88
+ } catch (error) {
89
+ ibiz.log.error(error);
90
+ canvasContextOptions = void 0;
91
+ }
92
+ }
93
+ Object.assign(_options, {
94
+ canvasContextOptions: {
95
+ ...canvasContextOptions
96
+ }
97
+ });
98
+ }
99
+ }
100
+ return _options;
101
+ };
102
+ const preventScroll = (_e) => {
103
+ _e.preventDefault();
104
+ };
105
+ const initSignaturePad = (_callback) => {
106
+ vue.nextTick(() => {
107
+ const canvas = canvasRef.value;
108
+ const signatures = signaturePadRef.value;
109
+ if (!canvas)
110
+ return;
111
+ const dpr = window.devicePixelRatio || 1;
112
+ const rect = signatures.getBoundingClientRect();
113
+ const canvasWidth = rect.width < 300 ? 300 : rect.width;
114
+ const canvasHeight = rect.height < 150 ? 150 : rect.height;
115
+ canvas.width = canvasWidth * dpr;
116
+ canvas.height = canvasHeight * dpr;
117
+ canvas.style.width = "".concat(canvasWidth, "px");
118
+ canvas.style.height = "".concat(canvasHeight, "px");
119
+ signaturePad.value = new signature_pad.default(canvas, {
120
+ ...getSignatureOptions()
121
+ });
122
+ const ctx = canvas.getContext("2d");
123
+ ctx.scale(dpr, dpr);
124
+ canvas.addEventListener("touchstart", preventScroll, {
125
+ passive: false
126
+ });
127
+ canvas.addEventListener("touchmove", preventScroll, {
128
+ passive: false
129
+ });
130
+ _callback == null ? void 0 : _callback();
131
+ });
132
+ };
133
+ const updateSignaturePad = (_callback) => initSignaturePad(_callback);
134
+ const handleResize = () => {
135
+ if (signaturePad.value) {
136
+ signaturePad.value.off();
137
+ updateSignaturePad();
138
+ }
139
+ };
140
+ vue.onMounted(() => {
141
+ initSignaturePad();
142
+ window.addEventListener("resize", handleResize);
143
+ });
144
+ vue.onUnmounted(() => {
145
+ window.removeEventListener("resize", handleResize);
146
+ });
147
+ return {
148
+ ns,
149
+ canvasRef,
150
+ signaturePadRef,
151
+ signaturePad,
152
+ updateSignaturePad
153
+ };
154
+ },
155
+ render() {
156
+ return vue.createVNode("div", {
157
+ "class": this.ns.b(),
158
+ "ref": "signaturePadRef"
159
+ }, [vue.createVNode("div", {
160
+ "class": this.ns.e("container")
161
+ }, [vue.createVNode("canvas", {
162
+ "ref": "canvasRef"
163
+ }, null)])]);
164
+ }
165
+ });
166
+
167
+ exports.IBizSignaturePad = IBizSignaturePad;
@@ -0,0 +1 @@
1
+ .ibiz-signature-pad{width:100%;height:100%}.ibiz-signature-pad__container{width:100%;height:100%;background-color:var(--ibiz-color-bg-1)}
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ var point = require('./point.cjs');
4
+
5
+ "use strict";
6
+ class Bezier {
7
+ /**
8
+ * 贝塞尔曲线构造函数
9
+ * @param startPoint 起始点
10
+ * @param control2 第二个控制点
11
+ * @param control1 第一个控制点
12
+ * @param endPoint 结束点
13
+ * @param startWidth 起始点宽度
14
+ * @param endWidth 结束点宽度
15
+ */
16
+ constructor(startPoint, control2, control1, endPoint, startWidth, endWidth) {
17
+ this.startPoint = startPoint;
18
+ this.control2 = control2;
19
+ this.control1 = control1;
20
+ this.endPoint = endPoint;
21
+ this.startWidth = startWidth;
22
+ this.endWidth = endWidth;
23
+ }
24
+ /**
25
+ * 从点数组创建贝塞尔曲线
26
+ * @param points 点数组,至少需要4个点来计算曲线
27
+ * @param widths 包含起点和终点宽度的对象
28
+ * @returns 新创建的贝塞尔曲线实例
29
+ */
30
+ static fromPoints(points, widths) {
31
+ const c2 = this.calculateControlPoints(points[0], points[1], points[2]).c2;
32
+ const c3 = this.calculateControlPoints(points[1], points[2], points[3]).c1;
33
+ return new Bezier(points[1], c2, c3, points[2], widths.start, widths.end);
34
+ }
35
+ /**
36
+ * 计算贝塞尔曲线的控制点
37
+ * @param s1 第一个点
38
+ * @param s2 第二个点(中间点)
39
+ * @param s3 第三个点
40
+ * @returns 包含两个控制点的对象
41
+ */
42
+ static calculateControlPoints(s1, s2, s3) {
43
+ const dx1 = s1.x - s2.x;
44
+ const dy1 = s1.y - s2.y;
45
+ const dx2 = s2.x - s3.x;
46
+ const dy2 = s2.y - s3.y;
47
+ const m1 = { x: (s1.x + s2.x) / 2, y: (s1.y + s2.y) / 2 };
48
+ const m2 = { x: (s2.x + s3.x) / 2, y: (s2.y + s3.y) / 2 };
49
+ const l1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
50
+ const l2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
51
+ const dxm = m1.x - m2.x;
52
+ const dym = m1.y - m2.y;
53
+ const k = l1 + l2 === 0 ? 0 : l2 / (l1 + l2);
54
+ const cm = { x: m2.x + dxm * k, y: m2.y + dym * k };
55
+ const tx = s2.x - cm.x;
56
+ const ty = s2.y - cm.y;
57
+ return {
58
+ c1: new point.Point(m1.x + tx, m1.y + ty),
59
+ c2: new point.Point(m2.x + tx, m2.y + ty)
60
+ };
61
+ }
62
+ /**
63
+ * 计算贝塞尔曲线的近似长度
64
+ * @returns 曲线的近似长度
65
+ */
66
+ length() {
67
+ const steps = 10;
68
+ let length = 0;
69
+ let px;
70
+ let py;
71
+ for (let i = 0; i <= steps; i += 1) {
72
+ const t = i / steps;
73
+ const cx = this.point(
74
+ t,
75
+ this.startPoint.x,
76
+ this.control1.x,
77
+ this.control2.x,
78
+ this.endPoint.x
79
+ );
80
+ const cy = this.point(
81
+ t,
82
+ this.startPoint.y,
83
+ this.control1.y,
84
+ this.control2.y,
85
+ this.endPoint.y
86
+ );
87
+ if (i > 0) {
88
+ const xdiff = cx - px;
89
+ const ydiff = cy - py;
90
+ length += Math.sqrt(xdiff * xdiff + ydiff * ydiff);
91
+ }
92
+ px = cx;
93
+ py = cy;
94
+ }
95
+ return length;
96
+ }
97
+ /**
98
+ * 计算三次贝塞尔曲线在参数t处的x或y坐标值
99
+ * @param t 参数t,范围0到1
100
+ * @param start 起始点的坐标值(x或y)
101
+ * @param c1 第一个控制点的坐标值(x或y)
102
+ * @param c2 第二个控制点的坐标值(x或y)
103
+ * @param end 结束点的坐标值(x或y)
104
+ * @returns 计算得到的坐标值
105
+ */
106
+ point(t, start, c1, c2, end) {
107
+ return start * (1 - t) * (1 - t) * (1 - t) + 3 * c1 * (1 - t) * (1 - t) * t + 3 * c2 * (1 - t) * t * t + end * t * t * t;
108
+ }
109
+ }
110
+
111
+ exports.Bezier = Bezier;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ "use strict";
4
+ class Point {
5
+ /**
6
+ * 构造函数,创建一个Point实例
7
+ * @param x X坐标
8
+ * @param y Y坐标
9
+ * @param pressure 压力值,可选,默认为0
10
+ * @param time 时间戳,可选,默认为当前时间
11
+ * @throws 如果x或y是NaN,抛出错误
12
+ */
13
+ constructor(x, y, pressure, time) {
14
+ if (Number.isNaN(x) || Number.isNaN(y)) {
15
+ throw new Error(
16
+ ibiz.i18n.t("vue3Util.common.invalidPointCoordinates", {
17
+ x,
18
+ y
19
+ })
20
+ );
21
+ }
22
+ this.x = +x;
23
+ this.y = +y;
24
+ this.pressure = pressure || 0;
25
+ this.time = time || Date.now();
26
+ }
27
+ /**
28
+ * 计算当前点到另一个点的直线距离
29
+ * @param start 起始点(另一个点)
30
+ * @returns 两点之间的距离
31
+ */
32
+ distanceTo(start) {
33
+ return Math.sqrt((this.x - start.x) ** 2 + (this.y - start.y) ** 2);
34
+ }
35
+ /**
36
+ * 判断当前点是否与另一个点相等
37
+ * @param other 要比较的另一个点
38
+ * @returns 如果所有属性都相等则返回true,否则返回false
39
+ */
40
+ equals(other) {
41
+ return this.x === other.x && this.y === other.y && this.pressure === other.pressure && this.time === other.time;
42
+ }
43
+ /**
44
+ * 计算从起始点到当前点的移动速度
45
+ * @param start 起始点
46
+ * @returns 速度值(距离/时间),如果时间相同则返回0
47
+ */
48
+ velocityFrom(start) {
49
+ return this.time !== start.time ? this.distanceTo(start) / (this.time - start.time) : 0;
50
+ }
51
+ }
52
+
53
+ exports.Point = Point;