@mapvx/web-components 0.0.8

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.
Files changed (34) hide show
  1. package/LICENSE +17 -0
  2. package/README.md +118 -0
  3. package/dist/cjs/accessibility-DWoi6we_.cjs +1 -0
  4. package/dist/cjs/back_arrow-Cb1GjmUe.cjs +1 -0
  5. package/dist/cjs/consume-21nhePJt.cjs +11 -0
  6. package/dist/cjs/custom-map-BL0kilso.cjs +7 -0
  7. package/dist/cjs/floor-selector-Cz_c7JJ0.cjs +19 -0
  8. package/dist/cjs/icon-destination-point-C8Bl9rvO.cjs +1 -0
  9. package/dist/cjs/icon-origin-point-B0FLE42C.cjs +1 -0
  10. package/dist/cjs/index.cjs +1 -0
  11. package/dist/cjs/lazy-load-CPuIj6DF.cjs +60 -0
  12. package/dist/cjs/map-view-with-modal.cjs +13 -0
  13. package/dist/cjs/maplibre-gl-P-Xd6Hdn.cjs +1 -0
  14. package/dist/cjs/qr-modal-aISu7Wx-.cjs +15 -0
  15. package/dist/cjs/repeat_icon-DBYc7GBB.cjs +1 -0
  16. package/dist/cjs/route-options-dkKqmEfw.cjs +69 -0
  17. package/dist/cjs/route-view-totems.cjs +32 -0
  18. package/dist/cjs/walking-CDbgxjU4.cjs +1 -0
  19. package/dist/es/assets/accessibility-Cnj-vwGM.js +3 -0
  20. package/dist/es/assets/back_arrow-CUOAm8Zc.js +3 -0
  21. package/dist/es/assets/components-B7xPEQ89.js +3626 -0
  22. package/dist/es/assets/icon-destination-point-DY-ha1KN.js +3 -0
  23. package/dist/es/assets/icon-origin-point-v4_9Pmls.js +3 -0
  24. package/dist/es/assets/map-view-with-modal-CVtICvdT.js +137 -0
  25. package/dist/es/assets/maplibre-gl-KgJ_zm92.js +3 -0
  26. package/dist/es/assets/repeat_icon-CY61-fSZ.js +3 -0
  27. package/dist/es/assets/route-view-totems-DsANsRxr.js +373 -0
  28. package/dist/es/assets/utils-BXXPDum1.js +12476 -0
  29. package/dist/es/assets/walking-BmgeFukv.js +3 -0
  30. package/dist/es/index.js +2 -0
  31. package/dist/es/route-view-totems.js +2 -0
  32. package/dist/iife/map-view-with-modal.js +87 -0
  33. package/dist/iife/route-view-totems.js +212 -0
  34. package/package.json +91 -0
