modules: update deps

This commit is contained in:
nym21
2025-12-29 09:32:51 +01:00
parent 31d2f8ef37
commit 705dbdbd7e
26 changed files with 10264 additions and 0 deletions

653
modules/lean-qr/2.6.1/index.d.ts vendored Normal file
View File

@@ -0,0 +1,653 @@
declare module 'lean-qr' {
interface ImageDataLike {
readonly data: Uint8ClampedArray;
}
interface Context2DLike<DataT extends ImageDataLike> {
createImageData(width: number, height: number): DataT;
putImageData(data: DataT, x: number, y: number): void;
}
interface CanvasLike<DataT extends ImageDataLike> {
width: number;
height: number;
getContext(type: '2d'): Context2DLike<DataT> | null;
}
/**
* A colour in `[red, green, blue, alpha]` format (all values from 0 to 255).
* If alpha is omitted, it is assumed to be 255 (opaque).
*/
export type RGBA = readonly [number, number, number, number?];
export interface Bitmap1D {
/**
* Appends a sequence of bits.
*
* @param value an integer containing the bits to append (big endian).
* @param bits the number of bits to read from `value`. Must be between 1 and 24.
*/
push(value: number, bits: number): void;
}
export interface StringOptions {
/** the text to use for modules which are 'on' (typically black) */
on?: string;
/** the text to use for modules which are 'off' (typically white) */
off?: string;
/** the text to use for linefeeds between rows */
lf?: string;
/** the padding to apply around the output (populated with 'off' modules) */
pad?: number;
/**
* the padding to apply on the left and right of the output (populated with 'off' modules)
* @deprecated use `pad` instead
*/
padX?: number;
/**
* the padding to apply on the top and bottom of the output (populated with 'off' modules)
* @deprecated use `pad` instead
*/
padY?: number;
}
export interface ImageDataOptions {
/** the colour to use for modules which are 'on' (typically black) */
on?: RGBA;
/** the colour to use for modules which are 'off' (typically white) */
off?: RGBA;
/** the padding to apply around the output (filled with 'off') */
pad?: number;
/**
* the padding to apply on the left and right of the output (filled with 'off')
* @deprecated use `pad` instead
*/
padX?: number;
/**
* the padding to apply on the top and bottom of the output (filled with 'off')
* @deprecated use `pad` instead
*/
padY?: number;
}
export interface Bitmap2D {
/** the width / height of the QR code in modules (excluding any padding) */
readonly size: number;
/**
* Read the state of a module from the QR code.
*
* @param x the x coordinate to read. Can be negative / out of bounds.
* @param y the y coordinate to read. Can be negative / out of bounds.
* @returns true if the requested module is set (i.e. typically black)
*/
get(x: number, y: number): boolean;
/**
* Generate a string containing the QR code, suitable for displaying in a
* terminal environment. Generally, you should customise on and off to use
* the ANSI escapes of your target terminal for better rendering.
*
* @param options optional configuration for the display.
*/
toString(options?: Readonly<StringOptions>): string;
/**
* Generate image data containing the QR code, at a scale of 1 pixel per
* module. Use this if you need more control than toCanvas allows.
*
* @param context a context to use for creating the image data.
* @param options optional configuration for the display.
*/
toImageData<DataT extends ImageDataLike>(
context: Context2DLike<DataT>,
options?: Readonly<ImageDataOptions>,
): DataT;
/**
* Generate a `data:image/*` URL for the QR code.
*
* @param options optional configuration for the output.
* @returns a string suitable for use as the `src` of an `img` tag.
*/
toDataURL(
options?: Readonly<
ImageDataOptions & {
type?: `image/${string}`;
scale?: number;
}
>,
): string;
/**
* Populate a given canvas with the QR code, at a scale of 1 pixel per
* module. Set image-rendering: pixelated and scale the canvas using CSS
* for a large image. Automatically resizes the canvas to fit the QR code
* if necessary.
*
* @param canvas the canvas to populate.
* @param options optional configuration for the display.
*/
toCanvas(
canvas: CanvasLike<ImageDataLike>,
options?: Readonly<ImageDataOptions>,
): void;
}
export type Mask = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
export type Mode = (data: Bitmap1D, version: number) => void;
export interface ModeFactory {
(value: string): Mode;
/** a function which returns true when given a character which the current mode can represent */
test(string: string): boolean;
/** a function which returns an estimate of the number of bits required to encode a given value */
est(value: string, version: number): number;
/** an optional ECI which must be active for this mode to be interpreted correctly by a reader */
eci?: number;
}
interface ModeAutoOptions {
/** a list of modes which can be considered when encoding a message */
modes?: ReadonlyArray<ModeFactory>;
}
export const mode: Readonly<{
/** automatically picks the most optimal combination of modes for the requested message */
auto(value: string, options?: Readonly<ModeAutoOptions>): Mode;
/** concatenates multiple modes together */
multi(...modes: ReadonlyArray<Mode>): Mode;
/** sets the Extended Channel Interpretation for the message from this point onwards */
eci(id: number): Mode;
/** supports `0-9` and stores 3 characters per 10 bits */
numeric: ModeFactory;
/** supports `0-9A-Z $%*+-./:` and stores 2 characters per 11 bits */
alphaNumeric: ModeFactory;
/** arbitrary byte data, typically combined with `eci` */
bytes(data: Uint8Array | ReadonlyArray<number>): Mode;
/** supports 7-bit ASCII and stores 1 character per 8 bits with no ECI */
ascii: ModeFactory;
/** supports 8-bit ISO-8859-1 and stores 1 character per 8 bits with ECI 3 */
iso8859_1: ModeFactory;
/** supports double-byte Shift-JIS characters stores 1 character per 13 bits */
shift_jis: ModeFactory;
/** supports variable length UTF-8 with ECI 26 */
utf8: ModeFactory;
}>;
export type Correction = number & { readonly _: unique symbol };
export const correction: Readonly<{
/**
* minimum possible correction level (same as L)
* @deprecated use correction.L
*/
min: Correction;
/** ~7.5% error tolerance, ~25% data overhead */
L: Correction;
/** ~15% error tolerance, ~60% data overhead */
M: Correction;
/** ~22.5% error tolerance, ~120% data overhead */
Q: Correction;
/** ~30% error tolerance, ~190% data overhead */
H: Correction;
/**
* maximum possible correction level (same as H)
* @deprecated use correction.H
*/
max: Correction;
}>;
export interface GenerateOptions extends ModeAutoOptions {
/** the minimum correction level to use (higher levels may still be used if the chosen version has space) */
minCorrectionLevel?: Correction;
/** the maximum correction level to use */
maxCorrectionLevel?: Correction;
/** the minimum version (size) of code to generate (must be between 1 and 40) */
minVersion?: number;
/** the maximum version (size) of code to generate (must be between 1 and 40) */
maxVersion?: number;
/** a mask to use on the QR code (should be left as `null` for ISO compliance but may be changed for artistic effect) */
mask?: null | Mask;
/** padding bits to use for extra space in the QR code (should be left as the default for ISO compliance but may be changed for artistic effect) */
trailer?: number;
}
/**
* Generate a QR code.
*
* @param data either a string, or a pre-encoded mode.
* @param options optional configuration for the QR code.
* @returns the requested QR code.
*/
export type GenerateFn = (
data: Mode | string,
options?: Readonly<GenerateOptions>,
) => Bitmap2D;
interface Generate extends GenerateFn {
/**
* Creates a scoped `generate` function which considers additional modes
* when using auto encoding.
*
* @param modes the modes to add.
* @returns a `generate` function which will additionally consider the
* given modes when using auto encoding.
*
* @deprecated this will be removed in version 3. Prefer passing an explicit list of modes when calling `generate`.
*/
with(...modes: ReadonlyArray<ModeFactory>): GenerateFn;
}
export const generate: Generate;
}
declare module 'lean-qr/nano' {
import type {
Correction,
Bitmap2D as FullBitmap2D,
GenerateOptions as FullGenerateOptions,
} from 'lean-qr';
import { correction as fullCorrection } from 'lean-qr';
export type { Correction };
export const correction: Pick<typeof fullCorrection, 'L' | 'M' | 'Q' | 'H'>;
export type Bitmap2D = Pick<FullBitmap2D, 'size' | 'get' | 'toCanvas'>;
export type GenerateOptions = Pick<
FullGenerateOptions,
'minCorrectionLevel' | 'minVersion'
>;
/**
* Generate a QR code.
*
* @param data either a string, or a pre-encoded mode.
* @param options optional configuration for the QR code.
* @returns the requested QR code.
*/
export function generate(
data: string,
options?: Readonly<GenerateOptions>,
): Bitmap2D;
}
declare module 'lean-qr/extras/svg' {
import type { Bitmap2D as FullBitmap2D } from 'lean-qr';
type Bitmap2D = Pick<FullBitmap2D, 'size' | 'get'>;
export interface SVGOptions {
/** the colour to use for modules which are 'on' (typically black) */
on?: string;
/** the colour to use for modules which are 'off' (typically white) */
off?: string;
/** the padding to apply around the output (filled with 'off') */
pad?: number;
/**
* the padding to apply on the left and right of the output (filled with 'off')
* @deprecated use `pad` instead
*/
padX?: number;
/**
* the padding to apply on the top and bottom of the output (filled with 'off')
* @deprecated use `pad` instead
*/
padY?: number;
/** a width to apply to the resulting image (overrides `scale`) */
width?: number | null;
/** a height to apply to the resulting image (overrides `scale`) */
height?: number | null;
/** a scale to apply to the resulting image (`scale` pixels = 1 module) */
scale?: number;
}
/**
* Generate the raw outline of the QR code for use in an existing SVG.
*
* @param code the QR code to convert.
* @returns a string suitable for passing to the `d` attribute of a `path`.
*/
export function toSvgPath(code: Bitmap2D): string;
/**
* Generate an SVG element which can be added to the DOM.
*
* @param code the QR code to convert.
* @param options optional configuration for the display.
* @returns an SVG element.
*/
export function toSvg(
code: Bitmap2D,
target: Document | SVGElement,
options?: Readonly<SVGOptions>,
): SVGElement;
/**
* Generate an SVG document which can be exported to a file or served from a
* web server.
*
* @param code the QR code to convert.
* @param options optional configuration for the display.
* @returns an SVG document.
*/
export function toSvgSource(
code: Bitmap2D,
options?: Readonly<
SVGOptions & {
/** `true` to include an XML declaration at the start of the source (for standalone documents which will not be embedded inside another document) */
xmlDeclaration?: boolean;
}
>,
): string;
/**
* Generate a `data:image/svg+xml` URL.
*
* @param code the QR code to convert.
* @param options optional configuration for the display.
* @returns a string suitable for use as the `src` of an `img` tag.
*/
export function toSvgDataURL(
code: Bitmap2D,
options?: Readonly<SVGOptions>,
): string;
}
declare module 'lean-qr/extras/node_export' {
import type { RGBA, Bitmap2D as FullBitmap2D } from 'lean-qr';
type Bitmap2D = Pick<FullBitmap2D, 'size' | 'get'>;
export interface PNGOptions {
/** the colour to use for modules which are 'on' (typically black) */
on?: RGBA;
/** the colour to use for modules which are 'off' (typically white) */
off?: RGBA;
/** the padding to apply around the output (filled with 'off') */
pad?: number;
/**
* the padding to apply on the left and right of the output (filled with 'off')
* @deprecated use `pad` instead
*/
padX?: number;
/**
* the padding to apply on the top and bottom of the output (filled with 'off')
* @deprecated use `pad` instead
*/
padY?: number;
/** a scale to apply to the resulting image (`scale` pixels = 1 module) */
scale?: number;
}
/**
* Generate a PNG document which can be exported to a file or served from a
* web server.
*
* @param code the QR code to convert.
* @param options optional configuration for the display.
* @returns a PNG document.
*/
export function toPngBuffer(
code: Bitmap2D,
options?: Readonly<PNGOptions>,
): Uint8Array;
/**
* Generate a `data:image/png` URL.
*
* @param code the QR code to convert.
* @param options optional configuration for the display.
* @returns a string suitable for use as the `src` of an `img` tag.
*/
export function toPngDataURL(
code: Bitmap2D,
options?: Readonly<PNGOptions>,
): string;
}
declare module 'lean-qr/extras/react' {
import type {
Bitmap2D as FullBitmap2D,
GenerateOptions,
ImageDataOptions,
} from 'lean-qr';
import type {
SVGOptions,
toSvgDataURL as toSvgDataURLFn,
} from 'lean-qr/extras/svg';
export interface AsyncFramework<T> {
createElement: (
type: 'canvas',
props: {
ref: any;
style: { imageRendering: 'pixelated' };
className: string;
},
) => T;
useRef<T>(initialValue: T | null): { readonly current: T | null };
useEffect(fn: () => void | (() => void), deps: unknown[]): void;
}
interface QRComponentProps {
content: string;
className?: string;
}
export interface AsyncQRComponentProps
extends ImageDataOptions,
GenerateOptions,
QRComponentProps {}
export type AsyncQRComponent<T> = (
props: Readonly<AsyncQRComponentProps>,
) => T;
/**
* Generate an asynchronous QR component (rendering to a `canvas`).
* You should call this just once, in the global scope.
*
* ```js
* import * as React from 'react';
* import { generate } from 'lean-qr';
* import { makeAsyncComponent } from 'lean-qr/extras/react';
* const QR = makeAsyncComponent(React, generate);
* ```
*
* This is not suitable for server-side rendering (use `makeSyncComponent`
* instead).
*
* @param framework the framework to use (e.g. `React`).
* @param generate the `generate` function to use
* (from `lean-qr` or `lean-qr/nano`).
* @param defaultProps optional default properties to apply when the
* component is used (overridden by properties set on use).
* @returns a component which can be rendered elsewhere.
*/
export function makeAsyncComponent<T>(
framework: Readonly<AsyncFramework<T>>,
generate: (
data: string,
options?: Readonly<GenerateOptions>,
) => Pick<FullBitmap2D, 'toCanvas'>,
defaultProps?: Readonly<Partial<AsyncQRComponentProps>>,
): AsyncQRComponent<T>;
export interface SyncFramework<T> {
createElement: (
type: 'img',
props: {
src: string;
style: { imageRendering: 'pixelated' };
className: string;
},
) => T;
useMemo<T>(fn: () => T, deps: unknown[]): T;
}
export interface SyncQRComponentProps
extends SVGOptions,
GenerateOptions,
QRComponentProps {}
export type SyncQRComponent<T> = (props: Readonly<SyncQRComponentProps>) => T;
/**
* Generate a synchronous QR component (rendering to an SVG).
* You should call this just once, in the global scope.
*
* ```js
* import * as React from 'react';
* import { generate } from 'lean-qr';
* import { toSvgDataURL } from 'lean-qr/extras/svg';
* import { makeSyncComponent } from 'lean-qr/extras/react';
* const QR = makeSyncComponent(React, generate, toSvgDataURL);
* ```
*
* This is best suited for server-side rendering (prefer
* `makeAsyncComponent` if you only need client-side rendering).
*
* @param framework the framework to use (e.g. `React`).
* @param generate the `generate` function to use
* (from `lean-qr` or `lean-qr/nano`).
* @param toSvgDataURL the `toSvgDataURL` function to use
* (from `lean-qr/extras/svg`).
* @param defaultProps optional default properties to apply when the
* component is used (overridden by properties set on use).
* @returns a component which can be rendered elsewhere.
*/
export function makeSyncComponent<T>(
framework: Readonly<SyncFramework<T>>,
generate: (
data: string,
options?: Readonly<GenerateOptions>,
) => Pick<FullBitmap2D, 'size' | 'get'>,
toSvgDataURL: typeof toSvgDataURLFn,
defaultProps?: Readonly<Partial<SyncQRComponentProps>>,
): SyncQRComponent<T>;
}
declare module 'lean-qr/extras/vue' {
import type {
Bitmap2D as FullBitmap2D,
GenerateOptions,
ImageDataOptions,
} from 'lean-qr';
import type {
SVGOptions,
toSvgDataURL as toSvgDataURLFn,
} from 'lean-qr/extras/svg';
export interface Framework {
h:
| ((type: 'canvas', props: { ref: string; style: string }) => unknown)
| ((type: 'img', props: { src: string; style: string }) => unknown);
}
interface QRComponentProps {
content: string;
}
export interface VueCanvasComponentProps
extends ImageDataOptions,
GenerateOptions,
QRComponentProps {}
type VueComponentDefinition<Props> = {
props: {
[k in keyof Props]-?: {
type: { (): Required<Props>[k] };
required: undefined extends Props[k] ? false : true;
};
};
} & ThisType<unknown>;
/**
* Generate a QR component which renders to a `canvas`.
* You should call this just once, in the global scope.
*
* ```js
* import { h, defineComponent } from 'vue';
* import { generate } from 'lean-qr';
* import { makeVueCanvasComponent } from 'lean-qr/extras/vue';
* export const QR = defineComponent(makeVueCanvasComponent({ h }, generate));
* ```
*
* This is not suitable for server-side rendering (use `makeSyncComponent`
* instead).
*
* @param framework the framework to use (e.g. `{ h }`).
* @param generate the `generate` function to use
* (from `lean-qr` or `lean-qr/nano`).
* @param defaultProps optional default properties to apply when the
* component is used (overridden by properties set on use).
* @returns a component which can be rendered elsewhere.
*/
export function makeVueCanvasComponent(
framework: Readonly<Framework>,
generate: (
data: string,
options?: Readonly<GenerateOptions>,
) => Pick<FullBitmap2D, 'toCanvas'>,
defaultProps?: Readonly<Partial<VueCanvasComponentProps>>,
): VueComponentDefinition<VueCanvasComponentProps>;
export interface VueSVGComponentProps
extends SVGOptions,
GenerateOptions,
QRComponentProps {}
/**
* Generate a QR component which renders to an SVG.
* You should call this just once, in the global scope:
*
* ```js
* import { h, defineComponent } from 'vue';
* import { generate } from 'lean-qr';
* import { toSvgDataURL } from 'lean-qr/extras/svg';
* import { makeVueSvgComponent } from 'lean-qr/extras/vue';
* export const QR = defineComponent(makeVueSvgComponent({ h }, generate, toSvgDataURL));
* ```
*
* This is best suited for server-side rendering (prefer
* `makeAsyncComponent` if you only need client-side rendering).
*
* @param framework the framework to use (e.g. `{ h }`).
* @param generate the `generate` function to use
* (from `lean-qr` or `lean-qr/nano`).
* @param toSvgDataURL the `toSvgDataURL` function to use
* (from `lean-qr/extras/svg`).
* @param defaultProps optional default properties to apply when the
* component is used (overridden by properties set on use).
* @returns a component which can be rendered elsewhere.
*/
export function makeVueSvgComponent(
framework: Readonly<Framework>,
generate: (
data: string,
options?: Readonly<GenerateOptions>,
) => Pick<FullBitmap2D, 'size' | 'get'>,
toSvgDataURL: typeof toSvgDataURLFn,
defaultProps?: Readonly<Partial<VueSVGComponentProps>>,
): VueComponentDefinition<VueSVGComponentProps>;
}
declare module 'lean-qr/extras/errors' {
/**
* Convert an error into a human-readable message. This is intended for use
* with Lean QR errors, but will return somewhat meaningful messages for
* other errors too.
*
* @param error the error to convert.
* @returns a human-readable message explaining the error.
*/
export function readError(error: unknown): string;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,353 @@
interface Options {
/**
* Width in pixels to be applied to node before rendering.
*/
width?: number;
/**
* Height in pixels to be applied to node before rendering.
*/
height?: number;
/**
* A number between `0` and `1` indicating image quality (e.g. 0.92 => 92%) of the JPEG image.
*/
quality?: number;
/**
* A string indicating the image format. The default type is image/png; that type is also used if the given type isn't supported.
*/
type?: string;
/**
* The pixel ratio of captured image.
*
* DPI = 96 * scale
*
* default: 1
*/
scale?: number;
/**
* A string value for the background color, any valid CSS color value.
*/
backgroundColor?: string | null;
/**
* An object whose properties to be copied to node's style before rendering.
*/
style?: Partial<CSSStyleDeclaration> | null;
/**
* A function taking DOM node as argument. Should return `true` if passed
* node should be included in the output. Excluding node means excluding
* it's children as well.
*/
filter?: ((el: Node) => boolean) | null;
/**
* Maximum canvas size (pixels).
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size
*/
maximumCanvasSize?: number;
/**
* Load media timeout and fetch remote asset timeout (millisecond).
*
* default: 30000
*/
timeout?: number;
/**
* Embed assets progress.
*/
progress?: ((current: number, total: number) => void) | null;
/**
* Enable debug mode to view the execution time log.
*/
debug?: boolean;
/**
* Custom implementation to get image data for a custom URL.
* This can be helpful for Capacitor or Cordova when using
* native fetch to bypass CORS issues.
*
* If returns a string, will completely bypass any `Options.fetch`
* settings with your custom implementation.
*
* If returns false, will fall back to normal fetch implementation
*
* @param url
* @returns A data URL for the image
*/
fetchFn?: ((url: string) => Promise<string | false>) | null;
/**
* The options of fetch resources.
*/
fetch?: {
/**
* The second parameter of `window.fetch` RequestInit
*
* default: {
* cache: 'force-cache',
* }
*/
requestInit?: RequestInit;
/**
* Set to `true` to append the current time as a query string to URL
* requests to enable cache busting.
*
* default: false
*/
bypassingCache?: boolean | RegExp;
/**
* A data URL for a placeholder image that will be used when fetching
* an image fails. Defaults to an empty string and will render empty
* areas for failed images.
*
* default: data:image/png;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
*/
placeholderImage?: string | ((cloned: HTMLImageElement | SVGImageElement) => string | Promise<string>);
};
/**
* The options of fonts download and embed.
*/
font?: false | {
/**
* Font minify
*/
minify?: (font: ArrayBuffer, subset: string) => ArrayBuffer;
/**
* The preferred font format. If specified all other font formats are ignored.
*/
preferredFormat?: 'woff' | 'woff2' | 'truetype' | 'opentype' | 'embedded-opentype' | 'svg' | string;
/**
* A CSS string to specify for font embeds. If specified only this CSS will
* be present in the resulting image.
*/
cssText?: string;
};
/**
* All enabled features
*
* default: true
*/
features?: boolean | {
/**
* Copy scrollbar css styles
*
* default: true
*/
copyScrollbar?: boolean;
/**
* Remove abnormal attributes to cloned node (for normalize XML)
*
* default: true
*/
removeAbnormalAttributes?: boolean;
/**
* Remove control characters (for normalize XML)
*
* default: true
*/
removeControlCharacter?: boolean;
/**
* Fix svg+xml image decode (for Safari、Firefox)
*
* default: true
*/
fixSvgXmlDecode?: boolean;
/**
* Render scrolled children with scrolled content
*
* default: false
*/
restoreScrollPosition?: boolean;
};
/**
* Canvas `drawImage` interval
* is used to fix errors in decoding images in Safari、Firefox
*
* default: 100
*/
drawImageInterval?: number;
/**
* Web Worker script url
*/
workerUrl?: string | null;
/**
* Web Worker number
*/
workerNumber?: number;
/**
* Triggered after each node is cloned
*/
onCloneEachNode?: ((cloned: Node) => void | Promise<void>) | null;
/**
* Triggered after a node is cloned
*/
onCloneNode?: ((cloned: Node) => void | Promise<void>) | null;
/**
* Triggered after a node is embed
*/
onEmbedNode?: ((cloned: Node) => void | Promise<void>) | null;
/**
* Triggered after a ForeignObjectSvg is created
*/
onCreateForeignObjectSvg?: ((svg: SVGSVGElement) => void | Promise<void>) | null;
/**
* An array of style property names.
* Can be used to manually specify which style properties are
* included when cloning nodes.
* This can be useful for performance-critical scenarios.
*/
includeStyleProperties?: string[] | null;
}
interface Request {
type: 'image' | 'text';
resolve?: (response: string) => void;
reject?: (error: Error) => void;
response: Promise<string>;
}
interface InternalContext<T extends Node> {
/**
* FLAG
*/
__CONTEXT__: true;
/**
* Logger
*/
log: {
time: (label: string) => void;
timeEnd: (label: string) => void;
warn: (...args: any[]) => void;
};
/**
* Node
*/
node: T;
/**
* Owner document
*/
ownerDocument?: Document;
/**
* Owner window
*/
ownerWindow?: Window;
/**
* DPI
*
* scale === 1 ? null : 96 * scale
*/
dpi: number | null;
/**
* The `style` element under the root `svg` element
*/
svgStyleElement?: HTMLStyleElement;
/**
* The `defs` element under the root `svg` element
*/
svgDefsElement?: SVGDefsElement;
/**
* The `svgStyleElement` class styles
*
* Map<cssText, class[]>
*/
svgStyles: Map<string, string[]>;
/**
* The map of default `getComputedStyle` for all tagnames
*/
defaultComputedStyles: Map<string, Map<string, any>>;
/**
* The IFrame sandbox used to get the `defaultComputedStyles`
*/
sandbox?: HTMLIFrameElement;
/**
* Web Workers
*/
workers: Worker[];
/**
* The map of `font-family` values for all cloend elements
*/
fontFamilies: Map<string, Set<string>>;
/**
* Map<CssUrl, DataUrl>
*/
fontCssTexts: Map<string, string>;
/**
* `headers.accept` to use when `window.fetch` fetches images
*/
acceptOfImage: string;
/**
* All requests for `fetch`
*/
requests: Map<string, Request>;
/**
* Canvas multiple draw image fix svg+xml image decoding in Safari and Firefox
*/
drawImageCount: number;
/**
* Wait for all tasks embedded in
*/
tasks: Promise<void>[];
/**
* Automatically destroy context
*/
autoDestruct: boolean;
/**
* Is enable
*
* @param key
*/
isEnable: (key: string) => boolean;
/**
* [cloning phase] To get the node style set by the user
*/
currentNodeStyle?: Map<string, [string, string]>;
currentParentNodeStyle?: Map<string, [string, string]>;
/**
* [cloning phase] shadowDOM root list
*/
shadowRoots: ShadowRoot[];
}
type Context<T extends Node = Node> = InternalContext<T> & Required<Options>;
declare function domToBlob<T extends Node>(node: T, options?: Options): Promise<Blob>;
declare function domToBlob<T extends Node>(context: Context<T>): Promise<Blob>;
declare function domToCanvas<T extends Node>(node: T, options?: Options): Promise<HTMLCanvasElement>;
declare function domToCanvas<T extends Node>(context: Context<T>): Promise<HTMLCanvasElement>;
declare function domToDataUrl<T extends Node>(node: T, options?: Options): Promise<string>;
declare function domToDataUrl<T extends Node>(context: Context<T>): Promise<string>;
declare function domToForeignObjectSvg<T extends Node>(node: T, options?: Options): Promise<SVGElement>;
declare function domToForeignObjectSvg<T extends Node>(context: Context<T>): Promise<SVGElement>;
declare function domToImage<T extends Node>(node: T, options?: Options): Promise<HTMLImageElement>;
declare function domToImage<T extends Node>(context: Context<T>): Promise<HTMLImageElement>;
declare function domToJpeg<T extends Node>(node: T, options?: Options): Promise<string>;
declare function domToJpeg<T extends Node>(context: Context<T>): Promise<string>;
declare function domToPixel<T extends Node>(node: T, options?: Options): Promise<Uint8ClampedArray>;
declare function domToPixel<T extends Node>(context: Context<T>): Promise<Uint8ClampedArray>;
declare function domToPng<T extends Node>(node: T, options?: Options): Promise<string>;
declare function domToPng<T extends Node>(context: Context<T>): Promise<string>;
declare function domToSvg<T extends Node>(node: T, options?: Options): Promise<string>;
declare function domToSvg<T extends Node>(context: Context<T>): Promise<string>;
declare function domToWebp<T extends Node>(node: T, options?: Options): Promise<string>;
declare function domToWebp<T extends Node>(context: Context<T>): Promise<string>;
declare function createContext<T extends Node>(node: T, options?: Options & {
autoDestruct?: boolean;
}): Promise<Context<T>>;
declare function destroyContext(context: Context): void;
type Media = HTMLVideoElement | HTMLImageElement | SVGImageElement;
interface LoadMediaOptions {
ownerDocument?: Document;
timeout?: number;
onError?: (error: Error) => void;
onWarn?: (...args: any[]) => void;
}
declare function loadMedia<T extends Media>(media: T, options?: LoadMediaOptions): Promise<T>;
declare function loadMedia(media: string, options?: LoadMediaOptions): Promise<HTMLImageElement>;
declare function waitUntilLoad(node: Node, options?: LoadMediaOptions): Promise<void>;
export { type Context, type Options, createContext, destroyContext, domToBlob, domToCanvas, domToDataUrl, domToForeignObjectSvg, domToImage, domToJpeg, domToPixel, domToPng, domToSvg, domToWebp, loadMedia, waitUntilLoad };

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

2077
modules/solidjs-signals/0.8.5/dist/prod.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
import { Queue, type Computed, type Effect } from "./core/index.js";
import type { Signal } from "./core/index.js";
export interface BoundaryComputed<T> extends Computed<T> {
_propagationMask: number;
}
export declare class CollectionQueue extends Queue {
_collectionType: number;
_nodes: Set<Effect<any>>;
_disabled: Signal<boolean>;
_initialized: boolean;
constructor(type: number);
run(type: number): void;
notify(node: Effect<any>, type: number, flags: number): boolean;
}
export declare const enum BoundaryMode {
VISIBLE = "visible",
HIDDEN = "hidden"
}
export declare function createBoundary<T>(fn: () => T, condition: () => BoundaryMode): () => T | undefined;
export declare function createLoadBoundary(fn: () => any, fallback: () => any): () => unknown;
export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): () => unknown;
export declare function flatten(children: any, options?: {
skipNonRendered?: boolean;
doNotUnwrap?: boolean;
}): any;

