textbrowser 0.39.0 → 0.40.3

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.
@@ -0,0 +1,158 @@
1
+ /* eslint-env worker */
2
+
3
+ const {ceil} = Math;
4
+ const arrayChunk = (arr, size) => {
5
+ return [...Array.from({length: ceil(arr.length / size)})].map((_, i) => {
6
+ const offset = i * size;
7
+ return arr.slice(offset, offset + size);
8
+ });
9
+ };
10
+
11
+ // Todo: If fetching fails here (or in install), e.g., because activate event
12
+ // never completed
13
+ // to cache, de-register and re-register (?); how to detect if all
14
+ // files in cache?
15
+ // Todo: Check `oldVersion` and run this first if still too old
16
+
17
+ /**
18
+ * @callback Logger
19
+ * @param {...any} args
20
+ * @returns {void}
21
+ */
22
+
23
+ /**
24
+ * @param {PlainObject} cfg
25
+ * @param {string} cfg.namespace
26
+ * @param {string[]} cfg.files
27
+ * @param {Logger} cfg.log
28
+ * @param {string} [cfg.basePath=""]
29
+ * @returns {Promise<void>}
30
+ */
31
+ async function activateCallback ({
32
+ namespace, files, log, basePath = ''
33
+ }) {
34
+ // Now we know we have the files cached, we can postpone
35
+ // the `indexedDB` processing (which will work offline
36
+ // anyways); also important to avoid conflicts with
37
+ // already-running versions upon future sw updates
38
+ log('Activate: Callback called');
39
+ const r = await fetch(files);
40
+ const {groups} = await r.json();
41
+
42
+ const addJSONFetch = (arr, path) => {
43
+ arr.push(
44
+ (async () => (await fetch(basePath + path)).json())()
45
+ );
46
+ };
47
+
48
+ const dataFileNames = [];
49
+ const dataFiles = [];
50
+ const schemaFiles = [];
51
+ const metadataFiles = [];
52
+ groups.forEach(
53
+ ({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
54
+ fileObjs.forEach(({file: {$ref: filePath}, metadataFile, schemaFile, name}) => {
55
+ // We don't i18nize the name here
56
+ dataFileNames.push(name);
57
+ addJSONFetch(dataFiles, filePath);
58
+ addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
59
+ addJSONFetch(schemaFiles, schemaBaseDirectory + '/' + schemaFile);
60
+ });
61
+ }
62
+ );
63
+ const promises = await Promise.all([
64
+ ...dataFiles, ...schemaFiles, ...metadataFiles
65
+ ]);
66
+ const chunked = arrayChunk(promises, dataFiles.length);
67
+ const [
68
+ dataFileResponses, schemaFileResponses, metadataFileResponses
69
+ ] = chunked;
70
+
71
+ log('Activate: Files fetched');
72
+ const dbName = namespace + '-textbrowser-cache-data';
73
+ indexedDB.deleteDatabase(dbName);
74
+ return new Promise((resolve, reject) => {
75
+ const req = indexedDB.open(dbName);
76
+ req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
77
+ db.onversionchange = () => {
78
+ db.close();
79
+ const err = new Error('versionchange');
80
+ err.type = 'versionchange';
81
+ reject(err);
82
+ };
83
+ dataFileResponses.forEach(({data: tableRows}, i) => {
84
+ const dataFileName = dataFileNames[i];
85
+ const store = db.createObjectStore('files-to-cache-' + dataFileName);
86
+
87
+ const schemaFileResponse = schemaFileResponses[i];
88
+ const metadataFileResponse = metadataFileResponses[i];
89
+ const fieldItems = schemaFileResponse.items.items;
90
+
91
+ let browseFields = metadataFileResponse.table.browse_fields;
92
+ browseFields = Array.isArray(browseFields) ? browseFields : [browseFields];
93
+
94
+ const columnIndexes = [];
95
+ browseFields.forEach((browseFieldSetObj) => {
96
+ if (typeof browseFieldSetObj === 'string') {
97
+ browseFieldSetObj = {set: [browseFieldSetObj]};
98
+ }
99
+ if (!browseFieldSetObj.name) {
100
+ browseFieldSetObj.name = browseFieldSetObj.set.join(',');
101
+ }
102
+ const browseFieldSetName = browseFieldSetObj.name;
103
+ const browseFieldSetIndexes = browseFieldSetObj.set.map((browseField) => {
104
+ // Need to convert to columns for numbers
105
+ // to become valid key paths
106
+ return 'c' + (
107
+ fieldItems.findIndex((item) => item.title === browseField)
108
+ );
109
+ });
110
+ columnIndexes.push(...browseFieldSetIndexes);
111
+
112
+ log(
113
+ 'Activate: Creating index:',
114
+ dataFileName,
115
+ 'browseFields-' + browseFieldSetName,
116
+ browseFieldSetIndexes
117
+ );
118
+
119
+ // No need for using `presort` as our index will sort anyways
120
+ store.createIndex(
121
+ 'browseFields-' + browseFieldSetName,
122
+ browseFieldSetIndexes
123
+ );
124
+ });
125
+
126
+ const uniqueColumnIndexes = [...new Set(columnIndexes)];
127
+
128
+ tableRows.forEach((tableRow, j) => {
129
+ // Todo: Optionally send notice when complete
130
+ // To take advantage of indexes on our arrays, we
131
+ // need to transform them to objects! See https://github.com/w3c/IndexedDB/issues/209
132
+ const objRow = {
133
+ value: tableRow
134
+ };
135
+ uniqueColumnIndexes.forEach((colIdx) => {
136
+ objRow[colIdx] = tableRow[colIdx.slice(1)];
137
+ });
138
+ // log('objRow', objRow);
139
+ store.put(objRow, j);
140
+ });
141
+ });
142
+ });
143
+ req.addEventListener('success', ({target: {result: db}}) => {
144
+ log('Activate: Database set-up complete', db);
145
+ // Todo: Replace this with `ready()` check
146
+ // in calling code?
147
+ resolve();
148
+ });
149
+ const onerr = ({error = new Error('dbError')}) => {
150
+ error.type = 'dbError';
151
+ reject(error);
152
+ };
153
+ req.addEventListener('blocked', onerr);
154
+ req.addEventListener('error', onerr);
155
+ });
156
+ }
157
+
158
+ export { activateCallback as default };
package/dist/index-es.js CHANGED
@@ -3,14 +3,9 @@ function ownKeys(object, enumerableOnly) {
3
3
 
4
4
  if (Object.getOwnPropertySymbols) {
5
5
  var symbols = Object.getOwnPropertySymbols(object);
6
-
7
- if (enumerableOnly) {
8
- symbols = symbols.filter(function (sym) {
9
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
10
- });
11
- }
12
-
13
- keys.push.apply(keys, symbols);
6
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
7
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
8
+ })), keys.push.apply(keys, symbols);
14
9
  }
