textbrowser 0.51.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGES.md +5 -0
  2. package/dist/WorkInfo-es.js +318 -78
  3. package/dist/activateCallback-es.js +9 -0
  4. package/dist/index-es.js +2569 -1732
  5. package/dist/index-es.min.js +4 -4
  6. package/dist/resources/activateCallback.d.ts.map +1 -1
  7. package/dist/resources/index.d.ts +1 -1
  8. package/dist/resources/index.d.ts.map +1 -1
  9. package/dist/resources/resultsDisplay.d.ts +4 -4
  10. package/dist/resources/resultsDisplay.d.ts.map +1 -1
  11. package/dist/resources/templates/index.d.ts.map +1 -1
  12. package/dist/resources/templates/utils/dom.d.ts +1 -1
  13. package/dist/resources/templates/utils/dom.d.ts.map +1 -1
  14. package/dist/resources/templates/workDisplay.d.ts.map +1 -1
  15. package/dist/resources/utils/IntlURLSearchParams.d.ts +4 -4
  16. package/dist/resources/utils/IntlURLSearchParams.d.ts.map +1 -1
  17. package/dist/resources/utils/Metadata.d.ts +2 -2
  18. package/dist/resources/utils/Metadata.d.ts.map +1 -1
  19. package/dist/resources/utils/Params.d.ts.map +1 -1
  20. package/dist/resources/utils/Plugin.d.ts +14 -10
  21. package/dist/resources/utils/Plugin.d.ts.map +1 -1
  22. package/dist/resources/utils/ServiceWorker.d.ts.map +1 -1
  23. package/dist/resources/utils/dialogs.d.ts +2 -2
  24. package/dist/resources/utils/dialogs.d.ts.map +1 -1
  25. package/dist/resources/utils/getLocaleFallbackResults.d.ts +1 -1
  26. package/dist/resources/utils/getLocaleFallbackResults.d.ts.map +1 -1
  27. package/dist/server/main.d.ts +2 -1
  28. package/dist/server/main.d.ts.map +1 -1
  29. package/package.json +20 -20
  30. package/resources/activateCallback.js +6 -0
  31. package/resources/index.js +10 -11
  32. package/resources/resultsDisplay.js +4 -2
  33. package/resources/templates/index.js +0 -1
  34. package/resources/templates/workDisplay.js +0 -1
  35. package/resources/user-sample.js +1 -0
  36. package/resources/utils/Metadata.js +3 -1
  37. package/resources/utils/Plugin.js +11 -5
  38. package/resources/utils/ServiceWorker.js +1 -2
  39. package/resources/utils/WorkInfo.js +1 -1
  40. package/resources/utils/getLocaleFallbackResults.js +3 -1
  41. package/server/main.js +9 -3
  42. package/sw-sample.js +2 -1
@@ -3,7 +3,7 @@ import {getPreferredLanguages} from './Languages.js';
3
3
  import JsonRefs from 'json-refs'; // // eslint-disable-line import/order
4
4
 