View File

@@ -0,0 +1,18 @@
export declare const REACTIVE_NONE = 0;
export declare const REACTIVE_CHECK: number;
export declare const REACTIVE_DIRTY: number;
export declare const REACTIVE_RECOMPUTING_DEPS: number;
export declare const REACTIVE_IN_HEAP: number;
export declare const REACTIVE_IN_HEAP_HEIGHT: number;
export declare const REACTIVE_ZOMBIE: number;
export declare const REACTIVE_DISPOSED: number;
export declare const STATUS_NONE = 0;
export declare const STATUS_PENDING: number;
export declare const STATUS_ERROR: number;
export declare const STATUS_UNINITIALIZED: number;
export declare const EFFECT_PURE = 0;
export declare const EFFECT_RENDER = 1;
export declare const EFFECT_USER = 2;
export declare const NOT_PENDING: {};
export declare const SUPPORTS_PROXY: boolean;
export declare const defaultContext: {};

View File

@@ -0,0 +1,28 @@
import { type Owner } from "./core.js";
export interface Context<T> {
readonly id: symbol;
readonly defaultValue: T | undefined;
}
export type ContextRecord = Record<string | symbol, unknown>;
/**
* Context provides a form of dependency injection. It is used to save from needing to pass
* data as props through intermediate components. This function creates a new context object
* that can be used with `getContext` and `setContext`.
*
* A default value can be provided here which will be used when a specific value is not provided
* via a `setContext` call.
*/
export declare function createContext<T>(defaultValue?: T, description?: string): Context<T>;
/**
* Attempts to get a context value for the given key.
*
* @throws `NoOwnerError` if there's no owner at the time of call.
* @throws `ContextNotFoundError` if a context value has not been set yet.
*/
export declare function getContext<T>(context: Context<T>, owner?: Owner | null): T;
/**
* Attempts to set a context value on the parent scope with the given key.
*
* @throws `NoOwnerError` if there's no owner at the time of call.
*/
export declare function setContext<T>(context: Context<T>, value?: T, owner?: Owner | null): void;

