textbrowser 0.49.1 → 0.51.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 (104) hide show
  1. package/.ncurc.cjs +3 -0
  2. package/CHANGES.md +14 -0
  3. package/dist/WorkInfo-es.js +262 -13
  4. package/dist/activateCallback-es.js +72 -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 +860 -134
  16. package/dist/index-es.min.js +2 -2
  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 +274 -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 +46 -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 +22 -9
  80. package/resources/activateCallback.js +75 -10
  81. package/resources/index.js +161 -49
  82. package/resources/resultsDisplay.js +517 -152
  83. package/resources/templates/index.js +39 -16
  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 -75
  89. package/resources/templates/workSelect.js +16 -3
  90. package/resources/utils/IntlURLSearchParams.js +46 -4
  91. package/resources/utils/Languages.js +71 -4
  92. package/resources/utils/Metadata.js +219 -22
  93. package/resources/utils/Params.js +70 -23
  94. package/resources/utils/Plugin.js +169 -1
  95. package/resources/utils/ServiceWorker.js +48 -19
  96. package/resources/utils/WorkInfo.js +255 -43
  97. package/resources/utils/dialogs.js +105 -7
  98. package/resources/utils/getLocaleFallbackResults.js +12 -2
  99. package/resources/utils/sanitize.js +4 -0
  100. package/resources/workDisplay.js +151 -25
  101. package/resources/workSelect.js +37 -17
  102. package/server/main.js +111 -19
  103. package/tsconfig.json +30 -0
  104. 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,46 @@
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 ResultsDisplayServerContext = import("../resources/utils/ServiceWorker.js").ServiceWorkerConfig & UserOptions & {
22
+ lang: string[];
23
+ langs: LanguageInfo[];
24
+ fallbackLanguages: string[];
25
+ log: (...args: any[]) => void;
26
+ nodeActivate?: boolean;
27
+ port?: number;
28
+ skipIndexedDB: false;
29
+ noDynamic: false;
30
+ };
31
+ export type LanguageInfo = {
32
+ code: string;
33
+ direction: "ltr" | "rtl";
34
+ locale: {
35
+ $ref: string;
36
+ };
37
+ };
38
+ export type LocalizationStrings = {
39
+ [key: string]: string | string[] | LocalizationStrings;
40
+ };
41
+ export type LanguagesData = {
42
+ languages: LanguageInfo[];
43
+ localeFileBasePath?: string;
44
+ "localization-strings": LocalizationStrings;
45
+ };
46
+ //# 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;0CA0CS,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,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,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.49.1",
3
+ "version": "0.51.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"
@@ -35,7 +40,7 @@
35
40
  "command-line-args": "^6.0.0",
36
41
  "dom-parser": "^1.1.5",
37
42
  "form-serialization": "^0.11.0",
38
- "indexeddbshim": "^15.2.0",
43
+ "indexeddbshim": "^12.0.0",
39
44
  "intl-dom": "^0.20.0",
40
45
  "intl-locale-textinfo-polyfill": "^2.1.1",
41
46
  "jamilih": "0.60.0",
@@ -43,7 +48,7 @@
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",
@@ -54,27 +59,35 @@
54
59
  "@rollup/plugin-node-resolve": "^15.2.3",
55
60
  "@rollup/plugin-terser": "^0.4.4",
56
61
  "@stadtlandnetz/rollup-plugin-postprocess": "^1.1.0",
62
+ "@types/chai": "^4.3.19",
63
+ "@types/express": "^4.17.21",
64
+ "@types/json-schema": "^7.0.15",
65
+ "@types/mocha": "^10.0.8",
66
+ "@types/node": "^22.5.5",
57
67
  "@web/rollup-plugin-import-meta-assets": "^2.2.1",
58
68
  "ajv": "8.17.1",
59
69
  "babel-plugin-dynamic-import-node": "^2.3.3",
60
70
  "chai": "^5.1.1",
61
- "eslint": "^9.10.0",
62
- "eslint-config-ash-nazg": "^36.17.0",
71
+ "eslint": "^9.11.0",
72
+ "eslint-config-ash-nazg": "^36.17.1",
63
73
  "json-metaschema": "1.3.0",
74
+ "json-schema": "^0.4.0",
64
75
  "mocha": "^10.7.3",
65
76
  "npm-run-all": "^4.1.5",
66
77
  "open-cli": "^8.0.0",
