@markdy/core 1.0.30 → 1.0.31
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 +17 -9
- package/dist/index.d.ts +3 -1
- package/dist/index.js +182 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,20 +46,28 @@ import { parse, ParseError } from "@markdy/core";
|
|
|
46
46
|
import type { DiagramAST } from "@markdy/core";
|
|
47
47
|
|
|
48
48
|
const source = `
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
scene "Cache-Aside Architecture" theme=paper
|
|
50
|
+
layout LR
|
|
51
|
+
|
|
52
|
+
browser Client "Web Client"
|
|
53
|
+
gateway Gateway "API Gateway"
|
|
54
|
+
service Shortener "URL Service"
|
|
55
|
+
cache Redis "Redis Cluster"
|
|
56
|
+
|
|
57
|
+
beat hit:
|
|
58
|
+
show $nodes stagger=60ms
|
|
59
|
+
Client -> Gateway "GET /x9" -> Shortener "resolve"
|
|
60
|
+
Shortener -> Redis "GET slug:x9"
|
|
61
|
+
Shortener <- Redis "200 Target URL"
|
|
62
|
+
Client <- Gateway "301 Redirect"
|
|
55
63
|
`;
|
|
56
64
|
|
|
57
65
|
try {
|
|
58
66
|
const ast: DiagramAST = parse(source);
|
|
59
67
|
|
|
60
|
-
console.log(ast.meta); // { width: 1280, height: 720, fps: 60, theme: "paper", direction: "LR", title: "
|
|
61
|
-
console.log(ast.nodes); // {
|
|
62
|
-
console.log(ast.beats); // [{ name: "
|
|
68
|
+
console.log(ast.meta); // { width: 1280, height: 720, fps: 60, theme: "paper", direction: "LR", title: "Cache-Aside Architecture" }
|
|
69
|
+
console.log(ast.nodes); // { Client: { kind: "browser", ... }, Gateway: { ... } }
|
|
70
|
+
console.log(ast.beats); // [{ name: "hit", cues: [...] }]
|
|
63
71
|
} catch (e) {
|
|
64
72
|
if (e instanceof ParseError) {
|
|
65
73
|
console.error(`Line ${e.line}: ${e.message}`);
|
package/dist/index.d.ts
CHANGED
|
@@ -778,4 +778,6 @@ declare function getIntelliCodeCompletions(docText: string, cursorLine: number,
|
|
|
778
778
|
declare function predictNextLineSuggestion(docText: string, cursorLine: number): GhostTextSuggestion | null;
|
|
779
779
|
declare function getArchitectureSuggestions(docText: string): ArchitectureRecommendation[];
|
|
780
780
|
|
|
781
|
-
|
|
781
|
+
declare function formatScene(ast: DiagramAST): string;
|
|
782
|
+
|
|
783
|
+
export { ARCH_RULE_PRESETS, type AnnotationDecl, type ArchRuleType, type ArchitecturePreset, type ArchitectureRecommendation, type ArchitectureRule, type ArchitectureViolation, type AutoRepairResult, BEAT_CUE_KEYWORDS, type BeatDecl, type BeatRange, type Box, CUE_ALIASES, type CardinalPort, type Cue, DIAGRAM_TYPES, type Diagnostic, type DiagnosticIssue, type DiagramAST, type DiagramContext, type DiagramDiffResult, type DiagramType, type DiffChangeType, EDGE_OPERATORS, type EdgeDecl, type EdgeDiff, type EdgeKind, type EdgeSelector, type ExtractedBeat, type ExtractedGroup, type ExtractedNode, type FlowSegment, type GhostTextSuggestion, type GroupBoundary, type GroupDecl, type IntelliCodeItem, type IntelliCodeItemKind, type LayoutDirection, type MarkdyConfig, NODE_ALIASES, NODE_KINDS, type NodeDecl, type NodeDiff, type NodeSelector, type NodeShape, OUTPUT_PRESETS, type OutputPreset, PLAYER_FLAT_KEYS, PLAYER_GROUPS, POPULAR_TECHS, ParseError, type ParseOptions, type ParseResult, type PatternDecl, type PlayerChromeConfig, type PlayerConfig, type PlayerControlsConfig, type PlayerInteractionConfig, type PlayerOverrides, type PlayerPlaybackConfig, type PlayerProgress, type PlayerScope, type Point, type PositionedNode, type RenderPlan, type RepairPromptBundle, type ResolvedPlayer, type RoutedEdge, type RoutedPath, type RuleSeverity, SCENE_KEYS, type SceneMeta, type SemanticProfile, type SequenceActivation, type SequenceMessage, type StyleDecl, type SyntaxDiagnosticReport, TECHNICAL_NODE_KINDS, TECHNICAL_NODE_TYPES, THEMES, type TechPreset, type ThemeGeneratorOptions, type ThemeTokens, type TimedCue, type TreeBus, VISUAL_PRIMITIVE_TYPES, analyzeAndBuildRepairPrompt, applyPlayerSetting, canonicalNodeKind, classifyTechnology, compile, compilePlan, compressMarkdyToUrlHash, computeAdaptiveDimensions, damerauLevenshteinDistance, decompressMarkdyFromUrlHash, diagnoseMarkdyCode, diffDiagramASTs, extractDiagramContext, findClosestMatch, formatScene, generateThemeFromBrand, getArchitectureSuggestions, getBoxPortPosition, getIntelliCodeCompletions, humanizeId, listOutputPresets, nodeRole, parse, parseAndCompile, predictNextLineSuggestion, repairMarkdyCode, resolveArchitectureConfig, resolveOutputPreset, resolvePlayer, resolveTheme, routeOrthogonalEdge, selectOptimalPorts, validateArchitecture };
|
package/dist/index.js
CHANGED
|
@@ -5834,6 +5834,187 @@ function getArchitectureSuggestions(docText) {
|
|
|
5834
5834
|
}
|
|
5835
5835
|
return recommendations;
|
|
5836
5836
|
}
|
|
5837
|
+
|
|
5838
|
+
// src/format.ts
|
|
5839
|
+
function formatScene(ast) {
|
|
5840
|
+
const lines = [];
|
|
5841
|
+
const sceneParts = [`scene`];
|
|
5842
|
+
if (ast.meta.title) sceneParts.push(JSON.stringify(ast.meta.title));
|
|
5843
|
+
sceneParts.push(`theme=${ast.meta.theme}`);
|
|
5844
|
+
if (ast.meta.width !== 1280) sceneParts.push(`width=${ast.meta.width}`);
|
|
5845
|
+
if (ast.meta.height !== 720) sceneParts.push(`height=${ast.meta.height}`);
|
|
5846
|
+
if (ast.meta.fps !== 60) sceneParts.push(`fps=${ast.meta.fps}`);
|
|
5847
|
+
if (ast.meta.duration !== void 0) sceneParts.push(`duration=${ast.meta.duration}`);
|
|
5848
|
+
lines.push(sceneParts.join(" "));
|
|
5849
|
+
if (ast.meta.direction !== "LR") {
|
|
5850
|
+
lines.push(`layout ${ast.meta.direction}`);
|
|
5851
|
+
}
|
|
5852
|
+
for (const style of Object.values(ast.styles)) {
|
|
5853
|
+
lines.push(formatStyle(style));
|
|
5854
|
+
}
|
|
5855
|
+
for (const node of Object.values(ast.nodes)) {
|
|
5856
|
+
lines.push(formatNode(node));
|
|
5857
|
+
}
|
|
5858
|
+
for (const edge of ast.edges) {
|
|
5859
|
+
lines.push(formatEdge(edge));
|
|
5860
|
+
}
|
|
5861
|
+
for (const group of Object.values(ast.groups)) {
|
|
5862
|
+
lines.push(formatGroup(group));
|
|
5863
|
+
}
|
|
5864
|
+
for (const pattern of Object.values(ast.patterns)) {
|
|
5865
|
+
lines.push(`pattern ${pattern.name}(${pattern.params.join(", ")}):`);
|
|
5866
|
+
for (const cue of pattern.body) {
|
|
5867
|
+
lines.push(` ${formatCue(cue)}`);
|
|
5868
|
+
}
|
|
5869
|
+
lines.push("");
|
|
5870
|
+
}
|
|
5871
|
+
for (const beat of ast.beats) {
|
|
5872
|
+
lines.push(formatBeat(beat));
|
|
5873
|
+
lines.push("");
|
|
5874
|
+
}
|
|
5875
|
+
const player = formatPlayer(ast.meta.player);
|
|
5876
|
+
if (player.length > 0) {
|
|
5877
|
+
if (lines.at(-1) !== "") lines.push("");
|
|
5878
|
+
lines.push(...player);
|
|
5879
|
+
}
|
|
5880
|
+
return `${lines.join("\n").trim()}
|
|
5881
|
+
`;
|
|
5882
|
+
}
|
|
5883
|
+
function formatPlayer(player) {
|
|
5884
|
+
if (!player) return [];
|
|
5885
|
+
const groups = [
|
|
5886
|
+
["playback", [
|
|
5887
|
+
["autoplay", player.playback?.autoplay],
|
|
5888
|
+
["loop", player.playback?.loop],
|
|
5889
|
+
["rate", player.playback?.rate]
|
|
5890
|
+
]],
|
|
5891
|
+
["controls", [
|
|
5892
|
+
["play", player.controls?.play],
|
|
5893
|
+
["restart", player.controls?.restart],
|
|
5894
|
+
["prev_beat", player.controls?.prevBeat],
|
|
5895
|
+
["next_beat", player.controls?.nextBeat],
|
|
5896
|
+
["seek", player.controls?.seek],
|
|
5897
|
+
["speed", player.controls?.speed],
|
|
5898
|
+
["speeds", player.controls?.speeds?.join(" ")],
|
|
5899
|
+
["fit", player.controls?.fit],
|
|
5900
|
+
["reset_view", player.controls?.resetView],
|
|
5901
|
+
["fullscreen", player.controls?.fullscreen],
|
|
5902
|
+
["svg", player.controls?.svg],
|
|
5903
|
+
["share", player.controls?.share],
|
|
5904
|
+
["code", player.controls?.code],
|
|
5905
|
+
["theme", player.controls?.theme]
|
|
5906
|
+
]],
|
|
5907
|
+
["interaction", [
|
|
5908
|
+
["zoom", player.interaction?.zoom],
|
|
5909
|
+
["pan", player.interaction?.pan],
|
|
5910
|
+
["click_to_play", player.interaction?.clickToPlay],
|
|
5911
|
+
["double_click_to_reset", player.interaction?.doubleClickToReset],
|
|
5912
|
+
["keyboard", player.interaction?.keyboard]
|
|
5913
|
+
]],
|
|
5914
|
+
["chrome", [
|
|
5915
|
+
["badge", player.chrome?.badge],
|
|
5916
|
+
["progress", player.chrome?.progress],
|
|
5917
|
+
["color", player.chrome?.progressColor]
|
|
5918
|
+
]]
|
|
5919
|
+
];
|
|
5920
|
+
const lines = ["player:"];
|
|
5921
|
+
for (const [group, settings] of groups) {
|
|
5922
|
+
const configured = settings.filter(([, value]) => value !== void 0);
|
|
5923
|
+
if (configured.length === 0) continue;
|
|
5924
|
+
lines.push(` ${group}:`);
|
|
5925
|
+
for (const [key, value] of configured) {
|
|
5926
|
+
const formatted = typeof value === "string" && key !== "progress" ? JSON.stringify(value) : String(value);
|
|
5927
|
+
lines.push(` ${key} ${formatted}`);
|
|
5928
|
+
}
|
|
5929
|
+
}
|
|
5930
|
+
return lines.length > 1 ? lines : [];
|
|
5931
|
+
}
|
|
5932
|
+
function formatStyle(style) {
|
|
5933
|
+
const props = Object.entries(style.props).map(([k, v]) => `${k}=${formatValue(v)}`).join(" ");
|
|
5934
|
+
return `style ${style.name} = ${props}`;
|
|
5935
|
+
}
|
|
5936
|
+
function formatNode(node) {
|
|
5937
|
+
let line = `${node.kind} ${node.id}`;
|
|
5938
|
+
if (node.label !== node.id && node.label) line += ` ${JSON.stringify(node.label)}`;
|
|
5939
|
+
if (node.style) line += ` style=${node.style}`;
|
|
5940
|
+
const extraProps = Object.entries(node.props).filter(([key]) => key !== "style");
|
|
5941
|
+
for (const [key, value] of extraProps) {
|
|
5942
|
+
line += ` ${key}=${formatValue(value)}`;
|
|
5943
|
+
}
|
|
5944
|
+
return line;
|
|
5945
|
+
}
|
|
5946
|
+
function formatEdge(edge) {
|
|
5947
|
+
const op = edge.kind === "request" ? "->" : edge.kind === "response" ? "<-" : edge.kind === "event" ? "~>" : "--";
|
|
5948
|
+
const [left, right] = edge.kind === "response" ? [edge.to, edge.from] : [edge.from, edge.to];
|
|
5949
|
+
let chain = `${left} ${op} ${right}`;
|
|
5950
|
+
if (edge.label) chain += ` ${JSON.stringify(edge.label)}`;
|
|
5951
|
+
return `edge ${edge.id}: ${chain}`;
|
|
5952
|
+
}
|
|
5953
|
+
function formatGroup(group) {
|
|
5954
|
+
const label = group.label ? ` ${JSON.stringify(group.label)}` : "";
|
|
5955
|
+
return `group ${group.id}${label}: ${group.members.join(" ")}`;
|
|
5956
|
+
}
|
|
5957
|
+
function formatBeat(beat) {
|
|
5958
|
+
const label = beat.label ? ` ${JSON.stringify(beat.label)}` : "";
|
|
5959
|
+
const lines = [`beat ${beat.name}${label}:`];
|
|
5960
|
+
for (const cue of beat.cues) {
|
|
5961
|
+
lines.push(` ${formatCue(cue)}`);
|
|
5962
|
+
}
|
|
5963
|
+
return lines.join("\n");
|
|
5964
|
+
}
|
|
5965
|
+
function formatCue(cue) {
|
|
5966
|
+
if (cue.kind === "parallel") {
|
|
5967
|
+
return cue.cues.map(formatCue).join(" & ");
|
|
5968
|
+
}
|
|
5969
|
+
if (cue.kind === "flow") {
|
|
5970
|
+
let chain = "";
|
|
5971
|
+
for (let i = 0; i < cue.segments.length; i++) {
|
|
5972
|
+
const seg = cue.segments[i];
|
|
5973
|
+
const op = seg.op === "request" ? "->" : seg.op === "response" ? "<-" : seg.op === "event" ? "~>" : "--";
|
|
5974
|
+
const [left, right] = seg.op === "response" ? [seg.to, seg.from] : [seg.from, seg.to];
|
|
5975
|
+
if (i === 0) chain += left;
|
|
5976
|
+
chain += ` ${op} ${right}`;
|
|
5977
|
+
if (seg.label) chain += ` ${JSON.stringify(seg.label)}`;
|
|
5978
|
+
}
|
|
5979
|
+
if (cue.dur !== void 0) chain += ` dur=${cue.dur}s`;
|
|
5980
|
+
return chain;
|
|
5981
|
+
}
|
|
5982
|
+
if (cue.kind === "show" || cue.kind === "hide") {
|
|
5983
|
+
let line = `${cue.kind} ${cue.targets.join(" ")}`;
|
|
5984
|
+
if (cue.kind === "show" && cue.stagger !== void 0) line += ` stagger=${cue.stagger}s`;
|
|
5985
|
+
if (cue.dur !== void 0) line += ` dur=${cue.dur}s`;
|
|
5986
|
+
return line;
|
|
5987
|
+
}
|
|
5988
|
+
if (cue.kind === "glow") {
|
|
5989
|
+
let line = `glow ${cue.targets.join(" ")}`;
|
|
5990
|
+
if (cue.color) line += ` color=${cue.color}`;
|
|
5991
|
+
if (cue.strength !== void 0) line += ` strength=${cue.strength}`;
|
|
5992
|
+
if (cue.dur !== void 0) line += ` dur=${cue.dur}s`;
|
|
5993
|
+
return line;
|
|
5994
|
+
}
|
|
5995
|
+
if (cue.kind === "focus") {
|
|
5996
|
+
let line = `focus ${cue.targets.join(" ")}`;
|
|
5997
|
+
if (cue.zoom !== void 0) line += ` zoom=${cue.zoom}`;
|
|
5998
|
+
if (cue.dur !== void 0) line += ` dur=${cue.dur}s`;
|
|
5999
|
+
return line;
|
|
6000
|
+
}
|
|
6001
|
+
if (cue.kind === "frame") {
|
|
6002
|
+
let line = `frame ${cue.targets.join(" ")}`;
|
|
6003
|
+
if (cue.zoom !== void 0) line += ` zoom=${cue.zoom}`;
|
|
6004
|
+
if (cue.dur !== void 0) line += ` dur=${cue.dur}s`;
|
|
6005
|
+
return line;
|
|
6006
|
+
}
|
|
6007
|
+
if (cue.kind === "use") {
|
|
6008
|
+
const args = Object.entries(cue.args).map(([k, v]) => k.startsWith("__pos_") ? v : `${k}=${v}`).join(", ");
|
|
6009
|
+
return `use ${cue.pattern}(${args})`;
|
|
6010
|
+
}
|
|
6011
|
+
return "";
|
|
6012
|
+
}
|
|
6013
|
+
function formatValue(value) {
|
|
6014
|
+
if (typeof value === "number") return String(value);
|
|
6015
|
+
if (typeof value === "string") return value;
|
|
6016
|
+
return JSON.stringify(value);
|
|
6017
|
+
}
|
|
5837
6018
|
export {
|
|
5838
6019
|
ARCH_RULE_PRESETS,
|
|
5839
6020
|
BEAT_CUE_KEYWORDS,
|
|
@@ -5866,6 +6047,7 @@ export {
|
|
|
5866
6047
|
diffDiagramASTs,
|
|
5867
6048
|
extractDiagramContext,
|
|
5868
6049
|
findClosestMatch,
|
|
6050
|
+
formatScene,
|
|
5869
6051
|
generateThemeFromBrand,
|
|
5870
6052
|
getArchitectureSuggestions,
|
|
5871
6053
|
getBoxPortPosition,
|
package/package.json
CHANGED