View File

@@ -0,0 +1,123 @@
import { NOT_PENDING } from "./constants.js";
import { type IQueue, type Transition } from "./scheduler.js";
export interface Disposable {
(): void;
}
export interface Link {
_dep: Signal<unknown> | Computed<unknown>;
_sub: Computed<unknown>;
_nextDep: Link | null;
_prevSub: Link | null;
_nextSub: Link | null;
}
export interface SignalOptions<T> {
id?: string;
name?: string;
equals?: ((prev: T, next: T) => boolean) | false;
pureWrite?: boolean;
unobserved?: () => void;
}
export interface RawSignal<T> {
id?: string;
_subs: Link | null;
_subsTail: Link | null;
_value: T;
_error?: unknown;
_statusFlags: number;
_name?: string;
_equals: false | ((a: T, b: T) => boolean);
_pureWrite?: boolean;
_unobserved?: () => void;
_time: number;
_transition: Transition | null;
_pendingValue: T | typeof NOT_PENDING;
_pendingCheck?: Signal<boolean> & {
_set: (v: boolean) => void;
};
_pendingSignal?: Signal<T> & {
_set: (v: T) => void;
};
_optimistic?: boolean;
}
export interface FirewallSignal<T> extends RawSignal<T> {
_firewall: Computed<any>;
_nextChild: FirewallSignal<unknown> | null;
}
export type Signal<T> = RawSignal<T> | FirewallSignal<T>;
export interface Owner {
id?: string;
_disposal: Disposable | Disposable[] | null;
_parent: Owner | null;
_context: Record<symbol | string, unknown>;
_childCount: number;
_queue: IQueue;
_firstChild: Owner | null;
_nextSibling: Owner | null;
_pendingDisposal: Disposable | Disposable[] | null;
_pendingFirstChild: Owner | null;
}
export interface Computed<T> extends RawSignal<T>, Owner {
_deps: Link | null;
_depsTail: Link | null;
_flags: number;
_height: number;
_nextHeap: Computed<any> | undefined;
_prevHeap: Computed<any>;
_fn: (prev?: T) => T;
_child: FirewallSignal<any> | null;
_notifyQueue?: (statusFlagsChanged: boolean, prevStatusFlags: number) => void;
}
export interface Root extends Owner {
_root: true;
_parentComputed: Computed<any> | null;
dispose(self?: boolean): void;
}
export declare let context: Owner | null;
export declare function recompute(el: Computed<any>, create?: boolean): void;
export declare function dispose(node: Computed<unknown>): void;
export declare function getNextChildId(owner: Owner): string;
export declare function computed<T>(fn: (prev?: T) => T): Computed<T>;
export declare function computed<T>(fn: (prev: T) => T, initialValue?: T, options?: SignalOptions<T>): Computed<T>;
export declare function asyncComputed<T>(asyncFn: (prev?: T, refreshing?: boolean) => T | Promise<T> | AsyncIterable<T>): Computed<T> & {
_refresh: () => void;
};
export declare function asyncComputed<T>(asyncFn: (prev: T, refreshing?: boolean) => T | Promise<T> | AsyncIterable<T>, initialValue: T, options?: SignalOptions<T>): Computed<T> & {
_refresh: () => void;
};
export declare function signal<T>(v: T, options?: SignalOptions<T>): Signal<T>;
export declare function signal<T>(v: T, options?: SignalOptions<T>, firewall?: Computed<any>): FirewallSignal<T>;
export declare function isEqual<T>(a: T, b: T): boolean;
/**
* Returns the current value stored inside the given compute function without triggering any
* dependencies. Use `untrack` if you want to also disable owner tracking.
*/
export declare function untrack<T>(fn: () => T): T;
export declare function read<T>(el: Signal<T> | Computed<T>): T;
export declare function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)): T;
export declare function getObserver(): Owner | null;
export declare function getOwner(): Owner | null;
export declare function onCleanup(fn: Disposable): Disposable;
export declare function createOwner(options?: {
id: string;
}): Root;
/**
* Creates a new non-tracked reactive context with manual disposal
*
* @param fn a function in which the reactive state is scoped
* @returns the output of `fn`.
*
* @description https://docs.solidjs.com/reference/reactive-utilities/create-root
*/
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T), options?: {
id: string;
}): T;
/**
* Runs the given function in the given owner to move ownership of nested primitives and cleanups.
* This method untracks the current scope.
*
* Warning: Usually there are simpler ways of modeling a problem that avoid using this function
*/
export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
export declare function staleValues<T>(fn: () => T, set?: boolean): T;
export declare function pending<T>(fn: () => T): T;
export declare function isPending(fn: () => any): boolean;

