@deepraxis/cli 0.3.0-dev.7bbb3d7 → 0.3.0-dev.bc829d1

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.
Files changed (2) hide show
  1. package/dist/praxis.js +100 -11
  2. package/package.json +1 -1
package/dist/praxis.js CHANGED
@@ -49895,7 +49895,8 @@ var KNOWN_PROPS = {
49895
49895
  context: keys(`${SIZE} ${TEXT} content`),
49896
49896
  icon: keys(`${SIZE} ${EFFECTS} library icon weight fill`),
49897
49897
  script: keys(`${SIZE} clip scriptUri inputs`),
49898
- browser: keys(`${SIZE} ${EFFECTS} ${STROKE} url deviceId zoom scrollX scrollY cornerRadius`),
49898
+ browser: keys(`${SIZE} ${GRAPHICS} url deviceId zoom scrollX scrollY cornerRadius`),
49899
+ html: keys(`${SIZE} ${GRAPHICS} html cornerRadius`),
49899
49900
  ref: keys("ref descendants")
49900
49901
  };
49901
49902
  function unknownProperties(node2, type) {
@@ -49996,9 +49997,64 @@ function pathLineBounds(geometry) {
49996
49997
  return { x: minX, y: minY, w: maxX - minX, h: maxY - minY };
49997
49998
  }
49998
49999
 
50000
+ // ../../packages/canvas/document/src/live-node.ts
50001
+ var HTML_MAX_BYTES = 256 * 1024;
50002
+ var drawsNothing = (value) => value === undefined || value === null || typeof value === "number" && !(value > 0);
50003
+ function checkLiveNode(node2) {
50004
+ const warnings = [];
50005
+ if (!node2 || typeof node2 !== "object" || node2.type !== "html")
50006
+ return { warnings };
50007
+ const html = node2.html;
50008
+ if (typeof html !== "string")
50009
+ return { reject: { property: "html", reason: "html must be a string" }, warnings };
50010
+ const bytes = new TextEncoder().encode(html).length;
50011
+ if (bytes > HTML_MAX_BYTES)
50012
+ return {
50013
+ reject: { property: "html", reason: `html is ${bytes} bytes of UTF-8; the limit is ${HTML_MAX_BYTES}` },
50014
+ warnings
50015
+ };
50016
+ if (drawsNothing(node2.width) || drawsNothing(node2.height))
50017
+ warnings.push({ code: "HTML_NODE_NO_SIZE", message: "html node has no width and height: set both, or it paints at zero size" });
50018
+ return { warnings };
50019
+ }
50020
+
49999
50021
  // ../../packages/canvas/document/src/execute-api.ts
50000
50022
  var LIMITS = { ops: 5000, printBytes: 64 * 1024, screenshots: 4 };
50001
50023
  var ID_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
50024
+ function undeclared(node2, key) {
50025
+ return node2[key] === undefined || node2[key] === null;
50026
+ }
50027
+ var TEXT_DEFAULT_KEYS = ["fontFamily", "fontSize", "fontWeight", "lineHeight", "letterSpacing", "fill"];
50028
+ var TEXT_DEFAULTS_BYTES = 4 * 1024;
50029
+ function normalizeDefaults(value) {
50030
+ const raw = value ?? {};
50031
+ const text = raw.text;
50032
+ if (!text || typeof text !== "object" || Array.isArray(text))
50033
+ return {};
50034
+ const out = {};
50035
+ for (const k of TEXT_DEFAULT_KEYS)
50036
+ if (!undeclared(text, k))
50037
+ out[k] = text[k];
50038
+ if (!Object.keys(out).length)
50039
+ return {};
50040
+ if (new TextEncoder().encode(JSON.stringify(out)).byteLength > TEXT_DEFAULTS_BYTES)
50041
+ return {};
50042
+ return { text: out };
50043
+ }
50044
+ function applyTextDefaults(node2, defaults) {
50045
+ const keys2 = defaults ? TEXT_DEFAULT_KEYS.filter((k) => !undeclared(defaults, k)) : [];
50046
+ let out = node2;
50047
+ if (keys2.length && node2.type === "text") {
50048
+ const filled = { ...node2 };
50049
+ for (const k of keys2)
50050
+ if (undeclared(filled, k))
50051
+ filled[k] = defaults[k];
50052
+ out = filled;
50053
+ }
50054
+ if (Array.isArray(out.children))
50055
+ out = { ...out, children: out.children.map((c) => applyTextDefaults(c, defaults)) };
50056
+ return out;
50057
+ }
50002
50058
  class ExecuteApi {
50003
50059
  store;
50004
50060
  rec;
@@ -50007,6 +50063,7 @@ class ExecuteApi {
50007
50063
  random;
50008
50064
  document = "document";
50009
50065
  layoutCache = new Map;
50066
+ defaults = {};
50010
50067
  constructor(store, rec, bounds, rev, random = Math.random) {
50011
50068
  this.store = store;
50012
50069
  this.rec = rec;
@@ -50014,6 +50071,28 @@ class ExecuteApi {
50014
50071
  this.rev = rev;
50015
50072
  this.random = random;
50016
50073
  }
50074
+ setDefaults(value) {
50075
+ const raw = value;
50076
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
50077
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: "SetDefaults", reason: "expected { text: { … } } or { text: null }" });
50078
+ for (const key of Object.keys(raw))
50079
+ if (key !== "text")
50080
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: key, reason: "SetDefaults only accepts text" });
50081
+ const text = raw.text;
50082
+ if (text !== null && text !== undefined) {
50083
+ if (typeof text !== "object" || Array.isArray(text))
50084
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: "text", reason: "expected an object of text properties" });
50085
+ for (const key of Object.keys(text))
50086
+ if (!TEXT_DEFAULT_KEYS.includes(key))
50087
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: `text.${key}`, reason: `not a default text property; use ${TEXT_DEFAULT_KEYS.join(", ")}` });
50088
+ if (new TextEncoder().encode(JSON.stringify(text)).byteLength > TEXT_DEFAULTS_BYTES)
50089
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: "text", reason: `defaults over ${TEXT_DEFAULTS_BYTES} bytes` });
50090
+ }
50091
+ return this.defaults = normalizeDefaults(value);
50092
+ }
50093
+ getDefaults() {
50094
+ return this.defaults;
50095
+ }
50017
50096
  mint() {
50018
50097
  for (;; ) {
50019
50098
  let id = "";
@@ -50069,6 +50148,9 @@ class ExecuteApi {
50069
50148
  if (typeof v === "string" && /%|vh|vw|calc/.test(v))
50070
50149
  throw new OpRejectedError({ code: "INVALID_VALUE", property: k, reason: "percentage and viewport sizes are not supported" });
50071
50150
  }
50151
+ const live = checkLiveNode(node2);
50152
+ if (live.reject)
50153
+ throw new OpRejectedError({ code: "INVALID_VALUE", property: live.reject.property, reason: live.reject.reason });
50072
50154
  const id = this.mint();
50073
50155
  const out = { ...node2, id };
50074
50156
  if (typeof node2.name === "string") {
@@ -50082,11 +50164,18 @@ class ExecuteApi {
50082
50164
  }
50083
50165
  return out;
50084
50166
  }
50085
- warnProps(data, type, nodeId) {
50167
+ warnProps(data, type, nodeId, declared = false) {
50086
50168
  if (hasUnsupportedImageUrl(data) && this.rec.warnings.length < 20 && !this.rec.warnings.some((w) => w.code === "UNSUPPORTED_IMAGE_URL" && w.nodeId === nodeId))
50087
50169
  this.rec.warnings.push({ code: "UNSUPPORTED_IMAGE_URL", nodeId, message: "image fill url must be a file id (file-…)" });
50170
+ if (declared && data.type === "text" && undeclared(data, "fill") && !this.defaults.text?.fill && this.rec.warnings.length < 20 && !this.rec.warnings.some((w) => w.code === "TEXT_NO_FILL" && w.nodeId === nodeId))
50171
+ this.rec.warnings.push({ code: "TEXT_NO_FILL", nodeId, message: `text node has no fill and paints nothing — or call SetDefaults({ text: { fill: "#111827" } }) once to give every text node this session a default fill` });
50088
50172
  if (data.type === "icon" && !iconNameOf(data) && this.rec.warnings.length < 20 && !this.rec.warnings.some((w) => w.code === "ICON_NAME_MISSING" && w.nodeId === nodeId))
50089
50173
  this.rec.warnings.push({ code: "ICON_NAME_MISSING", nodeId, message: "icon node has no icon: set icon to a lucide name (name is the node's name, not the icon)" });
50174
+ if (data.type === "html") {
50175
+ for (const w of checkLiveNode(data).warnings)
50176
+ if (this.rec.warnings.length < 20 && !this.rec.warnings.some((x) => x.code === w.code && x.nodeId === nodeId))
50177
+ this.rec.warnings.push({ code: w.code, nodeId, message: w.message });
50178
+ }
50090
50179
  for (const prop of unknownProperties(data, type)) {
50091
50180
  const message = `${prop} is not a .pen property`;
50092
50181
  if (this.rec.warnings.length >= 20)
@@ -50097,7 +50186,7 @@ class ExecuteApi {
50097
50186
  if (type === "path")
50098
50187
  this.warnPathBox(data, nodeId);
50099
50188
  for (const child of Array.isArray(data.children) ? data.children : [])
50100
- this.warnProps(child, child.type, child.id ?? nodeId);
50189
+ this.warnProps(child, child.type, child.id ?? nodeId, declared);
50101
50190
  if (data.descendants && typeof data.descendants === "object") {
50102
50191
  const descendants = typeof data.ref === "string" ? this.resolveDescendantKeys(data.ref, data.descendants) : data.descendants;
50103
50192
  for (const [key, value] of Object.entries(descendants)) {
@@ -50165,10 +50254,10 @@ class ExecuteApi {
50165
50254
  }
50166
50255
  Insert(parent, nodeData) {
50167
50256
  const p = this.parentId(parent);
50168
- let node2 = this.withIds(migrateLegacyProps(nodeData));
50257
+ let node2 = this.withIds(applyTextDefaults(migrateLegacyProps(nodeData), this.defaults.text));
50169
50258
  if (node2.type === "ref" && node2.descendants && typeof node2.descendants === "object")
50170
50259
  node2 = { ...node2, descendants: this.resolveDescendantKeys(node2.ref, node2.descendants) };
50171
- this.warnProps(node2, node2.type, node2.id);
50260
+ this.warnProps(node2, node2.type, node2.id, true);
50172
50261
  this.commit({ op: "insert", parent: p, ord: between(this.lastOrd(p), null), node: node2 });
50173
50262
  return node2.id;
50174
50263
  }
@@ -50198,7 +50287,7 @@ class ExecuteApi {
50198
50287
  };
50199
50288
  node2 = this.withIds({ ...apply(tree), ...over });
50200
50289
  }
50201
- this.warnProps(node2, node2.type, node2.id);
50290
+ this.warnProps(node2, node2.type, node2.id, true);
50202
50291
  this.commit({ op: "insert", parent: p, ord: between(this.lastOrd(p), null), node: node2 });
50203
50292
  return node2.id;
50204
50293
  }
@@ -50235,8 +50324,8 @@ class ExecuteApi {
50235
50324
  const owner = this.store.get(inst.owner);
50236
50325
  if (!owner || owner.props.type !== "ref")
50237
50326
  throw new OpRejectedError({ code: "NODE_NOT_FOUND", path });
50238
- const node3 = this.withIds(migrateLegacyProps(nodeData));
50239
- this.warnProps(node3, node3.type, node3.id);
50327
+ const node3 = this.withIds(applyTextDefaults(migrateLegacyProps(nodeData), this.defaults.text));
50328
+ this.warnProps(node3, node3.type, node3.id, true);
50240
50329
  const desc = { ...owner.props.descendants ?? {}, [inst.rest]: node3 };
50241
50330
  this.commit({ op: "update", id: owner.id, patch: { descendants: desc } });
50242
50331
  return node3.id;
@@ -50244,8 +50333,8 @@ class ExecuteApi {
50244
50333
  const row = this.store.get(path);
50245
50334
  if (!row)
50246
50335
  throw new OpRejectedError({ code: "NODE_NOT_FOUND", path });
50247
- const node2 = this.withIds(migrateLegacyProps(nodeData));
50248
- this.warnProps(node2, node2.type, node2.id);
50336
+ const node2 = this.withIds(applyTextDefaults(migrateLegacyProps(nodeData), this.defaults.text));
50337
+ this.warnProps(node2, node2.type, node2.id, true);
50249
50338
  this.commit({ op: "delete", id: row.id });
50250
50339
  this.commit({ op: "insert", parent: row.parent, ord: row.ord, node: node2 });
50251
50340
  return node2.id;
@@ -51496,7 +51585,7 @@ function startProgress(ctx, write = (text) => writeOutput({ stderr: text })) {
51496
51585
  }
51497
51586
 
51498
51587
  // src/main.ts
51499
- var version = "0.3.0-dev.7bbb3d7";
51588
+ var version = "0.3.0-dev.bc829d1";
51500
51589
  var commands = commandTree(operations);
51501
51590
  var manual = [...workflows.map((w) => w.words), [API_WORD]];
51502
51591
  function route(argv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepraxis/cli",
3
- "version": "0.3.0-dev.7bbb3d7",
3
+ "version": "0.3.0-dev.bc829d1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "praxis": "dist/praxis.js"