@bluechaine/print-designer 0.1.1 → 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.
@@ -1,7 +1,8 @@
1
+ var _a, _b, _c, _d;
1
2
  import { reactive, ref, computed, inject, provide, onMounted, onBeforeUnmount, watch, defineComponent, nextTick } from "vue-demi";
2
- import { hiprint, defaultElementTypeProvider, disAutoConnect } from "vue-plugin-hiprint";
3
- import { defaultElementTypeProvider as defaultElementTypeProvider2, hiprint as hiprint2 } from "vue-plugin-hiprint";
4
- import Vue, { resolveComponent, openBlock, createElementBlock, normalizeStyle, normalizeClass, createVNode, createElementVNode, renderSlot, createCommentVNode, toDisplayString, Fragment, renderList, createBlock, withModifiers, withDirectives, vModelText, createTextVNode, vShow, withCtx } from "vue";
3
+ import * as VuePluginHiprint from "vue-plugin-hiprint";
4
+ import { defaultElementTypeProvider as defaultElementTypeProvider$1 } from "vue-plugin-hiprint";
5
+ import Vue, { resolveComponent, openBlock, createElementBlock, normalizeStyle, normalizeClass, createVNode, createElementVNode, renderSlot, createCommentVNode, toDisplayString, Fragment, renderList, createBlock, withModifiers, withDirectives, vModelSelect, createTextVNode, vModelText, vShow, withCtx } from "vue";
5
6
  /**
6
7
  * (c) Iconify
7
8
  *
@@ -2667,10 +2668,10 @@ function isIconifyName(value) {
2667
2668
  return !!value && !value.trim().startsWith("<");
2668
2669
  }
2669
2670
  function elementTypeKey(item) {
2670
- var _a, _b;
2671
- const type = String(((_a = item == null ? void 0 : item.printElementType) == null ? void 0 : _a.type) || "");
2671
+ var _a2, _b2;
2672
+ const type = String(((_a2 = item == null ? void 0 : item.printElementType) == null ? void 0 : _a2.type) || "");
2672
2673
  if (type && ELEMENT_ICON_NAMES[type]) return type;
2673
- const tid = String(((_b = item == null ? void 0 : item.printElementType) == null ? void 0 : _b.tid) || "");
2674
+ const tid = String(((_b2 = item == null ? void 0 : item.printElementType) == null ? void 0 : _b2.tid) || "");
2674
2675
  const short = tid.split(".").pop() || type;
2675
2676
  return short && ELEMENT_ICON_NAMES[short] ? short : "text";
2676
2677
  }
@@ -2799,12 +2800,12 @@ function detectPaperType(width, height, list = defaultPaperList) {
2799
2800
  return (match == null ? void 0 : match.type) || "自定义";
2800
2801
  }
2801
2802
  function resolveTemplate(tplId) {
2802
- var _a, _b;
2803
+ var _a2;
2803
2804
  const cached = templateRegistry.get(tplId);
2804
2805
  if (cached) return cached;
2805
2806
  try {
2806
- const lib = ((_a = hiprint) == null ? void 0 : _a.instance) ?? hiprint;
2807
- return ((_b = lib == null ? void 0 : lib.getPrintTemplateById) == null ? void 0 : _b.call(lib, tplId)) ?? null;
2807
+ const lib = (hiprint == null ? void 0 : hiprint.instance) ?? hiprint;
2808
+ return ((_a2 = lib == null ? void 0 : lib.getPrintTemplateById) == null ? void 0 : _a2.call(lib, tplId)) ?? null;
2808
2809
  } catch {
2809
2810
  return null;
2810
2811
  }
@@ -2894,11 +2895,11 @@ PaperListOptionItem.prototype.createTarget = function(printTemplate) {
2894
2895
  return wrapper;
2895
2896
  };
2896
2897
  PaperListOptionItem.prototype.getValue = function() {
2897
- var _a, _b, _c;
2898
+ var _a2, _b2, _c2;
2898
2899
  return {
2899
- type: String(((_a = this.typeSelect) == null ? void 0 : _a.val()) || "自定义"),
2900
- width: Number((_b = this.widthInput) == null ? void 0 : _b.val()) || 0,
2901
- height: Number((_c = this.heightInput) == null ? void 0 : _c.val()) || 0
2900
+ type: String(((_a2 = this.typeSelect) == null ? void 0 : _a2.val()) || "自定义"),
2901
+ width: Number((_b2 = this.widthInput) == null ? void 0 : _b2.val()) || 0,
2902
+ height: Number((_c2 = this.heightInput) == null ? void 0 : _c2.val()) || 0
2902
2903
  };
2903
2904
  };
2904
2905
  PaperListOptionItem.prototype.setValue = function(value) {
@@ -2916,8 +2917,8 @@ PaperListOptionItem.prototype.setValue = function(value) {
2916
2917
  this.heightInput.val(value.height || "");
2917
2918
  };
2918
2919
  PaperListOptionItem.prototype.destroy = function() {
2919
- var _a, _b;
2920
- (_b = (_a = this.target) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
2920
+ var _a2, _b2;
2921
+ (_b2 = (_a2 = this.target) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2);
2921
2922
  };
2922
2923
  function OrientOptionItem() {
2923
2924
  this.name = "orient";
@@ -2945,18 +2946,18 @@ OrientOptionItem.prototype.createTarget = function() {
2945
2946
  return this.target;
2946
2947
  };
2947
2948
  OrientOptionItem.prototype.getValue = function() {
2948
- var _a, _b, _c, _d;
2949
- const val = (_d = (_c = (_b = (_a = this.target) == null ? void 0 : _a.find) == null ? void 0 : _b.call(_a, "select")) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c);
2949
+ var _a2, _b2, _c2, _d2;
2950
+ const val = (_d2 = (_c2 = (_b2 = (_a2 = this.target) == null ? void 0 : _a2.find) == null ? void 0 : _b2.call(_a2, "select")) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2);
2950
2951
  if (val === "" || val == null) return void 0;
2951
2952
  return parseFloat(String(val));
2952
2953
  };
2953
2954
  OrientOptionItem.prototype.setValue = function(value) {
2954
- var _a, _b, _c, _d;
2955
- (_d = (_c = (_b = (_a = this.target) == null ? void 0 : _a.find) == null ? void 0 : _b.call(_a, "select")) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c, value ?? "");
2955
+ var _a2, _b2, _c2, _d2;
2956
+ (_d2 = (_c2 = (_b2 = (_a2 = this.target) == null ? void 0 : _a2.find) == null ? void 0 : _b2.call(_a2, "select")) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2, value ?? "");
2956
2957
  };
2957
2958
  OrientOptionItem.prototype.destroy = function() {
2958
- var _a, _b;
2959
- (_b = (_a = this.target) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
2959
+ var _a2, _b2;
2960
+ (_b2 = (_a2 = this.target) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2);
2960
2961
  };
2961
2962
  const WATERMARK_TIME_FORMATS = [
2962
2963
  "YYYY-MM-DD HH:mm:ss",
@@ -3050,10 +3051,10 @@ WatermarkOptionItem.prototype.createTarget = function() {
3050
3051
  return this.target;
3051
3052
  };
3052
3053
  WatermarkOptionItem.prototype.getValue = function() {
3053
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
3054
- const format = (_b = (_a = this.format) == null ? void 0 : _a.val) == null ? void 0 : _b.call(_a);
3054
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
3055
+ const format = (_b2 = (_a2 = this.format) == null ? void 0 : _a2.val) == null ? void 0 : _b2.call(_a2);
3055
3056
  return {
3056
- content: ((_d = (_c = this.content) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c)) || "",
3057
+ content: ((_d2 = (_c2 = this.content) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2)) || "",
3057
3058
  fillStyle: ((_f = (_e = this.fillStyle) == null ? void 0 : _e.val) == null ? void 0 : _f.call(_e)) || "rgba(184, 184, 184, 0.3)",
3058
3059
  fontSize: `${parseInt(String(((_h = (_g = this.fontSize) == null ? void 0 : _g.val) == null ? void 0 : _h.call(_g)) || "14"), 10)}px`,
3059
3060
  rotate: parseInt(String(((_j = (_i = this.rotate) == null ? void 0 : _i.val) == null ? void 0 : _j.call(_i)) || "25"), 10),
@@ -3064,10 +3065,10 @@ WatermarkOptionItem.prototype.getValue = function() {
3064
3065
  };
3065
3066
  };
3066
3067
  WatermarkOptionItem.prototype.setValue = function(value) {
3067
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
3068
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
3068
3069
  if (!value) value = {};
3069
- (_b = (_a = this.content) == null ? void 0 : _a.val) == null ? void 0 : _b.call(_a, value.content || "");
3070
- (_d = (_c = this.fillStyle) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c, value.fillStyle || "rgba(184, 184, 184, 0.3)");
3070
+ (_b2 = (_a2 = this.content) == null ? void 0 : _a2.val) == null ? void 0 : _b2.call(_a2, value.content || "");
3071
+ (_d2 = (_c2 = this.fillStyle) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2, value.fillStyle || "rgba(184, 184, 184, 0.3)");
3071
3072
  try {
3072
3073
  (_f = (_e = this.fillStyle) == null ? void 0 : _e.minicolors) == null ? void 0 : _f.call(_e, {
3073
3074
  format: "rgb",
@@ -3085,8 +3086,8 @@ WatermarkOptionItem.prototype.setValue = function(value) {
3085
3086
  (_r = (_q = this.format) == null ? void 0 : _q.val) == null ? void 0 : _r.call(_q, value.format || "YYYY-MM-DD HH:mm");
3086
3087
  };
3087
3088
  WatermarkOptionItem.prototype.destroy = function() {
3088
- var _a, _b;
3089
- (_b = (_a = this.target) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
3089
+ var _a2, _b2;
3090
+ (_b2 = (_a2 = this.target) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2);
3090
3091
  };
3091
3092
  function PanelBackgroundColorOptionItem() {
3092
3093
  this.name = "backgroundColor";
@@ -3105,21 +3106,21 @@ PanelBackgroundColorOptionItem.prototype.createTarget = function() {
3105
3106
  return this.target;
3106
3107
  };
3107
3108
  PanelBackgroundColorOptionItem.prototype.getValue = function() {
3108
- var _a, _b;
3109
- const val = (_b = (_a = this.input) == null ? void 0 : _a.val) == null ? void 0 : _b.call(_a);
3109
+ var _a2, _b2;
3110
+ const val = (_b2 = (_a2 = this.input) == null ? void 0 : _a2.val) == null ? void 0 : _b2.call(_a2);
3110
3111
  return val ? String(val) : void 0;
3111
3112
  };
3112
3113
  PanelBackgroundColorOptionItem.prototype.setValue = function(value) {
3113
- var _a, _b, _c, _d;
3114
+ var _a2, _b2, _c2, _d2;
3114
3115
  const color = value || "#ffffff";
3115
3116
  try {
3116
- (_b = (_a = this.input) == null ? void 0 : _a.minicolors) == null ? void 0 : _b.call(_a, {
3117
+ (_b2 = (_a2 = this.input) == null ? void 0 : _a2.minicolors) == null ? void 0 : _b2.call(_a2, {
3117
3118
  defaultValue: color,
3118
3119
  theme: "bootstrap"
3119
3120
  });
3120
3121
  } catch {
3121
3122
  }
3122
- (_d = (_c = this.input) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c, color);
3123
+ (_d2 = (_c2 = this.input) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2, color);
3123
3124
  };
3124
3125
  PanelBackgroundColorOptionItem.prototype.css = function(target, value) {
3125
3126
  const $ = getJQuery();
@@ -3132,19 +3133,19 @@ PanelBackgroundColorOptionItem.prototype.css = function(target, value) {
3132
3133
  return null;
3133
3134
  };
3134
3135
  PanelBackgroundColorOptionItem.prototype.destroy = function() {
3135
- var _a, _b;
3136
- (_b = (_a = this.target) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
3136
+ var _a2, _b2;
3137
+ (_b2 = (_a2 = this.target) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2);
3137
3138
  };
3138
3139
  function applyPanelBackgroundColor(panel, color) {
3139
- var _a, _b, _c, _d;
3140
+ var _a2, _b2, _c2, _d2;
3140
3141
  if (!panel) return;
3141
3142
  const value = color || "#ffffff";
3142
3143
  panel.backgroundColor = value;
3143
3144
  const $ = getJQuery();
3144
- const paper = ((_a = panel.designPaper) == null ? void 0 : _a.target) || ((_c = (_b = panel.target) == null ? void 0 : _b.find) == null ? void 0 : _c.call(_b, ".hiprint-printPaper")) || ($ && panel.target ? $(panel.target).find(".hiprint-printPaper") : null);
3145
+ const paper = ((_a2 = panel.designPaper) == null ? void 0 : _a2.target) || ((_c2 = (_b2 = panel.target) == null ? void 0 : _b2.find) == null ? void 0 : _c2.call(_b2, ".hiprint-printPaper")) || ($ && panel.target ? $(panel.target).find(".hiprint-printPaper") : null);
3145
3146
  if (paper == null ? void 0 : paper.css) {
3146
3147
  paper.css("background-color", value);
3147
- } else if ((paper == null ? void 0 : paper.length) && ((_d = paper[0]) == null ? void 0 : _d.style)) {
3148
+ } else if ((paper == null ? void 0 : paper.length) && ((_d2 = paper[0]) == null ? void 0 : _d2.style)) {
3148
3149
  paper[0].style.backgroundColor = value;
3149
3150
  }
3150
3151
  }
@@ -3216,33 +3217,33 @@ PanelLayoutOptionItem.prototype.createTarget = function() {
3216
3217
  return this.target;
3217
3218
  };
3218
3219
  PanelLayoutOptionItem.prototype.getValue = function() {
3219
- var _a, _b, _c, _d;
3220
+ var _a2, _b2, _c2, _d2;
3220
3221
  const num = (el) => {
3221
- var _a2;
3222
- return parseInt(String(((_a2 = el == null ? void 0 : el.val) == null ? void 0 : _a2.call(el)) || 0), 10) || 0;
3222
+ var _a3;
3223
+ return parseInt(String(((_a3 = el == null ? void 0 : el.val) == null ? void 0 : _a3.call(el)) || 0), 10) || 0;
3223
3224
  };
3224
3225
  return {
3225
- layoutType: ((_b = (_a = this.layoutType) == null ? void 0 : _a.val) == null ? void 0 : _b.call(_a)) || "column",
3226
+ layoutType: ((_b2 = (_a2 = this.layoutType) == null ? void 0 : _a2.val) == null ? void 0 : _b2.call(_a2)) || "column",
3226
3227
  layoutRowGap: num(this.layoutRowGap),
3227
3228
  layoutColumnGap: num(this.layoutColumnGap),
3228
3229
  paperWidth: num(this.paperWidth),
3229
3230
  paperHeight: num(this.paperHeight),
3230
- paperStyle: ((_d = (_c = this.paperStyle) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c)) || ""
3231
+ paperStyle: ((_d2 = (_c2 = this.paperStyle) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2)) || ""
3231
3232
  };
3232
3233
  };
3233
3234
  PanelLayoutOptionItem.prototype.setValue = function(value) {
3234
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3235
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l;
3235
3236
  if (!value) return;
3236
- (_b = (_a = this.layoutType) == null ? void 0 : _a.val) == null ? void 0 : _b.call(_a, value.layoutType || "column");
3237
- (_d = (_c = this.layoutRowGap) == null ? void 0 : _c.val) == null ? void 0 : _d.call(_c, value.layoutRowGap ?? "");
3237
+ (_b2 = (_a2 = this.layoutType) == null ? void 0 : _a2.val) == null ? void 0 : _b2.call(_a2, value.layoutType || "column");
3238
+ (_d2 = (_c2 = this.layoutRowGap) == null ? void 0 : _c2.val) == null ? void 0 : _d2.call(_c2, value.layoutRowGap ?? "");
3238
3239
  (_f = (_e = this.layoutColumnGap) == null ? void 0 : _e.val) == null ? void 0 : _f.call(_e, value.layoutColumnGap ?? "");
3239
3240
  (_h = (_g = this.paperWidth) == null ? void 0 : _g.val) == null ? void 0 : _h.call(_g, value.paperWidth ?? "");
3240
3241
  (_j = (_i = this.paperHeight) == null ? void 0 : _i.val) == null ? void 0 : _j.call(_i, value.paperHeight ?? "");
3241
3242
  (_l = (_k = this.paperStyle) == null ? void 0 : _k.val) == null ? void 0 : _l.call(_k, value.paperStyle ?? "");
3242
3243
  };
3243
3244
  PanelLayoutOptionItem.prototype.destroy = function() {
3244
- var _a, _b;
3245
- (_b = (_a = this.target) == null ? void 0 : _a.remove) == null ? void 0 : _b.call(_a);
3245
+ var _a2, _b2;
3246
+ (_b2 = (_a2 = this.target) == null ? void 0 : _a2.remove) == null ? void 0 : _b2.call(_a2);
3246
3247
  };
3247
3248
  function reorderPanelSettingOptions(options, panel, paperList) {
3248
3249
  const {
@@ -3261,11 +3262,11 @@ function reorderPanelSettingOptions(options, panel, paperList) {
3261
3262
  };
3262
3263
  }
3263
3264
  function ensurePaperListSupportOptionsFirst() {
3264
- var _a, _b, _c, _d;
3265
+ var _a2, _b2, _c2;
3265
3266
  try {
3266
3267
  const cfg = window.HIPRINT_CONFIG;
3267
- const instanceOpts = (_c = (_b = (_a = hiprint) == null ? void 0 : _a.instance) == null ? void 0 : _b.panel) == null ? void 0 : _c.supportOptions;
3268
- const cfgOpts = (_d = cfg == null ? void 0 : cfg.panel) == null ? void 0 : _d.supportOptions;
3268
+ const instanceOpts = (_b2 = (_a2 = hiprint == null ? void 0 : hiprint.instance) == null ? void 0 : _a2.panel) == null ? void 0 : _b2.supportOptions;
3269
+ const cfgOpts = (_c2 = cfg == null ? void 0 : cfg.panel) == null ? void 0 : _c2.supportOptions;
3269
3270
  const opts = instanceOpts || cfgOpts;
3270
3271
  if (!Array.isArray(opts)) return;
3271
3272
  const idx = opts.findIndex((o) => o.name === "paperList");
@@ -3285,8 +3286,8 @@ function ensurePaperListSupportOptionsFirst() {
3285
3286
  }
3286
3287
  }
3287
3288
  function patchPrintTemplatePaperList() {
3288
- var _a;
3289
- const proto = (_a = hiprint.PrintTemplate) == null ? void 0 : _a.prototype;
3289
+ var _a2;
3290
+ const proto = (_a2 = hiprint.PrintTemplate) == null ? void 0 : _a2.prototype;
3290
3291
  if (!proto || proto.__svpPaperListPatched) return;
3291
3292
  proto.setPaperList = function(list) {
3292
3293
  this._paperList = Array.isArray(list) && list.length ? list : defaultPaperList;
@@ -3297,13 +3298,13 @@ function patchPrintTemplatePaperList() {
3297
3298
  proto.__svpPaperListPatched = true;
3298
3299
  }
3299
3300
  function patchPanelSettingTrigger(onPaperApplied) {
3300
- var _a;
3301
- const bus = (_a = window.hinnn) == null ? void 0 : _a.event;
3301
+ var _a2;
3302
+ const bus = (_a2 = window.hinnn) == null ? void 0 : _a2.event;
3302
3303
  if (!bus || bus.__svpPaperListTriggerPatch) return;
3303
3304
  const origTrigger = bus.trigger.bind(bus);
3304
3305
  bus.trigger = function(key, ...args) {
3305
- var _a2;
3306
- if (typeof key === "string" && key.startsWith("BuildCustomOptionSettingEventKey_") && ((_a2 = args[0]) == null ? void 0 : _a2.options)) {
3306
+ var _a3;
3307
+ if (typeof key === "string" && key.startsWith("BuildCustomOptionSettingEventKey_") && ((_a3 = args[0]) == null ? void 0 : _a3.options)) {
3307
3308
  const tplId = key.slice("BuildCustomOptionSettingEventKey_".length);
3308
3309
  const tpl = resolveTemplate(tplId);
3309
3310
  const panel = tpl == null ? void 0 : tpl.editingPanel;
@@ -3511,13 +3512,13 @@ function applyCustomTableType(current) {
3511
3512
  }
3512
3513
  class SvpElementTypeProvider extends Provider {
3513
3514
  addElementTypes(context) {
3514
- var _a;
3515
- new defaultElementTypeProvider().addElementTypes(context);
3515
+ var _a2;
3516
+ new defaultElementTypeProvider$1().addElementTypes(context);
3516
3517
  if (typeof context.updateElementType === "function") {
3517
3518
  context.updateElementType(TABLE_TID, applyCustomTableType);
3518
3519
  return;
3519
3520
  }
3520
- const current = (_a = context.getElementType) == null ? void 0 : _a.call(context, TABLE_TID);
3521
+ const current = (_a2 = context.getElementType) == null ? void 0 : _a2.call(context, TABLE_TID);
3521
3522
  if (current) applyCustomTableType(current);
3522
3523
  }
3523
3524
  }
@@ -3529,9 +3530,14 @@ function normalizeProviderMap(map) {
3529
3530
  if (!map) return [];
3530
3531
  return Array.isArray(map) ? map : [map];
3531
3532
  }
3533
+ const plugin = VuePluginHiprint;
3534
+ const hiprint = plugin.hiprint ?? ((_a = plugin.default) == null ? void 0 : _a.hiprint);
3535
+ const defaultElementTypeProvider = plugin.defaultElementTypeProvider ?? ((_b = plugin.default) == null ? void 0 : _b.defaultElementTypeProvider);
3536
+ const autoConnect = plugin.autoConnect ?? ((_c = plugin.default) == null ? void 0 : _c.autoConnect);
3537
+ const disAutoConnect = plugin.disAutoConnect ?? ((_d = plugin.default) == null ? void 0 : _d.disAutoConnect);
3532
3538
  let initialized = false;
3533
3539
  function initHiprint(options = {}) {
3534
- var _a;
3540
+ var _a2;
3535
3541
  const providers = ensureProviders(options.providers);
3536
3542
  if (!initialized) {
3537
3543
  try {
@@ -3544,12 +3550,12 @@ function initHiprint(options = {}) {
3544
3550
  console.error("[vue3-print-designer] hiprint.init failed", e);
3545
3551
  }
3546
3552
  initialized = true;
3547
- } else if ((_a = options.providers) == null ? void 0 : _a.length) {
3553
+ } else if ((_a2 = options.providers) == null ? void 0 : _a2.length) {
3548
3554
  try {
3549
3555
  options.providers.forEach(
3550
3556
  (p) => {
3551
- var _a2, _b;
3552
- return (_b = (_a2 = hiprint.PrintElementTypeManager) == null ? void 0 : _a2.build) == null ? void 0 : _b.call(_a2, [p]);
3557
+ var _a3, _b2;
3558
+ return (_b2 = (_a3 = hiprint.PrintElementTypeManager) == null ? void 0 : _a3.build) == null ? void 0 : _b2.call(_a3, [p]);
3553
3559
  }
3554
3560
  );
3555
3561
  } catch (e) {
@@ -3583,6 +3589,467 @@ function buildByHtml(selectors) {
3583
3589
  }
3584
3590
  });
3585
3591
  }
3592
+ function normalizePrinterList(raw) {
3593
+ if (!Array.isArray(raw)) return [];
3594
+ return raw.map((item) => {
3595
+ if (typeof item === "string") {
3596
+ return { name: item, displayName: item };
3597
+ }
3598
+ if (!item || typeof item !== "object") return null;
3599
+ const record = item;
3600
+ const name = String(record.name ?? record.Name ?? "");
3601
+ if (!name) return null;
3602
+ return {
3603
+ ...record,
3604
+ name,
3605
+ displayName: String(record.displayName ?? record.DisplayName ?? name),
3606
+ isDefault: Boolean(record.isDefault ?? record.IsDefault ?? record.default)
3607
+ };
3608
+ }).filter((item) => item != null);
3609
+ }
3610
+ function normalizeClientList(raw) {
3611
+ if (!Array.isArray(raw)) return [];
3612
+ return raw.filter((item) => item && typeof item === "object");
3613
+ }
3614
+ function buildPrint2Payload(options) {
3615
+ if (!options) {
3616
+ return { printer: "", title: "print" };
3617
+ }
3618
+ const {
3619
+ printer,
3620
+ title,
3621
+ client,
3622
+ printByFragments,
3623
+ generateHTMLInterval,
3624
+ fragmentSize,
3625
+ sendInterval,
3626
+ ...rest
3627
+ } = options;
3628
+ return {
3629
+ printer: printer ?? "",
3630
+ title: title ?? "print",
3631
+ ...client != null ? { client } : {},
3632
+ ...printByFragments != null ? { printByFragments } : {},
3633
+ ...generateHTMLInterval != null ? { generateHTMLInterval } : {},
3634
+ ...fragmentSize != null ? { fragmentSize } : {},
3635
+ ...sendInterval != null ? { sendInterval } : {},
3636
+ ...rest
3637
+ };
3638
+ }
3639
+ function readSocketConnected() {
3640
+ try {
3641
+ const ws = hiprint.hiwebSocket;
3642
+ if (!ws) return false;
3643
+ if (ws.opened === true || ws.connected === true) return true;
3644
+ if (typeof ws.isConnected === "function" && ws.isConnected()) return true;
3645
+ return false;
3646
+ } catch {
3647
+ return false;
3648
+ }
3649
+ }
3650
+ const _PrintClient = class _PrintClient {
3651
+ constructor() {
3652
+ this.status = { connected: false };
3653
+ this.initConfig = {};
3654
+ this.connectPromise = null;
3655
+ this.connectionCallbacks = /* @__PURE__ */ new Set();
3656
+ this.printSuccessCallbacks = /* @__PURE__ */ new Set();
3657
+ this.printErrorCallbacks = /* @__PURE__ */ new Set();
3658
+ }
3659
+ static getInstance() {
3660
+ if (!_PrintClient.instance) _PrintClient.instance = new _PrintClient();
3661
+ return _PrintClient.instance;
3662
+ }
3663
+ connect(options = {}) {
3664
+ if (typeof window === "undefined") {
3665
+ const status = { connected: false, message: "PrintClient requires a browser environment." };
3666
+ this.updateStatus(status);
3667
+ return Promise.resolve(status);
3668
+ }
3669
+ if (this.getStatus().connected) {
3670
+ return Promise.resolve(this.getStatus());
3671
+ }
3672
+ if (this.connectPromise) return this.connectPromise;
3673
+ this.connectPromise = new Promise((resolve) => {
3674
+ var _a2;
3675
+ const timeoutMs = options.timeout ?? 1e4;
3676
+ let settled = false;
3677
+ const finish = (status) => {
3678
+ if (settled) return;
3679
+ settled = true;
3680
+ window.clearTimeout(timer);
3681
+ this.connectPromise = null;
3682
+ this.updateStatus(status);
3683
+ resolve(status);
3684
+ };
3685
+ const timer = window.setTimeout(() => {
3686
+ finish({
3687
+ connected: false,
3688
+ message: "Connection timeout. Is electron-hiprint running?"
3689
+ });
3690
+ }, timeoutMs);
3691
+ const config = { ...this.initConfig };
3692
+ if (options.host) config.host = options.host;
3693
+ if (options.token) config.token = options.token;
3694
+ this.initConfig = config;
3695
+ initHiprint({
3696
+ providers: ensureProviders(),
3697
+ autoConnect: false,
3698
+ config
3699
+ });
3700
+ try {
3701
+ if (options.host && typeof ((_a2 = hiprint.hiwebSocket) == null ? void 0 : _a2.setHost) === "function") {
3702
+ hiprint.hiwebSocket.setHost(options.host, options.token);
3703
+ }
3704
+ } catch (e) {
3705
+ console.warn("[print-designer] hiwebSocket.setHost failed", e);
3706
+ }
3707
+ try {
3708
+ autoConnect((status, msg) => {
3709
+ const message = typeof msg === "string" ? msg : msg != null ? String(msg) : status ? void 0 : "Failed to connect to print client.";
3710
+ finish({ connected: !!status, message });
3711
+ });
3712
+ } catch (e) {
3713
+ finish({
3714
+ connected: false,
3715
+ message: e instanceof Error ? e.message : String(e)
3716
+ });
3717
+ }
3718
+ });
3719
+ return this.connectPromise;
3720
+ }
3721
+ disconnect() {
3722
+ try {
3723
+ disAutoConnect();
3724
+ } catch {
3725
+ }
3726
+ this.connectPromise = null;
3727
+ this.updateStatus({ connected: false, message: "Disconnected." });
3728
+ }
3729
+ getStatus() {
3730
+ const socketConnected = readSocketConnected();
3731
+ if (socketConnected && !this.status.connected) {
3732
+ this.status = { connected: true };
3733
+ }
3734
+ if (!socketConnected && this.status.connected) {
3735
+ this.status = { connected: false, message: this.status.message ?? "Disconnected." };
3736
+ }
3737
+ return { ...this.status };
3738
+ }
3739
+ getPrinterList() {
3740
+ var _a2, _b2;
3741
+ try {
3742
+ const list = (_b2 = (_a2 = hiprint.hiwebSocket) == null ? void 0 : _a2.getPrinterList) == null ? void 0 : _b2.call(_a2);
3743
+ return normalizePrinterList(list);
3744
+ } catch {
3745
+ return [];
3746
+ }
3747
+ }
3748
+ getClients() {
3749
+ try {
3750
+ const ws = hiprint.hiwebSocket;
3751
+ if (!ws) return [];
3752
+ if (Array.isArray(ws.clients)) return normalizeClientList(ws.clients);
3753
+ if (typeof ws.getClients === "function") {
3754
+ return normalizeClientList(ws.getClients());
3755
+ }
3756
+ return [];
3757
+ } catch {
3758
+ return [];
3759
+ }
3760
+ }
3761
+ async printByTemplate(template, printData, options) {
3762
+ initHiprint({
3763
+ providers: ensureProviders(),
3764
+ autoConnect: false,
3765
+ config: this.initConfig
3766
+ });
3767
+ const instance = new hiprint.PrintTemplate({ template });
3768
+ return this.printByInstance(instance, printData, options);
3769
+ }
3770
+ async printByInstance(printTemplate, printData, options) {
3771
+ if (!this.getStatus().connected) {
3772
+ throw new Error("[print-designer] Print client is not connected. Call connect() first.");
3773
+ }
3774
+ if (typeof (printTemplate == null ? void 0 : printTemplate.print2) !== "function") {
3775
+ throw new Error("[print-designer] print2 is not available on the template instance.");
3776
+ }
3777
+ return new Promise((resolve, reject) => {
3778
+ var _a2, _b2;
3779
+ const onSuccess = (data2) => {
3780
+ cleanup();
3781
+ this.notifyPrintSuccess(data2);
3782
+ resolve();
3783
+ };
3784
+ const onError = (data2) => {
3785
+ cleanup();
3786
+ this.notifyPrintError(data2);
3787
+ reject(data2 instanceof Error ? data2 : new Error(String(data2 ?? "Print failed")));
3788
+ };
3789
+ const cleanup = () => {
3790
+ var _a3, _b3;
3791
+ try {
3792
+ (_a3 = printTemplate.off) == null ? void 0 : _a3.call(printTemplate, "printSuccess", onSuccess);
3793
+ } catch {
3794
+ }
3795
+ try {
3796
+ (_b3 = printTemplate.off) == null ? void 0 : _b3.call(printTemplate, "printError", onError);
3797
+ } catch {
3798
+ }
3799
+ };
3800
+ try {
3801
+ (_a2 = printTemplate.on) == null ? void 0 : _a2.call(printTemplate, "printSuccess", onSuccess);
3802
+ (_b2 = printTemplate.on) == null ? void 0 : _b2.call(printTemplate, "printError", onError);
3803
+ printTemplate.print2(printData, buildPrint2Payload(options));
3804
+ } catch (e) {
3805
+ cleanup();
3806
+ reject(e);
3807
+ }
3808
+ });
3809
+ }
3810
+ onConnectionChange(callback2) {
3811
+ this.connectionCallbacks.add(callback2);
3812
+ return () => {
3813
+ this.connectionCallbacks.delete(callback2);
3814
+ };
3815
+ }
3816
+ onPrintSuccess(callback2) {
3817
+ this.printSuccessCallbacks.add(callback2);
3818
+ return () => {
3819
+ this.printSuccessCallbacks.delete(callback2);
3820
+ };
3821
+ }
3822
+ onPrintError(callback2) {
3823
+ this.printErrorCallbacks.add(callback2);
3824
+ return () => {
3825
+ this.printErrorCallbacks.delete(callback2);
3826
+ };
3827
+ }
3828
+ updateStatus(status) {
3829
+ this.status = status;
3830
+ this.notifyConnectionChange(status);
3831
+ }
3832
+ notifyConnectionChange(status) {
3833
+ this.connectionCallbacks.forEach((cb) => {
3834
+ try {
3835
+ cb(status);
3836
+ } catch (e) {
3837
+ console.error("[print-designer] connection listener failed", e);
3838
+ }
3839
+ });
3840
+ }
3841
+ notifyPrintSuccess(data2) {
3842
+ this.printSuccessCallbacks.forEach((cb) => {
3843
+ try {
3844
+ cb(data2);
3845
+ } catch (e) {
3846
+ console.error("[print-designer] printSuccess listener failed", e);
3847
+ }
3848
+ });
3849
+ }
3850
+ notifyPrintError(data2) {
3851
+ this.printErrorCallbacks.forEach((cb) => {
3852
+ try {
3853
+ cb(data2);
3854
+ } catch (e) {
3855
+ console.error("[print-designer] printError listener failed", e);
3856
+ }
3857
+ });
3858
+ }
3859
+ };
3860
+ _PrintClient.instance = null;
3861
+ let PrintClient = _PrintClient;
3862
+ function getPrintClient() {
3863
+ return PrintClient.getInstance();
3864
+ }
3865
+ function resolvePreviewHtml(value) {
3866
+ if (value == null || value === false) return "";
3867
+ if (typeof value === "string") return value;
3868
+ const any = value;
3869
+ if (typeof any.html === "function") {
3870
+ try {
3871
+ const html = any.html();
3872
+ if (typeof html === "string") return html;
3873
+ } catch {
3874
+ }
3875
+ }
3876
+ if (Array.isArray(value)) {
3877
+ return value.map((item) => resolvePreviewHtml(item)).join("");
3878
+ }
3879
+ if (typeof any.length === "number" && any.length > 0 && any[0] != null) {
3880
+ return resolvePreviewHtml(any[0]);
3881
+ }
3882
+ if (any.target != null) {
3883
+ return resolvePreviewHtml(any.target);
3884
+ }
3885
+ return "";
3886
+ }
3887
+ function collectHostStyles() {
3888
+ if (typeof document === "undefined") return "";
3889
+ const parts = [];
3890
+ document.querySelectorAll('link[rel="stylesheet"]').forEach((el) => {
3891
+ const href = el.getAttribute("href");
3892
+ if (!href) return;
3893
+ const media = el.getAttribute("media");
3894
+ const mediaAttr = media ? ` media="${media}"` : "";
3895
+ parts.push(`<link rel="stylesheet" href="${href}"${mediaAttr}>`);
3896
+ if (media && /print/i.test(media) && href.includes("print-lock.css")) {
3897
+ parts.push(`<link rel="stylesheet" href="${href}">`);
3898
+ }
3899
+ });
3900
+ document.querySelectorAll("style").forEach((el) => {
3901
+ parts.push(`<style>${el.textContent ?? ""}</style>`);
3902
+ });
3903
+ return parts.join("\n");
3904
+ }
3905
+ function buildIframeDocument(args) {
3906
+ const handlerStyles = args.styleHandler ? args.styleHandler() : "";
3907
+ const hostStyles = args.importCss ? collectHostStyles() : "";
3908
+ return `<!DOCTYPE html>
3909
+ <html>
3910
+ <head>
3911
+ <meta charset="UTF-8">
3912
+ <title>${args.title}</title>
3913
+ ${hostStyles}
3914
+ ${handlerStyles}
3915
+ </head>
3916
+ <body>${args.html}</body>
3917
+ </html>`;
3918
+ }
3919
+ function printIframe(args) {
3920
+ if (typeof document === "undefined" || typeof window === "undefined") {
3921
+ return Promise.resolve();
3922
+ }
3923
+ const previous = document.getElementById("svp_batch_print_iframe");
3924
+ if (previous == null ? void 0 : previous.parentNode) previous.parentNode.removeChild(previous);
3925
+ const iframe = document.createElement("iframe");
3926
+ iframe.id = "svp_batch_print_iframe";
3927
+ iframe.setAttribute(
3928
+ "style",
3929
+ "visibility: hidden; height: 0; width: 0; position: absolute; border: 0;"
3930
+ );
3931
+ document.body.appendChild(iframe);
3932
+ const cleanup = () => {
3933
+ try {
3934
+ if (iframe.parentNode) iframe.parentNode.removeChild(iframe);
3935
+ } catch {
3936
+ }
3937
+ };
3938
+ return new Promise((resolve) => {
3939
+ let triggered = false;
3940
+ const trigger = () => {
3941
+ if (triggered) return;
3942
+ triggered = true;
3943
+ try {
3944
+ const win = iframe.contentWindow;
3945
+ if (!win) {
3946
+ cleanup();
3947
+ resolve();
3948
+ return;
3949
+ }
3950
+ const finish = () => {
3951
+ var _a2;
3952
+ (_a2 = args.callback) == null ? void 0 : _a2.call(args);
3953
+ setTimeout(() => {
3954
+ cleanup();
3955
+ resolve();
3956
+ }, 500);
3957
+ };
3958
+ const onAfterPrint = () => {
3959
+ win.removeEventListener("afterprint", onAfterPrint);
3960
+ finish();
3961
+ };
3962
+ win.addEventListener("afterprint", onAfterPrint);
3963
+ try {
3964
+ win.focus();
3965
+ win.print();
3966
+ } catch (e) {
3967
+ console.error("[batch-print] window.print failed", e);
3968
+ finish();
3969
+ }
3970
+ setTimeout(finish, 6e4);
3971
+ } catch (e) {
3972
+ console.error("[batch-print] trigger failed", e);
3973
+ cleanup();
3974
+ resolve();
3975
+ }
3976
+ };
3977
+ iframe.onload = () => {
3978
+ waitForImages(iframe.contentDocument, trigger);
3979
+ };
3980
+ setTimeout(() => {
3981
+ if (!triggered) trigger();
3982
+ }, args.timeout);
3983
+ const doc = iframe.contentDocument;
3984
+ const docString = buildIframeDocument(args);
3985
+ if (doc) {
3986
+ doc.open();
3987
+ doc.write(docString);
3988
+ doc.close();
3989
+ } else {
3990
+ iframe.srcdoc = docString;
3991
+ }
3992
+ });
3993
+ }
3994
+ function waitForImages(doc, done, attempt = 0) {
3995
+ if (!doc) {
3996
+ done();
3997
+ return;
3998
+ }
3999
+ const imgs = doc.getElementsByTagName("img");
4000
+ let ready = true;
4001
+ for (let i = 0; i < imgs.length; i++) {
4002
+ const img = imgs[i];
4003
+ if (!img.src || img.src.indexOf("base64") >= 0) continue;
4004
+ if (img.complete && (img.naturalWidth ?? 1) > 0) continue;
4005
+ ready = false;
4006
+ break;
4007
+ }
4008
+ if (ready || attempt >= 10) {
4009
+ done();
4010
+ return;
4011
+ }
4012
+ setTimeout(() => waitForImages(doc, done, attempt + 1), 500);
4013
+ }
4014
+ function pageWrap(html, withBreak) {
4015
+ const breakStyle = withBreak ? ' style="page-break-after: always; break-after: page;"' : "";
4016
+ return `<div class="svp-batch-page"${breakStyle}>${html}</div>`;
4017
+ }
4018
+ async function batchPrint(printTemplate, printDataList, options = {}) {
4019
+ if (!printTemplate || typeof printTemplate.getHtml !== "function") {
4020
+ throw new Error("[batch-print] printTemplate.getHtml is required.");
4021
+ }
4022
+ const list = Array.isArray(printDataList) ? printDataList : [printDataList];
4023
+ if (!list.length) {
4024
+ throw new Error("[batch-print] printDataList is empty.");
4025
+ }
4026
+ const copies = Math.max(1, Math.floor(options.copies ?? 1));
4027
+ const pageBreak = options.pageBreak !== false;
4028
+ const title = options.title ?? "print";
4029
+ const expanded = [];
4030
+ for (const item of list) {
4031
+ for (let i = 0; i < copies; i++) expanded.push(item);
4032
+ }
4033
+ const fragments = [];
4034
+ for (let i = 0; i < expanded.length; i++) {
4035
+ const raw = printTemplate.getHtml(expanded[i]);
4036
+ const html = resolvePreviewHtml(raw);
4037
+ if (!html) continue;
4038
+ const isLast = i === expanded.length - 1;
4039
+ fragments.push(pageWrap(html, pageBreak && !isLast));
4040
+ }
4041
+ if (!fragments.length) {
4042
+ throw new Error("[batch-print] No HTML produced from print data.");
4043
+ }
4044
+ await printIframe({
4045
+ html: fragments.join("\n"),
4046
+ title,
4047
+ styleHandler: options.styleHandler,
4048
+ importCss: options.importCss !== false,
4049
+ callback: options.callback,
4050
+ timeout: Math.max(500, options.timeout ?? 1500)
4051
+ });
4052
+ }
3586
4053
  class PluginManager {
3587
4054
  constructor() {
3588
4055
  this.hooks = /* @__PURE__ */ new Map();
@@ -3593,12 +4060,12 @@ class PluginManager {
3593
4060
  this.plugins = [];
3594
4061
  plugins.forEach((p) => this.register(p));
3595
4062
  }
3596
- register(plugin) {
3597
- var _a;
3598
- if (!plugin || !Array.isArray(plugin.hooks)) return;
3599
- this.plugins.push(plugin);
3600
- (_a = plugin.init) == null ? void 0 : _a.call(plugin, plugin.config ?? {});
3601
- plugin.hooks.forEach((h) => {
4063
+ register(plugin2) {
4064
+ var _a2;
4065
+ if (!plugin2 || !Array.isArray(plugin2.hooks)) return;
4066
+ this.plugins.push(plugin2);
4067
+ (_a2 = plugin2.init) == null ? void 0 : _a2.call(plugin2, plugin2.config ?? {});
4068
+ plugin2.hooks.forEach((h) => {
3602
4069
  const arr = this.hooks.get(h.hook) ?? [];
3603
4070
  arr.push(h);
3604
4071
  arr.sort((a, b) => (a.priority ?? 100) - (b.priority ?? 100));
@@ -3609,8 +4076,8 @@ class PluginManager {
3609
4076
  return this.plugins.slice();
3610
4077
  }
3611
4078
  has(hook) {
3612
- var _a;
3613
- return (((_a = this.hooks.get(hook)) == null ? void 0 : _a.length) ?? 0) > 0;
4079
+ var _a2;
4080
+ return (((_a2 = this.hooks.get(hook)) == null ? void 0 : _a2.length) ?? 0) > 0;
3614
4081
  }
3615
4082
  /** Run all callbacks sequentially. Returns the array of results. */
3616
4083
  async run(hook, ...args) {
@@ -3735,9 +4202,9 @@ class HistoryController {
3735
4202
  this.onChanged = onChanged;
3736
4203
  }
3737
4204
  applySnapshot(tpl, json, panelIndex) {
3738
- var _a, _b, _c;
4205
+ var _a2, _b2, _c2;
3739
4206
  if (!(tpl == null ? void 0 : tpl.update) || json == null) return;
3740
- const index2 = panelIndex ?? ((_a = tpl.editingPanel) == null ? void 0 : _a.index) ?? ((_c = (_b = tpl.printPanels) == null ? void 0 : _b[0]) == null ? void 0 : _c.index) ?? 0;
4207
+ const index2 = panelIndex ?? ((_a2 = tpl.editingPanel) == null ? void 0 : _a2.index) ?? ((_c2 = (_b2 = tpl.printPanels) == null ? void 0 : _b2[0]) == null ? void 0 : _c2.index) ?? 0;
3741
4208
  tpl.update(json, index2);
3742
4209
  }
3743
4210
  refreshFromTemplate() {
@@ -3792,9 +4259,9 @@ class HistoryController {
3792
4259
  this.finishChange();
3793
4260
  }
3794
4261
  jump(index2) {
3795
- var _a;
4262
+ var _a2;
3796
4263
  const tpl = this.getTpl();
3797
- if (!(tpl == null ? void 0 : tpl.history) || !((_a = tpl.historyList) == null ? void 0 : _a[index2])) return;
4264
+ if (!(tpl == null ? void 0 : tpl.history) || !((_a2 = tpl.historyList) == null ? void 0 : _a2[index2])) return;
3798
4265
  tpl.historyPos = index2;
3799
4266
  const entry = tpl.historyList[index2];
3800
4267
  this.applySnapshot(tpl, entry == null ? void 0 : entry.json);
@@ -3827,9 +4294,9 @@ class HistoryController {
3827
4294
  this.finishChange();
3828
4295
  }
3829
4296
  finishChange() {
3830
- var _a;
4297
+ var _a2;
3831
4298
  this.refreshFromTemplate();
3832
- (_a = this.onChanged) == null ? void 0 : _a.call(this);
4299
+ (_a2 = this.onChanged) == null ? void 0 : _a2.call(this);
3833
4300
  }
3834
4301
  }
3835
4302
  function normalize(e) {
@@ -3860,8 +4327,8 @@ class ShortcutsController {
3860
4327
  mount() {
3861
4328
  if (typeof window === "undefined" || this.handler) return;
3862
4329
  this.handler = (e) => {
3863
- var _a, _b;
3864
- if (((_b = (_a = this.options).beforeDispatch) == null ? void 0 : _b.call(_a, e)) === false) return;
4330
+ var _a2, _b2;
4331
+ if (((_b2 = (_a2 = this.options).beforeDispatch) == null ? void 0 : _b2.call(_a2, e)) === false) return;
3865
4332
  const t = e.target;
3866
4333
  if (t && (t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.isContentEditable)) {
3867
4334
  const combo2 = normalize(e);
@@ -4011,7 +4478,7 @@ function openJsonEditorModal(options) {
4011
4478
  });
4012
4479
  ta.addEventListener("scroll", syncScroll);
4013
4480
  modal.addEventListener("click", (e) => {
4014
- var _a;
4481
+ var _a2;
4015
4482
  const act = e.target.dataset.act;
4016
4483
  if (act === "cancel") close(null);
4017
4484
  else if (act === "clear") {
@@ -4020,7 +4487,7 @@ function openJsonEditorModal(options) {
4020
4487
  syncLines();
4021
4488
  ta.focus();
4022
4489
  } else if (act === "copy") {
4023
- (_a = navigator.clipboard) == null ? void 0 : _a.writeText(ta.value).catch(() => {
4490
+ (_a2 = navigator.clipboard) == null ? void 0 : _a2.writeText(ta.value).catch(() => {
4024
4491
  ta.focus();
4025
4492
  ta.select();
4026
4493
  try {
@@ -4214,7 +4681,19 @@ const zhCN = {
4214
4681
  printDataAddRow: "添加一行",
4215
4682
  printDataDeleteRow: "删除",
4216
4683
  printDataFieldKey: "字段",
4217
- paper: "纸张"
4684
+ paper: "纸张",
4685
+ browserPrint: "浏览器打印",
4686
+ silentPrint: "静默打印",
4687
+ batchPrint: "批量打印",
4688
+ batchPrinting: "正在准备…",
4689
+ batchCopies: "每条份数",
4690
+ batchHint: "共 {rows} 条数据 × 每条份数 = 合计 {total} 页(无需客户端)",
4691
+ printClientConnected: "打印客户端已连接",
4692
+ printClientDisconnected: "打印客户端未连接",
4693
+ printClientConnect: "连接客户端",
4694
+ printClientDisconnect: "断开连接",
4695
+ printClientNoPrinters: "未检测到打印机",
4696
+ defaultPrinter: "默认"
4218
4697
  },
4219
4698
  header: {
4220
4699
  title: "打印设计器"
@@ -4317,7 +4796,19 @@ const enUS = {
4317
4796
  printDataAddRow: "Add row",
4318
4797
  printDataDeleteRow: "Delete",
4319
4798
  printDataFieldKey: "Field",
4320
- paper: "Paper"
4799
+ paper: "Paper",
4800
+ browserPrint: "Browser Print",
4801
+ silentPrint: "Silent Print",
4802
+ batchPrint: "Batch Print",
4803
+ batchPrinting: "Preparing…",
4804
+ batchCopies: "Copies per record",
4805
+ batchHint: "{rows} records × copies = {total} pages (no client required)",
4806
+ printClientConnected: "Print client connected",
4807
+ printClientDisconnected: "Print client disconnected",
4808
+ printClientConnect: "Connect Client",
4809
+ printClientDisconnect: "Disconnect",
4810
+ printClientNoPrinters: "No printers found",
4811
+ defaultPrinter: "Default"
4321
4812
  },
4322
4813
  header: {
4323
4814
  title: "Print Designer"
@@ -4555,8 +5046,21 @@ const _DesignerUtils = class _DesignerUtils {
4555
5046
  setConfig(config) {
4556
5047
  if (config) Object.assign(this.options, { config });
4557
5048
  }
4558
- setConnect(connect, _callback) {
5049
+ setConnect(connect, callback2) {
5050
+ var _a2, _b2;
4559
5051
  this.options.connect = connect;
5052
+ const client = getPrintClient();
5053
+ if (connect) {
5054
+ void client.connect({
5055
+ host: (_a2 = this.options.config) == null ? void 0 : _a2.host,
5056
+ token: (_b2 = this.options.config) == null ? void 0 : _b2.token
5057
+ }).then((status) => {
5058
+ callback2 == null ? void 0 : callback2(status.connected, status.message);
5059
+ });
5060
+ return;
5061
+ }
5062
+ client.disconnect();
5063
+ callback2 == null ? void 0 : callback2(false);
4560
5064
  }
4561
5065
  initProviders(providers) {
4562
5066
  initHiprint({
@@ -4565,9 +5069,9 @@ const _DesignerUtils = class _DesignerUtils {
4565
5069
  config: this.options.config,
4566
5070
  paperList: this.options.paperList,
4567
5071
  onPaperApplied: () => {
4568
- var _a, _b;
5072
+ var _a2, _b2;
4569
5073
  try {
4570
- (_b = (_a = this.ruler) == null ? void 0 : _a.redraw) == null ? void 0 : _b.call(_a);
5074
+ (_b2 = (_a2 = this.ruler) == null ? void 0 : _a2.redraw) == null ? void 0 : _b2.call(_a2);
4571
5075
  } catch {
4572
5076
  }
4573
5077
  }
@@ -4599,12 +5103,12 @@ const _DesignerUtils = class _DesignerUtils {
4599
5103
  return tpl;
4600
5104
  }
4601
5105
  newDesigner(options, designOptions = {}) {
4602
- var _a, _b;
5106
+ var _a2, _b2;
4603
5107
  if (this.printTemplate) {
4604
5108
  this.unbindSelectionEvents();
4605
5109
  this.unbindZoomEvents();
4606
5110
  try {
4607
- (_b = (_a = this.printTemplate).clear) == null ? void 0 : _b.call(_a);
5111
+ (_b2 = (_a2 = this.printTemplate).clear) == null ? void 0 : _b2.call(_a2);
4608
5112
  } catch (_) {
4609
5113
  }
4610
5114
  }
@@ -4616,19 +5120,19 @@ const _DesignerUtils = class _DesignerUtils {
4616
5120
  history: options.history ?? true,
4617
5121
  onImageChooseClick: options.onImageChooseClick,
4618
5122
  onZoomChange: (scale) => {
4619
- var _a2;
5123
+ var _a3;
4620
5124
  setZoom(scale);
4621
- (_a2 = options.onZoomChange) == null ? void 0 : _a2.call(options, scale);
5125
+ (_a3 = options.onZoomChange) == null ? void 0 : _a3.call(options, scale);
4622
5126
  },
4623
5127
  onPanelAddClick: options.onPanelAddClick,
4624
5128
  onFunctionClick: options.onFunctionClick,
4625
5129
  onDataChanged: (type, json) => {
4626
- var _a2;
5130
+ var _a3;
4627
5131
  this.history.refreshFromTemplate();
4628
5132
  this.refreshSelection();
4629
5133
  this.reapplyElementTransforms();
4630
5134
  designerStore.uiPulse += 1;
4631
- (_a2 = options.onDataChanged) == null ? void 0 : _a2.call(options, type, json);
5135
+ (_a3 = options.onDataChanged) == null ? void 0 : _a3.call(options, type, json);
4632
5136
  },
4633
5137
  onUpdateError: options.onUpdateError
4634
5138
  });
@@ -4661,28 +5165,28 @@ const _DesignerUtils = class _DesignerUtils {
4661
5165
  return tpl;
4662
5166
  }
4663
5167
  unbindSelectionEvents() {
4664
- var _a;
4665
- (_a = this.selectionEventCleanup) == null ? void 0 : _a.call(this);
5168
+ var _a2;
5169
+ (_a2 = this.selectionEventCleanup) == null ? void 0 : _a2.call(this);
4666
5170
  this.selectionEventCleanup = null;
4667
5171
  }
4668
5172
  unbindZoomEvents() {
4669
- var _a;
4670
- (_a = this.zoomEventCleanup) == null ? void 0 : _a.call(this);
5173
+ var _a2;
5174
+ (_a2 = this.zoomEventCleanup) == null ? void 0 : _a2.call(this);
4671
5175
  this.zoomEventCleanup = null;
4672
5176
  }
4673
5177
  /** Keep store/ruler in sync when hiprint paper scale changes (e.g. zoom toolbar). */
4674
5178
  bindZoomEvents(tpl) {
4675
- var _a;
5179
+ var _a2;
4676
5180
  this.unbindZoomEvents();
4677
- const paper = (_a = tpl == null ? void 0 : tpl.editingPanel) == null ? void 0 : _a.designPaper;
5181
+ const paper = (_a2 = tpl == null ? void 0 : tpl.editingPanel) == null ? void 0 : _a2.designPaper;
4678
5182
  if (!(paper == null ? void 0 : paper.subscribePaperBaseInfoChanged)) return;
4679
5183
  const onPaperInfo = (info) => {
4680
- var _a2, _b;
5184
+ var _a3, _b2;
4681
5185
  if (typeof (info == null ? void 0 : info.scale) !== "number" || !(info.scale > 0)) return;
4682
5186
  const next = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, info.scale));
4683
5187
  if (Math.abs(next - this.state.zoom) < 1e-3) return;
4684
5188
  setZoom(next);
4685
- (_b = (_a2 = this.ruler) == null ? void 0 : _a2.redraw) == null ? void 0 : _b.call(_a2);
5189
+ (_b2 = (_a3 = this.ruler) == null ? void 0 : _a3.redraw) == null ? void 0 : _b2.call(_a3);
4686
5190
  };
4687
5191
  paper.subscribePaperBaseInfoChanged(onPaperInfo);
4688
5192
  this.zoomEventCleanup = () => {
@@ -4693,23 +5197,23 @@ const _DesignerUtils = class _DesignerUtils {
4693
5197
  };
4694
5198
  }
4695
5199
  syncZoomFromTemplate() {
4696
- var _a, _b;
5200
+ var _a2, _b2;
4697
5201
  setZoom(this.getZoom());
4698
- (_b = (_a = this.ruler) == null ? void 0 : _a.redraw) == null ? void 0 : _b.call(_a);
5202
+ (_b2 = (_a2 = this.ruler) == null ? void 0 : _a2.redraw) == null ? void 0 : _b2.call(_a2);
4699
5203
  }
4700
5204
  readTemplateScale() {
4701
- var _a, _b, _c;
5205
+ var _a2, _b2, _c2;
4702
5206
  const tpl = this.printTemplate;
4703
5207
  if (!tpl) return null;
4704
- const scale = ((_b = (_a = tpl.editingPanel) == null ? void 0 : _a.designPaper) == null ? void 0 : _b.scale) ?? ((_c = tpl.editingPanel) == null ? void 0 : _c.scale) ?? tpl.scale;
5208
+ const scale = ((_b2 = (_a2 = tpl.editingPanel) == null ? void 0 : _a2.designPaper) == null ? void 0 : _b2.scale) ?? ((_c2 = tpl.editingPanel) == null ? void 0 : _c2.scale) ?? tpl.scale;
4705
5209
  return typeof scale === "number" && scale > 0 ? scale : null;
4706
5210
  }
4707
5211
  /** Sync Vue selection state when hiprint selects / deselects print elements. */
4708
5212
  bindSelectionEvents(tpl) {
4709
- var _a;
5213
+ var _a2;
4710
5214
  this.unbindSelectionEvents();
4711
5215
  if (typeof window === "undefined" || !tpl) return;
4712
- const eventBus = (_a = window.hinnn) == null ? void 0 : _a.event;
5216
+ const eventBus = (_a2 = window.hinnn) == null ? void 0 : _a2.event;
4713
5217
  const tplId = tpl.id ?? tpl.templateId;
4714
5218
  if (!eventBus || tplId == null) return;
4715
5219
  const selectKey = `PrintElementSelectEventKey_${tplId}`;
@@ -4751,9 +5255,9 @@ const _DesignerUtils = class _DesignerUtils {
4751
5255
  };
4752
5256
  }
4753
5257
  refreshPrintTemplate() {
4754
- var _a, _b;
5258
+ var _a2, _b2;
4755
5259
  try {
4756
- (_b = (_a = this.printTemplate) == null ? void 0 : _a.refresh) == null ? void 0 : _b.call(_a);
5260
+ (_b2 = (_a2 = this.printTemplate) == null ? void 0 : _a2.refresh) == null ? void 0 : _b2.call(_a2);
4757
5261
  } catch (_) {
4758
5262
  }
4759
5263
  this.reapplyElementTransforms();
@@ -4800,7 +5304,7 @@ const _DesignerUtils = class _DesignerUtils {
4800
5304
  });
4801
5305
  }
4802
5306
  refreshSelection() {
4803
- var _a, _b, _c, _d;
5307
+ var _a2, _b2, _c2, _d2;
4804
5308
  const tpl = this.printTemplate;
4805
5309
  if (!tpl) {
4806
5310
  setSelection({ count: 0, ids: [], elements: [] });
@@ -4808,15 +5312,15 @@ const _DesignerUtils = class _DesignerUtils {
4808
5312
  }
4809
5313
  let els = [];
4810
5314
  try {
4811
- els = ((_a = tpl.getSelectEls) == null ? void 0 : _a.call(tpl)) ?? [];
5315
+ els = ((_a2 = tpl.getSelectEls) == null ? void 0 : _a2.call(tpl)) ?? [];
4812
5316
  } catch {
4813
5317
  }
4814
5318
  if (!els.length) {
4815
- els = ((_d = (_c = (_b = tpl.editingPanel) == null ? void 0 : _b.printElements) == null ? void 0 : _c.filter) == null ? void 0 : _d.call(_c, (e) => {
4816
- var _a2, _b2, _c2, _d2;
5319
+ els = ((_d2 = (_c2 = (_b2 = tpl.editingPanel) == null ? void 0 : _b2.printElements) == null ? void 0 : _c2.filter) == null ? void 0 : _d2.call(_c2, (e) => {
5320
+ var _a3, _b3, _c3, _d3;
4817
5321
  if (e == null ? void 0 : e.selected) return true;
4818
5322
  try {
4819
- return !!((_b2 = (_a2 = e == null ? void 0 : e.designTarget) == null ? void 0 : _a2.hasClass) == null ? void 0 : _b2.call(_a2, "hiprint-printElement-selected")) || !!((_d2 = (_c2 = e == null ? void 0 : e.designTarget) == null ? void 0 : _c2.hasClass) == null ? void 0 : _d2.call(_c2, "selected"));
5323
+ return !!((_b3 = (_a3 = e == null ? void 0 : e.designTarget) == null ? void 0 : _a3.hasClass) == null ? void 0 : _b3.call(_a3, "hiprint-printElement-selected")) || !!((_d3 = (_c3 = e == null ? void 0 : e.designTarget) == null ? void 0 : _c3.hasClass) == null ? void 0 : _d3.call(_c3, "selected"));
4820
5324
  } catch {
4821
5325
  return false;
4822
5326
  }
@@ -4830,25 +5334,25 @@ const _DesignerUtils = class _DesignerUtils {
4830
5334
  }
4831
5335
  /** Select a print element from auxiliary panels (page structure, etc.). */
4832
5336
  selectPrintElement(item) {
4833
- var _a, _b, _c, _d, _e, _f, _g;
5337
+ var _a2, _b2, _c2, _d2, _e, _f, _g;
4834
5338
  const tpl = this.printTemplate;
4835
5339
  if (!tpl || !item) return;
4836
5340
  const $ = typeof window !== "undefined" ? window.$ || window.jQuery : null;
4837
5341
  const dt = $ == null ? void 0 : $(item.designTarget);
4838
5342
  if ($ && (dt == null ? void 0 : dt.length)) {
4839
- (_b = (_a = tpl.editingPanel) == null ? void 0 : _a.printElements) == null ? void 0 : _b.forEach((el) => {
5343
+ (_b2 = (_a2 = tpl.editingPanel) == null ? void 0 : _a2.printElements) == null ? void 0 : _b2.forEach((el) => {
4840
5344
  if (el === item) return;
4841
5345
  const target = $(el.designTarget);
4842
5346
  if (!(target == null ? void 0 : target.length)) return;
4843
5347
  target.children("div[panelindex]").removeClass("selected").css({ display: "none" });
4844
5348
  });
4845
- const type = String(((_c = item.printElementType) == null ? void 0 : _c.type) || "");
5349
+ const type = String(((_c2 = item.printElementType) == null ? void 0 : _c2.type) || "");
4846
5350
  if (type.includes("table")) {
4847
5351
  dt.find("tr:first td:first").trigger("click");
4848
5352
  } else {
4849
5353
  dt.children("div[panelindex]").addClass("selected").css({ display: "block" });
4850
5354
  try {
4851
- (_f = (_e = (_d = dt.data("hidraggable")) == null ? void 0 : _d.options) == null ? void 0 : _e.onBeforeSelectAllDrag) == null ? void 0 : _f.call(dt[0], {});
5355
+ (_f = (_e = (_d2 = dt.data("hidraggable")) == null ? void 0 : _d2.options) == null ? void 0 : _e.onBeforeSelectAllDrag) == null ? void 0 : _f.call(dt[0], {});
4852
5356
  } catch {
4853
5357
  }
4854
5358
  }
@@ -4871,10 +5375,10 @@ const _DesignerUtils = class _DesignerUtils {
4871
5375
  const $ = typeof window !== "undefined" ? window.$ || window.jQuery : null;
4872
5376
  if (!$) return;
4873
5377
  items.forEach((item) => {
4874
- var _a, _b, _c, _d;
5378
+ var _a2, _b2, _c2, _d2;
4875
5379
  const dt = $(item.designTarget);
4876
5380
  if (!(dt == null ? void 0 : dt.length)) return;
4877
- const type = String(((_a = item.printElementType) == null ? void 0 : _a.type) || "");
5381
+ const type = String(((_a2 = item.printElementType) == null ? void 0 : _a2.type) || "");
4878
5382
  if (type.includes("table")) {
4879
5383
  dt.find("tr:first td:first").trigger("click");
4880
5384
  return;
@@ -4882,7 +5386,7 @@ const _DesignerUtils = class _DesignerUtils {
4882
5386
  dt.children("div[panelindex]").addClass("selected").css({ display: "block" });
4883
5387
  try {
4884
5388
  const dom = dt[0];
4885
- (_d = (_c = (_b = dt.data("hidraggable")) == null ? void 0 : _b.options) == null ? void 0 : _c.onBeforeSelectAllDrag) == null ? void 0 : _d.call(dom, {});
5389
+ (_d2 = (_c2 = (_b2 = dt.data("hidraggable")) == null ? void 0 : _b2.options) == null ? void 0 : _c2.onBeforeSelectAllDrag) == null ? void 0 : _d2.call(dom, {});
4886
5390
  } catch {
4887
5391
  }
4888
5392
  });
@@ -4896,9 +5400,9 @@ const _DesignerUtils = class _DesignerUtils {
4896
5400
  // Persistence / IO
4897
5401
  // -------------------------------------------------------------------------
4898
5402
  getTemplateJson() {
4899
- var _a, _b;
5403
+ var _a2, _b2;
4900
5404
  try {
4901
- return ((_b = (_a = this.printTemplate) == null ? void 0 : _a.getJson) == null ? void 0 : _b.call(_a)) ?? null;
5405
+ return ((_b2 = (_a2 = this.printTemplate) == null ? void 0 : _a2.getJson) == null ? void 0 : _b2.call(_a2)) ?? null;
4902
5406
  } catch {
4903
5407
  return null;
4904
5408
  }
@@ -4907,11 +5411,11 @@ const _DesignerUtils = class _DesignerUtils {
4907
5411
  return `tpl:${this.options.templateKey || "default"}`;
4908
5412
  }
4909
5413
  save() {
4910
- var _a, _b;
5414
+ var _a2, _b2;
4911
5415
  const json = this.getTemplateJson();
4912
5416
  if (!json) return;
4913
5417
  const key = this.options.templateKey || "default";
4914
- const blocked = ((_b = (_a = this.options.events) == null ? void 0 : _a.onSave) == null ? void 0 : _b.call(_a, key, json)) === false;
5418
+ const blocked = ((_b2 = (_a2 = this.options.events) == null ? void 0 : _a2.onSave) == null ? void 0 : _b2.call(_a2, key, json)) === false;
4915
5419
  if (blocked) return;
4916
5420
  writeJSON(this.templateStorageKey(), json);
4917
5421
  }
@@ -4924,9 +5428,9 @@ const _DesignerUtils = class _DesignerUtils {
4924
5428
  return openJsonEditorModal(options);
4925
5429
  }
4926
5430
  async edit() {
4927
- var _a, _b;
5431
+ var _a2, _b2;
4928
5432
  const json = this.getTemplateJson();
4929
- if (((_b = (_a = this.options.events) == null ? void 0 : _a.onEdit) == null ? void 0 : _b.call(_a, json)) === false) return;
5433
+ if (((_b2 = (_a2 = this.options.events) == null ? void 0 : _a2.onEdit) == null ? void 0 : _b2.call(_a2, json)) === false) return;
4930
5434
  try {
4931
5435
  const next = await this.openJsonEditor({
4932
5436
  title: translate("designer.editTemplate"),
@@ -4946,8 +5450,8 @@ const _DesignerUtils = class _DesignerUtils {
4946
5450
  }
4947
5451
  }
4948
5452
  async editData() {
4949
- var _a, _b, _c;
4950
- if (((_b = (_a = this.options.events) == null ? void 0 : _a.onEditData) == null ? void 0 : _b.call(_a, this.printData)) === false) return;
5453
+ var _a2, _b2, _c2;
5454
+ if (((_b2 = (_a2 = this.options.events) == null ? void 0 : _a2.onEditData) == null ? void 0 : _b2.call(_a2, this.printData)) === false) return;
4951
5455
  try {
4952
5456
  const schema = extractTemplateFields(this.getTemplateJson());
4953
5457
  const host = this.printDataEditor;
@@ -4972,7 +5476,7 @@ const _DesignerUtils = class _DesignerUtils {
4972
5476
  });
4973
5477
  if (next == null) return;
4974
5478
  this.setPrintData(next);
4975
- (_c = this.onPrintDataChange) == null ? void 0 : _c.call(this, next);
5479
+ (_c2 = this.onPrintDataChange) == null ? void 0 : _c2.call(this, next);
4976
5480
  } catch (e) {
4977
5481
  console.error("[vue3-print-designer] edit print data failed", e);
4978
5482
  }
@@ -4997,8 +5501,8 @@ const _DesignerUtils = class _DesignerUtils {
4997
5501
  input.type = "file";
4998
5502
  input.accept = ".json,application/json";
4999
5503
  input.onchange = () => {
5000
- var _a;
5001
- const file = (_a = input.files) == null ? void 0 : _a[0];
5504
+ var _a2;
5505
+ const file = (_a2 = input.files) == null ? void 0 : _a2[0];
5002
5506
  if (!file) return;
5003
5507
  const reader = new FileReader();
5004
5508
  reader.onload = () => {
@@ -5015,15 +5519,15 @@ const _DesignerUtils = class _DesignerUtils {
5015
5519
  }
5016
5520
  /** Import onto existing paper(s) without creating extra panels. */
5017
5521
  applyImportTemplateJson(json) {
5018
- var _a, _b, _c, _d, _e;
5522
+ var _a2, _b2, _c2, _d2, _e;
5019
5523
  const tpl = this.printTemplate;
5020
5524
  const currentJson = this.getTemplateJson();
5021
- if (!(tpl == null ? void 0 : tpl.update) || !((_a = currentJson == null ? void 0 : currentJson.panels) == null ? void 0 : _a.length)) {
5525
+ if (!(tpl == null ? void 0 : tpl.update) || !((_a2 = currentJson == null ? void 0 : currentJson.panels) == null ? void 0 : _a2.length)) {
5022
5526
  this.applyTemplateJson(json);
5023
5527
  return;
5024
5528
  }
5025
5529
  const merged = mergeImportOntoCurrentPanels(currentJson, json);
5026
- const activeIndex = ((_b = tpl.editingPanel) == null ? void 0 : _b.index) ?? ((_d = (_c = tpl.printPanels) == null ? void 0 : _c[0]) == null ? void 0 : _d.index) ?? 0;
5530
+ const activeIndex = ((_b2 = tpl.editingPanel) == null ? void 0 : _b2.index) ?? ((_d2 = (_c2 = tpl.printPanels) == null ? void 0 : _c2[0]) == null ? void 0 : _d2.index) ?? 0;
5027
5531
  try {
5028
5532
  tpl.update(merged, activeIndex);
5029
5533
  } catch (e) {
@@ -5038,33 +5542,53 @@ const _DesignerUtils = class _DesignerUtils {
5038
5542
  if (nextJson) (_e = this.onTemplateChange) == null ? void 0 : _e.call(this, nextJson);
5039
5543
  }
5040
5544
  applyTemplateJson(json) {
5041
- var _a;
5545
+ var _a2;
5042
5546
  this.newDesigner(
5043
5547
  { template: json, history: true, dataMode: 1 },
5044
5548
  this.options.designOptions || {}
5045
5549
  );
5046
- (_a = this.onTemplateChange) == null ? void 0 : _a.call(this, json);
5550
+ (_a2 = this.onTemplateChange) == null ? void 0 : _a2.call(this, json);
5047
5551
  }
5048
5552
  getPrinterList() {
5049
- var _a, _b;
5050
- try {
5051
- return ((_b = (_a = hiprint.hiwebSocket) == null ? void 0 : _a.getPrinterList) == null ? void 0 : _b.call(_a)) ?? [];
5052
- } catch {
5053
- return [];
5553
+ return getPrintClient().getPrinterList();
5554
+ }
5555
+ getPrintClientStatus() {
5556
+ return getPrintClient().getStatus();
5557
+ }
5558
+ /**
5559
+ * Browser-side batch print. Combines records into a single print job —
5560
+ * works without electron-hiprint. `printDataList` can be a single
5561
+ * object or an array; each record can also be printed multiple times
5562
+ * via `options.copies`.
5563
+ */
5564
+ async batchPrint(printDataList, options) {
5565
+ if (!this.printTemplate) {
5566
+ throw new Error("[print-designer] No active print template.");
5567
+ }
5568
+ const data2 = printDataList ?? this.printData ?? {};
5569
+ const list = Array.isArray(data2) ? data2 : [data2];
5570
+ await this.plugins.run("beforePrint", this.printTemplate, this);
5571
+ await batchPrint(this.printTemplate, list, options);
5572
+ }
5573
+ async print2(printData, options) {
5574
+ const data2 = printData ?? this.printData;
5575
+ if (!this.printTemplate) {
5576
+ throw new Error("[print-designer] No active print template.");
5054
5577
  }
5578
+ return getPrintClient().printByInstance(this.printTemplate, data2, options);
5055
5579
  }
5056
5580
  // -------------------------------------------------------------------------
5057
5581
  // Zoom / view-port helpers
5058
5582
  // -------------------------------------------------------------------------
5059
5583
  setZoom(value) {
5060
- var _a, _b, _c, _d;
5584
+ var _a2, _b2, _c2, _d2;
5061
5585
  const scale = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, Number.isFinite(value) ? value : 1));
5062
5586
  setZoom(scale);
5063
5587
  try {
5064
- (_b = (_a = this.printTemplate) == null ? void 0 : _a.zoom) == null ? void 0 : _b.call(_a, scale);
5588
+ (_b2 = (_a2 = this.printTemplate) == null ? void 0 : _a2.zoom) == null ? void 0 : _b2.call(_a2, scale);
5065
5589
  } catch (_) {
5066
5590
  }
5067
- (_d = (_c = this.ruler) == null ? void 0 : _c.redraw) == null ? void 0 : _d.call(_c);
5591
+ (_d2 = (_c2 = this.ruler) == null ? void 0 : _c2.redraw) == null ? void 0 : _d2.call(_c2);
5068
5592
  }
5069
5593
  getZoom() {
5070
5594
  const scale = this.readTemplateScale();
@@ -5086,10 +5610,10 @@ const _DesignerUtils = class _DesignerUtils {
5086
5610
  return this.getZoom() > ZOOM_MIN + 1e-3;
5087
5611
  }
5088
5612
  adaptToSize() {
5089
- var _a;
5613
+ var _a2;
5090
5614
  if (typeof window === "undefined") return;
5091
5615
  const host = document.getElementById(DESIGN_CONTAINER_ID);
5092
- const paper = (_a = host == null ? void 0 : host.querySelector) == null ? void 0 : _a.call(host, ".hiprint-printPanel, .hiprint-printPaper");
5616
+ const paper = (_a2 = host == null ? void 0 : host.querySelector) == null ? void 0 : _a2.call(host, ".hiprint-printPanel, .hiprint-printPaper");
5093
5617
  if (!host || !paper) return;
5094
5618
  const hostRect = host.getBoundingClientRect();
5095
5619
  const zoom = Math.max(ZOOM_MIN, this.getZoom());
@@ -5108,24 +5632,24 @@ const _DesignerUtils = class _DesignerUtils {
5108
5632
  return [...this.getPanelElements()];
5109
5633
  }
5110
5634
  getSelectedElements() {
5111
- var _a;
5635
+ var _a2;
5112
5636
  const tpl = this.printTemplate;
5113
5637
  if (!tpl) return [];
5114
5638
  let els = [];
5115
5639
  try {
5116
- els = ((_a = tpl.getSelectEls) == null ? void 0 : _a.call(tpl)) ?? [];
5640
+ els = ((_a2 = tpl.getSelectEls) == null ? void 0 : _a2.call(tpl)) ?? [];
5117
5641
  } catch {
5118
5642
  }
5119
5643
  if (!els.length) els = this.state.selection.elements;
5120
5644
  return els.filter(Boolean);
5121
5645
  }
5122
5646
  getPanelElements() {
5123
- var _a, _b;
5124
- return ((_b = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel) == null ? void 0 : _b.printElements) ?? [];
5647
+ var _a2, _b2;
5648
+ return ((_b2 = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel) == null ? void 0 : _b2.printElements) ?? [];
5125
5649
  }
5126
5650
  getExplicitZIndex(el) {
5127
- var _a;
5128
- const raw = (_a = el == null ? void 0 : el.options) == null ? void 0 : _a.zIndex;
5651
+ var _a2;
5652
+ const raw = (_a2 = el == null ? void 0 : el.options) == null ? void 0 : _a2.zIndex;
5129
5653
  if (raw != null && raw !== "" && Number.isFinite(Number(raw))) return Number(raw);
5130
5654
  return null;
5131
5655
  }
@@ -5133,7 +5657,7 @@ const _DesignerUtils = class _DesignerUtils {
5133
5657
  this.updateElementOption(el, "zIndex", zIndex, true);
5134
5658
  }
5135
5659
  updateElementOption(el, name, value, silent = true) {
5136
- var _a;
5660
+ var _a2;
5137
5661
  try {
5138
5662
  if (typeof (el == null ? void 0 : el.updateOption) === "function") {
5139
5663
  el.updateOption(name, value, silent);
@@ -5143,34 +5667,34 @@ const _DesignerUtils = class _DesignerUtils {
5143
5667
  }
5144
5668
  try {
5145
5669
  el.options[name] = value;
5146
- (_a = el.updateDesignViewFromOptions) == null ? void 0 : _a.call(el);
5670
+ (_a2 = el.updateDesignViewFromOptions) == null ? void 0 : _a2.call(el);
5147
5671
  return true;
5148
5672
  } catch {
5149
5673
  }
5150
5674
  return false;
5151
5675
  }
5152
5676
  getElementFontSize(el) {
5153
- var _a, _b;
5154
- const raw = (_a = el == null ? void 0 : el.options) == null ? void 0 : _a.fontSize;
5677
+ var _a2, _b2;
5678
+ const raw = (_a2 = el == null ? void 0 : el.options) == null ? void 0 : _a2.fontSize;
5155
5679
  const size = Number(raw);
5156
5680
  if (Number.isFinite(size) && size > 0) return size;
5157
- const typeDefault = Number((_b = el == null ? void 0 : el.printElementType) == null ? void 0 : _b.fontSize);
5681
+ const typeDefault = Number((_b2 = el == null ? void 0 : el.printElementType) == null ? void 0 : _b2.fontSize);
5158
5682
  return Number.isFinite(typeDefault) && typeDefault > 0 ? typeDefault : 12;
5159
5683
  }
5160
5684
  resolveElementTid(el) {
5161
- var _a, _b;
5162
- const tid = ((_a = el == null ? void 0 : el.printElementType) == null ? void 0 : _a.tid) ?? (el == null ? void 0 : el.tid);
5685
+ var _a2, _b2;
5686
+ const tid = ((_a2 = el == null ? void 0 : el.printElementType) == null ? void 0 : _a2.tid) ?? (el == null ? void 0 : el.tid);
5163
5687
  if (tid) return String(tid);
5164
- const type = String(((_b = el == null ? void 0 : el.printElementType) == null ? void 0 : _b.type) || "");
5688
+ const type = String(((_b2 = el == null ? void 0 : el.printElementType) == null ? void 0 : _b2.type) || "");
5165
5689
  if (!type) return null;
5166
5690
  return `defaultModule.${type}`;
5167
5691
  }
5168
5692
  serializeElement(el) {
5169
- var _a, _b;
5693
+ var _a2, _b2;
5170
5694
  if (!el) return null;
5171
5695
  try {
5172
5696
  const tid = this.resolveElementTid(el);
5173
- const optionsSource = ((_b = (_a = el.options) == null ? void 0 : _a.getPrintElementOptionEntity) == null ? void 0 : _b.call(_a)) ?? el.options ?? {};
5697
+ const optionsSource = ((_b2 = (_a2 = el.options) == null ? void 0 : _a2.getPrintElementOptionEntity) == null ? void 0 : _b2.call(_a2)) ?? el.options ?? {};
5174
5698
  const options = JSON.parse(JSON.stringify(optionsSource));
5175
5699
  const printElementType = el.printElementType ? JSON.parse(JSON.stringify(el.printElementType)) : void 0;
5176
5700
  if (!tid && !(printElementType == null ? void 0 : printElementType.type)) return null;
@@ -5187,15 +5711,15 @@ const _DesignerUtils = class _DesignerUtils {
5187
5711
  return copy;
5188
5712
  }
5189
5713
  insertElementEntity(entity, initSizeByHtml = false) {
5190
- var _a, _b, _c, _d, _e, _f, _g, _h;
5191
- const panel = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel;
5714
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
5715
+ const panel = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel;
5192
5716
  const tpl = this.printTemplate;
5193
- if (!panel || !(entity == null ? void 0 : entity.tid) && !((_b = entity == null ? void 0 : entity.printElementType) == null ? void 0 : _b.type)) return null;
5717
+ if (!panel || !(entity == null ? void 0 : entity.tid) && !((_b2 = entity == null ? void 0 : entity.printElementType) == null ? void 0 : _b2.type)) return null;
5194
5718
  try {
5195
- const type = (_c = panel.getPrintElementTypeByEntity) == null ? void 0 : _c.call(panel, entity);
5719
+ const type = (_c2 = panel.getPrintElementTypeByEntity) == null ? void 0 : _c2.call(panel, entity);
5196
5720
  if (!(type == null ? void 0 : type.createPrintElement)) return null;
5197
5721
  const el = type.createPrintElement(entity.options);
5198
- (_d = el.setTemplateId) == null ? void 0 : _d.call(el, tpl.id ?? tpl.templateId);
5722
+ (_d2 = el.setTemplateId) == null ? void 0 : _d2.call(el, tpl.id ?? tpl.templateId);
5199
5723
  (_e = el.setPanel) == null ? void 0 : _e.call(el, panel);
5200
5724
  (_f = panel.appendDesignPrintElement) == null ? void 0 : _f.call(panel, panel.designPaper, el, initSizeByHtml);
5201
5725
  panel.printElements.push(el);
@@ -5211,7 +5735,7 @@ const _DesignerUtils = class _DesignerUtils {
5211
5735
  }
5212
5736
  /** Insert a new canvas element by hiprint `tid` (e.g. `defaultModule.text`). */
5213
5737
  addElementByTid(tid, options = {}) {
5214
- var _a;
5738
+ var _a2;
5215
5739
  const left = Number.isFinite(options.left) ? Number(options.left) : 60;
5216
5740
  const top = Number.isFinite(options.top) ? Number(options.top) : 60;
5217
5741
  const el = this.insertElementEntity({ tid, options: { left, top } }, true);
@@ -5219,20 +5743,20 @@ const _DesignerUtils = class _DesignerUtils {
5219
5743
  this.markTemplateChanged("新增元素");
5220
5744
  this.selectPrintElement(el);
5221
5745
  const json = this.getTemplateJson();
5222
- if (json) (_a = this.onTemplateChange) == null ? void 0 : _a.call(this, json);
5746
+ if (json) (_a2 = this.onTemplateChange) == null ? void 0 : _a2.call(this, json);
5223
5747
  return el;
5224
5748
  }
5225
5749
  /** Clone a live print element using hiprint's native clone path. */
5226
5750
  duplicateElement(el, delta = 10) {
5227
- var _a, _b, _c, _d, _e, _f, _g;
5228
- const panel = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel;
5751
+ var _a2, _b2, _c2, _d2, _e, _f, _g;
5752
+ const panel = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel;
5229
5753
  const tpl = this.printTemplate;
5230
5754
  if (!panel || !tpl || !el) return null;
5231
5755
  try {
5232
5756
  let copy = null;
5233
5757
  if (typeof el.clone === "function") {
5234
5758
  copy = el.clone();
5235
- } else if ((_b = el.printElementType) == null ? void 0 : _b.createPrintElement) {
5759
+ } else if ((_b2 = el.printElementType) == null ? void 0 : _b2.createPrintElement) {
5236
5760
  copy = el.printElementType.createPrintElement();
5237
5761
  Object.keys(el.options || {}).forEach((key) => {
5238
5762
  copy.options[key] = el.options[key];
@@ -5245,8 +5769,8 @@ const _DesignerUtils = class _DesignerUtils {
5245
5769
  else copy.options.left = left;
5246
5770
  if (typeof copy.options.setTop === "function") copy.options.setTop(top);
5247
5771
  else copy.options.top = top;
5248
- (_c = copy.setTemplateId) == null ? void 0 : _c.call(copy, tpl.id ?? tpl.templateId);
5249
- (_d = copy.setPanel) == null ? void 0 : _d.call(copy, panel);
5772
+ (_c2 = copy.setTemplateId) == null ? void 0 : _c2.call(copy, tpl.id ?? tpl.templateId);
5773
+ (_d2 = copy.setPanel) == null ? void 0 : _d2.call(copy, panel);
5250
5774
  (_e = panel.appendDesignPrintElement) == null ? void 0 : _e.call(panel, panel.designPaper, copy, false);
5251
5775
  panel.printElements.push(copy);
5252
5776
  (_f = copy.design) == null ? void 0 : _f.call(copy, void 0, panel.designPaper);
@@ -5260,15 +5784,15 @@ const _DesignerUtils = class _DesignerUtils {
5260
5784
  }
5261
5785
  }
5262
5786
  setElementDraggable(el, draggable) {
5263
- var _a, _b, _c, _d;
5787
+ var _a2, _b2, _c2, _d2;
5264
5788
  if (!(el == null ? void 0 : el.options)) return;
5265
5789
  el.options.draggable = draggable;
5266
5790
  try {
5267
- (_b = (_a = el.designTarget) == null ? void 0 : _a.hidraggable) == null ? void 0 : _b.call(_a, "update", { draggable });
5791
+ (_b2 = (_a2 = el.designTarget) == null ? void 0 : _a2.hidraggable) == null ? void 0 : _b2.call(_a2, "update", { draggable });
5268
5792
  } catch {
5269
5793
  }
5270
5794
  try {
5271
- (_d = (_c = el.designTarget) == null ? void 0 : _c.hireizeable) == null ? void 0 : _d.call(_c, "update", { draggable });
5795
+ (_d2 = (_c2 = el.designTarget) == null ? void 0 : _c2.hireizeable) == null ? void 0 : _d2.call(_c2, "update", { draggable });
5272
5796
  } catch {
5273
5797
  }
5274
5798
  }
@@ -5289,13 +5813,13 @@ const _DesignerUtils = class _DesignerUtils {
5289
5813
  ];
5290
5814
  }
5291
5815
  syncPanelElementOrder(ordered) {
5292
- var _a, _b;
5293
- const panel = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel;
5816
+ var _a2, _b2;
5817
+ const panel = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel;
5294
5818
  if (!panel) return;
5295
5819
  panel.printElements = ordered;
5296
5820
  try {
5297
5821
  const $ = window.jQuery || window.$;
5298
- const container = ((_b = panel.designPaper) == null ? void 0 : _b.target) ?? panel.target;
5822
+ const container = ((_b2 = panel.designPaper) == null ? void 0 : _b2.target) ?? panel.target;
5299
5823
  if ($ && (container == null ? void 0 : container.length)) {
5300
5824
  ordered.forEach((el) => {
5301
5825
  if (el == null ? void 0 : el.designTarget) $(el.designTarget).appendTo(container);
@@ -5305,37 +5829,37 @@ const _DesignerUtils = class _DesignerUtils {
5305
5829
  }
5306
5830
  }
5307
5831
  getPanelSizePt(panel) {
5308
- var _a;
5832
+ var _a2;
5309
5833
  const hinnn = window.hinnn;
5310
5834
  const mmW = Number((panel == null ? void 0 : panel.width) ?? (panel == null ? void 0 : panel.mmwidth) ?? 0);
5311
5835
  const mmH = Number((panel == null ? void 0 : panel.height) ?? (panel == null ? void 0 : panel.mmheight) ?? 0);
5312
- if ((_a = hinnn == null ? void 0 : hinnn.mm) == null ? void 0 : _a.toPt) {
5836
+ if ((_a2 = hinnn == null ? void 0 : hinnn.mm) == null ? void 0 : _a2.toPt) {
5313
5837
  return { width: hinnn.mm.toPt(mmW), height: hinnn.mm.toPt(mmH) };
5314
5838
  }
5315
5839
  return { width: mmW, height: mmH };
5316
5840
  }
5317
5841
  getElementRect(el) {
5318
- var _a, _b, _c, _d;
5842
+ var _a2, _b2, _c2, _d2;
5319
5843
  const opts = el == null ? void 0 : el.options;
5320
5844
  if (!opts) return null;
5321
- const left = Number(((_a = opts.getLeft) == null ? void 0 : _a.call(opts)) ?? opts.left ?? 0);
5322
- const top = Number(((_b = opts.getTop) == null ? void 0 : _b.call(opts)) ?? opts.top ?? 0);
5323
- const width = Number(((_c = opts.getWidth) == null ? void 0 : _c.call(opts)) ?? opts.width ?? 0);
5324
- const height = Number(((_d = opts.getHeight) == null ? void 0 : _d.call(opts)) ?? opts.height ?? 0);
5845
+ const left = Number(((_a2 = opts.getLeft) == null ? void 0 : _a2.call(opts)) ?? opts.left ?? 0);
5846
+ const top = Number(((_b2 = opts.getTop) == null ? void 0 : _b2.call(opts)) ?? opts.top ?? 0);
5847
+ const width = Number(((_c2 = opts.getWidth) == null ? void 0 : _c2.call(opts)) ?? opts.width ?? 0);
5848
+ const height = Number(((_d2 = opts.getHeight) == null ? void 0 : _d2.call(opts)) ?? opts.height ?? 0);
5325
5849
  return { el, left, top, width, height, right: left + width, bottom: top + height };
5326
5850
  }
5327
5851
  applyElementPosition(el, left, top) {
5328
- var _a, _b, _c, _d, _e, _f, _g, _h;
5852
+ var _a2, _b2, _c2, _d2, _e, _f, _g, _h;
5329
5853
  const opts = el == null ? void 0 : el.options;
5330
5854
  if (!opts) return;
5331
- const width = Number(((_a = opts.getWidth) == null ? void 0 : _a.call(opts)) ?? opts.width ?? 0);
5332
- const height = Number(((_b = opts.getHeight) == null ? void 0 : _b.call(opts)) ?? opts.height ?? 0);
5855
+ const width = Number(((_a2 = opts.getWidth) == null ? void 0 : _a2.call(opts)) ?? opts.width ?? 0);
5856
+ const height = Number(((_b2 = opts.getHeight) == null ? void 0 : _b2.call(opts)) ?? opts.height ?? 0);
5333
5857
  try {
5334
5858
  if (typeof el.updateSizeAndPositionOptions === "function") {
5335
5859
  el.updateSizeAndPositionOptions(left, top, width, height);
5336
5860
  } else {
5337
- (_c = opts.setLeft) == null ? void 0 : _c.call(opts, left);
5338
- (_d = opts.setTop) == null ? void 0 : _d.call(opts, top);
5861
+ (_c2 = opts.setLeft) == null ? void 0 : _c2.call(opts, left);
5862
+ (_d2 = opts.setTop) == null ? void 0 : _d2.call(opts, top);
5339
5863
  (_e = opts.copyDesignTopFromTop) == null ? void 0 : _e.call(opts);
5340
5864
  }
5341
5865
  } catch {
@@ -5351,14 +5875,14 @@ const _DesignerUtils = class _DesignerUtils {
5351
5875
  }
5352
5876
  }
5353
5877
  markTemplateChanged(label = HISTORY_PARAM) {
5354
- var _a, _b, _c;
5878
+ var _a2, _b2;
5355
5879
  const tpl = this.printTemplate;
5356
5880
  if (!tpl) return;
5357
5881
  try {
5358
- const lib = ((_a = hiprint) == null ? void 0 : _a.instance) ?? ((_b = window.HiPrintlib) == null ? void 0 : _b.instance);
5882
+ const lib = (hiprint == null ? void 0 : hiprint.instance) ?? ((_a2 = window.HiPrintlib) == null ? void 0 : _a2.instance);
5359
5883
  if (lib) lib.changed = true;
5360
5884
  const tplId = tpl.id ?? tpl.templateId;
5361
- const bus = (_c = window.hinnn) == null ? void 0 : _c.event;
5885
+ const bus = (_b2 = window.hinnn) == null ? void 0 : _b2.event;
5362
5886
  if (bus && tplId != null) bus.trigger(`hiprintTemplateDataChanged_${tplId}`, label);
5363
5887
  } catch {
5364
5888
  }
@@ -5366,7 +5890,7 @@ const _DesignerUtils = class _DesignerUtils {
5366
5890
  this.history.refreshFromTemplate();
5367
5891
  }
5368
5892
  align(side) {
5369
- var _a;
5893
+ var _a2;
5370
5894
  const tpl = this.printTemplate;
5371
5895
  if (!tpl) return;
5372
5896
  const rects = this.getSelectedElements().map((el) => this.getElementRect(el)).filter(Boolean);
@@ -5376,7 +5900,7 @@ const _DesignerUtils = class _DesignerUtils {
5376
5900
  let refRight;
5377
5901
  let refBottom;
5378
5902
  if (rects.length === 1) {
5379
- const panel = tpl.editingPanel ?? ((_a = rects[0].el) == null ? void 0 : _a.panel);
5903
+ const panel = tpl.editingPanel ?? ((_a2 = rects[0].el) == null ? void 0 : _a2.panel);
5380
5904
  const { width, height } = this.getPanelSizePt(panel);
5381
5905
  refLeft = 0;
5382
5906
  refTop = 0;
@@ -5422,9 +5946,9 @@ const _DesignerUtils = class _DesignerUtils {
5422
5946
  callOnSelection(method, ...args) {
5423
5947
  const els = this.state.selection.elements;
5424
5948
  els.forEach((el) => {
5425
- var _a;
5949
+ var _a2;
5426
5950
  try {
5427
- (_a = el == null ? void 0 : el[method]) == null ? void 0 : _a.call(el, ...args);
5951
+ (_a2 = el == null ? void 0 : el[method]) == null ? void 0 : _a2.call(el, ...args);
5428
5952
  } catch (_) {
5429
5953
  }
5430
5954
  });
@@ -5489,15 +6013,15 @@ const _DesignerUtils = class _DesignerUtils {
5489
6013
  isSelectionLocked() {
5490
6014
  const selected = this.getSelectedElements();
5491
6015
  return selected.length > 0 && selected.every((el) => {
5492
- var _a;
5493
- return ((_a = el == null ? void 0 : el.options) == null ? void 0 : _a.draggable) === false;
6016
+ var _a2;
6017
+ return ((_a2 = el == null ? void 0 : el.options) == null ? void 0 : _a2.draggable) === false;
5494
6018
  });
5495
6019
  }
5496
6020
  isSelectionUnlocked() {
5497
6021
  const selected = this.getSelectedElements();
5498
6022
  return selected.length > 0 && selected.every((el) => {
5499
- var _a;
5500
- return ((_a = el == null ? void 0 : el.options) == null ? void 0 : _a.draggable) !== false;
6023
+ var _a2;
6024
+ return ((_a2 = el == null ? void 0 : el.options) == null ? void 0 : _a2.draggable) !== false;
5501
6025
  });
5502
6026
  }
5503
6027
  setLock(locked) {
@@ -5548,17 +6072,17 @@ const _DesignerUtils = class _DesignerUtils {
5548
6072
  designerStore.uiPulse += 1;
5549
6073
  }
5550
6074
  delete() {
5551
- var _a;
6075
+ var _a2;
5552
6076
  const selected = this.getSelectedElements();
5553
- const panel = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel;
6077
+ const panel = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel;
5554
6078
  if (!panel || !selected.length) return;
5555
6079
  selected.forEach((el) => {
5556
- var _a2, _b;
6080
+ var _a3, _b2;
5557
6081
  try {
5558
- (_a2 = panel.deletePrintElement) == null ? void 0 : _a2.call(panel, el);
6082
+ (_a3 = panel.deletePrintElement) == null ? void 0 : _a3.call(panel, el);
5559
6083
  } catch {
5560
6084
  try {
5561
- (_b = el == null ? void 0 : el.delete) == null ? void 0 : _b.call(el);
6085
+ (_b2 = el == null ? void 0 : el.delete) == null ? void 0 : _b2.call(el);
5562
6086
  } catch {
5563
6087
  }
5564
6088
  }
@@ -5568,15 +6092,15 @@ const _DesignerUtils = class _DesignerUtils {
5568
6092
  }
5569
6093
  /** Delete a single element from the structure panel or other auxiliary UI. */
5570
6094
  deletePrintElement(item) {
5571
- var _a, _b, _c;
6095
+ var _a2, _b2, _c2;
5572
6096
  if (!item) return;
5573
- const panel = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel;
6097
+ const panel = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel;
5574
6098
  if (!panel) return;
5575
6099
  try {
5576
- (_b = panel.deletePrintElement) == null ? void 0 : _b.call(panel, item);
6100
+ (_b2 = panel.deletePrintElement) == null ? void 0 : _b2.call(panel, item);
5577
6101
  } catch {
5578
6102
  try {
5579
- (_c = item == null ? void 0 : item.delete) == null ? void 0 : _c.call(item);
6103
+ (_c2 = item == null ? void 0 : item.delete) == null ? void 0 : _c2.call(item);
5580
6104
  } catch {
5581
6105
  }
5582
6106
  }
@@ -5601,14 +6125,14 @@ const _DesignerUtils = class _DesignerUtils {
5601
6125
  this.markTemplateChanged(HISTORY_ALIGN);
5602
6126
  }
5603
6127
  clearPanel() {
5604
- var _a;
5605
- const panel = (_a = this.printTemplate) == null ? void 0 : _a.editingPanel;
6128
+ var _a2;
6129
+ const panel = (_a2 = this.printTemplate) == null ? void 0 : _a2.editingPanel;
5606
6130
  if (!panel) return;
5607
6131
  const list = (panel.printElements ?? []).slice();
5608
6132
  list.forEach((el) => {
5609
- var _a2;
6133
+ var _a3;
5610
6134
  try {
5611
- (_a2 = panel.deletePrintElement) == null ? void 0 : _a2.call(panel, el);
6135
+ (_a3 = panel.deletePrintElement) == null ? void 0 : _a3.call(panel, el);
5612
6136
  } catch (_) {
5613
6137
  }
5614
6138
  });
@@ -5860,14 +6384,14 @@ function useRuler(opts) {
5860
6384
  });
5861
6385
  }
5862
6386
  onMounted(() => {
5863
- var _a;
6387
+ var _a2;
5864
6388
  const scroller = opts.scrollerEl();
5865
6389
  scrollHandler = () => schedule();
5866
6390
  scroller == null ? void 0 : scroller.addEventListener("scroll", scrollHandler, { passive: true });
5867
6391
  if (typeof ResizeObserver !== "undefined") {
5868
6392
  resizeObserver = new ResizeObserver(() => schedule());
5869
6393
  if (scroller) resizeObserver.observe(scroller);
5870
- const workspace = (_a = opts.workspaceEl) == null ? void 0 : _a.call(opts);
6394
+ const workspace = (_a2 = opts.workspaceEl) == null ? void 0 : _a2.call(opts);
5871
6395
  if (workspace) resizeObserver.observe(workspace);
5872
6396
  const host = document.getElementById(DESIGN_CONTAINER_ID);
5873
6397
  if (host) resizeObserver.observe(host);
@@ -7819,12 +8343,12 @@ const _hoisted_4$a = {
7819
8343
  const _hoisted_5$a = { class: "svp-header__center" };
7820
8344
  const _hoisted_6$6 = ["title"];
7821
8345
  const _hoisted_7$6 = ["title"];
7822
- const _hoisted_8$4 = ["title"];
7823
- const _hoisted_9$3 = ["title"];
7824
- const _hoisted_10$2 = ["title"];
7825
- const _hoisted_11$1 = ["title"];
7826
- const _hoisted_12$1 = ["title", "onClick"];
7827
- const _hoisted_13$1 = { class: "svp-header__aside svp-header__aside--right" };
8346
+ const _hoisted_8$5 = ["title"];
8347
+ const _hoisted_9$4 = ["title"];
8348
+ const _hoisted_10$3 = ["title"];
8349
+ const _hoisted_11$2 = ["title"];
8350
+ const _hoisted_12$2 = ["title", "onClick"];
8351
+ const _hoisted_13$2 = { class: "svp-header__aside svp-header__aside--right" };
7828
8352
  function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
7829
8353
  const _component_SvpIcon = resolveComponent("SvpIcon");
7830
8354
  return openBlock(), createElementBlock("header", _hoisted_1$c, [
@@ -7875,7 +8399,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
7875
8399
  size: 22
7876
8400
  }, null, 8, ["icon"]),
7877
8401
  createElementVNode("span", null, toDisplayString(_ctx.t("designer.exportFile")), 1)
7878
- ], 8, _hoisted_8$4),
8402
+ ], 8, _hoisted_8$5),
7879
8403
  createElementVNode("button", {
7880
8404
  type: "button",
7881
8405
  class: "svp-header__menu",
@@ -7887,7 +8411,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
7887
8411
  size: 22
7888
8412
  }, null, 8, ["icon"]),
7889
8413
  createElementVNode("span", null, toDisplayString(_ctx.t("designer.importFile")), 1)
7890
- ], 8, _hoisted_9$3),
8414
+ ], 8, _hoisted_9$4),
7891
8415
  createElementVNode("button", {
7892
8416
  type: "button",
7893
8417
  class: "svp-header__menu",
@@ -7899,7 +8423,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
7899
8423
  size: 22
7900
8424
  }, null, 8, ["icon"]),
7901
8425
  createElementVNode("span", null, toDisplayString(_ctx.t("designer.save")), 1)
7902
- ], 8, _hoisted_10$2),
8426
+ ], 8, _hoisted_10$3),
7903
8427
  createElementVNode("button", {
7904
8428
  type: "button",
7905
8429
  class: "svp-header__menu",
@@ -7911,7 +8435,7 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
7911
8435
  size: 22
7912
8436
  }, null, 8, ["icon"]),
7913
8437
  createElementVNode("span", null, toDisplayString(_ctx.t("designer.preview")), 1)
7914
- ], 8, _hoisted_11$1),
8438
+ ], 8, _hoisted_11$2),
7915
8439
  _ctx.showElementBar ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
7916
8440
  _cache[6] || (_cache[6] = createElementVNode("span", {
7917
8441
  class: "svp-header__divider",
@@ -7931,12 +8455,12 @@ function _sfc_render$c(_ctx, _cache, $props, $setup, $data, $options) {
7931
8455
  size: 18
7932
8456
  }, null, 8, ["icon"])) : createCommentVNode("", true),
7933
8457
  createElementVNode("span", null, toDisplayString(item.label), 1)
7934
- ], 8, _hoisted_12$1);
8458
+ ], 8, _hoisted_12$2);
7935
8459
  }), 128))
7936
8460
  ], 64)) : createCommentVNode("", true)
7937
8461
  ])
7938
8462
  ]),
7939
- createElementVNode("div", _hoisted_13$1, [
8463
+ createElementVNode("div", _hoisted_13$2, [
7940
8464
  renderSlot(_ctx.$slots, "right")
7941
8465
  ])
7942
8466
  ]);
@@ -7980,8 +8504,8 @@ const _sfc_main$b = defineComponent({
7980
8504
  designerStore.lang = next;
7981
8505
  }
7982
8506
  function onToolbarMouseDown(e) {
7983
- var _a;
7984
- if ((_a = e.target) == null ? void 0 : _a.closest("button")) {
8507
+ var _a2;
8508
+ if ((_a2 = e.target) == null ? void 0 : _a2.closest("button")) {
7985
8509
  e.preventDefault();
7986
8510
  }
7987
8511
  }
@@ -8191,105 +8715,210 @@ function _sfc_render$b(_ctx, _cache, $props, $setup, $data, $options) {
8191
8715
  ], 32);
8192
8716
  }
8193
8717
  const Toolbar = /* @__PURE__ */ _export_sfc(_sfc_main$b, [["render", _sfc_render$b]]);
8194
- function resolvePreviewHtml(value) {
8195
- if (value == null || value === false) return "";
8196
- if (typeof value === "string") return value;
8197
- const any = value;
8198
- if (typeof any.html === "function") {
8199
- try {
8200
- const html = any.html();
8201
- if (typeof html === "string") return html;
8202
- } catch {
8203
- }
8204
- }
8205
- if (Array.isArray(value)) {
8206
- return value.map((item) => resolvePreviewHtml(item)).join("");
8207
- }
8208
- if (typeof any.length === "number" && any.length > 0 && any[0] != null) {
8209
- return resolvePreviewHtml(any[0]);
8210
- }
8211
- if (any.target != null) {
8212
- return resolvePreviewHtml(any.target);
8213
- }
8214
- return "";
8215
- }
8216
8718
  const _sfc_main$a = defineComponent({
8217
8719
  name: "SvpPreview",
8218
8720
  props: {
8219
8721
  options: { type: Object, default: () => ({}) }
8220
8722
  },
8221
8723
  setup(props, { expose }) {
8724
+ var _a2;
8222
8725
  const { t } = useI18n();
8223
8726
  const utils = useDesigner();
8224
8727
  const visible = ref(false);
8225
8728
  const html = ref("");
8226
- const opts = reactive({ showPdf: true, showImg: true, showPrint2: true, ...props.options });
8729
+ const opts = reactive({
8730
+ showPdf: true,
8731
+ showImg: true,
8732
+ showBrowserPrint: true,
8733
+ showPrint2: false,
8734
+ showBatchPrint: true,
8735
+ showPrintClient: false,
8736
+ ...props.options
8737
+ });
8738
+ const clientStatus = ref({ connected: false });
8739
+ const printers = ref([]);
8740
+ const selectedPrinter = ref("");
8741
+ const connecting = ref(false);
8742
+ const batchCopies = ref(Math.max(1, Math.floor(((_a2 = props.options) == null ? void 0 : _a2.defaultCopies) ?? 1)));
8743
+ const batchPrinting = ref(false);
8227
8744
  const tpl = computed(() => utils.printTemplate);
8228
8745
  const canExportPdf = computed(() => {
8229
- var _a;
8746
+ var _a3;
8230
8747
  if (opts.showPdf === false) return false;
8231
- return typeof ((_a = tpl.value) == null ? void 0 : _a.toPdf) === "function";
8748
+ return typeof ((_a3 = tpl.value) == null ? void 0 : _a3.toPdf) === "function";
8232
8749
  });
8233
8750
  const canExportImage = computed(() => {
8234
- var _a;
8751
+ var _a3;
8235
8752
  if (opts.showImg === false) return false;
8236
- return typeof ((_a = tpl.value) == null ? void 0 : _a.toImage) === "function";
8753
+ return typeof ((_a3 = tpl.value) == null ? void 0 : _a3.toImage) === "function";
8754
+ });
8755
+ const canBrowserPrint = computed(() => {
8756
+ var _a3;
8757
+ if (opts.showBrowserPrint === false) return false;
8758
+ return typeof ((_a3 = tpl.value) == null ? void 0 : _a3.print) === "function";
8759
+ });
8760
+ const canSilentPrint = computed(() => {
8761
+ var _a3;
8762
+ if (opts.showPrint2 === false || opts.showSilentPrint === false) return false;
8763
+ return typeof ((_a3 = tpl.value) == null ? void 0 : _a3.print2) === "function";
8764
+ });
8765
+ const showPrintClientBar = computed(() => {
8766
+ if (opts.showPrintClient === true) return true;
8767
+ return canSilentPrint.value;
8768
+ });
8769
+ const canBatchPrint = computed(() => {
8770
+ var _a3;
8771
+ if (opts.showBatchPrint === false) return false;
8772
+ return typeof ((_a3 = tpl.value) == null ? void 0 : _a3.getHtml) === "function";
8237
8773
  });
8238
- const canPrint = computed(() => {
8239
- var _a;
8240
- if (opts.showPrint2 === false) return false;
8241
- return typeof ((_a = tpl.value) == null ? void 0 : _a.print) === "function";
8774
+ const batchDataRows = computed(() => {
8775
+ const data2 = utils.printData;
8776
+ if (Array.isArray(data2)) return data2.length;
8777
+ return data2 == null ? 0 : 1;
8242
8778
  });
8779
+ const batchTotalPages = computed(() => {
8780
+ const copies = Math.max(1, Math.floor(batchCopies.value || 1));
8781
+ return batchDataRows.value * copies;
8782
+ });
8783
+ const batchHintText = computed(() => {
8784
+ const template = t("designer.batchHint");
8785
+ return template.replace("{rows}", String(batchDataRows.value)).replace("{total}", String(batchTotalPages.value));
8786
+ });
8787
+ function formatPrinterLabel(printer) {
8788
+ const label = printer.displayName || printer.name;
8789
+ return printer.isDefault ? `${label} (${t("designer.defaultPrinter")})` : label;
8790
+ }
8791
+ function syncDefaultPrinter(list) {
8792
+ if (!list.length) {
8793
+ selectedPrinter.value = "";
8794
+ return;
8795
+ }
8796
+ if (selectedPrinter.value && list.some((item) => item.name === selectedPrinter.value)) {
8797
+ return;
8798
+ }
8799
+ const fallback = list.find((item) => item.isDefault) ?? list[0];
8800
+ selectedPrinter.value = (fallback == null ? void 0 : fallback.name) ?? "";
8801
+ }
8802
+ function refreshClientState() {
8803
+ clientStatus.value = utils.getPrintClientStatus();
8804
+ if (!clientStatus.value.connected) {
8805
+ printers.value = [];
8806
+ return;
8807
+ }
8808
+ printers.value = utils.getPrinterList();
8809
+ syncDefaultPrinter(printers.value);
8810
+ }
8243
8811
  function open(content) {
8244
- var _a, _b;
8245
- const raw = content !== void 0 ? content : (_b = (_a = tpl.value) == null ? void 0 : _a.getHtml) == null ? void 0 : _b.call(_a, utils.printData);
8812
+ var _a3, _b2;
8813
+ const raw = content !== void 0 ? content : (_b2 = (_a3 = tpl.value) == null ? void 0 : _a3.getHtml) == null ? void 0 : _b2.call(_a3, utils.printData);
8246
8814
  html.value = resolvePreviewHtml(raw);
8247
8815
  visible.value = true;
8816
+ refreshClientState();
8248
8817
  utils.plugins.run("onPreview", html.value, utils).catch(() => {
8249
8818
  });
8250
8819
  }
8251
8820
  function close() {
8252
8821
  visible.value = false;
8253
8822
  }
8823
+ async function toggleConnect() {
8824
+ if (connecting.value) return;
8825
+ connecting.value = true;
8826
+ try {
8827
+ if (clientStatus.value.connected) {
8828
+ await new Promise((resolve) => {
8829
+ utils.setConnect(false, () => resolve());
8830
+ });
8831
+ } else {
8832
+ await new Promise((resolve) => {
8833
+ utils.setConnect(true, () => resolve());
8834
+ });
8835
+ }
8836
+ refreshClientState();
8837
+ } finally {
8838
+ connecting.value = false;
8839
+ }
8840
+ }
8254
8841
  async function onPrint() {
8255
- var _a, _b;
8842
+ var _a3, _b2;
8256
8843
  await utils.plugins.run("beforePrint", tpl.value, utils);
8257
8844
  try {
8258
- (_b = (_a = tpl.value) == null ? void 0 : _a.print) == null ? void 0 : _b.call(_a, utils.printData);
8845
+ (_b2 = (_a3 = tpl.value) == null ? void 0 : _a3.print) == null ? void 0 : _b2.call(_a3, utils.printData);
8846
+ } catch (e) {
8847
+ console.error(e);
8848
+ }
8849
+ }
8850
+ async function onSilentPrint() {
8851
+ const results = await utils.plugins.run("beforePrint2", tpl.value, utils, "silent");
8852
+ if (results.some((r) => r === false)) return;
8853
+ try {
8854
+ await utils.print2(utils.printData, {
8855
+ printer: selectedPrinter.value,
8856
+ title: t("designer.silentPrint")
8857
+ });
8259
8858
  } catch (e) {
8260
8859
  console.error(e);
8261
8860
  }
8262
8861
  }
8263
8862
  async function onPdf() {
8264
- var _a;
8863
+ var _a3;
8265
8864
  const results = await utils.plugins.run("beforePrint2", tpl.value, utils, "pdf");
8266
8865
  if (results.some((r) => r === false)) return;
8267
8866
  try {
8268
- if (typeof ((_a = tpl.value) == null ? void 0 : _a.toPdf) === "function") tpl.value.toPdf(utils.printData);
8867
+ if (typeof ((_a3 = tpl.value) == null ? void 0 : _a3.toPdf) === "function") tpl.value.toPdf(utils.printData);
8269
8868
  } catch (e) {
8270
8869
  console.error(e);
8271
8870
  }
8272
8871
  }
8273
8872
  async function onImage() {
8274
- var _a;
8873
+ var _a3;
8275
8874
  const results = await utils.plugins.run("beforePrint2", tpl.value, utils, "image");
8276
8875
  if (results.some((r) => r === false)) return;
8277
8876
  try {
8278
- if (typeof ((_a = tpl.value) == null ? void 0 : _a.toImage) === "function") tpl.value.toImage(utils.printData);
8877
+ if (typeof ((_a3 = tpl.value) == null ? void 0 : _a3.toImage) === "function") tpl.value.toImage(utils.printData);
8279
8878
  } catch (e) {
8280
8879
  console.error(e);
8281
8880
  }
8282
8881
  }
8882
+ async function onBatchPrint() {
8883
+ if (batchPrinting.value) return;
8884
+ const data2 = utils.printData;
8885
+ const list = Array.isArray(data2) ? data2 : [data2];
8886
+ if (!list.length) return;
8887
+ const copies = Math.max(1, Math.floor(batchCopies.value || 1));
8888
+ batchPrinting.value = true;
8889
+ try {
8890
+ await utils.batchPrint(list, { copies, title: t("designer.batchPrint") });
8891
+ } catch (e) {
8892
+ console.error(e);
8893
+ } finally {
8894
+ batchPrinting.value = false;
8895
+ }
8896
+ }
8283
8897
  expose({ open, close });
8284
8898
  return {
8285
8899
  t,
8286
8900
  visible,
8287
8901
  html,
8902
+ clientStatus,
8903
+ printers,
8904
+ selectedPrinter,
8905
+ batchCopies,
8906
+ batchPrinting,
8907
+ batchDataRows,
8908
+ batchTotalPages,
8909
+ batchHintText,
8288
8910
  canExportPdf,
8289
8911
  canExportImage,
8290
- canPrint,
8912
+ canBrowserPrint,
8913
+ canSilentPrint,
8914
+ canBatchPrint,
8915
+ showPrintClientBar,
8916
+ formatPrinterLabel,
8291
8917
  close,
8918
+ toggleConnect,
8292
8919
  onPrint,
8920
+ onSilentPrint,
8921
+ onBatchPrint,
8293
8922
  onPdf,
8294
8923
  onImage
8295
8924
  };
@@ -8304,12 +8933,28 @@ const _hoisted_6$4 = {
8304
8933
  key: 1,
8305
8934
  class: "svp-preview__empty"
8306
8935
  };
8307
- const _hoisted_7$4 = { class: "svp-dialog__footer svp-preview__footer" };
8936
+ const _hoisted_7$4 = {
8937
+ key: 0,
8938
+ class: "svp-preview__print-bar"
8939
+ };
8940
+ const _hoisted_8$4 = ["value"];
8941
+ const _hoisted_9$3 = {
8942
+ key: 1,
8943
+ class: "svp-preview__printer-empty"
8944
+ };
8945
+ const _hoisted_10$2 = {
8946
+ key: 1,
8947
+ class: "svp-preview__print-bar svp-preview__batch-bar"
8948
+ };
8949
+ const _hoisted_11$1 = { class: "svp-preview__batch-label" };
8950
+ const _hoisted_12$1 = { class: "svp-preview__batch-hint" };
8951
+ const _hoisted_13$1 = { class: "svp-dialog__footer svp-preview__footer" };
8952
+ const _hoisted_14$1 = ["disabled"];
8308
8953
  function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
8309
8954
  return _ctx.visible ? (openBlock(), createElementBlock("div", {
8310
8955
  key: 0,
8311
8956
  class: "svp-dialog-mask",
8312
- onClick: _cache[5] || (_cache[5] = withModifiers((...args) => _ctx.close && _ctx.close(...args), ["self"]))
8957
+ onClick: _cache[10] || (_cache[10] = withModifiers((...args) => _ctx.close && _ctx.close(...args), ["self"]))
8313
8958
  }, [
8314
8959
  createElementVNode("div", _hoisted_1$a, [
8315
8960
  createElementVNode("div", _hoisted_2$9, [
@@ -8328,29 +8973,86 @@ function _sfc_render$a(_ctx, _cache, $props, $setup, $data, $options) {
8328
8973
  innerHTML: _ctx.html
8329
8974
  }, null, 8, _hoisted_5$8)) : (openBlock(), createElementBlock("div", _hoisted_6$4, toDisplayString(_ctx.t("panel.empty")), 1))
8330
8975
  ]),
8331
- createElementVNode("div", _hoisted_7$4, [
8332
- _ctx.canExportPdf ? (openBlock(), createElementBlock("button", {
8976
+ _ctx.showPrintClientBar ? (openBlock(), createElementBlock("div", _hoisted_7$4, [
8977
+ createElementVNode("span", {
8978
+ class: normalizeClass(["svp-preview__status", { "is-connected": _ctx.clientStatus.connected }])
8979
+ }, toDisplayString(_ctx.clientStatus.connected ? _ctx.t("designer.printClientConnected") : _ctx.t("designer.printClientDisconnected")), 3),
8980
+ createElementVNode("button", {
8981
+ type: "button",
8982
+ class: "svp-btn",
8983
+ onClick: _cache[1] || (_cache[1] = (...args) => _ctx.toggleConnect && _ctx.toggleConnect(...args))
8984
+ }, toDisplayString(_ctx.clientStatus.connected ? _ctx.t("designer.printClientDisconnect") : _ctx.t("designer.printClientConnect")), 1),
8985
+ _ctx.clientStatus.connected && _ctx.printers.length ? withDirectives((openBlock(), createElementBlock("select", {
8333
8986
  key: 0,
8987
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => _ctx.selectedPrinter = $event),
8988
+ class: "svp-preview__printer-select"
8989
+ }, [
8990
+ (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.printers, (printer) => {
8991
+ return openBlock(), createElementBlock("option", {
8992
+ key: printer.name,
8993
+ value: printer.name
8994
+ }, toDisplayString(_ctx.formatPrinterLabel(printer)), 9, _hoisted_8$4);
8995
+ }), 128))
8996
+ ], 512)), [
8997
+ [vModelSelect, _ctx.selectedPrinter]
8998
+ ]) : _ctx.clientStatus.connected ? (openBlock(), createElementBlock("span", _hoisted_9$3, toDisplayString(_ctx.t("designer.printClientNoPrinters")), 1)) : createCommentVNode("", true)
8999
+ ])) : createCommentVNode("", true),
9000
+ _ctx.canBatchPrint ? (openBlock(), createElementBlock("div", _hoisted_10$2, [
9001
+ createElementVNode("label", _hoisted_11$1, [
9002
+ createTextVNode(toDisplayString(_ctx.t("designer.batchCopies")) + " ", 1),
9003
+ withDirectives(createElementVNode("input", {
9004
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => _ctx.batchCopies = $event),
9005
+ type: "number",
9006
+ min: "1",
9007
+ max: "999",
9008
+ class: "svp-preview__batch-input"
9009
+ }, null, 512), [
9010
+ [
9011
+ vModelText,
9012
+ _ctx.batchCopies,
9013
+ void 0,
9014
+ { number: true }
9015
+ ]
9016
+ ])
9017
+ ]),
9018
+ createElementVNode("span", _hoisted_12$1, toDisplayString(_ctx.batchHintText), 1)
9019
+ ])) : createCommentVNode("", true),
9020
+ createElementVNode("div", _hoisted_13$1, [
9021
+ _ctx.canBatchPrint ? (openBlock(), createElementBlock("button", {
9022
+ key: 0,
9023
+ type: "button",
9024
+ class: "svp-btn is-primary",
9025
+ disabled: _ctx.batchPrinting,
9026
+ onClick: _cache[4] || (_cache[4] = (...args) => _ctx.onBatchPrint && _ctx.onBatchPrint(...args))
9027
+ }, toDisplayString(_ctx.batchPrinting ? _ctx.t("designer.batchPrinting") : _ctx.t("designer.batchPrint")), 9, _hoisted_14$1)) : createCommentVNode("", true),
9028
+ _ctx.canSilentPrint ? (openBlock(), createElementBlock("button", {
9029
+ key: 1,
9030
+ type: "button",
9031
+ class: "svp-btn",
9032
+ onClick: _cache[5] || (_cache[5] = (...args) => _ctx.onSilentPrint && _ctx.onSilentPrint(...args))
9033
+ }, toDisplayString(_ctx.t("designer.silentPrint")), 1)) : createCommentVNode("", true),
9034
+ _ctx.canBrowserPrint ? (openBlock(), createElementBlock("button", {
9035
+ key: 2,
8334
9036
  type: "button",
8335
9037
  class: "svp-btn",
8336
- onClick: _cache[1] || (_cache[1] = (...args) => _ctx.onPdf && _ctx.onPdf(...args))
9038
+ onClick: _cache[6] || (_cache[6] = (...args) => _ctx.onPrint && _ctx.onPrint(...args))
9039
+ }, toDisplayString(_ctx.t("designer.browserPrint")), 1)) : createCommentVNode("", true),
9040
+ _ctx.canExportPdf ? (openBlock(), createElementBlock("button", {
9041
+ key: 3,
9042
+ type: "button",
9043
+ class: "svp-btn",
9044
+ onClick: _cache[7] || (_cache[7] = (...args) => _ctx.onPdf && _ctx.onPdf(...args))
8337
9045
  }, toDisplayString(_ctx.t("designer.pdf")), 1)) : createCommentVNode("", true),
8338
9046
  _ctx.canExportImage ? (openBlock(), createElementBlock("button", {
8339
- key: 1,
9047
+ key: 4,
8340
9048
  type: "button",
8341
9049
  class: "svp-btn",
8342
- onClick: _cache[2] || (_cache[2] = (...args) => _ctx.onImage && _ctx.onImage(...args))
9050
+ onClick: _cache[8] || (_cache[8] = (...args) => _ctx.onImage && _ctx.onImage(...args))
8343
9051
  }, toDisplayString(_ctx.t("designer.image")), 1)) : createCommentVNode("", true),
8344
- _ctx.canPrint ? (openBlock(), createElementBlock("button", {
8345
- key: 2,
8346
- type: "button",
8347
- class: "svp-btn is-primary",
8348
- onClick: _cache[3] || (_cache[3] = (...args) => _ctx.onPrint && _ctx.onPrint(...args))
8349
- }, toDisplayString(_ctx.t("designer.print")), 1)) : createCommentVNode("", true),
8350
9052
  createElementVNode("button", {
8351
9053
  type: "button",
8352
9054
  class: "svp-btn",
8353
- onClick: _cache[4] || (_cache[4] = (...args) => _ctx.close && _ctx.close(...args))
9055
+ onClick: _cache[9] || (_cache[9] = (...args) => _ctx.close && _ctx.close(...args))
8354
9056
  }, toDisplayString(_ctx.t("designer.cancel")), 1)
8355
9057
  ])
8356
9058
  ])
@@ -8443,10 +9145,10 @@ const _sfc_main$9 = defineComponent({
8443
9145
  if (ta && lines) lines.scrollTop = ta.scrollTop;
8444
9146
  }
8445
9147
  function doClear() {
8446
- var _a;
9148
+ var _a2;
8447
9149
  text.value = variant.value === "template" ? JSON.stringify(EMPTY_TEMPLATE_JSON, null, 2) : "{}";
8448
9150
  error.value = "";
8449
- (_a = textareaRef.value) == null ? void 0 : _a.focus();
9151
+ (_a2 = textareaRef.value) == null ? void 0 : _a2.focus();
8450
9152
  }
8451
9153
  async function doCopy() {
8452
9154
  try {
@@ -8997,25 +9699,25 @@ const _sfc_main$7 = defineComponent({
8997
9699
  },
8998
9700
  emits: ["update:visible", "close"],
8999
9701
  setup(props, { emit }) {
9000
- var _a, _b;
9702
+ var _a2, _b2;
9001
9703
  const boxRef = ref(null);
9002
9704
  const { t } = useI18n();
9003
9705
  const designerUi = useDesignerUi();
9004
9706
  const styleOverrides = computed(() => props.styleOptionKey ? resolvePanelDragBoxOptions(props.styleOptionKey, designerUi == null ? void 0 : designerUi.styleOption.value) : null);
9005
9707
  const resolvedTitle = computed(() => {
9006
- var _a2;
9007
- return ((_a2 = styleOverrides.value) == null ? void 0 : _a2.title) || props.title;
9708
+ var _a3;
9709
+ return ((_a3 = styleOverrides.value) == null ? void 0 : _a3.title) || props.title;
9008
9710
  });
9009
9711
  const draggable = computed(() => {
9010
- var _a2;
9011
- return ((_a2 = styleOverrides.value) == null ? void 0 : _a2.draggable) ?? true;
9712
+ var _a3;
9713
+ return ((_a3 = styleOverrides.value) == null ? void 0 : _a3.draggable) ?? true;
9012
9714
  });
9013
9715
  const showFold = computed(() => props.foldable);
9014
9716
  const showClose = computed(() => props.closable ?? !!props.panelKey);
9015
9717
  const dragBoxOptions = reactive({
9016
9718
  key: props.storageKey || void 0,
9017
- layoutKey: ((_a = styleOverrides.value) == null ? void 0 : _a.layoutKey) || props.layoutKey || void 0,
9018
- layoutSpec: (_b = styleOverrides.value) == null ? void 0 : _b.layoutSpec,
9719
+ layoutKey: ((_a2 = styleOverrides.value) == null ? void 0 : _a2.layoutKey) || props.layoutKey || void 0,
9720
+ layoutSpec: (_b2 = styleOverrides.value) == null ? void 0 : _b2.layoutSpec,
9019
9721
  defaultX: props.defaultX,
9020
9722
  defaultY: props.defaultY,
9021
9723
  defaultWidth: props.width,
@@ -9032,8 +9734,8 @@ const _sfc_main$7 = defineComponent({
9032
9734
  }, { immediate: true });
9033
9735
  watch(
9034
9736
  () => {
9035
- var _a2;
9036
- return (_a2 = styleOverrides.value) == null ? void 0 : _a2.layoutSpec;
9737
+ var _a3;
9738
+ return (_a3 = styleOverrides.value) == null ? void 0 : _a3.layoutSpec;
9037
9739
  },
9038
9740
  (spec) => {
9039
9741
  dragBoxOptions.layoutSpec = spec;
@@ -9041,8 +9743,8 @@ const _sfc_main$7 = defineComponent({
9041
9743
  );
9042
9744
  watch(
9043
9745
  () => {
9044
- var _a2;
9045
- return (_a2 = styleOverrides.value) == null ? void 0 : _a2.layoutKey;
9746
+ var _a3;
9747
+ return (_a3 = styleOverrides.value) == null ? void 0 : _a3.layoutKey;
9046
9748
  },
9047
9749
  (key) => {
9048
9750
  dragBoxOptions.layoutKey = key || props.layoutKey || void 0;
@@ -9066,8 +9768,8 @@ const _sfc_main$7 = defineComponent({
9066
9768
  }
9067
9769
  );
9068
9770
  const boxStyle = computed(() => {
9069
- var _a2;
9070
- const extra = { ...((_a2 = styleOverrides.value) == null ? void 0 : _a2.boxStyleExtra) ?? {} };
9771
+ var _a3;
9772
+ const extra = { ...((_a3 = styleOverrides.value) == null ? void 0 : _a3.boxStyleExtra) ?? {} };
9071
9773
  const isFixed = extra.position === "fixed";
9072
9774
  if (!isFixed) {
9073
9775
  delete extra.left;
@@ -9084,11 +9786,11 @@ const _sfc_main$7 = defineComponent({
9084
9786
  };
9085
9787
  });
9086
9788
  const bodyStyle = computed(() => {
9087
- var _a2;
9789
+ var _a3;
9088
9790
  return {
9089
9791
  padding: props.bodyPadding || void 0,
9090
9792
  ...props.bodyStyleExtra,
9091
- ...(_a2 = styleOverrides.value) == null ? void 0 : _a2.bodyStyleExtra
9793
+ ...(_a3 = styleOverrides.value) == null ? void 0 : _a3.bodyStyleExtra
9092
9794
  };
9093
9795
  });
9094
9796
  function onClose() {
@@ -9311,11 +10013,11 @@ const _sfc_main$5 = defineComponent({
9311
10013
  });
9312
10014
  }
9313
10015
  function refresh() {
9314
- var _a;
10016
+ var _a2;
9315
10017
  const map = miniMapRef.value;
9316
10018
  const host = document.getElementById(DESIGN_CONTAINER_ID);
9317
10019
  const scroller = host == null ? void 0 : host.parentElement;
9318
- const paper = (_a = host == null ? void 0 : host.querySelector) == null ? void 0 : _a.call(host, ".hiprint-printPaper");
10020
+ const paper = (_a2 = host == null ? void 0 : host.querySelector) == null ? void 0 : _a2.call(host, ".hiprint-printPaper");
9319
10021
  if (!map || !scroller || !paper) return;
9320
10022
  const mapW = map.clientWidth;
9321
10023
  const mapH = map.clientHeight;
@@ -9795,10 +10497,10 @@ const _sfc_main$1 = defineComponent({
9795
10497
  }
9796
10498
  };
9797
10499
  const activeTheme = computed(() => {
9798
- var _a, _b;
10500
+ var _a2, _b2;
9799
10501
  if (typeof props.theme === "string") return props.theme;
9800
- if (Array.isArray(props.theme)) return ((_a = props.theme[0]) == null ? void 0 : _a.theme) || "svpLight";
9801
- return ((_b = props.theme) == null ? void 0 : _b.theme) || "svpLight";
10502
+ if (Array.isArray(props.theme)) return ((_a2 = props.theme[0]) == null ? void 0 : _a2.theme) || "svpLight";
10503
+ return ((_b2 = props.theme) == null ? void 0 : _b2.theme) || "svpLight";
9802
10504
  });
9803
10505
  const { redraw: redrawRuler } = useRuler({
9804
10506
  canvasX: () => rulerXRef.value,
@@ -9815,9 +10517,9 @@ const _sfc_main$1 = defineComponent({
9815
10517
  return Array.isArray(json) && json.length > 0;
9816
10518
  }
9817
10519
  function resolveInitialTemplate() {
9818
- var _a;
10520
+ var _a2;
9819
10521
  if (templateHasPanels(props.template)) return props.template;
9820
- const saved = (_a = utils.loadSaved) == null ? void 0 : _a.call(utils);
10522
+ const saved = (_a2 = utils.loadSaved) == null ? void 0 : _a2.call(utils);
9821
10523
  if (saved && templateHasPanels(saved)) return saved;
9822
10524
  return props.template;
9823
10525
  }
@@ -9844,7 +10546,7 @@ const _sfc_main$1 = defineComponent({
9844
10546
  applyStyleOption(props.styleOption);
9845
10547
  }
9846
10548
  function buildDesigner() {
9847
- var _a;
10549
+ var _a2;
9848
10550
  utils.newDesigner(
9849
10551
  {
9850
10552
  template: resolveInitialTemplate(),
@@ -9861,13 +10563,13 @@ const _sfc_main$1 = defineComponent({
9861
10563
  utils.plugins.run("onDesigned", payload).catch(() => {
9862
10564
  });
9863
10565
  utils.setPreview(previewRef.value);
9864
- if ((_a = props.designOptions) == null ? void 0 : _a.adaptToSize) {
10566
+ if ((_a2 = props.designOptions) == null ? void 0 : _a2.adaptToSize) {
9865
10567
  requestAnimationFrame(() => utils.adaptToSize());
9866
10568
  }
9867
10569
  }
9868
10570
  let resizeHandler = null;
9869
10571
  onMounted(async () => {
9870
- var _a;
10572
+ var _a2;
9871
10573
  setLocale(props.lang);
9872
10574
  designerStore.lang = props.lang;
9873
10575
  designerStore.theme = activeTheme.value;
@@ -9883,10 +10585,13 @@ const _sfc_main$1 = defineComponent({
9883
10585
  utils.buildByHtml();
9884
10586
  } catch {
9885
10587
  }
9886
- if ((_a = props.designOptions) == null ? void 0 : _a.adaptToSize) {
10588
+ if ((_a2 = props.designOptions) == null ? void 0 : _a2.adaptToSize) {
9887
10589
  resizeHandler = () => utils.adaptToSize();
9888
10590
  window.addEventListener("resize", resizeHandler);
9889
10591
  }
10592
+ if (props.autoConnect) {
10593
+ utils.setConnect(true);
10594
+ }
9890
10595
  });
9891
10596
  onBeforeUnmount(() => {
9892
10597
  utils.shortcuts.unmount();
@@ -9925,8 +10630,8 @@ const _sfc_main$1 = defineComponent({
9925
10630
  utils.import();
9926
10631
  }
9927
10632
  function handlePreview() {
9928
- var _a, _b;
9929
- (_b = (_a = previewRef.value) == null ? void 0 : _a.open) == null ? void 0 : _b.call(_a);
10633
+ var _a2, _b2;
10634
+ (_b2 = (_a2 = previewRef.value) == null ? void 0 : _a2.open) == null ? void 0 : _b2.call(_a2);
9930
10635
  }
9931
10636
  return {
9932
10637
  DESIGN_CONTAINER_ID,
@@ -10094,7 +10799,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
10094
10799
  }
10095
10800
  const Ruler = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
10096
10801
  const pluginApiPdf = (opts = {}) => {
10097
- const plugin = {
10802
+ const plugin2 = {
10098
10803
  name: "plugin-api-pdf",
10099
10804
  description: "Exports the current template as a PDF document.",
10100
10805
  config: { ...opts },
@@ -10128,10 +10833,10 @@ const pluginApiPdf = (opts = {}) => {
10128
10833
  }
10129
10834
  ]
10130
10835
  };
10131
- return plugin;
10836
+ return plugin2;
10132
10837
  };
10133
10838
  const pluginApiImage = (opts = {}) => {
10134
- const plugin = {
10839
+ const plugin2 = {
10135
10840
  name: "plugin-api-image",
10136
10841
  description: "Exports the current template as PNG / JPEG.",
10137
10842
  config: { type: "png", ...opts },
@@ -10158,7 +10863,7 @@ const pluginApiImage = (opts = {}) => {
10158
10863
  }
10159
10864
  ]
10160
10865
  };
10161
- return plugin;
10866
+ return plugin2;
10162
10867
  };
10163
10868
  function defaultEditor(source, ctx) {
10164
10869
  return new Promise((resolve) => {
@@ -10199,7 +10904,7 @@ function defaultEditor(source, ctx) {
10199
10904
  }
10200
10905
  const pluginViewCodeEdit = (opts = {}) => {
10201
10906
  const editor = opts.editor ?? defaultEditor;
10202
- const plugin = {
10907
+ const plugin2 = {
10203
10908
  name: "plugin-view-code-edit",
10204
10909
  description: "Provides a small in-browser editor for `function` options.",
10205
10910
  config: { ...opts },
@@ -10209,18 +10914,18 @@ const pluginViewCodeEdit = (opts = {}) => {
10209
10914
  name: "editor-create-print-element",
10210
10915
  priority: 100,
10211
10916
  run: async (option, _printElement, _ev) => {
10212
- var _a;
10917
+ var _a2;
10213
10918
  if (!option || typeof option !== "object") return;
10214
10919
  if (option.type !== "function" && option.editor !== "code") return;
10215
10920
  const next = await editor(String(option.value ?? ""), { name: option.name ?? "function" });
10216
10921
  if (next == null) return;
10217
10922
  option.value = next;
10218
- (_a = option == null ? void 0 : option.onChange) == null ? void 0 : _a.call(option, next);
10923
+ (_a2 = option == null ? void 0 : option.onChange) == null ? void 0 : _a2.call(option, next);
10219
10924
  }
10220
10925
  }
10221
10926
  ]
10222
10927
  };
10223
- return plugin;
10928
+ return plugin2;
10224
10929
  };
10225
10930
  const index = {
10226
10931
  install(app) {
@@ -10266,6 +10971,7 @@ export {
10266
10971
  PageStructurePanel,
10267
10972
  PluginManager,
10268
10973
  Preview,
10974
+ PrintClient,
10269
10975
  PropertiesPanel,
10270
10976
  Provider,
10271
10977
  Ruler,
@@ -10281,18 +10987,22 @@ export {
10281
10987
  ZOOM_MIN,
10282
10988
  ZOOM_STEP,
10283
10989
  applyStyleOption,
10990
+ autoConnect,
10991
+ batchPrint,
10284
10992
  buildByHtml,
10285
10993
  buildPrintDataFromForm,
10286
10994
  createPrintDataFormState,
10287
10995
  index as default,
10288
- defaultElementTypeProvider2 as defaultElementTypeProvider,
10996
+ defaultElementTypeProvider,
10289
10997
  designerStore,
10998
+ disAutoConnect,
10290
10999
  elementTypeKey,
10291
11000
  enUS,
10292
11001
  extractTemplateFields,
10293
11002
  getLocaleList,
11003
+ getPrintClient,
10294
11004
  headerElementsFromCatalogue,
10295
- hiprint2 as hiprint,
11005
+ hiprint,
10296
11006
  iconForElement,
10297
11007
  iconForElementKey,
10298
11008
  iconForHeaderTab,