View File

@@ -0,0 +1,18 @@
import { type Computed, type Owner, type SignalOptions } from "./core.js";
export interface Effect<T> extends Computed<T>, Owner {
_effectFn: (val: T, prev: T | undefined) => void | (() => void);
_errorFn?: (err: unknown, cleanup: () => void) => void;
_cleanup?: () => void;
_modified: boolean;
_prevValue: T | undefined;
_type: number;
}
/**
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
* sources and recompute
*/
export declare function effect<T>(compute: (prev: T | undefined) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown, cleanup: () => void) => void | (() => void), initialValue?: T, options?: SignalOptions<any> & {
render?: boolean;
defer?: boolean;
}): void;

View File

@@ -0,0 +1,10 @@
export declare class NotReadyError extends Error {
cause: any;
constructor(cause: any);
}
export declare class NoOwnerError extends Error {
constructor();
}
export declare class ContextNotFoundError extends Error {
constructor();
}

View File

@@ -0,0 +1,14 @@
import type { Computed } from "./core.js";
export interface Heap {
_heap: (Computed<unknown> | undefined)[];
_marked: boolean;
_min: number;
_max: number;
}
export declare function increaseHeapSize(n: number, heap: Heap): void;
export declare function insertIntoHeap(n: Computed<any>, heap: Heap): void;
export declare function insertIntoHeapHeight(n: Computed<unknown>, heap: Heap): void;
export declare function deleteFromHeap(n: Computed<unknown>, heap: Heap): void;
export declare function markHeap(heap: Heap): void;
export declare function markNode(el: Computed<unknown>, newState?: number): void;
export declare function runHeap(heap: Heap, recompute: (el: Computed<unknown>) => void): void;

