@ancon/wildcat-utils 1.54.0-check-optimizations.4 → 1.54.0-check-optimizations.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancon/wildcat-utils",
3
- "version": "1.54.0-check-optimizations.4",
3
+ "version": "1.54.0-check-optimizations.6",
4
4
  "main": "index.js",
5
5
  "module": "index.mjs",
6
6
  "types": "index.d.ts",
@@ -175,6 +175,11 @@
175
175
  "require": "./checkout/getCheckoutGiftCardMetaData.js",
176
176
  "types": "./checkout/getCheckoutGiftCardMetaData.d.ts"
177
177
  },
178
+ "./checkout/getCheckoutGiftCardRecipientsMetaData": {
179
+ "import": "./checkout/getCheckoutGiftCardRecipientsMetaData.mjs",
180
+ "require": "./checkout/getCheckoutGiftCardRecipientsMetaData.js",
181
+ "types": "./checkout/getCheckoutGiftCardRecipientsMetaData.d.ts"
182
+ },
178
183
  "./checkout/getCheckoutGrandTotalAmount": {
179
184
  "import": "./checkout/getCheckoutGrandTotalAmount.mjs",
180
185
  "require": "./checkout/getCheckoutGrandTotalAmount.js",
@@ -1020,6 +1025,11 @@
1020
1025
  "require": "./preOrder/isPreOrderSharable.js",
1021
1026
  "types": "./preOrder/isPreOrderSharable.d.ts"
1022
1027
  },
1028
+ "./printing/StarScanConnection": {
1029
+ "import": "./printing/StarScanConnection.mjs",
1030
+ "require": "./printing/StarScanConnection.js",
1031
+ "types": "./printing/StarScanConnection.d.ts"
1032
+ },
1023
1033
  "./printing/createStarCloudScanHook": {
1024
1034
  "import": "./printing/createStarCloudScanHook.mjs",
1025
1035
  "require": "./printing/createStarCloudScanHook.js",
@@ -1200,6 +1210,11 @@
1200
1210
  "require": "./string/base64Encode.js",
1201
1211
  "types": "./string/base64Encode.d.ts"
1202
1212
  },
