import { Colord } from 'colord';

interface NormalizedAudio {
    src: string;
}
type Audio = string | NormalizedAudio;
declare function normalizeAudio(audio: Audio): NormalizedAudio | undefined;

interface RgbColor {
    r: number;
    g: number;
    b: number;
}
interface HslColor {
    h: number;
    s: number;
    l: number;
}
interface HsvColor {
    h: number;
    s: number;
    v: number;
}
interface HwbColor {
    h: number;
    w: number;
    b: number;
}
interface XyzColor {
    x: number;
    y: number;
    z: number;
}
interface LabColor {
    l: number;
    a: number;
    b: number;
}
interface LchColor {
    l: number;
    c: number;
    h: number;
}
interface CmykColor {
    c: number;
    m: number;
    y: number;
    k: number;
}
type WithAlpha<O> = O & {
    a: number;
};
type RgbaColor = WithAlpha<RgbColor>;
type HslaColor = WithAlpha<HslColor>;
type HsvaColor = WithAlpha<HsvColor>;
type HwbaColor = WithAlpha<HwbColor>;
type XyzaColor = WithAlpha<XyzColor>;
type LabaColor = LabColor & {
    alpha: number;
};
type LchaColor = WithAlpha<LchColor>;
type CmykaColor = WithAlpha<CmykColor>;
type ObjectColor = RgbColor | RgbaColor | HslColor | HslaColor | HsvColor | HsvaColor | HwbColor | HwbaColor | XyzColor | XyzaColor | LabColor | LabaColor | LchColor | LchaColor | CmykColor | CmykaColor;
type Uint32Color = number;
type Color = Uint32Color | ObjectColor | string;
type Hex8Color = string;
type NormalizedColor = Hex8Color;
declare function parseColor(color: Color): Colord;
declare const defaultColor: NormalizedColor;
declare function isColor(value: string): boolean;
declare function normalizeColor(color: Color, orFail?: boolean): NormalizedColor;

interface ColorStop {
    offset: number;
    color: NormalizedColor;
}
interface LinearGradient {
    angle: number;
    stops: ColorStop[];
    repeat?: boolean;
}
type LinearGradientWithType = LinearGradient & {
    type: 'linear-gradient';
};
interface RadialGradient {
    stops: ColorStop[];
    repeat?: boolean;
}
type RadialGradientWithType = RadialGradient & {
    type: 'radial-gradient';
};
declare function isGradient(cssText: string): boolean;
declare function normalizeGradient(cssText: string): (LinearGradientWithType | RadialGradientWithType)[];

interface LinearGradientNode {
  type: 'linear-gradient'
  orientation?: DirectionalNode | AngularNode | undefined
  colorStops: ColorStopNode[]
}

interface RepeatingLinearGradientNode {
  type: 'repeating-linear-gradient'
  orientation?: DirectionalNode | AngularNode | undefined
  colorStops: ColorStopNode[]
}

interface RadialGradientNode {
  type: 'radial-gradient'
  orientation?: (ShapeNode | DefaultRadialNode | ExtentKeywordNode)[] | undefined
  colorStops: ColorStopNode[]
}

interface RepeatingRadialGradientNode {
  type: 'repeating-radial-gradient'
  orientation?: (ShapeNode | DefaultRadialNode | ExtentKeywordNode)[] | undefined
  colorStops: ColorStopNode[]
}

interface DirectionalNode {
  type: 'directional'
  value:
    | 'left'
    | 'top'
    | 'bottom'
    | 'right'
    | 'left top'
    | 'top left'
    | 'left bottom'
    | 'bottom left'
    | 'right top'
    | 'top right'
    | 'right bottom'
    | 'bottom right'
}

interface AngularNode {
  type: 'angular'
  value: string
}

interface LiteralNode {
  type: 'literal'
  value: string
  length?: PxNode | EmNode | PercentNode | undefined
}

interface HexNode {
  type: 'hex'
  value: string
  length?: PxNode | EmNode | PercentNode | undefined
}

interface RgbNode {
  type: 'rgb'
  value: [string, string, string]
  length?: PxNode | EmNode | PercentNode | undefined
}

interface RgbaNode {
  type: 'rgba'
  value: [string, string, string, string?]
  length?: PxNode | EmNode | PercentNode | undefined
}

interface ShapeNode {
  type: 'shape'
  style?: ExtentKeywordNode | PxNode | EmNode | PercentNode | PositionKeywordNode | undefined
  value: 'ellipse' | 'circle'
  at?: PositionNode | undefined
}

interface DefaultRadialNode {
  type: 'default-radial'
  at: PositionNode
}

interface PositionKeywordNode {
  type: 'position-keyword'
  value: 'center' | 'left' | 'top' | 'bottom' | 'right'
}

interface PositionNode {
  type: 'position'
  value: {
    x: ExtentKeywordNode | PxNode | EmNode | PercentNode | PositionKeywordNode
    y: ExtentKeywordNode | PxNode | EmNode | PercentNode | PositionKeywordNode
  }
}

interface ExtentKeywordNode {
  type: 'extent-keyword'
  value: 'closest-side' | 'closest-corner' | 'farthest-side' | 'farthest-corner' | 'contain' | 'cover'
  at?: PositionNode | undefined
}

interface PxNode {
  type: 'px'
  value: string
}

interface EmNode {
  type: 'em'
  value: string
}

interface PercentNode {
  type: '%'
  value: string
}

type ColorStopNode = LiteralNode | HexNode | RgbNode | RgbaNode
type GradientNode = LinearGradientNode | RepeatingLinearGradientNode | RadialGradientNode | RepeatingRadialGradientNode

declare function parseGradient(cssText: string): GradientNode[]
declare function stringifyGradient(ast: GradientNode[]): string

interface ColorFillObject {
    color: Color;
}
type ColorFill = string | ColorFillObject;
interface NormalizedColorFill {
    color: NormalizedColor;
}
declare const colorFillFields: (keyof NormalizedColorFill)[];
declare function normalizeColorFill(fill: ColorFill): NormalizedColorFill;

type None = undefined | null | 'none';
type WithNone<T> = T | None;
type WithStyleNone<T> = T | 'none';
type LineCap = 'butt' | 'round' | 'square';
type LineJoin = 'miter' | 'round' | 'bevel';
interface Toggleable {
    enabled: boolean;
}