View File

@@ -0,0 +1,6 @@
export { ContextNotFoundError, NoOwnerError, NotReadyError } from "./error.js";
export { createContext, getContext, setContext, type Context, type ContextRecord } from "./context.js";
export { getObserver, isEqual, untrack, getOwner, runWithOwner, createOwner, createRoot, computed, dispose, signal, asyncComputed, read, setSignal, onCleanup, getNextChildId, isPending, pending, staleValues, type Owner, type Computed, type Root, type Signal, type SignalOptions } from "./core.js";
export { effect, type Effect } from "./effect.js";
export { flush, Queue, type IQueue, type QueueCallback } from "./scheduler.js";
export * from "./constants.js";

View File

@@ -0,0 +1,59 @@
import type { Computed, Signal } from "./core.js";
import { type Heap } from "./heap.js";
export declare const dirtyQueue: Heap;
export declare const zombieQueue: Heap;
export declare let clock: number;
export declare let activeTransition: Transition | null;
export type QueueCallback = (type: number) => void;
type QueueStub = {
_queues: [QueueCallback[], QueueCallback[]];
_children: QueueStub[];
};
export interface Transition {
time: number;
asyncNodes: Computed<any>[];
pendingNodes: Signal<any>[];
queueStash: QueueStub;
}
export declare function schedule(): void;
export interface IQueue {
enqueue(type: number, fn: QueueCallback): void;
run(type: number): boolean | void;
addChild(child: IQueue): void;
removeChild(child: IQueue): void;
created: number;
notify(node: Computed<any>, mask: number, flags: number): boolean;
stashQueues(stub: QueueStub): void;
restoreQueues(stub: QueueStub): void;
_parent: IQueue | null;
}
export declare class Queue implements IQueue {
_parent: IQueue | null;
_queues: [QueueCallback[], QueueCallback[]];
_children: IQueue[];
created: number;
addChild(child: IQueue): void;
removeChild(child: IQueue): void;
notify(node: Computed<any>, mask: number, flags: number): boolean;
run(type: number): void;
enqueue(type: number, fn: QueueCallback): void;
stashQueues(stub: QueueStub): void;
restoreQueues(stub: QueueStub): void;
}
export declare class GlobalQueue extends Queue {
_running: boolean;
_pendingNodes: Signal<any>[];
static _update: (el: Computed<unknown>) => void;
static _dispose: (el: Computed<unknown>, self: boolean, zombie: boolean) => void;
flush(): void;
notify(node: Computed<any>, mask: number, flags: number): boolean;
initTransition(node: Computed<any>): void;
}
export declare const globalQueue: GlobalQueue;
/**
* By default, changes are batched on the microtask queue which is an async process. You can flush
* the queue synchronously to get the latest updates by calling `flush()`.
*/
export declare function flush(): void;
export declare function runInTransition(el: Computed<unknown>, recompute: (el: Computed<unknown>) => void): void;
export {};

