@lightningjs/renderer
Advanced tools
Comparing version
@@ -114,3 +114,4 @@ /* | ||
.then(function (data) { | ||
self.postMessage({ id: id, src: src, data: data }); | ||
// @ts-ignore ts has wrong postMessage signature | ||
self.postMessage({ id: id, src: src, data: data }, [data.data]); | ||
}) | ||
@@ -117,0 +118,0 @@ .catch(function (error) { |
@@ -56,1 +56,5 @@ export declare const PROTOCOL_REGEX: RegExp; | ||
export declare function isBase64Image(src: string): boolean; | ||
export declare function calcFactoredRadius(radius: number, width: number, height: number): number; | ||
export declare function valuesAreEqual(values: number[]): boolean; | ||
export declare function calcFactoredRadiusArray(radius: [number, number, number, number], width: number, height: number): [number, number, number, number]; | ||
export declare function dataURIToBlob(dataURI: string): Blob; |
@@ -218,2 +218,48 @@ /* | ||
} | ||
export function calcFactoredRadius(radius, width, height) { | ||
return radius * Math.min(Math.min(width, height) / (2.0 * radius), 1); | ||
} | ||
export function valuesAreEqual(values) { | ||
let prevValue = values[0]; | ||
for (let i = 1; i < values.length; i++) { | ||
if (prevValue !== values[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
export function calcFactoredRadiusArray(radius, width, height) { | ||
const result = [ | ||
radius[0], | ||
radius[1], | ||
radius[2], | ||
radius[3], | ||
]; | ||
const factor = Math.min(Math.min(Math.min(width / Math.max(width, radius[0] + radius[1]), width / Math.max(width, radius[2] + radius[3])), Math.min(height / Math.max(height, radius[0] + radius[3]), height / Math.max(height, radius[1] + radius[2]))), 1); | ||
result[0] *= factor; | ||
result[1] *= factor; | ||
result[2] *= factor; | ||
result[3] *= factor; | ||
return result; | ||
} | ||
export function dataURIToBlob(dataURI) { | ||
dataURI = dataURI.replace(/^data:/, ''); | ||
const type = dataURI.match(/image\/[^;]+/)?.[0] || ''; | ||
const base64 = dataURI.replace(/^[^,]+,/, ''); | ||
const sliceSize = 1024; | ||
const byteCharacters = atob(base64); | ||
const bytesLength = byteCharacters.length; | ||
const slicesCount = Math.ceil(bytesLength / sliceSize); | ||
const byteArrays = new Array(slicesCount); | ||
for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { | ||
const begin = sliceIndex * sliceSize; | ||
const end = Math.min(begin + sliceSize, bytesLength); | ||
const bytes = new Array(end - begin); | ||
for (let offset = begin, i = 0; offset < end; ++i, ++offset) { | ||
bytes[i] = byteCharacters[offset]?.charCodeAt(0); | ||
} | ||
byteArrays[sliceIndex] = new Uint8Array(bytes); | ||
} | ||
return new Blob(byteArrays, { type }); | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import { WebGlCoreShader, } from '../WebGlCoreShader.js'; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import { ShaderEffect, } from './ShaderEffect.js'; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import { updateWebSafeRadius, validateArrayLength4 } from './EffectUtils.js'; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -16,3 +16,3 @@ import type { CoreTextureManager } from '../CoreTextureManager.js'; | ||
*/ | ||
src?: string | ImageData | (() => ImageData | null); | ||
src?: string | Blob | ImageData | (() => ImageData | null); | ||
/** | ||
@@ -100,3 +100,3 @@ * Whether to premultiply the alpha channel into the color channels of the | ||
hasAlphaChannel(mimeType: string): boolean; | ||
loadImageFallback(src: string, hasAlpha: boolean): Promise<{ | ||
loadImageFallback(src: string | Blob, hasAlpha: boolean): Promise<{ | ||
data: HTMLImageElement; | ||
@@ -103,0 +103,0 @@ premultiplyAlpha: boolean; |
@@ -21,3 +21,3 @@ /* | ||
import { isCompressedTextureContainer, loadCompressedTexture, } from '../lib/textureCompression.js'; | ||
import { convertUrlToAbsolute, isBase64Image } from '../lib/utils.js'; | ||
import { convertUrlToAbsolute, dataURIToBlob, isBase64Image, } from '../lib/utils.js'; | ||
import { isSvgImage, loadSvg } from '../lib/textureSvg.js'; | ||
@@ -51,3 +51,3 @@ import { fetchJson } from '../text-rendering/font-face-types/utils.js'; | ||
const img = new Image(); | ||
if (isBase64Image(src) === false) { | ||
if (typeof src === 'string' && isBase64Image(src) === false) { | ||
img.crossOrigin = 'anonymous'; | ||
@@ -63,3 +63,8 @@ } | ||
}; | ||
img.src = src; | ||
if (src instanceof Blob) { | ||
img.src = URL.createObjectURL(src); | ||
} | ||
else { | ||
img.src = src; | ||
} | ||
}); | ||
@@ -103,3 +108,9 @@ } | ||
} | ||
const blob = await fetchJson(src, 'blob').then((response) => response); | ||
let blob; | ||
if (isBase64Image(src) === true) { | ||
blob = dataURIToBlob(src); | ||
} | ||
else { | ||
blob = await fetchJson(src, 'blob').then((response) => response); | ||
} | ||
return this.createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh); | ||
@@ -155,2 +166,11 @@ } | ||
if (typeof src !== 'string') { | ||
if (src instanceof Blob) { | ||
if (this.txManager.hasCreateImageBitmap === true) { | ||
const { sx, sy, sw, sh } = this.props; | ||
return this.createImageBitmap(src, premultiplyAlpha, sx, sy, sw, sh); | ||
} | ||
else { | ||
return this.loadImageFallback(src, premultiplyAlpha ?? true); | ||
} | ||
} | ||
if (src instanceof ImageData) { | ||
@@ -157,0 +177,0 @@ return { |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
{ | ||
"name": "@lightningjs/renderer", | ||
"version": "2.13.0", | ||
"version": "2.13.1", | ||
"description": "Lightning 3 Renderer", | ||
@@ -64,2 +64,3 @@ "type": "module", | ||
], | ||
"packageManager": "pnpm@8.9.2", | ||
"engines": { | ||
@@ -66,0 +67,0 @@ "npm": ">= 10.0.0", |
@@ -0,0 +0,0 @@ # Lightning 3 Renderer |
@@ -0,0 +0,0 @@ if ( |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* eslint-disable @typescript-eslint/unbound-method */ |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -161,3 +161,4 @@ /* | ||
.then(function (data) { | ||
self.postMessage({ id: id, src: src, data: data }); | ||
// @ts-ignore ts has wrong postMessage signature | ||
self.postMessage({ id: id, src: src, data: data }, [data.data]); | ||
}) | ||
@@ -164,0 +165,0 @@ .catch(function (error) { |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ const rx1 = 0; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -311,1 +311,75 @@ /* | ||
} | ||
export function calcFactoredRadius( | ||
radius: number, | ||
width: number, | ||
height: number, | ||
): number { | ||
return radius * Math.min(Math.min(width, height) / (2.0 * radius), 1); | ||
} | ||
export function valuesAreEqual(values: number[]) { | ||
let prevValue = values[0]; | ||
for (let i = 1; i < values.length; i++) { | ||
if (prevValue !== values[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
export function calcFactoredRadiusArray( | ||
radius: [number, number, number, number], | ||
width: number, | ||
height: number, | ||
): [number, number, number, number] { | ||
const result: [number, number, number, number] = [ | ||
radius[0], | ||
radius[1], | ||
radius[2], | ||
radius[3], | ||
]; | ||
const factor = Math.min( | ||
Math.min( | ||
Math.min( | ||
width / Math.max(width, radius[0] + radius[1]), | ||
width / Math.max(width, radius[2] + radius[3]), | ||
), | ||
Math.min( | ||
height / Math.max(height, radius[0] + radius[3]), | ||
height / Math.max(height, radius[1] + radius[2]), | ||
), | ||
), | ||
1, | ||
); | ||
result[0] *= factor; | ||
result[1] *= factor; | ||
result[2] *= factor; | ||
result[3] *= factor; | ||
return result; | ||
} | ||
export function dataURIToBlob(dataURI: string): Blob { | ||
dataURI = dataURI.replace(/^data:/, ''); | ||
const type = dataURI.match(/image\/[^;]+/)?.[0] || ''; | ||
const base64 = dataURI.replace(/^[^,]+,/, ''); | ||
const sliceSize = 1024; | ||
const byteCharacters = atob(base64); | ||
const bytesLength = byteCharacters.length; | ||
const slicesCount = Math.ceil(bytesLength / sliceSize); | ||
const byteArrays = new Array(slicesCount); | ||
for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { | ||
const begin = sliceIndex * sliceSize; | ||
const end = Math.min(begin + sliceSize, bytesLength); | ||
const bytes = new Array(end - begin); | ||
for (let offset = begin, i = 0; offset < end; ++i, ++offset) { | ||
bytes[i] = byteCharacters[offset]?.charCodeAt(0); | ||
} | ||
byteArrays[sliceIndex] = new Uint8Array(bytes); | ||
} | ||
return new Blob(byteArrays, { type }); | ||
} |
@@ -0,0 +0,0 @@ export interface CreateImageBitmapSupport { |
@@ -0,0 +0,0 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import type { DynamicShaderProps } from '../DynamicShader.js'; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import { |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import type { EffectMap } from '../../../../CoreShaderManager.js'; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -26,3 +26,7 @@ /* | ||
} from '../lib/textureCompression.js'; | ||
import { convertUrlToAbsolute, isBase64Image } from '../lib/utils.js'; | ||
import { | ||
convertUrlToAbsolute, | ||
dataURIToBlob, | ||
isBase64Image, | ||
} from '../lib/utils.js'; | ||
import { isSvgImage, loadSvg } from '../lib/textureSvg.js'; | ||
@@ -44,3 +48,3 @@ import { fetchJson } from '../text-rendering/font-face-types/utils.js'; | ||
*/ | ||
src?: string | ImageData | (() => ImageData | null); | ||
src?: string | Blob | ImageData | (() => ImageData | null); | ||
/** | ||
@@ -138,6 +142,6 @@ * Whether to premultiply the alpha channel into the color channels of the | ||
async loadImageFallback(src: string, hasAlpha: boolean) { | ||
async loadImageFallback(src: string | Blob, hasAlpha: boolean) { | ||
const img = new Image(); | ||
if (isBase64Image(src) === false) { | ||
if (typeof src === 'string' && isBase64Image(src) === false) { | ||
img.crossOrigin = 'anonymous'; | ||
@@ -157,3 +161,7 @@ } | ||
img.src = src; | ||
if (src instanceof Blob) { | ||
img.src = URL.createObjectURL(src); | ||
} else { | ||
img.src = src; | ||
} | ||
}, | ||
@@ -222,5 +230,12 @@ ); | ||
const blob = await fetchJson(src, 'blob').then( | ||
(response) => response as Blob, | ||
); | ||
let blob; | ||
if (isBase64Image(src) === true) { | ||
blob = dataURIToBlob(src); | ||
} else { | ||
blob = await fetchJson(src, 'blob').then( | ||
(response) => response as Blob, | ||
); | ||
} | ||
return this.createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh); | ||
@@ -282,2 +297,10 @@ } | ||
if (typeof src !== 'string') { | ||
if (src instanceof Blob) { | ||
if (this.txManager.hasCreateImageBitmap === true) { | ||
const { sx, sy, sw, sh } = this.props; | ||
return this.createImageBitmap(src, premultiplyAlpha, sx, sy, sw, sh); | ||
} else { | ||
return this.loadImageFallback(src, premultiplyAlpha ?? true); | ||
} | ||
} | ||
if (src instanceof ImageData) { | ||
@@ -284,0 +307,0 @@ return { |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ interface ImportMetaEnv { |
@@ -0,0 +0,0 @@ import type { ShaderEffectValueMap } from '../../exports/index.js'; |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import { |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ /* |
@@ -0,0 +0,0 @@ import type { CustomDataMap } from '../core/CoreNode.js'; |
@@ -0,0 +0,0 @@ /* |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
2219180
10.69%496
16.43%0
-100%100
25%48623
10.28%