textbrowser 0.50.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 (106) hide show
  1. package/.ncurc.cjs +3 -0
  2. package/CHANGES.md +13 -0
  3. package/dist/WorkInfo-es.js +655 -165
  4. package/dist/activateCallback-es.js +81 -10
  5. package/dist/dist/WorkInfo-es.d.ts +331 -0
  6. package/dist/dist/WorkInfo-es.d.ts.map +1 -0
  7. package/dist/dist/activateCallback-es.d.ts +17 -0
  8. package/dist/dist/activateCallback-es.d.ts.map +1 -0
  9. package/dist/dist/index-es.d.ts +619 -0
  10. package/dist/dist/index-es.d.ts.map +1 -0
  11. package/dist/dist/sw-helper.d.ts +3 -0
  12. package/dist/dist/sw-helper.d.ts.map +1 -0
  13. package/dist/eslint.config.d.ts +126 -0
  14. package/dist/eslint.config.d.ts.map +1 -0
  15. package/dist/index-es.js +3449 -1848
  16. package/dist/index-es.min.js +4 -4
  17. package/dist/resources/activateCallback.d.ts +23 -0
  18. package/dist/resources/activateCallback.d.ts.map +1 -0
  19. package/dist/resources/index.d.ts +128 -0
  20. package/dist/resources/index.d.ts.map +1 -0
  21. package/dist/resources/resultsDisplay.d.ts +110 -0
  22. package/dist/resources/resultsDisplay.d.ts.map +1 -0
  23. package/dist/resources/templates/index.d.ts +59 -0
  24. package/dist/resources/templates/index.d.ts.map +1 -0
  25. package/dist/resources/templates/languageSelect.d.ts +18 -0
  26. package/dist/resources/templates/languageSelect.d.ts.map +1 -0
  27. package/dist/resources/templates/resultsDisplayClient.d.ts +26 -0
  28. package/dist/resources/templates/resultsDisplayClient.d.ts.map +1 -0
  29. package/dist/resources/templates/resultsDisplayServerOrClient.d.ts +131 -0
  30. package/dist/resources/templates/resultsDisplayServerOrClient.d.ts.map +1 -0
  31. package/dist/resources/templates/utils/dom.d.ts +15 -0
  32. package/dist/resources/templates/utils/dom.d.ts.map +1 -0
  33. package/dist/resources/templates/utils/html.d.ts +3 -0
  34. package/dist/resources/templates/utils/html.d.ts.map +1 -0
  35. package/dist/resources/templates/workDisplay.d.ts +183 -0
  36. package/dist/resources/templates/workDisplay.d.ts.map +1 -0
  37. package/dist/resources/templates/workSelect.d.ts +18 -0
  38. package/dist/resources/templates/workSelect.d.ts.map +1 -0
  39. package/dist/resources/user-sample.d.ts +2 -0
  40. package/dist/resources/user-sample.d.ts.map +1 -0
  41. package/dist/resources/user.d.ts +2 -0
  42. package/dist/resources/user.d.ts.map +1 -0
  43. package/dist/resources/utils/IntlURLSearchParams.d.ts +56 -0
  44. package/dist/resources/utils/IntlURLSearchParams.d.ts.map +1 -0
  45. package/dist/resources/utils/Languages.d.ts +81 -0
  46. package/dist/resources/utils/Languages.d.ts.map +1 -0
  47. package/dist/resources/utils/Metadata.d.ts +133 -0
  48. package/dist/resources/utils/Metadata.d.ts.map +1 -0
  49. package/dist/resources/utils/Params.d.ts +30 -0
  50. package/dist/resources/utils/Params.d.ts.map +1 -0
  51. package/dist/resources/utils/Plugin.d.ts +278 -0
  52. package/dist/resources/utils/Plugin.d.ts.map +1 -0
  53. package/dist/resources/utils/ServiceWorker.d.ts +26 -0
  54. package/dist/resources/utils/ServiceWorker.d.ts.map +1 -0
  55. package/dist/resources/utils/WorkInfo.d.ts +104 -0
  56. package/dist/resources/utils/WorkInfo.d.ts.map +1 -0
  57. package/dist/resources/utils/dialogs.d.ts +155 -0
  58. package/dist/resources/utils/dialogs.d.ts.map +1 -0
  59. package/dist/resources/utils/getLocaleFallbackResults.d.ts +19 -0
  60. package/dist/resources/utils/getLocaleFallbackResults.d.ts.map +1 -0
  61. package/dist/resources/utils/sanitize.d.ts +6 -0
  62. package/dist/resources/utils/sanitize.d.ts.map +1 -0
  63. package/dist/resources/vendor/json-refs-min.d.ts +3 -0
  64. package/dist/resources/vendor/json-refs-min.d.ts.map +1 -0
  65. package/dist/resources/workDisplay.d.ts +81 -0
  66. package/dist/resources/workDisplay.d.ts.map +1 -0
  67. package/dist/resources/workSelect.d.ts +17 -0
  68. package/dist/resources/workSelect.d.ts.map +1 -0
  69. package/dist/rollup.config.d.ts +19 -0
  70. package/dist/rollup.config.d.ts.map +1 -0
  71. package/dist/server/main.d.ts +47 -0
  72. package/dist/server/main.d.ts.map +1 -0
  73. package/dist/sw-helper.d.ts +3 -0
  74. package/dist/sw-helper.d.ts.map +1 -0
  75. package/dist/sw-helper.js +52 -12
  76. package/dist/sw-sample.d.ts +2 -0
  77. package/dist/sw-sample.d.ts.map +1 -0
  78. package/general-schemas/files.jsonschema +6 -0
  79. package/package.json +32 -19
  80. package/resources/activateCallback.js +81 -10
  81. package/resources/index.js +169 -58
  82. package/resources/resultsDisplay.js +520 -153
  83. package/resources/templates/index.js +39 -17
  84. package/resources/templates/languageSelect.js +14 -1
  85. package/resources/templates/resultsDisplayClient.js +22 -3
  86. package/resources/templates/resultsDisplayServerOrClient.js +188 -49
  87. package/resources/templates/utils/dom.js +13 -2
  88. package/resources/templates/workDisplay.js +299 -76
  89. package/resources/templates/workSelect.js +16 -3
  90. package/resources/user-sample.js +1 -0
  91. package/resources/utils/IntlURLSearchParams.js +46 -4
  92. package/resources/utils/Languages.js +71 -4
  93. package/resources/utils/Metadata.js +222 -23
  94. package/resources/utils/Params.js +70 -23
  95. package/resources/utils/Plugin.js +175 -1
  96. package/resources/utils/ServiceWorker.js +49 -21
  97. package/resources/utils/WorkInfo.js +256 -44
  98. package/resources/utils/dialogs.js +105 -7
  99. package/resources/utils/getLocaleFallbackResults.js +15 -3
  100. package/resources/utils/sanitize.js +4 -0
  101. package/resources/workDisplay.js +151 -25
  102. package/resources/workSelect.js +37 -17
  103. package/server/main.js +118 -20
  104. package/sw-sample.js +2 -1
  105. package/tsconfig.json +30 -0
  106. package/resources/user.js +0 -20
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @typedef {() => Promise<{
3
+ * groupName: string | Text | DocumentFragment,
4
+ * worksToFields: {
5
+ * workName: string | Text | DocumentFragment,
6
+ * shortcut: string,
7
+ * fieldAliasOrNames: (
8
+ * string|string[]|import('../server/main.js').LocalizationStrings
9
+ * )[]|undefined
10
+ * }[]
11
+ * }[]>} GetFieldAliasOrNames
12
+ */
13
+ /**
14
+ * @typedef {(innerArg: {
15
+ * form: HTMLFormElement,
16
+ * random: {
17
+ * checked: boolean
18
+ * },
19
+ * checkboxes: HTMLInputElement[],
20
+ * type: string,
21
+ * fieldAliasOrNames?: string[],
22
+ * workName?: string,
23
+ * }) => string} SerializeParamsAsURL
24
+ */
25
+ /**
26
+ * @typedef {(
27
+ * key: string|string[],
28
+ * substitutions?: Record<string, string>
29
+ * ) => string|Text|DocumentFragment} LDirectional
30
+ */
31
+ /**
32
+ * @typedef {(
33
+ * key: string,
34
+ * tag: string,
35
+ * attr: string,
36
+ * atts: import('jamilih').JamilihAttributes,
37
+ * children?: import('jamilih').JamilihChildren
38
+ * ) => import('jamilih').JamilihArray} LElement
39
+ */
40
+ /**
41
+ * @this {import('./index.js').default}
42
+ * @param {{
43
+ * l: import('intl-dom').I18NCallback,
44
+ * languageParam: string,
45
+ * lang: string[],
46
+ * preferredLocale: string,
47
+ * languages: import('./utils/Languages.js').Languages,
48
+ * fallbackLanguages: string[],
49
+ * $p: import('./utils/IntlURLSearchParams.js').default
50
+ * }} cfg
51
+ */
52
+ export default function workDisplay(this: import("./index.js").default, { l, languageParam, lang, preferredLocale, languages, fallbackLanguages, $p }: {
53
+ l: import("intl-dom").I18NCallback;
54
+ languageParam: string;
55
+ lang: string[];
56
+ preferredLocale: string;
57
+ languages: import("./utils/Languages.js").Languages;
58
+ fallbackLanguages: string[];
59
+ $p: import("./utils/IntlURLSearchParams.js").default;
60
+ }): Promise<void>;
61
+ export type GetFieldAliasOrNames = () => Promise<{
62
+ groupName: string | Text | DocumentFragment;
63
+ worksToFields: {
64
+ workName: string | Text | DocumentFragment;
65
+ shortcut: string;
66
+ fieldAliasOrNames: (string | string[] | import("../server/main.js").LocalizationStrings)[] | undefined;
67
+ }[];
68
+ }[]>;
69
+ export type SerializeParamsAsURL = (innerArg: {
70
+ form: HTMLFormElement;
71
+ random: {
72
+ checked: boolean;
73
+ };
74
+ checkboxes: HTMLInputElement[];
75
+ type: string;
76
+ fieldAliasOrNames?: string[];
77
+ workName?: string;
78
+ }) => string;
79
+ export type LDirectional = (key: string | string[], substitutions?: Record<string, string>) => string | Text | DocumentFragment;
80
+ export type LElement = (key: string, tag: string, attr: string, atts: import("jamilih").JamilihAttributes, children?: import("jamilih").JamilihChildren) => import("jamilih").JamilihArray;
81
+ //# sourceMappingURL=workDisplay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workDisplay.d.ts","sourceRoot":"","sources":["../../resources/workDisplay.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;GAWG;AACH,uJAVW;IACN,CAAC,EAAE,OAAO,UAAU,EAAE,YAAY,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,OAAO,sBAAsB,EAAE,SAAS,CAAC;IACpD,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,EAAE,EAAE,OAAO,gCAAgC,EAAE,OAAO,CAAA;CACrD,iBAyOH;mCA7RY,MAAM,OAAO,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB,CAAC;IAC5C,aAAa,EAAE;QACb,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,gBAAgB,CAAC;QAC3C,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,CACzB,MAAc,GAAC,MAAM,EAAE,GAAC,OAAO,mBAAmB,EAAE,mBAAmB,CAChE,EAAE,GAAC,SAAS,CAAA;KACd,EAAE,CAAA;CACJ,EAAE,CAAC;mCAIM,CAAC,QAAQ,EAAE;IACnB,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE;QACN,OAAO,EAAE,OAAO,CAAA;KACjB,CAAC;IACF,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,KAAK,MAAM;2BAIF,CACR,GAAG,EAAE,MAAM,GAAC,MAAM,EAAE,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACnC,MAAM,GAAC,IAAI,GAAC,gBAAgB;uBAIvB,CACR,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,SAAS,EAAE,iBAAiB,EACzC,QAAQ,CAAC,EAAE,OAAO,SAAS,EAAE,eAAe,KACzC,OAAO,SAAS,EAAE,YAAY"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @param {{
3
+ * files: string,
4
+ * lang: string[],
5
+ * fallbackLanguages: string[],
6
+ * $p: import('./utils/IntlURLSearchParams.js').default,
7
+ * followParams: (formSelector: string, cb: () => void) => void
8
+ * }} cfg
9
+ */
10
+ export default function workSelect({ files, lang, fallbackLanguages, $p, followParams }: {
11
+ files: string;
12
+ lang: string[];
13
+ fallbackLanguages: string[];
14
+ $p: import("./utils/IntlURLSearchParams.js").default;
15
+ followParams: (formSelector: string, cb: () => void) => void;
16
+ }): Promise<void>;
17
+ //# sourceMappingURL=workSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workSelect.d.ts","sourceRoot":"","sources":["../../resources/workSelect.js"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,yFARW;IACN,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,EAAE,EAAE,OAAO,gCAAgC,EAAE,OAAO,CAAC;IACrD,YAAY,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;CAC7D,iBAkFH"}
@@ -0,0 +1,19 @@
1
+ declare const _default: (import("rollup").RollupOptions | {
2
+ input: string;
3
+ output: {
4
+ format: string;
5
+ file: string;
6
+ name: string;
7
+ };
8
+ plugins: any[];
9
+ } | {
10
+ input: string;
11
+ output: {
12
+ format: string;
13
+ file: string;
14
+ name: string;
15
+ };
16
+ plugins?: undefined;
17
+ })[];
18
+ export default _default;
19
+ //# sourceMappingURL=rollup.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.config.d.ts","sourceRoot":"","sources":["../rollup.config.js"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env node
2
+ export type UserOptions = {
3
+ nodeActivate: boolean;
4
+ port: number;
5
+ domain: string;
6
+ basePath: string;
7
+ interlinearSeparator: string;
8
+ localizeParamNames: boolean;
9
+ trustFormatHTML: boolean;
10
+ allowPlugins: boolean;
11
+ showEmptyInterlinear: boolean;
12
+ showTitleOnSingleInterlinear: boolean;
13
+ serviceWorkerPath: string;
14
+ userJSON: string;
15
+ languages: string;
16
+ files: string;
17
+ namespace: string;
18
+ httpServer: string;
19
+ expressServer: string;
20
+ };
21
+ export type AnyValue = any;
22
+ export type ResultsDisplayServerContext = import("../resources/utils/ServiceWorker.js").ServiceWorkerConfig & UserOptions & {
23
+ lang: string[];
24
+ langs: LanguageInfo[];
25
+ fallbackLanguages: string[];
26
+ log: (...args: AnyValue[]) => void;
27
+ nodeActivate?: boolean;
28
+ port?: number;
29
+ skipIndexedDB: false;
30
+ noDynamic: false;
31
+ };
32
+ export type LanguageInfo = {
33
+ code: string;
34
+ direction: "ltr" | "rtl";
35
+ locale: {
36
+ $ref: string;
37
+ };
38
+ };
39
+ export type LocalizationStrings = {
40
+ [key: string]: string | string[] | LocalizationStrings;
41
+ };
42
+ export type LanguagesData = {
43
+ languages: LanguageInfo[];
44
+ localeFileBasePath?: string;
45
+ "localization-strings": LocalizationStrings;
46
+ };
47
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../server/main.js"],"names":[],"mappings":";0BAoCa;IACR,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,4BAA4B,EAAE,OAAO,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAA;CACtB;uBA2CS,GAAG;0CAKH,OAAO,qCAAqC,EAAE,mBAAmB,GACzE,WAAW,GAAG;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,IAAI,CAAC;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,KAAK,CAAC;IACrB,SAAS,EAAE,KAAK,CAAC;CAClB;2BA2DO;IACR,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,KAAK,GAAC,KAAK,CAAC;IACvB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF;kCAIS;IACZ,CAAK,GAAG,EAAE,MAAM,GAAG,MAAM,GAAC,MAAM,EAAE,GAAC,mBAAmB,CAAA;CACnD;4BAIS;IACR,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAA0B,EAAE,mBAAmB,CAAA;CAC5C"}
@@ -0,0 +1,3 @@
1
+ export default swHelper;
2
+ declare function swHelper(self: any): void;
3
+ //# sourceMappingURL=sw-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sw-helper.d.ts","sourceRoot":"","sources":["../sw-helper.js"],"names":[],"mappings":";AAiBA,2CAuSC"}
package/dist/sw-helper.js CHANGED
@@ -10,11 +10,25 @@ const minutes = 60 * 1000;
10
10
 
