@visactor/vrender-components 0.21.0-alpha.4 → 0.21.0-vstory.2

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 (75) hide show
  1. package/cjs/core/base.d.ts +1 -0
  2. package/cjs/core/base.js +3 -3
  3. package/cjs/core/base.js.map +1 -1
  4. package/cjs/index.d.ts +2 -2
  5. package/cjs/index.js +2 -2
  6. package/cjs/index.js.map +1 -1
  7. package/cjs/interface.d.ts +2 -1
  8. package/cjs/interface.js.map +1 -1
  9. package/cjs/jsx/component-type.js +2 -1
  10. package/cjs/label/arc.js +1 -2
  11. package/cjs/label/base.js +3 -8
  12. package/cjs/label/base.js.map +1 -1
  13. package/cjs/label/polygon.js +1 -1
  14. package/cjs/label/rect.js +1 -1
  15. package/cjs/legend/discrete/discrete.d.ts +0 -7
  16. package/cjs/legend/discrete/discrete.js +23 -106
  17. package/cjs/legend/discrete/discrete.js.map +1 -1
  18. package/cjs/legend/discrete/type.d.ts +3 -15
  19. package/cjs/legend/discrete/type.js.map +1 -1
  20. package/cjs/weather/index.d.ts +1 -0
  21. package/cjs/{gif → weather}/index.js +2 -2
  22. package/cjs/weather/index.js.map +1 -0
  23. package/cjs/weather/register.d.ts +1 -0
  24. package/cjs/weather/register.js +14 -0
  25. package/cjs/weather/register.js.map +1 -0
  26. package/cjs/weather/type.d.ts +24 -0
  27. package/cjs/weather/type.js +6 -0
  28. package/cjs/weather/type.js.map +1 -0
  29. package/cjs/weather/weather-box.d.ts +13 -0
  30. package/cjs/weather/weather-box.js +129 -0
  31. package/cjs/weather/weather-box.js.map +1 -0
  32. package/dist/index.es.js +5783 -6180
  33. package/es/core/base.d.ts +1 -0
  34. package/es/core/base.js +4 -3
  35. package/es/core/base.js.map +1 -1
  36. package/es/index.d.ts +2 -2
  37. package/es/index.js +3 -3
  38. package/es/index.js.map +1 -1
  39. package/es/interface.d.ts +2 -1
  40. package/es/interface.js.map +1 -1
  41. package/es/jsx/component-type.js +2 -1
  42. package/es/label/arc.js +1 -2
  43. package/es/label/base.js +2 -8
  44. package/es/label/base.js.map +1 -1
  45. package/es/label/polygon.js +1 -1
  46. package/es/label/rect.js +1 -1
  47. package/es/legend/discrete/discrete.d.ts +0 -7
  48. package/es/legend/discrete/discrete.js +24 -106
  49. package/es/legend/discrete/discrete.js.map +1 -1
  50. package/es/legend/discrete/type.d.ts +3 -15
  51. package/es/legend/discrete/type.js.map +1 -1
  52. package/es/weather/index.d.ts +1 -0
  53. package/es/weather/index.js +2 -0
  54. package/es/weather/index.js.map +1 -0
  55. package/es/weather/register.d.ts +1 -0
  56. package/es/weather/register.js +6 -0
  57. package/es/weather/register.js.map +1 -0
  58. package/es/weather/type.d.ts +24 -0
  59. package/es/weather/type.js +2 -0
  60. package/es/weather/type.js.map +1 -0
  61. package/es/weather/weather-box.d.ts +13 -0
  62. package/es/weather/weather-box.js +127 -0
  63. package/es/weather/weather-box.js.map +1 -0
  64. package/package.json +8 -9
  65. package/cjs/gif/gif.d.ts +0 -29
  66. package/cjs/gif/gif.js +0 -59
  67. package/cjs/gif/gif.js.map +0 -1
  68. package/cjs/gif/index.d.ts +0 -1
  69. package/cjs/gif/index.js.map +0 -1
  70. package/es/gif/gif.d.ts +0 -29
  71. package/es/gif/gif.js +0 -55
  72. package/es/gif/gif.js.map +0 -1
  73. package/es/gif/index.d.ts +0 -1
  74. package/es/gif/index.js +0 -2
  75. package/es/gif/index.js.map +0 -1
