btrz-liquid-templates 1.4.0 → 1.5.1

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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-liquid-templates",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "liquidjs": "^10.20.2",
28
28
  "moment": "^2.30.1",
29
29
  "moment-timezone": "^0.5.46",
30
- "symbology": "^4.0.1",
30
+ "symbology": "4.0.1",
31
31
  "written-number": "^0.11.1"
32
32
  },
33
33
  "devDependencies": {
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
- escEject
26
+ escTab,
27
+ escEject,
28
+ escHPos
27
29
  } = require("./escp.js");
28
30
 
29
31
  function getEngine() {
@@ -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) => {