type GradientFillObject = {
    image?: string;
} & Partial<NormalizedGradientFill>;
type GradientFill = string | GradientFillObject;
interface NormalizedGradientFill {
    linearGradient?: LinearGradient;
    radialGradient?: RadialGradient;
    rotateWithShape?: boolean;
}
declare const gradientFillFields: (keyof NormalizedGradientFill)[];
declare function normalizeGradientFill(fill: GradientFill): NormalizedGradientFill;

/**
 * 图片处理管线步骤：引用一个已注册的具名管线 + 参数。
 *
 * 数据只记录「用了哪个管线 + 参数」，处理函数（image → image）是运行时注册的黑盒，
 * 不入持久化数据。渲染端按需把 `图片 + imagePipelines` 烘焙到运行时纹理；导出端按需物化成成品图。
 */
interface ImagePipeline {
    name: string;
    params?: Record<string, any>;
}
interface NormalizedImagePipeline extends ImagePipeline {
}
/**
 * 跨端的中立图片像素结构（等价 `ImageData`），供管线处理函数 `image → image` 使用。
 * 不依赖 DOM，可在浏览器与 node 导出环境一致运行。
 */
interface PipelineImage {
    data: Uint8ClampedArray;
    width: number;
    height: number;
}
declare function normalizeImagePipeline(pipeline: ImagePipeline): NormalizedImagePipeline;

/**
 * 0    -0.5   0
 * -0.5        -0.5
 * 0    -0.5   0
 */
interface ImageFillCropRect {
    left?: number;
    top?: number;
    bottom?: number;
    right?: number;
}
/**
 * 0    0.5   0
 * 0.5        0.5
 * 0    0.5   0
 */
interface ImageFillStretchRect {
    left?: number;
    top?: number;
    bottom?: number;
    right?: number;
}
interface ImageFillTile {
    alignment?: string;
    scaleX?: number;
    scaleY?: number;
    translateX?: number;
    translateY?: number;
    flip?: string;
}
interface ImageFillObject {
    image: string;
    cropRect?: ImageFillCropRect;
    stretchRect?: ImageFillStretchRect;
    tile?: ImageFillTile;
    dpi?: number;
    opacity?: number;
    rotateWithShape?: boolean;
    /**
     * 图片处理管线：图片源在上屏/导出前依次流经的具名处理步骤（image → image）。
     * 只记录管线名与参数；处理函数为运行时注册的黑盒，不入数据。
     */
    imagePipelines?: ImagePipeline[];
}
type ImageFill = string | ImageFillObject;
interface NormalizedImageFill extends ImageFillObject {
    imagePipelines?: NormalizedImagePipeline[];
}
declare const imageFillFiedls: (keyof NormalizedImageFill)[];
declare function normalizeImageFill(fill: ImageFill): NormalizedImageFill;

interface PresetFillObject {
    preset: string;
    foregroundColor?: WithNone<Color>;
    backgroundColor?: WithNone<Color>;
}
type PresetFill = string | PresetFillObject;
interface NormalizedPresetFill extends PresetFillObject {
    foregroundColor?: NormalizedColor;
    backgroundColor?: NormalizedColor;
}
declare const presetFillFiedls: (keyof NormalizedPresetFill)[];
declare function normalizePresetFill(fill: PresetFill): NormalizedPresetFill;

type FillObject = Partial<Toggleable> & Partial<ColorFillObject> & Partial<GradientFillObject> & Partial<ImageFillObject> & Partial<PresetFillObject>;
type Fill = string | FillObject;
type NormalizedFill = Toggleable & Partial<NormalizedColorFill> & Partial<NormalizedGradientFill> & Partial<NormalizedImageFill> & Partial<NormalizedPresetFill>;
declare function isColorFillObject(fill: FillObject): fill is ColorFillObject;
declare function isColorFill(fill: Fill): fill is ColorFill;
declare function isGradientFillObject(fill: FillObject): fill is GradientFillObject;
declare function isGradientFill(fill: Fill): fill is GradientFill;
declare function isImageFillObject(fill: FillObject): fill is ImageFillObject;
declare function isImageFill(fill: Fill): fill is ImageFill;
declare function isPresetFillObject(fill: FillObject): fill is PresetFillObject;
declare function isPresetFill(fill: Fill): fill is PresetFill;
declare function normalizeFill(fill: Fill): NormalizedFill;

interface NormalizedBaseBackground {
    fillWithShape?: boolean;
}
type NormalizedBackground = NormalizedFill & NormalizedBaseBackground;
type BackgroundObject = FillObject & Partial<NormalizedBaseBackground>;
type Background = string | BackgroundObject;

declare function normalizeBackground(background: Background): NormalizedBackground;

type BackgroundSize = 'contain' | 'cover' | string | 'stretch' | 'rigid';
interface NormalizedBackgroundStyle {
    backgroundImage: WithStyleNone<string>;
    backgroundSize: BackgroundSize;
    backgroundColor: WithStyleNone<NormalizedColor>;
    backgroundColormap: WithStyleNone<Record<string, string>>;
}
declare function getDefaultBackgroundStyle(): NormalizedBackgroundStyle;

type ChartType = 'column' | 'bar' | 'line' | 'area' | 'pie' | 'doughnut' | 'scatter' | 'radar' | (string & {});
/** 分组方式（柱/条/面/线） */
type ChartGrouping = 'clustered' | 'stacked' | 'percentStacked' | 'standard';
type ChartLegend = false | 'top' | 'bottom' | 'left' | 'right';
interface ChartSeriesObject {
    name?: string;
    /** 数值序列（与 chart.categories 对齐） */
    values: number[];
    /** scatter 用：与 values 配对的 x 值 */
    xValues?: number[];
    color?: string;
}
interface ChartAxis {
    title?: string;
    min?: number;
    max?: number;
    /** 是否显示 */
    visible?: boolean;
}
interface ChartObject extends Partial<Toggleable> {
    type?: ChartType;
    grouping?: ChartGrouping;
    /** 分类标签（共享），如 ["一月","二月"] */
    categories?: string[];
    series?: ChartSeriesObject[];
    title?: string;
    legend?: ChartLegend;
    categoryAxis?: ChartAxis;
    valueAxis?: ChartAxis;
}
type Chart = ChartObject;
interface NormalizedChartSeries {
    name?: string;
    values: number[];
    xValues?: number[];
    color?: string;
}
interface NormalizedChart extends Toggleable {
    type: ChartType;
    grouping?: ChartGrouping;
    categories: string[];
    series: NormalizedChartSeries[];
    title?: string;
    legend?: ChartLegend;
    categoryAxis?: ChartAxis;
    valueAxis?: ChartAxis;
}
declare function normalizeChart(chart: Chart): NormalizedChart;

