vislite 1.2.0-alpha.6 → 1.2.0-beta.0

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 (64) hide show
  1. package/CHANGELOG +7 -2
  2. package/README.md +2 -1
  3. package/lib/Buffer/index.es.js +1 -1
  4. package/lib/Buffer/index.es.min.js +1 -1
  5. package/lib/Canvas/index.es.js +49 -23
  6. package/lib/Canvas/index.es.min.js +2 -2
  7. package/lib/Cardinal/index.es.js +1 -1
  8. package/lib/Cardinal/index.es.min.js +1 -1
  9. package/lib/Eoap/index.es.js +1 -1
  10. package/lib/Eoap/index.es.min.js +1 -1
  11. package/lib/Hermite/index.es.js +1 -1
  12. package/lib/Hermite/index.es.min.js +1 -1
  13. package/lib/Matrix4/index.es.js +1 -1
  14. package/lib/Matrix4/index.es.min.js +1 -1
  15. package/lib/Mercator/index.es.js +1 -1
  16. package/lib/Mercator/index.es.min.js +1 -1
  17. package/lib/RawCanvas/index.es.js +49 -23
  18. package/lib/RawCanvas/index.es.min.js +2 -2
  19. package/lib/SVG/index.es.js +23 -15
  20. package/lib/SVG/index.es.min.js +2 -2
  21. package/lib/Shader/index.es.js +1 -1
  22. package/lib/Shader/index.es.min.js +1 -1
  23. package/lib/Texture/index.es.js +1 -1
  24. package/lib/Texture/index.es.min.js +1 -1
  25. package/lib/TreeLayout/index.es.js +1 -1
  26. package/lib/TreeLayout/index.es.min.js +1 -1
  27. package/lib/animation/index.es.js +1 -1
  28. package/lib/animation/index.es.min.js +1 -1
  29. package/lib/assemble/index.es.js +1 -1
  30. package/lib/assemble/index.es.min.js +1 -1
  31. package/lib/getLoopColors/index.es.js +1 -1
  32. package/lib/getLoopColors/index.es.min.js +1 -1
  33. package/lib/getWebGLContext/index.es.js +1 -1
  34. package/lib/getWebGLContext/index.es.min.js +1 -1
  35. package/lib/index.umd.js +71 -37
  36. package/lib/index.umd.min.js +2 -2
  37. package/lib/initOption/index.es.js +1 -1
  38. package/lib/initOption/index.es.min.js +1 -1
  39. package/lib/mergeOption/index.es.js +1 -1
  40. package/lib/mergeOption/index.es.min.js +1 -1
  41. package/lib/move/index.es.js +1 -1
  42. package/lib/move/index.es.min.js +1 -1
  43. package/lib/rotate/index.es.js +1 -1
  44. package/lib/rotate/index.es.min.js +1 -1
  45. package/lib/ruler/index.es.js +1 -1
  46. package/lib/ruler/index.es.min.js +1 -1
  47. package/lib/scale/index.es.js +1 -1
  48. package/lib/scale/index.es.min.js +1 -1
  49. package/lib/throttle/index.es.js +1 -1
  50. package/lib/throttle/index.es.min.js +1 -1
  51. package/minialipay/ui-canvas/drawImage.js +36 -0
  52. package/minialipay/ui-canvas/index.acss +5 -0
  53. package/minialipay/ui-canvas/index.axml +4 -0
  54. package/minialipay/ui-canvas/index.d.ts +1 -0
  55. package/minialipay/ui-canvas/index.js +101 -0
  56. package/minialipay/ui-canvas/index.json +6 -0
  57. package/package.json +1 -1
  58. package/src/common/canvas/default.ts +62 -0
  59. package/src/common/canvas/index.ts +13 -7
  60. package/src/common/canvas/painter.ts +7 -58
  61. package/src/common/svg/default.ts +27 -0
  62. package/src/common/svg/index.ts +8 -26
  63. package/types/Canvas.d.ts +5 -0
  64. package/types/SVG.d.ts +5 -0
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * move of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * move of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function t(t,r,a,e,n){var u=Math.sqrt(t*t+r*r);return[t*a/u+e,r*a/u+n]}export{t as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * rotate of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * rotate of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function rotate (cx, cy, deg, x, y) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * rotate of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * rotate of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function t(t,a,n,r,e){var o=Math.cos(n),s=Math.sin(n);return[(r-t)*o-(e-a)*s+t,(r-t)*s+(e-a)*o+a]}export{t as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ruler of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * ruler of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function ruler (maxValue, minValue, num, option) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * ruler of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * ruler of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function n(n,r,t,e){if(n<r){var i=r;r=n,n=i}else if(n==r)return[n];var a=function(n){for(var r=n<100&&n>-100?10:.1,t=-1,e=n;10==r?e>=-100&&e<=100:e<=-100||e>=100;)t+=1,e*=r;if(10==r)return Math.pow(10,t);for(var i="0.",a=1;a<t;a++)i+="0";return+(i+"1")}(n-r),u=Math.ceil((n-r)*a/t),f=function(t){var e=({3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[u+t]||u+t)/a,i=Math.floor(r/e)*e,f=[];f.push(i);for(var l=1;f[f.length-1]<n;l++)f.push(i+e*l);return f},l=f(0),o=function(){for(var n=[],t=l[l.length-1]-(null==e?void 0:e.max),i=0;i<l.length;i++)i+1<l.length&&l[i+1]-t<r||n.push(l[i]-t);return n},h=function(){for(var r=[],t=l[0]-(null==e?void 0:e.min),i=0;i<l.length&&(r[i]=l[i]-t,!(n<=r[i]));i++);return r};if(e){if("max"in e&&"min"in e&&e.max>=n&&e.min<=r){var m=function(){if(l[0]>=e.min&&l[l.length-1]<=e.max)return!0;var n=o();if(n[0]>=e.min&&n[n.length-1]<=e.max)return l=n,!0;var r=h();return r[0]>=e.min&&r[n.length-1]<=e.max?(l=r,!0):void 0};if(m())return l;for(var v=1;v<100;v++){if(l=f(v),m())return l;if(l=f(-v),m())return l}}"max"in e&&e.max>=n?e.max<l[l.length-1]&&(l=o()):"min"in e&&e.min<=r&&e.min>l[0]&&(l=h())}for(var g=0;g<l.length;g++){var s=l[g]+"";/\./.test(s)&&(/9{7,}$/.test(s)?(s=s.replace(/9{7,}$/,""),l[g]=+(s.substring(0,s.length-1)+(+s[s.length-1]+1))):/0{7,}\d$/.test(s)&&(l[g]=+s.replace(/0{7,}\d$/,"")))}return l}export{n as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * scale of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * scale of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function scale (cx, cy, times, x, y) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * scale of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * scale of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function t(t,e,n,r,u){return[n*(r-t)+t,n*(u-e)+e]}export{t as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * throttle of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function throttle(callback, _option) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of VISLite JavaScript Library v1.2.0-alpha.6
2
+ * throttle of VISLite JavaScript Library v1.2.0-beta.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function t(t,e){var n={time:200,keep:!1,opportunity:"end"};if(e)for(var p in e)n[p]=e[p];var r,i=!1,o=!1,a=!1;return function(){const e=this;if(r=arguments,i)o=!0,a=!0;else{"end"!=n.opportunity&&t.apply(e,r),i=!0;var p=setInterval((()=>{o?n.keep||t.apply(e,r):("begin"!=n.opportunity&&(a||"end"==n.opportunity)&&t.apply(e,r),i=!1,a=!1,clearInterval(p)),o=!1}),n.time)}}}export{t as default};
@@ -0,0 +1,36 @@
1
+ export default function (_this, drawImage, canvas) {
2
+ return function (imgUrl, x, y, w, h) {
3
+ return new Promise((resolve) => {
4
+
5
+ let doit = (imgsrc) => {
6
+ if (canvas.createImage) {
7
+ let img = canvas.createImage();
8
+ img.onload = function () {
9
+ drawImage.call(_this, img, x, y, w, h, true).then(() => {
10
+ resolve({});
11
+ });
12
+ };
13
+ img.src = imgsrc;
14
+ }
15
+
16
+ // 低版本兼容
17
+ else {
18
+ drawImage.call(_this, imgsrc, x, y, w, h, true).then(() => {
19
+ resolve({});
20
+ });
21
+ }
22
+ };
23
+
24
+ if (/^http/.test(imgUrl)) {
25
+ my.downloadFile({
26
+ url: imgUrl,
27
+ success: function (res) {
28
+ doit(res.tempFilePath);
29
+ },
30
+ })
31
+ } else {
32
+ doit(imgUrl);
33
+ }
34
+ });
35
+ };
36
+ };
@@ -0,0 +1,5 @@
1
+ /* 辅助的区域不应该可以看见 */
2
+ .region {
3
+ position: fixed;
4
+ left: 50000px;
5
+ }
@@ -0,0 +1,4 @@
1
+ <view>
2
+ <canvas type="2d" id="{{'painter-'+uniqueid}}" style="{{'width:'+(width+'px')+';'+('height:'+(height+'px')+';')}}" width="{{2*width+'px'}}" height="{{2*height+'px'}}" onTouchStart="doitstart"></canvas>
3
+ <canvas a:if="{{region}}" type="2d" id="{{'region-'+uniqueid}}" style="{{'width:'+(width+'px')+';'+('height:'+(height+'px')+';')}}" id="{{'region-'+uniqueid}}" class="region"></canvas>
4
+ </view>
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,101 @@
1
+ import RawCanvas from "../../lib/RawCanvas/index.es.min.js";
2
+ import drawImage from "./drawImage.js";
3
+
4
+ // https://opendocs.alipay.com/mini/framework/custom-component-overview
5
+
6
+ Component({
7
+ props: {
8
+ width: 300,
9
+ height: 150,
10
+ region: true,
11
+ onDoTouchstart: () => { }
12
+ },
13
+ data: {
14
+ uniqueid: (Math.random() * 10000).toFixed(0),
15
+ help: {}
16
+ },
17
+ methods: {
18
+ fetch() {
19
+ return new Promise((resolve, reject) => {
20
+
21
+ let getCanvasContext = (idName, doback) => {
22
+ if (idName != 'region' || this.props.region) {
23
+ my.createSelectorQuery().select('#' + idName + '-' + this.data.uniqueid).node().exec((res) => {
24
+ const canvas = res[0].node;
25
+ const ctx = canvas.getContext('2d');
26
+
27
+ if (idName != "region") {
28
+ ctx.scale(2, 2);
29
+ }
30
+
31
+ doback(ctx, idName != 'region' ? canvas : null);
32
+
33
+ })
34
+ } else {
35
+ doback(null);
36
+ }
37
+ };
38
+
39
+ getCanvasContext("painter", (painter, panvas) => {
40
+ getCanvasContext("region", region => {
41
+
42
+ this.data.help.instance = new RawCanvas({
43
+ getContext() {
44
+ return painter;
45
+ }
46
+ }, this.props.region ? {
47
+ getContext() {
48
+ return region;
49
+ }
50
+ } : null);
51
+
52
+ this.data.help.instance.toDataURL = () => {
53
+ return new Promise((resolveUrl) => {
54
+ if (panvas.toDataURL) {
55
+ resolveUrl(panvas.toDataURL());
56
+ } else {
57
+ panvas.toTempFilePath({
58
+ x: 0,
59
+ y: 0,
60
+ width: this.props.widht,
61
+ height: this.props.height,
62
+ success(e) {
63
+ resolveUrl(e.tempFilePath);
64
+ },
65
+ fail(error) {
66
+ console.error(error);
67
+ }
68
+ });
69
+ }
70
+ });
71
+ };
72
+
73
+ this.data.help.instance.drawImage = drawImage(
74
+ this.data.help.instance,
75
+ this.data.help.instance.drawImage,
76
+ panvas
77
+ );
78
+
79
+ resolve(this.data.help.instance);
80
+ });
81
+ });
82
+
83
+ });
84
+ },
85
+ doit(event) {
86
+ let x = event.touches[0].x;
87
+ let y = event.touches[0].y;
88
+
89
+ this.data.help.instance.getRegion(x, y).then((regionName) => {
90
+ this.props.onDoTouchstart({
91
+ name: regionName,
92
+ x: x,
93
+ y: y
94
+ });
95
+ });
96
+ },
97
+ doitstart(event) {
98
+ this.doit(event);
99
+ }
100
+ }
101
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "component": true,
3
+ "usingComponents": {
4
+
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vislite",
3
- "version": "1.2.0-alpha.6",
3
+ "version": "1.2.0-beta.0",
4
4
  "description": "灵活、快速、简单的数据可视化交互式跨端前端库",
5
5
  "main": "./lib/index.umd.min.js",
6
6
  "typings": "./types/index.d.ts",
@@ -0,0 +1,62 @@
1
+ import type { arcCapType } from '../../../types/painterConfig'
2
+
3
+ export default function (type?: string) {
4
+
5
+ let special = {
6
+ // 文字大小
7
+ "fontSize": 16,
8
+
9
+ // 字体
10
+ "fontFamily": "sans-serif",
11
+
12
+ // 字重
13
+ "fontWeight": 400,
14
+
15
+ // 字类型
16
+ "fontStyle": "normal",
17
+
18
+ // 圆弧开始端闭合方式("butt"直线闭合、"round"圆帽闭合)
19
+ "arcStartCap": <arcCapType>'butt',
20
+
21
+ // 圆弧结束端闭合方式,和上一个类似
22
+ "arcEndCap": <arcCapType>'butt'
23
+ }
24
+
25
+ let init = {
26
+ // 填充色或图案
27
+ "fillStyle": 'black',
28
+
29
+ // 轮廓色或图案
30
+ "strokeStyle": 'black',
31
+
32
+ // 线条宽度(单位px,下同)
33
+ "lineWidth": 1,
34
+
35
+ // 线的端点类型,("butt"平直边缘、"round"半圆和"square"矩形)
36
+ "lineCap": "butt",
37
+
38
+ // 线的拐角连接方式,("miter"连接处边缘延长相接、"bevel"对角线斜角和"round"圆)
39
+ "lineJoin": "miter",
40
+
41
+ // 设置线条虚线,应该是一个数组[number,...]
42
+ "lineDash": [],
43
+
44
+ // 文字水平对齐方式("left"左对齐、"center"居中和"right"右对齐)
45
+ "textAlign": 'left',
46
+
47
+ // 文字垂直对齐方式("middle"垂直居中、"top"上对齐和"bottom"下对齐)
48
+ "textBaseline": 'middle',
49
+
50
+ // 阴影的模糊系数,默认0,也就是无阴影
51
+ "shadowBlur": 0,
52
+
53
+ // 阴影的颜色
54
+ "shadowColor": "black"
55
+ }
56
+
57
+ if (type == 'special') return special
58
+ else if (type == 'init') return init
59
+ else return {
60
+ ...special, ...init
61
+ }
62
+ }
@@ -5,6 +5,7 @@ import PainterRender from "./painter"
5
5
  import assemble from "../assemble"
6
6
  import { linearGradient, radialGradient, conicGradient } from "./gradient"
7
7
  import { initText } from './config'
8
+ import defaultFactory from "./default"
8
9
 
9
10
  class Canvas extends PainterRender {
10
11
  readonly name: string = "Canvas"
@@ -33,12 +34,17 @@ class Canvas extends PainterRender {
33
34
 
34
35
  config(configs: CanvasConfigType) {
35
36
  for (const key in configs) {
36
- this.useConfig(key, configs[key])
37
+ this.useConfig(key, (configs as any)[key])
37
38
  }
38
39
 
39
40
  return this
40
41
  }
41
42
 
43
+ reset() {
44
+ this.config(defaultFactory() as CanvasConfigType)
45
+ return this
46
+ }
47
+
42
48
  // 是否绘制的内容只需要进行区域记录
43
49
  onlyRegion(flag: boolean) {
44
50
  this.__onlyRegion = flag
@@ -54,14 +60,14 @@ class Canvas extends PainterRender {
54
60
  setRegion(regionName: string | number) {
55
61
  if (this.__region) {
56
62
  if (regionName) {
57
- if (this.__regionList[regionName] == void 0) {
58
- const tempColor = this.__regionAssemble()
59
- this.__regionList[regionName] =
63
+ if ((this.__regionList as any)[regionName] == void 0) {
64
+ const tempColor = this.__regionAssemble();
65
+ (this.__regionList as any)[regionName] =
60
66
  "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")"
61
67
  }
62
68
 
63
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
64
- this.__region.useConfig("strokeStyle", this.__regionList[regionName])
69
+ this.__region.useConfig("fillStyle", (this.__regionList as any)[regionName]) &&
70
+ this.__region.useConfig("strokeStyle", (this.__regionList as any)[regionName])
65
71
  } else {
66
72
  this.__region.useConfig("fillStyle", "#000000") &&
67
73
  this.__region.useConfig("strokeStyle", "#000000")
@@ -93,7 +99,7 @@ class Canvas extends PainterRender {
93
99
  "," +
94
100
  currentRGBA[2] +
95
101
  ")" ==
96
- this.__regionList[key]
102
+ (this.__regionList as any)[key]
97
103
  ) {
98
104
  resolve(key)
99
105
  break
@@ -1,8 +1,8 @@
1
- import type { arcCapType } from '../../../types/painterConfig'
2
1
  import type CanvasOptsType from '../../../types/CanvasOpts'
3
2
 
4
3
  import { initText, initArc, initCircle, initRect } from './config'
5
4
  import texts from './texts'
5
+ import defaultFactory from "./default"
6
6
 
7
7
  class Painter {
8
8
 
@@ -16,62 +16,11 @@ class Painter {
16
16
 
17
17
  // 用于记录配置
18
18
  // 因为部分配置的设置比较特殊,只先记录意图
19
- __specialConfig = {
20
-
21
- // 文字大小
22
- "fontSize": 16,
23
-
24
- // 字体
25
- "fontFamily": "sans-serif",
26
-
27
- // 字重
28
- "fontWeight": 400,
29
-
30
- // 字类型
31
- "fontStyle": "normal",
32
-
33
- // 圆弧开始端闭合方式("butt"直线闭合、"round"圆帽闭合)
34
- "arcStartCap": <arcCapType>'butt',
35
-
36
- // 圆弧结束端闭合方式,和上一个类似
37
- "arcEndCap": <arcCapType>'butt'
38
- } as {
19
+ __specialConfig = defaultFactory("special") as {
39
20
  [key: string]: any
40
21
  }
41
22
 
42
- private __initConfig = {
43
-
44
- // 填充色或图案
45
- "fillStyle": 'black',
46
-
47
- // 轮廓色或图案
48
- "strokeStyle": 'black',
49
-
50
- // 线条宽度(单位px,下同)
51
- "lineWidth": 1,
52
-
53
- // 线的端点类型,("butt"平直边缘、"round"半圆和"square"矩形)
54
- "lineCap": "butt",
55
-
56
- // 线的拐角连接方式,("miter"连接处边缘延长相接、"bevel"对角线斜角和"round"圆)
57
- "lineJoin": "miter",
58
-
59
- // 设置线条虚线,应该是一个数组[number,...]
60
- "lineDash": [],
61
-
62
- // 文字水平对齐方式("left"左对齐、"center"居中和"right"右对齐)
63
- "textAlign": 'left',
64
-
65
- // 文字垂直对齐方式("middle"垂直居中、"top"上对齐和"bottom"下对齐)
66
- "textBaseline": 'middle',
67
-
68
- // 阴影的模糊系数,默认0,也就是无阴影
69
- "shadowBlur": 0,
70
-
71
- // 阴影的颜色
72
- "shadowColor": "black"
73
-
74
- }
23
+ private __initConfig = defaultFactory("init")
75
24
 
76
25
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
77
26
  constructor(canvas: HTMLCanvasElement, opts: CanvasOptsType = {}, region?: Painter, isPainter = false, scaleSize = 1) {
@@ -122,7 +71,7 @@ class Painter {
122
71
 
123
72
  // 其它情况直接生效即可
124
73
  else if (key in this.__initConfig) {
125
- this.painter[key] = value
74
+ (this.painter as any)[key] = value
126
75
  }
127
76
 
128
77
  // 如果属性未被定义
@@ -446,12 +395,12 @@ class Painter {
446
395
  if (typeof img == 'string' && !isImage) {
447
396
  const imgInstance = new Image()
448
397
  imgInstance.onload = () => {
449
- this.painter.drawImage(imgInstance, 0, 0, imgInstance.width, imgInstance.height, x, y, w, h)
398
+ this.painter.drawImage(imgInstance, x, y, w, h)
450
399
  resolve({})
451
400
  }
452
401
  imgInstance.src = img
453
402
  } else {
454
- this.painter.drawImage(img as CanvasImageSource, 0, 0, w, h, x, y, w, h)
403
+ this.painter.drawImage(img as CanvasImageSource, x, y, w, h)
455
404
  resolve({})
456
405
  }
457
406
 
@@ -467,7 +416,7 @@ class Painter {
467
416
  if (key in this) {
468
417
  throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.")
469
418
  } else {
470
- this[key] = (...args: any) => {
419
+ (this as any)[key] = (...args: any) => {
471
420
  let value = methods[key].apply(this, args)
472
421
  if (value != void 0) return value
473
422
  return this
@@ -0,0 +1,27 @@
1
+ import type { arcCapType, textAlignType, textBaselineType, lineCapType, lineJoinType } from "../../../types/painterConfig"
2
+
3
+ export default function () {
4
+ return {
5
+ // 颜色
6
+ fillStyle: "#000",
7
+ strokeStyle: "#000",
8
+
9
+ // 文字对齐方式
10
+ textAlign: <textAlignType>"left",
11
+ textBaseline: <textBaselineType>"middle",
12
+
13
+ // 文字
14
+ "fontSize": 16,
15
+ "fontFamily": "sans-serif",
16
+
17
+ // arc二端闭合方式['butt':直线闭合,'round':圆帽闭合]
18
+ "arcStartCap": <arcCapType>"butt",
19
+ "arcEndCap": <arcCapType>"butt",
20
+
21
+ // 线条
22
+ lineDash: [],
23
+ lineWidth: 1,
24
+ lineCap: <lineCapType>"butt",
25
+ lineJoin: <lineJoinType>"miter"
26
+ }
27
+ }
@@ -1,39 +1,16 @@
1
1
  import type { default as SVGConfigType, svgElType, svgBoardType } from "../../../types/SVGConfig"
2
- import type { arcCapType, textAlignType, textBaselineType, lineCapType, lineJoinType } from "../../../types/painterConfig"
3
2
 
4
3
  import { initText, initCircle, initPath, initRect, initArc } from "./config"
5
4
  import { toNode, setAttribute, getAttribute, full, fill, stroke } from "./tool"
6
5
  import rotate from "../../rotate"
7
6
  import { linearGradient, radialGradient } from "./gradient"
7
+ import defaultFactory from "./default"
8
8
 
9
9
  class SVG {
10
10
  readonly name: string = "SVG"
11
11
 
12
12
  // 用于记录配置
13
- private __config = {
14
-
15
- // 颜色
16
- fillStyle: "#000",
17
- strokeStyle: "#000",
18
-
19
- // 文字对齐方式
20
- textAlign: <textAlignType>"left",
21
- textBaseline: <textBaselineType>"middle",
22
-
23
- // 文字
24
- "fontSize": 16,
25
- "fontFamily": "sans-serif",
26
-
27
- // arc二端闭合方式['butt':直线闭合,'round':圆帽闭合]
28
- "arcStartCap": <arcCapType>"butt",
29
- "arcEndCap": <arcCapType>"butt",
30
-
31
- // 线条
32
- lineDash: [],
33
- lineWidth: 1,
34
- lineCap: <lineCapType>"butt",
35
- lineJoin: <lineJoinType>"miter"
36
- }
13
+ private __config = defaultFactory()
37
14
 
38
15
  // 作用的节点
39
16
  private __useEl: SVGElement
@@ -53,12 +30,17 @@ class SVG {
53
30
  return this.__config[params]
54
31
  } else {
55
32
  for (const key in params) {
56
- this.__config[key] = params[key]
33
+ (this.__config as any)[key] = (params as any)[key]
57
34
  }
58
35
  }
59
36
  return this
60
37
  }
61
38
 
39
+ reset() {
40
+ this.config(defaultFactory())
41
+ return this
42
+ }
43
+
62
44
  /**
63
45
  * 基础方法
64
46
  * ---------------------------------
package/types/Canvas.d.ts CHANGED
@@ -7,6 +7,11 @@ export default interface CanvasType {
7
7
  */
8
8
  config(configs: CanvasConfigType): this
9
9
 
10
+ /**
11
+ * 重置
12
+ */
13
+ reset(): this
14
+
10
15
  /**
11
16
  * 绘制一个实心文字
12
17
  * @param text 需要绘制的文字
package/types/SVG.d.ts CHANGED
@@ -8,6 +8,11 @@ export default interface SVGType {
8
8
  */
9
9
  config(configs: SVGConfigType): this
10
10
 
11
+ /**
12
+ * 重置
13
+ */
14
+ reset(): this
15
+
11
16
  /**
12
17
  * 标记应用节点
13
18
  */