1213
+ "./string/getNameInitials": {
1214
+ "import": "./string/getNameInitials.mjs",
1215
+ "require": "./string/getNameInitials.js",
1216
+ "types": "./string/getNameInitials.d.ts"
1217
+ },
1203
1218
  "./string/getParsedJSONFromString": {
1204
1219
  "import": "./string/getParsedJSONFromString.mjs",
1205
1220
  "require": "./string/getParsedJSONFromString.js",
@@ -0,0 +1,64 @@
1
+ import type { StarMonitor } from '@ancon/wildcat-printing';
2
+ export declare type StarScanLogger = {
3
+ info: (message: string, data?: Record<string, unknown>) => void;
4
+ };
5
+ export declare enum StarScanReleaseReason {
6
+ /** A card was read, the scan is done */
7
+ CardRead = "CardRead",
8
+ /** The app went to the background */
9
+ Background = "Background",
10
+ /** The scan screen closed */
11
+ Unmount = "Unmount",
12
+ /** A new scan attempt replaced this one */
13
+ Restart = "Restart"
14
+ }
15
+ /**
16
+ * Owns the printer connection of one card scan screen.
17
+ *
18
+ * A Star printer accepts one connection at a time, and a card scan holds it
19
+ * for as long as it waits for a card. Another app on the device (POS and
20
+ * Express share devices and printers) cannot print meanwhile, so the
21
+ * connection is released when the app goes to the background and taken again
22
+ * when it returns.
23
+ */
24
+ export default class StarScanConnection {
25
+ private logger?;
26
+ private monitor?;
27
+ private identifier?;
28
+ private scanAttempt;
29
+ private isBackground;
30
+ private isPausedForBackground;
31
+ constructor(logger?: StarScanLogger | undefined);
32
+ /**
33
+ * Starts a scan attempt. An earlier attempt that is still discovering the
34
+ * printer may no longer connect.
35
+ */
36
+ beginScan(): number;
37
+ /**
38
+ * Whether this is still the latest scan attempt. Results of an older
39
+ * attempt, such as a failed discover, must not change the screen.
40
+ */
41
+ isLatest(scanAttempt: number): boolean;
42
+ /**
43
+ * Whether the monitor is still the one this screen uses. Events and
44
+ * failures of a released or replaced monitor must not change the screen.
45
+ */
46
+ isAttached(monitor: StarMonitor): boolean;
47
+ /**
48
+ * Whether the scan attempt may connect to the printer now: it is the latest
49
+ * attempt and the app is in the foreground. An attempt held back by the
50
+ * background is started again when the app returns.
51
+ */
52
+ mayConnect(scanAttempt: number): boolean;
53
+ /** Takes over a monitor that is about to connect, releasing any earlier one */
54
+ attach(monitor: StarMonitor, identifier: string): void;
55
+ /** Stops the monitor, which releases the printer connection */
56
+ release(reason: StarScanReleaseReason): void;
57
+ /**
58
+ * Call when the app moves between foreground and background. Returns true
59
+ * when a scan that was paused by the background should start again.
60
+ *
61
+ * @param isScanning - whether the screen is waiting for the printer or a card
62
+ */
63
+ setBackground(isBackground: boolean, isScanning: boolean): boolean;
64
+ }
@@ -0,0 +1 @@
1
+ "use strict";var c=Object.defineProperty;var d=(s,t,e)=>t in s?c(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var r=(s,t,e)=>(d(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var u=(s=>(s.CardRead="CardRead",s.Background="Background",s.Unmount="Unmount",s.Restart="Restart",s))(u||{});class g{constructor(t){r(this,"monitor");r(this,"identifier");r(this,"scanAttempt",0);r(this,"isBackground",!1);r(this,"isPausedForBackground",!1);this.logger=t}beginScan(){return this.scanAttempt+=1,this.isPausedForBackground=!1,this.scanAttempt}isLatest(t){return t===this.scanAttempt}isAttached(t){return this.monitor===t}mayConnect(t){return this.isLatest(t)?this.isBackground?(this.isPausedForBackground=!0,!1):!0:!1}attach(t,e){var i;this.release("Restart"),this.monitor=t,this.identifier=e,(i=this.logger)==null||i.info("Card scan connecting to printer",{identifier:e,sourceContext:"Printing"})}release(t){var a;const{monitor:e,identifier:i}=this;e&&(this.monitor=void 0,this.identifier=void 0,(a=this.logger)==null||a.info("Card scan released printer",{identifier:i,reason:t,sourceContext:"Printing"}),Promise.resolve(e.stop()).catch(n=>{var o;(o=this.logger)==null||o.info("Card scan release failed",{identifier:i,reason:t,error:(n==null?void 0:n.message)??String(n),sourceContext:"Printing"})}))}setBackground(t,e){if(t===this.isBackground)return!1;if(this.isBackground=t,t)return e&&(this.isPausedForBackground=!0),this.scanAttempt+=1,this.release("Background"),!1;const i=this.isPausedForBackground;return this.isPausedForBackground=!1,i}}exports.StarScanReleaseReason=u;exports.default=g;
@@ -0,0 +1,93 @@
1
+ var u = Object.defineProperty;
2
+ var c = (i, t, s) => t in i ? u(i, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : i[t] = s;
3
+ var r = (i, t, s) => (c(i, typeof t != "symbol" ? t + "" : t, s), s);
4
+ var d = /* @__PURE__ */ ((i) => (i.CardRead = "CardRead", i.Background = "Background", i.Unmount = "Unmount", i.Restart = "Restart", i))(d || {});
5
+ class g {
6
+ constructor(t) {
7
+ r(this, "monitor");
8
+ r(this, "identifier");
9
+ r(this, "scanAttempt", 0);
10
+ r(this, "isBackground", !1);
11
+ r(this, "isPausedForBackground", !1);
12
+ this.logger = t;
13
+ }
14
+ /**
15
+ * Starts a scan attempt. An earlier attempt that is still discovering the
16
+ * printer may no longer connect.
17
+ */
18
+ beginScan() {
19
+ return this.scanAttempt += 1, this.isPausedForBackground = !1, this.scanAttempt;
20
+ }
21
+ /**
22
+ * Whether this is still the latest scan attempt. Results of an older
23
+ * attempt, such as a failed discover, must not change the screen.
24
+ */
25
+ isLatest(t) {
26
+ return t === this.scanAttempt;
27
+ }
28
+ /**
29
+ * Whether the monitor is still the one this screen uses. Events and
30
+ * failures of a released or replaced monitor must not change the screen.
31
+ */
32
+ isAttached(t) {
33
+ return this.monitor === t;
34
+ }
35
+ /**
36
+ * Whether the scan attempt may connect to the printer now: it is the latest
37
+ * attempt and the app is in the foreground. An attempt held back by the
38
+ * background is started again when the app returns.
39
+ */
40
+ mayConnect(t) {
41
+ return this.isLatest(t) ? this.isBackground ? (this.isPausedForBackground = !0, !1) : !0 : !1;
42
+ }
43
+ /** Takes over a monitor that is about to connect, releasing any earlier one */
44
+ attach(t, s) {
45
+ var e;
46
+ this.release(
47
+ "Restart"
48
+ /* Restart */
49
+ ), this.monitor = t, this.identifier = s, (e = this.logger) == null || e.info("Card scan connecting to printer", {
50
+ identifier: s,
51
+ sourceContext: "Printing"
52
+ });
53
+ }
54
+ /** Stops the monitor, which releases the printer connection */
55
+ release(t) {
56
+ var a;
57
+ const { monitor: s, identifier: e } = this;
58
+ s && (this.monitor = void 0, this.identifier = void 0, (a = this.logger) == null || a.info("Card scan released printer", {
59
+ identifier: e,
60
+ reason: t,
61
+ sourceContext: "Printing"
62
+ }), Promise.resolve(s.stop()).catch((n) => {
63
+ var o;
64
+ (o = this.logger) == null || o.info("Card scan release failed", {
65
+ identifier: e,
66
+ reason: t,
67
+ error: (n == null ? void 0 : n.message) ?? String(n),
68
+ sourceContext: "Printing"
69
+ });
70
+ }));
71
+ }
72
+ /**
73
+ * Call when the app moves between foreground and background. Returns true
74
+ * when a scan that was paused by the background should start again.
75
+ *
76
+ * @param isScanning - whether the screen is waiting for the printer or a card
77
+ */
78
+ setBackground(t, s) {
79
+ if (t === this.isBackground)
80
+ return !1;
81
+ if (this.isBackground = t, t)
82
+ return s && (this.isPausedForBackground = !0), this.scanAttempt += 1, this.release(
83
+ "Background"
84
+ /* Background */
85
+ ), !1;
86
+ const e = this.isPausedForBackground;
87
+ return this.isPausedForBackground = !1, e;
88
+ }
89
+ }
90
+ export {
91
+ d as StarScanReleaseReason,
92
+ g as default
93
+ };
@@ -1,5 +1,6 @@
1
1
  import { ClientSettingsPrinter, DiscoveredStarPrinter } from '@ancon/wildcat-types';
2
2
  import { StarCloudScanStatus } from './types';
3
+ import { type StarScanLogger } from './StarScanConnection';
3
4
  declare type ReduxSelectorsArg<RootState = unknown> = {
4
5
  selectedClientPrinterSelector: (state: RootState) => ClientSettingsPrinter | null;
5
6
  };
@@ -8,6 +9,15 @@ declare type ReduxHooksArg<RootState = unknown> = {
8
9
  getState: () => RootState;
9
10
  };
10
11
  useStarPrinterDiscover: () => (timeout: number) => Promise<DiscoveredStarPrinter[]>;
12
+ /**
13
+ * Whether the app is in the background (React Native AppState
14
+ * 'background'). When given, the printer connection is released while the
15
+ * app is in the background, so another app on the device can print, and
16
+ * the scan resumes on return.
17
+ */
18
+ useIsAppInBackground?: () => boolean;
19
+ /** Logs when a scan takes and releases the printer connection */
20
+ logger?: StarScanLogger;
11
21
  };
12
22
  export declare type SanitizeRawOutputOptions = {
13
23
  /** Enable or disable sanitization of raw output */
@@ -1 +1 @@
1
- "use strict";const o=require("react"),L=require("dayjs"),I=require("@ancon/wildcat-printing"),B=require("../shared/hooks/usePrevious.js"),J=require("../shared/hooks/useMountedRef.js"),n=require("./types.js"),K=["TSP654"],Q=1;function V(T,p,x,N,d){const{useAppStore:_,useStarPrinterDiscover:F}=p,{selectedClientPrinterSelector:M}=x;function w(){const e=J(),D=_(),h=F(),P=o.useRef(void 0),[i,A]=o.useState(T),[r,f]=o.useState(),[l,v]=o.useState(),y=B(l),[U,g]=o.useState(),[W,E]=o.useState(N),a=o.useCallback(c=>{e!=null&&e.current&&A(c)},[e]),H=c=>{if((d==null?void 0:d.sanitizeEnabled)??!1){const s=(d==null?void 0:d.sanitizeRegex)??/[\D]/gi;return c.replace(s,"")}return c},m=o.useCallback(async c=>{var u;(u=P.current)==null||u.stop(),a(n.StarCloudScanStatus.ScanningComplete);const S=String.fromCharCode(...c).trim(),s=H(S);E(s)},[a]),k=o.useCallback(async({macAddress:c,ipAddress:S})=>{function s(t){a(n.StarCloudScanStatus.CommunicationError),e!=null&&e.current&&g(t==null?void 0:t.message)}const u={onStarted:t=>{if(t&&t.inputDevicesCount>0){const{inputDevicesCount:C}=t;a(n.StarCloudScanStatus.ReadyToScan),f({inputDeviceCount:C,lastConnectedOn:new Date})}},onStopped:t=>{t&&s(t),f(void 0)},inputDevice:{onConnected:()=>{const t=((r==null?void 0:r.inputDeviceCount)||0)+1;a(t>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),f({inputDeviceCount:t,lastConnectedOn:new Date})},onDisconnected:()=>{const t=((r==null?void 0:r.inputDeviceCount)||0)-1>=0?((r==null?void 0:r.inputDeviceCount)||0)-1:0;a(t>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),f({inputDeviceCount:t})},onCommunicationError:s,onDataReceived:t=>v({data:t,lastReceivedOn:new Date})}};if(P.current=I.monitor(S||c,u),e!=null&&e.current)try{await P.current.start()}catch(t){a(n.StarCloudScanStatus.CommunicationError),e!=null&&e.current&&g(t==null?void 0:t.message)}},[r,a,e]),b=o.useCallback(async()=>{e!=null&&e.current&&(a(n.StarCloudScanStatus.WaitingForPrinter),g(void 0),v(void 0),f(void 0),E(void 0));const c=M(D.getState()),{macAddress:S,serialNumber:s}=c;try{const t=(await h(2e3)).find(C=>S&&C.macAddress.toLowerCase()===S.toLowerCase()||s&&C.serialNumber===s);if(e!=null&&e.current){if(t){if(K.some(C=>{var q;return(q=t.model)==null?void 0:q.toLowerCase().includes(C.toLowerCase())})){a(n.StarCloudScanStatus.UnsupportedPrinter);return}k(t)}a(t?n.StarCloudScanStatus.PrinterDetected:n.StarCloudScanStatus.PrinterNotDetected)}}catch{e!=null&&e.current&&a(n.StarCloudScanStatus.PrinterNotDetected)}},[e,D,a,h,k]),j=i===n.StarCloudScanStatus.WaitingForPrinter||i===n.StarCloudScanStatus.PrinterDetected||i===n.StarCloudScanStatus.ReadyToScan||i===n.StarCloudScanStatus.ScanningComplete,G=i===n.StarCloudScanStatus.PrinterNotDetected||i===n.StarCloudScanStatus.ScanFailed||i===n.StarCloudScanStatus.CommunicationError||i===n.StarCloudScanStatus.UnsupportedPrinter;return o.useEffect(()=>{if(!y&&(l==null?void 0:l.data)&&r&&(r!=null&&r.lastConnectedOn)){const{lastConnectedOn:S}=r,{lastReceivedOn:s,data:u}=l;L(s).diff(L(S),"second",!0)>Q?m(u):v(void 0)}},[l,y,r,m]),o.useEffect(()=>(i===n.StarCloudScanStatus.WaitingForPrinter&&b(),()=>{var c;(c=P.current)==null||c.stop()}),[]),{startScan:b,changeDeviceStatus:a,scanStatus:i,reading:W,connectionError:U,isLoading:j,isError:G}}return w}module.exports=V;
1
+ "use strict";const a=require("react"),x=require("dayjs"),$=require("@ancon/wildcat-printing"),z=require("../shared/hooks/usePrevious.js"),O=require("../shared/hooks/useMountedRef.js"),n=require("./types.js"),A=require("./StarScanConnection.js"),tt=["TSP654"],nt=1,et=[n.StarCloudScanStatus.WaitingForPrinter,n.StarCloudScanStatus.PrinterDetected,n.StarCloudScanStatus.ReadyToScan];function rt(){return!1}function at(I,M,N,U,f){const{useAppStore:W,useStarPrinterDiscover:B,useIsAppInBackground:H=rt,logger:j}=M,{selectedClientPrinterSelector:G}=N;function J(){const t=O(),p=W(),b=B(),q=H(),y=a.useRef(null);y.current||(y.current=new A.default(j));const o=y.current,[i,K]=a.useState(I),[r,D]=a.useState(),[g,m]=a.useState(),L=z(g),[Q,k]=a.useState(),[V,T]=a.useState(U),c=a.useCallback(s=>{t!=null&&t.current&&K(s)},[t]),X=s=>{if((f==null?void 0:f.sanitizeEnabled)??!1){const u=(f==null?void 0:f.sanitizeRegex)??/[\D]/gi;return s.replace(u,"")}return s},w=a.useCallback(async s=>{o.release(A.StarScanReleaseReason.CardRead),c(n.StarCloudScanStatus.ScanningComplete);const d=String.fromCharCode(...s).trim(),u=X(d);T(u)},[c,o]),F=a.useCallback(async({macAddress:s,ipAddress:d})=>{let u;function S(e){return(...E)=>{u&&o.isAttached(u)&&e(...E)}}function v(e){c(n.StarCloudScanStatus.CommunicationError),t!=null&&t.current&&k(e==null?void 0:e.message)}const P={onStarted:S(e=>{if(e&&e.inputDevicesCount>0){const{inputDevicesCount:E}=e;c(n.StarCloudScanStatus.ReadyToScan),D({inputDeviceCount:E,lastConnectedOn:new Date})}}),onStopped:S(e=>{e&&v(e),D(void 0)}),inputDevice:{onConnected:S(()=>{const e=((r==null?void 0:r.inputDeviceCount)||0)+1;c(e>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),D({inputDeviceCount:e,lastConnectedOn:new Date})}),onDisconnected:S(()=>{const e=((r==null?void 0:r.inputDeviceCount)||0)-1>=0?((r==null?void 0:r.inputDeviceCount)||0)-1:0;c(e>0?n.StarCloudScanStatus.ReadyToScan:n.StarCloudScanStatus.PrinterDetected),D({inputDeviceCount:e})}),onCommunicationError:S(v),onDataReceived:S(e=>m({data:e,lastReceivedOn:new Date}))}},l=d||s,C=$.monitor(l,P);if(u=C,o.attach(C,l),t!=null&&t.current)try{await C.start()}catch(e){if(!o.isAttached(C))return;c(n.StarCloudScanStatus.CommunicationError),t!=null&&t.current&&k(e==null?void 0:e.message)}},[r,c,t,o]),h=a.useCallback(async()=>{const s=o.beginScan();t!=null&&t.current&&(c(n.StarCloudScanStatus.WaitingForPrinter),k(void 0),m(void 0),D(void 0),T(void 0));const d=G(p.getState()),{macAddress:u,serialNumber:S}=d;try{const P=(await b(2e3)).find(l=>u&&l.macAddress.toLowerCase()===u.toLowerCase()||S&&l.serialNumber===S);if(!o.mayConnect(s))return;if(t!=null&&t.current){if(P){if(tt.some(l=>{var C;return(C=P.model)==null?void 0:C.toLowerCase().includes(l.toLowerCase())})){c(n.StarCloudScanStatus.UnsupportedPrinter);return}F(P)}c(P?n.StarCloudScanStatus.PrinterDetected:n.StarCloudScanStatus.PrinterNotDetected)}}catch{if(!o.isLatest(s))return;t!=null&&t.current&&c(n.StarCloudScanStatus.PrinterNotDetected)}},[t,p,c,b,F,o]),R=a.useRef(i);R.current=i;const _=a.useRef(h);_.current=h,a.useEffect(()=>{o.setBackground(q,et.includes(R.current))&&(t!=null&&t.current)&&_.current()},[q,o,t]);const Y=i===n.StarCloudScanStatus.WaitingForPrinter||i===n.StarCloudScanStatus.PrinterDetected||i===n.StarCloudScanStatus.ReadyToScan||i===n.StarCloudScanStatus.ScanningComplete,Z=i===n.StarCloudScanStatus.PrinterNotDetected||i===n.StarCloudScanStatus.ScanFailed||i===n.StarCloudScanStatus.CommunicationError||i===n.StarCloudScanStatus.UnsupportedPrinter;return a.useEffect(()=>{if(!L&&(g==null?void 0:g.data)&&r&&(r!=null&&r.lastConnectedOn)){const{lastConnectedOn:d}=r,{lastReceivedOn:u,data:S}=g;x(u).diff(x(d),"second",!0)>nt?w(S):m(void 0)}},[g,L,r,w]),a.useEffect(()=>(i===n.StarCloudScanStatus.WaitingForPrinter&&h(),()=>{o.release(A.StarScanReleaseReason.Unmount)}),[]),{startScan:h,changeDeviceStatus:c,scanStatus:i,reading:V,connectionError:Q,isLoading:Y,isError:Z}}return J}module.exports=at;
@@ -1,138 +1,176 @@
1
- import { useRef as K, useState as f, useCallback as v, useEffect as N } from "react";
2
- import b from "dayjs";
3
- import { monitor as Q } from "@ancon/wildcat-printing";
4
- import V from "../shared/hooks/usePrevious.mjs";
5
- import X from "../shared/hooks/useMountedRef.mjs";
6
- import { StarCloudScanStatus as t } from "./types.mjs";
7
- const Y = ["TSP654"], Z = 1;
8
- function ne(k, F, M, A, u) {
9
- const { useAppStore: U, useStarPrinterDiscover: W } = F, { selectedClientPrinterSelector: w } = M;
10
- function H() {
11
- const n = X(), g = U(), y = W(), m = K(void 0), [s, j] = f(k), [r, C] = f(), [l, P] = f(), E = V(l), [G, D] = f(), [I, p] = f(A), o = v(
12
- (c) => {
13
- n != null && n.current && j(c);
1
+ import { useRef as k, useState as D, useCallback as h, useEffect as L } from "react";
2
+ import W from "dayjs";
3
+ import { monitor as nn } from "@ancon/wildcat-printing";
4
+ import en from "../shared/hooks/usePrevious.mjs";
5
+ import tn from "../shared/hooks/useMountedRef.mjs";
6
+ import { StarCloudScanStatus as e } from "./types.mjs";
7
+ import rn, { StarScanReleaseReason as B } from "./StarScanConnection.mjs";
8
+ const on = ["TSP654"], cn = 1, sn = [
9
+ e.WaitingForPrinter,
10
+ e.PrinterDetected,
11
+ e.ReadyToScan
12
+ ];
13
+ function an() {
14
+ return !1;
15
+ }
16
+ function mn(H, R, j, G, f) {
17
+ const {
18
+ useAppStore: q,
19
+ useStarPrinterDiscover: J,
20
+ useIsAppInBackground: K = an,
21
+ logger: Q
22
+ } = R, { selectedClientPrinterSelector: V } = j;
23
+ function X() {
24
+ const n = tn(), T = q(), F = J(), b = K(), p = k(null);
25
+ p.current || (p.current = new rn(Q));
26
+ const c = p.current, [s, Y] = D(H), [r, m] = D(), [C, y] = D(), w = en(C), [Z, A] = D(), [_, x] = D(G), o = h(
27
+ (i) => {
28
+ n != null && n.current && Y(i);
14
29
  },
15
30
  [n]
16
- ), q = (c) => {
17
- if ((u == null ? void 0 : u.sanitizeEnabled) ?? !1) {
18
- const i = (u == null ? void 0 : u.sanitizeRegex) ?? /[\D]/gi;
19
- return c.replace(i, "");
31
+ ), $ = (i) => {
32
+ if ((f == null ? void 0 : f.sanitizeEnabled) ?? !1) {
33
+ const a = (f == null ? void 0 : f.sanitizeRegex) ?? /[\D]/gi;
34
+ return i.replace(a, "");
20
35
  }
21
- return c;
22
- }, h = v(
23
- async (c) => {
24
- var d;
25
- (d = m.current) == null || d.stop(), o(t.ScanningComplete);
26
- const a = String.fromCharCode(...c).trim(), i = q(a);
27
- p(i);
36
+ return i;
37
+ }, I = h(
38
+ async (i) => {
39
+ c.release(B.CardRead), o(e.ScanningComplete);
40
+ const u = String.fromCharCode(...i).trim(), a = $(u);
41
+ x(a);
28
42
  },
29
- [o]
30
- ), L = v(
31
- async ({ macAddress: c, ipAddress: a }) => {
32
- function i(e) {
33
- o(t.CommunicationError), n != null && n.current && D(e == null ? void 0 : e.message);
43
+ [o, c]
44
+ ), M = h(
45
+ async ({ macAddress: i, ipAddress: u }) => {
46
+ let a;
47
+ function d(t) {
48
+ return (...E) => {
49
+ a && c.isAttached(a) && t(...E);
50
+ };
51
+ }
52
+ function P(t) {
53
+ o(e.CommunicationError), n != null && n.current && A(t == null ? void 0 : t.message);
34
54
  }
35
- const d = {
36
- onStarted: (e) => {
37
- if (e && e.inputDevicesCount > 0) {
38
- const { inputDevicesCount: S } = e;
39
- o(t.ReadyToScan), C({
40
- inputDeviceCount: S,
55
+ const g = {
56
+ onStarted: d((t) => {
57
+ if (t && t.inputDevicesCount > 0) {
58
+ const { inputDevicesCount: E } = t;
59
+ o(e.ReadyToScan), m({
60
+ inputDeviceCount: E,
41
61
  lastConnectedOn: /* @__PURE__ */ new Date()
42
62
  });
43
63
  }
44
- },
45
- onStopped: (e) => {
46
- e && i(e), C(void 0);
47
- },
64
+ }),
65
+ onStopped: d((t) => {
66
+ t && P(t), m(void 0);
67
+ }),
48
68
  inputDevice: {
49
- onConnected: () => {
50
- const e = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
69
+ onConnected: d(() => {
70
+ const t = ((r == null ? void 0 : r.inputDeviceCount) || 0) + 1;
51
71
  o(
52
- e > 0 ? t.ReadyToScan : t.PrinterDetected
53
- ), C({
54
- inputDeviceCount: e,
72
+ t > 0 ? e.ReadyToScan : e.PrinterDetected
73
+ ), m({
74
+ inputDeviceCount: t,
55
75
  lastConnectedOn: /* @__PURE__ */ new Date()
56
76
  });
57
- },
58
- onDisconnected: () => {
59
- const e = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
77
+ }),
78
+ onDisconnected: d(() => {
79
+ const t = ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 >= 0 ? ((r == null ? void 0 : r.inputDeviceCount) || 0) - 1 : 0;
60
80
  o(
61
- e > 0 ? t.ReadyToScan : t.PrinterDetected
62
- ), C({
63
- inputDeviceCount: e
81
+ t > 0 ? e.ReadyToScan : e.PrinterDetected
82
+ ), m({
83
+ inputDeviceCount: t
64
84
  });
65
- },
66
- onCommunicationError: i,
67
- onDataReceived: (e) => P({ data: e, lastReceivedOn: /* @__PURE__ */ new Date() })
85
+ }),
86
+ onCommunicationError: d(P),
87
+ onDataReceived: d(
88
+ (t) => y({ data: t, lastReceivedOn: /* @__PURE__ */ new Date() })
89
+ )
68
90
  }
69
- };
70
- if (m.current = Q(a || c, d), n != null && n.current)
91
+ }, l = u || i, S = nn(l, g);
92
+ if (a = S, c.attach(S, l), n != null && n.current)
71
93
  try {
72
- await m.current.start();
73
- } catch (e) {
74
- o(t.CommunicationError), n != null && n.current && D(e == null ? void 0 : e.message);
94
+ await S.start();
95
+ } catch (t) {
96
+ if (!c.isAttached(S))
97
+ return;
98
+ o(e.CommunicationError), n != null && n.current && A(t == null ? void 0 : t.message);
75
99
  }
76
100
  },
77
- [r, o, n]
78
- ), T = v(async () => {
79
- n != null && n.current && (o(t.WaitingForPrinter), D(void 0), P(void 0), C(void 0), p(void 0));
80
- const c = w(g.getState()), { macAddress: a, serialNumber: i } = c;
101
+ [r, o, n, c]
102
+ ), v = h(async () => {
103
+ const i = c.beginScan();
104
+ n != null && n.current && (o(e.WaitingForPrinter), A(void 0), y(void 0), m(void 0), x(void 0));
105
+ const u = V(T.getState()), { macAddress: a, serialNumber: d } = u;
81
106
  try {
82
- const e = (await y(2e3)).find(
83
- (S) => a && S.macAddress.toLowerCase() === a.toLowerCase() || i && S.serialNumber === i
107
+ const g = (await F(2e3)).find(
108
+ (l) => a && l.macAddress.toLowerCase() === a.toLowerCase() || d && l.serialNumber === d
84
109
  );
110
+ if (!c.mayConnect(i))
111
+ return;
85
112
  if (n != null && n.current) {
86
- if (e) {
87
- if (Y.some(
88
- (S) => {
89
- var x;
90
- return (x = e.model) == null ? void 0 : x.toLowerCase().includes(S.toLowerCase());
113
+ if (g) {
114
+ if (on.some(
115
+ (l) => {
116
+ var S;
117
+ return (S = g.model) == null ? void 0 : S.toLowerCase().includes(l.toLowerCase());
91
118
  }
92
119
  )) {
93
- o(t.UnsupportedPrinter);
120
+ o(e.UnsupportedPrinter);
94
121
  return;
95
122
  }
96
- L(e);
123
+ M(g);
97
124
  }
98
125
  o(
99
- e ? t.PrinterDetected : t.PrinterNotDetected
126
+ g ? e.PrinterDetected : e.PrinterNotDetected
100
127
  );
101
128
  }
102
129
  } catch {
103
- n != null && n.current && o(t.PrinterNotDetected);
130
+ if (!c.isLatest(i))
131
+ return;
132
+ n != null && n.current && o(e.PrinterNotDetected);
104
133
  }
105
134
  }, [
106
135
  n,
107
- g,
136
+ T,
108
137
  o,
109
- y,
110
- L
111
- ]), B = s === t.WaitingForPrinter || s === t.PrinterDetected || s === t.ReadyToScan || s === t.ScanningComplete, J = s === t.PrinterNotDetected || s === t.ScanFailed || s === t.CommunicationError || s === t.UnsupportedPrinter;
112
- return N(() => {
113
- if (!E && (l == null ? void 0 : l.data) && r && (r != null && r.lastConnectedOn)) {
114
- const { lastConnectedOn: a } = r, { lastReceivedOn: i, data: d } = l;
115
- b(i).diff(
116
- b(a),
138
+ F,
139
+ M,
140
+ c
141
+ ]), N = k(s);
142
+ N.current = s;
143
+ const U = k(v);
144
+ U.current = v, L(() => {
145
+ c.setBackground(
146
+ b,
147
+ sn.includes(N.current)
148
+ ) && (n != null && n.current) && U.current();
149
+ }, [b, c, n]);
150
+ const z = s === e.WaitingForPrinter || s === e.PrinterDetected || s === e.ReadyToScan || s === e.ScanningComplete, O = s === e.PrinterNotDetected || s === e.ScanFailed || s === e.CommunicationError || s === e.UnsupportedPrinter;
151
+ return L(() => {
152
+ if (!w && (C == null ? void 0 : C.data) && r && (r != null && r.lastConnectedOn)) {
153
+ const { lastConnectedOn: u } = r, { lastReceivedOn: a, data: d } = C;
154
+ W(a).diff(
155
+ W(u),
117
156
  "second",
118
157
  !0
119
- ) > Z ? h(d) : P(void 0);
158
+ ) > cn ? I(d) : y(void 0);
120
159
  }
121
- }, [l, E, r, h]), N(() => (s === t.WaitingForPrinter && T(), () => {
122
- var c;
123
- (c = m.current) == null || c.stop();
160
+ }, [C, w, r, I]), L(() => (s === e.WaitingForPrinter && v(), () => {
161
+ c.release(B.Unmount);
124
162
  }), []), {
125
- startScan: T,
163
+ startScan: v,
126
164
  changeDeviceStatus: o,
127
165
  scanStatus: s,
128
- reading: I,
129
- connectionError: G,
130
- isLoading: B,
131
- isError: J
166
+ reading: _,
167
+ connectionError: Z,
168
+ isLoading: z,
169
+ isError: O
132
170
  };
133
171
  }
134
- return H;
172
+ return X;
135
173
  }
136
174
  export {
137
- ne as default
175
+ mn as default
138
176
  };
package/printing/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./getPrinterType.js"),e=require("./isValidPrinter.js"),i=require("./isValidNetworkPrinter.js"),t=require("./isValidStarCloudPrinter.js"),n=require("./isTerminalPrinter.js"),o=require("./isCloudPrintModeEnabled.js"),u=require("./createStarCloudScanHook.js");require("@ancon/wildcat-types");require("react");require("dayjs");require("@ancon/wildcat-printing");require("../shared/hooks/usePrevious.js");require("../shared/hooks/useMountedRef.js");require("./types.js");exports.getPrinterType=r;exports.isValidPrinter=e;exports.isValidNetworkPrinter=i;exports.isValidStarCloudPrinter=t;exports.isTerminalPrinter=n;exports.isCloudPrintModeEnabled=o;exports.createUseStarCloudScanHook=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./getPrinterType.js"),e=require("./isValidPrinter.js"),i=require("./isValidNetworkPrinter.js"),t=require("./isValidStarCloudPrinter.js"),n=require("./isTerminalPrinter.js"),o=require("./isCloudPrintModeEnabled.js"),u=require("./createStarCloudScanHook.js");require("@ancon/wildcat-types");require("react");require("dayjs");require("@ancon/wildcat-printing");require("../shared/hooks/usePrevious.js");require("../shared/hooks/useMountedRef.js");require("./types.js");require("./StarScanConnection.js");exports.getPrinterType=r;exports.isValidPrinter=e;exports.isValidNetworkPrinter=i;exports.isValidStarCloudPrinter=t;exports.isTerminalPrinter=n;exports.isCloudPrintModeEnabled=o;exports.createUseStarCloudScanHook=u;
@@ -1,10 +1,10 @@
1
- import { default as p } from "./getPrinterType.mjs";
2
- import { default as s } from "./isValidPrinter.mjs";
3
- import { default as n } from "./isValidNetworkPrinter.mjs";
4
- import { default as P } from "./isValidStarCloudPrinter.mjs";
5
- import { default as S } from "./isTerminalPrinter.mjs";
6
- import { default as c } from "./isCloudPrintModeEnabled.mjs";
7
- import { default as T } from "./createStarCloudScanHook.mjs";
1
+ import { default as f } from "./getPrinterType.mjs";
2
+ import { default as u } from "./isValidPrinter.mjs";
3
+ import { default as x } from "./isValidNetworkPrinter.mjs";
4
+ import { default as C } from "./isValidStarCloudPrinter.mjs";
5
+ import { default as V } from "./isTerminalPrinter.mjs";
6
+ import { default as k } from "./isCloudPrintModeEnabled.mjs";
7
+ import { default as b } from "./createStarCloudScanHook.mjs";
8
8
  import "@ancon/wildcat-types";
9
9
  import "react";
10
10
  import "dayjs";
@@ -12,12 +12,13 @@ import "@ancon/wildcat-printing";
12
12
  import "../shared/hooks/usePrevious.mjs";
13
13
  import "../shared/hooks/useMountedRef.mjs";
14
14
  import "./types.mjs";
15
+ import "./StarScanConnection.mjs";
15
16
  export {
16
- T as createUseStarCloudScanHook,
17
- p as getPrinterType,
18
- c as isCloudPrintModeEnabled,
19
- S as isTerminalPrinter,
20
- n as isValidNetworkPrinter,
21
- s as isValidPrinter,
22
- P as isValidStarCloudPrinter
17
+ b as createUseStarCloudScanHook,
18
+ f as getPrinterType,
19
+ k as isCloudPrintModeEnabled,
20
+ V as isTerminalPrinter,
21
+ x as isValidNetworkPrinter,
22
+ u as isValidPrinter,
23
+ C as isValidStarCloudPrinter
23
24
  };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Up to two uppercase initials from a name, e.g. for a monogram shown in
3
+ * place of a logo. Words that don't start with a letter are skipped.
4
+ * @param name Name to take the initials from
5
+ * @returns Initials, or an empty string without a name
6
+ */
7
+ declare function getNameInitials(name: string | null | undefined): string;
8
+ export default getNameInitials;
@@ -0,0 +1 @@
1
+ "use strict";function s(e){return(e??"").split(/\s+/).filter(t=>/^\p{L}/u.test(t)).slice(0,2).map(t=>t.charAt(0).toUpperCase()).join("")}module.exports=s;
@@ -0,0 +1,6 @@
1
+ function a(e) {
2
+ return (e ?? "").split(/\s+/).filter((t) => /^\p{L}/u.test(t)).slice(0, 2).map((t) => t.charAt(0).toUpperCase()).join("");
3
+ }
4
+ export {
5
+ a as default
6
+ };
package/string/index.d.ts CHANGED
@@ -4,4 +4,5 @@ import getRandomAlphaNumericCode from './getRandomAlphaNumericCode';
4
4
  import getParsedJSONFromString from './getParsedJSONFromString';
5
5
  import base64Encode from './base64Encode';
6
6
  import base64Decode from './base64Decode';
7
- export { slugify, truncate, getRandomAlphaNumericCode, getParsedJSONFromString, base64Encode, base64Decode, };
7
+ import getNameInitials from './getNameInitials';
8
+ export { slugify, truncate, getRandomAlphaNumericCode, getParsedJSONFromString, base64Encode, base64Decode, getNameInitials, };
package/string/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./slugify.js"),r=require("./truncate.js"),t=require("./getRandomAlphaNumericCode.js"),n=require("./getParsedJSONFromString.js"),s=require("./base64Encode.js"),i=require("./base64Decode.js");exports.slugify=e;exports.truncate=r;exports.getRandomAlphaNumericCode=t;exports.getParsedJSONFromString=n;exports.base64Encode=s;exports.base64Decode=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./slugify.js"),r=require("./truncate.js"),t=require("./getRandomAlphaNumericCode.js"),i=require("./getParsedJSONFromString.js"),n=require("./base64Encode.js"),s=require("./base64Decode.js"),o=require("./getNameInitials.js");exports.slugify=e;exports.truncate=r;exports.getRandomAlphaNumericCode=t;exports.getParsedJSONFromString=i;exports.base64Encode=n;exports.base64Decode=s;exports.getNameInitials=o;
package/string/index.mjs CHANGED
@@ -1,14 +1,16 @@
1
- import { default as o } from "./slugify.mjs";
2
- import { default as t } from "./truncate.mjs";
1
+ import { default as t } from "./slugify.mjs";
2
+ import { default as r } from "./truncate.mjs";
3
3
  import { default as d } from "./getRandomAlphaNumericCode.mjs";
4
4
  import { default as m } from "./getParsedJSONFromString.mjs";
5
- import { default as l } from "./base64Encode.mjs";
5
+ import { default as u } from "./base64Encode.mjs";
6
6
  import { default as x } from "./base64Decode.mjs";
7
+ import { default as i } from "./getNameInitials.mjs";
7
8
  export {
8
9
  x as base64Decode,
9
- l as base64Encode,
10
+ u as base64Encode,
11
+ i as getNameInitials,
10
12
  m as getParsedJSONFromString,
11
13
  d as getRandomAlphaNumericCode,
12
- o as slugify,
13
- t as truncate
14
+ t as slugify,
15
+ r as truncate
14
16
  };