/** 评论位置：相对所属元素原点的偏移。 */
interface CommentOffset {
    x: number;
    y: number;
}
/** 评论作者。 */
interface CommentAuthor {
    id?: string;
    name?: string;
    color?: string;
    /** 姓名缩写（PPTX 作者用；缺省可由 name 推导）。 */
    initials?: string;
}
/** 线程中的单条消息（根消息即创建评论，其后为回复）。 */
interface CommentMessage {
    id?: string;
    author?: CommentAuthor;
    /** 正文。 */
    body?: string;
    /** 创建时间（毫秒时间戳）。 */
    createdAt?: number;
}
/**
 * 一条评论线程，作为 {@link Element} 的能力存于 `element.comments`。
 *
 * - 锚点：`offset` 为**相对所属元素原点的偏移**（渲染时经元素世界矩阵还原为屏幕位置），
 *   随该元素及其祖先的平移 / 缩放 / 旋转、复制 / 删除 / 重组自然跟随。
 *   「画布级评论」即挂在页/帧或根元素上的线程 —— 无需区分 canvas / element 锚点。
 * - 归属页（如 PPTX 幻灯片）由元素在文档树中的位置决定，无需显式 pageId。
 * - 线程级数据（offset / resolved）归线程本身；对话内容在 `messages`。
 */
interface CommentThread {
    id?: string;
    /** 锚点偏移（相对所属元素原点）。 */
    offset?: CommentOffset;
    /** 是否已解决。 */
    resolved?: boolean;
    /** 对话消息（首条为创建，其后为回复）。 */
    messages?: CommentMessage[];
}
interface NormalizedCommentMessage {
    id: string;
    author?: CommentAuthor;
    body: string;
    createdAt?: number;
}
interface NormalizedCommentThread {
    id: string;
    offset?: CommentOffset;
    resolved?: boolean;
    messages: NormalizedCommentMessage[];
}
declare function normalizeCommentMessage(message: CommentMessage): NormalizedCommentMessage;
declare function normalizeCommentThread(thread: CommentThread): NormalizedCommentThread;
declare function normalizeComments(comments?: CommentThread[]): NormalizedCommentThread[] | undefined;

type ConnectionMode = 'straight' | 'orthogonal' | 'curved';
interface ConnectionAnchor {
    id: string;
    idx?: number;
}
interface Connection {
    start?: ConnectionAnchor;
    end?: ConnectionAnchor;
    mode?: ConnectionMode;
}
interface NormalizedConnection {
    start?: ConnectionAnchor;
    end?: ConnectionAnchor;
    mode: ConnectionMode;
}
declare function normalizeConnection(connection: Connection): NormalizedConnection;

interface PropertyDeclaration {
    [key: string]: unknown;
    default?: unknown | (() => unknown);
    fallback?: unknown | (() => unknown);
    alias?: string;
    internal?: boolean;
    internalKey: symbol | string;
}
interface PropertyAccessor {
    /** `declaration` is a fast-path hint from decorated accessors; implementations may ignore it. */
    getProperty?: (key: string, declaration?: PropertyDeclaration) => any;
    setProperty?: (key: string, newValue: any, declaration?: PropertyDeclaration) => void;
    onUpdateProperty?: (key: string, newValue: any, oldValue: any) => void;
}
declare function getDeclarations(constructor: any): Record<string, PropertyDeclaration>;
declare function propertyOffsetSet(target: any & PropertyAccessor, key: string, newValue: any, declaration: PropertyDeclaration): void;
declare function propertyOffsetGet(target: any & PropertyAccessor, key: string, declaration: PropertyDeclaration): any;
declare function propertyOffsetFallback(target: any & PropertyAccessor, key: string, declaration: PropertyDeclaration): any;
declare function getPropertyDescriptor<V, T extends PropertyAccessor>(key: string, declaration: PropertyDeclaration): {
    get: () => any;
    set: (v: any) => void;
};
declare function defineProperty<V, T extends PropertyAccessor>(constructor: any, key: string, declaration?: Partial<PropertyDeclaration>): void;
declare function property<V, T extends PropertyAccessor>(declaration?: Partial<PropertyDeclaration>): PropertyDecorator;
declare function property2<V, T extends PropertyAccessor>(declaration?: Partial<PropertyDeclaration>): (_: ClassAccessorDecoratorTarget<T, V>, context: ClassAccessorDecoratorContext) => ClassAccessorDecoratorResult<T, V>;

type LineEndType = 'oval' | 'stealth' | 'triangle' | 'arrow' | 'diamond';
type LineEndSize = 'sm' | 'md' | 'lg';
type OutlineStyle = 'dashed' | 'solid' | string;
interface TailEnd {
    type: LineEndType;
    width?: WithNone<LineEndSize>;
    height?: WithNone<LineEndSize>;
}
interface HeadEnd {
    type: LineEndType;
    width?: WithNone<LineEndSize>;
    height?: WithNone<LineEndSize>;
}
interface NormalizedBaseOutline {
    width?: number;
    style?: OutlineStyle;
    lineCap?: LineCap;
    lineJoin?: LineJoin;
    headEnd?: HeadEnd;
    tailEnd?: TailEnd;
}
type OutlineObject = FillObject & Partial<NormalizedBaseOutline>;
type NormalizedOutline = NormalizedFill & NormalizedBaseOutline;
type Outline = string | OutlineObject;

declare function normalizeOutline(outline: Outline): NormalizedOutline;

interface NormalizedOutlineStyle {
    outlineWidth: number;
    outlineOffset: number;
    outlineColor: WithStyleNone<NormalizedColor>;
    outlineStyle: string;
}
declare function getDefaultOutlineStyle(): NormalizedOutlineStyle;

