Skip to content

Commit

Permalink
feat: add isImageAnonymous in global
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Jan 6, 2025
1 parent 0ca63c5 commit b1de9aa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-core",
"comment": "feat: add isImageAnonymous in global",
"type": "none"
}
],
"packageName": "@visactor/vrender-core"
}
9 changes: 9 additions & 0 deletions packages/vrender-core/src/core/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/vrender-core/src/interface/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,6 @@ export interface IGlobal extends Omit<IEventElement, 'on' | 'off' | 'once' | 'em
getElementTop: (dom: any, baseWindow?: boolean) => number;
getElementLeft: (dom: any, baseWindow?: boolean) => number;
getElementTopLeft: (dom: any, baseWindow?: boolean) => { top: number; left: number };

isImageAnonymous: boolean;
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -38,7 +38,9 @@ class DynamicB {

export function createImageElement(src: string, isSvg: boolean = false): Promise<HTMLImageElement> {
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);
Expand Down

0 comments on commit b1de9aa

Please sign in to comment.