5
5
  const getCurrDir = () => {
6
- return window.location.href.replace(/(index\.html)?#.*$/, '');
6
+ return globalThis.location.href.replace(/(index\.html)?#.*$/, '');
7
7
  };
8
8
 
9
9
  /**
@@ -105,6 +105,7 @@ export const getMetadata = async (file, property, basePath) => {
105
105
  url.toString(),
106
106
  {
107
107
  loaderOptions: {
108
+ /* eslint-disable jsdoc/reject-any-type -- How to resolve? */
108
109
  /**
109
110
  * @param {{
110
111
  * text: string,
@@ -113,6 +114,7 @@ export const getMetadata = async (file, property, basePath) => {
113
114
  * @param {(err?: Error, cbValue: any) => void} callback
114
115
  */
115
116
  processContent (res, callback) {
117
+ /* eslint-enable jsdoc/reject-any-type -- How to resolve? */
116
118
  callback(undefined, JSON.parse(
117
119
  res.text ||
118
120
  // `.metadata` not a recognized extension, so
@@ -40,6 +40,12 @@ export const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
40
40
  (targetLanguage ? '-' + escapePluginComponent(targetLanguage) : '');
41
41
  };
42
42
 
43
+ /* eslint-disable jsdoc/reject-any-type -- How to resolve? */
44
+ /**
45
+ * @typedef {any} MetaValue
46
+ */
47
+ /* eslint-enable jsdoc/reject-any-type -- Arbitrary */
48
+
43
49
  /**
44
50
  * @todo Complete
45
51
  * @typedef {{
@@ -66,7 +72,7 @@ export const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
66
72
  * },
67
73
  * $p: import('./IntlURLSearchParams.js').default,
68
74
  * thisObj: import('../index.js').default|import('../../server/main.js').ResultsDisplayServerContext
69
- * }) => void,
75
+ * }) => string|Integer,
70
76
  * done: (info: {
71
77
  * $p: import('./IntlURLSearchParams.js').default,
72
78
  * applicableField: string|undefined,
@@ -87,7 +93,7 @@ export const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
87
93
  * targetLanguage: string,
88
94
  * applicableField: string,
89
95
  * applicableFieldI18N: string|string[]|import("../../server/main.js").LocalizationStrings,
90
- * meta: any,
96
+ * meta: MetaValue,
91
97
  * metaApplicableField: {
92
98
  * [key: string]: string
93
99
  * },
@@ -100,7 +106,7 @@ export const escapePlugin = ({pluginName, applicableField, targetLanguage}) => {
100
106
  * @typedef {{
101
107
  * path: string,
102
108
  * lang: string,
103
- * meta: any,
109
+ * meta: MetaValue,
104
110
  * onByDefault: boolean
105
111
  * }} PluginInfo
106
112
  */
@@ -157,7 +163,7 @@ export class PluginsForWork {
157
163
  * [applicableField: string]: {
158
164
  * targetLanguage: string|string[],
159
165
  * onByDefault: boolean,
160
- * meta: any
166
+ * meta: MetaValue
161
167
  * }
162
168
  * },
163
169
  * pluginName: string,
@@ -199,7 +205,7 @@ export class PluginsForWork {
199
205
  * [applicableField: string]: {
200
206
  * targetLanguage: string|string[],
201
207
  * onByDefault: boolean,
202
- * meta: any
208
+ * meta: MetaValue
203
209
  * }
204
210
  * }} applicableFields
205
211
  * @param {(cfg: {
@@ -125,7 +125,7 @@ export const respondToState = async ({
125
125
  // We use this promise for rejecting (inside a listener)
126
126
  // to a common catch and to prevent continuation by
127
127
  // failing to return
128
- return new Promise(async () => { // eslint-disable-line no-async-promise-executor, sonarjs/no-misused-promises -- See above
128
+ return new Promise(async () => { // eslint-disable-line no-async-promise-executor -- See above
129
129
  navigator.serviceWorker.addEventListener('message', ({data}) => {
130
130
  const {message, type, name, errorType} = data;
131
131
  console.log('msg1', message, r);
@@ -292,7 +292,6 @@ export const registerServiceWorker = async ({
292
292
  type: 'module'
293
293
  }
294
294
  );
295
- // eslint-disable-next-line no-unused-vars -- Ok
296
295
  } catch (err) {
297
296
  console.log('serviceWorkerPath', serviceWorkerPath);
298
297
  await dialogs.alert(`
@@ -93,7 +93,7 @@ export const getWorkFiles = async function getWorkFiles (files) {
93
93
  filesObj.groups.forEach((fileGroup) => {
94
94
  fileGroup.files.forEach((fileData) => {
95
95
  const {file, schemaFile, metadataFile} =
96
- getFilePaths(filesObj, fileGroup, fileData);
96
+ getFilePaths(filesObj, fileGroup, fileData);
97
97
  dataFiles.push(file, schemaFile, metadataFile);
98
98
  });
99
99
  });
@@ -35,5 +35,7 @@ export default async function getLocaleFallbackResults ({
35
35
  if (!$p.l10n) {
36
36
  $p.l10n = l;
37
37
  }
38
- return l;
38
+
39
+ // Not sure why cast needed here, but works...
40
+ return /** @type {import('intl-dom').I18NCallback} */ (l);
39
41
  }
package/server/main.js CHANGED
@@ -93,13 +93,19 @@ const port = 'port' in userParams ? userParams.port : 8000;
93
93
  const domain = userParams.domain || `localhost`;
94
94
  const basePath = userParams.basePath || `http://${domain}${port ? ':' + port : ''}/`;
95
95
 
96
+ /* eslint-disable jsdoc/reject-any-type -- Arbitrary */
97
+ /**
98
+ * @typedef {any} AnyValue
99
+ */
100
+ /* eslint-enable jsdoc/reject-any-type -- Arbitrary */
101
+
96
102
  /**
97
103
  * @typedef {import('../resources/utils/ServiceWorker.js').ServiceWorkerConfig &
98
104
  * UserOptions & {
99
105
  * lang: string[],
100
106
  * langs: LanguageInfo[],
101
107
  * fallbackLanguages: string[],
102
- * log: (...args: any[]) => void,
108
+ * log: (...args: AnyValue[]) => void,
103
109
  * nodeActivate?: boolean,
104
110
  * port?: number,
105
111
  * skipIndexedDB: false,
@@ -117,7 +123,7 @@ const userParamsWithDefaults = {
117
123
  }),
118
124
  ...userParams,
119
125
  /**
120
- * @param {...any} args
126
+ * @param {...AnyValue} args
121
127
  */
122
128
  log (...args) {
123
129
  console.log(...args);
@@ -272,7 +278,7 @@ const srv = http.createServer(async (req, res) => {
272
278
  const languages = (req.headers['accept-language']?.replace(/;q=.*$/, '') ?? 'en-US').split(',');
273
279
  // @ts-expect-error Polyglot reasons
274
280
  // eslint-disable-next-line n/no-unsupported-features/node-builtins -- Polyglot reasons
275
- global.navigator = {
281
+ globalThis.navigator = {
276
282
  language: languages[0],
277
283
  languages
278
284
  };
package/sw-sample.js CHANGED
@@ -1,8 +1,9 @@
1
1
  /* eslint-env serviceworker -- Service worker */
2
2
 
3
+ // eslint-disable-next-line sonarjs/no-internal-api-use -- Demo
3
4
  import swHelper from './node_modules/textbrowser/dist/sw-helper.js';
4
5
 
5
6
  // IMPORTANT: Keep this comment and increment this number to trigger
6
7
  // a worker change: 1
7
8
 
8
- swHelper(self);
9
+ swHelper(globalThis);