Kokkoja: first public assembly
Assembled from the development repository by tools/make_release.sh. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
95c80d04c9
39 files changed
+9905
No files matched your search
@@ -0,0 +1,38 @@
|
||||
// @ts-check
|
||||
/**
|
||||
* Files without the local program: when Kokkoja is opened from a web
|
||||
* site, an image file comes from the browser's own file chooser, and
|
||||
* anything to be saved is a download.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Let the user choose an image file.
|
||||
* @returns {Promise<File | null>} Null if none was chosen.
|
||||
*/
|
||||
export function pickImageFile() {
|
||||
return new Promise((resolve) => {
|
||||
const picker = document.createElement('input');
|
||||
picker.type = 'file';
|
||||
picker.accept = 'image/*';
|
||||
picker.addEventListener('change', () => resolve(picker.files?.[0] ?? null));
|
||||
picker.addEventListener('cancel', () => resolve(null));
|
||||
picker.click();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Give the user a file, through the browser's downloads.
|
||||
* @param {string} name
|
||||
* @param {Blob} content
|
||||
*/
|
||||
export function download(name, content) {
|
||||
const address = URL.createObjectURL(content);
|
||||
const link = document.createElement('a');
|
||||
link.href = address;
|
||||
link.download = name;
|
||||
document.body.append(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
// The browser has begun the download; the address can go a moment later.
|
||||
setTimeout(() => URL.revokeObjectURL(address), 10000);
|
||||
}
|
||||
Reference in new issue
Block a user