@bitcaster/printkit 0.0.0-stage → 0.1.0

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.
Files changed (56) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +8 -2
  3. package/README.npm.md +9 -0
  4. package/THIRD_PARTY_NOTICES.md +1973 -0
  5. package/dist/assets/fonts/C400.ttf +0 -0
  6. package/dist/assets/fonts/M400.ttf +0 -0
  7. package/dist/assets/fonts/M600.ttf +0 -0
  8. package/dist/assets/fonts/M700.ttf +0 -0
  9. package/dist/assets/fonts/OFL-IBMPlexMono.txt +93 -0
  10. package/dist/assets/fonts/OFL-LibreCaslonText.txt +93 -0
  11. package/dist/assets/fonts/OFL-Manrope.txt +93 -0
  12. package/dist/assets/fonts/P400.ttf +0 -0
  13. package/dist/assets/fonts/P500.ttf +0 -0
  14. package/dist/assets/pdf.worker.min.mjs +29 -0
  15. package/dist/components/index.d.ts +42 -0
  16. package/dist/components/index.js +1 -0
  17. package/dist/components/p-6By_vSL9.js +1 -0
  18. package/dist/components/p-B85ddf5i.js +58 -0
  19. package/dist/components/p-BEuF_WyR.js +15 -0
  20. package/dist/components/p-C06-VTon.js +1 -0
  21. package/dist/components/p-C5up7ejY.js +22 -0
  22. package/dist/components/p-ChB3W-Ln.js +3 -0
  23. package/dist/components/p-DpEO5JlK.js +2 -0
  24. package/dist/components/p-DzTdZECU.js +21 -0
  25. package/dist/components/pk-editor.d.ts +11 -0
  26. package/dist/components/pk-editor.js +277 -0
  27. package/dist/components/pk-help.d.ts +11 -0
  28. package/dist/components/pk-help.js +1 -0
  29. package/dist/components/pk-template-editor.d.ts +11 -0
  30. package/dist/components/pk-template-editor.js +1 -0
  31. package/dist/types/.stencil/components/pk-editor/pk-editor.d.ts +113 -0
  32. package/dist/types/.stencil/components/pk-help/help.content.d.ts +1 -0
  33. package/dist/types/.stencil/components/pk-help/pk-help.d.ts +9 -0
  34. package/dist/types/.stencil/components/pk-template-editor/pk-template-editor.d.ts +203 -0
  35. package/dist/types/.stencil/services/background-load.d.ts +20 -0
  36. package/dist/types/.stencil/services/background.d.ts +70 -0
  37. package/dist/types/.stencil/services/card-engine.d.ts +123 -0
  38. package/dist/types/.stencil/services/card-render.d.ts +5 -0
  39. package/dist/types/.stencil/services/card.config.d.ts +48 -0
  40. package/dist/types/.stencil/services/cmyk-lut.d.ts +4 -0
  41. package/dist/types/.stencil/services/collide.d.ts +19 -0
  42. package/dist/types/.stencil/services/color.d.ts +12 -0
  43. package/dist/types/.stencil/services/design.d.ts +106 -0
  44. package/dist/types/.stencil/services/fonts.d.ts +32 -0
  45. package/dist/types/.stencil/services/layouts.d.ts +15 -0
  46. package/dist/types/.stencil/services/logo.d.ts +19 -0
  47. package/dist/types/.stencil/services/palette.d.ts +31 -0
  48. package/dist/types/.stencil/services/pdf.d.ts +26 -0
  49. package/dist/types/.stencil/services/qr.d.ts +21 -0
  50. package/dist/types/.stencil/services/spot.d.ts +49 -0
  51. package/dist/types/.stencil/services/terms.d.ts +1 -0
  52. package/dist/types/.stencil/types/card.types.d.ts +403 -0
  53. package/dist/types/.stencil/types/editor.types.d.ts +48 -0
  54. package/dist/types/components.d.ts +320 -0
  55. package/dist/types/stencil-public-runtime.d.ts +1879 -0
  56. package/package.json +46 -4
