@chassis-ui/docs 0.3.1 → 0.3.2

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Shared Astro layouts, components, and utilities for Chassis documentation sites.
4
4
 
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Version: 0.3.1](https://img.shields.io/badge/Version-0.3.1-blue.svg)](https://www.npmjs.com/package/@chassis-ui/docs) [![npm](https://img.shields.io/npm/v/@chassis-ui/docs.svg)](https://www.npmjs.com/package/@chassis-ui/docs)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Version: 0.3.2](https://img.shields.io/badge/Version-0.3.2-blue.svg)](https://www.npmjs.com/package/@chassis-ui/docs) [![npm](https://img.shields.io/npm/v/@chassis-ui/docs.svg)](https://www.npmjs.com/package/@chassis-ui/docs)
6
6
 
7
7
  ## Overview
8
8
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chassis-ui/docs",
3
3
  "description": "Shared Astro components and layouts for Chassis documentation sites.",
4
- "version": "0.3.1",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@astrojs/markdown-remark": "^7.0.0",
48
- "@chassis-ui/css": ">=0.3.1",
48
+ "@chassis-ui/css": ">=0.3.2",
49
49
  "@pagefind/component-ui": "^1.0.0",
50
50
  "@shikijs/transformers": "^4.3.1",
51
51
  "astro": "^7.0.0",
@@ -27,6 +27,43 @@ interface Props {
27
27
 
28
28
  const { name, file, compile = false } = Astro.props
29
29
 
30
+ // Unwraps the `.__cxd_docs_sentinel__` rule(s) produced by compiling a snippet.
31
+ // A snippet can be pure declarations (`color: red;`), a directive that emits its
32
+ // own selectors (`@each ... { .foo { ... } }`), or a mix of both in the same
33
+ // block — Sass hoists any nested selector into its own sibling
34
+ // `.__cxd_docs_sentinel__ <selector>` rule, so there can be several top-level
35
+ // rules to unwrap, not just one. Walks brace depth instead of regex-matching a
36
+ // single block so every case round-trips correctly.
37
+ function unwrapSentinel(css: string): string {
38
+ const blocks: string[] = []
39
+ let i = 0
40
+ while (i < css.length) {
41
+ const braceIndex = css.indexOf('{', i)
42
+ if (braceIndex === -1) break
43
+
44
+ const selector = css.slice(i, braceIndex).trim()
45
+ let depth = 1
46
+ let j = braceIndex + 1
47
+ while (j < css.length && depth > 0) {
48
+ if (css[j] === '{') depth++
49
+ else if (css[j] === '}') depth--
50
+ j++
51
+ }
52
+ const body = css.slice(braceIndex + 1, j - 1)
53
+
54
+ if (selector === '.__cxd_docs_sentinel__') {
55
+ blocks.push(body)
56
+ } else if (selector.startsWith('.__cxd_docs_sentinel__ ')) {
57
+ const bareSelector = selector.slice('.__cxd_docs_sentinel__ '.length)
58
+ blocks.push(`${bareSelector} {${body}}`)
59
+ } else if (selector) {
60
+ blocks.push(`${selector} {${body}}`)
61
+ }
62
+ i = j
63
+ }
64
+ return blocks.join('\n\n')
65
+ }
66
+
30
67
  if (!name || !file) {
31
68
  throw new Error(
32
69
  `Missing required parameter(s) for the '<ScssDocs />' component, expected both 'name' and 'file' but got 'name: ${name}' and 'file: ${file}'.`
@@ -68,17 +105,20 @@ try {
68
105
  ].join('\n')
69
106
 
70
107
  const result = await sass.compileStringAsync(scssInput, {
71
- loadPaths: [scssLoadPath, path.resolve(process.cwd(), 'scss/vendor')],
108
+ loadPaths: [
109
+ scssLoadPath,
110
+ path.resolve(process.cwd(), 'scss/vendor'),
111
+ // Vite's own Sass importer resolves bare npm specifiers (e.g. `@chassis-ui/tokens/...`)
112
+ // through its module resolver, independent of `loadPaths`. This raw Sass JS API call
113
+ // bypasses Vite, so `node_modules` must be added here explicitly.
114
+ path.resolve(process.cwd(), 'node_modules')
115
+ ],
72
116
  // Match the same deprecation silencing used in astro.config.ts / vite scss options
73
117
  silenceDeprecations: ['import', 'global-builtin', 'color-functions', 'if-function'] as any
74
118
  })
75
119
 
76
- // Extract the body between the sentinel braces.
77
- // Greedy [\s\S]* ensures we capture multi-property output including mixin expansions.
78
- const sentinelMatch = result.css.match(/\.__cxd_docs_sentinel__\s*\{([\s\S]*)\}/)
79
- content = sentinelMatch ? sentinelMatch[1] : result.css
120
+ content = unwrapSentinel(result.css)
80
121
  // Apply the same cx- prefix to CSS custom properties as the build's css:prefix step does.
81
- content = content.replace(/\.__cxd_docs_sentinel__\s*/g, '')
82
122
  content = content.replace(/--(?!cx-|cxd-|pf-|shell-|shiki-)([a-zA-Z][a-zA-Z0-9-]*)/g, '--cx-$1')
83
123
  } else {
84
124
  // Raw SCSS mode — Sass variable declarations, shown as-is.