taro-bluetooth-print 2.9.0 → 2.9.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/CHANGELOG.md +16 -1
- package/README.md +53 -4
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/core/di/Container.d.ts +84 -0
- package/dist/types/core/di/Tokens.d.ts +29 -0
- package/dist/types/core/di/index.d.ts +3 -0
- package/dist/types/core/event/EventBus.d.ts +66 -0
- package/dist/types/core/event/index.d.ts +2 -0
- package/dist/types/core/index.d.ts +5 -4
- package/dist/types/core/plugin/PluginManager.d.ts +64 -0
- package/dist/types/core/plugin/index.d.ts +2 -0
- package/dist/types/device/MultiPrinterManager.d.ts +2 -0
- package/dist/types/factory/di-factory.d.ts +52 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/providers/ServiceProvider.d.ts +56 -0
- package/dist/types/providers/index.d.ts +2 -0
- package/dist/types/template/TemplateEngine.d.ts +24 -68
- package/dist/types/template/engines/TemplateRenderer.d.ts +71 -0
- package/dist/types/template/parsers/TemplateParser.d.ts +23 -0
- package/dist/types/utils/index.d.ts +8 -0
- package/dist/types/utils/logger.d.ts +4 -3
- package/dist/types/utils/outputLimiter.d.ts +87 -0
- package/dist/types/utils/validation.d.ts +11 -309
- package/dist/types/utils/validators/array.d.ts +19 -0
- package/dist/types/utils/validators/buffer.d.ts +18 -0
- package/dist/types/utils/validators/chain.d.ts +31 -0
- package/dist/types/utils/validators/common.d.ts +22 -0
- package/dist/types/utils/validators/number.d.ts +20 -0
- package/dist/types/utils/validators/object.d.ts +24 -0
- package/dist/types/utils/validators/printer.d.ts +40 -0
- package/dist/types/utils/validators/types.d.ts +125 -0
- package/dist/types/utils/validators/uuid.d.ts +23 -0
- package/package.json +1 -1
- package/src/core/BluetoothPrinter.ts +2 -1
- package/src/core/di/Container.ts +332 -0
- package/src/core/di/Tokens.ts +45 -0
- package/src/core/di/index.ts +3 -0
- package/src/core/event/EventBus.ts +251 -0
- package/src/core/event/index.ts +2 -0
- package/src/core/index.ts +10 -4
- package/src/core/plugin/PluginManager.ts +161 -0
- package/src/core/plugin/index.ts +2 -0
- package/src/device/MultiPrinterManager.ts +15 -6
- package/src/factory/di-factory.ts +61 -0
- package/src/index.ts +50 -1
- package/src/providers/ServiceProvider.ts +213 -0
- package/src/providers/index.ts +2 -0
- package/src/template/TemplateEngine.ts +27 -792
- package/src/template/engines/TemplateRenderer.ts +762 -0
- package/src/template/parsers/TemplateParser.ts +94 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/logger.ts +17 -4
- package/src/utils/outputLimiter.ts +227 -0
- package/src/utils/validation.ts +21 -1138
- package/src/utils/validators/array.ts +95 -0
- package/src/utils/validators/buffer.ts +81 -0
- package/src/utils/validators/chain.ts +181 -0
- package/src/utils/validators/common.ts +216 -0
- package/src/utils/validators/number.ts +101 -0
- package/src/utils/validators/object.ts +63 -0
- package/src/utils/validators/printer.ts +294 -0
- package/src/utils/validators/types.ts +105 -0
- package/src/utils/validators/uuid.ts +49 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 依赖注入容器
|
|
3
|
+
* 提供现代化的依赖管理和服务定位功能
|
|
4
|
+
*/
|
|
5
|
+
export type Constructor<T = object> = new (...args: any[]) => T;
|
|
6
|
+
export type Factory<T> = (container: Container) => T;
|
|
7
|
+
export type Provider<T> = Constructor<T> | Factory<T> | T;
|
|
8
|
+
export interface RegistrationOptions {
|
|
9
|
+
/** 是否单例 */
|
|
10
|
+
singleton?: boolean;
|
|
11
|
+
/** 生命周期 */
|
|
12
|
+
lifecycle?: 'transient' | 'singleton' | 'scoped';
|
|
13
|
+
/** 标签,用于区分同一接口的不同实现 */
|
|
14
|
+
tag?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Angular 风格的服务提供者配置
|
|
18
|
+
*/
|
|
19
|
+
export interface ServiceProviderConfig<T = unknown> {
|
|
20
|
+
/** 使用类 */
|
|
21
|
+
useClass?: Constructor<T>;
|
|
22
|
+
/** 使用工厂函数 */
|
|
23
|
+
useFactory?: Factory<T>;
|
|
24
|
+
/** 使用实例值 */
|
|
25
|
+
useValue?: T;
|
|
26
|
+
/** 生命周期 */
|
|
27
|
+
lifecycle?: 'transient' | 'singleton' | 'scoped';
|
|
28
|
+
/** 依赖项 */
|
|
29
|
+
dependencies?: (string | symbol | Constructor<unknown>)[];
|
|
30
|
+
}
|
|
31
|
+
export declare class Container {
|
|
32
|
+
private registrations;
|
|
33
|
+
private parent?;
|
|
34
|
+
private scopedInstances;
|
|
35
|
+
constructor(parent?: Container);
|
|
36
|
+
/**
|
|
37
|
+
* 创建子容器
|
|
38
|
+
*/
|
|
39
|
+
createChild(): Container;
|
|
40
|
+
/**
|
|
41
|
+
* 注册服务
|
|
42
|
+
*/
|
|
43
|
+
register<T>(token: string | symbol | Constructor<T>, provider: Provider<T> | ServiceProviderConfig<T>, options?: RegistrationOptions): this;
|
|
44
|
+
/**
|
|
45
|
+
* 注册单例服务
|
|
46
|
+
*/
|
|
47
|
+
registerSingleton<T>(token: string | symbol | Constructor<T>, provider: Provider<T>): this;
|
|
48
|
+
/**
|
|
49
|
+
* 注册类型映射
|
|
50
|
+
*/
|
|
51
|
+
registerType<T>(from: string | symbol | Constructor<T>, to: Constructor<T>, options?: RegistrationOptions): this;
|
|
52
|
+
/**
|
|
53
|
+
* 注册实例
|
|
54
|
+
*/
|
|
55
|
+
registerInstance<T>(token: string | symbol | Constructor<T>, instance: T): this;
|
|
56
|
+
/**
|
|
57
|
+
* 解析服务
|
|
58
|
+
*/
|
|
59
|
+
resolve<T>(token: string | symbol | Constructor<T>, tag?: string): T;
|
|
60
|
+
/**
|
|
61
|
+
* 解析所有注册的服务
|
|
62
|
+
*/
|
|
63
|
+
resolveAll<T>(token: string | symbol | Constructor<T>): T[];
|
|
64
|
+
/**
|
|
65
|
+
* 检查是否已注册
|
|
66
|
+
*/
|
|
67
|
+
isRegistered<T>(token: string | symbol | Constructor<T>): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 清除所有注册
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
/**
|
|
73
|
+
* 创建作用域
|
|
74
|
+
*/
|
|
75
|
+
createScope(): Container;
|
|
76
|
+
private getTokenKey;
|
|
77
|
+
private isConstructor;
|
|
78
|
+
private getOrCreateInstance;
|
|
79
|
+
private createProviderInstance;
|
|
80
|
+
private createInstance;
|
|
81
|
+
}
|
|
82
|
+
export declare const rootContainer: Container;
|
|
83
|
+
export declare function injectable<T extends Constructor<object>>(constructor: T): T;
|
|
84
|
+
export declare function inject(token: string | symbol): (target: any, _propertyKey: string | symbol, parameterIndex: number) => any;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 服务标识符(Tokens)
|
|
3
|
+
* 用于依赖注入的常量定义
|
|
4
|
+
*/
|
|
5
|
+
export declare const ADAPTER_TOKEN: unique symbol;
|
|
6
|
+
export declare const ADAPTER_FACTORY_TOKEN: unique symbol;
|
|
7
|
+
export declare const DRIVER_TOKEN: unique symbol;
|
|
8
|
+
export declare const DRIVER_FACTORY_TOKEN: unique symbol;
|
|
9
|
+
export declare const DEVICE_MANAGER_TOKEN: unique symbol;
|
|
10
|
+
export declare const CONNECTION_MANAGER_TOKEN: unique symbol;
|
|
11
|
+
export declare const PRINT_JOB_MANAGER_TOKEN: unique symbol;
|
|
12
|
+
export declare const PRINT_QUEUE_TOKEN: unique symbol;
|
|
13
|
+
export declare const OFFLINE_CACHE_TOKEN: unique symbol;
|
|
14
|
+
export declare const CONFIG_MANAGER_TOKEN: unique symbol;
|
|
15
|
+
export declare const COMMAND_BUILDER_TOKEN: unique symbol;
|
|
16
|
+
export declare const PRINTER_STATUS_TOKEN: unique symbol;
|
|
17
|
+
export declare const PRINT_HISTORY_TOKEN: unique symbol;
|
|
18
|
+
export declare const PRINT_STATISTICS_TOKEN: unique symbol;
|
|
19
|
+
export declare const CLOUD_PRINT_MANAGER_TOKEN: unique symbol;
|
|
20
|
+
export declare const SCHEDULED_RETRY_MANAGER_TOKEN: unique symbol;
|
|
21
|
+
export declare const BATCH_PRINT_MANAGER_TOKEN: unique symbol;
|
|
22
|
+
export declare const LOGGER_TOKEN: unique symbol;
|
|
23
|
+
export declare const ENCODING_SERVICE_TOKEN: unique symbol;
|
|
24
|
+
export declare const IMAGE_PROCESSING_TOKEN: unique symbol;
|
|
25
|
+
export declare const BARCODE_GENERATOR_TOKEN: unique symbol;
|
|
26
|
+
export declare const TEMPLATE_ENGINE_TOKEN: unique symbol;
|
|
27
|
+
export declare const EVENT_BUS_TOKEN: unique symbol;
|
|
28
|
+
export declare const PLUGIN_MANAGER_TOKEN: unique symbol;
|
|
29
|
+
export declare const PERFORMANCE_MONITOR_TOKEN: unique symbol;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 事件总线 - 提供强大的事件驱动能力
|
|
3
|
+
* 支持事件订阅、发布、一次性监听、异步处理等
|
|
4
|
+
*/
|
|
5
|
+
export type EventHandler<T = any> = (payload: T) => void | Promise<void>;
|
|
6
|
+
export type EventFilter<T = any> = (payload: T) => boolean;
|
|
7
|
+
export interface EventSubscription {
|
|
8
|
+
unsubscribe(): void;
|
|
9
|
+
}
|
|
10
|
+
export interface EventOptions {
|
|
11
|
+
/** 优先级,数字越小优先级越高 */
|
|
12
|
+
priority?: number;
|
|
13
|
+
/** 过滤器 */
|
|
14
|
+
filter?: EventFilter<any>;
|
|
15
|
+
/** 是否只监听一次 */
|
|
16
|
+
once?: boolean;
|
|
17
|
+
/** 超时时间(毫秒) */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class EventBus {
|
|
21
|
+
private listeners;
|
|
22
|
+
private listenerIdCounter;
|
|
23
|
+
/**
|
|
24
|
+
* 订阅事件
|
|
25
|
+
*/
|
|
26
|
+
on<T>(event: string | symbol, handler: EventHandler<T>, options?: EventOptions): EventSubscription;
|
|
27
|
+
/**
|
|
28
|
+
* 只监听一次
|
|
29
|
+
*/
|
|
30
|
+
once<T>(event: string | symbol, handler: EventHandler<T>, options?: Omit<EventOptions, 'once'>): EventSubscription;
|
|
31
|
+
/**
|
|
32
|
+
* 取消订阅
|
|
33
|
+
*/
|
|
34
|
+
off<T>(event: string | symbol, handler: EventHandler<T>): void;
|
|
35
|
+
/**
|
|
36
|
+
* 发布事件
|
|
37
|
+
*/
|
|
38
|
+
emit<T>(event: string | symbol, payload: T): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 同步发布事件(不等待处理完成)
|
|
41
|
+
*/
|
|
42
|
+
emitSync<T>(event: string | symbol, payload: T): void;
|
|
43
|
+
/**
|
|
44
|
+
* 等待特定事件
|
|
45
|
+
*/
|
|
46
|
+
waitFor<T>(event: string | symbol, timeout?: number, _filter?: EventFilter<T>): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* 检查是否有监听器
|
|
49
|
+
*/
|
|
50
|
+
hasListeners(event: string | symbol): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 获取监听器数量
|
|
53
|
+
*/
|
|
54
|
+
listenerCount(event: string | symbol): number;
|
|
55
|
+
/**
|
|
56
|
+
* 移除所有监听器
|
|
57
|
+
*/
|
|
58
|
+
removeAllListeners(event?: string | symbol): void;
|
|
59
|
+
/**
|
|
60
|
+
* 获取所有事件名称
|
|
61
|
+
*/
|
|
62
|
+
eventNames(): (string | symbol)[];
|
|
63
|
+
private generateListenerId;
|
|
64
|
+
private executeWithTimeout;
|
|
65
|
+
}
|
|
66
|
+
export declare const globalEventBus: EventBus;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 核心架构模块
|
|
3
|
+
* 提供依赖注入、事件总线、插件管理等核心能力
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export * from './di';
|
|
6
|
+
export * from './event';
|
|
7
|
+
export * from './plugin';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { EventBus } from '../event/EventBus';
|
|
2
|
+
import { Container } from '../di/Container';
|
|
3
|
+
export interface PluginContext {
|
|
4
|
+
/** 事件总线 */
|
|
5
|
+
eventBus: EventBus;
|
|
6
|
+
/** DI容器 */
|
|
7
|
+
container: Container;
|
|
8
|
+
/** 配置 */
|
|
9
|
+
config: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface Plugin {
|
|
12
|
+
/** 插件名称 */
|
|
13
|
+
name: string;
|
|
14
|
+
/** 插件版本 */
|
|
15
|
+
version: string;
|
|
16
|
+
/** 插件依赖 */
|
|
17
|
+
dependencies?: string[];
|
|
18
|
+
/** 安装插件 */
|
|
19
|
+
install(context: PluginContext): void | Promise<void>;
|
|
20
|
+
/** 卸载插件 */
|
|
21
|
+
uninstall?(context: PluginContext): void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export interface PluginRegistration {
|
|
24
|
+
plugin: Plugin;
|
|
25
|
+
config: Record<string, unknown>;
|
|
26
|
+
installed: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare class PluginManager {
|
|
29
|
+
private plugins;
|
|
30
|
+
private context;
|
|
31
|
+
constructor(context: PluginContext);
|
|
32
|
+
/**
|
|
33
|
+
* 注册插件
|
|
34
|
+
*/
|
|
35
|
+
register(plugin: Plugin, config?: Record<string, unknown>): void;
|
|
36
|
+
/**
|
|
37
|
+
* 安装插件
|
|
38
|
+
*/
|
|
39
|
+
install(pluginName: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* 卸载插件
|
|
42
|
+
*/
|
|
43
|
+
uninstall(pluginName: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* 批量安装插件
|
|
46
|
+
*/
|
|
47
|
+
installAll(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* 获取插件
|
|
50
|
+
*/
|
|
51
|
+
getPlugin(name: string): Plugin | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* 检查插件是否已安装
|
|
54
|
+
*/
|
|
55
|
+
isInstalled(name: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* 获取所有已安装的插件
|
|
58
|
+
*/
|
|
59
|
+
getInstalledPlugins(): Plugin[];
|
|
60
|
+
/**
|
|
61
|
+
* 获取所有已注册的插件
|
|
62
|
+
*/
|
|
63
|
+
getRegisteredPlugins(): Plugin[];
|
|
64
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BluetoothPrinter } from '../core/BluetoothPrinter';
|
|
2
|
+
import { createServiceProvider, ServiceProviderOptions } from '../providers';
|
|
3
|
+
import { IConnectionManager, IPrintJobManager, ICommandBuilder } from '../services/interfaces';
|
|
4
|
+
/**
|
|
5
|
+
* 创建打印机实例的选项
|
|
6
|
+
*/
|
|
7
|
+
export interface CreatePrinterOptions extends ServiceProviderOptions {
|
|
8
|
+
/** 自定义连接管理器 */
|
|
9
|
+
connectionManager?: IConnectionManager;
|
|
10
|
+
/** 自定义打印任务管理器 */
|
|
11
|
+
printJobManager?: IPrintJobManager;
|
|
12
|
+
/** 自定义命令构建器 */
|
|
13
|
+
commandBuilder?: ICommandBuilder;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 使用依赖注入创建 BluetoothPrinter 实例
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // 基本用法
|
|
21
|
+
* const printer = createPrinter();
|
|
22
|
+
*
|
|
23
|
+
* // 使用自定义配置
|
|
24
|
+
* const printer = createPrinter({
|
|
25
|
+
* config: { debug: true },
|
|
26
|
+
* useGlobalEventBus: true
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function createPrinter(options?: CreatePrinterOptions): BluetoothPrinter;
|
|
31
|
+
/**
|
|
32
|
+
* 获取服务提供者(用于访问所有服务)
|
|
33
|
+
*/
|
|
34
|
+
export declare function getServiceProvider(options?: ServiceProviderOptions): {
|
|
35
|
+
getConnectionManager: () => unknown;
|
|
36
|
+
getPrintJobManager: () => unknown;
|
|
37
|
+
getCommandBuilder: () => unknown;
|
|
38
|
+
getDeviceManager: () => unknown;
|
|
39
|
+
getPrintQueue: () => unknown;
|
|
40
|
+
getOfflineCache: () => unknown;
|
|
41
|
+
getConfigManager: () => unknown;
|
|
42
|
+
getPrinterStatus: () => unknown;
|
|
43
|
+
getPrintHistory: () => unknown;
|
|
44
|
+
getPrintStatistics: () => unknown;
|
|
45
|
+
getCloudPrintManager: () => unknown;
|
|
46
|
+
getScheduledRetryManager: () => unknown;
|
|
47
|
+
getBatchPrintManager: () => unknown;
|
|
48
|
+
getEventBus: () => unknown;
|
|
49
|
+
getPluginManager: () => unknown;
|
|
50
|
+
getAdapter: () => unknown;
|
|
51
|
+
};
|
|
52
|
+
export { createServiceProvider, ServiceProviderOptions };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -39,16 +39,20 @@ export { Logger, LogLevel } from './utils/logger';
|
|
|
39
39
|
export { Encoding } from './utils/encoding';
|
|
40
40
|
export { ImageProcessing } from './utils/image';
|
|
41
41
|
export { PlatformType, detectPlatform, isPlatformSupported } from './utils/platform';
|
|
42
|
+
export { truncateString, truncateForLog, batchProcess, createLimitedLogger, generateSummary, } from './utils/outputLimiter';
|
|
43
|
+
export type { TruncateOptions } from './utils/outputLimiter';
|
|
42
44
|
export { BluetoothPrintError, ErrorCode } from './errors/BluetoothError';
|
|
43
45
|
export { ConnectionError, ConnectionErrorCode } from './errors/ConnectionError';
|
|
44
46
|
export { PrintJobError, PrintJobErrorCode } from './errors/PrintJobError';
|
|
45
47
|
export { CommandBuildError, CommandBuildErrorCode } from './errors/CommandBuildError';
|
|
46
48
|
export { createBluetoothPrinter, createWebBluetoothPrinter, PrinterFactory, type PrinterFactoryOptions, } from './factory';
|
|
49
|
+
export { createPrinter, getServiceProvider, createServiceProvider, type CreatePrinterOptions, type ServiceProviderOptions, } from './factory/di-factory';
|
|
50
|
+
export { Container, rootContainer, injectable, inject, EventBus, globalEventBus, PluginManager, } from './core';
|
|
51
|
+
export { ADAPTER_TOKEN, DRIVER_TOKEN, DEVICE_MANAGER_TOKEN, CONNECTION_MANAGER_TOKEN, PRINT_JOB_MANAGER_TOKEN, PRINT_QUEUE_TOKEN, OFFLINE_CACHE_TOKEN, CONFIG_MANAGER_TOKEN, LOGGER_TOKEN, EVENT_BUS_TOKEN, PLUGIN_MANAGER_TOKEN, PERFORMANCE_MONITOR_TOKEN, COMMAND_BUILDER_TOKEN, PRINTER_STATUS_TOKEN, PRINT_HISTORY_TOKEN, PRINT_STATISTICS_TOKEN, CLOUD_PRINT_MANAGER_TOKEN, SCHEDULED_RETRY_MANAGER_TOKEN, BATCH_PRINT_MANAGER_TOKEN, } from './core';
|
|
47
52
|
export { DEFAULT_CONFIG, mergeConfig } from './config/PrinterConfig';
|
|
48
53
|
export type { PrinterConfig, AdapterConfig, DriverConfig, LoggingConfig, } from './config/PrinterConfig';
|
|
49
54
|
export { PrinterConfigManager, printerConfigManager } from './config/PrinterConfigManager';
|
|
50
55
|
export type { SavedPrinter, GlobalConfig, IConfigStorage } from './config/PrinterConfigManager';
|
|
51
|
-
export { PluginManager } from './plugins/PluginManager';
|
|
52
56
|
export { createLoggingPlugin, createRetryPlugin } from './plugins';
|
|
53
57
|
export type { Plugin, PluginHooks, PluginOptions, PluginFactory } from './plugins/types';
|
|
54
58
|
export * from './types';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Provider Module
|
|
3
|
+
*
|
|
4
|
+
* 将现有服务层注册到 DI 容器
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 服务提供者配置选项
|
|
8
|
+
*/
|
|
9
|
+
export interface ServiceProviderOptions {
|
|
10
|
+
/** 是否启用全局事件总线 */
|
|
11
|
+
useGlobalEventBus?: boolean;
|
|
12
|
+
/** 自定义配置 */
|
|
13
|
+
config?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 注册所有服务到 DI 容器
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerServices(options?: ServiceProviderOptions): void;
|
|
19
|
+
/**
|
|
20
|
+
* 创建配置好的服务提供者
|
|
21
|
+
*/
|
|
22
|
+
export declare function createServiceProvider(options?: ServiceProviderOptions): {
|
|
23
|
+
/** 获取连接管理器 */
|
|
24
|
+
getConnectionManager: () => unknown;
|
|
25
|
+
/** 获取打印任务管理器 */
|
|
26
|
+
getPrintJobManager: () => unknown;
|
|
27
|
+
/** 获取命令构建器 */
|
|
28
|
+
getCommandBuilder: () => unknown;
|
|
29
|
+
/** 获取设备管理器 */
|
|
30
|
+
getDeviceManager: () => unknown;
|
|
31
|
+
/** 获取打印队列 */
|
|
32
|
+
getPrintQueue: () => unknown;
|
|
33
|
+
/** 获取离线缓存 */
|
|
34
|
+
getOfflineCache: () => unknown;
|
|
35
|
+
/** 获取配置管理器 */
|
|
36
|
+
getConfigManager: () => unknown;
|
|
37
|
+
/** 获取打印机状态服务 */
|
|
38
|
+
getPrinterStatus: () => unknown;
|
|
39
|
+
/** 获取打印历史服务 */
|
|
40
|
+
getPrintHistory: () => unknown;
|
|
41
|
+
/** 获取打印统计服务 */
|
|
42
|
+
getPrintStatistics: () => unknown;
|
|
43
|
+
/** 获取云打印管理器 */
|
|
44
|
+
getCloudPrintManager: () => unknown;
|
|
45
|
+
/** 获取定时重试管理器 */
|
|
46
|
+
getScheduledRetryManager: () => unknown;
|
|
47
|
+
/** 获取批量打印管理器 */
|
|
48
|
+
getBatchPrintManager: () => unknown;
|
|
49
|
+
/** 获取事件总线 */
|
|
50
|
+
getEventBus: () => unknown;
|
|
51
|
+
/** 获取插件管理器 */
|
|
52
|
+
getPluginManager: () => unknown;
|
|
53
|
+
/** 获取适配器 */
|
|
54
|
+
getAdapter: () => unknown;
|
|
55
|
+
};
|
|
56
|
+
export type ServiceProvider = ReturnType<typeof createServiceProvider>;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Template Engine
|
|
3
|
+
*
|
|
4
|
+
* Provides template parsing and rendering for receipts and labels.
|
|
5
|
+
* Supports variable substitution, conditional rendering, loops, and border/table drawing.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const engine = new TemplateEngine();
|
|
10
|
+
* const commands = engine.renderReceipt({
|
|
11
|
+
* store: { name: 'My Store' },
|
|
12
|
+
* items: [{ name: 'Item 1', quantity: 2, price: 10 }],
|
|
13
|
+
* payment: { total: 20, method: 'Cash' }
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
3
17
|
/**
|
|
4
18
|
* Template type
|
|
5
19
|
*/
|
|
@@ -64,7 +78,7 @@ export interface LabelData {
|
|
|
64
78
|
name: string;
|
|
65
79
|
price: number;
|
|
66
80
|
barcode?: string;
|
|
67
|
-
barcodeFormat?: BarcodeFormat;
|
|
81
|
+
barcodeFormat?: import('../barcode').BarcodeFormat;
|
|
68
82
|
spec?: string;
|
|
69
83
|
productionDate?: string;
|
|
70
84
|
expiryDate?: string;
|
|
@@ -155,9 +169,9 @@ export interface TableColumn {
|
|
|
155
169
|
/** Width of column in characters */
|
|
156
170
|
width: number;
|
|
157
171
|
/** Text alignment for header */
|
|
158
|
-
headerAlign?: TextAlign;
|
|
172
|
+
headerAlign?: import('../formatter').TextAlign;
|
|
159
173
|
/** Text alignment for cells */
|
|
160
|
-
cellAlign?: TextAlign;
|
|
174
|
+
cellAlign?: import('../formatter').TextAlign;
|
|
161
175
|
}
|
|
162
176
|
/**
|
|
163
177
|
* Table row data
|
|
@@ -186,7 +200,7 @@ export interface TableElement {
|
|
|
186
200
|
export type TemplateElement = {
|
|
187
201
|
type: 'text';
|
|
188
202
|
content: string;
|
|
189
|
-
align?: TextAlign;
|
|
203
|
+
align?: import('../formatter').TextAlign;
|
|
190
204
|
size?: number;
|
|
191
205
|
bold?: boolean;
|
|
192
206
|
} | {
|
|
@@ -205,7 +219,7 @@ export type TemplateElement = {
|
|
|
205
219
|
} | {
|
|
206
220
|
type: 'barcode';
|
|
207
221
|
content: string;
|
|
208
|
-
format: BarcodeFormat;
|
|
222
|
+
format: import('../barcode').BarcodeFormat;
|
|
209
223
|
height?: number;
|
|
210
224
|
} | {
|
|
211
225
|
type: 'feed';
|
|
@@ -247,15 +261,13 @@ export interface ITemplateEngine {
|
|
|
247
261
|
}
|
|
248
262
|
/**
|
|
249
263
|
* Template Engine class
|
|
250
|
-
*
|
|
264
|
+
* Facade for template parsing and rendering
|
|
251
265
|
*/
|
|
252
266
|
export declare class TemplateEngine implements ITemplateEngine {
|
|
253
267
|
private readonly logger;
|
|
254
|
-
private readonly
|
|
255
|
-
private readonly
|
|
256
|
-
private readonly driver;
|
|
268
|
+
private readonly parser;
|
|
269
|
+
private readonly renderer;
|
|
257
270
|
private readonly templates;
|
|
258
|
-
private readonly paperWidth;
|
|
259
271
|
/**
|
|
260
272
|
* Creates a new TemplateEngine instance
|
|
261
273
|
*/
|
|
@@ -284,61 +296,5 @@ export declare class TemplateEngine implements ITemplateEngine {
|
|
|
284
296
|
* Validate template data
|
|
285
297
|
*/
|
|
286
298
|
validate(template: TemplateDefinition, data: Record<string, unknown>): ValidationResult;
|
|
287
|
-
/**
|
|
288
|
-
* Render a single template element
|
|
289
|
-
*/
|
|
290
|
-
private renderElement;
|
|
291
|
-
/**
|
|
292
|
-
* Render a loop element
|
|
293
|
-
*/
|
|
294
|
-
private renderLoop;
|
|
295
|
-
/**
|
|
296
|
-
* Render a condition element
|
|
297
|
-
*/
|
|
298
|
-
private renderCondition;
|
|
299
|
-
/**
|
|
300
|
-
* Evaluate a condition
|
|
301
|
-
*/
|
|
302
|
-
private evaluateCondition;
|
|
303
|
-
/**
|
|
304
|
-
* Render a border element
|
|
305
|
-
*/
|
|
306
|
-
private renderBorder;
|
|
307
|
-
/**
|
|
308
|
-
* Render a table element
|
|
309
|
-
*/
|
|
310
|
-
private renderTable;
|
|
311
|
-
/**
|
|
312
|
-
* Align text within a specified width
|
|
313
|
-
*/
|
|
314
|
-
private alignText;
|
|
315
|
-
/**
|
|
316
|
-
* Render standard elements (text, line, image, qrcode, barcode, feed, variable)
|
|
317
|
-
*/
|
|
318
|
-
private renderStandardElement;
|
|
319
|
-
/**
|
|
320
|
-
* Render a separator line
|
|
321
|
-
*/
|
|
322
|
-
private renderLine;
|
|
323
|
-
/**
|
|
324
|
-
* Format an item line with columns
|
|
325
|
-
*/
|
|
326
|
-
private formatItemLine;
|
|
327
|
-
/**
|
|
328
|
-
* Substitute variables in a string
|
|
329
|
-
*/
|
|
330
|
-
private substituteVariables;
|
|
331
|
-
/**
|
|
332
|
-
* Get nested value from object
|
|
333
|
-
*/
|
|
334
|
-
private getNestedValue;
|
|
335
|
-
/**
|
|
336
|
-
* Format a value with optional format string
|
|
337
|
-
*/
|
|
338
|
-
private formatValue;
|
|
339
|
-
/**
|
|
340
|
-
* Combine multiple command arrays into one
|
|
341
|
-
*/
|
|
342
|
-
private combineCommands;
|
|
343
299
|
}
|
|
344
300
|
export declare const templateEngine: TemplateEngine;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { TextAlign } from '../../formatter';
|
|
2
|
+
import { TemplateElement, LoopElement, ConditionElement, BorderElement, TableElement, ReceiptData, LabelData } from '../TemplateEngine';
|
|
3
|
+
/**
|
|
4
|
+
* Template Renderer class
|
|
5
|
+
* Renders template elements to ESC/POS commands
|
|
6
|
+
*/
|
|
7
|
+
export declare class TemplateRenderer {
|
|
8
|
+
private readonly logger;
|
|
9
|
+
private readonly formatter;
|
|
10
|
+
private readonly barcodeGenerator;
|
|
11
|
+
private readonly driver;
|
|
12
|
+
private readonly parser;
|
|
13
|
+
private readonly paperWidth;
|
|
14
|
+
constructor(paperWidth?: number);
|
|
15
|
+
/**
|
|
16
|
+
* Render a receipt template
|
|
17
|
+
*/
|
|
18
|
+
renderReceipt(data: ReceiptData): Uint8Array;
|
|
19
|
+
/**
|
|
20
|
+
* Render a label template
|
|
21
|
+
*/
|
|
22
|
+
renderLabel(data: LabelData): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Render a custom template
|
|
25
|
+
*/
|
|
26
|
+
render(template: import('../TemplateEngine').TemplateDefinition, data: Record<string, unknown>): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Render a single template element
|
|
29
|
+
*/
|
|
30
|
+
renderElement(element: TemplateElement, data: Record<string, unknown>): Uint8Array[];
|
|
31
|
+
/**
|
|
32
|
+
* Render a loop element
|
|
33
|
+
*/
|
|
34
|
+
renderLoop(loop: LoopElement, data: Record<string, unknown>): Uint8Array[];
|
|
35
|
+
/**
|
|
36
|
+
* Render a condition element
|
|
37
|
+
*/
|
|
38
|
+
renderCondition(condition: ConditionElement, data: Record<string, unknown>): Uint8Array[];
|
|
39
|
+
/**
|
|
40
|
+
* Evaluate a condition
|
|
41
|
+
*/
|
|
42
|
+
evaluateCondition(value: unknown, operator: ConditionElement['operator'], compareValue?: unknown): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Render a border element
|
|
45
|
+
*/
|
|
46
|
+
renderBorder(border: BorderElement): Uint8Array[];
|
|
47
|
+
/**
|
|
48
|
+
* Render a table element
|
|
49
|
+
*/
|
|
50
|
+
renderTable(table: TableElement, data: Record<string, unknown>): Uint8Array[];
|
|
51
|
+
/**
|
|
52
|
+
* Align text within a specified width
|
|
53
|
+
*/
|
|
54
|
+
alignText(text: string, width: number, align: TextAlign): string;
|
|
55
|
+
/**
|
|
56
|
+
* Render standard elements (text, line, image, qrcode, barcode, feed, variable)
|
|
57
|
+
*/
|
|
58
|
+
renderStandardElement(element: Exclude<TemplateElement, LoopElement | ConditionElement | BorderElement | TableElement>, data: Record<string, unknown>): Uint8Array[];
|
|
59
|
+
/**
|
|
60
|
+
* Render a separator line
|
|
61
|
+
*/
|
|
62
|
+
renderLine(char?: string, length?: number): Uint8Array[];
|
|
63
|
+
/**
|
|
64
|
+
* Format an item line with columns
|
|
65
|
+
*/
|
|
66
|
+
formatItemLine(name: string, qty: string, amount: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Combine multiple command arrays into one
|
|
69
|
+
*/
|
|
70
|
+
combineCommands(commands: Uint8Array[]): Uint8Array;
|
|
71
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TemplateDefinition, ValidationResult } from '../TemplateEngine';
|
|
2
|
+
/**
|
|
3
|
+
* Template Parser class
|
|
4
|
+
* Handles template validation and data extraction
|
|
5
|
+
*/
|
|
6
|
+
export declare class TemplateParser {
|
|
7
|
+
/**
|
|
8
|
+
* Validate template data
|
|
9
|
+
*/
|
|
10
|
+
validate(template: TemplateDefinition, data: Record<string, unknown>): ValidationResult;
|
|
11
|
+
/**
|
|
12
|
+
* Substitute variables in a string
|
|
13
|
+
*/
|
|
14
|
+
substituteVariables(template: string, data: Record<string, unknown>): string;
|
|
15
|
+
/**
|
|
16
|
+
* Get nested value from object
|
|
17
|
+
*/
|
|
18
|
+
getNestedValue(obj: Record<string, unknown>, path: string): unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Format a value with optional format string
|
|
21
|
+
*/
|
|
22
|
+
formatValue(value: unknown, format?: string): string;
|
|
23
|
+
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logging utilities for debugging and monitoring
|
|
3
|
-
*/
|
|
4
1
|
/**
|
|
5
2
|
* Log entry structure
|
|
6
3
|
*/
|
|
@@ -42,6 +39,10 @@ export interface LoggerConfig {
|
|
|
42
39
|
prefix: string;
|
|
43
40
|
/** Custom log handler function */
|
|
44
41
|
handler?: LogHandler;
|
|
42
|
+
/** 单条日志最大长度,防止输出被截断 */
|
|
43
|
+
maxOutputLength?: number;
|
|
44
|
+
/** 是否使用数据摘要模式(减少输出量) */
|
|
45
|
+
useSummaryMode?: boolean;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Logger class for consistent logging across the library
|