@vx-oss/docs-story 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/css/preset.css +1 -0
- package/dist/.translations/index.d.ts +18 -0
- package/dist/.translations/keys.js +18 -0
- package/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/cache/fs.d.ts +5 -0
- package/dist/cache/fs.js +22 -0
- package/dist/cache/index.d.ts +11 -0
- package/dist/cache/index.js +15 -0
- package/dist/client/arg-form.js +357 -0
- package/dist/client/compiled.d.ts +52 -0
- package/dist/client/compiled.js +47 -0
- package/dist/client/components/input.js +13 -0
- package/dist/client/components/select.js +78 -0
- package/dist/client/with-control.d.ts +8 -0
- package/dist/client/with-control.js +104 -0
- package/dist/i18n.d.ts +6 -0
- package/dist/i18n.js +7 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +74 -0
- package/dist/next/client.d.ts +2 -0
- package/dist/next/client.js +2 -0
- package/dist/next/index.d.ts +14 -0
- package/dist/next/index.js +37 -0
- package/dist/node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js +110 -0
- package/dist/node_modules/.pnpm/@ungap_structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/deserialize.js +86 -0
- package/dist/node_modules/.pnpm/@ungap_structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/json.js +23 -0
- package/dist/node_modules/.pnpm/@ungap_structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/serialize.js +119 -0
- package/dist/node_modules/.pnpm/react-error-boundary@6.1.3_@types_react@19.2.18_react@19.2.8/node_modules/react-error-boundary/dist/react-error-boundary.js +61 -0
- package/dist/type-tree/builder.d.ts +41 -0
- package/dist/type-tree/builder.js +240 -0
- package/dist/type-tree/index.d.ts +6 -0
- package/dist/type-tree/index.js +5 -0
- package/dist/type-tree/sampler.d.ts +5 -0
- package/dist/type-tree/sampler.js +21 -0
- package/dist/type-tree/stringify.d.ts +9 -0
- package/dist/type-tree/stringify.js +20 -0
- package/dist/type-tree/types.d.ts +67 -0
- package/dist/type-tree/validator.d.ts +5 -0
- package/dist/type-tree/validator.js +21 -0
- package/dist/utils/cn.js +2 -0
- package/dist/utils/date.js +6 -0
- package/dist/utils/generate.js +24 -0
- package/dist/utils/parse.js +20 -0
- package/dist/utils/serialization.js +10 -0
- package/dist/utils/transform.js +27 -0
- package/dist/vite/client.d.ts +2 -0
- package/dist/vite/client.js +2 -0
- package/dist/vite/index.d.ts +19 -0
- package/dist/vite/index.js +25 -0
- package/dist/webpack/story.d.ts +13 -0
- package/dist/webpack/story.js +26 -0
- package/package.json +96 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../utils/cn.js";
|
|
3
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./components/select.js";
|
|
4
|
+
import { ErrorBoundary as m } from "../node_modules/.pnpm/react-error-boundary@6.1.3_@types_react@19.2.18_react@19.2.8/node_modules/react-error-boundary/dist/react-error-boundary.js";
|
|
5
|
+
import { FieldSet } from "./arg-form.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Suspense, createElement, useDeferredValue, useRef, useState } from "react";
|
|
8
|
+
import { StfProvider, useDataEngine, useListener, useStf } from "@vx-oss/docs-stf";
|
|
9
|
+
import { AlertCircle } from "lucide-react";
|
|
10
|
+
import { buttonVariants } from "@vx-oss/docs-react/components/ui/button";
|
|
11
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
12
|
+
//#region src/client/with-control.tsx
|
|
13
|
+
function WithControl({ presets, displayName, Component }) {
|
|
14
|
+
const t = useTranslations({ note: "story controls" });
|
|
15
|
+
const [variant, setVariant] = useState(presets[0].variant);
|
|
16
|
+
const preset = presets.find((preset) => preset.variant === variant);
|
|
17
|
+
const stf = useStf({ defaultValues: preset?.defaultValues });
|
|
18
|
+
return /* @__PURE__ */ jsx(StfProvider, {
|
|
19
|
+
value: stf,
|
|
20
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
21
|
+
className: "not-prose flex flex-col gap-1 p-1 border rounded-md shadow-sm bg-fd-card text-fd-card-foreground",
|
|
22
|
+
children: [
|
|
23
|
+
/* @__PURE__ */ jsxs("div", {
|
|
24
|
+
className: "flex flex-row items-center gap-2 empty:hidden",
|
|
25
|
+
children: [displayName && /* @__PURE__ */ jsx("p", {
|
|
26
|
+
className: "text-sm font-medium px-1.5",
|
|
27
|
+
children: displayName
|
|
28
|
+
}), presets.length > 1 && /* @__PURE__ */ jsxs(Select, {
|
|
29
|
+
value: variant,
|
|
30
|
+
onValueChange: (value) => {
|
|
31
|
+
if (value === null) return;
|
|
32
|
+
const preset = presets.find((preset) => preset.variant === value);
|
|
33
|
+
if (preset) {
|
|
34
|
+
setVariant(value);
|
|
35
|
+
stf.dataEngine.reset(preset.defaultValues ?? {});
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
39
|
+
variant: "ghost",
|
|
40
|
+
className: "w-fit ms-auto text-fd-muted-foreground text-xs font-medium",
|
|
41
|
+
children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("No Variant") })
|
|
42
|
+
}), /* @__PURE__ */ jsx(SelectContent, { children: presets.map((item) => /* @__PURE__ */ jsxs(SelectItem, {
|
|
43
|
+
value: item.variant,
|
|
44
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
45
|
+
className: "text-xs font-medium",
|
|
46
|
+
children: item.variant
|
|
47
|
+
}), /* @__PURE__ */ jsx("p", {
|
|
48
|
+
className: "text-xs text-fd-muted-foreground",
|
|
49
|
+
children: item.description
|
|
50
|
+
})]
|
|
51
|
+
}, item.variant)) })]
|
|
52
|
+
})]
|
|
53
|
+
}),
|
|
54
|
+
/* @__PURE__ */ jsx(StoryComponent, { Component }),
|
|
55
|
+
preset && /* @__PURE__ */ jsx(FieldSet, {
|
|
56
|
+
field: preset.controls,
|
|
57
|
+
fieldName: [],
|
|
58
|
+
name: t("Props"),
|
|
59
|
+
className: "max-h-[600px] overflow-auto"
|
|
60
|
+
})
|
|
61
|
+
]
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function StoryComponent({ Component }) {
|
|
66
|
+
const t = useTranslations({ note: "story error boundary" });
|
|
67
|
+
const engine = useDataEngine();
|
|
68
|
+
const timerRef = useRef(0);
|
|
69
|
+
const [args, setArgs] = useState(() => engine.getData());
|
|
70
|
+
const deferredArgs = useDeferredValue(args);
|
|
71
|
+
useListener({ onUpdate() {
|
|
72
|
+
if (timerRef.current) window.clearTimeout(timerRef.current);
|
|
73
|
+
timerRef.current = window.setTimeout(() => setArgs({ ...engine.getData() }), 100);
|
|
74
|
+
} });
|
|
75
|
+
return /* @__PURE__ */ jsx(m, {
|
|
76
|
+
fallbackRender: ({ error, resetErrorBoundary }) => /* @__PURE__ */ jsxs("div", {
|
|
77
|
+
className: "p-3 border rounded-lg bg-fd-card text-fd-card-foreground text-sm",
|
|
78
|
+
children: [
|
|
79
|
+
/* @__PURE__ */ jsxs("p", {
|
|
80
|
+
className: "inline-flex items-center gap-2 font-medium mb-2",
|
|
81
|
+
children: [/* @__PURE__ */ jsx(AlertCircle, { className: "text-fd-error size-4" }), t("Encountered error when rendering the component.")]
|
|
82
|
+
}),
|
|
83
|
+
/* @__PURE__ */ jsx("p", {
|
|
84
|
+
className: "text-fd-muted-foreground mb-2",
|
|
85
|
+
children: String(error)
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ jsx("button", {
|
|
88
|
+
className: cn(buttonVariants({
|
|
89
|
+
variant: "primary",
|
|
90
|
+
size: "sm"
|
|
91
|
+
})),
|
|
92
|
+
onClick: () => resetErrorBoundary(),
|
|
93
|
+
children: t("Reset")
|
|
94
|
+
})
|
|
95
|
+
]
|
|
96
|
+
}),
|
|
97
|
+
children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ createElement(Component, {
|
|
98
|
+
...deferredArgs,
|
|
99
|
+
key: void 0
|
|
100
|
+
}) })
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
export { WithControl };
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Translations } from "./.translations/index.js";
|
|
2
|
+
import { TranslationExtension } from "@vx-oss/docs-core/i18n";
|
|
3
|
+
//#region src/i18n.d.ts
|
|
4
|
+
declare function storyTranslations(): TranslationExtension<keyof Translations>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { type Translations, storyTranslations };
|
package/dist/i18n.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Cache } from "./cache/index.js";
|
|
2
|
+
import { TypeNode } from "./type-tree/types.js";
|
|
3
|
+
import { VariantInfo } from "./client/with-control.js";
|
|
4
|
+
import { createFileSystemCache } from "./cache/fs.js";
|
|
5
|
+
import { ComponentPropsWithoutRef, FC } from "react";
|
|
6
|
+
//#region src/index.d.ts
|
|
7
|
+
type Awaitable<T> = T | Promise<T>;
|
|
8
|
+
interface StoryOptions<C extends FC<any>> {
|
|
9
|
+
/**
|
|
10
|
+
* the export name of story, necessary for TypeScript Compiler.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue `story`
|
|
13
|
+
*/
|
|
14
|
+
name?: string;
|
|
15
|
+
displayName?: string;
|
|
16
|
+
Component: C;
|
|
17
|
+
/**
|
|
18
|
+
* story arguments, you can pass an array of options for multiple presets.
|
|
19
|
+
*/
|
|
20
|
+
args?: ArgsOptions<C> | (ArgsOptions<C> & VariantInfo)[];
|
|
21
|
+
}
|
|
22
|
+
interface ArgsOptions<C extends FC<any> = FC<any>> {
|
|
23
|
+
/**
|
|
24
|
+
* the default values of arguments.
|
|
25
|
+
*/
|
|
26
|
+
initial?: ComponentPropsWithoutRef<C> | (() => Awaitable<ComponentPropsWithoutRef<C>>);
|
|
27
|
+
/**
|
|
28
|
+
* fixed values for arguments, will disable the relevant controls.
|
|
29
|
+
*/
|
|
30
|
+
fixed?: Partial<ComponentPropsWithoutRef<C>> | (() => Awaitable<Partial<ComponentPropsWithoutRef<C>>>);
|
|
31
|
+
/**
|
|
32
|
+
* customize the generated controls, by default generated from component props using TypeScript compiler.
|
|
33
|
+
*/
|
|
34
|
+
controls?: {
|
|
35
|
+
node: TypeNode;
|
|
36
|
+
} | {
|
|
37
|
+
/** modify generated node */
|
|
38
|
+
transform?: (node: TypeNode) => TypeNode;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface Story<C extends FC<any> = FC<any>> {
|
|
42
|
+
/** render as a server component (require RSC). */
|
|
43
|
+
WithControl: FC;
|
|
44
|
+
_private_: {
|
|
45
|
+
component?: C;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
interface StoryFactoryOptions {
|
|
49
|
+
cache?: Cache | false;
|
|
50
|
+
tsc?: {
|
|
51
|
+
/** default to `tsconfig.json` under cwd */
|
|
52
|
+
tsconfigPath?: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface StoryFactory {
|
|
56
|
+
defineStory: <C extends FC<any>>(urlOrPath: URL | string, options: StoryOptions<C>) => Story<C>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create story under RSC environment without any build-time plugins, this requires caching to work on serverless environments.
|
|
60
|
+
*
|
|
61
|
+
* You're **highly** encouraged to use build-time plugins + clients over this.
|
|
62
|
+
*/
|
|
63
|
+
declare function defineStoryFactory(factoryOptions?: StoryFactoryOptions): StoryFactory;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ArgsOptions, type Cache, Story, StoryFactory, StoryFactoryOptions, StoryOptions, createFileSystemCache, defineStoryFactory };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { collapse } from "./type-tree/builder.js";
|
|
2
|
+
import { cached } from "./cache/index.js";
|
|
3
|
+
import { require_deepmerge } from "./node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js";
|
|
4
|
+
import { createControlsProject, generateControls } from "./utils/generate.js";
|
|
5
|
+
import { createFileSystemCache } from "./cache/fs.js";
|
|
6
|
+
import * as fs$1 from "node:fs/promises";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
//#region src/index.tsx
|
|
11
|
+
var import_deepmerge = require_deepmerge();
|
|
12
|
+
/**
|
|
13
|
+
* Create story under RSC environment without any build-time plugins, this requires caching to work on serverless environments.
|
|
14
|
+
*
|
|
15
|
+
* You're **highly** encouraged to use build-time plugins + clients over this.
|
|
16
|
+
*/
|
|
17
|
+
function defineStoryFactory(factoryOptions = {}) {
|
|
18
|
+
let _project;
|
|
19
|
+
const { cache = false } = factoryOptions;
|
|
20
|
+
const propsDeepmerge = (0, import_deepmerge.deepmerge)({ mergeArray: () => (_target, source) => source });
|
|
21
|
+
function initProject() {
|
|
22
|
+
const { tsconfigPath = "./tsconfig.json" } = factoryOptions.tsc ?? {};
|
|
23
|
+
return _project ??= createControlsProject(tsconfigPath);
|
|
24
|
+
}
|
|
25
|
+
async function generateControlsCached(filePath, name) {
|
|
26
|
+
const fileContent = await fs$1.readFile(filePath, "utf-8");
|
|
27
|
+
return cached(cache, getHash(`controls:${filePath}:${name}:${fileContent}`), async () => {
|
|
28
|
+
const project = await initProject();
|
|
29
|
+
return generateControls("@vx-oss/docs-story/next/client", project, filePath, name, fileContent);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return { defineStory(urlOrPath, { Component, name = "story", displayName, args = {} }) {
|
|
33
|
+
const filePath = urlOrPath instanceof URL || urlOrPath.startsWith("file:///") ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
34
|
+
async function getProps() {
|
|
35
|
+
const normalized = Array.isArray(args) ? args : [{
|
|
36
|
+
...args,
|
|
37
|
+
variant: "default"
|
|
38
|
+
}];
|
|
39
|
+
return {
|
|
40
|
+
Component,
|
|
41
|
+
displayName,
|
|
42
|
+
presets: await Promise.all(normalized.map(async (preset) => {
|
|
43
|
+
const fixedValues = typeof preset.fixed === "function" ? await preset.fixed() : preset.fixed;
|
|
44
|
+
const initial = typeof preset.initial === "function" ? await preset.initial() : preset.initial;
|
|
45
|
+
let controls;
|
|
46
|
+
if (preset.controls && "node" in preset.controls) controls = preset.controls.node;
|
|
47
|
+
else {
|
|
48
|
+
controls = await generateControlsCached(filePath, name);
|
|
49
|
+
if (preset.controls?.transform) controls = preset.controls.transform(controls);
|
|
50
|
+
if (fixedValues) controls = collapse(controls, fixedValues);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
variant: preset.variant,
|
|
54
|
+
description: preset.description,
|
|
55
|
+
controls,
|
|
56
|
+
defaultValues: fixedValues ? propsDeepmerge(initial, fixedValues) : initial
|
|
57
|
+
};
|
|
58
|
+
}))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
_private_: { component: Component },
|
|
63
|
+
async WithControl() {
|
|
64
|
+
const { WithControl } = await import("./client/with-control.js");
|
|
65
|
+
return /* @__PURE__ */ jsx(WithControl, { ...await getProps() });
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
} };
|
|
69
|
+
}
|
|
70
|
+
function getHash(v) {
|
|
71
|
+
return createHash("SHA-256").update(v).digest("hex").slice(0, 32);
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { createFileSystemCache, defineStoryFactory };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { StoryLoaderOptions } from "../webpack/story.js";
|
|
2
|
+
import { NextConfig } from "next";
|
|
3
|
+
//#region src/next/index.d.ts
|
|
4
|
+
interface NextStoryOptions extends StoryLoaderOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Filter story files to transform (glob)
|
|
7
|
+
*
|
|
8
|
+
* @default '*.story.{js,jsx,ts,tsx}'
|
|
9
|
+
*/
|
|
10
|
+
filter?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function createNextStory(createOptions?: NextStoryOptions): (nextConfig?: NextConfig) => NextConfig;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { NextStoryOptions, createNextStory };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/next/index.ts
|
|
2
|
+
function createNextStory(createOptions = {}) {
|
|
3
|
+
const { filter = "*.story.{js,jsx,ts,tsx}", tsconfigPath } = createOptions;
|
|
4
|
+
return (nextConfig = {}) => {
|
|
5
|
+
const loaderOptions = {};
|
|
6
|
+
if (tsconfigPath) loaderOptions.tsconfigPath = tsconfigPath;
|
|
7
|
+
const turbopack = {
|
|
8
|
+
...nextConfig.turbopack,
|
|
9
|
+
rules: {
|
|
10
|
+
...nextConfig.turbopack?.rules,
|
|
11
|
+
[filter]: { loaders: [{
|
|
12
|
+
loader: "@vx-oss/docs-story/webpack/story",
|
|
13
|
+
options: loaderOptions
|
|
14
|
+
}] }
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
...nextConfig,
|
|
19
|
+
turbopack,
|
|
20
|
+
webpack(config, options) {
|
|
21
|
+
config.module ||= {};
|
|
22
|
+
config.module.rules ||= [];
|
|
23
|
+
config.module.rules.push({
|
|
24
|
+
test: filter,
|
|
25
|
+
enforce: "pre",
|
|
26
|
+
use: [{
|
|
27
|
+
loader: "@vx-oss/docs-story/webpack/story",
|
|
28
|
+
options: loaderOptions
|
|
29
|
+
}]
|
|
30
|
+
});
|
|
31
|
+
return nextConfig.webpack?.(config, options) ?? config;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { createNextStory };
|
package/dist/node_modules/.pnpm/@fastify_deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { __commonJSMin } from "../../../../../../_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@fastify+deepmerge@3.2.1/node_modules/@fastify/deepmerge/index.js
|
|
3
|
+
var require_deepmerge = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
4
|
+
const JSON_PROTO = Object.getPrototypeOf({});
|
|
5
|
+
function defaultIsMergeableObjectFactory() {
|
|
6
|
+
return function defaultIsMergeableObject(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !(value instanceof RegExp) && !(value instanceof Date);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function deepmergeConstructor(options) {
|
|
11
|
+
function isNotPrototypeKey(value) {
|
|
12
|
+
return value !== "constructor" && value !== "prototype" && value !== "__proto__";
|
|
13
|
+
}
|
|
14
|
+
function cloneArray(value) {
|
|
15
|
+
let i = 0;
|
|
16
|
+
const il = value.length;
|
|
17
|
+
const result = new Array(il);
|
|
18
|
+
for (; i < il; ++i) result[i] = clone(value[i]);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function cloneObject(target) {
|
|
22
|
+
const result = {};
|
|
23
|
+
if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) return cloneProtoObject(target);
|
|
24
|
+
const targetKeys = getKeys(target);
|
|
25
|
+
let i, il, key;
|
|
26
|
+
for (i = 0, il = targetKeys.length; i < il; ++i) isNotPrototypeKey(key = targetKeys[i]) && (result[key] = clone(target[key]));
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
function concatArrays(target, source) {
|
|
30
|
+
const tl = target.length;
|
|
31
|
+
const sl = source.length;
|
|
32
|
+
let i = 0;
|
|
33
|
+
const result = new Array(tl + sl);
|
|
34
|
+
for (; i < tl; ++i) result[i] = clone(target[i]);
|
|
35
|
+
for (i = 0; i < sl; ++i) result[i + tl] = clone(source[i]);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
|
|
39
|
+
function getSymbolsAndKeys(value) {
|
|
40
|
+
const result = Object.keys(value);
|
|
41
|
+
const keys = Object.getOwnPropertySymbols(value);
|
|
42
|
+
for (let i = 0, il = keys.length; i < il; ++i) propertyIsEnumerable.call(value, keys[i]) && result.push(keys[i]);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
const getKeys = options?.symbols ? getSymbolsAndKeys : Object.keys;
|
|
46
|
+
const cloneProtoObject = typeof options?.cloneProtoObject === "function" ? options.cloneProtoObject : void 0;
|
|
47
|
+
const isMergeableObject = typeof options?.isMergeableObject === "function" ? options.isMergeableObject : defaultIsMergeableObjectFactory();
|
|
48
|
+
const onlyDefinedProperties = options?.onlyDefinedProperties === true;
|
|
49
|
+
function isPrimitive(value) {
|
|
50
|
+
return typeof value !== "object" || value === null;
|
|
51
|
+
}
|
|
52
|
+
const mergeArray = options && typeof options.mergeArray === "function" ? options.mergeArray({
|
|
53
|
+
clone,
|
|
54
|
+
deepmerge: _deepmerge,
|
|
55
|
+
getKeys,
|
|
56
|
+
isMergeableObject
|
|
57
|
+
}) : concatArrays;
|
|
58
|
+
function clone(entry) {
|
|
59
|
+
return isMergeableObject(entry) ? Array.isArray(entry) ? cloneArray(entry) : cloneObject(entry) : entry;
|
|
60
|
+
}
|
|
61
|
+
function mergeObject(target, source) {
|
|
62
|
+
const result = {};
|
|
63
|
+
const targetKeys = getKeys(target);
|
|
64
|
+
const sourceKeys = getKeys(source);
|
|
65
|
+
let i, il, key;
|
|
66
|
+
for (i = 0, il = targetKeys.length; i < il; ++i) isNotPrototypeKey(key = targetKeys[i]) && sourceKeys.indexOf(key) === -1 && (result[key] = clone(target[key]));
|
|
67
|
+
for (i = 0, il = sourceKeys.length; i < il; ++i) {
|
|
68
|
+
if (!isNotPrototypeKey(key = sourceKeys[i])) continue;
|
|
69
|
+
if (key in target) {
|
|
70
|
+
if (targetKeys.indexOf(key) !== -1) {
|
|
71
|
+
if (cloneProtoObject && isMergeableObject(source[key]) && Object.getPrototypeOf(source[key]) !== JSON_PROTO) result[key] = cloneProtoObject(source[key]);
|
|
72
|
+
else result[key] = _deepmerge(target[key], source[key]);
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
if (onlyDefinedProperties && typeof source[key] === "undefined") continue;
|
|
76
|
+
result[key] = clone(source[key]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
function _deepmerge(target, source) {
|
|
82
|
+
if (onlyDefinedProperties && typeof source === "undefined") return clone(target);
|
|
83
|
+
const sourceIsArray = Array.isArray(source);
|
|
84
|
+
const targetIsArray = Array.isArray(target);
|
|
85
|
+
if (isPrimitive(source)) return source;
|
|
86
|
+
else if (!isMergeableObject(target)) return clone(source);
|
|
87
|
+
else if (sourceIsArray && targetIsArray) return mergeArray(target, source);
|
|
88
|
+
else if (sourceIsArray !== targetIsArray) return clone(source);
|
|
89
|
+
else return mergeObject(target, source);
|
|
90
|
+
}
|
|
91
|
+
function _deepmergeAll() {
|
|
92
|
+
switch (arguments.length) {
|
|
93
|
+
case 0: return {};
|
|
94
|
+
case 1: return clone(arguments[0]);
|
|
95
|
+
case 2: return _deepmerge(arguments[0], arguments[1]);
|
|
96
|
+
}
|
|
97
|
+
let result;
|
|
98
|
+
for (let i = 0, il = arguments.length; i < il; ++i) result = _deepmerge(result, arguments[i]);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
return options?.all ? _deepmergeAll : _deepmerge;
|
|
102
|
+
}
|
|
103
|
+
module.exports = deepmergeConstructor;
|
|
104
|
+
module.exports.default = deepmergeConstructor;
|
|
105
|
+
module.exports.deepmerge = deepmergeConstructor;
|
|
106
|
+
Object.defineProperty(module.exports, "isMergeableObject", { get: defaultIsMergeableObjectFactory });
|
|
107
|
+
}));
|
|
108
|
+
//#endregion
|
|
109
|
+
export default require_deepmerge();
|
|
110
|
+
export { require_deepmerge };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/deserialize.js
|
|
2
|
+
const { defineProperty } = Object;
|
|
3
|
+
const env = typeof self === "object" ? self : globalThis;
|
|
4
|
+
const guard = (name, init) => {
|
|
5
|
+
switch (name) {
|
|
6
|
+
case "Function":
|
|
7
|
+
case "SharedWorker":
|
|
8
|
+
case "Worker":
|
|
9
|
+
case "eval":
|
|
10
|
+
case "setInterval":
|
|
11
|
+
case "setTimeout": throw new TypeError("unable to deserialize " + name);
|
|
12
|
+
}
|
|
13
|
+
return new env[name](init);
|
|
14
|
+
};
|
|
15
|
+
const deserializer = ($, _) => {
|
|
16
|
+
const as = (out, index) => {
|
|
17
|
+
$.set(index, out);
|
|
18
|
+
return out;
|
|
19
|
+
};
|
|
20
|
+
const unpair = (index) => {
|
|
21
|
+
if ($.has(index)) return $.get(index);
|
|
22
|
+
const [type, value] = _[index];
|
|
23
|
+
switch (type) {
|
|
24
|
+
case 0:
|
|
25
|
+
case -1: return as(value, index);
|
|
26
|
+
case 1: {
|
|
27
|
+
const arr = as([], index);
|
|
28
|
+
for (const index of value) arr.push(unpair(index));
|
|
29
|
+
return arr;
|
|
30
|
+
}
|
|
31
|
+
case 2: {
|
|
32
|
+
const object = as({}, index);
|
|
33
|
+
for (const [key, index] of value) {
|
|
34
|
+
const k = unpair(key), value = unpair(index);
|
|
35
|
+
if (k === "__proto__") defineProperty(object, k, {
|
|
36
|
+
value,
|
|
37
|
+
configurable: true,
|
|
38
|
+
enumerable: true,
|
|
39
|
+
writable: true
|
|
40
|
+
});
|
|
41
|
+
else object[k] = value;
|
|
42
|
+
}
|
|
43
|
+
return object;
|
|
44
|
+
}
|
|
45
|
+
case 3: return as(new Date(value), index);
|
|
46
|
+
case 4: {
|
|
47
|
+
const { source, flags } = value;
|
|
48
|
+
return as(new RegExp(source, flags), index);
|
|
49
|
+
}
|
|
50
|
+
case 5: {
|
|
51
|
+
const map = as(/* @__PURE__ */ new Map(), index);
|
|
52
|
+
for (const [key, index] of value) map.set(unpair(key), unpair(index));
|
|
53
|
+
return map;
|
|
54
|
+
}
|
|
55
|
+
case 6: {
|
|
56
|
+
const set = as(/* @__PURE__ */ new Set(), index);
|
|
57
|
+
for (const index of value) set.add(unpair(index));
|
|
58
|
+
return set;
|
|
59
|
+
}
|
|
60
|
+
case 7: {
|
|
61
|
+
const { name, message } = value;
|
|
62
|
+
return as(typeof env[name] === "function" ? guard(name, message) : new Error(message), index);
|
|
63
|
+
}
|
|
64
|
+
case 8: return as(BigInt(value), index);
|
|
65
|
+
case "BigInt": return as(Object(BigInt(value)), index);
|
|
66
|
+
case "ArrayBuffer": return as(new Uint8Array(value).buffer, value);
|
|
67
|
+
case "DataView": {
|
|
68
|
+
const { buffer } = new Uint8Array(value);
|
|
69
|
+
return as(new DataView(buffer), value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return as(guard(type, value), index);
|
|
73
|
+
};
|
|
74
|
+
return unpair;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @typedef {Array<string,any>} Record a type representation
|
|
78
|
+
*/
|
|
79
|
+
/**
|
|
80
|
+
* Returns a deserialized value from a serialized array of Records.
|
|
81
|
+
* @param {Record[]} serialized a previously serialized value.
|
|
82
|
+
* @returns {any}
|
|
83
|
+
*/
|
|
84
|
+
const deserialize = (serialized) => deserializer(/* @__PURE__ */ new Map(), serialized)(0);
|
|
85
|
+
//#endregion
|
|
86
|
+
export { deserialize };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { deserialize } from "./deserialize.js";
|
|
2
|
+
import { serialize } from "./serialize.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/json.js
|
|
4
|
+
/*! (c) Andrea Giammarchi - ISC */
|
|
5
|
+
const { parse: $parse, stringify: $stringify } = JSON;
|
|
6
|
+
const options = {
|
|
7
|
+
json: true,
|
|
8
|
+
lossy: true
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Revive a previously stringified structured clone.
|
|
12
|
+
* @param {string} str previously stringified data as string.
|
|
13
|
+
* @returns {any} whatever was previously stringified as clone.
|
|
14
|
+
*/
|
|
15
|
+
const parse = (str) => deserialize($parse(str));
|
|
16
|
+
/**
|
|
17
|
+
* Represent a structured clone value as string.
|
|
18
|
+
* @param {any} any some clone-able value to stringify.
|
|
19
|
+
* @returns {string} the value stringified.
|
|
20
|
+
*/
|
|
21
|
+
const stringify = (any) => $stringify(serialize(any, options));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { parse, stringify };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/@ungap+structured-clone@1.3.4/node_modules/@ungap/structured-clone/esm/serialize.js
|
|
2
|
+
const EMPTY = "";
|
|
3
|
+
const { toString } = {};
|
|
4
|
+
const { keys } = Object;
|
|
5
|
+
const typeOf = (value) => {
|
|
6
|
+
const type = typeof value;
|
|
7
|
+
if (type !== "object" || !value) return [0, type];
|
|
8
|
+
const asString = toString.call(value).slice(8, -1);
|
|
9
|
+
switch (asString) {
|
|
10
|
+
case "Array": return [1, EMPTY];
|
|
11
|
+
case "Object": return [2, EMPTY];
|
|
12
|
+
case "Date": return [3, EMPTY];
|
|
13
|
+
case "RegExp": return [4, EMPTY];
|
|
14
|
+
case "Map": return [5, EMPTY];
|
|
15
|
+
case "Set": return [6, EMPTY];
|
|
16
|
+
case "DataView": return [1, asString];
|
|
17
|
+
}
|
|
18
|
+
if (asString.includes("Array")) return [1, asString];
|
|
19
|
+
if (value instanceof Error) return [7, value.name || "Error"];
|
|
20
|
+
return [2, asString];
|
|
21
|
+
};
|
|
22
|
+
const shouldSkip = ([TYPE, type]) => TYPE === 0 && (type === "function" || type === "symbol");
|
|
23
|
+
const serializer = (strict, json, $, _) => {
|
|
24
|
+
const as = (out, value) => {
|
|
25
|
+
const index = _.push(out) - 1;
|
|
26
|
+
$.set(value, index);
|
|
27
|
+
return index;
|
|
28
|
+
};
|
|
29
|
+
const pair = (value) => {
|
|
30
|
+
if ($.has(value)) return $.get(value);
|
|
31
|
+
let [TYPE, type] = typeOf(value);
|
|
32
|
+
switch (TYPE) {
|
|
33
|
+
case 0: {
|
|
34
|
+
let entry = value;
|
|
35
|
+
switch (type) {
|
|
36
|
+
case "bigint":
|
|
37
|
+
TYPE = 8;
|
|
38
|
+
entry = value.toString();
|
|
39
|
+
break;
|
|
40
|
+
case "function":
|
|
41
|
+
case "symbol":
|
|
42
|
+
if (strict) throw new TypeError("unable to serialize " + type);
|
|
43
|
+
entry = null;
|
|
44
|
+
break;
|
|
45
|
+
case "undefined": return as([-1], value);
|
|
46
|
+
}
|
|
47
|
+
return as([TYPE, entry], value);
|
|
48
|
+
}
|
|
49
|
+
case 1: {
|
|
50
|
+
if (type) {
|
|
51
|
+
let spread = value;
|
|
52
|
+
if (type === "DataView") spread = new Uint8Array(value.buffer);
|
|
53
|
+
else if (type === "ArrayBuffer") spread = new Uint8Array(value);
|
|
54
|
+
return as([type, [...spread]], value);
|
|
55
|
+
}
|
|
56
|
+
const arr = [];
|
|
57
|
+
const index = as([TYPE, arr], value);
|
|
58
|
+
for (const entry of value) arr.push(pair(entry));
|
|
59
|
+
return index;
|
|
60
|
+
}
|
|
61
|
+
case 2: {
|
|
62
|
+
if (type) switch (type) {
|
|
63
|
+
case "BigInt": return as([type, value.toString()], value);
|
|
64
|
+
case "Boolean":
|
|
65
|
+
case "Number":
|
|
66
|
+
case "String": return as([type, value.valueOf()], value);
|
|
67
|
+
}
|
|
68
|
+
if (json && "toJSON" in value) return pair(value.toJSON());
|
|
69
|
+
const entries = [];
|
|
70
|
+
const index = as([TYPE, entries], value);
|
|
71
|
+
for (const key of keys(value)) if (strict || !shouldSkip(typeOf(value[key]))) entries.push([pair(key), pair(value[key])]);
|
|
72
|
+
return index;
|
|
73
|
+
}
|
|
74
|
+
case 3: return as([TYPE, isNaN(value.getTime()) ? EMPTY : value.toISOString()], value);
|
|
75
|
+
case 4: {
|
|
76
|
+
const { source, flags } = value;
|
|
77
|
+
return as([TYPE, {
|
|
78
|
+
source,
|
|
79
|
+
flags
|
|
80
|
+
}], value);
|
|
81
|
+
}
|
|
82
|
+
case 5: {
|
|
83
|
+
const entries = [];
|
|
84
|
+
const index = as([TYPE, entries], value);
|
|
85
|
+
for (const [key, entry] of value) if (strict || !(shouldSkip(typeOf(key)) || shouldSkip(typeOf(entry)))) entries.push([pair(key), pair(entry)]);
|
|
86
|
+
return index;
|
|
87
|
+
}
|
|
88
|
+
case 6: {
|
|
89
|
+
const entries = [];
|
|
90
|
+
const index = as([TYPE, entries], value);
|
|
91
|
+
for (const entry of value) if (strict || !shouldSkip(typeOf(entry))) entries.push(pair(entry));
|
|
92
|
+
return index;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const { message } = value;
|
|
96
|
+
return as([TYPE, {
|
|
97
|
+
name: type,
|
|
98
|
+
message
|
|
99
|
+
}], value);
|
|
100
|
+
};
|
|
101
|
+
return pair;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {Array<string,any>} Record a type representation
|
|
105
|
+
*/
|
|
106
|
+
/**
|
|
107
|
+
* Returns an array of serialized Records.
|
|
108
|
+
* @param {any} value a serializable value.
|
|
109
|
+
* @param {{json?: boolean, lossy?: boolean}?} options an object with a `lossy` or `json` property that,
|
|
110
|
+
* if `true`, will not throw errors on incompatible types, and behave more
|
|
111
|
+
* like JSON stringify would behave. Symbol and Function will be discarded.
|
|
112
|
+
* @returns {Record[]}
|
|
113
|
+
*/
|
|
114
|
+
const serialize = (value, { json, lossy } = {}) => {
|
|
115
|
+
const _ = [];
|
|
116
|
+
return serializer(!(json || lossy), !!json, /* @__PURE__ */ new Map(), _)(value), _;
|
|
117
|
+
};
|
|
118
|
+
//#endregion
|
|
119
|
+
export { serialize };
|