@psrt/sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -9
- package/dist/browser/index.d.ts +260 -0
- package/dist/browser/index.js +3447 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/index.cjs +2422 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -4
- package/dist/index.d.ts +85 -4
- package/dist/index.js +2414 -34
- package/dist/index.js.map +1 -1
- package/package.json +17 -6
- package/wasm/psrt.wasm +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
+
/** Initializes PSRT. Call once at app startup before any other SDK API. */
|
|
2
|
+
declare function initPsrt(): Promise<void>;
|
|
3
|
+
|
|
4
|
+
declare const CompileStep: {
|
|
5
|
+
readonly RESOLVE: "resolve";
|
|
6
|
+
readonly BUILD_ASSETS: "buildAssets";
|
|
7
|
+
readonly ADAPT_STYLE: "adaptStyle";
|
|
8
|
+
readonly RENDER_FONTS: "renderFonts";
|
|
9
|
+
readonly RENDER_HEAD: "renderHead";
|
|
10
|
+
readonly RENDER_PAGE: "renderPage";
|
|
11
|
+
readonly RENDER_TEXT: "renderText";
|
|
12
|
+
readonly RENDER_MASK: "renderMask";
|
|
13
|
+
readonly RENDER_INLINE: "renderInline";
|
|
14
|
+
readonly FINALIZE: "finalize";
|
|
15
|
+
};
|
|
16
|
+
type CompileStep = (typeof CompileStep)[keyof typeof CompileStep];
|
|
17
|
+
type CompileStepContext = {
|
|
18
|
+
step: typeof CompileStep.RESOLVE;
|
|
19
|
+
doc: PsrtDocument;
|
|
20
|
+
} | {
|
|
21
|
+
step: typeof CompileStep.BUILD_ASSETS;
|
|
22
|
+
assetCount: number;
|
|
23
|
+
canvasSizes: Record<string, {
|
|
24
|
+
w: number;
|
|
25
|
+
h: number;
|
|
26
|
+
}>;
|
|
27
|
+
} | {
|
|
28
|
+
step: typeof CompileStep.ADAPT_STYLE;
|
|
29
|
+
pageName: string;
|
|
30
|
+
blockIndex: number;
|
|
31
|
+
kind: 'text' | 'mask';
|
|
32
|
+
} | {
|
|
33
|
+
step: typeof CompileStep.RENDER_FONTS;
|
|
34
|
+
fontCount: number;
|
|
35
|
+
} | {
|
|
36
|
+
step: typeof CompileStep.RENDER_HEAD;
|
|
37
|
+
title: string;
|
|
38
|
+
} | {
|
|
39
|
+
step: typeof CompileStep.RENDER_PAGE;
|
|
40
|
+
pageIndex: number;
|
|
41
|
+
pageName: string;
|
|
42
|
+
canvasW: number;
|
|
43
|
+
canvasH: number;
|
|
44
|
+
} | {
|
|
45
|
+
step: typeof CompileStep.RENDER_TEXT;
|
|
46
|
+
pageName: string;
|
|
47
|
+
textIndex: number;
|
|
48
|
+
contentPreview: string;
|
|
49
|
+
} | {
|
|
50
|
+
step: typeof CompileStep.RENDER_MASK;
|
|
51
|
+
pageName: string;
|
|
52
|
+
maskIndex: number;
|
|
53
|
+
} | {
|
|
54
|
+
step: typeof CompileStep.RENDER_INLINE;
|
|
55
|
+
pageName: string;
|
|
56
|
+
textIndex: number;
|
|
57
|
+
htmlLength: number;
|
|
58
|
+
} | {
|
|
59
|
+
step: typeof CompileStep.FINALIZE;
|
|
60
|
+
htmlLength: number;
|
|
61
|
+
pageCount: number;
|
|
62
|
+
};
|
|
63
|
+
type CompileStepObserver = (ctx: CompileStepContext) => void;
|
|
64
|
+
type CompileStepObservers = Partial<Record<CompileStep, CompileStepObserver[]>>;
|
|
65
|
+
declare function notifyObservers(observers: CompileStepObservers | undefined, ctx: CompileStepContext): void;
|
|
66
|
+
|
|
1
67
|
/** JSON object or compact style string from PSRT. */
|
|
2
68
|
type PsrtStyle = Record<string, unknown> | string;
|
|
3
69
|
/** Canonical PSRT document representation. */
|
|
@@ -54,8 +120,17 @@ interface CompileOptions {
|
|
|
54
120
|
/** Omit the HTML variant switcher script (Ctrl+L). */
|
|
55
121
|
noScript?: boolean;
|
|
56
122
|
}
|
|
57
|
-
|
|
58
|
-
|
|
123
|
+
interface CompileToHtmlPureOptions extends CompileOptions {
|
|
124
|
+
observers?: CompileStepObservers;
|
|
125
|
+
/** Additional PSRT variants bundled into the same HTML (Ctrl+L to switch). */
|
|
126
|
+
variants?: PsrtVariant[];
|
|
127
|
+
}
|
|
128
|
+
/** One PSRT document bundled as an HTML variant alongside the primary doc. */
|
|
129
|
+
interface PsrtVariant {
|
|
130
|
+
/** Label shown in the variant switcher hint (defaults to variant-N). */
|
|
131
|
+
label?: string;
|
|
132
|
+
doc: PsrtDocument;
|
|
133
|
+
}
|
|
59
134
|
|
|
60
135
|
/** Converts a .psrt string into a typed PsrtDocument. */
|
|
61
136
|
declare function parse(psrtString: string): PsrtDocument;
|
|
@@ -64,8 +139,14 @@ declare function stringify(doc: PsrtDocument): string;
|
|
|
64
139
|
/** Formats a document with editor cleanup rules. */
|
|
65
140
|
declare function formatDocument(doc: PsrtDocument): string;
|
|
66
141
|
|
|
67
|
-
/**
|
|
142
|
+
/** Expands all @const@ placeholders in styles, content, and URLs. */
|
|
143
|
+
declare function resolveDocumentPure(doc: PsrtDocument): PsrtDocument;
|
|
144
|
+
|
|
145
|
+
/** Compiles the document to a self-contained HTML string (WASM). */
|
|
68
146
|
declare function compileToHtml(doc: PsrtDocument | string, options?: CompileOptions): string;
|
|
147
|
+
/** Compiles PsrtDocument to HTML using pure JavaScript (no WASM, no initPsrt). */
|
|
148
|
+
declare function compileToHtmlPure(doc: PsrtDocument, options?: CompileToHtmlPureOptions): string;
|
|
149
|
+
|
|
69
150
|
/** Compiles one page of the document to SVG. */
|
|
70
151
|
declare function compileToSvg(doc: PsrtDocument | string, pageName: string, options?: CompileOptions): string;
|
|
71
152
|
|
|
@@ -176,4 +257,4 @@ declare function resolveDocument(doc: PsrtDocument): PsrtDocument;
|
|
|
176
257
|
/** Like resolveDocument but throws on invalid style JSON after expansion. */
|
|
177
258
|
declare function resolveDocumentStrict(doc: PsrtDocument): PsrtDocument;
|
|
178
259
|
|
|
179
|
-
export { type CompileOptions, type Document, type MaskPositionFields, type Page, type PositionFields, type PsrtDocument, type PsrtMask, type PsrtPage, type PsrtStyle, type PsrtText, type TextBlock, Transformer, type WebPreviewStyle, adaptEntriesForWeb, addConst, addFont, addMask, addPage, addText, compileToHtml, compileToSvg, findMaskByIndex, findPage, findPageIndex, findTextByIndex, formatDocument, formatPageDocumentJSON, initPsrt, mergePageDocumentPSRT, mergeStyle, movePage, nudgeTextPosition, parse, parseTextIndex, removeConst, removeFont, removeMask, removeMaskStyleKey, removePage, removePageStyleKey, removeStyleKey, removeText, removeTextStyleKey, renamePage, reorderTextByDelta, reorderTextRelative, reorderTextTo, resolveDocument, resolveDocumentStrict, revertConstReferences, setMaskPosition, setMaskStyle, setPagePath, setPageStyle, setStyleKey, setTextContent, setTextPosition, setTextStyle, stringify, substituteConstReferences, transform };
|
|
260
|
+
export { type CompileOptions, CompileStep, type CompileStepContext, type CompileStepObserver, type CompileStepObservers, type CompileToHtmlPureOptions, type Document, type MaskPositionFields, type Page, type PositionFields, type PsrtDocument, type PsrtMask, type PsrtPage, type PsrtStyle, type PsrtText, type PsrtVariant, type TextBlock, Transformer, type WebPreviewStyle, adaptEntriesForWeb, addConst, addFont, addMask, addPage, addText, compileToHtml, compileToHtmlPure, compileToSvg, findMaskByIndex, findPage, findPageIndex, findTextByIndex, formatDocument, formatPageDocumentJSON, initPsrt, mergePageDocumentPSRT, mergeStyle, movePage, notifyObservers, nudgeTextPosition, parse, parseTextIndex, removeConst, removeFont, removeMask, removeMaskStyleKey, removePage, removePageStyleKey, removeStyleKey, removeText, removeTextStyleKey, renamePage, reorderTextByDelta, reorderTextRelative, reorderTextTo, resolveDocument, resolveDocumentPure, resolveDocumentStrict, revertConstReferences, setMaskPosition, setMaskStyle, setPagePath, setPageStyle, setStyleKey, setTextContent, setTextPosition, setTextStyle, stringify, substituteConstReferences, transform };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
+
/** Initializes PSRT. Call once at app startup before any other SDK API. */
|
|
2
|
+
declare function initPsrt(): Promise<void>;
|
|
3
|
+
|
|
4
|
+
declare const CompileStep: {
|
|
5
|
+
readonly RESOLVE: "resolve";
|
|
6
|
+
readonly BUILD_ASSETS: "buildAssets";
|
|
7
|
+
readonly ADAPT_STYLE: "adaptStyle";
|
|
8
|
+
readonly RENDER_FONTS: "renderFonts";
|
|
9
|
+
readonly RENDER_HEAD: "renderHead";
|
|
10
|
+
readonly RENDER_PAGE: "renderPage";
|
|
11
|
+
readonly RENDER_TEXT: "renderText";
|
|
12
|
+
readonly RENDER_MASK: "renderMask";
|
|
13
|
+
readonly RENDER_INLINE: "renderInline";
|
|
14
|
+
readonly FINALIZE: "finalize";
|
|
15
|
+
};
|
|
16
|
+
type CompileStep = (typeof CompileStep)[keyof typeof CompileStep];
|
|
17
|
+
type CompileStepContext = {
|
|
18
|
+
step: typeof CompileStep.RESOLVE;
|
|
19
|
+
doc: PsrtDocument;
|
|
20
|
+
} | {
|
|
21
|
+
step: typeof CompileStep.BUILD_ASSETS;
|
|
22
|
+
assetCount: number;
|
|
23
|
+
canvasSizes: Record<string, {
|
|
24
|
+
w: number;
|
|
25
|
+
h: number;
|
|
26
|
+
}>;
|
|
27
|
+
} | {
|
|
28
|
+
step: typeof CompileStep.ADAPT_STYLE;
|
|
29
|
+
pageName: string;
|
|
30
|
+
blockIndex: number;
|
|
31
|
+
kind: 'text' | 'mask';
|
|
32
|
+
} | {
|
|
33
|
+
step: typeof CompileStep.RENDER_FONTS;
|
|
34
|
+
fontCount: number;
|
|
35
|
+
} | {
|
|
36
|
+
step: typeof CompileStep.RENDER_HEAD;
|
|
37
|
+
title: string;
|
|
38
|
+
} | {
|
|
39
|
+
step: typeof CompileStep.RENDER_PAGE;
|
|
40
|
+
pageIndex: number;
|
|
41
|
+
pageName: string;
|
|
42
|
+
canvasW: number;
|
|
43
|
+
canvasH: number;
|
|
44
|
+
} | {
|
|
45
|
+
step: typeof CompileStep.RENDER_TEXT;
|
|
46
|
+
pageName: string;
|
|
47
|
+
textIndex: number;
|
|
48
|
+
contentPreview: string;
|
|
49
|
+
} | {
|
|
50
|
+
step: typeof CompileStep.RENDER_MASK;
|
|
51
|
+
pageName: string;
|
|
52
|
+
maskIndex: number;
|
|
53
|
+
} | {
|
|
54
|
+
step: typeof CompileStep.RENDER_INLINE;
|
|
55
|
+
pageName: string;
|
|
56
|
+
textIndex: number;
|
|
57
|
+
htmlLength: number;
|
|
58
|
+
} | {
|
|
59
|
+
step: typeof CompileStep.FINALIZE;
|
|
60
|
+
htmlLength: number;
|
|
61
|
+
pageCount: number;
|
|
62
|
+
};
|
|
63
|
+
type CompileStepObserver = (ctx: CompileStepContext) => void;
|
|
64
|
+
type CompileStepObservers = Partial<Record<CompileStep, CompileStepObserver[]>>;
|
|
65
|
+
declare function notifyObservers(observers: CompileStepObservers | undefined, ctx: CompileStepContext): void;
|
|
66
|
+
|
|
1
67
|
/** JSON object or compact style string from PSRT. */
|
|
2
68
|
type PsrtStyle = Record<string, unknown> | string;
|
|
3
69
|
/** Canonical PSRT document representation. */
|
|
@@ -54,8 +120,17 @@ interface CompileOptions {
|
|
|
54
120
|
/** Omit the HTML variant switcher script (Ctrl+L). */
|
|
55
121
|
noScript?: boolean;
|
|
56
122
|
}
|
|
57
|
-
|
|
58
|
-
|
|
123
|
+
interface CompileToHtmlPureOptions extends CompileOptions {
|
|
124
|
+
observers?: CompileStepObservers;
|
|
125
|
+
/** Additional PSRT variants bundled into the same HTML (Ctrl+L to switch). */
|
|
126
|
+
variants?: PsrtVariant[];
|
|
127
|
+
}
|
|
128
|
+
/** One PSRT document bundled as an HTML variant alongside the primary doc. */
|
|
129
|
+
interface PsrtVariant {
|
|
130
|
+
/** Label shown in the variant switcher hint (defaults to variant-N). */
|
|
131
|
+
label?: string;
|
|
132
|
+
doc: PsrtDocument;
|
|
133
|
+
}
|
|
59
134
|
|
|
60
135
|
/** Converts a .psrt string into a typed PsrtDocument. */
|
|
61
136
|
declare function parse(psrtString: string): PsrtDocument;
|
|
@@ -64,8 +139,14 @@ declare function stringify(doc: PsrtDocument): string;
|
|
|
64
139
|
/** Formats a document with editor cleanup rules. */
|
|
65
140
|
declare function formatDocument(doc: PsrtDocument): string;
|
|
66
141
|
|
|
67
|
-
/**
|
|
142
|
+
/** Expands all @const@ placeholders in styles, content, and URLs. */
|
|
143
|
+
declare function resolveDocumentPure(doc: PsrtDocument): PsrtDocument;
|
|
144
|
+
|
|
145
|
+
/** Compiles the document to a self-contained HTML string (WASM). */
|
|
68
146
|
declare function compileToHtml(doc: PsrtDocument | string, options?: CompileOptions): string;
|
|
147
|
+
/** Compiles PsrtDocument to HTML using pure JavaScript (no WASM, no initPsrt). */
|
|
148
|
+
declare function compileToHtmlPure(doc: PsrtDocument, options?: CompileToHtmlPureOptions): string;
|
|
149
|
+
|
|
69
150
|
/** Compiles one page of the document to SVG. */
|
|
70
151
|
declare function compileToSvg(doc: PsrtDocument | string, pageName: string, options?: CompileOptions): string;
|
|
71
152
|
|
|
@@ -176,4 +257,4 @@ declare function resolveDocument(doc: PsrtDocument): PsrtDocument;
|
|
|
176
257
|
/** Like resolveDocument but throws on invalid style JSON after expansion. */
|
|
177
258
|
declare function resolveDocumentStrict(doc: PsrtDocument): PsrtDocument;
|
|
178
259
|
|
|
179
|
-
export { type CompileOptions, type Document, type MaskPositionFields, type Page, type PositionFields, type PsrtDocument, type PsrtMask, type PsrtPage, type PsrtStyle, type PsrtText, type TextBlock, Transformer, type WebPreviewStyle, adaptEntriesForWeb, addConst, addFont, addMask, addPage, addText, compileToHtml, compileToSvg, findMaskByIndex, findPage, findPageIndex, findTextByIndex, formatDocument, formatPageDocumentJSON, initPsrt, mergePageDocumentPSRT, mergeStyle, movePage, nudgeTextPosition, parse, parseTextIndex, removeConst, removeFont, removeMask, removeMaskStyleKey, removePage, removePageStyleKey, removeStyleKey, removeText, removeTextStyleKey, renamePage, reorderTextByDelta, reorderTextRelative, reorderTextTo, resolveDocument, resolveDocumentStrict, revertConstReferences, setMaskPosition, setMaskStyle, setPagePath, setPageStyle, setStyleKey, setTextContent, setTextPosition, setTextStyle, stringify, substituteConstReferences, transform };
|
|
260
|
+
export { type CompileOptions, CompileStep, type CompileStepContext, type CompileStepObserver, type CompileStepObservers, type CompileToHtmlPureOptions, type Document, type MaskPositionFields, type Page, type PositionFields, type PsrtDocument, type PsrtMask, type PsrtPage, type PsrtStyle, type PsrtText, type PsrtVariant, type TextBlock, Transformer, type WebPreviewStyle, adaptEntriesForWeb, addConst, addFont, addMask, addPage, addText, compileToHtml, compileToHtmlPure, compileToSvg, findMaskByIndex, findPage, findPageIndex, findTextByIndex, formatDocument, formatPageDocumentJSON, initPsrt, mergePageDocumentPSRT, mergeStyle, movePage, notifyObservers, nudgeTextPosition, parse, parseTextIndex, removeConst, removeFont, removeMask, removeMaskStyleKey, removePage, removePageStyleKey, removeStyleKey, removeText, removeTextStyleKey, renamePage, reorderTextByDelta, reorderTextRelative, reorderTextTo, resolveDocument, resolveDocumentPure, resolveDocumentStrict, revertConstReferences, setMaskPosition, setMaskStyle, setPagePath, setPageStyle, setStyleKey, setTextContent, setTextPosition, setTextStyle, stringify, substituteConstReferences, transform };
|