@mapvx/web-components 0.0.29 → 0.0.31

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