11
11
  // UTILITIES
12
12
 
13
+ /**
14
+ * @typedef {number} PositiveInteger
15
+ */
16
+
17
+ /**
18
+ * @typedef {number} Float
19
+ */
20
+
21
+ /**
22
+ * @param {string} url
23
+ */
13
24
  async function getJSON (url) {
14
25
  const resp = await fetch(url);
15
26
  return await resp.json();
16
27
  }
17
28
 
29
+ /**
30
+ * @param {ServiceWorkerGlobalScope} self
31
+ */
18
32
  function swHelper (self) {
19
33
  // These could be made configurable by argument too
20
34
  const defaultUserStaticFiles = [
@@ -49,7 +63,7 @@ function swHelper (self) {
49
63
  ];
50
64
 
51
65
  /**
52
- * @typedef {PlainObject} ConfigObject
66
+ * @typedef {object} ConfigObject
53
67
  * @property {string} namespace
54
68
  * @property {string} basePath
55
69
  * @property {string} languages
@@ -59,8 +73,8 @@ function swHelper (self) {
59
73
 
60
74
  /**
61
75
  *
62
- * @param {ConfigObject} args
63
- * @returns {ConfigObject}
76
+ * @param {Partial<ConfigObject>} args
77
+ * @returns {Required<ConfigObject>}
64
78
  * @todo Since some of these reused, move to external file (or
65
79
  * use `setServiceWorkerDefaults`?)
66
80
  */
@@ -96,7 +110,12 @@ function swHelper (self) {
96
110
  function logError (error, ...messages) {
97
111
  const message = messages.join(' ');
98
112
  console.error(error, message);
99
- return post({message, errorType: error.type, name: error.name, type: 'error'});
113
+ return post({
114
+ message,
115
+ // errorType: error.type,
116
+ // name: error.name,
117
+ type: 'error'
118
+ });
100
119
  }
101
120
 
102
121
  /**
@@ -120,7 +139,12 @@ function swHelper (self) {
120
139
  return undefined;
121
140
  } catch (err) {
122
141
  console.log('errrr', err);
123
- logError(err, err.message || errMessage);
142
+ logError(
143
+ /** @type {Error} */
144
+ (err),
145
+ /** @type {Error} */
146
+ (err).message || errMessage
147
+ );
124
148
  return new Promise((resolve) => {
125
149
  setTimeout(() => {
126
150
  resolve(tryAndRetry(cb, timeout, errMessage, time));
@@ -131,7 +155,7 @@ function swHelper (self) {
131
155
 
132
156
  /**
133
157
  *
134
- * @param {PlainObject} args
158
+ * @param {object} args
135
159
  * @param {"log"|"error"|"beginInstall"|"finishedInstall"|"beginActivate"|"finishedActivate"} args.type
136
160
  * @param {string} [args.message]
137
161
  * @returns {Promise<void>}
@@ -163,7 +187,7 @@ function swHelper (self) {
163
187
  post({type: 'beginInstall'});
164
188
  log(`Install: Trying, attempt ${time}`);
165
189
  const now = Date.now();
166
- const json = await getJSON(pathToUserJSON);
190
+ const json = await getJSON(/** @type {string} */ (pathToUserJSON));
167
191
 
168
192
  const {
169
193
  namespace, languages, files, userStaticFiles
@@ -190,7 +214,14 @@ function swHelper (self) {
190
214
  // to work selection
191
215
  // Todo: We might give option to only download
192
216
  // one locale and avoid language splash page
193
- const localeFiles = langs.map(
217
+ const localeFiles =
218
+ /**
219
+ * @type {{
220
+ * code: string,
221
+ * direction: "rtl"|"ltr",
222
+ * locale: {$ref: string}
223
+ * }[]}
224
+ */ (langs).map(
194
225
  ({locale: {$ref}}) => {
195
226
  return (langPathParts.length > 1
196
227
  ? langPathParts.slice(0, -1).join('/') + '/'
@@ -222,14 +253,22 @@ function swHelper (self) {
222
253
  }
223
254
  return cache.put(urlToPrefetch, response);
224
255
  } catch (error) {
225
- logError(error, 'Not caching ' + urlToPrefetch + ' due to ' + error);
256
+ logError(
257
+ /** @type {Error} */
258
+ (error),
259
+ `Not caching ${urlToPrefetch} due to ${error}`
260
+ );
226
261
  throw error;
227
262
  }
228
263
  });
229
264
  await Promise.all(cachePromises);
230
265
  log('Install: Pre-fetching complete.');
231
266
  } catch (error) {
232
- logError(error, `Install: Pre-fetching failed: ${error}`);
267
+ logError(
268
+ /** @type {Error} */
269
+ (error),
270
+ `Install: Pre-fetching failed: ${error}`
271
+ );
233
272
  // Failing gives chance for a new client to re-trigger install?
234
273
  throw error;
235
274
  }
@@ -252,7 +291,7 @@ function swHelper (self) {
252
291
  post({type: 'beginActivate'});
253
292
  log(`Activate: Trying, attempt ${time}`);
254
293
  const [json, cacheNames] = await Promise.all([
255
- getJSON(pathToUserJSON),
294
+ getJSON(/** @type {string} */ (pathToUserJSON)),
256
295
  caches.keys()
257
296
  ]);
258
297
  const {namespace, files, basePath} = getConfigDefaults(json);
@@ -274,9 +313,10 @@ function swHelper (self) {
274
313
  post({type: 'finishedActivate'});
275
314
  }
276
315
 
316
+ // @ts-expect-error Ok
277
317
  const params = new URL(location).searchParams;
278
318
  const pathToUserJSON = params.get('pathToUserJSON');
279
- const stylesheets = JSON.parse(params.get('stylesheets') || []);
319
+ const stylesheets = JSON.parse(params.get('stylesheets') || '[]');
280
320
 
281
321
  console.log('sw info', pathToUserJSON);
282
322
  console.log('sw stylesheets', stylesheets);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=sw-sample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sw-sample.d.ts","sourceRoot":"","sources":["../sw-sample.js"],"names":[],"mappings":""}
@@ -17,6 +17,9 @@
17
17
  },
18
18
  "type": "object",
19
19
  "properties": {
20
+ "baseDirectory": {
21
+ "type": "string"
22
+ },
20
23
  "schemaBaseDirectory": {
21
24
  "type": "string"
22
25
  },
@@ -193,6 +196,9 @@
193
196
  "id": {"type": "string"},
194
197
  "name": {"$ref": "#/definitions/localeKey"},
195
198
  "directions": {"$ref": "#/definitions/localeKey"},
199
+ "baseDirectory": {
200
+ "type": "string"
201
+ },
196
202
  "schemaBaseDirectory": {
197
203
  "type": "string"
198
204
  },
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "textbrowser",
3
- "version": "0.50.0",
3
+ "version": "0.52.0",
4
4
  "description": "Multilinear text browser",
5
5
  "type": "module",
6
6
  "main": "dist/index-es.min.js",
7
- "exports": "./dist/index-es.min.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/dist/index-es.d.ts",
10
+ "default": "./dist/index-es.min.js"
11
+ }
12
+ },
8
13
  "module": "resources/index.js",
9
14
  "bin": {
10
15
  "textbrowser": "./server/main.js"
@@ -30,51 +35,59 @@
30
35
  "text"
31
36
  ],
32
37
  "dependencies": {
33
- "@babel/core": "^7.25.2",
34
- "@brettz9/node-static": "^0.1.1",
35
- "command-line-args": "^6.0.0",
38
+ "@babel/core": "^7.28.4",
39
+ "@node-static/node-static": "^0.8.0",
40
+ "command-line-args": "^6.0.1",
36
41
  "dom-parser": "^1.1.5",
37
42
  "form-serialization": "^0.11.0",
38
43
  "indexeddbshim": "^12.0.0",
39
44
  "intl-dom": "^0.20.0",
40
- "intl-locale-textinfo-polyfill": "^2.1.1",
45
+ "intl-locale-textinfo-polyfill": "^3.0.0",
41
46
  "jamilih": "0.60.0",
42
- "jsdom": "^25.0.0",
47
+ "jsdom": "^27.0.0",
43
48
  "json-refs": "^3.0.15",
44
49
  "load-stylesheets": "0.12.5",
45
50
  "node-fetch": "^3.3.2",
46
- "simple-get-json": "^9.0.1"
51
+ "simple-get-json": "^10.0.0"
47
52
  },
48
53
  "devDependencies": {
49
54
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
50
- "@babel/preset-env": "^7.25.4",
55
+ "@babel/preset-env": "^7.28.3",
51
56
  "@rollup/plugin-babel": "^6.0.4",
52
- "@rollup/plugin-commonjs": "^26.0.1",
57
+ "@rollup/plugin-commonjs": "^28.0.6",
53
58
  "@rollup/plugin-json": "^6.1.0",
54
- "@rollup/plugin-node-resolve": "^15.2.3",
59
+ "@rollup/plugin-node-resolve": "^16.0.1",
55
60
  "@rollup/plugin-terser": "^0.4.4",
56
61
  "@stadtlandnetz/rollup-plugin-postprocess": "^1.1.0",
57
- "@web/rollup-plugin-import-meta-assets": "^2.2.1",
62
+ "@types/chai": "^5.2.2",
63
+ "@types/express": "^5.0.3",
64
+ "@types/json-schema": "^7.0.15",
65
+ "@types/mocha": "^10.0.10",
66
+ "@types/node": "^24.6.2",
67
+ "@web/rollup-plugin-import-meta-assets": "^2.3.0",
58
68
  "ajv": "8.17.1",
59
69
  "babel-plugin-dynamic-import-node": "^2.3.3",
60
- "chai": "^5.1.1",
61
- "eslint": "^9.10.0",
62
- "eslint-config-ash-nazg": "^36.17.0",
70
+ "chai": "^6.2.0",
71
+ "eslint": "^9.37.0",
72
+ "eslint-config-ash-nazg": "^39.5.0",
63
73
  "json-metaschema": "1.3.0",
64
- "mocha": "^10.7.3",
74
+ "json-schema": "^0.4.0",
75
+ "mocha": "^11.7.4",
65
76
  "npm-run-all": "^4.1.5",
66
77
  "open-cli": "^8.0.0",
67
- "rollup": "^4.22.0",
78
+ "rollup": "^4.52.4",
68
79
  "rollup-plugin-re": "^1.0.7",
69
- "textbrowser-data-schemas": "^0.2.0"
80
+ "textbrowser-data-schemas": "^0.2.0",
81
+ "typescript": "^5.9.3"
70
82
  },
71
83
  "scripts": {
84
+ "tsc": "tsc",
72
85
  "server": "./server/main.js --allowPlugins --namespace=test",
73
86
  "start": "static -p 8081",
74
87
  "rollup": "rollup -c",
75
88
  "lint": "npm run eslint",
76
89
  "eslint": "eslint .",
77
- "mocha": "mocha --require test/bootstrap/node.js --require chai/register-assert.js test/textbrowserTests.js",
90
+ "mocha": "node_modules/.bin/_mocha --require test/bootstrap/node.js --require chai/register-assert.js test/textbrowserTests.js",
78
91
  "node": "npm run eslint && npm run rollup && npm run mocha",
79
92
  "open-test": "open-cli http://127.0.0.1:8081/test/",
80
93
  "start-open-test": "run-p start open-test",
@@ -4,8 +4,22 @@
4
4
  */
5
5
  /* eslint-env worker -- Worker environment */
6
6
 
7
+ /**
8
+ * @typedef {import('./utils/Metadata.js')} MetadataFile
9
+ */
10
+
11
+ /**
12
+ * @typedef {number} Integer
13
+ */
7
14
  const {ceil} = Math;
15
+
16
+ /* eslint-disable jsdoc/reject-any-type -- Generic */
17
+ /**
18
+ * @param {any[]} arr
19
+ * @param {number} size
20
+ */
8
21
  const arrayChunk = (arr, size) => {
22
+ /* eslint-enable jsdoc/reject-any-type -- Generic */
9
23
  return Array.from({length: ceil(arr.length / size)}, (_, i) => {
10
24
  const offset = i * size;
11
25
  return arr.slice(offset, offset + size);
@@ -18,16 +32,18 @@ const arrayChunk = (arr, size) => {
18
32
  // files in cache?
19
33
  // Todo: Check `oldVersion` and run this first if still too old
20
34
 
35
+ /* eslint-disable jsdoc/reject-any-type -- Generic */
21
36
  /**
22
37
  * @callback Logger
23
38
  * @param {...any} args
24
39
  * @returns {void}
25
40
  */
41
+ /* eslint-enable jsdoc/reject-any-type -- Generic */
26
42
 
27
43
  /**
28
- * @param {PlainObject} cfg
44
+ * @param {object} cfg
29
45
  * @param {string} cfg.namespace
30
- * @param {string[]} cfg.files
46
+ * @param {string} cfg.files The files.json path
31
47
  * @param {Logger} cfg.log
32
48
  * @param {string} [cfg.basePath]
33
49
  * @returns {Promise<void>}
@@ -41,17 +57,36 @@ export default async function activateCallback ({
41
57
  // already-running versions upon future sw updates
42
58
  log('Activate: Callback called');
43
59
  const r = await fetch(files);
44
- const {groups} = await r.json();
60
+ const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
61
+ await r.json()
62
+ );
45
63
 
64
+ /* eslint-disable jsdoc/reject-any-type -- Generic */
65
+ /**
66
+ * @param {any[]} arr
67
+ * @param {string} path
68
+ */
46
69
  const addJSONFetch = (arr, path) => {
70
+ /* eslint-enable jsdoc/reject-any-type -- Generic */
47
71
  arr.push(
48
72
  (async () => (await fetch(basePath + path)).json())()
49
73
  );
50
74
  };
51
75
 
76
+ /** @type {string[]} */
52
77
  const dataFileNames = [];
78
+
79
+ /** @type {import('./utils/WorkInfo.js').WorkTableContainer[]} */
53
80
  const dataFiles = [];
81
+
82
+ /**
83
+ * @typedef {import('json-schema').JSONSchema4} SchemaFile
84
+ */
85
+
86
+ /** @type {SchemaFile[]} */
54
87
  const schemaFiles = [];
88
+
89
+ /** @type {MetadataFile[]} */
55
90
  const metadataFiles = [];
56
91
  groups.forEach(
57
92
  ({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
@@ -59,8 +94,8 @@ export default async function activateCallback ({
59
94
  // We don't i18nize the name here
60
95
  dataFileNames.push(name);
61
96
  addJSONFetch(dataFiles, filePath);
62
- addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
63
97
  addJSONFetch(schemaFiles, schemaBaseDirectory + '/' + schemaFile);
98
+ addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
64
99
  });
65
100
  }
66
101
  );
@@ -69,18 +104,20 @@ export default async function activateCallback ({
69
104
  ]);
70
105
  const chunked = arrayChunk(promises, dataFiles.length);
71
106
  const [
72
- dataFileResponses, schemaFileResponses, metadataFileResponses
107
+ , schemaFileResponses, metadataFileResponses
73
108
  ] = chunked;
109
+ const dataFileResponses = /** @type {{data: (Integer|string)[][]}[]} */ (chunked[0]);
74
110
 
75
111
  log('Activate: Files fetched');
76
112
  const dbName = namespace + '-textbrowser-cache-data';
77
113
  indexedDB.deleteDatabase(dbName);
78
114
  return new Promise((resolve, reject) => {
79
115
  const req = indexedDB.open(dbName);
116
+ // @ts-expect-error Ok
80
117
  req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
81
118
  db.onversionchange = () => {
82
119
  db.close();
83
- const err = new Error('versionchange');
120
+ const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
84
121
  err.type = 'versionchange';
85
122
  reject(err);
86
123
  };
@@ -90,11 +127,27 @@ export default async function activateCallback ({
90
127
 
91
128
  const schemaFileResponse = schemaFileResponses[i];
92
129
  const metadataFileResponse = metadataFileResponses[i];
93
- const fieldItems = schemaFileResponse.items.items;
130
+ const fieldItems = /** @type {{title: string}[]} */ (
131
+ schemaFileResponse.items.items
132
+ );
94
133
 
95
- let browseFields = metadataFileResponse.table.browse_fields;
134
+ /**
135
+ * @typedef {{
136
+ * name?: string,
137
+ * presort?: boolean,
138
+ * set: string[]
139
+ * }} NameSet
140
+ */
141
+
142
+ let browseFields =
143
+ /**
144
+ * @type {(string|NameSet)[]|NameSet}
145
+ */ (
146
+ metadataFileResponse.table.browse_fields
147
+ );
96
148
  browseFields = Array.isArray(browseFields) ? browseFields : [browseFields];
97
149
 
150
+ /** @type {string[]} */
98
151
  const columnIndexes = [];
99
152
  browseFields.forEach((browseFieldSetObj) => {
100
153
  if (typeof browseFieldSetObj === 'string') {
@@ -133,24 +186,42 @@ export default async function activateCallback ({
133
186
  // Todo: Optionally send notice when complete
134
187
  // To take advantage of indexes on our arrays, we
135
188
  // need to transform them to objects! See https://github.com/w3c/IndexedDB/issues/209
189
+
190
+ /**
191
+ * The `value` property alone contains the latter
192
+ * `(Integer|string)[]` value.
193
+ * @type {{
194
+ * [key: string]: string|Integer|(Integer|string)[]
195
+ * }}
196
+ */
136
197
  const objRow = {
137
198
  value: tableRow
138
199
  };
139
200
  uniqueColumnIndexes.forEach((colIdx) => {
140
- objRow[colIdx] = tableRow[colIdx.slice(1)];
201
+ // Indexed like c0, c1, c2, etc.
202
+ objRow[colIdx] = tableRow[Number.parseInt(colIdx.slice(1))];
141
203
  });
142
204
  // log('objRow', objRow);
143
205
  store.put(objRow, j);
144
206
  });
145
207
  });
146
208
  });
209
+
210
+ // @ts-expect-error Ok
147
211
  req.addEventListener('success', ({target: {result: db}}) => {
148
212
  log('Activate: Database set-up complete', db);
149
213
  // Todo: Replace this with `ready()` check
150
214
  // in calling code?
151
215
  resolve();
152
216
  });
153
- const onerr = ({error = new Error('dbError')}) => {
217
+
218
+ /**
219
+ * @param {Event & {error?: Error}} ev
220
+ */
221
+ const onerr = (ev) => {
222
+ const error = /** @type {Error & {type: string}} */ (
223
+ ev.error ?? new Error('dbError')
224
+ );
154
225
  error.type = 'dbError';
155
226
  reject(error);
156
227
  };