View File

@@ -0,0 +1,6 @@
export { ContextNotFoundError, NoOwnerError, NotReadyError, createContext, createRoot, runWithOwner, flush, getNextChildId, getContext, setContext, getOwner, onCleanup, getObserver, isEqual, untrack, isPending, pending, SUPPORTS_PROXY } from "./core/index.js";
export type { Owner, SignalOptions, Context, ContextRecord, IQueue } from "./core/index.js";
export * from "./signals.js";
export { mapArray, repeat, type Maybe } from "./map.js";
export * from "./store/index.js";
export { createLoadBoundary, createErrorBoundary, createBoundary, flatten, type BoundaryMode } from "./boundaries.js";

View File

@@ -0,0 +1,22 @@
import { type Accessor } from "./signals.js";
export type Maybe<T> = T | void | null | undefined | false;
/**
* Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
*
* similar to `Array.prototype.map`, but gets the value and index as accessors, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
*
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
*/
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
keyed?: boolean | ((item: Item) => any);
fallback?: Accessor<any>;
}): Accessor<MappedItem[]>;
/**
* Reactively repeats a callback function the count provided - underlying helper for the `<Repeat>` control flow
*
* @description https://docs.solidjs.com/reference/reactive-utilities/repeat
*/
export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
from?: Accessor<number | undefined>;
fallback?: Accessor<any>;
}): Accessor<any[]>;

