GeezerVison is showing github.com — feat(zpl): model the pending setup commands and finish the supported … · u8array/ZPLab@4aae217
File treeExpand file treeCollapse file tree Open diff view settings components/PrinterSettings
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/core/src/lib/zplGenerator.ts +15-3Lines changed: 15 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -448,6 +448,14 @@ export function planFieldEmission( | 448 | 448 | return { headerLines, bodyLines: shifted.flatMap(emitLeaf) }; | 449 | 449 | } | 450 | 450 |
| | 451 | +/** Positional-command slots with trailing empties dropped, so unset | | 452 | + * params fall back to the printer's own defaults on the wire. */ | | 453 | +export function trimTrailingEmptySlots(slots: readonly string[]): string[] { | | 454 | + const trimmed = [...slots]; | | 455 | + while (trimmed.length > 0 && trimmed[trimmed.length - 1] === "") trimmed.pop(); | | 456 | + return trimmed; | | 457 | +} | | 458 | + | 451 | 459 | export function generateZPL( | 452 | 460 | label: LabelConfig, | 453 | 461 | objects: LabelObject[], | @@ -531,6 +539,11 @@ export function generateZPL( | 531 | 539 | if (label.darkness !== undefined) lines.push(`^MD${label.darkness}`); | 532 | 540 | if (label.printOrientation) lines.push(`^PO${label.printOrientation}`); | 533 | 541 | if (label.mirror) lines.push(`^PM${label.mirror}`); | | 542 | + if (label.mapClear) lines.push(`^MC${label.mapClear}`); | | 543 | + // slewDotRows=0 is a valid explicit "no slew"; check undefined. | | 544 | + if (label.slewDotRows !== undefined) lines.push(`^PF${label.slewDotRows}`); | | 545 | + if (label.slewToHome) lines.push('^PH'); | | 546 | + if (label.programmablePause) lines.push('^PP'); | 534 | 547 | // ^LH / ^LT subtract below from per-field absolute (x,y) so emit matches editor. | 535 | 548 | const homeX = label.labelHomeX ?? 0; | 536 | 549 | const homeY = label.labelHomeY ?? 0; | @@ -552,12 +565,11 @@ export function generateZPL( | 552 | 565 | label.defaultFontHeight !== undefined || | 553 | 566 | label.defaultFontWidth !== undefined | 554 | 567 | ) { | 555 | | - const slots = [ | | 568 | + const slots = trimTrailingEmptySlots([ | 556 | 569 | label.defaultFontId ?? "", | 557 | 570 | label.defaultFontHeight !== undefined ? String(label.defaultFontHeight) : "", | 558 | 571 | label.defaultFontWidth !== undefined ? String(label.defaultFontWidth) : "", | 559 | | - ]; | 560 | | - while (slots.length > 1 && slots[slots.length - 1] === "") slots.pop(); | | 572 | + ]); | 561 | 573 | lines.push(`^CF${slots.join(",")}`); | 562 | 574 | } | 563 | 575 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/lib/zplParser.ts +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -152,8 +152,12 @@ export function parseZPL( | 152 | 152 | // ^DY font uploads are intentionally not flagged. | 153 | 153 | const replayRiskCodes = new Set(Object.keys(setupScriptHandlers)); | 154 | 154 | const deviceActionCodes = new Set([ | 155 | | - "JA", "JM", "JC", "JD", "JE", "JI", "JR", "PP", | | 155 | + "JA", "JM", "JC", "JD", "JE", "JI", "JR", | 156 | 156 | ]); | | 157 | + // ^PH/^PP are modelled per-format settings, but their tilde twins are | | 158 | + // immediate device controls; the handler map keys have no prefix, so the | | 159 | + // split happens at dispatch via the token's source char. | | 160 | + const tildeDeviceCodes = new Set(["PH", "PP"]); | 157 | 161 | Object.assign(handlers, setupScriptHandlers); | 158 | 162 | Object.assign(handlers, createLabelConfigHandlers(s, dpmm)); | 159 | 163 | Object.assign(handlers, createUnitsHandler(s, dpmm)); | @@ -323,6 +327,12 @@ export function parseZPL( | 323 | 327 | const p = rest.split(s.format.delimiterChar); | 324 | 328 | // Flag printer-config commands: lossless replay re-emits them, so they run | 325 | 329 | // on the user's printer at print/export. Recorded by code (deduped later). | | 330 | + // ~PH/~PP: flagged as device actions AND skipped entirely, or they would | | 331 | + // fall through to the unknown bucket and surface twice in the summary. | | 332 | + if (tildeDeviceCodes.has(cmd) && zpl[start] === s.format.tildeChar) { | | 333 | + deviceAction.push(`~${cmd}`); | | 334 | + continue; | | 335 | + } | 326 | 336 | if (replayRiskCodes.has(cmd)) replayRisk.push(`^${cmd}`); | 327 | 337 | else if (deviceActionCodes.has(cmd)) deviceAction.push(`^${cmd}`); | 328 | 338 | const handler = handlers[cmd] ?? wildcards.find((w) => w.matches(cmd))?.handle; | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/lib/zplParser/handlers/barcodes.ts +5-8Lines changed: 5 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -153,15 +153,12 @@ export function createBarcodeHandlers(s: ParserState): Record<string, Handler> { | 153 | 153 | B0: handleAztec, | 154 | 154 | BO: handleAztec, | 155 | 155 |
| 156 | | - // ^BVo,{mode},{symbolNumber},{totalSymbols}: Maxicode (fixed | 157 | | - // physical size, no magnification). symbolNumber/totalSymbols | 158 | | - // describe structured-append composition; we don't expose that | 159 | | - // in the editor, so the params are read but the emitted form | 160 | | - // pins them to (1, 1). | 161 | | - // ^BV orientation slot is a firmware no-op; canonicalized on emit. | 162 | | - BV(p) { | | 156 | + // ^BDm,{symbolNumber},{totalSymbols}: Maxicode (spec p106; fixed | | 157 | + // physical size, no orientation slot). Structured-append params are | | 158 | + // read but pinned to (1,1) on emit. | | 159 | + BD(p) { | 163 | 160 | field.fieldType = "maxicode"; | 164 | | - const m = int(p[1], 4); | | 161 | + const m = int(p[0], 4); | 165 | 162 | field.maxicodeMode = (m >= 2 && m <= 6 ? m : 4) as MaxicodeProps["mode"]; | 166 | 163 | }, | 167 | 164 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/lib/zplParser/handlers/labelConfig.ts +30-7Lines changed: 30 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { DARKNESS_INSTANT_RANGE, DARKNESS_PERMANENT_RANGE, MAX_LABEL_LENGTH_RANGE, SPEED_RANGE, isBackfeedSequence, isMediaFeedMode, isMediaMode, isMediaTracking, isMediaType, isPrintOrientation } from "../../../types/LabelConfig"; | | 1 | +import { DARKNESS_INSTANT_RANGE, DARKNESS_PERMANENT_RANGE, MAX_LABEL_LENGTH_RANGE, SLEW_DOT_ROWS_RANGE, SPEED_RANGE, isBackfeedPercent, isBackfeedSequence, isMediaFeedMode, isMediaMode, isMediaTracking, isMediaType, isPrintOrientation } from "../../../types/LabelConfig"; | 2 | 2 | import { parseIntOrUndef } from "../../inputParse"; | | 3 | +import { isYesNo } from "../../../types/typeHelpers"; | 3 | 4 | import type { ParserState } from "../context"; | 4 | 5 | import { dotsFor, firstChar, inRange, int, strParam } from "../helpers"; | 5 | 6 | import type { Handler } from "../types"; | @@ -38,7 +39,7 @@ export function createLabelConfigHandlers( | 38 | 39 | } | 39 | 40 | if (p.length > 3) { | 40 | 41 | const o = (p[3] ?? "").toUpperCase(); | 41 | | - if (o === "Y" || o === "N") labelConfig.overridePauseCount = o; | | 42 | + if (isYesNo(o)) labelConfig.overridePauseCount = o; | 42 | 43 | } | 43 | 44 | }, | 44 | 45 | MM(_, rest) { | @@ -65,6 +66,22 @@ export function createLabelConfigHandlers( | 65 | 66 | const mt = firstChar(rest); | 66 | 67 | if (isMediaType(mt)) labelConfig.mediaType = mt; | 67 | 68 | }, | | 69 | + MC(p) { | | 70 | + const v = strParam(p[0]); | | 71 | + if (isYesNo(v)) labelConfig.mapClear = v; | | 72 | + }, | | 73 | + PF(p) { | | 74 | + const v = inRange(parseIntOrUndef(p[0]), SLEW_DOT_ROWS_RANGE); | | 75 | + if (v !== undefined) labelConfig.slewDotRows = v; | | 76 | + }, | | 77 | + // ^PH/^PP take no parameters; the tilde forms never reach these handlers | | 78 | + // (dispatch routes them as device actions). | | 79 | + PH() { | | 80 | + labelConfig.slewToHome = true; | | 81 | + }, | | 82 | + PP() { | | 83 | + labelConfig.programmablePause = true; | | 84 | + }, | 68 | 85 | MN(p) { | 69 | 86 | // ^MNa,b: b is an optional black-mark offset for W/M modes, | 70 | 87 | // which we don't model. Reading p[0] instead of the raw rest | @@ -92,20 +109,26 @@ export function createLabelConfigHandlers( | 92 | 109 | }, | 93 | 110 | PM(_, rest) { | 94 | 111 | const m = firstChar(rest); | 95 | | - if (m === "Y" || m === "N") labelConfig.mirror = m; | | 112 | + if (isYesNo(m)) labelConfig.mirror = m; | 96 | 113 | }, | 97 | 114 | // ~SD: instant darkness set (00..30). Tilde-prefix, so the tokenizer | 98 | 115 | // drops the delimiter and this is the canonical SD handler. | 99 | 116 | SD(_, rest) { | 100 | 117 | const v = inRange(parseIntOrUndef(rest), DARKNESS_INSTANT_RANGE); | 101 | 118 | if (v !== undefined) labelConfig.instantDarkness = v; | 102 | 119 | }, | 103 | | - // ~JS: change backfeed sequence. A/B/N/O modeled; percent forms | 104 | | - // (10-90) aren't, so track them as a partial-import loss. | | 120 | + // ~JS: change backfeed sequence. Percent forms round to the nearest | | 121 | + // ten like the printer does (~JS55 -> 60, p276). | 105 | 122 | JS(_, rest) { | 106 | 123 | const v = firstChar(rest); | 107 | | - if (isBackfeedSequence(v)) labelConfig.backfeedSequence = v; | 108 | | - else if (rest) s.result.partialCmds.add("~JS"); | | 124 | + if (isBackfeedSequence(v)) { | | 125 | + labelConfig.backfeedSequence = v; | | 126 | + return; | | 127 | + } | | 128 | + const pct = inRange(parseIntOrUndef(rest), { min: 10, max: 90 }); | | 129 | + if (pct === undefined) return; | | 130 | + const rounded = Math.round(pct / 10) * 10; | | 131 | + if (isBackfeedPercent(rounded)) labelConfig.backfeedSequence = rounded; | 109 | 132 | }, | 110 | 133 | }; | 111 | 134 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/lib/zplParser/handlers/setupScript.ts +43-7Lines changed: 43 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { CLOCK_TOLERANCE_RANGE, FONT_LINKS_PATH_MAX_LEN, HEAD_CLEANING_INTERVAL_METERS, HEAD_TEST_INTERVAL_RANGE, JH_SLOT_F, JH_SLOT_G, MAINTENANCE_ALERT_DEFAULTS, MAINTENANCE_DISTANCE_MAX_BY_TYPE, MAINTENANCE_MESSAGE_MAX_LEN, PRINTER_NAME_MAX_LEN, PRINTER_PASSWORD_REGEX, TEAR_OFF_ADJUST_RANGE, isClockFormat, isClockLanguage, isConfigUpdateAction, isMaintenanceAlertPrint, isMaintenanceAlertType, isMaintenanceAlertUnit, isPrinterLocale, isZplMode, setupScriptUnsafeCharRegex } from "../../../types/PrinterProfile"; | | 1 | +import { CLOCK_TOLERANCE_RANGE, FONT_CACHE_KB_RANGE, FONT_LINKS_PATH_MAX_LEN, HEAD_CLEANING_INTERVAL_METERS, HEAD_TEST_INTERVAL_RANGE, JH_SLOT_F, JH_SLOT_G, MAINTENANCE_ALERT_DEFAULTS, MAINTENANCE_DISTANCE_MAX_BY_TYPE, MAINTENANCE_MESSAGE_MAX_LEN, PRINTER_NAME_MAX_LEN, PRINTER_PASSWORD_REGEX, TEAR_OFF_ADJUST_RANGE, isClockFormat, isClockLanguage, isConfigUpdateAction, isFontCacheType, isMaintenanceAlertPrint, isMaintenanceAlertType, isMaintenanceAlertUnit, isModeProtection, isPrinterLocale, isZplMode, setupScriptUnsafeCharRegex } from "../../../types/PrinterProfile"; | 2 | 2 | import { parseIntOrUndef } from "../../inputParse"; | | 3 | +import { isYesNo } from "../../../types/typeHelpers"; | 3 | 4 | import { parseRealtimeClock } from "../../realtimeClock"; | 4 | 5 | import type { ParserState } from "../context"; | 5 | 6 | import { inRange, strParam } from "../helpers"; | 6 | 7 | import type { Handler } from "../types"; | 7 | 8 |
| 8 | | -/** Setup-Script commands (^JZ, ^JT, ~TA, ^ST, ^KD, ^KL, ^SE, ^SZ, | 9 | | - * ^KN, ^SL, ^KP, ^MA, ^MI, ^MW, ^JH, ^JU): all write the shared | 10 | | - * `printerProfile` slice. */ | | 9 | +/** Setup-Script command handlers: all write the shared `printerProfile` slice. */ | 11 | 10 | export function createSetupScriptHandlers(s: ParserState): Record<string, Handler> { | 12 | 11 | const printerProfile = s.result.printerProfile; | 13 | 12 | return { | | 13 | + // Each ^CO is a complete command: an empty slot means the printer's own | | 14 | + // default, so it clears a value an earlier ^CO in the stream had set. | | 15 | + CO(p) { | | 16 | + const on = strParam(p[0]); | | 17 | + // A fully-empty ^CO would parse to nothing and vanish on re-emit; | | 18 | + // normalise it to its a-slot default (Y, cache on) instead. | | 19 | + if (on === "" && strParam(p[1]) === "" && strParam(p[2]) === "") { | | 20 | + printerProfile.fontCacheOn = "Y"; | | 21 | + delete printerProfile.fontCacheAddKb; | | 22 | + delete printerProfile.fontCacheType; | | 23 | + return; | | 24 | + } | | 25 | + if (on === "") delete printerProfile.fontCacheOn; | | 26 | + else if (isYesNo(on)) printerProfile.fontCacheOn = on; | | 27 | + const rawKb = strParam(p[1]); | | 28 | + if (rawKb === "") delete printerProfile.fontCacheAddKb; | | 29 | + else { | | 30 | + const kb = inRange(parseIntOrUndef(rawKb), FONT_CACHE_KB_RANGE); | | 31 | + if (kb !== undefined) printerProfile.fontCacheAddKb = kb; | | 32 | + } | | 33 | + const type = strParam(p[2]); | | 34 | + if (type === "") delete printerProfile.fontCacheType; | | 35 | + else if (isFontCacheType(type)) printerProfile.fontCacheType = type; | | 36 | + }, | | 37 | + MP(p) { | | 38 | + const v = strParam(p[0]); | | 39 | + // E re-enables all modes, wiping the protection set. It also anchors | | 40 | + // the set as absolute; without it the stream only ADDS modes and the | | 41 | + // emitter must not inject a resetting ^MPE baseline. | | 42 | + if (v === "E") { | | 43 | + printerProfile.modeProtection = []; | | 44 | + printerProfile.modeProtectionExplicit = true; | | 45 | + } else if (isModeProtection(v)) { | | 46 | + const set = printerProfile.modeProtection ?? []; | | 47 | + if (!set.includes(v)) printerProfile.modeProtection = [...set, v]; | | 48 | + } | | 49 | + }, | 14 | 50 | JZ(p) { | 15 | 51 | const v = strParam(p[0]); | 16 | | - if (v === "Y" || v === "N") printerProfile.reprintAfterError = v; | | 52 | + if (isYesNo(v)) printerProfile.reprintAfterError = v; | 17 | 53 | }, | 18 | 54 | JT(p) { | 19 | 55 | const v = inRange(parseIntOrUndef(p[0]), HEAD_TEST_INTERVAL_RANGE); | @@ -130,11 +166,11 @@ export function createSetupScriptHandlers(s: ParserState): Record<string, Handle | 130 | 166 | }, | 131 | 167 | MW(_, rest) { | 132 | 168 | const v = rest.trim().toUpperCase(); | 133 | | - if (v === "Y" || v === "N") printerProfile.headColdWarning = v; | | 169 | + if (isYesNo(v)) printerProfile.headColdWarning = v; | 134 | 170 | }, | 135 | 171 | CV(_, rest) { | 136 | 172 | const v = rest.trim().toUpperCase(); | 137 | | - if (v === "Y" || v === "N") printerProfile.codeValidation = v; | | 173 | + if (isYesNo(v)) printerProfile.codeValidation = v; | 138 | 174 | }, | 139 | 175 | PA(p) { | 140 | 176 | // ^PAa,b,c,d each 0/1; missing slot = 0 (printer default). | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/lib/zplParser/handlers/unsupported.ts -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,6 @@ export function createUnsupportedHandlers( | 20 | 20 | JE: noop, | 21 | 21 | JI: noop, | 22 | 22 | JR: noop, | 23 | | - PP: noop, | 24 | 23 | // Browser-limit factories, surface as "not loaded" findings. | 25 | 24 | HT: mkBrowserLimit("HT"), | 26 | 25 | LF: mkBrowserLimit("LF"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/registry/maxicode.ts +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ export const ALL_MODES = [2, 3, 4, 5, 6] as const; | 9 | 9 | /** Mode 4 = standard symbol, only mode without UPS-domain SCM requirement. */ | 10 | 10 | const MAXICODE_DEFAULT_MODE = 4 as const; | 11 | 11 |
| 12 | | -// No rotation prop: ^BV orientation slot is a firmware no-op (^BD has none). | | 12 | +// No rotation prop: ^BD has no orientation slot (spec p106). | 13 | 13 | export interface MaxicodeProps { | 14 | 14 | content: string; | 15 | 15 | mode: 2 | 3 | 4 | 5 | 6; | @@ -18,7 +18,7 @@ export interface MaxicodeProps { | 18 | 18 | export const maxicode: ObjectTypeCore<MaxicodeProps> = { | 19 | 19 | label: "Maxicode", | 20 | 20 | icon: "⬡", | 21 | | - zplCmd: "^BV", | | 21 | + zplCmd: "^BD", | 22 | 22 | group: "code-2d", | 23 | 23 | bindable: true, | 24 | 24 | defaultProps: { | @@ -32,10 +32,10 @@ export const maxicode: ObjectTypeCore<MaxicodeProps> = { | 32 | 32 |
| 33 | 33 | toZPL: (obj, ctx) => { | 34 | 34 | const p = obj.props; | 35 | | - // ^BV; structured-append slots fixed at (1,1) since unexposed. | | 35 | + // Structured-append slots fixed at (1,1) since unexposed. | 36 | 36 | return [ | 37 | 37 | fieldPosZ(obj), | 38 | | - `^BVN,${p.mode},1,1`, | | 38 | + `^BD${p.mode},1,1`, | 39 | 39 | fdFieldFor(p.content, ctx), | 40 | 40 | ].join(""); | 41 | 41 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/types/LabelConfig.ts +37-7Lines changed: 37 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { z } from 'zod'; | 2 | | -import { intInRange, makeEnumGuard } from './typeHelpers'; | | 2 | +import { YES_NO_VALUES, intInRange, makeEnumGuard } from './typeHelpers'; | 3 | 3 |
| 4 | 4 | /** Two row shapes: uploaded font (path + optional preview, bytes in cache) | 5 | 5 | * or manual printer-resident reference (path only, no bytes). Empty strings | @@ -30,10 +30,14 @@ export const isMediaTracking = makeEnumGuard(MEDIA_TRACKING_VALUES); | 30 | 30 | export const isMediaFeedMode = makeEnumGuard(MEDIA_FEED_VALUES); | 31 | 31 |
| 32 | 32 | /** ~JS backfeed sequence: A=100% after, B=before next label, N=normal, | 33 | | - * O=off. Percent forms 10-90 are not modeled (param-fidelity limit). */ | | 33 | + * O=off, or percent-after in tens (printer rounds to the nearest ten, p276). */ | 34 | 34 | export const BACKFEED_SEQUENCE_VALUES = ['A', 'B', 'N', 'O'] as const; | 35 | 35 | export type BackfeedSequence = (typeof BACKFEED_SEQUENCE_VALUES)[number]; | 36 | 36 | export const isBackfeedSequence = makeEnumGuard(BACKFEED_SEQUENCE_VALUES); | | 37 | +export const BACKFEED_PERCENT_VALUES = [10, 20, 30, 40, 50, 60, 70, 80, 90] as const; | | 38 | +export type BackfeedPercent = (typeof BACKFEED_PERCENT_VALUES)[number]; | | 39 | +export const isBackfeedPercent = (n: number): n is BackfeedPercent => | | 40 | + (BACKFEED_PERCENT_VALUES as readonly number[]).includes(n); | 37 | 41 |
| 38 | 42 | /** ^MM print mode (per-label cut/peel/tear behaviour). */ | 39 | 43 | export const MEDIA_MODE_VALUES = ['T', 'V', 'D', 'K'] as const; | @@ -63,6 +67,7 @@ export const DARKNESS_PERMANENT_RANGE = { min: -30, max: 30 } as const; | 63 | 67 | export const DARKNESS_INSTANT_RANGE = { min: 0, max: 30 } as const; | 64 | 68 | /** ^ML: maximum label length, in dots. Zebra spec accepts 1..32000. */ | 65 | 69 | export const MAX_LABEL_LENGTH_RANGE = { min: 1, max: 32000 } as const; | | 70 | +export const SLEW_DOT_ROWS_RANGE = { min: 0, max: 32000 } as const; | 66 | 71 |
| 67 | 72 | /** ^MU b,c dpi tokens; 200 = 203 dpi; ratio drives resampling. */ | 68 | 73 | export const MU_DPI_VALUES = [150, 200, 300, 600] as const; | @@ -78,6 +83,18 @@ export const muResamplingSchema = z.object({ | 78 | 83 | }); | 79 | 84 | export type MuResampling = z.infer<typeof muResamplingSchema>; | 80 | 85 |
| | 86 | +/** Setting one slot seeds the other from it, keeping both-or-neither. */ | | 87 | +export function composeMuResampling( | | 88 | + current: MuResampling | undefined, | | 89 | + slot: keyof MuResampling, | | 90 | + dpi: MuDpi, | | 91 | +): MuResampling { | | 92 | + return { | | 93 | + formatDpi: slot === 'formatDpi' ? dpi : current?.formatDpi ?? dpi, | | 94 | + outputDpi: slot === 'outputDpi' ? dpi : current?.outputDpi ?? dpi, | | 95 | + }; | | 96 | +} | | 97 | + | 81 | 98 | /** ^SO offset slots; mirrors the b,c,d,e,f,g wire-format order. All | 82 | 99 | * fields signed; omitted = 0. Schema-natural order in our type is | 83 | 100 | * years/months/days/hours/minutes/seconds; the parser/generator | @@ -140,7 +157,7 @@ export const labelConfigSchema = z.object({ | 140 | 157 | /** ^PQ p3: replicates of each serialised label. */ | 141 | 158 | replicates: z.number().int().min(0).max(99999999).optional(), | 142 | 159 | /** ^PQ p4: override pause count (cutter behaviour). */ | 143 | | - overridePauseCount: z.enum(['Y', 'N']).optional(), | | 160 | + overridePauseCount: z.enum(YES_NO_VALUES).optional(), | 144 | 161 | mediaMode: z.enum(MEDIA_MODE_VALUES).optional(), | 145 | 162 | labelShift: z.number().optional(), | 146 | 163 | /** ^LH x; field FOs shifted at export so screen == print. */ | @@ -160,7 +177,7 @@ export const labelConfigSchema = z.object({ | 160 | 177 | mediaType: z.enum(MEDIA_TYPE_VALUES).optional(), | 161 | 178 | printOrientation: z.enum(PRINT_ORIENTATION_VALUES).optional(), | 162 | 179 | /** ^PM: mirror image (left/right flip). */ | 163 | | - mirror: z.enum(['Y', 'N']).optional(), | | 180 | + mirror: z.enum(YES_NO_VALUES).optional(), | 164 | 181 | defaultFontId: z.string().min(1).optional(), | 165 | 182 | defaultFontHeight: z.number().int().positive().optional(), | 166 | 183 | /** ^CF width param. Spec allows 0 → printer auto-derives from height. */ | @@ -178,13 +195,23 @@ export const labelConfigSchema = z.object({ | 178 | 195 | /** ^XB: suppress backfeed for the next label. Standalone toggle. */ | 179 | 196 | suppressBackfeed: z.boolean().optional(), | 180 | 197 | /** ~JS: backfeed sequence. Immediate/transient, emitted before ^XA. */ | 181 | | - backfeedSequence: z.enum(BACKFEED_SEQUENCE_VALUES).optional(), | | 198 | + backfeedSequence: z | | 199 | + .union([z.enum(BACKFEED_SEQUENCE_VALUES), z.number().refine(isBackfeedPercent)]) | | 200 | + .optional(), | 182 | 201 | /** ^MU b,c; set only when both slots arrived valid. */ | 183 | 202 | muResampling: muResamplingSchema.optional(), | 184 | 203 | /** ^SO2: secondary clock offset (`«clock2:T»` markers resolve through this). */ | 185 | 204 | secondaryClockOffset: z.preprocess(coerceEmptyOffset, clockOffsetSchema.optional()), | 186 | 205 | /** ^SO3: tertiary clock offset (`«clock3:T»` markers resolve through this). */ | 187 | 206 | tertiaryClockOffset: z.preprocess(coerceEmptyOffset, clockOffsetSchema.optional()), | | 207 | + /** ^MC: N retains the bitmap as background of subsequent labels. */ | | 208 | + mapClear: z.enum(YES_NO_VALUES).optional(), | | 209 | + /** ^PF: slew this many dot rows instead of printing blank bottom area. */ | | 210 | + slewDotRows: intInRange(SLEW_DOT_ROWS_RANGE).optional(), | | 211 | + /** ^PH: feed one blank label after the format prints. */ | | 212 | + slewToHome: z.boolean().optional(), | | 213 | + /** ^PP: pause after the format prints (until PAUSE or ~PS). */ | | 214 | + programmablePause: z.boolean().optional(), | 188 | 215 | }); | 189 | 216 |
| 190 | 217 | export type LabelConfig = z.infer<typeof labelConfigSchema>; | @@ -201,10 +228,13 @@ export const PER_LABEL_ZPL_FIELDS = [ | 201 | 228 | 'darkness', 'instantDarkness', | 202 | 229 | 'labelHomeX', 'labelHomeY', 'labelTop', 'labelShift', | 203 | 230 | 'printQuantity', 'pauseCount', 'replicates', 'overridePauseCount', | | 231 | + 'mapClear', 'slewDotRows', 'slewToHome', 'programmablePause', | 204 | 232 | ] as const satisfies readonly (keyof LabelConfig)[]; | 205 | 233 |
| 206 | | -/** The ^PQ family is scoped to its own ^XA block; every other config field is | 207 | | - * persistent printer state a later block may contribute to the design. */ | | 234 | +/** Fields the import fold scopes to their own ^XA block; the rest is | | 235 | + * persistent state a later block may extend. ^MC persists on the wire | | 236 | + * (p300), but folding a later ^MCN back would leak its bitmap into page two. */ | 208 | 237 | export const PER_FORMAT_ZPL_FIELDS = [ | 209 | 238 | 'printQuantity', 'pauseCount', 'replicates', 'overridePauseCount', | | 239 | + 'slewDotRows', 'slewToHome', 'programmablePause', 'mapClear', | 210 | 240 | ] as const satisfies readonly (keyof LabelConfig)[]; |
|