15
10
 
16
11
  return keys;
@@ -18,19 +13,12 @@ function ownKeys(object, enumerableOnly) {
18
13
 
19
14
  function _objectSpread2(target) {
20
15
  for (var i = 1; i < arguments.length; i++) {
21
- var source = arguments[i] != null ? arguments[i] : {};
22
-
23
- if (i % 2) {
24
- ownKeys(Object(source), true).forEach(function (key) {
25
- _defineProperty(target, key, source[key]);
26
- });
27
- } else if (Object.getOwnPropertyDescriptors) {
28
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
29
- } else {
30
- ownKeys(Object(source)).forEach(function (key) {
31
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
32
- });
33
- }
16
+ var source = null != arguments[i] ? arguments[i] : {};
17
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
18
+ _defineProperty(target, key, source[key]);
19
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
20
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
21
+ });
34
22
  }
35
23
 
36
24
  return target;
@@ -1485,15 +1473,15 @@ var number = createCommonjsModule(function (module, exports) {
1485
1473
  result.maximumSignificantDigits = g1.length;
1486
1474
  } // @@@+ case
1487
1475
  else if (g2 === '+') {
1488
- result.minimumSignificantDigits = g1.length;
1489
- } // .### case
1490
- else if (g1[0] === '#') {
1491
- result.maximumSignificantDigits = g1.length;
1492
- } // .@@## or .@@@ case
1493
- else {
1494
- result.minimumSignificantDigits = g1.length;
1495
- result.maximumSignificantDigits = g1.length + (typeof g2 === 'string' ? g2.length : 0);
1496
- }
1476
+ result.minimumSignificantDigits = g1.length;
1477
+ } // .### case
1478
+ else if (g1[0] === '#') {
1479
+ result.maximumSignificantDigits = g1.length;
1480
+ } // .@@## or .@@@ case
1481
+ else {
1482
+ result.minimumSignificantDigits = g1.length;
1483
+ result.maximumSignificantDigits = g1.length + (typeof g2 === 'string' ? g2.length : 0);
1484
+ }
1497
1485
 
