This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function vortex(n, m) { | |
| let x = 0, y = 0; count = 1; | |
| const result = Array(n).fill(0).map(() => Array(m).fill(0)); | |
| const check = (a, b) => result[a] && result[a][b] === 0; | |
| let pre = NaN; | |
| while (pre !== count) { | |
| pre = count; | |
| while (check(x, y + 1)) result[x][y++] = count++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type NumberToString<N extends number> = `${N}`; | |
| type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : never; | |
| type StringToCharArr<S extends string> = S extends `${infer First}${infer Rest}` ? [First, ...StringToCharArr<Rest>] : []; | |
| type CharArrToString<Arr extends string[]> = Arr extends [infer First extends string, ...infer Rest extends string[]] ? `${First}${CharArrToString<Rest>}` : ''; | |
| type DigitMap = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] | |
| type CharArrAddOne<Arr extends string[], Acc extends string[] = []> = Arr extends [...infer Rest extends string[], infer Last extends string] | |
| ? Last extends DigitMap[number] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streamSaver from "streamsaver"; | |
| import downloadFile from "./downloadFile"; | |
| const HAS_FILE_SYSTEM_ACCESS_API = !!window.showSaveFilePicker; | |
| // Why is this in UI? streamsaver does not work in worker. Otherwise it would be better there. | |
| // If this is ever moved to the worker, be careful about file system access API crashing Chrome 93/94 https://dumbmatter.com/file-system-access-worker-bug/ | |
| const downloadFileStream = async ( | |
| stream: boolean, | |
| filename: string, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const inIframe = globalThis.window !== undefined && globalThis.window !== globalThis.top | |
| const supportShowSaveFilePicker = "showSaveFilePicker" in globalThis | |
| function legacySaveFile(file, options) { | |
| const link = document.createElement("a") | |
| link.download = options.suggestedName | |
| link.href = URL.createObjectURL(file) | |
| link.click() | |
| setTimeout(() => URL.revokeObjectURL(link.href), options.timeout ?? 10_000) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface BlobWritable { | |
| getWriter: () => { | |
| abort: () => Promise<void>; | |
| close: () => Promise<void>; | |
| closed: Promise<undefined>; | |
| desiredSize: number | null; | |
| ready: Promise<undefined>; | |
| releaseLock: () => void; | |
| write: (chunk: Uint8Array) => Promise<void>; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function urlToBlob(url) { | |
| return new Promise((resolve, reject) => { | |
| const xhr = new XMLHttpRequest(); | |
| xhr.open('GET', url, true); | |
| xhr.responseType = 'blob'; | |
| xhr.onload = () => { | |
| if (xhr.status === 200) { | |
| resolve(xhr.response); | |
| } else { | |
| reject(new Error(`urlToBlob: Request failed with status ${xhr.status}`)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface IDisposable { | |
| dispose(): void; | |
| } | |
| export interface IReference<T> extends IDisposable { | |
| readonly object: T; | |
| } | |
| export interface IObjectData { | |
| getId(): unknown; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const workerPool = (concurrentCount) => { | |
| const queue = []; | |
| let max = Math.max(concurrentCount, 1); | |
| const resetMax = (m) => { | |
| max = Math.max(m, 1); | |
| checkQueue(); | |
| }; | |
| const checkQueue = () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| self.addEventListener('install', (event) => { | |
| event.waitUntil(self.skipWaiting()); | |
| }); | |
| self.addEventListener('activate', (event) => { | |
| event.waitUntil(self.clients.claim()); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SynchronizedLock { | |
| constructor() { | |
| this.lock = false; | |
| this.queue = []; | |
| } | |
| async getLock(timeout = 10000) { | |
| while (this.lock) { | |
| await new Promise((resolve) => { | |
| this.queue.push(resolve); |
NewerOlder