hd-garden 0.14.10 → 0.14.12

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,20 +1,40 @@
1
+ "use client";
2
+
3
+ import { useLayoutEffect, useRef } from "react";
1
4
  import { splitTitle, titleLineScale } from "../../ui/garden/title.mjs";
5
+ import { mountArticleTitle } from "../../ui/garden/article-title-fit.mjs";
6
+ import fitRuntime from "../../ui/garden/feature-title-fit.mjs?raw";
7
+ import articleRuntime from "../../ui/garden/article-title-fit.mjs?raw";
8
+
9
+ // Preserve one authored runtime across SSR/browser builds; function.toString()
10
+ // would be changed independently by server and client optimizers.
11
+ const ARTICLE_TITLE_BOOT = `(()=>{${fitRuntime.replace(/^export /gm, "")}
12
+ ${articleRuntime.replace(/^import\s+[^;]+;\s*/u, "").replace(/^export /gm, "")}
13
+ mountArticleTitle(document.currentScript.parentElement);})();`;
2
14
 
3
15
  export function ArticleTitle({ title, className = "" }: { title: string; className?: string }) {
16
+ const heading = useRef<HTMLHeadingElement>(null);
4
17
  const split = splitTitle(title);
18
+ useLayoutEffect(() => mountArticleTitle(heading.current?.parentElement), [title]);
5
19
  if (!split.split) {
6
20
  return <h1 className={`p-name${className ? ` ${className}` : ""}`}>{title}</h1>;
7
21
  }
8
22
  const scale = titleLineScale(split.lines);
9
23
  return (
10
- <h1 className={`p-name h1-br${className ? ` ${className}` : ""}`} style={{ ["--l" as string]: scale }}>
11
- <span className="h1-line">{split.lines[0]}</span>
12
- <span className="vh">{split.separator}</span>
13
- <span className="h1-line">{split.lines[1]}</span>
14
- </h1>
24
+ <>
25
+ <h1
26
+ id="at"
27
+ ref={heading}
28
+ data-article-title=""
29
+ className={`p-name h1-br${className ? ` ${className}` : ""}`}
30
+ style={{ ["--l" as string]: scale }}
31
+ >
32
+ <span className="h1-line">{split.lines[0]}</span>
33
+ <span className="vh">{split.separator}</span>
34
+ <span className="h1-line">{split.lines[1]}</span>
35
+ </h1>
36
+ <style data-article-title-rules="">{""}</style>
37
+ <script data-article-title-boot="" dangerouslySetInnerHTML={{ __html: ARTICLE_TITLE_BOOT }} />
38
+ </>
15
39
  );
16
40
  }
17
-
18
- export function originalUrl(entry: { original?: unknown }) {
19
- return typeof entry.original === "string" && /^https?:\/\//iu.test(entry.original) ? entry.original : "";
20
- }
@@ -2,7 +2,8 @@ import Link from "next/link";
2
2
  import { CoverImage } from "./CoverImage";
3
3
  import { ArticleMeasure } from "./ArticleMeasure";
4
4
  import { ArticleReferences } from "./ArticleReferences";
5
- import { ArticleTitle, originalUrl } from "./ArticleTitle";
5
+ import { ArticleTitle } from "./ArticleTitle";
6
+ import { originalUrl } from "../../ui/garden/title.mjs";
6
7
  import { MarkdownArticle } from "./MarkdownArticle";
7
8
  import { TableOfContents } from "./TableOfContents";
8
9
  import { Comments } from "./Comments";