|
1 | | -import * as itk from 'itk-wasm' |
2 | | -globalThis.itk = itk |
| 1 | +import * as itk from "itk-wasm"; |
| 2 | +globalThis.itk = itk; |
3 | 3 |
|
4 | 4 | function downloadFile(content, filename) { |
5 | | - const url = URL.createObjectURL(new Blob([content])) |
6 | | - const a = document.createElement('a') |
7 | | - a.href = url |
8 | | - a.download = filename || 'download' |
9 | | - document.body.appendChild(a) |
| 5 | + // Handle shared ArrayBuffers by creating a copy |
| 6 | + let blobContent = content; |
| 7 | + if (content instanceof ArrayBuffer || ArrayBuffer.isView(content)) { |
| 8 | + // Create a copy to avoid shared ArrayBuffer issues |
| 9 | + const buffer = content instanceof ArrayBuffer ? content : content.buffer; |
| 10 | + const copy = new ArrayBuffer(buffer.byteLength); |
| 11 | + new Uint8Array(copy).set(new Uint8Array(buffer)); |
| 12 | + blobContent = copy; |
| 13 | + } |
| 14 | + |
| 15 | + const url = URL.createObjectURL(new Blob([blobContent])); |
| 16 | + const a = document.createElement("a"); |
| 17 | + a.href = url; |
| 18 | + a.download = filename || "download"; |
| 19 | + document.body.appendChild(a); |
10 | 20 | function clickHandler(event) { |
11 | 21 | setTimeout(() => { |
12 | | - URL.revokeObjectURL(url) |
13 | | - a.removeEventListener('click', clickHandler) |
14 | | - }, 200) |
15 | | - }; |
16 | | - a.addEventListener('click', clickHandler, false) |
17 | | - a.click() |
18 | | - return a |
| 22 | + URL.revokeObjectURL(url); |
| 23 | + a.removeEventListener("click", clickHandler); |
| 24 | + }, 200); |
| 25 | + } |
| 26 | + a.addEventListener("click", clickHandler, false); |
| 27 | + a.click(); |
| 28 | + return a; |
19 | 29 | } |
20 | | -globalThis.downloadFile = downloadFile |
| 30 | +globalThis.downloadFile = downloadFile; |
21 | 31 |
|
22 | | -function interfaceTypeJsonReplacer (key, value) { |
| 32 | +function interfaceTypeJsonReplacer(key, value) { |
23 | 33 | if (!!value && value.byteLength !== undefined) { |
24 | | - return String(value.slice(0, 6)) + '...' |
| 34 | + return String(value.slice(0, 6)) + "..."; |
25 | 35 | } |
26 | | - return value |
| 36 | + return value; |
27 | 37 | } |
28 | | -globalThis.interfaceTypeJsonReplacer = interfaceTypeJsonReplacer |
| 38 | +globalThis.interfaceTypeJsonReplacer = interfaceTypeJsonReplacer; |
29 | 39 |
|
30 | 40 | function escapeHtml(html) { |
31 | | - const div = document.createElement('div'); |
| 41 | + const div = document.createElement("div"); |
32 | 42 | div.textContent = html; |
33 | 43 | const escaped = div.innerHTML; |
34 | | - div.remove() |
35 | | - return escaped |
| 44 | + div.remove(); |
| 45 | + return escaped; |
36 | 46 | } |
37 | | -globalThis.escapeHtml = escapeHtml |
| 47 | +globalThis.escapeHtml = escapeHtml; |
38 | 48 |
|
39 | | -function notify(title, message, variant = 'primary', icon = 'info-circle', duration = 3000) { |
40 | | - const slAlert = Object.assign(document.createElement('sl-alert'), { |
| 49 | +function notify( |
| 50 | + title, |
| 51 | + message, |
| 52 | + variant = "primary", |
| 53 | + icon = "info-circle", |
| 54 | + duration = 3000 |
| 55 | +) { |
| 56 | + const slAlert = Object.assign(document.createElement("sl-alert"), { |
41 | 57 | variant, |
42 | 58 | closable: true, |
43 | 59 | duration: duration, |
44 | 60 | innerHTML: ` |
45 | 61 | <sl-icon name="${icon}" slot="icon"></sl-icon> |
46 | 62 | <strong>${escapeHtml(title)}</strong><br /> |
47 | 63 | ${escapeHtml(message)} |
48 | | - ` |
| 64 | + `, |
49 | 65 | }); |
50 | 66 |
|
51 | 67 | document.body.append(slAlert); |
52 | | - setTimeout(() => slAlert.toast(), 300) |
| 68 | + setTimeout(() => slAlert.toast(), 300); |
53 | 69 | } |
54 | | -globalThis.notify = notify |
| 70 | +globalThis.notify = notify; |
55 | 71 |
|
56 | 72 | function disableInputs(inputId) { |
57 | | - document.querySelectorAll(`#${inputId} sl-button`).forEach(button => { |
58 | | - button.disabled = true |
59 | | - }) |
60 | | - document.querySelector(`#${inputId} sl-button[name="run"]`).loading = true |
61 | | - document.querySelectorAll(`#${inputId} sl-checkbox`).forEach(checkbox => { |
62 | | - checkbox.disabled = true |
63 | | - }) |
64 | | - document.querySelectorAll(`#${inputId} sl-input`).forEach(input => { |
65 | | - input.disabled = true |
66 | | - }) |
| 73 | + document.querySelectorAll(`#${inputId} sl-button`).forEach((button) => { |
| 74 | + button.disabled = true; |
| 75 | + }); |
| 76 | + document.querySelector(`#${inputId} sl-button[name="run"]`).loading = true; |
| 77 | + document.querySelectorAll(`#${inputId} sl-checkbox`).forEach((checkbox) => { |
| 78 | + checkbox.disabled = true; |
| 79 | + }); |
| 80 | + document.querySelectorAll(`#${inputId} sl-input`).forEach((input) => { |
| 81 | + input.disabled = true; |
| 82 | + }); |
67 | 83 | } |
68 | | -globalThis.disableInputs = disableInputs |
| 84 | +globalThis.disableInputs = disableInputs; |
69 | 85 |
|
70 | 86 | function enableInputs(inputId) { |
71 | | - document.querySelectorAll(`#${inputId} sl-button`).forEach(button => { |
72 | | - button.disabled = false |
73 | | - }) |
74 | | - document.querySelector(`#${inputId} sl-button[name="run"]`).loading = false |
75 | | - document.querySelectorAll(`#${inputId} sl-checkbox`).forEach(checkbox => { |
76 | | - checkbox.disabled = false |
77 | | - }) |
78 | | - document.querySelectorAll(`#${inputId} sl-input`).forEach(input => { |
79 | | - input.disabled = false |
80 | | - }) |
| 87 | + document.querySelectorAll(`#${inputId} sl-button`).forEach((button) => { |
| 88 | + button.disabled = false; |
| 89 | + }); |
| 90 | + document.querySelector(`#${inputId} sl-button[name="run"]`).loading = false; |
| 91 | + document.querySelectorAll(`#${inputId} sl-checkbox`).forEach((checkbox) => { |
| 92 | + checkbox.disabled = false; |
| 93 | + }); |
| 94 | + document.querySelectorAll(`#${inputId} sl-input`).forEach((input) => { |
| 95 | + input.disabled = false; |
| 96 | + }); |
81 | 97 | } |
82 | | -globalThis.enableInputs = enableInputs |
| 98 | +globalThis.enableInputs = enableInputs; |
83 | 99 |
|
84 | 100 | function applyInputParsedJson(inputElement, modelMap, parameterName) { |
85 | 101 | try { |
86 | | - const parsedJson = JSON.parse(inputElement.value) |
87 | | - modelMap.set(parameterName, parsedJson) |
88 | | - inputElement.setCustomValidity('') |
| 102 | + const parsedJson = JSON.parse(inputElement.value); |
| 103 | + modelMap.set(parameterName, parsedJson); |
| 104 | + inputElement.setCustomValidity(""); |
89 | 105 | } catch (error) { |
90 | | - inputElement.setCustomValidity(error.message) |
| 106 | + inputElement.setCustomValidity(error.message); |
91 | 107 | } |
92 | 108 | } |
93 | | -globalThis.applyInputParsedJson = applyInputParsedJson |
| 109 | +globalThis.applyInputParsedJson = applyInputParsedJson; |
0 commit comments