UNPKG

ngx-lottie

Version:

<h1 align="center"> <img src="https://raw.githubusercontent.com/ngx-lottie/ngx-lottie/refs/heads/master/docs/assets/logo.png"> </h1>

1 lines 7.37 kB
{"version":3,"file":"ngx-lottie-server.mjs","sources":["../../../../libs/ngx-lottie/server/src/utils.ts","../../../../libs/ngx-lottie/server/src/symbols.ts","../../../../libs/ngx-lottie/server/src/internals.ts","../../../../libs/ngx-lottie/server/src/lottie-server.module.ts","../../../../libs/ngx-lottie/server/src/ngx-lottie-server.ts"],"sourcesContent":["import { readFile } from 'fs';\n\nimport { AnimationData } from './symbols';\n\n/** A simple cache used to store the serialized animation data. */\nconst cache = new Map<string, AnimationData>();\n\nexport function readFileWithAnimationData(path: string): Promise<AnimationData> {\n return cache.has(path)\n ? Promise.resolve(cache.get(path)!)\n : new Promise((resolve, reject) => {\n readFile(path, (error, buffer) => {\n if (error) {\n reject(error);\n } else {\n const data = buffer.toString();\n cache.set(path, data);\n resolve(data);\n }\n });\n });\n}\n","import { InjectionToken } from '@angular/core';\n\nexport interface LottieServerOptions {\n preloadAnimations: {\n folder: string;\n animations: string[];\n };\n}\n\nexport type PathToAnimation = string;\nexport type AnimationData = string;\n\nexport const LOTTIE_SERVER_OPTIONS = new InjectionToken<LottieServerOptions>('LottieServerOptions');\n","import { join } from 'node:path';\nimport { inject, makeStateKey, TransferState } from '@angular/core';\nimport { AnimationFilename, transformAnimationFilenameToKey } from 'ngx-lottie';\n\nimport { readFileWithAnimationData } from './utils';\nimport {\n LottieServerOptions,\n PathToAnimation,\n AnimationData,\n LOTTIE_SERVER_OPTIONS,\n} from './symbols';\n\n/** Will be provided through Terser global definitions when the app is build in production mode. */\ndeclare const ngDevMode: boolean;\n\nfunction readAndTransferAnimationData(\n transferState: TransferState,\n animations: AnimationFilename[],\n pathsToAnimations: PathToAnimation[],\n): Promise<void>[] {\n const sources: Promise<void>[] = [];\n\n for (let i = 0, length = animations.length; i < length; i++) {\n const path = pathsToAnimations[i];\n\n const source = readFileWithAnimationData(path)\n .then(animationData => {\n transferAnimationData(transferState, animations[i], animationData);\n })\n .catch(error => {\n if (typeof ngDevMode !== 'undefined' && ngDevMode) {\n console.error(`Failed to read the following file ${path}. Error: `, error);\n }\n\n // This is empty since we don't have to do anything if the file was failed to read.\n });\n\n sources.push(source);\n }\n\n return sources;\n}\n\nfunction transferAnimationData(\n state: TransferState,\n animation: AnimationFilename,\n animationData: AnimationData,\n): void {\n animation = transformAnimationFilenameToKey(animation);\n const key = makeStateKey(animation);\n if (state.hasKey(key)) {\n return;\n }\n state.set(key, JSON.parse(animationData));\n}\n\nexport async function appInitializer() {\n const options = inject(LOTTIE_SERVER_OPTIONS);\n const transferState = inject(TransferState);\n const pathsToAnimations = resolveLottiePaths(options);\n const sources = readAndTransferAnimationData(\n transferState,\n options.preloadAnimations.animations,\n pathsToAnimations,\n );\n\n await Promise.all(sources);\n}\n\nexport function resolveLottiePaths({ preloadAnimations }: LottieServerOptions): PathToAnimation[] {\n const { folder, animations } = preloadAnimations;\n const path = join(process.cwd(), folder);\n return animations.map(animation => join(path, animation));\n}\n","import {\n NgModule,\n ModuleWithProviders,\n makeEnvironmentProviders,\n provideAppInitializer,\n} from '@angular/core';\n\nimport { appInitializer } from './internals';\nimport { LOTTIE_SERVER_OPTIONS, LottieServerOptions } from './symbols';\n\n@NgModule()\nexport class LottieServerModule {\n static forRoot(options: LottieServerOptions): ModuleWithProviders<LottieServerModule> {\n return {\n ngModule: LottieServerModule,\n providers: [\n {\n provide: LOTTIE_SERVER_OPTIONS,\n useValue: options,\n },\n provideAppInitializer(appInitializer),\n ],\n };\n }\n}\n\nexport function provideLottieServerOptions(options: LottieServerOptions) {\n return makeEnvironmentProviders([\n {\n provide: LOTTIE_SERVER_OPTIONS,\n useValue: options,\n },\n provideAppInitializer(appInitializer),\n ]);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAIA;AACA,MAAM,KAAK,GAAG,IAAI,GAAG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