type BoxShadow = string;
type Shadow = BoxShadow | ShadowObject;
type ShadowObject = Partial<Toggleable> & Partial<NormalizedShadow> & {
    color?: WithNone<Color>;
};
interface NormalizedShadow extends Toggleable {
    color: NormalizedColor;
    offsetX?: number;
    offsetY?: number;
    blur?: number;
}

declare function normalizeShadow(shadow: Shadow): NormalizedShadow;

interface NormalizedShadowStyle {
    boxShadow: BoxShadow;
    shadowColor?: NormalizedColor;
    shadowOffsetX?: number;
    shadowOffsetY?: number;
    shadowBlur?: number;
}
declare function getDefaultShadowStyle(): NormalizedShadowStyle;

/**
 * 滤镜/调色。字段与语义对齐 CSS filter 函数（可经 stringifyFilter 无损转成 CSS filter 字符串），
 * 并扩展若干 CSS 无等价、但 OOXML a:blip 支持的项（duotone / biLevel / colorChange）。
 */
interface Filter {
    /** filter: blur(Npx) */
    blur?: number;
    /** filter: brightness(N)，1 = 原值 */
    brightness?: number;
    /** filter: contrast(N)，1 = 原值 */
    contrast?: number;
    /** filter: grayscale(0~1) */
    grayscale?: number;
    /** filter: hue-rotate(Ndeg) */
    hueRotate?: number;
    /** filter: invert(0~1) */
    invert?: number;
    /** filter: opacity(0~1) */
    opacity?: number;
    /** filter: saturate(N)，1 = 原值 */
    saturate?: number;
    /** filter: sepia(0~1) */
    sepia?: number;
    /** 双色调，[暗, 亮] 两色映射（OOXML a:duotone，无 CSS 等价） */
    duotone?: [Color, Color];
    /** 黑白阈值 0~1（OOXML a:biLevel，无直接 CSS 等价） */
    biLevel?: number;
    /** 颜色替换（OOXML a:clrChange，无 CSS 等价） */
    colorChange?: {
        from: Color;
        to: Color;
    };
}
interface NormalizedFilter {
    blur?: number;
    brightness?: number;
    contrast?: number;
    grayscale?: number;
    hueRotate?: number;
    invert?: number;
    opacity?: number;
    saturate?: number;
    sepia?: number;
    duotone?: [NormalizedColor, NormalizedColor];
    biLevel?: number;
    colorChange?: {
        from: NormalizedColor;
        to: NormalizedColor;
    };
}
declare function normalizeFilter(filter: Filter): NormalizedFilter;
/**
 * 把 Filter 转成 CSS filter 字符串（仅含有 CSS 等价的项）。
 * duotone / biLevel / colorChange 无 CSS filter 形式，自动跳过。
 */
declare function stringifyFilter(filter: NormalizedFilter): string;
interface _EffectV0 {
    transformOrigin?: string;
    rotate?: number;
    scaleX?: number;
    scaleY?: number;
    skewX?: number;
    skewY?: number;
    translateX?: number;
    translateY?: number;
    shadowOffsetX?: number;
    shadowOffsetY?: number;
    shadowBlur?: number;
    shadowColor?: string;
    textStrokeWidth?: number;
    textStrokeColor?: string;
    color?: string;
}
interface Effect {
    fill?: WithNone<Fill>;
    outline?: WithNone<Outline>;
    shadow?: WithNone<Shadow>;
    transform?: WithStyleNone<string>;
    transformOrigin?: string;
    /** 滤镜/调色（灰度/双色调/亮度/对比度等），多用于图片元素的整图调色 */
    filter?: Filter;
}
interface NormalizedEffect {
    fill?: NormalizedFill;
    outline?: NormalizedOutline;
    shadow?: NormalizedShadow;
    transform?: string;
    transformOrigin?: string;
    filter?: NormalizedFilter;
}
declare const effectFields: (keyof Effect)[];
declare function normalizeEffect(effect: _EffectV0 & Effect): NormalizedEffect;

interface NormalizedBaseForeground {
    fillWithShape?: boolean;
}
type NormalizedForeground = NormalizedBaseForeground & NormalizedFill;
type ForegroundObject = Partial<NormalizedBaseForeground> & FillObject;
type Foreground = string | ForegroundObject;
declare function normalizeForeground(foreground: Foreground): NormalizedForeground | undefined;

interface Meta {
    [key: string]: any;
}

interface Node<T = Meta> {
    name?: string;
    children?: Node[];
    meta?: T;
}

type Shape = SVGPathData | SVGPathData[] | ShapePath[] | NormalizedShape;
type SVGPathData = string;
type FillRule = 'nonzero' | 'evenodd';
type StrokeLinecap = 'butt' | 'round' | 'square';
type StrokeLinejoin = 'arcs' | 'bevel' | 'miter' | 'miter-clip' | 'round';
interface ShapePathStyle {
    [key: string]: any;
    opacity: number;
    visibility: string;
    shadowColor: NormalizedColor;
    shadowOffsetX: number;
    shadowOffsetY: number;
    shadowBlur: number;
    fill: string;
    fillOpacity: number;
    fillRule: FillRule;
    stroke: string;
    strokeOpacity: number;
    strokeWidth: number;
    strokeLinecap: StrokeLinecap;
    strokeLinejoin: StrokeLinejoin;
    strokeMiterlimit: number;
    strokeDasharray: number[];
    strokeDashoffset: number;
}
interface ShapePath extends Partial<ShapePathStyle> {
    data: SVGPathData;
}
interface ShapeConnectionPoint {
    idx: number;
    x: number;
    y: number;
    ang?: number;
}
interface NormalizedShape extends Toggleable {
    preset?: string;
    viewBox?: number[];
    svg?: string;
    paths?: ShapePath[];
    connectionPoints?: ShapeConnectionPoint[];
}
declare function normalizeShape(shape: Shape): NormalizedShape;

