1import { 2 init_cfLodash, 3 init_cf_utils, 4 throttle, 5 uuidv4 6} from "./chunk-KIZY5IRN.js"; 7import { 8 __esm, 9 __export, 10 __publicField, 11 define_process_default, 12 init_define_process 13} from "./chunk-RFSPGZ3L.js"; 14
vendor: 736 bytes, lines 15-53
15// node_modules/nanostores/task/index.js 16function startTask() { 17 tasks += 1; 18 return () => { 19 tasks -= 1; 20 if (tasks === 0) { 21 let prevResolves = resolves; 22 resolves = []; 23 for (let i of prevResolves) i(); 24 } 25 }; 26} 27function task(cb) { 28 let endTask = startTask(); 29 let promise = cb().finally(endTask); 30 promise.t = true; 31 return promise; 32} 33function allTasks() { 34 if (tasks === 0) { 35 return Promise.resolve(); 36 } else { 37 return new Promise((resolve) => { 38 resolves.push(resolve); 39 }); 40 } 41} 42function cleanTasks() { 43 tasks = 0; 44} 45var tasks, resolves; 46var init_task = __esm({ 47 "node_modules/nanostores/task/index.js"() { 48 init_define_process(); 49 tasks = 0; 50 resolves = []; 51 } 52}); 53
vendor: 656 bytes, lines 54-77
54// node_modules/nanostores/clean-stores/index.js 55var clean, cleanStores; 56var init_clean_stores = __esm({ 57 "node_modules/nanostores/clean-stores/index.js"() { 58 init_define_process(); 59 init_task(); 60 clean = Symbol("clean"); 61 cleanStores = (...stores) => { 62 if (define_process_default.env.NODE_ENV === "production") { 63 throw new Error( 64 "cleanStores() can be used only during development or tests" 65 ); 66 } 67 cleanTasks(); 68 for (let $store of stores) { 69 if ($store) { 70 if ($store.mocked) delete $store.mocked; 71 if ($store[clean]) $store[clean](); 72 } 73 } 74 }; 75 } 76}); 77
vendor: 2,632 bytes, lines 78-167
78// node_modules/nanostores/atom/index.js 79var listenerQueue, lqIndex, QUEUE_ITEMS_PER_LISTENER, epoch, atom; 80var init_atom = __esm({ 81 "node_modules/nanostores/atom/index.js"() { 82 init_define_process(); 83 init_clean_stores(); 84 listenerQueue = []; 85 lqIndex = 0; 86 QUEUE_ITEMS_PER_LISTENER = 4; 87 epoch = 0; 88 atom = (initialValue) => { 89 let listeners = []; 90 let $atom = { 91 get() { 92 if (!$atom.lc) { 93 $atom.listen(() => { 94 })(); 95 } 96 return $atom.value; 97 }, 98 lc: 0, 99 listen(listener) { 100 $atom.lc = listeners.push(listener); 101 return () => { 102 for (let i = lqIndex + QUEUE_ITEMS_PER_LISTENER; i < listenerQueue.length; ) { 103 if (listenerQueue[i] === listener) { 104 listenerQueue.splice(i, QUEUE_ITEMS_PER_LISTENER); 105 } else { 106 i += QUEUE_ITEMS_PER_LISTENER; 107 } 108 } 109 let index = listeners.indexOf(listener); 110 if (~index) { 111 listeners.splice(index, 1); 112 if (!--$atom.lc) $atom.off(); 113 } 114 }; 115 }, 116 notify(oldValue, changedKey) { 117 epoch++; 118 let runListenerQueue = !listenerQueue.length; 119 for (let listener of listeners) { 120 listenerQueue.push( 121 listener, 122 $atom.value, 123 oldValue, 124 changedKey 125 ); 126 } 127 if (runListenerQueue) { 128 for (lqIndex = 0; lqIndex < listenerQueue.length; lqIndex += QUEUE_ITEMS_PER_LISTENER) { 129 listenerQueue[lqIndex]( 130 listenerQueue[lqIndex + 1], 131 listenerQueue[lqIndex + 2], 132 listenerQueue[lqIndex + 3] 133 ); 134 } 135 listenerQueue.length = 0; 136 } 137 }, 138 /* It will be called on last listener unsubscribing. 139 We will redefine it in onMount and onStop. */ 140 off() { 141 }, 142 set(newValue) { 143 let oldValue = $atom.value; 144 if (oldValue !== newValue) { 145 $atom.value = newValue; 146 $atom.notify(oldValue); 147 } 148 }, 149 subscribe(listener) { 150 let unbind = $atom.listen(listener); 151 listener($atom.value); 152 return unbind; 153 }, 154 value: initialValue 155 }; 156 if (define_process_default.env.NODE_ENV !== "production") { 157 $atom[clean] = () => { 158 listeners = []; 159 $atom.lc = 0; 160 $atom.off(); 161 }; 162 } 163 return $atom; 164 }; 165 } 166}); 167
vendor: 4,809 bytes, lines 168-316
168// node_modules/nanostores/lifecycle/index.js 169var START, STOP, SET, NOTIFY, MOUNT, UNMOUNT, REVERT_MUTATION, on, onStart, onStop, onSet, onNotify, STORE_UNMOUNT_DELAY, onMount; 170var init_lifecycle = __esm({ 171 "node_modules/nanostores/lifecycle/index.js"() { 172 init_define_process(); 173 init_clean_stores(); 174 START = 0; 175 STOP = 1; 176 SET = 2; 177 NOTIFY = 3; 178 MOUNT = 5; 179 UNMOUNT = 6; 180 REVERT_MUTATION = 10; 181 on = (object, listener, eventKey, mutateStore) => { 182 object.events = object.events || {}; 183 if (!object.events[eventKey + REVERT_MUTATION]) { 184 object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => { 185 object.events[eventKey].reduceRight((event, l) => (l(event), event), { 186 shared: {}, 187 ...eventProps 188 }); 189 }); 190 } 191 object.events[eventKey] = object.events[eventKey] || []; 192 object.events[eventKey].push(listener); 193 return () => { 194 let currentListeners = object.events[eventKey]; 195 let index = currentListeners.indexOf(listener); 196 currentListeners.splice(index, 1); 197 if (!currentListeners.length) { 198 delete object.events[eventKey]; 199 object.events[eventKey + REVERT_MUTATION](); 200 delete object.events[eventKey + REVERT_MUTATION]; 201 } 202 }; 203 }; 204 onStart = ($store, listener) => on($store, listener, START, (runListeners) => { 205 let originListen = $store.listen; 206 $store.listen = (arg) => { 207 if (!$store.lc && !$store.starting) { 208 $store.starting = true; 209 runListeners(); 210 delete $store.starting; 211 } 212 return originListen(arg); 213 }; 214 return () => { 215 $store.listen = originListen; 216 }; 217 }); 218 onStop = ($store, listener) => on($store, listener, STOP, (runListeners) => { 219 let originOff = $store.off; 220 $store.off = () => { 221 runListeners(); 222 originOff(); 223 }; 224 return () => { 225 $store.off = originOff; 226 }; 227 }); 228 onSet = ($store, listener) => on($store, listener, SET, (runListeners) => { 229 let originSet = $store.set; 230 let originSetKey = $store.setKey; 231 if ($store.setKey) { 232 $store.setKey = (changed, changedValue) => { 233 let isAborted; 234 let abort = () => { 235 isAborted = true; 236 }; 237 runListeners({ 238 abort, 239 changed, 240 newValue: { ...$store.value, [changed]: changedValue } 241 }); 242 if (!isAborted) return originSetKey(changed, changedValue); 243 }; 244 } 245 $store.set = (newValue) => { 246 let isAborted; 247 let abort = () => { 248 isAborted = true; 249 }; 250 runListeners({ abort, newValue }); 251 if (!isAborted) return originSet(newValue); 252 }; 253 return () => { 254 $store.set = originSet; 255 $store.setKey = originSetKey; 256 }; 257 }); 258 onNotify = ($store, listener) => on($store, listener, NOTIFY, (runListeners) => { 259 let originNotify = $store.notify; 260 $store.notify = (oldValue, changed) => { 261 let isAborted; 262 let abort = () => { 263 isAborted = true; 264 }; 265 runListeners({ abort, changed, oldValue }); 266 if (!isAborted) return originNotify(oldValue, changed); 267 }; 268 return () => { 269 $store.notify = originNotify; 270 }; 271 }); 272 STORE_UNMOUNT_DELAY = 1e3; 273 onMount = ($store, initialize) => { 274 let listener = (payload) => { 275 let destroy = initialize(payload); 276 if (destroy) $store.events[UNMOUNT].push(destroy); 277 }; 278 return on($store, listener, MOUNT, (runListeners) => { 279 let originListen = $store.listen; 280 $store.listen = (...args) => { 281 if (!$store.lc && !$store.active) { 282 $store.active = true; 283 runListeners(); 284 } 285 return originListen(...args); 286 }; 287 let originOff = $store.off; 288 $store.events[UNMOUNT] = []; 289 $store.off = () => { 290 originOff(); 291 setTimeout(() => { 292 if ($store.active && !$store.lc) { 293 $store.active = false; 294 for (let destroy of $store.events[UNMOUNT]) destroy(); 295 $store.events[UNMOUNT] = []; 296 } 297 }, STORE_UNMOUNT_DELAY); 298 }; 299 if (define_process_default.env.NODE_ENV !== "production") { 300 let originClean = $store[clean]; 301 $store[clean] = () => { 302 for (let destroy of $store.events[UNMOUNT]) destroy(); 303 $store.events[UNMOUNT] = []; 304 $store.active = false; 305 originClean(); 306 }; 307 } 308 return () => { 309 $store.listen = originListen; 310 $store.off = originOff; 311 }; 312 }); 313 }; 314 } 315}); 316
vendor: 1,642 bytes, lines 317-371
317// node_modules/nanostores/computed/index.js 318var computedStore, computed, batched; 319var init_computed = __esm({ 320 "node_modules/nanostores/computed/index.js"() { 321 init_define_process(); 322 init_atom(); 323 init_lifecycle(); 324 computedStore = (stores, cb, batched2) => { 325 if (!Array.isArray(stores)) stores = [stores]; 326 let previousArgs; 327 let currentEpoch; 328 let set = () => { 329 if (currentEpoch === epoch) return; 330 currentEpoch = epoch; 331 let args = stores.map(($store) => $store.get()); 332 if (!previousArgs || args.some((arg, i) => arg !== previousArgs[i])) { 333 previousArgs = args; 334 let value = cb(...args); 335 if (value && value.then && value.t) { 336 value.then((asyncValue) => { 337 if (previousArgs === args) { 338 $computed.set(asyncValue); 339 } 340 }); 341 } else { 342 $computed.set(value); 343 currentEpoch = epoch; 344 } 345 } 346 }; 347 let $computed = atom(void 0); 348 let get2 = $computed.get; 349 $computed.get = () => { 350 set(); 351 return get2(); 352 }; 353 let timer; 354 let run = batched2 ? () => { 355 clearTimeout(timer); 356 timer = setTimeout(set); 357 } : set; 358 onMount($computed, () => { 359 let unbinds = stores.map(($store) => $store.listen(run)); 360 set(); 361 return () => { 362 for (let unbind of unbinds) unbind(); 363 }; 364 }); 365 return $computed; 366 }; 367 computed = (stores, fn) => computedStore(stores, fn); 368 batched = (stores, fn) => computedStore(stores, fn, true); 369 } 370}); 371
vendor: 704 bytes, lines 372-398
372// node_modules/nanostores/map/index.js 373var map; 374var init_map = __esm({ 375 "node_modules/nanostores/map/index.js"() { 376 init_define_process(); 377 init_atom(); 378 map = (initial = {}) => { 379 let $map = atom(initial); 380 $map.setKey = function(key, value) { 381 let oldMap = $map.value; 382 if (typeof value === "undefined" && key in $map.value) { 383 $map.value = { ...$map.value }; 384 delete $map.value[key]; 385 $map.notify(oldMap, key); 386 } else if ($map.value[key] !== value) { 387 $map.value = { 388 ...$map.value, 389 [key]: value 390 }; 391 $map.notify(oldMap, key); 392 } 393 }; 394 return $map; 395 }; 396 } 397}); 398
vendor: 1,592 bytes, lines 399-462
399// node_modules/nanostores/deep-map/path.js 400function getPath(obj, path) { 401 let allKeys = getAllKeysFromPath(path); 402 let res = obj; 403 for (let key of allKeys) { 404 if (res === void 0) { 405 break; 406 } 407 res = res[key]; 408 } 409 return res; 410} 411function setPath(obj, path, value) { 412 return setByKey(obj != null ? obj : {}, getAllKeysFromPath(path), value); 413} 414function setByKey(obj, splittedKeys, value) { 415 let key = splittedKeys[0]; 416 let copy2 = Array.isArray(obj) ? [...obj] : { ...obj }; 417 if (splittedKeys.length === 1) { 418 if (value === void 0) { 419 if (Array.isArray(copy2)) { 420 copy2.splice(key, 1); 421 } else { 422 delete copy2[key]; 423 } 424 } else { 425 copy2[key] = value; 426 } 427 return copy2; 428 } 429 ensureKey(copy2, key, splittedKeys[1]); 430 copy2[key] = setByKey(copy2[key], splittedKeys.slice(1), value); 431 return copy2; 432} 433function getAllKeysFromPath(path) { 434 return path.split(".").flatMap((key) => getKeyAndIndicesFromKey(key)); 435} 436function getKeyAndIndicesFromKey(key) { 437 if (ARRAY_INDEX.test(key)) { 438 let [, keyPart, index] = key.match(ARRAY_INDEX); 439 return [...getKeyAndIndicesFromKey(keyPart), index]; 440 } 441 return [key]; 442} 443function ensureKey(obj, key, nextKey) { 444 if (key in obj) { 445 return; 446 } 447 let isNum = IS_NUMBER.test(nextKey); 448 if (isNum) { 449 obj[key] = Array(parseInt(nextKey, 10) + 1); 450 } else { 451 obj[key] = {}; 452 } 453} 454var ARRAY_INDEX, IS_NUMBER; 455var init_path = __esm({ 456 "node_modules/nanostores/deep-map/path.js"() { 457 init_define_process(); 458 ARRAY_INDEX = /(.*)\[(\d+)\]/; 459 IS_NUMBER = /^\d+$/; 460 } 461}); 462
vendor: 530 bytes, lines 463-483
463// node_modules/nanostores/deep-map/index.js 464function deepMap(initial = {}) { 465 let $deepMap = atom(initial); 466 $deepMap.setKey = (key, value) => { 467 if (getPath($deepMap.value, key) !== value) { 468 let oldValue = $deepMap.value; 469 $deepMap.value = setPath($deepMap.value, key, value); 470 $deepMap.notify(oldValue, key); 471 } 472 }; 473 return $deepMap; 474} 475var init_deep_map = __esm({ 476 "node_modules/nanostores/deep-map/index.js"() { 477 init_define_process(); 478 init_atom(); 479 init_path(); 480 init_path(); 481 } 482}); 483
vendor: 255 bytes, lines 484-495
484// node_modules/nanostores/keep-mount/index.js 485var keepMount; 486var init_keep_mount = __esm({ 487 "node_modules/nanostores/keep-mount/index.js"() { 488 init_define_process(); 489 keepMount = ($store) => { 490 $store.listen(() => { 491 }); 492 }; 493 } 494}); 495
vendor: 562 bytes, lines 496-515
496// node_modules/nanostores/listen-keys/index.js 497function listenKeys($store, keys, listener) { 498 let keysSet = /* @__PURE__ */ new Set([...keys, void 0]); 499 return $store.listen((value, oldValue, changed) => { 500 if (keysSet.has(changed)) { 501 listener(value, oldValue, changed); 502 } 503 }); 504} 505function subscribeKeys($store, keys, listener) { 506 let unbind = listenKeys($store, keys, listener); 507 listener($store.value); 508 return unbind; 509} 510var init_listen_keys = __esm({ 511 "node_modules/nanostores/listen-keys/index.js"() { 512 init_define_process(); 513 } 514}); 515
vendor: 962 bytes, lines 516-555
516// node_modules/nanostores/map-creator/index.js 517function mapCreator(init) { 518 let Creator = (id, ...args) => { 519 if (!Creator.cache[id]) { 520 Creator.cache[id] = Creator.build(id, ...args); 521 } 522 return Creator.cache[id]; 523 }; 524 Creator.build = (id, ...args) => { 525 let store = map({ id }); 526 onMount(store, () => { 527 let destroy; 528 if (init) destroy = init(store, id, ...args); 529 return () => { 530 delete Creator.cache[id]; 531 if (destroy) destroy(); 532 }; 533 }); 534 return store; 535 }; 536 Creator.cache = {}; 537 if (define_process_default.env.NODE_ENV !== "production") { 538 Creator[clean] = () => { 539 for (let id in Creator.cache) { 540 Creator.cache[id][clean](); 541 } 542 Creator.cache = {}; 543 }; 544 } 545 return Creator; 546} 547var init_map_creator = __esm({ 548 "node_modules/nanostores/map-creator/index.js"() { 549 init_define_process(); 550 init_clean_stores(); 551 init_lifecycle(); 552 init_map(); 553 } 554}); 555
vendor: 1,088 bytes, lines 556-599
556// node_modules/nanostores/index.js 557var nanostores_exports = {}; 558__export(nanostores_exports, { 559 STORE_UNMOUNT_DELAY: () => STORE_UNMOUNT_DELAY, 560 allTasks: () => allTasks, 561 atom: () => atom, 562 batched: () => batched, 563 clean: () => clean, 564 cleanStores: () => cleanStores, 565 cleanTasks: () => cleanTasks, 566 computed: () => computed, 567 deepMap: () => deepMap, 568 getPath: () => getPath, 569 keepMount: () => keepMount, 570 listenKeys: () => listenKeys, 571 map: () => map, 572 mapCreator: () => mapCreator, 573 onMount: () => onMount, 574 onNotify: () => onNotify, 575 onSet: () => onSet, 576 onStart: () => onStart, 577 onStop: () => onStop, 578 setByKey: () => setByKey, 579 setPath: () => setPath, 580 startTask: () => startTask, 581 subscribeKeys: () => subscribeKeys, 582 task: () => task 583}); 584var init_nanostores = __esm({ 585 "node_modules/nanostores/index.js"() { 586 init_define_process(); 587 init_atom(); 588 init_clean_stores(); 589 init_computed(); 590 init_deep_map(); 591 init_keep_mount(); 592 init_lifecycle(); 593 init_listen_keys(); 594 init_map_creator(); 595 init_map(); 596 init_task(); 597 } 598}); 599
600// projects/lib/packages/yggdrasil-blueprints/src/Elements/Utils/general.ts 601async function sleepMs(timeMs) { 602 return new Promise((resolve) => { 603 setTimeout(resolve, timeMs); 604 }); 605} 606var cleanEmptyObjectKeys, deepEqual, formatNumberToCurrency, numberToCurrency, isElementVisibleOnViewport, debounce; 607var init_general = __esm({ 608 "projects/lib/packages/yggdrasil-blueprints/src/Elements/Utils/general.ts"() { 609 init_define_process(); 610 cleanEmptyObjectKeys = (obj) => { 611 for (const propName in obj) { 612 const value = obj[propName]; 613 if ([null, void 0, ""].includes(value)) { 614 delete obj[propName]; 615 } 616 } 617 return obj; 618 }; 619 deepEqual = (x, y) => { 620 const ok = Object.keys, tx = typeof x, ty = typeof y; 621 return x && y && tx === "object" && tx === ty ? ok(x).length === ok(y).length && ok(x).every((key) => deepEqual(x[key], y[key])) : x === y; 622 }; 623 formatNumberToCurrency = (currency, n) => { 624 const numericValue = typeof n === "string" ? parseFloat(n) : n; 625 if (currency && currency === "$" && n > 0) { 626 return new Intl.NumberFormat("en-US", { 627 style: "currency", 628 currency: "USD", 629 maximumFractionDigits: 2 630 }).format(numericValue); 631 } 632 return currency + numericValue?.toFixed(2); 633 }; 634 numberToCurrency = (number, currency) => { 635 if (currency && currency === "$" && Number.isFinite(number)) { 636 return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 2 }).format(number).replace("$", ""); 637 } else if (currency && currency === "\u20AC" && Number.isFinite(number)) { 638 return new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR", maximumFractionDigits: 2 }).format(number).replace("\u20AC", ""); 639 } 640 return number && number.toFixed(2); 641 }; 642 isElementVisibleOnViewport = (element, percentage) => { 643 const rect = element.getBoundingClientRect(); 644 const windowHeight = window.innerHeight || document.documentElement.clientHeight; 645 return !(Math.floor(100 - (rect.top >= 0 ? 0 : rect.top) / +-rect.height * 100) < percentage || Math.floor(100 - (rect.bottom - windowHeight) / rect.height * 100) < percentage); 646 }; 647 debounce = (callback, wait) => { 648 let debounceTimeout; 649 return (...props) => { 650 clearTimeout(debounceTimeout); 651 debounceTimeout = setTimeout(() => { 652 callback([...props]); 653 }, wait); 654 }; 655 }; 656 } 657}); 658
vendor: 513 bytes, lines 659-673
659// node_modules/@babel/runtime/helpers/esm/typeof.js 660function _typeof(o) { 661 "@babel/helpers - typeof"; 662 return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) { 663 return typeof o2; 664 } : function(o2) { 665 return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2; 666 }, _typeof(o); 667} 668var init_typeof = __esm({ 669 "node_modules/@babel/runtime/helpers/esm/typeof.js"() { 670 init_define_process(); 671 } 672}); 673
vendor: 545 bytes, lines 674-691
674// node_modules/@babel/runtime/helpers/esm/toPrimitive.js 675function toPrimitive(t, r) { 676 if ("object" != _typeof(t) || !t) return t; 677 var e = t[Symbol.toPrimitive]; 678 if (void 0 !== e) { 679 var i = e.call(t, r || "default"); 680 if ("object" != _typeof(i)) return i; 681 throw new TypeError("@@toPrimitive must return a primitive value."); 682 } 683 return ("string" === r ? String : Number)(t); 684} 685var init_toPrimitive = __esm({ 686 "node_modules/@babel/runtime/helpers/esm/toPrimitive.js"() { 687 init_define_process(); 688 init_typeof(); 689 } 690}); 691
vendor: 349 bytes, lines 692-704
692// node_modules/@babel/runtime/helpers/esm/toPropertyKey.js 693function toPropertyKey(t) { 694 var i = toPrimitive(t, "string"); 695 return "symbol" == _typeof(i) ? i : i + ""; 696} 697var init_toPropertyKey = __esm({ 698 "node_modules/@babel/runtime/helpers/esm/toPropertyKey.js"() { 699 init_define_process(); 700 init_typeof(); 701 init_toPrimitive(); 702 } 703}); 704
vendor: 429 bytes, lines 705-720
705// node_modules/@babel/runtime/helpers/esm/defineProperty.js 706function _defineProperty(e, r, t) { 707 return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, { 708 value: t, 709 enumerable: true, 710 configurable: true, 711 writable: true 712 }) : e[r] = t, e; 713} 714var init_defineProperty = __esm({ 715 "node_modules/@babel/runtime/helpers/esm/defineProperty.js"() { 716 init_define_process(); 717 init_toPropertyKey(); 718 } 719}); 720
vendor: 663 bytes, lines 721-739
721// node_modules/@babel/runtime/helpers/esm/objectSpread.js 722function _objectSpread(e) { 723 for (var r = 1; r < arguments.length; r++) { 724 var t = null != arguments[r] ? Object(arguments[r]) : {}, o = Object.keys(t); 725 "function" == typeof Object.getOwnPropertySymbols && o.push.apply(o, Object.getOwnPropertySymbols(t).filter(function(e2) { 726 return Object.getOwnPropertyDescriptor(t, e2).enumerable; 727 })), o.forEach(function(r2) { 728 _defineProperty(e, r2, t[r2]); 729 }); 730 } 731 return e; 732} 733var init_objectSpread = __esm({ 734 "node_modules/@babel/runtime/helpers/esm/objectSpread.js"() { 735 init_define_process(); 736 init_defineProperty(); 737 } 738}); 739
vendor: 315 bytes, lines 740-749
740// node_modules/@babel/runtime/helpers/esm/classCallCheck.js 741function _classCallCheck(a, n) { 742 if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); 743} 744var init_classCallCheck = __esm({ 745 "node_modules/@babel/runtime/helpers/esm/classCallCheck.js"() { 746 init_define_process(); 747 } 748}); 749
vendor: 648 bytes, lines 750-768
750// node_modules/@babel/runtime/helpers/esm/createClass.js 751function _defineProperties(e, r) { 752 for (var t = 0; t < r.length; t++) { 753 var o = r[t]; 754 o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, toPropertyKey(o.key), o); 755 } 756} 757function _createClass(e, r, t) { 758 return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { 759 writable: false 760 }), e; 761} 762var init_createClass = __esm({ 763 "node_modules/@babel/runtime/helpers/esm/createClass.js"() { 764 init_define_process(); 765 init_toPropertyKey(); 766 } 767}); 768
vendor: 376 bytes, lines 769-779
769// node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js 770function _assertThisInitialized(e) { 771 if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); 772 return e; 773} 774var init_assertThisInitialized = __esm({ 775 "node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js"() { 776 init_define_process(); 777 } 778}); 779
vendor: 539 bytes, lines 780-793
780// node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js 781function _possibleConstructorReturn(t, e) { 782 if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; 783 if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); 784 return _assertThisInitialized(t); 785} 786var init_possibleConstructorReturn = __esm({ 787 "node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js"() { 788 init_define_process(); 789 init_typeof(); 790 init_assertThisInitialized(); 791 } 792}); 793
vendor: 405 bytes, lines 794-805
794// node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js 795function _getPrototypeOf(t) { 796 return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(t2) { 797 return t2.__proto__ || Object.getPrototypeOf(t2); 798 }, _getPrototypeOf(t); 799} 800var init_getPrototypeOf = __esm({ 801 "node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js"() { 802 init_define_process(); 803 } 804}); 805
vendor: 395 bytes, lines 806-817
806// node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js 807function _setPrototypeOf(t, e) { 808 return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(t2, e2) { 809 return t2.__proto__ = e2, t2; 810 }, _setPrototypeOf(t, e); 811} 812var init_setPrototypeOf = __esm({ 813 "node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js"() { 814 init_define_process(); 815 } 816}); 817
vendor: 592 bytes, lines 818-837
818// node_modules/@babel/runtime/helpers/esm/inherits.js 819function _inherits(t, e) { 820 if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); 821 t.prototype = Object.create(e && e.prototype, { 822 constructor: { 823 value: t, 824 writable: true, 825 configurable: true 826 } 827 }), Object.defineProperty(t, "prototype", { 828 writable: false 829 }), e && _setPrototypeOf(t, e); 830} 831var init_inherits = __esm({ 832 "node_modules/@babel/runtime/helpers/esm/inherits.js"() { 833 init_define_process(); 834 init_setPrototypeOf(); 835 } 836}); 837
vendor: 82,718 bytes, lines 838-2813
838// node_modules/i18next/dist/esm/i18next.js 839function defer() { 840 var res; 841 var rej; 842 var promise = new Promise(function(resolve, reject) { 843 res = resolve; 844 rej = reject; 845 }); 846 promise.resolve = res; 847 promise.reject = rej; 848 return promise; 849} 850function makeString(object) { 851 if (object == null) return ""; 852 return "" + object; 853} 854function copy(a, s, t) { 855 a.forEach(function(m) { 856 if (s[m]) t[m] = s[m]; 857 }); 858} 859function getLastOfPath(object, path, Empty) { 860 function cleanKey(key2) { 861 return key2 && key2.indexOf("###") > -1 ? key2.replace(/###/g, ".") : key2; 862 } 863 function canNotTraverseDeeper() { 864 return !object || typeof object === "string"; 865 } 866 var stack = typeof path !== "string" ? [].concat(path) : path.split("."); 867 while (stack.length > 1) { 868 if (canNotTraverseDeeper()) return {}; 869 var key = cleanKey(stack.shift()); 870 if (!object[key] && Empty) object[key] = new Empty(); 871 if (Object.prototype.hasOwnProperty.call(object, key)) { 872 object = object[key]; 873 } else { 874 object = {}; 875 } 876 } 877 if (canNotTraverseDeeper()) return {}; 878 return { 879 obj: object, 880 k: cleanKey(stack.shift()) 881 }; 882} 883function setPath2(object, path, newValue) { 884 var _getLastOfPath = getLastOfPath(object, path, Object), obj = _getLastOfPath.obj, k = _getLastOfPath.k; 885 obj[k] = newValue; 886} 887function pushPath(object, path, newValue, concat) { 888 var _getLastOfPath2 = getLastOfPath(object, path, Object), obj = _getLastOfPath2.obj, k = _getLastOfPath2.k; 889 obj[k] = obj[k] || []; 890 if (concat) obj[k] = obj[k].concat(newValue); 891 if (!concat) obj[k].push(newValue); 892} 893function getPath2(object, path) { 894 var _getLastOfPath3 = getLastOfPath(object, path), obj = _getLastOfPath3.obj, k = _getLastOfPath3.k; 895 if (!obj) return void 0; 896 return obj[k]; 897} 898function getPathWithDefaults(data, defaultData, key) { 899 var value = getPath2(data, key); 900 if (value !== void 0) { 901 return value; 902 } 903 return getPath2(defaultData, key); 904} 905function deepExtend(target, source, overwrite) { 906 for (var prop in source) { 907 if (prop !== "__proto__" && prop !== "constructor") { 908 if (prop in target) { 909 if (typeof target[prop] === "string" || target[prop] instanceof String || typeof source[prop] === "string" || source[prop] instanceof String) { 910 if (overwrite) target[prop] = source[prop]; 911 } else { 912 deepExtend(target[prop], source[prop], overwrite); 913 } 914 } else { 915 target[prop] = source[prop]; 916 } 917 } 918 } 919 return target; 920} 921function regexEscape(str) { 922 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); 923} 924function escape2(data) { 925 if (typeof data === "string") { 926 return data.replace(/[&<>"'\/]/g, function(s) { 927 return _entityMap[s]; 928 }); 929 } 930 return data; 931} 932function capitalize(string) { 933 return string.charAt(0).toUpperCase() + string.slice(1); 934} 935function createRules() { 936 var rules = {}; 937 sets.forEach(function(set) { 938 set.lngs.forEach(function(l) { 939 rules[l] = { 940 numbers: set.nr, 941 plurals: _rulesPluralsTypes[set.fc] 942 }; 943 }); 944 }); 945 return rules; 946} 947function remove(arr, what) { 948 var found = arr.indexOf(what); 949 while (found !== -1) { 950 arr.splice(found, 1); 951 found = arr.indexOf(what); 952 } 953} 954function get() { 955 return { 956 debug: false, 957 initImmediate: true, 958 ns: ["translation"], 959 defaultNS: ["translation"], 960 fallbackLng: ["dev"], 961 fallbackNS: false, 962 whitelist: false, 963 nonExplicitWhitelist: false, 964 supportedLngs: false, 965 nonExplicitSupportedLngs: false, 966 load: "all", 967 preload: false, 968 simplifyPluralSuffix: true, 969 keySeparator: ".", 970 nsSeparator: ":", 971 pluralSeparator: "_", 972 contextSeparator: "_", 973 partialBundledLanguages: false, 974 saveMissing: false, 975 updateMissing: false, 976 saveMissingTo: "fallback", 977 saveMissingPlurals: true, 978 missingKeyHandler: false, 979 missingInterpolationHandler: false, 980 postProcess: false, 981 postProcessPassResolved: false, 982 returnNull: true, 983 returnEmptyString: true, 984 returnObjects: false, 985 joinArrays: false, 986 returnedObjectHandler: false, 987 parseMissingKeyHandler: false, 988 appendNamespaceToMissingKey: false, 989 appendNamespaceToCIMode: false, 990 overloadTranslationOptionHandler: function handle2(args) { 991 var ret = {}; 992 if (_typeof(args[1]) === "object") ret = args[1]; 993 if (typeof args[1] === "string") ret.defaultValue = args[1]; 994 if (typeof args[2] === "string") ret.tDescription = args[2]; 995 if (_typeof(args[2]) === "object" || _typeof(args[3]) === "object") { 996 var options = args[3] || args[2]; 997 Object.keys(options).forEach(function(key) { 998 ret[key] = options[key]; 999 }); 1000 } 1001 return ret; 1002 }, 1003 interpolation: { 1004 escapeValue: true, 1005 format: function format(value, _format, lng, options) { 1006 return value; 1007 }, 1008 prefix: "{{", 1009 suffix: "}}", 1010 formatSeparator: ",", 1011 unescapePrefix: "-", 1012 nestingPrefix: "$t(", 1013 nestingSuffix: ")", 1014 nestingOptionsSeparator: ",", 1015 maxReplaces: 1e3, 1016 skipOnVariables: false 1017 } 1018 }; 1019} 1020function transformOptions(options) { 1021 if (typeof options.ns === "string") options.ns = [options.ns]; 1022 if (typeof options.fallbackLng === "string") options.fallbackLng = [options.fallbackLng]; 1023 if (typeof options.fallbackNS === "string") options.fallbackNS = [options.fallbackNS]; 1024 if (options.whitelist) { 1025 if (options.whitelist && options.whitelist.indexOf("cimode") < 0) { 1026 options.whitelist = options.whitelist.concat(["cimode"]); 1027 } 1028 options.supportedLngs = options.whitelist; 1029 } 1030 if (options.nonExplicitWhitelist) { 1031 options.nonExplicitSupportedLngs = options.nonExplicitWhitelist; 1032 } 1033 if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) { 1034 options.supportedLngs = options.supportedLngs.concat(["cimode"]); 1035 } 1036 return options; 1037} 1038function noop() { 1039} 1040var consoleLogger, Logger, baseLogger, EventEmitter, _entityMap, isIE10, ResourceStore, postProcessor, checkedLoadedFor, Translator, LanguageUtil, sets, _rulesPluralsTypes, PluralResolver, Interpolator, Connector, I18n, i18next, i18next_default; 1041var init_i18next = __esm({ 1042 "node_modules/i18next/dist/esm/i18next.js"() { 1043 init_define_process(); 1044 init_typeof(); 1045 init_objectSpread(); 1046 init_classCallCheck(); 1047 init_createClass(); 1048 init_possibleConstructorReturn(); 1049 init_getPrototypeOf(); 1050 init_assertThisInitialized(); 1051 init_inherits(); 1052 consoleLogger = { 1053 type: "logger", 1054 log: function log(args) { 1055 this.output("log", args); 1056 }, 1057 warn: function warn(args) { 1058 this.output("warn", args); 1059 }, 1060 error: function error(args) { 1061 this.output("error", args); 1062 }, 1063 output: function output(type, args) { 1064 if (console && console[type]) console[type].apply(console, args); 1065 } 1066 }; 1067 Logger = function() { 1068 function Logger2(concreteLogger) { 1069 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; 1070 _classCallCheck(this, Logger2); 1071 this.init(concreteLogger, options); 1072 } 1073 _createClass(Logger2, [{ 1074 key: "init", 1075 value: function init(concreteLogger) { 1076 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; 1077 this.prefix = options.prefix || "i18next:"; 1078 this.logger = concreteLogger || consoleLogger; 1079 this.options = options; 1080 this.debug = options.debug; 1081 } 1082 }, { 1083 key: "setDebug", 1084 value: function setDebug(bool) { 1085 this.debug = bool; 1086 } 1087 }, { 1088 key: "log", 1089 value: function log2() { 1090 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 1091 args[_key] = arguments[_key]; 1092 } 1093 return this.forward(args, "log", "", true); 1094 } 1095 }, { 1096 key: "warn", 1097 value: function warn2() { 1098 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 1099 args[_key2] = arguments[_key2]; 1100 } 1101 return this.forward(args, "warn", "", true); 1102 } 1103 }, { 1104 key: "error", 1105 value: function error2() { 1106 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { 1107 args[_key3] = arguments[_key3]; 1108 } 1109 return this.forward(args, "error", ""); 1110 } 1111 }, { 1112 key: "deprecate", 1113 value: function deprecate() { 1114 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { 1115 args[_key4] = arguments[_key4]; 1116 } 1117 return this.forward(args, "warn", "WARNING DEPRECATED: ", true); 1118 } 1119 }, { 1120 key: "forward", 1121 value: function forward(args, lvl, prefix, debugOnly) { 1122 if (debugOnly && !this.debug) return null; 1123 if (typeof args[0] === "string") args[0] = "".concat(prefix).concat(this.prefix, " ").concat(args[0]); 1124 return this.logger[lvl](args); 1125 } 1126 }, { 1127 key: "create", 1128 value: function create(moduleName) { 1129 return new Logger2(this.logger, _objectSpread({}, { 1130 prefix: "".concat(this.prefix, ":").concat(moduleName, ":") 1131 }, this.options)); 1132 } 1133 }]); 1134 return Logger2; 1135 }(); 1136 baseLogger = new Logger(); 1137 EventEmitter = function() { 1138 function EventEmitter2() { 1139 _classCallCheck(this, EventEmitter2); 1140 this.observers = {}; 1141 } 1142 _createClass(EventEmitter2, [{ 1143 key: "on", 1144 value: function on2(events, listener) { 1145 var _this = this; 1146 events.split(" ").forEach(function(event) { 1147 _this.observers[event] = _this.observers[event] || []; 1148 _this.observers[event].push(listener); 1149 }); 1150 return this; 1151 } 1152 }, { 1153 key: "off", 1154 value: function off(event, listener) { 1155 if (!this.observers[event]) return; 1156 if (!listener) { 1157 delete this.observers[event]; 1158 return; 1159 } 1160 this.observers[event] = this.observers[event].filter(function(l) { 1161 return l !== listener; 1162 }); 1163 } 1164 }, { 1165 key: "emit", 1166 value: function emit(event) { 1167 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1168 args[_key - 1] = arguments[_key]; 1169 } 1170 if (this.observers[event]) { 1171 var cloned = [].concat(this.observers[event]); 1172 cloned.forEach(function(observer) { 1173 observer.apply(void 0, args); 1174 }); 1175 } 1176 if (this.observers["*"]) { 1177 var _cloned = [].concat(this.observers["*"]); 1178 _cloned.forEach(function(observer) { 1179 observer.apply(observer, [event].concat(args)); 1180 }); 1181 } 1182 } 1183 }]); 1184 return EventEmitter2; 1185 }(); 1186 _entityMap = { 1187 "&": "&", 1188 "<": "<", 1189 ">": ">", 1190 '"': """, 1191 "'": "'", 1192 "/": "/" 1193 }; 1194 isIE10 = typeof window !== "undefined" && window.navigator && window.navigator.userAgent && window.navigator.userAgent.indexOf("MSIE") > -1; 1195 ResourceStore = function(_EventEmitter) { 1196 _inherits(ResourceStore2, _EventEmitter); 1197 function ResourceStore2(data) { 1198 var _this; 1199 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { 1200 ns: ["translation"], 1201 defaultNS: "translation" 1202 }; 1203 _classCallCheck(this, ResourceStore2); 1204 _this = _possibleConstructorReturn(this, _getPrototypeOf(ResourceStore2).call(this)); 1205 if (isIE10) { 1206 EventEmitter.call(_assertThisInitialized(_this)); 1207 } 1208 _this.data = data || {}; 1209 _this.options = options; 1210 if (_this.options.keySeparator === void 0) { 1211 _this.options.keySeparator = "."; 1212 } 1213 return _this; 1214 } 1215 _createClass(ResourceStore2, [{ 1216 key: "addNamespaces", 1217 value: function addNamespaces(ns) { 1218 if (this.options.ns.indexOf(ns) < 0) { 1219 this.options.ns.push(ns); 1220 } 1221 } 1222 }, { 1223 key: "removeNamespaces", 1224 value: function removeNamespaces(ns) { 1225 var index = this.options.ns.indexOf(ns); 1226 if (index > -1) { 1227 this.options.ns.splice(index, 1); 1228 } 1229 } 1230 }, { 1231 key: "getResource", 1232 value: function getResource(lng, ns, key) { 1233 var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}; 1234 var keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator; 1235 var path = [lng, ns]; 1236 if (key && typeof key !== "string") path = path.concat(key); 1237 if (key && typeof key === "string") path = path.concat(keySeparator ? key.split(keySeparator) : key); 1238 if (lng.indexOf(".") > -1) { 1239 path = lng.split("."); 1240 } 1241 return getPath2(this.data, path); 1242 } 1243 }, { 1244 key: "addResource", 1245 value: function addResource(lng, ns, key, value) { 1246 var options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : { 1247 silent: false 1248 }; 1249 var keySeparator = this.options.keySeparator; 1250 if (keySeparator === void 0) keySeparator = "."; 1251 var path = [lng, ns]; 1252 if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); 1253 if (lng.indexOf(".") > -1) { 1254 path = lng.split("."); 1255 value = ns; 1256 ns = path[1]; 1257 } 1258 this.addNamespaces(ns); 1259 setPath2(this.data, path, value); 1260 if (!options.silent) this.emit("added", lng, ns, key, value); 1261 } 1262 }, { 1263 key: "addResources", 1264 value: function addResources(lng, ns, resources) { 1265 var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : { 1266 silent: false 1267 }; 1268 for (var m in resources) { 1269 if (typeof resources[m] === "string" || Object.prototype.toString.apply(resources[m]) === "[object Array]") this.addResource(lng, ns, m, resources[m], { 1270 silent: true 1271 }); 1272 } 1273 if (!options.silent) this.emit("added", lng, ns, resources); 1274 } 1275 }, { 1276 key: "addResourceBundle", 1277 value: function addResourceBundle(lng, ns, resources, deep, overwrite) { 1278 var options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : { 1279 silent: false 1280 }; 1281 var path = [lng, ns]; 1282 if (lng.indexOf(".") > -1) { 1283 path = lng.split("."); 1284 deep = resources; 1285 resources = ns; 1286 ns = path[1]; 1287 } 1288 this.addNamespaces(ns); 1289 var pack = getPath2(this.data, path) || {}; 1290 if (deep) { 1291 deepExtend(pack, resources, overwrite); 1292 } else { 1293 pack = _objectSpread({}, pack, resources); 1294 } 1295 setPath2(this.data, path, pack); 1296 if (!options.silent) this.emit("added", lng, ns, resources); 1297 } 1298 }, { 1299 key: "removeResourceBundle", 1300 value: function removeResourceBundle(lng, ns) { 1301 if (this.hasResourceBundle(lng, ns)) { 1302 delete this.data[lng][ns]; 1303 } 1304 this.removeNamespaces(ns); 1305 this.emit("removed", lng, ns); 1306 } 1307 }, { 1308 key: "hasResourceBundle", 1309 value: function hasResourceBundle(lng, ns) { 1310 return this.getResource(lng, ns) !== void 0; 1311 } 1312 }, { 1313 key: "getResourceBundle", 1314 value: function getResourceBundle(lng, ns) { 1315 if (!ns) ns = this.options.defaultNS; 1316 if (this.options.compatibilityAPI === "v1") return _objectSpread({}, {}, this.getResource(lng, ns)); 1317 return this.getResource(lng, ns); 1318 } 1319 }, { 1320 key: "getDataByLanguage", 1321 value: function getDataByLanguage(lng) { 1322 return this.data[lng]; 1323 } 1324 }, { 1325 key: "toJSON", 1326 value: function toJSON() { 1327 return this.data; 1328 } 1329 }]); 1330 return ResourceStore2; 1331 }(EventEmitter); 1332 postProcessor = { 1333 processors: {}, 1334 addPostProcessor: function addPostProcessor(module) { 1335 this.processors[module.name] = module; 1336 }, 1337 handle: function handle(processors, value, key, options, translator) { 1338 var _this = this; 1339 processors.forEach(function(processor) { 1340 if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator); 1341 }); 1342 return value; 1343 } 1344 }; 1345 checkedLoadedFor = {}; 1346 Translator = function(_EventEmitter) { 1347 _inherits(Translator2, _EventEmitter); 1348 function Translator2(services) { 1349 var _this; 1350 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; 1351 _classCallCheck(this, Translator2); 1352 _this = _possibleConstructorReturn(this, _getPrototypeOf(Translator2).call(this)); 1353 if (isIE10) { 1354 EventEmitter.call(_assertThisInitialized(_this)); 1355 } 1356 copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, _assertThisInitialized(_this)); 1357 _this.options = options; 1358 if (_this.options.keySeparator === void 0) { 1359 _this.options.keySeparator = "."; 1360 } 1361 _this.logger = baseLogger.create("translator"); 1362 return _this; 1363 } 1364 _createClass(Translator2, [{ 1365 key: "changeLanguage", 1366 value: function changeLanguage(lng) { 1367 if (lng) this.language = lng; 1368 } 1369 }, { 1370 key: "exists", 1371 value: function exists(key) { 1372 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : { 1373 interpolation: {} 1374 }; 1375 var resolved = this.resolve(key, options); 1376 return resolved && resolved.res !== void 0; 1377 } 1378 }, { 1379 key: "extractFromKey", 1380 value: function extractFromKey(key, options) { 1381 var nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator; 1382 if (nsSeparator === void 0) nsSeparator = ":"; 1383 var keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator; 1384 var namespaces = options.ns || this.options.defaultNS; 1385 if (nsSeparator && key.indexOf(nsSeparator) > -1) { 1386 var m = key.match(this.interpolator.nestingRegexp); 1387 if (m && m.length > 0) { 1388 return { 1389 key, 1390 namespaces 1391 }; 1392 } 1393 var parts = key.split(nsSeparator); 1394 if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift(); 1395 key = parts.join(keySeparator); 1396 } 1397 if (typeof namespaces === "string") namespaces = [namespaces]; 1398 return { 1399 key, 1400 namespaces 1401 }; 1402 } 1403 }, { 1404 key: "translate", 1405 value: function translate(keys, options, lastKey) { 1406 var _this2 = this; 1407 if (_typeof(options) !== "object" && this.options.overloadTranslationOptionHandler) { 1408 options = this.options.overloadTranslationOptionHandler(arguments); 1409 } 1410 if (!options) options = {}; 1411 if (keys === void 0 || keys === null) return ""; 1412 if (!Array.isArray(keys)) keys = [String(keys)]; 1413 var keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator; 1414 var _this$extractFromKey = this.extractFromKey(keys[keys.length - 1], options), key = _this$extractFromKey.key, namespaces = _this$extractFromKey.namespaces; 1415 var namespace = namespaces[namespaces.length - 1]; 1416 var lng = options.lng || this.language; 1417 var appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode; 1418 if (lng && lng.toLowerCase() === "cimode") { 1419 if (appendNamespaceToCIMode) { 1420 var nsSeparator = options.nsSeparator || this.options.nsSeparator; 1421 return namespace + nsSeparator + key; 1422 } 1423 return key; 1424 } 1425 var resolved = this.resolve(keys, options); 1426 var res = resolved && resolved.res; 1427 var resUsedKey = resolved && resolved.usedKey || key; 1428 var resExactUsedKey = resolved && resolved.exactUsedKey || key; 1429 var resType = Object.prototype.toString.apply(res); 1430 var noObject = ["[object Number]", "[object Function]", "[object RegExp]"]; 1431 var joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays; 1432 var handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject; 1433 var handleAsObject = typeof res !== "string" && typeof res !== "boolean" && typeof res !== "number"; 1434 if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(typeof joinArrays === "string" && resType === "[object Array]")) { 1435 if (!options.returnObjects && !this.options.returnObjects) { 1436 this.logger.warn("accessing an object - but returnObjects options is not enabled!"); 1437 return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, options) : "key '".concat(key, " (").concat(this.language, ")' returned an object instead of string."); 1438 } 1439 if (keySeparator) { 1440 var resTypeIsArray = resType === "[object Array]"; 1441 var copy2 = resTypeIsArray ? [] : {}; 1442 var newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey; 1443 for (var m in res) { 1444 if (Object.prototype.hasOwnProperty.call(res, m)) { 1445 var deepKey = "".concat(newKeyToUse).concat(keySeparator).concat(m); 1446 copy2[m] = this.translate(deepKey, _objectSpread({}, options, { 1447 joinArrays: false, 1448 ns: namespaces 1449 })); 1450 if (copy2[m] === deepKey) copy2[m] = res[m]; 1451 } 1452 } 1453 res = copy2; 1454 } 1455 } else if (handleAsObjectInI18nFormat && typeof joinArrays === "string" && resType === "[object Array]") { 1456 res = res.join(joinArrays); 1457 if (res) res = this.extendTranslation(res, keys, options, lastKey); 1458 } else { 1459 var usedDefault = false; 1460 var usedKey = false; 1461 var needsPluralHandling = options.count !== void 0 && typeof options.count !== "string"; 1462 var hasDefaultValue = Translator2.hasDefaultValue(options); 1463 var defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count) : ""; 1464 var defaultValue = options["defaultValue".concat(defaultValueSuffix)] || options.defaultValue; 1465 if (!this.isValidLookup(res) && hasDefaultValue) { 1466 usedDefault = true; 1467 res = defaultValue; 1468 } 1469 if (!this.isValidLookup(res)) { 1470 usedKey = true; 1471 res = key; 1472 } 1473 var updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing; 1474 if (usedKey || usedDefault || updateMissing) { 1475 this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res); 1476 if (keySeparator) { 1477 var fk = this.resolve(key, _objectSpread({}, options, { 1478 keySeparator: false 1479 })); 1480 if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format."); 1481 } 1482 var lngs = []; 1483 var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language); 1484 if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) { 1485 for (var i = 0; i < fallbackLngs.length; i++) { 1486 lngs.push(fallbackLngs[i]); 1487 } 1488 } else if (this.options.saveMissingTo === "all") { 1489 lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); 1490 } else { 1491 lngs.push(options.lng || this.language); 1492 } 1493 var send = function send2(l, k, fallbackValue) { 1494 if (_this2.options.missingKeyHandler) { 1495 _this2.options.missingKeyHandler(l, namespace, k, updateMissing ? fallbackValue : res, updateMissing, options); 1496 } else if (_this2.backendConnector && _this2.backendConnector.saveMissing) { 1497 _this2.backendConnector.saveMissing(l, namespace, k, updateMissing ? fallbackValue : res, updateMissing, options); 1498 } 1499 _this2.emit("missingKey", l, namespace, k, res); 1500 }; 1501 if (this.options.saveMissing) { 1502 if (this.options.saveMissingPlurals && needsPluralHandling) { 1503 lngs.forEach(function(language) { 1504 _this2.pluralResolver.getSuffixes(language).forEach(function(suffix) { 1505 send([language], key + suffix, options["defaultValue".concat(suffix)] || defaultValue); 1506 }); 1507 }); 1508 } else { 1509 send(lngs, key, defaultValue); 1510 } 1511 } 1512 } 1513 res = this.extendTranslation(res, keys, options, resolved, lastKey); 1514 if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = "".concat(namespace, ":").concat(key); 1515 if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); 1516 } 1517 return res; 1518 } 1519 }, { 1520 key: "extendTranslation", 1521 value: function extendTranslation(res, key, options, resolved, lastKey) { 1522 var _this3 = this; 1523 if (this.i18nFormat && this.i18nFormat.parse) { 1524 res = this.i18nFormat.parse(res, options, resolved.usedLng, resolved.usedNS, resolved.usedKey, { 1525 resolved 1526 }); 1527 } else if (!options.skipInterpolation) { 1528 if (options.interpolation) this.interpolator.init(_objectSpread({}, options, { 1529 interpolation: _objectSpread({}, this.options.interpolation, options.interpolation) 1530 })); 1531 var skipOnVariables = options.interpolation && options.interpolation.skipOnVariables || this.options.interpolation.skipOnVariables; 1532 var nestBef; 1533 if (skipOnVariables) { 1534 var nb = res.match(this.interpolator.nestingRegexp); 1535 nestBef = nb && nb.length; 1536 } 1537 var data = options.replace && typeof options.replace !== "string" ? options.replace : options; 1538 if (this.options.interpolation.defaultVariables) data = _objectSpread({}, this.options.interpolation.defaultVariables, data); 1539 res = this.interpolator.interpolate(res, data, options.lng || this.language, options); 1540 if (skipOnVariables) { 1541 var na = res.match(this.interpolator.nestingRegexp); 1542 var nestAft = na && na.length; 1543 if (nestBef < nestAft) options.nest = false; 1544 } 1545 if (options.nest !== false) res = this.interpolator.nest(res, function() { 1546 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 1547 args[_key] = arguments[_key]; 1548 } 1549 if (lastKey && lastKey[0] === args[0] && !options.context) { 1550 _this3.logger.warn("It seems you are nesting recursively key: ".concat(args[0], " in key: ").concat(key[0])); 1551 return null; 1552 } 1553 return _this3.translate.apply(_this3, args.concat([key])); 1554 }, options); 1555 if (options.interpolation) this.interpolator.reset(); 1556 } 1557 var postProcess = options.postProcess || this.options.postProcess; 1558 var postProcessorNames = typeof postProcess === "string" ? [postProcess] : postProcess; 1559 if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { 1560 res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? _objectSpread({ 1561 i18nResolved: resolved 1562 }, options) : options, this); 1563 } 1564 return res; 1565 } 1566 }, { 1567 key: "resolve", 1568 value: function resolve(keys) { 1569 var _this4 = this; 1570 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; 1571 var found; 1572 var usedKey; 1573 var exactUsedKey; 1574 var usedLng; 1575 var usedNS; 1576 if (typeof keys === "string") keys = [keys]; 1577 keys.forEach(function(k) { 1578 if (_this4.isValidLookup(found)) return; 1579 var extracted = _this4.extractFromKey(k, options); 1580 var key = extracted.key; 1581 usedKey = key; 1582 var namespaces = extracted.namespaces; 1583 if (_this4.options.fallbackNS) namespaces = namespaces.concat(_this4.options.fallbackNS); 1584 var needsPluralHandling = options.count !== void 0 && typeof options.count !== "string"; 1585 var needsContextHandling = options.context !== void 0 && typeof options.context === "string" && options.context !== ""; 1586 var codes = options.lngs ? options.lngs : _this4.languageUtils.toResolveHierarchy(options.lng || _this4.language, options.fallbackLng); 1587 namespaces.forEach(function(ns) { 1588 if (_this4.isValidLookup(found)) return; 1589 usedNS = ns; 1590 if (!checkedLoadedFor["".concat(codes[0], "-").concat(ns)] && _this4.utils && _this4.utils.hasLoadedNamespace && !_this4.utils.hasLoadedNamespace(usedNS)) { 1591 checkedLoadedFor["".concat(codes[0], "-").concat(ns)] = true; 1592 _this4.logger.warn('key "'.concat(usedKey, '" for languages "').concat(codes.join(", "), `" won't get resolved as namespace "`).concat(usedNS, '" was not yet loaded'), "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!"); 1593 } 1594 codes.forEach(function(code) { 1595 if (_this4.isValidLookup(found)) return; 1596 usedLng = code; 1597 var finalKey = key; 1598 var finalKeys = [finalKey]; 1599 if (_this4.i18nFormat && _this4.i18nFormat.addLookupKeys) { 1600 _this4.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options); 1601 } else { 1602 var pluralSuffix; 1603 if (needsPluralHandling) pluralSuffix = _this4.pluralResolver.getSuffix(code, options.count); 1604 if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); 1605 if (needsContextHandling) finalKeys.push(finalKey += "".concat(_this4.options.contextSeparator).concat(options.context)); 1606 if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); 1607 } 1608 var possibleKey; 1609 while (possibleKey = finalKeys.pop()) { 1610 if (!_this4.isValidLookup(found)) { 1611 exactUsedKey = possibleKey; 1612 found = _this4.getResource(code, ns, possibleKey, options); 1613 } 1614 } 1615 }); 1616 }); 1617 }); 1618 return { 1619 res: found, 1620 usedKey, 1621 exactUsedKey, 1622 usedLng, 1623 usedNS 1624 }; 1625 } 1626 }, { 1627 key: "isValidLookup", 1628 value: function isValidLookup(res) { 1629 return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ""); 1630 } 1631 }, { 1632 key: "getResource", 1633 value: function getResource(code, ns, key) { 1634 var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}; 1635 if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options); 1636 return this.resourceStore.getResource(code, ns, key, options); 1637 } 1638 }], [{ 1639 key: "hasDefaultValue", 1640 value: function hasDefaultValue(options) { 1641 var prefix = "defaultValue"; 1642 for (var option in options) { 1643 if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) { 1644 return true; 1645 } 1646 } 1647 return false; 1648 } 1649 }]); 1650 return Translator2; 1651 }(EventEmitter); 1652 LanguageUtil = function() { 1653 function LanguageUtil2(options) { 1654 _classCallCheck(this, LanguageUtil2); 1655 this.options = options; 1656 this.whitelist = this.options.supportedLngs || false; 1657 this.supportedLngs = this.options.supportedLngs || false; 1658 this.logger = baseLogger.create("languageUtils"); 1659 } 1660 _createClass(LanguageUtil2, [{ 1661 key: "getScriptPartFromCode", 1662 value: function getScriptPartFromCode(code) { 1663 if (!code || code.indexOf("-") < 0) return null; 1664 var p = code.split("-"); 1665 if (p.length === 2) return null; 1666 p.pop(); 1667 if (p[p.length - 1].toLowerCase() === "x") return null; 1668 return this.formatLanguageCode(p.join("-")); 1669 } 1670 }, { 1671 key: "getLanguagePartFromCode", 1672 value: function getLanguagePartFromCode(code) { 1673 if (!code || code.indexOf("-") < 0) return code; 1674 var p = code.split("-"); 1675 return this.formatLanguageCode(p[0]); 1676 } 1677 }, { 1678 key: "formatLanguageCode", 1679 value: function formatLanguageCode(code) { 1680 if (typeof code === "string" && code.indexOf("-") > -1) { 1681 var specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"]; 1682 var p = code.split("-"); 1683 if (this.options.lowerCaseLng) { 1684 p = p.map(function(part) { 1685 return part.toLowerCase(); 1686 }); 1687 } else if (p.length === 2) { 1688 p[0] = p[0].toLowerCase(); 1689 p[1] = p[1].toUpperCase(); 1690 if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase()); 1691 } else if (p.length === 3) { 1692 p[0] = p[0].toLowerCase(); 1693 if (p[1].length === 2) p[1] = p[1].toUpperCase(); 1694 if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase(); 1695 if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase()); 1696 if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase()); 1697 } 1698 return p.join("-"); 1699 } 1700 return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; 1701 } 1702 }, { 1703 key: "isWhitelisted", 1704 value: function isWhitelisted(code) { 1705 this.logger.deprecate("languageUtils.isWhitelisted", `function "isWhitelisted" will be renamed to "isSupportedCode" in the next major - please make sure to rename it's usage asap.`); 1706 return this.isSupportedCode(code); 1707 } 1708 }, { 1709 key: "isSupportedCode", 1710 value: function isSupportedCode(code) { 1711 if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) { 1712 code = this.getLanguagePartFromCode(code); 1713 } 1714 return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1; 1715 } 1716 }, { 1717 key: "getBestMatchFromCodes", 1718 value: function getBestMatchFromCodes(codes) { 1719 var _this = this; 1720 if (!codes) return null; 1721 var found; 1722 codes.forEach(function(code) { 1723 if (found) return; 1724 var cleanedLng = _this.formatLanguageCode(code); 1725 if (!_this.options.supportedLngs || _this.isSupportedCode(cleanedLng)) found = cleanedLng; 1726 }); 1727 if (!found && this.options.supportedLngs) { 1728 codes.forEach(function(code) { 1729 if (found) return; 1730 var lngOnly = _this.getLanguagePartFromCode(code); 1731 if (_this.isSupportedCode(lngOnly)) return found = lngOnly; 1732 found = _this.options.supportedLngs.find(function(supportedLng) { 1733 if (supportedLng.indexOf(lngOnly) === 0) return supportedLng; 1734 }); 1735 }); 1736 } 1737 if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0]; 1738 return found; 1739 } 1740 }, { 1741 key: "getFallbackCodes", 1742 value: function getFallbackCodes(fallbacks, code) { 1743 if (!fallbacks) return []; 1744 if (typeof fallbacks === "function") fallbacks = fallbacks(code); 1745 if (typeof fallbacks === "string") fallbacks = [fallbacks]; 1746 if (Object.prototype.toString.apply(fallbacks) === "[object Array]") return fallbacks; 1747 if (!code) return fallbacks["default"] || []; 1748 var found = fallbacks[code]; 1749 if (!found) found = fallbacks[this.getScriptPartFromCode(code)]; 1750 if (!found) found = fallbacks[this.formatLanguageCode(code)]; 1751 if (!found) found = fallbacks[this.getLanguagePartFromCode(code)]; 1752 if (!found) found = fallbacks["default"]; 1753 return found || []; 1754 } 1755 }, { 1756 key: "toResolveHierarchy", 1757 value: function toResolveHierarchy(code, fallbackCode) { 1758 var _this2 = this; 1759 var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code); 1760 var codes = []; 1761 var addCode = function addCode2(c) { 1762 if (!c) return; 1763 if (_this2.isSupportedCode(c)) { 1764 codes.push(c); 1765 } else { 1766 _this2.logger.warn("rejecting language code not found in supportedLngs: ".concat(c)); 1767 } 1768 }; 1769 if (typeof code === "string" && code.indexOf("-") > -1) { 1770 if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code)); 1771 if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code)); 1772 if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code)); 1773 } else if (typeof code === "string") { 1774 addCode(this.formatLanguageCode(code)); 1775 } 1776 fallbackCodes.forEach(function(fc) { 1777 if (codes.indexOf(fc) < 0) addCode(_this2.formatLanguageCode(fc)); 1778 }); 1779 return codes; 1780 } 1781 }]); 1782 return LanguageUtil2; 1783 }(); 1784 sets = [{ 1785 lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"], 1786 nr: [1, 2], 1787 fc: 1 1788 }, { 1789 lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"], 1790 nr: [1, 2], 1791 fc: 2 1792 }, { 1793 lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "kk", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"], 1794 nr: [1], 1795 fc: 3 1796 }, { 1797 lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"], 1798 nr: [1, 2, 5], 1799 fc: 4 1800 }, { 1801 lngs: ["ar"], 1802 nr: [0, 1, 2, 3, 11, 100], 1803 fc: 5 1804 }, { 1805 lngs: ["cs", "sk"], 1806 nr: [1, 2, 5], 1807 fc: 6 1808 }, { 1809 lngs: ["csb", "pl"], 1810 nr: [1, 2, 5], 1811 fc: 7 1812 }, { 1813 lngs: ["cy"], 1814 nr: [1, 2, 3, 8], 1815 fc: 8 1816 }, { 1817 lngs: ["fr"], 1818 nr: [1, 2], 1819 fc: 9 1820 }, { 1821 lngs: ["ga"], 1822 nr: [1, 2, 3, 7, 11], 1823 fc: 10 1824 }, { 1825 lngs: ["gd"], 1826 nr: [1, 2, 3, 20], 1827 fc: 11 1828 }, { 1829 lngs: ["is"], 1830 nr: [1, 2], 1831 fc: 12 1832 }, { 1833 lngs: ["jv"], 1834 nr: [0, 1], 1835 fc: 13 1836 }, { 1837 lngs: ["kw"], 1838 nr: [1, 2, 3, 4], 1839 fc: 14 1840 }, { 1841 lngs: ["lt"], 1842 nr: [1, 2, 10], 1843 fc: 15 1844 }, { 1845 lngs: ["lv"], 1846 nr: [1, 2, 0], 1847 fc: 16 1848 }, { 1849 lngs: ["mk"], 1850 nr: [1, 2], 1851 fc: 17 1852 }, { 1853 lngs: ["mnk"], 1854 nr: [0, 1, 2], 1855 fc: 18 1856 }, { 1857 lngs: ["mt"], 1858 nr: [1, 2, 11, 20], 1859 fc: 19 1860 }, { 1861 lngs: ["or"], 1862 nr: [2, 1], 1863 fc: 2 1864 }, { 1865 lngs: ["ro"], 1866 nr: [1, 2, 20], 1867 fc: 20 1868 }, { 1869 lngs: ["sl"], 1870 nr: [5, 1, 2, 3], 1871 fc: 21 1872 }, { 1873 lngs: ["he", "iw"], 1874 nr: [1, 2, 20, 21], 1875 fc: 22 1876 }]; 1877 _rulesPluralsTypes = { 1878 1: function _(n) { 1879 return Number(n > 1); 1880 }, 1881 2: function _2(n) { 1882 return Number(n != 1); 1883 }, 1884 3: function _3(n) { 1885 return 0; 1886 }, 1887 4: function _4(n) { 1888 return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); 1889 }, 1890 5: function _5(n) { 1891 return Number(n == 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); 1892 }, 1893 6: function _6(n) { 1894 return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2); 1895 }, 1896 7: function _7(n) { 1897 return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); 1898 }, 1899 8: function _8(n) { 1900 return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3); 1901 }, 1902 9: function _9(n) { 1903 return Number(n >= 2); 1904 }, 1905 10: function _10(n) { 1906 return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4); 1907 }, 1908 11: function _11(n) { 1909 return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3); 1910 }, 1911 12: function _12(n) { 1912 return Number(n % 10 != 1 || n % 100 == 11); 1913 }, 1914 13: function _13(n) { 1915 return Number(n !== 0); 1916 }, 1917 14: function _14(n) { 1918 return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3); 1919 }, 1920 15: function _15(n) { 1921 return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); 1922 }, 1923 16: function _16(n) { 1924 return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2); 1925 }, 1926 17: function _17(n) { 1927 return Number(n == 1 || n % 10 == 1 && n % 100 != 11 ? 0 : 1); 1928 }, 1929 18: function _18(n) { 1930 return Number(n == 0 ? 0 : n == 1 ? 1 : 2); 1931 }, 1932 19: function _19(n) { 1933 return Number(n == 1 ? 0 : n == 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3); 1934 }, 1935 20: function _20(n) { 1936 return Number(n == 1 ? 0 : n == 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2); 1937 }, 1938 21: function _21(n) { 1939 return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0); 1940 }, 1941 22: function _22(n) { 1942 return Number(n == 1 ? 0 : n == 2 ? 1 : (n < 0 || n > 10) && n % 10 == 0 ? 2 : 3); 1943 } 1944 }; 1945 PluralResolver = function() { 1946 function PluralResolver2(languageUtils) { 1947 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; 1948 _classCallCheck(this, PluralResolver2); 1949 this.languageUtils = languageUtils; 1950 this.options = options; 1951 this.logger = baseLogger.create("pluralResolver"); 1952 this.rules = createRules(); 1953 } 1954 _createClass(PluralResolver2, [{ 1955 key: "addRule", 1956 value: function addRule(lng, obj) { 1957 this.rules[lng] = obj; 1958 } 1959 }, { 1960 key: "getRule", 1961 value: function getRule(code) { 1962 return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)]; 1963 } 1964 }, { 1965 key: "needsPlural", 1966 value: function needsPlural(code) { 1967 var rule = this.getRule(code); 1968 return rule && rule.numbers.length > 1; 1969 } 1970 }, { 1971 key: "getPluralFormsOfKey", 1972 value: function getPluralFormsOfKey(code, key) { 1973 return this.getSuffixes(code).map(function(suffix) { 1974 return key + suffix; 1975 }); 1976 } 1977 }, { 1978 key: "getSuffixes", 1979 value: function getSuffixes(code) { 1980 var _this = this; 1981 var rule = this.getRule(code); 1982 if (!rule) { 1983 return []; 1984 } 1985 return rule.numbers.map(function(number) { 1986 return _this.getSuffix(code, number); 1987 }); 1988 } 1989 }, { 1990 key: "getSuffix", 1991 value: function getSuffix(code, count) { 1992 var _this2 = this; 1993 var rule = this.getRule(code); 1994 if (rule) { 1995 var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); 1996 var suffix = rule.numbers[idx]; 1997 if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) { 1998 if (suffix === 2) { 1999 suffix = "plural"; 2000 } else if (suffix === 1) { 2001 suffix = ""; 2002 } 2003 } 2004 var returnSuffix = function returnSuffix2() { 2005 return _this2.options.prepend && suffix.toString() ? _this2.options.prepend + suffix.toString() : suffix.toString(); 2006 }; 2007 if (this.options.compatibilityJSON === "v1") { 2008 if (suffix === 1) return ""; 2009 if (typeof suffix === "number") return "_plural_".concat(suffix.toString()); 2010 return returnSuffix(); 2011 } else if (this.options.compatibilityJSON === "v2") { 2012 return returnSuffix(); 2013 } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) { 2014 return returnSuffix(); 2015 } 2016 return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString(); 2017 } 2018 this.logger.warn("no plural rule found for: ".concat(code)); 2019 return ""; 2020 } 2021 }]); 2022 return PluralResolver2; 2023 }(); 2024 Interpolator = function() { 2025 function Interpolator2() { 2026 var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; 2027 _classCallCheck(this, Interpolator2); 2028 this.logger = baseLogger.create("interpolator"); 2029 this.options = options; 2030 this.format = options.interpolation && options.interpolation.format || function(value) { 2031 return value; 2032 }; 2033 this.init(options); 2034 } 2035 _createClass(Interpolator2, [{ 2036 key: "init", 2037 value: function init() { 2038 var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; 2039 if (!options.interpolation) options.interpolation = { 2040 escapeValue: true 2041 }; 2042 var iOpts = options.interpolation; 2043 this.escape = iOpts.escape !== void 0 ? iOpts.escape : escape2; 2044 this.escapeValue = iOpts.escapeValue !== void 0 ? iOpts.escapeValue : true; 2045 this.useRawValueToEscape = iOpts.useRawValueToEscape !== void 0 ? iOpts.useRawValueToEscape : false; 2046 this.prefix = iOpts.prefix ? regexEscape(iOpts.prefix) : iOpts.prefixEscaped || "{{"; 2047 this.suffix = iOpts.suffix ? regexEscape(iOpts.suffix) : iOpts.suffixEscaped || "}}"; 2048 this.formatSeparator = iOpts.formatSeparator ? iOpts.formatSeparator : iOpts.formatSeparator || ","; 2049 this.unescapePrefix = iOpts.unescapeSuffix ? "" : iOpts.unescapePrefix || "-"; 2050 this.unescapeSuffix = this.unescapePrefix ? "" : iOpts.unescapeSuffix || ""; 2051 this.nestingPrefix = iOpts.nestingPrefix ? regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || regexEscape("$t("); 2052 this.nestingSuffix = iOpts.nestingSuffix ? regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || regexEscape(")"); 2053 this.nestingOptionsSeparator = iOpts.nestingOptionsSeparator ? iOpts.nestingOptionsSeparator : iOpts.nestingOptionsSeparator || ","; 2054 this.maxReplaces = iOpts.maxReplaces ? iOpts.maxReplaces : 1e3; 2055 this.alwaysFormat = iOpts.alwaysFormat !== void 0 ? iOpts.alwaysFormat : false; 2056 this.resetRegExp(); 2057 } 2058 }, { 2059 key: "reset", 2060 value: function reset() { 2061 if (this.options) this.init(this.options); 2062 } 2063 }, { 2064 key: "resetRegExp", 2065 value: function resetRegExp() { 2066 var regexpStr = "".concat(this.prefix, "(.+?)").concat(this.suffix); 2067 this.regexp = new RegExp(regexpStr, "g"); 2068 var regexpUnescapeStr = "".concat(this.prefix).concat(this.unescapePrefix, "(.+?)").concat(this.unescapeSuffix).concat(this.suffix); 2069 this.regexpUnescape = new RegExp(regexpUnescapeStr, "g"); 2070 var nestingRegexpStr = "".concat(this.nestingPrefix, "(.+?)").concat(this.nestingSuffix); 2071 this.nestingRegexp = new RegExp(nestingRegexpStr, "g"); 2072 } 2073 }, { 2074 key: "interpolate", 2075 value: function interpolate(str, data, lng, options) { 2076 var _this = this; 2077 var match; 2078 var value; 2079 var replaces; 2080 var defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {}; 2081 function regexSafe(val) { 2082 return val.replace(/\$/g, "$$$$"); 2083 } 2084 var handleFormat = function handleFormat2(key) { 2085 if (key.indexOf(_this.formatSeparator) < 0) { 2086 var path = getPathWithDefaults(data, defaultData, key); 2087 return _this.alwaysFormat ? _this.format(path, void 0, lng) : path; 2088 } 2089 var p = key.split(_this.formatSeparator); 2090 var k = p.shift().trim(); 2091 var f = p.join(_this.formatSeparator).trim(); 2092 return _this.format(getPathWithDefaults(data, defaultData, k), f, lng, options); 2093 }; 2094 this.resetRegExp(); 2095 var missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler; 2096 var skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables || this.options.interpolation.skipOnVariables; 2097 var todos = [{ 2098 regex: this.regexpUnescape, 2099 safeValue: function safeValue(val) { 2100 return regexSafe(val); 2101 } 2102 }, { 2103 regex: this.regexp, 2104 safeValue: function safeValue(val) { 2105 return _this.escapeValue ? regexSafe(_this.escape(val)) : regexSafe(val); 2106 } 2107 }]; 2108 todos.forEach(function(todo) { 2109 replaces = 0; 2110 while (match = todo.regex.exec(str)) { 2111 value = handleFormat(match[1].trim()); 2112 if (value === void 0) { 2113 if (typeof missingInterpolationHandler === "function") { 2114 var temp = missingInterpolationHandler(str, match, options); 2115 value = typeof temp === "string" ? temp : ""; 2116 } else if (skipOnVariables) { 2117 value = match[0]; 2118 continue; 2119 } else { 2120 _this.logger.warn("missed to pass in variable ".concat(match[1], " for interpolating ").concat(str)); 2121 value = ""; 2122 } 2123 } else if (typeof value !== "string" && !_this.useRawValueToEscape) { 2124 value = makeString(value); 2125 } 2126 str = str.replace(match[0], todo.safeValue(value)); 2127 todo.regex.lastIndex = 0; 2128 replaces++; 2129 if (replaces >= _this.maxReplaces) { 2130 break; 2131 } 2132 } 2133 }); 2134 return str; 2135 } 2136 }, { 2137 key: "nest", 2138 value: function nest(str, fc) { 2139 var _this2 = this; 2140 var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; 2141 var match; 2142 var value; 2143 var clonedOptions = _objectSpread({}, options); 2144 clonedOptions.applyPostProcessor = false; 2145 delete clonedOptions.defaultValue; 2146 function handleHasOptions(key, inheritedOptions) { 2147 var sep = this.nestingOptionsSeparator; 2148 if (key.indexOf(sep) < 0) return key; 2149 var c = key.split(new RegExp("".concat(sep, "[ ]*{"))); 2150 var optionsString = "{".concat(c[1]); 2151 key = c[0]; 2152 optionsString = this.interpolate(optionsString, clonedOptions); 2153 optionsString = optionsString.replace(/'/g, '"'); 2154 try { 2155 clonedOptions = JSON.parse(optionsString); 2156 if (inheritedOptions) clonedOptions = _objectSpread({}, inheritedOptions, clonedOptions); 2157 } catch (e) { 2158 this.logger.warn("failed parsing options string in nesting for key ".concat(key), e); 2159 return "".concat(key).concat(sep).concat(optionsString); 2160 } 2161 delete clonedOptions.defaultValue; 2162 return key; 2163 } 2164 while (match = this.nestingRegexp.exec(str)) { 2165 var formatters = []; 2166 var doReduce = false; 2167 if (match[0].includes(this.formatSeparator) && !/{.*}/.test(match[1])) { 2168 var r = match[1].split(this.formatSeparator).map(function(elem) { 2169 return elem.trim(); 2170 }); 2171 match[1] = r.shift(); 2172 formatters = r; 2173 doReduce = true; 2174 } 2175 value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions); 2176 if (value && match[0] === str && typeof value !== "string") return value; 2177 if (typeof value !== "string") value = makeString(value); 2178 if (!value) { 2179 this.logger.warn("missed to resolve ".concat(match[1], " for nesting ").concat(str)); 2180 value = ""; 2181 } 2182 if (doReduce) { 2183 value = formatters.reduce(function(v, f) { 2184 return _this2.format(v, f, options.lng, options); 2185 }, value.trim()); 2186 } 2187 str = str.replace(match[0], value); 2188 this.regexp.lastIndex = 0; 2189 } 2190 return str; 2191 } 2192 }]); 2193 return Interpolator2; 2194 }(); 2195 Connector = function(_EventEmitter) { 2196 _inherits(Connector2, _EventEmitter); 2197 function Connector2(backend, store, services) { 2198 var _this; 2199 var options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}; 2200 _classCallCheck(this, Connector2); 2201 _this = _possibleConstructorReturn(this, _getPrototypeOf(Connector2).call(this)); 2202 if (isIE10) { 2203 EventEmitter.call(_assertThisInitialized(_this)); 2204 } 2205 _this.backend = backend; 2206 _this.store = store; 2207 _this.services = services; 2208 _this.languageUtils = services.languageUtils; 2209 _this.options = options; 2210 _this.logger = baseLogger.create("backendConnector"); 2211 _this.state = {}; 2212 _this.queue = []; 2213 if (_this.backend && _this.backend.init) { 2214 _this.backend.init(services, options.backend, options); 2215 } 2216 return _this; 2217 } 2218 _createClass(Connector2, [{ 2219 key: "queueLoad", 2220 value: function queueLoad(languages, namespaces, options, callback) { 2221 var _this2 = this; 2222 var toLoad = []; 2223 var pending = []; 2224 var toLoadLanguages = []; 2225 var toLoadNamespaces = []; 2226 languages.forEach(function(lng) { 2227 var hasAllNamespaces = true; 2228 namespaces.forEach(function(ns) { 2229 var name = "".concat(lng, "|").concat(ns); 2230 if (!options.reload && _this2.store.hasResourceBundle(lng, ns)) { 2231 _this2.state[name] = 2; 2232 } else if (_this2.state[name] < 0) ; 2233 else if (_this2.state[name] === 1) { 2234 if (pending.indexOf(name) < 0) pending.push(name); 2235 } else { 2236 _this2.state[name] = 1; 2237 hasAllNamespaces = false; 2238 if (pending.indexOf(name) < 0) pending.push(name); 2239 if (toLoad.indexOf(name) < 0) toLoad.push(name); 2240 if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); 2241 } 2242 }); 2243 if (!hasAllNamespaces) toLoadLanguages.push(lng); 2244 }); 2245 if (toLoad.length || pending.length) { 2246 this.queue.push({ 2247 pending, 2248 loaded: {}, 2249 errors: [], 2250 callback 2251 }); 2252 } 2253 return { 2254 toLoad, 2255 pending, 2256 toLoadLanguages, 2257 toLoadNamespaces 2258 }; 2259 } 2260 }, { 2261 key: "loaded", 2262 value: function loaded(name, err, data) { 2263 var s = name.split("|"); 2264 var lng = s[0]; 2265 var ns = s[1]; 2266 if (err) this.emit("failedLoading", lng, ns, err); 2267 if (data) { 2268 this.store.addResourceBundle(lng, ns, data); 2269 } 2270 this.state[name] = err ? -1 : 2; 2271 var loaded2 = {}; 2272 this.queue.forEach(function(q) { 2273 pushPath(q.loaded, [lng], ns); 2274 remove(q.pending, name); 2275 if (err) q.errors.push(err); 2276 if (q.pending.length === 0 && !q.done) { 2277 Object.keys(q.loaded).forEach(function(l) { 2278 if (!loaded2[l]) loaded2[l] = []; 2279 if (q.loaded[l].length) { 2280 q.loaded[l].forEach(function(ns2) { 2281 if (loaded2[l].indexOf(ns2) < 0) loaded2[l].push(ns2); 2282 }); 2283 } 2284 }); 2285 q.done = true; 2286 if (q.errors.length) { 2287 q.callback(q.errors); 2288 } else { 2289 q.callback(); 2290 } 2291 } 2292 }); 2293 this.emit("loaded", loaded2); 2294 this.queue = this.queue.filter(function(q) { 2295 return !q.done; 2296 }); 2297 } 2298 }, { 2299 key: "read", 2300 value: function read(lng, ns, fcName) { 2301 var _this3 = this; 2302 var tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0; 2303 var wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : 350; 2304 var callback = arguments.length > 5 ? arguments[5] : void 0; 2305 if (!lng.length) return callback(null, {}); 2306 return this.backend[fcName](lng, ns, function(err, data) { 2307 if (err && data && tried < 5) { 2308 setTimeout(function() { 2309 _this3.read.call(_this3, lng, ns, fcName, tried + 1, wait * 2, callback); 2310 }, wait); 2311 return; 2312 } 2313 callback(err, data); 2314 }); 2315 } 2316 }, { 2317 key: "prepareLoading", 2318 value: function prepareLoading(languages, namespaces) { 2319 var _this4 = this; 2320 var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; 2321 var callback = arguments.length > 3 ? arguments[3] : void 0; 2322 if (!this.backend) { 2323 this.logger.warn("No backend was added via i18next.use. Will not load resources."); 2324 return callback && callback(); 2325 } 2326 if (typeof languages === "string") languages = this.languageUtils.toResolveHierarchy(languages); 2327 if (typeof namespaces === "string") namespaces = [namespaces]; 2328 var toLoad = this.queueLoad(languages, namespaces, options, callback); 2329 if (!toLoad.toLoad.length) { 2330 if (!toLoad.pending.length) callback(); 2331 return null; 2332 } 2333 toLoad.toLoad.forEach(function(name) { 2334 _this4.loadOne(name); 2335 }); 2336 } 2337 }, { 2338 key: "load", 2339 value: function load(languages, namespaces, callback) { 2340 this.prepareLoading(languages, namespaces, {}, callback); 2341 } 2342 }, { 2343 key: "reload", 2344 value: function reload(languages, namespaces, callback) { 2345 this.prepareLoading(languages, namespaces, { 2346 reload: true 2347 }, callback); 2348 } 2349 }, { 2350 key: "loadOne", 2351 value: function loadOne(name) { 2352 var _this5 = this; 2353 var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ""; 2354 var s = name.split("|"); 2355 var lng = s[0]; 2356 var ns = s[1]; 2357 this.read(lng, ns, "read", void 0, void 0, function(err, data) { 2358 if (err) _this5.logger.warn("".concat(prefix, "loading namespace ").concat(ns, " for language ").concat(lng, " failed"), err); 2359 if (!err && data) _this5.logger.log("".concat(prefix, "loaded namespace ").concat(ns, " for language ").concat(lng), data); 2360 _this5.loaded(name, err, data); 2361 }); 2362 } 2363 }, { 2364 key: "saveMissing", 2365 value: function saveMissing(languages, namespace, key, fallbackValue, isUpdate) { 2366 var options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {}; 2367 if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) { 2368 this.logger.warn('did not save key "'.concat(key, '" as the namespace "').concat(namespace, '" was not yet loaded'), "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!"); 2369 return; 2370 } 2371 if (key === void 0 || key === null || key === "") return; 2372 if (this.backend && this.backend.create) { 2373 this.backend.create(languages, namespace, key, fallbackValue, null, _objectSpread({}, options, { 2374 isUpdate 2375 })); 2376 } 2377 if (!languages || !languages[0]) return; 2378 this.store.addResource(languages[0], namespace, key, fallbackValue); 2379 } 2380 }]); 2381 return Connector2; 2382 }(EventEmitter); 2383 I18n = function(_EventEmitter) { 2384 _inherits(I18n2, _EventEmitter); 2385 function I18n2() { 2386 var _this; 2387 var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; 2388 var callback = arguments.length > 1 ? arguments[1] : void 0; 2389 _classCallCheck(this, I18n2); 2390 _this = _possibleConstructorReturn(this, _getPrototypeOf(I18n2).call(this)); 2391 if (isIE10) { 2392 EventEmitter.call(_assertThisInitialized(_this)); 2393 } 2394 _this.options = transformOptions(options); 2395 _this.services = {}; 2396 _this.logger = baseLogger; 2397 _this.modules = { 2398 external: [] 2399 }; 2400 if (callback && !_this.isInitialized && !options.isClone) { 2401 if (!_this.options.initImmediate) { 2402 _this.init(options, callback); 2403 return _possibleConstructorReturn(_this, _assertThisInitialized(_this)); 2404 } 2405 setTimeout(function() { 2406 _this.init(options, callback); 2407 }, 0); 2408 } 2409 return _this; 2410 } 2411 _createClass(I18n2, [{ 2412 key: "init", 2413 value: function init() { 2414 var _this2 = this; 2415 var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; 2416 var callback = arguments.length > 1 ? arguments[1] : void 0; 2417 if (typeof options === "function") { 2418 callback = options; 2419 options = {}; 2420 } 2421 if (options.whitelist && !options.supportedLngs) { 2422 this.logger.deprecate("whitelist", 'option "whitelist" will be renamed to "supportedLngs" in the next major - please make sure to rename this option asap.'); 2423 } 2424 if (options.nonExplicitWhitelist && !options.nonExplicitSupportedLngs) { 2425 this.logger.deprecate("whitelist", 'options "nonExplicitWhitelist" will be renamed to "nonExplicitSupportedLngs" in the next major - please make sure to rename this option asap.'); 2426 } 2427 this.options = _objectSpread({}, get(), this.options, transformOptions(options)); 2428 this.format = this.options.interpolation.format; 2429 if (!callback) callback = noop; 2430 function createClassOnDemand(ClassOrObject) { 2431 if (!ClassOrObject) return null; 2432 if (typeof ClassOrObject === "function") return new ClassOrObject(); 2433 return ClassOrObject; 2434 } 2435 if (!this.options.isClone) { 2436 if (this.modules.logger) { 2437 baseLogger.init(createClassOnDemand(this.modules.logger), this.options); 2438 } else { 2439 baseLogger.init(null, this.options); 2440 } 2441 var lu = new LanguageUtil(this.options); 2442 this.store = new ResourceStore(this.options.resources, this.options); 2443 var s = this.services; 2444 s.logger = baseLogger; 2445 s.resourceStore = this.store; 2446 s.languageUtils = lu; 2447 s.pluralResolver = new PluralResolver(lu, { 2448 prepend: this.options.pluralSeparator, 2449 compatibilityJSON: this.options.compatibilityJSON, 2450 simplifyPluralSuffix: this.options.simplifyPluralSuffix 2451 }); 2452 s.interpolator = new Interpolator(this.options); 2453 s.utils = { 2454 hasLoadedNamespace: this.hasLoadedNamespace.bind(this) 2455 }; 2456 s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); 2457 s.backendConnector.on("*", function(event) { 2458 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 2459 args[_key - 1] = arguments[_key]; 2460 } 2461 _this2.emit.apply(_this2, [event].concat(args)); 2462 }); 2463 if (this.modules.languageDetector) { 2464 s.languageDetector = createClassOnDemand(this.modules.languageDetector); 2465 s.languageDetector.init(s, this.options.detection, this.options); 2466 } 2467 if (this.modules.i18nFormat) { 2468 s.i18nFormat = createClassOnDemand(this.modules.i18nFormat); 2469 if (s.i18nFormat.init) s.i18nFormat.init(this); 2470 } 2471 this.translator = new Translator(this.services, this.options); 2472 this.translator.on("*", function(event) { 2473 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { 2474 args[_key2 - 1] = arguments[_key2]; 2475 } 2476 _this2.emit.apply(_this2, [event].concat(args)); 2477 }); 2478 this.modules.external.forEach(function(m) { 2479 if (m.init) m.init(_this2); 2480 }); 2481 } 2482 if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) { 2483 var codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng); 2484 if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0]; 2485 } 2486 if (!this.services.languageDetector && !this.options.lng) { 2487 this.logger.warn("init: no languageDetector is used and no lng is defined"); 2488 } 2489 var storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"]; 2490 storeApi.forEach(function(fcName) { 2491 _this2[fcName] = function() { 2492 var _this2$store; 2493 return (_this2$store = _this2.store)[fcName].apply(_this2$store, arguments); 2494 }; 2495 }); 2496 var storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"]; 2497 storeApiChained.forEach(function(fcName) { 2498 _this2[fcName] = function() { 2499 var _this2$store2; 2500 (_this2$store2 = _this2.store)[fcName].apply(_this2$store2, arguments); 2501 return _this2; 2502 }; 2503 }); 2504 var deferred = defer(); 2505 var load = function load2() { 2506 var finish = function finish2(err, t) { 2507 if (_this2.isInitialized) _this2.logger.warn("init: i18next is already initialized. You should call init just once!"); 2508 _this2.isInitialized = true; 2509 if (!_this2.options.isClone) _this2.logger.log("initialized", _this2.options); 2510 _this2.emit("initialized", _this2.options); 2511 deferred.resolve(t); 2512 callback(err, t); 2513 }; 2514 if (_this2.languages && _this2.options.compatibilityAPI !== "v1" && !_this2.isInitialized) return finish(null, _this2.t.bind(_this2)); 2515 _this2.changeLanguage(_this2.options.lng, finish); 2516 }; 2517 if (this.options.resources || !this.options.initImmediate) { 2518 load(); 2519 } else { 2520 setTimeout(load, 0); 2521 } 2522 return deferred; 2523 } 2524 }, { 2525 key: "loadResources", 2526 value: function loadResources(language) { 2527 var _this3 = this; 2528 var callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop; 2529 var usedCallback = callback; 2530 var usedLng = typeof language === "string" ? language : this.language; 2531 if (typeof language === "function") usedCallback = language; 2532 if (!this.options.resources || this.options.partialBundledLanguages) { 2533 if (usedLng && usedLng.toLowerCase() === "cimode") return usedCallback(); 2534 var toLoad = []; 2535 var append = function append2(lng) { 2536 if (!lng) return; 2537 var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); 2538 lngs.forEach(function(l) { 2539 if (toLoad.indexOf(l) < 0) toLoad.push(l); 2540 }); 2541 }; 2542 if (!usedLng) { 2543 var fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng); 2544 fallbacks.forEach(function(l) { 2545 return append(l); 2546 }); 2547 } else { 2548 append(usedLng); 2549 } 2550 if (this.options.preload) { 2551 this.options.preload.forEach(function(l) { 2552 return append(l); 2553 }); 2554 } 2555 this.services.backendConnector.load(toLoad, this.options.ns, usedCallback); 2556 } else { 2557 usedCallback(null); 2558 } 2559 } 2560 }, { 2561 key: "reloadResources", 2562 value: function reloadResources(lngs, ns, callback) { 2563 var deferred = defer(); 2564 if (!lngs) lngs = this.languages; 2565 if (!ns) ns = this.options.ns; 2566 if (!callback) callback = noop; 2567 this.services.backendConnector.reload(lngs, ns, function(err) { 2568 deferred.resolve(); 2569 callback(err); 2570 }); 2571 return deferred; 2572 } 2573 }, { 2574 key: "use", 2575 value: function use(module) { 2576 if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()"); 2577 if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()"); 2578 if (module.type === "backend") { 2579 this.modules.backend = module; 2580 } 2581 if (module.type === "logger" || module.log && module.warn && module.error) { 2582 this.modules.logger = module; 2583 } 2584 if (module.type === "languageDetector") { 2585 this.modules.languageDetector = module; 2586 } 2587 if (module.type === "i18nFormat") { 2588 this.modules.i18nFormat = module; 2589 } 2590 if (module.type === "postProcessor") { 2591 postProcessor.addPostProcessor(module); 2592 } 2593 if (module.type === "3rdParty") { 2594 this.modules.external.push(module); 2595 } 2596 return this; 2597 } 2598 }, { 2599 key: "changeLanguage", 2600 value: function changeLanguage(lng, callback) { 2601 var _this4 = this; 2602 this.isLanguageChangingTo = lng; 2603 var deferred = defer(); 2604 this.emit("languageChanging", lng); 2605 var done = function done2(err, l) { 2606 if (l) { 2607 _this4.language = l; 2608 _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l); 2609 _this4.translator.changeLanguage(l); 2610 _this4.isLanguageChangingTo = void 0; 2611 _this4.emit("languageChanged", l); 2612 _this4.logger.log("languageChanged", l); 2613 } else { 2614 _this4.isLanguageChangingTo = void 0; 2615 } 2616 deferred.resolve(function() { 2617 return _this4.t.apply(_this4, arguments); 2618 }); 2619 if (callback) callback(err, function() { 2620 return _this4.t.apply(_this4, arguments); 2621 }); 2622 }; 2623 var setLng = function setLng2(lngs) { 2624 var l = typeof lngs === "string" ? lngs : _this4.services.languageUtils.getBestMatchFromCodes(lngs); 2625 if (l) { 2626 if (!_this4.language) { 2627 _this4.language = l; 2628 _this4.languages = _this4.services.languageUtils.toResolveHierarchy(l); 2629 } 2630 if (!_this4.translator.language) _this4.translator.changeLanguage(l); 2631 if (_this4.services.languageDetector) _this4.services.languageDetector.cacheUserLanguage(l); 2632 } 2633 _this4.loadResources(l, function(err) { 2634 done(err, l); 2635 }); 2636 }; 2637 if (!lng && this.services.languageDetector && !this.services.languageDetector.async) { 2638 setLng(this.services.languageDetector.detect()); 2639 } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) { 2640 this.services.languageDetector.detect(setLng); 2641 } else { 2642 setLng(lng); 2643 } 2644 return deferred; 2645 } 2646 }, { 2647 key: "getFixedT", 2648 value: function getFixedT(lng, ns) { 2649 var _this5 = this; 2650 var fixedT = function fixedT2(key, opts) { 2651 var options; 2652 if (_typeof(opts) !== "object") { 2653 for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { 2654 rest[_key3 - 2] = arguments[_key3]; 2655 } 2656 options = _this5.options.overloadTranslationOptionHandler([key, opts].concat(rest)); 2657 } else { 2658 options = _objectSpread({}, opts); 2659 } 2660 options.lng = options.lng || fixedT2.lng; 2661 options.lngs = options.lngs || fixedT2.lngs; 2662 options.ns = options.ns || fixedT2.ns; 2663 return _this5.t(key, options); 2664 }; 2665 if (typeof lng === "string") { 2666 fixedT.lng = lng; 2667 } else { 2668 fixedT.lngs = lng; 2669 } 2670 fixedT.ns = ns; 2671 return fixedT; 2672 } 2673 }, { 2674 key: "t", 2675 value: function t() { 2676 var _this$translator; 2677 return this.translator && (_this$translator = this.translator).translate.apply(_this$translator, arguments); 2678 } 2679 }, { 2680 key: "exists", 2681 value: function exists() { 2682 var _this$translator2; 2683 return this.translator && (_this$translator2 = this.translator).exists.apply(_this$translator2, arguments); 2684 } 2685 }, { 2686 key: "setDefaultNamespace", 2687 value: function setDefaultNamespace(ns) { 2688 this.options.defaultNS = ns; 2689 } 2690 }, { 2691 key: "hasLoadedNamespace", 2692 value: function hasLoadedNamespace(ns) { 2693 var _this6 = this; 2694 var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; 2695 if (!this.isInitialized) { 2696 this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages); 2697 return false; 2698 } 2699 if (!this.languages || !this.languages.length) { 2700 this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages); 2701 return false; 2702 } 2703 var lng = this.languages[0]; 2704 var fallbackLng = this.options ? this.options.fallbackLng : false; 2705 var lastLng = this.languages[this.languages.length - 1]; 2706 if (lng.toLowerCase() === "cimode") return true; 2707 var loadNotPending = function loadNotPending2(l, n) { 2708 var loadState = _this6.services.backendConnector.state["".concat(l, "|").concat(n)]; 2709 return loadState === -1 || loadState === 2; 2710 }; 2711 if (options.precheck) { 2712 var preResult = options.precheck(this, loadNotPending); 2713 if (preResult !== void 0) return preResult; 2714 } 2715 if (this.hasResourceBundle(lng, ns)) return true; 2716 if (!this.services.backendConnector.backend) return true; 2717 if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true; 2718 return false; 2719 } 2720 }, { 2721 key: "loadNamespaces", 2722 value: function loadNamespaces(ns, callback) { 2723 var _this7 = this; 2724 var deferred = defer(); 2725 if (!this.options.ns) { 2726 callback && callback(); 2727 return Promise.resolve(); 2728 } 2729 if (typeof ns === "string") ns = [ns]; 2730 ns.forEach(function(n) { 2731 if (_this7.options.ns.indexOf(n) < 0) _this7.options.ns.push(n); 2732 }); 2733 this.loadResources(function(err) { 2734 deferred.resolve(); 2735 if (callback) callback(err); 2736 }); 2737 return deferred; 2738 } 2739 }, { 2740 key: "loadLanguages", 2741 value: function loadLanguages(lngs, callback) { 2742 var deferred = defer(); 2743 if (typeof lngs === "string") lngs = [lngs]; 2744 var preloaded = this.options.preload || []; 2745 var newLngs = lngs.filter(function(lng) { 2746 return preloaded.indexOf(lng) < 0; 2747 }); 2748 if (!newLngs.length) { 2749 if (callback) callback(); 2750 return Promise.resolve(); 2751 } 2752 this.options.preload = preloaded.concat(newLngs); 2753 this.loadResources(function(err) { 2754 deferred.resolve(); 2755 if (callback) callback(err); 2756 }); 2757 return deferred; 2758 } 2759 }, { 2760 key: "dir", 2761 value: function dir(lng) { 2762 if (!lng) lng = this.languages && this.languages.length > 0 ? this.languages[0] : this.language; 2763 if (!lng) return "rtl"; 2764 var rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam"]; 2765 return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) >= 0 ? "rtl" : "ltr"; 2766 } 2767 }, { 2768 key: "createInstance", 2769 value: function createInstance() { 2770 var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; 2771 var callback = arguments.length > 1 ? arguments[1] : void 0; 2772 return new I18n2(options, callback); 2773 } 2774 }, { 2775 key: "cloneInstance", 2776 value: function cloneInstance() { 2777 var _this8 = this; 2778 var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; 2779 var callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop; 2780 var mergedOptions = _objectSpread({}, this.options, options, { 2781 isClone: true 2782 }); 2783 var clone = new I18n2(mergedOptions); 2784 var membersToCopy = ["store", "services", "language"]; 2785 membersToCopy.forEach(function(m) { 2786 clone[m] = _this8[m]; 2787 }); 2788 clone.services = _objectSpread({}, this.services); 2789 clone.services.utils = { 2790 hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) 2791 }; 2792 clone.translator = new Translator(clone.services, clone.options); 2793 clone.translator.on("*", function(event) { 2794 for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { 2795 args[_key4 - 1] = arguments[_key4]; 2796 } 2797 clone.emit.apply(clone, [event].concat(args)); 2798 }); 2799 clone.init(mergedOptions, callback); 2800 clone.translator.options = clone.options; 2801 clone.translator.backendConnector.services.utils = { 2802 hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) 2803 }; 2804 return clone; 2805 } 2806 }]); 2807 return I18n2; 2808 }(EventEmitter); 2809 i18next = new I18n(); 2810 i18next_default = i18next; 2811 } 2812}); 2813
2814// projects/lib/packages/yggdrasil-blueprints/src/Elements/Cart/index.ts 2815function hasPendingOperations() { 2816 return syncingCart.get() || unsynchronizedEvents.length > 0; 2817} 2818function closeCart() { 2819 const cartElement = document.querySelector('[data-page-element="CartReviewModal"]'); 2820 const cartElementModal = cartElement.cf2_instance.getComponent("ModalSidebar/V1"); 2821 cartElementModal.hide(); 2822} 2823function openCart() { 2824 const cartElement = document.querySelector('[data-page-element="CartReviewModal"]'); 2825 const cartElementModal = cartElement.cf2_instance.getComponent("ModalSidebar/V1"); 2826 cartElementModal.show(); 2827} 2828async function syncCartWithServer() { 2829 let response; 2830 if (syncingCart.get()) { 2831 return syncCartWithServerThrottled(); 2832 } 2833 syncingCart.set(true); 2834 const operations = unsynchronizedEvents; 2835 unsynchronizedEvents = []; 2836 const max_retries = 3; 2837 for (let i = 0; i < max_retries; i++) { 2838 try { 2839 const loaded_product_ids = Object.keys(globalThis.globalResourceData?.productsById ?? {}).map(Number); 2840 response = await fetch("/user_pages/api/v1/carts/operations", { 2841 method: "POST", 2842 credentials: "include", 2843 headers: { "Content-Type": "application/json" }, 2844 body: JSON.stringify({ operations, loaded_product_ids }) 2845 }); 2846 if (response.ok) break; 2847 } catch (error2) { 2848 console.warn("[Cart] Error syncing cart with server", error2); 2849 } 2850 const status = response?.status ?? 0; 2851 if (status === 409) { 2852 const retryAfter = Number(response.headers.get("Retry-After") ?? 1e3); 2853 await sleepMs(retryAfter); 2854 } else if (status >= 400 && status < 500) { 2855 break; 2856 } else { 2857 await sleepMs(1e3 * (i + 1)); 2858 } 2859 console.log(`[Cart] ${response?.status ?? 0} - Retrying sync operations`); 2860 } 2861 if (!response || !response.ok) { 2862 console.warn("[Cart] Error syncing cart with server", response); 2863 if (lastCartBeforeSync) { 2864 globalThis.globalResourceData.cart = { ...lastCartBeforeSync }; 2865 Cart.stores.cartData.set(lastCartBeforeSync); 2866 } 2867 lastCartBeforeSync = null; 2868 const flashErrorElement = document.createElement("div"); 2869 flashErrorElement.className = "alert alert-error"; 2870 flashErrorElement.innerText = "We were unable to update your cart."; 2871 document.body.append(flashErrorElement); 2872 flashErrorElement.onanimationend = () => { 2873 document.body.removeChild(flashErrorElement); 2874 }; 2875 } else { 2876 let newCartData; 2877 try { 2878 newCartData = await response.json(); 2879 } catch (e) { 2880 console.error("[Cart] Error parsing response as json", e, response); 2881 } 2882 if (unsynchronizedEvents.length == 0) { 2883 globalThis.registerProductsIndexes(newCartData?.products_diff ?? []); 2884 globalThis.globalResourceData.cart = { ...newCartData }; 2885 Cart.stores.cartData.set({ ...newCartData }); 2886 } 2887 } 2888 syncingCart.set(false); 2889} 2890var unsynchronizedEvents, syncingCart, lastCartBeforeSync, syncCartWithServerThrottled, _Cart, Cart; 2891var init_Cart = __esm({ 2892 "projects/lib/packages/yggdrasil-blueprints/src/Elements/Cart/index.ts"() { 2893 init_define_process(); 2894 init_cfLodash(); 2895 init_nanostores(); 2896 init_general(); 2897 init_cf_utils(); 2898 init_i18next(); 2899 unsynchronizedEvents = []; 2900 syncingCart = atom(false); 2901 lastCartBeforeSync = null; 2902 window.addEventListener("beforeunload", async (evt) => { 2903 if (hasPendingOperations()) { 2904 const ok = confirm(); 2905 if (!ok) { 2906 evt.preventDefault(); 2907 } 2908 } 2909 }); 2910 syncCartWithServerThrottled = throttle(syncCartWithServer, 500, { leading: false }); 2911 _Cart = class _Cart { 2912 static initialize() { 2913 const initialCart = this.getInitialCartData(); 2914 this.stores.cartData = atom(initialCart); 2915 this.subscribers = []; 2916 this.operations = []; 2917 this.scheduledUpdate = false; 2918 } 2919 static listenToEvents(eventHandler) { 2920 this.subscribers.push(eventHandler); 2921 } 2922 static getInitialCartData() { 2923 return globalThis.globalResourceData.cart ?? { items: [], summary: { display_sub_total: "", total_quantity: 0 } }; 2924 } 2925 static lineItemUniqueId(item) { 2926 return `${item.product_id}-${item.variant_id}-${item.price_id}`; 2927 } 2928 static findItemByUniqueId(uniqueId) { 2929 return this.stores.cartData.get().items.find((item) => this.lineItemUniqueId(item) === uniqueId); 2930 } 2931 static findItemByProductId(productId) { 2932 return this.stores.cartData.get().items.find((item) => item.product_id == productId); 2933 } 2934 static isItemRecurring(item) { 2935 return globalThis.globalResourceData.pricesById[item.price_id].is_recurring; 2936 } 2937 static compareItems(item1, item2) { 2938 return item1.price_id == item2.price_id && item1.product_id == item2.product_id && item1.variant_id == item2.variant_id; 2939 } 2940 static removeItem(cartData, eventItem, updatePerformed) { 2941 const cartItems = cartData.items; 2942 const index = cartItems.findIndex((item) => this.compareItems(item, eventItem)); 2943 if (index > -1) { 2944 updatePerformed = true; 2945 cartData.items.splice(index, 1); 2946 } 2947 return updatePerformed; 2948 } 2949 static queueOperation(operation) { 2950 this.operations.push(operation); 2951 if (this.scheduledUpdate) return; 2952 this.scheduledUpdate = true; 2953 queueMicrotask(() => { 2954 this.dispatchEvents(); 2955 this.scheduledUpdate = false;
2956 }); 2957 } 2958 static setOperation(items) { 2959 items = Array.isArray(items) ? items : [items]; 2960 const operation = { 2961 type: "set", 2962 items 2963 }; 2964 this.queueOperation(operation); 2965 return operation; 2966 } 2967 static upsertOperation(item, quantity = 1) { 2968 if (quantity == 0) { 2969 if (!window.confirm(i18next_default.t("Cart.AreYouSure"))) return; 2970 } 2971 const operation = { 2972 type: "upsert", 2973 item, 2974 quantity 2975 }; 2976 this.queueOperation(operation); 2977 return operation; 2978 } 2979 static incrementOperation(item) { 2980 const operation = { 2981 type: "increment", 2982 item 2983 }; 2984 this.queueOperation(operation); 2985 return operation; 2986 } 2987 static decrementOperation(item) { 2988 const cartItems = this.stores.cartData.get().items; 2989 const cartItem = cartItems.find((i) => this.compareItems(i, item)); 2990 if (cartItem.quantity == 1) { 2991 if (!window.confirm(i18next_default.t("Cart.AreYouSure"))) { 2992 return; 2993 } 2994 } 2995 const operation = { 2996 type: "decrement", 2997 item 2998 }; 2999 this.queueOperation(operation); 3000 return operation; 3001 } 3002 static removeOperation(item, skipConfirmation = false) { 3003 if (!skipConfirmation && !window.confirm(i18next_default.t("Cart.AreYouSure"))) { 3004 return; 3005 } 3006 const operation = { 3007 type: "remove", 3008 item 3009 }; 3010 this.queueOperation(operation); 3011 return operation; 3012 } 3013 static replaceOperation(item, newItem) { 3014 const operation = { 3015 type: "replace", 3016 item, 3017 newItem 3018 }; 3019 this.queueOperation(operation); 3020 return operation; 3021 } 3022 static changeOrderIdOperation(orderId) { 3023 const operation = { 3024 type: "changeOrderId", 3025 orderId 3026 }; 3027 this.queueOperation(operation); 3028 return operation; 3029 } 3030 static dispatchEvents() { 3031 const cartData = this.stores.cartData.get(); 3032 if (!lastCartBeforeSync) { 3033 lastCartBeforeSync = structuredClone(cartData); 3034 } 3035 let updatePerformed = false; 3036 this.operations.forEach((event) => { 3037 switch (event.type) { 3038 case "changeOrderId": { 3039 if (cartData.order_id != event.orderId) { 3040 updatePerformed = true; 3041 cartData.order_id = event.orderId; 3042 } 3043 break; 3044 } 3045 case "set": { 3046 updatePerformed = true; 3047 cartData.items = event.items; 3048 break; 3049 } 3050 case "increment": { 3051 const cartItems = cartData.items; 3052 const index = cartItems.findIndex((item2) => this.compareItems(item2, event.item)); 3053 const { item } = event; 3054 if (index == -1) { 3055 updatePerformed = true; 3056 cartItems.push({ 3057 ...item, 3058 quantity: 1 3059 }); 3060 } else { 3061 updatePerformed = true; 3062 cartItems[index].quantity += 1; 3063 } 3064 break; 3065 } 3066 case "decrement": { 3067 const cartItems = cartData.items; 3068 const index = cartItems.findIndex((item) => this.compareItems(item, event.item)); 3069 if (cartItems[index].quantity == 1) { 3070 updatePerformed = this.removeItem(cartData, event.item, updatePerformed); 3071 } else { 3072 if (index != -1) { 3073 updatePerformed = true; 3074 cartItems[index].quantity -= 1; 3075 if (cartItems[index].quantity <= 0) { 3076 cartData.items.splice(index, 1); 3077 } 3078 } 3079 } 3080 break; 3081 } 3082 case "upsert": { 3083 const cartItems = cartData.items; 3084 const index = cartItems.findIndex((item2) => this.compareItems(item2, event.item)); 3085 const { item, quantity } = event; 3086 if (index == -1) { 3087 updatePerformed = true; 3088 cartItems.push({ 3089 ...item, 3090 quantity 3091 }); 3092 } else if (cartItems[index].quantity != quantity) { 3093 if (quantity == 0) { 3094 updatePerformed = this.removeItem(cartData, event.item, updatePerformed); 3095 } else { 3096 updatePerformed = true; 3097 cartItems[index].quantity = quantity; 3098 } 3099 } 3100 break; 3101 } 3102 case "remove": { 3103 updatePerformed = this.removeItem(cartData, event.item, updatePerformed); 3104 break; 3105 } 3106 case "replace": { 3107 const cartItems = cartData.items; 3108 const index = cartItems.findIndex((item) => this.compareItems(item, event.item)); 3109 const newItemIndex = cartItems.findIndex((item) => this.compareItems(item, event.newItem)); 3110 if (index > -1) { 3111 const currentCartItem = cartItems[index]; 3112 updatePerformed = true; 3113 if (newItemIndex > -1 && index != newItemIndex) { 3114 const currentItemQuantity = currentCartItem.quantity; 3115 cartItems[newItemIndex].quantity += currentItemQuantity; 3116 cartItems.splice(index, 1); 3117 } else { 3118 cartItems[index] = { 3119 ...currentCartItem, 3120 ...event.newItem 3121 }; 3122 } 3123 } 3124 break; 3125 } 3126 } 3127 }); 3128 if (updatePerformed) { 3129 unsynchronizedEvents.push( 3130 ...this.operations.map((op) => { 3131 op.id = uuidv4(); 3132 return op; 3133 }) 3134 ); 3135 syncCartWithServerThrottled();
3136 this.subscribers.forEach((sub) => { 3137 sub(this.operations); 3138 }); 3139 globalThis.globalResourceData.cart = { ...cartData }; 3140 _Cart.stores.cartData.set({ ...cartData }); 3141 } 3142 this.operations = []; 3143 } 3144 }; 3145 __publicField(_Cart, "stores", {}); 3146 __publicField(_Cart, "subscribers"); 3147 __publicField(_Cart, "operations", []); 3148 __publicField(_Cart, "scheduledUpdate"); 3149 Cart = _Cart; 3150 Cart.initialize(); 3151 } 3152}); 3153 3154export { 3155 atom, 3156 onMount, 3157 computed, 3158 batched, 3159 map, 3160 nanostores_exports, 3161 init_nanostores, 3162 cleanEmptyObjectKeys, 3163 sleepMs, 3164 deepEqual, 3165 formatNumberToCurrency, 3166 numberToCurrency, 3167 isElementVisibleOnViewport, 3168 debounce, 3169 init_general, 3170 syncingCart, 3171 hasPendingOperations, 3172 closeCart, 3173 openCart, 3174 Cart, 3175 init_Cart 3176}; 3177//# sourceMappingURL=chunk-BY72GGKB.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.