@design.estate/dees-catalog 6.12.1 → 7.0.1
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/.smartconfig.json +5 -1
- package/dist_bundle/bundle.js +24145 -1247
- package/dist_bundle/bundle.js.map +1 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/.tsbundle-artifacts.json +7 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/worker-KZQQYSUG.js +58301 -0
- package/dist_bundle/chunks/U6Ua8p1giFoD1s7vrUZUdpbg/worker-KZQQYSUG.js.map +1 -0
- package/dist_bundle/third-party-notices.md +190 -0
- package/dist_ts_web/00_commitinfo_data.js +2 -2
- package/dist_ts_web/elements/00group-button/dees-button/dees-button.d.ts +8 -5
- package/dist_ts_web/elements/00group-button/dees-button/dees-button.js +100 -46
- package/dist_ts_web/elements/00group-form/dees-form-submit/dees-form-submit.js +2 -5
- package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.d.ts +4 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.js +29 -2
- package/dist_ts_web/elements/00group-harness/dees-harness-session-sidebar/dees-harness-session-sidebar.d.ts +4 -1
- package/dist_ts_web/elements/00group-harness/dees-harness-session-sidebar/dees-harness-session-sidebar.js +65 -8
- package/dist_ts_web/elements/00group-harness/interfaces.d.ts +1 -0
- package/dist_ts_web/elements/00group-media/dees-pdf-shared/CanvasPool.d.ts +1 -0
- package/dist_ts_web/elements/00group-media/dees-pdf-shared/CanvasPool.js +15 -1
- package/dist_ts_web/elements/00group-media/dees-pdf-shared/PdfManager.d.ts +6 -4
- package/dist_ts_web/elements/00group-media/dees-pdf-shared/PdfManager.js +183 -21
- package/dist_ts_web/elements/00group-media/dees-pdf-shared/utils.d.ts +3 -0
- package/dist_ts_web/elements/00group-media/dees-pdf-shared/utils.js +67 -1
- package/dist_ts_web/elements/00group-media/dees-pdf-viewer/component.d.ts +25 -1
- package/dist_ts_web/elements/00group-media/dees-pdf-viewer/component.js +693 -285
- package/dist_ts_web/elements/00group-media/dees-pdf-viewer/demo.js +7 -7
- package/dist_ts_web/elements/00group-media/dees-thumbnail-pdf/component.d.ts +20 -1
- package/dist_ts_web/elements/00group-media/dees-thumbnail-pdf/component.js +379 -116
- package/dist_ts_web/elements/00group-media/dees-thumbnail-pdf/demo.js +2 -2
- package/dist_ts_web/elements/00group-media/dees-thumbnail-shared/DeesThumbnailBase.d.ts +1 -0
- package/dist_ts_web/elements/00group-media/dees-thumbnail-shared/DeesThumbnailBase.js +7 -1
- package/dist_ts_web/elements/00group-utility/dees-icon/dees-icon.js +2 -1
- package/package.json +5 -4
- package/readme.hints.md +26 -19
- package/readme.md +100 -53
- package/third-party-notices.md +190 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements/00group-button/dees-button/dees-button.ts +97 -53
- package/ts_web/elements/00group-form/dees-form-submit/dees-form-submit.ts +1 -4
- package/ts_web/elements/00group-harness/dees-harness-chat/dees-harness-chat.ts +13 -0
- package/ts_web/elements/00group-harness/dees-harness-session-sidebar/dees-harness-session-sidebar.ts +51 -6
- package/ts_web/elements/00group-harness/interfaces.ts +2 -0
- package/ts_web/elements/00group-media/dees-pdf-shared/CanvasPool.ts +15 -1
- package/ts_web/elements/00group-media/dees-pdf-shared/PdfManager.ts +214 -24
- package/ts_web/elements/00group-media/dees-pdf-shared/utils.ts +77 -1
- package/ts_web/elements/00group-media/dees-pdf-viewer/component.ts +774 -327
- package/ts_web/elements/00group-media/dees-pdf-viewer/demo.ts +7 -7
- package/ts_web/elements/00group-media/dees-thumbnail-pdf/component.ts +427 -128
- package/ts_web/elements/00group-media/dees-thumbnail-pdf/demo.ts +1 -1
- package/ts_web/elements/00group-media/dees-thumbnail-shared/DeesThumbnailBase.ts +5 -0
- package/ts_web/elements/00group-utility/dees-icon/dees-icon.ts +1 -0
|
@@ -1,36 +1,226 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getDocument,
|
|
3
|
+
PDFWorker,
|
|
4
|
+
type PDFDocumentLoadingTask,
|
|
5
|
+
type PDFDocumentProxy,
|
|
6
|
+
} from 'pdfjs-dist';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
interface IPdfDocumentResources {
|
|
9
|
+
workerPort: Worker;
|
|
10
|
+
networkAbortController: AbortController;
|
|
11
|
+
pdfWorker?: PDFWorker;
|
|
12
|
+
loadingTask?: PDFDocumentLoadingTask;
|
|
13
|
+
document?: PDFDocumentProxy;
|
|
14
|
+
abortSignal?: AbortSignal;
|
|
15
|
+
abortListener?: () => void;
|
|
16
|
+
workerErrorListener?: (eventArg: Event) => void;
|
|
17
|
+
firstError?: Error;
|
|
18
|
+
workerFailed: boolean;
|
|
19
|
+
interruptionPromise: Promise<Error>;
|
|
20
|
+
resolveInterruption: (errorArg: Error) => void;
|
|
21
|
+
workerFailurePromise: Promise<void>;
|
|
22
|
+
resolveWorkerFailure: () => void;
|
|
23
|
+
releasePromise?: Promise<void>;
|
|
24
|
+
}
|
|
6
25
|
|
|
7
|
-
|
|
8
|
-
|
|
26
|
+
const normalizeError = (errorArg: unknown): Error => (
|
|
27
|
+
errorArg instanceof Error ? errorArg : new Error(String(errorArg))
|
|
28
|
+
);
|
|
9
29
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
const createAbortError = (): Error => {
|
|
31
|
+
const error = new Error('PDF load aborted');
|
|
32
|
+
error.name = 'AbortError';
|
|
33
|
+
return error;
|
|
34
|
+
};
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
}
|
|
36
|
+
const workerTerminationGraceMs = 2_000;
|
|
16
37
|
|
|
17
|
-
|
|
18
|
-
|
|
38
|
+
export class PdfManager {
|
|
39
|
+
private static readonly resourcesByDocument = new WeakMap<
|
|
40
|
+
PDFDocumentProxy,
|
|
41
|
+
IPdfDocumentResources
|
|
42
|
+
>();
|
|
43
|
+
private static readonly releasedDocuments = new WeakSet<PDFDocumentProxy>();
|
|
19
44
|
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
45
|
+
public static async initialize(): Promise<void> {
|
|
46
|
+
// PDF.js is loaded statically; retained for existing callers.
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public static async loadDocument(
|
|
50
|
+
urlArg: string,
|
|
51
|
+
signalArg?: AbortSignal,
|
|
52
|
+
): Promise<PDFDocumentProxy> {
|
|
53
|
+
const workerPort = new Worker(
|
|
54
|
+
new URL('pdfjs-dist/build/pdf.worker.mjs', import.meta.url),
|
|
55
|
+
{ type: 'module' },
|
|
56
|
+
);
|
|
57
|
+
let resolveInterruption!: (errorArg: Error) => void;
|
|
58
|
+
const interruptionPromise = new Promise<Error>((resolve) => {
|
|
59
|
+
resolveInterruption = resolve;
|
|
60
|
+
});
|
|
61
|
+
let resolveWorkerFailure!: () => void;
|
|
62
|
+
const workerFailurePromise = new Promise<void>((resolve) => {
|
|
63
|
+
resolveWorkerFailure = resolve;
|
|
64
|
+
});
|
|
65
|
+
const resources: IPdfDocumentResources = {
|
|
66
|
+
workerPort,
|
|
67
|
+
networkAbortController: new AbortController(),
|
|
68
|
+
workerFailed: false,
|
|
69
|
+
interruptionPromise,
|
|
70
|
+
resolveInterruption,
|
|
71
|
+
workerFailurePromise,
|
|
72
|
+
resolveWorkerFailure,
|
|
73
|
+
};
|
|
74
|
+
const recordInterruption = (errorArg: Error): void => {
|
|
75
|
+
if (!resources.firstError) {
|
|
76
|
+
resources.firstError = errorArg;
|
|
77
|
+
resources.resolveInterruption(errorArg);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
resources.workerErrorListener = (eventArg: Event): void => {
|
|
81
|
+
if (!resources.workerFailed) {
|
|
82
|
+
resources.workerFailed = true;
|
|
83
|
+
resources.resolveWorkerFailure();
|
|
84
|
+
}
|
|
85
|
+
const message = eventArg instanceof ErrorEvent && eventArg.message
|
|
86
|
+
? eventArg.message
|
|
87
|
+
: 'PDF worker failed';
|
|
88
|
+
recordInterruption(new Error(message));
|
|
89
|
+
void this.releaseResources(resources).catch(() => {});
|
|
90
|
+
};
|
|
91
|
+
workerPort.addEventListener('error', resources.workerErrorListener);
|
|
25
92
|
|
|
26
|
-
|
|
93
|
+
try {
|
|
94
|
+
if (signalArg) {
|
|
95
|
+
resources.abortSignal = signalArg;
|
|
96
|
+
resources.abortListener = (): void => {
|
|
97
|
+
recordInterruption(createAbortError());
|
|
98
|
+
void this.releaseResources(resources).catch(() => {});
|
|
99
|
+
};
|
|
100
|
+
signalArg.addEventListener('abort', resources.abortListener, { once: true });
|
|
101
|
+
if (signalArg.aborted) {
|
|
102
|
+
resources.abortListener();
|
|
103
|
+
throw resources.firstError || createAbortError();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
resources.pdfWorker = PDFWorker.fromPort({ port: workerPort }) as PDFWorker;
|
|
107
|
+
const response = await Promise.race([
|
|
108
|
+
fetch(urlArg, {
|
|
109
|
+
signal: resources.networkAbortController.signal,
|
|
110
|
+
}),
|
|
111
|
+
resources.interruptionPromise.then((errorArg) => {
|
|
112
|
+
throw errorArg;
|
|
113
|
+
}),
|
|
114
|
+
]);
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
throw new Error(`Failed to load PDF (${response.status} ${response.statusText})`);
|
|
117
|
+
}
|
|
118
|
+
const data = new Uint8Array(await Promise.race([
|
|
119
|
+
response.arrayBuffer(),
|
|
120
|
+
resources.interruptionPromise.then((errorArg) => {
|
|
121
|
+
throw errorArg;
|
|
122
|
+
}),
|
|
123
|
+
]));
|
|
124
|
+
resources.loadingTask = getDocument({
|
|
125
|
+
data,
|
|
126
|
+
docBaseUrl: response.url || urlArg,
|
|
127
|
+
worker: resources.pdfWorker,
|
|
128
|
+
});
|
|
129
|
+
const document = await Promise.race([
|
|
130
|
+
resources.loadingTask.promise,
|
|
131
|
+
resources.interruptionPromise.then((errorArg) => {
|
|
132
|
+
throw errorArg;
|
|
133
|
+
}),
|
|
134
|
+
]);
|
|
135
|
+
if (signalArg?.aborted) {
|
|
136
|
+
resources.abortListener?.();
|
|
137
|
+
throw resources.firstError || createAbortError();
|
|
138
|
+
}
|
|
139
|
+
if (resources.abortSignal && resources.abortListener) {
|
|
140
|
+
resources.abortSignal.removeEventListener('abort', resources.abortListener);
|
|
141
|
+
resources.abortSignal = undefined;
|
|
142
|
+
resources.abortListener = undefined;
|
|
143
|
+
}
|
|
144
|
+
resources.document = document;
|
|
145
|
+
this.resourcesByDocument.set(document, resources);
|
|
146
|
+
return document;
|
|
147
|
+
} catch (error: unknown) {
|
|
148
|
+
recordInterruption(normalizeError(error));
|
|
149
|
+
try {
|
|
150
|
+
await this.releaseResources(resources);
|
|
151
|
+
} catch {
|
|
152
|
+
// Preserve the load, abort, or worker error that initiated cleanup.
|
|
153
|
+
}
|
|
154
|
+
throw resources.firstError;
|
|
155
|
+
}
|
|
27
156
|
}
|
|
28
157
|
|
|
29
|
-
public static releaseDocument(
|
|
30
|
-
|
|
31
|
-
|
|
158
|
+
public static async releaseDocument(
|
|
159
|
+
documentArg: PDFDocumentProxy | null | undefined,
|
|
160
|
+
): Promise<void> {
|
|
161
|
+
if (!documentArg) return;
|
|
162
|
+
if (this.releasedDocuments.has(documentArg)) return;
|
|
163
|
+
const resources = this.resourcesByDocument.get(documentArg);
|
|
164
|
+
if (!resources) {
|
|
165
|
+
await documentArg.destroy();
|
|
166
|
+
this.releasedDocuments.add(documentArg);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
await this.releaseResources(resources);
|
|
32
170
|
}
|
|
33
171
|
|
|
34
|
-
|
|
35
|
-
|
|
172
|
+
private static releaseResources(resourcesArg: IPdfDocumentResources): Promise<void> {
|
|
173
|
+
if (!resourcesArg.releasePromise) {
|
|
174
|
+
let resolveRelease!: () => void;
|
|
175
|
+
let rejectRelease!: (errorArg: unknown) => void;
|
|
176
|
+
resourcesArg.releasePromise = new Promise<void>((resolve, reject) => {
|
|
177
|
+
resolveRelease = resolve;
|
|
178
|
+
rejectRelease = reject;
|
|
179
|
+
});
|
|
180
|
+
void (async () => {
|
|
181
|
+
resourcesArg.networkAbortController.abort();
|
|
182
|
+
try {
|
|
183
|
+
if (resourcesArg.loadingTask) {
|
|
184
|
+
const loadingTaskDestroyPromise = resourcesArg.loadingTask.destroy();
|
|
185
|
+
void loadingTaskDestroyPromise.catch(() => {});
|
|
186
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
187
|
+
const timeoutPromise = new Promise<void>((resolve) => {
|
|
188
|
+
timeout = setTimeout(resolve, workerTerminationGraceMs);
|
|
189
|
+
});
|
|
190
|
+
try {
|
|
191
|
+
await Promise.race([
|
|
192
|
+
loadingTaskDestroyPromise,
|
|
193
|
+
resourcesArg.workerFailurePromise,
|
|
194
|
+
timeoutPromise,
|
|
195
|
+
]);
|
|
196
|
+
} finally {
|
|
197
|
+
if (timeout) {
|
|
198
|
+
clearTimeout(timeout);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} finally {
|
|
203
|
+
try {
|
|
204
|
+
resourcesArg.pdfWorker?.destroy();
|
|
205
|
+
} finally {
|
|
206
|
+
if (resourcesArg.abortSignal && resourcesArg.abortListener) {
|
|
207
|
+
resourcesArg.abortSignal.removeEventListener('abort', resourcesArg.abortListener);
|
|
208
|
+
}
|
|
209
|
+
if (resourcesArg.workerErrorListener) {
|
|
210
|
+
resourcesArg.workerPort.removeEventListener('error', resourcesArg.workerErrorListener);
|
|
211
|
+
}
|
|
212
|
+
resourcesArg.workerPort.terminate();
|
|
213
|
+
if (resourcesArg.document) {
|
|
214
|
+
this.releasedDocuments.add(resourcesArg.document);
|
|
215
|
+
this.resourcesByDocument.delete(resourcesArg.document);
|
|
216
|
+
}
|
|
217
|
+
resourcesArg.document = undefined;
|
|
218
|
+
resourcesArg.loadingTask = undefined;
|
|
219
|
+
resourcesArg.pdfWorker = undefined;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
})().then(resolveRelease, rejectRelease);
|
|
223
|
+
}
|
|
224
|
+
return resourcesArg.releasePromise;
|
|
225
|
+
}
|
|
36
226
|
}
|
|
@@ -40,6 +40,82 @@ export function formatFileSize(bytes: number): string {
|
|
|
40
40
|
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
export async function settlePromisesWithin(
|
|
44
|
+
promisesArg: readonly Promise<unknown>[],
|
|
45
|
+
timeoutMsArg: number,
|
|
46
|
+
): Promise<boolean> {
|
|
47
|
+
if (promisesArg.length === 0) return true;
|
|
48
|
+
|
|
49
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
50
|
+
try {
|
|
51
|
+
return await Promise.race([
|
|
52
|
+
Promise.allSettled(promisesArg).then(() => true),
|
|
53
|
+
new Promise<boolean>((resolve) => {
|
|
54
|
+
timeout = setTimeout(() => resolve(false), timeoutMsArg);
|
|
55
|
+
}),
|
|
56
|
+
]);
|
|
57
|
+
} finally {
|
|
58
|
+
if (timeout) clearTimeout(timeout);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function raceWithAbort<T>(
|
|
63
|
+
promiseArg: Promise<T>,
|
|
64
|
+
signalArg: AbortSignal,
|
|
65
|
+
): Promise<T> {
|
|
66
|
+
const abortError = (): Error => {
|
|
67
|
+
const error = new Error('Operation aborted');
|
|
68
|
+
error.name = 'AbortError';
|
|
69
|
+
return error;
|
|
70
|
+
};
|
|
71
|
+
if (signalArg.aborted) {
|
|
72
|
+
void promiseArg.catch(() => {});
|
|
73
|
+
return Promise.reject(abortError());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new Promise<T>((resolve, reject) => {
|
|
77
|
+
let settled = false;
|
|
78
|
+
const finish = (callbackArg: () => void): void => {
|
|
79
|
+
if (settled) return;
|
|
80
|
+
settled = true;
|
|
81
|
+
signalArg.removeEventListener('abort', handleAbort);
|
|
82
|
+
callbackArg();
|
|
83
|
+
};
|
|
84
|
+
const handleAbort = (): void => {
|
|
85
|
+
finish(() => reject(abortError()));
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
signalArg.addEventListener('abort', handleAbort, { once: true });
|
|
89
|
+
void promiseArg.then(
|
|
90
|
+
(valueArg) => finish(() => resolve(valueArg)),
|
|
91
|
+
(errorArg) => finish(() => reject(errorArg)),
|
|
92
|
+
);
|
|
93
|
+
if (signalArg.aborted) handleAbort();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const waitForAnimationFrame = (signalArg?: AbortSignal): Promise<void> => new Promise((resolve) => {
|
|
98
|
+
if (signalArg?.aborted) {
|
|
99
|
+
resolve();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let settled = false;
|
|
104
|
+
let frame = 0;
|
|
105
|
+
let timeout = 0;
|
|
106
|
+
const finish = () => {
|
|
107
|
+
if (settled) return;
|
|
108
|
+
settled = true;
|
|
109
|
+
cancelAnimationFrame(frame);
|
|
110
|
+
window.clearTimeout(timeout);
|
|
111
|
+
signalArg?.removeEventListener('abort', finish);
|
|
112
|
+
resolve();
|
|
113
|
+
};
|
|
114
|
+
frame = requestAnimationFrame(finish);
|
|
115
|
+
timeout = window.setTimeout(finish, 100);
|
|
116
|
+
signalArg?.addEventListener('abort', finish, { once: true });
|
|
117
|
+
});
|
|
118
|
+
|
|
43
119
|
export function isInViewport(element: Element, margin = 0): boolean {
|
|
44
120
|
const rect = element.getBoundingClientRect();
|
|
45
121
|
return (
|
|
@@ -95,4 +171,4 @@ export class PerformanceMonitor {
|
|
|
95
171
|
this.marks.clear();
|
|
96
172
|
this.measures = [];
|
|
97
173
|
}
|
|
98
|
-
}
|
|
174
|
+
}
|