type StyleUnit = `${number}%` | number;
type Display = 'inherit' | 'freeform' | 'flex';
type Direction = 'inherit' | 'ltr' | 'rtl';
type Overflow = 'hidden' | 'visible' | 'clip' | 'scroll' | 'auto';
type Visibility = 'hidden' | 'visible';
type FontWeight = 'normal' | 'bold' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
type FontStyle = 'normal' | 'italic' | 'oblique' | `oblique ${string}`;
type FontKerning = WithStyleNone<'auto' | 'normal'>;
type TextWrap = 'wrap' | 'nowrap';
type TextAlign = WithStyleNone<'center' | 'end' | 'left' | 'right' | 'start' | 'justify'>;
type TextTransform = WithStyleNone<'uppercase' | 'lowercase'>;
type TextOrientation = 'mixed' | 'upright' | 'sideways-right' | 'sideways';
type TextDecoration = WithStyleNone<'underline' | 'line-through' | 'overline'>;
type VerticalAlign = 'baseline' | 'top' | 'middle' | 'bottom' | 'sub' | 'super' | 'text-top' | 'text-bottom';
type WritingMode = 'horizontal-tb' | 'vertical-lr' | 'vertical-rl';
type Align = 'auto' | 'flex-start' | 'center' | 'flex-end' | 'stretch' | 'baseline' | 'space-between' | 'space-around' | 'space-evenly';
type FlexDirection = 'column' | 'column-reverse' | 'row' | 'row-reverse';
type FlexWrap = 'nowrap' | 'wrap' | 'Wrap-reverse';
type Justify = 'flex-start' | 'center' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly';
type Position = 'static' | 'relative' | 'absolute';
type BorderStyle = WithStyleNone<'dashed' | 'solid'>;
type BoxSizing = 'border-box' | 'content-box';
type PointerEvents = 'auto' | 'none';
type ListStyleType = WithStyleNone<'disc' | 'circle' | 'square' | 'decimal' | 'decimal-leading-zero' | 'lower-alpha' | 'upper-alpha' | 'lower-roman' | 'upper-roman' | 'lower-greek' | 'cjk-decimal' | 'trad-chinese-informal' | 'simp-chinese-informal' | 'japanese-informal' | 'hiragana' | 'katakana' | (string & {})>;
type ListStyleImage = WithStyleNone<string>;
type ListStyleColormap = WithStyleNone<Record<string, string>>;
type ListStyleSize = StyleUnit | `${number}rem` | 'cover';
type ListStylePosition = 'inside' | 'outside';
type HighlightLine = TextDecoration | 'outline';
type HighlightImage = WithStyleNone<string>;
type HighlightReferImage = WithStyleNone<string>;
type HighlightColormap = WithStyleNone<Record<string, string>>;
type HighlightSize = StyleUnit | `${number}rem` | 'cover';
type HighlightThickness = StyleUnit;

interface NormalizedLayoutStyle {
    overflow: Overflow;
    direction: Direction;
    display: Display;
    boxSizing: BoxSizing;
    width: StyleUnit | 'auto';
    height: StyleUnit | 'auto';
    maxHeight: StyleUnit;
    maxWidth: StyleUnit;
    minHeight: StyleUnit;
    minWidth: StyleUnit;
    position: Position;
    left: StyleUnit;
    top: StyleUnit;
    right: StyleUnit;
    bottom: StyleUnit;
    borderTop: string;
    borderLeft: string;
    borderRight: string;
    borderBottom: string;
    borderWidth: number;
    border: string;
    flex: number;
    flexBasis: StyleUnit | 'auto';
    flexDirection: FlexDirection;
    flexGrow: number;
    flexShrink: number;
    flexWrap: FlexWrap;
    alignContent: Align;
    alignItems: Align;
    alignSelf: Align;
    justifyContent: Justify;
    gap: StyleUnit;
    marginTop: WithStyleNone<StyleUnit | 'auto'>;
    marginLeft: WithStyleNone<StyleUnit | 'auto'>;
    marginRight: WithStyleNone<StyleUnit | 'auto'>;
    marginBottom: WithStyleNone<StyleUnit | 'auto'>;
    margin: WithStyleNone<StyleUnit | 'auto'>;
    paddingTop: StyleUnit;
    paddingLeft: StyleUnit;
    paddingRight: StyleUnit;
    paddingBottom: StyleUnit;
    padding: StyleUnit;
}
declare function getDefaultLayoutStyle(): Partial<NormalizedLayoutStyle>;

interface NormalizedTransformStyle {
    rotate: number;
    scaleX: number;
    scaleY: number;
    skewX: number;
    skewY: number;
    translateX: number;
    translateY: number;
    transform: WithStyleNone<string>;
    transformOrigin: string;
}
declare function getDefaultTransformStyle(): NormalizedTransformStyle;

type NormalizedElementStyle = Partial<NormalizedLayoutStyle> & NormalizedTransformStyle & NormalizedShadowStyle & NormalizedOutlineStyle & NormalizedBackgroundStyle & {
    borderRadius: number;
    borderColor: WithStyleNone<NormalizedColor>;
    borderStyle: BorderStyle;
    visibility: Visibility;
    filter: string;
    opacity: number;
    pointerEvents: PointerEvents;
    maskImage: WithStyleNone<string>;
};
declare function getDefaultElementStyle(): NormalizedElementStyle;

interface NormalizedHighlight {
    image: HighlightImage;
    referImage: HighlightReferImage;
    colormap: HighlightColormap;
    line: HighlightLine;
    size: HighlightSize;
    thickness: HighlightThickness;
}
interface NormalizedHighlightStyle {
    highlight: Partial<NormalizedHighlight>;
    highlightImage: HighlightImage;
    highlightReferImage: HighlightReferImage;
    highlightColormap: HighlightColormap;
    highlightLine: HighlightLine;
    highlightSize: HighlightSize;
    highlightThickness: HighlightThickness;
}
declare function getDefaultHighlightStyle(): Required<NormalizedHighlightStyle>;

interface NormalizedListStyle {
    type: ListStyleType;
    image: ListStyleImage;
    colormap: ListStyleColormap;
    size: ListStyleSize;
    position: ListStylePosition;
}
interface NormalizedListStyleStyle {
    listStyle: Partial<NormalizedListStyle>;
    listStyleType: ListStyleType;
    listStyleImage: ListStyleImage;
    listStyleColormap: ListStyleColormap;
    listStyleSize: ListStyleSize;
    listStylePosition: ListStylePosition;
}
declare function getDefaultListStyleStyle(): NormalizedListStyleStyle;

