Add yet-another-react-lightbox package and update .gitignore to exclude node_modules

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-12 18:50:30 +00:00
parent bd2a5570a9
commit c92f4a5edd
9304 changed files with 29 additions and 2008667 deletions

View File

@@ -1,165 +0,0 @@
/* eslint-disable no-restricted-globals, @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars, @typescript-eslint/no-non-null-assertion */
import { makeRequestCall, makeRequestCallFromTimer } from './makeRequestCall.js'
import type { Task } from './types.js'
export class AsapQueue {
private queue: Task[] = []
// We queue errors to ensure they are thrown in right order (FIFO).
// Array-as-queue is good enough here, since we are just dealing with exceptions.
private pendingErrors: any[] = []
// Once a flush has been requested, no further calls to `requestFlush` are
// necessary until the next `flush` completes.
// @ts-ignore
private flushing = false
// `requestFlush` is an implementation-specific method that attempts to kick
// off a `flush` event as quickly as possible. `flush` will attempt to exhaust
// the event queue before yielding to the browser's own event loop.
private requestFlush: () => void
private requestErrorThrow: () => void
// The position of the next task to execute in the task queue. This is
// preserved between calls to `flush` so that it can be resumed if
// a task throws an exception.
private index = 0
// If a task schedules additional tasks recursively, the task queue can grow
// unbounded. To prevent memory exhaustion, the task queue will periodically
// truncate already-completed tasks.
private capacity = 1024
public constructor() {
// `requestFlush` requests that the high priority event queue be flushed as
// soon as possible.
// This is useful to prevent an error thrown in a task from stalling the event
// queue if the exception handled by Node.jss
// `process.on("uncaughtException")` or by a domain.
// `requestFlush` is implemented using a strategy based on data collected from
// every available SauceLabs Selenium web driver worker at time of writing.
// https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
this.requestFlush = makeRequestCall(this.flush)
this.requestErrorThrow = makeRequestCallFromTimer(() => {
// Throw first error
if (this.pendingErrors.length) {
throw this.pendingErrors.shift()
}
})
}
// Use the fastest means possible to execute a task in its own turn, with
// priority over other events including IO, animation, reflow, and redraw
// events in browsers.
//
// An exception thrown by a task will permanently interrupt the processing of
// subsequent tasks. The higher level `asap` function ensures that if an
// exception is thrown by a task, that the task queue will continue flushing as
// soon as possible, but if you use `rawAsap` directly, you are responsible to
// either ensure that no exceptions are thrown from your task, or to manually
// call `rawAsap.requestFlush` if an exception is thrown.
public enqueueTask(task: Task): void {
const { queue: q, requestFlush } = this
if (!q.length) {
requestFlush()
this.flushing = true
}
// Equivalent to push, but avoids a function call.
q[q.length] = task
}
// The flush function processes all tasks that have been scheduled with
// `rawAsap` unless and until one of those tasks throws an exception.
// If a task throws an exception, `flush` ensures that its state will remain
// consistent and will resume where it left off when called again.
// However, `flush` does not make any arrangements to be called again if an
// exception is thrown.
private flush = () => {
const { queue: q } = this
while (this.index < q.length) {
const currentIndex = this.index
// Advance the index before calling the task. This ensures that we will
// begin flushing on the next task the task throws an error.
this.index++
q[currentIndex]!.call()
// Prevent leaking memory for long chains of recursive calls to `asap`.
// If we call `asap` within tasks scheduled by `asap`, the queue will
// grow, but to avoid an O(n) walk for every task we execute, we don't
// shift tasks off the queue after they have been executed.
// Instead, we periodically shift 1024 tasks off the queue.
if (this.index > this.capacity) {
// Manually shift all values starting at the index back to the
// beginning of the queue.
for (
let scan = 0, newLength = q.length - this.index;
scan < newLength;
scan++
) {
q[scan] = q[scan + this.index]!
}
q.length -= this.index
this.index = 0
}
}
q.length = 0
this.index = 0
this.flushing = false
}
// In a web browser, exceptions are not fatal. However, to avoid
// slowing down the queue of pending tasks, we rethrow the error in a
// lower priority turn.
public registerPendingError = (err: any) => {
this.pendingErrors.push(err)
this.requestErrorThrow()
}
}
// The message channel technique was discovered by Malte Ubl and was the
// original foundation for this library.
// http://www.nonblocking.io/2011/06/windownexttick.html
// Safari 6.0.5 (at least) intermittently fails to create message ports on a
// page's first load. Thankfully, this version of Safari supports
// MutationObservers, so we don't need to fall back in that case.
// function makeRequestCallFromMessageChannel(callback) {
// var channel = new MessageChannel();
// channel.port1.onmessage = callback;
// return function requestCall() {
// channel.port2.postMessage(0);
// };
// }
// For reasons explained above, we are also unable to use `setImmediate`
// under any circumstances.
// Even if we were, there is another bug in Internet Explorer 10.
// It is not sufficient to assign `setImmediate` to `requestFlush` because
// `setImmediate` must be called *by name* and therefore must be wrapped in a
// closure.
// Never forget.
// function makeRequestCallFromSetImmediate(callback) {
// return function requestCall() {
// setImmediate(callback);
// };
// }
// Safari 6.0 has a problem where timers will get lost while the user is
// scrolling. This problem does not impact ASAP because Safari 6.0 supports
// mutation observers, so that implementation is used instead.
// However, if we ever elect to use timers in Safari, the prevalent work-around
// is to add a scroll event listener that calls for a flush.
// `setTimeout` does not call the passed callback if the delay is less than
// approximately 7 in web workers in Firefox 8 through 18, and sometimes not
// even then.
// This is for `asap.js` only.
// Its name will be periodically randomized to break any code that depends on
// // its existence.
// rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer
// ASAP was originally a nextTick shim included in Q. This was factored out
// into this ASAP package. It was later adapted to RSVP which made further
// amendments. These decisions, particularly to marginalize MessageChannel and
// to capture the MutationObserver implementation in a closure, were integrated
// back into ASAP proper.
// https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js