@@ -0,0 +1,13 @@
1
+ import { AbstractComponent } from '../core/base';
2
+ import type { IWeatherBoxAttrs } from './type';
3
+ import type { ComponentOptions } from '../interface';
4
+ import { type IGroup, type ITimeline } from '@visactor/vrender-core';
5
+ export declare class WeatherBox extends AbstractComponent<Required<IWeatherBoxAttrs>> {
6
+ name: string;
7
+ static defaultAttributes: Partial<IWeatherBoxAttrs>;
8
+ timeline: ITimeline;
9
+ constructor(attributes: IWeatherBoxAttrs, options?: ComponentOptions);
10
+ protected render(): void;
11
+ protected generateWind(windRatio: number, windIconPath: string, group: IGroup, size: number, speed: number): void;
12
+ protected generateRainOrSnow(type: string, ratio: number, threshold: number, windRatio: number, group: IGroup, path: string, windAngle: number, sizeRange: [number, number], speed: number): void;
13
+ }
@@ -0,0 +1,127 @@
1
+ import { AbstractComponent } from "../core/base";
2
+
3
+ import { merge } from "@visactor/vutils";
4
+
5
+ import { Animate, DefaultTimeline } from "@visactor/vrender-core";
6
+
7
+ function random() {
8
+ return Math.random();
9
+ }
10
+
11
+ function createUniformRandom(count) {
12
+ const result = [], step = 1 / count;
13
+ for (let i = 0; i < count; i++) result.push((random() - .5) * step / 2 + step * i);
14
+ result.sort((() => Math.random() - .5));
15
+ let idx = 0;
16
+ return function(i) {
17
+ return idx > count - 1 && (idx = 0), void 0 === i && (i = idx, idx++), result[i];
18
+ };
19
+ }
20
+
21
+ export class WeatherBox extends AbstractComponent {
22
+ constructor(attributes, options) {
23
+ var _a;
24
+ super((null == options ? void 0 : options.skipDefault) ? attributes : merge({}, WeatherBox.defaultAttributes, attributes)),
25
+ this.name = "weatherBox", this.timeline = null !== (_a = null == options ? void 0 : options.timeline) && void 0 !== _a ? _a : new DefaultTimeline;
26
+ }
27
+ render() {
28
+ const {rainRatio: rainRatio, rainIconPath: rainIconPath, snowRatio: snowRatio, snowIconPath: snowIconPath, rainCountThreshold: rainCountThreshold, snowCountThreshold: snowCountThreshold, windRatio: windRatio, rainSizeRange: rainSizeRange, snowSizeRange: snowSizeRange, rainSpeed: rainSpeed, snowSpeed: snowSpeed, width: width, height: height, windIconPath: windIconPath, windSize: windSize, windSpeed: windSpeed} = this.attribute;
29
+ this.attribute.clip = !0;
30
+ const windAngle = -windRatio * Math.PI / 4, rainGroup = this.createOrUpdateChild("rain-container", {
31
+ zIndex: 1,
32
+ width: width,
33
+ height: height
34
+ }, "group");
35
+ rainRatio > 0 && this.generateRainOrSnow("rain", rainRatio, rainCountThreshold, windRatio, rainGroup, rainIconPath, windAngle, rainSizeRange, rainSpeed);
36
+ const snowGroup = this.createOrUpdateChild("snow-container", {
37
+ zIndex: 1,
38
+ width: width,
39
+ height: height
40
+ }, "group");
41
+ snowRatio > 0 && this.generateRainOrSnow("snow", snowRatio, snowCountThreshold, windRatio, snowGroup, snowIconPath, windAngle, snowSizeRange, snowSpeed);
42
+ const windGroup = this.createOrUpdateChild("wind-container", {
43
+ zIndex: 0,
44
+ width: width,
45
+ height: height
46
+ }, "group");
47
+ windRatio > 0 && this.generateWind(windRatio, windIconPath, windGroup, windSize, windSpeed);
48
+ }
49
+ generateWind(windRatio, windIconPath, group, size, speed) {
50
+ const {width: width, height: height} = group.attribute, {windAnimateEffect: windAnimateEffect, windStyle: windStyle = {}} = this.attribute;
51
+ let fromAttribute = {
52
+ opacity: 0,
53
+ clipRange: 1
54
+ }, toAttribute = {
55
+ opacity: 1,
56
+ clipRange: 1
57
+ };
58
+ "clipRange" === windAnimateEffect && (fromAttribute = {
59
+ clipRange: 0,
60
+ opacity: 1
61
+ }, toAttribute = {
62
+ clipRange: 1,
63
+ opacity: 1
64
+ });
65
+ const wind = group.createOrUpdateChild("wind", Object.assign(Object.assign({
66
+ x: (width - size) / 2,
67
+ y: (height - size) / 2,
68
+ symbolType: windIconPath,
69
+ size: size,
70
+ stroke: "white",
71
+ lineWidth: 2,
72
+ dx: -size / 2,
73
+ dy: -size / 2
74
+ }, windStyle), fromAttribute), "symbol"), duration = speed / 4 * 1e3;
75
+ new Animate(void 0, this.timeline).bind(wind).to(fromAttribute, duration, "linear").to(toAttribute, duration, "linear").wait(duration / 2).loop(1 / 0);
76
+ }
77
+ generateRainOrSnow(type, ratio, threshold, windRatio, group, path, windAngle, sizeRange, speed) {
78
+ let {width: width} = group.attribute;
79
+ const {height: height} = group.attribute, {snowRainBottomPadding: snowRainBottomPadding, rainStyle: rainStyle = {}, snowStyle: snowStyle = {}} = this.attribute;
80
+ let maxCount = Math.round(ratio * threshold);
81
+ windRatio > 0 && (maxCount *= Math.round(1 + windRatio)), width *= Math.round(1 + windRatio);
82
+ const uniformRandomX = createUniformRandom(maxCount), uniformRandomY = createUniformRandom(maxCount);
83
+ for (let i = 0; i < maxCount; i++) {
84
+ const x = uniformRandomX(), y = uniformRandomY(), size = sizeRange[0] + random() * (sizeRange[1] - sizeRange[0]), startX = x * width - (windAngle ? height * Math.tan(Math.abs(windAngle)) : 0), startY = -y * height, particle = group.createOrUpdateChild(`${type}-${i}`, Object.assign({
85
+ x: startX,
86
+ y: startY,
87
+ symbolType: path,
88
+ size: size,
89
+ fill: "white",
90
+ angle: windAngle
91
+ }, "rain" === type ? rainStyle : snowStyle), "symbol"), duration = 1 / speed / 2 * (1 + y) * 1e3;
92
+ let endX = x * width;
93
+ "rain" === type && windAngle && (endX = startX + (1 + y) * height * Math.tan(Math.abs(windAngle))),
94
+ new Animate(void 0, this.timeline).bind(particle).to({
95
+ x: endX,
96
+ y: height - snowRainBottomPadding
97
+ }, duration, "linear").loop(1 / 0), new Animate(void 0, this.timeline).bind(particle).to({
98
+ opacity: 0
99
+ }, duration, "quintIn").loop(1 / 0);
100
+ }
101
+ }
102
+ }
103
+
104
+ WeatherBox.defaultAttributes = {
105
+ snowIconPath: "M512 64c24.7 0 44.8 20.1 44.8 44.8v43.1l29.3-15.5c21.9-11.6 49-3.2 60.5 18.7s3.2 49-18.7 60.5l-71.2 37.6v85.2c32 8.2 60.6 25.1 83.1 48l73.8-42.6-3-80.4c-0.9-24.7 18.4-45.5 43.1-46.4 24.7-0.9 45.5 18.4 46.4 43.1l1.2 33.1 37.3-21.5c21.4-12.4 48.8-5 61.2 16.4 12.4 21.4 5 48.8-16.4 61.2l-37.3 21.5 28.1 17.6c21 13.2 27.3 40.8 14.1 61.8-13.2 20.9-40.8 27.3-61.8 14.1l-68.2-42.8-73.6 42.5c4.2 15.3 6.5 31.4 6.5 48s-2.3 32.7-6.5 48l73.8 42.6 68.2-42.8c20.9-13.2 48.6-6.8 61.8 14.1 13.2 21 6.8 48.6-14.1 61.8l-28.1 17.6 37.3 21.5c21.4 12.4 28.8 39.8 16.4 61.2-12.4 21.4-39.8 28.8-61.2 16.4l-37.3-21.5-1.2 33.1c-0.9 24.7-21.7 44-46.4 43.1-24.7-0.9-44-21.7-43.1-46.4l3-80.4-73.8-42.6c-22.5 22.9-51 39.8-83.1 48v85.2l71.2 37.6c21.9 11.6 30.2 38.7 18.7 60.5-11.6 21.9-38.7 30.2-60.5 18.7L557 872.2v43.1c0 24.7-20.1 44.8-44.8 44.8-24.7 0-44.8-20.1-44.8-44.8v-43.1l-29.3 15.5c-21.9 11.6-49 3.2-60.5-18.7-11.6-21.9-3.2-49 18.7-60.5l71.2-37.6v-85.2c-32-8.2-60.6-25.1-83.1-48l-73.8 42.6 3 80.4c0.9 24.7-18.4 45.5-43.1 46.4-24.7 0.9-45.5-18.4-46.4-43.1l-1.2-33.1-37.3 21.5c-21.4 12.4-48.8 5-61.2-16.4s-5-48.8 16.4-61.2l37.3-21.5-28.1-17.6c-21-13.2-27.3-40.8-14.1-61.8 13.2-20.9 40.8-27.3 61.8-14.1l68.2 42.8 73.8-42.6c-4.2-15.3-6.5-31.4-6.5-48s2.3-32.7 6.5-48l-73.8-42.6-68.2 42.8c-21 13.2-48.6 6.8-61.8-14.1-13.2-21-6.8-48.6 14.1-61.8l28.1-17.6-37.3-21.5C119 336.8 111.7 309.4 124 288c12.4-21.4 39.8-28.8 61.2-16.4l37.3 21.5 1.2-33.1c0.9-24.7 21.7-44 46.4-43.1 24.7 0.9 44 21.7 43.1 46.4l-3 80.4 73.8 42.6c22.5-22.9 51-39.8 83.1-48v-85.2L396 215.6c-21.9-11.6-30.2-38.7-18.7-60.5 11.6-21.9 38.7-30.2 60.5-18.7l29.3 15.5v-43.1C467.2 84.1 487.3 64 512 64z m0 537.6c49.5 0 89.6-40.1 89.6-89.6s-40.1-89.6-89.6-89.6-89.6 40.1-89.6 89.6 40.1 89.6 89.6 89.6z",
106
+ rainIconPath: "M802.94208 583.04c19.328 38.016 29.056 78.336 29.056 120.96a313.216 313.216 0 0 1-44.032 161.536 324.48 324.48 0 0 1-114.56 114.944c-23.552 13.696-49.024 24.32-76.416 32-27.264 7.68-55.68 11.52-84.992 11.52-29.44 0-57.6-3.84-84.992-11.52a331.136 331.136 0 0 1-76.544-32 337.536 337.536 0 0 1-65.024-49.92 337.536 337.536 0 0 1-49.92-65.024 331.136 331.136 0 0 1-32-76.544A313.216 313.216 0 0 1 191.99808 704c0-42.24 9.344-82.56 28.032-120.448L509.43808 0l293.504 583.04z",
107
+ windIconPath: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <path d="M 4.0003 14.0002 L 12.0003 14.0008 M 12.0003 14.0008 C 13.1049 14.0009 14.0003 14.8964 14.0002 16.001 C 14.0001 17.1055 13.1046 18.0009 12 18.0008 L 10.5 18.0007" stroke-linecap="round" stroke-linejoin="round"/>\n <path d="M 7 10.0002 L 14.5 10.0008 C 15.6046 10.0009 16.5001 9.1055 16.5002 8.001 C 16.5003 6.8964 15.6049 6.0009 14.5003 6.0008 L 13.0003 6.0007" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',
108
+ windRatio: 0,
109
+ rainRatio: 0,
110
+ snowRatio: 0,
111
+ rainCountThreshold: 10,
112
+ snowCountThreshold: 10,
113
+ rainSizeRange: [ 5, 10 ],
114
+ snowSizeRange: [ 5, 13 ],
115
+ windSize: 30,
116
+ rainSpeed: 1,
117
+ snowSpeed: .5,
118
+ windSpeed: 1,
119
+ windAnimateEffect: "fade",
120
+ rainStyle: {},
121
+ snowStyle: {},
122
+ windStyle: {
123
+ opacity: .8
124
+ },
125
+ snowRainBottomPadding: 0
126
+ };
127
+ //# sourceMappingURL=weather-box.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/weather/weather-box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,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,CAAC;iBACd,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAG,qBAAqB,EAAE,EAAE,QAAQ,EAAE,QAAQ,CAAC;iBACtE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAClB,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC1G;IACH,CAAC;;AA3LM,4BAAiB,GAA8B;IACpD,YAAY,EACV,wsDAAwsD;IAC1sD,YAAY,EACV,wdAAwd;IAC1d,YAAY,EAAE;;;WAGP;IACP,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,CAAC;IACZ,kBAAkB,EAAE,EAAE;IACtB,kBAAkB,EAAE,EAAE;IACtB,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACtB,aAAa,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACtB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,GAAG;IACd,SAAS,EAAE,CAAC;IACZ,iBAAiB,EAAE,MAAM;IACzB,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,SAAS,EAAE;QACT,OAAO,EAAE,GAAG;KACb;IACD,qBAAqB,EAAE,CAAC;CACzB,CAAC","file":"weather-box.js","sourcesContent":["import { AbstractComponent } from '../core/base';\nimport type { IWeatherBoxAttrs } from './type';\nimport type { ComponentOptions } from '../interface';\nimport { merge } from '@visactor/vutils';\nimport { Animate, DefaultTimeline, type IGroup, type ISymbol, type ITimeline } from '@visactor/vrender-core';\n\n// todo 后续可能做成有随机数种子的伪随机,这样可以保证每次都生成一样的随机数\nfunction random() {\n return Math.random();\n}\n\nfunction createUniformRandom(count: number) {\n const result: number[] = [];\n const step = 1 / count;\n for (let i = 0; i < count; i++) {\n result.push(((random() - 0.5) * step) / 2 + step * i);\n }\n result.sort(() => Math.random() - 0.5);\n let idx = 0;\n return function (i?: number) {\n if (idx > count - 1) {\n idx = 0;\n }\n if (i === void 0) {\n i = idx;\n idx++;\n }\n return result[i];\n };\n}\n\nexport class WeatherBox extends AbstractComponent<Required<IWeatherBoxAttrs>> {\n name: string = 'weatherBox';\n\n static defaultAttributes: Partial<IWeatherBoxAttrs> = {\n snowIconPath:\n 'M512 64c24.7 0 44.8 20.1 44.8 44.8v43.1l29.3-15.5c21.9-11.6 49-3.2 60.5 18.7s3.2 49-18.7 60.5l-71.2 37.6v85.2c32 8.2 60.6 25.1 83.1 48l73.8-42.6-3-80.4c-0.9-24.7 18.4-45.5 43.1-46.4 24.7-0.9 45.5 18.4 46.4 43.1l1.2 33.1 37.3-21.5c21.4-12.4 48.8-5 61.2 16.4 12.4 21.4 5 48.8-16.4 61.2l-37.3 21.5 28.1 17.6c21 13.2 27.3 40.8 14.1 61.8-13.2 20.9-40.8 27.3-61.8 14.1l-68.2-42.8-73.6 42.5c4.2 15.3 6.5 31.4 6.5 48s-2.3 32.7-6.5 48l73.8 42.6 68.2-42.8c20.9-13.2 48.6-6.8 61.8 14.1 13.2 21 6.8 48.6-14.1 61.8l-28.1 17.6 37.3 21.5c21.4 12.4 28.8 39.8 16.4 61.2-12.4 21.4-39.8 28.8-61.2 16.4l-37.3-21.5-1.2 33.1c-0.9 24.7-21.7 44-46.4 43.1-24.7-0.9-44-21.7-43.1-46.4l3-80.4-73.8-42.6c-22.5 22.9-51 39.8-83.1 48v85.2l71.2 37.6c21.9 11.6 30.2 38.7 18.7 60.5-11.6 21.9-38.7 30.2-60.5 18.7L557 872.2v43.1c0 24.7-20.1 44.8-44.8 44.8-24.7 0-44.8-20.1-44.8-44.8v-43.1l-29.3 15.5c-21.9 11.6-49 3.2-60.5-18.7-11.6-21.9-3.2-49 18.7-60.5l71.2-37.6v-85.2c-32-8.2-60.6-25.1-83.1-48l-73.8 42.6 3 80.4c0.9 24.7-18.4 45.5-43.1 46.4-24.7 0.9-45.5-18.4-46.4-43.1l-1.2-33.1-37.3 21.5c-21.4 12.4-48.8 5-61.2-16.4s-5-48.8 16.4-61.2l37.3-21.5-28.1-17.6c-21-13.2-27.3-40.8-14.1-61.8 13.2-20.9 40.8-27.3 61.8-14.1l68.2 42.8 73.8-42.6c-4.2-15.3-6.5-31.4-6.5-48s2.3-32.7 6.5-48l-73.8-42.6-68.2 42.8c-21 13.2-48.6 6.8-61.8-14.1-13.2-21-6.8-48.6 14.1-61.8l28.1-17.6-37.3-21.5C119 336.8 111.7 309.4 124 288c12.4-21.4 39.8-28.8 61.2-16.4l37.3 21.5 1.2-33.1c0.9-24.7 21.7-44 46.4-43.1 24.7 0.9 44 21.7 43.1 46.4l-3 80.4 73.8 42.6c22.5-22.9 51-39.8 83.1-48v-85.2L396 215.6c-21.9-11.6-30.2-38.7-18.7-60.5 11.6-21.9 38.7-30.2 60.5-18.7l29.3 15.5v-43.1C467.2 84.1 487.3 64 512 64z m0 537.6c49.5 0 89.6-40.1 89.6-89.6s-40.1-89.6-89.6-89.6-89.6 40.1-89.6 89.6 40.1 89.6 89.6 89.6z',\n rainIconPath:\n 'M802.94208 583.04c19.328 38.016 29.056 78.336 29.056 120.96a313.216 313.216 0 0 1-44.032 161.536 324.48 324.48 0 0 1-114.56 114.944c-23.552 13.696-49.024 24.32-76.416 32-27.264 7.68-55.68 11.52-84.992 11.52-29.44 0-57.6-3.84-84.992-11.52a331.136 331.136 0 0 1-76.544-32 337.536 337.536 0 0 1-65.024-49.92 337.536 337.536 0 0 1-49.92-65.024 331.136 331.136 0 0 1-32-76.544A313.216 313.216 0 0 1 191.99808 704c0-42.24 9.344-82.56 28.032-120.448L509.43808 0l293.504 583.04z',\n windIconPath: `<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M 4.0003 14.0002 L 12.0003 14.0008 M 12.0003 14.0008 C 13.1049 14.0009 14.0003 14.8964 14.0002 16.001 C 14.0001 17.1055 13.1046 18.0009 12 18.0008 L 10.5 18.0007\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n <path d=\"M 7 10.0002 L 14.5 10.0008 C 15.6046 10.0009 16.5001 9.1055 16.5002 8.001 C 16.5003 6.8964 15.6049 6.0009 14.5003 6.0008 L 13.0003 6.0007\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n </svg>`,\n windRatio: 0,\n rainRatio: 0,\n snowRatio: 0,\n rainCountThreshold: 10,\n snowCountThreshold: 10,\n rainSizeRange: [5, 10],\n snowSizeRange: [5, 13],\n windSize: 30,\n rainSpeed: 1,\n snowSpeed: 0.5,\n windSpeed: 1,\n windAnimateEffect: 'fade',\n rainStyle: {},\n snowStyle: {},\n windStyle: {\n opacity: 0.8\n },\n snowRainBottomPadding: 0\n };\n\n timeline: ITimeline;\n\n constructor(attributes: IWeatherBoxAttrs, options?: ComponentOptions) {\n super(options?.skipDefault ? attributes : merge({}, WeatherBox.defaultAttributes, attributes));\n this.timeline = options?.timeline ?? new DefaultTimeline();\n }\n\n protected render(): void {\n const {\n rainRatio,\n rainIconPath,\n snowRatio,\n snowIconPath,\n rainCountThreshold,\n snowCountThreshold,\n windRatio,\n rainSizeRange,\n snowSizeRange,\n rainSpeed,\n snowSpeed,\n width,\n height,\n windIconPath,\n windSize,\n windSpeed\n } = this.attribute as IWeatherBoxAttrs;\n\n this.attribute.clip = true;\n\n // 计算风速导致的偏转角度\n const windAngle = (-windRatio * Math.PI) / 4;\n\n const rainGroup = this.createOrUpdateChild('rain-container', { zIndex: 1, width, height }, 'group') as IGroup;\n if (rainRatio > 0) {\n this.generateRainOrSnow(\n 'rain',\n rainRatio,\n rainCountThreshold,\n windRatio,\n rainGroup,\n rainIconPath,\n windAngle,\n rainSizeRange,\n rainSpeed\n );\n }\n const snowGroup = this.createOrUpdateChild('snow-container', { zIndex: 1, width, height }, 'group') as IGroup;\n if (snowRatio > 0) {\n this.generateRainOrSnow(\n 'snow',\n snowRatio,\n snowCountThreshold,\n windRatio,\n snowGroup,\n snowIconPath,\n windAngle,\n snowSizeRange,\n snowSpeed\n );\n }\n\n const windGroup = this.createOrUpdateChild('wind-container', { zIndex: 0, width, height }, 'group') as IGroup;\n if (windRatio > 0) {\n this.generateWind(windRatio, windIconPath, windGroup, windSize, windSpeed);\n }\n }\n\n protected generateWind(windRatio: number, windIconPath: string, group: IGroup, size: number, speed: number) {\n const { width, height } = group.attribute;\n const { windAnimateEffect, windStyle = {} } = this.attribute;\n\n let fromAttribute = { opacity: 0, clipRange: 1 };\n let toAttribute = { opacity: 1, clipRange: 1 };\n if (windAnimateEffect === 'clipRange') {\n fromAttribute = { clipRange: 0, opacity: 1 };\n toAttribute = { clipRange: 1, opacity: 1 };\n }\n const wind = group.createOrUpdateChild(\n `wind`,\n {\n x: (width - size) / 2,\n y: (height - size) / 2,\n symbolType: windIconPath,\n size,\n stroke: 'white',\n lineWidth: 2,\n dx: -size / 2,\n dy: -size / 2,\n ...windStyle,\n ...fromAttribute\n },\n 'symbol'\n ) as ISymbol;\n\n const duration = (speed / 4) * 1000;\n\n new Animate(void 0, this.timeline)\n .bind(wind)\n .to(fromAttribute, duration, 'linear')\n .to(toAttribute, duration, 'linear')\n .wait(duration / 2)\n .loop(Infinity);\n }\n\n protected generateRainOrSnow(\n type: string,\n ratio: number,\n threshold: number,\n windRatio: number,\n group: IGroup,\n path: string,\n windAngle: number,\n sizeRange: [number, number],\n speed: number\n ) {\n let { width } = group.attribute;\n const { height } = group.attribute;\n const { snowRainBottomPadding, rainStyle = {}, snowStyle = {} } = this.attribute;\n let maxCount = Math.round(ratio * threshold);\n // 由于风速,雨雪粒子会偏转,所以需要增加粒子数量\n if (windRatio > 0) {\n maxCount = maxCount * Math.round(1 + windRatio);\n }\n width = width * Math.round(1 + windRatio);\n const uniformRandomX = createUniformRandom(maxCount);\n const uniformRandomY = createUniformRandom(maxCount);\n for (let i = 0; i < maxCount; i++) {\n const x = uniformRandomX();\n const y = uniformRandomY();\n const size = sizeRange[0] + random() * (sizeRange[1] - sizeRange[0]);\n\n const deltaX = windAngle ? height * Math.tan(Math.abs(windAngle)) : 0;\n const startX = x * width - deltaX;\n const startY = -y * height;\n const particle = group.createOrUpdateChild(\n `${type}-${i}`,\n {\n x: startX,\n y: startY,\n symbolType: path,\n size,\n fill: 'white',\n angle: windAngle,\n ...(type === 'rain' ? rainStyle : snowStyle)\n },\n 'symbol'\n ) as ISymbol;\n const duration = (1 / speed / 2) * (1 + y) * 1000;\n let endX = x * width;\n if (type === 'rain' && windAngle) {\n endX = startX + (1 + y) * height * Math.tan(Math.abs(windAngle));\n }\n new Animate(void 0, this.timeline)\n .bind(particle)\n .to({ x: endX, y: height - snowRainBottomPadding }, duration, 'linear')\n .loop(Infinity);\n new Animate(void 0, this.timeline).bind(particle).to({ opacity: 0 }, duration, 'quintIn').loop(Infinity);\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vrender-components",
3
- "version": "0.21.0-alpha.4",
3
+ "version": "0.21.0-vstory.2",
4
4
  "description": "components library for dp visualization",
