mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 16:49:58 -07:00
website: moved packages + added ratio charts to compare folders
This commit is contained in:
@@ -2,18 +2,18 @@
|
||||
|
||||
/**
|
||||
* @import { Option, ResourceDataset, TimeScale, SerializedHistory, TimeRange, Unit, Marker, Weighted, DatasetPath, OHLC, FetchedJSON, DatasetValue, FetchedResult, AnyDatasetPath, SeriesBlueprint, BaselineSpecificSeriesBlueprint, CandlestickSpecificSeriesBlueprint, LineSpecificSeriesBlueprint, SpecificSeriesBlueprintWithChart, Signal, Color, SettingsTheme, DatasetCandlestickData, FoldersFilter, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, AnyPath, SimulationOption } from "./types/self"
|
||||
* @import {createChart as CreateClassicChart, createChartEx as CreateCustomChart, LineStyleOptions} from "./packages/lightweight-charts/v4.2.0/types";
|
||||
* @import * as _ from "./packages/ufuzzy/v1.0.14/types"
|
||||
* @import { DeepPartial, ChartOptions, IChartApi, IHorzScaleBehavior, WhitespaceData, SingleValueData, ISeriesApi, Time, LogicalRange, SeriesMarker, CandlestickData, SeriesType, BaselineStyleOptions, SeriesOptionsCommon } from "./packages/lightweight-charts/v4.2.0/types"
|
||||
* @import {createChart as CreateClassicChart, createChartEx as CreateCustomChart, LineStyleOptions} from "../packages/lightweight-charts/v4.2.0/types";
|
||||
* @import * as _ from "../packages/ufuzzy/v1.0.14/types"
|
||||
* @import { DeepPartial, ChartOptions, IChartApi, IHorzScaleBehavior, WhitespaceData, SingleValueData, ISeriesApi, Time, LogicalRange, SeriesMarker, CandlestickData, SeriesType, BaselineStyleOptions, SeriesOptionsCommon } from "../packages/lightweight-charts/v4.2.0/types"
|
||||
* @import { DatePath, HeightPath, LastPath } from "./types/paths";
|
||||
* @import { SignalOptions } from "./packages/solid-signals/2024-10-28/types/core"
|
||||
* @import { getOwner as GetOwner, onCleanup as OnCleanup, Owner } from "./packages/solid-signals/2024-10-28/types/owner"
|
||||
* @import { createSignal as CreateSignal, createEffect as CreateEffect, Accessor, Setter, createMemo as CreateMemo, createRoot as CreateRoot, runWithOwner as RunWithOwner } from "./packages/solid-signals/2024-10-28/types/signals";
|
||||
* @import { SignalOptions } from "../packages/solid-signals/2024-11-01/types/core/core"
|
||||
* @import { getOwner as GetOwner, onCleanup as OnCleanup, Owner } from "../packages/solid-signals/2024-11-01/types/core/owner"
|
||||
* @import { createSignal as CreateSignal, createEffect as CreateEffect, Accessor, Setter, createMemo as CreateMemo, createRoot as CreateRoot, runWithOwner as RunWithOwner } from "../packages/solid-signals/2024-11-01/types/signals";
|
||||
*/
|
||||
|
||||
function initPackages() {
|
||||
async function importSignals() {
|
||||
return import("./packages/solid-signals/2024-10-28/script.js").then(
|
||||
return import("../packages/solid-signals/2024-11-01/script.js").then(
|
||||
(_signals) => {
|
||||
const signals = {
|
||||
createSolidSignal: /** @type {CreateSignal} */ (
|
||||
@@ -95,7 +95,7 @@ function initPackages() {
|
||||
signals: importSignals,
|
||||
async lightweightCharts() {
|
||||
return window.document.fonts.ready.then(() =>
|
||||
import("./packages/lightweight-charts/v4.2.0/script.js").then(
|
||||
import("../packages/lightweight-charts/v4.2.0/script.js").then(
|
||||
({
|
||||
createChart: createClassicChart,
|
||||
createChartEx: createCustomChart,
|
||||
@@ -572,10 +572,10 @@ function initPackages() {
|
||||
);
|
||||
},
|
||||
async leanQr() {
|
||||
return import("./packages/lean-qr/v2.3.4/script.js").then((d) => d);
|
||||
return import("../packages/lean-qr/v2.3.4/script.js").then((d) => d);
|
||||
},
|
||||
async ufuzzy() {
|
||||
return import("./packages/ufuzzy/v1.0.14/script.js").then(
|
||||
return import("../packages/ufuzzy/v1.0.14/script.js").then(
|
||||
({ default: d }) => d,
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @import { AnySpecificSeriesBlueprint, CohortOption, CohortOptions, Color, DefaultCohortOption, DefaultCohortOptions, OptionPath, OptionsGroup, PartialChartOption, PartialOptionsGroup, PartialOptionsTree, Series, SeriesBlueprint, SeriesBlueprintParam, SeriesBluePrintType, TimeScale } from "./types/self"
|
||||
* @import { AnySpecificSeriesBlueprint, CohortOption, CohortOptions, Color, DefaultCohortOption, DefaultCohortOptions, OptionPath, OptionsGroup, PartialChartOption, PartialOptionsGroup, PartialOptionsTree, RatioOption, RatioOptions, Series, SeriesBlueprint, SeriesBlueprintParam, SeriesBluePrintType, TimeScale } from "./types/self"
|
||||
*/
|
||||
|
||||
const DATE_TO_PREFIX = "date-to-";
|
||||
@@ -115,6 +115,12 @@ function initGroups() {
|
||||
]);
|
||||
|
||||
const fromXToY = /** @type {const} */ ([
|
||||
{
|
||||
id: "up-to-1d",
|
||||
key: "up_to_1d",
|
||||
name: "24h",
|
||||
legend: "24h",
|
||||
},
|
||||
{
|
||||
id: "from-1d-to-1w",
|
||||
key: "from_1d_to_1w",
|
||||
@@ -181,6 +187,12 @@ function initGroups() {
|
||||
name: "From 10 Years To 15 Years",
|
||||
legend: "10Y — 15Y",
|
||||
},
|
||||
{
|
||||
id: "from-15y",
|
||||
key: "from_15y",
|
||||
name: "From 15 Years To End",
|
||||
legend: "15Y — End",
|
||||
},
|
||||
]);
|
||||
|
||||
const fromX = /** @type {const} */ ([
|
||||
@@ -854,21 +866,30 @@ function createPartialOptions(colors) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} args
|
||||
* @param {TimeScale} args.scale
|
||||
* @param {Color} args.color
|
||||
* @param {AnyDatasetPath} args.valueDatasetPath
|
||||
* @param {AnyDatasetPath} args.ratioDatasetPath
|
||||
* @param {string} args.title
|
||||
* @param {RatioOption | RatioOptions} arg
|
||||
* @returns {PartialOptionsGroup}
|
||||
*/
|
||||
function createRatioOptions({
|
||||
scale,
|
||||
color,
|
||||
valueDatasetPath,
|
||||
ratioDatasetPath,
|
||||
title,
|
||||
}) {
|
||||
function createRatioOptions(arg) {
|
||||
const { scale, title } = arg;
|
||||
|
||||
const isSingle = !("list" in arg);
|
||||
|
||||
/**
|
||||
* @param {RatioOption | RatioOptions} arg
|
||||
*/
|
||||
function toList(arg) {
|
||||
return "list" in arg ? arg.list : [arg];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {RatioOption | RatioOptions} arg
|
||||
* @param {string} cohortName
|
||||
* @param {string} legendName
|
||||
*/
|
||||
function toLegendName(arg, cohortName, legendName) {
|
||||
return "list" in arg ? `${cohortName} ${legendName}` : legendName;
|
||||
}
|
||||
|
||||
return {
|
||||
name: "Ratio",
|
||||
tree: [
|
||||
@@ -879,73 +900,82 @@ function createPartialOptions(colors) {
|
||||
title: `Market Price To ${title} Ratio`,
|
||||
unit: "Ratio",
|
||||
description: "",
|
||||
top: [
|
||||
{
|
||||
top: toList(arg).map(
|
||||
({ title, color, valueDatasetPath: datasetPath }) => ({
|
||||
title,
|
||||
color,
|
||||
datasetPath: valueDatasetPath,
|
||||
},
|
||||
],
|
||||
datasetPath,
|
||||
}),
|
||||
),
|
||||
bottom: [
|
||||
{
|
||||
title: `Ratio`,
|
||||
type: "Baseline",
|
||||
datasetPath: ratioDatasetPath,
|
||||
options: {
|
||||
baseValue: {
|
||||
price: 1,
|
||||
...toList(arg).map(
|
||||
({ title, color, ratioDatasetPath: datasetPath }) => ({
|
||||
title: toLegendName(arg, title, "Ratio"),
|
||||
color: isSingle ? undefined : color,
|
||||
type: /** @type {const} */ ("Baseline"),
|
||||
datasetPath,
|
||||
options: {
|
||||
baseValue: {
|
||||
price: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
bases[1](scale),
|
||||
],
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "Averages",
|
||||
description: "",
|
||||
icon: "〰️",
|
||||
unit: "Ratio",
|
||||
title: `Market Price To ${title} Ratio Averages`,
|
||||
top: [
|
||||
{
|
||||
title,
|
||||
color,
|
||||
datasetPath: valueDatasetPath,
|
||||
},
|
||||
],
|
||||
bottom: [
|
||||
{
|
||||
title: `1Y SMA`,
|
||||
color: colors.red,
|
||||
datasetPath: /** @type {any} */ (`${ratioDatasetPath}-1y-sma`),
|
||||
},
|
||||
{
|
||||
title: `1M SMA`,
|
||||
color: colors.orange,
|
||||
datasetPath: `${ratioDatasetPath}-1m-sma`,
|
||||
},
|
||||
{
|
||||
title: `1W SMA`,
|
||||
color: colors.yellow,
|
||||
datasetPath: `${ratioDatasetPath}-1w-sma`,
|
||||
},
|
||||
{
|
||||
title: `Raw`,
|
||||
color: colors.default,
|
||||
datasetPath: ratioDatasetPath,
|
||||
},
|
||||
{
|
||||
title: `Even`,
|
||||
color: colors.off,
|
||||
datasetPath: `${scale}-to-1`,
|
||||
options: {
|
||||
lineStyle: 3,
|
||||
lastValueVisible: false,
|
||||
...(isSingle
|
||||
? /** @satisfies {PartialChartOption[]} */ ([
|
||||
{
|
||||
scale,
|
||||
name: "Averages",
|
||||
description: "",
|
||||
icon: "〰️",
|
||||
unit: "Ratio",
|
||||
title: `Market Price To ${title} Ratio Averages`,
|
||||
top: [
|
||||
{
|
||||
title,
|
||||
color: arg.color,
|
||||
datasetPath: arg.valueDatasetPath,
|
||||
},
|
||||
],
|
||||
bottom: [
|
||||
{
|
||||
title: `1Y SMA`,
|
||||
color: colors.red,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${arg.ratioDatasetPath}-1y-sma`
|
||||
),
|
||||
},
|
||||
{
|
||||
title: `1M SMA`,
|
||||
color: colors.orange,
|
||||
datasetPath: `${arg.ratioDatasetPath}-1m-sma`,
|
||||
},
|
||||
{
|
||||
title: `1W SMA`,
|
||||
color: colors.yellow,
|
||||
datasetPath: `${arg.ratioDatasetPath}-1w-sma`,
|
||||
},
|
||||
{
|
||||
title: `Raw`,
|
||||
color: colors.default,
|
||||
datasetPath: arg.ratioDatasetPath,
|
||||
},
|
||||
{
|
||||
title: `Even`,
|
||||
color: colors.off,
|
||||
datasetPath: `${scale}-to-1`,
|
||||
options: {
|
||||
lineStyle: 3,
|
||||
lastValueVisible: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
: []),
|
||||
{
|
||||
scale,
|
||||
name: "Momentum Oscillator",
|
||||
@@ -953,145 +983,282 @@ function createPartialOptions(colors) {
|
||||
description: "",
|
||||
unit: "Ratio",
|
||||
icon: "🔀",
|
||||
top: [
|
||||
{
|
||||
title: `SMA`,
|
||||
top: toList(arg).map(
|
||||
({ title, color, valueDatasetPath: datasetPath }) => ({
|
||||
title: toLegendName(arg, title, ""),
|
||||
color,
|
||||
datasetPath: valueDatasetPath,
|
||||
},
|
||||
],
|
||||
datasetPath,
|
||||
}),
|
||||
),
|
||||
bottom: [
|
||||
{
|
||||
title: `Momentum`,
|
||||
type: "Baseline",
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${ratioDatasetPath}-1y-sma-momentum-oscillator`
|
||||
),
|
||||
},
|
||||
...toList(arg).map(
|
||||
({ title, color, ratioDatasetPath: datasetPath }) => ({
|
||||
title: toLegendName(arg, title, "Momentum"),
|
||||
color: isSingle ? undefined : color,
|
||||
type: /** @type {const} */ ("Baseline"),
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${datasetPath}-1y-sma-momentum-oscillator`
|
||||
),
|
||||
}),
|
||||
),
|
||||
bases[0](scale),
|
||||
],
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "Top Percentiles",
|
||||
icon: "✈️",
|
||||
title: `Market Price To ${title} Ratio Top Percentiles`,
|
||||
description: "",
|
||||
unit: "Ratio",
|
||||
top: [
|
||||
name: "Top",
|
||||
tree: [
|
||||
...(isSingle
|
||||
? /** @satisfies {PartialChartOption[]} */ ([
|
||||
{
|
||||
scale,
|
||||
name: "Percentiles",
|
||||
icon: "✈️",
|
||||
title: `Market Price To ${title} Ratio Top Percentiles`,
|
||||
description: "",
|
||||
unit: "Ratio",
|
||||
top: [
|
||||
{
|
||||
title,
|
||||
color: arg.color,
|
||||
datasetPath: arg.valueDatasetPath,
|
||||
},
|
||||
],
|
||||
bottom: [
|
||||
{
|
||||
title: `99.9%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${arg.ratioDatasetPath}-99-9p`
|
||||
),
|
||||
},
|
||||
{
|
||||
title: `99.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${arg.ratioDatasetPath}-99-5p`,
|
||||
},
|
||||
{
|
||||
title: `99%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: `${arg.ratioDatasetPath}-99p`,
|
||||
},
|
||||
{
|
||||
title: `Raw`,
|
||||
color: colors.default,
|
||||
datasetPath: arg.ratioDatasetPath,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
: []),
|
||||
{
|
||||
title,
|
||||
color,
|
||||
datasetPath: valueDatasetPath,
|
||||
},
|
||||
],
|
||||
bottom: [
|
||||
{
|
||||
title: `99.9%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: /** @type {any} */ (`${ratioDatasetPath}-99-9p`),
|
||||
},
|
||||
{
|
||||
title: `99.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${ratioDatasetPath}-99-5p`,
|
||||
},
|
||||
{
|
||||
title: `99%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: `${ratioDatasetPath}-99p`,
|
||||
},
|
||||
{
|
||||
title: `Raw`,
|
||||
color: colors.default,
|
||||
datasetPath: ratioDatasetPath,
|
||||
name: "Prices",
|
||||
tree: [
|
||||
...(isSingle
|
||||
? /** @satisfies {PartialChartOption[]} */ ([
|
||||
{
|
||||
scale,
|
||||
name: "All",
|
||||
icon: "🚀",
|
||||
title: `${title} Top Prices`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: [
|
||||
{
|
||||
title: `99.9%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${arg.valueDatasetPath}-99-9p`
|
||||
),
|
||||
},
|
||||
{
|
||||
title: `99.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${arg.valueDatasetPath}-99-5p`,
|
||||
},
|
||||
{
|
||||
title: `99%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: `${arg.valueDatasetPath}-99p`,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
: []),
|
||||
{
|
||||
scale,
|
||||
name: "99%",
|
||||
icon: "🚀",
|
||||
title: `${title} Top 99% Price`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: toList(arg).map((cohort) => ({
|
||||
title: toLegendName(arg, cohort.title, `99%`),
|
||||
color: isSingle ? colors.probability1p : cohort.color,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${cohort.valueDatasetPath}-99p`
|
||||
),
|
||||
})),
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "99.5%",
|
||||
icon: "🚀",
|
||||
title: `${title} Top 99.5% Price`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: toList(arg).map((cohort) => ({
|
||||
title: toLegendName(arg, cohort.title, `99.5%`),
|
||||
color: isSingle ? colors.probability0_5p : cohort.color,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${cohort.valueDatasetPath}-99-5p`
|
||||
),
|
||||
})),
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "99.9%",
|
||||
icon: "🚀",
|
||||
title: `${title} Top 99.9% Price`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: toList(arg).map((cohort) => ({
|
||||
title: toLegendName(arg, cohort.title, `99.9%`),
|
||||
color: isSingle ? colors.probability0_1p : cohort.color,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${cohort.valueDatasetPath}-99-9p`
|
||||
),
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "Bottom Percentiles",
|
||||
icon: "🤿",
|
||||
title: `Market Price To ${title} Ratio Bottom Percentiles`,
|
||||
description: "",
|
||||
unit: "Ratio",
|
||||
top: [
|
||||
name: "Bottom",
|
||||
tree: [
|
||||
...(isSingle
|
||||
? /** @satisfies {PartialChartOption[]} */ ([
|
||||
{
|
||||
scale,
|
||||
name: "Percentiles",
|
||||
icon: "🤿",
|
||||
title: `Market Price To ${title} Ratio Bottom Percentiles`,
|
||||
description: "",
|
||||
unit: "Ratio",
|
||||
top: [
|
||||
{
|
||||
title,
|
||||
color: arg.color,
|
||||
datasetPath: arg.valueDatasetPath,
|
||||
},
|
||||
],
|
||||
bottom: [
|
||||
{
|
||||
title: `0.1%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: `${arg.ratioDatasetPath}-0-1p`,
|
||||
},
|
||||
{
|
||||
title: `0.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${arg.ratioDatasetPath}-0-5p`,
|
||||
},
|
||||
{
|
||||
title: `1%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${arg.ratioDatasetPath}-1p`
|
||||
),
|
||||
},
|
||||
{
|
||||
title: `Raw`,
|
||||
color: colors.default,
|
||||
datasetPath: arg.ratioDatasetPath,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
: []),
|
||||
{
|
||||
title: `SMA`,
|
||||
color,
|
||||
datasetPath: valueDatasetPath,
|
||||
},
|
||||
],
|
||||
bottom: [
|
||||
{
|
||||
title: `0.1%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: `${ratioDatasetPath}-0-1p`,
|
||||
},
|
||||
{
|
||||
title: `0.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${ratioDatasetPath}-0-5p`,
|
||||
},
|
||||
{
|
||||
title: `1%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: /** @type {any} */ (`${ratioDatasetPath}-1p`),
|
||||
},
|
||||
{
|
||||
title: `Raw`,
|
||||
color: colors.default,
|
||||
datasetPath: ratioDatasetPath,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "Top Probabilities",
|
||||
icon: "🚀",
|
||||
title: `${title} Top Probabilities`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: [
|
||||
{
|
||||
title: `99.9%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: /** @type {any} */ (`${valueDatasetPath}-99-9p`),
|
||||
},
|
||||
{
|
||||
title: `99.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${valueDatasetPath}-99-5p`,
|
||||
},
|
||||
{
|
||||
title: `99%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: `${valueDatasetPath}-99p`,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "Bottom Probabilities",
|
||||
icon: "🚇",
|
||||
title: `${title} Bottom Probabilities`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: [
|
||||
{
|
||||
title: `99.9%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: `${valueDatasetPath}-0-1p`,
|
||||
},
|
||||
{
|
||||
title: `99.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${valueDatasetPath}-0-5p`,
|
||||
},
|
||||
{
|
||||
title: `99%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: `${valueDatasetPath}-1p`,
|
||||
name: "Prices",
|
||||
tree: [
|
||||
...(isSingle
|
||||
? /** @satisfies {PartialChartOption[]} */ ([
|
||||
{
|
||||
scale,
|
||||
name: "All",
|
||||
icon: "🚇",
|
||||
title: `${title} Bottom Prices`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: [
|
||||
{
|
||||
title: `0.1%`,
|
||||
color: colors.probability0_1p,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${arg.valueDatasetPath}-0-1p`
|
||||
),
|
||||
},
|
||||
{
|
||||
title: `0.5%`,
|
||||
color: colors.probability0_5p,
|
||||
datasetPath: `${arg.valueDatasetPath}-0-5p`,
|
||||
},
|
||||
{
|
||||
title: `1%`,
|
||||
color: colors.probability1p,
|
||||
datasetPath: `${arg.valueDatasetPath}-1p`,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
: []),
|
||||
{
|
||||
scale,
|
||||
name: "1%",
|
||||
icon: "🚇",
|
||||
title: `${title} Bottom 1% Price`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: toList(arg).map((cohort) => ({
|
||||
title: toLegendName(arg, cohort.title, `1%`),
|
||||
color: isSingle ? colors.probability1p : cohort.color,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${cohort.valueDatasetPath}-1p`
|
||||
),
|
||||
})),
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "0.5%",
|
||||
icon: "🚇",
|
||||
title: `${title} Bottom 0.5% Price`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: toList(arg).map((cohort) => ({
|
||||
title: toLegendName(arg, cohort.title, `0.5%`),
|
||||
color: isSingle ? colors.probability0_5p : cohort.color,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${cohort.valueDatasetPath}-0-5p`
|
||||
),
|
||||
})),
|
||||
},
|
||||
{
|
||||
scale,
|
||||
name: "0.1%",
|
||||
icon: "🚇",
|
||||
title: `${title} Bottom 0.1% Price`,
|
||||
description: "",
|
||||
unit: "US Dollars",
|
||||
top: toList(arg).map((cohort) => ({
|
||||
title: toLegendName(arg, cohort.title, `0.1%`),
|
||||
color: isSingle ? colors.probability0_1p : cohort.color,
|
||||
datasetPath: /** @type {any} */ (
|
||||
`${cohort.valueDatasetPath}-0-1p`
|
||||
),
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -2733,6 +2900,20 @@ function createPartialOptions(colors) {
|
||||
function createCohortRealizedOptions(arg) {
|
||||
const { scale, title } = arg;
|
||||
|
||||
/**
|
||||
* @param {DefaultCohortOption} arg
|
||||
* @returns {RatioOption}
|
||||
*/
|
||||
function argToRatioArg(arg) {
|
||||
return {
|
||||
scale,
|
||||
color: arg.color,
|
||||
ratioDatasetPath: `${scale}-to-market-price-to-${datasetIdToPrefix(arg.datasetId)}realized-price-ratio`,
|
||||
valueDatasetPath: `${scale}-to-${datasetIdToPrefix(arg.datasetId)}realized-price`,
|
||||
title: `${arg.title} Realized Price`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
name: "Realized",
|
||||
tree: [
|
||||
@@ -2746,20 +2927,19 @@ function createPartialOptions(colors) {
|
||||
top: cohortOptionOrOptions.toSeriesBlueprints(arg, {
|
||||
title: "Realized Price",
|
||||
genPath: (id, scale) =>
|
||||
`${scale}-to-${datasetIdToPrefix(id)}realized-price`,
|
||||
/** @type {const} */ (
|
||||
`${scale}-to-${datasetIdToPrefix(id)}realized-price`
|
||||
),
|
||||
}),
|
||||
},
|
||||
...(!("list" in arg)
|
||||
? [
|
||||
createRatioOptions({
|
||||
scale,
|
||||
color: arg.color,
|
||||
ratioDatasetPath: `${scale}-to-market-price-to-${datasetIdToPrefix(arg.datasetId)}realized-price-ratio`,
|
||||
valueDatasetPath: `${scale}-to-${datasetIdToPrefix(arg.datasetId)}realized-price`,
|
||||
title: `${title} Realized Price`,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
createRatioOptions(
|
||||
"list" in arg
|
||||
? {
|
||||
...arg,
|
||||
list: arg.list.map(argToRatioArg),
|
||||
}
|
||||
: argToRatioArg(arg),
|
||||
),
|
||||
{
|
||||
scale,
|
||||
name: `Capitalization`,
|
||||
@@ -2774,7 +2954,9 @@ function createPartialOptions(colors) {
|
||||
{
|
||||
title: "Realized Cap.",
|
||||
genPath: (id, scale) =>
|
||||
`${scale}-to-${datasetIdToPrefix(id)}realized-cap`,
|
||||
/** @type {const} */ (
|
||||
`${scale}-to-${datasetIdToPrefix(id)}realized-cap`
|
||||
),
|
||||
},
|
||||
),
|
||||
...(cohortOptionOrOptions.shouldShowAll(arg)
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
URL + Version:
|
||||
|
||||
https://unpkg.com/browse/lean-qr@latest/
|
||||
File diff suppressed because one or more lines are too long
241
website/scripts/packages/lean-qr/v2.3.4/types.d.ts
vendored
241
website/scripts/packages/lean-qr/v2.3.4/types.d.ts
vendored
@@ -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;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
TradingView Lightweight Charts™
|
||||
Copyright (с) 2023 TradingView, Inc. https://www.tradingview.com/
|
||||
@@ -1,3 +0,0 @@
|
||||
URL + Version:
|
||||
|
||||
https://unpkg.com/browse/lightweight-charts@latest/
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,10 +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;
|
||||
@@ -1,143 +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';
|
||||
import { Owner } from './owner';
|
||||
export interface SignalOptions<T> {
|
||||
name?: string;
|
||||
equals?: ((prev: T, next: T) => boolean) | false;
|
||||
}
|
||||
export interface MemoOptions<T> extends SignalOptions<T> {
|
||||
initial?: T;
|
||||
}
|
||||
interface SourceType {
|
||||
_observers: ObserverType[] | null;
|
||||
_updateIfNecessary: () => void;
|
||||
_stateFlags: Flags;
|
||||
}
|
||||
interface ObserverType {
|
||||
_sources: SourceType[] | null;
|
||||
_notify: (state: number) => void;
|
||||
_handlerMask: Flags;
|
||||
_notifyFlags: (mask: Flags, newFlags: Flags) => void;
|
||||
}
|
||||
/**
|
||||
* Returns the current observer.
|
||||
*/
|
||||
export declare function getObserver(): ObserverType | 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;
|
||||
_compute: null | (() => T);
|
||||
_name: string | undefined;
|
||||
_equals: false | ((a: T, b: T) => boolean);
|
||||
/** 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;
|
||||
_error: Computation<boolean> | null;
|
||||
_loading: Computation<boolean> | null;
|
||||
constructor(initialValue: T | undefined, compute: null | (() => T), options?: MemoOptions<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;
|
||||
/**
|
||||
* Return true if the computation is the value is dependent on an unresolved promise
|
||||
* Triggers re-execution of the computation when the loading state changes
|
||||
*
|
||||
* This is useful especially when effects want to re-execute when a computation's
|
||||
* loading state changes
|
||||
*/
|
||||
loading(): boolean;
|
||||
/**
|
||||
* Return true if the computation is the computation threw an error
|
||||
* Triggers re-execution of the computation when the error state changes
|
||||
*/
|
||||
error(): boolean;
|
||||
/** 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): 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;
|
||||
/**
|
||||
* 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, compute: (val: T) => T, observer: Computation<T>): T;
|
||||
export declare function compute<T>(owner: Owner | null, compute: (val: undefined) => T, observer: null): T;
|
||||
export {};
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Computation, type MemoOptions } from './core';
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* 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> {
|
||||
constructor(initialValue: T, compute: () => T, options?: MemoOptions<T>);
|
||||
_notify(state: number): void;
|
||||
write(value: T): T;
|
||||
_setError(error: unknown): void;
|
||||
}
|
||||
export declare class RenderEffect<T = any> extends Computation<T> {
|
||||
effect: (val: T) => void;
|
||||
modified: boolean;
|
||||
constructor(initialValue: T, compute: () => T, effect: (val: T) => void, options?: MemoOptions<T>);
|
||||
_notify(state: number): void;
|
||||
write(value: T): T;
|
||||
_setError(error: unknown): void;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
export declare class NotReadyError extends Error {
|
||||
}
|
||||
export declare class NoOwnerError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class ContextNotFoundError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export interface ErrorHandler {
|
||||
(error: unknown): void;
|
||||
}
|
||||
@@ -1,8 +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 DEFAULT_FLAGS: number;
|
||||
@@ -1,8 +0,0 @@
|
||||
export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler, } from './error';
|
||||
export { Owner, createContext, getContext, setContext, hasContext, getOwner, setOwner, onCleanup, type Context, type ContextRecord, type Disposable, } from './owner';
|
||||
export { Computation, compute, getObserver, isEqual, untrack, type MemoOptions, type SignalOptions, } from './core';
|
||||
export { flushSync, Effect, RenderEffect } from './effect';
|
||||
export { indexArray, mapArray, type Maybe } from './map';
|
||||
export { createSelector, type SelectorOptions, type SelectorSignal, } from './selector';
|
||||
export * from './signals';
|
||||
export * from './store';
|
||||
@@ -1,26 +0,0 @@
|
||||
import type { Accessor } from './signals';
|
||||
export type Maybe<T> = T | void | null | undefined | false;
|
||||
/**
|
||||
* Reactive map helper that caches each item by index to reduce unnecessary mapping on updates.
|
||||
* It only runs the mapping function once per item and adds/removes as needed. In a non-keyed map
|
||||
* like this the index is fixed but value can change (opposite of a keyed map).
|
||||
*
|
||||
* Prefer `mapArray` when referential checks are required.
|
||||
*
|
||||
* @see {@link https://github.com/solidjs/x-reactivity#indexarray}
|
||||
*/
|
||||
export declare function indexArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: number) => MappedItem, options?: {
|
||||
name?: string;
|
||||
}): Accessor<MappedItem[]>;
|
||||
/**
|
||||
* Reactive map helper that caches each list item by reference to reduce unnecessary mapping on
|
||||
* updates. It only runs the mapping function once per item and then moves or removes it as needed.
|
||||
* In a keyed map like this the value is fixed but the index changes (opposite of non-keyed map).
|
||||
*
|
||||
* Prefer `indexArray` when working with primitives to avoid unnecessary re-renders.
|
||||
*
|
||||
* @see {@link https://github.com/solidjs/x-reactivity#maparray}
|
||||
*/
|
||||
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Item, index: Accessor<number>) => MappedItem, options?: {
|
||||
name?: string;
|
||||
}): Accessor<MappedItem[]>;
|
||||
@@ -1,88 +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 ErrorHandler } from './error';
|
||||
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;
|
||||
_handlers: ErrorHandler[] | null;
|
||||
constructor(signal?: boolean);
|
||||
append(child: Owner): void;
|
||||
dispose(this: Owner, self?: boolean): void;
|
||||
_disposeNode(): void;
|
||||
emptyDisposal(): void;
|
||||
handleError(error: unknown): void;
|
||||
}
|
||||
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 the given function when the parent owner computation is being disposed.
|
||||
*/
|
||||
export declare function onCleanup(disposable: Disposable): void;
|
||||
@@ -1,15 +0,0 @@
|
||||
import type { Accessor } from './signals';
|
||||
export interface SelectorSignal<T> {
|
||||
(key: T): Boolean;
|
||||
}
|
||||
export interface SelectorOptions<Key, Value> {
|
||||
name?: string;
|
||||
equals?: (key: Key, value: Value | undefined) => boolean;
|
||||
}
|
||||
/**
|
||||
* Creates a signal that observes the given `source` and returns a new signal who only notifies
|
||||
* observers when entering or exiting a specified key.
|
||||
*
|
||||
* @see {@link https://github.com/solidjs/x-reactivity#createselector}
|
||||
*/
|
||||
export declare function createSelector<Source, Key = Source>(source: Accessor<Source>, options?: SelectorOptions<Key, Source>): SelectorSignal<Key>;
|
||||
@@ -1,55 +0,0 @@
|
||||
import type { MemoOptions, SignalOptions } from './core';
|
||||
import { Owner } from './owner';
|
||||
export interface Accessor<T> {
|
||||
(): T;
|
||||
}
|
||||
export interface Setter<T> {
|
||||
(value: T | SetValue<T>): T;
|
||||
}
|
||||
export interface SetValue<T> {
|
||||
(currentValue: T): T;
|
||||
}
|
||||
export type Signal<T> = [read: Accessor<T>, write: Setter<T>];
|
||||
/**
|
||||
* Wraps the given value into a signal. The signal will return the current value when invoked
|
||||
* `fn()`, and provide a simple write API via `write()`. The value can now be observed
|
||||
* when used inside other computations created with `computed` and `effect`.
|
||||
*/
|
||||
export declare function createSignal<T>(initialValue: T, options?: SignalOptions<T>): Signal<T>;
|
||||
export declare function createAsync<T>(fn: () => Promise<T>, initial?: T, options?: SignalOptions<T>): Accessor<T>;
|
||||
/**
|
||||
* Creates a new computation whose value is computed and returned by the given function. The given
|
||||
* compute function is _only_ re-run when one of it's dependencies are updated. Dependencies are
|
||||
* are all signals that are read during execution.
|
||||
*/
|
||||
export declare function createMemo<T>(compute: () => T, initialValue?: T, options?: MemoOptions<T>): Accessor<T>;
|
||||
/**
|
||||
* Invokes the given function each time any of the signals that are read inside are updated
|
||||
* (i.e., their value changes). The effect is immediately invoked on initialization.
|
||||
*/
|
||||
export declare function createEffect<T>(effect: () => T, initialValue?: T, options?: {
|
||||
name?: string;
|
||||
}): void;
|
||||
/**
|
||||
* Invokes the given function each time any of the signals that are read inside are updated
|
||||
* (i.e., their value changes). The effect is immediately invoked on initialization.
|
||||
*/
|
||||
export declare function createRenderEffect<T>(compute: () => T, effect: (v: T) => T, initialValue?: T, options?: {
|
||||
name?: string;
|
||||
}): void;
|
||||
/**
|
||||
* Creates a computation root which is given a `dispose()` function to dispose of all inner
|
||||
* computations.
|
||||
*/
|
||||
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
|
||||
/**
|
||||
* Runs the given function in the given owner so that error handling and cleanups continue to work.
|
||||
*
|
||||
* 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 | undefined;
|
||||
/**
|
||||
* Runs the given function when an error is thrown in a child owner. If the error is thrown again
|
||||
* inside the error handler, it will trigger the next available parent owner handler.
|
||||
*/
|
||||
export declare function catchError<T>(fn: () => T, handler: (error: unknown) => void): void;
|
||||
@@ -1,22 +0,0 @@
|
||||
export type Store<T> = Readonly<T>;
|
||||
export type StoreSetter<T> = (fn: (state: T) => void) => void;
|
||||
export type StoreNode = Record<PropertyKey, any>;
|
||||
export declare namespace SolidStore {
|
||||
interface Unwrappable {
|
||||
}
|
||||
}
|
||||
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
|
||||
export declare function 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, set?: Set<unknown>): T;
|
||||
export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
||||
@@ -1 +0,0 @@
|
||||
export declare function isUndefined(value: any): value is undefined;
|
||||
@@ -1,762 +0,0 @@
|
||||
// src/error.ts
|
||||
var NotReadyError = class extends Error {};
|
||||
var NoOwnerError = class extends Error {
|
||||
constructor() {
|
||||
super("");
|
||||
}
|
||||
};
|
||||
var ContextNotFoundError = class extends Error {
|
||||
constructor() {
|
||||
super("");
|
||||
}
|
||||
};
|
||||
|
||||
// src/constants.ts
|
||||
var STATE_CLEAN = 0;
|
||||
var STATE_CHECK = 1;
|
||||
var STATE_DIRTY = 2;
|
||||
var STATE_DISPOSED = 3;
|
||||
|
||||
// src/utils.ts
|
||||
function isUndefined(value) {
|
||||
return typeof value === "undefined";
|
||||
}
|
||||
|
||||
// src/owner.ts
|
||||
var currentOwner = null;
|
||||
var defaultContext = {};
|
||||
function getOwner() {
|
||||
return currentOwner;
|
||||
}
|
||||
function setOwner(owner) {
|
||||
const out = currentOwner;
|
||||
currentOwner = owner;
|
||||
return out;
|
||||
}
|
||||
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
|
||||
k = null;
|
||||
g = null;
|
||||
j = null;
|
||||
a = STATE_CLEAN;
|
||||
e = null;
|
||||
h = defaultContext;
|
||||
f = null;
|
||||
constructor(signal = false) {
|
||||
if (currentOwner && !signal) currentOwner.append(this);
|
||||
}
|
||||
append(child) {
|
||||
child.k = this;
|
||||
child.j = this;
|
||||
if (this.g) this.g.j = child;
|
||||
child.g = this.g;
|
||||
this.g = child;
|
||||
if (child.h !== this.h) {
|
||||
child.h = { ...this.h, ...child.h };
|
||||
}
|
||||
if (this.f) {
|
||||
child.f = !child.f ? this.f : [...child.f, ...this.f];
|
||||
}
|
||||
}
|
||||
dispose(self = true) {
|
||||
if (this.a === STATE_DISPOSED) return;
|
||||
let head = self ? this.j || this.k : this,
|
||||
current = this.g,
|
||||
next = null;
|
||||
while (current && current.k === this) {
|
||||
current.dispose(true);
|
||||
current.n();
|
||||
next = current.g;
|
||||
current.g = null;
|
||||
current = next;
|
||||
}
|
||||
if (self) this.n();
|
||||
if (current) current.j = !self ? this : this.j;
|
||||
if (head) head.g = current;
|
||||
}
|
||||
n() {
|
||||
if (this.j) this.j.g = null;
|
||||
this.k = null;
|
||||
this.j = null;
|
||||
this.h = defaultContext;
|
||||
this.f = null;
|
||||
this.a = STATE_DISPOSED;
|
||||
this.emptyDisposal();
|
||||
}
|
||||
emptyDisposal() {
|
||||
if (!this.e) return;
|
||||
if (Array.isArray(this.e)) {
|
||||
for (let i = 0; i < this.e.length; i++) {
|
||||
const callable = this.e[i];
|
||||
callable.call(callable);
|
||||
}
|
||||
} else {
|
||||
this.e.call(this.e);
|
||||
}
|
||||
this.e = null;
|
||||
}
|
||||
handleError(error) {
|
||||
if (!this.f) throw error;
|
||||
let i = 0,
|
||||
len = this.f.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
try {
|
||||
this.f[i](error);
|
||||
break;
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
if (i === len) throw error;
|
||||
}
|
||||
};
|
||||
function createContext(defaultValue, description) {
|
||||
return { id: Symbol(description), defaultValue };
|
||||
}
|
||||
function getContext(context, owner = currentOwner) {
|
||||
if (!owner) {
|
||||
throw new NoOwnerError();
|
||||
}
|
||||
const value = hasContext(context, owner)
|
||||
? owner.h[context.id]
|
||||
: context.defaultValue;
|
||||
if (isUndefined(value)) {
|
||||
throw new ContextNotFoundError();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function setContext(context, value, owner = currentOwner) {
|
||||
if (!owner) {
|
||||
throw new NoOwnerError();
|
||||
}
|
||||
owner.h = {
|
||||
...owner.h,
|
||||
[context.id]: isUndefined(value) ? context.defaultValue : value,
|
||||
};
|
||||
}
|
||||
function hasContext(context, owner = currentOwner) {
|
||||
return !isUndefined(owner?.h[context.id]);
|
||||
}
|
||||
function onCleanup(disposable) {
|
||||
if (!currentOwner) return;
|
||||
const node = currentOwner;
|
||||
if (!node.e) {
|
||||
node.e = disposable;
|
||||
} else if (Array.isArray(node.e)) {
|
||||
node.e.push(disposable);
|
||||
} else {
|
||||
node.e = [node.e, disposable];
|
||||
}
|
||||
}
|
||||
|
||||
// src/flags.ts
|
||||
var ERROR_OFFSET = 0;
|
||||
var ERROR_BIT = 1 << ERROR_OFFSET;
|
||||
var LOADING_OFFSET = 1;
|
||||
var LOADING_BIT = 1 << LOADING_OFFSET;
|
||||
var DEFAULT_FLAGS = ERROR_BIT;
|
||||
|
||||
// src/scheduler.ts
|
||||
var scheduled = false;
|
||||
var runningScheduled = false;
|
||||
var Computations = [];
|
||||
var RenderEffects = [];
|
||||
var Effects = [];
|
||||
function flushSync() {
|
||||
if (!runningScheduled) runScheduled();
|
||||
}
|
||||
function flushQueue() {
|
||||
if (scheduled) return;
|
||||
scheduled = true;
|
||||
queueMicrotask(runScheduled);
|
||||
}
|
||||
function runTop(node) {
|
||||
const ancestors = [];
|
||||
for (let current = node; current !== null; current = current.k) {
|
||||
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].l();
|
||||
}
|
||||
}
|
||||
function runScheduled() {
|
||||
if (!Effects.length && !RenderEffects.length && !Computations.length) {
|
||||
scheduled = false;
|
||||
return;
|
||||
}
|
||||
runningScheduled = true;
|
||||
try {
|
||||
runPureQueue(Computations);
|
||||
runPureQueue(RenderEffects);
|
||||
runPureQueue(Effects);
|
||||
} finally {
|
||||
const renderEffects = RenderEffects;
|
||||
const effects = Effects;
|
||||
Computations = [];
|
||||
Effects = [];
|
||||
RenderEffects = [];
|
||||
scheduled = false;
|
||||
runningScheduled = false;
|
||||
incrementClock();
|
||||
runEffectQueue(renderEffects);
|
||||
runEffectQueue(effects);
|
||||
}
|
||||
}
|
||||
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++) {
|
||||
if (queue[i].q && queue[i].a !== STATE_DISPOSED) {
|
||||
queue[i].r(queue[i].d, queue[i].o);
|
||||
queue[i].q = false;
|
||||
queue[i].o = queue[i].d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// src/core.ts
|
||||
var currentObserver = null;
|
||||
var currentMask = DEFAULT_FLAGS;
|
||||
var newSources = null;
|
||||
var newSourcesIndex = 0;
|
||||
var newFlags = 0;
|
||||
var clock = 0;
|
||||
var updateCheck = null;
|
||||
function getObserver() {
|
||||
return currentObserver;
|
||||
}
|
||||
function incrementClock() {
|
||||
clock++;
|
||||
}
|
||||
var UNCHANGED = Symbol(0);
|
||||
var Computation2 = class extends Owner {
|
||||
b = null;
|
||||
c = null;
|
||||
d;
|
||||
s;
|
||||
// Used in __DEV__ mode, hopefully removed in production
|
||||
B;
|
||||
// Using false is an optimization as an alternative to _equals: () => false
|
||||
// which could enable more efficient DIRTY notification
|
||||
t = isEqual;
|
||||
x;
|
||||
/** Whether the computation is an error or has ancestors that are unresolved */
|
||||
i = 0;
|
||||
/** Which flags raised by sources are handled, vs. being passed through. */
|
||||
p = DEFAULT_FLAGS;
|
||||
u = null;
|
||||
v = null;
|
||||
w = -1;
|
||||
constructor(initialValue, compute2, options) {
|
||||
super(compute2 === null);
|
||||
this.s = compute2;
|
||||
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
||||
this.d = initialValue;
|
||||
if (options?.equals !== void 0) this.t = options.equals;
|
||||
if (options?.unobserved) this.x = options?.unobserved;
|
||||
}
|
||||
y() {
|
||||
if (this.s) this.l();
|
||||
if (!this.b || this.b.length) track(this);
|
||||
newFlags |= this.i & ~currentMask;
|
||||
if (this.i & ERROR_BIT) {
|
||||
throw this.d;
|
||||
} else {
|
||||
return this.d;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Return the current value of this computation
|
||||
* Automatically re-executes the surrounding computation when the value changes
|
||||
*/
|
||||
read() {
|
||||
return this.y();
|
||||
}
|
||||
/**
|
||||
* 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.loading()) {
|
||||
throw new NotReadyError();
|
||||
}
|
||||
return this.y();
|
||||
}
|
||||
/**
|
||||
* Return true if the computation is the value is dependent on an unresolved promise
|
||||
* Triggers re-execution of the computation when the loading state changes
|
||||
*
|
||||
* This is useful especially when effects want to re-execute when a computation's
|
||||
* loading state changes
|
||||
*/
|
||||
loading() {
|
||||
if (this.v === null) {
|
||||
this.v = loadingState(this);
|
||||
}
|
||||
return this.v.read();
|
||||
}
|
||||
/**
|
||||
* Return true if the computation is the computation threw an error
|
||||
* Triggers re-execution of the computation when the error state changes
|
||||
*/
|
||||
error() {
|
||||
if (this.u === null) {
|
||||
this.u = errorState(this);
|
||||
}
|
||||
return this.u.read();
|
||||
}
|
||||
/** Update the computation with a new value. */
|
||||
write(value, flags = 0, raw = false) {
|
||||
const newValue =
|
||||
!raw && typeof value === "function" ? value(this.d) : value;
|
||||
const valueChanged =
|
||||
newValue !== UNCHANGED &&
|
||||
(!!(flags & ERROR_BIT) || this.t === false || !this.t(this.d, newValue));
|
||||
if (valueChanged) this.d = newValue;
|
||||
const changedFlagsMask = this.i ^ flags,
|
||||
changedFlags = changedFlagsMask & flags;
|
||||
this.i = flags;
|
||||
this.w = clock + 1;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
if (valueChanged) {
|
||||
this.c[i].m(STATE_DIRTY);
|
||||
} else if (changedFlagsMask) {
|
||||
this.c[i].z(changedFlagsMask, changedFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.d;
|
||||
}
|
||||
/**
|
||||
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
||||
*/
|
||||
m(state) {
|
||||
if (this.a >= state) return;
|
||||
this.a = state;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
this.c[i].m(STATE_CHECK);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
z(mask, newFlags2) {
|
||||
if (this.a >= STATE_DIRTY) return;
|
||||
if (mask & this.p) {
|
||||
this.m(STATE_DIRTY);
|
||||
return;
|
||||
}
|
||||
if (this.a >= STATE_CHECK) return;
|
||||
const prevFlags = this.i & mask;
|
||||
const deltaFlags = prevFlags ^ newFlags2;
|
||||
if (newFlags2 === prevFlags);
|
||||
else if (deltaFlags & prevFlags & mask) {
|
||||
this.m(STATE_CHECK);
|
||||
} else {
|
||||
this.i ^= deltaFlags;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
this.c[i].z(mask, newFlags2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
A(error) {
|
||||
this.write(error, this.i | ERROR_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
|
||||
*/
|
||||
l() {
|
||||
if (this.a === STATE_DISPOSED) {
|
||||
throw new Error("Tried to read a disposed computation");
|
||||
}
|
||||
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].l();
|
||||
observerFlags |= this.b[i].i;
|
||||
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
|
||||
*/
|
||||
n() {
|
||||
if (this.a === STATE_DISPOSED) return;
|
||||
if (this.b) removeSourceObservers(this, 0);
|
||||
super.n();
|
||||
}
|
||||
};
|
||||
function loadingState(node) {
|
||||
const prevOwner = setOwner(node.k);
|
||||
const options = void 0;
|
||||
const computation = new Computation2(
|
||||
void 0,
|
||||
() => {
|
||||
track(node);
|
||||
node.l();
|
||||
return !!(node.i & LOADING_BIT);
|
||||
},
|
||||
options,
|
||||
);
|
||||
computation.p = ERROR_BIT | LOADING_BIT;
|
||||
setOwner(prevOwner);
|
||||
return computation;
|
||||
}
|
||||
function errorState(node) {
|
||||
const prevOwner = setOwner(node.k);
|
||||
const options = void 0;
|
||||
const computation = new Computation2(
|
||||
void 0,
|
||||
() => {
|
||||
track(node);
|
||||
node.l();
|
||||
return !!(node.i & ERROR_BIT);
|
||||
},
|
||||
options,
|
||||
);
|
||||
computation.p = ERROR_BIT;
|
||||
setOwner(prevOwner);
|
||||
return computation;
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (updateCheck) {
|
||||
updateCheck.d = computation.w > currentObserver.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
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.s, node);
|
||||
node.write(result, newFlags, true);
|
||||
} catch (error) {
|
||||
if (error instanceof NotReadyError) {
|
||||
node.write(UNCHANGED, newFlags | LOADING_BIT);
|
||||
} else {
|
||||
node.A(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.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.x?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
function isEqual(a, b) {
|
||||
return a === b;
|
||||
}
|
||||
function untrack(fn) {
|
||||
if (currentObserver === null) return fn();
|
||||
return compute(getOwner(), fn, null);
|
||||
}
|
||||
function hasUpdated(fn) {
|
||||
const current = updateCheck;
|
||||
updateCheck = { d: false };
|
||||
try {
|
||||
fn();
|
||||
return updateCheck.d;
|
||||
} finally {
|
||||
updateCheck = current;
|
||||
}
|
||||
}
|
||||
function compute(owner, compute2, observer) {
|
||||
const prevOwner = setOwner(owner),
|
||||
prevObserver = currentObserver,
|
||||
prevMask = currentMask;
|
||||
currentObserver = observer;
|
||||
currentMask = observer?.p ?? DEFAULT_FLAGS;
|
||||
try {
|
||||
return compute2(observer ? observer.d : void 0);
|
||||
} finally {
|
||||
setOwner(prevOwner);
|
||||
currentObserver = prevObserver;
|
||||
currentMask = prevMask;
|
||||
}
|
||||
}
|
||||
var EagerComputation = class extends Computation2 {
|
||||
constructor(initialValue, compute2, options) {
|
||||
super(initialValue, compute2, options);
|
||||
this.l();
|
||||
Computations.push(this);
|
||||
}
|
||||
m(state) {
|
||||
if (this.a >= state) return;
|
||||
if (this.a === STATE_CLEAN) {
|
||||
Computations.push(this);
|
||||
flushQueue();
|
||||
}
|
||||
this.a = state;
|
||||
}
|
||||
};
|
||||
|
||||
// src/effect.ts
|
||||
var BaseEffect = class extends Computation2 {
|
||||
r;
|
||||
q = false;
|
||||
o;
|
||||
constructor(initialValue, compute2, effect, options) {
|
||||
super(initialValue, compute2, options);
|
||||
this.r = effect;
|
||||
this.o = initialValue;
|
||||
}
|
||||
write(value) {
|
||||
if (value === UNCHANGED) return this.d;
|
||||
this.d = value;
|
||||
this.q = true;
|
||||
return value;
|
||||
}
|
||||
A(error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
n() {
|
||||
this.r = void 0;
|
||||
this.o = void 0;
|
||||
super.n();
|
||||
}
|
||||
};
|
||||
var Effect = class extends BaseEffect {
|
||||
constructor(initialValue, compute2, effect, options) {
|
||||
super(initialValue, compute2, effect, options);
|
||||
Effects.push(this);
|
||||
flushQueue();
|
||||
}
|
||||
m(state) {
|
||||
if (this.a >= state) return;
|
||||
if (this.a === STATE_CLEAN) {
|
||||
Effects.push(this);
|
||||
flushQueue();
|
||||
}
|
||||
this.a = state;
|
||||
}
|
||||
};
|
||||
var RenderEffect = class extends BaseEffect {
|
||||
constructor(initialValue, compute2, effect, options) {
|
||||
super(initialValue, compute2, effect, options);
|
||||
this.l();
|
||||
RenderEffects.push(this);
|
||||
}
|
||||
m(state) {
|
||||
if (this.a >= state) return;
|
||||
if (this.a === STATE_CLEAN) {
|
||||
RenderEffects.push(this);
|
||||
flushQueue();
|
||||
}
|
||||
this.a = state;
|
||||
}
|
||||
};
|
||||
|
||||
// src/signals.ts
|
||||
function createSignal(first, second, third) {
|
||||
if (typeof first === "function") {
|
||||
const memo = createMemo((p) => {
|
||||
const node2 = new Computation2(
|
||||
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 Computation2(first, null, second);
|
||||
return [node.read.bind(node), node.write.bind(node)];
|
||||
}
|
||||
function createAsync(fn, initial, options) {
|
||||
const lhs = new EagerComputation(void 0, () => {
|
||||
const source = fn(initial);
|
||||
const isPromise = source instanceof Promise;
|
||||
const iterator = source[Symbol.asyncIterator];
|
||||
if (!isPromise && !iterator) {
|
||||
return {
|
||||
wait() {
|
||||
return source;
|
||||
},
|
||||
};
|
||||
}
|
||||
const signal = new Computation2(initial, null, options);
|
||||
signal.write(UNCHANGED, LOADING_BIT);
|
||||
if (isPromise) {
|
||||
source.then(
|
||||
(value) => {
|
||||
signal.write(value, 0);
|
||||
},
|
||||
(error) => {
|
||||
signal.write(error, ERROR_BIT);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
let abort = false;
|
||||
onCleanup(() => (abort = true));
|
||||
(async () => {
|
||||
try {
|
||||
for await (let value of source) {
|
||||
if (abort) return;
|
||||
signal.write(value, 0);
|
||||
}
|
||||
} catch (error) {
|
||||
signal.write(error, ERROR_BIT);
|
||||
}
|
||||
})();
|
||||
}
|
||||
return signal;
|
||||
});
|
||||
return () => lhs.wait().wait();
|
||||
}
|
||||
function createMemo(compute2, initialValue, options) {
|
||||
let node = new Computation2(initialValue, compute2, options);
|
||||
let value;
|
||||
return () => {
|
||||
if (node) {
|
||||
value = node.wait();
|
||||
if (!node.b?.length) node = void 0;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
function createEffect(compute2, effect, initialValue, options) {
|
||||
void new Effect(initialValue, compute2, effect, void 0);
|
||||
}
|
||||
function createRenderEffect(compute2, effect, initialValue, options) {
|
||||
void new RenderEffect(initialValue, compute2, effect, void 0);
|
||||
}
|
||||
function createRoot(init) {
|
||||
const owner = new Owner();
|
||||
return compute(
|
||||
owner,
|
||||
!init.length ? init : () => init(() => owner.dispose()),
|
||||
null,
|
||||
);
|
||||
}
|
||||
function runWithOwner(owner, run) {
|
||||
try {
|
||||
return compute(owner, run, null);
|
||||
} catch (error) {
|
||||
owner?.handleError(error);
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
function catchError(fn, handler) {
|
||||
const owner = new Owner();
|
||||
owner.f = owner.f ? [handler, ...owner.f] : [handler];
|
||||
try {
|
||||
compute(owner, fn, null);
|
||||
} catch (error) {
|
||||
owner.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
Computation2 as Computation,
|
||||
ContextNotFoundError,
|
||||
Effect,
|
||||
NoOwnerError,
|
||||
NotReadyError,
|
||||
Owner,
|
||||
RenderEffect,
|
||||
catchError,
|
||||
compute,
|
||||
createAsync,
|
||||
createContext,
|
||||
createEffect,
|
||||
createMemo,
|
||||
createRenderEffect,
|
||||
createRoot,
|
||||
createSignal,
|
||||
flushSync,
|
||||
getContext,
|
||||
getObserver,
|
||||
getOwner,
|
||||
hasContext,
|
||||
hasUpdated,
|
||||
isEqual,
|
||||
onCleanup,
|
||||
runWithOwner,
|
||||
setContext,
|
||||
setOwner,
|
||||
untrack,
|
||||
};
|
||||
@@ -1,10 +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;
|
||||
@@ -1,152 +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';
|
||||
import { Owner } from './owner';
|
||||
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) => void;
|
||||
_handlerMask: Flags;
|
||||
_notifyFlags: (mask: Flags, newFlags: Flags) => void;
|
||||
_time: number;
|
||||
}
|
||||
/**
|
||||
* Returns the current observer.
|
||||
*/
|
||||
export declare function getObserver(): ObserverType | null;
|
||||
export declare function incrementClock(): void;
|
||||
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;
|
||||
_compute: null | (() => 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;
|
||||
_error: Computation<boolean> | null;
|
||||
_loading: Computation<boolean> | null;
|
||||
_time: number;
|
||||
constructor(initialValue: T | undefined, compute: null | (() => 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;
|
||||
/**
|
||||
* Return true if the computation is the value is dependent on an unresolved promise
|
||||
* Triggers re-execution of the computation when the loading state changes
|
||||
*
|
||||
* This is useful especially when effects want to re-execute when a computation's
|
||||
* loading state changes
|
||||
*/
|
||||
loading(): boolean;
|
||||
/**
|
||||
* Return true if the computation is the computation threw an error
|
||||
* Triggers re-execution of the computation when the error state changes
|
||||
*/
|
||||
error(): boolean;
|
||||
/** 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): 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;
|
||||
export declare function hasUpdated(fn: () => any): Boolean;
|
||||
/**
|
||||
* 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, compute: (val: T) => T, observer: Computation<T>): T;
|
||||
export declare function compute<T>(owner: Owner | null, compute: (val: undefined) => T, observer: null): T;
|
||||
export declare class EagerComputation<T = any> extends Computation<T> {
|
||||
constructor(initialValue: T, compute: () => T, options?: SignalOptions<T>);
|
||||
_notify(state: number): void;
|
||||
}
|
||||
export {};
|
||||
@@ -1,23 +0,0 @@
|
||||
import { Computation, type SignalOptions } from './core';
|
||||
/**
|
||||
* 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 BaseEffect<T = any> extends Computation<T> {
|
||||
_effect: (val: T, prev: T | undefined) => void;
|
||||
_modified: boolean;
|
||||
_prevValue: T | undefined;
|
||||
constructor(initialValue: T, compute: () => T, effect: (val: T, prev: T | undefined) => void, options?: SignalOptions<T>);
|
||||
write(value: T): T;
|
||||
_setError(error: unknown): void;
|
||||
_disposeNode(): void;
|
||||
}
|
||||
export declare class Effect<T = any> extends BaseEffect<T> {
|
||||
constructor(initialValue: T, compute: () => T, effect: (val: T, prev: T | undefined) => void, options?: SignalOptions<T>);
|
||||
_notify(state: number): void;
|
||||
}
|
||||
export declare class RenderEffect<T = any> extends BaseEffect<T> {
|
||||
constructor(initialValue: T, compute: () => T, effect: (val: T, prev: T | undefined) => void, options?: SignalOptions<T>);
|
||||
_notify(state: number): void;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
export declare class NotReadyError extends Error {
|
||||
}
|
||||
export declare class NoOwnerError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export declare class ContextNotFoundError extends Error {
|
||||
constructor();
|
||||
}
|
||||
export interface ErrorHandler {
|
||||
(error: unknown): void;
|
||||
}
|
||||
@@ -1,8 +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 DEFAULT_FLAGS: number;
|
||||
@@ -1,6 +0,0 @@
|
||||
export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler, } from './error';
|
||||
export { Owner, createContext, getContext, setContext, hasContext, getOwner, setOwner, onCleanup, type Context, type ContextRecord, type Disposable, } from './owner';
|
||||
export { Computation, compute, getObserver, isEqual, untrack, hasUpdated, type SignalOptions, } from './core';
|
||||
export { Effect, RenderEffect } from './effect';
|
||||
export { flushSync } from './scheduler';
|
||||
export * from './signals';
|
||||
@@ -1,12 +0,0 @@
|
||||
import type { Accessor } from './signals';
|
||||
export type Maybe<T> = T | void | null | undefined | false;
|
||||
/**
|
||||
* Reactive map helper that caches each list item by reference to reduce unnecessary mapping on
|
||||
* updates.
|
||||
*
|
||||
* @see {@link https://github.com/solidjs/x-reactivity#maparray}
|
||||
*/
|
||||
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);
|
||||
name?: string;
|
||||
}): Accessor<MappedItem[]>;
|
||||
@@ -1,88 +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 ErrorHandler } from './error';
|
||||
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;
|
||||
_handlers: ErrorHandler[] | null;
|
||||
constructor(signal?: boolean);
|
||||
append(child: Owner): void;
|
||||
dispose(this: Owner, self?: boolean): void;
|
||||
_disposeNode(): void;
|
||||
emptyDisposal(): void;
|
||||
handleError(error: unknown): void;
|
||||
}
|
||||
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 the given function when the parent owner computation is being disposed.
|
||||
*/
|
||||
export declare function onCleanup(disposable: Disposable): void;
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Computation } from './core';
|
||||
import type { Effect, RenderEffect } from './effect';
|
||||
export declare let Computations: Computation[], RenderEffects: RenderEffect[], Effects: Effect[];
|
||||
/**
|
||||
* 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;
|
||||
export declare function flushQueue(): void;
|
||||
@@ -1,56 +0,0 @@
|
||||
import type { SignalOptions } from './core';
|
||||
import { Owner } from './owner';
|
||||
export interface Accessor<T> {
|
||||
(): T;
|
||||
}
|
||||
export interface Setter<T> {
|
||||
(value: T | SetValue<T>): T;
|
||||
}
|
||||
export interface SetValue<T> {
|
||||
(currentValue: T): T;
|
||||
}
|
||||
export type Signal<T> = [read: Accessor<T>, write: Setter<T>];
|
||||
/**
|
||||
* Wraps the given value into a signal. The signal will return the current value when invoked
|
||||
* `fn()`, and provide a simple write API via `write()`. The value can now be observed
|
||||
* when used inside other computations created with `computed` and `effect`.
|
||||
*/
|
||||
export declare function createSignal<T>(initialValue: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
|
||||
export declare function createSignal<T>(fn: (prev?: T) => T, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
|
||||
export declare function createAsync<T>(fn: (prev?: T) => Promise<T> | AsyncIterable<T> | T, initial?: T, options?: SignalOptions<T>): Accessor<T>;
|
||||
/**
|
||||
* Creates a new computation whose value is computed and returned by the given function. The given
|
||||
* compute function is _only_ re-run when one of it's dependencies are updated. Dependencies are
|
||||
* are all signals that are read during execution.
|
||||
*/
|
||||
export declare function createMemo<T>(compute: (prev?: T) => T, initialValue?: T, options?: SignalOptions<T>): Accessor<T>;
|
||||
/**
|
||||
* Invokes the given function each time any of the signals that are read inside are updated
|
||||
* (i.e., their value changes). The effect is immediately invoked on initialization.
|
||||
*/
|
||||
export declare function createEffect<T>(compute: () => T, effect: (v: T) => (() => void) | void, initialValue?: T, options?: {
|
||||
name?: string;
|
||||
}): void;
|
||||
/**
|
||||
* Invokes the given function each time any of the signals that are read inside are updated
|
||||
* (i.e., their value changes). The effect is immediately invoked on initialization.
|
||||
*/
|
||||
export declare function createRenderEffect<T>(compute: () => T, effect: (v: T) => (() => void) | void, initialValue?: T, options?: {
|
||||
name?: string;
|
||||
}): void;
|
||||
/**
|
||||
* Creates a computation root which is given a `dispose()` function to dispose of all inner
|
||||
* computations.
|
||||
*/
|
||||
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
|
||||
/**
|
||||
* Runs the given function in the given owner so that error handling and cleanups continue to work.
|
||||
*
|
||||
* 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 | undefined;
|
||||
/**
|
||||
* Runs the given function when an error is thrown in a child owner. If the error is thrown again
|
||||
* inside the error handler, it will trigger the next available parent owner handler.
|
||||
*/
|
||||
export declare function catchError<T>(fn: () => T, handler: (error: unknown) => void): void;
|
||||
@@ -1,31 +0,0 @@
|
||||
export type Store<T> = Readonly<T>;
|
||||
export type StoreSetter<T> = (fn: (state: T) => void) => void;
|
||||
declare const $TRACK: unique symbol, $PROXY: unique symbol;
|
||||
export { $PROXY, $TRACK };
|
||||
export type StoreNode = Record<PropertyKey, any>;
|
||||
export declare namespace SolidStore {
|
||||
interface Unwrappable {
|
||||
}
|
||||
}
|
||||
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
|
||||
export declare function 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, 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>];
|
||||
/**
|
||||
* 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): Readonly<T>;
|
||||
@@ -1 +0,0 @@
|
||||
export declare function isUndefined(value: any): value is undefined;
|
||||
@@ -1,5 +0,0 @@
|
||||
Compiled version of: https://github.com/solidjs/signals/commits/main/
|
||||
|
||||
Head:
|
||||
- SHA: 4d75d3f84ce22b560988f3b27a5065c0fd2e69a8
|
||||
- Date: Apr 17, 2024
|
||||
@@ -1,8 +0,0 @@
|
||||
URL:
|
||||
https://github.com/leeoniya/uFuzzy/commits/main/dist
|
||||
|
||||
Head:
|
||||
|
||||
- SHA: 6bb27a8d8c41e4be5458844afc5c89f6c2399512
|
||||
- Date: Feb 21, 2024
|
||||
- Version: v1.0.14
|
||||
1053
website/scripts/packages/ufuzzy/v1.0.14/script.js
vendored
1053
website/scripts/packages/ufuzzy/v1.0.14/script.js
vendored
File diff suppressed because it is too large
Load Diff
196
website/scripts/packages/ufuzzy/v1.0.14/types.d.ts
vendored
196
website/scripts/packages/ufuzzy/v1.0.14/types.d.ts
vendored
@@ -1,196 +0,0 @@
|
||||
declare class uFuzzy {
|
||||
constructor(opts?: uFuzzy.Options);
|
||||
|
||||
/** search API composed of filter/info/sort, with a info/ranking threshold (1e3) and fast outOfOrder impl */
|
||||
search(
|
||||
haystack: string[],
|
||||
needle: string,
|
||||
/** limit how many terms will be permuted, default = 0; 5 will result in up to 5! (120) search iterations. be careful with this! */
|
||||
outOfOrder?: number,
|
||||
/** default = 1e3 */
|
||||
infoThresh?: number,
|
||||
preFiltered?: uFuzzy.HaystackIdxs | null
|
||||
): uFuzzy.SearchResult;
|
||||
|
||||
/** initial haystack filter, can accept idxs from previous prefix/typeahead match as optimization */
|
||||
filter(
|
||||
haystack: string[],
|
||||
needle: string,
|
||||
idxs?: uFuzzy.HaystackIdxs
|
||||
): uFuzzy.HaystackIdxs | null;
|
||||
|
||||
/** collects stats about pre-filtered matches, does additional filtering based on term boundary settings, finds highlight ranges */
|
||||
info(
|
||||
idxs: uFuzzy.HaystackIdxs,
|
||||
haystack: string[],
|
||||
needle: string
|
||||
): uFuzzy.Info;
|
||||
|
||||
/** performs final result sorting via Array.sort(), relying on Info */
|
||||
sort(
|
||||
info: uFuzzy.Info,
|
||||
haystack: string[],
|
||||
needle: string
|
||||
): uFuzzy.InfoIdxOrder;
|
||||
|
||||
/** utility for splitting needle into terms following defined interSplit/intraSplit opts. useful for out-of-order permutes */
|
||||
split(needle: string): uFuzzy.Terms;
|
||||
|
||||
/** util for creating out-of-order permutations of a needle terms array */
|
||||
static permute(arr: unknown[]): unknown[][];
|
||||
|
||||
/** util for replacing common diacritics/accents */
|
||||
static latinize<T extends string[] | string>(strings: T): T;
|
||||
|
||||
/** util for highlighting matched substr parts of a result */
|
||||
static highlight<TAccum = string, TMarkedPart = string>(
|
||||
match: string,
|
||||
ranges: number[],
|
||||
|
||||
mark?: (part: string, matched: boolean) => TMarkedPart,
|
||||
accum?: TAccum,
|
||||
append?: (accum: TAccum, part: TMarkedPart) => TAccum | undefined
|
||||
): TAccum;
|
||||
}
|
||||
|
||||
export = uFuzzy;
|
||||
|
||||
declare namespace uFuzzy {
|
||||
/** needle's terms */
|
||||
export type Terms = string[];
|
||||
|
||||
/** subset of idxs of a haystack array */
|
||||
export type HaystackIdxs = number[];
|
||||
|
||||
/** sorted order in which info facets should be iterated */
|
||||
export type InfoIdxOrder = number[];
|
||||
|
||||
export type AbortedResult = [null, null, null];
|
||||
|
||||
export type FilteredResult = [uFuzzy.HaystackIdxs, null, null];
|
||||
|
||||
export type RankedResult = [
|
||||
uFuzzy.HaystackIdxs,
|
||||
uFuzzy.Info,
|
||||
uFuzzy.InfoIdxOrder
|
||||
];
|
||||
|
||||
export type SearchResult = FilteredResult | RankedResult | AbortedResult;
|
||||
|
||||
/** partial RegExp */
|
||||
type PartialRegExp = string;
|
||||
|
||||
/** what should be considered acceptable term bounds */
|
||||
export const enum BoundMode {
|
||||
/** will match 'man' substr anywhere. e.g. tasmania */
|
||||
Any = 0,
|
||||
/** will match 'man' at whitespace, punct, case-change, and alpha-num boundaries. e.g. mantis, SuperMan, fooManBar, 0007man */
|
||||
Loose = 1,
|
||||
/** will match 'man' at whitespace, punct boundaries only. e.g. mega man, walk_man, man-made, foo.man.bar */
|
||||
Strict = 2,
|
||||
}
|
||||
|
||||
export const enum IntraMode {
|
||||
/** allows any number of extra char insertions within a term, but all term chars must be present for a match */
|
||||
MultiInsert = 0,
|
||||
/** allows for a single-char substitution, transposition, insertion, or deletion within terms (excluding first and last chars) */
|
||||
SingleError = 1,
|
||||
}
|
||||
|
||||
export type IntraSliceIdxs = [from: number, to: number];
|
||||
|
||||
export interface Options {
|
||||
// whether regexps use a /u unicode flag
|
||||
unicode?: boolean; // false
|
||||
|
||||
/** @deprecated renamed to opts.alpha */
|
||||
letters?: PartialRegExp | null; // a-z
|
||||
|
||||
// regexp character class [] of chars which should be treated as letters (case insensitive)
|
||||
alpha?: PartialRegExp | null; // a-z
|
||||
|
||||
/** term segmentation & punct/whitespace merging */
|
||||
interSplit?: PartialRegExp; // '[^A-Za-z\\d']+'
|
||||
intraSplit?: PartialRegExp | null; // '[a-z][A-Z]'
|
||||
|
||||
/** inter bounds that will be used to increase lft2/rgt2 info counters */
|
||||
interBound?: PartialRegExp | null; // '[^A-Za-z\\d]'
|
||||
/** intra bounds that will be used to increase lft1/rgt1 info counters */
|
||||
intraBound?: PartialRegExp | null; // '[A-Za-z][0-9]|[0-9][A-Za-z]|[a-z][A-Z]'
|
||||
|
||||
/** inter-term modes, during .info() can discard matches when bounds conditions are not met */
|
||||
interLft?: BoundMode; // 0
|
||||
interRgt?: BoundMode; // 0
|
||||
|
||||
/** allowance between terms */
|
||||
interChars?: PartialRegExp; // '.'
|
||||
interIns?: number; // Infinity
|
||||
|
||||
/** allowance between chars within terms */
|
||||
intraChars?: PartialRegExp; // '[a-z\\d]'
|
||||
intraIns?: number; // 0
|
||||
|
||||
/** contractions detection */
|
||||
intraContr?: PartialRegExp; // "'[a-z]{1,2}\\b"
|
||||
|
||||
/** error tolerance mode within terms. will clamp intraIns to 1 when set to SingleError */
|
||||
intraMode?: IntraMode; // 0
|
||||
|
||||
/** which part of each term should tolerate errors (when intraMode: 1) */
|
||||
intraSlice?: IntraSliceIdxs; // [1, Infinity]
|
||||
|
||||
/** max substitutions (when intraMode: 1) */
|
||||
intraSub?: 0 | 1; // 0
|
||||
/** max transpositions (when intraMode: 1) */
|
||||
intraTrn?: 0 | 1; // 0
|
||||
/** max omissions/deletions (when intraMode: 1) */
|
||||
intraDel?: 0 | 1; // 0
|
||||
|
||||
/** can dynamically adjust error tolerance rules per term in needle (when intraMode: 1) */
|
||||
intraRules?: (term: string) => {
|
||||
intraSlice?: IntraSliceIdxs;
|
||||
intraIns: 0 | 1;
|
||||
intraSub: 0 | 1;
|
||||
intraTrn: 0 | 1;
|
||||
intraDel: 0 | 1;
|
||||
};
|
||||
|
||||
/** 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;
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
/** matched idxs from haystack */
|
||||
idx: HaystackIdxs;
|
||||
|
||||
/** match offsets */
|
||||
start: number[];
|
||||
|
||||
/** number of left BoundMode.Strict term boundaries found */
|
||||
interLft2: number[];
|
||||
/** number of right BoundMode.Strict term boundaries found */
|
||||
interRgt2: number[];
|
||||
/** number of left BoundMode.Loose term boundaries found */
|
||||
interLft1: number[];
|
||||
/** number of right BoundMode.Loose term boundaries found */
|
||||
interRgt1: number[];
|
||||
|
||||
/** total number of extra chars matched within all terms. higher = matched terms have more fuzz in them */
|
||||
intraIns: number[];
|
||||
/** total number of chars found in between matched terms. higher = terms are more sparse, have more fuzz in between them */
|
||||
interIns: number[];
|
||||
|
||||
/** total number of matched contiguous chars (substrs but not necessarily full terms) */
|
||||
chars: number[];
|
||||
|
||||
/** number of exactly-matched terms (intra = 0) where both lft and rgt landed on a BoundMode.Loose or BoundMode.Strict boundary */
|
||||
terms: number[];
|
||||
|
||||
/** offset ranges within match for highlighting: [startIdx0, endIdx0, startIdx1, endIdx1,...] */
|
||||
ranges: number[][];
|
||||
}
|
||||
}
|
||||
|
||||
export as namespace uFuzzy;
|
||||
@@ -17,10 +17,10 @@ self.addEventListener("install", (_event) => {
|
||||
"/scripts/options.js",
|
||||
"/scripts/chart.js",
|
||||
"/styles/chart.css",
|
||||
"/scripts/packages/lean-qr/v2.3.4/script.js",
|
||||
"/scripts/packages/lightweight-charts/v4.2.0/script.js",
|
||||
"/scripts/packages/solid-signals/2024-10-28/script.js",
|
||||
"/scripts/packages/ufuzzy/v1.0.14/script.js",
|
||||
"/packages/lean-qr/v2.3.4/script.js",
|
||||
"/packages/lightweight-charts/v4.2.0/script.js",
|
||||
"/packages/solid-signals/2024-11-01/script.js",
|
||||
"/packages/ufuzzy/v1.0.14/script.js",
|
||||
]);
|
||||
}),
|
||||
);
|
||||
|
||||
20
website/scripts/types/self.d.ts
vendored
20
website/scripts/types/self.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
Accessor,
|
||||
Setter,
|
||||
} from "../packages/solid-signals/2024-10-28/types/signals";
|
||||
} from "../../packages/solid-signals/2024-11-01/types/signals";
|
||||
import {
|
||||
DeepPartial,
|
||||
BaselineStyleOptions,
|
||||
@@ -15,9 +15,9 @@ import {
|
||||
SeriesType,
|
||||
IChartApi,
|
||||
ISeriesApi,
|
||||
} from "../packages/lightweight-charts/v4.2.0/types";
|
||||
} from "../../packages/lightweight-charts/v4.2.0/types";
|
||||
import { DatePath, HeightPath, LastPath } from "./paths";
|
||||
import { Owner } from "../packages/solid-signals/2024-10-28/types/owner";
|
||||
import { Owner } from "../../packages/solid-signals/2024-11-01/types/core/owner";
|
||||
import { AnyPossibleCohortId } from "../options";
|
||||
|
||||
type GrowToSize<T, N extends number, A extends T[]> = A["length"] extends N
|
||||
@@ -327,3 +327,17 @@ interface SeriesBlueprintParam<T> {
|
||||
singleColor?: Color;
|
||||
genPath: (id: T, scale: TimeScale) => AnyDatasetPath;
|
||||
}
|
||||
|
||||
interface RatioOption {
|
||||
scale: TimeScale;
|
||||
color: Color;
|
||||
valueDatasetPath: AnyDatasetPath;
|
||||
ratioDatasetPath: AnyDatasetPath;
|
||||
title: string;
|
||||
}
|
||||
|
||||
interface RatioOptions {
|
||||
scale: TimeScale;
|
||||
title: string;
|
||||
list: RatioOption[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user