@parity-app/cli 0.7.6 → 0.8.0
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/dist/bin.mjs +7 -7
- package/dist/{client-BkLeG26A.mjs → client-CkT-5H3_.mjs} +7 -1
- package/dist/index.mjs +1 -1
- package/dist/{published-BtL8RM6W.mjs → published-B0sNR0jd.mjs} +1 -1
- package/dist/{published-CdXoUgfD.mjs → published-DYY8_8m9.mjs} +54 -16
- package/dist/src-C4S96XEj.mjs +5 -0
- package/dist/{src-BZFjMWhp.mjs → src-Ck9A-Gxr.mjs} +306 -149
- package/dist/{src-CMPL5C8p.mjs → src-XUZS4M-k.mjs} +179 -136
- package/dist/{src-DHuMBGiB.mjs → src-ZsXhzNYa.mjs} +1 -1
- package/dist/{src-CdMzjFSa.mjs → src-gCnKQqH5.mjs} +1 -1
- package/package.json +1 -1
- package/skills/execute.md +9 -0
- package/dist/src-CbLrA8BA.mjs +0 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as fileObject, o as parseData, r as finiteNumber, s as plainObject } from "./schema-Dp5Jhloe.mjs";
|
|
1
|
+
import { i as jsonText, n as fileObject, o as parseData, r as finiteNumber, s as plainObject } from "./schema-Dp5Jhloe.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
// ../core/src/adapters.ts
|
|
4
4
|
const packageVersions = z.record(z.string(), z.string());
|
|
@@ -18,6 +18,7 @@ const packageManifest = z.looseObject({
|
|
|
18
18
|
version: z.string().optional(),
|
|
19
19
|
dependencies: packageVersions.optional(),
|
|
20
20
|
devDependencies: packageVersions.optional(),
|
|
21
|
+
optionalDependencies: packageVersions.optional(),
|
|
21
22
|
scripts: z.record(z.string(), z.string()).optional(),
|
|
22
23
|
/** Entry points by subpath (`.`, `./tailwind.css`), or where the package's one entry point leads. */
|
|
23
24
|
exports: exportsTarget.optional(),
|
|
@@ -28,8 +29,28 @@ const packageManifest = z.looseObject({
|
|
|
28
29
|
/** The stylesheet a project imports to use the package, as some packages name it. */
|
|
29
30
|
style: z.string().optional(),
|
|
30
31
|
/** A workspace root's package folders, as npm, Yarn and Bun write them. */
|
|
31
|
-
workspaces: z.union([z.array(z.string()), z.looseObject({ packages: z.array(z.string()).optional() })]).optional()
|
|
32
|
+
workspaces: z.union([z.array(z.string()), z.looseObject({ packages: z.array(z.string()).optional() })]).optional(),
|
|
33
|
+
/** The command line it installs: one file named after the package, or files by command name. */
|
|
34
|
+
bin: z.union([z.string(), z.record(z.string(), z.string())]).optional(),
|
|
35
|
+
/** Where its source is, which libgen reads examples from. */
|
|
36
|
+
repository: z.union([z.string(), z.looseObject({
|
|
37
|
+
url: z.string().optional(),
|
|
38
|
+
directory: z.string().optional()
|
|
39
|
+
})]).optional(),
|
|
40
|
+
/** The package manager and version a project asks for, as Corepack writes it (`pnpm@10.4.0`). */
|
|
41
|
+
packageManager: z.string().optional()
|
|
32
42
|
});
|
|
43
|
+
/**
|
|
44
|
+
* A package.json's text, read through {@link packageManifest}. Throws `TypeError` naming the file and the field at
|
|
45
|
+
* fault, as in `/app/package.json: /scripts/dev: expected a string`, or `/: expected JSON`.
|
|
46
|
+
*/
|
|
47
|
+
function parseManifest(text, file) {
|
|
48
|
+
try {
|
|
49
|
+
return parseData(jsonText(packageManifest), text);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw new TypeError(`${file}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
33
54
|
// ../core/src/devices.ts
|
|
34
55
|
const deviceKinds = [
|
|
35
56
|
"phone",
|
|
@@ -505,18 +526,20 @@ const componentNode$1 = nodeBase.extend({
|
|
|
505
526
|
return z.record(z.string(), z.array(designNode)).optional();
|
|
506
527
|
}
|
|
507
528
|
});
|
|
529
|
+
/** The elements a text node can be. */
|
|
530
|
+
const textTags = [
|
|
531
|
+
"p",
|
|
532
|
+
"span",
|
|
533
|
+
"h1",
|
|
534
|
+
"h2",
|
|
535
|
+
"h3",
|
|
536
|
+
"h4",
|
|
537
|
+
"strong"
|
|
538
|
+
];
|
|
508
539
|
const textNode = nodeBase.extend({
|
|
509
540
|
type: z.literal("text"),
|
|
510
541
|
text: z.string(),
|
|
511
|
-
tag: z.enum(
|
|
512
|
-
"p",
|
|
513
|
-
"span",
|
|
514
|
-
"h1",
|
|
515
|
-
"h2",
|
|
516
|
-
"h3",
|
|
517
|
-
"h4",
|
|
518
|
-
"strong"
|
|
519
|
-
]).optional()
|
|
542
|
+
tag: z.enum(textTags).optional()
|
|
520
543
|
});
|
|
521
544
|
const instanceNode = nodeBase.extend({
|
|
522
545
|
type: z.literal("instance"),
|
|
@@ -753,6 +776,269 @@ const canvasDocument = fileObject({
|
|
|
753
776
|
/** The source each lens reads, where the person switched from the one Parity picked. */
|
|
754
777
|
sources: lensSources.optional()
|
|
755
778
|
});
|
|
779
|
+
// ../core/src/values/evaluate.ts
|
|
780
|
+
/** The keys that mark an object as one of the value forms rather than plain JSON. */
|
|
781
|
+
const valueForms = [
|
|
782
|
+
"$import",
|
|
783
|
+
"$call",
|
|
784
|
+
"$global",
|
|
785
|
+
"$frame",
|
|
786
|
+
"$function"
|
|
787
|
+
];
|
|
788
|
+
/** The parts of a frame a `$frame` value can name. */
|
|
789
|
+
const frameParts = [
|
|
790
|
+
"root",
|
|
791
|
+
"host",
|
|
792
|
+
"body",
|
|
793
|
+
"document",
|
|
794
|
+
"dir",
|
|
795
|
+
"lang",
|
|
796
|
+
"selector"
|
|
797
|
+
];
|
|
798
|
+
/** Whether a sample's prop value is elements. */
|
|
799
|
+
function isSampleElement(value) {
|
|
800
|
+
return typeof value === "object" && value !== null && Array.isArray(value.$element);
|
|
801
|
+
}
|
|
802
|
+
/** Whether a value is one the package makes. */
|
|
803
|
+
function isMadeValue(value) {
|
|
804
|
+
const call = typeof value === "object" && value !== null ? value.$call : void 0;
|
|
805
|
+
return typeof call === "object" && call !== null && typeof call.import === "string";
|
|
806
|
+
}
|
|
807
|
+
/** Whether a sample's child or prop value is a render function. */
|
|
808
|
+
function isSampleRender(value) {
|
|
809
|
+
return typeof value === "object" && value !== null && Array.isArray(value.$render);
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* A value worked out against a host: plain JSON as written, and its kind's forms made. A `$import` without an `export`
|
|
813
|
+
* is the module's default export. A `$call` calls its function with its `args`, then the `methods` in order on what it
|
|
814
|
+
* returned, wherever the call is; a method that's missing or throws is passed over, as the made value is still usable.
|
|
815
|
+
* Arrays and objects with no form inside them come back as they were, so a prop keeps its identity between draws.
|
|
816
|
+
*/
|
|
817
|
+
function evaluateValue(value, host, kind = "decorator") {
|
|
818
|
+
const evaluate = (item) => evaluateValue(item, host, kind);
|
|
819
|
+
if (Array.isArray(value)) {
|
|
820
|
+
const items = value.map(evaluate);
|
|
821
|
+
return items.every((item, index) => item === value[index]) ? value : items;
|
|
822
|
+
}
|
|
823
|
+
if (typeof value !== "object" || value === null) return value;
|
|
824
|
+
const record = value;
|
|
825
|
+
if (isMadeValue(record)) return made$1(record, host, kind);
|
|
826
|
+
if (kind === "sample") return evaluateEntries(record, evaluate);
|
|
827
|
+
if (typeof record.$import === "string") {
|
|
828
|
+
const imported = record;
|
|
829
|
+
return host.exported(imported.$import, imported.export ?? "default");
|
|
830
|
+
}
|
|
831
|
+
if (typeof record.$global === "string") {
|
|
832
|
+
const global = record;
|
|
833
|
+
const chosen = host.global(global.$global);
|
|
834
|
+
const values = global.values ?? {};
|
|
835
|
+
return evaluate(chosen !== void 0 && Object.hasOwn(values, chosen) ? values[chosen] : global.default);
|
|
836
|
+
}
|
|
837
|
+
if (typeof record.$frame === "string") return host.frame(record.$frame);
|
|
838
|
+
if ("$function" in record) return () => evaluate(record.$function);
|
|
839
|
+
return evaluateEntries(record, evaluate);
|
|
840
|
+
}
|
|
841
|
+
/** Plain JSON's entries worked out, or the object as it was when none of them changed. */
|
|
842
|
+
function evaluateEntries(record, evaluate) {
|
|
843
|
+
let changed = false;
|
|
844
|
+
const entries = Object.entries(record).map(([key, item]) => {
|
|
845
|
+
const evaluated = evaluate(item);
|
|
846
|
+
if (evaluated !== item) changed = true;
|
|
847
|
+
return [key, evaluated];
|
|
848
|
+
});
|
|
849
|
+
return changed ? Object.fromEntries(entries) : record;
|
|
850
|
+
}
|
|
851
|
+
function made$1(value, host, kind) {
|
|
852
|
+
const key = JSON.stringify(value);
|
|
853
|
+
if (host.made.has(key)) return host.made.get(key);
|
|
854
|
+
const { import: specifier, export: name } = value.$call;
|
|
855
|
+
const fn = host.exported(specifier, name);
|
|
856
|
+
if (typeof fn !== "function") throw new Error(`${specifier} has no function ${name}`);
|
|
857
|
+
const result = fn(...(value.args ?? []).map((arg) => evaluateValue(arg, host, kind)));
|
|
858
|
+
for (const step of value.methods ?? []) {
|
|
859
|
+
const method = result?.[step.method];
|
|
860
|
+
if (typeof method !== "function") continue;
|
|
861
|
+
try {
|
|
862
|
+
method.apply(result, (step.args ?? []).map((arg) => evaluateValue(arg, host, kind)));
|
|
863
|
+
} catch {}
|
|
864
|
+
}
|
|
865
|
+
host.made.set(key, result);
|
|
866
|
+
return result;
|
|
867
|
+
}
|
|
868
|
+
/** The modules a value imports from, each once, in the order they first appear. Plain JSON imports none. */
|
|
869
|
+
function valueImports(value, kind = "decorator") {
|
|
870
|
+
const found = /* @__PURE__ */ new Set();
|
|
871
|
+
const visit = (item) => {
|
|
872
|
+
if (Array.isArray(item)) return item.forEach(visit);
|
|
873
|
+
if (typeof item !== "object" || item === null) return;
|
|
874
|
+
const record = item;
|
|
875
|
+
if (kind === "decorator" && typeof record.$import === "string") {
|
|
876
|
+
found.add(record.$import);
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
if (isMadeValue(record)) {
|
|
880
|
+
found.add(record.$call.import);
|
|
881
|
+
record.args?.forEach(visit);
|
|
882
|
+
for (const step of record.methods ?? []) step.args?.forEach(visit);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
if (kind === "decorator" && typeof record.$frame === "string") return;
|
|
886
|
+
Object.values(record).forEach(visit);
|
|
887
|
+
};
|
|
888
|
+
visit(value);
|
|
889
|
+
return [...found];
|
|
890
|
+
}
|
|
891
|
+
/** An export of a module, following dots into namespaces (`Tooltip.Provider`). */
|
|
892
|
+
function exportOf(module, path) {
|
|
893
|
+
let found = module;
|
|
894
|
+
for (const part of path.split(".")) found = found?.[part];
|
|
895
|
+
return found;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Where a part's sample calls what's inside it: its function children, else a render prop (Chakra's `TreeView.Node`
|
|
899
|
+
* `render`), with the render function.
|
|
900
|
+
*/
|
|
901
|
+
function renderSlotOf(sample) {
|
|
902
|
+
const children = sample?.children?.find(isSampleRender);
|
|
903
|
+
if (children) return {
|
|
904
|
+
prop: "children",
|
|
905
|
+
render: children
|
|
906
|
+
};
|
|
907
|
+
const entry = Object.entries(sample?.props ?? {}).find(([, value]) => isSampleRender(value));
|
|
908
|
+
return entry ? {
|
|
909
|
+
prop: entry[0],
|
|
910
|
+
render: entry[1]
|
|
911
|
+
} : void 0;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* The key a component node keeps a render function's nodes under (`renderInput`, function children): `$render:` and the
|
|
915
|
+
* prop, `$renderWith:` when what it's called with is spread onto them, and `?pass=a,b` for the props that take it.
|
|
916
|
+
*/
|
|
917
|
+
function renderSlotKey(prop, render) {
|
|
918
|
+
const pass = render.pass ? `?pass=${render.pass.join(",")}` : "";
|
|
919
|
+
return `${render.spread ? "$renderWith" : "$render"}:${prop}${pass}`;
|
|
920
|
+
}
|
|
921
|
+
/** A slot key `renderSlotKey` wrote, read back; `undefined` for a slot of plain nodes. */
|
|
922
|
+
function readRenderSlotKey(key) {
|
|
923
|
+
const match = /^\$render(With)?:([^?]+)(?:\?pass=(.+))?$/.exec(key);
|
|
924
|
+
if (!match) return void 0;
|
|
925
|
+
const [, spread, prop, pass] = match;
|
|
926
|
+
return {
|
|
927
|
+
prop,
|
|
928
|
+
spread: spread !== void 0,
|
|
929
|
+
...pass ? { pass: pass.split(",") } : {}
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
// ../core/src/values/grammar.ts
|
|
933
|
+
const primitives = [
|
|
934
|
+
z.string(),
|
|
935
|
+
finiteNumber,
|
|
936
|
+
z.boolean(),
|
|
937
|
+
z.null()
|
|
938
|
+
];
|
|
939
|
+
/**
|
|
940
|
+
* A decorator's or sample's value: JSON, or one of five forms that `evaluateValue` works out against a host, the frame
|
|
941
|
+
* in the guest and a trial outside one in libgen. An object with one of the forms' keys must be that form; any other
|
|
942
|
+
* object is plain JSON, its values values too.
|
|
943
|
+
*
|
|
944
|
+
* - `{ "$import": "pkg", "export": "name" }`: something the package exports, such as a theme object. `export` defaults
|
|
945
|
+
* to `default`, the default export.
|
|
946
|
+
* - `{ "$call": { "import": "pkg", "export": "name" }, "args": [...], "methods": [...] }`: what calling it returns,
|
|
947
|
+
* after calling `methods` on it in order.
|
|
948
|
+
* - `{ "$global": "theme", "values": { "dark": ... }, "default": ... }`: picked by the frame's global, which is the
|
|
949
|
+
* mode's option for that variable.
|
|
950
|
+
* - `{ "$frame": "root" | "host" | "body" }`: the frame's shadow root, the element it hangs from (which `:root[...]`
|
|
951
|
+
* rules match, as `:host(...)`), or the element standing in for its `<body>`. Also `document`, `dir`, `lang`, and
|
|
952
|
+
* `selector`, a CSS selector for the body alone.
|
|
953
|
+
* - `{ "$function": ... }`: a function returning the value it holds.
|
|
954
|
+
*
|
|
955
|
+
* Values are checked once, when their library file loads. The guest evaluates them on every frame without zod. A
|
|
956
|
+
* sample's values are `sampleValue`s.
|
|
957
|
+
*/
|
|
958
|
+
const decoratorValue = z.lazy(() => z.union([
|
|
959
|
+
...primitives,
|
|
960
|
+
z.array(decoratorValue),
|
|
961
|
+
form("$import", importedValue),
|
|
962
|
+
form("$call", madeValue),
|
|
963
|
+
form("$global", globalValue),
|
|
964
|
+
form("$frame", frameValue),
|
|
965
|
+
form("$function", functionValue),
|
|
966
|
+
plain(valueForms, decoratorValue)
|
|
967
|
+
]));
|
|
968
|
+
/**
|
|
969
|
+
* A sample's value, which a design node's props copy: JSON, and values the package makes (`$call`), as an example
|
|
970
|
+
* passes them. The other forms are a decorator's alone, so in a sample an object with their keys is data as written.
|
|
971
|
+
*/
|
|
972
|
+
const sampleValue = z.lazy(() => z.union([
|
|
973
|
+
...primitives,
|
|
974
|
+
z.array(sampleValue),
|
|
975
|
+
form("$call", made(sampleValue)),
|
|
976
|
+
plain(["$call"], sampleValue)
|
|
977
|
+
]));
|
|
978
|
+
/** Something the package exports, such as a theme object. */
|
|
979
|
+
const importedValue = fileObject({
|
|
980
|
+
$import: z.string(),
|
|
981
|
+
export: z.string().optional()
|
|
982
|
+
});
|
|
983
|
+
/**
|
|
984
|
+
* A value the package makes by calling one of its own functions, as an example does (Chakra's
|
|
985
|
+
* `collection={createTreeCollection({ rootNode })}`): the canvas calls it with `args`, once per frame.
|
|
986
|
+
*/
|
|
987
|
+
function made(value) {
|
|
988
|
+
return fileObject({
|
|
989
|
+
$call: fileObject({
|
|
990
|
+
import: z.string(),
|
|
991
|
+
export: z.string()
|
|
992
|
+
}),
|
|
993
|
+
args: z.array(value).optional(),
|
|
994
|
+
/**
|
|
995
|
+
* Methods called on what it makes, in order, as the examples call them (Chakra's `toaster.create({ title })`), so
|
|
996
|
+
* a toaster is drawn with a toast in it.
|
|
997
|
+
*/
|
|
998
|
+
methods: z.array(fileObject({
|
|
999
|
+
method: z.string(),
|
|
1000
|
+
args: z.array(value).optional()
|
|
1001
|
+
})).optional()
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
const madeValue = made(decoratorValue);
|
|
1005
|
+
/** Picked by the frame's global, which is the mode's option for that variable, else `default`. */
|
|
1006
|
+
const globalValue = fileObject({
|
|
1007
|
+
$global: z.string(),
|
|
1008
|
+
values: z.record(z.string(), decoratorValue),
|
|
1009
|
+
default: decoratorValue.optional()
|
|
1010
|
+
});
|
|
1011
|
+
/** Part of the frame itself. */
|
|
1012
|
+
const frameValue = fileObject({ $frame: z.enum(frameParts) });
|
|
1013
|
+
/** A function returning the value it holds. */
|
|
1014
|
+
const functionValue = fileObject({ $function: decoratorValue });
|
|
1015
|
+
/**
|
|
1016
|
+
* An object with a form's key is that form. Any other object is refused as another type of value would be, which
|
|
1017
|
+
* `parseData` passes over, so a broken form reports its own mistake and not the closest of the other forms.
|
|
1018
|
+
*/
|
|
1019
|
+
function form(key, schema) {
|
|
1020
|
+
return z.unknown().superRefine((value, context) => {
|
|
1021
|
+
if (!(typeof value === "object" && value !== null && key in value)) context.addIssue({
|
|
1022
|
+
code: "invalid_type",
|
|
1023
|
+
expected: "object",
|
|
1024
|
+
input: value
|
|
1025
|
+
});
|
|
1026
|
+
}).pipe(schema);
|
|
1027
|
+
}
|
|
1028
|
+
/** Plain JSON, its values values too. An object with a form's key is refused, for the form to report. */
|
|
1029
|
+
function plain(forms, value) {
|
|
1030
|
+
return plainObject.superRefine((record, context) => {
|
|
1031
|
+
if (forms.some((key) => key in record)) context.addIssue({
|
|
1032
|
+
code: "invalid_type",
|
|
1033
|
+
expected: "object",
|
|
1034
|
+
input: record
|
|
1035
|
+
});
|
|
1036
|
+
}).pipe(z.record(z.string(), value));
|
|
1037
|
+
}
|
|
1038
|
+
/** A decorator's attributes, styles and element props. */
|
|
1039
|
+
const decoratorProps = z.record(z.string(), decoratorValue);
|
|
1040
|
+
/** A sample's props, and those of the components in its children. */
|
|
1041
|
+
const sampleProps = z.record(z.string(), sampleValue);
|
|
756
1042
|
// ../core/src/library.ts
|
|
757
1043
|
const libraryBreakpoint = fileObject({
|
|
758
1044
|
id: z.string(),
|
|
@@ -807,7 +1093,7 @@ const sampleRender = fileObject({
|
|
|
807
1093
|
/** A component of the same library, by its name in `components.list`, with its props and children. */
|
|
808
1094
|
const sampleComponent = fileObject({
|
|
809
1095
|
component: z.string(),
|
|
810
|
-
props:
|
|
1096
|
+
props: sampleProps.optional(),
|
|
811
1097
|
get children() {
|
|
812
1098
|
return z.array(sampleChild).optional();
|
|
813
1099
|
}
|
|
@@ -824,38 +1110,9 @@ const sampleChild = z.union([
|
|
|
824
1110
|
z.object({ $element: z.array(sampleChild) });
|
|
825
1111
|
/** What a component needs to draw something: props with sample values, and children, as for a collection's items. */
|
|
826
1112
|
const componentSample = fileObject({
|
|
827
|
-
props:
|
|
1113
|
+
props: sampleProps.optional(),
|
|
828
1114
|
children: z.array(sampleChild).optional()
|
|
829
1115
|
});
|
|
830
|
-
/** Whether a sample's prop value is elements. */
|
|
831
|
-
function isSampleElement(value) {
|
|
832
|
-
return typeof value === "object" && value !== null && Array.isArray(value.$element);
|
|
833
|
-
}
|
|
834
|
-
/** Whether a sample's prop value is one the package makes. */
|
|
835
|
-
function isMadeValue(value) {
|
|
836
|
-
const call = typeof value === "object" && value !== null ? value.$call : void 0;
|
|
837
|
-
return typeof call === "object" && call !== null && typeof call.import === "string";
|
|
838
|
-
}
|
|
839
|
-
/** Whether a sample's child or prop value is a render function. */
|
|
840
|
-
function isSampleRender(value) {
|
|
841
|
-
return typeof value === "object" && value !== null && Array.isArray(value.$render);
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
* Where a part's sample calls what's inside it: its function children, else a render prop (Chakra's `TreeView.Node`
|
|
845
|
-
* `render`), with the render function.
|
|
846
|
-
*/
|
|
847
|
-
function renderSlotOf(sample) {
|
|
848
|
-
const children = sample?.children?.find(isSampleRender);
|
|
849
|
-
if (children) return {
|
|
850
|
-
prop: "children",
|
|
851
|
-
render: children
|
|
852
|
-
};
|
|
853
|
-
const entry = Object.entries(sample?.props ?? {}).find(([, value]) => isSampleRender(value));
|
|
854
|
-
return entry ? {
|
|
855
|
-
prop: entry[0],
|
|
856
|
-
render: entry[1]
|
|
857
|
-
} : void 0;
|
|
858
|
-
}
|
|
859
1116
|
/** A regular expression's source, checked by compiling it. */
|
|
860
1117
|
const pattern = z.string().refine((source) => {
|
|
861
1118
|
try {
|
|
@@ -977,110 +1234,11 @@ const libraryIcons = fileObject({
|
|
|
977
1234
|
/** Where `tags` were read from, as `package@version/path`. */
|
|
978
1235
|
tagSource: z.string().optional()
|
|
979
1236
|
});
|
|
980
|
-
/**
|
|
981
|
-
* A decorator's value: JSON, or one of five forms that the guest works out for each frame. An object with one of the
|
|
982
|
-
* forms' keys must be that form; any other object is plain JSON, its values decorator values too.
|
|
983
|
-
*
|
|
984
|
-
* - `{ "$import": "pkg", "export": "name" }`: something the package exports, such as a theme object. `export` defaults
|
|
985
|
-
* to `default`.
|
|
986
|
-
* - `{ "$call": { "import": "pkg", "export": "name" }, "args": [...], "methods": [...] }`: what calling it returns.
|
|
987
|
-
* - `{ "$global": "theme", "values": { "dark": ... }, "default": ... }`: picked by the frame's global, which is the
|
|
988
|
-
* mode's option for that variable.
|
|
989
|
-
* - `{ "$frame": "root" | "host" | "body" }`: the frame's shadow root, the element it hangs from (which `:root[...]`
|
|
990
|
-
* rules match, as `:host(...)`), or the element standing in for its `<body>`. Also `document`, `dir`, `lang`, and
|
|
991
|
-
* `selector`, a CSS selector for the body alone.
|
|
992
|
-
* - `{ "$function": ... }`: a function returning the value it holds.
|
|
993
|
-
*
|
|
994
|
-
* Values are checked once, when their library file loads. The guest evaluates them on every frame without zod.
|
|
995
|
-
*/
|
|
996
|
-
const decoratorValue = z.lazy(() => z.union([
|
|
997
|
-
z.string(),
|
|
998
|
-
finiteNumber,
|
|
999
|
-
z.boolean(),
|
|
1000
|
-
z.null(),
|
|
1001
|
-
z.array(decoratorValue),
|
|
1002
|
-
form("$import", importedValue),
|
|
1003
|
-
form("$call", madeValue),
|
|
1004
|
-
form("$global", globalValue),
|
|
1005
|
-
form("$frame", frameValue),
|
|
1006
|
-
form("$function", functionValue),
|
|
1007
|
-
plainValue
|
|
1008
|
-
]));
|
|
1009
|
-
const valueForms = [
|
|
1010
|
-
"$import",
|
|
1011
|
-
"$call",
|
|
1012
|
-
"$global",
|
|
1013
|
-
"$frame",
|
|
1014
|
-
"$function"
|
|
1015
|
-
];
|
|
1016
|
-
/** Something the package exports, such as a theme object. */
|
|
1017
|
-
const importedValue = fileObject({
|
|
1018
|
-
$import: z.string(),
|
|
1019
|
-
export: z.string().optional()
|
|
1020
|
-
});
|
|
1021
|
-
/**
|
|
1022
|
-
* A value the package makes by calling one of its own functions, as an example does (Chakra's
|
|
1023
|
-
* `collection={createTreeCollection({ rootNode })}`): the canvas calls it with `args`, once per frame.
|
|
1024
|
-
*/
|
|
1025
|
-
const madeValue = fileObject({
|
|
1026
|
-
$call: fileObject({
|
|
1027
|
-
import: z.string(),
|
|
1028
|
-
export: z.string()
|
|
1029
|
-
}),
|
|
1030
|
-
args: z.array(decoratorValue).optional(),
|
|
1031
|
-
/**
|
|
1032
|
-
* Methods called on what it makes, in order, as the examples call them (Chakra's `toaster.create({ title })`), so a
|
|
1033
|
-
* toaster is drawn with a toast in it.
|
|
1034
|
-
*/
|
|
1035
|
-
methods: z.array(fileObject({
|
|
1036
|
-
method: z.string(),
|
|
1037
|
-
args: z.array(decoratorValue).optional()
|
|
1038
|
-
})).optional()
|
|
1039
|
-
});
|
|
1040
|
-
/** Picked by the frame's global, which is the mode's option for that variable, else `default`. */
|
|
1041
|
-
const globalValue = fileObject({
|
|
1042
|
-
$global: z.string(),
|
|
1043
|
-
values: z.record(z.string(), decoratorValue),
|
|
1044
|
-
default: decoratorValue.optional()
|
|
1045
|
-
});
|
|
1046
|
-
/** Part of the frame itself. */
|
|
1047
|
-
const frameValue = fileObject({ $frame: z.enum([
|
|
1048
|
-
"root",
|
|
1049
|
-
"host",
|
|
1050
|
-
"body",
|
|
1051
|
-
"document",
|
|
1052
|
-
"dir",
|
|
1053
|
-
"lang",
|
|
1054
|
-
"selector"
|
|
1055
|
-
]) });
|
|
1056
|
-
/** A function returning the value it holds. */
|
|
1057
|
-
const functionValue = fileObject({ $function: decoratorValue });
|
|
1058
|
-
/**
|
|
1059
|
-
* An object with a form's key is that form. Any other object is refused as another type of value would be, which
|
|
1060
|
-
* `parseData` passes over, so a broken form reports its own mistake and not the closest of the other forms.
|
|
1061
|
-
*/
|
|
1062
|
-
function form(key, schema) {
|
|
1063
|
-
return z.unknown().superRefine((value, context) => {
|
|
1064
|
-
if (!(typeof value === "object" && value !== null && key in value)) context.addIssue({
|
|
1065
|
-
code: "invalid_type",
|
|
1066
|
-
expected: "object",
|
|
1067
|
-
input: value
|
|
1068
|
-
});
|
|
1069
|
-
}).pipe(schema);
|
|
1070
|
-
}
|
|
1071
|
-
/** Plain JSON, its values decorator values too. An object with a form's key is refused, for the form to report. */
|
|
1072
|
-
const plainValue = plainObject.superRefine((record, context) => {
|
|
1073
|
-
if (valueForms.some((key) => key in record)) context.addIssue({
|
|
1074
|
-
code: "invalid_type",
|
|
1075
|
-
expected: "object",
|
|
1076
|
-
input: record
|
|
1077
|
-
});
|
|
1078
|
-
}).pipe(z.record(z.string(), decoratorValue));
|
|
1079
1237
|
const decoratorElement = fileObject({
|
|
1080
1238
|
import: z.string(),
|
|
1081
1239
|
/** The export to render; `default` for a default export. */
|
|
1082
1240
|
component: z.string(),
|
|
1083
|
-
props:
|
|
1241
|
+
props: decoratorProps.optional()
|
|
1084
1242
|
});
|
|
1085
1243
|
const decoratorEffects = [
|
|
1086
1244
|
"wrap",
|
|
@@ -1101,8 +1259,8 @@ const libraryDecorator = fileObject({
|
|
|
1101
1259
|
wrap: decoratorElement.optional(),
|
|
1102
1260
|
add: decoratorElement.optional(),
|
|
1103
1261
|
class: decoratorValue.optional(),
|
|
1104
|
-
attributes:
|
|
1105
|
-
style:
|
|
1262
|
+
attributes: decoratorProps.optional(),
|
|
1263
|
+
style: decoratorProps.optional()
|
|
1106
1264
|
}).superRefine((decorator, context) => {
|
|
1107
1265
|
if (decoratorEffects.filter((key) => decorator[key] !== void 0).length !== 1) context.addIssue({
|
|
1108
1266
|
code: "custom",
|
|
@@ -1296,8 +1454,7 @@ function withLibraryContext(node, sources, around, taken) {
|
|
|
1296
1454
|
const plain = {};
|
|
1297
1455
|
const slots = {};
|
|
1298
1456
|
const renderSlot = (prop, render) => {
|
|
1299
|
-
|
|
1300
|
-
slots[`${render.spread ? "$renderWith" : "$render"}:${prop}${pass}`] = nodes(render.$render);
|
|
1457
|
+
slots[renderSlotKey(prop, render)] = nodes(render.$render);
|
|
1301
1458
|
};
|
|
1302
1459
|
for (const [key, value] of Object.entries(props)) if (isSampleRender(value)) renderSlot(key, value);
|
|
1303
1460
|
else if (isSampleElement(value)) slots[key] = nodes(value.$element);
|
|
@@ -1354,8 +1511,8 @@ function withLibraryContext(node, sources, around, taken) {
|
|
|
1354
1511
|
for (const parent of added.reverse()) {
|
|
1355
1512
|
const wrapper = component(parent);
|
|
1356
1513
|
const calls = renderSlotOf(sources[parent]?.sample);
|
|
1357
|
-
const slot = calls ?
|
|
1358
|
-
const kept = Object.fromEntries(Object.entries(wrapper.type === "component" ? wrapper.slots ?? {} : {}).filter(([name]) => !calls ||
|
|
1514
|
+
const slot = calls ? renderSlotKey(calls.prop, calls.render) : "children";
|
|
1515
|
+
const kept = Object.fromEntries(Object.entries(wrapper.type === "component" ? wrapper.slots ?? {} : {}).filter(([name]) => !calls || readRenderSlotKey(name)?.prop !== calls.prop));
|
|
1359
1516
|
placed = wrapper.type === "component" ? {
|
|
1360
1517
|
...wrapper,
|
|
1361
1518
|
slots: {
|
|
@@ -1491,4 +1648,4 @@ function sampleIds(sample, library) {
|
|
|
1491
1648
|
...sample.children ? { children: sample.children.map(child) } : {}
|
|
1492
1649
|
};
|
|
1493
1650
|
}
|
|
1494
|
-
export {
|
|
1651
|
+
export { lengthToPixels as $, canvasObjectKinds as A, nodeTree as B, isSampleRender as C, valueForms as D, renderSlotOf as E, imageFits as F, walkNodes as G, paramTypes as H, linkAllowed as I, collectCustomProperties as J, generateId as K, linkEndKinds as L, containerSpec as M, detectionCorrections as N, valueImports as O, imageCredit as P, deviceKinds as Q, linkTypes as R, isSampleElement as S, renderSlotKey as T, patchUnset as U, noteSpec as V, textTags as W, viewportHeightProperty as X, remProperty as Y, viewportWidthProperty as Z, sampleValue as _, openProps as a, frameParts as b, libraryManifest as c, parentSignals as d, packageManifest as et, parseLibraryEdits as f, sampleProps as g, decoratorValue as h, withLibraryContext as i, containerKinds as j, canvasDocument as k, libraryManifestExtension as l, decoratorProps as m, librarySource as n, applyLibraryEdits as o, parseLibraryManifest as p, modeSettings as q, sampleIds as r, componentEvidence as s, componentNode as t, parseManifest as tt, libraryPackage as u, evaluateValue as v, readRenderSlotKey as w, isMadeValue as x, exportOf as y, nodeStyle as z };
|