@visactor/vchart 2.0.4-alpha.7 → 2.0.4-alpha.8
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/build/es5/index.js +1 -1
- package/build/index.es.js +66 -1469
- package/build/index.js +66 -1469
- package/build/index.min.js +2 -2
- package/build/tsconfig.tsbuildinfo +1 -1
- package/cjs/chart/base/base-chart.js +1 -2
- package/cjs/chart/base/base-chart.js.map +1 -1
- package/cjs/chart/range-area/range-area-transformer.js +1 -2
- package/cjs/chart/range-area/range-area-transformer.js.map +1 -1
- package/cjs/compile/compiler.js +4 -6
- package/cjs/compile/compiler.js.map +1 -1
- package/cjs/component/base/base-component.js.map +1 -1
- package/cjs/component/custom-mark/custom-mark.js +2 -1
- package/cjs/component/custom-mark/custom-mark.js.map +1 -1
- package/cjs/component/data-zoom/data-filter-base-component.d.ts +0 -2
- package/cjs/component/data-zoom/data-filter-base-component.js +5 -15
- package/cjs/component/data-zoom/data-filter-base-component.js.map +1 -1
- package/cjs/component/data-zoom/interface.d.ts +0 -1
- package/cjs/component/data-zoom/interface.js.map +1 -1
- package/cjs/component/marker/mark-point/cartesian-mark-point.js +2 -2
- package/cjs/component/marker/mark-point/cartesian-mark-point.js.map +1 -1
- package/cjs/constant/event.d.ts +1 -2
- package/cjs/constant/event.js +1 -1
- package/cjs/constant/event.js.map +1 -1
- package/cjs/core/factory.d.ts +0 -4
- package/cjs/core/factory.js +2 -8
- package/cjs/core/factory.js.map +1 -1
- package/cjs/core/index.d.ts +1 -1
- package/cjs/core/index.js +1 -1
- package/cjs/core/index.js.map +1 -1
- package/cjs/core/interface.d.ts +0 -2
- package/cjs/core/interface.js.map +1 -1
- package/cjs/core/vchart.d.ts +1 -3
- package/cjs/core/vchart.js +1 -7
- package/cjs/core/vchart.js.map +1 -1
- package/cjs/event/event-dispatcher.d.ts +1 -0
- package/cjs/event/event-dispatcher.js +12 -1
- package/cjs/event/event-dispatcher.js.map +1 -1
- package/cjs/model/interface.d.ts +0 -1
- package/cjs/model/interface.js.map +1 -1
- package/cjs/plugin/components/tooltip-handler/dom-tooltip-handler.d.ts +1 -1
- package/cjs/plugin/components/tooltip-handler/dom-tooltip-handler.js +17 -17
- package/cjs/plugin/components/tooltip-handler/dom-tooltip-handler.js.map +1 -1
- package/cjs/series/treemap/treemap.js +2 -2
- package/cjs/series/treemap/treemap.js.map +1 -1
- package/cjs/series/word-cloud/base.js +1 -15
- package/cjs/series/word-cloud/base.js.map +1 -1
- package/cjs/typings/spec/common.d.ts +0 -1
- package/cjs/typings/spec/common.js.map +1 -1
- package/cjs/util/style.js +2 -3
- package/cjs/util/style.js.map +1 -1
- package/esm/chart/base/base-chart.js +1 -2
- package/esm/chart/base/base-chart.js.map +1 -1
- package/esm/chart/range-area/range-area-transformer.js +1 -2
- package/esm/chart/range-area/range-area-transformer.js.map +1 -1
- package/esm/compile/compiler.js +4 -6
- package/esm/compile/compiler.js.map +1 -1
- package/esm/component/base/base-component.js.map +1 -1
- package/esm/component/custom-mark/custom-mark.js +2 -1
- package/esm/component/custom-mark/custom-mark.js.map +1 -1
- package/esm/component/data-zoom/data-filter-base-component.d.ts +0 -2
- package/esm/component/data-zoom/data-filter-base-component.js +6 -16
- package/esm/component/data-zoom/data-filter-base-component.js.map +1 -1
- package/esm/component/data-zoom/interface.d.ts +0 -1
- package/esm/component/data-zoom/interface.js.map +1 -1
- package/esm/component/marker/mark-point/cartesian-mark-point.js +2 -2
- package/esm/component/marker/mark-point/cartesian-mark-point.js.map +1 -1
- package/esm/constant/event.d.ts +1 -2
- package/esm/constant/event.js +1 -1
- package/esm/constant/event.js.map +1 -1
- package/esm/core/factory.d.ts +0 -4
- package/esm/core/factory.js +1 -8
- package/esm/core/factory.js.map +1 -1
- package/esm/core/index.d.ts +1 -1
- package/esm/core/index.js +1 -1
- package/esm/core/index.js.map +1 -1
- package/esm/core/interface.d.ts +0 -2
- package/esm/core/interface.js.map +1 -1
- package/esm/core/vchart.d.ts +1 -3
- package/esm/core/vchart.js +0 -8
- package/esm/core/vchart.js.map +1 -1
- package/esm/event/event-dispatcher.d.ts +1 -0
- package/esm/event/event-dispatcher.js +12 -1
- package/esm/event/event-dispatcher.js.map +1 -1
- package/esm/model/interface.d.ts +0 -1
- package/esm/model/interface.js.map +1 -1
- package/esm/plugin/components/tooltip-handler/dom-tooltip-handler.d.ts +1 -1
- package/esm/plugin/components/tooltip-handler/dom-tooltip-handler.js +17 -17
- package/esm/plugin/components/tooltip-handler/dom-tooltip-handler.js.map +1 -1
- package/esm/series/treemap/treemap.js +2 -2
- package/esm/series/treemap/treemap.js.map +1 -1
- package/esm/series/word-cloud/base.js +0 -16
- package/esm/series/word-cloud/base.js.map +1 -1
- package/esm/typings/spec/common.d.ts +0 -1
- package/esm/typings/spec/common.js.map +1 -1
- package/esm/util/style.js +2 -3
- package/esm/util/style.js.map +1 -1
- package/package.json +8 -8
- package/cjs/plugin/vchart/index.d.ts +0 -2
- package/cjs/plugin/vchart/index.js +0 -21
- package/cjs/plugin/vchart/index.js.map +0 -1
- package/cjs/plugin/vchart/interface.d.ts +0 -16
- package/cjs/plugin/vchart/interface.js +0 -6
- package/cjs/plugin/vchart/interface.js.map +0 -1
- package/cjs/plugin/vchart/plugin-service.d.ts +0 -9
- package/cjs/plugin/vchart/plugin-service.js +0 -24
- package/cjs/plugin/vchart/plugin-service.js.map +0 -1
- package/cjs/plugin/vchart/register.d.ts +0 -2
- package/cjs/plugin/vchart/register.js +0 -12
- package/cjs/plugin/vchart/register.js.map +0 -1
- package/cjs/plugin/vchart/rotate/index.d.ts +0 -1
- package/cjs/plugin/vchart/rotate/index.js +0 -21
- package/cjs/plugin/vchart/rotate/index.js.map +0 -1
- package/cjs/plugin/vchart/rotate/rotate.d.ts +0 -18
- package/cjs/plugin/vchart/rotate/rotate.js +0 -67
- package/cjs/plugin/vchart/rotate/rotate.js.map +0 -1
- package/esm/plugin/vchart/index.d.ts +0 -2
- package/esm/plugin/vchart/index.js +0 -4
- package/esm/plugin/vchart/index.js.map +0 -1
- package/esm/plugin/vchart/interface.d.ts +0 -16
- package/esm/plugin/vchart/interface.js +0 -2
- package/esm/plugin/vchart/interface.js.map +0 -1
- package/esm/plugin/vchart/plugin-service.d.ts +0 -9
- package/esm/plugin/vchart/plugin-service.js +0 -16
- package/esm/plugin/vchart/plugin-service.js.map +0 -1
- package/esm/plugin/vchart/register.d.ts +0 -2
- package/esm/plugin/vchart/register.js +0 -6
- package/esm/plugin/vchart/register.js.map +0 -1
- package/esm/plugin/vchart/rotate/index.d.ts +0 -1
- package/esm/plugin/vchart/rotate/index.js +0 -2
- package/esm/plugin/vchart/rotate/index.js.map +0 -1
- package/esm/plugin/vchart/rotate/rotate.d.ts +0 -18
- package/esm/plugin/vchart/rotate/rotate.js +0 -62
- package/esm/plugin/vchart/rotate/rotate.js.map +0 -1
package/build/index.js
CHANGED
|
@@ -9737,34 +9737,6 @@
|
|
|
9737
9737
|
}
|
|
9738
9738
|
return c;
|
|
9739
9739
|
}
|
|
9740
|
-
static processColorStops(colorStops) {
|
|
9741
|
-
if (!colorStops || 0 === colorStops.length) return [];
|
|
9742
|
-
if (colorStops.some(item => item.length)) {
|
|
9743
|
-
const stops = colorStops.map(item => ({
|
|
9744
|
-
color: item.value,
|
|
9745
|
-
offset: item.length ? parseFloat(item.length.value) / 100 : -1
|
|
9746
|
-
}));
|
|
9747
|
-
stops[0].offset < 0 && (stops[0].offset = 0), stops[stops.length - 1].offset < 0 && (stops[stops.length - 1].offset = 1);
|
|
9748
|
-
for (let i = 1; i < stops.length - 1; i++) if (stops[i].offset < 0) {
|
|
9749
|
-
const prevWithOffsetIdx = i - 1;
|
|
9750
|
-
let nextWithOffsetIdx = i + 1;
|
|
9751
|
-
for (; nextWithOffsetIdx < stops.length && stops[nextWithOffsetIdx].offset < 0;) nextWithOffsetIdx++;
|
|
9752
|
-
const startOffset = stops[prevWithOffsetIdx].offset,
|
|
9753
|
-
endOffset = stops[nextWithOffsetIdx].offset,
|
|
9754
|
-
unspecCount = nextWithOffsetIdx - prevWithOffsetIdx;
|
|
9755
|
-
for (let j = 1; j < unspecCount; j++) stops[prevWithOffsetIdx + j].offset = startOffset + (endOffset - startOffset) * j / unspecCount;
|
|
9756
|
-
i = nextWithOffsetIdx - 1;
|
|
9757
|
-
}
|
|
9758
|
-
return stops;
|
|
9759
|
-
}
|
|
9760
|
-
return colorStops.map((item, index) => {
|
|
9761
|
-
const offset = colorStops.length > 1 ? index / (colorStops.length - 1) : 0;
|
|
9762
|
-
return {
|
|
9763
|
-
color: item.value,
|
|
9764
|
-
offset: offset
|
|
9765
|
-
};
|
|
9766
|
-
});
|
|
9767
|
-
}
|
|
9768
9740
|
static ParseConic(datum) {
|
|
9769
9741
|
const {
|
|
9770
9742
|
orientation: orientation,
|
|
@@ -9778,7 +9750,10 @@
|
|
|
9778
9750
|
y: .5,
|
|
9779
9751
|
startAngle: sa,
|
|
9780
9752
|
endAngle: sa + pi2,
|
|
9781
|
-
stops:
|
|
9753
|
+
stops: colorStops.map(item => ({
|
|
9754
|
+
color: item.value,
|
|
9755
|
+
offset: parseFloat(item.length.value) / 100
|
|
9756
|
+
}))
|
|
9782
9757
|
};
|
|
9783
9758
|
}
|
|
9784
9759
|
static ParseRadial(datum) {
|
|
@@ -9793,7 +9768,10 @@
|
|
|
9793
9768
|
y1: .5,
|
|
9794
9769
|
r0: 0,
|
|
9795
9770
|
r1: 1,
|
|
9796
|
-
stops:
|
|
9771
|
+
stops: colorStops.map(item => ({
|
|
9772
|
+
color: item.value,
|
|
9773
|
+
offset: parseFloat(item.length.value) / 100
|
|
9774
|
+
}))
|
|
9797
9775
|
};
|
|
9798
9776
|
}
|
|
9799
9777
|
static ParseLinear(datum) {
|
|
@@ -9815,7 +9793,10 @@
|
|
|
9815
9793
|
y0: y0,
|
|
9816
9794
|
x1: x1,
|
|
9817
9795
|
y1: y1,
|
|
9818
|
-
stops:
|
|
9796
|
+
stops: colorStops.map(item => ({
|
|
9797
|
+
color: item.value,
|
|
9798
|
+
offset: parseFloat(item.length.value) / 100
|
|
9799
|
+
}))
|
|
9819
9800
|
};
|
|
9820
9801
|
}
|
|
9821
9802
|
}
|
|
@@ -17160,7 +17141,7 @@
|
|
|
17160
17141
|
case "right":
|
|
17161
17142
|
deltaX = -aabbBounds.width();
|
|
17162
17143
|
}
|
|
17163
|
-
return
|
|
17144
|
+
return aabbBounds.translate(deltaX, deltaY), application.graphicService.updateTempAABBBounds(aabbBounds), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, richtextTheme, aabbBounds), this.widthWithoutTransform = aabbBounds.x2 - aabbBounds.x1, this.heightWithoutTransform = aabbBounds.y2 - aabbBounds.y1, application.graphicService.transformAABBBounds(attribute, aabbBounds, richtextTheme, !1, this), 0 === aabbBounds.width() && 0 === aabbBounds.height() && aabbBounds.clear(), aabbBounds;
|
|
17164
17145
|
}
|
|
17165
17146
|
needUpdateTags(keys) {
|
|
17166
17147
|
return super.needUpdateTags(keys, RICHTEXT_UPDATE_TAG_KEY);
|
|
@@ -31751,6 +31732,8 @@
|
|
|
31751
31732
|
}
|
|
31752
31733
|
onStart() {
|
|
31753
31734
|
super.onStart();
|
|
31735
|
+
}
|
|
31736
|
+
onFirstRun() {
|
|
31754
31737
|
const fromProps = this.getFromProps();
|
|
31755
31738
|
this.target.setAttributes(fromProps);
|
|
31756
31739
|
}
|
|
@@ -32831,45 +32814,6 @@
|
|
|
32831
32814
|
this._animator && this._animator.stop();
|
|
32832
32815
|
}
|
|
32833
32816
|
}
|
|
32834
|
-
class AStageAnimate extends ACustomAnimate {
|
|
32835
|
-
constructor(customFrom, customTo, duration, easing, params) {
|
|
32836
|
-
super(customFrom, customTo, duration, easing, params), this.willCallBeforeStageRender = !0, this.willCallAfterStageRender = !0, this._beforeStageRender = () => {
|
|
32837
|
-
if (!this.willCallBeforeStageRender) return;
|
|
32838
|
-
this.willCallBeforeStageRender = !1;
|
|
32839
|
-
const stage = this.target.stage,
|
|
32840
|
-
canvas = stage.window.getContext().canvas.nativeCanvas,
|
|
32841
|
-
outputCanvas = this.beforeStageRender(stage, canvas);
|
|
32842
|
-
outputCanvas && this.renderToStage(stage, outputCanvas);
|
|
32843
|
-
}, this._afterStageRender = () => {
|
|
32844
|
-
if (!this.willCallAfterStageRender) return;
|
|
32845
|
-
this.willCallAfterStageRender = !1;
|
|
32846
|
-
const stage = this.target.stage,
|
|
32847
|
-
canvas = stage.window.getContext().canvas.nativeCanvas,
|
|
32848
|
-
outputCanvas = this.afterStageRender(stage, canvas);
|
|
32849
|
-
outputCanvas && this.renderToStage(stage, outputCanvas);
|
|
32850
|
-
}, this.props = {};
|
|
32851
|
-
}
|
|
32852
|
-
beforeStageRender(stage, canvas) {
|
|
32853
|
-
return !1;
|
|
32854
|
-
}
|
|
32855
|
-
afterStageRender(stage, canvas) {
|
|
32856
|
-
return !1;
|
|
32857
|
-
}
|
|
32858
|
-
onFirstRun() {
|
|
32859
|
-
super.onFirstRun(), this.target.stage.setBeforeRender(this._beforeStageRender), this.target.stage.setAfterRender(this._afterStageRender), this.target.stage.disableDirtyBounds();
|
|
32860
|
-
}
|
|
32861
|
-
stop() {
|
|
32862
|
-
super.stop(), this.target.stage.removeBeforeRender(this._beforeStageRender), this.target.stage.removeAfterRender(this._afterStageRender);
|
|
32863
|
-
}
|
|
32864
|
-
onUpdate(end, ratio, out) {
|
|
32865
|
-
super.onUpdate(end, ratio, out), this.willCallBeforeStageRender = !0, this.willCallAfterStageRender = !0;
|
|
32866
|
-
}
|
|
32867
|
-
renderToStage(stage, canvas) {
|
|
32868
|
-
const stageCanvas = stage.window.getContext().canvas.nativeCanvas,
|
|
32869
|
-
ctx = stageCanvas.getContext("2d");
|
|
32870
|
-
return !!ctx && (ctx.clearRect(0, 0, stageCanvas.width, stageCanvas.height), ctx.drawImage(canvas, 0, 0), stageCanvas);
|
|
32871
|
-
}
|
|
32872
|
-
}
|
|
32873
32817
|
|
|
32874
32818
|
class ComponentAnimator {
|
|
32875
32819
|
constructor(component) {
|
|
@@ -36305,1277 +36249,8 @@
|
|
|
36305
36249
|
}
|
|
36306
36250
|
}
|
|
36307
36251
|
|
|
36308
|
-
class DisappearAnimateBase extends AStageAnimate {
|
|
36309
|
-
constructor(from, to, duration, easing, params) {
|
|
36310
|
-
super(from, to, duration, easing, params), this.webglCanvas = null, this.gl = null, this.program = null, this.currentAnimationRatio = 0, this.animationTime = 0;
|
|
36311
|
-
}
|
|
36312
|
-
onUpdate(end, ratio, out) {
|
|
36313
|
-
super.onUpdate(end, ratio, out), this.currentAnimationRatio = ratio, this.animationTime = ratio * Math.PI * 2;
|
|
36314
|
-
}
|
|
36315
|
-
getAnimationTime() {
|
|
36316
|
-
return this.currentAnimationRatio > 0 ? this.animationTime : Date.now() / 1e3;
|
|
36317
|
-
}
|
|
36318
|
-
getDurationFromParent() {
|
|
36319
|
-
return this.duration || 1e3;
|
|
36320
|
-
}
|
|
36321
|
-
initWebGL(canvas) {
|
|
36322
|
-
try {
|
|
36323
|
-
if (this.webglCanvas = vglobal.createCanvas({
|
|
36324
|
-
width: canvas.width,
|
|
36325
|
-
height: canvas.height,
|
|
36326
|
-
dpr: vglobal.devicePixelRatio
|
|
36327
|
-
}), !this.webglCanvas) return console.warn("WebGL canvas creation failed"), !1;
|
|
36328
|
-
this.webglCanvas.style.width = canvas.style.width || `${canvas.width}px`, this.webglCanvas.style.height = canvas.style.height || `${canvas.height}px`;
|
|
36329
|
-
let glContext = null;
|
|
36330
|
-
try {
|
|
36331
|
-
glContext = this.webglCanvas.getContext("webgl"), glContext || (glContext = this.webglCanvas.getContext("experimental-webgl"));
|
|
36332
|
-
} catch (e) {
|
|
36333
|
-
console.warn("Failed to get WebGL context:", e);
|
|
36334
|
-
}
|
|
36335
|
-
if (this.gl = glContext, !this.gl) return console.warn("WebGL not supported"), !1;
|
|
36336
|
-
const shaders = this.getShaderSources();
|
|
36337
|
-
return this.program = this.createShaderProgram(shaders.vertex, shaders.fragment), null !== this.program;
|
|
36338
|
-
} catch (error) {
|
|
36339
|
-
return console.warn("Failed to initialize WebGL:", error), !1;
|
|
36340
|
-
}
|
|
36341
|
-
}
|
|
36342
|
-
createShaderProgram(vertexSource, fragmentSource) {
|
|
36343
|
-
if (!this.gl) return null;
|
|
36344
|
-
const vertexShader = this.createShader(this.gl.VERTEX_SHADER, vertexSource),
|
|
36345
|
-
fragmentShader = this.createShader(this.gl.FRAGMENT_SHADER, fragmentSource);
|
|
36346
|
-
if (!vertexShader || !fragmentShader) return null;
|
|
36347
|
-
const program = this.gl.createProgram();
|
|
36348
|
-
return program ? (this.gl.attachShader(program, vertexShader), this.gl.attachShader(program, fragmentShader), this.gl.linkProgram(program), this.gl.getProgramParameter(program, this.gl.LINK_STATUS) ? program : (console.error("Shader program link error:", this.gl.getProgramInfoLog(program)), null)) : null;
|
|
36349
|
-
}
|
|
36350
|
-
createShader(type, source) {
|
|
36351
|
-
if (!this.gl) return null;
|
|
36352
|
-
const shader = this.gl.createShader(type);
|
|
36353
|
-
return shader ? (this.gl.shaderSource(shader, source), this.gl.compileShader(shader), this.gl.getShaderParameter(shader, this.gl.COMPILE_STATUS) ? shader : (console.error("Shader compile error:", this.gl.getShaderInfoLog(shader)), this.gl.deleteShader(shader), null)) : null;
|
|
36354
|
-
}
|
|
36355
|
-
setupWebGLState(canvas) {
|
|
36356
|
-
this.gl && this.webglCanvas && (this.webglCanvas.width === canvas.width && this.webglCanvas.height === canvas.height || (this.webglCanvas.width = canvas.width, this.webglCanvas.height = canvas.height), this.gl.viewport(0, 0, this.webglCanvas.width, this.webglCanvas.height), this.gl.clearColor(0, 0, 0, 0), this.gl.clear(this.gl.COLOR_BUFFER_BIT));
|
|
36357
|
-
}
|
|
36358
|
-
createFullScreenQuad() {
|
|
36359
|
-
if (!this.gl) return null;
|
|
36360
|
-
const vertices = new Float32Array([-1, -1, 0, 1, 1, -1, 1, 1, -1, 1, 0, 0, 1, 1, 1, 0]),
|
|
36361
|
-
vertexBuffer = this.gl.createBuffer();
|
|
36362
|
-
return this.gl.bindBuffer(this.gl.ARRAY_BUFFER, vertexBuffer), this.gl.bufferData(this.gl.ARRAY_BUFFER, vertices, this.gl.STATIC_DRAW), vertexBuffer;
|
|
36363
|
-
}
|
|
36364
|
-
createTextureFromCanvas(canvas) {
|
|
36365
|
-
if (!this.gl) return null;
|
|
36366
|
-
const texture = this.gl.createTexture();
|
|
36367
|
-
return this.gl.activeTexture(this.gl.TEXTURE0), this.gl.bindTexture(this.gl.TEXTURE_2D, texture), this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.gl.RGBA, this.gl.UNSIGNED_BYTE, canvas), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR), texture;
|
|
36368
|
-
}
|
|
36369
|
-
setupVertexAttributes() {
|
|
36370
|
-
if (!this.gl || !this.program) return;
|
|
36371
|
-
const positionLocation = this.gl.getAttribLocation(this.program, "a_position"),
|
|
36372
|
-
texCoordLocation = this.gl.getAttribLocation(this.program, "a_texCoord");
|
|
36373
|
-
this.gl.enableVertexAttribArray(positionLocation), this.gl.vertexAttribPointer(positionLocation, 2, this.gl.FLOAT, !1, 16, 0), this.gl.enableVertexAttribArray(texCoordLocation), this.gl.vertexAttribPointer(texCoordLocation, 2, this.gl.FLOAT, !1, 16, 8);
|
|
36374
|
-
}
|
|
36375
|
-
createOutputCanvas(canvas) {
|
|
36376
|
-
const outputCanvas = vglobal.createCanvas({
|
|
36377
|
-
width: canvas.width,
|
|
36378
|
-
height: canvas.height,
|
|
36379
|
-
dpr: vglobal.devicePixelRatio
|
|
36380
|
-
}),
|
|
36381
|
-
ctx = outputCanvas.getContext("2d");
|
|
36382
|
-
return ctx ? (ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.drawImage(canvas, 0, 0), {
|
|
36383
|
-
canvas: outputCanvas,
|
|
36384
|
-
ctx: ctx
|
|
36385
|
-
}) : null;
|
|
36386
|
-
}
|
|
36387
|
-
getShaderSources() {
|
|
36388
|
-
return null;
|
|
36389
|
-
}
|
|
36390
|
-
applyWebGLEffect(canvas) {
|
|
36391
|
-
return null;
|
|
36392
|
-
}
|
|
36393
|
-
applyCanvas2DEffect(canvas) {
|
|
36394
|
-
return null;
|
|
36395
|
-
}
|
|
36396
|
-
supportsWebGL() {
|
|
36397
|
-
return null !== this.getShaderSources();
|
|
36398
|
-
}
|
|
36399
|
-
supportsCanvas2D() {
|
|
36400
|
-
return this.applyCanvas2DEffect !== DisappearAnimateBase.prototype.applyCanvas2DEffect;
|
|
36401
|
-
}
|
|
36402
|
-
release() {
|
|
36403
|
-
super.release(), this.gl && (this.program && (this.gl.deleteProgram(this.program), this.program = null), this.gl = null), this.webglCanvas && (this.webglCanvas = null), this.currentAnimationRatio = 0, this.animationTime = 0;
|
|
36404
|
-
}
|
|
36405
|
-
afterStageRender(stage, canvas) {
|
|
36406
|
-
let result = null;
|
|
36407
|
-
if (this.supportsWebGL() && (this.gl || this.initWebGL(canvas) || console.warn("WebGL初始化失败,尝试Canvas 2D回退"), this.gl)) {
|
|
36408
|
-
if (result = this.applyWebGLEffect(canvas), result) return result;
|
|
36409
|
-
console.warn("WebGL特效执行失败,尝试Canvas 2D回退");
|
|
36410
|
-
}
|
|
36411
|
-
if (this.supportsCanvas2D()) {
|
|
36412
|
-
if (result = this.applyCanvas2DEffect(canvas), result) return result;
|
|
36413
|
-
console.warn("Canvas 2D特效执行失败");
|
|
36414
|
-
}
|
|
36415
|
-
return this.supportsWebGL() || this.supportsCanvas2D() || console.error(`特效类 ${this.constructor.name} 未实现任何渲染方法。请实现 applyWebGLEffect 或 applyCanvas2DEffect 方法。`), canvas;
|
|
36416
|
-
}
|
|
36417
|
-
}
|
|
36418
|
-
|
|
36419
|
-
class Canvas2DEffectBase extends DisappearAnimateBase {
|
|
36420
|
-
constructor(from, to, duration, easing, params) {
|
|
36421
|
-
super(from, to, duration, easing, params);
|
|
36422
|
-
}
|
|
36423
|
-
getShaderSources() {
|
|
36424
|
-
return null;
|
|
36425
|
-
}
|
|
36426
|
-
applyWebGLEffect(canvas) {
|
|
36427
|
-
return null;
|
|
36428
|
-
}
|
|
36429
|
-
}
|
|
36430
|
-
class HybridEffectBase extends DisappearAnimateBase {
|
|
36431
|
-
constructor(from, to, duration, easing, params) {
|
|
36432
|
-
super(from, to, duration, easing, params);
|
|
36433
|
-
}
|
|
36434
|
-
getShaderSources() {
|
|
36435
|
-
return null;
|
|
36436
|
-
}
|
|
36437
|
-
applyWebGLEffect(canvas) {
|
|
36438
|
-
return null;
|
|
36439
|
-
}
|
|
36440
|
-
applyCanvas2DEffect(canvas) {
|
|
36441
|
-
return null;
|
|
36442
|
-
}
|
|
36443
|
-
supportsWebGL() {
|
|
36444
|
-
return this.getShaderSources !== HybridEffectBase.prototype.getShaderSources && null !== this.getShaderSources();
|
|
36445
|
-
}
|
|
36446
|
-
supportsCanvas2D() {
|
|
36447
|
-
return this.applyCanvas2DEffect !== HybridEffectBase.prototype.applyCanvas2DEffect;
|
|
36448
|
-
}
|
|
36449
|
-
afterStageRender(stage, canvas) {
|
|
36450
|
-
var _a, _b;
|
|
36451
|
-
let result = null;
|
|
36452
|
-
if (!1 !== (null === (_b = null === (_a = this.params) || void 0 === _a ? void 0 : _a.options) || void 0 === _b ? void 0 : _b.useWebGL)) {
|
|
36453
|
-
if (this.supportsWebGL() && (this.gl || this.initWebGL(canvas) || console.warn("WebGL初始化失败,尝试Canvas 2D回退"), this.gl)) {
|
|
36454
|
-
if (result = this.applyWebGLEffect(canvas), result) return result;
|
|
36455
|
-
console.warn("WebGL特效执行失败,尝试Canvas 2D回退");
|
|
36456
|
-
}
|
|
36457
|
-
if (this.supportsCanvas2D()) {
|
|
36458
|
-
if (result = this.applyCanvas2DEffect(canvas), result) return result;
|
|
36459
|
-
console.warn("Canvas 2D特效执行失败");
|
|
36460
|
-
}
|
|
36461
|
-
} else if (this.supportsCanvas2D()) {
|
|
36462
|
-
if (result = this.applyCanvas2DEffect(canvas), result) return result;
|
|
36463
|
-
console.warn("Canvas 2D特效执行失败");
|
|
36464
|
-
} else console.warn(`${this.constructor.name}: useWebGL=false 但未实现Canvas 2D方法`);
|
|
36465
|
-
return this.supportsWebGL() || this.supportsCanvas2D() || console.error(`特效类 ${this.constructor.name} 未实现任何渲染方法。请实现 applyWebGLEffect 或 applyCanvas2DEffect 方法。`), canvas;
|
|
36466
|
-
}
|
|
36467
|
-
}
|
|
36468
|
-
|
|
36469
|
-
class ImageProcessUtils {
|
|
36470
|
-
static createTempCanvas(width, height, dpr) {
|
|
36471
|
-
return vglobal.createCanvas({
|
|
36472
|
-
width: width,
|
|
36473
|
-
height: height,
|
|
36474
|
-
dpr: dpr || vglobal.devicePixelRatio
|
|
36475
|
-
});
|
|
36476
|
-
}
|
|
36477
|
-
static cloneImageData(imageData) {
|
|
36478
|
-
const clonedData = new Uint8ClampedArray(imageData.data);
|
|
36479
|
-
return new ImageData(clonedData, imageData.width, imageData.height);
|
|
36480
|
-
}
|
|
36481
|
-
static lerp(start, end, t) {
|
|
36482
|
-
return start * (1 - t) + end * t;
|
|
36483
|
-
}
|
|
36484
|
-
static smoothstep(edge0, edge1, x) {
|
|
36485
|
-
const t = Math.max(0, Math.min(1, (x - edge0) / (edge1 - edge0)));
|
|
36486
|
-
return t * t * (3 - 2 * t);
|
|
36487
|
-
}
|
|
36488
|
-
static distance(x1, y1, x2, y2) {
|
|
36489
|
-
const dx = x2 - x1,
|
|
36490
|
-
dy = y2 - y1;
|
|
36491
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
36492
|
-
}
|
|
36493
|
-
static normalizeAngle(angle) {
|
|
36494
|
-
return (angle + Math.PI) / (2 * Math.PI);
|
|
36495
|
-
}
|
|
36496
|
-
static pixelNoise(x, y, pixelSize) {
|
|
36497
|
-
if (pixelSize <= 0) return 0;
|
|
36498
|
-
const gridX = Math.floor(x / pixelSize) * pixelSize,
|
|
36499
|
-
gridY = Math.floor(y / pixelSize) * pixelSize,
|
|
36500
|
-
n = 43758.5453 * Math.sin(12.9898 * gridX + 78.233 * gridY);
|
|
36501
|
-
return n - Math.floor(n);
|
|
36502
|
-
}
|
|
36503
|
-
static generateNoiseTexture(width, height) {
|
|
36504
|
-
const data = new Uint8Array(width * height);
|
|
36505
|
-
for (let i = 0; i < data.length; i++) data[i] = Math.floor(256 * Math.random());
|
|
36506
|
-
return data;
|
|
36507
|
-
}
|
|
36508
|
-
static applyCSSFilter(canvas, filter) {
|
|
36509
|
-
const outputCanvas = this.createTempCanvas(canvas.width, canvas.height),
|
|
36510
|
-
ctx = outputCanvas.getContext("2d");
|
|
36511
|
-
return ctx ? (ctx.filter = filter, ctx.drawImage(canvas, 0, 0), ctx.filter = "none", outputCanvas) : canvas;
|
|
36512
|
-
}
|
|
36513
|
-
static extractChannel(imageData, channelIndex) {
|
|
36514
|
-
const {
|
|
36515
|
-
data: data,
|
|
36516
|
-
width: width,
|
|
36517
|
-
height: height
|
|
36518
|
-
} = imageData,
|
|
36519
|
-
channelData = new Uint8ClampedArray(data.length);
|
|
36520
|
-
for (let i = 0; i < data.length; i += 4) channelData[i] = 0, channelData[i + 1] = 0, channelData[i + 2] = 0, channelData[i + 3] = data[i + 3], channelIndex >= 0 && channelIndex <= 2 && (channelData[i + channelIndex] = data[i + channelIndex]);
|
|
36521
|
-
return new ImageData(channelData, width, height);
|
|
36522
|
-
}
|
|
36523
|
-
static blendImageData(imageData1, imageData2, ratio) {
|
|
36524
|
-
const {
|
|
36525
|
-
data: data1,
|
|
36526
|
-
width: width,
|
|
36527
|
-
height: height
|
|
36528
|
-
} = imageData1,
|
|
36529
|
-
{
|
|
36530
|
-
data: data2
|
|
36531
|
-
} = imageData2,
|
|
36532
|
-
result = new Uint8ClampedArray(data1.length);
|
|
36533
|
-
for (let i = 0; i < data1.length; i += 4) result[i] = Math.round(this.lerp(data1[i], data2[i], ratio)), result[i + 1] = Math.round(this.lerp(data1[i + 1], data2[i + 1], ratio)), result[i + 2] = Math.round(this.lerp(data1[i + 2], data2[i + 2], ratio)), result[i + 3] = Math.round(this.lerp(data1[i + 3], data2[i + 3], ratio));
|
|
36534
|
-
return new ImageData(result, width, height);
|
|
36535
|
-
}
|
|
36536
|
-
static getLuminance(r, g, b) {
|
|
36537
|
-
return .299 * r + .587 * g + .114 * b;
|
|
36538
|
-
}
|
|
36539
|
-
static applySepiaToPixel(r, g, b) {
|
|
36540
|
-
return [Math.min(255, .393 * r + .769 * g + .189 * b), Math.min(255, .349 * r + .686 * g + .168 * b), Math.min(255, .272 * r + .534 * g + .131 * b)];
|
|
36541
|
-
}
|
|
36542
|
-
static calculateDynamicStrength(baseStrength, animationTime) {
|
|
36543
|
-
return baseStrength * (animationTime / (2 * Math.PI));
|
|
36544
|
-
}
|
|
36545
|
-
}
|
|
36546
|
-
class ShaderLibrary {}
|
|
36547
|
-
ShaderLibrary.STANDARD_VERTEX_SHADER = "\n attribute vec2 a_position;\n attribute vec2 a_texCoord;\n varying vec2 v_texCoord;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_texCoord;\n }\n ", ShaderLibrary.SHADER_FUNCTIONS = "\n // 亮度计算函数\n float luminance(vec3 color) {\n return dot(color, vec3(0.299, 0.587, 0.114));\n }\n\n // 褐色调函数\n vec3 sepia(vec3 color) {\n float r = color.r * 0.393 + color.g * 0.769 + color.b * 0.189;\n float g = color.r * 0.349 + color.g * 0.686 + color.b * 0.168;\n float b = color.r * 0.272 + color.g * 0.534 + color.b * 0.131;\n return vec3(r, g, b);\n }\n\n // 线性插值函数\n float lerp(float a, float b, float t) {\n return a * (1.0 - t) + b * t;\n }\n\n\n // 简单噪声函数\n float pixelNoise(vec2 coord, float pixelSize) {\n vec2 gridCoord = floor(coord / pixelSize) * pixelSize;\n return fract(sin(dot(gridCoord, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n\n // 动态强度计算\n float calculateDynamicStrength(float baseStrength, float time) {\n return baseStrength * (time / 6.28318531); // 2π\n }\n ";
|
|
36548
|
-
|
|
36549
|
-
class Dissolve extends HybridEffectBase {
|
|
36550
|
-
constructor(from, to, duration, easing, params) {
|
|
36551
|
-
var _a, _b, _c, _d;
|
|
36552
|
-
super(from, to, duration, easing, params), this.noiseData = null;
|
|
36553
|
-
const rawNoiseScale = null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.noiseScale,
|
|
36554
|
-
clampedNoiseScale = void 0 !== rawNoiseScale ? Math.max(0, Math.floor(rawNoiseScale)) : 8;
|
|
36555
|
-
this.dissolveConfig = {
|
|
36556
|
-
dissolveType: (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.dissolveType) || "outward",
|
|
36557
|
-
useWebGL: void 0 === (null === (_c = null == params ? void 0 : params.options) || void 0 === _c ? void 0 : _c.useWebGL) || params.options.useWebGL,
|
|
36558
|
-
noiseScale: clampedNoiseScale,
|
|
36559
|
-
fadeEdge: void 0 === (null === (_d = null == params ? void 0 : params.options) || void 0 === _d ? void 0 : _d.fadeEdge) || params.options.fadeEdge
|
|
36560
|
-
};
|
|
36561
|
-
}
|
|
36562
|
-
getShaderSources() {
|
|
36563
|
-
return {
|
|
36564
|
-
vertex: ShaderLibrary.STANDARD_VERTEX_SHADER,
|
|
36565
|
-
fragment: `\n precision mediump float;\n uniform sampler2D u_texture;\n uniform sampler2D u_noiseTexture;\n uniform float u_time;\n uniform int u_dissolveType;\n uniform vec2 u_resolution;\n uniform float u_noiseScale;\n uniform bool u_fadeEdge;\n varying vec2 v_texCoord;\n\n ${ShaderLibrary.SHADER_FUNCTIONS}\n\n // 向外溶解函数\n float outwardDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n vec2 center = vec2(0.5, 0.5);\n float distFromCenter = length(uv - center);\n float maxDist = length(vec2(0.5, 0.5));\n\n // 归一化距离 (0为中心,1为边缘)\n float normalizedDist = distFromCenter / maxDist;\n\n // 向外溶解:从边缘开始溶解,time控制溶解进度\n // 增加安全边距,确保动画结束时完全溶解\n float edgeThreshold = 1.2 - time * 1.5;\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n // 添加基于像素大小的噪声,让边缘呈现颗粒状\n vec2 pixelCoord = uv * resolution; // 转换为像素坐标\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.4; // 增强噪声影响\n edgeThreshold += noiseInfluence;\n return normalizedDist > edgeThreshold ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.15; // 渐变宽度\n return 1.0 - smoothstep(edgeThreshold - fadeWidth, edgeThreshold, normalizedDist);\n } else {\n // 硬边缘:返回0或1\n return normalizedDist > edgeThreshold ? 0.0 : 1.0;\n }\n }\n }\n\n // 向内溶解函数\n float inwardDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n vec2 center = vec2(0.5, 0.5);\n float distFromCenter = length(uv - center);\n float maxDist = length(vec2(0.5, 0.5));\n\n float normalizedDist = distFromCenter / maxDist;\n\n // 向内溶解:从中心开始溶解,time控制溶解进度\n // 增加系数,确保动画结束时完全溶解\n float centerThreshold = time * 1.4;\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n vec2 pixelCoord = uv * resolution;\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.4;\n centerThreshold += noiseInfluence;\n return normalizedDist < centerThreshold ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.15; // 渐变宽度\n return smoothstep(centerThreshold, centerThreshold + fadeWidth, normalizedDist);\n } else {\n // 硬边缘:返回0或1\n return normalizedDist < centerThreshold ? 0.0 : 1.0;\n }\n }\n }\n\n // 径向溶解函数\n float radialDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n vec2 center = vec2(0.5, 0.5);\n float angle = atan(uv.y - center.y, uv.x - center.x);\n float normalizedAngle = (angle + 3.14159) / (2.0 * 3.14159);\n\n // 径向溶解:按角度顺序溶解,time控制溶解进度\n // 增加系数,确保动画结束时完全溶解\n float angleThreshold = time * 1.2;\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n vec2 pixelCoord = uv * resolution;\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.3;\n angleThreshold += noiseInfluence;\n return normalizedAngle < angleThreshold ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.08; // 渐变宽度\n return smoothstep(angleThreshold, angleThreshold + fadeWidth, normalizedAngle);\n } else {\n // 硬边缘:返回0或1\n return normalizedAngle < angleThreshold ? 0.0 : 1.0;\n }\n }\n }\n\n // 从左到右溶解函数\n float leftToRightDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n // 左到右溶解:从x=0开始向x=1溶解\n float dissolvePosition = time * 1.2; // 增加系数确保完全溶解\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n vec2 pixelCoord = uv * resolution;\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.3;\n dissolvePosition += noiseInfluence;\n return uv.x < dissolvePosition ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.08; // 渐变宽度\n return smoothstep(dissolvePosition, dissolvePosition + fadeWidth, uv.x);\n } else {\n // 硬边缘:返回0或1\n return uv.x < dissolvePosition ? 0.0 : 1.0;\n }\n }\n }\n\n // 从右到左溶解函数\n float rightToLeftDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n // 右到左溶解:从x=1开始向x=0溶解\n float dissolvePosition = 1.0 - time * 1.2; // 增加系数确保完全溶解\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n vec2 pixelCoord = uv * resolution;\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.3;\n dissolvePosition += noiseInfluence;\n return uv.x > dissolvePosition ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.08; // 渐变宽度\n return smoothstep(dissolvePosition - fadeWidth, dissolvePosition, uv.x);\n } else {\n // 硬边缘:返回0或1\n return uv.x > dissolvePosition ? 0.0 : 1.0;\n }\n }\n }\n\n // 从上到下溶解函数\n float topToBottomDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n // 上到下溶解:从y=0开始向y=1溶解\n float dissolvePosition = time * 1.2; // 增加系数确保完全溶解\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n vec2 pixelCoord = uv * resolution;\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.3;\n dissolvePosition += noiseInfluence;\n return uv.y < dissolvePosition ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.08; // 渐变宽度\n return smoothstep(dissolvePosition, dissolvePosition + fadeWidth, uv.y);\n } else {\n // 硬边缘:返回0或1\n return uv.y < dissolvePosition ? 0.0 : 1.0;\n }\n }\n }\n\n // 从下到上溶解函数\n float bottomToTopDissolve(vec2 uv, float time, float pixelSize, vec2 resolution) {\n // 下到上溶解:从y=1开始向y=0溶解\n float dissolvePosition = 1.0 - time * 1.2; // 增加系数确保完全溶解\n\n // 当pixelSize > 0时添加颗粒效果\n if (pixelSize > 0.0) {\n vec2 pixelCoord = uv * resolution;\n float noiseValue = pixelNoise(pixelCoord, pixelSize);\n float noiseInfluence = (noiseValue - 0.5) * 0.3;\n dissolvePosition += noiseInfluence;\n return uv.y > dissolvePosition ? 0.0 : 1.0;\n } else {\n // 平滑溶解:根据fadeEdge决定是否使用渐变\n if (u_fadeEdge) {\n // 柔和边缘:返回渐变值\n float fadeWidth = 0.08; // 渐变宽度\n return smoothstep(dissolvePosition - fadeWidth, dissolvePosition, uv.y);\n } else {\n // 硬边缘:返回0或1\n return uv.y > dissolvePosition ? 0.0 : 1.0;\n }\n }\n }\n\n void main() {\n vec2 uv = v_texCoord;\n vec4 texColor = texture2D(u_texture, uv);\n\n float alpha = 1.0;\n\n // 根据溶解类型选择对应的溶解函数\n if (u_dissolveType == 0) {\n alpha = outwardDissolve(uv, u_time, u_noiseScale, u_resolution);\n } else if (u_dissolveType == 1) {\n alpha = inwardDissolve(uv, u_time, u_noiseScale, u_resolution);\n } else if (u_dissolveType == 2) {\n alpha = radialDissolve(uv, u_time, u_noiseScale, u_resolution);\n } else if (u_dissolveType == 3) {\n alpha = leftToRightDissolve(uv, u_time, u_noiseScale, u_resolution);\n } else if (u_dissolveType == 4) {\n alpha = rightToLeftDissolve(uv, u_time, u_noiseScale, u_resolution);\n } else if (u_dissolveType == 5) {\n alpha = topToBottomDissolve(uv, u_time, u_noiseScale, u_resolution);\n } else if (u_dissolveType == 6) {\n alpha = bottomToTopDissolve(uv, u_time, u_noiseScale, u_resolution);\n }\n\n gl_FragColor = vec4(texColor.rgb, texColor.a * alpha);\n }\n `
|
|
36566
|
-
};
|
|
36567
|
-
}
|
|
36568
|
-
applyWebGLEffect(canvas) {
|
|
36569
|
-
if (!this.gl || !this.program || !this.webglCanvas) return canvas;
|
|
36570
|
-
this.setupWebGLState(canvas);
|
|
36571
|
-
const texture = this.createTextureFromCanvas(canvas);
|
|
36572
|
-
if (!texture) return canvas;
|
|
36573
|
-
this.noiseData || (this.noiseData = ImageProcessUtils.generateNoiseTexture(256, 256));
|
|
36574
|
-
const noiseTexture = this.gl.createTexture();
|
|
36575
|
-
this.gl.activeTexture(this.gl.TEXTURE1), this.gl.bindTexture(this.gl.TEXTURE_2D, noiseTexture), this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.LUMINANCE, 256, 256, 0, this.gl.LUMINANCE, this.gl.UNSIGNED_BYTE, this.noiseData), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.REPEAT), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.REPEAT), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR), this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
|
|
36576
|
-
const vertexBuffer = this.createFullScreenQuad();
|
|
36577
|
-
return vertexBuffer ? (this.gl.useProgram(this.program), this.setupVertexAttributes(), this.setUniforms(), this.gl.enable(this.gl.BLEND), this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA), this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4), this.gl.deleteTexture(texture), this.gl.deleteTexture(noiseTexture), this.gl.deleteBuffer(vertexBuffer), this.webglCanvas) : canvas;
|
|
36578
|
-
}
|
|
36579
|
-
setUniforms() {
|
|
36580
|
-
if (!this.gl || !this.program || !this.webglCanvas) return;
|
|
36581
|
-
const textureLocation = this.gl.getUniformLocation(this.program, "u_texture"),
|
|
36582
|
-
noiseTextureLocation = this.gl.getUniformLocation(this.program, "u_noiseTexture"),
|
|
36583
|
-
timeLocation = this.gl.getUniformLocation(this.program, "u_time"),
|
|
36584
|
-
dissolveTypeLocation = this.gl.getUniformLocation(this.program, "u_dissolveType"),
|
|
36585
|
-
resolutionLocation = this.gl.getUniformLocation(this.program, "u_resolution"),
|
|
36586
|
-
noiseScaleLocation = this.gl.getUniformLocation(this.program, "u_noiseScale"),
|
|
36587
|
-
fadeEdgeLocation = this.gl.getUniformLocation(this.program, "u_fadeEdge");
|
|
36588
|
-
this.gl.uniform1i(textureLocation, 0), this.gl.uniform1i(noiseTextureLocation, 1), this.gl.uniform1f(timeLocation, this.currentAnimationRatio), this.gl.uniform2f(resolutionLocation, this.webglCanvas.width, this.webglCanvas.height), this.gl.uniform1f(noiseScaleLocation, this.dissolveConfig.noiseScale), this.gl.uniform1i(fadeEdgeLocation, this.dissolveConfig.fadeEdge ? 1 : 0);
|
|
36589
|
-
this.gl.uniform1i(dissolveTypeLocation, {
|
|
36590
|
-
outward: 0,
|
|
36591
|
-
inward: 1,
|
|
36592
|
-
radial: 2,
|
|
36593
|
-
leftToRight: 3,
|
|
36594
|
-
rightToLeft: 4,
|
|
36595
|
-
topToBottom: 5,
|
|
36596
|
-
bottomToTop: 6
|
|
36597
|
-
}[this.dissolveConfig.dissolveType] || 0);
|
|
36598
|
-
}
|
|
36599
|
-
applyCanvas2DEffect(canvas) {
|
|
36600
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
36601
|
-
if (!outputCanvas) return canvas;
|
|
36602
|
-
const {
|
|
36603
|
-
canvas: outputCanvasElement,
|
|
36604
|
-
ctx: ctx
|
|
36605
|
-
} = outputCanvas,
|
|
36606
|
-
imageData = ctx.getImageData(0, 0, canvas.width, canvas.height),
|
|
36607
|
-
progress = this.currentAnimationRatio;
|
|
36608
|
-
let dissolvedImageData;
|
|
36609
|
-
switch (this.dissolveConfig.dissolveType) {
|
|
36610
|
-
case "outward":
|
|
36611
|
-
dissolvedImageData = this.applyOutwardDissolve(imageData, progress);
|
|
36612
|
-
break;
|
|
36613
|
-
case "inward":
|
|
36614
|
-
dissolvedImageData = this.applyInwardDissolve(imageData, progress);
|
|
36615
|
-
break;
|
|
36616
|
-
case "radial":
|
|
36617
|
-
dissolvedImageData = this.applyRadialDissolve(imageData, progress);
|
|
36618
|
-
break;
|
|
36619
|
-
case "leftToRight":
|
|
36620
|
-
dissolvedImageData = this.applyLeftToRightDissolve(imageData, progress);
|
|
36621
|
-
break;
|
|
36622
|
-
case "rightToLeft":
|
|
36623
|
-
dissolvedImageData = this.applyRightToLeftDissolve(imageData, progress);
|
|
36624
|
-
break;
|
|
36625
|
-
case "topToBottom":
|
|
36626
|
-
dissolvedImageData = this.applyTopToBottomDissolve(imageData, progress);
|
|
36627
|
-
break;
|
|
36628
|
-
case "bottomToTop":
|
|
36629
|
-
dissolvedImageData = this.applyBottomToTopDissolve(imageData, progress);
|
|
36630
|
-
break;
|
|
36631
|
-
default:
|
|
36632
|
-
dissolvedImageData = imageData;
|
|
36633
|
-
}
|
|
36634
|
-
return ctx.putImageData(dissolvedImageData, 0, 0), outputCanvasElement;
|
|
36635
|
-
}
|
|
36636
|
-
applyOutwardDissolve(imageData, progress) {
|
|
36637
|
-
const {
|
|
36638
|
-
data: data,
|
|
36639
|
-
width: width,
|
|
36640
|
-
height: height
|
|
36641
|
-
} = imageData,
|
|
36642
|
-
result = new Uint8ClampedArray(data.length);
|
|
36643
|
-
result.set(data);
|
|
36644
|
-
const centerX = width / 2,
|
|
36645
|
-
centerY = height / 2,
|
|
36646
|
-
maxDist = Math.sqrt(centerX * centerX + centerY * centerY),
|
|
36647
|
-
pixelSize = this.dissolveConfig.noiseScale;
|
|
36648
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36649
|
-
const dx = x - centerX,
|
|
36650
|
-
dy = y - centerY,
|
|
36651
|
-
normalizedDist = Math.sqrt(dx * dx + dy * dy) / maxDist;
|
|
36652
|
-
let dissolveThreshold = 1.2 - 1.4 * progress,
|
|
36653
|
-
alpha = 1;
|
|
36654
|
-
if (pixelSize > 0) {
|
|
36655
|
-
dissolveThreshold += .4 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedDist > dissolveThreshold ? 0 : 1;
|
|
36656
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36657
|
-
const fadeStart = dissolveThreshold - .15;
|
|
36658
|
-
alpha = normalizedDist < fadeStart ? 1 : normalizedDist > dissolveThreshold ? 0 : 1 - (normalizedDist - fadeStart) / (dissolveThreshold - fadeStart);
|
|
36659
|
-
} else alpha = normalizedDist > dissolveThreshold ? 0 : 1;
|
|
36660
|
-
const index = 4 * (y * width + x);
|
|
36661
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36662
|
-
}
|
|
36663
|
-
return new ImageData(result, width, height);
|
|
36664
|
-
}
|
|
36665
|
-
applyInwardDissolve(imageData, progress) {
|
|
36666
|
-
const {
|
|
36667
|
-
data: data,
|
|
36668
|
-
width: width,
|
|
36669
|
-
height: height
|
|
36670
|
-
} = imageData,
|
|
36671
|
-
result = new Uint8ClampedArray(data.length);
|
|
36672
|
-
result.set(data);
|
|
36673
|
-
const centerX = width / 2,
|
|
36674
|
-
centerY = height / 2,
|
|
36675
|
-
maxDist = Math.sqrt(centerX * centerX + centerY * centerY),
|
|
36676
|
-
pixelSize = this.dissolveConfig.noiseScale;
|
|
36677
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36678
|
-
const dx = x - centerX,
|
|
36679
|
-
dy = y - centerY,
|
|
36680
|
-
normalizedDist = Math.sqrt(dx * dx + dy * dy) / maxDist;
|
|
36681
|
-
let dissolveThreshold = 1.4 * progress,
|
|
36682
|
-
alpha = 1;
|
|
36683
|
-
if (pixelSize > 0) {
|
|
36684
|
-
dissolveThreshold += .4 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedDist < dissolveThreshold ? 0 : 1;
|
|
36685
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36686
|
-
const fadeEnd = dissolveThreshold + .15;
|
|
36687
|
-
alpha = normalizedDist < dissolveThreshold ? 0 : normalizedDist > fadeEnd ? 1 : (normalizedDist - dissolveThreshold) / (fadeEnd - dissolveThreshold);
|
|
36688
|
-
} else alpha = normalizedDist < dissolveThreshold ? 0 : 1;
|
|
36689
|
-
const index = 4 * (y * width + x);
|
|
36690
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36691
|
-
}
|
|
36692
|
-
return new ImageData(result, width, height);
|
|
36693
|
-
}
|
|
36694
|
-
applyRadialDissolve(imageData, progress) {
|
|
36695
|
-
const {
|
|
36696
|
-
data: data,
|
|
36697
|
-
width: width,
|
|
36698
|
-
height: height
|
|
36699
|
-
} = imageData,
|
|
36700
|
-
result = new Uint8ClampedArray(data.length);
|
|
36701
|
-
result.set(data);
|
|
36702
|
-
const centerX = width / 2,
|
|
36703
|
-
centerY = height / 2,
|
|
36704
|
-
pixelSize = this.dissolveConfig.noiseScale;
|
|
36705
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36706
|
-
const dx = x - centerX,
|
|
36707
|
-
dy = y - centerY,
|
|
36708
|
-
normalizedAngle = (Math.atan2(dy, dx) + Math.PI) / (2 * Math.PI);
|
|
36709
|
-
let dissolveThreshold = 1.2 * progress,
|
|
36710
|
-
alpha = 1;
|
|
36711
|
-
if (pixelSize > 0) {
|
|
36712
|
-
dissolveThreshold += .3 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedAngle < dissolveThreshold ? 0 : 1;
|
|
36713
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36714
|
-
const fadeEnd = dissolveThreshold + .08;
|
|
36715
|
-
alpha = normalizedAngle < dissolveThreshold ? 0 : normalizedAngle > fadeEnd ? 1 : (normalizedAngle - dissolveThreshold) / (fadeEnd - dissolveThreshold);
|
|
36716
|
-
} else alpha = normalizedAngle < dissolveThreshold ? 0 : 1;
|
|
36717
|
-
const index = 4 * (y * width + x);
|
|
36718
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36719
|
-
}
|
|
36720
|
-
return new ImageData(result, width, height);
|
|
36721
|
-
}
|
|
36722
|
-
applyLeftToRightDissolve(imageData, progress) {
|
|
36723
|
-
const {
|
|
36724
|
-
data: data,
|
|
36725
|
-
width: width,
|
|
36726
|
-
height: height
|
|
36727
|
-
} = imageData,
|
|
36728
|
-
result = new Uint8ClampedArray(data.length);
|
|
36729
|
-
result.set(data);
|
|
36730
|
-
const pixelSize = this.dissolveConfig.noiseScale;
|
|
36731
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36732
|
-
const normalizedX = x / width;
|
|
36733
|
-
let dissolveThreshold = 1.2 * progress,
|
|
36734
|
-
alpha = 1;
|
|
36735
|
-
if (pixelSize > 0) {
|
|
36736
|
-
dissolveThreshold += .3 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedX < dissolveThreshold ? 0 : 1;
|
|
36737
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36738
|
-
const fadeEnd = dissolveThreshold + .08;
|
|
36739
|
-
alpha = normalizedX < dissolveThreshold ? 0 : normalizedX > fadeEnd ? 1 : (normalizedX - dissolveThreshold) / (fadeEnd - dissolveThreshold);
|
|
36740
|
-
} else alpha = normalizedX < dissolveThreshold ? 0 : 1;
|
|
36741
|
-
const index = 4 * (y * width + x);
|
|
36742
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36743
|
-
}
|
|
36744
|
-
return new ImageData(result, width, height);
|
|
36745
|
-
}
|
|
36746
|
-
applyRightToLeftDissolve(imageData, progress) {
|
|
36747
|
-
const {
|
|
36748
|
-
data: data,
|
|
36749
|
-
width: width,
|
|
36750
|
-
height: height
|
|
36751
|
-
} = imageData,
|
|
36752
|
-
result = new Uint8ClampedArray(data.length);
|
|
36753
|
-
result.set(data);
|
|
36754
|
-
const pixelSize = this.dissolveConfig.noiseScale;
|
|
36755
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36756
|
-
const normalizedX = x / width;
|
|
36757
|
-
let dissolveThreshold = 1 - 1.2 * progress,
|
|
36758
|
-
alpha = 1;
|
|
36759
|
-
if (pixelSize > 0) {
|
|
36760
|
-
dissolveThreshold += .3 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedX > dissolveThreshold ? 0 : 1;
|
|
36761
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36762
|
-
const fadeStart = dissolveThreshold - .08;
|
|
36763
|
-
alpha = normalizedX < fadeStart ? 1 : normalizedX > dissolveThreshold ? 0 : 1 - (normalizedX - fadeStart) / (dissolveThreshold - fadeStart);
|
|
36764
|
-
} else alpha = normalizedX > dissolveThreshold ? 0 : 1;
|
|
36765
|
-
const index = 4 * (y * width + x);
|
|
36766
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36767
|
-
}
|
|
36768
|
-
return new ImageData(result, width, height);
|
|
36769
|
-
}
|
|
36770
|
-
applyTopToBottomDissolve(imageData, progress) {
|
|
36771
|
-
const {
|
|
36772
|
-
data: data,
|
|
36773
|
-
width: width,
|
|
36774
|
-
height: height
|
|
36775
|
-
} = imageData,
|
|
36776
|
-
result = new Uint8ClampedArray(data.length);
|
|
36777
|
-
result.set(data);
|
|
36778
|
-
const pixelSize = this.dissolveConfig.noiseScale;
|
|
36779
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36780
|
-
const normalizedY = y / height;
|
|
36781
|
-
let dissolveThreshold = 1.2 * progress,
|
|
36782
|
-
alpha = 1;
|
|
36783
|
-
if (pixelSize > 0) {
|
|
36784
|
-
dissolveThreshold += .3 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedY < dissolveThreshold ? 0 : 1;
|
|
36785
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36786
|
-
const fadeEnd = dissolveThreshold + .08;
|
|
36787
|
-
alpha = normalizedY < dissolveThreshold ? 0 : normalizedY > fadeEnd ? 1 : (normalizedY - dissolveThreshold) / (fadeEnd - dissolveThreshold);
|
|
36788
|
-
} else alpha = normalizedY < dissolveThreshold ? 0 : 1;
|
|
36789
|
-
const index = 4 * (y * width + x);
|
|
36790
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36791
|
-
}
|
|
36792
|
-
return new ImageData(result, width, height);
|
|
36793
|
-
}
|
|
36794
|
-
applyBottomToTopDissolve(imageData, progress) {
|
|
36795
|
-
const {
|
|
36796
|
-
data: data,
|
|
36797
|
-
width: width,
|
|
36798
|
-
height: height
|
|
36799
|
-
} = imageData,
|
|
36800
|
-
result = new Uint8ClampedArray(data.length);
|
|
36801
|
-
result.set(data);
|
|
36802
|
-
const pixelSize = this.dissolveConfig.noiseScale;
|
|
36803
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
36804
|
-
const normalizedY = y / height;
|
|
36805
|
-
let dissolveThreshold = 1 - 1.2 * progress,
|
|
36806
|
-
alpha = 1;
|
|
36807
|
-
if (pixelSize > 0) {
|
|
36808
|
-
dissolveThreshold += .3 * (ImageProcessUtils.pixelNoise(x, y, pixelSize) - .5), alpha = normalizedY > dissolveThreshold ? 0 : 1;
|
|
36809
|
-
} else if (this.dissolveConfig.fadeEdge) {
|
|
36810
|
-
const fadeStart = dissolveThreshold - .08;
|
|
36811
|
-
alpha = normalizedY < fadeStart ? 1 : normalizedY > dissolveThreshold ? 0 : 1 - (normalizedY - fadeStart) / (dissolveThreshold - fadeStart);
|
|
36812
|
-
} else alpha = normalizedY > dissolveThreshold ? 0 : 1;
|
|
36813
|
-
const index = 4 * (y * width + x);
|
|
36814
|
-
result[index + 3] = Math.floor(result[index + 3] * alpha);
|
|
36815
|
-
}
|
|
36816
|
-
return new ImageData(result, width, height);
|
|
36817
|
-
}
|
|
36818
|
-
}
|
|
36819
|
-
|
|
36820
|
-
class Grayscale extends HybridEffectBase {
|
|
36821
|
-
constructor(from, to, duration, easing, params) {
|
|
36822
|
-
var _a, _b, _c;
|
|
36823
|
-
super(from, to, duration, easing, params);
|
|
36824
|
-
const rawStrength = void 0 !== (null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.strength) ? params.options.strength : 1,
|
|
36825
|
-
clampedStrength = Math.max(0, Math.min(1, rawStrength));
|
|
36826
|
-
this.colorConfig = {
|
|
36827
|
-
effectType: (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.effectType) || "grayscale",
|
|
36828
|
-
strength: clampedStrength,
|
|
36829
|
-
useWebGL: void 0 === (null === (_c = null == params ? void 0 : params.options) || void 0 === _c ? void 0 : _c.useWebGL) || params.options.useWebGL
|
|
36830
|
-
};
|
|
36831
|
-
}
|
|
36832
|
-
getShaderSources() {
|
|
36833
|
-
return {
|
|
36834
|
-
vertex: ShaderLibrary.STANDARD_VERTEX_SHADER,
|
|
36835
|
-
fragment: `\n precision mediump float;\n uniform sampler2D u_texture;\n uniform float u_time;\n uniform float u_strength;\n uniform int u_effectType;\n uniform vec2 u_resolution;\n varying vec2 v_texCoord;\n\n ${ShaderLibrary.SHADER_FUNCTIONS}\n\n void main() {\n vec2 uv = v_texCoord;\n vec4 originalColor = texture2D(u_texture, uv);\n vec3 color = originalColor.rgb;\n\n // 计算动态强度\n float dynamicStrength = calculateDynamicStrength(u_strength, u_time);\n\n if (u_effectType == 0) {\n // 灰度效果\n float gray = luminance(color);\n vec3 grayColor = vec3(gray);\n color = mix(color, grayColor, dynamicStrength);\n } else if (u_effectType == 1) {\n // 褐色调效果\n vec3 sepiaColor = sepia(color);\n color = mix(color, sepiaColor, dynamicStrength);\n }\n\n gl_FragColor = vec4(color, originalColor.a);\n }\n `
|
|
36836
|
-
};
|
|
36837
|
-
}
|
|
36838
|
-
applyWebGLEffect(canvas) {
|
|
36839
|
-
if (!this.gl || !this.program || !this.webglCanvas) return null;
|
|
36840
|
-
this.setupWebGLState(canvas);
|
|
36841
|
-
const texture = this.createTextureFromCanvas(canvas);
|
|
36842
|
-
if (!texture) return null;
|
|
36843
|
-
const vertexBuffer = this.createFullScreenQuad();
|
|
36844
|
-
if (!vertexBuffer) return this.gl.deleteTexture(texture), null;
|
|
36845
|
-
try {
|
|
36846
|
-
return this.gl.useProgram(this.program), this.setupVertexAttributes(), this.setColorUniforms(), this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4), this.webglCanvas;
|
|
36847
|
-
} finally {
|
|
36848
|
-
this.gl.deleteTexture(texture), this.gl.deleteBuffer(vertexBuffer);
|
|
36849
|
-
}
|
|
36850
|
-
}
|
|
36851
|
-
setColorUniforms() {
|
|
36852
|
-
if (!this.gl || !this.program) return;
|
|
36853
|
-
const currentTime = this.getAnimationTime(),
|
|
36854
|
-
timeLocation = this.gl.getUniformLocation(this.program, "u_time"),
|
|
36855
|
-
strengthLocation = this.gl.getUniformLocation(this.program, "u_strength"),
|
|
36856
|
-
effectTypeLocation = this.gl.getUniformLocation(this.program, "u_effectType"),
|
|
36857
|
-
resolutionLocation = this.gl.getUniformLocation(this.program, "u_resolution");
|
|
36858
|
-
this.gl.uniform1f(timeLocation, currentTime), this.gl.uniform1f(strengthLocation, this.colorConfig.strength), this.gl.uniform2f(resolutionLocation, this.webglCanvas.width, this.webglCanvas.height);
|
|
36859
|
-
this.gl.uniform1i(effectTypeLocation, {
|
|
36860
|
-
grayscale: 0,
|
|
36861
|
-
sepia: 1
|
|
36862
|
-
}[this.colorConfig.effectType] || 0);
|
|
36863
|
-
}
|
|
36864
|
-
applyCanvas2DEffect(canvas) {
|
|
36865
|
-
if (this.colorConfig.strength <= 0) {
|
|
36866
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
36867
|
-
return outputCanvas ? outputCanvas.canvas : null;
|
|
36868
|
-
}
|
|
36869
|
-
if (this.canUseCSSFilter()) return this.applyCSSFilter(canvas);
|
|
36870
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
36871
|
-
if (!outputCanvas) return null;
|
|
36872
|
-
const {
|
|
36873
|
-
ctx: ctx
|
|
36874
|
-
} = outputCanvas;
|
|
36875
|
-
try {
|
|
36876
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height),
|
|
36877
|
-
currentTime = this.getAnimationTime();
|
|
36878
|
-
let processedImageData;
|
|
36879
|
-
switch (this.colorConfig.effectType) {
|
|
36880
|
-
case "grayscale":
|
|
36881
|
-
default:
|
|
36882
|
-
processedImageData = this.applyGrayscaleEffect(imageData, this.colorConfig.strength, currentTime);
|
|
36883
|
-
break;
|
|
36884
|
-
case "sepia":
|
|
36885
|
-
processedImageData = this.applySepiaEffect(imageData, this.colorConfig.strength, currentTime);
|
|
36886
|
-
}
|
|
36887
|
-
return ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.putImageData(processedImageData, 0, 0), outputCanvas.canvas;
|
|
36888
|
-
} catch (error) {
|
|
36889
|
-
return console.warn("Canvas 2D color effect failed:", error), null;
|
|
36890
|
-
}
|
|
36891
|
-
}
|
|
36892
|
-
canUseCSSFilter() {
|
|
36893
|
-
var _a;
|
|
36894
|
-
return !!window.useFilterAPI && "undefined" != typeof CSS && (null === (_a = CSS.supports) || void 0 === _a ? void 0 : _a.call(CSS, "filter", "grayscale(1)"));
|
|
36895
|
-
}
|
|
36896
|
-
applyCSSFilter(canvas) {
|
|
36897
|
-
try {
|
|
36898
|
-
const outputCanvas = ImageProcessUtils.createTempCanvas(canvas.width, canvas.height),
|
|
36899
|
-
ctx = outputCanvas.getContext("2d");
|
|
36900
|
-
if (!ctx) return null;
|
|
36901
|
-
const currentTime = this.getAnimationTime(),
|
|
36902
|
-
dynamicStrength = ImageProcessUtils.calculateDynamicStrength(this.colorConfig.strength, currentTime);
|
|
36903
|
-
let filterValue = "";
|
|
36904
|
-
return "grayscale" === this.colorConfig.effectType ? filterValue = `grayscale(${Math.min(1, dynamicStrength)})` : "sepia" === this.colorConfig.effectType && (filterValue = `sepia(${Math.min(1, dynamicStrength)})`), ctx.filter = filterValue, ctx.drawImage(canvas, 0, 0), ctx.filter = "none", outputCanvas;
|
|
36905
|
-
} catch (error) {
|
|
36906
|
-
return console.warn("CSS Filter API failed, falling back to pixel processing:", error), null;
|
|
36907
|
-
}
|
|
36908
|
-
}
|
|
36909
|
-
applyGrayscaleEffect(imageData, strength, time) {
|
|
36910
|
-
const {
|
|
36911
|
-
data: data,
|
|
36912
|
-
width: width,
|
|
36913
|
-
height: height
|
|
36914
|
-
} = imageData,
|
|
36915
|
-
result = new Uint8ClampedArray(data.length),
|
|
36916
|
-
dynamicStrength = ImageProcessUtils.calculateDynamicStrength(strength, time);
|
|
36917
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
36918
|
-
const r = data[i],
|
|
36919
|
-
g = data[i + 1],
|
|
36920
|
-
b = data[i + 2],
|
|
36921
|
-
a = data[i + 3],
|
|
36922
|
-
gray = ImageProcessUtils.getLuminance(r, g, b);
|
|
36923
|
-
result[i] = Math.round(ImageProcessUtils.lerp(r, gray, dynamicStrength)), result[i + 1] = Math.round(ImageProcessUtils.lerp(g, gray, dynamicStrength)), result[i + 2] = Math.round(ImageProcessUtils.lerp(b, gray, dynamicStrength)), result[i + 3] = a;
|
|
36924
|
-
}
|
|
36925
|
-
return new ImageData(result, width, height);
|
|
36926
|
-
}
|
|
36927
|
-
applySepiaEffect(imageData, strength, time) {
|
|
36928
|
-
const {
|
|
36929
|
-
data: data,
|
|
36930
|
-
width: width,
|
|
36931
|
-
height: height
|
|
36932
|
-
} = imageData,
|
|
36933
|
-
result = new Uint8ClampedArray(data.length),
|
|
36934
|
-
dynamicStrength = ImageProcessUtils.calculateDynamicStrength(strength, time);
|
|
36935
|
-
for (let i = 0; i < data.length; i += 4) {
|
|
36936
|
-
const r = data[i],
|
|
36937
|
-
g = data[i + 1],
|
|
36938
|
-
b = data[i + 2],
|
|
36939
|
-
a = data[i + 3],
|
|
36940
|
-
[sepiaR, sepiaG, sepiaB] = ImageProcessUtils.applySepiaToPixel(r, g, b);
|
|
36941
|
-
result[i] = Math.round(ImageProcessUtils.lerp(r, sepiaR, dynamicStrength)), result[i + 1] = Math.round(ImageProcessUtils.lerp(g, sepiaG, dynamicStrength)), result[i + 2] = Math.round(ImageProcessUtils.lerp(b, sepiaB, dynamicStrength)), result[i + 3] = a;
|
|
36942
|
-
}
|
|
36943
|
-
return new ImageData(result, width, height);
|
|
36944
|
-
}
|
|
36945
|
-
afterStageRender(stage, canvas) {
|
|
36946
|
-
if (this.canUseCSSFilter() && this.colorConfig.strength > 0) {
|
|
36947
|
-
const cssResult = this.applyCSSFilter(canvas);
|
|
36948
|
-
if (cssResult) return cssResult;
|
|
36949
|
-
}
|
|
36950
|
-
return super.afterStageRender(stage, canvas);
|
|
36951
|
-
}
|
|
36952
|
-
}
|
|
36953
|
-
|
|
36954
|
-
class Distortion extends HybridEffectBase {
|
|
36955
|
-
constructor(from, to, duration, easing, params) {
|
|
36956
|
-
var _a, _b, _c;
|
|
36957
|
-
super(from, to, duration, easing, params), this.distortionConfig = {
|
|
36958
|
-
distortionType: (null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.distortionType) || "wave",
|
|
36959
|
-
strength: (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.strength) || .3,
|
|
36960
|
-
useWebGL: void 0 === (null === (_c = null == params ? void 0 : params.options) || void 0 === _c ? void 0 : _c.useWebGL) || params.options.useWebGL
|
|
36961
|
-
};
|
|
36962
|
-
}
|
|
36963
|
-
getShaderSources() {
|
|
36964
|
-
return {
|
|
36965
|
-
vertex: "\n attribute vec2 a_position;\n attribute vec2 a_texCoord;\n varying vec2 v_texCoord;\n\n void main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_texCoord;\n }\n ",
|
|
36966
|
-
fragment: "\n precision mediump float;\n uniform sampler2D u_texture;\n uniform float u_time;\n uniform float u_strength;\n uniform int u_distortionType;\n uniform vec2 u_resolution;\n varying vec2 v_texCoord;\n\n // 波浪扭曲函数\n vec2 wave(vec2 uv, float time, float strength) {\n float waveX = sin(uv.y * 10.0 + time * 3.0) * strength * 0.1;\n float waveY = sin(uv.x * 10.0 + time * 2.0) * strength * 0.1;\n return uv + vec2(waveX, waveY);\n }\n\n // 涟漪扭曲函数\n vec2 ripple(vec2 uv, float time, float strength) {\n vec2 center = vec2(0.5, 0.5);\n float distance = length(uv - center);\n float ripple = sin(distance * 20.0 - time * 5.0) * strength * 0.1;\n vec2 direction = normalize(uv - center);\n return uv + direction * ripple;\n }\n\n // 漩涡扭曲函数\n vec2 swirl(vec2 uv, float time, float strength) {\n vec2 center = vec2(0.5, 0.5);\n vec2 delta = uv - center;\n float dist = length(delta);\n float originalAngle = atan(delta.y, delta.x);\n float rotationAngle = dist * strength * time * 2.0;\n float finalAngle = originalAngle + rotationAngle;\n return center + dist * vec2(cos(finalAngle), sin(finalAngle));\n }\n\n void main() {\n vec2 uv = v_texCoord;\n\n // 根据扭曲类型应用相应变换\n if (u_distortionType == 0) {\n uv = wave(uv, u_time, u_strength);\n } else if (u_distortionType == 1) {\n uv = ripple(uv, u_time, u_strength);\n } else if (u_distortionType == 2) {\n uv = swirl(uv, u_time, u_strength);\n }\n\n // 边界检查\n if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {\n gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n } else {\n gl_FragColor = texture2D(u_texture, uv);\n }\n }\n "
|
|
36967
|
-
};
|
|
36968
|
-
}
|
|
36969
|
-
applyWebGLEffect(canvas) {
|
|
36970
|
-
if (!this.gl || !this.program || !this.webglCanvas) return null;
|
|
36971
|
-
this.setupWebGLState(canvas);
|
|
36972
|
-
const texture = this.createTextureFromCanvas(canvas);
|
|
36973
|
-
if (!texture) return null;
|
|
36974
|
-
const vertexBuffer = this.createFullScreenQuad();
|
|
36975
|
-
if (!vertexBuffer) return this.gl.deleteTexture(texture), null;
|
|
36976
|
-
try {
|
|
36977
|
-
return this.gl.useProgram(this.program), this.setupVertexAttributes(), this.setDistortionUniforms(), this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4), this.webglCanvas;
|
|
36978
|
-
} finally {
|
|
36979
|
-
this.gl.deleteTexture(texture), this.gl.deleteBuffer(vertexBuffer);
|
|
36980
|
-
}
|
|
36981
|
-
}
|
|
36982
|
-
setDistortionUniforms() {
|
|
36983
|
-
if (!this.gl || !this.program) return;
|
|
36984
|
-
const currentTime = this.getAnimationTime(),
|
|
36985
|
-
timeLocation = this.gl.getUniformLocation(this.program, "u_time"),
|
|
36986
|
-
strengthLocation = this.gl.getUniformLocation(this.program, "u_strength"),
|
|
36987
|
-
distortionTypeLocation = this.gl.getUniformLocation(this.program, "u_distortionType"),
|
|
36988
|
-
resolutionLocation = this.gl.getUniformLocation(this.program, "u_resolution");
|
|
36989
|
-
this.gl.uniform1f(timeLocation, currentTime), this.gl.uniform1f(strengthLocation, this.distortionConfig.strength), this.gl.uniform2f(resolutionLocation, this.webglCanvas.width, this.webglCanvas.height);
|
|
36990
|
-
this.gl.uniform1i(distortionTypeLocation, {
|
|
36991
|
-
wave: 0,
|
|
36992
|
-
ripple: 1,
|
|
36993
|
-
swirl: 2
|
|
36994
|
-
}[this.distortionConfig.distortionType] || 0);
|
|
36995
|
-
}
|
|
36996
|
-
applyCanvas2DEffect(canvas) {
|
|
36997
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
36998
|
-
if (!outputCanvas) return null;
|
|
36999
|
-
const {
|
|
37000
|
-
ctx: ctx
|
|
37001
|
-
} = outputCanvas;
|
|
37002
|
-
try {
|
|
37003
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height),
|
|
37004
|
-
currentTime = this.getAnimationTime();
|
|
37005
|
-
let distortedImageData;
|
|
37006
|
-
switch (this.distortionConfig.distortionType) {
|
|
37007
|
-
case "wave":
|
|
37008
|
-
distortedImageData = this.applyWaveDistortion(imageData, this.distortionConfig.strength, currentTime);
|
|
37009
|
-
break;
|
|
37010
|
-
case "ripple":
|
|
37011
|
-
distortedImageData = this.applyRippleDistortion(imageData, this.distortionConfig.strength, currentTime);
|
|
37012
|
-
break;
|
|
37013
|
-
case "swirl":
|
|
37014
|
-
distortedImageData = this.applySwirlDistortion(imageData, this.distortionConfig.strength, currentTime);
|
|
37015
|
-
break;
|
|
37016
|
-
default:
|
|
37017
|
-
distortedImageData = imageData;
|
|
37018
|
-
}
|
|
37019
|
-
return ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.putImageData(distortedImageData, 0, 0), outputCanvas.canvas;
|
|
37020
|
-
} catch (error) {
|
|
37021
|
-
return console.warn("Canvas 2D distortion effect failed:", error), null;
|
|
37022
|
-
}
|
|
37023
|
-
}
|
|
37024
|
-
applyWaveDistortion(imageData, strength, time) {
|
|
37025
|
-
const {
|
|
37026
|
-
data: data,
|
|
37027
|
-
width: width,
|
|
37028
|
-
height: height
|
|
37029
|
-
} = imageData,
|
|
37030
|
-
result = new Uint8ClampedArray(data.length);
|
|
37031
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
37032
|
-
const waveX = Math.sin(.1 * y + 3 * time) * strength * 20,
|
|
37033
|
-
waveY = Math.sin(.1 * x + 2 * time) * strength * 20,
|
|
37034
|
-
sourceX = Math.round(x - waveX),
|
|
37035
|
-
sourceY = Math.round(y - waveY),
|
|
37036
|
-
targetIndex = 4 * (y * width + x);
|
|
37037
|
-
if (sourceX >= 0 && sourceX < width && sourceY >= 0 && sourceY < height) {
|
|
37038
|
-
const sourceIndex = 4 * (sourceY * width + sourceX);
|
|
37039
|
-
result[targetIndex] = data[sourceIndex], result[targetIndex + 1] = data[sourceIndex + 1], result[targetIndex + 2] = data[sourceIndex + 2], result[targetIndex + 3] = data[sourceIndex + 3];
|
|
37040
|
-
} else result[targetIndex + 3] = 0;
|
|
37041
|
-
}
|
|
37042
|
-
return new ImageData(result, width, height);
|
|
37043
|
-
}
|
|
37044
|
-
applyRippleDistortion(imageData, strength, time) {
|
|
37045
|
-
const {
|
|
37046
|
-
data: data,
|
|
37047
|
-
width: width,
|
|
37048
|
-
height: height
|
|
37049
|
-
} = imageData,
|
|
37050
|
-
result = new Uint8ClampedArray(data.length),
|
|
37051
|
-
centerX = width / 2,
|
|
37052
|
-
centerY = height / 2;
|
|
37053
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
37054
|
-
const dx = x - centerX,
|
|
37055
|
-
dy = y - centerY,
|
|
37056
|
-
distance = Math.sqrt(dx * dx + dy * dy),
|
|
37057
|
-
ripple = Math.sin(.2 * distance - 5 * time) * strength * 10,
|
|
37058
|
-
angle = Math.atan2(dy, dx),
|
|
37059
|
-
sourceX = Math.round(x - Math.cos(angle) * ripple),
|
|
37060
|
-
sourceY = Math.round(y - Math.sin(angle) * ripple),
|
|
37061
|
-
targetIndex = 4 * (y * width + x);
|
|
37062
|
-
if (sourceX >= 0 && sourceX < width && sourceY >= 0 && sourceY < height) {
|
|
37063
|
-
const sourceIndex = 4 * (sourceY * width + sourceX);
|
|
37064
|
-
result[targetIndex] = data[sourceIndex], result[targetIndex + 1] = data[sourceIndex + 1], result[targetIndex + 2] = data[sourceIndex + 2], result[targetIndex + 3] = data[sourceIndex + 3];
|
|
37065
|
-
} else result[targetIndex + 3] = 0;
|
|
37066
|
-
}
|
|
37067
|
-
return new ImageData(result, width, height);
|
|
37068
|
-
}
|
|
37069
|
-
applySwirlDistortion(imageData, strength, time) {
|
|
37070
|
-
const {
|
|
37071
|
-
data: data,
|
|
37072
|
-
width: width,
|
|
37073
|
-
height: height
|
|
37074
|
-
} = imageData,
|
|
37075
|
-
result = new Uint8ClampedArray(data.length),
|
|
37076
|
-
centerX = width / 2,
|
|
37077
|
-
centerY = height / 2;
|
|
37078
|
-
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
37079
|
-
const dx = x - centerX,
|
|
37080
|
-
dy = y - centerY,
|
|
37081
|
-
distance = Math.sqrt(dx * dx + dy * dy),
|
|
37082
|
-
finalAngle = Math.atan2(dy, dx) + distance * strength * time * .02,
|
|
37083
|
-
sourceX = Math.round(centerX + distance * Math.cos(finalAngle)),
|
|
37084
|
-
sourceY = Math.round(centerY + distance * Math.sin(finalAngle)),
|
|
37085
|
-
targetIndex = 4 * (y * width + x);
|
|
37086
|
-
if (sourceX >= 0 && sourceX < width && sourceY >= 0 && sourceY < height) {
|
|
37087
|
-
const sourceIndex = 4 * (sourceY * width + sourceX);
|
|
37088
|
-
result[targetIndex] = data[sourceIndex], result[targetIndex + 1] = data[sourceIndex + 1], result[targetIndex + 2] = data[sourceIndex + 2], result[targetIndex + 3] = data[sourceIndex + 3];
|
|
37089
|
-
} else result[targetIndex + 3] = 0;
|
|
37090
|
-
}
|
|
37091
|
-
return new ImageData(result, width, height);
|
|
37092
|
-
}
|
|
37093
|
-
afterStageRender(stage, canvas) {
|
|
37094
|
-
return this.distortionConfig.strength <= 0 ? canvas : super.afterStageRender(stage, canvas);
|
|
37095
|
-
}
|
|
37096
|
-
}
|
|
37097
|
-
|
|
37098
|
-
class Particle extends HybridEffectBase {
|
|
37099
|
-
constructor(from, to, duration, easing, params) {
|
|
37100
|
-
var _a, _b, _c, _d, _e;
|
|
37101
|
-
super(from, to, duration, easing, params), this.particles = [], this.positionBuffer = null, this.colorBuffer = null, this.particleConfig = {
|
|
37102
|
-
effectType: (null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.effectType) || "gravity",
|
|
37103
|
-
count: (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.count) || 4e3,
|
|
37104
|
-
size: (null === (_c = null == params ? void 0 : params.options) || void 0 === _c ? void 0 : _c.size) || 20,
|
|
37105
|
-
strength: (null === (_d = null == params ? void 0 : params.options) || void 0 === _d ? void 0 : _d.strength) || 1.5,
|
|
37106
|
-
useWebGL: void 0 === (null === (_e = null == params ? void 0 : params.options) || void 0 === _e ? void 0 : _e.useWebGL) || params.options.useWebGL
|
|
37107
|
-
};
|
|
37108
|
-
}
|
|
37109
|
-
getShaderSources() {
|
|
37110
|
-
return {
|
|
37111
|
-
vertex: "\n attribute vec2 a_position;\n attribute vec4 a_color;\n attribute float a_size;\n\n uniform vec2 u_resolution;\n uniform float u_time;\n uniform float u_forceStrength;\n uniform int u_effectType;\n\n varying vec4 v_color;\n\n void main() {\n // 将像素坐标转换为剪辑空间坐标\n vec2 clipSpace = ((a_position / u_resolution) * 2.0) - 1.0;\n clipSpace.y = -clipSpace.y; // 翻转Y轴\n\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n gl_PointSize = a_size;\n v_color = a_color;\n }\n ",
|
|
37112
|
-
fragment: "\n precision mediump float;\n varying vec4 v_color;\n\n void main() {\n // 创建圆形粒子\n vec2 coord = gl_PointCoord - vec2(0.5);\n float distance = length(coord);\n\n if (distance > 0.5) {\n discard;\n }\n\n // 保持原始颜色,只调整透明度渐变\n gl_FragColor = vec4(v_color.rgb, v_color.a);\n }\n "
|
|
37113
|
-
};
|
|
37114
|
-
}
|
|
37115
|
-
applyWebGLEffect(canvas) {
|
|
37116
|
-
if (!this.gl || !this.program || !this.webglCanvas) return null;
|
|
37117
|
-
this.setupWebGLState(canvas), 0 === this.particles.length && this.extractParticles(canvas), this.updateParticles(canvas);
|
|
37118
|
-
const gl = this.gl;
|
|
37119
|
-
return gl.enable(gl.BLEND), gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA), gl.useProgram(this.program), this.prepareAndDrawParticles(gl), this.webglCanvas;
|
|
37120
|
-
}
|
|
37121
|
-
applyCanvas2DEffect(canvas) {
|
|
37122
|
-
const output = this.createOutputCanvas(canvas);
|
|
37123
|
-
if (!output) return null;
|
|
37124
|
-
const {
|
|
37125
|
-
canvas: outputCanvas,
|
|
37126
|
-
ctx: ctx
|
|
37127
|
-
} = output,
|
|
37128
|
-
progress = this.currentAnimationRatio;
|
|
37129
|
-
switch (this.particleConfig.effectType) {
|
|
37130
|
-
case "explode":
|
|
37131
|
-
this.applyCanvas2DExplode(ctx, canvas, progress);
|
|
37132
|
-
break;
|
|
37133
|
-
case "gravity":
|
|
37134
|
-
this.applyCanvas2DGravity(ctx, canvas, progress);
|
|
37135
|
-
break;
|
|
37136
|
-
case "vortex":
|
|
37137
|
-
this.applyCanvas2DVortex(ctx, canvas, progress);
|
|
37138
|
-
break;
|
|
37139
|
-
default:
|
|
37140
|
-
ctx.globalAlpha = Math.max(0, 1 - progress), ctx.drawImage(canvas, 0, 0);
|
|
37141
|
-
}
|
|
37142
|
-
return outputCanvas;
|
|
37143
|
-
}
|
|
37144
|
-
extractParticles(canvas) {
|
|
37145
|
-
const tempCanvas = ImageProcessUtils.createTempCanvas(canvas.width, canvas.height, 1),
|
|
37146
|
-
tempCtx = tempCanvas.getContext("2d");
|
|
37147
|
-
if (!tempCtx) return;
|
|
37148
|
-
tempCtx.drawImage(canvas, 0, 0, tempCanvas.width, tempCanvas.height);
|
|
37149
|
-
const data = tempCtx.getImageData(0, 0, tempCanvas.width, tempCanvas.height).data;
|
|
37150
|
-
this.particles = [];
|
|
37151
|
-
const step = Math.max(1, Math.floor(Math.sqrt(tempCanvas.width * tempCanvas.height / (1.5 * this.particleConfig.count))));
|
|
37152
|
-
for (let y = 0; y < tempCanvas.height; y += step) for (let x = 0; x < tempCanvas.width; x += step) {
|
|
37153
|
-
const index = 4 * (y * tempCanvas.width + x),
|
|
37154
|
-
r = data[index],
|
|
37155
|
-
g = data[index + 1],
|
|
37156
|
-
b = data[index + 2],
|
|
37157
|
-
a = data[index + 3];
|
|
37158
|
-
if (a > 5) {
|
|
37159
|
-
const realX = x / tempCanvas.width * canvas.width,
|
|
37160
|
-
realY = y / tempCanvas.height * canvas.height,
|
|
37161
|
-
particle = {
|
|
37162
|
-
x: realX,
|
|
37163
|
-
y: realY,
|
|
37164
|
-
originX: realX,
|
|
37165
|
-
originY: realY,
|
|
37166
|
-
vx: 0,
|
|
37167
|
-
vy: 0,
|
|
37168
|
-
r: r / 255,
|
|
37169
|
-
g: g / 255,
|
|
37170
|
-
b: b / 255,
|
|
37171
|
-
a: Math.max(.6, a / 255),
|
|
37172
|
-
life: 1,
|
|
37173
|
-
size: this.particleConfig.size * (1 + .5 * Math.random())
|
|
37174
|
-
};
|
|
37175
|
-
this.particles.push(particle);
|
|
37176
|
-
}
|
|
37177
|
-
}
|
|
37178
|
-
}
|
|
37179
|
-
updateParticles(canvas) {
|
|
37180
|
-
const centerX = canvas.width / 2,
|
|
37181
|
-
centerY = canvas.height / 2,
|
|
37182
|
-
progress = this.currentAnimationRatio,
|
|
37183
|
-
duration = this.getDurationFromParent(),
|
|
37184
|
-
isShortAnimation = duration < 2e3,
|
|
37185
|
-
timeMultiplier = isShortAnimation ? Math.max(1.5, 3e3 / duration) : 1,
|
|
37186
|
-
intensityBoost = isShortAnimation ? Math.min(2, 2e3 / duration) : 1;
|
|
37187
|
-
this.particles.forEach(particle => {
|
|
37188
|
-
const dx = particle.x - centerX,
|
|
37189
|
-
dy = particle.y - centerY,
|
|
37190
|
-
distance = Math.sqrt(dx * dx + dy * dy),
|
|
37191
|
-
angle = Math.atan2(dy, dx);
|
|
37192
|
-
this.applyParticleForces(particle, angle, distance, progress, intensityBoost, canvas), this.updateParticleProperties(particle, progress, isShortAnimation, timeMultiplier, intensityBoost);
|
|
37193
|
-
});
|
|
37194
|
-
}
|
|
37195
|
-
applyParticleForces(particle, angle, distance, progress, intensityBoost, canvas) {
|
|
37196
|
-
const time = this.getAnimationTime();
|
|
37197
|
-
switch (this.particleConfig.effectType) {
|
|
37198
|
-
case "explode":
|
|
37199
|
-
const explodeIntensity = progress * this.particleConfig.strength * intensityBoost * 5;
|
|
37200
|
-
particle.vx += Math.cos(angle) * explodeIntensity, particle.vy += Math.sin(angle) * explodeIntensity;
|
|
37201
|
-
break;
|
|
37202
|
-
case "gravity":
|
|
37203
|
-
this.applyGravityEffect(particle, progress, intensityBoost, canvas, time);
|
|
37204
|
-
break;
|
|
37205
|
-
case "vortex":
|
|
37206
|
-
this.applyVortexEffect(particle, progress, intensityBoost, canvas, angle, distance);
|
|
37207
|
-
}
|
|
37208
|
-
}
|
|
37209
|
-
applyGravityEffect(particle, progress, intensityBoost, canvas, time) {
|
|
37210
|
-
const gravityThreshold = (particle.originX + .7 * particle.originY) / (canvas.width + canvas.height) * .8;
|
|
37211
|
-
if (progress > gravityThreshold) {
|
|
37212
|
-
const gravityProgress = (progress - gravityThreshold) / (1 - gravityThreshold),
|
|
37213
|
-
gravityForce = this.particleConfig.strength * gravityProgress * gravityProgress * 12 * intensityBoost;
|
|
37214
|
-
particle.vy += gravityForce;
|
|
37215
|
-
const turbulence = Math.sin(3 * time + .02 * particle.originX) * Math.cos(2 * time + .015 * particle.originY);
|
|
37216
|
-
particle.vx += turbulence * this.particleConfig.strength * 2 * intensityBoost;
|
|
37217
|
-
}
|
|
37218
|
-
}
|
|
37219
|
-
applyVortexEffect(particle, progress, intensityBoost, canvas, angle, distance) {
|
|
37220
|
-
const centerX = canvas.width / 2,
|
|
37221
|
-
centerY = canvas.height / 2,
|
|
37222
|
-
spiralAngle = angle + progress * Math.PI * .8,
|
|
37223
|
-
targetRadius = distance + progress * Math.max(canvas.width, canvas.height) * .7 * 1.8,
|
|
37224
|
-
targetX = centerX + Math.cos(spiralAngle) * targetRadius,
|
|
37225
|
-
targetY = centerY + Math.sin(spiralAngle) * targetRadius,
|
|
37226
|
-
baseForce = progress * this.particleConfig.strength * .08 * intensityBoost;
|
|
37227
|
-
particle.vx += (targetX - particle.x) * baseForce, particle.vy += (targetY - particle.y) * baseForce;
|
|
37228
|
-
}
|
|
37229
|
-
updateParticleProperties(particle, progress, isShortAnimation, timeMultiplier, intensityBoost) {
|
|
37230
|
-
const dragCoeff = isShortAnimation ? .99 : .98;
|
|
37231
|
-
if (particle.vx *= dragCoeff, particle.vy *= dragCoeff, particle.x += particle.vx, particle.y += particle.vy, isShortAnimation) {
|
|
37232
|
-
const lifeDecayRate = Math.max(.1, .5 / timeMultiplier);
|
|
37233
|
-
particle.life = Math.max(0, 1 - progress * lifeDecayRate), particle.a = Math.max(.2, particle.life * Math.min(1, 1.2 * particle.a)), particle.size = Math.max(.7 * this.particleConfig.size, this.particleConfig.size * (.5 + .5 * particle.life));
|
|
37234
|
-
} else particle.life = Math.max(0, 1 - .2 * progress), particle.a = Math.max(.1, particle.life * Math.min(1, 1.5 * particle.a)), particle.size = Math.max(.5 * this.particleConfig.size, this.particleConfig.size * (.3 + .7 * particle.life));
|
|
37235
|
-
}
|
|
37236
|
-
prepareAndDrawParticles(gl) {
|
|
37237
|
-
const positions = new Float32Array(2 * this.particles.length),
|
|
37238
|
-
colors = new Float32Array(4 * this.particles.length),
|
|
37239
|
-
sizes = new Float32Array(this.particles.length);
|
|
37240
|
-
this.particles.forEach((particle, i) => {
|
|
37241
|
-
positions[2 * i] = particle.x, positions[2 * i + 1] = particle.y, colors[4 * i] = particle.r, colors[4 * i + 1] = particle.g, colors[4 * i + 2] = particle.b, colors[4 * i + 3] = Math.max(.1, particle.a), sizes[i] = Math.max(6, 1.5 * particle.size);
|
|
37242
|
-
}), this.updateParticleBuffers(gl, positions, colors, sizes), this.setParticleUniforms(gl), gl.drawArrays(gl.POINTS, 0, this.particles.length), this.cleanupTempBuffers(gl);
|
|
37243
|
-
}
|
|
37244
|
-
updateParticleBuffers(gl, positions, colors, sizes) {
|
|
37245
|
-
this.positionBuffer || (this.positionBuffer = gl.createBuffer()), gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer), gl.bufferData(gl.ARRAY_BUFFER, positions, gl.DYNAMIC_DRAW);
|
|
37246
|
-
const positionLocation = gl.getAttribLocation(this.program, "a_position");
|
|
37247
|
-
gl.enableVertexAttribArray(positionLocation), gl.vertexAttribPointer(positionLocation, 2, gl.FLOAT, !1, 0, 0), this.colorBuffer || (this.colorBuffer = gl.createBuffer()), gl.bindBuffer(gl.ARRAY_BUFFER, this.colorBuffer), gl.bufferData(gl.ARRAY_BUFFER, colors, gl.DYNAMIC_DRAW);
|
|
37248
|
-
const colorLocation = gl.getAttribLocation(this.program, "a_color");
|
|
37249
|
-
gl.enableVertexAttribArray(colorLocation), gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, !1, 0, 0);
|
|
37250
|
-
const sizeBuffer = gl.createBuffer();
|
|
37251
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, sizeBuffer), gl.bufferData(gl.ARRAY_BUFFER, sizes, gl.DYNAMIC_DRAW);
|
|
37252
|
-
const sizeLocation = gl.getAttribLocation(this.program, "a_size");
|
|
37253
|
-
gl.enableVertexAttribArray(sizeLocation), gl.vertexAttribPointer(sizeLocation, 1, gl.FLOAT, !1, 0, 0), this._tempSizeBuffer = sizeBuffer;
|
|
37254
|
-
}
|
|
37255
|
-
setParticleUniforms(gl) {
|
|
37256
|
-
const resolutionLocation = gl.getUniformLocation(this.program, "u_resolution"),
|
|
37257
|
-
timeLocation = gl.getUniformLocation(this.program, "u_time"),
|
|
37258
|
-
forceStrengthLocation = gl.getUniformLocation(this.program, "u_forceStrength"),
|
|
37259
|
-
effectTypeLocation = gl.getUniformLocation(this.program, "u_effectType");
|
|
37260
|
-
gl.uniform2f(resolutionLocation, this.webglCanvas.width, this.webglCanvas.height), gl.uniform1f(timeLocation, this.getAnimationTime()), gl.uniform1f(forceStrengthLocation, this.particleConfig.strength);
|
|
37261
|
-
gl.uniform1i(effectTypeLocation, {
|
|
37262
|
-
explode: 0,
|
|
37263
|
-
vortex: 1,
|
|
37264
|
-
gravity: 2
|
|
37265
|
-
}[this.particleConfig.effectType] || 0);
|
|
37266
|
-
}
|
|
37267
|
-
cleanupTempBuffers(gl) {
|
|
37268
|
-
const tempSizeBuffer = this._tempSizeBuffer;
|
|
37269
|
-
tempSizeBuffer && (gl.deleteBuffer(tempSizeBuffer), delete this._tempSizeBuffer);
|
|
37270
|
-
}
|
|
37271
|
-
applyCanvas2DExplode(ctx, canvas, progress) {
|
|
37272
|
-
const centerX = canvas.width / 2,
|
|
37273
|
-
centerY = canvas.height / 2;
|
|
37274
|
-
ctx.save(), ctx.globalAlpha = Math.max(0, 1 - progress), ctx.translate(centerX, centerY);
|
|
37275
|
-
const scale = 1 + .5 * progress;
|
|
37276
|
-
ctx.scale(scale, scale), ctx.translate(-centerX, -centerY), ctx.drawImage(canvas, 0, 0), ctx.restore();
|
|
37277
|
-
}
|
|
37278
|
-
applyCanvas2DGravity(ctx, canvas, progress) {
|
|
37279
|
-
ctx.save(), ctx.globalAlpha = Math.max(0, 1 - progress);
|
|
37280
|
-
const offsetY = progress * canvas.height * .3;
|
|
37281
|
-
ctx.drawImage(canvas, 0, offsetY), ctx.restore();
|
|
37282
|
-
}
|
|
37283
|
-
applyCanvas2DVortex(ctx, canvas, progress) {
|
|
37284
|
-
const centerX = canvas.width / 2,
|
|
37285
|
-
centerY = canvas.height / 2;
|
|
37286
|
-
ctx.save(), ctx.globalAlpha = Math.max(0, 1 - progress), ctx.translate(centerX, centerY), ctx.rotate(progress * Math.PI * 2), ctx.translate(-centerX, -centerY), ctx.drawImage(canvas, 0, 0), ctx.restore();
|
|
37287
|
-
}
|
|
37288
|
-
}
|
|
37289
|
-
|
|
37290
|
-
class Glitch extends Canvas2DEffectBase {
|
|
37291
|
-
constructor(from, to, duration, easing, params) {
|
|
37292
|
-
var _a, _b;
|
|
37293
|
-
super(from, to, duration, easing, params), this.glitchConfig = {
|
|
37294
|
-
effectType: (null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.effectType) || "rgb-shift",
|
|
37295
|
-
intensity: void 0 !== (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.intensity) ? params.options.intensity : .5
|
|
37296
|
-
};
|
|
37297
|
-
}
|
|
37298
|
-
applyCanvas2DEffect(canvas) {
|
|
37299
|
-
if (this.glitchConfig.intensity <= 0) {
|
|
37300
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
37301
|
-
return outputCanvas ? outputCanvas.canvas : null;
|
|
37302
|
-
}
|
|
37303
|
-
try {
|
|
37304
|
-
switch (this.glitchConfig.effectType) {
|
|
37305
|
-
case "rgb-shift":
|
|
37306
|
-
default:
|
|
37307
|
-
return this.applyRGBShiftGlitch(canvas);
|
|
37308
|
-
case "digital-distortion":
|
|
37309
|
-
return this.applyDigitalDistortionGlitch(canvas);
|
|
37310
|
-
case "scan-lines":
|
|
37311
|
-
return this.applyScanLineGlitch(canvas);
|
|
37312
|
-
case "data-corruption":
|
|
37313
|
-
return this.applyDataCorruptionGlitch(canvas);
|
|
37314
|
-
}
|
|
37315
|
-
} catch (error) {
|
|
37316
|
-
return console.warn("Glitch effect failed:", error), null;
|
|
37317
|
-
}
|
|
37318
|
-
}
|
|
37319
|
-
applyRGBShiftGlitch(canvas) {
|
|
37320
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
37321
|
-
if (!outputCanvas) return null;
|
|
37322
|
-
const {
|
|
37323
|
-
ctx: ctx
|
|
37324
|
-
} = outputCanvas;
|
|
37325
|
-
try {
|
|
37326
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
37327
|
-
const dynamicIntensity = ImageProcessUtils.calculateDynamicStrength(this.glitchConfig.intensity, this.getAnimationTime()),
|
|
37328
|
-
maxOffset = Math.floor(20 * dynamicIntensity),
|
|
37329
|
-
redOffset = this.generateRandomOffset(maxOffset),
|
|
37330
|
-
greenOffset = this.generateRandomOffset(maxOffset, .3),
|
|
37331
|
-
blueOffset = this.generateRandomOffset(-maxOffset),
|
|
37332
|
-
tempCanvas = ImageProcessUtils.createTempCanvas(canvas.width, canvas.height),
|
|
37333
|
-
tempCtx = tempCanvas.getContext("2d");
|
|
37334
|
-
tempCtx.drawImage(canvas, 0, 0);
|
|
37335
|
-
const originalImageData = tempCtx.getImageData(0, 0, canvas.width, canvas.height),
|
|
37336
|
-
redChannelData = ImageProcessUtils.extractChannel(originalImageData, 0),
|
|
37337
|
-
greenChannelData = ImageProcessUtils.extractChannel(originalImageData, 1),
|
|
37338
|
-
blueChannelData = ImageProcessUtils.extractChannel(originalImageData, 2);
|
|
37339
|
-
return ctx.globalCompositeOperation = "screen", tempCtx.clearRect(0, 0, canvas.width, canvas.height), tempCtx.putImageData(redChannelData, 0, 0), ctx.drawImage(tempCanvas, redOffset.x, redOffset.y), tempCtx.clearRect(0, 0, canvas.width, canvas.height), tempCtx.putImageData(greenChannelData, 0, 0), ctx.drawImage(tempCanvas, greenOffset.x, greenOffset.y), tempCtx.clearRect(0, 0, canvas.width, canvas.height), tempCtx.putImageData(blueChannelData, 0, 0), ctx.drawImage(tempCanvas, blueOffset.x, blueOffset.y), ctx.globalCompositeOperation = "source-over", outputCanvas.canvas;
|
|
37340
|
-
} catch (error) {
|
|
37341
|
-
return console.warn("RGB shift glitch failed:", error), null;
|
|
37342
|
-
}
|
|
37343
|
-
}
|
|
37344
|
-
applyDigitalDistortionGlitch(canvas) {
|
|
37345
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
37346
|
-
if (!outputCanvas) return null;
|
|
37347
|
-
const {
|
|
37348
|
-
ctx: ctx
|
|
37349
|
-
} = outputCanvas;
|
|
37350
|
-
try {
|
|
37351
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height),
|
|
37352
|
-
dynamicIntensity = ImageProcessUtils.calculateDynamicStrength(this.glitchConfig.intensity, this.getAnimationTime()),
|
|
37353
|
-
distortedImageData = this.processDigitalDistortion(imageData, dynamicIntensity);
|
|
37354
|
-
return ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.putImageData(distortedImageData, 0, 0), outputCanvas.canvas;
|
|
37355
|
-
} catch (error) {
|
|
37356
|
-
return console.warn("Digital distortion glitch failed:", error), null;
|
|
37357
|
-
}
|
|
37358
|
-
}
|
|
37359
|
-
applyScanLineGlitch(canvas) {
|
|
37360
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
37361
|
-
if (!outputCanvas) return null;
|
|
37362
|
-
const {
|
|
37363
|
-
ctx: ctx
|
|
37364
|
-
} = outputCanvas;
|
|
37365
|
-
try {
|
|
37366
|
-
const dynamicIntensity = ImageProcessUtils.calculateDynamicStrength(this.glitchConfig.intensity, this.getAnimationTime()),
|
|
37367
|
-
lineSpacing = Math.max(2, Math.floor(10 - 8 * dynamicIntensity));
|
|
37368
|
-
ctx.globalCompositeOperation = "multiply";
|
|
37369
|
-
for (let y = 0; y < canvas.height; y += lineSpacing) if (Math.random() < dynamicIntensity) {
|
|
37370
|
-
const opacity = .1 + .4 * dynamicIntensity;
|
|
37371
|
-
ctx.fillStyle = `rgba(0, 0, 0, ${opacity})`, ctx.fillRect(0, y, canvas.width, 1);
|
|
37372
|
-
}
|
|
37373
|
-
ctx.globalCompositeOperation = "screen";
|
|
37374
|
-
const brightLineCount = Math.floor(20 * dynamicIntensity);
|
|
37375
|
-
for (let i = 0; i < brightLineCount; i++) {
|
|
37376
|
-
const y = Math.random() * canvas.height,
|
|
37377
|
-
opacity = .3 * dynamicIntensity;
|
|
37378
|
-
ctx.fillStyle = `rgba(255, 255, 255, ${opacity})`, ctx.fillRect(0, Math.floor(y), canvas.width, 1);
|
|
37379
|
-
}
|
|
37380
|
-
return ctx.globalCompositeOperation = "source-over", outputCanvas.canvas;
|
|
37381
|
-
} catch (error) {
|
|
37382
|
-
return console.warn("Scan line glitch failed:", error), null;
|
|
37383
|
-
}
|
|
37384
|
-
}
|
|
37385
|
-
applyDataCorruptionGlitch(canvas) {
|
|
37386
|
-
const outputCanvas = this.createOutputCanvas(canvas);
|
|
37387
|
-
if (!outputCanvas) return null;
|
|
37388
|
-
const {
|
|
37389
|
-
ctx: ctx
|
|
37390
|
-
} = outputCanvas;
|
|
37391
|
-
try {
|
|
37392
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height),
|
|
37393
|
-
dynamicIntensity = ImageProcessUtils.calculateDynamicStrength(this.glitchConfig.intensity, this.getAnimationTime()),
|
|
37394
|
-
corruptedImageData = this.processDataCorruption(imageData, dynamicIntensity);
|
|
37395
|
-
return ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.putImageData(corruptedImageData, 0, 0), outputCanvas.canvas;
|
|
37396
|
-
} catch (error) {
|
|
37397
|
-
return console.warn("Data corruption glitch failed:", error), null;
|
|
37398
|
-
}
|
|
37399
|
-
}
|
|
37400
|
-
generateRandomOffset(maxOffset, scale = 1) {
|
|
37401
|
-
return {
|
|
37402
|
-
x: (Math.random() - .5) * maxOffset,
|
|
37403
|
-
y: (Math.random() - .5) * maxOffset * scale
|
|
37404
|
-
};
|
|
37405
|
-
}
|
|
37406
|
-
processDigitalDistortion(imageData, intensity) {
|
|
37407
|
-
const {
|
|
37408
|
-
data: data,
|
|
37409
|
-
width: width,
|
|
37410
|
-
height: height
|
|
37411
|
-
} = imageData,
|
|
37412
|
-
result = new Uint8ClampedArray(data),
|
|
37413
|
-
sliceCount = Math.floor(20 * intensity) + 5,
|
|
37414
|
-
sliceHeight = Math.floor(height / sliceCount);
|
|
37415
|
-
for (let i = 0; i < sliceCount; i++) if (Math.random() < intensity) {
|
|
37416
|
-
const y = i * sliceHeight,
|
|
37417
|
-
sliceEnd = Math.min(y + sliceHeight, height),
|
|
37418
|
-
offset = Math.floor((Math.random() - .5) * width * intensity * .1);
|
|
37419
|
-
this.shiftSliceHorizontal(result, width, height, y, sliceEnd, offset);
|
|
37420
|
-
}
|
|
37421
|
-
const noiseIntensity = .3 * intensity;
|
|
37422
|
-
for (let i = 0; i < data.length; i += 4) Math.random() < noiseIntensity && (result[i] = 255 * Math.random(), result[i + 1] = 255 * Math.random(), result[i + 2] = 255 * Math.random());
|
|
37423
|
-
return new ImageData(result, width, height);
|
|
37424
|
-
}
|
|
37425
|
-
shiftSliceHorizontal(data, width, height, startY, endY, offset) {
|
|
37426
|
-
const tempRow = new Uint8ClampedArray(4 * width);
|
|
37427
|
-
for (let y = startY; y < endY; y++) {
|
|
37428
|
-
const rowStart = y * width * 4;
|
|
37429
|
-
for (let x = 0; x < 4 * width; x++) tempRow[x] = data[rowStart + x];
|
|
37430
|
-
for (let x = 0; x < width; x++) {
|
|
37431
|
-
const targetIndex = rowStart + 4 * x,
|
|
37432
|
-
sourceIndex = 4 * ((x - offset + width) % width);
|
|
37433
|
-
data[targetIndex] = tempRow[sourceIndex], data[targetIndex + 1] = tempRow[sourceIndex + 1], data[targetIndex + 2] = tempRow[sourceIndex + 2], data[targetIndex + 3] = tempRow[sourceIndex + 3];
|
|
37434
|
-
}
|
|
37435
|
-
}
|
|
37436
|
-
}
|
|
37437
|
-
processDataCorruption(imageData, intensity) {
|
|
37438
|
-
const {
|
|
37439
|
-
data: data,
|
|
37440
|
-
width: width,
|
|
37441
|
-
height: height
|
|
37442
|
-
} = imageData,
|
|
37443
|
-
result = new Uint8ClampedArray(data),
|
|
37444
|
-
stripeCount = Math.floor(15 * intensity) + 5;
|
|
37445
|
-
for (let i = 0; i < stripeCount; i++) if (Math.random() < intensity) {
|
|
37446
|
-
const x = Math.floor(Math.random() * width),
|
|
37447
|
-
stripeWidth = Math.floor(5 * Math.random()) + 1,
|
|
37448
|
-
color = Math.random() < .5 ? 0 : 255;
|
|
37449
|
-
for (let y = 0; y < height; y++) for (let dx = 0; dx < stripeWidth && x + dx < width; dx++) {
|
|
37450
|
-
const index = 4 * (y * width + x + dx);
|
|
37451
|
-
result[index] = color, result[index + 1] = color, result[index + 2] = color;
|
|
37452
|
-
}
|
|
37453
|
-
}
|
|
37454
|
-
const corruptionCount = Math.floor(20 * intensity);
|
|
37455
|
-
for (let i = 0; i < corruptionCount; i++) {
|
|
37456
|
-
const blockX = Math.floor(Math.random() * width),
|
|
37457
|
-
blockY = Math.floor(Math.random() * height),
|
|
37458
|
-
blockW = Math.floor(20 * Math.random()) + 5,
|
|
37459
|
-
blockH = Math.floor(10 * Math.random()) + 2;
|
|
37460
|
-
this.corruptBlock(result, width, height, blockX, blockY, blockW, blockH);
|
|
37461
|
-
}
|
|
37462
|
-
return new ImageData(result, width, height);
|
|
37463
|
-
}
|
|
37464
|
-
corruptBlock(data, width, height, x, y, w, h) {
|
|
37465
|
-
for (let dy = 0; dy < h && y + dy < height; dy++) for (let dx = 0; dx < w && x + dx < width; dx++) {
|
|
37466
|
-
const index = 4 * ((y + dy) * width + (x + dx));
|
|
37467
|
-
Math.random() < .7 && (data[index] = 255 * Math.random(), data[index + 1] = 255 * Math.random(), data[index + 2] = 255 * Math.random());
|
|
37468
|
-
}
|
|
37469
|
-
}
|
|
37470
|
-
}
|
|
37471
|
-
|
|
37472
|
-
class GaussianBlur extends AStageAnimate {
|
|
37473
|
-
constructor(from, to, duration, easing, params) {
|
|
37474
|
-
var _a, _b;
|
|
37475
|
-
super(from, to, duration, easing, params), this.blurConfig = {
|
|
37476
|
-
blurRadius: (null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.blurRadius) || 8,
|
|
37477
|
-
useOptimizedBlur: void 0 === (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.useOptimizedBlur) || params.options.useOptimizedBlur
|
|
37478
|
-
};
|
|
37479
|
-
}
|
|
37480
|
-
applyCSSBlur(canvas, radius) {
|
|
37481
|
-
const c = vglobal.createCanvas({
|
|
37482
|
-
width: canvas.width,
|
|
37483
|
-
height: canvas.height,
|
|
37484
|
-
dpr: vglobal.devicePixelRatio
|
|
37485
|
-
}),
|
|
37486
|
-
ctx = c.getContext("2d");
|
|
37487
|
-
return ctx ? (ctx.filter = `blur(${radius}px)`, ctx.drawImage(canvas, 0, 0), ctx.filter = "none", c) : canvas;
|
|
37488
|
-
}
|
|
37489
|
-
applyDownsampleBlur(imageData, radius) {
|
|
37490
|
-
const {
|
|
37491
|
-
width: width,
|
|
37492
|
-
height: height
|
|
37493
|
-
} = imageData,
|
|
37494
|
-
downsample = Math.max(1, Math.floor(radius / 2)),
|
|
37495
|
-
smallWidth = Math.floor(width / downsample),
|
|
37496
|
-
smallHeight = Math.floor(height / downsample),
|
|
37497
|
-
tempCanvas = vglobal.createCanvas({
|
|
37498
|
-
width: smallWidth,
|
|
37499
|
-
height: smallHeight,
|
|
37500
|
-
dpr: 1
|
|
37501
|
-
}),
|
|
37502
|
-
tempCtx = tempCanvas.getContext("2d");
|
|
37503
|
-
if (!tempCtx) return imageData;
|
|
37504
|
-
const originalCanvas = vglobal.createCanvas({
|
|
37505
|
-
width: width,
|
|
37506
|
-
height: height,
|
|
37507
|
-
dpr: 1
|
|
37508
|
-
}),
|
|
37509
|
-
originalCtx = originalCanvas.getContext("2d");
|
|
37510
|
-
return originalCtx ? (originalCtx.putImageData(imageData, 0, 0), tempCtx.drawImage(originalCanvas, 0, 0, smallWidth, smallHeight), tempCtx.filter = `blur(${radius / downsample}px)`, tempCtx.drawImage(tempCanvas, 0, 0), tempCtx.filter = "none", originalCtx.clearRect(0, 0, width, height), originalCtx.drawImage(tempCanvas, 0, 0, width, height), originalCtx.getImageData(0, 0, width, height)) : imageData;
|
|
37511
|
-
}
|
|
37512
|
-
afterStageRender(stage, canvas) {
|
|
37513
|
-
if (this.blurConfig.blurRadius <= 0) return canvas;
|
|
37514
|
-
let result;
|
|
37515
|
-
if (this.blurConfig.useOptimizedBlur) result = this.applyCSSBlur(canvas, this.blurConfig.blurRadius);else {
|
|
37516
|
-
const c = vglobal.createCanvas({
|
|
37517
|
-
width: canvas.width,
|
|
37518
|
-
height: canvas.height,
|
|
37519
|
-
dpr: vglobal.devicePixelRatio
|
|
37520
|
-
}),
|
|
37521
|
-
ctx = c.getContext("2d");
|
|
37522
|
-
if (!ctx) return !1;
|
|
37523
|
-
ctx.clearRect(0, 0, canvas.width, canvas.height), ctx.drawImage(canvas, 0, 0);
|
|
37524
|
-
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height),
|
|
37525
|
-
blurredImageData = this.applyDownsampleBlur(imageData, this.blurConfig.blurRadius);
|
|
37526
|
-
ctx.putImageData(blurredImageData, 0, 0), result = c;
|
|
37527
|
-
}
|
|
37528
|
-
const ctx = result.getContext("2d");
|
|
37529
|
-
return ctx && (ctx.globalCompositeOperation = "overlay", ctx.fillStyle = "rgba(255, 255, 255, 0.1)", ctx.fillRect(0, 0, result.width, result.height), ctx.globalCompositeOperation = "source-over"), result;
|
|
37530
|
-
}
|
|
37531
|
-
}
|
|
37532
|
-
|
|
37533
|
-
class Pixelation extends DisappearAnimateBase {
|
|
37534
|
-
constructor(from, to, duration, easing, params) {
|
|
37535
|
-
var _a, _b;
|
|
37536
|
-
super(from, to, duration, easing, params), this.pixelationConfig = {
|
|
37537
|
-
maxPixelSize: (null === (_a = null == params ? void 0 : params.options) || void 0 === _a ? void 0 : _a.maxPixelSize) || 20,
|
|
37538
|
-
method: (null === (_b = null == params ? void 0 : params.options) || void 0 === _b ? void 0 : _b.method) || "out"
|
|
37539
|
-
};
|
|
37540
|
-
}
|
|
37541
|
-
applyDownsamplePixelation(canvas, pixelSize) {
|
|
37542
|
-
if (pixelSize <= 1) return canvas;
|
|
37543
|
-
const {
|
|
37544
|
-
width: width,
|
|
37545
|
-
height: height
|
|
37546
|
-
} = canvas,
|
|
37547
|
-
smallWidth = Math.ceil(width / pixelSize),
|
|
37548
|
-
smallHeight = Math.ceil(height / pixelSize),
|
|
37549
|
-
smallCanvas = vglobal.createCanvas({
|
|
37550
|
-
width: smallWidth,
|
|
37551
|
-
height: smallHeight,
|
|
37552
|
-
dpr: 1
|
|
37553
|
-
}),
|
|
37554
|
-
smallCtx = smallCanvas.getContext("2d");
|
|
37555
|
-
if (!smallCtx) return canvas;
|
|
37556
|
-
const outputCanvas = vglobal.createCanvas({
|
|
37557
|
-
width: width,
|
|
37558
|
-
height: height,
|
|
37559
|
-
dpr: vglobal.devicePixelRatio
|
|
37560
|
-
}),
|
|
37561
|
-
outputCtx = outputCanvas.getContext("2d");
|
|
37562
|
-
return outputCtx ? (smallCtx.imageSmoothingEnabled = !1, outputCtx.imageSmoothingEnabled = !1, smallCtx.drawImage(canvas, 0, 0, smallWidth, smallHeight), outputCtx.drawImage(smallCanvas, 0, 0, width, height), outputCanvas) : canvas;
|
|
37563
|
-
}
|
|
37564
|
-
updateAnimationProgress() {
|
|
37565
|
-
if ("in" === this.pixelationConfig.method) {
|
|
37566
|
-
return this.pixelationConfig.maxPixelSize - this.currentAnimationRatio * (this.pixelationConfig.maxPixelSize - 1);
|
|
37567
|
-
}
|
|
37568
|
-
return 1 + this.currentAnimationRatio * (this.pixelationConfig.maxPixelSize - 1);
|
|
37569
|
-
}
|
|
37570
|
-
afterStageRender(stage, canvas) {
|
|
37571
|
-
const currentPixelSize = this.updateAnimationProgress();
|
|
37572
|
-
if (currentPixelSize <= 1) return canvas;
|
|
37573
|
-
return this.applyDownsamplePixelation(canvas, currentPixelSize);
|
|
37574
|
-
}
|
|
37575
|
-
}
|
|
37576
|
-
|
|
37577
36252
|
const registerCustomAnimate = () => {
|
|
37578
|
-
AnimateExecutor.registerBuiltInAnimate("increaseCount", IncreaseCount), AnimateExecutor.registerBuiltInAnimate("fromTo", FromTo), AnimateExecutor.registerBuiltInAnimate("scaleIn", ScaleIn), AnimateExecutor.registerBuiltInAnimate("scaleOut", ScaleOut), AnimateExecutor.registerBuiltInAnimate("growHeightIn", GrowHeightIn), AnimateExecutor.registerBuiltInAnimate("growHeightOut", GrowHeightOut), AnimateExecutor.registerBuiltInAnimate("growWidthIn", GrowWidthIn), AnimateExecutor.registerBuiltInAnimate("growWidthOut", GrowWidthOut), AnimateExecutor.registerBuiltInAnimate("growCenterIn", GrowCenterIn), AnimateExecutor.registerBuiltInAnimate("growCenterOut", GrowCenterOut), AnimateExecutor.registerBuiltInAnimate("clipIn", ClipIn), AnimateExecutor.registerBuiltInAnimate("clipOut", ClipOut), AnimateExecutor.registerBuiltInAnimate("fadeIn", FadeIn), AnimateExecutor.registerBuiltInAnimate("fadeOut", FadeOut), AnimateExecutor.registerBuiltInAnimate("growPointsIn", GrowPointsIn), AnimateExecutor.registerBuiltInAnimate("growPointsOut", GrowPointsOut), AnimateExecutor.registerBuiltInAnimate("growPointsXIn", GrowPointsXIn), AnimateExecutor.registerBuiltInAnimate("growPointsXOut", GrowPointsXOut), AnimateExecutor.registerBuiltInAnimate("growPointsYIn", GrowPointsYIn), AnimateExecutor.registerBuiltInAnimate("growPointsYOut", GrowPointsYOut), AnimateExecutor.registerBuiltInAnimate("growAngleIn", GrowAngleIn), AnimateExecutor.registerBuiltInAnimate("growAngleOut", GrowAngleOut), AnimateExecutor.registerBuiltInAnimate("growRadiusIn", GrowRadiusIn), AnimateExecutor.registerBuiltInAnimate("growRadiusOut", GrowRadiusOut), AnimateExecutor.registerBuiltInAnimate("moveIn", MoveIn), AnimateExecutor.registerBuiltInAnimate("moveOut", MoveOut), AnimateExecutor.registerBuiltInAnimate("rotateIn", RotateIn), AnimateExecutor.registerBuiltInAnimate("rotateOut", RotateOut), AnimateExecutor.registerBuiltInAnimate("update", Update), AnimateExecutor.registerBuiltInAnimate("state", State), AnimateExecutor.registerBuiltInAnimate("labelItemAppear", LabelItemAppear), AnimateExecutor.registerBuiltInAnimate("labelItemDisappear", LabelItemDisappear), AnimateExecutor.registerBuiltInAnimate("poptipAppear", PoptipAppear), AnimateExecutor.registerBuiltInAnimate("poptipDisappear", PoptipDisappear), AnimateExecutor.registerBuiltInAnimate("inputText", InputText), AnimateExecutor.registerBuiltInAnimate("inputRichText", InputRichText), AnimateExecutor.registerBuiltInAnimate("outputRichText", OutputRichText), AnimateExecutor.registerBuiltInAnimate("slideRichText", SlideRichText), AnimateExecutor.registerBuiltInAnimate("slideOutRichText", SlideOutRichText), AnimateExecutor.registerBuiltInAnimate("slideIn", SlideIn), AnimateExecutor.registerBuiltInAnimate("growIn", GrowIn), AnimateExecutor.registerBuiltInAnimate("spinIn", SpinIn), AnimateExecutor.registerBuiltInAnimate("moveScaleIn", MoveScaleIn), AnimateExecutor.registerBuiltInAnimate("moveRotateIn", MoveRotateIn), AnimateExecutor.registerBuiltInAnimate("strokeIn", StrokeIn), AnimateExecutor.registerBuiltInAnimate("slideOut", SlideOut), AnimateExecutor.registerBuiltInAnimate("growOut", GrowOut), AnimateExecutor.registerBuiltInAnimate("spinOut", SpinOut), AnimateExecutor.registerBuiltInAnimate("moveScaleOut", MoveScaleOut), AnimateExecutor.registerBuiltInAnimate("moveRotateOut", MoveRotateOut), AnimateExecutor.registerBuiltInAnimate("strokeOut", StrokeOut), AnimateExecutor.registerBuiltInAnimate("pulse", PulseAnimate), AnimateExecutor.registerBuiltInAnimate("MotionPath", MotionPath), AnimateExecutor.registerBuiltInAnimate("streamLight", StreamLight)
|
|
36253
|
+
AnimateExecutor.registerBuiltInAnimate("increaseCount", IncreaseCount), AnimateExecutor.registerBuiltInAnimate("fromTo", FromTo), AnimateExecutor.registerBuiltInAnimate("scaleIn", ScaleIn), AnimateExecutor.registerBuiltInAnimate("scaleOut", ScaleOut), AnimateExecutor.registerBuiltInAnimate("growHeightIn", GrowHeightIn), AnimateExecutor.registerBuiltInAnimate("growHeightOut", GrowHeightOut), AnimateExecutor.registerBuiltInAnimate("growWidthIn", GrowWidthIn), AnimateExecutor.registerBuiltInAnimate("growWidthOut", GrowWidthOut), AnimateExecutor.registerBuiltInAnimate("growCenterIn", GrowCenterIn), AnimateExecutor.registerBuiltInAnimate("growCenterOut", GrowCenterOut), AnimateExecutor.registerBuiltInAnimate("clipIn", ClipIn), AnimateExecutor.registerBuiltInAnimate("clipOut", ClipOut), AnimateExecutor.registerBuiltInAnimate("fadeIn", FadeIn), AnimateExecutor.registerBuiltInAnimate("fadeOut", FadeOut), AnimateExecutor.registerBuiltInAnimate("growPointsIn", GrowPointsIn), AnimateExecutor.registerBuiltInAnimate("growPointsOut", GrowPointsOut), AnimateExecutor.registerBuiltInAnimate("growPointsXIn", GrowPointsXIn), AnimateExecutor.registerBuiltInAnimate("growPointsXOut", GrowPointsXOut), AnimateExecutor.registerBuiltInAnimate("growPointsYIn", GrowPointsYIn), AnimateExecutor.registerBuiltInAnimate("growPointsYOut", GrowPointsYOut), AnimateExecutor.registerBuiltInAnimate("growAngleIn", GrowAngleIn), AnimateExecutor.registerBuiltInAnimate("growAngleOut", GrowAngleOut), AnimateExecutor.registerBuiltInAnimate("growRadiusIn", GrowRadiusIn), AnimateExecutor.registerBuiltInAnimate("growRadiusOut", GrowRadiusOut), AnimateExecutor.registerBuiltInAnimate("moveIn", MoveIn), AnimateExecutor.registerBuiltInAnimate("moveOut", MoveOut), AnimateExecutor.registerBuiltInAnimate("rotateIn", RotateIn), AnimateExecutor.registerBuiltInAnimate("rotateOut", RotateOut), AnimateExecutor.registerBuiltInAnimate("update", Update), AnimateExecutor.registerBuiltInAnimate("state", State), AnimateExecutor.registerBuiltInAnimate("labelItemAppear", LabelItemAppear), AnimateExecutor.registerBuiltInAnimate("labelItemDisappear", LabelItemDisappear), AnimateExecutor.registerBuiltInAnimate("poptipAppear", PoptipAppear), AnimateExecutor.registerBuiltInAnimate("poptipDisappear", PoptipDisappear), AnimateExecutor.registerBuiltInAnimate("inputText", InputText), AnimateExecutor.registerBuiltInAnimate("inputRichText", InputRichText), AnimateExecutor.registerBuiltInAnimate("outputRichText", OutputRichText), AnimateExecutor.registerBuiltInAnimate("slideRichText", SlideRichText), AnimateExecutor.registerBuiltInAnimate("slideOutRichText", SlideOutRichText), AnimateExecutor.registerBuiltInAnimate("slideIn", SlideIn), AnimateExecutor.registerBuiltInAnimate("growIn", GrowIn), AnimateExecutor.registerBuiltInAnimate("spinIn", SpinIn), AnimateExecutor.registerBuiltInAnimate("moveScaleIn", MoveScaleIn), AnimateExecutor.registerBuiltInAnimate("moveRotateIn", MoveRotateIn), AnimateExecutor.registerBuiltInAnimate("strokeIn", StrokeIn), AnimateExecutor.registerBuiltInAnimate("slideOut", SlideOut), AnimateExecutor.registerBuiltInAnimate("growOut", GrowOut), AnimateExecutor.registerBuiltInAnimate("spinOut", SpinOut), AnimateExecutor.registerBuiltInAnimate("moveScaleOut", MoveScaleOut), AnimateExecutor.registerBuiltInAnimate("moveRotateOut", MoveRotateOut), AnimateExecutor.registerBuiltInAnimate("strokeOut", StrokeOut), AnimateExecutor.registerBuiltInAnimate("pulse", PulseAnimate), AnimateExecutor.registerBuiltInAnimate("MotionPath", MotionPath), AnimateExecutor.registerBuiltInAnimate("streamLight", StreamLight);
|
|
37579
36254
|
};
|
|
37580
36255
|
|
|
37581
36256
|
class AxisEnter extends AComponentAnimate {
|
|
@@ -40610,22 +39285,19 @@
|
|
|
40610
39285
|
const {
|
|
40611
39286
|
clampForce = !0,
|
|
40612
39287
|
hideOnHit = !0,
|
|
40613
|
-
hideOnOverflow = !1,
|
|
40614
39288
|
overlapPadding: overlapPadding,
|
|
40615
39289
|
strategy: strategy
|
|
40616
39290
|
} = option;
|
|
40617
|
-
if (clampForce
|
|
39291
|
+
if (clampForce) for (let i = 0; i < result.length; i++) {
|
|
40618
39292
|
const text = labels[i],
|
|
40619
39293
|
{
|
|
40620
39294
|
dx = 0,
|
|
40621
39295
|
dy = 0
|
|
40622
39296
|
} = clampText(text, bmpTool.width, bmpTool.height, bmpTool.padding);
|
|
40623
|
-
0 === dx && 0 === dy || (
|
|
40624
|
-
visible: !1
|
|
40625
|
-
}) : (text.setAttributes({
|
|
39297
|
+
0 === dx && 0 === dy || (text.setAttributes({
|
|
40626
39298
|
x: text.attribute.x + dx,
|
|
40627
39299
|
y: text.attribute.y + dy
|
|
40628
|
-
}), text._isClamped = !0)
|
|
39300
|
+
}), text._isClamped = !0);
|
|
40629
39301
|
}
|
|
40630
39302
|
result = shiftY(result, Object.assign(Object.assign({
|
|
40631
39303
|
maxY: bmpTool.height
|
|
@@ -40641,9 +39313,9 @@
|
|
|
40641
39313
|
bounds = text.AABBBounds,
|
|
40642
39314
|
range = boundToRange(bmpTool, bounds, !0);
|
|
40643
39315
|
if (canPlace(bmpTool, bitmap, bounds, clampForce, overlapPadding)) bitmap.setRange(range);else {
|
|
40644
|
-
if (
|
|
40645
|
-
if (this.
|
|
40646
|
-
}
|
|
39316
|
+
if (clampForce) {
|
|
39317
|
+
if (this._processClampForce(text, bmpTool, bitmap, overlapPadding)) continue;
|
|
39318
|
+
}
|
|
40647
39319
|
hideOnHit ? text.setAttributes({
|
|
40648
39320
|
visible: !1
|
|
40649
39321
|
}) : bitmap.setRange(range);
|
|
@@ -40651,15 +39323,6 @@
|
|
|
40651
39323
|
}
|
|
40652
39324
|
return result;
|
|
40653
39325
|
}
|
|
40654
|
-
_processHideOnOverflow(text, bmpTool) {
|
|
40655
|
-
const {
|
|
40656
|
-
dy = 0,
|
|
40657
|
-
dx = 0
|
|
40658
|
-
} = clampText(text, bmpTool.width, bmpTool.height, bmpTool.padding);
|
|
40659
|
-
return 0 === dx && 0 === dy || (text.setAttributes({
|
|
40660
|
-
visible: !1
|
|
40661
|
-
}), !1);
|
|
40662
|
-
}
|
|
40663
39326
|
_processClampForce(text, bmpTool, bitmap, overlapPadding = 0) {
|
|
40664
39327
|
const {
|
|
40665
39328
|
dy = 0,
|
|
@@ -40686,8 +39349,7 @@
|
|
|
40686
39349
|
hideOnHit = !0,
|
|
40687
39350
|
clampForce = !0,
|
|
40688
39351
|
avoidMarks = [],
|
|
40689
|
-
overlapPadding: overlapPadding
|
|
40690
|
-
hideOnOverflow = !1
|
|
39352
|
+
overlapPadding: overlapPadding
|
|
40691
39353
|
} = option,
|
|
40692
39354
|
result = [],
|
|
40693
39355
|
checkBounds = strategy.some(s => "bound" === s.type);
|
|
@@ -40714,16 +39376,15 @@
|
|
|
40714
39376
|
}
|
|
40715
39377
|
}
|
|
40716
39378
|
let hasPlace = !1;
|
|
40717
|
-
for (let j = 0; j < strategy.length; j++) if (hasPlace = place$2(bmpTool, bitmap, strategy[j], this.attribute, text, this._isCollectionBase ? this.getGraphicBounds(null, this._idToPoint.get(labels[i].attribute.id)) : this.getGraphicBounds(baseMark, labels[i].attribute), this.labeling), !1 !== hasPlace
|
|
40718
|
-
|
|
40719
|
-
|
|
40720
|
-
|
|
40721
|
-
result.push(text);
|
|
39379
|
+
for (let j = 0; j < strategy.length; j++) if (hasPlace = place$2(bmpTool, bitmap, strategy[j], this.attribute, text, this._isCollectionBase ? this.getGraphicBounds(null, this._idToPoint.get(labels[i].attribute.id)) : this.getGraphicBounds(baseMark, labels[i].attribute), this.labeling), !1 !== hasPlace) {
|
|
39380
|
+
text.setAttributes({
|
|
39381
|
+
x: hasPlace.x,
|
|
39382
|
+
y: hasPlace.y
|
|
39383
|
+
}), result.push(text);
|
|
40722
39384
|
break;
|
|
40723
39385
|
}
|
|
40724
|
-
if (!hasPlace) {
|
|
40725
|
-
if (
|
|
40726
|
-
if (clampForce && this._processClampForce(text, bmpTool, bitmap, overlapPadding)) {
|
|
39386
|
+
if (!hasPlace && clampForce) {
|
|
39387
|
+
if (this._processClampForce(text, bmpTool, bitmap, overlapPadding)) {
|
|
40727
39388
|
result.push(text);
|
|
40728
39389
|
continue;
|
|
40729
39390
|
}
|
|
@@ -49544,9 +48205,6 @@
|
|
|
49544
48205
|
static registerChartPlugin(key, plugin) {
|
|
49545
48206
|
Factory._chartPlugin[key] = plugin;
|
|
49546
48207
|
}
|
|
49547
|
-
static registerVChartPlugin(key, plugin) {
|
|
49548
|
-
Factory._vChartPlugin[key] = plugin;
|
|
49549
|
-
}
|
|
49550
48208
|
static registerComponentPlugin(key, plugin) {
|
|
49551
48209
|
Factory._componentPlugin[key] = plugin;
|
|
49552
48210
|
}
|
|
@@ -49663,9 +48321,6 @@
|
|
|
49663
48321
|
static getChartPlugins() {
|
|
49664
48322
|
return Object.values(Factory._chartPlugin);
|
|
49665
48323
|
}
|
|
49666
|
-
static getVChartPlugins() {
|
|
49667
|
-
return Object.values(Factory._vChartPlugin);
|
|
49668
|
-
}
|
|
49669
48324
|
static getComponentPlugins() {
|
|
49670
48325
|
return Object.values(Factory._componentPlugin);
|
|
49671
48326
|
}
|
|
@@ -49701,7 +48356,6 @@
|
|
|
49701
48356
|
Factory._animations = {};
|
|
49702
48357
|
Factory._implements = {};
|
|
49703
48358
|
Factory._chartPlugin = {};
|
|
49704
|
-
Factory._vChartPlugin = {};
|
|
49705
48359
|
Factory._componentPlugin = {};
|
|
49706
48360
|
Factory.transforms = {
|
|
49707
48361
|
fields: fields,
|
|
@@ -50503,7 +49157,7 @@
|
|
|
50503
49157
|
}
|
|
50504
49158
|
function transformToGraphic(style) {
|
|
50505
49159
|
if (style === null || style === void 0 ? void 0 : style.angle) {
|
|
50506
|
-
|
|
49160
|
+
style.angle = degreeToRadian(style.angle);
|
|
50507
49161
|
}
|
|
50508
49162
|
return style;
|
|
50509
49163
|
}
|
|
@@ -50778,7 +49432,6 @@
|
|
|
50778
49432
|
ChartEvent["afterRender"] = "afterRender";
|
|
50779
49433
|
ChartEvent["afterLayout"] = "afterLayout";
|
|
50780
49434
|
ChartEvent["afterMarkLayoutEnd"] = "afterMarkLayoutEnd";
|
|
50781
|
-
ChartEvent["afterWordcloudShapeDraw"] = "afterWordcloudShapeDraw";
|
|
50782
49435
|
})(exports.ChartEvent || (exports.ChartEvent = {}));
|
|
50783
49436
|
var Event_Source_Type;
|
|
50784
49437
|
(function (Event_Source_Type) {
|
|
@@ -51070,13 +49723,21 @@
|
|
|
51070
49723
|
}
|
|
51071
49724
|
return true;
|
|
51072
49725
|
}
|
|
49726
|
+
_prepareParams(filter, params) {
|
|
49727
|
+
var _a, _b, _c;
|
|
49728
|
+
if (filter.markName && params.mark) {
|
|
49729
|
+
const markGraphic = (_c = (_b = (_a = params.mark).getGraphics) === null || _b === void 0 ? void 0 : _b.call(_a)) === null || _c === void 0 ? void 0 : _c[0];
|
|
49730
|
+
return Object.assign(Object.assign({}, params), { item: markGraphic, datum: getDatumOfGraphic(markGraphic) });
|
|
49731
|
+
}
|
|
49732
|
+
return Object.assign({}, params);
|
|
49733
|
+
}
|
|
51073
49734
|
_invoke(handlers, type, params) {
|
|
51074
49735
|
const result = handlers.map(handler => {
|
|
51075
49736
|
var _a, _b, _c;
|
|
51076
49737
|
const filter = handler.filter;
|
|
51077
49738
|
if (!handler.prevented && (!handler.query || this._filter(filter, type, params))) {
|
|
51078
49739
|
const callback = handler.wrappedCallback || handler.callback;
|
|
51079
|
-
const stopBubble = callback.call(null,
|
|
49740
|
+
const stopBubble = callback.call(null, this._prepareParams(filter, params));
|
|
51080
49741
|
const doStopBubble = stopBubble !== null && stopBubble !== void 0 ? stopBubble : (_a = handler.query) === null || _a === void 0 ? void 0 : _a.consume;
|
|
51081
49742
|
if (doStopBubble) {
|
|
51082
49743
|
(_b = params.event) === null || _b === void 0 ? void 0 : _b.stopPropagation();
|
|
@@ -51606,7 +50267,7 @@
|
|
|
51606
50267
|
(_b = (_a = this._compileChart) === null || _a === void 0 ? void 0 : _a.getEvent()) === null || _b === void 0 ? void 0 : _b.emit(exports.ChartEvent.afterRender, { chart: this._compileChart });
|
|
51607
50268
|
};
|
|
51608
50269
|
this._handleAfterNextRender = () => {
|
|
51609
|
-
var _a, _b
|
|
50270
|
+
var _a, _b;
|
|
51610
50271
|
if (this._stage && !this._option.disableDirtyBounds) {
|
|
51611
50272
|
this._stage.enableDirtyBounds();
|
|
51612
50273
|
}
|
|
@@ -51616,7 +50277,6 @@
|
|
|
51616
50277
|
vchart: (_b = this._compileChart.getOption()) === null || _b === void 0 ? void 0 : _b.globalInstance
|
|
51617
50278
|
});
|
|
51618
50279
|
}
|
|
51619
|
-
(_d = (_c = this._option.performanceHook) === null || _c === void 0 ? void 0 : _c.afterVRenderDraw) === null || _d === void 0 ? void 0 : _d.call(_c, this._compileChart.getOption().globalInstance);
|
|
51620
50280
|
};
|
|
51621
50281
|
this.handleProgressiveFrame = () => {
|
|
51622
50282
|
if (this._progressiveMarks.length) {
|
|
@@ -51766,7 +50426,6 @@
|
|
|
51766
50426
|
});
|
|
51767
50427
|
}
|
|
51768
50428
|
_doRender(immediately) {
|
|
51769
|
-
var _a, _b, _c, _d;
|
|
51770
50429
|
if (this._stage) {
|
|
51771
50430
|
this._rootMarks.forEach(g => {
|
|
51772
50431
|
traverseGroupMark(g, m => {
|
|
@@ -51779,12 +50438,10 @@
|
|
|
51779
50438
|
}
|
|
51780
50439
|
}, null, true);
|
|
51781
50440
|
});
|
|
51782
|
-
(_b = (_a = this._option.performanceHook) === null || _a === void 0 ? void 0 : _a.beforeVRenderDraw) === null || _b === void 0 ? void 0 : _b.call(_a, this._compileChart.getOption().globalInstance);
|
|
51783
50441
|
this._stage.disableDirtyBounds();
|
|
51784
50442
|
this._stage.afterNextRender(this._handleAfterNextRender);
|
|
51785
50443
|
if (immediately) {
|
|
51786
50444
|
this._stage.render();
|
|
51787
|
-
(_d = (_c = this._option.performanceHook) === null || _c === void 0 ? void 0 : _c.afterVRenderDraw) === null || _d === void 0 ? void 0 : _d.call(_c, this._compileChart.getOption().globalInstance);
|
|
51788
50445
|
}
|
|
51789
50446
|
}
|
|
51790
50447
|
}
|
|
@@ -56853,22 +55510,6 @@
|
|
|
56853
55510
|
Factory.registerInteractionTrigger(ElementSelect.type, ElementSelect);
|
|
56854
55511
|
};
|
|
56855
55512
|
|
|
56856
|
-
class VChartPluginService extends BasePluginService {
|
|
56857
|
-
constructor(globalInstance) {
|
|
56858
|
-
super();
|
|
56859
|
-
this.globalInstance = globalInstance;
|
|
56860
|
-
}
|
|
56861
|
-
onInit() {
|
|
56862
|
-
this._plugins.forEach(plugin => {
|
|
56863
|
-
plugin.onInit && plugin.onInit(this);
|
|
56864
|
-
});
|
|
56865
|
-
}
|
|
56866
|
-
releaseAll() {
|
|
56867
|
-
super.releaseAll();
|
|
56868
|
-
this.globalInstance = null;
|
|
56869
|
-
}
|
|
56870
|
-
}
|
|
56871
|
-
|
|
56872
55513
|
class VChart {
|
|
56873
55514
|
static useRegisters(comps) {
|
|
56874
55515
|
comps.forEach((fn) => {
|
|
@@ -56950,9 +55591,6 @@
|
|
|
56950
55591
|
getSpecInfo() {
|
|
56951
55592
|
return this._specInfo;
|
|
56952
55593
|
}
|
|
56953
|
-
get event() {
|
|
56954
|
-
return this._event;
|
|
56955
|
-
}
|
|
56956
55594
|
getDataSet() {
|
|
56957
55595
|
return this._dataSet;
|
|
56958
55596
|
}
|
|
@@ -58157,12 +56795,6 @@
|
|
|
58157
56795
|
this._chartPlugin.load(pluginList.map(p => new p()));
|
|
58158
56796
|
this._chartPluginApply('onInit', this._spec);
|
|
58159
56797
|
}
|
|
58160
|
-
const vChartPluginList = Factory.getVChartPlugins();
|
|
58161
|
-
if (vChartPluginList.length > 0) {
|
|
58162
|
-
this._vChartPlugin = new VChartPluginService(this);
|
|
58163
|
-
this._vChartPlugin.load(vChartPluginList.map(p => new p()));
|
|
58164
|
-
this._vChartPlugin.onInit();
|
|
58165
|
-
}
|
|
58166
56798
|
}
|
|
58167
56799
|
_chartPluginApply(funcName, ...args) {
|
|
58168
56800
|
if (!this._chartPlugin || !this._chartPlugin[funcName]) {
|
|
@@ -58315,7 +56947,7 @@
|
|
|
58315
56947
|
});
|
|
58316
56948
|
};
|
|
58317
56949
|
|
|
58318
|
-
const version = "2.0.4-alpha.
|
|
56950
|
+
const version = "2.0.4-alpha.8";
|
|
58319
56951
|
|
|
58320
56952
|
const addVChartProperty = (data, op) => {
|
|
58321
56953
|
const context = op.beforeCall();
|
|
@@ -66249,7 +64881,7 @@
|
|
|
66249
64881
|
this._event = new Event$1(option.eventDispatcher, option.mode);
|
|
66250
64882
|
this._dataSet = option.dataSet;
|
|
66251
64883
|
this._chartData = new ChartData(this._dataSet);
|
|
66252
|
-
this._modelOption = Object.assign(Object.assign({}, option), { mode: this._option.mode, map: this._idMap, getChartLayoutRect: () => this._layoutRect, getChartViewRect: () => this._viewRect, getChart: () => this, globalScale: this._globalScale, onError: (_b = this._option) === null || _b === void 0 ? void 0 : _b.onError, disableTriggerEvent: ((_c = this._option) === null || _c === void 0 ? void 0 : _c.disableTriggerEvent) === true, getSeriesData: this._chartData.getSeriesData.bind(this._chartData)
|
|
64884
|
+
this._modelOption = Object.assign(Object.assign({}, option), { mode: this._option.mode, map: this._idMap, getChartLayoutRect: () => this._layoutRect, getChartViewRect: () => this._viewRect, getChart: () => this, globalScale: this._globalScale, onError: (_b = this._option) === null || _b === void 0 ? void 0 : _b.onError, disableTriggerEvent: ((_c = this._option) === null || _c === void 0 ? void 0 : _c.disableTriggerEvent) === true, getSeriesData: this._chartData.getSeriesData.bind(this._chartData) });
|
|
66253
64885
|
if (this._setModelOption) {
|
|
66254
64886
|
this._setModelOption();
|
|
66255
64887
|
}
|
|
@@ -77866,26 +76498,6 @@
|
|
|
77866
76498
|
isNil$1(this._maskShape.fontFamily)
|
|
77867
76499
|
? Object.assign({ fontFamily: this._option.getTheme('fontFamily') }, this._maskShape) : this._maskShape,
|
|
77868
76500
|
onUpdateMaskCanvas: this.handleMaskCanvasUpdate,
|
|
77869
|
-
onLayoutFinished: () => {
|
|
77870
|
-
const afterWordcloudShapeDraw = () => {
|
|
77871
|
-
var _a, _b, _c, _d;
|
|
77872
|
-
this._option.globalInstance.getStage().hooks.afterRender.taps = this._option.globalInstance
|
|
77873
|
-
.getStage()
|
|
77874
|
-
.hooks.afterRender.taps.filter(tap => tap.fn !== afterWordcloudShapeDraw);
|
|
77875
|
-
(_b = (_a = this._option).dispatchEvent) === null || _b === void 0 ? void 0 : _b.call(_a, exports.ChartEvent.afterWordcloudShapeDraw, {
|
|
77876
|
-
instance: this._option.globalInstance
|
|
77877
|
-
});
|
|
77878
|
-
(_d = (_c = this._option.globalInstance
|
|
77879
|
-
.getChart()
|
|
77880
|
-
.getOption()
|
|
77881
|
-
.performanceHook) === null || _c === void 0 ? void 0 : _c.afterWordcloudShapeDraw) === null || _d === void 0 ? void 0 : _d.call(_c, this._option.globalInstance);
|
|
77882
|
-
};
|
|
77883
|
-
this._option.globalInstance.getStage().hooks.afterRender.taps.push({
|
|
77884
|
-
type: 'sync',
|
|
77885
|
-
name: 'afterWordcloudShapeDraw',
|
|
77886
|
-
fn: afterWordcloudShapeDraw
|
|
77887
|
-
});
|
|
77888
|
-
},
|
|
77889
76501
|
dataIndexKey: DEFAULT_DATA_KEY,
|
|
77890
76502
|
text: wordSpec.formatMethod
|
|
77891
76503
|
? (datum) => {
|
|
@@ -85637,7 +84249,7 @@
|
|
|
85637
84249
|
});
|
|
85638
84250
|
[this._labelMark, this._nonLeafLabelMark].forEach(m => {
|
|
85639
84251
|
if (m && m.getComponent()) {
|
|
85640
|
-
m.getComponent().getProduct().enableAnimation();
|
|
84252
|
+
m.getComponent().getProduct().getGroupGraphicItem().enableAnimation();
|
|
85641
84253
|
}
|
|
85642
84254
|
});
|
|
85643
84255
|
this.event.off(HOOK_EVENT.AFTER_DO_RENDER, this._enableAnimationHook);
|
|
@@ -85647,7 +84259,7 @@
|
|
|
85647
84259
|
});
|
|
85648
84260
|
[this._labelMark, this._nonLeafLabelMark].forEach(m => {
|
|
85649
84261
|
if (m && m.getComponent()) {
|
|
85650
|
-
m.getComponent().getProduct().disableAnimation();
|
|
84262
|
+
m.getComponent().getProduct().getGroupGraphicItem().disableAnimation();
|
|
85651
84263
|
}
|
|
85652
84264
|
});
|
|
85653
84265
|
}
|
|
@@ -89583,8 +88195,6 @@
|
|
|
89583
88195
|
var _a, _b;
|
|
89584
88196
|
const series = super._getDefaultSeriesSpec(spec);
|
|
89585
88197
|
series.area = spec.area;
|
|
89586
|
-
series.point = spec.point;
|
|
89587
|
-
series.line = spec.line;
|
|
89588
88198
|
if (spec.direction === "horizontal") {
|
|
89589
88199
|
series.xField = (_a = spec.xField) !== null && _a !== void 0 ? _a : [spec.minField, spec.maxField];
|
|
89590
88200
|
}
|
|
@@ -93040,19 +91650,16 @@
|
|
|
93040
91650
|
return active && hasChange;
|
|
93041
91651
|
};
|
|
93042
91652
|
this._handleChartDrag = (delta, e) => {
|
|
93043
|
-
var _a
|
|
91653
|
+
var _a;
|
|
93044
91654
|
if (!this._activeRoam || (this._dragAttr.filter && !this._dragAttr.filter(delta, e))) {
|
|
93045
91655
|
return;
|
|
93046
91656
|
}
|
|
93047
|
-
if ((_a = this._spec.roamDrag) === null || _a === void 0 ? void 0 : _a.autoVisible) {
|
|
93048
|
-
this.show();
|
|
93049
|
-
}
|
|
93050
91657
|
const [dx, dy] = delta;
|
|
93051
91658
|
let value = this._isHorizontal ? dx : dy;
|
|
93052
91659
|
if (this._dragAttr.reverse) {
|
|
93053
91660
|
value = -value;
|
|
93054
91661
|
}
|
|
93055
|
-
this._handleChartMove(value, (
|
|
91662
|
+
this._handleChartMove(value, (_a = this._dragAttr.rate) !== null && _a !== void 0 ? _a : 1);
|
|
93056
91663
|
};
|
|
93057
91664
|
this._handleChartMove = (value, rate) => {
|
|
93058
91665
|
const totalValue = this._isHorizontal ? this.getLayoutRect().width : this.getLayoutRect().height;
|
|
@@ -93457,9 +92064,9 @@
|
|
|
93457
92064
|
return allDomain.slice(Math.min(startIndex, endIndex), Math.max(startIndex, endIndex) + 1);
|
|
93458
92065
|
}
|
|
93459
92066
|
_initCommonEvent() {
|
|
93460
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
92067
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
93461
92068
|
const delayType = (_b = (_a = this._spec) === null || _a === void 0 ? void 0 : _a.delayType) !== null && _b !== void 0 ? _b : 'throttle';
|
|
93462
|
-
const delayTime = isValid$1((_c = this._spec) === null || _c === void 0 ? void 0 : _c.delayType) ? (
|
|
92069
|
+
const delayTime = isValid$1((_c = this._spec) === null || _c === void 0 ? void 0 : _c.delayType) ? (_e = (_d = this._spec) === null || _d === void 0 ? void 0 : _d.delayTime) !== null && _e !== void 0 ? _e : 30 : 0;
|
|
93463
92070
|
const realTime = (_g = (_f = this._spec) === null || _f === void 0 ? void 0 : _f.realTime) !== null && _g !== void 0 ? _g : true;
|
|
93464
92071
|
const option = { delayType, delayTime, realTime, allowComponentZoom: true };
|
|
93465
92072
|
if (this._zoomAttr.enable) {
|
|
@@ -93471,13 +92078,6 @@
|
|
|
93471
92078
|
if (this._dragAttr.enable) {
|
|
93472
92079
|
this.initDragEventOfRegions(this._regions, null, this._handleChartDrag, option);
|
|
93473
92080
|
}
|
|
93474
|
-
if ((_h = this._spec.roamDrag) === null || _h === void 0 ? void 0 : _h.autoVisible) {
|
|
93475
|
-
const dragEnd = 'panend';
|
|
93476
|
-
this._throttledHide = throttle(() => this.hide(), 300);
|
|
93477
|
-
this.event.on(dragEnd, () => {
|
|
93478
|
-
this._throttledHide();
|
|
93479
|
-
});
|
|
93480
|
-
}
|
|
93481
92081
|
}
|
|
93482
92082
|
updateLayoutAttribute() {
|
|
93483
92083
|
if (this._visible) {
|
|
@@ -93598,9 +92198,6 @@
|
|
|
93598
92198
|
_getNeedClearVRenderComponents() {
|
|
93599
92199
|
return [this._component];
|
|
93600
92200
|
}
|
|
93601
|
-
clear() {
|
|
93602
|
-
this._throttledHide = null;
|
|
93603
|
-
}
|
|
93604
92201
|
}
|
|
93605
92202
|
mixin(DataFilterBaseComponent, Zoomable);
|
|
93606
92203
|
|
|
@@ -97678,7 +96275,7 @@ C0.3-1.4,0.3-1.4,0.3-1.4z;`;
|
|
|
97678
96275
|
this.coordinateType = 'cartesian';
|
|
97679
96276
|
}
|
|
97680
96277
|
_computePointsAttr() {
|
|
97681
|
-
var _a
|
|
96278
|
+
var _a;
|
|
97682
96279
|
const spec = this._spec;
|
|
97683
96280
|
const data = this._markerData;
|
|
97684
96281
|
const relativeSeries = this._relativeSeries;
|
|
@@ -97688,7 +96285,7 @@ C0.3-1.4,0.3-1.4,0.3-1.4z;`;
|
|
|
97688
96285
|
const autoRange = (_a = spec === null || spec === void 0 ? void 0 : spec.autoRange) !== null && _a !== void 0 ? _a : false;
|
|
97689
96286
|
let point;
|
|
97690
96287
|
if (isXYLayout) {
|
|
97691
|
-
point =
|
|
96288
|
+
point = xyLayout(data, relativeSeries, relativeSeries, relativeSeries, autoRange)[0][0];
|
|
97692
96289
|
}
|
|
97693
96290
|
else if (isCoordinateLayout) {
|
|
97694
96291
|
point = cartesianCoordinateLayout(data, relativeSeries, autoRange, spec.coordinatesOffset)[0];
|
|
@@ -98530,13 +97127,14 @@ C0.3-1.4,0.3-1.4,0.3-1.4z;`;
|
|
|
98530
97127
|
getVRenderComponents() {
|
|
98531
97128
|
const comps = [];
|
|
98532
97129
|
const checkFunc = (m) => {
|
|
97130
|
+
var _a;
|
|
98533
97131
|
if (m && m.type === "group") {
|
|
98534
97132
|
m.getMarks().forEach(child => {
|
|
98535
97133
|
checkFunc(child);
|
|
98536
97134
|
});
|
|
98537
97135
|
}
|
|
98538
97136
|
else if (m.type === "component") {
|
|
98539
|
-
const comp = m === null || m === void 0 ? void 0 : m.
|
|
97137
|
+
const comp = (_a = m === null || m === void 0 ? void 0 : m.getProduct()) === null || _a === void 0 ? void 0 : _a.getGroupGraphicItem();
|
|
98540
97138
|
if (comp) {
|
|
98541
97139
|
comps.push(comp);
|
|
98542
97140
|
}
|
|
@@ -99541,7 +98139,7 @@ C0.3-1.4,0.3-1.4,0.3-1.4z;`;
|
|
|
99541
98139
|
this._container = null;
|
|
99542
98140
|
}
|
|
99543
98141
|
_updateTooltip(visible, params) {
|
|
99544
|
-
var _a, _b;
|
|
98142
|
+
var _a, _b, _c;
|
|
99545
98143
|
if (!visible || !this._rootDom) {
|
|
99546
98144
|
this.setVisibility(visible);
|
|
99547
98145
|
this._cacheCustomTooltipPosition = undefined;
|
|
@@ -99551,26 +98149,29 @@ C0.3-1.4,0.3-1.4,0.3-1.4z;`;
|
|
|
99551
98149
|
if (!params.changePositionOnly) {
|
|
99552
98150
|
this._tooltipActual = activeTooltipSpec;
|
|
99553
98151
|
}
|
|
98152
|
+
const currentVisible = this.getVisibility();
|
|
99554
98153
|
const el = this._rootDom;
|
|
99555
98154
|
if (el) {
|
|
99556
98155
|
const { x = 0, y = 0 } = (_a = activeTooltipSpec.position) !== null && _a !== void 0 ? _a : {};
|
|
99557
|
-
let position = { x, y };
|
|
99558
|
-
const currentVisible = this.getVisibility();
|
|
99559
98156
|
if (tooltipSpec.updateElement) {
|
|
99560
98157
|
this._updatePosition((_b = this._cacheCustomTooltipPosition) !== null && _b !== void 0 ? _b : { x, y });
|
|
99561
98158
|
tooltipSpec.updateElement(el, activeTooltipSpec, params);
|
|
99562
|
-
position = this._getActualTooltipPosition(activeTooltipSpec, params, {
|
|
98159
|
+
const position = this._getActualTooltipPosition(activeTooltipSpec, params, {
|
|
99563
98160
|
width: el.offsetWidth,
|
|
99564
98161
|
height: el.offsetHeight
|
|
99565
98162
|
});
|
|
98163
|
+
this._updatePosition(position);
|
|
99566
98164
|
this._cacheCustomTooltipPosition = position;
|
|
99567
98165
|
}
|
|
99568
|
-
|
|
99569
|
-
|
|
99570
|
-
|
|
99571
|
-
|
|
98166
|
+
else {
|
|
98167
|
+
if (!currentVisible) {
|
|
98168
|
+
this._rootDom.style.transitionDuration = '0ms';
|
|
98169
|
+
}
|
|
98170
|
+
else {
|
|
98171
|
+
this._rootDom.style.transitionDuration = (_c = this._domStyle.panel.transitionDuration) !== null && _c !== void 0 ? _c : 'initial';
|
|
98172
|
+
}
|
|
98173
|
+
this._updatePosition({ x, y });
|
|
99572
98174
|
}
|
|
99573
|
-
this._updatePosition(position);
|
|
99574
98175
|
}
|
|
99575
98176
|
this.setVisibility(visible);
|
|
99576
98177
|
}
|
|
@@ -99748,13 +98349,9 @@ C0.3-1.4,0.3-1.4,0.3-1.4z;`;
|
|
|
99748
98349
|
this._updateDomStyle('height', false);
|
|
99749
98350
|
}
|
|
99750
98351
|
}
|
|
99751
|
-
_updatePosition({ x, y }
|
|
98352
|
+
_updatePosition({ x, y }) {
|
|
99752
98353
|
if (this._rootDom) {
|
|
99753
98354
|
this._rootDom.style.transform = `translate3d(${x}px, ${y}px, 0)`;
|
|
99754
|
-
if (resetTransition && this._rootDom.style.transition !== '') {
|
|
99755
|
-
this._rootDom.style.transition = '';
|
|
99756
|
-
Object.assign(this._rootDom.style, this._domStyle.panel);
|
|
99757
|
-
}
|
|
99758
98355
|
}
|
|
99759
98356
|
}
|
|
99760
98357
|
}
|