@dogsbay/ui 0.2.0-beta.24 → 0.2.0-beta.25

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": "@dogsbay/ui",
3
- "version": "0.2.0-beta.24",
3
+ "version": "0.2.0-beta.25",
4
4
  "description": "Accessible UI components for Astro, inspired by Base UI and shadcn",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,9 +11,9 @@
11
11
  },
12
12
  "peerDependencies": {
13
13
  "astro": "^5.0.0 || ^6.0.0",
14
- "@dogsbay/primitives": "0.2.0-beta.24",
15
- "@dogsbay/elements": "0.2.0-beta.24",
16
- "@dogsbay/icons": "0.2.0-beta.24"
14
+ "@dogsbay/primitives": "0.2.0-beta.25",
15
+ "@dogsbay/elements": "0.2.0-beta.25",
16
+ "@dogsbay/icons": "0.2.0-beta.25"
17
17
  },
18
18
  "optionalDependencies": {
19
19
  "shiki": "^4.0.0",
@@ -126,7 +126,7 @@ function inlineToHtml(nodes: InlineNode[]): string {
126
126
  case "code": return `<code>${n.text || ""}</code>`;
127
127
  case "highlight": return `<mark>${inlineToHtml((n.children || []) as InlineNode[])}</mark>`;
128
128
  case "link": return `<a href="${n.href || ""}">${inlineToHtml((n.children || []) as InlineNode[])}</a>`;
129
- case "image": return `<img src="${n.src || ""}" alt="${n.alt || ""}">`;
129
+ case "image": return `<img src="${withBaseUrl(n.src as string | undefined)}" alt="${n.alt || ""}">`;
130
130
  case "kbd": return (n.keys as string[] || []).map((k: string) => `<kbd>${k}</kbd>`).join("+");
131
131
  case "html-inline": return String(n.html || "");
132
132
  case "break": return "<br>";
@@ -142,6 +142,26 @@ function resolveImage(src: string): ImageMetadata | undefined {
142
142
  const clean = normalized.replace(/#.*$/, "");
143
143
  return images[clean];
144
144
  }
145
+
146
+ /**
147
+ * Prefix Astro's `base` config (= urlBase from site.url's path)
148
+ * onto absolute image paths so they resolve on subpath-mounted
149
+ * deploys. Skip for external / data: / already-prefixed URLs.
150
+ * See plans/content-assets-folder.md.
151
+ */
152
+ function withBaseUrl(src: string | undefined): string {
153
+ if (!src) return "";
154
+ const baseUrl = import.meta.env.BASE_URL.replace(/\/$/, "");
155
+ if (
156
+ !baseUrl ||
157
+ !src.startsWith("/") ||
158
+ src.startsWith(`${baseUrl}/`) ||
159
+ /^(?:[a-z]+:|\/\/)/i.test(src)
160
+ ) {
161
+ return src;
162
+ }
163
+ return `${baseUrl}${src}`;
164
+ }
145
165
  ---
146
166
 
147
167
  {/* ── Prose ──────────────────────────────────────────────── */}
@@ -296,11 +316,14 @@ function resolveImage(src: string): ImageMetadata | undefined {
296
316
  {node.type === "hr" && <hr class="my-8 border-border" />}
297
317
  {node.type === "html" && (() => {
298
318
  let html = node.html || "";
299
- if (html.includes("<img") && Object.keys(images).length > 0) {
319
+ if (html.includes("<img")) {
300
320
  html = html.replace(/src="([^"]+)"/g, (_match: string, src: string) => {
301
321
  const resolved = resolveImage(src);
302
322
  if (resolved) return `src="${resolved.src}" width="${resolved.width}" height="${resolved.height}"`;
303
- return _match;
323
+ // Not in the glob (SVG / PDF / build-without-optimization) —
324
+ // prefix BASE_URL so absolute paths resolve on subpath deploys.
325
+ const prefixed = withBaseUrl(src);
326
+ return prefixed === src ? _match : `src="${prefixed}"`;
304
327
  });
305
328
  }
306
329
  return <Fragment set:html={html} />;
@@ -47,6 +47,24 @@ function resolveImage(src: string): ImageMetadata | undefined {
47
47
 
48
48
  const resolvedImg = node.type === "image" ? resolveImage(node.src as string || "") : undefined;
49
49
 
50
+ // When the image isn't in the glob map (SVG, PDF, or built with
51
+ // imageOptimization: false), the `<img src={node.src}>` fallback
52
+ // fires below. Prefix Astro's `base` for absolute paths so they
53
+ // resolve on subpath-mounted deploys. See plans/content-assets-folder.md.
54
+ function withBaseUrl(src: string | undefined): string {
55
+ if (!src) return "";
56
+ const baseUrl = import.meta.env.BASE_URL.replace(/\/$/, "");
57
+ if (
58
+ !baseUrl ||
59
+ !src.startsWith("/") ||
60
+ src.startsWith(`${baseUrl}/`) ||
61
+ /^(?:[a-z]+:|\/\/)/i.test(src)
62
+ ) {
63
+ return src;
64
+ }
65
+ return `${baseUrl}${src}`;
66
+ }
67
+
50
68
  // Icon resolution
51
69
  const iconSvg = node.type === "icon" && icons
52
70
  ? icons.resolve(node.library || "emoji", node.name, node.variant, node.size) as string | null
@@ -90,7 +108,7 @@ const isEmojiIcon = node.type === "icon" && (node.library === "emoji" || (iconSv
90
108
  )}
91
109
  {node.type === "image" && !resolvedImg && (
92
110
  <img
93
- src={node.src}
111
+ src={withBaseUrl(node.src as string | undefined)}
94
112
  alt={node.alt || ""}
95
113
  title={node.title}
96
114
  width={node.width}
@@ -47,6 +47,27 @@ const captionText = caption || title;
47
47
  const w = width || (imageData ? imageData.width : undefined);
48
48
  const h = height || (imageData ? imageData.height : undefined);
49
49
 
50
+ // When `imageData` is unavailable (image not in import.meta.glob —
51
+ // e.g. SVG, PDF, or build-time `imageOptimization: false`), the
52
+ // `<img src={src}>` fallback fires with the raw markdown src. For
53
+ // absolute paths like `/_assets/foo.png`, we need to prefix with
54
+ // Astro's `base` so the URL resolves on subpath-mounted deploys
55
+ // (GH Pages project pages, multi-mount Cloudflare).
56
+ //
57
+ // `<AstroImage>` does this automatically; raw `<img>` does not.
58
+ //
59
+ // Skip prefixing for: external URLs (http/https), data: URIs,
60
+ // and paths that already start with `import.meta.env.BASE_URL`
61
+ // (defensive; shouldn't normally happen).
62
+ const baseUrl = import.meta.env.BASE_URL.replace(/\/$/, "");
63
+ const resolvedSrc =
64
+ baseUrl &&
65
+ src.startsWith("/") &&
66
+ !src.startsWith(`${baseUrl}/`) &&
67
+ !/^(?:[a-z]+:|\/\/)/i.test(src)
68
+ ? `${baseUrl}${src}`
69
+ : src;
70
+
50
71
  const alignClass = align === "left"
51
72
  ? "float-left mr-4 mb-2"
52
73
  : align === "right"
@@ -71,7 +92,7 @@ const alignClass = align === "left"
71
92
  />
72
93
  ) : (
73
94
  <img
74
- src={src}
95
+ src={resolvedSrc}
75
96
  alt={alt}
76
97
  title={title}
77
98
  width={w}