@imgly/psd-importer
Version:
Import PSD files into the Creative Editor Ecosystem
122 lines (118 loc) • 3.84 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
import CreativeEngine from '@cesdk/engine';
import { Font, Typeface } from '@cesdk/engine';
export interface TypefaceParams {
family: string;
style: Font["style"];
weight: Font["weight"];
}
export interface FontResolverOptions {
/**
* When true and no exact (weight, style) match is available in the resolved
* typeface, fall back to the closest matching weight using the CSS Font
* Matching algorithm. This is useful when a known-good typeface (e.g. Roboto)
* is requested but lacks the exact weight (e.g. semiBold/extraBold). It is
* not enabled by default to avoid masking poor fuzzy-name matches.
*/
closestWeightMatch?: boolean;
}
export type TypefaceResolver = (fontParameters: TypefaceParams, engine: CreativeEngine, options?: FontResolverOptions) => Promise<FontResolverResult | null>;
export declare function addGfontsAssetLibrary(engine: CreativeEngine): Promise<void>;
export interface FontResolverResult {
typeface: Typeface;
font: Font;
}
export interface EncodeBufferToPNG {
(rawImageBuffer: Uint8ClampedArray, imageWidth: number, imageHeight: number, backgroundColor?: {
r: number;
g: number;
b: number;
a: number;
}): Promise<Blob>;
}
export type LogMessage = {
message: string;
type: "error" | "warning" | "info";
};
export declare class Logger {
private static instance;
constructor();
private messages;
log(message: string, type?: "error" | "warning" | "info"): void;
getMessages(): LogMessage[];
}
export interface Flags {
applyClipMasks: boolean;
enableTextFitting: boolean;
enableTextVerticalAlignmentFix: boolean;
enableTextTypefaceReachableCheck: boolean;
enableCreateHiddenLayers: boolean;
enableTopLevelGroupsArePages: boolean;
groupsEnabled: boolean;
}
export interface Options {
fontResolver: TypefaceResolver;
flags: Flags;
}
export declare class PSDParser {
private engine;
private scene;
private stack;
private width;
private height;
private psd;
private logger;
private fontResolver;
private fontMetricsCache;
private encodeBufferToPNG;
private flags;
private groups;
private constructor();
private loadFontMetrics;
static fromFile(engine: CreativeEngine, fileBuffer: ArrayBuffer, encodeBufferToPNG: EncodeBufferToPNG, options?: Partial<Options>): Promise<PSDParser>;
private traverseNode;
private checkUnsupportedLayerFeatures;
private applyParentClipMasks;
/**
* Creates a graphic block with the shape of the vector mask of the PSD node
* @param psdNode The PSD node to extract the clip mask from
* @returns A graphic block with the shape of the clip mask or null if no clip mask is present
*/
private createClipMaskLayer;
private createGroups;
parse(): Promise<{
scene: number;
logger: Logger;
}>;
private initScene;
private createPage;
private applyTreeOpacity;
private createTextBlock;
private moveTextInTextDirection;
private textVerticalAlignmentFix;
private textFitting;
private getTextFontSet;
private getStyleSheetColor;
private getTextValue;
private getTextStrokeColor;
/**
* This function scales a text attribute based on the scaling factor of the PSD file
* @param textAttribute The text attribute to scale
* @param TySh The TypeToolObjectSettingAliBlock object
* @param dpi The DPI of the PSD file. Default is 72
* @returns returns the scaled text attribute
*/
private scaleTextNumber;
private getLineHeight;
private createImageBlock;
private getSvgMoveTo;
private getSvgCurve;
private createVectorBlock;
private buildShapeFromPathRecords;
private applyRotationFromTransform;
private getBlendModeFillOpacity;
private getBlendMode;
}
export declare function createWebEncodeBufferToPNG(): EncodeBufferToPNG;
export declare function createPNGJSEncodeBufferToPNG(PNG: typeof import("pngjs/browser").PNG): EncodeBufferToPNG;
export {};