codecaine-cli 0.1.0 → 0.1.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/README.md +14 -2
- package/dist/cli.mjs +3212 -185
- package/dist/resources/bb-plugin/package.json +22 -0
- package/dist/resources/bb-plugin/src/server.ts +1084 -0
- package/dist/resources/bb-plugin/src/snapshot.ts +74 -0
- package/dist/resources/bb-plugin/src/tools.ts +926 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a mention or a request keeps of a layer. No imports: the bb plugin loads
|
|
3
|
+
* this inside bb's process, and the editor's request brief reuses it.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** How much of a layer's markup a mention carries. A fingerprint to find or
|
|
7
|
+
* rebuild the layer by, not its source — getLayer and exportHtml have that. */
|
|
8
|
+
const SNAPSHOT_HTML_MAX = 1200;
|
|
9
|
+
const SNAPSHOT_TEXT_MAX = 200;
|
|
10
|
+
/** Mentions that carry a picture at once; a whole selection of forty layers is
|
|
11
|
+
* not forty pictures. */
|
|
12
|
+
export const SNAPSHOT_MAX_LAYERS = 3;
|
|
13
|
+
|
|
14
|
+
function clip(text: string, max: number): string {
|
|
15
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
16
|
+
return flat.length > max ? `${flat.slice(0, max)}…` : flat;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The frame an element of a running page belongs to: `live:<frame>:<handle>`. */
|
|
20
|
+
export function frameOfLiveId(id: string): string | null {
|
|
21
|
+
if (!id.startsWith("live:")) return null;
|
|
22
|
+
const body = id.slice("live:".length);
|
|
23
|
+
const split = body.lastIndexOf(":");
|
|
24
|
+
return split > 0 ? body.slice(0, split) : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* What a mention keeps of a layer so that it still means something once its id
|
|
29
|
+
* is gone — a reload, a re-import or a restored project renumbers layers, and
|
|
30
|
+
* "make @Hero bigger" then names nothing. The id stays first (it is what the
|
|
31
|
+
* tools take while it lasts); after it come the things that survive: name, kind,
|
|
32
|
+
* place in the tree, words, address of a running page, a short markup excerpt,
|
|
33
|
+
* and a small picture on disk. Deliberately short: the context rides along on
|
|
34
|
+
* every later turn of the conversation.
|
|
35
|
+
*/
|
|
36
|
+
export function layerSnapshot(input: {
|
|
37
|
+
layer: Record<string, unknown>;
|
|
38
|
+
html?: string | null;
|
|
39
|
+
/** Of the running page this layer is an element of, when it is one. */
|
|
40
|
+
page?: { id: string; address: string } | null;
|
|
41
|
+
shot?: string | null;
|
|
42
|
+
}): string {
|
|
43
|
+
const { layer, page } = input;
|
|
44
|
+
const str = (value: unknown): string => (typeof value === "string" ? value : "");
|
|
45
|
+
const id = str(layer.id);
|
|
46
|
+
const name = str(layer.name) || str(layer.type) || "layer";
|
|
47
|
+
const kind = [str(layer.type), str(layer.tag) && str(layer.tag) !== str(layer.type) ? `<${str(layer.tag)}>` : ""]
|
|
48
|
+
.filter(Boolean)
|
|
49
|
+
.join(" ");
|
|
50
|
+
const props = (layer.props ?? {}) as Record<string, unknown>;
|
|
51
|
+
const size = (layer.size ?? {}) as { width?: unknown; height?: unknown };
|
|
52
|
+
const lines = [`Layer "${name}" — ${kind || "layer"}, canvas node id ${id}.`];
|
|
53
|
+
const where = str(layer.path);
|
|
54
|
+
if (where) lines.push(`Where: ${where}`);
|
|
55
|
+
if (typeof size.width === "number" && typeof size.height === "number") {
|
|
56
|
+
lines.push(`Size: ${Math.round(size.width)}×${Math.round(size.height)}`);
|
|
57
|
+
}
|
|
58
|
+
const text = str(layer.text);
|
|
59
|
+
if (text) lines.push(`Text: ${clip(text, SNAPSHOT_TEXT_MAX)}`);
|
|
60
|
+
const address = page?.address || (/^https?:\/\//.test(str(props.src)) ? str(props.src) : "");
|
|
61
|
+
if (address) {
|
|
62
|
+
lines.push(
|
|
63
|
+
page
|
|
64
|
+
? `Element of the running page ${address} (page canvas node id ${page.id}); if the element id above is stale, find it by the markup below.`
|
|
65
|
+
: `Running page: ${address}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (input.html) lines.push(`Markup (excerpt): ${clip(input.html, SNAPSHOT_HTML_MAX)}`);
|
|
69
|
+
if (input.shot) lines.push(`Picture of how it looked when mentioned: ${input.shot}`);
|
|
70
|
+
lines.push(
|
|
71
|
+
"If this id no longer resolves, the design was reloaded: find the layer again with listLayers by name or text, or use the markup and picture above.",
|
|
72
|
+
);
|
|
73
|
+
return lines.join("\n");
|
|
74
|
+
}
|