View File

@@ -0,0 +1,161 @@
import type { SignalOptions } from "./core/index.js";
export type Accessor<T> = () => T;
export type Setter<in out T> = {
<U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
<U extends T>(value: (prev: T) => U): U;
<U extends T>(value: Exclude<U, Function>): U;
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
};
export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
export type EffectBundle<Prev, Next extends Prev = Prev> = {
effect: EffectFunction<Prev, Next>;
error: (err: unknown, cleanup: () => void) => void;
};
export interface EffectOptions {
name?: string;
defer?: boolean;
}
export interface MemoOptions<T> {
name?: string;
equals?: false | ((prev: T, next: T) => boolean);
}
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
/**
* Creates a simple reactive state with a getter and setter
* ```typescript
* const [state: Accessor<T>, setState: Setter<T>] = createSignal<T>(
* value: T,
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
* )
* ```
* @param value initial value of the state; if empty, the state's type will automatically extended with undefined; otherwise you need to extend the type manually if you want setting to undefined not be an error
* @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
*
* @returns ```typescript
* [state: Accessor<T>, setState: Setter<T>]
* ```
* * the Accessor is a function that returns the current value and registers each call to the reactive root
* * the Setter is a function that allows directly setting or mutating the value:
* ```typescript
* const [count, setCount] = createSignal(0);
* setCount(count => count + 1);
* ```
*
* @description https://docs.solidjs.com/reference/basic-reactivity/create-signal
*/
export declare function createSignal<T>(): Signal<T | undefined>;
export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
export declare function createSignal<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
/**
* Creates a readonly derived reactive memoized signal
* ```typescript
* export function createMemo<T>(
* compute: (v: T) => T,
* value?: T,
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
* ): () => T;
* ```
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
* @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
*
* @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
*/
export declare function createMemo<Next extends Prev, Prev = Next>(compute: ComputeFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(compute: ComputeFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
/**
* Creates a readonly derived async reactive memoized signal
* ```typescript
* export function createAsync<T>(
* compute: (v: T) => Promise<T> | T,
* value?: T,
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
* ): () => T;
* ```
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
* @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
*
* @description https://docs.solidjs.com/reference/basic-reactivity/create-async
*/
export declare function createAsync<T>(compute: (prev: T | undefined, refreshing: boolean) => Promise<T> | AsyncIterable<T> | T, value?: T, options?: MemoOptions<T>): Accessor<T> & {
refresh: () => void;
};
/**
* Creates a reactive effect that runs after the render phase
* ```typescript
* export function createEffect<T>(
* compute: (prev: T) => T,
* effect: (v: T, prev: T) => (() => void) | void,
* value?: T,
* options?: { name?: string }
* ): void;
* ```
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
* @param effect a function that receives the new value and is used to perform side effects, return a cleanup function to run on disposal
* @param error an optional function that receives an error if thrown during the computation
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
* @param options allows to set a name in dev mode for debugging purposes
*
* @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
*/
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effectFn: EffectFunction<NoInfer<Next>, Next> | EffectBundle<NoInfer<Next>, Next>): void;
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next> | EffectBundle<Next, Next>, value: Init, options?: EffectOptions): void;
/**
* Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
* ```typescript
* export function createRenderEffect<T>(
* compute: (prev: T) => T,
* effect: (v: T, prev: T) => (() => void) | void,
* value?: T,
* options?: { name?: string }
* ): void;
* ```
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
* @param effect a function that receives the new value and is used to perform side effects
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
* @param options allows to set a name in dev mode for debugging purposes
*
* @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
*/
export declare function createRenderEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effectFn: EffectFunction<NoInfer<Next>, Next>): void;
export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effectFn: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
/**
* Creates a tracked reactive effect that only tracks dependencies inside the effect itself
* ```typescript
* export function createTrackedEffect(
* compute: () => (() => void) | void,
* options?: { name?: string, defer?: boolean }
* ): void;
* ```
* @param compute a function that contains reactive reads to track and returns an optional cleanup function to run on disposal or before next execution
* @param options allows to set a name in dev mode for debugging purposes
*
* @description https://docs.solidjs.com/reference/secondary-primitives/create-tracked-effect
*/
export declare function createTrackedEffect(compute: () => void | (() => void), options?: EffectOptions): void;
/**
* Creates a reactive computation that runs after the render phase with flexible tracking
* ```typescript
* export function createReaction(
* onInvalidate: () => void,
* options?: { name?: string }
* ): (fn: () => void) => void;
* ```
* @param invalidated a function that is called when tracked function is invalidated.
* @param options allows to set a name in dev mode for debugging purposes
*
* @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
*/
export declare function createReaction(effectFn: EffectFunction<undefined> | EffectBundle<undefined>, options?: EffectOptions): (tracking: () => void) => void;
/**
* Returns a promise of the resolved value of a reactive expression
* @param fn a reactive expression to resolve
*/
export declare function resolve<T>(fn: () => T): Promise<T>;
export declare function createOptimistic<T>(): Signal<T | undefined>;
export declare function createOptimistic<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
export declare function createOptimistic<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
export declare function onSettled(callback: () => void | (() => void)): void;

