@preference-sl/pref-viewer 2.11.0-beta.1 → 2.11.0-beta.11
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/package.json +12 -8
- package/src/babylonjs-animation-controller.js +235 -0
- package/src/babylonjs-animation-opening-menu.js +360 -0
- package/src/babylonjs-animation-opening.js +496 -0
- package/src/babylonjs-controller.js +343 -86
- package/src/css/pref-viewer-2d.css +39 -0
- package/src/css/pref-viewer-3d.css +28 -0
- package/src/css/pref-viewer-dialog.css +105 -0
- package/src/css/pref-viewer.css +11 -0
- package/src/file-storage.js +166 -39
- package/src/index.js +318 -81
- package/src/pref-viewer-2d.js +67 -47
- package/src/pref-viewer-3d.js +328 -84
- package/src/pref-viewer-dialog.js +140 -0
package/src/pref-viewer-2d.js
CHANGED
|
@@ -21,12 +21,17 @@ import PanzoomController from "./panzoom-controller.js";
|
|
|
21
21
|
* - async load(svgConfig) : Promise<boolean> — accept SVG input/config and prepare for render
|
|
22
22
|
* - show(), hide() — toggle visibility and event subscriptions
|
|
23
23
|
* - zoomIn(), zoomOut(), zoomCenter(), zoomExtentsAll() — pan/zoom controls
|
|
24
|
+
*
|
|
25
|
+
* * Public Properties:
|
|
26
|
+
* - isInitialized: Indicates whether the component has completed initialization.
|
|
27
|
+
* - isLoaded: Indicates whether the SVG content is loaded and ready.
|
|
28
|
+
* - isVisible: Indicates whether the component is currently visible.
|
|
24
29
|
*
|
|
25
30
|
* Events
|
|
26
|
-
* - "
|
|
27
|
-
* - "
|
|
28
|
-
* - "
|
|
29
|
-
* - "
|
|
31
|
+
* - "drawing-loading": emitted before loading starts
|
|
32
|
+
* - "drawing-loaded": emitted after content and Panzoom are ready
|
|
33
|
+
* - "drawing-error": emitted on validation/fetch errors (detail.error: Error)
|
|
34
|
+
* - "drawing-zoom-changed": emitted when pan/zoom state changes (detail: { moved, scaled, maximized, minimized })
|
|
30
35
|
*
|
|
31
36
|
* Implementation notes
|
|
32
37
|
* - Keeps internal state in private fields (#svg, #panzoom, #panzoomOptions, ...).
|
|
@@ -80,10 +85,10 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @param {string} name -
|
|
85
|
-
* @param {string|null} _old -
|
|
86
|
-
* @param {string|null} value -
|
|
88
|
+
* Handles changes to observed attributes and updates the component state accordingly.
|
|
89
|
+
* @param {string} name - The name of the changed attribute.
|
|
90
|
+
* @param {string|null} _old - The previous value of the attribute.
|
|
91
|
+
* @param {string|null} value - The new value of the attribute.
|
|
87
92
|
* @returns {void}
|
|
88
93
|
* @description
|
|
89
94
|
* - "svg": triggers load of new SVG content.
|
|
@@ -119,6 +124,11 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
119
124
|
this.#loadSVG();
|
|
120
125
|
}
|
|
121
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Called when the element is removed from the DOM.
|
|
129
|
+
* Disables the PanzoomController to clean up event listeners and resources.
|
|
130
|
+
* @returns {void}
|
|
131
|
+
*/
|
|
122
132
|
disconnectedCallback() {
|
|
123
133
|
if (this.#panzoomController) {
|
|
124
134
|
this.#panzoomController.disable();
|
|
@@ -134,7 +144,8 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
134
144
|
this.#wrapper = document.createElement("div");
|
|
135
145
|
this.append(this.#wrapper);
|
|
136
146
|
const style = document.createElement("style");
|
|
137
|
-
|
|
147
|
+
const cssUrl = new URL("./css/pref-viewer-2d.css", import.meta.url);
|
|
148
|
+
style.textContent = `@import "${cssUrl}";`;
|
|
138
149
|
this.append(style);
|
|
139
150
|
}
|
|
140
151
|
|
|
@@ -203,20 +214,21 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
203
214
|
}
|
|
204
215
|
|
|
205
216
|
/**
|
|
206
|
-
*
|
|
217
|
+
* Handles invalid or unsupported SVG input by emitting a custom error event.
|
|
207
218
|
* @private
|
|
208
|
-
* @returns {
|
|
219
|
+
* @returns {object} Detail object with an Error describing the SVG input issue.
|
|
209
220
|
*/
|
|
210
221
|
#onError() {
|
|
211
222
|
const error = "PrefViewer2D: Error in SVG provided for loading. Ensure the SVG is a URL to an SVG file, a string containing a SVG, or a string containing a base64-encoded SVG.";
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
);
|
|
223
|
+
const detail = { error: new Error(error) };
|
|
224
|
+
const customEventOptions = {
|
|
225
|
+
bubbles: true, // indicates whether the event bubbles up through the DOM tree or not
|
|
226
|
+
cancelable: true, // indicates whether the event can be canceled, and therefore prevented as if the event never happened
|
|
227
|
+
composed: false, // indicates whether or not the event will propagate across the shadow DOM boundary into the standard DOM
|
|
228
|
+
detail: detail,
|
|
229
|
+
};
|
|
230
|
+
this.dispatchEvent(new CustomEvent("drawing-error", customEventOptions));
|
|
231
|
+
return detail;
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
/**
|
|
@@ -225,13 +237,12 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
225
237
|
* @returns {void}
|
|
226
238
|
*/
|
|
227
239
|
#onLoaded() {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
);
|
|
240
|
+
const customEventOptions = {
|
|
241
|
+
bubbles: true,
|
|
242
|
+
cancelable: true,
|
|
243
|
+
composed: false,
|
|
244
|
+
};
|
|
245
|
+
this.dispatchEvent(new CustomEvent("drawing-loaded", customEventOptions));
|
|
235
246
|
|
|
236
247
|
this.removeAttribute("loading");
|
|
237
248
|
this.setAttribute("loaded", "");
|
|
@@ -246,13 +257,12 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
246
257
|
* @returns {void}
|
|
247
258
|
*/
|
|
248
259
|
#onLoading() {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
);
|
|
260
|
+
const customEventOptions = {
|
|
261
|
+
bubbles: true,
|
|
262
|
+
cancelable: true,
|
|
263
|
+
composed: false,
|
|
264
|
+
};
|
|
265
|
+
this.dispatchEvent(new CustomEvent("drawing-loading", customEventOptions));
|
|
256
266
|
|
|
257
267
|
this.removeAttribute("loaded");
|
|
258
268
|
this.setAttribute("loading", "");
|
|
@@ -274,10 +284,20 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
274
284
|
* the UI with the enabled/disabled status of the zoomIn, zoomOut, center, and zoomExtentsAll buttons.
|
|
275
285
|
*/
|
|
276
286
|
#onPanzoomChanged(state) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
287
|
+
const customEventOptions = {
|
|
288
|
+
bubbles: true,
|
|
289
|
+
cancelable: true,
|
|
290
|
+
composed: false,
|
|
291
|
+
detail: state,
|
|
292
|
+
};
|
|
293
|
+
customEventOptions.detail.desde2d = "true";
|
|
294
|
+
this.dispatchEvent(new CustomEvent("drawing-zoom-changed", customEventOptions));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Subscribe DOM events required by Panzoom and keyboard interactions.
|
|
299
|
+
* @private
|
|
300
|
+
* @returns {void}
|
|
281
301
|
composed: true,
|
|
282
302
|
detail: state,
|
|
283
303
|
})
|
|
@@ -325,17 +345,17 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
325
345
|
* @param {object} svgConfig - SVG configuration. An object with a `storage` property describing the source:
|
|
326
346
|
* { storage: { url: "<url>" } }
|
|
327
347
|
* or { storage: { db: "<db>", table: "<table>", id: "<id>" } }
|
|
328
|
-
* @returns {Promise<boolean|
|
|
329
|
-
* - Resolves to false when the input is invalid or the SVG could not be retrieved/decoded, or when there is no update required (cached copy unchanged).
|
|
330
|
-
* - Resolves to true when the SVG was accepted and the component has started rendering.
|
|
348
|
+
* @returns {Promise<{success: boolean, error: Error|null}>}
|
|
349
|
+
* - Resolves to { success: false, error: <Error> } when the input is invalid or the SVG could not be retrieved/decoded, or when there is no update required (cached copy unchanged).
|
|
350
|
+
* - Resolves to { success: true, error: null } when the SVG was accepted and the component has started rendering.
|
|
331
351
|
*/
|
|
332
352
|
async load(svgConfig) {
|
|
333
353
|
if (!svgConfig || !(await this.#svgResolver.getSVG(svgConfig))) {
|
|
334
|
-
this.#onError();
|
|
335
|
-
return false;
|
|
354
|
+
const errorDetail = this.#onError();
|
|
355
|
+
return { success: false, ...errorDetail };
|
|
336
356
|
}
|
|
337
|
-
this.#isInitialized && this.#loadSVG();
|
|
338
|
-
return
|
|
357
|
+
const success = this.#isInitialized && this.#loadSVG();
|
|
358
|
+
return { success: success, error: null };
|
|
339
359
|
}
|
|
340
360
|
|
|
341
361
|
/**
|
|
@@ -417,7 +437,7 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
417
437
|
* @public
|
|
418
438
|
* @returns {boolean} True if the component is initialized; otherwise, false.
|
|
419
439
|
*/
|
|
420
|
-
get
|
|
440
|
+
get isInitialized() {
|
|
421
441
|
return this.#isInitialized;
|
|
422
442
|
}
|
|
423
443
|
|
|
@@ -426,7 +446,7 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
426
446
|
* @public
|
|
427
447
|
* @returns {boolean} True if the SVG is loaded; otherwise, false.
|
|
428
448
|
*/
|
|
429
|
-
get
|
|
449
|
+
get isLoaded() {
|
|
430
450
|
return this.#isLoaded;
|
|
431
451
|
}
|
|
432
452
|
|
|
@@ -435,7 +455,7 @@ export class PrefViewer2D extends HTMLElement {
|
|
|
435
455
|
* @public
|
|
436
456
|
* @returns {boolean} True if the component is visible; otherwise, false.
|
|
437
457
|
*/
|
|
438
|
-
get
|
|
458
|
+
get isVisible() {
|
|
439
459
|
return this.#isVisible;
|
|
440
460
|
}
|
|
441
461
|
}
|