@bbn/bbn 2.0.218 → 2.0.221

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
@@ -213,7 +213,7 @@ onProgress, onChunkProgress, headers = {}, uploadId }) => {
213
213
  const totalSize = file.size;
214
214
  const totalChunks = Math.ceil(totalSize / chunkSize);
215
215
  const finalUploadId = uploadId ||
216
- (window.crypto && crypto.randomUUID
216
+ (globalThis.crypto && crypto.randomUUID
217
217
  ? crypto.randomUUID()
218
218
  : Date.now().toString(36) + Math.random().toString(36).slice(2));
219
219
  let uploadedBytes = 0;
package/dist/db.js CHANGED
@@ -13,11 +13,11 @@ import log from './fn/browser/log.js';
13
13
  import isObject from './fn/type/isObject.js';
14
14
  import isArray from './fn/type/isArray.js';
15
15
  import extend from './fn/object/extend.js';
16
- const idb = window.indexedDB ||
17
- window.webkitIndexedDB ||
18
- window.mozIndexedDB ||
19
- window.OIndexedDB ||
20
- window.msIndexedDB;
16
+ const idb = globalThis.indexedDB ||
17
+ globalThis.webkitIndexedDB ||
18
+ globalThis.mozIndexedDB ||
19
+ globalThis.OIndexedDB ||
20
+ globalThis.msIndexedDB;
21
21
  const transformResult = (obj, fields) => {
22
22
  if (!obj) {
23
23
  return undefined;
@@ -239,9 +239,9 @@ class DbObject {
239
239
  resolve();
240
240
  return;
241
241
  }
242
- const matches = !where || !((_b = (_a = window.bbn) === null || _a === void 0 ? void 0 : _a.fn) === null || _b === void 0 ? void 0 : _b.search)
242
+ const matches = !where || !((_b = (_a = globalThis.bbn) === null || _a === void 0 ? void 0 : _a.fn) === null || _b === void 0 ? void 0 : _b.search)
243
243
  ? true
244
- : !window.bbn.fn.search([cursor.value], where);
244
+ : !globalThis.bbn.fn.search([cursor.value], where);
245
245
  if (matches) {
246
246
  if (i >= start) {
247
247
  const transformed = transformResult(cursor.value, fields);
@@ -378,35 +378,35 @@ const db = {
378
378
  });
379
379
  });
380
380
  },
381
- open(name) {
381
+ open(database) {
382
382
  return __awaiter(this, void 0, void 0, function* () {
383
383
  if (!idb) {
384
384
  throw new Error(_('IndexedDB is not available'));
385
385
  }
386
- if (!this._structures[name]) {
387
- throw new Error(_('Impossible to find a structure for the database %s', name));
386
+ if (!this._structures[database]) {
387
+ throw new Error(_('Impossible to find a structure for the database %s', database));
388
388
  }
389
- if (this._connections[name]) {
390
- return new DbObject(name);
389
+ if (this._connections[database]) {
390
+ return new DbObject(database);
391
391
  }
392
392
  yield new Promise((resolve, reject) => {
393
- const req = idb.open(name);
393
+ const req = idb.open(database);
394
394
  req.onupgradeneeded = () => {
395
- const database = req.result;
396
- const dbStructure = this._structures[name] || {};
395
+ const db = req.result;
396
+ const dbStructure = this._structures[database] || {};
397
397
  iterate(dbStructure, (structure, storeName) => {
398
- if (!database.objectStoreNames.contains(storeName)) {
399
- this.updateStructure(storeName, structure, database);
398
+ if (!db.objectStoreNames.contains(storeName)) {
399
+ this.updateStructure(storeName, structure, db);
400
400
  }
401
401
  });
402
402
  };
403
403
  req.onsuccess = () => {
404
- this._connections[name] = req.result;
404
+ this._connections[database] = req.result;
405
405
  resolve(req.result);
406
406
  };
407
407
  req.onerror = () => reject(req.error);
408
408
  });
409
- return new DbObject(name);
409
+ return new DbObject(database);
410
410
  });
411
411
  },
412
412
  add(database, name, structure) {
@@ -30,7 +30,7 @@ function parseLocaleTag(tag) {
30
30
  }
31
31
  return { language, script, region };
32
32
  }
33
- const REGION_WEEK_INFO = import('../data/weekinfo-overrides.js');
33
+ const REGION_WEEK_INFO = globalThis.document ? import('../data/weekinfo-overrides.js') : {};
34
34
  function computeWeekInfo(localeInstance) {
35
35
  var _a, _b, _c;
36
36
  const tag = (_c = (_a = localeInstance.baseName) !== null && _a !== void 0 ? _a : (_b = localeInstance.toString) === null || _b === void 0 ? void 0 : _b.call(localeInstance)) !== null && _c !== void 0 ? _c : 'und';
package/dist/env.js CHANGED
@@ -1,13 +1,14 @@
1
+ var _a, _b, _c, _d, _e, _f;
1
2
  export default {
2
- siteTitle: window.document.title,
3
+ siteTitle: (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.title,
3
4
  /* This variable should be set to true in debugging mode only */
4
5
  logging: false,
5
6
  /* Address of the CDN (where this file should be hosted) */
6
7
  cdn: '',
7
8
  /* Default language */
8
9
  lang: 'en',
9
- host: window.location.protocol + '//' + window.location.hostname,
10
- url: window.location.href,
10
+ host: ((_b = globalThis.location) === null || _b === void 0 ? void 0 : _b.protocol) + '//' + ((_c = globalThis.location) === null || _c === void 0 ? void 0 : _c.hostname),
11
+ url: (_d = globalThis.location) === null || _d === void 0 ? void 0 : _d.href,
11
12
  old_path: null,
12
13
  /* True when non asynchronous Ajax loads */
13
14
  loading: false,
@@ -15,15 +16,15 @@ export default {
15
16
  get isEnumerating() {
16
17
  return this._enumerated.length > 0;
17
18
  },
18
- /* Window width */
19
+ /* globalThis width */
19
20
  width: 0,
20
- /* Window height */
21
+ /* globalThis height */
21
22
  height: 0,
22
23
  /* Element currently focused (Element object) */
23
24
  focused: false,
24
25
  /* Last time user has been active */
25
26
  last_focus: (new Date()).getTime(),
26
- /* Sleep mode (tab or window unfocused */
27
+ /* Sleep mode (tab or globalThis unfocused */
27
28
  sleep: false,
28
29
  theme: 'dark',
29
30
  /**
@@ -39,11 +40,11 @@ export default {
39
40
  params: [],
40
41
  isInit: false,
41
42
  isFocused: false,
42
- isVisible: !document.hidden,
43
+ isVisible: !((_e = globalThis.document) === null || _e === void 0 ? void 0 : _e.hidden),
43
44
  timeoff: Math.round((new Date()).getTime() / 1000),
44
45
  loggingLevel: 5,
45
46
  ignoreUnload: false,
46
47
  historyDisabled: false,
47
48
  nav: 'ajax',
48
- online: window.navigator.onLine
49
+ online: (_f = globalThis.navigator) === null || _f === void 0 ? void 0 : _f.onLine
49
50
  };
@@ -11,4 +11,4 @@
11
11
  * @param {...any} args
12
12
  * @returns
13
13
  */
14
- export default function log(...args: any[]): any;
14
+ export default function log(...args: any[]): void;
@@ -14,12 +14,12 @@ import isFunction from '../type/isFunction.js';
14
14
  */
15
15
  export default function log(...args) {
16
16
  var _a, _b, _c, _d;
17
- if (((_b = (_a = window['bbn']) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.logging) && ((window === null || window === void 0 ? void 0 : window.console) !== undefined)) {
17
+ if (((_b = (_a = globalThis.bbn) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.logging) && (globalThis.console !== undefined)) {
18
18
  let cfg;
19
19
  let level = 5;
20
20
  let fn = 'log';
21
21
  if (args[0] && typeof args[0] === 'object' && args[0]._bbn_console_style) {
22
- if (args[0]._bbn_console_mode && isFunction(console[args[0]._bbn_console_mode])) {
22
+ if (args[0]._bbn_console_mode && isFunction(globalThis.console[args[0]._bbn_console_mode])) {
23
23
  fn = args[0]._bbn_console_mode;
24
24
  }
25
25
  else {
@@ -28,8 +28,8 @@ export default function log(...args) {
28
28
  }
29
29
  args.shift();
30
30
  }
31
- const exec = window.console[fn];
32
- if (((_d = (_c = window['bbn']) === null || _c === void 0 ? void 0 : _c.env) === null || _d === void 0 ? void 0 : _d.loggingLevel) >= level) {
31
+ const exec = globalThis.console[fn];
32
+ if (((_d = (_c = globalThis.bbn) === null || _c === void 0 ? void 0 : _c.env) === null || _d === void 0 ? void 0 : _d.loggingLevel) >= level) {
33
33
  let i = 0;
34
34
  while (i < args.length) {
35
35
  let t = typeof args[i];
@@ -37,11 +37,10 @@ export default function log(...args) {
37
37
  if (t === 'string' || t === 'number') {
38
38
  consoleArguments.unshift('%c %s ', cfg);
39
39
  }
40
- exec.apply(window.console, consoleArguments);
40
+ exec.apply(globalThis.console, consoleArguments);
41
41
  i++;
42
42
  }
43
43
  }
44
44
  }
45
- return this;
46
45
  }
47
46
  ;
package/dist/fn/init.js CHANGED
@@ -56,10 +56,10 @@ const onActivity = (e) => {
56
56
  * @returns
57
57
  */
58
58
  export default function init(cfg, force) {
59
+ var _a, _b;
59
60
  let parts;
60
61
  if (!bbn.env.isInit) {
61
- bbn.env.root =
62
- document.baseURI.length > 0 ? document.baseURI : bbn.env.host;
62
+ bbn.env.root = ((_b = (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.baseURI) === null || _b === void 0 ? void 0 : _b.length) ? globalThis.document.baseURI : bbn.env.host;
63
63
  if (bbn.env.root.length && substr(bbn.env.root, -1) !== "/") {
64
64
  bbn.env.root += "/";
65
65
  }
@@ -70,88 +70,90 @@ export default function init(cfg, force) {
70
70
  bbn.env.path = substr(bbn.env.url, bbn.env.root.length);
71
71
  parts = bbn.env.path.split("/");
72
72
  //$.each(parts, function(i, v){
73
- each(parts, (v, i) => {
73
+ each(parts, (v) => {
74
74
  v = decodeURI(v.trim());
75
75
  if (v !== "") {
76
76
  bbn.env.params.push(v);
77
77
  }
78
78
  });
79
- if (bbn.var.colors) {
80
- addColors(bbn.var.colors);
81
- }
82
79
  setupIntl();
83
- document.addEventListener("visibilitychange", () => {
84
- if (document.hidden) {
85
- bbn.env.isVisible = false;
86
- }
87
- else {
88
- bbn.env.isVisible = true;
89
- }
90
- });
91
- document.addEventListener("focus", (e) => {
92
- if (e.target instanceof HTMLElement &&
93
- !e.target.classList.contains("bbn-no")) {
94
- bbn.env.focused = e.target;
95
- }
96
- bbn.env.isFocused = true;
97
- bbn.env.last_focus = timestamp();
98
- });
99
- document.addEventListener("blur", (e) => {
100
- if (e.target instanceof HTMLElement &&
101
- !e.target.classList.contains("bbn-no")) {
102
- bbn.env.focused = e.target;
80
+ if (globalThis.document) {
81
+ if (bbn.var.colors) {
82
+ addColors(bbn.var.colors);
103
83
  }
104
- bbn.env.isFocused = false;
105
- bbn.env.last_focus = timestamp();
106
- });
107
- document.addEventListener("click", onActivity);
108
- document.addEventListener("keydown", onActivity);
109
- document.addEventListener("focusin", onFocus);
110
- document.addEventListener("focusout", onFocus);
111
- window.addEventListener("hashchange", () => {
112
- bbn.env.hashChanged = new Date().getTime();
113
- }, false);
114
- window.addEventListener("resize", () => {
115
- resize();
116
- });
117
- window.addEventListener("orientationchange", () => {
84
+ globalThis.document.addEventListener("visibilitychange", () => {
85
+ if (document.hidden) {
86
+ bbn.env.isVisible = false;
87
+ }
88
+ else {
89
+ bbn.env.isVisible = true;
90
+ }
91
+ });
92
+ globalThis.document.addEventListener("focus", (e) => {
93
+ if (e.target instanceof HTMLElement &&
94
+ !e.target.classList.contains("bbn-no")) {
95
+ bbn.env.focused = e.target;
96
+ }
97
+ bbn.env.isFocused = true;
98
+ bbn.env.last_focus = timestamp();
99
+ });
100
+ globalThis.document.addEventListener("blur", (e) => {
101
+ if (e.target instanceof HTMLElement &&
102
+ !e.target.classList.contains("bbn-no")) {
103
+ bbn.env.focused = e.target;
104
+ }
105
+ bbn.env.isFocused = false;
106
+ bbn.env.last_focus = timestamp();
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", () => {
113
+ bbn.env.hashChanged = new Date().getTime();
114
+ }, false);
115
+ globalThis.addEventListener("resize", () => {
116
+ resize();
117
+ });
118
+ globalThis.addEventListener("orientationchange", () => {
119
+ resize();
120
+ });
118
121
  resize();
119
- });
120
- resize();
121
- if (isMobile()) {
122
- document.body.classList.add("bbn-mobile");
123
- if (isTabletDevice()) {
124
- document.body.classList.add("bbn-tablet");
122
+ if (isMobile()) {
123
+ globalThis.document.body.classList.add("bbn-mobile");
124
+ if (isTabletDevice()) {
125
+ globalThis.document.body.classList.add("bbn-tablet");
126
+ }
125
127
  }
126
- }
127
- if (window.history) {
128
- window.onpopstate = function (e) {
129
- let h = window.history;
130
- if (!bbn.env.historyDisabled && h) {
131
- //e.preventDefault();
132
- if (bbn.fn.defaultHistoryFunction(h.state)) {
133
- let state = h.state;
134
- if (state) {
135
- //link(substr(state.url, bbn.env.root.length), $.extend({title: state.title}, state.data));
136
- link(state.url, extend({ title: state.title || bbn.env.siteTitle }, state.data || {}));
137
- }
138
- else if (state && state.data && isFunction(state.data.script)) {
139
- state.data.script();
128
+ if (globalThis.history) {
129
+ globalThis.onpopstate = function (e) {
130
+ let h = globalThis.history;
131
+ if (!bbn.env.historyDisabled && h) {
132
+ //e.preventDefault();
133
+ if (bbn.fn.defaultHistoryFunction(h.state)) {
134
+ let state = h.state;
135
+ if (state) {
136
+ //link(substr(state.url, bbn.env.root.length), $.extend({title: state.title}, state.data));
137
+ link(state.url, extend({ title: state.title || bbn.env.siteTitle }, state.data || {}));
138
+ }
139
+ else if (state && state.data && isFunction(state.data.script)) {
140
+ state.data.script();
141
+ }
140
142
  }
141
143
  }
142
- }
143
- };
144
- }
145
- window.addEventListener('online', () => {
146
- bbn.env.online = true;
147
- });
148
- window.addEventListener('offline', () => {
149
- bbn.env.online = false;
150
- });
151
- bbn.env.isInit = true;
152
- document.dispatchEvent(new Event("bbninit"));
153
- if (bbn.env.logging) {
154
- log("Logging in bbn is enabled");
144
+ };
145
+ }
146
+ globalThis.addEventListener('online', () => {
147
+ bbn.env.online = true;
148
+ });
149
+ globalThis.addEventListener('offline', () => {
150
+ bbn.env.online = false;
151
+ });
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
+ }
155
157
  }
156
158
  }
157
159
  }
@@ -0,0 +1,2 @@
1
+ declare const bbn: Bbn;
2
+ export default bbn;
@@ -0,0 +1,94 @@
1
+ import _ from './_.js';
2
+ import $ from './$.js';
3
+ import lng from './lng.js';
4
+ import vars from './vars.js';
5
+ import env from './env.js';
6
+ import com from './com.js';
7
+ import db from './db.js';
8
+ import fn from './fn.js';
9
+ import dt from './dt.js';
10
+ const bbn = {
11
+ version: "1.0.1",
12
+ opt: {
13
+ _cat: {}
14
+ },
15
+ app: {},
16
+ _,
17
+ $,
18
+ lng,
19
+ var: vars,
20
+ dt,
21
+ com,
22
+ env,
23
+ db,
24
+ fn,
25
+ info: [
26
+ {
27
+ value: 'ajax',
28
+ label: 'Loading and streaming',
29
+ description: 'Functions related to Ajax requests',
30
+ icon: 'nf nf-fa-rocket',
31
+ }, {
32
+ value: 'browser',
33
+ label: 'Browser-only',
34
+ description: 'Functions that can only be run in the browser',
35
+ icon: 'nf nf-fa-desktop',
36
+ }, {
37
+ value: 'convert',
38
+ label: 'Conversion',
39
+ description: 'Functions related to data conversion',
40
+ icon: 'nf nf-fa-exchange',
41
+ }, {
42
+ value: 'datetime',
43
+ label: 'Date and time',
44
+ description: 'Functions related to dates and times',
45
+ icon: 'nf nf-fa-calendar',
46
+ }, {
47
+ value: 'form',
48
+ label: 'Form manipulation',
49
+ description: 'Functions related to form manipulation and validation',
50
+ icon: 'nf nf-fa-edit',
51
+ }, {
52
+ value: 'html',
53
+ label: 'HTML manipulation',
54
+ description: 'Functions related to HTML manipulation and DOM interaction',
55
+ icon: 'nf nf-fa-html5',
56
+ }, {
57
+ value: 'loop',
58
+ label: 'Looping',
59
+ description: 'Functions related to looping through arrays and objects',
60
+ icon: 'nf nf-fa-repeat',
61
+ }, {
62
+ value: 'misc',
63
+ label: 'Miscellaneous',
64
+ description: 'Miscellaneous functions that do not fit into other categories',
65
+ icon: 'nf nf-fa-cubes',
66
+ }, {
67
+ value: 'object',
68
+ label: 'Object manipulation',
69
+ description: 'Functions related to object manipulation and inspection',
70
+ icon: 'nf nf-fa-object_group',
71
+ }, {
72
+ value: 'phone',
73
+ label: 'Phone and contact',
74
+ description: 'Functions related to phone numbers and contact information',
75
+ icon: 'nf nf-fa-phone',
76
+ }, {
77
+ value: 'string',
78
+ label: 'String manipulation',
79
+ description: 'Functions related to string manipulation and formatting',
80
+ icon: 'nf nf-fa-text_height'
81
+ }, {
82
+ value: 'style',
83
+ label: 'Styling and layout',
84
+ description: 'Functions related to styling and layout management',
85
+ icon: 'nf nf-fa-paint_brush',
86
+ }, {
87
+ value: 'type',
88
+ label: 'Type checking',
89
+ description: 'Functions related to type checking and validation',
90
+ icon: 'nf nf-fa-check_square',
91
+ }
92
+ ]
93
+ };
94
+ export default bbn;
package/dist/index.js CHANGED
@@ -92,10 +92,10 @@ const bbn = {
92
92
  }
93
93
  ]
94
94
  };
95
- if ('undefined' !== typeof window) {
96
- window.bbn = bbn;
97
- if (!window.Temporal) {
98
- window.Temporal = Temporal;
95
+ if ('undefined' !== typeof globalThis) {
96
+ globalThis.bbn = bbn;
97
+ if (!globalThis.Temporal) {
98
+ globalThis.Temporal = Temporal;
99
99
  }
100
100
  }
101
101
  export { bbn as default, bbn, Temporal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.218",
3
+ "version": "2.0.221",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",