67
- "rollup": "^4.22.0",
78
+ "rollup": "^4.22.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.6.2"
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,7 +4,19 @@
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
+ /**
17
+ * @param {any[]} arr
18
+ * @param {number} size
19
+ */
8
20
  const arrayChunk = (arr, size) => {
9
21
  return Array.from({length: ceil(arr.length / size)}, (_, i) => {
10
22
  const offset = i * size;
@@ -25,9 +37,9 @@ const arrayChunk = (arr, size) => {
25
37
  */
26
38
 
27
39
  /**
28
- * @param {PlainObject} cfg
40
+ * @param {object} cfg
29
41
  * @param {string} cfg.namespace
30
- * @param {string[]} cfg.files
42
+ * @param {string} cfg.files The files.json path
31
43
  * @param {Logger} cfg.log
32
44
  * @param {string} [cfg.basePath]
33
45
  * @returns {Promise<void>}
@@ -41,17 +53,34 @@ export default async function activateCallback ({
41
53
  // already-running versions upon future sw updates
42
54
  log('Activate: Callback called');
43
55
  const r = await fetch(files);
44
- const {groups} = await r.json();
56
+ const {groups} = /** @type {import('./utils/WorkInfo.js').FilesObject} */ (
57
+ await r.json()
58
+ );
45
59
 
60
+ /**
61
+ * @param {any[]} arr
62
+ * @param {string} path
63
+ */
46
64
  const addJSONFetch = (arr, path) => {
47
65
  arr.push(
48
66
  (async () => (await fetch(basePath + path)).json())()
49
67
  );
50
68
  };
51
69
 
70
+ /** @type {string[]} */
52
71
  const dataFileNames = [];
72
+
73
+ /** @type {import('./utils/WorkInfo.js').WorkTableContainer[]} */
53
74
  const dataFiles = [];
75
+
76
+ /**
77
+ * @typedef {import('json-schema').JSONSchema4} SchemaFile
78
+ */
79
+
80
+ /** @type {SchemaFile[]} */
54
81
  const schemaFiles = [];
82
+
83
+ /** @type {MetadataFile[]} */
55
84
  const metadataFiles = [];
56
85
  groups.forEach(
57
86
  ({files: fileObjs, metadataBaseDirectory, schemaBaseDirectory}) => {
@@ -59,8 +88,8 @@ export default async function activateCallback ({
59
88
  // We don't i18nize the name here
60
89
  dataFileNames.push(name);
61
90
  addJSONFetch(dataFiles, filePath);
62
- addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
63
91
  addJSONFetch(schemaFiles, schemaBaseDirectory + '/' + schemaFile);
92
+ addJSONFetch(metadataFiles, metadataBaseDirectory + '/' + metadataFile);
64
93
  });
65
94
  }
66
95
  );
@@ -69,18 +98,20 @@ export default async function activateCallback ({
69
98
  ]);
70
99
  const chunked = arrayChunk(promises, dataFiles.length);
71
100
  const [
72
- dataFileResponses, schemaFileResponses, metadataFileResponses
101
+ , schemaFileResponses, metadataFileResponses
73
102
  ] = chunked;
103
+ const dataFileResponses = /** @type {{data: (Integer|string)[][]}[]} */ (chunked[0]);
74
104
 
75
105
  log('Activate: Files fetched');
76
106
  const dbName = namespace + '-textbrowser-cache-data';
77
107
  indexedDB.deleteDatabase(dbName);
78
108
  return new Promise((resolve, reject) => {
79
109
  const req = indexedDB.open(dbName);
110
+ // @ts-expect-error Ok
80
111
  req.addEventListener('upgradeneeded', ({target: {result: db}}) => {
81
112
  db.onversionchange = () => {
82
113
  db.close();
83
- const err = new Error('versionchange');
114
+ const err = /** @type {Error & {type: string}} */ (new Error('versionchange'));
84
115
  err.type = 'versionchange';
85
116
  reject(err);
86
117
  };
@@ -90,11 +121,27 @@ export default async function activateCallback ({
90
121
 
91
122
  const schemaFileResponse = schemaFileResponses[i];
92
123
  const metadataFileResponse = metadataFileResponses[i];
93
- const fieldItems = schemaFileResponse.items.items;
124
+ const fieldItems = /** @type {{title: string}[]} */ (
125
+ schemaFileResponse.items.items
126
+ );
94
127
 
95
- let browseFields = metadataFileResponse.table.browse_fields;
128
+ /**
129
+ * @typedef {{
130
+ * name?: string,
131
+ * presort?: boolean,
132
+ * set: string[]
133
+ * }} NameSet
134
+ */
135
+
136
+ let browseFields =
137
+ /**
138
+ * @type {(string|NameSet)[]|NameSet}
139
+ */ (
140
+ metadataFileResponse.table.browse_fields
141
+ );
96
142
  browseFields = Array.isArray(browseFields) ? browseFields : [browseFields];
97
143
 
144
+ /** @type {string[]} */
98
145
  const columnIndexes = [];
99
146
  browseFields.forEach((browseFieldSetObj) => {
100
147
  if (typeof browseFieldSetObj === 'string') {
@@ -133,24 +180,42 @@ export default async function activateCallback ({
133
180
  // Todo: Optionally send notice when complete
134
181
  // To take advantage of indexes on our arrays, we
135
182
  // need to transform them to objects! See https://github.com/w3c/IndexedDB/issues/209
183
+
184
+ /**
185
+ * The `value` property alone contains the latter
186
+ * `(Integer|string)[]` value.
187
+ * @type {{
188
+ * [key: string]: string|Integer|(Integer|string)[]
189
+ * }}
190
+ */
136
191
  const objRow = {
137
192
  value: tableRow
138
193
  };
139
194
  uniqueColumnIndexes.forEach((colIdx) => {
140
- objRow[colIdx] = tableRow[colIdx.slice(1)];
195
+ // Indexed like c0, c1, c2, etc.
196
+ objRow[colIdx] = tableRow[Number.parseInt(colIdx.slice(1))];
141
197
  });
142
198
  // log('objRow', objRow);
143
199
  store.put(objRow, j);
144
200
  });
145
201
  });
146
202
  });
203
+
204
+ // @ts-expect-error Ok
147
205
  req.addEventListener('success', ({target: {result: db}}) => {
148
206
  log('Activate: Database set-up complete', db);
149
207
  // Todo: Replace this with `ready()` check
150
208
  // in calling code?
151
209
  resolve();
152
210
  });
153
- const onerr = ({error = new Error('dbError')}) => {
211
+
212
+ /**
213
+ * @param {Event & {error?: Error}} ev
214
+ */
215
+ const onerr = (ev) => {
216
+ const error = /** @type {Error & {type: string}} */ (
217
+ ev.error ?? new Error('dbError')
218
+ );
154
219
  error.type = 'dbError';
155
220
  reject(error);
156
221
  };