type NormalizedTextInlineStyle = NormalizedHighlightStyle & {
    color: NormalizedColor;
    verticalAlign: VerticalAlign;
    letterSpacing: number;
    wordSpacing: number;
    fontSize: number;
    fontWeight: FontWeight;
    fontFamily: string;
    fontStyle: FontStyle;
    fontKerning: FontKerning;
    textTransform: TextTransform;
    textOrientation: TextOrientation;
    textDecoration: TextDecoration;
};
declare function getDefaultTextInlineStyle(): Required<NormalizedTextInlineStyle>;

type NormalizedTextLineStyle = NormalizedListStyleStyle & {
    writingMode: WritingMode;
    textWrap: TextWrap;
    textAlign: TextAlign;
    textIndent: number;
    lineHeight: number;
};
declare function getDefaultTextLineStyle(): NormalizedTextLineStyle;

interface NormalizedTextDrawStyle {
    textStrokeWidth: number;
    textStrokeColor: WithStyleNone<NormalizedColor>;
}
type NormalizedTextStyle = NormalizedTextLineStyle & NormalizedTextInlineStyle & NormalizedTextDrawStyle;
declare function getDefaultTextStyle(): NormalizedTextStyle;

type FullStyle = NormalizedTextStyle & NormalizedElementStyle;
type NormalizedStyle = Partial<FullStyle>;
type StyleObject = NormalizedStyle & {
    color?: WithStyleNone<Color>;
    backgroundColor?: WithStyleNone<Color>;
    borderColor?: WithStyleNone<Color>;
    outlineColor?: WithStyleNone<Color>;
    shadowColor?: WithStyleNone<Color>;
};
type Style = StyleObject;
declare function normalizeStyle(style: Style): NormalizedStyle;
declare function getDefaultStyle(): FullStyle;

interface TableColumnObject {
    width?: number;
}
interface TableRowObject {
    height?: number;
}
interface NormalizedTableColumn {
    width?: number;
}
interface NormalizedTableRow {
    height?: number;
}
interface TableCellObject {
    row: number;
    col: number;
    rowSpan?: number;
    colSpan?: number;
    children?: Element[];
    background?: Background;
    style?: Style;
}
interface NormalizedTableCell {
    row: number;
    col: number;
    rowSpan?: number;
    colSpan?: number;
    children: NormalizedElement[];
    background?: NormalizedBackground;
    style?: NormalizedStyle;
}
interface TableObject extends Partial<Toggleable> {
    columns?: TableColumnObject[];
    rows?: TableRowObject[];
    cells?: TableCellObject[];
}
type Table = TableObject;
interface NormalizedTable extends Toggleable {
    columns: NormalizedTableColumn[];
    rows: NormalizedTableRow[];
    cells: NormalizedTableCell[];
}
declare function normalizeTable(table: Table): NormalizedTable;

type Text = string | FlatTextContent[] | TextObject;
interface FragmentObject extends StyleObject {
    content: string;
    fill?: Fill;
    outline?: Outline;
}
interface NormalizedFragment extends NormalizedStyle {
    content: string;
    fill?: NormalizedFill;
    outline?: NormalizedOutline;
}
interface ParagraphObject extends StyleObject {
    fragments: FragmentObject[];
    fill?: Fill;
    outline?: Outline;
}
interface NormalizedParagraph extends NormalizedStyle {
    fragments: NormalizedFragment[];
    fill?: NormalizedFill;
    outline?: NormalizedOutline;
}
type FlatTextContent = string | FragmentObject | ParagraphObject | (string | FragmentObject)[];
type TextContent = FlatTextContent | FlatTextContent[];
type NormalizedTextContent = NormalizedParagraph[];
interface TextDeformation {
    type: string;
    intensities?: number[];
    maxFontSize?: number;
}
interface NormalizedTextDeformation {
    type: string;
    intensities?: number[];
    maxFontSize: number;
}
interface TextObject extends Pick<Effect, 'fill' | 'outline'>, Partial<Toggleable> {
    content?: TextContent;
    style?: Style;
    deformation?: TextDeformation;
    measureDom?: any;
    fonts?: any;
    effects?: Effect[];
}
interface NormalizedText extends Pick<NormalizedEffect, 'fill' | 'outline'>, Toggleable {
    content: NormalizedTextContent;
    style?: NormalizedStyle;
    deformation?: NormalizedTextDeformation;
    effects?: NormalizedEffect[];
    measureDom?: any;
    fonts?: any;
}
declare function hasCRLF(content: string): boolean;
declare function isCRLF(char: string): boolean;
declare function normalizeCRLF(content: string): string;
declare function normalizeTextContent(value: TextContent): NormalizedTextContent;
declare function isParagraphObject(value: any): value is ParagraphObject;
declare function isFragmentObject(value: any): value is FragmentObject;
declare function normalizeTextDeformation(deformation: TextDeformation): NormalizedTextDeformation;
declare function normalizeText(value: Text): NormalizedText;
declare function textContentToString(value: TextContent): string;

interface NormalizedVideo {
    src: string;
}
type Video = string | NormalizedVideo;
declare function normalizeVideo(video: Video): NormalizedVideo | undefined;

interface Element<T = Meta> extends Effect, Omit<Node<T>, 'children'> {
    id?: string;
    style?: WithNone<Style>;
    text?: WithNone<Text>;
    background?: WithNone<Background>;
    shape?: WithNone<Shape>;
    foreground?: WithNone<Foreground>;
    video?: WithNone<Video>;
    audio?: WithNone<Audio>;
    connection?: WithNone<Connection>;
    table?: WithNone<Table>;
    chart?: WithNone<Chart>;
    /** 评论线程。挂在哪个元素即归属哪个元素 / 页；offset 相对该元素原点。 */
    comments?: CommentThread[];
    children?: Element[];
}
interface NormalizedElement<T = Meta> extends NormalizedEffect, Omit<Node<T>, 'children'> {
    id: string;
    style?: NormalizedStyle;
    text?: NormalizedText;
    background?: NormalizedBackground;
    shape?: NormalizedShape;
    foreground?: NormalizedForeground;
    video?: NormalizedVideo;
    audio?: NormalizedAudio;
    connection?: NormalizedConnection;
    table?: NormalizedTable;
    chart?: NormalizedChart;
    comments?: NormalizedCommentThread[];
    children?: NormalizedElement[];
}
declare function normalizeElement<T = Meta>(element: Element<T>): NormalizedElement<T>;

