yh-hiprint 2.3.5 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiprintDesigner.vue +494 -86
- package/hooks/useHiprint.js +48 -27
- package/libs/jquery.js +1 -0
- package/libs/jsbarcode/JsBarcode.js +225 -251
- package/libs/jsbarcode/barcodes/Barcode.js +9 -17
- package/libs/jsbarcode/barcodes/CODE128/CODE128.js +93 -133
- package/libs/jsbarcode/barcodes/CODE128/CODE128A.js +10 -38
- package/libs/jsbarcode/barcodes/CODE128/CODE128B.js +10 -38
- package/libs/jsbarcode/barcodes/CODE128/CODE128C.js +10 -38
- package/libs/jsbarcode/barcodes/CODE128/CODE128_AUTO.js +10 -36
- package/libs/jsbarcode/barcodes/CODE128/auto.js +32 -37
- package/libs/jsbarcode/barcodes/CODE128/constants.js +47 -30
- package/libs/jsbarcode/barcodes/CODE128/index.js +5 -28
- package/libs/jsbarcode/barcodes/CODE39/index.js +61 -61
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN.js +58 -78
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN13.js +66 -95
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN2.js +22 -50
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN5.js +29 -54
- package/libs/jsbarcode/barcodes/EAN_UPC/EAN8.js +42 -66
- package/libs/jsbarcode/barcodes/EAN_UPC/UPC.js +92 -125
- package/libs/jsbarcode/barcodes/EAN_UPC/UPCE.js +134 -142
- package/libs/jsbarcode/barcodes/EAN_UPC/constants.js +32 -21
- package/libs/jsbarcode/barcodes/EAN_UPC/encoder.js +11 -18
- package/libs/jsbarcode/barcodes/EAN_UPC/index.js +8 -39
- package/libs/jsbarcode/barcodes/GenericBarcode/index.js +16 -49
- package/libs/jsbarcode/barcodes/ITF/ITF.js +31 -63
- package/libs/jsbarcode/barcodes/ITF/ITF14.js +18 -40
- package/libs/jsbarcode/barcodes/ITF/constants.js +6 -8
- package/libs/jsbarcode/barcodes/ITF/index.js +3 -18
- package/libs/jsbarcode/barcodes/MSI/MSI.js +31 -57
- package/libs/jsbarcode/barcodes/MSI/MSI10.js +7 -30
- package/libs/jsbarcode/barcodes/MSI/MSI1010.js +10 -33
- package/libs/jsbarcode/barcodes/MSI/MSI11.js +7 -30
- package/libs/jsbarcode/barcodes/MSI/MSI1110.js +10 -33
- package/libs/jsbarcode/barcodes/MSI/checksums.js +11 -17
- package/libs/jsbarcode/barcodes/MSI/index.js +6 -33
- package/libs/jsbarcode/barcodes/codabar/index.js +49 -78
- package/libs/jsbarcode/barcodes/index.js +20 -33
- package/libs/jsbarcode/barcodes/pharmacode/index.js +32 -62
- package/libs/jsbarcode/exceptions/ErrorHandler.js +28 -43
- package/libs/jsbarcode/exceptions/exceptions.js +21 -59
- package/libs/jsbarcode/help/fixOptions.js +3 -9
- package/libs/jsbarcode/help/getOptionsFromElement.js +10 -23
- package/libs/jsbarcode/help/getRenderProperties.js +63 -69
- package/libs/jsbarcode/help/linearizeEncodings.js +8 -13
- package/libs/jsbarcode/help/merge.js +1 -11
- package/libs/jsbarcode/help/optionsFromStrings.js +19 -15
- package/libs/jsbarcode/options/defaults.js +2 -7
- package/libs/jsbarcode/renderers/canvas.js +106 -127
- package/libs/jsbarcode/renderers/index.js +4 -20
- package/libs/jsbarcode/renderers/object.js +7 -23
- package/libs/jsbarcode/renderers/shared.js +32 -39
- package/libs/jsbarcode/renderers/svg.js +136 -154
- package/package.json +1 -1
- package/libs/jsbarcode/barcodes/index.tmp.js +0 -33
package/hooks/useHiprint.js
CHANGED
|
@@ -6,12 +6,12 @@ import "../libs/hiprint.config.js";
|
|
|
6
6
|
// 样式
|
|
7
7
|
import "../libs/css/hiprint.css";
|
|
8
8
|
import "../libs/css/print-lock.css";
|
|
9
|
-
import { ref, computed, watch } from "vue";
|
|
9
|
+
import { ref, computed, watch, reactive, nextTick } from "vue";
|
|
10
10
|
|
|
11
11
|
export const hiprint = h;
|
|
12
12
|
export const defaultElementTypeProvider = p;
|
|
13
13
|
|
|
14
|
-
export function print(provider = defaultElementTypeProvider, template, ...args) {
|
|
14
|
+
export function print (provider = defaultElementTypeProvider, template, ...args) {
|
|
15
15
|
hiprint.init({
|
|
16
16
|
providers: [new provider()],
|
|
17
17
|
});
|
|
@@ -22,7 +22,7 @@ export function print(provider = defaultElementTypeProvider, template, ...args)
|
|
|
22
22
|
return hiprintTemplate;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function print2(provider = defaultElementTypeProvider, template, ...args) {
|
|
25
|
+
export function print2 (provider = defaultElementTypeProvider, template, ...args) {
|
|
26
26
|
hiprint.init({
|
|
27
27
|
providers: [new provider()],
|
|
28
28
|
});
|
|
@@ -33,11 +33,28 @@ export function print2(provider = defaultElementTypeProvider, template, ...args)
|
|
|
33
33
|
return hiprintTemplate;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function usePaper() {
|
|
36
|
+
export function usePaper () {
|
|
37
37
|
const paperType = ref("A4");
|
|
38
|
+
const paperTypeName = computed(() => {
|
|
39
|
+
const paperTypeObj = paperTypesObj.find((item) => item.value === paperType.value);
|
|
40
|
+
if (paperTypeObj) {
|
|
41
|
+
return paperTypeObj.label;
|
|
42
|
+
} else {
|
|
43
|
+
return "自定义";
|
|
44
|
+
}
|
|
45
|
+
});
|
|
38
46
|
const paperWidth = ref(210);
|
|
39
47
|
const paperHeight = ref(296.6);
|
|
40
48
|
|
|
49
|
+
const paperTypesObj = reactive([
|
|
50
|
+
{ label: "A3", value: "A3" },
|
|
51
|
+
{ label: "A4", value: "A4" },
|
|
52
|
+
{ label: "A5", value: "A5" },
|
|
53
|
+
{ label: "B3", value: "B3" },
|
|
54
|
+
{ label: "B4", value: "B4" },
|
|
55
|
+
{ label: "B5", value: "B5" },
|
|
56
|
+
]);
|
|
57
|
+
|
|
41
58
|
const paperTypes = {
|
|
42
59
|
A3: {
|
|
43
60
|
width: 420,
|
|
@@ -65,7 +82,7 @@ export function usePaper() {
|
|
|
65
82
|
},
|
|
66
83
|
};
|
|
67
84
|
|
|
68
|
-
function setPaper(type, callback) {
|
|
85
|
+
function setPaper (type, callback) {
|
|
69
86
|
if (type !== "other") {
|
|
70
87
|
let { width, height } = paperTypes[type];
|
|
71
88
|
paperWidth.value = width;
|
|
@@ -74,33 +91,37 @@ export function usePaper() {
|
|
|
74
91
|
callback();
|
|
75
92
|
}
|
|
76
93
|
|
|
77
|
-
watch([paperWidth, paperHeight], (width, height) => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
watch([paperWidth, paperHeight], ([width, height], [oldW, oldH]) => {
|
|
95
|
+
nextTick(() => {
|
|
96
|
+
if (width === 420 && height === 297) {
|
|
97
|
+
paperType.value = "A3";
|
|
98
|
+
} else if (width === 210 && height === 297) {
|
|
99
|
+
paperType.value = "A4";
|
|
100
|
+
} else if (width === 210 && height === 148) {
|
|
101
|
+
paperType.value = "A5";
|
|
102
|
+
} else if (width === 500 && height === 353) {
|
|
103
|
+
paperType.value = "B3";
|
|
104
|
+
} else if (width === 250 && height === 353) {
|
|
105
|
+
paperType.value = "B4";
|
|
106
|
+
} else if (width === 250 && height === 176) {
|
|
107
|
+
paperType.value = "B5";
|
|
108
|
+
} else {
|
|
109
|
+
paperType.value = "other";
|
|
110
|
+
}
|
|
111
|
+
});
|
|
93
112
|
});
|
|
94
113
|
|
|
95
114
|
return {
|
|
96
115
|
paperType,
|
|
97
116
|
paperWidth,
|
|
98
117
|
paperHeight,
|
|
118
|
+
paperTypesObj,
|
|
119
|
+
paperTypeName,
|
|
99
120
|
setPaper,
|
|
100
121
|
};
|
|
101
122
|
}
|
|
102
123
|
|
|
103
|
-
export function useScale(callback) {
|
|
124
|
+
export function useScale (callback) {
|
|
104
125
|
const scaleValue = ref(1);
|
|
105
126
|
const scalePercentage = computed(() => {
|
|
106
127
|
return `${(scaleValue.value * 100).toFixed(0)}%`;
|
|
@@ -111,11 +132,11 @@ export function useScale(callback) {
|
|
|
111
132
|
const canZoomOut = computed(() => {
|
|
112
133
|
return scaleValue.value < 4;
|
|
113
134
|
});
|
|
114
|
-
function zoomIn() {
|
|
135
|
+
function zoomIn () {
|
|
115
136
|
scaleValue.value = scaleValue.value - 0.1;
|
|
116
137
|
callback();
|
|
117
138
|
}
|
|
118
|
-
function zoomOut() {
|
|
139
|
+
function zoomOut () {
|
|
119
140
|
scaleValue.value = scaleValue.value + 0.1;
|
|
120
141
|
callback();
|
|
121
142
|
}
|
|
@@ -129,9 +150,9 @@ export function useScale(callback) {
|
|
|
129
150
|
};
|
|
130
151
|
}
|
|
131
152
|
|
|
132
|
-
export function useDataSource(axios) {
|
|
153
|
+
export function useDataSource (axios) {
|
|
133
154
|
const detailData = ref();
|
|
134
|
-
function getDetail(id) {
|
|
155
|
+
function getDetail (id) {
|
|
135
156
|
return axios
|
|
136
157
|
.request({
|
|
137
158
|
url: `/printTemplate/get/${id}`,
|
|
@@ -171,7 +192,7 @@ export function useDataSource(axios) {
|
|
|
171
192
|
});
|
|
172
193
|
const dataSourceForm = ref([]);
|
|
173
194
|
const codeMapDataSource = ref({});
|
|
174
|
-
function getDataSourceList() {
|
|
195
|
+
function getDataSourceList () {
|
|
175
196
|
return axios
|
|
176
197
|
.request({
|
|
177
198
|
url: "/printTemplate/getDsList",
|
package/libs/jquery.js
CHANGED
|
@@ -10616,5 +10616,6 @@ jQuery.trim = function (text) {
|
|
|
10616
10616
|
(text + "").replace(rtrim, "$1");
|
|
10617
10617
|
};
|
|
10618
10618
|
|
|
10619
|
+
export default jQuery;
|
|
10619
10620
|
|
|
10620
10621
|
window.hiprintJQuery = jQuery;
|
|
@@ -1,251 +1,225 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
renderer.render();
|
|
227
|
-
|
|
228
|
-
if (renderProperties.afterRender) {
|
|
229
|
-
renderProperties.afterRender();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// Export to browser
|
|
234
|
-
if (typeof window !== "undefined") {
|
|
235
|
-
window.JsBarcode = JsBarcode;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// Export to jQuery
|
|
239
|
-
/*global jQuery */
|
|
240
|
-
if (typeof hiprintJQuery !== 'undefined') {
|
|
241
|
-
hiprintJQuery.fn.JsBarcode = function (content, options) {
|
|
242
|
-
var elementArray = [];
|
|
243
|
-
hiprintJQuery(this).each(function () {
|
|
244
|
-
elementArray.push(this);
|
|
245
|
-
});
|
|
246
|
-
return JsBarcode(elementArray, content, options);
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Export to commonJS
|
|
251
|
-
module.exports = JsBarcode;
|
|
1
|
+
// Import all the barcodes
|
|
2
|
+
import barcodes from './barcodes/';
|
|
3
|
+
|
|
4
|
+
// Help functions
|
|
5
|
+
import merge from './help/merge.js';
|
|
6
|
+
import linearizeEncodings from './help/linearizeEncodings.js';
|
|
7
|
+
import fixOptions from './help/fixOptions.js';
|
|
8
|
+
import getRenderProperties from './help/getRenderProperties.js';
|
|
9
|
+
import optionsFromStrings from './help/optionsFromStrings.js';
|
|
10
|
+
|
|
11
|
+
// Exceptions
|
|
12
|
+
import ErrorHandler from './exceptions/ErrorHandler.js';
|
|
13
|
+
import { InvalidInputException, NoElementException } from './exceptions/exceptions.js';
|
|
14
|
+
|
|
15
|
+
// Default values
|
|
16
|
+
import defaults from './options/defaults.js';
|
|
17
|
+
|
|
18
|
+
// The protype of the object returned from the JsBarcode() call
|
|
19
|
+
let API = function () {};
|
|
20
|
+
|
|
21
|
+
// The first call of the library API
|
|
22
|
+
// Will return an object with all barcodes calls and the data that is used
|
|
23
|
+
// by the renderers
|
|
24
|
+
let JsBarcode = function (element, text, options) {
|
|
25
|
+
var api = new API();
|
|
26
|
+
|
|
27
|
+
if (typeof element === "undefined") {
|
|
28
|
+
throw Error("No element to render on was provided.");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Variables that will be pased through the API calls
|
|
32
|
+
api._renderProperties = getRenderProperties(element);
|
|
33
|
+
api._encodings = [];
|
|
34
|
+
api._options = defaults;
|
|
35
|
+
api._errorHandler = new ErrorHandler(api);
|
|
36
|
+
|
|
37
|
+
// If text is set, use the simple syntax (render the barcode directly)
|
|
38
|
+
if (typeof text !== "undefined") {
|
|
39
|
+
options = options || {};
|
|
40
|
+
|
|
41
|
+
if (!options.format) {
|
|
42
|
+
options.format = autoSelectBarcode();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
api.options(options)[options.format](text, options).render();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return api;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// To make tests work TODO: remove
|
|
52
|
+
JsBarcode.getModule = function (name) {
|
|
53
|
+
return barcodes[name];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Register all barcodes
|
|
57
|
+
for (var name in barcodes) {
|
|
58
|
+
if (barcodes.hasOwnProperty(name)) { // Security check if the propery is a prototype property
|
|
59
|
+
registerBarcode(barcodes, name);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function registerBarcode (barcodes, name) {
|
|
63
|
+
API.prototype[name] =
|
|
64
|
+
API.prototype[name.toUpperCase()] =
|
|
65
|
+
API.prototype[name.toLowerCase()] =
|
|
66
|
+
function (text, options) {
|
|
67
|
+
var api = this;
|
|
68
|
+
return api._errorHandler.wrapBarcodeCall(function () {
|
|
69
|
+
// Ensure text is options.text
|
|
70
|
+
options.text = typeof options.text === 'undefined' ? undefined : '' + options.text;
|
|
71
|
+
|
|
72
|
+
var newOptions = merge(api._options, options);
|
|
73
|
+
newOptions = optionsFromStrings(newOptions);
|
|
74
|
+
var Encoder = barcodes[name];
|
|
75
|
+
var encoded = encode(text, Encoder, newOptions);
|
|
76
|
+
api._encodings.push(encoded);
|
|
77
|
+
|
|
78
|
+
return api;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// encode() handles the Encoder call and builds the binary string to be rendered
|
|
84
|
+
function encode (text, Encoder, options) {
|
|
85
|
+
// Ensure that text is a string
|
|
86
|
+
text = "" + text;
|
|
87
|
+
|
|
88
|
+
var encoder = new Encoder(text, options);
|
|
89
|
+
|
|
90
|
+
// If the input is not valid for the encoder, throw error.
|
|
91
|
+
// If the valid callback option is set, call it instead of throwing error
|
|
92
|
+
if (!encoder.valid()) {
|
|
93
|
+
throw new InvalidInputException(encoder.constructor.name, text);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Make a request for the binary data (and other infromation) that should be rendered
|
|
97
|
+
var encoded = encoder.encode();
|
|
98
|
+
|
|
99
|
+
// Encodings can be nestled like [[1-1, 1-2], 2, [3-1, 3-2]
|
|
100
|
+
// Convert to [1-1, 1-2, 2, 3-1, 3-2]
|
|
101
|
+
encoded = linearizeEncodings(encoded);
|
|
102
|
+
|
|
103
|
+
// Merge
|
|
104
|
+
for (let i = 0; i < encoded.length; i++) {
|
|
105
|
+
encoded[i].options = merge(options, encoded[i].options);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return encoded;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function autoSelectBarcode () {
|
|
112
|
+
// If CODE128 exists. Use it
|
|
113
|
+
if (barcodes["CODE128"]) {
|
|
114
|
+
return "CODE128";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Else, take the first (probably only) barcode
|
|
118
|
+
return Object.keys(barcodes)[0];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Sets global encoder options
|
|
122
|
+
// Added to the api by the JsBarcode function
|
|
123
|
+
API.prototype.options = function (options) {
|
|
124
|
+
this._options = merge(this._options, options);
|
|
125
|
+
return this;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Will create a blank space (usually in between barcodes)
|
|
129
|
+
API.prototype.blank = function (size) {
|
|
130
|
+
const zeroes = new Array(size + 1).join("0");
|
|
131
|
+
this._encodings.push({ data: zeroes });
|
|
132
|
+
return this;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Initialize JsBarcode on all HTML elements defined.
|
|
136
|
+
API.prototype.init = function () {
|
|
137
|
+
// Should do nothing if no elements where found
|
|
138
|
+
if (!this._renderProperties) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Make sure renderProperies is an array
|
|
143
|
+
if (!Array.isArray(this._renderProperties)) {
|
|
144
|
+
this._renderProperties = [this._renderProperties];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
var renderProperty;
|
|
148
|
+
for (let i in this._renderProperties) {
|
|
149
|
+
renderProperty = this._renderProperties[i];
|
|
150
|
+
var options = merge(this._options, renderProperty.options);
|
|
151
|
+
|
|
152
|
+
if (options.format == "auto") {
|
|
153
|
+
options.format = autoSelectBarcode();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
this._errorHandler.wrapBarcodeCall(function () {
|
|
157
|
+
var text = options.value;
|
|
158
|
+
var Encoder = barcodes[options.format.toUpperCase()];
|
|
159
|
+
var encoded = encode(text, Encoder, options);
|
|
160
|
+
|
|
161
|
+
render(renderProperty, encoded, options);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
// The render API call. Calls the real render function.
|
|
168
|
+
API.prototype.render = function () {
|
|
169
|
+
if (!this._renderProperties) {
|
|
170
|
+
throw new NoElementException();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (Array.isArray(this._renderProperties)) {
|
|
174
|
+
for (var i = 0; i < this._renderProperties.length; i++) {
|
|
175
|
+
render(this._renderProperties[i], this._encodings, this._options);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
render(this._renderProperties, this._encodings, this._options);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return this;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
API.prototype._defaults = defaults;
|
|
186
|
+
|
|
187
|
+
// Prepares the encodings and calls the renderer
|
|
188
|
+
function render (renderProperties, encodings, options) {
|
|
189
|
+
encodings = linearizeEncodings(encodings);
|
|
190
|
+
|
|
191
|
+
for (let i = 0; i < encodings.length; i++) {
|
|
192
|
+
encodings[i].options = merge(options, encodings[i].options);
|
|
193
|
+
fixOptions(encodings[i].options);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
fixOptions(options);
|
|
197
|
+
|
|
198
|
+
var Renderer = renderProperties.renderer;
|
|
199
|
+
var renderer = new Renderer(renderProperties.element, encodings, options);
|
|
200
|
+
renderer.render();
|
|
201
|
+
|
|
202
|
+
if (renderProperties.afterRender) {
|
|
203
|
+
renderProperties.afterRender();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Export to browser
|
|
208
|
+
if (typeof window !== "undefined") {
|
|
209
|
+
window.JsBarcode = JsBarcode;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Export to jQuery
|
|
213
|
+
/*global jQuery */
|
|
214
|
+
if (typeof hiprintJQuery !== 'undefined') {
|
|
215
|
+
hiprintJQuery.fn.JsBarcode = function (content, options) {
|
|
216
|
+
var elementArray = [];
|
|
217
|
+
hiprintJQuery(this).each(function () {
|
|
218
|
+
elementArray.push(this);
|
|
219
|
+
});
|
|
220
|
+
return JsBarcode(elementArray, content, options);
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Export to commonJS
|
|
225
|
+
export default JsBarcode;
|