5
5
  "sideEffects": false,
6
6
  "main": "cjs/index.js",
@@ -12,15 +12,14 @@
12
12
  "dist"
13
13
  ],
14
14
  "dependencies": {
15
- "@visactor/vutils": "~0.18.17",
16
- "@visactor/vscale": "~0.18.17",
17
- "@visactor/vrender-core": "0.21.0-alpha.4",
18
- "@visactor/vrender-kits": "0.21.0-alpha.4",
19
- "gifuct-js": "2.1.2"
15
+ "@visactor/vutils": "~0.18.18",
16
+ "@visactor/vscale": "~0.18.18",
17
+ "@visactor/vrender-core": "0.21.0-vstory.2",
18
+ "@visactor/vrender-kits": "0.21.0-vstory.2"
20
19
  },
21
20
  "devDependencies": {
22
21
  "@rushstack/eslint-patch": "~1.1.4",
23
- "@visactor/vscale": "~0.18.17",
22
+ "@visactor/vscale": "~0.18.18",
24
23
  "@types/jest": "^26.0.0",
25
24
  "jest": "^26.0.0",
26
25
  "jest-electron": "^0.1.12",
@@ -31,8 +30,8 @@
31
30
  "typescript": "4.9.5",
32
31
  "cross-env": "^7.0.3",
33
32
  "@internal/bundler": "0.0.1",
34
- "@internal/eslint-config": "0.0.1",
35
- "@internal/ts-config": "0.0.1"
33
+ "@internal/ts-config": "0.0.1",
34
+ "@internal/eslint-config": "0.0.1"
36
35
  },
