sdocs 0.0.11 → 0.0.13

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/dist/app-gen.js CHANGED
@@ -58,15 +58,16 @@ mount(App, {
58
58
  }
59
59
  /** Generate a preview HTML page for an iframe snippet */
60
60
  function generatePreviewHtml(iframeVirtualId, css) {
61
+ const normHref = (href) => href.startsWith('http') ? href : href.startsWith('/') ? `/@fs${href}` : '/' + href;
61
62
  let cssLinks = '';
62
63
  if (css) {
63
64
  if (typeof css === 'string') {
64
- cssLinks = `<link rel="stylesheet" href="${css}">`;
65
+ cssLinks = `<link rel="stylesheet" href="${normHref(css)}">`;
65
66
  }
66
67
  else {
67
68
  const names = Object.keys(css);
68
69
  cssLinks = names
69
- .map((name, i) => `<link rel="stylesheet" href="${css[name]}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
70
+ .map((name, i) => `<link rel="stylesheet" href="${normHref(css[name])}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
70
71
  .join('\n\t');
71
72
  }
72
73
  }
package/dist/config.js CHANGED
@@ -22,13 +22,28 @@ export function findConfigFile(root) {
22
22
  }
23
23
  return null;
24
24
  }
25
+ /** Resolve CSS paths to absolute filesystem paths */
26
+ function resolveCssPaths(css, root) {
27
+ if (!css)
28
+ return null;
29
+ if (typeof css === 'string') {
30
+ return css.startsWith('/') || css.startsWith('http') ? css : resolve(root, css);
31
+ }
32
+ const resolved = {};
33
+ for (const [name, href] of Object.entries(css)) {
34
+ resolved[name] = href.startsWith('/') || href.startsWith('http') ? href : resolve(root, href);
35
+ }
36
+ return resolved;
37
+ }
25
38
  /** Load and resolve the sdocs config with defaults */
26
39
  export async function loadConfig(root) {
27
40
  const configPath = findConfigFile(root);
28
41
  if (!configPath)
29
42
  return { ...DEFAULTS };
30
43
  const userConfig = await importConfig(configPath);
31
- return resolveConfig(userConfig);
44
+ const resolved = resolveConfig(userConfig);
45
+ resolved.css = resolveCssPaths(resolved.css, root);
46
+ return resolved;
32
47
  }
33
48
  /** Import a config file (supports .js, .mjs, .ts via Vite) */
34
49
  async function importConfig(configPath) {
@@ -63,17 +63,26 @@ export function generateIframeComponent(absoluteImports, snippetBody) {
63
63
  ${snippetBody}
64
64
  </div>`;
65
65
  }
66
+ /** Convert a CSS path to a Vite-servable URL */
67
+ function normalizeCssHref(href) {
68
+ if (href.startsWith('http'))
69
+ return href;
70
+ // Absolute filesystem path → use Vite's /@fs/ prefix
71
+ if (href.startsWith('/'))
72
+ return `/@fs${href}`;
73
+ return '/' + href;
74
+ }
66
75
  /** Generate CSS link tags for the preview HTML */
67
76
  function generateCssLinks(css) {
68
77
  if (!css)
69
78
  return '';
70
79
  if (typeof css === 'string') {
71
- return `<link rel="stylesheet" href="${css}">`;
80
+ return `<link rel="stylesheet" href="${normalizeCssHref(css)}">`;
72
81
  }
73
82
  // Named stylesheets: first one active, rest disabled
74
83
  const names = Object.keys(css);
75
84
  return names
76
- .map((name, i) => `<link rel="stylesheet" href="${css[name]}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
85
+ .map((name, i) => `<link rel="stylesheet" href="${normalizeCssHref(css[name])}" data-sdocs-stylesheet="${name}"${i > 0 ? ' disabled' : ''}>`)
77
86
  .join('\n\t');
78
87
  }
79
88
  /** Generate the HTML page served inside the iframe */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdocs",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "A lightweight documentation tool for Svelte 5 components",
5
5
  "type": "module",
6
6
  "license": "MIT",