btrz-liquid-templates 1.3.0 → 1.5.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/docs/index.md +33 -0
- package/package.json +1 -1
- package/src/escp.js +25 -1
- package/src/index.js +15 -11
package/docs/index.md
CHANGED
|
@@ -194,6 +194,39 @@ Move to next horizontal tab
|
|
|
194
194
|
{% raw%} {% escTab %} {% endraw %}
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
+
* ## escHPos
|
|
198
|
+
|
|
199
|
+
Set absolute horizontal print position
|
|
200
|
+
|
|
201
|
+
*reference **ESC $** command*
|
|
202
|
+
|
|
203
|
+
```liquid
|
|
204
|
+
{% raw%} {% escHPos pos %} {% endraw %}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### Parameters
|
|
208
|
+
|
|
209
|
+
| name | range | required | default |
|
|
210
|
+
|------|------------|----------|---------|
|
|
211
|
+
| pos | 0 <= pos <= 65535 | Y | 0 |
|
|
212
|
+
|
|
213
|
+
### Description
|
|
214
|
+
|
|
215
|
+
This command sets the absolute horizontal print position (in dots) for the next data that will be printed. It tells the printer exactly how many dots from the left margin to move the print head.
|
|
216
|
+
|
|
217
|
+
### Units
|
|
218
|
+
|
|
219
|
+
The measurement is in dots. For example, if the printer is configured such that 1 dot equals 1/60 inch, then setting **pos** to 360 would move the print head to approximately 360 dots, which could correspond to about 60 characters (if one character is roughly 6 dots wide).
|
|
220
|
+
|
|
221
|
+
### Example
|
|
222
|
+
|
|
223
|
+
Suppose you want to set the horizontal position to 360 dots
|
|
224
|
+
|
|
225
|
+
#### Usage in Template
|
|
226
|
+
|
|
227
|
+
{% raw %}{% escHPos 360 %}{% endraw %}
|
|
228
|
+
|
|
229
|
+
This will move the print head so that the next printed data starts at 360 dots from the left margin.
|
|
197
230
|
|
|
198
231
|
## Images, barcodes and QR codes
|
|
199
232
|
|
package/package.json
CHANGED
package/src/escp.js
CHANGED
|
@@ -117,6 +117,29 @@ function escTab(engine) {
|
|
|
117
117
|
}
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
+
|
|
121
|
+
function escHPos(engine) {
|
|
122
|
+
this.registerTag("escHPos", {
|
|
123
|
+
parse: function(tagToken, remainTokens) {
|
|
124
|
+
try {
|
|
125
|
+
const args = (tagToken.args || "").split(" ");
|
|
126
|
+
this.position = args[0] || 0;
|
|
127
|
+
} catch (err) {
|
|
128
|
+
this.position = args[0] || 0;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
render: async function(ctx) {
|
|
132
|
+
try {
|
|
133
|
+
const nL = String.fromCharCode(this.position & 0xFF);
|
|
134
|
+
const nH = String.fromCharCode((this.position >> 8) & 0xFF);
|
|
135
|
+
const escMoveCursor = "\x1B\x24" + nL + nH;
|
|
136
|
+
return escMoveCursor;
|
|
137
|
+
} catch (e) {
|
|
138
|
+
return "PNA";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
120
143
|
module.exports = {
|
|
121
144
|
escInitQzTray,
|
|
122
145
|
lineSpacing,
|
|
@@ -128,5 +151,6 @@ module.exports = {
|
|
|
128
151
|
escCut,
|
|
129
152
|
escEject,
|
|
130
153
|
escCondensed,
|
|
131
|
-
escTab
|
|
154
|
+
escTab,
|
|
155
|
+
escHPos
|
|
132
156
|
}
|
package/src/index.js
CHANGED
|
@@ -23,7 +23,9 @@ const {
|
|
|
23
23
|
escCondensed,
|
|
24
24
|
escNewLine,
|
|
25
25
|
escCut,
|
|
26
|
-
|
|
26
|
+
escTab,
|
|
27
|
+
escEject,
|
|
28
|
+
escHPos
|
|
27
29
|
} = require("./escp.js");
|
|
28
30
|
|
|
29
31
|
function getEngine() {
|
|
@@ -34,16 +36,16 @@ function getEngine() {
|
|
|
34
36
|
extname: ".liquid",
|
|
35
37
|
dynamicPartials: false,
|
|
36
38
|
outputEscape: (val) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
if (typeof val === "string") {
|
|
40
|
+
return val.replace(/[\\]/g, '\\\\')
|
|
41
|
+
.replace(/[\"]/g, '\\"')
|
|
42
|
+
.replace(/[\/]/g, '\\/')
|
|
43
|
+
.replace(/[\b]/g, '\\b')
|
|
44
|
+
.replace(/[\f]/g, '\\f')
|
|
45
|
+
.replace(/[\n]/g, '\\n')
|
|
46
|
+
.replace(/[\r]/g, '\\r')
|
|
47
|
+
.replace(/[\t]/g, '\\t');
|
|
48
|
+
}
|
|
47
49
|
return val;
|
|
48
50
|
}
|
|
49
51
|
});
|
|
@@ -102,6 +104,8 @@ module.exports = {
|
|
|
102
104
|
engine.plugin(escCondensed);
|
|
103
105
|
engine.plugin(escNewLine);
|
|
104
106
|
engine.plugin(escCut);
|
|
107
|
+
engine.plugin(escTab);
|
|
108
|
+
engine.plugin(escHPos);
|
|
105
109
|
engine.plugin(escEject);
|
|
106
110
|
let str = await engine.parseAndRender(liquidTemplate, data);
|
|
107
111
|
str = str.split(/\n/).map((line) => {
|