37
36
  "keywords": [
38
37
  "VisActor",
package/cjs/gif/gif.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import type { IImageGraphicAttribute, ISetAttributeContext } from '@visactor/vrender-core';
2
- import { Image } from '@visactor/vrender-core';
3
- import type { ITimeline } from '@visactor/vrender-core';
4
- import type { ParsedFrame } from 'gifuct-js';
5
- export interface IGifImageGraphicAttribute extends IImageGraphicAttribute {
6
- timeline?: ITimeline;
7
- gifImage?: string | ArrayBuffer;
8
- }
9
- export declare class GifImage extends Image {
10
- attribute: IGifImageGraphicAttribute;
11
- frameImageData?: ImageData;
12
- tempCanvas?: HTMLCanvasElement;
13
- tempCtx?: CanvasRenderingContext2D;
14
- gifCanvas?: HTMLCanvasElement;
15
- gifCtx?: CanvasRenderingContext2D;
16
- loadedFrames?: ParsedFrame[];
17
- frameIndex?: number;
18
- playing?: boolean;
19
- lastTime?: number;
20
- isGifImage: boolean;
21
- constructor(params: IGifImageGraphicAttribute);
22
- loadGif(): void;
23
- renderGIF(frames: ParsedFrame[]): void;
24
- renderFrame(context: CanvasRenderingContext2D, x: number, y: number): void;
25
- drawPatch(frame: ParsedFrame): void;
26
- manipulate(context: CanvasRenderingContext2D, x: number, y: number): void;
27
- setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
28
- setAttributes(params: Partial<IGifImageGraphicAttribute>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
29
- }
package/cjs/gif/gif.js DELETED
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: !0
5
- }), exports.GifImage = void 0;
6
-
7
- const vrender_core_1 = require("@visactor/vrender-core"), vutils_1 = require("@visactor/vutils"), gifuct_js_1 = require("gifuct-js");
8
-
9
- class GifImage extends vrender_core_1.Image {
10
- constructor(params) {
11
- super(params), this.isGifImage = !0, this.loadGif();
12
- }
13
- loadGif() {
14
- if ((0, vutils_1.isString)(this.attribute.gifImage)) vrender_core_1.ResourceLoader.GetFile(this.attribute.gifImage, "arrayBuffer").then((res => {
15
- const gif = (0, gifuct_js_1.parseGIF)(res), frames = (0, gifuct_js_1.decompressFrames)(gif, !0);
16
- this.renderGIF(frames);
17
- })).catch((e => {
18
- console.error("Gif load error: ", e);
19
- })); else if (this.attribute.gifImage instanceof ArrayBuffer) {
20
- const gif = (0, gifuct_js_1.parseGIF)(this.attribute.gifImage), frames = (0, gifuct_js_1.decompressFrames)(gif, !0);
21
- this.renderGIF(frames);
22
- }
23
- }
24
- renderGIF(frames) {
25
- this.loadedFrames = frames, this.frameIndex = 0, this.tempCanvas || (this.tempCanvas = vrender_core_1.application.global.createCanvas({}),
26
- this.tempCtx = this.tempCanvas.getContext("2d")), this.gifCanvas || (this.gifCanvas = vrender_core_1.application.global.createCanvas({}),
27
- this.gifCtx = this.gifCanvas.getContext("2d")), this.gifCanvas.width = frames[0].dims.width,
28
- this.gifCanvas.height = frames[0].dims.height, this.playing = !0, this.lastTime = (new Date).getTime();
29
- const animation = this.animate();
30
- this.attribute.timeline && animation.setTimeline(this.attribute.timeline), animation.to({}, 1e3, "linear").loop(1 / 0);
31
- }
32
- renderFrame(context, x, y) {
33
- const frame = this.loadedFrames[this.frameIndex || 0];
34
- 2 === frame.disposalType && this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height),
35
- this.drawPatch(frame), this.manipulate(context, x, y);
36
- const diff = (new Date).getTime() - this.lastTime;
37
- frame.delay < diff && (this.frameIndex++, this.lastTime = (new Date).getTime()),
38
- this.frameIndex >= this.loadedFrames.length && (this.frameIndex = 0);
39
- }
40
- drawPatch(frame) {
41
- const dims = frame.dims;
42
- this.frameImageData && dims.width === this.frameImageData.width && dims.height === this.frameImageData.height || (this.tempCanvas.width = dims.width,
43
- this.tempCanvas.height = dims.height, this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height)),
44
- this.frameImageData.data.set(frame.patch), this.tempCtx.putImageData(this.frameImageData, 0, 0),
45
- this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);
46
- }
47
- manipulate(context, x, y) {
48
- context.drawImage(this.gifCanvas, 0, 0, this.gifCanvas.width, this.gifCanvas.height, x, y, this.attribute.width, this.attribute.height);
49
- }
50
- setAttribute(key, value, forceUpdateTag, context) {
51
- super.setAttribute(key, value, forceUpdateTag, context), "gifImage" === key && this.loadGif();
52
- }
53
- setAttributes(params, forceUpdateTag, context) {
54
- super.setAttributes(params, forceUpdateTag, context), params.gifImage && this.loadGif();
55
- }
56
- }
57
-
58
- exports.GifImage = GifImage;
59
- //# sourceMappingURL=gif.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gif/gif.ts"],"names":[],"mappings":";;;AACA,yDAA4E;AAE5E,6CAA4C;AAE5C,yCAAuD;AAOvD,MAAa,QAAS,SAAQ,oBAAK;IAejC,YAAY,MAAiC;QAC3C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHhB,eAAU,GAAG,IAAI,CAAC;QAKhB,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,OAAO;QACL,IAAI,IAAA,iBAAQ,EAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;YACrC,6BAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC;iBAC3D,IAAI,CAAC,CAAC,GAAgB,EAAE,EAAE;gBACzB,MAAM,GAAG,GAAG,IAAA,oBA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,CAAC;IACJ,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,KAAU,EAAE,cAAwB,EAAE,OAA8B;QAC5F,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,GAAG,KAAK,UAAU,EAAE;YACtB,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;IAED,aAAa,CACX,MAA0C,EAC1C,cAAwB,EACxB,OAA8B;QAE9B,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;CACF;AA/ID,4BA+IC","file":"gif.js","sourcesContent":["import type { IImageGraphicAttribute, ISetAttributeContext } from '@visactor/vrender-core';\nimport { application, Image, ResourceLoader } from '@visactor/vrender-core';\nimport type { ITimeline } from '@visactor/vrender-core';\nimport { isString } from '@visactor/vutils';\nimport type { ParsedFrame } from 'gifuct-js';\nimport { decompressFrames, parseGIF } from 'gifuct-js';\n\nexport interface IGifImageGraphicAttribute extends IImageGraphicAttribute {\n timeline?: ITimeline;\n gifImage?: string | ArrayBuffer;\n}\n\nexport class GifImage extends Image {\n declare attribute: IGifImageGraphicAttribute;\n\n frameImageData?: ImageData;\n tempCanvas?: HTMLCanvasElement;\n tempCtx?: CanvasRenderingContext2D;\n gifCanvas?: HTMLCanvasElement;\n gifCtx?: CanvasRenderingContext2D;\n loadedFrames?: ParsedFrame[];\n frameIndex?: number;\n playing?: boolean;\n lastTime?: number;\n\n isGifImage = true;\n\n constructor(params: IGifImageGraphicAttribute) {\n super(params);\n\n this.loadGif();\n }\n\n loadGif() {\n if (isString(this.attribute.gifImage)) {\n ResourceLoader.GetFile(this.attribute.gifImage, 'arrayBuffer')\n .then((res: ArrayBuffer) => {\n const gif = parseGIF(res);\n const frames = decompressFrames(gif, true);\n this.renderGIF(frames);\n })\n .catch(e => {\n console.error('Gif load error: ', e);\n });\n } else if (this.attribute.gifImage instanceof ArrayBuffer) {\n const gif = parseGIF(this.attribute.gifImage);\n const frames = decompressFrames(gif, true);\n this.renderGIF(frames);\n }\n }\n\n renderGIF(frames: ParsedFrame[]) {\n this.loadedFrames = frames;\n this.frameIndex = 0;\n\n if (!this.tempCanvas) {\n this.tempCanvas = application.global.createCanvas({});\n this.tempCtx = this.tempCanvas.getContext('2d');\n }\n\n if (!this.gifCanvas) {\n this.gifCanvas = application.global.createCanvas({});\n this.gifCtx = this.gifCanvas.getContext('2d');\n }\n\n this.gifCanvas.width = frames[0].dims.width;\n this.gifCanvas.height = frames[0].dims.height;\n\n this.playing = true;\n this.lastTime = new Date().getTime();\n const animation = this.animate();\n if (this.attribute.timeline) {\n animation.setTimeline(this.attribute.timeline);\n }\n animation.to({}, 1000, 'linear').loop(Infinity);\n }\n\n renderFrame(context: CanvasRenderingContext2D, x: number, y: number) {\n // get the frame\n const frame = this.loadedFrames[this.frameIndex || 0];\n\n if (frame.disposalType === 2) {\n this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height);\n }\n\n // draw image into gifCanvas\n this.drawPatch(frame);\n\n // draw gifCanvas into stage\n this.manipulate(context, x, y);\n\n // update the frame index\n const diff = new Date().getTime() - this.lastTime;\n if (frame.delay < diff) {\n this.frameIndex++;\n this.lastTime = new Date().getTime();\n }\n if (this.frameIndex >= this.loadedFrames.length) {\n this.frameIndex = 0;\n }\n }\n\n drawPatch(frame: ParsedFrame) {\n const dims = frame.dims;\n\n if (\n !this.frameImageData ||\n dims.width !== this.frameImageData.width ||\n dims.height !== this.frameImageData.height\n ) {\n this.tempCanvas.width = dims.width;\n this.tempCanvas.height = dims.height;\n this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height);\n }\n\n // set the patch data as an override\n this.frameImageData.data.set(frame.patch);\n\n // draw the patch back over the canvas\n this.tempCtx.putImageData(this.frameImageData, 0, 0);\n\n this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);\n }\n\n manipulate(context: CanvasRenderingContext2D, x: number, y: number) {\n context.drawImage(\n this.gifCanvas,\n 0,\n 0,\n this.gifCanvas.width,\n this.gifCanvas.height,\n x,\n y,\n this.attribute.width,\n this.attribute.height\n );\n }\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void {\n super.setAttribute(key, value, forceUpdateTag, context);\n if (key === 'gifImage') {\n this.loadGif();\n }\n }\n\n setAttributes(\n params: Partial<IGifImageGraphicAttribute>,\n forceUpdateTag?: boolean,\n context?: ISetAttributeContext\n ): void {\n super.setAttributes(params, forceUpdateTag, context);\n if (params.gifImage) {\n this.loadGif();\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- export * from './gif';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gif/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB","file":"index.js","sourcesContent":["export * from './gif';\n"]}
package/es/gif/gif.d.ts DELETED
@@ -1,29 +0,0 @@
1
- import type { IImageGraphicAttribute, ISetAttributeContext } from '@visactor/vrender-core';
2
- import { Image } from '@visactor/vrender-core';
3
- import type { ITimeline } from '@visactor/vrender-core';
4
- import type { ParsedFrame } from 'gifuct-js';
5
- export interface IGifImageGraphicAttribute extends IImageGraphicAttribute {
6
- timeline?: ITimeline;
7
- gifImage?: string | ArrayBuffer;
8
- }
9
- export declare class GifImage extends Image {
10
- attribute: IGifImageGraphicAttribute;
11
- frameImageData?: ImageData;
12
- tempCanvas?: HTMLCanvasElement;
13
- tempCtx?: CanvasRenderingContext2D;
14
- gifCanvas?: HTMLCanvasElement;
15
- gifCtx?: CanvasRenderingContext2D;
16
- loadedFrames?: ParsedFrame[];
17
- frameIndex?: number;
18
- playing?: boolean;
19
- lastTime?: number;
20
- isGifImage: boolean;
21
- constructor(params: IGifImageGraphicAttribute);
22
- loadGif(): void;
23
- renderGIF(frames: ParsedFrame[]): void;
24
- renderFrame(context: CanvasRenderingContext2D, x: number, y: number): void;
25
- drawPatch(frame: ParsedFrame): void;
26
- manipulate(context: CanvasRenderingContext2D, x: number, y: number): void;
27
- setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
28
- setAttributes(params: Partial<IGifImageGraphicAttribute>, forceUpdateTag?: boolean, context?: ISetAttributeContext): void;
29
- }
package/es/gif/gif.js DELETED
@@ -1,55 +0,0 @@
1
- import { application, Image, ResourceLoader } from "@visactor/vrender-core";
2
-
3
- import { isString } from "@visactor/vutils";
4
-
5
- import { decompressFrames, parseGIF } from "gifuct-js";
6
-
7
- export class GifImage extends Image {
8
- constructor(params) {
9
- super(params), this.isGifImage = !0, this.loadGif();
10
- }
11
- loadGif() {
12
- if (isString(this.attribute.gifImage)) ResourceLoader.GetFile(this.attribute.gifImage, "arrayBuffer").then((res => {
13
- const gif = parseGIF(res), frames = decompressFrames(gif, !0);
14
- this.renderGIF(frames);
15
- })).catch((e => {
16
- console.error("Gif load error: ", e);
17
- })); else if (this.attribute.gifImage instanceof ArrayBuffer) {
18
- const gif = parseGIF(this.attribute.gifImage), frames = decompressFrames(gif, !0);
19
- this.renderGIF(frames);
20
- }
21
- }
22
- renderGIF(frames) {
23
- this.loadedFrames = frames, this.frameIndex = 0, this.tempCanvas || (this.tempCanvas = application.global.createCanvas({}),
24
- this.tempCtx = this.tempCanvas.getContext("2d")), this.gifCanvas || (this.gifCanvas = application.global.createCanvas({}),
25
- this.gifCtx = this.gifCanvas.getContext("2d")), this.gifCanvas.width = frames[0].dims.width,
26
- this.gifCanvas.height = frames[0].dims.height, this.playing = !0, this.lastTime = (new Date).getTime();
27
- const animation = this.animate();
28
- this.attribute.timeline && animation.setTimeline(this.attribute.timeline), animation.to({}, 1e3, "linear").loop(1 / 0);
29
- }
30
- renderFrame(context, x, y) {
31
- const frame = this.loadedFrames[this.frameIndex || 0];
32
- 2 === frame.disposalType && this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height),
33
- this.drawPatch(frame), this.manipulate(context, x, y);
34
- const diff = (new Date).getTime() - this.lastTime;
35
- frame.delay < diff && (this.frameIndex++, this.lastTime = (new Date).getTime()),
36
- this.frameIndex >= this.loadedFrames.length && (this.frameIndex = 0);
37
- }
38
- drawPatch(frame) {
39
- const dims = frame.dims;
40
- this.frameImageData && dims.width === this.frameImageData.width && dims.height === this.frameImageData.height || (this.tempCanvas.width = dims.width,
41
- this.tempCanvas.height = dims.height, this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height)),
42
- this.frameImageData.data.set(frame.patch), this.tempCtx.putImageData(this.frameImageData, 0, 0),
43
- this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);
44
- }
45
- manipulate(context, x, y) {
46
- context.drawImage(this.gifCanvas, 0, 0, this.gifCanvas.width, this.gifCanvas.height, x, y, this.attribute.width, this.attribute.height);
47
- }
48
- setAttribute(key, value, forceUpdateTag, context) {
49
- super.setAttribute(key, value, forceUpdateTag, context), "gifImage" === key && this.loadGif();
50
- }
51
- setAttributes(params, forceUpdateTag, context) {
52
- super.setAttributes(params, forceUpdateTag, context), params.gifImage && this.loadGif();
53
- }
54
- }
55
- //# sourceMappingURL=gif.js.map
package/es/gif/gif.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gif/gif.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE5E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAOvD,MAAM,OAAO,QAAS,SAAQ,KAAK;IAejC,YAAY,MAAiC;QAC3C,KAAK,CAAC,MAAM,CAAC,CAAC;QAHhB,eAAU,GAAG,IAAI,CAAC;QAKhB,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,OAAO;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,SAAS,EACd,CAAC,EACD,CAAC,EACD,IAAI,CAAC,SAAS,CAAC,KAAK,EACpB,IAAI,CAAC,SAAS,CAAC,MAAM,EACrB,CAAC,EACD,CAAC,EACD,IAAI,CAAC,SAAS,CAAC,KAAK,EACpB,IAAI,CAAC,SAAS,CAAC,MAAM,CACtB,CAAC;IACJ,CAAC;IAED,YAAY,CAAC,GAAW,EAAE,KAAU,EAAE,cAAwB,EAAE,OAA8B;QAC5F,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QACxD,IAAI,GAAG,KAAK,UAAU,EAAE;YACtB,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;IAED,aAAa,CACX,MAA0C,EAC1C,cAAwB,EACxB,OAA8B;QAE9B,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,MAAM,CAAC,QAAQ,EAAE;YACnB,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;CACF","file":"gif.js","sourcesContent":["import type { IImageGraphicAttribute, ISetAttributeContext } from '@visactor/vrender-core';\nimport { application, Image, ResourceLoader } from '@visactor/vrender-core';\nimport type { ITimeline } from '@visactor/vrender-core';\nimport { isString } from '@visactor/vutils';\nimport type { ParsedFrame } from 'gifuct-js';\nimport { decompressFrames, parseGIF } from 'gifuct-js';\n\nexport interface IGifImageGraphicAttribute extends IImageGraphicAttribute {\n timeline?: ITimeline;\n gifImage?: string | ArrayBuffer;\n}\n\nexport class GifImage extends Image {\n declare attribute: IGifImageGraphicAttribute;\n\n frameImageData?: ImageData;\n tempCanvas?: HTMLCanvasElement;\n tempCtx?: CanvasRenderingContext2D;\n gifCanvas?: HTMLCanvasElement;\n gifCtx?: CanvasRenderingContext2D;\n loadedFrames?: ParsedFrame[];\n frameIndex?: number;\n playing?: boolean;\n lastTime?: number;\n\n isGifImage = true;\n\n constructor(params: IGifImageGraphicAttribute) {\n super(params);\n\n this.loadGif();\n }\n\n loadGif() {\n if (isString(this.attribute.gifImage)) {\n ResourceLoader.GetFile(this.attribute.gifImage, 'arrayBuffer')\n .then((res: ArrayBuffer) => {\n const gif = parseGIF(res);\n const frames = decompressFrames(gif, true);\n this.renderGIF(frames);\n })\n .catch(e => {\n console.error('Gif load error: ', e);\n });\n } else if (this.attribute.gifImage instanceof ArrayBuffer) {\n const gif = parseGIF(this.attribute.gifImage);\n const frames = decompressFrames(gif, true);\n this.renderGIF(frames);\n }\n }\n\n renderGIF(frames: ParsedFrame[]) {\n this.loadedFrames = frames;\n this.frameIndex = 0;\n\n if (!this.tempCanvas) {\n this.tempCanvas = application.global.createCanvas({});\n this.tempCtx = this.tempCanvas.getContext('2d');\n }\n\n if (!this.gifCanvas) {\n this.gifCanvas = application.global.createCanvas({});\n this.gifCtx = this.gifCanvas.getContext('2d');\n }\n\n this.gifCanvas.width = frames[0].dims.width;\n this.gifCanvas.height = frames[0].dims.height;\n\n this.playing = true;\n this.lastTime = new Date().getTime();\n const animation = this.animate();\n if (this.attribute.timeline) {\n animation.setTimeline(this.attribute.timeline);\n }\n animation.to({}, 1000, 'linear').loop(Infinity);\n }\n\n renderFrame(context: CanvasRenderingContext2D, x: number, y: number) {\n // get the frame\n const frame = this.loadedFrames[this.frameIndex || 0];\n\n if (frame.disposalType === 2) {\n this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height);\n }\n\n // draw image into gifCanvas\n this.drawPatch(frame);\n\n // draw gifCanvas into stage\n this.manipulate(context, x, y);\n\n // update the frame index\n const diff = new Date().getTime() - this.lastTime;\n if (frame.delay < diff) {\n this.frameIndex++;\n this.lastTime = new Date().getTime();\n }\n if (this.frameIndex >= this.loadedFrames.length) {\n this.frameIndex = 0;\n }\n }\n\n drawPatch(frame: ParsedFrame) {\n const dims = frame.dims;\n\n if (\n !this.frameImageData ||\n dims.width !== this.frameImageData.width ||\n dims.height !== this.frameImageData.height\n ) {\n this.tempCanvas.width = dims.width;\n this.tempCanvas.height = dims.height;\n this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height);\n }\n\n // set the patch data as an override\n this.frameImageData.data.set(frame.patch);\n\n // draw the patch back over the canvas\n this.tempCtx.putImageData(this.frameImageData, 0, 0);\n\n this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);\n }\n\n manipulate(context: CanvasRenderingContext2D, x: number, y: number) {\n context.drawImage(\n this.gifCanvas,\n 0,\n 0,\n this.gifCanvas.width,\n this.gifCanvas.height,\n x,\n y,\n this.attribute.width,\n this.attribute.height\n );\n }\n\n setAttribute(key: string, value: any, forceUpdateTag?: boolean, context?: ISetAttributeContext): void {\n super.setAttribute(key, value, forceUpdateTag, context);\n if (key === 'gifImage') {\n this.loadGif();\n }\n }\n\n setAttributes(\n params: Partial<IGifImageGraphicAttribute>,\n forceUpdateTag?: boolean,\n context?: ISetAttributeContext\n ): void {\n super.setAttributes(params, forceUpdateTag, context);\n if (params.gifImage) {\n this.loadGif();\n }\n }\n}\n"]}
package/es/gif/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './gif';
package/es/gif/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./gif";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gif/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC","file":"index.js","sourcesContent":["export * from './gif';\n"]}