/** * This variant of Picard should be used in server scenarios with Node.js as runtime (e.g., using Express with Node.js), with or without islands architectures. * @module */ export interface PicardAsset { /** * The id of the asset. */ id: string; /** * The URL of the asset. */ url: string; /** * The type of the component (e.g., "css", "wasm" ec.). */ type: string; /** * The name of the originating micro frontend. */ origin: string; } export interface PiComponentProps { cid?: string; source?: string; name?: string; data?: string; format?: string; framework?: string; container?: string; "fallback-template-id"?: string; } export interface PiSlotProps { name: string; rel?: string; data?: string; "item-template-id"?: string; "fallback-template-id"?: string; } export interface PiPartProps { name: string; } export interface ComponentLifecycle { load(): Promise; unload(): Promise; /** * Mounts the component into the container. If `locals.hydrate` is true, * the container already holds the server-rendered markup of the component, * which should be hydrated instead of rendered again. */ mount(container: HTMLElement, props: any, locals: any): void; unmount(container: HTMLElement, locals: any): void; update(props: any, locals: any): void; bootstrap(): Promise; stringify(props: any): Promise; } export interface ComponentRef { /** * The component ID, if any. */ cid?: string; /** * The name of the component, if no cid is given. */ name?: string; /** * The source micro frontend of the component, if no cid is given. */ source?: string; /** * The format of the source micro frontend, if no cid is given and * the micro frontend needs to be loaded first. */ format?: string; /** * The name of the remote, in case of loading a Module Federation (v1) micro frontend. */ remoteName?: string; /** * The type of the remote, in case of loading a Module Federation (v1) micro frontend. */ remoteType?: "var" | "esm"; } export interface PicardComponent { /** * The id of the component. */ id: string; /** * The (original) name of the component. */ name: string; /** * The name of the originating micro frontend. */ origin: string; /** * The type of the component, if any. */ type?: string; /** * The additional metadata of the component, if any. */ meta?: any; } export interface PicardComponentWithExport extends PicardComponent { /** * The export of the component. */ exports: any; } export interface ComponentDefinition { /** * The name of the export. */ name: string; /** * The type of the component, if any. */ type?: string; /** * The additional metadata of the component, if any. */ meta?: any; } export interface AssetDefinition { /** * The URL of the asset. */ url: string; /** * The type of the asset (e.g., "css", "wasm", ...). */ type: string; } export interface ComponentGetter { load(name: string): Promise; getComponents(): Array; getAssets(): Array; } export interface ContainerService { createContainer(details: any): Promise; } export interface ConverterService { convert(component: any, opts: any): ComponentLifecycle; } export interface DebugService { dispose(): void; } export interface DecoratorService { render: FragmentLoader; decorate(content: string): Promise; } export type StaticFeed = Array | DiscoveryResponse | PiletResponse | Record; export type FeedDefinition = string | StaticFeed | (() => Promise); export interface DiscoveryResponse { schema: string; microFrontends: { [name: string]: Array; }; } export interface MicroFrontendDefinition { url: string; fallbackUrl?: string; metadata?: { integrity?: string; version?: string; }; extras?: any; } export interface ElementsService {} export interface EsmService { load(url: string, depMap: Record, parent: string): Promise; } /** * Gets fired when a micro frontend is about to be loaded or * has been loaded. */ export interface LoadMicrofrontendEvent { /** * The name of the micro frontend. */ name: string; } /** * Gets fired when a micro frontend is about to be unloaded or * has been unloaded. */ export interface UnloadMicrofrontendEvent { /** * The name of the micro frontend. */ name: string; } /** * Gets fired when the micro frontends have been changed. */ export interface UpdatedMicrofrontendsEvent { /** * The names of the added micro frontends. */ added: Array; /** * The names of the removed micro frontends. */ removed: Array; } /** * Gets fired when dependency has been resolved. */ export interface ResolvedDependencyEvent { /** * The id of the dependency to resolve. */ id: string; /** * The URL of the parent requesting the dependency. */ parentUrl: string; /** * The resolved name of the dependency. */ result: string; } /** * Gets fired when a pi-component mounts. */ export interface MountedComponentEvent { /** * The corresponding HTML element. */ element: HTMLElement; } /** * Gets fired when a pi-component unmounts. */ export interface UnmountedComponentEvent { /** * The corresponding HTML element. */ element: HTMLElement; } /** * Gets fired when a pi-slot mounts. */ export interface MountedSlotEvent { /** * The corresponding HTML element. */ element: HTMLElement; } /** * Gets fired when a pi-slot unmounts. */ export interface UnmountedSlotEvent { /** * The corresponding HTML element. */ element: HTMLElement; } /** * Gets fired when a pi-component changes data. */ export interface ChangedDataEvent { /** * The currently deserialized data. */ current: any; /** * The currently available data serialization. */ data: string; } /** * Gets fired when any event occurs. */ export interface AnyEvent { /** * The name of the event. */ name: string; /** * The args coming with the event. */ args: any; } /** * The map of known events. */ export interface PicardEventMap { "load-microfrontend": LoadMicrofrontendEvent; "loaded-microfrontend": LoadMicrofrontendEvent; "unload-microfrontend": UnloadMicrofrontendEvent; "unloaded-microfrontend": UnloadMicrofrontendEvent; "updated-microfrontends": UpdatedMicrofrontendsEvent; "resolved-dependency": ResolvedDependencyEvent; "mounted-slot": MountedSlotEvent; "unmounted-slot": UnmountedSlotEvent; "mounted-component": MountedComponentEvent; "unmounted-component": UnmountedComponentEvent; "changed-data": ChangedDataEvent; "*": AnyEvent; [custom: string]: any; } /** * Listener for orchestrator events. */ export interface Listener { /** * Receives an event of type T. */ (arg: T): void; } /** * The emitter for orchestrator events. */ export interface EventSystem { /** * Attaches a new event listener. * @param type The type of the event to listen for. * @param callback The callback to trigger. */ on(type: string & K, callback: Listener): EventSystem; /** * Attaches a new event listener that is removed once the event fired. * @param type The type of the event to listen for. * @param callback The callback to trigger. */ once(type: string & K, callback: Listener): EventSystem; /** * Detaches an existing event listener. * @param type The type of the event to listen for. * @param callback The callback to trigger. */ off(type: string & K, callback: Listener): EventSystem; /** * Emits a new event with the given type. * @param type The type of the event to emit. * @param arg The payload of the event. */ emit(type: string & K, arg: PicardEventMap[K]): EventSystem; } export interface FeedService {} export interface FragmentsOptions extends OrderingOptions {} export interface FragmentLoader { (name: string, parameters: any, options?: FragmentsOptions): Promise; } export interface FragmentsService { load: FragmentLoader; } export interface Services { config: Configuration; events: EventSystem; scope: PicardStore; loader: LoaderService; pilet?: PiletService; esm: EsmService; router: RouterService; platform: PlatformService; renderer: RendererService; sheet?: SheetService; [framework: `framework.${string}`]: ConverterService; } export interface Configuration { partName: string; slotName: string; componentName: string; meta?: any; baseUrl?: string; } export type ServiceCreator = (injector: DependencyInjector) => Services[TService]; export interface DependencyInjector { get(name: TService): Services[TService]; getAll(name: TService): Array[TService]>; instantiate(name: TService): DependencyInjector; } export interface ModuleResolver { (): any | Promise; } export interface DependencyModule { id: string; name: string; version: string; } export interface LoaderService { registerUrls(dependencies: Record): void; registerResolvers(dependencies: Record ModuleResolver>): void; registerModule(url: string, content: any): void; load(url: string): Promise; import(id: string, parent?: string): Promise; list(): Array; setPackageResolver(resolver: (name: string, versionRange: string, parent?: string) => Promise): void; } export interface BasePicardMicrofrontend { /** * The name of the micro frontend. */ name: string; /** * The list of associated component IDs. */ components: Array; /** * The list of associated asset IDs. */ assets: Array; /** * The source link for the micro frontend. */ source: string; /** * Indicates if the MF is active (0), disabled (1), or removed (2). */ flags: 0 | 1 | 2; } export interface PiletPicardMicrofrontend extends BasePicardMicrofrontend { format: "pilet"; details: PiletEntry; } export interface ModuleFederationPicardMicrofrontend extends BasePicardMicrofrontend { format: "module"; details: ModuleFederationEntry; } export interface NativeFederationPicardMicrofrontend extends BasePicardMicrofrontend { format: "native"; details: NativeFederationEntry; } export type PicardMicrofrontend = PiletPicardMicrofrontend | ModuleFederationPicardMicrofrontend | NativeFederationPicardMicrofrontend; export interface ModuleFederationFactory { (): any; } export interface ModuleFederationFactoryScope { [depName: string]: { [depVersion: string]: { from: string; eager: boolean; strategy?: "loaded-first" | "version-first"; loaded?: number | boolean; version?: string; get(): Promise; }; }; } export interface ModuleFederationManifestV2MetaData { name: string; type: "app"; buildInfo: { buildVersion: string; buildName: string; }; remoteEntry: { name: string; path: string; type: "global" | "module"; }; types: { path: string; name: string; zip: string; api: string; }; globalName: string; pluginVersion: string; publicPath: string; } export interface ModuleFederationManifestV2SharedDependency { id: string; name: string; version: string; singleton: boolean; requiredVersion: string; assets: { js: { async: Array; sync: Array; }; css: { sync: Array; async: Array; }; }; } export interface ModuleFederationManifestV2Exposed { id: string; name: string; assets: { js: { sync: Array; async: Array; }; css: { sync: Array; async: Array; }; }; path: string; } export interface ModuleFederationManifestV2 { id: string; name: string; metaData: ModuleFederationManifestV2MetaData; shared: Array; remotes: Array; exposes: Array; } export interface ModuleFederationContainer { init(scope: ModuleFederationFactoryScope): void; get(name: string): Promise; } export interface ModuleFederationEntry { id: string; url: string; type?: "var" | "esm" | "global" | "module"; runtime?: "1.0" | "1.5" | "2.0"; metaData?: ModuleFederationManifestV2MetaData; shared?: Array; remotes?: Array; exposes?: Array; } export interface NativeFederationExposedEntry { key: string; outFileName: string; } export interface NativeFederationEntry { url: string; exposes?: Array; dependencies?: Array; } export interface NativeFederationDependency { packageName: string; outFileName: string; requiredVersion: string; singleton: boolean; strictVersion: boolean; version: string; } export interface NativeFederationManifest { name: string; shared: Array; exposes: Array; } export interface PartService { getReplacement(document: Document, attribs: Record): Promise; } export interface PiletDefinition { name: string; version?: string; link: string; spec?: string; custom?: any; integrity?: string; config?: Record; dependencies?: Record; } export interface PiletResponse { items: Array; } export interface PiletEntry { name?: string; dependencies?: Record; spec?: string; url: string; } export interface PiletMeta { basePath: string; } export interface PiletApi { registerComponent(name: string, component: ComponentLifecycle): void; meta: PiletMeta; } export interface PiletService { extend(api: PiletApi): void; } export interface PiletManifest { name: string; version: string; description: string; author: { name: string; email: string; }; integrity?: string; custom?: any; config?: Record; dependencies?: Record; main: string; spec: "v2"; } export interface PlatformService { loadScript(url: string, integrity?: string, crossOrigin?: string): Promise; loadModule(url: string): Promise; loadJson(url: string): Promise; } export interface RenderOptions { framework?: string; } export interface RendererService { render(component: ComponentRef, opts: RenderOptions): ComponentLifecycle; } export interface RouteMatch { name: string; data: Record>; } export interface RouterService { navigate(route: string, state: any): void; findRoutes(): Array; matchRoute(name: string): undefined | RouteMatch; dispose(): void; } export interface SheetService { content: string; } export interface SlotBehaviorService { apply(attribs: Record): [string, any]; } export interface OrderingOptions { reverse?: boolean; orderBy?: string; } export interface PicardState { microfrontends: Array; components: Record>; assets: Record>; } export interface PicardStore { dispose(): void; readState(): PicardState; saveSnapshot(): string; subscribe(listener: (curr: PicardState, prev: PicardState) => void): Dispose; loadMicrofrontends(loader: Promise>): Promise; loadComponents(name: string, options?: OrderingOptions): Promise>; loadAssets(type: string): Promise>; getComponent(ref: ComponentRef): Promise; removeMicrofrontend(origin: string): void; removeMicrofrontends(origins: Array): void; updateMicrofrontend(origin: string, details: Partial): void; appendMicrofrontend(mf: PicardMicrofrontend): void; appendMicrofrontends(mfs: Array): void; toggleMicrofrontend(origin: string): void; registerComponent(mf: PicardMicrofrontend, component: ComponentDefinition): PicardComponent; registerAsset(mf: PicardMicrofrontend, asset: AssetDefinition): PicardAsset; retrieveComponent(id: string): PicardComponent | undefined; retrieveAsset(id: string): PicardAsset | undefined; } export interface LoadingQueue { /** * The current promise. */ current: Promise; /** * Depends on the current promise, but also replaces it to * move it forward. * @param cb The callback to enqueue to run after the promise resolved. */ enqueue(cb: () => Promise | T): Promise; /** * Depends only on the current promise - does not shift it. * @param cb The callback to run after the promise resolved. */ depends(cb: () => Promise | T): Promise; } export type Dispose = () => void; export interface PicardClientOptions { /** * The services to add when resuming in the browser. Maps the name of * the service (e.g., "framework.react") to the URL of an ES module, * which default exports the service creator. */ services?: Record; /** * The centrally shared dependencies to use when resuming in the browser. * Maps the dependency (e.g., "react@18.3.1") to the URL of an ES module. */ dependencies?: Record; } export interface PicardOptions { /** * The name of the pi-component. * @default pi-component */ componentName?: string; /** * The name of the pi-slot. * @default pi-slot */ slotName?: string; /** * The name of the pi-part. * @default pi-part */ partName?: string; /** * The URL of the fragment service, if any. */ fragmentUrl?: string; /** * The URL of the script for interactive sessions. * If not given the islands variant from unpkg will be used. * Use `getIslandsFile` to serve it from this process instead. */ scriptUrl?: string; /** * The micro frontend discovery service URL, * data from calling it, or callback function * to call it manually. */ feed?: FeedDefinition; /** * The initial state of Picard.js - if resumed. */ state?: any; /** * The additional services to register. */ services?: Record; /** * The centrally shared dependencies to use. */ dependencies?: Record Promise>; /** * Indicates that the rendering should be interactive, i.e., * going into an islands architecture application. */ interactive?: boolean; /** * The configuration for resuming in the browser. Only * used if the rendering is interactive. */ client?: PicardClientOptions; } /** * Gets the content of a file of the islands variant, i.e., the lightweight * client resuming the server-rendered page. Serve the files from the * directory of the `scriptUrl` to resume without any external resource. * @param name The name of the file, e.g., "picard.js". * @returns The JavaScript content or undefined if no such file exists. */ export function getIslandsFile(name: string): string | undefined; /** * Gets the names of the files of the islands variant, e.g., to write them * next to statically generated pages. * @returns The names of the files, e.g., "picard.js" and its chunks. */ export function getIslandsFileNames(): Array; export function initializePicard(options?: PicardOptions): DecoratorService; export class Document extends NodeWithChildren { /** * The type of the node. */ type: ElementType.Root; /** * [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible * node {@link type}. */ get nodeType(): 9; /** * [Document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks) (parse5 only). */ "\"x-mode\"": "no-quirks" | "quirks" | "limited-quirks"; } export class NodeWithChildren extends Node { children: Array; constructor(children: Array); /** * First child of the node. */ get firstChild(): ChildNode | null; /** * Last child of the node. */ get lastChild(): ChildNode | null; /** * Same as {@link children}. * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. */ get childNodes(): Array; /** * Same as {@link children}. * [DOM spec](https://dom.spec.whatwg.org)-compatible alias. */ set childNodes(children: Array); } /** * Types of elements found in htmlparser2's DOM */ export enum ElementType { /** * Type for the root element of a document */ Root = "root", /** * Type for Text */ Text = "text", /** * Type for */ Directive = "directive", /** * Type for */ Comment = "comment", /** * Type for