From 8634ef138fdc4cf2ae717ae18ff06f384cea1ba0 Mon Sep 17 00:00:00 2001 From: Rui-Sun Date: Mon, 6 Jan 2025 14:24:05 +0800 Subject: [PATCH] feat: add isImageAnonymous in global --- .../feat-isImageAnonymous_2025-01-06-06-22.json | 10 ++++++++++ packages/vrender-core/src/core/global.ts | 9 +++++++++ packages/vrender-core/src/interface/global.ts | 2 ++ .../src/env/contributions/browser-contribution.ts | 6 ++++-- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 common/changes/@visactor/vrender-core/feat-isImageAnonymous_2025-01-06-06-22.json diff --git a/common/changes/@visactor/vrender-core/feat-isImageAnonymous_2025-01-06-06-22.json b/common/changes/@visactor/vrender-core/feat-isImageAnonymous_2025-01-06-06-22.json new file mode 100644 index 000000000..7f0298227 --- /dev/null +++ b/common/changes/@visactor/vrender-core/feat-isImageAnonymous_2025-01-06-06-22.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vrender-core", + "comment": "feat: add isImageAnonymous in global", + "type": "none" + } + ], + "packageName": "@visactor/vrender-core" +} \ No newline at end of file diff --git a/packages/vrender-core/src/core/global.ts b/packages/vrender-core/src/core/global.ts index 4c1ec7f75..3d7d0fb91 100644 --- a/packages/vrender-core/src/core/global.ts +++ b/packages/vrender-core/src/core/global.ts @@ -24,11 +24,20 @@ export class DefaultGlobal implements IGlobal { private _env: EnvType; private _isSafari?: boolean; private _isChrome?: boolean; + private _isImageAnonymous?: boolean = true; get env(): EnvType { return this._env; } private envContribution: IEnvContribution; + get isImageAnonymous(): boolean { + return this._isImageAnonymous; + } + + set isImageAnonymous(isImageAnonymous: boolean) { + this._isImageAnonymous = isImageAnonymous; + } + get devicePixelRatio(): number { if (!this._env) { this.setEnv(defaultEnv); diff --git a/packages/vrender-core/src/interface/global.ts b/packages/vrender-core/src/interface/global.ts index efca682f0..001c96bc5 100644 --- a/packages/vrender-core/src/interface/global.ts +++ b/packages/vrender-core/src/interface/global.ts @@ -283,4 +283,6 @@ export interface IGlobal extends Omit number; getElementLeft: (dom: any, baseWindow?: boolean) => number; getElementTopLeft: (dom: any, baseWindow?: boolean) => { top: number; left: number }; + + isImageAnonymous: boolean; } diff --git a/packages/vrender-kits/src/env/contributions/browser-contribution.ts b/packages/vrender-kits/src/env/contributions/browser-contribution.ts index 82fd1f493..9f55d589c 100644 --- a/packages/vrender-kits/src/env/contributions/browser-contribution.ts +++ b/packages/vrender-kits/src/env/contributions/browser-contribution.ts @@ -1,4 +1,4 @@ -import { injectable, Generator, BaseEnvContribution } from '@visactor/vrender-core'; +import { injectable, Generator, BaseEnvContribution, application } from '@visactor/vrender-core'; import type { ICanvasLike, EnvType, @@ -38,7 +38,9 @@ class DynamicB { export function createImageElement(src: string, isSvg: boolean = false): Promise { const img = document.createElement('img'); - img.crossOrigin = 'anonymous'; + if (application.global.isImageAnonymous) { + img.crossOrigin = 'anonymous'; + } if (isSvg) { const data = new Blob([src], { type: 'image/svg+xml' }); src = window.URL.createObjectURL(data);