hprint-designer 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.
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # hprint-designer
2
+
3
+ A Vue 2 print-template designer wrapping [vue-plugin-hiprint](https://github.com/CcSimple/vue-plugin-hiprint) — for designing paper scenic-ticket & invitation print templates, with custom fonts, field-schema third-party binding, and Electron silent-print client detection.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install hprint-designer
9
+ # or taobao mirror:
10
+ cnpm install hprint-designer
11
+ ```
12
+
13
+ Peer dependencies: `vue@^2.6.0`, `ant-design-vue@^1.7.2`.
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import Vue from 'vue'
19
+ import HPrintDesigner from 'hprint-designer'
20
+ import 'hprint-designer/dist/style.css'
21
+
22
+ Vue.use(HPrintDesigner, { baseURL: 'https://your-server/api' })
23
+ ```
24
+
25
+ ```html
26
+ <print-designer
27
+ :template-id="id"
28
+ host="http://localhost:17521"
29
+ @save="onSave"
30
+ @print="onPrint" />
31
+ ```
32
+
33
+ ## Backend contract
34
+
35
+ Implement a REST backend matching `BackendAdapter`. See `src/contract/adapter.ts`:
36
+
37
+ - `GET/POST/PUT/DELETE /templates` (PUT uses `If-Match` header for optimistic lock)
38
+ - `GET/POST/DELETE /fonts`, `PUT /fonts/:id`
39
+ - `GET /client-release` — returns `{ officialUrl, selfHostedUrl?, minCompatibleVersion, ... }` for the Electron client download guide.
40
+
41
+ ## License
42
+
43
+ MIT. This library depends on `vue-plugin-hiprint` (hiprint 2.5.4, LGPL). The library
44
+ references hiprint as a class library without modifying its source, per the LGPL
45
+ class-library exemption. See hiprint's LICENSE for its terms.
@@ -0,0 +1,7 @@
1
+ export interface HttpOptions {
2
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
3
+ body?: any;
4
+ headers?: Record<string, string>;
5
+ signal?: AbortSignal;
6
+ }
7
+ export declare function http(baseURL: string, path: string, opts?: HttpOptions): Promise<any>;
@@ -0,0 +1,33 @@
1
+ import { BackendAdapter } from '../contract/adapter';
2
+ import { PrintTemplate, NewPrintTemplate, PrintFont, ClientRelease } from '../contract/types';
3
+
4
+ export declare class MockAdapter implements BackendAdapter {
5
+ private templates;
6
+ private fonts;
7
+ listTemplates(filter?: {
8
+ keyword?: string;
9
+ [k: string]: any;
10
+ }): Promise<{
11
+ items: PrintTemplate[];
12
+ total: number;
13
+ }>;
14
+ getTemplate(id: string): Promise<PrintTemplate>;
15
+ createTemplate(input: NewPrintTemplate): Promise<PrintTemplate>;
16
+ updateTemplate(id: string, patch: Partial<PrintTemplate>, ifVersion?: number): Promise<PrintTemplate>;
17
+ deleteTemplate(id: string): Promise<void>;
18
+ listFonts(): Promise<PrintFont[]>;
19
+ uploadFont(file: File | File[], meta: {
20
+ name: string;
21
+ family: string;
22
+ }): Promise<PrintFont>;
23
+ updateFont(id: string, patch: Partial<Pick<PrintFont, 'name' | 'family'>>): Promise<{
24
+ name: string;
25
+ family: string;
26
+ id: string;
27
+ files: import('../contract/types').FontFile[];
28
+ uploader?: string | undefined;
29
+ createdAt: string;
30
+ }>;
31
+ deleteFont(id: string): Promise<void>;
32
+ getClientRelease(): Promise<ClientRelease>;
33
+ }
@@ -0,0 +1,29 @@
1
+ import { BackendAdapter } from '../contract/adapter';
2
+ import { PrintTemplate, NewPrintTemplate, PrintFont, ClientRelease } from '../contract/types';
3
+
4
+ export interface RestAdapterOptions {
5
+ baseURL: string;
6
+ }
7
+ export declare class RestAdapter implements BackendAdapter {
8
+ private opts;
9
+ constructor(opts: RestAdapterOptions);
10
+ listTemplates(filter?: {
11
+ keyword?: string;
12
+ [k: string]: any;
13
+ }): Promise<{
14
+ items: PrintTemplate[];
15
+ total: number;
16
+ }>;
17
+ getTemplate(id: string): Promise<PrintTemplate>;
18
+ createTemplate(input: NewPrintTemplate): Promise<PrintTemplate>;
19
+ updateTemplate(id: string, patch: Partial<PrintTemplate>, ifVersion?: number): Promise<PrintTemplate>;
20
+ deleteTemplate(id: string): Promise<void>;
21
+ listFonts(): Promise<PrintFont[]>;
22
+ uploadFont(file: File | File[], meta: {
23
+ name: string;
24
+ family: string;
25
+ }): Promise<PrintFont>;
26
+ updateFont(id: string, patch: Partial<Pick<PrintFont, 'name' | 'family'>>): Promise<PrintFont>;
27
+ deleteFont(id: string): Promise<void>;
28
+ getClientRelease(): Promise<ClientRelease>;
29
+ }
@@ -0,0 +1,4 @@
1
+ import { PrintClientInfo } from '../contract/types';
2
+
3
+ export declare function isClientOpen(): boolean;
4
+ export declare function getClientInfo(): PrintClientInfo;
@@ -0,0 +1,2 @@
1
+ export type Platform = 'win' | 'mac' | 'linux';
2
+ export declare function detectPlatform(userAgentPlatform?: string): Platform;
@@ -0,0 +1,2 @@
1
+ export declare function compareVersions(a: string, b: string): number;
2
+ export declare function isVersionBelow(version: string, min: string): boolean;
@@ -0,0 +1,23 @@
1
+ import { PrintTemplate, NewPrintTemplate, PrintFont, ClientRelease } from './types';
2
+
3
+ export interface BackendAdapter {
4
+ listTemplates(filter?: {
5
+ keyword?: string;
6
+ [k: string]: any;
7
+ }): Promise<{
8
+ items: PrintTemplate[];
9
+ total: number;
10
+ }>;
11
+ getTemplate(id: string): Promise<PrintTemplate>;
12
+ createTemplate(input: NewPrintTemplate): Promise<PrintTemplate>;
13
+ updateTemplate(id: string, patch: Partial<PrintTemplate>, ifVersion?: number): Promise<PrintTemplate>;
14
+ deleteTemplate(id: string): Promise<void>;
15
+ listFonts(): Promise<PrintFont[]>;
16
+ uploadFont(file: File | File[], meta: {
17
+ name: string;
18
+ family: string;
19
+ }): Promise<PrintFont>;
20
+ updateFont(id: string, patch: Partial<Pick<PrintFont, 'name' | 'family'>>): Promise<PrintFont>;
21
+ deleteFont(id: string): Promise<void>;
22
+ getClientRelease(): Promise<ClientRelease>;
23
+ }
@@ -0,0 +1,63 @@
1
+ export type FieldType = 'string' | 'number' | 'date' | 'datetime' | 'image' | 'qrcode' | 'barcode' | 'longtext';
2
+ export interface FieldSchema {
3
+ key: string;
4
+ label: string;
5
+ type: FieldType;
6
+ required?: boolean;
7
+ group?: string;
8
+ sample: any;
9
+ formatter?: string;
10
+ enum?: {
11
+ label: string;
12
+ value: any;
13
+ }[];
14
+ description?: string;
15
+ }
16
+ export interface PrintTemplate {
17
+ id: string;
18
+ name: string;
19
+ paper?: {
20
+ widthMm: number;
21
+ heightMm: number;
22
+ orientation?: 'portrait' | 'landscape';
23
+ };
24
+ panels: any[];
25
+ fields: FieldSchema[];
26
+ status: 'draft' | 'published';
27
+ version: number;
28
+ updatedAt: string;
29
+ updatedBy?: string;
30
+ }
31
+ export type NewPrintTemplate = Omit<PrintTemplate, 'id' | 'version' | 'updatedAt'>;
32
+ export interface FontFile {
33
+ format: 'woff2' | 'woff' | 'ttf';
34
+ url: string;
35
+ size?: number;
36
+ }
37
+ export interface PrintFont {
38
+ id: string;
39
+ name: string;
40
+ family: string;
41
+ files: FontFile[];
42
+ uploader?: string;
43
+ createdAt: string;
44
+ }
45
+ export interface PrintClientInfo {
46
+ opened: boolean;
47
+ hostname?: string;
48
+ version?: string;
49
+ platform?: string;
50
+ mac?: string;
51
+ ip?: string;
52
+ clientUrl?: string;
53
+ nickName?: string;
54
+ }
55
+ export interface ClientRelease {
56
+ version: string;
57
+ officialUrl: string;
58
+ selfHostedUrl?: string;
59
+ minCompatibleVersion: string;
60
+ releaseNotes?: string;
61
+ os?: string[];
62
+ publishedAt: string;
63
+ }
@@ -0,0 +1,15 @@
1
+ import { BackendAdapter } from '../contract/adapter';
2
+
3
+ export interface HPrintDesignerOptions {
4
+ adapter?: BackendAdapter;
5
+ host?: string;
6
+ token?: string;
7
+ lang?: 'cn' | 'en' | 'de' | 'es' | 'fr' | 'it' | 'ja' | 'ru' | 'cn_tw';
8
+ }
9
+ export declare class HPrintDesigner {
10
+ private _hiprint;
11
+ private opts;
12
+ constructor(opts?: HPrintDesignerOptions);
13
+ load(): Promise<any>;
14
+ get raw(): any;
15
+ }
@@ -0,0 +1,11 @@
1
+ import { HPrintDesignerOptions } from './facade';
2
+ import { BackendAdapter } from '../contract/adapter';
3
+
4
+ export interface PluginOptions extends HPrintDesignerOptions {
5
+ componentName?: string;
6
+ baseURL?: string;
7
+ adapter?: BackendAdapter;
8
+ }
9
+ export declare const HprintPlugin: {
10
+ install(Vue: any, options?: PluginOptions): void;
11
+ };
@@ -0,0 +1,2 @@
1
+ export declare const PRINT_LOCK_LINK_ID = "hprint-print-lock";
2
+ export declare function injectPrintLockCss(): void;
@@ -0,0 +1,10 @@
1
+ export interface DragItem {
2
+ tid: string;
3
+ label: string;
4
+ icon: string;
5
+ }
6
+ export interface DragGroup {
7
+ title: string;
8
+ items: DragItem[];
9
+ }
10
+ export declare function getDragGroups(): DragGroup[];
@@ -0,0 +1,6 @@
1
+ export interface FormatterPreset {
2
+ label: string;
3
+ value: string;
4
+ }
5
+ export declare function getFormatterPresets(): FormatterPreset[];
6
+ export declare function resolveFormatter(name?: string): (v: any) => string;
@@ -0,0 +1,3 @@
1
+ import { FieldSchema } from '../contract/types';
2
+
3
+ export declare function buildPreviewData(fields: FieldSchema[]): Record<string, any>;
@@ -0,0 +1,8 @@
1
+ import { PrintFont } from '../contract/types';
2
+
3
+ export declare function buildFontFaceCss(fonts: PrintFont[]): string;
4
+ export declare function buildStyleHandlerCss(fonts: PrintFont[]): string;
5
+ export declare function toHiprintFontList(fonts: PrintFont[]): {
6
+ title: string;
7
+ value: string;
8
+ }[];
@@ -0,0 +1,7 @@
1
+ import { PrintFont } from '../contract/types';
2
+
3
+ export declare class FontManager {
4
+ private el;
5
+ inject(fonts: PrintFont[]): void;
6
+ cleanup(): void;
7
+ }