mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-08 14:11:56 -07:00
websites: default: snapshot
This commit is contained in:
@@ -70,21 +70,13 @@ In contrast, existing alternatives tend to be either [very costly](https://studi
|
||||
- [`brk_store`](https://crates.io/crates/brk_store): A thin wrapper around [`fjall`](https://crates.io/crates/fjall)
|
||||
- [`brk_vec`](https://crates.io/crates/brk_vec): A push-only, truncable, compressable, saveable Vec
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
Deepest gratitude to the [Open Sats](https://opensats.org/) public charity. Their grant — from December 2024 to the present — has been critical in sustaining this project.
|
||||
|
||||
Heartfelt thanks go out to every donor on [Nostr](https://primal.net/p/npub1jagmm3x39lmwfnrtvxcs9ac7g300y3dusv9lgzhk2e4x5frpxlrqa73v44) and [Geyser.fund](https://geyser.fund/project/brk) whose support has ensured the availability of the [kibo.money](https://kibo.money) public instance.
|
||||
|
||||
## Hosting as a service
|
||||
|
||||
*Soon™*
|
||||
|
||||
If you'd like to have your own instance hosted for you please contact [hosting@bitcoinresearchkit.org](mailto:hosting@bitcoinresearchkit.org).
|
||||
|
||||
- 2 separate dedicated servers (1 GB/s each) with different ISPs and Cloudflare integration for enhanced performance and optimal availability
|
||||
- 99.99% SLA
|
||||
- Configurated for speed (`raw + eager`)
|
||||
- Configurated for speed
|
||||
- Updates delivered at your convenience
|
||||
- Direct communication for feature requests and support
|
||||
- Bitcoin Core or Knots with desired version
|
||||
@@ -93,6 +85,12 @@ If you'd like to have your own instance hosted for you please contact [hosting@b
|
||||
|
||||
Pricing: `0.01 BTC / month` *or* `0.1 BTC / year`
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
Deepest gratitude to the [Open Sats](https://opensats.org/) public charity. Their grant — from December 2024 to the present — has been critical in sustaining this project.
|
||||
|
||||
Heartfelt thanks go out to every donor on [Nostr](https://primal.net/p/npub1jagmm3x39lmwfnrtvxcs9ac7g300y3dusv9lgzhk2e4x5frpxlrqa73v44) and [Geyser.fund](https://geyser.fund/project/brk) whose support has ensured the availability of the [kibo.money](https://kibo.money) public instance.
|
||||
|
||||
## Donate
|
||||
|
||||
[`bc1q09 8zsm89 m7kgyz e338vf ejhpdt 92ua9p 3peuve`](bitcoin:bc1q098zsm89m7kgyze338vfejhpdt92ua9p3peuve)
|
||||
|
||||
+10
-29
@@ -1,4 +1,4 @@
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
@@ -649,17 +649,9 @@
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2rem;
|
||||
padding-bottom: var(--bottom-area);
|
||||
}
|
||||
|
||||
nav {
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
sup {
|
||||
opacity: 0.5;
|
||||
margin-left: 0.25rem;
|
||||
@@ -728,6 +720,7 @@
|
||||
*/
|
||||
|
||||
.tree {
|
||||
margin-top: -0.125rem;
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
|
||||
@@ -800,14 +793,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
search {
|
||||
ul {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
#share-div {
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: var(--line-height-sm);
|
||||
@@ -848,16 +833,12 @@
|
||||
}
|
||||
|
||||
search {
|
||||
> #search-no-input-text {
|
||||
color: var(--off-color);
|
||||
gap: 1rem;
|
||||
|
||||
&:has(+ ul li) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
> button {
|
||||
color: var(--color);
|
||||
}
|
||||
ul {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1133,7 +1114,7 @@
|
||||
// @ts-check
|
||||
|
||||
const preferredColorSchemeMatchMedia = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
"(prefers-color-scheme: dark)"
|
||||
);
|
||||
|
||||
const themeColor = window.document.createElement("meta");
|
||||
@@ -1143,7 +1124,7 @@
|
||||
/** @param {boolean} dark */
|
||||
function updateThemeColor(dark) {
|
||||
const backgroundColor = getComputedStyle(
|
||||
window.document.documentElement,
|
||||
window.document.documentElement
|
||||
).getPropertyValue(dark ? "--black" : "--white");
|
||||
themeColor.content = backgroundColor;
|
||||
}
|
||||
@@ -1153,7 +1134,7 @@
|
||||
"change",
|
||||
({ matches }) => {
|
||||
updateThemeColor(matches);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if ("standalone" in window.navigator && !!window.navigator.standalone) {
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"checkJs": true,
|
||||
"strict": true,
|
||||
"target": "ESNext",
|
||||
"module": "ESNext"
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["assets", "packages", "ignore"]
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
-241
@@ -1,241 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
export type RGBA = readonly [number, number, number, number?];
|
||||
|
||||
export interface Bitmap1D {
|
||||
push(value: number, bits: number): void;
|
||||
}
|
||||
|
||||
export interface StringOptions {
|
||||
on?: string;
|
||||
off?: string;
|
||||
lf?: string;
|
||||
padX?: number;
|
||||
padY?: number;
|
||||
}
|
||||
|
||||
export interface ImageDataOptions {
|
||||
on?: RGBA;
|
||||
off?: RGBA;
|
||||
padX?: number;
|
||||
padY?: number;
|
||||
}
|
||||
|
||||
export interface Bitmap2D {
|
||||
readonly size: number;
|
||||
|
||||
get(x: number, y: number): boolean;
|
||||
|
||||
toString(options?: Readonly<StringOptions>): string;
|
||||
|
||||
toImageData<DataT extends ImageDataLike>(
|
||||
context: Context2DLike<DataT>,
|
||||
options?: Readonly<ImageDataOptions>,
|
||||
): DataT;
|
||||
|
||||
toDataURL(
|
||||
options?: Readonly<
|
||||
ImageDataOptions & {
|
||||
type?: `image/${string}`;
|
||||
scale?: number;
|
||||
}
|
||||
>,
|
||||
): string;
|
||||
|
||||
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;
|
||||
test(string: string): boolean;
|
||||
est(value: string, version: number): number;
|
||||
eci?: number;
|
||||
}
|
||||
|
||||
interface ModeAutoOptions {
|
||||
modes?: ReadonlyArray<ModeFactory>;
|
||||
}
|
||||
|
||||
export const mode: Readonly<{
|
||||
auto(value: string, options?: Readonly<ModeAutoOptions>): Mode;
|
||||
multi(...modes: ReadonlyArray<Mode>): Mode;
|
||||
eci(id: number): Mode;
|
||||
numeric: ModeFactory;
|
||||
alphaNumeric: ModeFactory;
|
||||
bytes(data: Uint8Array | ReadonlyArray<number>): Mode;
|
||||
ascii: ModeFactory;
|
||||
iso8859_1: ModeFactory;
|
||||
shift_jis: ModeFactory;
|
||||
utf8: ModeFactory;
|
||||
}>;
|
||||
|
||||
type Correction = number & { readonly _: unique symbol };
|
||||
export const correction: Readonly<{
|
||||
min: Correction;
|
||||
L: Correction;
|
||||
M: Correction;
|
||||
Q: Correction;
|
||||
H: Correction;
|
||||
max: Correction;
|
||||
}>;
|
||||
|
||||
export interface GenerateOptions extends ModeAutoOptions {
|
||||
minCorrectionLevel?: Correction;
|
||||
maxCorrectionLevel?: Correction;
|
||||
minVersion?: number;
|
||||
maxVersion?: number;
|
||||
mask?: null | Mask;
|
||||
trailer?: number;
|
||||
}
|
||||
|
||||
export type GenerateFn = (
|
||||
data: Mode | string,
|
||||
options?: Readonly<GenerateOptions>,
|
||||
) => Bitmap2D;
|
||||
interface Generate extends GenerateFn {
|
||||
with(...modes: ReadonlyArray<ModeFactory>): GenerateFn;
|
||||
}
|
||||
export const generate: Generate;
|
||||
}
|
||||
|
||||
declare module "lean-qr/extras/svg" {
|
||||
import type { Bitmap2D } from "lean-qr";
|
||||
|
||||
export interface SVGOptions {
|
||||
on?: string;
|
||||
off?: string;
|
||||
padX?: number;
|
||||
padY?: number;
|
||||
width?: number | null;
|
||||
height?: number | null;
|
||||
scale?: number;
|
||||
}
|
||||
|
||||
export const toSvgPath: (code: Bitmap2D) => string;
|
||||
|
||||
export const toSvg: (
|
||||
code: Bitmap2D,
|
||||
target: Document | SVGElement,
|
||||
options?: Readonly<SVGOptions>,
|
||||
) => SVGElement;
|
||||
|
||||
export const toSvgSource: (
|
||||
code: Bitmap2D,
|
||||
options?: Readonly<SVGOptions & { xmlDeclaration?: boolean }>,
|
||||
) => string;
|
||||
|
||||
export type toSvgDataURLFn = (
|
||||
code: Bitmap2D,
|
||||
options?: Readonly<SVGOptions>,
|
||||
) => string;
|
||||
export const toSvgDataURL: toSvgDataURLFn;
|
||||
}
|
||||
|
||||
declare module "lean-qr/extras/node_export" {
|
||||
import type { RGBA, Bitmap2D } from "lean-qr";
|
||||
|
||||
export interface PNGOptions {
|
||||
on?: RGBA;
|
||||
off?: RGBA;
|
||||
padX?: number;
|
||||
padY?: number;
|
||||
scale?: number;
|
||||
}
|
||||
|
||||
export const toPngBuffer: (
|
||||
code: Bitmap2D,
|
||||
options?: Readonly<PNGOptions>,
|
||||
) => Uint8Array;
|
||||
|
||||
export const toPngDataURL: (
|
||||
code: Bitmap2D,
|
||||
options?: Readonly<PNGOptions>,
|
||||
) => string;
|
||||
}
|
||||
|
||||
declare module "lean-qr/extras/react" {
|
||||
import type { ImageDataOptions, GenerateOptions, GenerateFn } from "lean-qr";
|
||||
import type { SVGOptions, 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;
|
||||
|
||||
export const makeAsyncComponent: <T>(
|
||||
framework: Readonly<AsyncFramework<T>>,
|
||||
generate: GenerateFn,
|
||||
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;
|
||||
|
||||
export const makeSyncComponent: <T>(
|
||||
framework: Readonly<SyncFramework<T>>,
|
||||
generate: GenerateFn,
|
||||
toSvgDataURL: toSvgDataURLFn,
|
||||
defaultProps?: Readonly<Partial<SyncQRComponentProps>>,
|
||||
) => SyncQRComponent<T>;
|
||||
}
|
||||
|
||||
declare module "lean-qr/extras/errors" {
|
||||
export const readError: (error: unknown) => string;
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
+491
@@ -0,0 +1,491 @@
|
||||
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 on the left and right of the output (populated with 'off' modules) */
|
||||
padX?: number;
|
||||
|
||||
/** the padding to apply on the top and bottom of the output (populated with 'off' modules) */
|
||||
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 on the left and right of the output (filled with 'off') */
|
||||
padX?: number;
|
||||
|
||||
/** the padding to apply on the top and bottom of the output (filled with 'off') */
|
||||
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) */
|
||||
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) */
|
||||
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.
|
||||
*/
|
||||
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 on the left and right of the output (filled with 'off') */
|
||||
padX?: number;
|
||||
/** the padding to apply on the top and bottom of the output (filled with 'off') */
|
||||
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 on the left and right of the output (filled with 'off') */
|
||||
padX?: number;
|
||||
/** the padding to apply on the top and bottom of the output (filled with 'off') */
|
||||
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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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/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 it is too large
Load Diff
@@ -99,12 +99,12 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
index === /** @satisfies {MonthIndex} */ (7)
|
||||
? 1
|
||||
: index === /** @satisfies {QuarterIndex} */ (19)
|
||||
? 3
|
||||
: index === /** @satisfies {YearIndex} */ (23)
|
||||
? 12
|
||||
: index === /** @satisfies {DecadeIndex} */ (1)
|
||||
? 120
|
||||
: undefined,
|
||||
? 3
|
||||
: index === /** @satisfies {YearIndex} */ (23)
|
||||
? 12
|
||||
: index === /** @satisfies {DecadeIndex} */ (1)
|
||||
? 120
|
||||
: undefined,
|
||||
},
|
||||
crosshair: {
|
||||
horzLine: {
|
||||
@@ -118,7 +118,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
mode: 3,
|
||||
},
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return chart;
|
||||
@@ -178,7 +178,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
|
||||
if (fitContentOnResize) {
|
||||
new ResizeObserver(() => ichart?.timeScale().fitContent()).observe(
|
||||
chartDiv,
|
||||
chartDiv
|
||||
);
|
||||
}
|
||||
|
||||
@@ -217,27 +217,34 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
const time = indexes[i];
|
||||
if (prevTime === time) {
|
||||
const sameTime = prevTime === time;
|
||||
if (sameTime) {
|
||||
offset += 1;
|
||||
}
|
||||
const v = ohlcs[i];
|
||||
const offsetedI = i - offset;
|
||||
if (v === null) {
|
||||
data[i - offset] = {
|
||||
data[offsetedI] = {
|
||||
time,
|
||||
value: NaN,
|
||||
};
|
||||
} else if (typeof v === "number") {
|
||||
data[i - offset] = {
|
||||
data[offsetedI] = {
|
||||
time,
|
||||
value: v,
|
||||
};
|
||||
} else {
|
||||
data[i - offset] = {
|
||||
if (sameTime) {
|
||||
console.log(data[offsetedI]);
|
||||
}
|
||||
// const prev = sameTime ? data[offsetedI] : undefined;
|
||||
let [open, high, low, close] = v;
|
||||
data[offsetedI] = {
|
||||
time,
|
||||
open: v[0],
|
||||
high: v[1],
|
||||
low: v[2],
|
||||
close: v[3],
|
||||
open: sameTime ? data[offsetedI].open : open,
|
||||
high: sameTime ? Math.max(data[offsetedI].high, high) : high,
|
||||
low: sameTime ? Math.min(data[offsetedI].low, low) : low,
|
||||
close,
|
||||
};
|
||||
}
|
||||
prevTime = time;
|
||||
@@ -259,8 +266,8 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
}
|
||||
});
|
||||
timeScaleSet = true;
|
||||
},
|
||||
),
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -271,7 +278,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
activeResources.forEach((v) => {
|
||||
v.fetch();
|
||||
});
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const chart = {
|
||||
@@ -291,7 +298,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
vecIndex,
|
||||
vecIndex === /** @satisfies {Height} */ (5)
|
||||
? "timestamp-fixed"
|
||||
: "timestamp",
|
||||
: "timestamp"
|
||||
);
|
||||
timeResource.fetch();
|
||||
|
||||
@@ -349,7 +356,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
borderVisible: false,
|
||||
visible: defaultActive !== false,
|
||||
},
|
||||
paneIndex,
|
||||
paneIndex
|
||||
);
|
||||
|
||||
let url = /** @type {string | undefined} */ (undefined);
|
||||
@@ -365,7 +372,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
signals.runWithOwner(owner, () =>
|
||||
signals.createEffect(data, (data) => {
|
||||
series.setData(data);
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -429,7 +436,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
color: color(),
|
||||
...options,
|
||||
},
|
||||
paneIndex,
|
||||
paneIndex
|
||||
);
|
||||
|
||||
const priceLineOptions = options?.createPriceLine;
|
||||
@@ -452,7 +459,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
ichart
|
||||
?.timeScale()
|
||||
.setVisibleLogicalRange({ from: -1, to: data.length });
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -521,7 +528,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
topFillColor2: "transparent",
|
||||
lineVisible: true,
|
||||
},
|
||||
paneIndex,
|
||||
paneIndex
|
||||
);
|
||||
|
||||
const priceLineOptions = options?.createPriceLine;
|
||||
@@ -545,7 +552,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
ichart
|
||||
?.timeScale()
|
||||
.setVisibleLogicalRange({ from: -1, to: data.length });
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -638,7 +645,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
Array.from(parent.childNodes).filter(
|
||||
(element) =>
|
||||
/** @type {HTMLElement} */ (element).dataset.position ===
|
||||
position,
|
||||
position
|
||||
).length
|
||||
) {
|
||||
return;
|
||||
@@ -657,7 +664,7 @@ export default import("./v5.0.7-treeshaked/script.js").then((lc) => {
|
||||
|
||||
fieldset.append(createChild({ owner, pane }));
|
||||
},
|
||||
paneIndex ? 50 : 0,
|
||||
paneIndex ? 50 : 0
|
||||
);
|
||||
},
|
||||
/**
|
||||
@@ -730,7 +737,7 @@ function createLegend({ parent, signals, utils, paneIndex }) {
|
||||
parent.append(legendElement);
|
||||
|
||||
const hovered = signals.createSignal(
|
||||
/** @type {ISeriesApi<SeriesType> | null} */ (null),
|
||||
/** @type {ISeriesApi<SeriesType> | null} */ (null)
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -823,7 +830,7 @@ function createLegend({ parent, signals, utils, paneIndex }) {
|
||||
} else {
|
||||
spanColor.style.backgroundColor = tameColor(color);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -899,7 +906,7 @@ function createOklchToRGBA() {
|
||||
return rgb.map((c) =>
|
||||
Math.abs(c) > 0.0031308
|
||||
? (c < 0 ? -1 : 1) * (1.055 * Math.abs(c) ** (1 / 2.4) - 0.055)
|
||||
: 12.92 * c,
|
||||
: 12.92 * c
|
||||
);
|
||||
}
|
||||
/**
|
||||
@@ -911,7 +918,7 @@ function createOklchToRGBA() {
|
||||
1, 0.3963377773761749, 0.2158037573099136, 1, -0.1055613458156586,
|
||||
-0.0638541728258133, 1, -0.0894841775298119, -1.2914855480194092,
|
||||
]),
|
||||
lab,
|
||||
lab
|
||||
);
|
||||
const LMS = /** @type {[number, number, number]} */ (
|
||||
LMSg.map((val) => val ** 3)
|
||||
@@ -922,7 +929,7 @@ function createOklchToRGBA() {
|
||||
-0.0405757452148008, 1.112286803280317, -0.0717110580655164,
|
||||
-0.0763729366746601, -0.4214933324022432, 1.5869240198367816,
|
||||
]),
|
||||
LMS,
|
||||
LMS
|
||||
);
|
||||
}
|
||||
/**
|
||||
@@ -935,7 +942,7 @@ function createOklchToRGBA() {
|
||||
-0.9692436362808796, 1.8759675015077202, 0.04155505740717559,
|
||||
0.05563007969699366, -0.20397695888897652, 1.0569715142428786,
|
||||
],
|
||||
xyz,
|
||||
xyz
|
||||
);
|
||||
}
|
||||
|
||||
@@ -958,8 +965,8 @@ function createOklchToRGBA() {
|
||||
});
|
||||
const rgb = srgbLinear2rgb(
|
||||
xyz2rgbLinear(
|
||||
oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch))),
|
||||
),
|
||||
oklab2xyz(oklch2oklab(/** @type {[number, number, number]} */ (lch)))
|
||||
)
|
||||
).map((v) => {
|
||||
return Math.max(Math.min(Math.round(v * 255), 255), 0);
|
||||
});
|
||||
|
||||
@@ -1,686 +0,0 @@
|
||||
// @ts-nocheck
|
||||
// src/core/error.ts
|
||||
var NotReadyError = class extends Error {
|
||||
};
|
||||
var EffectError = class extends Error {
|
||||
constructor(effect, cause) {
|
||||
super("");
|
||||
this.cause = cause;
|
||||
}
|
||||
};
|
||||
|
||||
// src/core/constants.ts
|
||||
var STATE_CLEAN = 0;
|
||||
var STATE_CHECK = 1;
|
||||
var STATE_DIRTY = 2;
|
||||
var STATE_DISPOSED = 3;
|
||||
var EFFECT_PURE = 0;
|
||||
var EFFECT_RENDER = 1;
|
||||
var EFFECT_USER = 2;
|
||||
|
||||
// src/core/scheduler.ts
|
||||
var clock = 0;
|
||||
function getClock() {
|
||||
return clock;
|
||||
}
|
||||
function incrementClock() {
|
||||
clock++;
|
||||
}
|
||||
var scheduled = false;
|
||||
function schedule() {
|
||||
if (scheduled)
|
||||
return;
|
||||
scheduled = true;
|
||||
if (!globalQueue.y)
|
||||
queueMicrotask(flushSync);
|
||||
}
|
||||
var Queue = class {
|
||||
i = null;
|
||||
y = false;
|
||||
m = [[], [], []];
|
||||
v = [];
|
||||
created = clock;
|
||||
enqueue(type, node) {
|
||||
this.m[0].push(node);
|
||||
if (type)
|
||||
this.m[type].push(node);
|
||||
schedule();
|
||||
}
|
||||
run(type) {
|
||||
if (this.m[type].length) {
|
||||
if (type === EFFECT_PURE) {
|
||||
runPureQueue(this.m[type]);
|
||||
this.m[type] = [];
|
||||
} else {
|
||||
const effects = this.m[type];
|
||||
this.m[type] = [];
|
||||
runEffectQueue(effects);
|
||||
}
|
||||
}
|
||||
let rerun = false;
|
||||
for (let i = 0; i < this.v.length; i++) {
|
||||
rerun = this.v[i].run(type) || rerun;
|
||||
}
|
||||
if (type === EFFECT_PURE)
|
||||
return rerun || !!this.m[type].length;
|
||||
}
|
||||
flush() {
|
||||
if (this.y)
|
||||
return;
|
||||
this.y = true;
|
||||
try {
|
||||
while (this.run(EFFECT_PURE)) {
|
||||
}
|
||||
incrementClock();
|
||||
scheduled = false;
|
||||
this.run(EFFECT_RENDER);
|
||||
this.run(EFFECT_USER);
|
||||
} finally {
|
||||
this.y = false;
|
||||
}
|
||||
}
|
||||
addChild(child) {
|
||||
this.v.push(child);
|
||||
child.i = this;
|
||||
}
|
||||
removeChild(child) {
|
||||
const index = this.v.indexOf(child);
|
||||
if (index >= 0)
|
||||
this.v.splice(index, 1);
|
||||
}
|
||||
notify(...args) {
|
||||
if (this.i)
|
||||
return this.i.notify(...args);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var globalQueue = new Queue();
|
||||
function flushSync() {
|
||||
while (scheduled) {
|
||||
globalQueue.flush();
|
||||
}
|
||||
}
|
||||
function runTop(node) {
|
||||
const ancestors = [];
|
||||
for (let current = node; current !== null; current = current.i) {
|
||||
if (current.a !== STATE_CLEAN) {
|
||||
ancestors.push(current);
|
||||
}
|
||||
}
|
||||
for (let i = ancestors.length - 1; i >= 0; i--) {
|
||||
if (ancestors[i].a !== STATE_DISPOSED)
|
||||
ancestors[i].p();
|
||||
}
|
||||
}
|
||||
function runPureQueue(queue) {
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
if (queue[i].a !== STATE_CLEAN)
|
||||
runTop(queue[i]);
|
||||
}
|
||||
}
|
||||
function runEffectQueue(queue) {
|
||||
for (let i = 0; i < queue.length; i++)
|
||||
queue[i].L();
|
||||
}
|
||||
|
||||
// src/core/owner.ts
|
||||
var currentOwner = null;
|
||||
var defaultContext = {};
|
||||
function getOwner() {
|
||||
return currentOwner;
|
||||
}
|
||||
function setOwner(owner) {
|
||||
const out = currentOwner;
|
||||
currentOwner = owner;
|
||||
return out;
|
||||
}
|
||||
function formatId(prefix, id) {
|
||||
const num = id.toString(36), len = num.length - 1;
|
||||
return prefix + (len ? String.fromCharCode(64 + len) : "") + num;
|
||||
}
|
||||
var Owner = class {
|
||||
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
||||
// However, the children are actually added in reverse creation order
|
||||
// See comment at the top of the file for an example of the _nextSibling traversal
|
||||
i = null;
|
||||
g = null;
|
||||
n = null;
|
||||
a = STATE_CLEAN;
|
||||
h = null;
|
||||
j = defaultContext;
|
||||
f = globalQueue;
|
||||
G = null;
|
||||
M = 0;
|
||||
id = null;
|
||||
constructor(id = null, skipAppend = false) {
|
||||
this.id = id;
|
||||
if (currentOwner && !skipAppend)
|
||||
currentOwner.append(this);
|
||||
}
|
||||
append(child) {
|
||||
child.i = this;
|
||||
child.n = this;
|
||||
if (this.id) {
|
||||
child.G = this.g ? this.g.G + 1 : 0;
|
||||
child.id = formatId(this.id, child.G);
|
||||
}
|
||||
if (this.g)
|
||||
this.g.n = child;
|
||||
child.g = this.g;
|
||||
this.g = child;
|
||||
if (child.j !== this.j) {
|
||||
child.j = { ...this.j, ...child.j };
|
||||
}
|
||||
if (this.f)
|
||||
child.f = this.f;
|
||||
}
|
||||
dispose(self = true) {
|
||||
if (this.a === STATE_DISPOSED)
|
||||
return;
|
||||
let head = self ? this.n || this.i : this, current = this.g, next = null;
|
||||
while (current && current.i === this) {
|
||||
current.dispose(true);
|
||||
current.q();
|
||||
next = current.g;
|
||||
current.g = null;
|
||||
current = next;
|
||||
}
|
||||
this.M = 0;
|
||||
if (self)
|
||||
this.q();
|
||||
if (current)
|
||||
current.n = !self ? this : this.n;
|
||||
if (head)
|
||||
head.g = current;
|
||||
}
|
||||
q() {
|
||||
if (this.n)
|
||||
this.n.g = null;
|
||||
this.i = null;
|
||||
this.n = null;
|
||||
this.j = defaultContext;
|
||||
this.a = STATE_DISPOSED;
|
||||
this.emptyDisposal();
|
||||
}
|
||||
emptyDisposal() {
|
||||
if (!this.h)
|
||||
return;
|
||||
if (Array.isArray(this.h)) {
|
||||
for (let i = 0; i < this.h.length; i++) {
|
||||
const callable = this.h[i];
|
||||
callable.call(callable);
|
||||
}
|
||||
} else {
|
||||
this.h.call(this.h);
|
||||
}
|
||||
this.h = null;
|
||||
}
|
||||
getNextChildId() {
|
||||
if (this.id)
|
||||
return formatId(this.id + "-", this.M++);
|
||||
throw new Error("Cannot get child id from owner without an id");
|
||||
}
|
||||
};
|
||||
function onCleanup(fn) {
|
||||
if (!currentOwner)
|
||||
return fn;
|
||||
const node = currentOwner;
|
||||
if (!node.h) {
|
||||
node.h = fn;
|
||||
} else if (Array.isArray(node.h)) {
|
||||
node.h.push(fn);
|
||||
} else {
|
||||
node.h = [node.h, fn];
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
// src/core/flags.ts
|
||||
var ERROR_OFFSET = 0;
|
||||
var ERROR_BIT = 1 << ERROR_OFFSET;
|
||||
var LOADING_OFFSET = 1;
|
||||
var LOADING_BIT = 1 << LOADING_OFFSET;
|
||||
var UNINITIALIZED_OFFSET = 2;
|
||||
var UNINITIALIZED_BIT = 1 << UNINITIALIZED_OFFSET;
|
||||
var DEFAULT_FLAGS = ERROR_BIT;
|
||||
|
||||
// src/core/core.ts
|
||||
var currentObserver = null;
|
||||
var currentMask = DEFAULT_FLAGS;
|
||||
var newSources = null;
|
||||
var newSourcesIndex = 0;
|
||||
var newFlags = 0;
|
||||
var notStale = false;
|
||||
var UNCHANGED = Symbol(0);
|
||||
var Computation = class extends Owner {
|
||||
b = null;
|
||||
c = null;
|
||||
e;
|
||||
w;
|
||||
r;
|
||||
// Used in __DEV__ mode, hopefully removed in production
|
||||
Q;
|
||||
// Using false is an optimization as an alternative to _equals: () => false
|
||||
// which could enable more efficient DIRTY notification
|
||||
H = isEqual;
|
||||
N;
|
||||
/** Whether the computation is an error or has ancestors that are unresolved */
|
||||
d = 0;
|
||||
/** Which flags raised by sources are handled, vs. being passed through. */
|
||||
I = DEFAULT_FLAGS;
|
||||
s = -1;
|
||||
z = false;
|
||||
constructor(initialValue, compute2, options) {
|
||||
super(null, compute2 === null);
|
||||
this.r = compute2;
|
||||
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
||||
this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
||||
this.e = initialValue;
|
||||
if (options?.equals !== void 0)
|
||||
this.H = options.equals;
|
||||
if (options?.unobserved)
|
||||
this.N = options?.unobserved;
|
||||
}
|
||||
O() {
|
||||
if (this.r) {
|
||||
if (this.d & ERROR_BIT && this.s <= getClock())
|
||||
update(this);
|
||||
else
|
||||
this.p();
|
||||
}
|
||||
track(this);
|
||||
newFlags |= this.d & ~currentMask;
|
||||
if (this.d & ERROR_BIT) {
|
||||
throw this.w;
|
||||
} else {
|
||||
return this.e;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*/
|
||||
read() {
|
||||
return this.O();
|
||||
}
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*
|
||||
* If the computation has any unresolved ancestors, this function waits for the value to resolve
|
||||
* before continuing
|
||||
*/
|
||||
wait() {
|
||||
if (this.r && this.d & ERROR_BIT && this.s <= getClock()) {
|
||||
update(this);
|
||||
} else {
|
||||
this.p();
|
||||
}
|
||||
track(this);
|
||||
if ((notStale || this.d & UNINITIALIZED_BIT) && this.d & LOADING_BIT) {
|
||||
throw new NotReadyError();
|
||||
}
|
||||
return this.O();
|
||||
}
|
||||
/** Update the computation with a new value. */
|
||||
write(value, flags = 0, raw = false) {
|
||||
const newValue = !raw && typeof value === "function" ? value(this.e) : value;
|
||||
const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.d & LOADING_BIT & ~flags || this.H === false || !this.H(this.e, newValue));
|
||||
if (valueChanged) {
|
||||
this.e = newValue;
|
||||
this.w = void 0;
|
||||
}
|
||||
const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
|
||||
this.d = flags;
|
||||
this.s = getClock() + 1;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
if (valueChanged) {
|
||||
this.c[i].l(STATE_DIRTY);
|
||||
} else if (changedFlagsMask) {
|
||||
this.c[i].P(changedFlagsMask, changedFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.e;
|
||||
}
|
||||
/**
|
||||
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
||||
*/
|
||||
l(state, skipQueue) {
|
||||
if (this.a >= state && !this.z)
|
||||
return;
|
||||
this.z = !!skipQueue;
|
||||
this.a = state;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
this.c[i].l(STATE_CHECK, skipQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Notify the computation that one of its sources has changed flags.
|
||||
*
|
||||
* @param mask A bitmask for which flag(s) were changed.
|
||||
* @param newFlags The source's new flags, masked to just the changed ones.
|
||||
*/
|
||||
P(mask, newFlags2) {
|
||||
if (this.a >= STATE_DIRTY)
|
||||
return;
|
||||
if (mask & this.I) {
|
||||
this.l(STATE_DIRTY);
|
||||
return;
|
||||
}
|
||||
if (this.a >= STATE_CHECK)
|
||||
return;
|
||||
const prevFlags = this.d & mask;
|
||||
const deltaFlags = prevFlags ^ newFlags2;
|
||||
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
||||
this.l(STATE_CHECK);
|
||||
} else {
|
||||
this.d ^= deltaFlags;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
this.c[i].P(mask, newFlags2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
J(error) {
|
||||
this.w = error;
|
||||
this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
||||
}
|
||||
/**
|
||||
* This is the core part of the reactivity system, which makes sure that the values are updated
|
||||
* before they are read. We've also adapted it to return the loading state of the computation,
|
||||
* so that we can propagate that to the computation's observers.
|
||||
*
|
||||
* This function will ensure that the value and states we read from the computation are up to date
|
||||
*/
|
||||
p() {
|
||||
if (!this.r) {
|
||||
return;
|
||||
}
|
||||
if (this.a === STATE_DISPOSED) {
|
||||
return;
|
||||
}
|
||||
if (this.a === STATE_CLEAN) {
|
||||
return;
|
||||
}
|
||||
let observerFlags = 0;
|
||||
if (this.a === STATE_CHECK) {
|
||||
for (let i = 0; i < this.b.length; i++) {
|
||||
this.b[i].p();
|
||||
observerFlags |= this.b[i].d;
|
||||
if (this.a === STATE_DIRTY) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.a === STATE_DIRTY) {
|
||||
update(this);
|
||||
} else {
|
||||
this.write(UNCHANGED, observerFlags);
|
||||
this.a = STATE_CLEAN;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Remove ourselves from the owner graph and the computation graph
|
||||
*/
|
||||
q() {
|
||||
if (this.a === STATE_DISPOSED)
|
||||
return;
|
||||
if (this.b)
|
||||
removeSourceObservers(this, 0);
|
||||
super.q();
|
||||
}
|
||||
};
|
||||
function track(computation) {
|
||||
if (currentObserver) {
|
||||
if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
|
||||
newSourcesIndex++;
|
||||
} else if (!newSources)
|
||||
newSources = [computation];
|
||||
else if (computation !== newSources[newSources.length - 1]) {
|
||||
newSources.push(computation);
|
||||
}
|
||||
}
|
||||
}
|
||||
function update(node) {
|
||||
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
||||
newSources = null;
|
||||
newSourcesIndex = 0;
|
||||
newFlags = 0;
|
||||
try {
|
||||
node.dispose(false);
|
||||
node.emptyDisposal();
|
||||
const result = compute(node, node.r, node);
|
||||
node.write(result, newFlags, true);
|
||||
} catch (error) {
|
||||
if (error instanceof NotReadyError) {
|
||||
node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
|
||||
} else {
|
||||
node.J(error);
|
||||
}
|
||||
} finally {
|
||||
if (newSources) {
|
||||
if (node.b)
|
||||
removeSourceObservers(node, newSourcesIndex);
|
||||
if (node.b && newSourcesIndex > 0) {
|
||||
node.b.length = newSourcesIndex + newSources.length;
|
||||
for (let i = 0; i < newSources.length; i++) {
|
||||
node.b[newSourcesIndex + i] = newSources[i];
|
||||
}
|
||||
} else {
|
||||
node.b = newSources;
|
||||
}
|
||||
let source;
|
||||
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
||||
source = node.b[i];
|
||||
if (!source.c)
|
||||
source.c = [node];
|
||||
else
|
||||
source.c.push(node);
|
||||
}
|
||||
} else if (node.b && newSourcesIndex < node.b.length) {
|
||||
removeSourceObservers(node, newSourcesIndex);
|
||||
node.b.length = newSourcesIndex;
|
||||
}
|
||||
newSources = prevSources;
|
||||
newSourcesIndex = prevSourcesIndex;
|
||||
newFlags = prevFlags;
|
||||
node.s = getClock() + 1;
|
||||
node.a = STATE_CLEAN;
|
||||
}
|
||||
}
|
||||
function removeSourceObservers(node, index) {
|
||||
let source;
|
||||
let swap;
|
||||
for (let i = index; i < node.b.length; i++) {
|
||||
source = node.b[i];
|
||||
if (source.c) {
|
||||
swap = source.c.indexOf(node);
|
||||
source.c[swap] = source.c[source.c.length - 1];
|
||||
source.c.pop();
|
||||
if (!source.c.length)
|
||||
source.N?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
function isEqual(a, b) {
|
||||
return a === b;
|
||||
}
|
||||
function untrack(fn) {
|
||||
if (currentObserver === null)
|
||||
return fn();
|
||||
return compute(getOwner(), fn, null);
|
||||
}
|
||||
function latest(fn, fallback) {
|
||||
const argLength = arguments.length;
|
||||
const prevFlags = newFlags;
|
||||
const prevNotStale = notStale;
|
||||
notStale = false;
|
||||
try {
|
||||
return fn();
|
||||
} catch (err) {
|
||||
if (argLength > 1 && err instanceof NotReadyError)
|
||||
return fallback;
|
||||
throw err;
|
||||
} finally {
|
||||
newFlags = prevFlags;
|
||||
notStale = prevNotStale;
|
||||
}
|
||||
}
|
||||
function compute(owner, fn, observer) {
|
||||
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
||||
currentObserver = observer;
|
||||
currentMask = observer?.I ?? DEFAULT_FLAGS;
|
||||
notStale = true;
|
||||
try {
|
||||
return fn(observer ? observer.e : void 0);
|
||||
} finally {
|
||||
setOwner(prevOwner);
|
||||
currentObserver = prevObserver;
|
||||
currentMask = prevMask;
|
||||
notStale = prevNotStale;
|
||||
}
|
||||
}
|
||||
|
||||
// src/core/effect.ts
|
||||
var Effect = class extends Computation {
|
||||
A;
|
||||
B;
|
||||
t;
|
||||
K = false;
|
||||
C;
|
||||
o;
|
||||
constructor(initialValue, compute2, effect, error, options) {
|
||||
super(initialValue, compute2, options);
|
||||
this.A = effect;
|
||||
this.B = error;
|
||||
this.C = initialValue;
|
||||
this.o = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
||||
if (this.o === EFFECT_RENDER) {
|
||||
this.r = (p) => getClock() > this.f.created && !(this.d & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
||||
}
|
||||
this.p();
|
||||
!options?.defer && (this.o === EFFECT_USER ? this.f.enqueue(this.o, this) : this.L());
|
||||
}
|
||||
write(value, flags = 0) {
|
||||
if (this.a == STATE_DIRTY) {
|
||||
this.d;
|
||||
this.d = flags;
|
||||
if (this.o === EFFECT_RENDER) {
|
||||
this.f.notify(this, LOADING_BIT | ERROR_BIT, flags);
|
||||
}
|
||||
}
|
||||
if (value === UNCHANGED)
|
||||
return this.e;
|
||||
this.e = value;
|
||||
this.K = true;
|
||||
return value;
|
||||
}
|
||||
l(state, skipQueue) {
|
||||
if (this.a >= state || skipQueue)
|
||||
return;
|
||||
if (this.a === STATE_CLEAN)
|
||||
this.f.enqueue(this.o, this);
|
||||
this.a = state;
|
||||
}
|
||||
J(error) {
|
||||
this.w = error;
|
||||
this.t?.();
|
||||
this.f.notify(this, LOADING_BIT, 0);
|
||||
this.d = ERROR_BIT;
|
||||
if (this.o === EFFECT_USER) {
|
||||
try {
|
||||
return this.B ? this.t = this.B(error) : console.error(new EffectError(this.A, error));
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
if (!this.f.notify(this, ERROR_BIT, ERROR_BIT))
|
||||
throw error;
|
||||
}
|
||||
q() {
|
||||
if (this.a === STATE_DISPOSED)
|
||||
return;
|
||||
this.A = void 0;
|
||||
this.C = void 0;
|
||||
this.B = void 0;
|
||||
this.t?.();
|
||||
this.t = void 0;
|
||||
super.q();
|
||||
}
|
||||
L() {
|
||||
if (this.K && this.a !== STATE_DISPOSED) {
|
||||
this.t?.();
|
||||
try {
|
||||
this.t = this.A(this.e, this.C);
|
||||
} catch (e) {
|
||||
if (!this.f.notify(this, ERROR_BIT, ERROR_BIT))
|
||||
throw e;
|
||||
} finally {
|
||||
this.C = this.e;
|
||||
this.K = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// src/signals.ts
|
||||
function createSignal(first, second, third) {
|
||||
if (typeof first === "function") {
|
||||
const memo = createMemo((p) => {
|
||||
const node2 = new Computation(
|
||||
first(p ? untrack(p[0]) : second),
|
||||
null,
|
||||
third
|
||||
);
|
||||
return [node2.read.bind(node2), node2.write.bind(node2)];
|
||||
});
|
||||
return [() => memo()[0](), (value) => memo()[1](value)];
|
||||
}
|
||||
const node = new Computation(first, null, second);
|
||||
return [node.read.bind(node), node.write.bind(node)];
|
||||
}
|
||||
function createMemo(compute2, value, options) {
|
||||
let node = new Computation(
|
||||
value,
|
||||
compute2,
|
||||
options
|
||||
);
|
||||
let resolvedValue;
|
||||
return () => {
|
||||
if (node) {
|
||||
if (node.a === STATE_DISPOSED) {
|
||||
node = void 0;
|
||||
return resolvedValue;
|
||||
}
|
||||
resolvedValue = node.wait();
|
||||
if (!node.b?.length && node.g?.i !== node) {
|
||||
node.dispose();
|
||||
node = void 0;
|
||||
}
|
||||
}
|
||||
return resolvedValue;
|
||||
};
|
||||
}
|
||||
function createEffect(compute2, effect, error, value, options) {
|
||||
void new Effect(
|
||||
value,
|
||||
compute2,
|
||||
effect,
|
||||
error,
|
||||
options
|
||||
);
|
||||
}
|
||||
function createRoot(init, options) {
|
||||
const owner = new Owner(options?.id);
|
||||
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
||||
}
|
||||
function runWithOwner(owner, run) {
|
||||
return compute(owner, run, null);
|
||||
}
|
||||
|
||||
export { Owner, createEffect, createMemo, createRoot, createSignal, getOwner, onCleanup, runWithOwner, untrack };
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
import { Computation } from "./core.js";
|
||||
import { type Effect } from "./effect.js";
|
||||
import { Queue } from "./scheduler.js";
|
||||
export declare class CollectionQueue extends Queue {
|
||||
_collectionType: number;
|
||||
_nodes: Set<Effect>;
|
||||
_disabled: Computation<boolean>;
|
||||
constructor(type: number);
|
||||
notify(node: Effect, type: number, flags: number): boolean;
|
||||
}
|
||||
export declare enum BoundaryMode {
|
||||
VISIBLE = "visible",
|
||||
HIDDEN = "hidden"
|
||||
}
|
||||
export declare function createBoundary<T>(fn: () => T, condition: () => BoundaryMode): () => T | undefined;
|
||||
export declare function createSuspense(fn: () => any, fallback: () => any): () => any;
|
||||
export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): () => any;
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* See https://dev.to/modderme123/super-charging-fine-grained-reactive-performance-47ph
|
||||
* State clean corresponds to a node where all the sources are fully up to date
|
||||
* State check corresponds to a node where some sources (including grandparents) may have changed
|
||||
* State dirty corresponds to a node where the direct parents of a node has changed
|
||||
*/
|
||||
export declare const STATE_CLEAN = 0;
|
||||
export declare const STATE_CHECK = 1;
|
||||
export declare const STATE_DIRTY = 2;
|
||||
export declare const STATE_DISPOSED = 3;
|
||||
export declare const EFFECT_PURE = 0;
|
||||
export declare const EFFECT_RENDER = 1;
|
||||
export declare const EFFECT_USER = 2;
|
||||
export declare const SUPPORTS_PROXY: boolean;
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
/**
|
||||
* Nodes for constructing a graph of reactive values and reactive computations.
|
||||
*
|
||||
* - The graph is acyclic.
|
||||
* - The user inputs new values into the graph by calling .write() on one more computation nodes.
|
||||
* - The user retrieves computed results from the graph by calling .read() on one or more computation nodes.
|
||||
* - The library is responsible for running any necessary computations so that .read() is up to date
|
||||
* with all prior .write() calls anywhere in the graph.
|
||||
* - We call the input nodes 'roots' and the output nodes 'leaves' of the graph here.
|
||||
* - Changes flow from roots to leaves. It would be effective but inefficient to immediately
|
||||
* propagate all changes from a root through the graph to descendant leaves. Instead, we defer
|
||||
* change most change propagation computation until a leaf is accessed. This allows us to
|
||||
* coalesce computations and skip altogether recalculating unused sections of the graph.
|
||||
* - Each computation node tracks its sources and its observers (observers are other
|
||||
* elements that have this node as a source). Source and observer links are updated automatically
|
||||
* as observer computations re-evaluate and call get() on their sources.
|
||||
* - Each node stores a cache state (clean/check/dirty) to support the change propagation algorithm:
|
||||
*
|
||||
* In general, execution proceeds in three passes:
|
||||
*
|
||||
* 1. write() propagates changes down the graph to the leaves
|
||||
* direct children are marked as dirty and their deeper descendants marked as check
|
||||
* (no computations are evaluated)
|
||||
* 2. read() requests that parent nodes updateIfNecessary(), which proceeds recursively up the tree
|
||||
* to decide whether the node is clean (parents unchanged) or dirty (parents changed)
|
||||
* 3. updateIfNecessary() evaluates the computation if the node is dirty (the computations are
|
||||
* executed in root to leaf order)
|
||||
*/
|
||||
import { type Flags } from "./flags.js";
|
||||
import { Owner } from "./owner.js";
|
||||
export interface SignalOptions<T> {
|
||||
name?: string;
|
||||
equals?: ((prev: T, next: T) => boolean) | false;
|
||||
unobserved?: () => void;
|
||||
}
|
||||
interface SourceType {
|
||||
_observers: ObserverType[] | null;
|
||||
_unobserved?: () => void;
|
||||
_updateIfNecessary: () => void;
|
||||
_stateFlags: Flags;
|
||||
_time: number;
|
||||
}
|
||||
interface ObserverType {
|
||||
_sources: SourceType[] | null;
|
||||
_notify: (state: number, skipQueue?: boolean) => void;
|
||||
_handlerMask: Flags;
|
||||
_notifyFlags: (mask: Flags, newFlags: Flags) => void;
|
||||
_time: number;
|
||||
}
|
||||
/**
|
||||
* Returns the current observer.
|
||||
*/
|
||||
export declare function getObserver(): Computation | null;
|
||||
export declare const UNCHANGED: unique symbol;
|
||||
export type UNCHANGED = typeof UNCHANGED;
|
||||
export declare class Computation<T = any> extends Owner implements SourceType, ObserverType {
|
||||
_sources: SourceType[] | null;
|
||||
_observers: ObserverType[] | null;
|
||||
_value: T | undefined;
|
||||
_error: unknown;
|
||||
_compute: null | ((p?: T) => T);
|
||||
_name: string | undefined;
|
||||
_equals: false | ((a: T, b: T) => boolean);
|
||||
_unobserved: (() => void) | undefined;
|
||||
/** Whether the computation is an error or has ancestors that are unresolved */
|
||||
_stateFlags: number;
|
||||
/** Which flags raised by sources are handled, vs. being passed through. */
|
||||
_handlerMask: number;
|
||||
_time: number;
|
||||
_forceNotify: boolean;
|
||||
constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
|
||||
_read(): T;
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*/
|
||||
read(): T;
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*
|
||||
* If the computation has any unresolved ancestors, this function waits for the value to resolve
|
||||
* before continuing
|
||||
*/
|
||||
wait(): T;
|
||||
/** Update the computation with a new value. */
|
||||
write(value: T | ((currentValue: T) => T) | UNCHANGED, flags?: number, raw?: boolean): T;
|
||||
/**
|
||||
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
||||
*/
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
/**
|
||||
* Notify the computation that one of its sources has changed flags.
|
||||
*
|
||||
* @param mask A bitmask for which flag(s) were changed.
|
||||
* @param newFlags The source's new flags, masked to just the changed ones.
|
||||
*/
|
||||
_notifyFlags(mask: Flags, newFlags: Flags): void;
|
||||
_setError(error: unknown): void;
|
||||
/**
|
||||
* This is the core part of the reactivity system, which makes sure that the values are updated
|
||||
* before they are read. We've also adapted it to return the loading state of the computation,
|
||||
* so that we can propagate that to the computation's observers.
|
||||
*
|
||||
* This function will ensure that the value and states we read from the computation are up to date
|
||||
*/
|
||||
_updateIfNecessary(): void;
|
||||
/**
|
||||
* Remove ourselves from the owner graph and the computation graph
|
||||
*/
|
||||
_disposeNode(): void;
|
||||
}
|
||||
/**
|
||||
* Reruns a computation's _compute function, producing a new value and keeping track of dependencies.
|
||||
*
|
||||
* It handles the updating of sources and observers, disposal of previous executions,
|
||||
* and error handling if the _compute function throws. It also sets the node as loading
|
||||
* if it reads any parents that are currently loading.
|
||||
*/
|
||||
export declare function update<T>(node: Computation<T>): void;
|
||||
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;
|
||||
/**
|
||||
* Returns true if the given functinon contains signals that have been updated since the last time
|
||||
* the parent computation was run.
|
||||
*/
|
||||
export declare function hasUpdated(fn: () => any): boolean;
|
||||
/**
|
||||
* Returns an accessor that is true if the given function contains async signals are out of date.
|
||||
*/
|
||||
export declare function isPending(fn: () => any): boolean;
|
||||
export declare function isPending(fn: () => any, loadingValue: boolean): boolean;
|
||||
/**
|
||||
* Attempts to resolve value of expression synchronously returning the last resolved value for any async computation.
|
||||
*/
|
||||
export declare function latest<T>(fn: () => T): T;
|
||||
export declare function latest<T, U>(fn: () => T, fallback: U): T | U;
|
||||
/**
|
||||
* Runs the given function in the given observer.
|
||||
*
|
||||
* Warning: Usually there are simpler ways of modeling a problem that avoid using this function
|
||||
*/
|
||||
export declare function runWithObserver<T>(observer: Computation, run: () => T): T | undefined;
|
||||
/**
|
||||
* A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
|
||||
* to reset the global context after the computation is finished even if an error is thrown.
|
||||
*/
|
||||
export declare function compute<T>(owner: Owner | null, fn: (val: T) => T, observer: Computation<T>): T;
|
||||
export declare function compute<T>(owner: Owner | null, fn: (val: undefined) => T, observer: null): T;
|
||||
export declare function flatten(children: any, options?: {
|
||||
skipNonRendered?: boolean;
|
||||
doNotUnwrap?: boolean;
|
||||
}): any;
|
||||
export {};
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
import { EFFECT_RENDER, EFFECT_USER } from "./constants.js";
|
||||
import { Computation, type SignalOptions } from "./core.js";
|
||||
/**
|
||||
* 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 class Effect<T = any> extends Computation<T> {
|
||||
_effect: (val: T, prev: T | undefined) => void | (() => void);
|
||||
_onerror: ((err: unknown) => void | (() => void)) | undefined;
|
||||
_cleanup: (() => void) | undefined;
|
||||
_modified: boolean;
|
||||
_prevValue: T | undefined;
|
||||
_type: typeof EFFECT_RENDER | typeof EFFECT_USER;
|
||||
constructor(initialValue: T, compute: (val?: T) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown) => void | (() => void), options?: SignalOptions<T> & {
|
||||
render?: boolean;
|
||||
defer?: boolean;
|
||||
});
|
||||
write(value: T, flags?: number): T;
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
_setError(error: unknown): void;
|
||||
_disposeNode(): void;
|
||||
_runEffect(): void;
|
||||
}
|
||||
export declare class EagerComputation<T = any> extends Computation<T> {
|
||||
constructor(initialValue: T, compute: () => T, options?: SignalOptions<T> & {
|
||||
defer?: boolean;
|
||||
});
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
}
|
||||
export declare class ProjectionComputation extends Computation {
|
||||
constructor(compute: () => void);
|
||||
_notify(state: number, skipQueue?: boolean): void;
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
import type { Owner } from "./owner.js";
|
||||
export declare class NotReadyError extends Error {
|
||||
}
|
||||
export declare class NoOwnerError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class ContextNotFoundError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class EffectError extends Error {
|
||||
constructor(effect: Function, cause: unknown);
|
||||
}
|
||||
export interface ErrorHandler {
|
||||
(error: unknown, node: Owner): void;
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
export type Flags = number;
|
||||
export declare const ERROR_OFFSET = 0;
|
||||
export declare const ERROR_BIT: number;
|
||||
export declare const ERROR: unique symbol;
|
||||
export declare const LOADING_OFFSET = 1;
|
||||
export declare const LOADING_BIT: number;
|
||||
export declare const LOADING: unique symbol;
|
||||
export declare const UNINITIALIZED_OFFSET = 2;
|
||||
export declare const UNINITIALIZED_BIT: number;
|
||||
export declare const UNINITIALIZED: unique symbol;
|
||||
export declare const DEFAULT_FLAGS: number;
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler } from "./error.js";
|
||||
export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
|
||||
export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, flatten, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
|
||||
export { Effect, EagerComputation } from "./effect.js";
|
||||
export { flushSync, type IQueue, Queue } from "./scheduler.js";
|
||||
export { createSuspense, createErrorBoundary, createBoundary } from "./boundaries.js";
|
||||
export { SUPPORTS_PROXY } from "./constants.js";
|
||||
export { tryCatch, type TryCatchResult } from "./utils.js";
|
||||
export * from "./flags.js";
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* Owner tracking is used to enable nested tracking scopes with automatic cleanup.
|
||||
* We also use owners to also keep track of which error handling context we are in.
|
||||
*
|
||||
* If you write the following
|
||||
*
|
||||
* const a = createOwner(() => {
|
||||
* const b = createOwner(() => {});
|
||||
*
|
||||
* const c = createOwner(() => {
|
||||
* const d = createOwner(() => {});
|
||||
* });
|
||||
*
|
||||
* const e = createOwner(() => {});
|
||||
* });
|
||||
*
|
||||
* The owner tree will look like this:
|
||||
*
|
||||
* a
|
||||
* /|\
|
||||
* b-c-e
|
||||
* |
|
||||
* d
|
||||
*
|
||||
* Following the _nextSibling pointers of each owner will first give you its children, and then its siblings (in reverse).
|
||||
* a -> e -> c -> d -> b
|
||||
*
|
||||
* Note that the owner tree is largely orthogonal to the reactivity tree, and is much closer to the component tree.
|
||||
*/
|
||||
import { type IQueue } from "./scheduler.js";
|
||||
export type ContextRecord = Record<string | symbol, unknown>;
|
||||
export interface Disposable {
|
||||
(): void;
|
||||
}
|
||||
/**
|
||||
* Returns the currently executing parent owner.
|
||||
*/
|
||||
export declare function getOwner(): Owner | null;
|
||||
export declare function setOwner(owner: Owner | null): Owner | null;
|
||||
export declare class Owner {
|
||||
_parent: Owner | null;
|
||||
_nextSibling: Owner | null;
|
||||
_prevSibling: Owner | null;
|
||||
_state: number;
|
||||
_disposal: Disposable | Disposable[] | null;
|
||||
_context: ContextRecord;
|
||||
_queue: IQueue;
|
||||
_siblingCount: number | null;
|
||||
_childCount: number;
|
||||
id: string | null;
|
||||
constructor(id?: string | null, skipAppend?: boolean);
|
||||
append(child: Owner): void;
|
||||
dispose(this: Owner, self?: boolean): void;
|
||||
_disposeNode(): void;
|
||||
emptyDisposal(): void;
|
||||
getNextChildId(): string;
|
||||
}
|
||||
export interface Context<T> {
|
||||
readonly id: symbol;
|
||||
readonly defaultValue: T | undefined;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* Whether the given context is currently defined.
|
||||
*/
|
||||
export declare function hasContext(context: Context<any>, owner?: Owner | null): boolean;
|
||||
/**
|
||||
* Runs an effect once before the reactive scope is disposed
|
||||
* @param fn an effect that should run only once on cleanup
|
||||
*
|
||||
* @returns the same {@link fn} function that was passed in
|
||||
*
|
||||
* @description https://docs.solidjs.com/reference/lifecycle/on-cleanup
|
||||
*/
|
||||
export declare function onCleanup(fn: Disposable): Disposable;
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
import type { Computation } from "./core.js";
|
||||
import type { Effect } from "./effect.js";
|
||||
export declare function getClock(): number;
|
||||
export declare function incrementClock(): void;
|
||||
export interface IQueue {
|
||||
enqueue<T extends Computation | Effect>(type: number, node: T): void;
|
||||
run(type: number): boolean | void;
|
||||
flush(): void;
|
||||
addChild(child: IQueue): void;
|
||||
removeChild(child: IQueue): void;
|
||||
created: number;
|
||||
notify(...args: any[]): boolean;
|
||||
_parent: IQueue | null;
|
||||
}
|
||||
export declare class Queue implements IQueue {
|
||||
_parent: IQueue | null;
|
||||
_running: boolean;
|
||||
_queues: [Computation[], Effect[], Effect[]];
|
||||
_children: IQueue[];
|
||||
created: number;
|
||||
enqueue<T extends Computation | Effect>(type: number, node: T): void;
|
||||
run(type: number): boolean | undefined;
|
||||
flush(): void;
|
||||
addChild(child: IQueue): void;
|
||||
removeChild(child: IQueue): void;
|
||||
notify(...args: any[]): boolean;
|
||||
}
|
||||
export declare const globalQueue: Queue;
|
||||
/**
|
||||
* 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 `flushSync()`.
|
||||
*/
|
||||
export declare function flushSync(): void;
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
export declare function isUndefined(value: any): value is undefined;
|
||||
export type TryCatchResult<T, E> = [undefined, T] | [E];
|
||||
export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
|
||||
export declare function tryCatch<T, E = Error>(fn: () => T): TryCatchResult<T, E>;
|
||||
@@ -1,3 +0,0 @@
|
||||
export { Owner, getOwner, onCleanup, untrack } from "./core/index.js";
|
||||
export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
|
||||
export * from "./signals.js";
|
||||
@@ -1,22 +0,0 @@
|
||||
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[]>;
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
import type { SignalOptions } from "./core/index.js";
|
||||
import { Owner } 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 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 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>, effect: EffectFunction<NoInfer<Next>, Next>, error?: (err: unknown) => void): void;
|
||||
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, error: ((err: unknown) => void) | undefined, value: Init, options?: EffectOptions): void;
|
||||
/**
|
||||
* 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, run: () => T): T;
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
|
||||
export type { Merge, Omit } from "./utils.js";
|
||||
export { unwrap, isWrappable, createStore, deep, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
|
||||
export { createProjection } from "./projection.js";
|
||||
export { reconcile } from "./reconcile.js";
|
||||
export { merge, omit } from "./utils.js";
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
import { type Store, type StoreSetter } from "./store.js";
|
||||
/**
|
||||
* 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, initialValue?: T): Store<T>;
|
||||
export declare function wrapProjection<T>(fn: (draft: T) => void, store: Store<T>, setStore: StoreSetter<T>): [Store<T>, StoreSetter<T>];
|
||||
-1
@@ -1 +0,0 @@
|
||||
export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => T;
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
import { Computation } from "../core/index.js";
|
||||
export type Store<T> = Readonly<T>;
|
||||
export type StoreSetter<T> = (fn: (state: T) => void) => void;
|
||||
type DataNode = Computation<any>;
|
||||
type DataNodes = Record<PropertyKey, DataNode>;
|
||||
declare const $RAW: unique symbol, $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol;
|
||||
export declare const STORE_VALUE = "v", STORE_NODE = "n", STORE_HAS = "h";
|
||||
export { $PROXY, $TRACK, $RAW, $TARGET };
|
||||
export type StoreNode = {
|
||||
[STORE_VALUE]: Record<PropertyKey, any>;
|
||||
[STORE_NODE]?: DataNodes;
|
||||
[STORE_HAS]?: DataNodes;
|
||||
};
|
||||
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 wrap<T extends Record<PropertyKey, any>>(value: T): T;
|
||||
export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
||||
/**
|
||||
* Returns the underlying data in the store without a proxy.
|
||||
* @param item store proxy object
|
||||
* @example
|
||||
* ```js
|
||||
* const initial = {z...};
|
||||
* const [state, setState] = createStore(initial);
|
||||
* initial === state; // => false
|
||||
* initial === unwrap(state); // => true
|
||||
* ```
|
||||
*/
|
||||
export declare function unwrap<T>(item: T, deep?: boolean, set?: Set<unknown>): T;
|
||||
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, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
||||
export declare function deep<T extends object>(store: Store<T>): Store<any>;
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
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 {};
|
||||
@@ -1,4 +1,5 @@
|
||||
// @ts-nocheck
|
||||
|
||||
// src/core/error.ts
|
||||
var NotReadyError = class extends Error {};
|
||||
var EffectError = class extends Error {
|
||||
@@ -351,7 +352,7 @@ var Computation = class extends Owner {
|
||||
this.w = error;
|
||||
this.write(
|
||||
UNCHANGED,
|
||||
(this.d & ~LOADING_BIT) | ERROR_BIT | UNINITIALIZED_BIT,
|
||||
(this.d & ~LOADING_BIT) | ERROR_BIT | UNINITIALIZED_BIT
|
||||
);
|
||||
}
|
||||
/**
|
||||
@@ -427,7 +428,7 @@ function update(node) {
|
||||
if (error instanceof NotReadyError) {
|
||||
node.write(
|
||||
UNCHANGED,
|
||||
newFlags | LOADING_BIT | (node.d & UNINITIALIZED_BIT),
|
||||
newFlags | LOADING_BIT | (node.d & UNINITIALIZED_BIT)
|
||||
);
|
||||
} else {
|
||||
node.C(error);
|
||||
@@ -617,7 +618,7 @@ function createSignal(first, second, third) {
|
||||
const node2 = new Computation(
|
||||
first(p ? untrack(p[0]) : second),
|
||||
null,
|
||||
third,
|
||||
third
|
||||
);
|
||||
return [node2.read.bind(node2), node2.write.bind(node2)];
|
||||
});
|
||||
@@ -628,7 +629,7 @@ function createSignal(first, second, third) {
|
||||
const node = new Computation(
|
||||
first,
|
||||
null,
|
||||
needsId ? { id: o.getNextChildId(), ...second } : second,
|
||||
needsId ? { id: o.getNextChildId(), ...second } : second
|
||||
);
|
||||
return [node.read.bind(node), node.write.bind(node)];
|
||||
}
|
||||
@@ -658,7 +659,7 @@ function createRoot(init, options) {
|
||||
return compute(
|
||||
owner,
|
||||
!init.length ? init : () => init(() => owner.dispose()),
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
function runWithOwner(owner, run) {
|
||||
|
||||
@@ -46,7 +46,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
|
||||
createSignal(initialValue, options) {
|
||||
const [get, set] = this.createSolidSignal(
|
||||
/** @type {any} */ (initialValue),
|
||||
options,
|
||||
options
|
||||
);
|
||||
|
||||
// @ts-ignore
|
||||
@@ -64,7 +64,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
|
||||
let serialized = /** @type {string | null} */ (null);
|
||||
if (options.save.serializeParam !== false) {
|
||||
serialized = new URLSearchParams(window.location.search).get(
|
||||
paramKey,
|
||||
paramKey
|
||||
);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ const importSignals = import("./v0.3.2-treeshaked/script.js").then(
|
||||
};
|
||||
|
||||
return signals;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -131,11 +131,13 @@ function writeParam(key, value) {
|
||||
urlParams.delete(key);
|
||||
}
|
||||
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
`${window.location.pathname}?${urlParams.toString()}`,
|
||||
);
|
||||
try {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
`${window.location.pathname}?${urlParams.toString()}`
|
||||
);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,4 +5,4 @@ Head:
|
||||
|
||||
- SHA: 6bb27a8d8c41e4be5458844afc5c89f6c2399512
|
||||
- Date: Feb 21, 2024
|
||||
- Version: v1.0.14
|
||||
- Version: v1.0.18
|
||||
|
||||
+56
-15
@@ -1,16 +1,15 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024, Leon Sorokin
|
||||
* Copyright (c) 2025, Leon Sorokin
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* uFuzzy.js (μFuzzy)
|
||||
* A tiny, efficient fuzzy matcher that doesn't suck
|
||||
* https://github.com/leeoniya/uFuzzy (v1.0.14)
|
||||
* https://github.com/leeoniya/uFuzzy (v1.0.18)
|
||||
*/
|
||||
|
||||
const cmp = new Intl.Collator("en", { numeric: true, sensitivity: "base" })
|
||||
.compare;
|
||||
const cmp = (a, b) => (a > b ? 1 : a < b ? -1 : 0);
|
||||
|
||||
const inf = Infinity;
|
||||
|
||||
@@ -25,6 +24,8 @@ const PUNCT_RE = /\p{P}/gu;
|
||||
const LATIN_UPPER = "A-Z";
|
||||
const LATIN_LOWER = "a-z";
|
||||
|
||||
const COLLATE_ARGS = ["en", { numeric: true, sensitivity: "base" }];
|
||||
|
||||
const swapAlpha = (str, upper, lower) =>
|
||||
str.replace(LATIN_UPPER, upper).replace(LATIN_LOWER, lower);
|
||||
|
||||
@@ -75,8 +76,12 @@ const OPTS = {
|
||||
// (since intraIns is between each char, it can accum to nonsense matches)
|
||||
intraFilt: (term, match, index) => true, // should this also accept WIP info?
|
||||
|
||||
toUpper: (str) => str.toLocaleUpperCase(),
|
||||
toLower: (str) => str.toLocaleLowerCase(),
|
||||
compare: null,
|
||||
|
||||
// final sorting fn
|
||||
sort: (info, haystack, needle) => {
|
||||
sort: (info, haystack, needle, compare = cmp) => {
|
||||
let {
|
||||
idx,
|
||||
chars,
|
||||
@@ -88,6 +93,7 @@ const OPTS = {
|
||||
start,
|
||||
intraIns,
|
||||
interIns,
|
||||
cases,
|
||||
} = info;
|
||||
|
||||
return idx
|
||||
@@ -109,8 +115,10 @@ const OPTS = {
|
||||
interIns[ia] - interIns[ib] ||
|
||||
// earliest start of match
|
||||
start[ia] - start[ib] ||
|
||||
// case match
|
||||
cases[ib] - cases[ia] ||
|
||||
// alphabetic
|
||||
cmp(haystack[idx[ia]], haystack[idx[ib]])
|
||||
compare(haystack[idx[ia]], haystack[idx[ib]])
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -145,6 +153,9 @@ function uFuzzy(opts) {
|
||||
intraBound: _intraBound,
|
||||
interBound: _interBound,
|
||||
intraChars,
|
||||
toUpper,
|
||||
toLower,
|
||||
compare,
|
||||
} = opts;
|
||||
|
||||
intraIns ??= intraMode;
|
||||
@@ -152,11 +163,16 @@ function uFuzzy(opts) {
|
||||
intraTrn ??= intraMode;
|
||||
intraDel ??= intraMode;
|
||||
|
||||
compare ??=
|
||||
typeof Intl == "undefined"
|
||||
? cmp
|
||||
: new Intl.Collator(...COLLATE_ARGS).compare;
|
||||
|
||||
let alpha = opts.letters ?? opts.alpha;
|
||||
|
||||
if (alpha != null) {
|
||||
let upper = alpha.toLocaleUpperCase();
|
||||
let lower = alpha.toLocaleLowerCase();
|
||||
let upper = toUpper(alpha);
|
||||
let lower = toLower(alpha);
|
||||
|
||||
_interSplit = swapAlpha(_interSplit, upper, lower);
|
||||
_intraSplit = swapAlpha(_intraSplit, upper, lower);
|
||||
@@ -232,7 +248,7 @@ function uFuzzy(opts) {
|
||||
);
|
||||
let contrsRe = new RegExp(intraContr, "gi" + uFlag);
|
||||
|
||||
const split = (needle) => {
|
||||
const split = (needle, keepCase = false) => {
|
||||
let exacts = [];
|
||||
|
||||
needle = needle.replace(EXACTS_RE, (m) => {
|
||||
@@ -240,7 +256,9 @@ function uFuzzy(opts) {
|
||||
return EXACT_HERE;
|
||||
});
|
||||
|
||||
needle = needle.replace(trimRe, "").toLocaleLowerCase();
|
||||
needle = needle.replace(trimRe, "");
|
||||
|
||||
if (!keepCase) needle = toLower(needle);
|
||||
|
||||
if (withIntraSplit)
|
||||
needle = needle.replace(intraSplit, (m) => m[0] + " " + m[1]);
|
||||
@@ -460,9 +478,25 @@ function uFuzzy(opts) {
|
||||
|
||||
const info = (idxs, haystack, needle) => {
|
||||
let [query, parts, contrs] = prepQuery(needle, 1);
|
||||
let partsCased = split(needle, true);
|
||||
let [queryR] = prepQuery(needle, 2);
|
||||
let partsLen = parts.length;
|
||||
|
||||
let _terms = Array(partsLen);
|
||||
let _termsCased = Array(partsLen);
|
||||
|
||||
for (let j = 0; j < partsLen; j++) {
|
||||
let part = parts[j];
|
||||
let partCased = partsCased[j];
|
||||
|
||||
let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];
|
||||
let termCased =
|
||||
partCased[0] == '"' ? partCased.slice(1, -1) : partCased + contrs[j];
|
||||
|
||||
_terms[j] = term;
|
||||
_termsCased[j] = termCased;
|
||||
}
|
||||
|
||||
let len = idxs.length;
|
||||
|
||||
let field = Array(len).fill(0);
|
||||
@@ -479,6 +513,9 @@ function uFuzzy(opts) {
|
||||
// contiguous chars matched
|
||||
chars: field.slice(),
|
||||
|
||||
// case matched in term (via term.includes(match))
|
||||
cases: field.slice(),
|
||||
|
||||
// contiguous (no fuzz) and bounded terms (intra=0, lft2/1, rgt2/1)
|
||||
// excludes terms that are contiguous but have < 2 bounds (substrings)
|
||||
terms: field.slice(),
|
||||
@@ -520,24 +557,27 @@ function uFuzzy(opts) {
|
||||
let rgt1 = 0;
|
||||
let chars = 0;
|
||||
let terms = 0;
|
||||
let cases = 0;
|
||||
let inter = 0;
|
||||
let intra = 0;
|
||||
|
||||
let refine = [];
|
||||
|
||||
for (let j = 0, k = 2; j < partsLen; j++, k += 2) {
|
||||
let group = m[k].toLocaleLowerCase();
|
||||
let part = parts[j];
|
||||
let term = part[0] == '"' ? part.slice(1, -1) : part + contrs[j];
|
||||
let group = toLower(m[k]);
|
||||
let term = _terms[j];
|
||||
let termCased = _termsCased[j];
|
||||
let termLen = term.length;
|
||||
let groupLen = group.length;
|
||||
let fullMatch = group == term;
|
||||
|
||||
if (m[k] == termCased) cases++;
|
||||
|
||||
// this won't handle the case when an exact match exists across the boundary of the current group and the next junk
|
||||
// e.g. blob,ob when searching for 'bob' but finding the earlier `blob` (with extra insertion)
|
||||
if (!fullMatch && m[k + 1].length >= termLen) {
|
||||
// probe for exact match in inter junk (TODO: maybe even in this matched part?)
|
||||
let idxOf = m[k + 1].toLocaleLowerCase().indexOf(term);
|
||||
let idxOf = toLower(m[k + 1]).indexOf(term);
|
||||
|
||||
if (idxOf > -1) {
|
||||
refine.push(idxAcc, groupLen, idxOf, termLen);
|
||||
@@ -685,6 +725,7 @@ function uFuzzy(opts) {
|
||||
info.interRgt1[ii] = rgt1;
|
||||
info.chars[ii] = chars;
|
||||
info.terms[ii] = terms;
|
||||
info.cases[ii] = cases;
|
||||
info.interIns[ii] = inter;
|
||||
info.intraIns[ii] = intra;
|
||||
|
||||
@@ -906,7 +947,7 @@ function uFuzzy(opts) {
|
||||
|
||||
let needle = needles[ni];
|
||||
let _info = info(idxs, haystack, needle);
|
||||
let order = opts.sort(_info, haystack, needle);
|
||||
let order = opts.sort(_info, haystack, needle, compare);
|
||||
|
||||
// offset idxs for concat'ing infos
|
||||
if (ni > 0) {
|
||||
+21
-2
@@ -34,7 +34,7 @@ declare class uFuzzy {
|
||||
): uFuzzy.InfoIdxOrder;
|
||||
|
||||
/** utility for splitting needle into terms following defined interSplit/intraSplit opts. useful for out-of-order permutes */
|
||||
split(needle: string): uFuzzy.Terms;
|
||||
split(needle: string, keepCase?: boolean): uFuzzy.Terms;
|
||||
|
||||
/** util for creating out-of-order permutations of a needle terms array */
|
||||
static permute(arr: unknown[]): unknown[][];
|
||||
@@ -99,6 +99,8 @@ declare namespace uFuzzy {
|
||||
|
||||
export type IntraSliceIdxs = [from: number, to: number];
|
||||
|
||||
type CompareFn = (a: string, b: string) => number;
|
||||
|
||||
export interface Options {
|
||||
// whether regexps use a /u unicode flag
|
||||
unicode?: boolean; // false
|
||||
@@ -158,7 +160,21 @@ declare namespace uFuzzy {
|
||||
/** post-filters matches during .info() based on cmp of term in needle vs partial match */
|
||||
intraFilt?: (term: string, match: string, index: number) => boolean; // should this also accept WIP info?
|
||||
|
||||
sort?: (info: Info, haystack: string[], needle: string) => InfoIdxOrder;
|
||||
/** default: toLocaleUpperCase() */
|
||||
toUpper?: (str: string) => string;
|
||||
|
||||
/** default: toLocaleLowerCase() */
|
||||
toLower?: (str: string) => string;
|
||||
|
||||
/** final sorting cmp when all other match metrics are equal */
|
||||
compare?: CompareFn;
|
||||
|
||||
sort?: (
|
||||
info: Info,
|
||||
haystack: string[],
|
||||
needle: string,
|
||||
compare?: CompareFn
|
||||
) => InfoIdxOrder;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
@@ -188,6 +204,9 @@ declare namespace uFuzzy {
|
||||
/** number of exactly-matched terms (intra = 0) where both lft and rgt landed on a BoundMode.Loose or BoundMode.Strict boundary */
|
||||
terms: number[];
|
||||
|
||||
/** number of needle terms with case-sensitive partial matches */
|
||||
cases: number[];
|
||||
|
||||
/** offset ranges within match for highlighting: [startIdx0, endIdx0, startIdx1, endIdx1,...] */
|
||||
ranges: number[][];
|
||||
}
|
||||
@@ -45,6 +45,7 @@ export function init({
|
||||
|
||||
signals.createEffect(selected, (option) => {
|
||||
headingElement.innerHTML = option.title;
|
||||
|
||||
signals.createEffect(index, (index) => {
|
||||
const { field: topUnitField, selected: topUnit } =
|
||||
utils.dom.createHorizontalChoiceField({
|
||||
@@ -126,7 +127,7 @@ export function init({
|
||||
key: "from",
|
||||
serializeParam: firstRun,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
const to = signals.createSignal(
|
||||
/** @type {number | null} */ (null),
|
||||
@@ -137,7 +138,7 @@ export function init({
|
||||
key: "to",
|
||||
serializeParam: firstRun,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
chart.create({
|
||||
@@ -274,7 +275,7 @@ export function init({
|
||||
from.set(t.from);
|
||||
to.set(t.to);
|
||||
}
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
firstRun = false;
|
||||
@@ -293,7 +294,6 @@ export function init({
|
||||
*/
|
||||
function createIndexSelector({ elements, signals, utils }) {
|
||||
const { field, selected } = utils.dom.createHorizontalChoiceField({
|
||||
// title: "Index",
|
||||
defaultValue: "date",
|
||||
keyPrefix: "charts",
|
||||
key: "index",
|
||||
@@ -335,7 +335,7 @@ function createIndexSelector({ elements, signals, utils }) {
|
||||
case "decade":
|
||||
return /** @satisfies {DecadeIndex} */ (1);
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
return index;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @import { Option, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, SimulationOption, AnySeriesBlueprint, ChartableIndex,CreatePriceLineOptions, CreatePriceLine } from "./options"
|
||||
* @import {Valued, SingleValueData, CandlestickData, ChartData, OHLCTuple} from "../packages/lightweight-charts/wrapper"
|
||||
* @import * as _ from "../packages/ufuzzy/v1.0.14/types"
|
||||
* @import * as _ from "../packages/ufuzzy/v1.0.18/types"
|
||||
* @import { createChart as CreateClassicChart, LineStyleOptions, DeepPartial, ChartOptions, IChartApi, IHorzScaleBehavior, WhitespaceData, ISeriesApi, Time, LineData, LogicalRange, BaselineStyleOptions, SeriesOptionsCommon, BaselineData, CandlestickStyleOptions } from "../packages/lightweight-charts/v5.0.7-treeshaked/types"
|
||||
* @import { SignalOptions } from "../packages/solid-signals/v0.3.2-treeshaked/types/core/core"
|
||||
* @import {Signal, Signals} from "../packages/solid-signals/types";
|
||||
@@ -67,22 +67,22 @@ function initPackages() {
|
||||
const imports = {
|
||||
async signals() {
|
||||
return import("../packages/solid-signals/wrapper.js").then((d) =>
|
||||
d.default.then((d) => d),
|
||||
d.default.then((d) => d)
|
||||
);
|
||||
},
|
||||
async lightweightCharts() {
|
||||
return window.document.fonts.ready.then(() =>
|
||||
import("../packages/lightweight-charts/wrapper.js").then((d) =>
|
||||
d.default.then((d) => d),
|
||||
),
|
||||
d.default.then((d) => d)
|
||||
)
|
||||
);
|
||||
},
|
||||
async leanQr() {
|
||||
return import("../packages/lean-qr/v2.3.4/script.js").then((d) => d);
|
||||
return import("../packages/lean-qr/v2.5.0/script.js").then((d) => d);
|
||||
},
|
||||
async ufuzzy() {
|
||||
return import("../packages/ufuzzy/v1.0.14/script.js").then(
|
||||
({ default: d }) => d,
|
||||
return import("../packages/ufuzzy/v1.0.18/script.js").then(
|
||||
({ default: d }) => d
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -256,6 +256,7 @@ function createUtils() {
|
||||
|
||||
return button;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {string} args.inputName
|
||||
@@ -359,7 +360,6 @@ function createUtils() {
|
||||
/**
|
||||
* @template {Readonly<string[]>} T
|
||||
* @param {Object} args
|
||||
* @param {string | Accessor<string>} [args.title]
|
||||
* @param {T[number]} args.defaultValue
|
||||
* @param {string} [args.id]
|
||||
* @param {T} args.choices
|
||||
@@ -369,7 +369,6 @@ function createUtils() {
|
||||
* @param {{createEffect: CreateEffect, createSignal: Signals["createSignal"]}} args.signals
|
||||
*/
|
||||
createHorizontalChoiceField({
|
||||
title,
|
||||
id,
|
||||
choices: unsortedChoices,
|
||||
defaultValue,
|
||||
@@ -397,21 +396,6 @@ function createUtils() {
|
||||
const field = window.document.createElement("div");
|
||||
field.classList.add("field");
|
||||
|
||||
if (title) {
|
||||
const legend = window.document.createElement("legend");
|
||||
if (typeof title === "string") {
|
||||
legend.innerHTML = title;
|
||||
} else {
|
||||
signals.createEffect(title, (title) => {
|
||||
legend.innerHTML = title;
|
||||
});
|
||||
}
|
||||
field.append(legend);
|
||||
|
||||
const hr = window.document.createElement("hr");
|
||||
field.append(hr);
|
||||
}
|
||||
|
||||
const div = window.document.createElement("div");
|
||||
field.append(div);
|
||||
|
||||
@@ -587,7 +571,13 @@ function createUtils() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
pathname ||= window.location.pathname;
|
||||
|
||||
window.history.pushState(null, "", `${pathname}?${urlParams.toString()}`);
|
||||
try {
|
||||
window.history.pushState(
|
||||
null,
|
||||
"",
|
||||
`${pathname}?${urlParams.toString()}`
|
||||
);
|
||||
} catch (_) {}
|
||||
},
|
||||
/**
|
||||
* @param {Object} args
|
||||
@@ -598,11 +588,13 @@ function createUtils() {
|
||||
urlParams ||= new URLSearchParams(window.location.search);
|
||||
pathname ||= window.location.pathname;
|
||||
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
`${pathname}?${urlParams.toString()}`,
|
||||
);
|
||||
try {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
`${pathname}?${urlParams.toString()}`
|
||||
);
|
||||
} catch (_) {}
|
||||
},
|
||||
/**
|
||||
* @param {Option} option
|
||||
@@ -971,12 +963,8 @@ function createUtils() {
|
||||
return numberToUSFormat(value, 2);
|
||||
} else if (absoluteValue < 1_000) {
|
||||
return numberToUSFormat(value, 1);
|
||||
} else if (absoluteValue < 100_000) {
|
||||
return numberToUSFormat(value, 0);
|
||||
} else if (absoluteValue < 200_000) {
|
||||
return `${numberToUSFormat(value / 1_000, 2)}K`;
|
||||
} else if (absoluteValue < 1_000_000) {
|
||||
return `${numberToUSFormat(value / 1_000, 1)}K`;
|
||||
return numberToUSFormat(value, 0);
|
||||
} else if (absoluteValue >= 900_000_000_000_000_000) {
|
||||
return "Inf.";
|
||||
}
|
||||
@@ -987,24 +975,10 @@ function createUtils() {
|
||||
const letterIndex = Math.floor(log / 3);
|
||||
const letter = suffices[letterIndex];
|
||||
|
||||
const modulused = log % 3;
|
||||
|
||||
if (modulused === 0) {
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
3,
|
||||
)}${letter}`;
|
||||
} else if (modulused === 1) {
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
2,
|
||||
)}${letter}`;
|
||||
} else {
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
1,
|
||||
)}${letter}`;
|
||||
}
|
||||
return `${numberToUSFormat(
|
||||
value / (1_000_000 * 1_000 ** letterIndex),
|
||||
3
|
||||
)}${letter}`;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1170,8 +1144,8 @@ function createUtils() {
|
||||
today.getUTCDate(),
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
),
|
||||
0
|
||||
)
|
||||
);
|
||||
},
|
||||
/**
|
||||
@@ -1273,7 +1247,7 @@ function createUtils() {
|
||||
*/
|
||||
function getNumberOfDaysBetweenTwoDates(oldest, youngest) {
|
||||
return Math.round(
|
||||
Math.abs((youngest.getTime() - oldest.getTime()) / date.ONE_DAY_IN_MS),
|
||||
Math.abs((youngest.getTime() - oldest.getTime()) / date.ONE_DAY_IN_MS)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1291,6 +1265,8 @@ function createUtils() {
|
||||
}
|
||||
|
||||
const api = (() => {
|
||||
const CACHE_NAME = "api";
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {(value: T) => void} callback
|
||||
@@ -1306,7 +1282,7 @@ function createUtils() {
|
||||
/** @type {Cache | undefined} */
|
||||
let cache;
|
||||
try {
|
||||
cache = await caches.open("api");
|
||||
cache = await caches.open(CACHE_NAME);
|
||||
const cachedResponse = await cache.match(url);
|
||||
if (cachedResponse) {
|
||||
console.log(`cache: ${url}`);
|
||||
@@ -1582,7 +1558,7 @@ function createVecsResources(signals, utils) {
|
||||
index,
|
||||
id,
|
||||
from,
|
||||
to,
|
||||
to
|
||||
)
|
||||
);
|
||||
fetched.at = new Date();
|
||||
@@ -1772,8 +1748,6 @@ function createColors(dark, elements) {
|
||||
default: textColor,
|
||||
gray,
|
||||
border: borderColor,
|
||||
// dollars: green,
|
||||
// offDollars: emerald,
|
||||
|
||||
red,
|
||||
orange,
|
||||
@@ -1793,141 +1767,6 @@ function createColors(dark, elements) {
|
||||
fuchsia,
|
||||
pink,
|
||||
rose,
|
||||
|
||||
// _1d: pink,
|
||||
// _1w: red,
|
||||
// _8d: orange,
|
||||
// _13d: amber,
|
||||
// _21d: yellow,
|
||||
// _1m: lime,
|
||||
// _34d: green,
|
||||
// _55d: emerald,
|
||||
// _89d: teal,
|
||||
// _144d: cyan,
|
||||
// _6m: sky,
|
||||
// _1y: blue,
|
||||
// _2y: indigo,
|
||||
// _200w: violet,
|
||||
// _4y: purple,
|
||||
// _10y: fuchsia,
|
||||
|
||||
// 2015: pink,
|
||||
// 2016: red,
|
||||
// 2017: orange,
|
||||
// 2018: amber,
|
||||
// 2019: yellow,
|
||||
// 2020: lime,
|
||||
// 2021: green,
|
||||
// 2022: emerald,
|
||||
// 2023: teal,
|
||||
// 2024: cyan,
|
||||
// 2025: sky,
|
||||
// 2026: blue,
|
||||
// 2027: indigo,
|
||||
// 2028: violet,
|
||||
// 2029: purple,
|
||||
// 2030: fuchsia,
|
||||
|
||||
// r1d: pink,
|
||||
// r1w: red,
|
||||
// r1m: amber,
|
||||
// r3m: yellow,
|
||||
// r6m: lime,
|
||||
// r1y: green,
|
||||
// r2y: emerald,
|
||||
// r3y: teal,
|
||||
// r4y: blue,
|
||||
// r5y: indigo,
|
||||
// r6y: violet,
|
||||
// r8y: purple,
|
||||
// r10y: fuchsia,
|
||||
|
||||
// p2pk: lime,
|
||||
// p2pkh: violet,
|
||||
// p2sh: emerald,
|
||||
// p2wpkh: cyan,
|
||||
// p2wsh: pink,
|
||||
// p2tr: blue,
|
||||
// crab: red,
|
||||
// fish: lime,
|
||||
// humpback: violet,
|
||||
// plankton: emerald,
|
||||
// shark: cyan,
|
||||
// shrimp: pink,
|
||||
// whale: blue,
|
||||
// megalodon: purple,
|
||||
// realizedPrice: orange,
|
||||
// oneMonthHolders: cyan,
|
||||
// threeMonthsHolders: lime,
|
||||
// sth: yellow,
|
||||
// sixMonthsHolder: red,
|
||||
// oneYearHolders: pink,
|
||||
// twoYearsHolders: purple,
|
||||
// lth: fuchsia,
|
||||
// balancedPrice: yellow,
|
||||
// cointimePrice: yellow,
|
||||
// trueMarketMeanPrice: blue,
|
||||
// vaultedPrice: green,
|
||||
// cvdd: lime,
|
||||
// terminalPrice: red,
|
||||
// loss: red,
|
||||
// profit: green,
|
||||
// thermoCap: green,
|
||||
// investorCap: rose,
|
||||
// realizedCap: orange,
|
||||
// offLiveliness: red,
|
||||
// liveliness: rose,
|
||||
// vaultedness: green,
|
||||
// activityToVaultednessRatio: violet,
|
||||
// up_to_1d: pink,
|
||||
// up_to_1w: red,
|
||||
// up_to_1m: orange,
|
||||
// up_to_2m: amber,
|
||||
// up_to_3m: yellow,
|
||||
// up_to_4m: lime,
|
||||
// up_to_5m: green,
|
||||
// up_to_6m: teal,
|
||||
// up_to_1y: sky,
|
||||
// up_to_2y: indigo,
|
||||
// up_to_3y: violet,
|
||||
// up_to_4y: purple,
|
||||
// up_to_5y: red,
|
||||
// up_to_7y: orange,
|
||||
// up_to_10y: amber,
|
||||
// up_to_15y: yellow,
|
||||
// from_10y_to_15y: purple,
|
||||
// from_7y_to_10y: violet,
|
||||
// from_5y_to_7y: indigo,
|
||||
// from_3y_to_5y: sky,
|
||||
// from_2y_to_3y: teal,
|
||||
// from_1y_to_2y: green,
|
||||
// from_6m_to_1y: lime,
|
||||
// from_3m_to_6m: yellow,
|
||||
// from_1m_to_3m: amber,
|
||||
// from_1w_to_1m: orange,
|
||||
// from_1d_to_1w: red,
|
||||
// from_1y: green,
|
||||
// from_2y: teal,
|
||||
// from_4y: indigo,
|
||||
// from_10y: violet,
|
||||
// from_15y: fuchsia,
|
||||
// coinblocksCreated: purple,
|
||||
// coinblocksDestroyed: red,
|
||||
// coinblocksStored: green,
|
||||
// momentumGreen: green,
|
||||
// momentumYellow: yellow,
|
||||
// momentumRed: red,
|
||||
// probability0_1p: red,
|
||||
// probability0_5p: orange,
|
||||
// probability1p: yellow,
|
||||
// epoch_1: red,
|
||||
// epoch_2: orange,
|
||||
// epoch_3: yellow,
|
||||
// epoch_4: green,
|
||||
// epoch_5: blue,
|
||||
// highly_liquid: red,
|
||||
// liquid: lime,
|
||||
// illiquid: cyan,
|
||||
};
|
||||
}
|
||||
/**
|
||||
@@ -1980,7 +1819,7 @@ function initWebSockets(signals, utils) {
|
||||
|
||||
window.document.addEventListener(
|
||||
"visibilitychange",
|
||||
reinitWebSocketIfDocumentNotHidden,
|
||||
reinitWebSocketIfDocumentNotHidden
|
||||
);
|
||||
|
||||
window.document.addEventListener("online", reinitWebSocket);
|
||||
@@ -1989,7 +1828,7 @@ function initWebSockets(signals, utils) {
|
||||
ws?.close();
|
||||
window.document.removeEventListener(
|
||||
"visibilitychange",
|
||||
reinitWebSocketIfDocumentNotHidden,
|
||||
reinitWebSocketIfDocumentNotHidden
|
||||
);
|
||||
window.document.removeEventListener("online", reinitWebSocket);
|
||||
live.set(false);
|
||||
@@ -2016,7 +1855,7 @@ function initWebSockets(signals, utils) {
|
||||
symbol: ["BTC/USD"],
|
||||
interval: 1440,
|
||||
},
|
||||
}),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -2049,7 +1888,7 @@ function initWebSockets(signals, utils) {
|
||||
}
|
||||
|
||||
const kraken1dCandle = createWebsocket((callback) =>
|
||||
krakenCandleWebSocketCreator(callback, 1440),
|
||||
krakenCandleWebSocketCreator(callback, 1440)
|
||||
);
|
||||
|
||||
kraken1dCandle.open();
|
||||
@@ -2060,9 +1899,9 @@ function initWebSockets(signals, utils) {
|
||||
const close = latest.close;
|
||||
console.log("close:", close);
|
||||
|
||||
window.document.title = `${latest.close.toLocaleString(
|
||||
"en-us",
|
||||
)} | ${window.location.host}`;
|
||||
window.document.title = `${latest.close.toLocaleString("en-us")} | ${
|
||||
window.location.host
|
||||
}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2108,7 +1947,7 @@ function main() {
|
||||
}
|
||||
|
||||
const frame = window.document.getElementById(
|
||||
/** @type {string} */ (input.value),
|
||||
/** @type {string} */ (input.value)
|
||||
);
|
||||
|
||||
if (!frame) {
|
||||
@@ -2203,23 +2042,23 @@ function main() {
|
||||
|
||||
function initDark() {
|
||||
const preferredColorSchemeMatchMedia = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
"(prefers-color-scheme: dark)"
|
||||
);
|
||||
const dark = signals.createSignal(
|
||||
preferredColorSchemeMatchMedia.matches,
|
||||
preferredColorSchemeMatchMedia.matches
|
||||
);
|
||||
preferredColorSchemeMatchMedia.addEventListener(
|
||||
"change",
|
||||
({ matches }) => {
|
||||
dark.set(matches);
|
||||
},
|
||||
}
|
||||
);
|
||||
return dark;
|
||||
}
|
||||
const dark = initDark();
|
||||
|
||||
const qrcode = signals.createSignal(
|
||||
/** @type {string | null} */ (null),
|
||||
/** @type {string | null} */ (null)
|
||||
);
|
||||
|
||||
function createLastHeightResource() {
|
||||
@@ -2230,7 +2069,7 @@ function main() {
|
||||
lastHeight.set(h);
|
||||
},
|
||||
/** @satisfies {Height} */ (5),
|
||||
"height",
|
||||
"height"
|
||||
);
|
||||
}
|
||||
fetchLastHeight();
|
||||
@@ -2272,10 +2111,10 @@ function main() {
|
||||
|
||||
function createApplyOptionEffect() {
|
||||
const lastChartOption = signals.createSignal(
|
||||
/** @type {ChartOption | null} */ (null),
|
||||
/** @type {ChartOption | null} */ (null)
|
||||
);
|
||||
const lastSimulationOption = signals.createSignal(
|
||||
/** @type {SimulationOption | null} */ (null),
|
||||
/** @type {SimulationOption | null} */ (null)
|
||||
);
|
||||
|
||||
const owner = signals.getOwner();
|
||||
@@ -2324,10 +2163,10 @@ function main() {
|
||||
webSockets,
|
||||
vecsResources,
|
||||
vecIdToIndexes,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
firstTimeLoadingChart = false;
|
||||
@@ -2350,9 +2189,9 @@ function main() {
|
||||
vecsResources,
|
||||
option,
|
||||
vecIdToIndexes,
|
||||
}),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
firstTimeLoadingTable = false;
|
||||
@@ -2380,10 +2219,10 @@ function main() {
|
||||
signals,
|
||||
utils,
|
||||
vecsResources,
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
firstTimeLoadingSimulation = false;
|
||||
@@ -2489,7 +2328,7 @@ function main() {
|
||||
if (indexes?.length) {
|
||||
const maxIndex = Math.min(
|
||||
(order || indexes).length - 1,
|
||||
minIndex + RESULTS_PER_PAGE - 1,
|
||||
minIndex + RESULTS_PER_PAGE - 1
|
||||
);
|
||||
|
||||
list = Array(maxIndex - minIndex + 1);
|
||||
@@ -2565,7 +2404,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
undefined,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
|
||||
if (!result?.[0]?.length || !result?.[1]) {
|
||||
@@ -2573,7 +2412,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2582,7 +2421,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2591,7 +2430,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2600,7 +2439,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
undefined,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2609,7 +2448,7 @@ function main() {
|
||||
haystack,
|
||||
needle,
|
||||
outOfOrder,
|
||||
infoThresh,
|
||||
infoThresh
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2711,7 +2550,7 @@ function main() {
|
||||
localStorage.setItem(barWidthLocalStorageKey, String(width));
|
||||
} else {
|
||||
elements.main.style.width = elements.style.getPropertyValue(
|
||||
"--default-main-width",
|
||||
"--default-main-width"
|
||||
);
|
||||
localStorage.removeItem(barWidthLocalStorageKey);
|
||||
}
|
||||
@@ -2747,8 +2586,8 @@ function main() {
|
||||
window.addEventListener("mouseleave", setResizeFalse);
|
||||
}
|
||||
initDesktopResizeBar();
|
||||
}),
|
||||
),
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
main();
|
||||
|
||||
@@ -29,11 +29,11 @@ function createTable({
|
||||
keyPrefix: "table",
|
||||
key: "index",
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
const index = signals.createMemo(() =>
|
||||
serializedIndexToIndex(serializedIndex()),
|
||||
serializedIndexToIndex(serializedIndex())
|
||||
);
|
||||
|
||||
const table = window.document.createElement("table");
|
||||
@@ -73,7 +73,7 @@ function createTable({
|
||||
table.append(tbody);
|
||||
|
||||
const rowElements = signals.createSignal(
|
||||
/** @type {HTMLTableRowElement[]} */ ([]),
|
||||
/** @type {HTMLTableRowElement[]} */ ([])
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -196,6 +196,10 @@ function createTable({
|
||||
signal: vecIdOption,
|
||||
});
|
||||
|
||||
signals.createEffect(vecIdOption, (vecIdOption) => {
|
||||
select.style.width = `${30 + 8.5 * vecIdOption.name.length}px`;
|
||||
});
|
||||
|
||||
if (_colIndex === columns().length) {
|
||||
columns.set((l) => {
|
||||
l.push(vecId);
|
||||
@@ -319,7 +323,7 @@ function createTable({
|
||||
});
|
||||
|
||||
return () => vecId;
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -390,7 +394,7 @@ export function init({
|
||||
},
|
||||
inside: span,
|
||||
title: "Click or tap to add a column to the table",
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -495,7 +499,7 @@ function createIndexToVecIds(vecIdToIndexes) {
|
||||
});
|
||||
return arr;
|
||||
},
|
||||
/** @type {VecId[][]} */ (new Array(24)),
|
||||
/** @type {VecId[][]} */ (new Array(24))
|
||||
);
|
||||
indexToVecIds.forEach((arr) => {
|
||||
arr.sort();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// File auto-generated, any modifications will be overwritten
|
||||
//
|
||||
|
||||
export const VERSION = "v0.0.46";
|
||||
export const VERSION = "v0.0.47";
|
||||
|
||||
/** @typedef {0} DateIndex */
|
||||
/** @typedef {1} DecadeIndex */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const CACHE_NAME = "v1";
|
||||
const CACHE_NAME = "cache";
|
||||
|
||||
/** @type {ServiceWorkerGlobalScope} */
|
||||
const sw = /** @type {any} */ (self);
|
||||
@@ -11,7 +11,17 @@ sw.addEventListener("install", (event) => {
|
||||
sw.addEventListener("activate", (event) => {
|
||||
console.log("sw: active");
|
||||
event.waitUntil(sw.clients.claim());
|
||||
event.waitUntil(caches.delete(CACHE_NAME));
|
||||
event.waitUntil(
|
||||
caches
|
||||
.keys()
|
||||
.then((keys) =>
|
||||
Promise.all(
|
||||
keys
|
||||
.filter((key) => key !== CACHE_NAME && key !== "api")
|
||||
.map((key) => caches.delete(key))
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
async function indexHTMLOrOffline() {
|
||||
@@ -53,7 +63,7 @@ sw.addEventListener("fetch", (event) => {
|
||||
throw new Error("Non-2xx on shell");
|
||||
})
|
||||
// On any failure, fall back to the cached shell
|
||||
.catch(indexHTMLOrOffline),
|
||||
.catch(indexHTMLOrOffline)
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -76,6 +86,6 @@ sw.addEventListener("fetch", (event) => {
|
||||
})
|
||||
.catch(indexHTMLOrOffline);
|
||||
})
|
||||
.catch(indexHTMLOrOffline),
|
||||
.catch(indexHTMLOrOffline)
|
||||
);
|
||||
});
|
||||
|
||||
@@ -68,9 +68,8 @@
|
||||
.lightweight-chart {
|
||||
margin-left: calc(var(--negative-main-padding) * 0.75);
|
||||
|
||||
fieldset {
|
||||
margin-left: -0.5rem;
|
||||
}
|
||||
fieldset {
|
||||
margin-left: -0.5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"outDir": "/tmp/brk",
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext", "WebWorker"]
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext", "WebWorker"],
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["assets", "packages", "ignore"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user