@paprize/core 0.0.4 → 0.0.5

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.
@@ -1,5 +1,8 @@
1
+ import type * as CSS_2 from 'csstype';
1
2
  import { default as default_2 } from 'loglevel';
2
3
 
4
+ export declare function adjustDimension(dimension: PageDimension, orientation: PageOrientation): PageDimension;
5
+
3
6
  declare const AttributeDef: {
4
7
  hyphen: AttributeValueDef<string>;
5
8
  keepOnSamePage: AttributeValueDef<boolean>;
@@ -22,8 +25,12 @@ declare class AttributeValueDef<T> {
22
25
  static createBool(name: string, defaultValue: boolean): AttributeValueDef<boolean>;
23
26
  }
24
27
 
28
+ export declare function buildPageId(sectionId: string, pageIndex: number): string;
29
+
25
30
  export declare function callPluginHook<T extends PluginHookNames>(plugins: PaginationPlugin[], hookName: T, ...args: Parameters<NonNullable<PaginationPlugin[T]>>): void;
26
31
 
32
+ export declare function cloneComponents(components: SectionComponents): SectionComponents;
33
+
27
34
  export declare type ConfigAttribute = {
28
35
  [K in AttributeKey]?: AttributeValue<K>;
29
36
  };
@@ -32,6 +39,8 @@ export declare function configToAttributeMap(config: ConfigAttribute): Record<st
32
39
 
33
40
  export declare function createLoremIpsumParagraph(wordCount: number, seed: number): string;
34
41
 
42
+ export declare type CSSProperties = CSS_2.Properties<string | number>;
43
+
35
44
  export declare const currentElementClassName = "pz-current-element";
36
45
 
37
46
  export declare const currentTextClassName = "pz-current-text";
@@ -51,11 +60,11 @@ export declare class DomState {
51
60
  get completed(): boolean;
52
61
  get currentNode(): PageNode | null;
53
62
  get previousNode(): PageNode | null;
54
- nextNode(): void;
55
- nextSiblingOrParentSibling(): {
63
+ goToNextNode(): void;
64
+ goToNextSiblingOrParentSibling(): {
56
65
  parentsTraversed: number;
57
66
  };
58
- firstChildOrNextNode(): {
67
+ goToFirstChildOrNextNode(): {
59
68
  parentsTraversed: number;
60
69
  };
61
70
  private setState;
@@ -63,8 +72,21 @@ export declare class DomState {
63
72
 
64
73
  export declare const enableDebugMode: () => void;
65
74
 
75
+ export declare class EventDispatcher<TEvents> {
76
+ private registry;
77
+ addEventListener<T extends keyof TEvents>(name: T, handler: EventHandler<T, TEvents>): () => void;
78
+ removeEventListener<T extends keyof TEvents>(name: T, handler: EventHandler<T, TEvents>): void;
79
+ dispatch<T extends keyof TEvents>(name: T, ...args: Parameters<EventHandler<T, TEvents>>): void;
80
+ }
81
+
82
+ declare type EventHandler<TKey extends keyof TEvents, TEvents> = TEvents[TKey] extends (...args: infer TArgs) => infer TReturn ? (...args: TArgs) => TReturn : never;
83
+
66
84
  export declare function getVisibleHeight(element: Element): number;
67
85
 
86
+ export declare const globalStyle = "\n html {\n box-sizing: border-box;\n }\n\n *,\n *:before,\n *:after {\n box-sizing: inherit;\n }\n\n :root {\n --paprize-page-background-color: #ffffff;\n --paprize-page-margin-bottom: 10px;\n --paprize-page-box-shadow: rgb(142 138 138) -1px 3px 5px 2px;\n --paprize-section-margin-bottom: 10px;\n --paprize-preview-background-color: rgb(218 220 224);\n --paprize-preview-padding: 30px 10px;\n }\n\n body {\n margin: 0;\n }\n \n @media screen {\n .pz-preview {\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n background-color: var(--paprize-preview-background-color);\n padding: var(--paprize-preview-padding);\n }\n\n .pz-page {\n box-shadow: var(--paprize-page-box-shadow);\n margin-bottom: var(--paprize-page-margin-bottom);\n background-color: var(--paprize-page-background-color);\n }\n\n .pz-section {\n margin-bottom: var(--paprize-section-margin-bottom);\n }\n }\n\n @media print {\n html:has(.pz-preview) *:not(.pz-preview):not(.pz-preview *):not(:has(.pz-preview)) {\n display: none !important;\n }\n } \n ";
87
+
88
+ export declare const globalStyleId = "paprize-global-style";
89
+
68
90
  export declare const ignoredElementClassName = "pz-ignored-element";
69
91
 
70
92
  export declare const ignoredTextClassName = "pz-ignored-text";
@@ -79,22 +101,43 @@ export declare const logger: default_2.Logger;
79
101
 
80
102
  export declare const loggerName = "paprize";
81
103
 
104
+ export declare type Monitor<TEvents> = Omit<EventDispatcher<TEvents>, 'dispatch'>;
105
+
82
106
  export declare function moveOffscreen(element: HTMLDivElement): void;
83
107
 
84
108
  export declare const pageBreakAttributeName = "data-pz-page-break";
85
109
 
86
- export declare const pageBreakPlugin: PaginationPlugin;
87
-
88
- export declare const pageBreakPluginName = "pageBreak";
110
+ export declare class PageBreakPlugin implements PaginationPlugin {
111
+ name: string;
112
+ order: number;
113
+ onVisitElement: (_id: string, domState: DomState & {
114
+ currentNode: PageElement;
115
+ }, pageManager: PageManager, context: VisitContext) => void;
116
+ }
89
117
 
90
118
  export declare const pageClassName = "pz-page";
91
119
 
120
+ export declare interface PageContext {
121
+ sectionId: string;
122
+ index: number;
123
+ totalPages: number;
124
+ pageContentHtml: string;
125
+ }
126
+
127
+ export declare interface PageDimension {
128
+ height: string;
129
+ width: string;
130
+ }
131
+
92
132
  declare class PageElement {
93
133
  private readonly _node;
94
- private readonly _transaction;
134
+ config: PaginationConfig;
95
135
  readonly type: 'element';
96
- readonly config: PaginationConfig;
97
- constructor(element: Element, transaction: Transaction, config: PaginationConfig);
136
+ readonly transaction: Transaction;
137
+ readonly clonedFrom?: PageElement;
138
+ readonly cloneCount: number;
139
+ constructor(element: Element, transaction: Transaction, config: PaginationConfig, clonedFrom?: PageElement);
140
+ getOriginalNode(): Node | undefined;
98
141
  appendChild(node: PageNode): void;
99
142
  clone(withChildren?: boolean): PageElement;
100
143
  getHeight(): number;
@@ -129,13 +172,104 @@ declare class PageManager {
129
172
  getPageState(): PageState;
130
173
  }
131
174
 
175
+ export declare interface PageMargin {
176
+ top: string;
177
+ right: string;
178
+ bottom: string;
179
+ left: string;
180
+ }
181
+
182
+ export declare const pageMargin: Record<keyof typeof _pageMargin, PageMargin>;
183
+
184
+ declare const _pageMargin: {
185
+ Normal: {
186
+ top: string;
187
+ right: string;
188
+ bottom: string;
189
+ left: string;
190
+ };
191
+ Narrow: {
192
+ top: string;
193
+ right: string;
194
+ bottom: string;
195
+ left: string;
196
+ };
197
+ Wide: {
198
+ top: string;
199
+ right: string;
200
+ bottom: string;
201
+ left: string;
202
+ };
203
+ None: {
204
+ top: string;
205
+ right: string;
206
+ bottom: string;
207
+ left: string;
208
+ };
209
+ };
210
+
132
211
  declare type PageNode = PageElement | PageText;
133
212
 
213
+ export declare type PageOrientation = 'portrait' | 'landscape';
214
+
134
215
  export declare interface PageSize {
135
216
  width: number;
136
217
  height: number;
137
218
  }
138
219
 
220
+ export declare const pageSize: Record<keyof typeof _pageSize, PageDimension>;
221
+
222
+ declare const _pageSize: {
223
+ A1: {
224
+ height: string;
225
+ width: string;
226
+ };
227
+ A2: {
228
+ height: string;
229
+ width: string;
230
+ };
231
+ A3: {
232
+ height: string;
233
+ width: string;
234
+ };
235
+ A4: {
236
+ height: string;
237
+ width: string;
238
+ };
239
+ A5: {
240
+ height: string;
241
+ width: string;
242
+ };
243
+ A6: {
244
+ height: string;
245
+ width: string;
246
+ };
247
+ B3: {
248
+ height: string;
249
+ width: string;
250
+ };
251
+ B4: {
252
+ height: string;
253
+ width: string;
254
+ };
255
+ B5: {
256
+ height: string;
257
+ width: string;
258
+ };
259
+ Letter: {
260
+ height: string;
261
+ width: string;
262
+ };
263
+ Legal: {
264
+ height: string;
265
+ width: string;
266
+ };
267
+ Tabloid: {
268
+ height: string;
269
+ width: string;
270
+ };
271
+ };
272
+
139
273
  declare class PageState {
140
274
  currentPage: PageElement;
141
275
  activeElement: PageNode | null;
@@ -151,9 +285,9 @@ declare class PageState {
151
285
 
152
286
  declare class PageText {
153
287
  private readonly _node;
154
- private readonly _transaction;
155
288
  readonly type: 'text';
156
- readonly config: PaginationConfig;
289
+ readonly transaction: Transaction;
290
+ config: PaginationConfig;
157
291
  constructor(text: Text, transaction: Transaction, config: PaginationConfig);
158
292
  get textContent(): string;
159
293
  set textContent(value: string);
@@ -168,6 +302,10 @@ export declare type PaginationConfig = Required<ConfigAttribute> & {
168
302
  plugins: PaginationPlugin[];
169
303
  };
170
304
 
305
+ export declare interface PaginationCycleCompleted {
306
+ sections: SectionContext[];
307
+ }
308
+
171
309
  export declare interface PaginationPlugin {
172
310
  readonly name: string;
173
311
  readonly order: number;
@@ -177,7 +315,7 @@ export declare interface PaginationPlugin {
177
315
  onVisitElement?: (id: string, domState: DomState & {
178
316
  currentNode: PageElement;
179
317
  }, pageManager: PageManager, context: VisitContext) => void;
180
- afterVisitNode?: (id: string, domState: DomState, pageManager: PageManager) => void;
318
+ afterVisitNode?: (id: string, result: SplitResult, domState: DomState, pageManager: PageManager) => void;
181
319
  onNewPage?: (id: string, pageManager: PageManager) => void;
182
320
  onClone?: (id: string, source: Element, cloned: PageElement) => void;
183
321
  }
@@ -198,6 +336,8 @@ export declare class Paginator {
198
336
  private processCurrentNode;
199
337
  }
200
338
 
339
+ export declare const paprize_isInitialized = "__PAPRIZE_IS_INITIALIZED";
340
+
201
341
  export declare const paprize_isReady = "__PAPRIZE_IS_READY";
202
342
 
203
343
  export declare const paprize_readJsonDataFile = "__PAPRIZE_READ_JSON_DATA_FILE";
@@ -205,19 +345,96 @@ export declare const paprize_readJsonDataFile = "__PAPRIZE_READ_JSON_DATA_FILE";
205
345
  declare type PluginHookNames = NonNullable<PluginKeys>;
206
346
 
207
347
  declare type PluginKeys = {
208
- [K in keyof PaginationPlugin]: PaginationPlugin[K] extends ((...args: any[]) => any) | undefined ? K : never;
348
+ [K in keyof PaginationPlugin]: PaginationPlugin[K] extends ((...args: never[]) => unknown) | undefined ? K : never;
209
349
  }[keyof PaginationPlugin];
210
350
 
351
+ export declare const previewClassName = "pz-preview";
352
+
353
+ export declare class ReportBuilder {
354
+ private readonly _sections;
355
+ private readonly _monitor;
356
+ private _paginationInProgress;
357
+ private _pendingPaginateResolvers;
358
+ private _currentAbortController;
359
+ constructor();
360
+ get monitor(): Monitor<ReportBuilderEvents>;
361
+ removeSection(sectionId: string): void;
362
+ tryAddSection(options: SectionOptions, components: SectionComponents, onPaginationCompleted: (pages: PageContext[]) => void): boolean;
363
+ schedulePaginate(): Promise<ScheduleResult>;
364
+ private _executePagination;
365
+ private _processPendingPagination;
366
+ private _injectStyle;
367
+ private _paginateSection;
368
+ }
369
+
370
+ export declare interface ReportBuilderEvents {
371
+ pageCompleted: (event: PageContext) => void;
372
+ sectionCompleted: (event: SectionContext) => void;
373
+ sectionCreated: (event: SectionContext) => void;
374
+ paginationCycleCompleted: (event: PaginationCycleCompleted) => void;
375
+ }
376
+
377
+ export declare const reportStyles: {
378
+ globalStyle: string;
379
+ component: CSSProperties;
380
+ outOfScreen: CSSProperties;
381
+ page: (pageDimension: PageDimension, pageMargin: PageMargin) => CSSProperties;
382
+ overlay: CSSProperties;
383
+ pageContent: CSSProperties;
384
+ sectionPageMedia: typeof sectionPageMedia;
385
+ section: (sectionId: string) => CSSProperties;
386
+ };
387
+
211
388
  declare type SafeElement = Omit<Element, 'removeChild' | 'appendChild' | 'replaceChild' | 'remove'>;
212
389
 
213
390
  declare type SafeText = Omit<Text, 'remove'>;
214
391
 
392
+ export declare interface ScheduleResult {
393
+ sections: SectionContext[];
394
+ suspension: Promise<void>;
395
+ }
396
+
397
+ export declare const sectionClassName = "pz-section";
398
+
399
+ export declare interface SectionComponents {
400
+ sectionHeader: HTMLElement | null;
401
+ sectionFooter: HTMLElement | null;
402
+ pageHeader: HTMLElement | null;
403
+ pageFooter: HTMLElement | null;
404
+ pageContent: HTMLElement;
405
+ }
406
+
407
+ export declare interface SectionContext {
408
+ index: number;
409
+ sectionId: string;
410
+ isSuspended: boolean;
411
+ isPaginated: boolean;
412
+ pages: PageContext[];
413
+ }
414
+
415
+ export declare interface SectionOptions extends Partial<PaginationConfig> {
416
+ readonly id: string;
417
+ readonly dimension: PageDimension;
418
+ readonly margin?: PageMargin;
419
+ readonly suspense?: Promise<unknown>[];
420
+ }
421
+
422
+ declare function sectionPageMedia(sectionId: string, dimension: PageDimension): string;
423
+
424
+ export declare interface SectionState {
425
+ options: SectionOptions;
426
+ context: SectionContext;
427
+ components: SectionComponents;
428
+ onPaginationCompleted: (pages: PageContext[]) => void;
429
+ }
430
+
215
431
  export declare const sectionTocName = "sectionToc";
216
432
 
217
433
  export declare class SectionTocPlugin implements PaginationPlugin {
218
- readonly state: SectionTocState[];
219
434
  readonly name = "sectionToc";
220
435
  readonly order = 1;
436
+ private _state;
437
+ getContentList: () => SectionTocState[];
221
438
  onVisitElement: (id: string, domState: DomState & {
222
439
  currentNode: PageElement;
223
440
  }, pageManager: PageManager) => void;
@@ -226,7 +443,7 @@ export declare class SectionTocPlugin implements PaginationPlugin {
226
443
 
227
444
  export declare type SectionTocState = {
228
445
  sectionId: string;
229
- pageNumber: number;
446
+ pageIndex: number;
230
447
  title: string;
231
448
  level: number;
232
449
  };
@@ -239,6 +456,32 @@ export declare const SplitResult: {
239
456
 
240
457
  export declare type SplitResult = (typeof SplitResult)[keyof typeof SplitResult];
241
458
 
459
+ export declare class TablePlugin implements PaginationPlugin {
460
+ private readonly _options;
461
+ name: string;
462
+ order: number;
463
+ constructor(options?: TablePluginOptions);
464
+ onNewPage: (_id: string, pageManager: PageManager) => void;
465
+ onClone: (_id: string, source: Element, cloned: PageElement) => void;
466
+ private _isTable;
467
+ private _isTableBodyEmpty;
468
+ }
469
+
470
+ export declare interface TablePluginOptions {
471
+ /**
472
+ * If true, the table header (thead) will be cloned on each page.
473
+ */
474
+ cloneHeader?: boolean;
475
+ /**
476
+ * If true, the table footer (tfoot) will be cloned on each page.
477
+ */
478
+ cloneFooter?: boolean;
479
+ /**
480
+ * When true, tables containing only a header (no body rows) will not be removed.
481
+ */
482
+ includeHeaderOnlyTables?: boolean;
483
+ }
484
+
242
485
  export declare const tempContainerClassName = "pz-temp-container";
243
486
 
244
487
  declare class Transaction {
@@ -262,6 +505,7 @@ export { }
262
505
 
263
506
  declare global {
264
507
  interface Window {
508
+ [paprize_isInitialized]?: boolean;
265
509
  [paprize_isReady]?: boolean;
266
510
  [paprize_readJsonDataFile]?: () => Promise<string>;
267
511
  }