@bbn/bbn 2.0.221 → 2.0.223

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/com.js CHANGED
@@ -53,7 +53,6 @@ const fetchRequest = (method, url, config = {}, aborter) => {
53
53
  const hasBody = methodsWithBody.includes(method.toUpperCase());
54
54
  if (config.data != null && hasBody) {
55
55
  // You can get fancier here (JSON, FormData, etc.)
56
- bbn.fn.log('DATA', config.data);
57
56
  if (typeof config.data === 'object' && !(config.data instanceof FormData)) {
58
57
  fetchConfig.headers.set('Content-Type', 'application/json');
59
58
  fetchConfig.body = JSON.stringify(config.data);
package/dist/db.d.ts CHANGED
@@ -16,6 +16,7 @@ type WhereObject = Record<string, unknown> | null;
16
16
  type OrderClause = unknown;
17
17
  interface IDbApi {
18
18
  lastError(): unknown;
19
+ close(): void;
19
20
  insert(table: string, data: Record<string, unknown> | Record<string, unknown>[]): Promise<number>;
20
21
  update(table: string, data: Record<string, unknown>, where: WhereObject, replace?: boolean): Promise<number>;
21
22
  delete(table: string, where: Record<string, unknown>): Promise<number>;
@@ -31,12 +32,15 @@ interface DbManager {
31
32
  _connections: Record<string, IDBDatabase>;
32
33
  _stores: Record<string, unknown>;
33
34
  ok: boolean;
34
- open(name: string): Promise<IDbApi>;
35
- add(database: string, name: string, structure: DbStructure): Promise<void>;
35
+ open(name: string, version?: number): Promise<IDbApi>;
36
+ add(database: string, name: string, structure: DbStructure): Promise<boolean>;
37
+ openRaw(name: string, version?: number): Promise<IDBDatabase>;
36
38
  remove(database: string, name: string): Promise<void>;
37
39
  updateStructure(storeName: string, structure: DbStructure, database: IDBDatabase): void;
38
- reopenWithUpgrade(name: string): Promise<IDBDatabase>;
40
+ importStructure(database: string, structure: Record<string, DbStructure>): Promise<void>;
41
+ reopenWithUpgrade(name: string): Promise<IDbApi>;
39
42
  getExistingVersion(name: string): Promise<number>;
43
+ close(database: string): void;
40
44
  }
41
45
  declare const db: DbManager;
42
46
  export default db;
package/dist/db.js CHANGED
@@ -82,12 +82,22 @@ class DbObject {
82
82
  this.lastErr = null;
83
83
  this.dbName = dbName;
84
84
  }
85
- get connection() {
86
- const conn = db._connections[this.dbName];
87
- if (!conn) {
88
- throw new Error(_('The database %s is not open', this.dbName));
89
- }
90
- return conn;
85
+ hasMissingStores(database, conn) {
86
+ const structures = db._structures[database] || {};
87
+ return Object.keys(structures).some(storeName => !conn.objectStoreNames.contains(storeName));
88
+ }
89
+ getConnection() {
90
+ return __awaiter(this, arguments, void 0, function* (database = '') {
91
+ let conn = db._connections[database || this.dbName];
92
+ if (!conn) {
93
+ const tmp = yield db.open(database || this.dbName);
94
+ if (!db._connections[database || this.dbName]) {
95
+ throw new Error(_('The database %s is not open', this.dbName));
96
+ }
97
+ conn = db._connections[database || this.dbName];
98
+ }
99
+ return conn;
100
+ });
91
101
  }
92
102
  get structure() {
93
103
  const structure = db._structures[this.dbName];
@@ -97,27 +107,43 @@ class DbObject {
97
107
  return structure;
98
108
  }
99
109
  getStore(table, mode) {
100
- const tx = this.connection.transaction([table], mode);
101
- tx.onabort = () => {
102
- this.lastErr = tx.error;
103
- log(tx.error);
104
- };
105
- tx.onerror = () => {
106
- this.lastErr = tx.error;
107
- log(tx.error);
108
- };
109
- return [tx, tx.objectStore(table)];
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const connection = yield this.getConnection();
112
+ if (!this.structure[table]) {
113
+ throw new Error(_('Table %s is not defined in database structure %s', table, this.dbName));
114
+ }
115
+ if (!connection.objectStoreNames.contains(table)) {
116
+ throw new Error(_('Table %s does not exist in database %s. Schema upgrade required.', table, this.dbName));
117
+ }
118
+ const tx = connection.transaction([table], mode);
119
+ tx.onabort = () => {
120
+ this.lastErr = tx.error;
121
+ log(tx.error);
122
+ };
123
+ tx.onerror = () => {
124
+ this.lastErr = tx.error;
125
+ log(tx.error);
126
+ };
127
+ return [tx, tx.objectStore(table)];
128
+ });
110
129
  }
111
130
  lastError() {
112
131
  return this.lastErr;
113
132
  }
133
+ close() {
134
+ const conn = db._connections[this.dbName];
135
+ if (conn) {
136
+ conn.close();
137
+ delete db._connections[this.dbName];
138
+ }
139
+ }
114
140
  insert(table, data) {
115
141
  return __awaiter(this, void 0, void 0, function* () {
116
142
  const rows = Array.isArray(data) ? data : [data];
117
143
  if (!rows.length) {
118
144
  return 0;
119
145
  }
120
- const [tx, store] = this.getStore(table, 'readwrite');
146
+ const [tx, store] = yield this.getStore(table, 'readwrite');
121
147
  let inserted = 0;
122
148
  for (const row of rows) {
123
149
  const req = store.put(row);
@@ -144,7 +170,7 @@ class DbObject {
144
170
  if (Array.isArray(primary)) {
145
171
  throw new Error(_('Composite primary keys are not supported by this update implementation'));
146
172
  }
147
- const [tx, store] = this.getStore(table, 'readwrite');
173
+ const [tx, store] = yield this.getStore(table, 'readwrite');
148
174
  let updated = 0;
149
175
  for (const row of rows) {
150
176
  const nextRow = extend({}, replace ? { [primary]: row[primary] } : row, data);
@@ -174,7 +200,7 @@ class DbObject {
174
200
  if (!(primary in where)) {
175
201
  throw new Error(_('No primary key in the filter'));
176
202
  }
177
- const [tx, store] = this.getStore(table, 'readwrite');
203
+ const [tx, store] = yield this.getStore(table, 'readwrite');
178
204
  store.delete(where[primary]);
179
205
  yield transactionDone(tx);
180
206
  return 1;
@@ -196,7 +222,7 @@ class DbObject {
196
222
  selectAll(table_1) {
197
223
  return __awaiter(this, arguments, void 0, function* (table, fields = [], where = null, order = null, start = 0, limit = null) {
198
224
  void order;
199
- const [tx, store] = this.getStore(table, 'readonly');
225
+ const [tx, store] = yield this.getStore(table, 'readonly');
200
226
  const structure = this.structure[table];
201
227
  const primary = getPrimaryKey(structure);
202
228
  const results = [];
@@ -241,7 +267,7 @@ class DbObject {
241
267
  }
242
268
  const matches = !where || !((_b = (_a = globalThis.bbn) === null || _a === void 0 ? void 0 : _a.fn) === null || _b === void 0 ? void 0 : _b.search)
243
269
  ? true
244
- : !globalThis.bbn.fn.search([cursor.value], where);
270
+ : 0 === globalThis.bbn.fn.search([cursor.value], where);
245
271
  if (matches) {
246
272
  if (i >= start) {
247
273
  const transformed = transformResult(cursor.value, fields);
@@ -277,11 +303,15 @@ class DbObject {
277
303
  }
278
304
  copyTable(target_1, table_1) {
279
305
  return __awaiter(this, arguments, void 0, function* (target, table, fields = [], where = null, order = null, start = 0, limit = null) {
280
- if (!this.connection.objectStoreNames.contains(target)) {
306
+ if (!this.structure[table]) {
307
+ throw new Error(_('Source table %s does not exist in structure', table));
308
+ }
309
+ let connection = yield this.getConnection();
310
+ if (!connection.objectStoreNames.contains(target)) {
281
311
  yield db.add(this.dbName, target, this.structure[table]);
282
- yield db.open(this.dbName);
312
+ connection = yield this.getConnection();
283
313
  }
284
- if (!this.connection.objectStoreNames.contains(target)) {
314
+ if (!connection.objectStoreNames.contains(target)) {
285
315
  throw new Error(_('The target table %s does not exist', target));
286
316
  }
287
317
  const rows = yield this.selectAll(table, fields, where, order, start, limit);
@@ -303,6 +333,13 @@ const db = {
303
333
  _connections: {},
304
334
  _stores: {},
305
335
  ok: idb !== undefined,
336
+ close(database) {
337
+ const conn = this._connections[database];
338
+ if (conn) {
339
+ conn.close();
340
+ delete this._connections[database];
341
+ }
342
+ },
306
343
  updateStructure(storeName, structure, database) {
307
344
  const primary = getPrimaryKey(structure);
308
345
  if (!database.objectStoreNames.contains(storeName)) {
@@ -316,6 +353,20 @@ const db = {
316
353
  });
317
354
  }
318
355
  },
356
+ importStructure(database, structure) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ if (!this._structures[database]) {
359
+ this._structures[database] = {};
360
+ }
361
+ for (const storeName in structure) {
362
+ if (!this._structures[database].hasOwnProperty(storeName)) {
363
+ this._structures[database][storeName] = structure[storeName];
364
+ }
365
+ }
366
+ yield this.reopenWithUpgrade(database);
367
+ this.close(database);
368
+ });
369
+ },
319
370
  getExistingVersion(name) {
320
371
  return __awaiter(this, void 0, void 0, function* () {
321
372
  const live = this._connections[name];
@@ -348,37 +399,19 @@ const db = {
348
399
  },
349
400
  reopenWithUpgrade(name) {
350
401
  return __awaiter(this, void 0, void 0, function* () {
402
+ if (!this._structures[name]) {
403
+ throw new Error(_('Impossible to find a structure for the database %s', name));
404
+ }
351
405
  const existingVersion = yield this.getExistingVersion(name);
352
406
  const nextVersion = existingVersion + 1;
407
+ log(_('Going from version %s to version %s for database %s', existingVersion, nextVersion, name));
353
408
  if (this._connections[name]) {
354
- this._connections[name].close();
355
- delete this._connections[name];
409
+ this.close(name);
356
410
  }
357
- return new Promise((resolve, reject) => {
358
- if (!idb) {
359
- reject(new Error(_('IndexedDB is not available')));
360
- return;
361
- }
362
- const req = idb.open(name, nextVersion);
363
- req.onupgradeneeded = () => {
364
- const database = req.result;
365
- const dbStructure = this._structures[name] || {};
366
- iterate(dbStructure, (structure, storeName) => {
367
- if (!database.objectStoreNames.contains(storeName)) {
368
- this.updateStructure(storeName, structure, database);
369
- }
370
- });
371
- };
372
- req.onsuccess = () => {
373
- this._connections[name] = req.result;
374
- resolve(req.result);
375
- };
376
- req.onerror = () => reject(req.error);
377
- req.onblocked = () => reject(req.error || new Error(_('IndexedDB upgrade blocked')));
378
- });
411
+ return yield this.open(name, nextVersion);
379
412
  });
380
413
  },
381
- open(database) {
414
+ open(database, version) {
382
415
  return __awaiter(this, void 0, void 0, function* () {
383
416
  if (!idb) {
384
417
  throw new Error(_('IndexedDB is not available'));
@@ -390,7 +423,7 @@ const db = {
390
423
  return new DbObject(database);
391
424
  }
392
425
  yield new Promise((resolve, reject) => {
393
- const req = idb.open(database);
426
+ const req = version ? idb.open(database, version) : idb.open(database);
394
427
  req.onupgradeneeded = () => {
395
428
  const db = req.result;
396
429
  const dbStructure = this._structures[database] || {};
@@ -405,6 +438,9 @@ const db = {
405
438
  resolve(req.result);
406
439
  };
407
440
  req.onerror = () => reject(req.error);
441
+ req.onblocked = (event) => {
442
+ reject(_('open: Upgrade blocked for database %s. Please close other connections to proceed.', database));
443
+ };
408
444
  });
409
445
  return new DbObject(database);
410
446
  });
@@ -419,42 +455,79 @@ const db = {
419
455
  this._structures[database] = {};
420
456
  }
421
457
  this._structures[database][name] = structure;
422
- // Only upgrade if the DB already exists/open and the store is missing
423
- const conn = this._connections[database];
424
- if (conn && !conn.objectStoreNames.contains(name)) {
425
- yield this.reopenWithUpgrade(database);
458
+ const hadConn = !!this._connections[database];
459
+ let conn;
460
+ if (!hadConn) {
461
+ yield this.open(database);
426
462
  }
463
+ conn = this._connections[database];
464
+ // DB exists already: open temporarily and check if store exists
465
+ const hasStore = conn.objectStoreNames.contains(name);
466
+ if (!hasStore) {
467
+ const tmp = yield this.reopenWithUpgrade(database);
468
+ if (!this._connections[database]) {
469
+ throw new Error(_('The database %s is not open after upgrade', database));
470
+ }
471
+ conn = this._connections[database];
472
+ }
473
+ if (!hadConn) {
474
+ this.close(database);
475
+ }
476
+ return true;
477
+ });
478
+ },
479
+ openRaw(name, version) {
480
+ return new Promise((resolve, reject) => {
481
+ if (!idb) {
482
+ reject(new Error(_('IndexedDB is not available')));
483
+ return;
484
+ }
485
+ const req = version ? idb.open(name, version) : idb.open(name);
486
+ req.onsuccess = () => resolve(req.result);
487
+ req.onerror = () => reject(req.error);
488
+ req.onblocked = () => reject(new Error(_('IndexedDB open blocked for database %s', name)));
427
489
  });
428
490
  },
429
491
  remove(database, name) {
430
492
  return __awaiter(this, void 0, void 0, function* () {
431
- var _a;
432
- (_a = this._structures[database]) === null || _a === void 0 ? true : delete _a[name];
433
- const conn = this._connections[database];
434
- if (!conn) {
493
+ const currentStructure = this._structures[database];
494
+ if (!(currentStructure === null || currentStructure === void 0 ? void 0 : currentStructure[name])) {
435
495
  return;
436
496
  }
437
- const nextVersion = conn.version + 1;
438
- conn.close();
439
- delete this._connections[database];
440
- yield new Promise((resolve, reject) => {
441
- if (!idb) {
442
- reject(new Error(_('IndexedDB is not available')));
497
+ const old = currentStructure[name];
498
+ delete currentStructure[name];
499
+ try {
500
+ const conn = this._connections[database];
501
+ if (!conn) {
443
502
  return;
444
503
  }
445
- const req = idb.open(database, nextVersion);
446
- req.onupgradeneeded = () => {
447
- const dbInstance = req.result;
448
- if (dbInstance.objectStoreNames.contains(name)) {
449
- dbInstance.deleteObjectStore(name);
504
+ const nextVersion = conn.version + 1;
505
+ this.close(database);
506
+ yield new Promise((resolve, reject) => {
507
+ if (!idb) {
508
+ reject(new Error(_('IndexedDB is not available')));
509
+ return;
450
510
  }
451
- };
452
- req.onsuccess = () => {
453
- this._connections[database] = req.result;
454
- resolve();
455
- };
456
- req.onerror = () => reject(req.error);
457
- });
511
+ const req = idb.open(database, nextVersion);
512
+ req.onupgradeneeded = () => {
513
+ const dbInstance = req.result;
514
+ if (dbInstance.objectStoreNames.contains(name)) {
515
+ dbInstance.deleteObjectStore(name);
516
+ dbInstance.close();
517
+ }
518
+ };
519
+ req.onsuccess = () => {
520
+ req.result.close();
521
+ resolve();
522
+ };
523
+ req.onerror = () => reject(req.error);
524
+ req.onblocked = () => reject(new Error(_('Remove blocked for database %s', database)));
525
+ });
526
+ }
527
+ catch (e) {
528
+ currentStructure[name] = old;
529
+ throw e;
530
+ }
458
531
  });
459
532
  }
460
533
  };
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtDate extends bbnDt<Temporal.PlainDate> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtDate extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtDateTime extends bbnDt<Temporal.PlainDateTime> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtDateTime extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import { bbnDtTemporal } from '../vars/types.js';
3
3
  import bbnDtDuration from './duration.js';
4
4
  export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _bbnDt_value;
13
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
13
+ import { Temporal } from 'temporal-polyfill';
14
14
  import { unitsCorrespondence, units, formatsMap } from '../vars/units.js';
15
15
  import _ from '../../_.js';
16
16
  import substr from '../../fn/string/substr.js';
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  export default class bbnDtDuration {
3
3
  #private;
4
4
  static fromUnit(value: number, unit: string): bbnDtDuration;
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _bbnDtDuration_instances, _bbnDtDuration_value, _bbnDtDuration_unit, _bbnDtDuration_getUnitValue;
13
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
13
+ import { Temporal } from 'temporal-polyfill';
14
14
  import { units, unitsCorrespondence } from '../vars/units.js';
15
15
  import getRow from '../../fn/object/getRow.js';
16
16
  const DURATION_RELATIVE_TO = Temporal.ZonedDateTime.from('1970-01-01T00:00Z[UTC]');
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtMonthDay extends bbnDt<Temporal.PlainMonthDay> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtMonthDay extends bbnDt {
4
4
  constructor(m, d) {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtTime extends bbnDt<Temporal.PlainTime> {
4
4
  readonly kind: 'time';
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtTime extends bbnDt {
4
4
  constructor(h, i, s, ms) {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtYearMonth extends bbnDt<Temporal.PlainYearMonth> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  import getRow from '../../fn/object/getRow.js';
4
4
  export default class bbnDtYearMonth extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
3
  export default class bbnDtZoned extends bbnDt<Temporal.ZonedDateTime> {
4
4
  readonly kind: bbnDtKind;
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import fromJsDate from '../functions/fromJsDate.js';
3
3
  import bbnDt from './dt.js';
4
4
  export default class bbnDtZoned extends bbnDt {
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  /**
3
3
  * Convert a JS Date into:
4
4
  * - Temporal.Instant (if hasZone=true)
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  /**
3
3
  * Convert a JS Date into:
4
4
  * - Temporal.Instant (if hasZone=true)
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import buildLocaleFromIntl from './buildLocaleFromIntl.js';
3
3
  import bbnDtZoned from '../classes/zoned.js';
4
4
  import bbnDtDateTime from '../classes/dateTime.js';
@@ -1,2 +1,2 @@
1
- import { Temporal } from '../../../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  export type bbnDtTemporal = Temporal.PlainDateTime | Temporal.PlainDate | Temporal.PlainTime | Temporal.PlainYearMonth | Temporal.PlainMonthDay | Temporal.ZonedDateTime;
package/dist/dt.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDtDateTime from './dt/classes/dateTime.js';
3
3
  import bbnDtDate from './dt/classes/date.js';
4
4
  import bbnDtTime from './dt/classes/zoned.js';
package/dist/fn/init.js CHANGED
@@ -81,7 +81,7 @@ export default function init(cfg, force) {
81
81
  if (bbn.var.colors) {
82
82
  addColors(bbn.var.colors);
83
83
  }
84
- globalThis.document.addEventListener("visibilitychange", () => {
84
+ document.addEventListener("visibilitychange", () => {
85
85
  if (document.hidden) {
86
86
  bbn.env.isVisible = false;
87
87
  }
@@ -89,7 +89,7 @@ export default function init(cfg, force) {
89
89
  bbn.env.isVisible = true;
90
90
  }
91
91
  });
92
- globalThis.document.addEventListener("focus", (e) => {
92
+ document.addEventListener("focus", (e) => {
93
93
  if (e.target instanceof HTMLElement &&
94
94
  !e.target.classList.contains("bbn-no")) {
95
95
  bbn.env.focused = e.target;
@@ -97,7 +97,7 @@ export default function init(cfg, force) {
97
97
  bbn.env.isFocused = true;
98
98
  bbn.env.last_focus = timestamp();
99
99
  });
100
- globalThis.document.addEventListener("blur", (e) => {
100
+ document.addEventListener("blur", (e) => {
101
101
  if (e.target instanceof HTMLElement &&
102
102
  !e.target.classList.contains("bbn-no")) {
103
103
  bbn.env.focused = e.target;
@@ -105,29 +105,29 @@ export default function init(cfg, force) {
105
105
  bbn.env.isFocused = false;
106
106
  bbn.env.last_focus = timestamp();
107
107
  });
108
- globalThis.document.addEventListener("click", onActivity);
109
- globalThis.document.addEventListener("keydown", onActivity);
110
- globalThis.document.addEventListener("focusin", onFocus);
111
- globalThis.document.addEventListener("focusout", onFocus);
112
- globalThis.addEventListener("hashchange", () => {
108
+ document.addEventListener("click", onActivity);
109
+ document.addEventListener("keydown", onActivity);
110
+ document.addEventListener("focusin", onFocus);
111
+ document.addEventListener("focusout", onFocus);
112
+ window.addEventListener("hashchange", () => {
113
113
  bbn.env.hashChanged = new Date().getTime();
114
114
  }, false);
115
- globalThis.addEventListener("resize", () => {
115
+ window.addEventListener("resize", () => {
116
116
  resize();
117
117
  });
118
- globalThis.addEventListener("orientationchange", () => {
118
+ window.addEventListener("orientationchange", () => {
119
119
  resize();
120
120
  });
121
121
  resize();
122
122
  if (isMobile()) {
123
- globalThis.document.body.classList.add("bbn-mobile");
123
+ document.body.classList.add("bbn-mobile");
124
124
  if (isTabletDevice()) {
125
- globalThis.document.body.classList.add("bbn-tablet");
125
+ document.body.classList.add("bbn-tablet");
126
126
  }
127
127
  }
128
- if (globalThis.history) {
129
- globalThis.onpopstate = function (e) {
130
- let h = globalThis.history;
128
+ if (window.history) {
129
+ window.onpopstate = function (e) {
130
+ let h = window.history;
131
131
  if (!bbn.env.historyDisabled && h) {
132
132
  //e.preventDefault();
133
133
  if (bbn.fn.defaultHistoryFunction(h.state)) {
@@ -143,17 +143,17 @@ export default function init(cfg, force) {
143
143
  }
144
144
  };
145
145
  }
146
- globalThis.addEventListener('online', () => {
146
+ window.addEventListener('online', () => {
147
147
  bbn.env.online = true;
148
148
  });
149
- globalThis.addEventListener('offline', () => {
149
+ window.addEventListener('offline', () => {
150
150
  bbn.env.online = false;
151
151
  });
152
152
  bbn.env.isInit = true;
153
- globalThis.document.dispatchEvent(new Event("bbninit"));
154
- if (bbn.env.logging) {
155
- log("Logging in bbn is enabled");
156
- }
153
+ document.dispatchEvent(new Event("bbninit"));
154
+ }
155
+ if (bbn.env.logging) {
156
+ log("Logging in bbn is enabled");
157
157
  }
158
158
  }
159
159
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { Temporal } from '../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  declare const bbn: Bbn;
3
3
  export { bbn as default, bbn, Temporal };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Temporal } from '../node_modules/temporal-polyfill/index.js';
1
+ import { Temporal } from 'temporal-polyfill';
2
2
  import _ from './_.js';
3
3
  import $ from './$.js';
4
4
  import lng from './lng.js';