interface Document extends Element {
    fonts?: any;
}
interface NormalizedDocument extends NormalizedElement {
    fonts?: any;
}
declare function normalizeDocument(doc: Document): NormalizedDocument;

interface FlatElement extends Omit<Element, 'children'> {
    parentId?: string;
    childrenIds?: string[];
}
interface FlatDocument extends Omit<Element, 'children'> {
    fonts?: any;
    children: Record<string, FlatElement>;
}
interface NormalizedFlatElement extends Omit<NormalizedElement, 'children'> {
    parentId?: string;
    childrenIds?: string[];
}
interface NormalizedFlatDocument {
    fonts?: any;
    children: Record<string, NormalizedFlatElement>;
}
declare function normalizeFlatDocument(doc: FlatDocument): NormalizedFlatDocument;
declare function flatDocumentToDocument(flatDoc: FlatDocument): Document;

type IdGenerator = () => string;
declare const nanoid: IdGenerator;
declare const idGenerator: IdGenerator;

type EventListenerValue<T extends any[] = any[]> = (...args: T) => void;
type EventListenerOptions = boolean | {
    once?: boolean;
};
interface EventListener<T extends any[] = any[]> {
    value: EventListenerValue<T>;
    options?: EventListenerOptions;
}
declare class EventEmitter<T extends Record<string, any> = Record<string, any>> {
    eventListeners: Map<keyof T, EventListener<any[]> | EventListener<any[]>[]>;
    addEventListener<K extends keyof T>(event: K, listener: EventListenerValue<T[K]>, options?: EventListenerOptions): this;
    removeEventListener<K extends keyof T>(event: K, listener: EventListenerValue<T[K]>, options?: EventListenerOptions): this;
    removeAllListeners(): this;
    hasEventListener(event: string): boolean;
    dispatchEvent<K extends keyof T>(event: K, ...args: T[K]): boolean;
    on<K extends keyof T>(event: K, listener: EventListenerValue<T[K]>, options?: EventListenerOptions): this;
    once<K extends keyof T>(event: K, listener: EventListenerValue<T[K]>): this;
    off<K extends keyof T>(event: K, listener: EventListenerValue<T[K]>, options?: EventListenerOptions): this;
    emit<K extends keyof T>(event: K, ...args: T[K]): void;
}

declare function isNone<T>(value: T): value is Extract<T, null | undefined | '' | 'none'>;
declare function round(number: number, digits?: number, base?: number): number;
/**
 * Defensively coerce an unknown value to a finite number.
 * - number: returned as-is when finite, otherwise `fallback`
 * - string: parsed via parseFloat (e.g. '20' / '20px' -> 20), `fallback` when not finite
 * - anything else: `fallback`
 */
declare function normalizeNumber(value: unknown, fallback?: number): number | undefined;
declare function clearUndef<T>(obj: T, deep?: boolean): T;
declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;

declare function isEqualObject(a: any, b: any): boolean;
declare function getNestedValue(obj: any, path: (string | number)[], fallback?: any): any;
declare function setNestedValue(obj: any, path: (string | number)[], value: any): void;
declare function getObjectValueByPath(obj: any, path: string, fallback?: any): any;
declare function setObjectValueByPath(obj: any, path: string, value: any): void;

interface ObservableEvents {
    [event: string]: any[];
}
declare class Observable<T extends ObservableEvents = ObservableEvents> {
    protected _eventListeners: Record<string, any[]>;
    on<K extends keyof T & string>(event: K, listener: (...args: T[K]) => void): this;
    once<K extends keyof T & string>(event: K, listener: (...args: T[K]) => void): this;
    off<K extends keyof T & string>(event: K, listener: (...args: T[K]) => void): this;
    emit<K extends keyof T & string>(event: K, ...args: T[K]): this;
    removeAllListeners(): this;
    hasEventListener(event: string): boolean;
    destroy(): void;
}

declare class RawWeakMap<K extends WeakKey = WeakKey, V = any> {
    protected _map: WeakMap<K, V>;
    protected _toRaw(value: any): any;
    delete(key: K): boolean;
    get(key: K): V | undefined;
    has(key: K): boolean;
    set(key: K, value: V): this;
}

interface ReactivableEvents extends ObservableEvents {
    updateProperty: [key: string, newValue: any, oldValue: any];
    destroy: [];
}
interface Reactivable {
    on: <K extends keyof ReactivableEvents & string>(event: K, listener: (...args: ReactivableEvents[K]) => void) => this;
    once: <K extends keyof ReactivableEvents & string>(event: K, listener: (...args: ReactivableEvents[K]) => void) => this;
    off: <K extends keyof ReactivableEvents & string>(event: K, listener: (...args: ReactivableEvents[K]) => void) => this;
    emit: <K extends keyof ReactivableEvents & string>(event: K, ...args: ReactivableEvents[K]) => this;
}
declare class Reactivable extends Observable implements PropertyAccessor {
    protected _propertyAccessor?: PropertyAccessor;
    protected _properties: Record<string, any>;
    protected _updatedProperties: Record<string, any>;
    protected _changedProperties: Set<string>;
    protected _updatingPromise: Promise<void>;
    protected _updating: boolean;
    constructor(properties?: Record<string, any>);
    isDirty(key?: string): boolean;
    offsetGetProperty(key: string): any;
    offsetSetProperty(key: string, value: any): void;
    offsetGetProperties(keys?: string[]): Record<string, any>;
    offsetSetProperties(properties?: Record<string, any>): this;
    getProperty(key: string, declaration?: PropertyDeclaration | undefined): any;
    setProperty(key: string, newValue: any, declaration?: PropertyDeclaration | undefined): void;
    getProperties(keys?: string[]): Record<string, any>;
    setProperties(properties?: Record<string, any>): this;
    resetProperties(): this;
    getPropertyDeclarations(): Record<string, PropertyDeclaration>;
    getPropertyDeclaration(key: string): PropertyDeclaration | undefined;
    setPropertyAccessor(accessor?: PropertyAccessor): this;
    protected _nextTick(): Promise<void>;
    protected _enqueueUpdate(): Promise<void>;
    onUpdate(): void;
    onUpdateProperty(key: string, newValue: any, oldValue: any): void;
    requestUpdate(key?: string, newValue?: any, oldValue?: any): void;
    protected _update(changed: Record<string, any>): void;
    protected _updateProperty(key: string, newValue: any, oldValue: any): void;
    toJSON(): Record<string, any>;
    clone(): this;
    destroy(): void;
}

