@limcpf/everything-is-a-markdown 0.6.4 → 0.6.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limcpf/everything-is-a-markdown",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "type": "module",
package/src/build.ts CHANGED
@@ -737,7 +737,11 @@ function pickHomeDoc(docs: DocRecord[]): DocRecord | null {
737
737
  const inDefaultBranch = docs.filter((doc) => doc.branch == null || doc.branch === DEFAULT_BRANCH);
738
738
  const candidates = inDefaultBranch.length > 0 ? inDefaultBranch : docs;
739
739
  const byRoute = candidates.find((doc) => doc.route === "/index/");
740
- return byRoute ?? candidates[0] ?? null;
740
+ if (byRoute) {
741
+ return byRoute;
742
+ }
743
+
744
+ return [...candidates].sort(compareByRecentDateThenPath)[0] ?? null;
741
745
  }
742
746
 
743
747
  function buildPinnedMenuFolder(docs: DocRecord[], options: BuildOptions): FolderNode | null {
@@ -67,6 +67,8 @@
67
67
  --content-heading-accent-soft: rgba(136, 57, 239, 0.32);
68
68
  --content-heading-subtle: var(--latte-subtext1);
69
69
  --content-visual-max-width: 720px;
70
+ --mermaid-wide-max-width: 640px;
71
+ --mermaid-tall-max-height: 560px;
70
72
  --desktop-sidebar-default: 420px;
71
73
  --desktop-sidebar-min: 320px;
72
74
  --desktop-viewer-min: 680px;
@@ -1102,6 +1104,9 @@ body.mobile-toggle-left .mobile-menu-toggle {
1102
1104
  .viewer-content .mermaid-block {
1103
1105
  margin: 1.5rem 0;
1104
1106
  padding: 16px 18px;
1107
+ max-width: min(100%, var(--content-visual-max-width));
1108
+ margin-left: auto;
1109
+ margin-right: auto;
1105
1110
  border-radius: 12px;
1106
1111
  border: 1px solid var(--latte-surface0);
1107
1112
  background: linear-gradient(180deg, var(--latte-base), var(--latte-mantle));
@@ -1142,6 +1147,14 @@ body.mobile-toggle-left .mobile-menu-toggle {
1142
1147
  margin: 0 auto;
1143
1148
  }
1144
1149
 
1150
+ .viewer-content .mermaid-block.is-wide pre.mermaid[data-mermaid-rendered="true"] svg {
1151
+ max-width: min(100%, var(--mermaid-wide-max-width));
1152
+ }
1153
+
1154
+ .viewer-content .mermaid-block.is-tall pre.mermaid[data-mermaid-rendered="true"] svg {
1155
+ max-height: min(var(--mermaid-tall-max-height), 68vh);
1156
+ }
1157
+
1145
1158
  .viewer-content .mermaid-block .mermaid-render-error {
1146
1159
  margin: 12px 0 0;
1147
1160
  padding: 10px 12px;
@@ -22,6 +22,10 @@ const MERMAID_SELECTOR = "pre.mermaid";
22
22
  const MERMAID_ERROR_CLASS = "mermaid-render-error";
23
23
  const MERMAID_THEME_VALIDATION_RE = /^[a-zA-Z][a-zA-Z0-9._-]*$/;
24
24
  const MERMAID_URL_VALIDATION_RE = /^(https?:\/\/|\/|\.{1,2}\/)[^\s"'<>]+$/;
25
+ const MERMAID_WIDE_RATIO = 2.4;
26
+ const MERMAID_TALL_RATIO = 0.85;
27
+ const MERMAID_BLOCK_WIDE_CLASS = "is-wide";
28
+ const MERMAID_BLOCK_TALL_CLASS = "is-tall";
25
29
  const mermaidRuntime = {
26
30
  initialized: false,
27
31
  loadingPromise: null,
@@ -109,16 +113,47 @@ function normalizeRenderedMermaidSvg(block) {
109
113
  return;
110
114
  }
111
115
 
116
+ const container = block.parentElement instanceof HTMLElement ? block.parentElement : null;
112
117
  const svg = block.querySelector("svg");
113
118
  if (!(svg instanceof SVGElement)) {
114
119
  return;
115
120
  }
116
121
 
122
+ if (container) {
123
+ container.classList.remove(MERMAID_BLOCK_WIDE_CLASS, MERMAID_BLOCK_TALL_CLASS);
124
+ }
125
+
117
126
  svg.style.display = "block";
118
127
  svg.style.width = "auto";
119
128
  svg.style.height = "auto";
120
129
  svg.style.margin = "0 auto";
121
130
  svg.style.maxWidth = "min(100%, var(--content-visual-max-width, 720px))";
131
+ svg.style.removeProperty("max-height");
132
+
133
+ const viewBox = svg.viewBox?.baseVal;
134
+ const intrinsicWidth =
135
+ viewBox && Number.isFinite(viewBox.width) && viewBox.width > 0
136
+ ? viewBox.width
137
+ : Number.parseFloat(svg.getAttribute("width") ?? "");
138
+ const intrinsicHeight =
139
+ viewBox && Number.isFinite(viewBox.height) && viewBox.height > 0
140
+ ? viewBox.height
141
+ : Number.parseFloat(svg.getAttribute("height") ?? "");
142
+
143
+ if (!(intrinsicWidth > 0) || !(intrinsicHeight > 0)) {
144
+ return;
145
+ }
146
+
147
+ const aspectRatio = intrinsicWidth / intrinsicHeight;
148
+ if (container && aspectRatio >= MERMAID_WIDE_RATIO) {
149
+ container.classList.add(MERMAID_BLOCK_WIDE_CLASS);
150
+ svg.style.maxWidth = "min(100%, var(--mermaid-wide-max-width, 640px))";
151
+ }
152
+
153
+ if (container && aspectRatio <= MERMAID_TALL_RATIO) {
154
+ container.classList.add(MERMAID_BLOCK_TALL_CLASS);
155
+ svg.style.maxHeight = "min(var(--mermaid-tall-max-height, 560px), 68vh)";
156
+ }
122
157
  }
123
158
 
124
159
  function parseMermaidNodes() {
@@ -134,6 +169,7 @@ function resetMermaidNodes(nodes) {
134
169
  for (const node of nodes) {
135
170
  node.removeAttribute("data-mermaid-rendered");
136
171
  if (node.parentElement instanceof HTMLElement) {
172
+ node.parentElement.classList.remove(MERMAID_BLOCK_WIDE_CLASS, MERMAID_BLOCK_TALL_CLASS);
137
173
  removeMermaidErrorMessage(node.parentElement);
138
174
  }
139
175
  }
@@ -472,6 +508,37 @@ function isDocVisibleInBranch(doc, branch, defaultBranch) {
472
508
  return docBranch === branch;
473
509
  }
474
510
 
511
+ function parseDateToEpochMs(value) {
512
+ if (typeof value !== "string" || value.trim().length === 0) {
513
+ return null;
514
+ }
515
+
516
+ const parsed = Date.parse(value);
517
+ return Number.isFinite(parsed) ? parsed : null;
518
+ }
519
+
520
+ function getRecentSortEpochMs(doc) {
521
+ return parseDateToEpochMs(doc.updatedDate) ?? parseDateToEpochMs(doc.date);
522
+ }
523
+
524
+ function compareDocsByRecentDateThenRoute(left, right) {
525
+ const leftEpoch = getRecentSortEpochMs(left);
526
+ const rightEpoch = getRecentSortEpochMs(right);
527
+
528
+ if (leftEpoch != null && rightEpoch != null) {
529
+ const byDate = rightEpoch - leftEpoch;
530
+ if (byDate !== 0) {
531
+ return byDate;
532
+ }
533
+ } else if (leftEpoch != null && rightEpoch == null) {
534
+ return -1;
535
+ } else if (leftEpoch == null && rightEpoch != null) {
536
+ return 1;
537
+ }
538
+
539
+ return left.route.localeCompare(right.route, "ko-KR");
540
+ }
541
+
475
542
  function cloneFilteredTree(nodes, visibleDocIds) {
476
543
  const filteredNodes = [];
477
544
 
@@ -523,7 +590,7 @@ function pickHomeRoute(view) {
523
590
  if (view.routeMap["/index/"]) {
524
591
  return "/index/";
525
592
  }
526
- return view.docs[0]?.route || "/";
593
+ return [...view.docs].sort(compareDocsByRecentDateThenRoute)[0]?.route || "/";
527
594
  }
528
595
 
529
596
  function loadExpandedSet() {