@@ -0,0 +1,3626 @@
1
+ import { i as i$2, x, r, t as t$1, T } from './route-view-totems-DsANsRxr.js';
2
+ import { R as RouteAnimationController, M as MarkerController } from './utils-BXXPDum1.js';
3
+
4
+ /**
5
+ * @license
6
+ * Copyright 2021 Google LLC
7
+ * SPDX-License-Identifier: BSD-3-Clause
8
+ */
9
+ let s$2 = class s extends Event{constructor(s,t,e,o){super("context-request",{bubbles:true,composed:true}),this.context=s,this.contextTarget=t,this.callback=e,this.subscribe=o??false;}};
10
+
11
+ /**
12
+ * @license
13
+ * Copyright 2021 Google LLC
14
+ * SPDX-License-Identifier: BSD-3-Clause
15
+ */
16
+ function n(n){return n}
17
+
18
+ /**
19
+ * @license
20
+ * Copyright 2021 Google LLC
21
+ * SPDX-License-Identifier: BSD-3-Clause
22
+ */let s$1 = class s{constructor(t,s,i,h){if(this.subscribe=false,this.provided=false,this.value=void 0,this.t=(t,s)=>{this.unsubscribe&&(this.unsubscribe!==s&&(this.provided=false,this.unsubscribe()),this.subscribe||this.unsubscribe()),this.value=t,this.host.requestUpdate(),this.provided&&!this.subscribe||(this.provided=true,this.callback&&this.callback(t,s)),this.unsubscribe=s;},this.host=t,void 0!==s.context){const t=s;this.context=t.context,this.callback=t.callback,this.subscribe=t.subscribe??false;}else this.context=s,this.callback=i,this.subscribe=h??false;this.host.addController(this);}hostConnected(){this.dispatchRequest();}hostDisconnected(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=void 0);}dispatchRequest(){this.host.dispatchEvent(new s$2(this.context,this.host,this.t,this.subscribe));}};
23
+
24
+ /**
25
+ * @license
26
+ * Copyright 2021 Google LLC
27
+ * SPDX-License-Identifier: BSD-3-Clause
28
+ */
29
+ class s{get value(){return this.o}set value(s){this.setValue(s);}setValue(s,t=false){const i=t||!Object.is(s,this.o);this.o=s,i&&this.updateObservers();}constructor(s){this.subscriptions=new Map,this.updateObservers=()=>{for(const[s,{disposer:t}]of this.subscriptions)s(this.o,t);},void 0!==s&&(this.value=s);}addCallback(s,t,i){if(!i)return void s(this.value);this.subscriptions.has(s)||this.subscriptions.set(s,{disposer:()=>{this.subscriptions.delete(s);},consumerHost:t});const{disposer:h}=this.subscriptions.get(s);s(this.value,h);}clearCallbacks(){this.subscriptions.clear();}}
30
+
31
+ /**
32
+ * @license
33
+ * Copyright 2021 Google LLC
34
+ * SPDX-License-Identifier: BSD-3-Clause
35
+ */let e$2 = class e extends Event{constructor(t,s){super("context-provider",{bubbles:true,composed:true}),this.context=t,this.contextTarget=s;}};let i$1 = class i extends s{constructor(s,e,i){super(void 0!==e.context?e.initialValue:i),this.onContextRequest=t=>{if(t.context!==this.context)return;const s=t.contextTarget??t.composedPath()[0];s!==this.host&&(t.stopPropagation(),this.addCallback(t.callback,s,t.subscribe));},this.onProviderRequest=s=>{if(s.context!==this.context)return;if((s.contextTarget??s.composedPath()[0])===this.host)return;const e=new Set;for(const[s,{consumerHost:i}]of this.subscriptions)e.has(s)||(e.add(s),i.dispatchEvent(new s$2(this.context,i,s,true)));s.stopPropagation();},this.host=s,void 0!==e.context?this.context=e.context:this.context=e,this.attachListeners(),this.host.addController?.(this);}attachListeners(){this.host.addEventListener("context-request",this.onContextRequest),this.host.addEventListener("context-provider",this.onProviderRequest);}hostConnected(){this.host.dispatchEvent(new e$2(this.context,this.host));}};
36
+
37
+ /**
38
+ * @license
39
+ * Copyright 2022 Google LLC
40
+ * SPDX-License-Identifier: BSD-3-Clause
41
+ */function c({context:c,subscribe:e}){return (o,n)=>{"object"==typeof n?n.addInitializer((function(){new s$1(this,{context:c,callback:t=>{o.set.call(this,t);},subscribe:e});})):o.constructor.addInitializer((o=>{new s$1(o,{context:c,callback:t=>{o[n]=t;},subscribe:e});}));}}
42
+
43
+ const sdkContext = n("lazarillo-sdk");
44
+
45
+ const style$3 = ":host{display:block;height:100%;width:100%}#map{width:100vw;height:100vh}.maplibregl-canvas{width:100%;height:100%}.maplibregl-ctrl-bottom-right .maplibregl-ctrl{float:right;margin:0 20px 50px 0}.maplibregl-ctrl{bottom:80px;right:40px;border:3px solid #000;padding:0;border-radius:100px;background:#fff;overflow:hidden;display:flex;flex-direction:column;width:70px;height:129px}.maplibregl-ctrl button{background-color:transparent;box-shadow:none;border-radius:0;margin:0;font-size:31px;font-weight:400;width:100%;height:100%;color:#000;transition:background-color .4s ease,color .4s ease}.maplibregl-ctrl button:hover{background-color:#000!important;color:#fff}.maplibregl-ctrl button.maplibregl-ctrl-zoom-in{border-bottom:3px solid #000}.maplibregl-ctrl-group .maplibregl-ctrl-icon{background:none!important;display:none!important}.maplibregl-ctrl-group button.maplibregl-ctrl-zoom-in:after{content:\"+\";display:block;font-size:32px;font-weight:600;line-height:1;text-align:center}.maplibregl-ctrl-group button.maplibregl-ctrl-zoom-out:after{content:\"–\";display:block;font-size:32px;font-weight:600;line-height:1;text-align:center}#modal{position:absolute;width:100%;height:100%;background:#0003;-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px);display:flex;align-items:center;justify-content:center;justify-items:center;top:0;left:0;z-index:100}.modal-content{min-width:100px;min-height:100px;background-color:#fff;border:1px solid #000;border-radius:10px;padding:10px;width:fit-content;height:fit-content;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px}.modal-text{font-family:Poppins,sans-serif;font-size:20pt;font-weight:500;color:#000}.modal-icon{max-height:100px;align-self:center}.maplibregl-marker:has(.popup){z-index:10}.maplibregl-marker:not(:has(.popup)){z-index:5}";
46
+
47
+ var __defProp$3 = Object.defineProperty;
48
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
49
+ var __decorateClass$3 = (decorators, target, key, kind) => {
50
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
51
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
52
+ if (decorator = decorators[i])
53
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
54
+ if (kind && result) __defProp$3(target, key, result);
55
+ return result;
56
+ };
57
+ let CustomMap = class extends i$2 {
58
+ constructor() {
59
+ super();
60
+ this.mapReady = false;
61
+ this.routeAnimationHandlers = {
62
+ onRouteAnimationFinished: () => {
63
+ this.dispatchEvent(
64
+ new CustomEvent("routeAnimationFinished", {
65
+ bubbles: true,
66
+ composed: true
67
+ })
68
+ );
69
+ },
70
+ onFloorChange: (floorId) => {
71
+ this.dispatchEvent(
72
+ new CustomEvent("floorChange", {
73
+ detail: floorId,
74
+ bubbles: true,
75
+ composed: true
76
+ })
77
+ );
78
+ },
79
+ onStartRouteAnimation: () => {
80
+ this.dispatchEvent(
81
+ new CustomEvent("startRouteAnimation", {
82
+ bubbles: true,
83
+ composed: true
84
+ })
85
+ );
86
+ },
87
+ onShowMapModal: (modal) => {
88
+ this.modalData = modal;
89
+ },
90
+ onDismissModal: () => {
91
+ this.modalData = void 0;
92
+ }
93
+ };
94
+ this.mapContainer = null;
95
+ this.pendingUpdateMarkers = false;
96
+ this.pendingUpdateCamera = false;
97
+ this.routeAnimationController = new RouteAnimationController(this, this.routeAnimationHandlers);
98
+ this.markerController = new MarkerController(this);
99
+ }
100
+ async firstUpdated() {
101
+ if (this.shadowRoot) {
102
+ const style2 = document.createElement("style");
103
+ style2.textContent = (await import('./maplibre-gl-KgJ_zm92.js')).default;
104
+ this.shadowRoot.appendChild(style2);
105
+ }
106
+ }
107
+ async updated() {
108
+ if (!this.sdkData?.sdk) return;
109
+ const { sdk, parentPlace, locale, generalConfig, currentFloor, markers, route, isRouteAnimating } = this.sdkData;
110
+ if (!this.lzMap && sdk && parentPlace && locale && this.shadowRoot && generalConfig) {
111
+ this.routeAnimationController.setParentPlace(parentPlace);
112
+ this.routeAnimationController.setLocale(locale);
113
+ this.mapContainer = this.shadowRoot.getElementById("map");
114
+ this.shadowRoot?.appendChild(this.mapContainer);
115
+ this.config = generalConfig;
116
+ const mapConfig = {
117
+ zoom: generalConfig.initialZoom || 17,
118
+ parentPlaceId: parentPlace?.lazarilloId,
119
+ center: generalConfig.initialCenter || { lat: 0, lng: 0 },
120
+ minZoom: generalConfig.limitZoomOut || 15,
121
+ maxZoom: generalConfig.limitZoomIn || 22,
122
+ showCompass: false,
123
+ navigationPosition: "bottom-right",
124
+ pitch: generalConfig.pitch || 0,
125
+ lang: locale,
126
+ maxBounds: generalConfig.pointsOfInterest || [],
127
+ otherPotentialParentPlacesIds: generalConfig.potentialParentPlaces || [],
128
+ onMapReady: () => {
129
+ this.mapReady = true;
130
+ this.markerController.setMapReady(true);
131
+ this.pendingUpdateCamera = true;
132
+ this.dispatchEvent(
133
+ new CustomEvent("mapReady", {
134
+ detail: {},
135
+ bubbles: true,
136
+ composed: true
137
+ })
138
+ );
139
+ },
140
+ onFloorChange: (newFloorId) => {
141
+ this.setCurrentMapFloor(newFloorId);
142
+ }
143
+ };
144
+ this.lzMap = sdk.createMap(this.mapContainer, mapConfig);
145
+ this.lzMap.setParentPlace(parentPlace, false);
146
+ this.routeAnimationController.setMap(this.lzMap);
147
+ this.markerController.setMap(this.lzMap);
148
+ this.markerController.setParentPlace(parentPlace);
149
+ }
150
+ if (currentFloor && currentFloor.key !== this._currentMapFloor && this.mapReady) {
151
+ this.setCurrentMapFloor(currentFloor.key);
152
+ }
153
+ if (markers.some(
154
+ (marker) => !this.markerController.getMarkersIds().includes(marker.id) || markers.length !== this.markerController.getMarkersIds().length
155
+ )) {
156
+ if (this.mapReady) {
157
+ this.updateMarkers();
158
+ } else {
159
+ this.pendingUpdateMarkers = true;
160
+ }
161
+ }
162
+ if (this.pendingUpdateMarkers && this.mapReady) {
163
+ this.updateMarkers();
164
+ }
165
+ if (this.pendingUpdateCamera && this.sdkData?.origin) {
166
+ this._initializeCamera();
167
+ this.pendingUpdateCamera = false;
168
+ }
169
+ const currentRoute = this.routeAnimationController.getCurrentRoute();
170
+ if (!currentRoute || currentRoute.id !== route?.id) {
171
+ if (currentRoute) {
172
+ this.routeAnimationController.removeRoute();
173
+ }
174
+ if (route) {
175
+ this.routeAnimationController.startRouteAnimation(route);
176
+ }
177
+ }
178
+ if (!this.routeAnimationController.isAnimating() && isRouteAnimating && route) {
179
+ this.routeAnimationController.startRouteAnimation(route);
180
+ }
181
+ }
182
+ updateMarkers() {
183
+ const markers = this.sdkData?.markers ?? [];
184
+ this.markerController.updateMarkers(markers);
185
+ this.pendingUpdateMarkers = false;
186
+ }
187
+ _initializeCamera() {
188
+ if (!this.lzMap || !this.mapReady || !this.sdkData) return;
189
+ const { origin } = this.sdkData;
190
+ this.lzMap?.updateCamera({
191
+ bearing: this.config?.mapRotations?.[origin?.lazarilloId ?? ""]?.angle ?? 0,
192
+ animate: false,
193
+ pitch: this.config?.pitch ?? 0
194
+ });
195
+ }
196
+ setCurrentMapFloor(floorId) {
197
+ if (this._currentMapFloor === floorId || !this.lzMap) return;
198
+ this._currentMapFloor = floorId;
199
+ this.lzMap?.updateFloor(floorId);
200
+ this.routeAnimationController.setCurrentFloor(floorId);
201
+ this.dispatchEvent(
202
+ new CustomEvent("floorChange", {
203
+ detail: floorId,
204
+ bubbles: true,
205
+ composed: true
206
+ })
207
+ );
208
+ }
209
+ render() {
210
+ return x`<div id="map"></div>
211
+ <div id="modal" style="display: ${this.modalData ? "flex" : "none"}">
212
+ <div class="modal-content">
213
+ <img class="modal-icon" .src=${this.modalData?.iconPath}></img>
214
+ <p class="modal-text">${this.modalData?.title}</p>
215
+ </div>
216
+ </div>`;
217
+ }
218
+ };
219
+ CustomMap.styles = [r(style$3)];
220
+ __decorateClass$3([
221
+ c({ context: sdkContext, subscribe: true })
222
+ ], CustomMap.prototype, "sdkData", 2);
223
+ CustomMap = __decorateClass$3([
224
+ t$1("custom-map")
225
+ ], CustomMap);
226
+
227
+ const customMap = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
228
+ __proto__: null,
229
+ get CustomMap () { return CustomMap; }
230
+ }, Symbol.toStringTag, { value: 'Module' }));
231
+
232
+ /**
233
+ * @license
234
+ * Copyright 2017 Google LLC
235
+ * SPDX-License-Identifier: BSD-3-Clause
236
+ */
237
+ const t={ATTRIBUTE:1},e$1=t=>(...e)=>({_$litDirective$:t,values:e});class i{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,i){this._$Ct=t,this._$AM=e,this._$Ci=i;}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
238
+
239
+ /**
240
+ * @license
241
+ * Copyright 2018 Google LLC
242
+ * SPDX-License-Identifier: BSD-3-Clause
243
+ */const e=e$1(class extends i{constructor(t$1){if(super(t$1),t$1.type!==t.ATTRIBUTE||"class"!==t$1.name||t$1.strings?.length>2)throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.")}render(t){return " "+Object.keys(t).filter((s=>t[s])).join(" ")+" "}update(s,[i]){if(void 0===this.st){this.st=new Set,void 0!==s.strings&&(this.nt=new Set(s.strings.join(" ").split(/\s/).filter((t=>""!==t))));for(const t in i)i[t]&&!this.nt?.has(t)&&this.st.add(t);return this.render(i)}const r=s.element.classList;for(const t of this.st)t in i||(r.remove(t),this.st.delete(t));for(const t in i){const s=!!i[t];s===this.st.has(t)||this.nt?.has(t)||(s?(r.add(t),this.st.add(t)):(r.remove(t),this.st.delete(t)));}return T}});
244
+
245
+ const style$2 = ":host{position:absolute;top:0;right:10px}.floor-selector-container{display:flex;flex-direction:row;background:#fff;border-radius:0 0 30px 30px;box-shadow:0 0 15px #00000026;padding:0 24px;gap:8px;min-height:60px}.btn-floor{height:auto;width:100px;vertical-align:middle;font-size:small!important;word-wrap:break-word!important;font-family:Poppins;font-weight:600;font-size:16pt;border-radius:10px;border:0;box-shadow:0 0 15px #00000026}@media only screen and (max-width: 576px){.btn-floor{padding:6px;width:70px;height:auto;font-size:small!important}}.floor-btn-container:hover .floor-btn:not(.active):not(.disabled){width:100%;height:100%;border-radius:0 0 999px 999px;background:#000;color:#fff}.floor-btn{transition:background .2s ease,color .2s ease,transform .2s ease,opacity .2s ease;position:relative;background:transparent;border:none;outline:none;font-family:Poppins,sans-serif;font-weight:600;font-size:16px;padding:0 18px;border-radius:0 0 30px 30px;cursor:pointer;transition:all .2s ease;min-width:70px;height:100%;display:flex;align-items:center;justify-content:center;color:#000;z-index:1}.floor-btn.disabled{color:#c5c3c3;background:transparent;pointer-events:none;-webkit-tap-highlight-color:transparent;user-select:none}.floor-btn.active{color:#fff;background:transparent;z-index:2}.floor-btn.active:after{content:\"\";position:absolute;inset:0 2px;border-radius:0 0 999px 999px;background:#000;color:#fff;z-index:1}.floor-btn.active:before{content:\"\";position:absolute;inset:0 -3px -3px;border-radius:0 0 999px 999px;background:linear-gradient(45.8deg,#f5a 10.03%,#b850c9 25.23%,#6572d6 48.67%,#4eaeb8 72.74%);z-index:0}.floor-btn.active span{z-index:10}@media (max-width: 1100px){.floor-btn-container:hover .floor-btn:not(.active):not(.disabled){border-radius:999px 0 0 999px}.floor-selector-container{right:0;position:fixed;top:50%;transform:translateY(-50%);display:flex;flex-direction:column-reverse;border-radius:30px 0 0 30px;min-width:87px;max-height:100%;height:auto;padding:0;gap:0}.floor-btn-container{padding:0;width:100%}.floor-btn{width:100%;padding:20px;border-radius:999px 0 0 999px}.floor-btn.active:after{position:absolute;inset:2px 0 2px 2px;border-radius:999px 0 0 999px}.floor-btn.active:before{inset:-3px 0 -3px -3px;border-radius:999px 0 0 999px}}";
246
+
247
+ var __defProp$2 = Object.defineProperty;
248
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
249
+ var __decorateClass$2 = (decorators, target, key, kind) => {
250
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
251
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
252
+ if (decorator = decorators[i])
253
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
254
+ if (kind && result) __defProp$2(target, key, result);
255
+ return result;
256
+ };
257
+ let FloorSelector = class extends i$2 {
258
+ _selectFloor(floorKey) {
259
+ this.dispatchEvent(
260
+ new CustomEvent("floorChange", {
261
+ detail: floorKey,
262
+ bubbles: true,
263
+ composed: true
264
+ })
265
+ );
266
+ }
267
+ render() {
268
+ if (!this.sdkData) {
269
+ return x`<div>No data</div>`;
270
+ }
271
+ const { currentFloor, parentPlace, enabledFloors } = this.sdkData;
272
+ let floors = parentPlace?.innerFloors || [];
273
+ const generalConfig = this.sdkData?.generalConfig?.enabledFloors || [];
274
+ if (generalConfig.length > 0) {
275
+ floors = floors.filter((floor) => generalConfig.includes(floor.key));
276
+ }
277
+ return x`
278
+ <div class="floor-selector-container">
279
+ ${floors.map((floor) => {
280
+ const isActive = floor.key === currentFloor?.key;
281
+ const isEnabled = enabledFloors?.some((f) => f.key === floor.key) || false;
282
+ return x`
283
+ <div class="floor-btn-container">
284
+ <button
285
+ class=${e({
286
+ "floor-btn": true,
287
+ active: isActive,
288
+ disabled: !isActive && !isEnabled
289
+ })}
290
+ @click=${() => isEnabled ? this._selectFloor(floor.key) : null}
291
+ >
292
+ <span>${floor.name}</span>
293
+ </button>
294
+ </div>
295
+ `;
296
+ })}
297
+ </div>
298
+ `;
299
+ }
300
+ };
301
+ FloorSelector.styles = [r(style$2)];
302
+ __decorateClass$2([
303
+ c({ context: sdkContext, subscribe: true })
304
+ ], FloorSelector.prototype, "sdkData", 2);
305
+ FloorSelector = __decorateClass$2([
306
+ t$1("floor-selector")
307
+ ], FloorSelector);
308
+
309
+ const floorSelector = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
310
+ __proto__: null,
311
+ get FloorSelector () { return FloorSelector; }
312
+ }, Symbol.toStringTag, { value: 'Module' }));
313
+
314
+ var browser = {};
315
+
316
+ var canPromise;
317
+ var hasRequiredCanPromise;
318
+
319
+ function requireCanPromise () {
320
+ if (hasRequiredCanPromise) return canPromise;
321
+ hasRequiredCanPromise = 1;
322
+ // can-promise has a crash in some versions of react native that dont have
323
+ // standard global objects
324
+ // https://github.com/soldair/node-qrcode/issues/157
325
+
326
+ canPromise = function () {
327
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
328
+ };
329
+ return canPromise;
330
+ }
331
+
332
+ var qrcode = {};
333
+
334
+ var utils$1 = {};
335
+
336
+ var hasRequiredUtils$1;
337
+
338
+ function requireUtils$1 () {
339
+ if (hasRequiredUtils$1) return utils$1;
340
+ hasRequiredUtils$1 = 1;
341
+ let toSJISFunction;
342
+ const CODEWORDS_COUNT = [
343
+ 0, // Not used
344
+ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
345
+ 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
346
+ 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
347
+ 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
348
+ ];
349
+
350
+ /**
351
+ * Returns the QR Code size for the specified version
352
+ *
353
+ * @param {Number} version QR Code version
354
+ * @return {Number} size of QR code
355
+ */
356
+ utils$1.getSymbolSize = function getSymbolSize (version) {
357
+ if (!version) throw new Error('"version" cannot be null or undefined')
358
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
359
+ return version * 4 + 17
360
+ };
361
+
362
+ /**
363
+ * Returns the total number of codewords used to store data and EC information.
364
+ *
365
+ * @param {Number} version QR Code version
366
+ * @return {Number} Data length in bits
367
+ */
368
+ utils$1.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
369
+ return CODEWORDS_COUNT[version]
370
+ };
371
+
372
+ /**
373
+ * Encode data with Bose-Chaudhuri-Hocquenghem
374
+ *
375
+ * @param {Number} data Value to encode
376
+ * @return {Number} Encoded value
377
+ */
378
+ utils$1.getBCHDigit = function (data) {
379
+ let digit = 0;
380
+
381
+ while (data !== 0) {
382
+ digit++;
383
+ data >>>= 1;
384
+ }
385
+
386
+ return digit
387
+ };
388
+
389
+ utils$1.setToSJISFunction = function setToSJISFunction (f) {
390
+ if (typeof f !== 'function') {
391
+ throw new Error('"toSJISFunc" is not a valid function.')
392
+ }
393
+
394
+ toSJISFunction = f;
395
+ };
396
+
397
+ utils$1.isKanjiModeEnabled = function () {
398
+ return typeof toSJISFunction !== 'undefined'
399
+ };
400
+
401
+ utils$1.toSJIS = function toSJIS (kanji) {
402
+ return toSJISFunction(kanji)
403
+ };
404
+ return utils$1;
405
+ }
406
+
407
+ var errorCorrectionLevel = {};
408
+
409
+ var hasRequiredErrorCorrectionLevel;
410
+
411
+ function requireErrorCorrectionLevel () {
412
+ if (hasRequiredErrorCorrectionLevel) return errorCorrectionLevel;
413
+ hasRequiredErrorCorrectionLevel = 1;
414
+ (function (exports) {
415
+ exports.L = { bit: 1 };
416
+ exports.M = { bit: 0 };
417
+ exports.Q = { bit: 3 };
418
+ exports.H = { bit: 2 };
419
+
420
+ function fromString (string) {
421
+ if (typeof string !== 'string') {
422
+ throw new Error('Param is not a string')
423
+ }
424
+
425
+ const lcStr = string.toLowerCase();
426
+
427
+ switch (lcStr) {
428
+ case 'l':
429
+ case 'low':
430
+ return exports.L
431
+
432
+ case 'm':
433
+ case 'medium':
434
+ return exports.M
435
+
436
+ case 'q':
437
+ case 'quartile':
438
+ return exports.Q
439
+
440
+ case 'h':
441
+ case 'high':
442
+ return exports.H
443
+
444
+ default:
445
+ throw new Error('Unknown EC Level: ' + string)
446
+ }
447
+ }
448
+
449
+ exports.isValid = function isValid (level) {
450
+ return level && typeof level.bit !== 'undefined' &&
451
+ level.bit >= 0 && level.bit < 4
452
+ };
453
+
454
+ exports.from = function from (value, defaultValue) {
455
+ if (exports.isValid(value)) {
456
+ return value
457
+ }
458
+
459
+ try {
460
+ return fromString(value)
461
+ } catch (e) {
462
+ return defaultValue
463
+ }
464
+ };
465
+ } (errorCorrectionLevel));
466
+ return errorCorrectionLevel;
467
+ }
468
+
469
+ var bitBuffer;
470
+ var hasRequiredBitBuffer;
471
+
472
+ function requireBitBuffer () {
473
+ if (hasRequiredBitBuffer) return bitBuffer;
474
+ hasRequiredBitBuffer = 1;
475
+ function BitBuffer () {
476
+ this.buffer = [];
477
+ this.length = 0;
478
+ }
479
+
480
+ BitBuffer.prototype = {
481
+
482
+ get: function (index) {
483
+ const bufIndex = Math.floor(index / 8);
484
+ return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
485
+ },
486
+
487
+ put: function (num, length) {
488
+ for (let i = 0; i < length; i++) {
489
+ this.putBit(((num >>> (length - i - 1)) & 1) === 1);
490
+ }
491
+ },
492
+
493
+ getLengthInBits: function () {
494
+ return this.length
495
+ },
496
+
497
+ putBit: function (bit) {
498
+ const bufIndex = Math.floor(this.length / 8);
499
+ if (this.buffer.length <= bufIndex) {
500
+ this.buffer.push(0);
501
+ }
502
+
503
+ if (bit) {
504
+ this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
505
+ }
506
+
507
+ this.length++;
508
+ }
509
+ };
510
+
511
+ bitBuffer = BitBuffer;
512
+ return bitBuffer;
513
+ }
514
+
515
+ /**
516
+ * Helper class to handle QR Code symbol modules
517
+ *
518
+ * @param {Number} size Symbol size
519
+ */
520
+
521
+ var bitMatrix;
522
+ var hasRequiredBitMatrix;
523
+
524
+ function requireBitMatrix () {
525
+ if (hasRequiredBitMatrix) return bitMatrix;
526
+ hasRequiredBitMatrix = 1;
527
+ function BitMatrix (size) {
528
+ if (!size || size < 1) {
529
+ throw new Error('BitMatrix size must be defined and greater than 0')
530
+ }
531
+
532
+ this.size = size;
533
+ this.data = new Uint8Array(size * size);
534
+ this.reservedBit = new Uint8Array(size * size);
535
+ }
536
+
537
+ /**
538
+ * Set bit value at specified location
539
+ * If reserved flag is set, this bit will be ignored during masking process
540
+ *
541
+ * @param {Number} row
542
+ * @param {Number} col
543
+ * @param {Boolean} value
544
+ * @param {Boolean} reserved
545
+ */
546
+ BitMatrix.prototype.set = function (row, col, value, reserved) {
547
+ const index = row * this.size + col;
548
+ this.data[index] = value;
549
+ if (reserved) this.reservedBit[index] = true;
550
+ };
551
+
552
+ /**
553
+ * Returns bit value at specified location
554
+ *
555
+ * @param {Number} row
556
+ * @param {Number} col
557
+ * @return {Boolean}
558
+ */
559
+ BitMatrix.prototype.get = function (row, col) {
560
+ return this.data[row * this.size + col]
561
+ };
562
+
563
+ /**
564
+ * Applies xor operator at specified location
565
+ * (used during masking process)
566
+ *
567
+ * @param {Number} row
568
+ * @param {Number} col
569
+ * @param {Boolean} value
570
+ */
571
+ BitMatrix.prototype.xor = function (row, col, value) {
572
+ this.data[row * this.size + col] ^= value;
573
+ };
574
+
575
+ /**
576
+ * Check if bit at specified location is reserved
577
+ *
578
+ * @param {Number} row
579
+ * @param {Number} col
580
+ * @return {Boolean}
581
+ */
582
+ BitMatrix.prototype.isReserved = function (row, col) {
583
+ return this.reservedBit[row * this.size + col]
584
+ };
585
+
586
+ bitMatrix = BitMatrix;
587
+ return bitMatrix;
588
+ }
589
+
590
+ var alignmentPattern = {};
591
+
592
+ /**
593
+ * Alignment pattern are fixed reference pattern in defined positions
594
+ * in a matrix symbology, which enables the decode software to re-synchronise
595
+ * the coordinate mapping of the image modules in the event of moderate amounts
596
+ * of distortion of the image.
597
+ *
598
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
599
+ * and their number depends on the symbol version.
600
+ */
601
+
602
+ var hasRequiredAlignmentPattern;
603
+
604
+ function requireAlignmentPattern () {
605
+ if (hasRequiredAlignmentPattern) return alignmentPattern;
606
+ hasRequiredAlignmentPattern = 1;
607
+ (function (exports) {
608
+ const getSymbolSize = requireUtils$1().getSymbolSize;
609
+
610
+ /**
611
+ * Calculate the row/column coordinates of the center module of each alignment pattern
612
+ * for the specified QR Code version.
613
+ *
614
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
615
+ * running from the top left corner of the symbol to the bottom right corner.
616
+ *
617
+ * Since positions are simmetrical only half of the coordinates are returned.
618
+ * Each item of the array will represent in turn the x and y coordinate.
619
+ * @see {@link getPositions}
620
+ *
621
+ * @param {Number} version QR Code version
622
+ * @return {Array} Array of coordinate
623
+ */
624
+ exports.getRowColCoords = function getRowColCoords (version) {
625
+ if (version === 1) return []
626
+
627
+ const posCount = Math.floor(version / 7) + 2;
628
+ const size = getSymbolSize(version);
629
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
630
+ const positions = [size - 7]; // Last coord is always (size - 7)
631
+
632
+ for (let i = 1; i < posCount - 1; i++) {
633
+ positions[i] = positions[i - 1] - intervals;
634
+ }
635
+
636
+ positions.push(6); // First coord is always 6
637
+
638
+ return positions.reverse()
639
+ };
640
+
641
+ /**
642
+ * Returns an array containing the positions of each alignment pattern.
643
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
644
+ *
645
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
646
+ * and filtering out the items that overlaps with finder pattern
647
+ *
648
+ * @example
649
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
650
+ * The alignment patterns, therefore, are to be centered on (row, column)
651
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
652
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
653
+ * and are not therefore used for alignment patterns.
654
+ *
655
+ * let pos = getPositions(7)
656
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
657
+ *
658
+ * @param {Number} version QR Code version
659
+ * @return {Array} Array of coordinates
660
+ */
661
+ exports.getPositions = function getPositions (version) {
662
+ const coords = [];
663
+ const pos = exports.getRowColCoords(version);
664
+ const posLength = pos.length;
665
+
666
+ for (let i = 0; i < posLength; i++) {
667
+ for (let j = 0; j < posLength; j++) {
668
+ // Skip if position is occupied by finder patterns
669
+ if ((i === 0 && j === 0) || // top-left
670
+ (i === 0 && j === posLength - 1) || // bottom-left
671
+ (i === posLength - 1 && j === 0)) { // top-right
672
+ continue
673
+ }
674
+
675
+ coords.push([pos[i], pos[j]]);
676
+ }
677
+ }
678
+
679
+ return coords
680
+ };
681
+ } (alignmentPattern));
682
+ return alignmentPattern;
683
+ }
684
+
685
+ var finderPattern = {};
686
+
687
+ var hasRequiredFinderPattern;
688
+
689
+ function requireFinderPattern () {
690
+ if (hasRequiredFinderPattern) return finderPattern;
691
+ hasRequiredFinderPattern = 1;
692
+ const getSymbolSize = requireUtils$1().getSymbolSize;
693
+ const FINDER_PATTERN_SIZE = 7;
694
+
695
+ /**
696
+ * Returns an array containing the positions of each finder pattern.
697
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
698
+ *
699
+ * @param {Number} version QR Code version
700
+ * @return {Array} Array of coordinates
701
+ */
702
+ finderPattern.getPositions = function getPositions (version) {
703
+ const size = getSymbolSize(version);
704
+
705
+ return [
706
+ // top-left
707
+ [0, 0],
708
+ // top-right
709
+ [size - FINDER_PATTERN_SIZE, 0],
710
+ // bottom-left
711
+ [0, size - FINDER_PATTERN_SIZE]
712
+ ]
713
+ };
714
+ return finderPattern;
715
+ }
716
+
717
+ var maskPattern = {};
718
+
719
+ /**
720
+ * Data mask pattern reference
721
+ * @type {Object}
722
+ */
723
+
724
+ var hasRequiredMaskPattern;
725
+
726
+ function requireMaskPattern () {
727
+ if (hasRequiredMaskPattern) return maskPattern;
728
+ hasRequiredMaskPattern = 1;
729
+ (function (exports) {
730
+ exports.Patterns = {
731
+ PATTERN000: 0,
732
+ PATTERN001: 1,
733
+ PATTERN010: 2,
734
+ PATTERN011: 3,
735
+ PATTERN100: 4,
736
+ PATTERN101: 5,
737
+ PATTERN110: 6,
738
+ PATTERN111: 7
739
+ };
740
+
741
+ /**
742
+ * Weighted penalty scores for the undesirable features
743
+ * @type {Object}
744
+ */
745
+ const PenaltyScores = {
746
+ N1: 3,
747
+ N2: 3,
748
+ N3: 40,
749
+ N4: 10
750
+ };
751
+
752
+ /**
753
+ * Check if mask pattern value is valid
754
+ *
755
+ * @param {Number} mask Mask pattern
756
+ * @return {Boolean} true if valid, false otherwise
757
+ */
758
+ exports.isValid = function isValid (mask) {
759
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
760
+ };
761
+
762
+ /**
763
+ * Returns mask pattern from a value.
764
+ * If value is not valid, returns undefined
765
+ *
766
+ * @param {Number|String} value Mask pattern value
767
+ * @return {Number} Valid mask pattern or undefined
768
+ */
769
+ exports.from = function from (value) {
770
+ return exports.isValid(value) ? parseInt(value, 10) : undefined
771
+ };
772
+
773
+ /**
774
+ * Find adjacent modules in row/column with the same color
775
+ * and assign a penalty value.
776
+ *
777
+ * Points: N1 + i
778
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
779
+ */
780
+ exports.getPenaltyN1 = function getPenaltyN1 (data) {
781
+ const size = data.size;
782
+ let points = 0;
783
+ let sameCountCol = 0;
784
+ let sameCountRow = 0;
785
+ let lastCol = null;
786
+ let lastRow = null;
787
+
788
+ for (let row = 0; row < size; row++) {
789
+ sameCountCol = sameCountRow = 0;
790
+ lastCol = lastRow = null;
791
+
792
+ for (let col = 0; col < size; col++) {
793
+ let module = data.get(row, col);
794
+ if (module === lastCol) {
795
+ sameCountCol++;
796
+ } else {
797
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
798
+ lastCol = module;
799
+ sameCountCol = 1;
800
+ }
801
+
802
+ module = data.get(col, row);
803
+ if (module === lastRow) {
804
+ sameCountRow++;
805
+ } else {
806
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
807
+ lastRow = module;
808
+ sameCountRow = 1;
809
+ }
810
+ }
811
+
812
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
813
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
814
+ }
815
+
816
+ return points
817
+ };
818
+
819
+ /**
820
+ * Find 2x2 blocks with the same color and assign a penalty value
821
+ *
822
+ * Points: N2 * (m - 1) * (n - 1)
823
+ */
824
+ exports.getPenaltyN2 = function getPenaltyN2 (data) {
825
+ const size = data.size;
826
+ let points = 0;
827
+
828
+ for (let row = 0; row < size - 1; row++) {
829
+ for (let col = 0; col < size - 1; col++) {
830
+ const last = data.get(row, col) +
831
+ data.get(row, col + 1) +
832
+ data.get(row + 1, col) +
833
+ data.get(row + 1, col + 1);
834
+
835
+ if (last === 4 || last === 0) points++;
836
+ }
837
+ }
838
+
839
+ return points * PenaltyScores.N2
840
+ };
841
+
842
+ /**
843
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
844
+ * preceded or followed by light area 4 modules wide
845
+ *
846
+ * Points: N3 * number of pattern found
847
+ */
848
+ exports.getPenaltyN3 = function getPenaltyN3 (data) {
849
+ const size = data.size;
850
+ let points = 0;
851
+ let bitsCol = 0;
852
+ let bitsRow = 0;
853
+
854
+ for (let row = 0; row < size; row++) {
855
+ bitsCol = bitsRow = 0;
856
+ for (let col = 0; col < size; col++) {
857
+ bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
858
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
859
+
860
+ bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
861
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
862
+ }
863
+ }
864
+
865
+ return points * PenaltyScores.N3
866
+ };
867
+
868
+ /**
869
+ * Calculate proportion of dark modules in entire symbol
870
+ *
871
+ * Points: N4 * k
872
+ *
873
+ * k is the rating of the deviation of the proportion of dark modules
874
+ * in the symbol from 50% in steps of 5%
875
+ */
876
+ exports.getPenaltyN4 = function getPenaltyN4 (data) {
877
+ let darkCount = 0;
878
+ const modulesCount = data.data.length;
879
+
880
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
881
+
882
+ const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
883
+
884
+ return k * PenaltyScores.N4
885
+ };
886
+
887
+ /**
888
+ * Return mask value at given position
889
+ *
890
+ * @param {Number} maskPattern Pattern reference value
891
+ * @param {Number} i Row
892
+ * @param {Number} j Column
893
+ * @return {Boolean} Mask value
894
+ */
895
+ function getMaskAt (maskPattern, i, j) {
896
+ switch (maskPattern) {
897
+ case exports.Patterns.PATTERN000: return (i + j) % 2 === 0
898
+ case exports.Patterns.PATTERN001: return i % 2 === 0
899
+ case exports.Patterns.PATTERN010: return j % 3 === 0
900
+ case exports.Patterns.PATTERN011: return (i + j) % 3 === 0
901
+ case exports.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
902
+ case exports.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
903
+ case exports.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
904
+ case exports.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
905
+
906
+ default: throw new Error('bad maskPattern:' + maskPattern)
907
+ }
908
+ }
909
+
910
+ /**
911
+ * Apply a mask pattern to a BitMatrix
912
+ *
913
+ * @param {Number} pattern Pattern reference number
914
+ * @param {BitMatrix} data BitMatrix data
915
+ */
916
+ exports.applyMask = function applyMask (pattern, data) {
917
+ const size = data.size;
918
+
919
+ for (let col = 0; col < size; col++) {
920
+ for (let row = 0; row < size; row++) {
921
+ if (data.isReserved(row, col)) continue
922
+ data.xor(row, col, getMaskAt(pattern, row, col));
923
+ }
924
+ }
925
+ };
926
+
927
+ /**
928
+ * Returns the best mask pattern for data
929
+ *
930
+ * @param {BitMatrix} data
931
+ * @return {Number} Mask pattern reference number
932
+ */
933
+ exports.getBestMask = function getBestMask (data, setupFormatFunc) {
934
+ const numPatterns = Object.keys(exports.Patterns).length;
935
+ let bestPattern = 0;
936
+ let lowerPenalty = Infinity;
937
+
938
+ for (let p = 0; p < numPatterns; p++) {
939
+ setupFormatFunc(p);
940
+ exports.applyMask(p, data);
941
+
942
+ // Calculate penalty
943
+ const penalty =
944
+ exports.getPenaltyN1(data) +
945
+ exports.getPenaltyN2(data) +
946
+ exports.getPenaltyN3(data) +
947
+ exports.getPenaltyN4(data);
948
+
949
+ // Undo previously applied mask
950
+ exports.applyMask(p, data);
951
+
952
+ if (penalty < lowerPenalty) {
953
+ lowerPenalty = penalty;
954
+ bestPattern = p;
955
+ }
956
+ }
957
+
958
+ return bestPattern
959
+ };
960
+ } (maskPattern));
961
+ return maskPattern;
962
+ }
963
+
964
+ var errorCorrectionCode = {};
965
+
966
+ var hasRequiredErrorCorrectionCode;
967
+
968
+ function requireErrorCorrectionCode () {
969
+ if (hasRequiredErrorCorrectionCode) return errorCorrectionCode;
970
+ hasRequiredErrorCorrectionCode = 1;
971
+ const ECLevel = requireErrorCorrectionLevel();
972
+
973
+ const EC_BLOCKS_TABLE = [
974
+ // L M Q H
975
+ 1, 1, 1, 1,
976
+ 1, 1, 1, 1,
977
+ 1, 1, 2, 2,
978
+ 1, 2, 2, 4,
979
+ 1, 2, 4, 4,
980
+ 2, 4, 4, 4,
981
+ 2, 4, 6, 5,
982
+ 2, 4, 6, 6,
983
+ 2, 5, 8, 8,
984
+ 4, 5, 8, 8,
985
+ 4, 5, 8, 11,
986
+ 4, 8, 10, 11,
987
+ 4, 9, 12, 16,
988
+ 4, 9, 16, 16,
989
+ 6, 10, 12, 18,
990
+ 6, 10, 17, 16,
991
+ 6, 11, 16, 19,
992
+ 6, 13, 18, 21,
993
+ 7, 14, 21, 25,
994
+ 8, 16, 20, 25,
995
+ 8, 17, 23, 25,
996
+ 9, 17, 23, 34,
997
+ 9, 18, 25, 30,
998
+ 10, 20, 27, 32,
999
+ 12, 21, 29, 35,
1000
+ 12, 23, 34, 37,
1001
+ 12, 25, 34, 40,
1002
+ 13, 26, 35, 42,
1003
+ 14, 28, 38, 45,
1004
+ 15, 29, 40, 48,
1005
+ 16, 31, 43, 51,
1006
+ 17, 33, 45, 54,
1007
+ 18, 35, 48, 57,
1008
+ 19, 37, 51, 60,
1009
+ 19, 38, 53, 63,
1010
+ 20, 40, 56, 66,
1011
+ 21, 43, 59, 70,
1012
+ 22, 45, 62, 74,
1013
+ 24, 47, 65, 77,
1014
+ 25, 49, 68, 81
1015
+ ];
1016
+
1017
+ const EC_CODEWORDS_TABLE = [
1018
+ // L M Q H
1019
+ 7, 10, 13, 17,
1020
+ 10, 16, 22, 28,
1021
+ 15, 26, 36, 44,
1022
+ 20, 36, 52, 64,
1023
+ 26, 48, 72, 88,
1024
+ 36, 64, 96, 112,
1025
+ 40, 72, 108, 130,
1026
+ 48, 88, 132, 156,
1027
+ 60, 110, 160, 192,
1028
+ 72, 130, 192, 224,
1029
+ 80, 150, 224, 264,
1030
+ 96, 176, 260, 308,
1031
+ 104, 198, 288, 352,
1032
+ 120, 216, 320, 384,
1033
+ 132, 240, 360, 432,
1034
+ 144, 280, 408, 480,
1035
+ 168, 308, 448, 532,
1036
+ 180, 338, 504, 588,
1037
+ 196, 364, 546, 650,
1038
+ 224, 416, 600, 700,
1039
+ 224, 442, 644, 750,
1040
+ 252, 476, 690, 816,
1041
+ 270, 504, 750, 900,
1042
+ 300, 560, 810, 960,
1043
+ 312, 588, 870, 1050,
1044
+ 336, 644, 952, 1110,
1045
+ 360, 700, 1020, 1200,
1046
+ 390, 728, 1050, 1260,
1047
+ 420, 784, 1140, 1350,
1048
+ 450, 812, 1200, 1440,
1049
+ 480, 868, 1290, 1530,
1050
+ 510, 924, 1350, 1620,
1051
+ 540, 980, 1440, 1710,
1052
+ 570, 1036, 1530, 1800,
1053
+ 570, 1064, 1590, 1890,
1054
+ 600, 1120, 1680, 1980,
1055
+ 630, 1204, 1770, 2100,
1056
+ 660, 1260, 1860, 2220,
1057
+ 720, 1316, 1950, 2310,
1058
+ 750, 1372, 2040, 2430
1059
+ ];
1060
+
1061
+ /**
1062
+ * Returns the number of error correction block that the QR Code should contain
1063
+ * for the specified version and error correction level.
1064
+ *
1065
+ * @param {Number} version QR Code version
1066
+ * @param {Number} errorCorrectionLevel Error correction level
1067
+ * @return {Number} Number of error correction blocks
1068
+ */
1069
+ errorCorrectionCode.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
1070
+ switch (errorCorrectionLevel) {
1071
+ case ECLevel.L:
1072
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
1073
+ case ECLevel.M:
1074
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
1075
+ case ECLevel.Q:
1076
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
1077
+ case ECLevel.H:
1078
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
1079
+ default:
1080
+ return undefined
1081
+ }
1082
+ };
1083
+
1084
+ /**
1085
+ * Returns the number of error correction codewords to use for the specified
1086
+ * version and error correction level.
1087
+ *
1088
+ * @param {Number} version QR Code version
1089
+ * @param {Number} errorCorrectionLevel Error correction level
1090
+ * @return {Number} Number of error correction codewords
1091
+ */
1092
+ errorCorrectionCode.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
1093
+ switch (errorCorrectionLevel) {
1094
+ case ECLevel.L:
1095
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
1096
+ case ECLevel.M:
1097
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
1098
+ case ECLevel.Q:
1099
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
1100
+ case ECLevel.H:
1101
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
1102
+ default:
1103
+ return undefined
1104
+ }
1105
+ };
1106
+ return errorCorrectionCode;
1107
+ }
1108
+
1109
+ var polynomial = {};
1110
+
1111
+ var galoisField = {};
1112
+
1113
+ var hasRequiredGaloisField;
1114
+
1115
+ function requireGaloisField () {
1116
+ if (hasRequiredGaloisField) return galoisField;
1117
+ hasRequiredGaloisField = 1;
1118
+ const EXP_TABLE = new Uint8Array(512);
1119
+ const LOG_TABLE = new Uint8Array(256)
1120
+ /**
1121
+ * Precompute the log and anti-log tables for faster computation later
1122
+ *
1123
+ * For each possible value in the galois field 2^8, we will pre-compute
1124
+ * the logarithm and anti-logarithm (exponential) of this value
1125
+ *
1126
+ * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
1127
+ */
1128
+ ;(function initTables () {
1129
+ let x = 1;
1130
+ for (let i = 0; i < 255; i++) {
1131
+ EXP_TABLE[i] = x;
1132
+ LOG_TABLE[x] = i;
1133
+
1134
+ x <<= 1; // multiply by 2
1135
+
1136
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
1137
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
1138
+ if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
1139
+ x ^= 0x11D;
1140
+ }
1141
+ }
1142
+
1143
+ // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
1144
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
1145
+ // two GF numbers, no more).
1146
+ // @see {@link mul}
1147
+ for (let i = 255; i < 512; i++) {
1148
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
1149
+ }
1150
+ }());
1151
+
1152
+ /**
1153
+ * Returns log value of n inside Galois Field
1154
+ *
1155
+ * @param {Number} n
1156
+ * @return {Number}
1157
+ */
1158
+ galoisField.log = function log (n) {
1159
+ if (n < 1) throw new Error('log(' + n + ')')
1160
+ return LOG_TABLE[n]
1161
+ };
1162
+
1163
+ /**
1164
+ * Returns anti-log value of n inside Galois Field
1165
+ *
1166
+ * @param {Number} n
1167
+ * @return {Number}
1168
+ */
1169
+ galoisField.exp = function exp (n) {
1170
+ return EXP_TABLE[n]
1171
+ };
1172
+
1173
+ /**
1174
+ * Multiplies two number inside Galois Field
1175
+ *
1176
+ * @param {Number} x
1177
+ * @param {Number} y
1178
+ * @return {Number}
1179
+ */
1180
+ galoisField.mul = function mul (x, y) {
1181
+ if (x === 0 || y === 0) return 0
1182
+
1183
+ // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
1184
+ // @see {@link initTables}
1185
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
1186
+ };
1187
+ return galoisField;
1188
+ }
1189
+
1190
+ var hasRequiredPolynomial;
1191
+
1192
+ function requirePolynomial () {
1193
+ if (hasRequiredPolynomial) return polynomial;
1194
+ hasRequiredPolynomial = 1;
1195
+ (function (exports) {
1196
+ const GF = requireGaloisField();
1197
+
1198
+ /**
1199
+ * Multiplies two polynomials inside Galois Field
1200
+ *
1201
+ * @param {Uint8Array} p1 Polynomial
1202
+ * @param {Uint8Array} p2 Polynomial
1203
+ * @return {Uint8Array} Product of p1 and p2
1204
+ */
1205
+ exports.mul = function mul (p1, p2) {
1206
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
1207
+
1208
+ for (let i = 0; i < p1.length; i++) {
1209
+ for (let j = 0; j < p2.length; j++) {
1210
+ coeff[i + j] ^= GF.mul(p1[i], p2[j]);
1211
+ }
1212
+ }
1213
+
1214
+ return coeff
1215
+ };
1216
+
1217
+ /**
1218
+ * Calculate the remainder of polynomials division
1219
+ *
1220
+ * @param {Uint8Array} divident Polynomial
1221
+ * @param {Uint8Array} divisor Polynomial
1222
+ * @return {Uint8Array} Remainder
1223
+ */
1224
+ exports.mod = function mod (divident, divisor) {
1225
+ let result = new Uint8Array(divident);
1226
+
1227
+ while ((result.length - divisor.length) >= 0) {
1228
+ const coeff = result[0];
1229
+
1230
+ for (let i = 0; i < divisor.length; i++) {
1231
+ result[i] ^= GF.mul(divisor[i], coeff);
1232
+ }
1233
+
1234
+ // remove all zeros from buffer head
1235
+ let offset = 0;
1236
+ while (offset < result.length && result[offset] === 0) offset++;
1237
+ result = result.slice(offset);
1238
+ }
1239
+
1240
+ return result
1241
+ };
1242
+
1243
+ /**
1244
+ * Generate an irreducible generator polynomial of specified degree
1245
+ * (used by Reed-Solomon encoder)
1246
+ *
1247
+ * @param {Number} degree Degree of the generator polynomial
1248
+ * @return {Uint8Array} Buffer containing polynomial coefficients
1249
+ */
1250
+ exports.generateECPolynomial = function generateECPolynomial (degree) {
1251
+ let poly = new Uint8Array([1]);
1252
+ for (let i = 0; i < degree; i++) {
1253
+ poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
1254
+ }
1255
+
1256
+ return poly
1257
+ };
1258
+ } (polynomial));
1259
+ return polynomial;
1260
+ }
1261
+
1262
+ var reedSolomonEncoder;
1263
+ var hasRequiredReedSolomonEncoder;
1264
+
1265
+ function requireReedSolomonEncoder () {
1266
+ if (hasRequiredReedSolomonEncoder) return reedSolomonEncoder;
1267
+ hasRequiredReedSolomonEncoder = 1;
1268
+ const Polynomial = requirePolynomial();
1269
+
1270
+ function ReedSolomonEncoder (degree) {
1271
+ this.genPoly = undefined;
1272
+ this.degree = degree;
1273
+
1274
+ if (this.degree) this.initialize(this.degree);
1275
+ }
1276
+
1277
+ /**
1278
+ * Initialize the encoder.
1279
+ * The input param should correspond to the number of error correction codewords.
1280
+ *
1281
+ * @param {Number} degree
1282
+ */
1283
+ ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
1284
+ // create an irreducible generator polynomial
1285
+ this.degree = degree;
1286
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
1287
+ };
1288
+
1289
+ /**
1290
+ * Encodes a chunk of data
1291
+ *
1292
+ * @param {Uint8Array} data Buffer containing input data
1293
+ * @return {Uint8Array} Buffer containing encoded data
1294
+ */
1295
+ ReedSolomonEncoder.prototype.encode = function encode (data) {
1296
+ if (!this.genPoly) {
1297
+ throw new Error('Encoder not initialized')
1298
+ }
1299
+
1300
+ // Calculate EC for this data block
1301
+ // extends data size to data+genPoly size
1302
+ const paddedData = new Uint8Array(data.length + this.degree);
1303
+ paddedData.set(data);
1304
+
1305
+ // The error correction codewords are the remainder after dividing the data codewords
1306
+ // by a generator polynomial
1307
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
1308
+
1309
+ // return EC data blocks (last n byte, where n is the degree of genPoly)
1310
+ // If coefficients number in remainder are less than genPoly degree,
1311
+ // pad with 0s to the left to reach the needed number of coefficients
1312
+ const start = this.degree - remainder.length;
1313
+ if (start > 0) {
1314
+ const buff = new Uint8Array(this.degree);
1315
+ buff.set(remainder, start);
1316
+
1317
+ return buff
1318
+ }
1319
+
1320
+ return remainder
1321
+ };
1322
+
1323
+ reedSolomonEncoder = ReedSolomonEncoder;
1324
+ return reedSolomonEncoder;
1325
+ }
1326
+
1327
+ var version = {};
1328
+
1329
+ var mode = {};
1330
+
1331
+ var versionCheck = {};
1332
+
1333
+ /**
1334
+ * Check if QR Code version is valid
1335
+ *
1336
+ * @param {Number} version QR Code version
1337
+ * @return {Boolean} true if valid version, false otherwise
1338
+ */
1339
+
1340
+ var hasRequiredVersionCheck;
1341
+
1342
+ function requireVersionCheck () {
1343
+ if (hasRequiredVersionCheck) return versionCheck;
1344
+ hasRequiredVersionCheck = 1;
1345
+ versionCheck.isValid = function isValid (version) {
1346
+ return !isNaN(version) && version >= 1 && version <= 40
1347
+ };
1348
+ return versionCheck;
1349
+ }
1350
+
1351
+ var regex = {};
1352
+
1353
+ var hasRequiredRegex;
1354
+
1355
+ function requireRegex () {
1356
+ if (hasRequiredRegex) return regex;
1357
+ hasRequiredRegex = 1;
1358
+ const numeric = '[0-9]+';
1359
+ const alphanumeric = '[A-Z $%*+\\-./:]+';
1360
+ let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
1361
+ '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
1362
+ '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
1363
+ '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
1364
+ kanji = kanji.replace(/u/g, '\\u');
1365
+
1366
+ const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
1367
+
1368
+ regex.KANJI = new RegExp(kanji, 'g');
1369
+ regex.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
1370
+ regex.BYTE = new RegExp(byte, 'g');
1371
+ regex.NUMERIC = new RegExp(numeric, 'g');
1372
+ regex.ALPHANUMERIC = new RegExp(alphanumeric, 'g');
1373
+
1374
+ const TEST_KANJI = new RegExp('^' + kanji + '$');
1375
+ const TEST_NUMERIC = new RegExp('^' + numeric + '$');
1376
+ const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
1377
+
1378
+ regex.testKanji = function testKanji (str) {
1379
+ return TEST_KANJI.test(str)
1380
+ };
1381
+
1382
+ regex.testNumeric = function testNumeric (str) {
1383
+ return TEST_NUMERIC.test(str)
1384
+ };
1385
+
1386
+ regex.testAlphanumeric = function testAlphanumeric (str) {
1387
+ return TEST_ALPHANUMERIC.test(str)
1388
+ };
1389
+ return regex;
1390
+ }
1391
+
1392
+ var hasRequiredMode;
1393
+
1394
+ function requireMode () {
1395
+ if (hasRequiredMode) return mode;
1396
+ hasRequiredMode = 1;
1397
+ (function (exports) {
1398
+ const VersionCheck = requireVersionCheck();
1399
+ const Regex = requireRegex();
1400
+
1401
+ /**
1402
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1403
+ * (byte values 30HEX to 39HEX).
1404
+ * Normally, 3 data characters are represented by 10 bits.
1405
+ *
1406
+ * @type {Object}
1407
+ */
1408
+ exports.NUMERIC = {
1409
+ id: 'Numeric',
1410
+ bit: 1 << 0,
1411
+ ccBits: [10, 12, 14]
1412
+ };
1413
+
1414
+ /**
1415
+ * Alphanumeric mode encodes data from a set of 45 characters,
1416
+ * i.e. 10 numeric digits (0 - 9),
1417
+ * 26 alphabetic characters (A - Z),
1418
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1419
+ * Normally, two input characters are represented by 11 bits.
1420
+ *
1421
+ * @type {Object}
1422
+ */
1423
+ exports.ALPHANUMERIC = {
1424
+ id: 'Alphanumeric',
1425
+ bit: 1 << 1,
1426
+ ccBits: [9, 11, 13]
1427
+ };
1428
+
1429
+ /**
1430
+ * In byte mode, data is encoded at 8 bits per character.
1431
+ *
1432
+ * @type {Object}
1433
+ */
1434
+ exports.BYTE = {
1435
+ id: 'Byte',
1436
+ bit: 1 << 2,
1437
+ ccBits: [8, 16, 16]
1438
+ };
1439
+
1440
+ /**
1441
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1442
+ * the Shift JIS system based on JIS X 0208.
1443
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1444
+ * JIS X 0208 gives details of the shift coded representation.
1445
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1446
+ *
1447
+ * @type {Object}
1448
+ */
1449
+ exports.KANJI = {
1450
+ id: 'Kanji',
1451
+ bit: 1 << 3,
1452
+ ccBits: [8, 10, 12]
1453
+ };
1454
+
1455
+ /**
1456
+ * Mixed mode will contain a sequences of data in a combination of any of
1457
+ * the modes described above
1458
+ *
1459
+ * @type {Object}
1460
+ */
1461
+ exports.MIXED = {
1462
+ bit: -1
1463
+ };
1464
+
1465
+ /**
1466
+ * Returns the number of bits needed to store the data length
1467
+ * according to QR Code specifications.
1468
+ *
1469
+ * @param {Mode} mode Data mode
1470
+ * @param {Number} version QR Code version
1471
+ * @return {Number} Number of bits
1472
+ */
1473
+ exports.getCharCountIndicator = function getCharCountIndicator (mode, version) {
1474
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
1475
+
1476
+ if (!VersionCheck.isValid(version)) {
1477
+ throw new Error('Invalid version: ' + version)
1478
+ }
1479
+
1480
+ if (version >= 1 && version < 10) return mode.ccBits[0]
1481
+ else if (version < 27) return mode.ccBits[1]
1482
+ return mode.ccBits[2]
1483
+ };
1484
+
1485
+ /**
1486
+ * Returns the most efficient mode to store the specified data
1487
+ *
1488
+ * @param {String} dataStr Input data string
1489
+ * @return {Mode} Best mode
1490
+ */
1491
+ exports.getBestModeForData = function getBestModeForData (dataStr) {
1492
+ if (Regex.testNumeric(dataStr)) return exports.NUMERIC
1493
+ else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC
1494
+ else if (Regex.testKanji(dataStr)) return exports.KANJI
1495
+ else return exports.BYTE
1496
+ };
1497
+
1498
+ /**
1499
+ * Return mode name as string
1500
+ *
1501
+ * @param {Mode} mode Mode object
1502
+ * @returns {String} Mode name
1503
+ */
1504
+ exports.toString = function toString (mode) {
1505
+ if (mode && mode.id) return mode.id
1506
+ throw new Error('Invalid mode')
1507
+ };
1508
+
1509
+ /**
1510
+ * Check if input param is a valid mode object
1511
+ *
1512
+ * @param {Mode} mode Mode object
1513
+ * @returns {Boolean} True if valid mode, false otherwise
1514
+ */
1515
+ exports.isValid = function isValid (mode) {
1516
+ return mode && mode.bit && mode.ccBits
1517
+ };
1518
+
1519
+ /**
1520
+ * Get mode object from its name
1521
+ *
1522
+ * @param {String} string Mode name
1523
+ * @returns {Mode} Mode object
1524
+ */
1525
+ function fromString (string) {
1526
+ if (typeof string !== 'string') {
1527
+ throw new Error('Param is not a string')
1528
+ }
1529
+
1530
+ const lcStr = string.toLowerCase();
1531
+
1532
+ switch (lcStr) {
1533
+ case 'numeric':
1534
+ return exports.NUMERIC
1535
+ case 'alphanumeric':
1536
+ return exports.ALPHANUMERIC
1537
+ case 'kanji':
1538
+ return exports.KANJI
1539
+ case 'byte':
1540
+ return exports.BYTE
1541
+ default:
1542
+ throw new Error('Unknown mode: ' + string)
1543
+ }
1544
+ }
1545
+
1546
+ /**
1547
+ * Returns mode from a value.
1548
+ * If value is not a valid mode, returns defaultValue
1549
+ *
1550
+ * @param {Mode|String} value Encoding mode
1551
+ * @param {Mode} defaultValue Fallback value
1552
+ * @return {Mode} Encoding mode
1553
+ */
1554
+ exports.from = function from (value, defaultValue) {
1555
+ if (exports.isValid(value)) {
1556
+ return value
1557
+ }
1558
+
1559
+ try {
1560
+ return fromString(value)
1561
+ } catch (e) {
1562
+ return defaultValue
1563
+ }
1564
+ };
1565
+ } (mode));
1566
+ return mode;
1567
+ }
1568
+
1569
+ var hasRequiredVersion;
1570
+
1571
+ function requireVersion () {
1572
+ if (hasRequiredVersion) return version;
1573
+ hasRequiredVersion = 1;
1574
+ (function (exports) {
1575
+ const Utils = requireUtils$1();
1576
+ const ECCode = requireErrorCorrectionCode();
1577
+ const ECLevel = requireErrorCorrectionLevel();
1578
+ const Mode = requireMode();
1579
+ const VersionCheck = requireVersionCheck();
1580
+
1581
+ // Generator polynomial used to encode version information
1582
+ const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
1583
+ const G18_BCH = Utils.getBCHDigit(G18);
1584
+
1585
+ function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
1586
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1587
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1588
+ return currentVersion
1589
+ }
1590
+ }
1591
+
1592
+ return undefined
1593
+ }
1594
+
1595
+ function getReservedBitsCount (mode, version) {
1596
+ // Character count indicator + mode indicator bits
1597
+ return Mode.getCharCountIndicator(mode, version) + 4
1598
+ }
1599
+
1600
+ function getTotalBitsFromDataArray (segments, version) {
1601
+ let totalBits = 0;
1602
+
1603
+ segments.forEach(function (data) {
1604
+ const reservedBits = getReservedBitsCount(data.mode, version);
1605
+ totalBits += reservedBits + data.getBitsLength();
1606
+ });
1607
+
1608
+ return totalBits
1609
+ }
1610
+
1611
+ function getBestVersionForMixedData (segments, errorCorrectionLevel) {
1612
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1613
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
1614
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
1615
+ return currentVersion
1616
+ }
1617
+ }
1618
+
1619
+ return undefined
1620
+ }
1621
+
1622
+ /**
1623
+ * Returns version number from a value.
1624
+ * If value is not a valid version, returns defaultValue
1625
+ *
1626
+ * @param {Number|String} value QR Code version
1627
+ * @param {Number} defaultValue Fallback value
1628
+ * @return {Number} QR Code version number
1629
+ */
1630
+ exports.from = function from (value, defaultValue) {
1631
+ if (VersionCheck.isValid(value)) {
1632
+ return parseInt(value, 10)
1633
+ }
1634
+
1635
+ return defaultValue
1636
+ };
1637
+
1638
+ /**
1639
+ * Returns how much data can be stored with the specified QR code version
1640
+ * and error correction level
1641
+ *
1642
+ * @param {Number} version QR Code version (1-40)
1643
+ * @param {Number} errorCorrectionLevel Error correction level
1644
+ * @param {Mode} mode Data mode
1645
+ * @return {Number} Quantity of storable data
1646
+ */
1647
+ exports.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
1648
+ if (!VersionCheck.isValid(version)) {
1649
+ throw new Error('Invalid QR Code version')
1650
+ }
1651
+
1652
+ // Use Byte mode as default
1653
+ if (typeof mode === 'undefined') mode = Mode.BYTE;
1654
+
1655
+ // Total codewords for this QR code version (Data + Error correction)
1656
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
1657
+
1658
+ // Total number of error correction codewords
1659
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1660
+
1661
+ // Total number of data codewords
1662
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1663
+
1664
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits
1665
+
1666
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1667
+
1668
+ // Return max number of storable codewords
1669
+ switch (mode) {
1670
+ case Mode.NUMERIC:
1671
+ return Math.floor((usableBits / 10) * 3)
1672
+
1673
+ case Mode.ALPHANUMERIC:
1674
+ return Math.floor((usableBits / 11) * 2)
1675
+
1676
+ case Mode.KANJI:
1677
+ return Math.floor(usableBits / 13)
1678
+
1679
+ case Mode.BYTE:
1680
+ default:
1681
+ return Math.floor(usableBits / 8)
1682
+ }
1683
+ };
1684
+
1685
+ /**
1686
+ * Returns the minimum version needed to contain the amount of data
1687
+ *
1688
+ * @param {Segment} data Segment of data
1689
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1690
+ * @param {Mode} mode Data mode
1691
+ * @return {Number} QR Code version
1692
+ */
1693
+ exports.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
1694
+ let seg;
1695
+
1696
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1697
+
1698
+ if (Array.isArray(data)) {
1699
+ if (data.length > 1) {
1700
+ return getBestVersionForMixedData(data, ecl)
1701
+ }
1702
+
1703
+ if (data.length === 0) {
1704
+ return 1
1705
+ }
1706
+
1707
+ seg = data[0];
1708
+ } else {
1709
+ seg = data;
1710
+ }
1711
+
1712
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
1713
+ };
1714
+
1715
+ /**
1716
+ * Returns version information with relative error correction bits
1717
+ *
1718
+ * The version information is included in QR Code symbols of version 7 or larger.
1719
+ * It consists of an 18-bit sequence containing 6 data bits,
1720
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1721
+ *
1722
+ * @param {Number} version QR Code version
1723
+ * @return {Number} Encoded version info bits
1724
+ */
1725
+ exports.getEncodedBits = function getEncodedBits (version) {
1726
+ if (!VersionCheck.isValid(version) || version < 7) {
1727
+ throw new Error('Invalid QR Code version')
1728
+ }
1729
+
1730
+ let d = version << 12;
1731
+
1732
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
1733
+ d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH));
1734
+ }
1735
+
1736
+ return (version << 12) | d
1737
+ };
1738
+ } (version));
1739
+ return version;
1740
+ }
1741
+
1742
+ var formatInfo = {};
1743
+
1744
+ var hasRequiredFormatInfo;
1745
+
1746
+ function requireFormatInfo () {
1747
+ if (hasRequiredFormatInfo) return formatInfo;
1748
+ hasRequiredFormatInfo = 1;
1749
+ const Utils = requireUtils$1();
1750
+
1751
+ const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
1752
+ const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
1753
+ const G15_BCH = Utils.getBCHDigit(G15);
1754
+
1755
+ /**
1756
+ * Returns format information with relative error correction bits
1757
+ *
1758
+ * The format information is a 15-bit sequence containing 5 data bits,
1759
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1760
+ *
1761
+ * @param {Number} errorCorrectionLevel Error correction level
1762
+ * @param {Number} mask Mask pattern
1763
+ * @return {Number} Encoded format information bits
1764
+ */
1765
+ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
1766
+ const data = ((errorCorrectionLevel.bit << 3) | mask);
1767
+ let d = data << 10;
1768
+
1769
+ while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
1770
+ d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH));
1771
+ }
1772
+
1773
+ // xor final data with mask pattern in order to ensure that
1774
+ // no combination of Error Correction Level and data mask pattern
1775
+ // will result in an all-zero data string
1776
+ return ((data << 10) | d) ^ G15_MASK
1777
+ };
1778
+ return formatInfo;
1779
+ }
1780
+
1781
+ var segments = {};
1782
+
1783
+ var numericData;
1784
+ var hasRequiredNumericData;
1785
+
1786
+ function requireNumericData () {
1787
+ if (hasRequiredNumericData) return numericData;
1788
+ hasRequiredNumericData = 1;
1789
+ const Mode = requireMode();
1790
+
1791
+ function NumericData (data) {
1792
+ this.mode = Mode.NUMERIC;
1793
+ this.data = data.toString();
1794
+ }
1795
+
1796
+ NumericData.getBitsLength = function getBitsLength (length) {
1797
+ return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
1798
+ };
1799
+
1800
+ NumericData.prototype.getLength = function getLength () {
1801
+ return this.data.length
1802
+ };
1803
+
1804
+ NumericData.prototype.getBitsLength = function getBitsLength () {
1805
+ return NumericData.getBitsLength(this.data.length)
1806
+ };
1807
+
1808
+ NumericData.prototype.write = function write (bitBuffer) {
1809
+ let i, group, value;
1810
+
1811
+ // The input data string is divided into groups of three digits,
1812
+ // and each group is converted to its 10-bit binary equivalent.
1813
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1814
+ group = this.data.substr(i, 3);
1815
+ value = parseInt(group, 10);
1816
+
1817
+ bitBuffer.put(value, 10);
1818
+ }
1819
+
1820
+ // If the number of input digits is not an exact multiple of three,
1821
+ // the final one or two digits are converted to 4 or 7 bits respectively.
1822
+ const remainingNum = this.data.length - i;
1823
+ if (remainingNum > 0) {
1824
+ group = this.data.substr(i);
1825
+ value = parseInt(group, 10);
1826
+
1827
+ bitBuffer.put(value, remainingNum * 3 + 1);
1828
+ }
1829
+ };
1830
+
1831
+ numericData = NumericData;
1832
+ return numericData;
1833
+ }
1834
+
1835
+ var alphanumericData;
1836
+ var hasRequiredAlphanumericData;
1837
+
1838
+ function requireAlphanumericData () {
1839
+ if (hasRequiredAlphanumericData) return alphanumericData;
1840
+ hasRequiredAlphanumericData = 1;
1841
+ const Mode = requireMode();
1842
+
1843
+ /**
1844
+ * Array of characters available in alphanumeric mode
1845
+ *
1846
+ * As per QR Code specification, to each character
1847
+ * is assigned a value from 0 to 44 which in this case coincides
1848
+ * with the array index
1849
+ *
1850
+ * @type {Array}
1851
+ */
1852
+ const ALPHA_NUM_CHARS = [
1853
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1854
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1855
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1856
+ ' ', '$', '%', '*', '+', '-', '.', '/', ':'
1857
+ ];
1858
+
1859
+ function AlphanumericData (data) {
1860
+ this.mode = Mode.ALPHANUMERIC;
1861
+ this.data = data;
1862
+ }
1863
+
1864
+ AlphanumericData.getBitsLength = function getBitsLength (length) {
1865
+ return 11 * Math.floor(length / 2) + 6 * (length % 2)
1866
+ };
1867
+
1868
+ AlphanumericData.prototype.getLength = function getLength () {
1869
+ return this.data.length
1870
+ };
1871
+
1872
+ AlphanumericData.prototype.getBitsLength = function getBitsLength () {
1873
+ return AlphanumericData.getBitsLength(this.data.length)
1874
+ };
1875
+
1876
+ AlphanumericData.prototype.write = function write (bitBuffer) {
1877
+ let i;
1878
+
1879
+ // Input data characters are divided into groups of two characters
1880
+ // and encoded as 11-bit binary codes.
1881
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1882
+ // The character value of the first character is multiplied by 45
1883
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1884
+
1885
+ // The character value of the second digit is added to the product
1886
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1887
+
1888
+ // The sum is then stored as 11-bit binary number
1889
+ bitBuffer.put(value, 11);
1890
+ }
1891
+
1892
+ // If the number of input data characters is not a multiple of two,
1893
+ // the character value of the final character is encoded as a 6-bit binary number.
1894
+ if (this.data.length % 2) {
1895
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1896
+ }
1897
+ };
1898
+
1899
+ alphanumericData = AlphanumericData;
1900
+ return alphanumericData;
1901
+ }
1902
+
1903
+ var byteData;
1904
+ var hasRequiredByteData;
1905
+
1906
+ function requireByteData () {
1907
+ if (hasRequiredByteData) return byteData;
1908
+ hasRequiredByteData = 1;
1909
+ const Mode = requireMode();
1910
+
1911
+ function ByteData (data) {
1912
+ this.mode = Mode.BYTE;
1913
+ if (typeof (data) === 'string') {
1914
+ this.data = new TextEncoder().encode(data);
1915
+ } else {
1916
+ this.data = new Uint8Array(data);
1917
+ }
1918
+ }
1919
+
1920
+ ByteData.getBitsLength = function getBitsLength (length) {
1921
+ return length * 8
1922
+ };
1923
+
1924
+ ByteData.prototype.getLength = function getLength () {
1925
+ return this.data.length
1926
+ };
1927
+
1928
+ ByteData.prototype.getBitsLength = function getBitsLength () {
1929
+ return ByteData.getBitsLength(this.data.length)
1930
+ };
1931
+
1932
+ ByteData.prototype.write = function (bitBuffer) {
1933
+ for (let i = 0, l = this.data.length; i < l; i++) {
1934
+ bitBuffer.put(this.data[i], 8);
1935
+ }
1936
+ };
1937
+
1938
+ byteData = ByteData;
1939
+ return byteData;
1940
+ }
1941
+
1942
+ var kanjiData;
1943
+ var hasRequiredKanjiData;
1944
+
1945
+ function requireKanjiData () {
1946
+ if (hasRequiredKanjiData) return kanjiData;
1947
+ hasRequiredKanjiData = 1;
1948
+ const Mode = requireMode();
1949
+ const Utils = requireUtils$1();
1950
+
1951
+ function KanjiData (data) {
1952
+ this.mode = Mode.KANJI;
1953
+ this.data = data;
1954
+ }
1955
+
1956
+ KanjiData.getBitsLength = function getBitsLength (length) {
1957
+ return length * 13
1958
+ };
1959
+
1960
+ KanjiData.prototype.getLength = function getLength () {
1961
+ return this.data.length
1962
+ };
1963
+
1964
+ KanjiData.prototype.getBitsLength = function getBitsLength () {
1965
+ return KanjiData.getBitsLength(this.data.length)
1966
+ };
1967
+
1968
+ KanjiData.prototype.write = function (bitBuffer) {
1969
+ let i;
1970
+
1971
+ // In the Shift JIS system, Kanji characters are represented by a two byte combination.
1972
+ // These byte values are shifted from the JIS X 0208 values.
1973
+ // JIS X 0208 gives details of the shift coded representation.
1974
+ for (i = 0; i < this.data.length; i++) {
1975
+ let value = Utils.toSJIS(this.data[i]);
1976
+
1977
+ // For characters with Shift JIS values from 0x8140 to 0x9FFC:
1978
+ if (value >= 0x8140 && value <= 0x9FFC) {
1979
+ // Subtract 0x8140 from Shift JIS value
1980
+ value -= 0x8140;
1981
+
1982
+ // For characters with Shift JIS values from 0xE040 to 0xEBBF
1983
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
1984
+ // Subtract 0xC140 from Shift JIS value
1985
+ value -= 0xC140;
1986
+ } else {
1987
+ throw new Error(
1988
+ 'Invalid SJIS character: ' + this.data[i] + '\n' +
1989
+ 'Make sure your charset is UTF-8')
1990
+ }
1991
+
1992
+ // Multiply most significant byte of result by 0xC0
1993
+ // and add least significant byte to product
1994
+ value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
1995
+
1996
+ // Convert result to a 13-bit binary string
1997
+ bitBuffer.put(value, 13);
1998
+ }
1999
+ };
2000
+
2001
+ kanjiData = KanjiData;
2002
+ return kanjiData;
2003
+ }
2004
+
2005
+ var dijkstra = {exports: {}};
2006
+
2007
+ var hasRequiredDijkstra;
2008
+
2009
+ function requireDijkstra () {
2010
+ if (hasRequiredDijkstra) return dijkstra.exports;
2011
+ hasRequiredDijkstra = 1;
2012
+ (function (module) {
2013
+
2014
+ /******************************************************************************
2015
+ * Created 2008-08-19.
2016
+ *
2017
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
2018
+ *
2019
+ * Copyright (C) 2008
2020
+ * Wyatt Baldwin <self@wyattbaldwin.com>
2021
+ * All rights reserved
2022
+ *
2023
+ * Licensed under the MIT license.
2024
+ *
2025
+ * http://www.opensource.org/licenses/mit-license.php
2026
+ *
2027
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2028
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2029
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2030
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2031
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2032
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2033
+ * THE SOFTWARE.
2034
+ *****************************************************************************/
2035
+ var dijkstra = {
2036
+ single_source_shortest_paths: function(graph, s, d) {
2037
+ // Predecessor map for each node that has been encountered.
2038
+ // node ID => predecessor node ID
2039
+ var predecessors = {};
2040
+
2041
+ // Costs of shortest paths from s to all nodes encountered.
2042
+ // node ID => cost
2043
+ var costs = {};
2044
+ costs[s] = 0;
2045
+
2046
+ // Costs of shortest paths from s to all nodes encountered; differs from
2047
+ // `costs` in that it provides easy access to the node that currently has
2048
+ // the known shortest path from s.
2049
+ // XXX: Do we actually need both `costs` and `open`?
2050
+ var open = dijkstra.PriorityQueue.make();
2051
+ open.push(s, 0);
2052
+
2053
+ var closest,
2054
+ u, v,
2055
+ cost_of_s_to_u,
2056
+ adjacent_nodes,
2057
+ cost_of_e,
2058
+ cost_of_s_to_u_plus_cost_of_e,
2059
+ cost_of_s_to_v,
2060
+ first_visit;
2061
+ while (!open.empty()) {
2062
+ // In the nodes remaining in graph that have a known cost from s,
2063
+ // find the node, u, that currently has the shortest path from s.
2064
+ closest = open.pop();
2065
+ u = closest.value;
2066
+ cost_of_s_to_u = closest.cost;
2067
+
2068
+ // Get nodes adjacent to u...
2069
+ adjacent_nodes = graph[u] || {};
2070
+
2071
+ // ...and explore the edges that connect u to those nodes, updating
2072
+ // the cost of the shortest paths to any or all of those nodes as
2073
+ // necessary. v is the node across the current edge from u.
2074
+ for (v in adjacent_nodes) {
2075
+ if (adjacent_nodes.hasOwnProperty(v)) {
2076
+ // Get the cost of the edge running from u to v.
2077
+ cost_of_e = adjacent_nodes[v];
2078
+
2079
+ // Cost of s to u plus the cost of u to v across e--this is *a*
2080
+ // cost from s to v that may or may not be less than the current
2081
+ // known cost to v.
2082
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
2083
+
2084
+ // If we haven't visited v yet OR if the current known cost from s to
2085
+ // v is greater than the new cost we just found (cost of s to u plus
2086
+ // cost of u to v across e), update v's cost in the cost list and
2087
+ // update v's predecessor in the predecessor list (it's now u).
2088
+ cost_of_s_to_v = costs[v];
2089
+ first_visit = (typeof costs[v] === 'undefined');
2090
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
2091
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
2092
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
2093
+ predecessors[v] = u;
2094
+ }
2095
+ }
2096
+ }
2097
+ }
2098
+
2099
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
2100
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
2101
+ throw new Error(msg);
2102
+ }
2103
+
2104
+ return predecessors;
2105
+ },
2106
+
2107
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
2108
+ var nodes = [];
2109
+ var u = d;
2110
+ while (u) {
2111
+ nodes.push(u);
2112
+ predecessors[u];
2113
+ u = predecessors[u];
2114
+ }
2115
+ nodes.reverse();
2116
+ return nodes;
2117
+ },
2118
+
2119
+ find_path: function(graph, s, d) {
2120
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
2121
+ return dijkstra.extract_shortest_path_from_predecessor_list(
2122
+ predecessors, d);
2123
+ },
2124
+
2125
+ /**
2126
+ * A very naive priority queue implementation.
2127
+ */
2128
+ PriorityQueue: {
2129
+ make: function (opts) {
2130
+ var T = dijkstra.PriorityQueue,
2131
+ t = {},
2132
+ key;
2133
+ opts = opts || {};
2134
+ for (key in T) {
2135
+ if (T.hasOwnProperty(key)) {
2136
+ t[key] = T[key];
2137
+ }
2138
+ }
2139
+ t.queue = [];
2140
+ t.sorter = opts.sorter || T.default_sorter;
2141
+ return t;
2142
+ },
2143
+
2144
+ default_sorter: function (a, b) {
2145
+ return a.cost - b.cost;
2146
+ },
2147
+
2148
+ /**
2149
+ * Add a new item to the queue and ensure the highest priority element
2150
+ * is at the front of the queue.
2151
+ */
2152
+ push: function (value, cost) {
2153
+ var item = {value: value, cost: cost};
2154
+ this.queue.push(item);
2155
+ this.queue.sort(this.sorter);
2156
+ },
2157
+
2158
+ /**
2159
+ * Return the highest priority element in the queue.
2160
+ */
2161
+ pop: function () {
2162
+ return this.queue.shift();
2163
+ },
2164
+
2165
+ empty: function () {
2166
+ return this.queue.length === 0;
2167
+ }
2168
+ }
2169
+ };
2170
+
2171
+
2172
+ // node.js module exports
2173
+ {
2174
+ module.exports = dijkstra;
2175
+ }
2176
+ } (dijkstra));
2177
+ return dijkstra.exports;
2178
+ }
2179
+
2180
+ var hasRequiredSegments;
2181
+
2182
+ function requireSegments () {
2183
+ if (hasRequiredSegments) return segments;
2184
+ hasRequiredSegments = 1;
2185
+ (function (exports) {
2186
+ const Mode = requireMode();
2187
+ const NumericData = requireNumericData();
2188
+ const AlphanumericData = requireAlphanumericData();
2189
+ const ByteData = requireByteData();
2190
+ const KanjiData = requireKanjiData();
2191
+ const Regex = requireRegex();
2192
+ const Utils = requireUtils$1();
2193
+ const dijkstra = requireDijkstra();
2194
+
2195
+ /**
2196
+ * Returns UTF8 byte length
2197
+ *
2198
+ * @param {String} str Input string
2199
+ * @return {Number} Number of byte
2200
+ */
2201
+ function getStringByteLength (str) {
2202
+ return unescape(encodeURIComponent(str)).length
2203
+ }
2204
+
2205
+ /**
2206
+ * Get a list of segments of the specified mode
2207
+ * from a string
2208
+ *
2209
+ * @param {Mode} mode Segment mode
2210
+ * @param {String} str String to process
2211
+ * @return {Array} Array of object with segments data
2212
+ */
2213
+ function getSegments (regex, mode, str) {
2214
+ const segments = [];
2215
+ let result;
2216
+
2217
+ while ((result = regex.exec(str)) !== null) {
2218
+ segments.push({
2219
+ data: result[0],
2220
+ index: result.index,
2221
+ mode: mode,
2222
+ length: result[0].length
2223
+ });
2224
+ }
2225
+
2226
+ return segments
2227
+ }
2228
+
2229
+ /**
2230
+ * Extracts a series of segments with the appropriate
2231
+ * modes from a string
2232
+ *
2233
+ * @param {String} dataStr Input string
2234
+ * @return {Array} Array of object with segments data
2235
+ */
2236
+ function getSegmentsFromString (dataStr) {
2237
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
2238
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
2239
+ let byteSegs;
2240
+ let kanjiSegs;
2241
+
2242
+ if (Utils.isKanjiModeEnabled()) {
2243
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
2244
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
2245
+ } else {
2246
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
2247
+ kanjiSegs = [];
2248
+ }
2249
+
2250
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
2251
+
2252
+ return segs
2253
+ .sort(function (s1, s2) {
2254
+ return s1.index - s2.index
2255
+ })
2256
+ .map(function (obj) {
2257
+ return {
2258
+ data: obj.data,
2259
+ mode: obj.mode,
2260
+ length: obj.length
2261
+ }
2262
+ })
2263
+ }
2264
+
2265
+ /**
2266
+ * Returns how many bits are needed to encode a string of
2267
+ * specified length with the specified mode
2268
+ *
2269
+ * @param {Number} length String length
2270
+ * @param {Mode} mode Segment mode
2271
+ * @return {Number} Bit length
2272
+ */
2273
+ function getSegmentBitsLength (length, mode) {
2274
+ switch (mode) {
2275
+ case Mode.NUMERIC:
2276
+ return NumericData.getBitsLength(length)
2277
+ case Mode.ALPHANUMERIC:
2278
+ return AlphanumericData.getBitsLength(length)
2279
+ case Mode.KANJI:
2280
+ return KanjiData.getBitsLength(length)
2281
+ case Mode.BYTE:
2282
+ return ByteData.getBitsLength(length)
2283
+ }
2284
+ }
2285
+
2286
+ /**
2287
+ * Merges adjacent segments which have the same mode
2288
+ *
2289
+ * @param {Array} segs Array of object with segments data
2290
+ * @return {Array} Array of object with segments data
2291
+ */
2292
+ function mergeSegments (segs) {
2293
+ return segs.reduce(function (acc, curr) {
2294
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
2295
+ if (prevSeg && prevSeg.mode === curr.mode) {
2296
+ acc[acc.length - 1].data += curr.data;
2297
+ return acc
2298
+ }
2299
+
2300
+ acc.push(curr);
2301
+ return acc
2302
+ }, [])
2303
+ }
2304
+
2305
+ /**
2306
+ * Generates a list of all possible nodes combination which
2307
+ * will be used to build a segments graph.
2308
+ *
2309
+ * Nodes are divided by groups. Each group will contain a list of all the modes
2310
+ * in which is possible to encode the given text.
2311
+ *
2312
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
2313
+ * The group for '12345' will contain then 3 objects, one for each
2314
+ * possible encoding mode.
2315
+ *
2316
+ * Each node represents a possible segment.
2317
+ *
2318
+ * @param {Array} segs Array of object with segments data
2319
+ * @return {Array} Array of object with segments data
2320
+ */
2321
+ function buildNodes (segs) {
2322
+ const nodes = [];
2323
+ for (let i = 0; i < segs.length; i++) {
2324
+ const seg = segs[i];
2325
+
2326
+ switch (seg.mode) {
2327
+ case Mode.NUMERIC:
2328
+ nodes.push([seg,
2329
+ { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
2330
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2331
+ ]);
2332
+ break
2333
+ case Mode.ALPHANUMERIC:
2334
+ nodes.push([seg,
2335
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2336
+ ]);
2337
+ break
2338
+ case Mode.KANJI:
2339
+ nodes.push([seg,
2340
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2341
+ ]);
2342
+ break
2343
+ case Mode.BYTE:
2344
+ nodes.push([
2345
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2346
+ ]);
2347
+ }
2348
+ }
2349
+
2350
+ return nodes
2351
+ }
2352
+
2353
+ /**
2354
+ * Builds a graph from a list of nodes.
2355
+ * All segments in each node group will be connected with all the segments of
2356
+ * the next group and so on.
2357
+ *
2358
+ * At each connection will be assigned a weight depending on the
2359
+ * segment's byte length.
2360
+ *
2361
+ * @param {Array} nodes Array of object with segments data
2362
+ * @param {Number} version QR Code version
2363
+ * @return {Object} Graph of all possible segments
2364
+ */
2365
+ function buildGraph (nodes, version) {
2366
+ const table = {};
2367
+ const graph = { start: {} };
2368
+ let prevNodeIds = ['start'];
2369
+
2370
+ for (let i = 0; i < nodes.length; i++) {
2371
+ const nodeGroup = nodes[i];
2372
+ const currentNodeIds = [];
2373
+
2374
+ for (let j = 0; j < nodeGroup.length; j++) {
2375
+ const node = nodeGroup[j];
2376
+ const key = '' + i + j;
2377
+
2378
+ currentNodeIds.push(key);
2379
+ table[key] = { node: node, lastCount: 0 };
2380
+ graph[key] = {};
2381
+
2382
+ for (let n = 0; n < prevNodeIds.length; n++) {
2383
+ const prevNodeId = prevNodeIds[n];
2384
+
2385
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2386
+ graph[prevNodeId][key] =
2387
+ getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
2388
+ getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2389
+
2390
+ table[prevNodeId].lastCount += node.length;
2391
+ } else {
2392
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2393
+
2394
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
2395
+ 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost
2396
+ }
2397
+ }
2398
+ }
2399
+
2400
+ prevNodeIds = currentNodeIds;
2401
+ }
2402
+
2403
+ for (let n = 0; n < prevNodeIds.length; n++) {
2404
+ graph[prevNodeIds[n]].end = 0;
2405
+ }
2406
+
2407
+ return { map: graph, table: table }
2408
+ }
2409
+
2410
+ /**
2411
+ * Builds a segment from a specified data and mode.
2412
+ * If a mode is not specified, the more suitable will be used.
2413
+ *
2414
+ * @param {String} data Input data
2415
+ * @param {Mode | String} modesHint Data mode
2416
+ * @return {Segment} Segment
2417
+ */
2418
+ function buildSingleSegment (data, modesHint) {
2419
+ let mode;
2420
+ const bestMode = Mode.getBestModeForData(data);
2421
+
2422
+ mode = Mode.from(modesHint, bestMode);
2423
+
2424
+ // Make sure data can be encoded
2425
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
2426
+ throw new Error('"' + data + '"' +
2427
+ ' cannot be encoded with mode ' + Mode.toString(mode) +
2428
+ '.\n Suggested mode is: ' + Mode.toString(bestMode))
2429
+ }
2430
+
2431
+ // Use Mode.BYTE if Kanji support is disabled
2432
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
2433
+ mode = Mode.BYTE;
2434
+ }
2435
+
2436
+ switch (mode) {
2437
+ case Mode.NUMERIC:
2438
+ return new NumericData(data)
2439
+
2440
+ case Mode.ALPHANUMERIC:
2441
+ return new AlphanumericData(data)
2442
+
2443
+ case Mode.KANJI:
2444
+ return new KanjiData(data)
2445
+
2446
+ case Mode.BYTE:
2447
+ return new ByteData(data)
2448
+ }
2449
+ }
2450
+
2451
+ /**
2452
+ * Builds a list of segments from an array.
2453
+ * Array can contain Strings or Objects with segment's info.
2454
+ *
2455
+ * For each item which is a string, will be generated a segment with the given
2456
+ * string and the more appropriate encoding mode.
2457
+ *
2458
+ * For each item which is an object, will be generated a segment with the given
2459
+ * data and mode.
2460
+ * Objects must contain at least the property "data".
2461
+ * If property "mode" is not present, the more suitable mode will be used.
2462
+ *
2463
+ * @param {Array} array Array of objects with segments data
2464
+ * @return {Array} Array of Segments
2465
+ */
2466
+ exports.fromArray = function fromArray (array) {
2467
+ return array.reduce(function (acc, seg) {
2468
+ if (typeof seg === 'string') {
2469
+ acc.push(buildSingleSegment(seg, null));
2470
+ } else if (seg.data) {
2471
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2472
+ }
2473
+
2474
+ return acc
2475
+ }, [])
2476
+ };
2477
+
2478
+ /**
2479
+ * Builds an optimized sequence of segments from a string,
2480
+ * which will produce the shortest possible bitstream.
2481
+ *
2482
+ * @param {String} data Input string
2483
+ * @param {Number} version QR Code version
2484
+ * @return {Array} Array of segments
2485
+ */
2486
+ exports.fromString = function fromString (data, version) {
2487
+ const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
2488
+
2489
+ const nodes = buildNodes(segs);
2490
+ const graph = buildGraph(nodes, version);
2491
+ const path = dijkstra.find_path(graph.map, 'start', 'end');
2492
+
2493
+ const optimizedSegs = [];
2494
+ for (let i = 1; i < path.length - 1; i++) {
2495
+ optimizedSegs.push(graph.table[path[i]].node);
2496
+ }
2497
+
2498
+ return exports.fromArray(mergeSegments(optimizedSegs))
2499
+ };
2500
+
2501
+ /**
2502
+ * Splits a string in various segments with the modes which
2503
+ * best represent their content.
2504
+ * The produced segments are far from being optimized.
2505
+ * The output of this function is only used to estimate a QR Code version
2506
+ * which may contain the data.
2507
+ *
2508
+ * @param {string} data Input string
2509
+ * @return {Array} Array of segments
2510
+ */
2511
+ exports.rawSplit = function rawSplit (data) {
2512
+ return exports.fromArray(
2513
+ getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2514
+ )
2515
+ };
2516
+ } (segments));
2517
+ return segments;
2518
+ }
2519
+
2520
+ var hasRequiredQrcode;
2521
+
2522
+ function requireQrcode () {
2523
+ if (hasRequiredQrcode) return qrcode;
2524
+ hasRequiredQrcode = 1;
2525
+ const Utils = requireUtils$1();
2526
+ const ECLevel = requireErrorCorrectionLevel();
2527
+ const BitBuffer = requireBitBuffer();
2528
+ const BitMatrix = requireBitMatrix();
2529
+ const AlignmentPattern = requireAlignmentPattern();
2530
+ const FinderPattern = requireFinderPattern();
2531
+ const MaskPattern = requireMaskPattern();
2532
+ const ECCode = requireErrorCorrectionCode();
2533
+ const ReedSolomonEncoder = requireReedSolomonEncoder();
2534
+ const Version = requireVersion();
2535
+ const FormatInfo = requireFormatInfo();
2536
+ const Mode = requireMode();
2537
+ const Segments = requireSegments();
2538
+
2539
+ /**
2540
+ * QRCode for JavaScript
2541
+ *
2542
+ * modified by Ryan Day for nodejs support
2543
+ * Copyright (c) 2011 Ryan Day
2544
+ *
2545
+ * Licensed under the MIT license:
2546
+ * http://www.opensource.org/licenses/mit-license.php
2547
+ *
2548
+ //---------------------------------------------------------------------
2549
+ // QRCode for JavaScript
2550
+ //
2551
+ // Copyright (c) 2009 Kazuhiko Arase
2552
+ //
2553
+ // URL: http://www.d-project.com/
2554
+ //
2555
+ // Licensed under the MIT license:
2556
+ // http://www.opensource.org/licenses/mit-license.php
2557
+ //
2558
+ // The word "QR Code" is registered trademark of
2559
+ // DENSO WAVE INCORPORATED
2560
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
2561
+ //
2562
+ //---------------------------------------------------------------------
2563
+ */
2564
+
2565
+ /**
2566
+ * Add finder patterns bits to matrix
2567
+ *
2568
+ * @param {BitMatrix} matrix Modules matrix
2569
+ * @param {Number} version QR Code version
2570
+ */
2571
+ function setupFinderPattern (matrix, version) {
2572
+ const size = matrix.size;
2573
+ const pos = FinderPattern.getPositions(version);
2574
+
2575
+ for (let i = 0; i < pos.length; i++) {
2576
+ const row = pos[i][0];
2577
+ const col = pos[i][1];
2578
+
2579
+ for (let r = -1; r <= 7; r++) {
2580
+ if (row + r <= -1 || size <= row + r) continue
2581
+
2582
+ for (let c = -1; c <= 7; c++) {
2583
+ if (col + c <= -1 || size <= col + c) continue
2584
+
2585
+ if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
2586
+ (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
2587
+ (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
2588
+ matrix.set(row + r, col + c, true, true);
2589
+ } else {
2590
+ matrix.set(row + r, col + c, false, true);
2591
+ }
2592
+ }
2593
+ }
2594
+ }
2595
+ }
2596
+
2597
+ /**
2598
+ * Add timing pattern bits to matrix
2599
+ *
2600
+ * Note: this function must be called before {@link setupAlignmentPattern}
2601
+ *
2602
+ * @param {BitMatrix} matrix Modules matrix
2603
+ */
2604
+ function setupTimingPattern (matrix) {
2605
+ const size = matrix.size;
2606
+
2607
+ for (let r = 8; r < size - 8; r++) {
2608
+ const value = r % 2 === 0;
2609
+ matrix.set(r, 6, value, true);
2610
+ matrix.set(6, r, value, true);
2611
+ }
2612
+ }
2613
+
2614
+ /**
2615
+ * Add alignment patterns bits to matrix
2616
+ *
2617
+ * Note: this function must be called after {@link setupTimingPattern}
2618
+ *
2619
+ * @param {BitMatrix} matrix Modules matrix
2620
+ * @param {Number} version QR Code version
2621
+ */
2622
+ function setupAlignmentPattern (matrix, version) {
2623
+ const pos = AlignmentPattern.getPositions(version);
2624
+
2625
+ for (let i = 0; i < pos.length; i++) {
2626
+ const row = pos[i][0];
2627
+ const col = pos[i][1];
2628
+
2629
+ for (let r = -2; r <= 2; r++) {
2630
+ for (let c = -2; c <= 2; c++) {
2631
+ if (r === -2 || r === 2 || c === -2 || c === 2 ||
2632
+ (r === 0 && c === 0)) {
2633
+ matrix.set(row + r, col + c, true, true);
2634
+ } else {
2635
+ matrix.set(row + r, col + c, false, true);
2636
+ }
2637
+ }
2638
+ }
2639
+ }
2640
+ }
2641
+
2642
+ /**
2643
+ * Add version info bits to matrix
2644
+ *
2645
+ * @param {BitMatrix} matrix Modules matrix
2646
+ * @param {Number} version QR Code version
2647
+ */
2648
+ function setupVersionInfo (matrix, version) {
2649
+ const size = matrix.size;
2650
+ const bits = Version.getEncodedBits(version);
2651
+ let row, col, mod;
2652
+
2653
+ for (let i = 0; i < 18; i++) {
2654
+ row = Math.floor(i / 3);
2655
+ col = i % 3 + size - 8 - 3;
2656
+ mod = ((bits >> i) & 1) === 1;
2657
+
2658
+ matrix.set(row, col, mod, true);
2659
+ matrix.set(col, row, mod, true);
2660
+ }
2661
+ }
2662
+
2663
+ /**
2664
+ * Add format info bits to matrix
2665
+ *
2666
+ * @param {BitMatrix} matrix Modules matrix
2667
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2668
+ * @param {Number} maskPattern Mask pattern reference value
2669
+ */
2670
+ function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
2671
+ const size = matrix.size;
2672
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2673
+ let i, mod;
2674
+
2675
+ for (i = 0; i < 15; i++) {
2676
+ mod = ((bits >> i) & 1) === 1;
2677
+
2678
+ // vertical
2679
+ if (i < 6) {
2680
+ matrix.set(i, 8, mod, true);
2681
+ } else if (i < 8) {
2682
+ matrix.set(i + 1, 8, mod, true);
2683
+ } else {
2684
+ matrix.set(size - 15 + i, 8, mod, true);
2685
+ }
2686
+
2687
+ // horizontal
2688
+ if (i < 8) {
2689
+ matrix.set(8, size - i - 1, mod, true);
2690
+ } else if (i < 9) {
2691
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2692
+ } else {
2693
+ matrix.set(8, 15 - i - 1, mod, true);
2694
+ }
2695
+ }
2696
+
2697
+ // fixed module
2698
+ matrix.set(size - 8, 8, 1, true);
2699
+ }
2700
+
2701
+ /**
2702
+ * Add encoded data bits to matrix
2703
+ *
2704
+ * @param {BitMatrix} matrix Modules matrix
2705
+ * @param {Uint8Array} data Data codewords
2706
+ */
2707
+ function setupData (matrix, data) {
2708
+ const size = matrix.size;
2709
+ let inc = -1;
2710
+ let row = size - 1;
2711
+ let bitIndex = 7;
2712
+ let byteIndex = 0;
2713
+
2714
+ for (let col = size - 1; col > 0; col -= 2) {
2715
+ if (col === 6) col--;
2716
+
2717
+ while (true) {
2718
+ for (let c = 0; c < 2; c++) {
2719
+ if (!matrix.isReserved(row, col - c)) {
2720
+ let dark = false;
2721
+
2722
+ if (byteIndex < data.length) {
2723
+ dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
2724
+ }
2725
+
2726
+ matrix.set(row, col - c, dark);
2727
+ bitIndex--;
2728
+
2729
+ if (bitIndex === -1) {
2730
+ byteIndex++;
2731
+ bitIndex = 7;
2732
+ }
2733
+ }
2734
+ }
2735
+
2736
+ row += inc;
2737
+
2738
+ if (row < 0 || size <= row) {
2739
+ row -= inc;
2740
+ inc = -inc;
2741
+ break
2742
+ }
2743
+ }
2744
+ }
2745
+ }
2746
+
2747
+ /**
2748
+ * Create encoded codewords from data input
2749
+ *
2750
+ * @param {Number} version QR Code version
2751
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2752
+ * @param {ByteData} data Data input
2753
+ * @return {Uint8Array} Buffer containing encoded codewords
2754
+ */
2755
+ function createData (version, errorCorrectionLevel, segments) {
2756
+ // Prepare data buffer
2757
+ const buffer = new BitBuffer();
2758
+
2759
+ segments.forEach(function (data) {
2760
+ // prefix data with mode indicator (4 bits)
2761
+ buffer.put(data.mode.bit, 4);
2762
+
2763
+ // Prefix data with character count indicator.
2764
+ // The character count indicator is a string of bits that represents the
2765
+ // number of characters that are being encoded.
2766
+ // The character count indicator must be placed after the mode indicator
2767
+ // and must be a certain number of bits long, depending on the QR version
2768
+ // and data mode
2769
+ // @see {@link Mode.getCharCountIndicator}.
2770
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2771
+
2772
+ // add binary data sequence to buffer
2773
+ data.write(buffer);
2774
+ });
2775
+
2776
+ // Calculate required number of bits
2777
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2778
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2779
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2780
+
2781
+ // Add a terminator.
2782
+ // If the bit string is shorter than the total number of required bits,
2783
+ // a terminator of up to four 0s must be added to the right side of the string.
2784
+ // If the bit string is more than four bits shorter than the required number of bits,
2785
+ // add four 0s to the end.
2786
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2787
+ buffer.put(0, 4);
2788
+ }
2789
+
2790
+ // If the bit string is fewer than four bits shorter, add only the number of 0s that
2791
+ // are needed to reach the required number of bits.
2792
+
2793
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2794
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
2795
+ while (buffer.getLengthInBits() % 8 !== 0) {
2796
+ buffer.putBit(0);
2797
+ }
2798
+
2799
+ // Add pad bytes if the string is still shorter than the total number of required bits.
2800
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
2801
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2802
+ // and 00010001 (0x11) alternately.
2803
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2804
+ for (let i = 0; i < remainingByte; i++) {
2805
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2806
+ }
2807
+
2808
+ return createCodewords(buffer, version, errorCorrectionLevel)
2809
+ }
2810
+
2811
+ /**
2812
+ * Encode input data with Reed-Solomon and return codewords with
2813
+ * relative error correction bits
2814
+ *
2815
+ * @param {BitBuffer} bitBuffer Data to encode
2816
+ * @param {Number} version QR Code version
2817
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2818
+ * @return {Uint8Array} Buffer containing encoded codewords
2819
+ */
2820
+ function createCodewords (bitBuffer, version, errorCorrectionLevel) {
2821
+ // Total codewords for this QR code version (Data + Error correction)
2822
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2823
+
2824
+ // Total number of error correction codewords
2825
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2826
+
2827
+ // Total number of data codewords
2828
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
2829
+
2830
+ // Total number of blocks
2831
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2832
+
2833
+ // Calculate how many blocks each group should contain
2834
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
2835
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2836
+
2837
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2838
+
2839
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2840
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2841
+
2842
+ // Number of EC codewords is the same for both groups
2843
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2844
+
2845
+ // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
2846
+ const rs = new ReedSolomonEncoder(ecCount);
2847
+
2848
+ let offset = 0;
2849
+ const dcData = new Array(ecTotalBlocks);
2850
+ const ecData = new Array(ecTotalBlocks);
2851
+ let maxDataSize = 0;
2852
+ const buffer = new Uint8Array(bitBuffer.buffer);
2853
+
2854
+ // Divide the buffer into the required number of blocks
2855
+ for (let b = 0; b < ecTotalBlocks; b++) {
2856
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2857
+
2858
+ // extract a block of data from buffer
2859
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2860
+
2861
+ // Calculate EC codewords for this data block
2862
+ ecData[b] = rs.encode(dcData[b]);
2863
+
2864
+ offset += dataSize;
2865
+ maxDataSize = Math.max(maxDataSize, dataSize);
2866
+ }
2867
+
2868
+ // Create final data
2869
+ // Interleave the data and error correction codewords from each block
2870
+ const data = new Uint8Array(totalCodewords);
2871
+ let index = 0;
2872
+ let i, r;
2873
+
2874
+ // Add data codewords
2875
+ for (i = 0; i < maxDataSize; i++) {
2876
+ for (r = 0; r < ecTotalBlocks; r++) {
2877
+ if (i < dcData[r].length) {
2878
+ data[index++] = dcData[r][i];
2879
+ }
2880
+ }
2881
+ }
2882
+
2883
+ // Apped EC codewords
2884
+ for (i = 0; i < ecCount; i++) {
2885
+ for (r = 0; r < ecTotalBlocks; r++) {
2886
+ data[index++] = ecData[r][i];
2887
+ }
2888
+ }
2889
+
2890
+ return data
2891
+ }
2892
+
2893
+ /**
2894
+ * Build QR Code symbol
2895
+ *
2896
+ * @param {String} data Input string
2897
+ * @param {Number} version QR Code version
2898
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2899
+ * @param {MaskPattern} maskPattern Mask pattern
2900
+ * @return {Object} Object containing symbol data
2901
+ */
2902
+ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
2903
+ let segments;
2904
+
2905
+ if (Array.isArray(data)) {
2906
+ segments = Segments.fromArray(data);
2907
+ } else if (typeof data === 'string') {
2908
+ let estimatedVersion = version;
2909
+
2910
+ if (!estimatedVersion) {
2911
+ const rawSegments = Segments.rawSplit(data);
2912
+
2913
+ // Estimate best version that can contain raw splitted segments
2914
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2915
+ }
2916
+
2917
+ // Build optimized segments
2918
+ // If estimated version is undefined, try with the highest version
2919
+ segments = Segments.fromString(data, estimatedVersion || 40);
2920
+ } else {
2921
+ throw new Error('Invalid data')
2922
+ }
2923
+
2924
+ // Get the min version that can contain data
2925
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2926
+
2927
+ // If no version is found, data cannot be stored
2928
+ if (!bestVersion) {
2929
+ throw new Error('The amount of data is too big to be stored in a QR Code')
2930
+ }
2931
+
2932
+ // If not specified, use min version as default
2933
+ if (!version) {
2934
+ version = bestVersion;
2935
+
2936
+ // Check if the specified version can contain the data
2937
+ } else if (version < bestVersion) {
2938
+ throw new Error('\n' +
2939
+ 'The chosen QR Code version cannot contain this amount of data.\n' +
2940
+ 'Minimum version required to store current data is: ' + bestVersion + '.\n'
2941
+ )
2942
+ }
2943
+
2944
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2945
+
2946
+ // Allocate matrix buffer
2947
+ const moduleCount = Utils.getSymbolSize(version);
2948
+ const modules = new BitMatrix(moduleCount);
2949
+
2950
+ // Add function modules
2951
+ setupFinderPattern(modules, version);
2952
+ setupTimingPattern(modules);
2953
+ setupAlignmentPattern(modules, version);
2954
+
2955
+ // Add temporary dummy bits for format info just to set them as reserved.
2956
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
2957
+ // since the masking operation must be performed only on the encoding region.
2958
+ // These blocks will be replaced with correct values later in code.
2959
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2960
+
2961
+ if (version >= 7) {
2962
+ setupVersionInfo(modules, version);
2963
+ }
2964
+
2965
+ // Add data codewords
2966
+ setupData(modules, dataBits);
2967
+
2968
+ if (isNaN(maskPattern)) {
2969
+ // Find best mask pattern
2970
+ maskPattern = MaskPattern.getBestMask(modules,
2971
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2972
+ }
2973
+
2974
+ // Apply mask pattern
2975
+ MaskPattern.applyMask(maskPattern, modules);
2976
+
2977
+ // Replace format info bits with correct values
2978
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2979
+
2980
+ return {
2981
+ modules: modules,
2982
+ version: version,
2983
+ errorCorrectionLevel: errorCorrectionLevel,
2984
+ maskPattern: maskPattern,
2985
+ segments: segments
2986
+ }
2987
+ }
2988
+
2989
+ /**
2990
+ * QR Code
2991
+ *
2992
+ * @param {String | Array} data Input data
2993
+ * @param {Object} options Optional configurations
2994
+ * @param {Number} options.version QR Code version
2995
+ * @param {String} options.errorCorrectionLevel Error correction level
2996
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2997
+ */
2998
+ qrcode.create = function create (data, options) {
2999
+ if (typeof data === 'undefined' || data === '') {
3000
+ throw new Error('No input text')
3001
+ }
3002
+
3003
+ let errorCorrectionLevel = ECLevel.M;
3004
+ let version;
3005
+ let mask;
3006
+
3007
+ if (typeof options !== 'undefined') {
3008
+ // Use higher error correction level as default
3009
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
3010
+ version = Version.from(options.version);
3011
+ mask = MaskPattern.from(options.maskPattern);
3012
+
3013
+ if (options.toSJISFunc) {
3014
+ Utils.setToSJISFunction(options.toSJISFunc);
3015
+ }
3016
+ }
3017
+
3018
+ return createSymbol(data, version, errorCorrectionLevel, mask)
3019
+ };
3020
+ return qrcode;
3021
+ }
3022
+
3023
+ var canvas = {};
3024
+
3025
+ var utils = {};
3026
+
3027
+ var hasRequiredUtils;
3028
+
3029
+ function requireUtils () {
3030
+ if (hasRequiredUtils) return utils;
3031
+ hasRequiredUtils = 1;
3032
+ (function (exports) {
3033
+ function hex2rgba (hex) {
3034
+ if (typeof hex === 'number') {
3035
+ hex = hex.toString();
3036
+ }
3037
+
3038
+ if (typeof hex !== 'string') {
3039
+ throw new Error('Color should be defined as hex string')
3040
+ }
3041
+
3042
+ let hexCode = hex.slice().replace('#', '').split('');
3043
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
3044
+ throw new Error('Invalid hex color: ' + hex)
3045
+ }
3046
+
3047
+ // Convert from short to long form (fff -> ffffff)
3048
+ if (hexCode.length === 3 || hexCode.length === 4) {
3049
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
3050
+ return [c, c]
3051
+ }));
3052
+ }
3053
+
3054
+ // Add default alpha value
3055
+ if (hexCode.length === 6) hexCode.push('F', 'F');
3056
+
3057
+ const hexValue = parseInt(hexCode.join(''), 16);
3058
+
3059
+ return {
3060
+ r: (hexValue >> 24) & 255,
3061
+ g: (hexValue >> 16) & 255,
3062
+ b: (hexValue >> 8) & 255,
3063
+ a: hexValue & 255,
3064
+ hex: '#' + hexCode.slice(0, 6).join('')
3065
+ }
3066
+ }
3067
+
3068
+ exports.getOptions = function getOptions (options) {
3069
+ if (!options) options = {};
3070
+ if (!options.color) options.color = {};
3071
+
3072
+ const margin = typeof options.margin === 'undefined' ||
3073
+ options.margin === null ||
3074
+ options.margin < 0
3075
+ ? 4
3076
+ : options.margin;
3077
+
3078
+ const width = options.width && options.width >= 21 ? options.width : undefined;
3079
+ const scale = options.scale || 4;
3080
+
3081
+ return {
3082
+ width: width,
3083
+ scale: width ? 4 : scale,
3084
+ margin: margin,
3085
+ color: {
3086
+ dark: hex2rgba(options.color.dark || '#000000ff'),
3087
+ light: hex2rgba(options.color.light || '#ffffffff')
3088
+ },
3089
+ type: options.type,
3090
+ rendererOpts: options.rendererOpts || {}
3091
+ }
3092
+ };
3093
+
3094
+ exports.getScale = function getScale (qrSize, opts) {
3095
+ return opts.width && opts.width >= qrSize + opts.margin * 2
3096
+ ? opts.width / (qrSize + opts.margin * 2)
3097
+ : opts.scale
3098
+ };
3099
+
3100
+ exports.getImageWidth = function getImageWidth (qrSize, opts) {
3101
+ const scale = exports.getScale(qrSize, opts);
3102
+ return Math.floor((qrSize + opts.margin * 2) * scale)
3103
+ };
3104
+
3105
+ exports.qrToImageData = function qrToImageData (imgData, qr, opts) {
3106
+ const size = qr.modules.size;
3107
+ const data = qr.modules.data;
3108
+ const scale = exports.getScale(size, opts);
3109
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
3110
+ const scaledMargin = opts.margin * scale;
3111
+ const palette = [opts.color.light, opts.color.dark];
3112
+
3113
+ for (let i = 0; i < symbolSize; i++) {
3114
+ for (let j = 0; j < symbolSize; j++) {
3115
+ let posDst = (i * symbolSize + j) * 4;
3116
+ let pxColor = opts.color.light;
3117
+
3118
+ if (i >= scaledMargin && j >= scaledMargin &&
3119
+ i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
3120
+ const iSrc = Math.floor((i - scaledMargin) / scale);
3121
+ const jSrc = Math.floor((j - scaledMargin) / scale);
3122
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
3123
+ }
3124
+
3125
+ imgData[posDst++] = pxColor.r;
3126
+ imgData[posDst++] = pxColor.g;
3127
+ imgData[posDst++] = pxColor.b;
3128
+ imgData[posDst] = pxColor.a;
3129
+ }
3130
+ }
3131
+ };
3132
+ } (utils));
3133
+ return utils;
3134
+ }
3135
+
3136
+ var hasRequiredCanvas;
3137
+
3138
+ function requireCanvas () {
3139
+ if (hasRequiredCanvas) return canvas;
3140
+ hasRequiredCanvas = 1;
3141
+ (function (exports) {
3142
+ const Utils = requireUtils();
3143
+
3144
+ function clearCanvas (ctx, canvas, size) {
3145
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
3146
+
3147
+ if (!canvas.style) canvas.style = {};
3148
+ canvas.height = size;
3149
+ canvas.width = size;
3150
+ canvas.style.height = size + 'px';
3151
+ canvas.style.width = size + 'px';
3152
+ }
3153
+
3154
+ function getCanvasElement () {
3155
+ try {
3156
+ return document.createElement('canvas')
3157
+ } catch (e) {
3158
+ throw new Error('You need to specify a canvas element')
3159
+ }
3160
+ }
3161
+
3162
+ exports.render = function render (qrData, canvas, options) {
3163
+ let opts = options;
3164
+ let canvasEl = canvas;
3165
+
3166
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
3167
+ opts = canvas;
3168
+ canvas = undefined;
3169
+ }
3170
+
3171
+ if (!canvas) {
3172
+ canvasEl = getCanvasElement();
3173
+ }
3174
+
3175
+ opts = Utils.getOptions(opts);
3176
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
3177
+
3178
+ const ctx = canvasEl.getContext('2d');
3179
+ const image = ctx.createImageData(size, size);
3180
+ Utils.qrToImageData(image.data, qrData, opts);
3181
+
3182
+ clearCanvas(ctx, canvasEl, size);
3183
+ ctx.putImageData(image, 0, 0);
3184
+
3185
+ return canvasEl
3186
+ };
3187
+
3188
+ exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
3189
+ let opts = options;
3190
+
3191
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
3192
+ opts = canvas;
3193
+ canvas = undefined;
3194
+ }
3195
+
3196
+ if (!opts) opts = {};
3197
+
3198
+ const canvasEl = exports.render(qrData, canvas, opts);
3199
+
3200
+ const type = opts.type || 'image/png';
3201
+ const rendererOpts = opts.rendererOpts || {};
3202
+
3203
+ return canvasEl.toDataURL(type, rendererOpts.quality)
3204
+ };
3205
+ } (canvas));
3206
+ return canvas;
3207
+ }
3208
+
3209
+ var svgTag = {};
3210
+
3211
+ var hasRequiredSvgTag;
3212
+
3213
+ function requireSvgTag () {
3214
+ if (hasRequiredSvgTag) return svgTag;
3215
+ hasRequiredSvgTag = 1;
3216
+ const Utils = requireUtils();
3217
+
3218
+ function getColorAttrib (color, attrib) {
3219
+ const alpha = color.a / 255;
3220
+ const str = attrib + '="' + color.hex + '"';
3221
+
3222
+ return alpha < 1
3223
+ ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
3224
+ : str
3225
+ }
3226
+
3227
+ function svgCmd (cmd, x, y) {
3228
+ let str = cmd + x;
3229
+ if (typeof y !== 'undefined') str += ' ' + y;
3230
+
3231
+ return str
3232
+ }
3233
+
3234
+ function qrToPath (data, size, margin) {
3235
+ let path = '';
3236
+ let moveBy = 0;
3237
+ let newRow = false;
3238
+ let lineLength = 0;
3239
+
3240
+ for (let i = 0; i < data.length; i++) {
3241
+ const col = Math.floor(i % size);
3242
+ const row = Math.floor(i / size);
3243
+
3244
+ if (!col && !newRow) newRow = true;
3245
+
3246
+ if (data[i]) {
3247
+ lineLength++;
3248
+
3249
+ if (!(i > 0 && col > 0 && data[i - 1])) {
3250
+ path += newRow
3251
+ ? svgCmd('M', col + margin, 0.5 + row + margin)
3252
+ : svgCmd('m', moveBy, 0);
3253
+
3254
+ moveBy = 0;
3255
+ newRow = false;
3256
+ }
3257
+
3258
+ if (!(col + 1 < size && data[i + 1])) {
3259
+ path += svgCmd('h', lineLength);
3260
+ lineLength = 0;
3261
+ }
3262
+ } else {
3263
+ moveBy++;
3264
+ }
3265
+ }
3266
+
3267
+ return path
3268
+ }
3269
+
3270
+ svgTag.render = function render (qrData, options, cb) {
3271
+ const opts = Utils.getOptions(options);
3272
+ const size = qrData.modules.size;
3273
+ const data = qrData.modules.data;
3274
+ const qrcodesize = size + opts.margin * 2;
3275
+
3276
+ const bg = !opts.color.light.a
3277
+ ? ''
3278
+ : '<path ' + getColorAttrib(opts.color.light, 'fill') +
3279
+ ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
3280
+
3281
+ const path =
3282
+ '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
3283
+ ' d="' + qrToPath(data, size, opts.margin) + '"/>';
3284
+
3285
+ const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
3286
+
3287
+ const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
3288
+
3289
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
3290
+
3291
+ if (typeof cb === 'function') {
3292
+ cb(null, svgTag);
3293
+ }
3294
+
3295
+ return svgTag
3296
+ };
3297
+ return svgTag;
3298
+ }
3299
+
3300
+ var hasRequiredBrowser;
3301
+
3302
+ function requireBrowser () {
3303
+ if (hasRequiredBrowser) return browser;
3304
+ hasRequiredBrowser = 1;
3305
+ const canPromise = requireCanPromise();
3306
+
3307
+ const QRCode = requireQrcode();
3308
+ const CanvasRenderer = requireCanvas();
3309
+ const SvgRenderer = requireSvgTag();
3310
+
3311
+ function renderCanvas (renderFunc, canvas, text, opts, cb) {
3312
+ const args = [].slice.call(arguments, 1);
3313
+ const argsNum = args.length;
3314
+ const isLastArgCb = typeof args[argsNum - 1] === 'function';
3315
+
3316
+ if (!isLastArgCb && !canPromise()) {
3317
+ throw new Error('Callback required as last argument')
3318
+ }
3319
+
3320
+ if (isLastArgCb) {
3321
+ if (argsNum < 2) {
3322
+ throw new Error('Too few arguments provided')
3323
+ }
3324
+
3325
+ if (argsNum === 2) {
3326
+ cb = text;
3327
+ text = canvas;
3328
+ canvas = opts = undefined;
3329
+ } else if (argsNum === 3) {
3330
+ if (canvas.getContext && typeof cb === 'undefined') {
3331
+ cb = opts;
3332
+ opts = undefined;
3333
+ } else {
3334
+ cb = opts;
3335
+ opts = text;
3336
+ text = canvas;
3337
+ canvas = undefined;
3338
+ }
3339
+ }
3340
+ } else {
3341
+ if (argsNum < 1) {
3342
+ throw new Error('Too few arguments provided')
3343
+ }
3344
+
3345
+ if (argsNum === 1) {
3346
+ text = canvas;
3347
+ canvas = opts = undefined;
3348
+ } else if (argsNum === 2 && !canvas.getContext) {
3349
+ opts = text;
3350
+ text = canvas;
3351
+ canvas = undefined;
3352
+ }
3353
+
3354
+ return new Promise(function (resolve, reject) {
3355
+ try {
3356
+ const data = QRCode.create(text, opts);
3357
+ resolve(renderFunc(data, canvas, opts));
3358
+ } catch (e) {
3359
+ reject(e);
3360
+ }
3361
+ })
3362
+ }
3363
+
3364
+ try {
3365
+ const data = QRCode.create(text, opts);
3366
+ cb(null, renderFunc(data, canvas, opts));
3367
+ } catch (e) {
3368
+ cb(e);
3369
+ }
3370
+ }
3371
+
3372
+ browser.create = QRCode.create;
3373
+ browser.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
3374
+ browser.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
3375
+
3376
+ // only svg for now.
3377
+ browser.toString = renderCanvas.bind(null, function (data, _, opts) {
3378
+ return SvgRenderer.render(data, opts)
3379
+ });
3380
+ return browser;
3381
+ }
3382
+
3383
+ var browserExports = requireBrowser();
3384
+
3385
+ const deviceIcon = "<svg width=\"63\" height=\"63\" viewBox=\"0 0 63 63\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n<g clip-path=\"url(#clip0_15_10760)\">\n<path d=\"M32.8125 55.125H21C19.6076 55.125 18.2723 54.5719 17.2877 53.5873C16.3031 52.6027 15.75 51.2674 15.75 49.875V13.125C15.75 11.7326 16.3031 10.3973 17.2877 9.41269C18.2723 8.42812 19.6076 7.875 21 7.875H42C43.3924 7.875 44.7277 8.42812 45.7123 9.41269C46.6969 10.3973 47.25 11.7326 47.25 13.125V28.875\" stroke=\"#DAEBF2\" stroke-width=\"5.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path d=\"M28.8758 10.4992H34.1258\" stroke=\"#DAEBF2\" stroke-width=\"5.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path d=\"M55.4418 52.8193C56.5434 51.7181 57.2937 50.3149 57.5977 48.7872C57.9018 47.2595 57.746 45.676 57.15 44.2369C56.554 42.7978 55.5447 41.5678 54.2496 40.7023C52.9545 39.8369 51.4318 39.375 49.8742 39.375C48.3166 39.375 46.7939 39.8369 45.4988 40.7023C44.2038 41.5678 43.1944 42.7978 42.5984 44.2369C42.0025 45.676 41.8466 47.2595 42.1507 48.7872C42.4548 50.3149 43.205 51.7181 44.3066 52.8193C45.4038 53.9192 47.2597 55.5624 49.8742 57.7517C52.6331 55.4154 54.4916 53.7722 55.4418 52.8193Z\" stroke=\"#DAEBF2\" stroke-width=\"5.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path d=\"M49.8742 47.25V47.2757\" stroke=\"#DAEBF2\" stroke-width=\"5.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n<path d=\"M31.5 44.6258V44.6515\" stroke=\"#DAEBF2\" stroke-width=\"5.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>\n</g>\n<defs>\n<clipPath id=\"clip0_15_10760\">\n<rect width=\"63\" height=\"63\" fill=\"white\"/>\n</clipPath>\n</defs>\n</svg>\n";
3386
+
3387
+ const style$1 = ":host{display:block;height:100%;width:100%;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}.card{margin-top:15px;background:#11032b;color:#fff;border-radius:24px;z-index:10;width:29.79vw;min-width:415px}.modal-content{display:flex;flex-direction:row;align-items:center;gap:16px;padding:16px}.pin-container{display:flex;align-items:center;gap:8px}.qr-text{margin:0;font-size:16px;font-weight:600;font-family:Poppins}.qr-code{display:flex;justify-content:center;align-items:center}.qr-code img{height:auto}";
3388
+
3389
+ var __defProp$1 = Object.defineProperty;
3390
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
3391
+ var __decorateClass$1 = (decorators, target, key, kind) => {
3392
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
3393
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
3394
+ if (decorator = decorators[i])
3395
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
3396
+ if (kind && result) __defProp$1(target, key, result);
3397
+ return result;
3398
+ };
3399
+ let QRModal = class extends i$2 {
3400
+ constructor() {
3401
+ super(...arguments);
3402
+ this.qrLoaded = false;
3403
+ }
3404
+ updated() {
3405
+ const { originId, destinationId, generalConfig } = this.sdkData ?? {};
3406
+ if (!this.qrLoaded && originId && destinationId && generalConfig) {
3407
+ this.qrLoaded = true;
3408
+ const { baseUrl } = generalConfig;
3409
+ const url = `${baseUrl}/${originId}?destinationId=${destinationId}&utm_source=qr-totem&utm_content=route&utm_referrer=totem`;
3410
+ const options = {
3411
+ errorCorrectionLevel: "M",
3412
+ type: "image/webp",
3413
+ margin: 1,
3414
+ width: 150
3415
+ };
3416
+ browserExports.toDataURL(url, options).then((url2) => {
3417
+ const qr = this.shadowRoot?.getElementById("qr");
3418
+ if (qr && qr instanceof HTMLImageElement) {
3419
+ qr.src = url2;
3420
+ }
3421
+ });
3422
+ }
3423
+ }
3424
+ render() {
3425
+ return x`
3426
+ <div class="card">
3427
+ <div class="modal-content">
3428
+ <div class="pin-container">
3429
+ <span .innerHTML=${deviceIcon}></span>
3430
+ </div>
3431
+ <div class="qr-text">
3432
+ <span>Continúa la ruta en tu celular, escaneando el código QR</span>
3433
+ </div>
3434
+ <div class="qr-code">
3435
+ <img id="qr" src="" alt="QR Code" />
3436
+ </div>
3437
+ </div>
3438
+ </div>
3439
+ `;
3440
+ }
3441
+ };
3442
+ QRModal.styles = [r(style$1)];
3443
+ __decorateClass$1([
3444
+ c({ context: sdkContext, subscribe: true })
3445
+ ], QRModal.prototype, "sdkData", 2);
3446
+ QRModal = __decorateClass$1([
3447
+ t$1("qr-modal")
3448
+ ], QRModal);
3449
+
3450
+ const qrModal = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3451
+ __proto__: null,
3452
+ get QRModal () { return QRModal; }
3453
+ }, Symbol.toStringTag, { value: 'Module' }));
3454
+
3455
+ const style = ":host{position:absolute;top:0;left:0;padding:1rem;z-index:10;font-family:Poppins!important;user-select:none}svg{vertical-align:middle}.back-panel{background-color:#11032b;color:#fff;margin-bottom:5px;padding-left:1.2rem;align-items:center;height:55px;position:relative}.back-content{margin:0;position:relative;top:50%;transform:translateY(-50%);font-size:22px;color:#fff;display:flex;align-items:center;gap:8px;cursor:pointer}.route-panel{width:29.79vw;min-width:415px;max-height:75vh;overflow-y:auto;overflow-x:hidden;border-radius:24px;background:#fff;box-shadow:0 0 24px #00000026}.back-text{font-size:18pt;font-weight:600}.back-content img{vertical-align:middle}.route-modal{padding:19px 13px 22px 32px}.icon_switcher_user_type{position:relative;color:#000}.d-flex{display:flex!important}.flex-fill{flex:1 1 auto!important}.place-name{font-weight:700;font-size:32px;line-height:1;letter-spacing:-1.6px;color:#333;margin-left:2px}.repeat-route-btn{display:flex;gap:10px;justify-content:center;align-items:center;text-align:center;background-color:#fff;border:2px solid #000000;border-radius:999px;margin-left:auto;margin-right:0;padding:12px 20px;font-size:20px;font-weight:700;line-height:20px;letter-spacing:-1px;color:#000;transition:background-color .3s ease,color .3s ease;cursor:pointer}.repeat-route-btn[disabled]{color:gray;border-color:gray;cursor:not-allowed;pointer-events:none}.floor-name{color:#427553}.floor-specs{font-family:Poppins;font-weight:600;line-height:14px;size:18px}.route-distance{color:#666}.container-controls{margin-top:16px;align-items:end;gap:11px}.c-route-input{color:#000;display:flex;padding:15px;font-size:16px;font-style:normal;font-weight:600;line-height:16px;letter-spacing:-.8px;align-items:center;gap:9px;border-radius:30px;background:#fff;box-shadow:0 0 10px #0000001a;position:relative;margin-top:12px}.c-route-input .c-route-input-icon svg{width:22px;height:22px}.c-route-input-from{margin-top:0}.c-route-input-from:after{content:\"\";position:absolute;bottom:-50%;left:24px;width:3.998px;height:34.5px;z-index:1;background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='38' viewBox='0 0 4 38' fill='none'%3E%3Cpath d='M-0.00028944 18.9386C-0.00028944 17.8347 0.894666 16.9397 1.99864 16.9397C3.10259 16.9397 3.99756 17.8347 3.99756 18.9386C3.99756 20.0426 3.10259 20.9375 1.99864 20.9375C0.894666 20.9375 -0.00028944 20.0426 -0.00028944 18.9386ZM-0.00028944 27.2198C-0.00028944 26.1159 0.894666 25.2209 1.99864 25.2209C3.10259 25.2209 3.99756 26.1159 3.99756 27.2198C3.99756 28.3238 3.10259 29.2188 1.99864 29.2188C0.894666 29.2188 -0.00028944 28.3238 -0.00028944 27.2198ZM-0.00028944 35.5011C-0.00028944 34.3971 0.894666 33.5021 1.99864 33.5021C3.10259 33.5021 3.99756 34.3971 3.99756 35.5011C3.99756 36.605 3.10259 37.5 1.99864 37.5C0.894666 37.5 -0.00028944 36.605 -0.00028944 35.5011Z' fill='%23D0D0D0'/%3E%3Cpath d='M1.99864 8.49999C0.894666 8.49999 -0.00028944 9.39496 -0.00028944 10.4989C-0.00028944 11.6029 0.894666 12.4978 1.99864 12.4978C3.10259 12.4978 3.99756 11.6029 3.99756 10.4989C3.99756 9.39496 3.10259 8.49999 1.99864 8.49999Z' fill='%23D0D0D0'/%3E%3Cpath d='M1.99864 0C0.894666 0 -0.00028944 0.894973 -0.00028944 1.99892C-0.00028944 3.10289 0.894666 3.99784 1.99864 3.99784C3.10259 3.99784 3.99756 3.10289 3.99756 1.99892C3.99756 0.894973 3.10259 0 1.99864 0Z' fill='%23D0D0D0'/%3E%3C/svg%3E\")}.c-route-input span{padding:0 6px;border-radius:15px;color:#454545;background:#f2f2f2;font-size:10px;font-style:normal;font-weight:600;line-height:14px;letter-spacing:-.5px}.accessibility-switch{display:flex;align-items:center;justify-content:center;min-width:100px;height:50px;border-radius:48px;background-color:#fff;box-shadow:0 0 15px #0003;position:relative}.accessibility-switch:before,.accessibility-switch:after{content:\"\";border-radius:50%;width:50%;height:100%;background:#000;position:absolute;bottom:0;left:0;background:linear-gradient(45.8deg,#f5a 10.03%,#b850c9 25.23%,#6572d6 48.67%,#4eaeb8 72.74%);z-index:0;transition:transform .5s ease}.accessibility-switch:after{background:#000;clip-path:circle(22px);z-index:1}.accessibility-switch.accessible:before,.accessibility-switch.accessible:after{transform:translate(100%)}.accessibility-switch-icon{width:50px;height:100%;display:grid;place-items:center;cursor:pointer;z-index:2;transition:color .5s ease;color:#000}.accessibility-switch-icon.active{color:#fff}.generate-route-btn{border-style:solid;width:100%;border-radius:30px;height:58px;background-color:#11032b;cursor:pointer}.generate-route-btn span{font-family:Poppins;font-size:16px;line-height:16px;font-weight:600;text-align:center;color:#fff}.generate-route-container{width:100%}.mt-3{margin-top:1rem!important}.align-items-center{align-items:center!important}.justify-content-center{justify-content:center!important}";
3456
+
3457
+ var __defProp = Object.defineProperty;
3458
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3459
+ var __decorateClass = (decorators, target, key, kind) => {
3460
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
3461
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
3462
+ if (decorator = decorators[i])
3463
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
3464
+ if (kind && result) __defProp(target, key, result);
3465
+ return result;
3466
+ };
3467
+ const loadAssets = async () => {
3468
+ const [accessibilityIcon, backIcon, destinationPoint, originPoint, repeatIcon, walkingIcon] = await Promise.all([
3469
+ import('./accessibility-Cnj-vwGM.js'),
3470
+ import('./back_arrow-CUOAm8Zc.js'),
3471
+ import('./icon-destination-point-DY-ha1KN.js'),
3472
+ import('./icon-origin-point-v4_9Pmls.js'),
3473
+ import('./repeat_icon-CY61-fSZ.js'),
3474
+ import('./walking-BmgeFukv.js')
3475
+ ]);
3476
+ return {
3477
+ accessibilityIcon: accessibilityIcon.default,
3478
+ backIcon: backIcon.default,
3479
+ destinationPoint: destinationPoint.default,
3480
+ originPoint: originPoint.default,
3481
+ repeatIcon: repeatIcon.default,
3482
+ walkingIcon: walkingIcon.default
3483
+ };
3484
+ };
3485
+ let RouteOptions = class extends i$2 {
3486
+ constructor() {
3487
+ super();
3488
+ this.assets = null;
3489
+ this._loadAssets();
3490
+ }
3491
+ async _loadAssets() {
3492
+ this.assets = await loadAssets();
3493
+ this.requestUpdate();
3494
+ }
3495
+ handleBack() {
3496
+ this.dispatchEvent(
3497
+ new CustomEvent("back", {
3498
+ detail: {},
3499
+ bubbles: true,
3500
+ composed: true
3501
+ })
3502
+ );
3503
+ }
3504
+ handleAccessibility() {
3505
+ this.dispatchEvent(
3506
+ new CustomEvent("accessibilityChange", {
3507
+ detail: !this.sdkData?.accessibleRoute,
3508
+ bubbles: true,
3509
+ composed: true
3510
+ })
3511
+ );
3512
+ }
3513
+ handleRepeatRoute() {
3514
+ this.dispatchEvent(
3515
+ new CustomEvent("repeatRoute", {
3516
+ detail: true,
3517
+ bubbles: true,
3518
+ composed: true
3519
+ })
3520
+ );
3521
+ }
3522
+ handleGenerateRoute() {
3523
+ this.dispatchEvent(
3524
+ new CustomEvent("generateRoute", {
3525
+ detail: true,
3526
+ bubbles: true,
3527
+ composed: true
3528
+ })
3529
+ );
3530
+ }
3531
+ render() {
3532
+ if (!this.sdkData) return x``;
3533
+ const { destination, accessibleRoute, parentPlace, origin, route, isRouteAnimating } = this.sdkData;
3534
+ const defaultIcon = accessibleRoute ? this.assets?.accessibilityIcon : this.assets?.walkingIcon;
3535
+ const destinationName = destination?.title ?? "";
3536
+ const parentPlaceFloors = parentPlace?.innerFloors ?? [];
3537
+ const originFloor = origin?.inFloor(parentPlaceFloors)?.name ?? "";
3538
+ const destinationFloor = destination?.inFloor(parentPlaceFloors)?.name ?? "";
3539
+ const isAnimating = isRouteAnimating ?? false;
3540
+ let distance = "";
3541
+ if (route) distance = `• ${route.legs[0].distance.toFixed(0)} mts`;
3542
+ return x`
3543
+ <div class="route-panel">
3544
+ <div class="flex flex-col h-full">
3545
+ <div class="back-panel" @click=${this.handleBack}>
3546
+ <div class="back-content">
3547
+ <span .innerHTML=${this.assets?.backIcon}></span>
3548
+ <span class="back-text">Volver</span>
3549
+ </div>
3550
+ </div>
3551
+
3552
+ <div class="route-modal">
3553
+ <div class="entrance-name d-flex align-items-center">
3554
+ <div class="icon_switcher_user_type">
3555
+ <span .innerHTML=${defaultIcon}></span>
3556
+ </div>
3557
+ <span class="justify-content-center place-name"> ${destinationName} </span>
3558
+ ${route ? x`
3559
+ <button class="repeat-route-btn" @click=${this.handleRepeatRoute} ?disabled=${isAnimating}>
3560
+ <span .innerHTML=${this.assets?.repeatIcon}></span>
3561
+ <span>Repetir ruta</span>
3562
+ </button>
3563
+ ` : ""}
3564
+ </div>
3565
+ <div class="floor-specs">
3566
+ <span class="floor-name">${destinationFloor}</span>
3567
+ <span class="route-distance">${distance}</span>
3568
+ </div>
3569
+ <div class="d-flex flex-wrap container-controls">
3570
+ <div class="flex-fill route-input-wrapper">
3571
+ <div class="c-route-input c-route-input-from">
3572
+ <div class="c-route-input-icon">
3573
+ <img src=${this.assets?.originPoint} alt="" class="icon-point" />
3574
+ </div>
3575
+ Desde mi ubicación
3576
+ <span>${originFloor}</span>
3577
+ </div>
3578
+ <div class="c-route-input" @click=${this.handleBack}>
3579
+ <div class="c-route-input-icon">
3580
+ <img src=${this.assets?.destinationPoint} alt="" class="icon-point" />
3581
+ </div>
3582
+ ${destinationName}
3583
+ <span>${destinationFloor}</span>
3584
+ </div>
3585
+ </div>
3586
+ <div
3587
+ class="accessibility-switch ${this.sdkData?.accessibleRoute ? "accessible" : ""}"
3588
+ @click=${this.handleAccessibility}
3589
+ >
3590
+ <div class="accessibility-switch-icon ${!this.sdkData?.accessibleRoute ? "active" : ""}">
3591
+ <span .innerHTML=${this.assets?.walkingIcon}></span>
3592
+ </div>
3593
+ <div class="accessibility-switch-icon ${this.sdkData?.accessibleRoute ? "active" : ""}">
3594
+ <span .innerHTML=${this.assets?.accessibilityIcon}></span>
3595
+ </div>
3596
+ </div>
3597
+ </div>
3598
+
3599
+ ${!route ? x`
3600
+ <div class="generate-route-container d-flex justify-content-center align-items-center mt-3">
3601
+ <button class="generate-route-btn" @click=${this.handleGenerateRoute}>
3602
+ <span> Generar ruta</span>
3603
+ </button>
3604
+ </div>
3605
+ ` : ""}
3606
+ </div>
3607
+ </div>
3608
+ </div>
3609
+ <qr-modal></qr-modal>
3610
+ `;
3611
+ }
3612
+ };
3613
+ RouteOptions.styles = [r(style)];
3614
+ __decorateClass([
3615
+ c({ context: sdkContext, subscribe: true })
3616
+ ], RouteOptions.prototype, "sdkData", 2);
3617
+ RouteOptions = __decorateClass([
3618
+ t$1("route-options")
3619
+ ], RouteOptions);
3620
+
3621
+ const routeOptions = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
3622
+ __proto__: null,
3623
+ get RouteOptions () { return RouteOptions; }
3624
+ }, Symbol.toStringTag, { value: 'Module' }));
3625
+
3626
+ export { customMap as c, floorSelector as f, i$1 as i, qrModal as q, routeOptions as r, sdkContext as s };