export { EventEmitter, Observable, RawWeakMap, Reactivable, clearUndef, colorFillFields, defaultColor, defineProperty, effectFields, flatDocumentToDocument, getDeclarations, getDefaultBackgroundStyle, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOutlineStyle, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, getNestedValue, getObjectValueByPath, getPropertyDescriptor, gradientFillFields, hasCRLF, idGenerator, imageFillFiedls, isCRLF, isColor, isColorFill, isColorFillObject, isEqualObject, isFragmentObject, isGradient, isGradientFill, isGradientFillObject, isImageFill, isImageFillObject, isNone, isParagraphObject, isPresetFill, isPresetFillObject, nanoid, normalizeAudio, normalizeBackground, normalizeCRLF, normalizeChart, normalizeColor, normalizeColorFill, normalizeCommentMessage, normalizeCommentThread, normalizeComments, normalizeConnection, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeFilter, normalizeFlatDocument, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeImagePipeline, normalizeNumber, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeStyle, normalizeTable, normalizeText, normalizeTextContent, normalizeTextDeformation, normalizeVideo, parseColor, parseGradient, pick, presetFillFiedls, property, property2, propertyOffsetFallback, propertyOffsetGet, propertyOffsetSet, round, setNestedValue, setObjectValueByPath, stringifyFilter, stringifyGradient, textContentToString };
export type { Align, AngularNode, Audio, Background, BackgroundObject, BackgroundSize, BorderStyle, BoxShadow, BoxSizing, Chart, ChartAxis, ChartGrouping, ChartLegend, ChartObject, ChartSeriesObject, ChartType, CmykColor, CmykaColor, Color, ColorFill, ColorFillObject, ColorStop, ColorStopNode, CommentAuthor, CommentMessage, CommentOffset, CommentThread, Connection, ConnectionAnchor, ConnectionMode, DefaultRadialNode, Direction, DirectionalNode, Display, Document, Effect, Element, EmNode, EventListener, EventListenerOptions, EventListenerValue, ExtentKeywordNode, Fill, FillObject, FillRule, Filter, FlatDocument, FlatElement, FlatTextContent, FlexDirection, FlexWrap, FontKerning, FontStyle, FontWeight, Foreground, ForegroundObject, FragmentObject, FullStyle, GradientFill, GradientFillObject, GradientNode, HeadEnd, Hex8Color, HexNode, HighlightColormap, HighlightImage, HighlightLine, HighlightReferImage, HighlightSize, HighlightThickness, HslColor, HslaColor, HsvColor, HsvaColor, HwbColor, HwbaColor, IdGenerator, ImageFill, ImageFillCropRect, ImageFillObject, ImageFillStretchRect, ImageFillTile, ImagePipeline, Justify, LabColor, LabaColor, LchColor, LchaColor, LineCap, LineEndSize, LineEndType, LineJoin, LinearGradient, LinearGradientNode, LinearGradientWithType, ListStyleColormap, ListStyleImage, ListStylePosition, ListStyleSize, ListStyleType, LiteralNode, Meta, Node, None, NormalizedAudio, NormalizedBackground, NormalizedBackgroundStyle, NormalizedBaseBackground, NormalizedBaseForeground, NormalizedBaseOutline, NormalizedChart, NormalizedChartSeries, NormalizedColor, NormalizedColorFill, NormalizedCommentMessage, NormalizedCommentThread, NormalizedConnection, NormalizedDocument, NormalizedEffect, NormalizedElement, NormalizedElementStyle, NormalizedFill, NormalizedFilter, NormalizedFlatDocument, NormalizedFlatElement, NormalizedForeground, NormalizedFragment, NormalizedGradientFill, NormalizedHighlight, NormalizedHighlightStyle, NormalizedImageFill, NormalizedImagePipeline, NormalizedLayoutStyle, NormalizedListStyle, NormalizedListStyleStyle, NormalizedOutline, NormalizedOutlineStyle, NormalizedParagraph, NormalizedPresetFill, NormalizedShadow, NormalizedShadowStyle, NormalizedShape, NormalizedStyle, NormalizedTable, NormalizedTableCell, NormalizedTableColumn, NormalizedTableRow, NormalizedText, NormalizedTextContent, NormalizedTextDeformation, NormalizedTextDrawStyle, NormalizedTextInlineStyle, NormalizedTextLineStyle, NormalizedTextStyle, NormalizedTransformStyle, NormalizedVideo, ObjectColor, ObservableEvents, Outline, OutlineObject, OutlineStyle, Overflow, ParagraphObject, PercentNode, PipelineImage, PointerEvents, Position, PositionKeywordNode, PositionNode, PresetFill, PresetFillObject, PropertyAccessor, PropertyDeclaration, PxNode, RadialGradient, RadialGradientNode, RadialGradientWithType, ReactivableEvents, RepeatingLinearGradientNode, RepeatingRadialGradientNode, RgbColor, RgbNode, RgbaColor, RgbaNode, SVGPathData, Shadow, ShadowObject, Shape, ShapeConnectionPoint, ShapeNode, ShapePath, ShapePathStyle, StrokeLinecap, StrokeLinejoin, Style, StyleObject, StyleUnit, Table, TableCellObject, TableColumnObject, TableObject, TableRowObject, TailEnd, Text, TextAlign, TextContent, TextDecoration, TextDeformation, TextObject, TextOrientation, TextTransform, TextWrap, Toggleable, Uint32Color, VerticalAlign, Video, Visibility, WithNone, WithStyleNone, WritingMode, XyzColor, XyzaColor, _EffectV0 };