1498
1486
  return '';
1499
1487
  });
@@ -1733,15 +1721,15 @@ var number = createCommonjsModule(function (module, exports) {
1733
1721
  result.minimumFractionDigits = g1.length;
1734
1722
  } // .### case
1735
1723
  else if (g3 && g3[0] === '#') {
1736
- result.maximumFractionDigits = g3.length;
1737
- } // .00## case
1738
- else if (g4 && g5) {
1739
- result.minimumFractionDigits = g4.length;
1740
- result.maximumFractionDigits = g4.length + g5.length;
1741
- } else {
1742
- result.minimumFractionDigits = g1.length;
1743
- result.maximumFractionDigits = g1.length;
1744
- }
1724
+ result.maximumFractionDigits = g3.length;
1725
+ } // .00## case
1726
+ else if (g4 && g5) {
1727
+ result.minimumFractionDigits = g4.length;
1728
+ result.maximumFractionDigits = g4.length + g5.length;
1729
+ } else {
1730
+ result.minimumFractionDigits = g1.length;
1731
+ result.maximumFractionDigits = g1.length;
1732
+ }
1745
1733
 
1746
1734
  return '';
1747
1735
  });
@@ -1966,14 +1954,14 @@ var parser = createCommonjsModule(function (module, exports) {
1966
1954
  if (char === 123
1967
1955
  /* `{` */
1968
1956
  ) {
1969
- var result = this.parseArgument(nestingLevel, expectingCloseTag);
1957
+ var result = this.parseArgument(nestingLevel, expectingCloseTag);
1970
1958
 
1971
- if (result.err) {
1972
- return result;
1973
- }
1959
+ if (result.err) {
1960
+ return result;
1961
+ }
1974
1962
 
1975
- elements.push(result.val);
1976
- } else if (char === 125
1963
+ elements.push(result.val);
1964
+ } else if (char === 125
1977
1965
  /* `}` */
1978
1966
  && nestingLevel > 0) {
1979
1967
  break;
@@ -1990,12 +1978,12 @@ var parser = createCommonjsModule(function (module, exports) {
1990
1978
  /* `<` */
1991
1979
  && !this.ignoreTag && this.peek() === 47 // char code for '/'
1992
1980
  ) {
1993
- if (expectingCloseTag) {
1994
- break;
1995
- } else {
1996
- return this.error(error.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
1997
- }
1998
- } else if (char === 60
1981
+ if (expectingCloseTag) {
1982
+ break;
1983
+ } else {
1984
+ return this.error(error.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
1985
+ }
1986
+ } else if (char === 60
1999
1987
  /* `<` */
2000
1988
  && !this.ignoreTag && _isAlpha(this.peek() || 0)) {
2001
1989
  var result = this.parseTag(nestingLevel, parentArgType);
@@ -2180,8 +2168,8 @@ var parser = createCommonjsModule(function (module, exports) {
2180
2168
  if (this.isEOF() || this.char() !== 39
2181
2169
  /* `'` */
2182
2170
  ) {
2183
- return null;
2184
- } // Parse escaped char following the apostrophe, or early return if there is no escaped char.
2171
+ return null;
2172
+ } // Parse escaped char following the apostrophe, or early return if there is no escaped char.
2185
2173
  // Check if is valid escaped character
2186
2174
 
2187
2175
 
@@ -2225,18 +2213,18 @@ var parser = createCommonjsModule(function (module, exports) {
2225
2213
  if (ch === 39
2226
2214
  /* `'` */
2227
2215
  ) {
2228
- if (this.peek() === 39
2229
- /* `'` */
2230
- ) {
2231
- codePoints.push(39); // Bump one more time because we need to skip 2 characters.
2216
+ if (this.peek() === 39
2217
+ /* `'` */
2218
+ ) {
2219
+ codePoints.push(39); // Bump one more time because we need to skip 2 characters.
2232
2220
 
2233
- this.bump();
2234
- } else {
2235
- // Optional closing apostrophe.
2236
- this.bump();
2237
- break;
2238
- }
2221
+ this.bump();
2239
2222
  } else {
2223
+ // Optional closing apostrophe.
2224
+ this.bump();
2225
+ break;
2226
+ }
2227
+ } else {
2240
2228
  codePoints.push(ch);
2241
2229
  }
2242
2230
 
@@ -2282,9 +2270,9 @@ var parser = createCommonjsModule(function (module, exports) {
2282
2270
  if (this.char() === 125
2283
2271
  /* `}` */
2284
2272
  ) {
2285
- this.bump();
2286
- return this.error(error.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
2287
- } // argument name
2273
+ this.bump();
2274
+ return this.error(error.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
2275
+ } // argument name
2288
2276
 
2289
2277
 
2290
2278
  var value = this.parseIdentifierIfPossible().value;
@@ -2563,8 +2551,8 @@ var parser = createCommonjsModule(function (module, exports) {
2563
2551
  if (this.isEOF() || this.char() !== 125
2564
2552
  /* `}` */
2565
2553
  ) {
2566
- return this.error(error.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2567
- }
2554
+ return this.error(error.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
2555
+ }
2568
2556
 
2569
2557
  this.bump(); // `}`
2570
2558
 
@@ -2774,10 +2762,10 @@ var parser = createCommonjsModule(function (module, exports) {
2774
2762
  && ch <= 57
2775
2763
  /* `9` */
2776
2764
  ) {
2777
- hasDigits = true;
2778
- decimal = decimal * 10 + (ch - 48);
2779
- this.bump();
2780
- } else {
2765
+ hasDigits = true;
2766
+ decimal = decimal * 10 + (ch - 48);
2767
+ this.bump();
2768
+ } else {
2781
2769
  break;
2782
2770
  }
2783
2771
  }
@@ -2861,10 +2849,10 @@ var parser = createCommonjsModule(function (module, exports) {
2861
2849
  if (code === 10
2862
2850
  /* '\n' */
2863
2851
  ) {
2864
- this.position.line += 1;
2865
- this.position.column = 1;
2866
- this.position.offset += 1;
2867
- } else {
2852
+ this.position.line += 1;
2853
+ this.position.column = 1;
2854
+ this.position.offset += 1;
2855
+ } else {
2868
2856
  this.position.column += 1; // 0 ~ 0x10000 -> unicode BMP, otherwise skip the surrogate pair.
2869
2857
 
2870
2858
  this.position.offset += code < 0x10000 ? 1 : 2;
@@ -15179,7 +15167,12 @@ const getMetaProp = function getMetaProp(lang, metadataObj, properties, allowObj
15179
15167
  // Todo: Allow use of dbs and fileGroup together in base directories?
15180
15168
 
15181
15169
  const getMetadata = async (file, property, basePath) => {
15182
- return (await JsonRefs.resolveRefsAt((basePath || getCurrDir()) + file + (property ? '#/' + property : ''), {
15170
+ const url = new URL(basePath || getCurrDir());
15171
+ url.search = ''; // Clear out query string, e.g., `?fbclid` from Facebook
15172
+
15173
+ url.pathname = file;
15174
+ url.hash = property ? '#/' + property : '';
15175
+ return (await JsonRefs.resolveRefsAt(url.toString(), {
15183
15176
  loaderOptions: {
15184
15177
  processContent(res, callback) {
15185
15178
  callback(undefined, JSON.parse(res.text || // `.metadata` not a recognized extension, so
@@ -16027,7 +16020,9 @@ const registerServiceWorker = async ({
16027
16020
  let r;
16028
16021
 
16029
16022
  try {
16030
- r = await navigator.serviceWorker.register(serviceWorkerPath);
16023
+ r = await navigator.serviceWorker.register(serviceWorkerPath, {
16024
+ type: 'module'
16025
+ });
16031
16026
  } catch (err) {
16032
16027
  console.log('serviceWorkerPath', serviceWorkerPath);
16033
16028
  await dialogs.alert(`
@@ -17964,8 +17959,7 @@ async function workDisplay({
17964
17959
  groupsToWorks
17965
17960
  }) {
17966
17961
  const il = localizeParamNames ? key => l(['params', key]) : key => key;
17967
- const iil = localizeParamNames ? key => l(['params', 'indexed', key]) : key => key; // eslint-disable-next-line unicorn/prefer-prototype-methods -- Convenient
17968
-
17962
+ const iil = localizeParamNames ? key => l(['params', 'indexed', key]) : key => key;
17969
17963
  const localeFromLangData = languages.localeFromLangData.bind(languages);
17970
17964
  const imfLang = IMF({
17971
17965
  locales: lang.map(localeFromLangData),
@@ -18305,6 +18299,8 @@ Object.defineProperty(self$1, '_BIDI_RTL_LANGS', {
18305
18299
  /* 'فارسی', Persian */
18306
18300
  'glk',
18307
18301
  /* 'گیلکی', Gilaki */
18302
+ 'he',
18303
+ /* 'עברית', Hebrew */
18308
18304
  'ku',
18309
18305
  /* 'Kurdî / كوردی', Kurdish */
18310
18306
  'mzn',
@@ -18319,8 +18315,10 @@ Object.defineProperty(self$1, '_BIDI_RTL_LANGS', {
18319
18315
  /* 'سنڌي', Sindhi */
18320
18316
  'ug',
18321
18317
  /* 'Uyghurche / ئۇيغۇرچە', Uyghur */
18322
- 'ur'
18318
+ 'ur',
18323
18319
  /* 'اردو', Urdu */
18320
+ 'yi'
18321
+ /* 'ייִדיש', Yiddish */
18324
18322
  ],
18325
18323
  writable: false,
18326
18324
  enumerable: true,
@@ -18382,8 +18380,8 @@ const setAnchor = ({
18382
18380
  if (i === max || // No more field sets to check
18383
18381
  anchors.length // Already had anchors found
18384
18382
  ) {
18385
- breakout = true;
18386
- }
18383
+ breakout = true;
18384
+ }
18387
18385
 
18388
18386
  break;
18389
18387
  }
@@ -19434,7 +19432,7 @@ async function requestPermissions(langs, l) {
19434
19432
  // rememberRefusal();
19435
19433
  resolve();
19436
19434
  return;
19437
- // eslint-disable-next-line radar/no-duplicated-branches
19435
+ // eslint-disable-next-line sonarjs/no-duplicated-branches
19438
19436
 
19439
19437
  case 'default':
19440
19438
  resolve();
@@ -19898,4 +19896,4 @@ TextBrowser.prototype.workDisplay = workDisplay;
19898
19896
  TextBrowser.prototype.resultsDisplayClient = resultsDisplayClient;
19899
19897
  TextBrowser.prototype.getWorkFiles = getWorkFiles;
19900
19898
 
19901
- export default TextBrowser;
19899
+ export { TextBrowser as default };