@@ -0,0 +1,106 @@
1
+ import { ArtItem, CardData, Issue, CardDesign, ColorRef, ColorRole, FieldConfig, FieldOverride, LineSrc, Side, StackDef, StyleKey, Template } from '../types/card.types';
2
+ import type { CardEngine } from './card-engine';
3
+ import { AlignHow, Box, Handle } from '../types/editor.types';
4
+ export declare const COLOR_ROLES: ColorRole[];
5
+ /** Lazy because card.config imports this module (circular import) */
6
+ export declare const styleKeys: () => StyleKey[];
7
+ /** Validate a design from untrusted JSON; invalid items are dropped, a missing design returns undefined */
8
+ export declare function cleanDesign(o: unknown): CardDesign | undefined;
9
+ /** Data that fills every field, so all blocks are visible while designing; template defaults win */
10
+ export declare function sampleData(fields: FieldConfig[]): CardData;
11
+ /** Long values for every field, to test a template before customers find the limits; fixed defaults of locked fields win */
12
+ export declare function stressData(fields: FieldConfig[]): CardData;
13
+ /** What a customer starts with: only defaults (and locked values), everything else empty */
14
+ export declare function customerData(fields: FieldConfig[]): CardData;
15
+ /** Problems with the uploaded logo that only the template designer can fix: text set in a font, low resolution */
16
+ export declare function logoIssues(eng: CardEngine): Issue[];
17
+ /** QR codes covered by art drawn after them, or set in an accent too light to scan */
18
+ export declare function qrIssues(eng: CardEngine): Issue[];
19
+ /** Keys of the fields one side prints: text lines (explicit or through a group) and image boxes */
20
+ export declare function placedKeys(eng: CardEngine, side: Side, d: CardData): Set<string>;
21
+ /** Visible fields that no block on either side prints */
22
+ export declare function unplacedFields(eng: CardEngine, d: CardData): FieldConfig[];
23
+ /**
24
+ * Fields as the customer gets them. In a template with its own color list (made in the current template editor, which
25
+ * starts from an empty page) a field no side uses is hidden: it is not in the form and cannot block the PDF. A field
26
+ * counts as used when a text line prints it (directly or through its group), an image box shows it or a QR code
27
+ * encodes it. Older templates are returned unchanged, so their forms stay as they are.
28
+ */
29
+ export declare function customerFields(t: Template, fields: FieldConfig[]): FieldConfig[];
30
+ /** Unused key for the field a new text or image element creates: text1, text2, … */
31
+ export declare function newFieldKey(fields: FieldConfig[], prefix: string): {
32
+ key: string;
33
+ n: number;
34
+ };
35
+ export declare const snap: (v: number, step?: number) => number;
36
+ /** Bounding box of an art item in mm */
37
+ export declare function artBox(it: ArtItem): {
38
+ x: number;
39
+ y: number;
40
+ w: number;
41
+ h: number;
42
+ };
43
+ /** Rects covering the whole card are backgrounds; they are not dragged so the bleed stays intact */
44
+ export declare const isBackground: (it: ArtItem, W: number, H: number) => boolean;
45
+ /** Move an art item; rect edges close to the trim edge snap onto it so color areas run into the bleed */
46
+ export declare function moveArt(it: ArtItem, dx: number, dy: number, W: number, H: number): ArtItem;
47
+ export declare function moveStack(s: StackDef, dx: number, dy: number): StackDef;
48
+ /** Offsets that align boxes to the common edge or center of their bounding box */
49
+ export declare function alignDeltas(boxes: Box[], how: AlignHow): {
50
+ dx: number;
51
+ dy: number;
52
+ }[];
53
+ /** Guide line in mm, shown while an element snaps */
54
+ export interface Guide {
55
+ x1: number;
56
+ y1: number;
57
+ x2: number;
58
+ y2: number;
59
+ }
60
+ /**
61
+ * Snap a moving box to edges and centers of other boxes, of the page and of the safety margin, per axis within `tol` mm.
62
+ * Returns the correction to add to the move and the guide lines to show.
63
+ */
64
+ export declare function smartSnap(b: Box, others: Box[], W: number, H: number, tol: number): {
65
+ dx: number;
66
+ dy: number;
67
+ guides: Guide[];
68
+ };
69
+ export type NewKind = 'stack' | ArtItem['t'];
70
+ /** Default element placed in the middle of the card */
71
+ /** `shape` colors areas, lines and circles; `text` and `key` set the color and the field of a new text block's line */
72
+ export declare function newItem(kind: NewKind, W: number, H: number, o?: {
73
+ shape?: ColorRef;
74
+ text?: ColorRef;
75
+ key?: string;
76
+ }): StackDef | ArtItem;
77
+ /** A text line as the editor adds it: regular face, 7 pt, in the given color (face, size and color sit on the line itself) */
78
+ export declare function newLine(key: string, color?: ColorRef): LineSrc;
79
+ /** Field properties the template editor writes into template.fields */
80
+ export type FieldProp = 'label' | 'placeholder' | 'group' | 'order' | 'required' | 'locked' | 'hidden' | 'default' | 'kind' | 'labelText' | 'labelShort' | 'mobile' | 'inputType' | 'choices' | 'vcard';
81
+ /**
82
+ * Set one property in the override list. Built-in fields only keep properties that differ from the built-in
83
+ * definition; custom fields (no built-in) keep their full config.
84
+ */
85
+ export declare function setFieldProp(list: FieldOverride[], builtin: FieldConfig | undefined, key: string, prop: FieldProp, value: FieldConfig[FieldProp] | undefined): FieldOverride[];
86
+ /** Set a field's choice list; a default that is no longer in the list is cleared too, so the panel and the preview agree */
87
+ export declare function setChoices(list: FieldOverride[], builtin: FieldConfig | undefined, f: FieldConfig, choices: string[]): FieldOverride[];
88
+ /**
89
+ * Move field `from` next to field `to`: it joins `to`'s group and that group is renumbered 10, 20, … in the new order.
90
+ * Moving down lands after `to`, moving up (or in from another group) lands before it.
91
+ */
92
+ export declare function moveField(list: FieldOverride[], builtins: FieldConfig[], fields: FieldConfig[], from: string, to: string): FieldOverride[];
93
+ /** Move legacy template.locked/defaults into field overrides so the editor has one place to change them */
94
+ export declare function foldLegacy(t: Template, builtins: FieldConfig[]): Template;
95
+ /** Handles an element offers when it is selected */
96
+ export declare function handlesOf(it: StackDef | ArtItem): Handle[];
97
+ /** Position of a handle in mm */
98
+ export declare function handlePos(it: StackDef | ArtItem, h: Handle): {
99
+ x: number;
100
+ y: number;
101
+ };
102
+ /**
103
+ * Resize by dragging a handle dx/dy mm from where the drag started. `keepRatio` keeps the aspect ratio on corners and
104
+ * makes lines horizontal or vertical. Box edges near the trim edge snap onto it, like when moving.
105
+ */
106
+ export declare function resizeItem(it: StackDef | ArtItem, h: Handle, dx: number, dy: number, W: number, H: number, keepRatio?: boolean): StackDef | ArtItem;
@@ -0,0 +1,32 @@
1
+ import opentype from 'opentype.js';
2
+ import { BaseFontId, CustomFont, CustomFontId, FontId } from '../types/card.types';
3
+ export declare const FONT_IDS: BaseFontId[];
4
+ /** Name of each built-in face, for the face picker of a text line */
5
+ export declare const FONT_LABEL: Record<BaseFontId, string>;
6
+ export declare const CUSTOM_LABEL: Record<CustomFontId, string>;
7
+ export interface LoadedFont {
8
+ ot: opentype.Font;
9
+ /** Raw TTF as base64, needed when the PDF embeds fonts instead of outlining text */
10
+ b64: string;
11
+ /** Baseline offset as a fraction of the font size (line-height: 1) */
12
+ base: number;
13
+ /** CSS family of an uploaded house font face; built-in faces use family(id) */
14
+ family?: string;
15
+ }
16
+ /** Fonts an engine works with: all built-in faces, plus the faces of the house font that are loaded */
17
+ export type FontSet = Record<BaseFontId, LoadedFont> & Partial<Record<CustomFontId, LoadedFont>>;
18
+ /** CSS family name used on the card; prefixed to avoid collisions with the host page */
19
+ export declare const family: (id: FontId) => string;
20
+ export declare const UI_FAMILY = "pk-ui";
21
+ export declare function toB64(buf: ArrayBuffer): string;
22
+ /** Load all card fonts once per page; base URL must end with a slash */
23
+ export declare function loadFonts(base: string): Promise<Record<BaseFontId, LoadedFont>>;
24
+ /** Load the faces of a template's house font; faces that fail to load are left out */
25
+ export declare function loadCustomFont(font: CustomFont | undefined): Promise<Partial<Record<CustomFontId, LoadedFont>>>;
26
+ /** Changes when the house font of a template changes, without comparing megabytes of base64 */
27
+ export declare const fontKey: (font: CustomFont | undefined) => string;
28
+ /** Family name and face (by weight class) of a font file; throws when the file is not a readable font */
29
+ export declare function describeFont(buf: ArrayBuffer): {
30
+ name: string;
31
+ id: CustomFontId;
32
+ };
@@ -0,0 +1,15 @@
1
+ import { LayoutDef, LayoutKey } from '../types/card.types';
2
+ declare const fitBox: (ar: number, b: {
3
+ x: number;
4
+ y: number;
5
+ w: number;
6
+ h: number;
7
+ align: "left" | "right" | "center";
8
+ }) => {
9
+ x: number;
10
+ y: number;
11
+ w: number;
12
+ h: number;
13
+ };
14
+ export { fitBox };
15
+ export declare const LAYOUTS: Record<LayoutKey, LayoutDef>;
@@ -0,0 +1,19 @@
1
+ import { ImageValue, Logo } from '../types/card.types';
2
+ /** Raster images from templates, props or uploads: PNG/JPEG data URL with a pixel size */
3
+ export declare function cleanImage(v: unknown): ImageValue | null;
4
+ /** Largest image upload; the data travels inside the template or the order data */
5
+ export declare const MAX_IMAGE_MB = 20;
6
+ /** Read an uploaded PNG/JPEG into an ImageValue */
7
+ export declare function readImage(file: File): Promise<ImageValue>;
8
+ /** Short object URL for a data URL, so re-rendering the card does not copy megabytes of base64 into the DOM */
9
+ export declare function imageHref(src: string): string;
10
+ /** Strip scripts/handlers/external refs and make sure a viewBox exists */
11
+ export declare function sanitizeSvg(text: string): {
12
+ data: string;
13
+ ar: number;
14
+ hasText: boolean;
15
+ };
16
+ /** Logos from props are untrusted: re-sanitize SVG and recompute the aspect ratio */
17
+ export declare function cleanLogo(l: Logo | null): Logo | null;
18
+ /** Raster logos and PDF previews become object URLs: short, and nothing from the template is written into markup */
19
+ export declare const logoHref: (l: Logo) => string;
@@ -0,0 +1,31 @@
1
+ import { CardDesign, Cmyk, ColorRef, CustomFont, CustomFontId, PaletteColor, PaletteRef, Template, Theme } from '../types/card.types';
2
+ export declare const MAX_COLORS = 24;
3
+ export declare const isPaletteRef: (c: unknown) => c is PaletteRef;
4
+ export declare const refOf: (id: string) => PaletteRef;
5
+ export declare const isCmyk: (v: unknown) => v is Cmyk;
6
+ export declare const reservedSpotName: (name: string) => boolean;
7
+ /** The color prints on its own plate: switched on, named, and the name is not a reserved one */
8
+ export declare const printsAsSpot: (c: PaletteColor) => boolean;
9
+ /** Validate a color list from untrusted JSON. Not a list: undefined (template on the old scheme). Bad entries are dropped. */
10
+ export declare function cleanColors(v: unknown): PaletteColor[] | undefined;
11
+ /** Validate an uploaded house font from untrusted JSON; without a usable file there is no font */
12
+ export declare function cleanFont(v: unknown): CustomFont | undefined;
13
+ /** Face a font file is used for, from its weight class (OS/2 usWeightClass) */
14
+ export declare const fontSlot: (weight: number) => CustomFontId;
15
+ /** Colors of the old scheme, used while a template has no color list */
16
+ export declare function legacyTheme(t: Template): Theme;
17
+ /** Colors a new, empty template starts with */
18
+ export declare const startColors: () => PaletteColor[];
19
+ /** Unused id for a new color */
20
+ export declare function newColorId(colors: PaletteColor[]): string;
21
+ /** Apply `fn` to every color reference of a design: areas, lines, circles, QR codes, text lines and their prefixes */
22
+ export declare function mapDesignColors(design: CardDesign, fn: (c: ColorRef) => ColorRef): CardDesign;
23
+ /** Remove a color from the list; elements that used it keep its CMYK value, so nothing changes color unnoticed */
24
+ export declare function removeColor(t: Template, id: string): Template;
25
+ /**
26
+ * Move a template with a design from the old color scheme onto its own color list. Every scheme color the design uses
27
+ * becomes a list entry (the accent keeps its name, spot color and overprint setting), and every text line gets the
28
+ * face, size and color its style gave it, so the result prints exactly as before. Templates that already have a color
29
+ * list, or no design yet, are returned unchanged.
30
+ */
31
+ export declare function toPalette(t: Template): Template;
@@ -0,0 +1,26 @@
1
+ import 'svg2pdf.js';
2
+ import { CardData } from '../types/card.types';
3
+ import { CardEngine } from './card-engine';
4
+ /** Page boxes in PDF points from the bottom-left corner, as jsPDF and pdf-lib expect them */
5
+ export declare function pageBoxes(eng: CardEngine): {
6
+ trim: Box;
7
+ bleed: Box;
8
+ };
9
+ interface Box {
10
+ x: number;
11
+ y: number;
12
+ w: number;
13
+ h: number;
14
+ }
15
+ export declare function pageGeometry(eng: CardEngine): {
16
+ W: number;
17
+ H: number;
18
+ b: import("../types/card.types").Bleed;
19
+ pad: number;
20
+ pw: number;
21
+ ph: number;
22
+ };
23
+ /** CMYK PDF with one page per printed side, optional bleed and crop marks */
24
+ export declare function buildPDF(eng: CardEngine, d: CardData): Promise<Blob>;
25
+ export declare function specText(eng: CardEngine): string[];
26
+ export {};
@@ -0,0 +1,21 @@
1
+ import { CardData, FieldConfig, PhoneValue } from '../types/card.types';
2
+ export declare function phoneIntl(o: PhoneValue | undefined): string;
3
+ /** vCard 3.0 from the built-in fields plus custom fields that have a vCard role */
4
+ export declare function vcard(d: CardData, fields?: FieldConfig[]): string;
5
+ /** Text a QR item encodes: the vCard, or a field's text (bare domains get https://) */
6
+ export declare function qrText(it: {
7
+ src?: string;
8
+ }, d: CardData, fields?: FieldConfig[]): string;
9
+ export interface QrRect {
10
+ x: number;
11
+ y: number;
12
+ w: number;
13
+ h: number;
14
+ }
15
+ /** Dark modules merged into horizontal runs; the quiet zone stays inside the item's light square */
16
+ export declare function qrRuns(it: {
17
+ x: number;
18
+ y: number;
19
+ size: number;
20
+ src?: string;
21
+ }, d: CardData, fields?: FieldConfig[]): QrRect[];
@@ -0,0 +1,49 @@
1
+ import { Cmyk, ColorRef, Template } from '../types/card.types';
2
+ import { reservedSpotName } from './palette';
3
+ export { reservedSpotName };
4
+ type LibPage = import('pdf-lib').PDFPage;
5
+ /**
6
+ * Resource name of the spot color in the page content: `/CSpot cs 1 scn` (fill) and `/CSpot CS 1 SCN` (stroke).
7
+ * Further spot colors of a template are CSpot1, CSpot2, …
8
+ */
9
+ export declare const SPOT_RES = "CSpot";
10
+ /** Registration color for crop marks: `/CAll CS 1 SCN` puts them on every plate, spot plates included */
11
+ export declare const ALL_RES = "CAll";
12
+ /** Graphics state that makes the spot color overprint instead of knocking out what lies underneath */
13
+ export declare const OP_RES = "GSOverprint";
14
+ export interface Spot {
15
+ name: string;
16
+ cmyk: Cmyk;
17
+ overprint: boolean;
18
+ }
19
+ /** One spot color plate of the print file and the resource name its drawing uses */
20
+ export interface Plate {
21
+ name: string;
22
+ cmyk: Cmyk;
23
+ res: string;
24
+ }
25
+ /** Old color scheme: the accent as a spot color, when the template asks for it (own scheme, a usable color name and the switch) */
26
+ export declare function spotOf(t: Template): Spot | null;
27
+ /**
28
+ * Spot color plates of a template: one per spot color name of its color list (colors sharing a name share a plate,
29
+ * the first one's CMYK is the alternate), or the accent of the old scheme.
30
+ */
31
+ export declare function platesOf(t: Template): Plate[];
32
+ /** The plate a color reference is drawn on and whether it overprints, or null when it prints as CMYK */
33
+ export declare function plateFor(t: Template, ref: ColorRef): (Plate & {
34
+ overprint: boolean;
35
+ }) | null;
36
+ /** Some spot color of the template overprints, so the print file needs the overprint graphics state */
37
+ export declare const overprintsOf: (t: Template) => boolean;
38
+ /** The print file can hold more plates than CMYK: spot colors, or a background or logo PDF that may carry its own */
39
+ export declare const separatedOf: (t: Template) => boolean;
40
+ /**
41
+ * Add the color spaces the page content references: the registration color `All` for crop marks, and with a spot
42
+ * color its Separation (named like the color, the CMYK value as the alternate for proofs and screens) plus the
43
+ * overprint graphics state.
44
+ */
45
+ export declare function addSpot(pdf: ArrayBuffer | Uint8Array, spot: Spot | null): Promise<Uint8Array>;
46
+ /** As addSpot, for any number of spot color plates; `overprint` adds the graphics state when some color uses it */
47
+ export declare function addPlates(pdf: ArrayBuffer | Uint8Array, plates: Plate[], overprint: boolean): Promise<Uint8Array>;
48
+ /** Spot color names a PDF page uses: Separation and DeviceN color spaces in its resources and in nested forms */
49
+ export declare function spotNamesOf(page: LibPage): Promise<string[]>;
@@ -0,0 +1 @@
1
+ export declare const TERMS: Record<string, string>;