@parity-app/cli 0.1.0 → 0.2.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.
@@ -1,11 +1,3 @@
1
- // ../core/src/css.ts
2
- /**
3
- * Custom properties holding 1% of a frame's viewport width and height, which viewport units are rewritten to: in a frame,
4
- * `100vh` is the height of the screen the frame stands for, not of Parity's window.
5
- */
6
- const viewportWidthProperty = "--canvas-vw";
7
- const viewportHeightProperty = "--canvas-vh";
8
- new RegExp(String.raw`"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|url\([^)]*\)|var\((?:${viewportWidthProperty}|${viewportHeightProperty}),[^)]*\)`, "g");
9
1
  // ../core/src/devices.ts
10
2
  const deviceKinds = [
11
3
  "phone",
@@ -24,6 +16,110 @@ function lengthToPixels(value) {
24
16
  if (!Number.isFinite(number)) return void 0;
25
17
  return match[2] === "rem" || match[2] === "em" ? number * 16 : number;
26
18
  }
19
+ // ../core/src/css.ts
20
+ /**
21
+ * Custom properties holding 1% of a frame's viewport width and height, which viewport units are rewritten to: in a frame,
22
+ * `100vh` is the height of the screen the frame stands for, not of Parity's window.
23
+ */
24
+ const viewportWidthProperty = "--canvas-vw";
25
+ const viewportHeightProperty = "--canvas-vh";
26
+ /** Every custom property declaration in a stylesheet, in source order. */
27
+ function collectCustomProperties(css) {
28
+ const declarations = [];
29
+ const visit = (nodes, selector, atRules) => {
30
+ for (const node of nodes) if (node.kind === "block") {
31
+ const prelude = node.prelude.trim();
32
+ const atRule = /^@([\w-]+)\s*([\s\S]*)$/.exec(prelude);
33
+ if (atRule) visit(node.children, selector, [...atRules, {
34
+ name: atRule[1].toLowerCase(),
35
+ prelude: atRule[2].trim()
36
+ }]);
37
+ else visit(node.children, prelude, atRules);
38
+ } else if (selector !== void 0 || atRules.length > 0) for (const match of node.text.matchAll(/--([\w-]+)\s*:\s*([^;]+)/g)) declarations.push({
39
+ selector: selector ?? "",
40
+ atRules,
41
+ name: match[1],
42
+ value: match[2].trim()
43
+ });
44
+ };
45
+ visit(parse(css), void 0, []);
46
+ return declarations;
47
+ }
48
+ function parse(css) {
49
+ let index = 0;
50
+ function parseLevel() {
51
+ const nodes = [];
52
+ let buffer = "";
53
+ let afterLastSemicolon = 0;
54
+ let parens = 0;
55
+ while (index < css.length) {
56
+ const char = css[index];
57
+ if (char === "/" && css[index + 1] === "*") {
58
+ const end = css.indexOf("*/", index + 2);
59
+ index = end === -1 ? css.length : end + 2;
60
+ continue;
61
+ }
62
+ if (char === "\\") {
63
+ buffer += css.slice(index, index + 2);
64
+ index += 2;
65
+ continue;
66
+ }
67
+ if (char === "\"" || char === "'") {
68
+ const end = findStringEnd(css, index);
69
+ buffer += css.slice(index, end);
70
+ index = end;
71
+ continue;
72
+ }
73
+ index++;
74
+ if (char === "(") parens++;
75
+ if (char === ")") parens = Math.max(0, parens - 1);
76
+ if (parens > 0) {
77
+ buffer += char;
78
+ continue;
79
+ }
80
+ if (char === ";") {
81
+ buffer += char;
82
+ afterLastSemicolon = buffer.length;
83
+ } else if (char === "{") {
84
+ const text = buffer.slice(0, afterLastSemicolon);
85
+ if (text) nodes.push({
86
+ kind: "text",
87
+ text
88
+ });
89
+ nodes.push({
90
+ kind: "block",
91
+ prelude: buffer.slice(afterLastSemicolon),
92
+ children: parseLevel()
93
+ });
94
+ buffer = "";
95
+ afterLastSemicolon = 0;
96
+ } else if (char === "}") {
97
+ if (buffer) nodes.push({
98
+ kind: "text",
99
+ text: buffer
100
+ });
101
+ return nodes;
102
+ } else buffer += char;
103
+ }
104
+ if (buffer) nodes.push({
105
+ kind: "text",
106
+ text: buffer
107
+ });
108
+ return nodes;
109
+ }
110
+ const nodes = [];
111
+ while (index < css.length) nodes.push(...parseLevel());
112
+ return nodes;
113
+ }
114
+ function findStringEnd(css, start) {
115
+ const quote = css[start];
116
+ let index = start + 1;
117
+ while (index < css.length) if (css[index] === "\\") index += 2;
118
+ else if (css[index] === quote) return index + 1;
119
+ else index++;
120
+ return css.length;
121
+ }
122
+ new RegExp(String.raw`"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|url\([^)]*\)|var\((?:${viewportWidthProperty}|${viewportHeightProperty}),[^)]*\)`, "g");
27
123
  // ../core/src/validate.ts
28
124
  function expectObject(value, path) {
29
125
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path || "/"}: expected an object`);
@@ -270,10 +366,7 @@ function parseDetection(value, path) {
270
366
  export: expectString(ref.export, `${at}/${index}/export`)
271
367
  };
272
368
  });
273
- return compact({
274
- include: optional(detection.include, (list) => refs(list, `${path}/include`)),
275
- exclude: optional(detection.exclude, (list) => refs(list, `${path}/exclude`))
276
- });
369
+ return compact({ include: optional(detection.include, (list) => refs(list, `${path}/include`)) });
277
370
  }
278
371
  function parseNote(value, path) {
279
372
  const note = expectObject(value, path);
@@ -729,7 +822,7 @@ const decoratorKeys = [
729
822
  const libraryManifestExtension = ".lib.par";
730
823
  function parseLibraryManifest(value) {
731
824
  const manifest = expectObject(value, "");
732
- const keys = [
825
+ expectKnownKeys(manifest, [
733
826
  "$schema",
734
827
  "version",
735
828
  "id",
@@ -738,13 +831,16 @@ function parseLibraryManifest(value) {
738
831
  "styles",
739
832
  "breakpoints",
740
833
  "tokens",
741
- "canvas"
742
- ];
743
- if (manifest.version === 3) keys.push("package", "components", "icons", "decorators", "edits");
744
- expectKnownKeys(manifest, keys, "");
745
- if (manifest.version !== 1 && manifest.version !== 2 && manifest.version !== 3) throw new TypeError("/version: expected 1, 2 or 3");
834
+ "canvas",
835
+ "package",
836
+ "components",
837
+ "icons",
838
+ "decorators",
839
+ "edits"
840
+ ], "");
841
+ if (manifest.version !== 3) throw new TypeError("/version: expected 3");
746
842
  return compact({
747
- version: manifest.version,
843
+ version: 3,
748
844
  id: optional(manifest.id, (v) => expectString(v, "/id")),
749
845
  name: expectString(manifest.name, "/name"),
750
846
  description: optional(manifest.description, (v) => expectString(v, "/description")),
@@ -1074,7 +1170,7 @@ function expectStringRecord(value, path) {
1074
1170
  const named = /* @__PURE__ */ new WeakSet();
1075
1171
  /**
1076
1172
  * A new node for a component, ready to show something: required props get their default or first option, and a
1077
- * component that takes children gets its own name as text, so it isn't an empty box.
1173
+ * component that takes children gets its own name as text, so it isn't an empty box, unless `given` has its own.
1078
1174
  */
1079
1175
  function componentNode(component, info, taken, given = {}) {
1080
1176
  const props = { ...given };
@@ -1086,7 +1182,7 @@ function componentNode(component, info, taken, given = {}) {
1086
1182
  else if (prop.kind === "number") props[prop.name] = 0;
1087
1183
  else if (prop.kind === "string") props[prop.name] = prop.name;
1088
1184
  }
1089
- const labelled = info?.props.some((prop) => prop.name === "children" && prop.kind === "node");
1185
+ const labelled = !("children" in given) && info?.props.some((prop) => prop.name === "children" && prop.kind === "node");
1090
1186
  if (labelled) props.children = component.split("/").at(-1) ?? component;
1091
1187
  const node = {
1092
1188
  type: "component",
@@ -1247,10 +1343,10 @@ function withLibraryContext(node, sources, around, taken) {
1247
1343
  }
1248
1344
  }
1249
1345
  /**
1250
- * A library file's component as the canvas inserts it, but for where it's declared: its import, its parents and sample
1251
- * by component id (`nova/AccordionItem`), and `imported` naming the package the way the project depends on it.
1346
+ * A library file's component as the canvas inserts it, with its parents and sample named by component id.
1347
+ * Discovery has already rewritten module imports for the name the project installed the package under.
1252
1348
  */
1253
- function librarySource(library, name, component, path, imported = (specifier) => specifier) {
1349
+ function librarySource(library, name, component, path) {
1254
1350
  return {
1255
1351
  path,
1256
1352
  export: name,
@@ -1261,14 +1357,13 @@ function librarySource(library, name, component, path, imported = (specifier) =>
1261
1357
  ...component.visual === false ? { visual: false } : {},
1262
1358
  ...component.optionalParents ? { optionalParents: component.optionalParents.map((parent) => `${library}/${parent}`) } : {},
1263
1359
  ...component.parentParts ? { parentParts: true } : {},
1264
- ...component.sample ? { sample: sampleIds(component.sample, library, imported) } : {}
1360
+ ...component.sample ? { sample: sampleIds(component.sample, library) } : {}
1265
1361
  };
1266
1362
  }
1267
1363
  /**
1268
- * A sample with its children's components named by id, as `nova/AccordionItem`; HTML elements keep their tag. A value the
1269
- * package makes (`{ $call: { import: "@chakra-ui/react", ... } }`) imports it by the name the project depends on.
1364
+ * A sample with its children's components named by id, as `nova/AccordionItem`; HTML elements keep their tag.
1270
1365
  */
1271
- function sampleIds(sample, library, imported = (specifier) => specifier) {
1366
+ function sampleIds(sample, library) {
1272
1367
  const child = (node) => {
1273
1368
  if (typeof node === "string") return node;
1274
1369
  if (isSampleRender(node)) return {
@@ -1288,13 +1383,7 @@ function sampleIds(sample, library, imported = (specifier) => specifier) {
1288
1383
  $render: item.$render.map(child)
1289
1384
  };
1290
1385
  if (isSampleElement(item)) return { $element: item.$element.map(child) };
1291
- return isMadeValue(item) ? {
1292
- ...item,
1293
- $call: {
1294
- ...item.$call,
1295
- import: imported(item.$call.import)
1296
- }
1297
- } : item;
1386
+ return item;
1298
1387
  };
1299
1388
  const propIds = (props) => Object.fromEntries(Object.entries(props).map(([key, item]) => [key, propId(item)]));
1300
1389
  return {
@@ -1303,4 +1392,4 @@ function sampleIds(sample, library, imported = (specifier) => specifier) {
1303
1392
  ...sample.children ? { children: sample.children.map(child) } : {}
1304
1393
  };
1305
1394
  }
1306
- export { viewportHeightProperty as C, lengthToPixels as S, parseCanvasDocument as _, applyLibraryEdits as a, parseModeSettings as b, isSampleElement as c, parentSignals as d, parseLibraryEdits as f, paramTypes as g, imageFits as h, withLibraryContext as i, isSampleRender as l, renderSlotOf as m, librarySource as n, componentEvidence as o, parseLibraryManifest as p, sampleIds as r, isMadeValue as s, componentNode as t, libraryManifestExtension as u, styleKeys as v, viewportWidthProperty as w, deviceKinds as x, generateId as y };
1395
+ export { viewportWidthProperty as C, viewportHeightProperty as S, lengthToPixels as T, parseCanvasDocument as _, applyLibraryEdits as a, parseModeSettings as b, isSampleElement as c, parentSignals as d, parseLibraryEdits as f, paramTypes as g, imageFits as h, withLibraryContext as i, isSampleRender as l, renderSlotOf as m, librarySource as n, componentEvidence as o, parseLibraryManifest as p, sampleIds as r, isMadeValue as s, componentNode as t, libraryManifestExtension as u, styleKeys as v, deviceKinds as w, collectCustomProperties as x, generateId as y };
@@ -1,4 +1,4 @@
1
- import { p as parseLibraryManifest, u as libraryManifestExtension } from "./src-D9EMN48r.mjs";
1
+ import { p as parseLibraryManifest, u as libraryManifestExtension } from "./src-BZ1p_ip_.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { readFile, readdir } from "node:fs/promises";
4
4
  import { dirname, join } from "node:path";