@dotlottie/dotlottie-js
Advanced tools
Comparing version 0.7.0 to 0.7.1
@@ -793,4 +793,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -803,12 +803,25 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -824,23 +837,19 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -847,0 +856,0 @@ let base64; |
@@ -34,3 +34,34 @@ export { DotLottie } from './dotlottie.js'; | ||
declare const MIME_TO_EXTENSION: MimeToExtension; | ||
declare enum ErrorCodes { | ||
ASSET_NOT_FOUND = "ASSET_NOT_FOUND", | ||
INVALID_DOTLOTTIE = "INVALID_DOTLOTTIE", | ||
INVALID_STATEMACHINE = "INVALID_STATEMACHINE", | ||
INVALID_URL = "INVALID_URL" | ||
} | ||
declare class DotLottieError extends Error { | ||
code: ErrorCodes | undefined; | ||
constructor(message: string, code?: ErrorCodes); | ||
} | ||
/** | ||
* Creates an Error object with the specified message. | ||
* | ||
* @remarks | ||
* This function accepts a message string and constructs a new Error object prefixed with "[dotlottie-js]: ". | ||
* | ||
* @deprecated | ||
* This function has been deprecated in favor of using the {@link DotLottieError} class directly. | ||
* | ||
* @param message - The error message to include in the Error object. | ||
* @returns An Error object with the specified message, prefixed with "[dotlottie-js]: ". | ||
* | ||
* @example | ||
* ```typescript | ||
* const message = 'DotLottie not found'; | ||
* const error = createError(message); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare const createError: (message: string) => Error; | ||
/** | ||
* Converts a base64 string into a Uint8Array. | ||
@@ -70,3 +101,3 @@ * | ||
*/ | ||
declare const getMimeTypeFromBase64: (base64: string) => string | null | undefined; | ||
declare const getMimeTypeFromBase64: (base64: string) => string | undefined; | ||
/** | ||
@@ -90,34 +121,3 @@ * Determines the file extension from a base64-encoded string. | ||
declare const getExtensionTypeFromBase64: (base64: string) => string | null; | ||
declare enum ErrorCodes { | ||
ASSET_NOT_FOUND = "ASSET_NOT_FOUND", | ||
INVALID_DOTLOTTIE = "INVALID_DOTLOTTIE", | ||
INVALID_STATEMACHINE = "INVALID_STATEMACHINE", | ||
INVALID_URL = "INVALID_URL" | ||
} | ||
declare class DotLottieError extends Error { | ||
code: ErrorCodes | undefined; | ||
constructor(message: string, code?: ErrorCodes); | ||
} | ||
/** | ||
* Creates an Error object with the specified message. | ||
* | ||
* @remarks | ||
* This function accepts a message string and constructs a new Error object prefixed with "[dotlottie-js]: ". | ||
* | ||
* @deprecated | ||
* This function has been deprecated in favor of using the {@link DotLottieError} class directly. | ||
* | ||
* @param message - The error message to include in the Error object. | ||
* @returns An Error object with the specified message, prefixed with "[dotlottie-js]: ". | ||
* | ||
* @example | ||
* ```typescript | ||
* const message = 'DotLottie not found'; | ||
* const error = createError(message); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare const createError: (message: string) => Error; | ||
/** | ||
* Validates a given URL string. | ||
@@ -124,0 +124,0 @@ * |
@@ -99,4 +99,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -109,6 +109,6 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
@@ -125,7 +125,20 @@ var MIME_TO_EXTENSION = { | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -141,10 +154,18 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
@@ -156,20 +177,8 @@ var getExtensionTypeFromBase64 = (base64) => { | ||
if (ext) { | ||
return MIME_TO_EXTENSION[ext] || "png"; | ||
return MIME_TO_EXTENSION[ext] || null; | ||
} | ||
return "png"; | ||
return null; | ||
} | ||
return MIME_TO_EXTENSION[mimeType] || "png"; | ||
return MIME_TO_EXTENSION[mimeType] || null; | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -176,0 +185,0 @@ let base64; |
@@ -99,4 +99,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -109,12 +109,21 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -130,19 +139,19 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -149,0 +158,0 @@ let base64; |
@@ -99,4 +99,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -109,12 +109,21 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -130,19 +139,19 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -149,0 +158,0 @@ let base64; |
@@ -15,3 +15,3 @@ import { strToU8, zip, unzip, strFromU8 } from 'fflate'; | ||
name: "@dotlottie/dotlottie-js", | ||
version: "0.7.0", | ||
version: "0.7.1", | ||
type: "module", | ||
@@ -186,4 +186,4 @@ description: "This library helps in creating and modifying .lottie files.", | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -196,6 +196,6 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
@@ -212,2 +212,14 @@ var MIME_TO_EXTENSION = { | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
var base64ToUint8Array = (base64String) => { | ||
@@ -225,4 +237,5 @@ const withoutMeta = base64String.substring(base64String.indexOf(",") + 1); | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -238,10 +251,18 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
@@ -253,20 +274,8 @@ var getExtensionTypeFromBase64 = (base64) => { | ||
if (ext) { | ||
return MIME_TO_EXTENSION[ext] || "png"; | ||
return MIME_TO_EXTENSION[ext] || null; | ||
} | ||
return "png"; | ||
return null; | ||
} | ||
return MIME_TO_EXTENSION[mimeType] || "png"; | ||
return MIME_TO_EXTENSION[mimeType] || null; | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
var isValidURL = (url) => { | ||
@@ -273,0 +282,0 @@ try { |
@@ -100,4 +100,4 @@ import phash from 'sharp-phash'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -110,12 +110,25 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -131,23 +144,19 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -154,0 +163,0 @@ let base64; |
@@ -41,3 +41,34 @@ export { DotLottie } from './dotlottie.js'; | ||
declare const MIME_TO_EXTENSION: MimeToExtension; | ||
declare enum ErrorCodes { | ||
ASSET_NOT_FOUND = "ASSET_NOT_FOUND", | ||
INVALID_DOTLOTTIE = "INVALID_DOTLOTTIE", | ||
INVALID_STATEMACHINE = "INVALID_STATEMACHINE", | ||
INVALID_URL = "INVALID_URL" | ||
} | ||
declare class DotLottieError extends Error { | ||
code: ErrorCodes | undefined; | ||
constructor(message: string, code?: ErrorCodes); | ||
} | ||
/** | ||
* Creates an Error object with the specified message. | ||
* | ||
* @remarks | ||
* This function accepts a message string and constructs a new Error object prefixed with "[dotlottie-js]: ". | ||
* | ||
* @deprecated | ||
* This function has been deprecated in favor of using the {@link DotLottieError} class directly. | ||
* | ||
* @param message - The error message to include in the Error object. | ||
* @returns An Error object with the specified message, prefixed with "[dotlottie-js]: ". | ||
* | ||
* @example | ||
* ```typescript | ||
* const message = 'DotLottie not found'; | ||
* const error = createError(message); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare const createError: (message: string) => Error; | ||
/** | ||
* Converts a base64 string into a Uint8Array. | ||
@@ -77,3 +108,3 @@ * | ||
*/ | ||
declare const getMimeTypeFromBase64: (base64: string) => string | null | undefined; | ||
declare const getMimeTypeFromBase64: (base64: string) => string | undefined; | ||
/** | ||
@@ -97,34 +128,3 @@ * Determines the file extension from a base64-encoded string. | ||
declare const getExtensionTypeFromBase64: (base64: string) => string | null; | ||
declare enum ErrorCodes { | ||
ASSET_NOT_FOUND = "ASSET_NOT_FOUND", | ||
INVALID_DOTLOTTIE = "INVALID_DOTLOTTIE", | ||
INVALID_STATEMACHINE = "INVALID_STATEMACHINE", | ||
INVALID_URL = "INVALID_URL" | ||
} | ||
declare class DotLottieError extends Error { | ||
code: ErrorCodes | undefined; | ||
constructor(message: string, code?: ErrorCodes); | ||
} | ||
/** | ||
* Creates an Error object with the specified message. | ||
* | ||
* @remarks | ||
* This function accepts a message string and constructs a new Error object prefixed with "[dotlottie-js]: ". | ||
* | ||
* @deprecated | ||
* This function has been deprecated in favor of using the {@link DotLottieError} class directly. | ||
* | ||
* @param message - The error message to include in the Error object. | ||
* @returns An Error object with the specified message, prefixed with "[dotlottie-js]: ". | ||
* | ||
* @example | ||
* ```typescript | ||
* const message = 'DotLottie not found'; | ||
* const error = createError(message); | ||
* ``` | ||
* | ||
* @public | ||
*/ | ||
declare const createError: (message: string) => Error; | ||
/** | ||
* Validates a given URL string. | ||
@@ -131,0 +131,0 @@ * |
@@ -99,4 +99,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -109,6 +109,6 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
@@ -125,7 +125,20 @@ var MIME_TO_EXTENSION = { | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -141,10 +154,18 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
@@ -156,20 +177,8 @@ var getExtensionTypeFromBase64 = (base64) => { | ||
if (ext) { | ||
return MIME_TO_EXTENSION[ext] || "png"; | ||
return MIME_TO_EXTENSION[ext] || null; | ||
} | ||
return "png"; | ||
return null; | ||
} | ||
return MIME_TO_EXTENSION[mimeType] || "png"; | ||
return MIME_TO_EXTENSION[mimeType] || null; | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var createError = (message) => { | ||
const error = new Error(`[dotlottie-js]: ${message}`); | ||
return error; | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -176,0 +185,0 @@ let base64; |
@@ -99,4 +99,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -109,12 +109,21 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -130,19 +139,19 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -149,0 +158,0 @@ let base64; |
@@ -99,4 +99,4 @@ import { nativeEnum, object, optional, boolean, string, union, literal, number, array, record, any, omit, merge, minValue, maxValue, tuple } from 'valibot'; | ||
svg: "image/svg+xml", | ||
svgxml: "image/svg+xml", | ||
webp: "image/webp", | ||
mpeg: "audio/mpeg", | ||
mp3: "audio/mp3" | ||
@@ -109,12 +109,21 @@ }; | ||
bmp: [66, 77], | ||
webp: [82, 73, 70, 70, 87, 69, 66, 80], | ||
svg: [60, 63, 120], | ||
mp3: [73, 68, 51, 3, 0, 0, 0, 0], | ||
mpeg: [73, 68, 51, 3, 0, 0, 0, 0] | ||
webp: [82, 73, 70, 70, 63, 63, 63, 63, 87, 69, 66, 80], | ||
svg: [60, 115, 118, 103], | ||
svgxml: [60, 63, 120, 109, 108], | ||
mp3: [73, 68, 51] | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
var getMimeTypeFromBase64 = (base64) => { | ||
let data = null; | ||
let bytes = []; | ||
if (!base64) | ||
return null; | ||
if (!base64) { | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
} | ||
const withoutMeta = base64.substring(base64.indexOf(",") + 1); | ||
@@ -130,19 +139,19 @@ if (typeof window === "undefined") { | ||
} | ||
bytes = Array.from(bufData.subarray(0, 8)); | ||
for (const mimeType in MIME_CODES) { | ||
const dataArr = MIME_CODES[mimeType]; | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
if (mimeType === "webp" && dataArr && bufData.length > dataArr.length) { | ||
const riffHeader = Array.from(bufData.subarray(0, 4)); | ||
const webpFormatMarker = Array.from(bufData.subarray(8, 12)); | ||
if (riffHeader.every((byte, index) => byte === dataArr[index]) && webpFormatMarker.every((byte, index) => byte === dataArr[index + 8])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} else { | ||
bytes = Array.from(bufData.subarray(0, dataArr?.length)); | ||
if (dataArr && bytes.every((byte, index) => byte === dataArr[index])) { | ||
return MIME_TYPES[mimeType]; | ||
} | ||
} | ||
} | ||
return null; | ||
throw new DotLottieError("Failed to determine the MIME type from the base64 asset string. Please check the input data. Supported asset types for dotlottie-js are: jpeg, png, gif, bmp, svg, webp, mp3", "INVALID_DOTLOTTIE" /* INVALID_DOTLOTTIE */); | ||
}; | ||
var DotLottieError = class extends Error { | ||
constructor(message, code) { | ||
super(message); | ||
__publicField(this, "code"); | ||
this.name = "[dotlottie-js]"; | ||
this.code = code; | ||
} | ||
}; | ||
function dataUrlFromU8(uint8Data) { | ||
@@ -149,0 +158,0 @@ let base64; |
{ | ||
"name": "@dotlottie/dotlottie-js", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "This library helps in creating and modifying .lottie files.", |
Sorry, the diff of this file is too big to display
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
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2179759
18963