View File

@@ -1,24 +0,0 @@
// We wrap tasks with recyclable task objects. A task object implements
import type { Task, TaskFn } from 'types'
// `call`, just like a function.
export class RawTask implements Task {
public task: TaskFn | null = null
public constructor(
private onError: (err: any) => void,
private release: (t: RawTask) => void,
) {}
public call() {
try {
this.task && this.task()
} catch (error) {
this.onError(error)
} finally {
this.task = null
this.release(this)
}
}
}

View File

@@ -1,17 +0,0 @@
import { RawTask } from './RawTask.js'
import type { Task } from './types.js'
export class TaskFactory {
private freeTasks: RawTask[] = []
public constructor(private onError: (err: any) => void) {}
public create(task: () => void): Task {
const tasks = this.freeTasks
const t = tasks.length
? (tasks.pop() as RawTask)
: new RawTask(this.onError, (t) => (tasks[tasks.length] = t))
t.task = task
return t
}
}

View File

@@ -1,18 +0,0 @@
import { AsapQueue } from './AsapQueue.js'
import { TaskFactory } from './TaskFactory.js'
import type { TaskFn } from './types.js'
const asapQueue = new AsapQueue()
const taskFactory = new TaskFactory(asapQueue.registerPendingError)
/**
* Calls a task as soon as possible after returning, in its own event, with priority
* over other events like animation, reflow, and repaint. An error thrown from an
* event will not interrupt, nor even substantially slow down the processing of
* other events, but will be rather postponed to a lower priority event.
* @param {{call}} task A callable object, typically a function that takes no
* arguments.
*/
export function asap(task: TaskFn) {
asapQueue.enqueueTask(taskFactory.create(task))
}

View File

@@ -1,4 +0,0 @@
export * from './asap.js'
export * from './AsapQueue.js'
export * from './TaskFactory.js'
export * from './types.js'

View File

@@ -1,87 +0,0 @@
// Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
// have WebKitMutationObserver but not un-prefixed MutationObserver.
// Must use `global` or `self` instead of `window` to work in both frames and web
// workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
/* globals self */
const scope = typeof global !== 'undefined' ? global : self
const BrowserMutationObserver =
(scope as any).MutationObserver || (scope as any).WebKitMutationObserver
export function makeRequestCallFromTimer(callback: () => void) {
return function requestCall() {
// We dispatch a timeout with a specified delay of 0 for engines that
// can reliably accommodate that request. This will usually be snapped
// to a 4 milisecond delay, but once we're flushing, there's no delay
// between events.
const timeoutHandle = setTimeout(handleTimer, 0)
// However, since this timer gets frequently dropped in Firefox
// workers, we enlist an interval handle that will try to fire
// an event 20 times per second until it succeeds.
const intervalHandle = setInterval(handleTimer, 50)
function handleTimer() {
// Whichever timer succeeds will cancel both timers and
// execute the callback.
clearTimeout(timeoutHandle)
clearInterval(intervalHandle)
callback()
}
}
}
// To request a high priority event, we induce a mutation observer by toggling
// the text of a text node between "1" and "-1".
export function makeRequestCallFromMutationObserver(callback: () => void) {
let toggle = 1
const observer = new BrowserMutationObserver(callback)
const node = document.createTextNode('')
observer.observe(node, { characterData: true })
return function requestCall() {
toggle = -toggle
;(node as any).data = toggle
}
}
export const makeRequestCall =
typeof BrowserMutationObserver === 'function'
? // MutationObservers are desirable because they have high priority and work
// reliably everywhere they are implemented.
// They are implemented in all modern browsers.
//
// - Android 4-4.3
// - Chrome 26-34
// - Firefox 14-29
// - Internet Explorer 11
// - iPad Safari 6-7.1
// - iPhone Safari 7-7.1
// - Safari 6-7
makeRequestCallFromMutationObserver
: // MessageChannels are desirable because they give direct access to the HTML
// task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
// 11-12, and in web workers in many engines.
// Although message channels yield to any queued rendering and IO tasks, they
// would be better than imposing the 4ms delay of timers.
// However, they do not work reliably in Internet Explorer or Safari.
// Internet Explorer 10 is the only browser that has setImmediate but does
// not have MutationObservers.
// Although setImmediate yields to the browser's renderer, it would be
// preferrable to falling back to setTimeout since it does not have
// the minimum 4ms penalty.
// Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
// Desktop to a lesser extent) that renders both setImmediate and
// MessageChannel useless for the purposes of ASAP.
// https://github.com/kriskowal/q/issues/396
// Timers are implemented universally.
// We fall back to timers in workers in most engines, and in foreground
// contexts in the following browsers.
// However, note that even this simple case requires nuances to operate in a
// broad spectrum of browsers.
//
// - Firefox 3-13
// - Internet Explorer 6-9
// - iPad Safari 4.3
// - Lynx 2.8.7
makeRequestCallFromTimer

View File

@@ -1,4 +0,0 @@
export interface Task {
call(): void
}
export type TaskFn = () => void