View File

@@ -0,0 +1,7 @@
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
export type { Merge, Omit } from "./utils.js";
export { isWrappable, createStore, deep, $TRACK, $PROXY, $TARGET } from "./store.js";
export { createProjection } from "./projection.js";
export { createOptimisticStore } from "./optimistic.js";
export { reconcile } from "./reconcile.js";
export { snapshot, merge, omit } from "./utils.js";

View File

@@ -0,0 +1,22 @@
import { type Store, type StoreSetter } from "./store.js";
/**
* Creates an optimistic store that can be used to optimistically update a value
* and then revert it back to the previous value at end of transition.
* ```typescript
* export function createOptimistic<T>(
* fn: (store: T) => void,
* initial: T,
* options?: { key?: string | ((item: NonNullable<any>) => any); all?: boolean }
* ): [get: Store<T>, set: StoreSetter<T>];
* ```
* @param fn a function that receives the current store and can be used to mutate it directly inside a transition
* @param initial The initial value of the signal.
* @param options Optional signal options.
*
* @returns A tuple containing an accessor for the current value and a setter function to apply changes.
*/
export declare function createOptimisticStore<T extends object = {}>(initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => T | void, initial: T | Store<T>, options?: {
key?: string | ((item: NonNullable<any>) => any);
all?: boolean;
}): [get: Store<T>, set: StoreSetter<T>];

View File

@@ -0,0 +1,11 @@
import { type Store, type StoreOptions } from "./store.js";
export declare function createProjectionInternal<T extends object = {}>(fn: (draft: T) => void | T, initialValue?: T, options?: StoreOptions): {
store: Readonly<T>;
node: any;
};
/**
* Creates a mutable derived value
*
* @see {@link https://github.com/solidjs/x-reactivity#createprojection}
*/
export declare function createProjection<T extends Object = {}>(fn: (draft: T) => void | T, initialValue?: T, options?: StoreOptions): Store<T>;

View File

@@ -0,0 +1 @@
export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any), all?: boolean): (state: U) => void;

View File

@@ -0,0 +1,38 @@
import { type Computed, type Signal } from "../core/index.js";
export type Store<T> = Readonly<T>;
export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
export type StoreOptions = {
key?: string | ((item: NonNullable<any>) => any);
all?: boolean;
};
type DataNode = Signal<any>;
type DataNodes = Record<PropertyKey, DataNode>;
export declare const $TRACK: unique symbol, $DEEP: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_NODE = "n", STORE_HAS = "h", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f";
export type StoreNode = {
[$PROXY]: any;
[STORE_VALUE]: Record<PropertyKey, any>;
[STORE_OVERRIDE]?: Record<PropertyKey, any>;
[STORE_NODE]?: DataNodes;
[STORE_HAS]?: DataNodes;
[STORE_WRAP]?: (value: any, target?: StoreNode) => any;
[STORE_LOOKUP]?: WeakMap<any, any>;
[STORE_FIREWALL]?: () => Computed<any>;
};
export declare namespace SolidStore {
interface Unwrappable {
}
}
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: Record<PropertyKey, any>): any;
export declare const storeLookup: WeakMap<object, any>;
export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
export declare const storeTraps: ProxyHandler<StoreNode>;
export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
export declare function createStore<T extends object = {}>(fn: (store: T) => void | T, store: T | Store<T>, options?: StoreOptions): [get: Store<T>, set: StoreSetter<T>];
export declare function deep<T extends object>(store: Store<T>): Store<T>;
export {};

View File

@@ -0,0 +1,36 @@
/**
* Returns a non reactive copy of the store object.
* It will attempt to preserver the original reference unless the value has been modified.
* @param item store proxy object
*/
export declare function snapshot<T>(item: T): T;
export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
type DistributeOverride<T, F> = T extends undefined ? F : T;
type Override<T, U> = T extends any ? U extends any ? {
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
} & {
[K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K];
} : T & U : T & U;
type OverrideSpread<T, U> = T extends any ? {
[K in keyof ({
[K in keyof T]: any;
} & {
[K in keyof U]?: any;
} & {
[K in U extends any ? keyof U : keyof U]?: any;
})]: K extends keyof T ? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] : U extends any ? U[K & keyof U] : never;
} : T & U;
type Simplify<T> = T extends any ? {
[K in keyof T]: T[K];
} : T;
type _Merge<T extends unknown[], Curr = {}> = T extends [
infer Next | (() => infer Next),
...infer Rest
] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
export type Omit<T, K extends readonly (keyof T)[]> = {
[P in keyof T as Exclude<P, K[number]>]: T[P];
};
export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
export {};