@inkdropapp/theme-dev-helpers 0.3.9 → 0.3.10
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 +1 -1
- package/pnpm-workspace.yaml +2 -2
- package/src/dev-server/variables.tsx +1 -1
- package/src/generate-palette.ts +11 -1
- package/src/palette.test.ts +17 -13
- package/src/palette.ts +14 -7
package/package.json
CHANGED
package/pnpm-workspace.yaml
CHANGED
package/src/generate-palette.ts
CHANGED
|
@@ -22,6 +22,15 @@ const options = program.opts()
|
|
|
22
22
|
const outputPath = options.output as string
|
|
23
23
|
const appearance = options.appearance as 'light' | 'dark' | undefined
|
|
24
24
|
|
|
25
|
+
const baseStyleSheetSpecifiers = [
|
|
26
|
+
'@inkdropapp/css/reset.css',
|
|
27
|
+
'@inkdropapp/css/tokens.css',
|
|
28
|
+
'@inkdropapp/css/ui.css',
|
|
29
|
+
'@inkdropapp/css/tags.css',
|
|
30
|
+
'@inkdropapp/css/status.css',
|
|
31
|
+
'@inkdropapp/base-ui-theme/styles/theme.css'
|
|
32
|
+
]
|
|
33
|
+
|
|
25
34
|
// Function to extract theme CSS variables
|
|
26
35
|
async function extractPalette(outputPath: string) {
|
|
27
36
|
const themePackageJson = await import(path.join(process.cwd(), 'package.json'))
|
|
@@ -39,7 +48,8 @@ async function extractPalette(outputPath: string) {
|
|
|
39
48
|
.on('pageerror', (error) => console.error(error instanceof Error ? error.message : error))
|
|
40
49
|
|
|
41
50
|
const baseUrl = pathToFileURL(process.cwd()).toString() + '/'
|
|
42
|
-
const
|
|
51
|
+
const baseStyleSheetURLs = baseStyleSheetSpecifiers.map((spec) => import.meta.resolve(spec))
|
|
52
|
+
const content = buildPreviewHTML(themePackageJson, baseUrl, baseStyleSheetURLs, appearance)
|
|
43
53
|
|
|
44
54
|
await page.goto(baseUrl)
|
|
45
55
|
await page.setContent(content)
|
package/src/palette.test.ts
CHANGED
|
@@ -3,46 +3,50 @@ import { buildPreviewHTML, mapThemeVariables } from './palette'
|
|
|
3
3
|
|
|
4
4
|
describe('buildPreviewHTML', () => {
|
|
5
5
|
const baseUrl = 'file:///themes/acme/'
|
|
6
|
+
const baseStyleSheetURLs = [
|
|
7
|
+
'file:///pkgs/@inkdropapp/css/reset.css',
|
|
8
|
+
'file:///pkgs/@inkdropapp/base-ui-theme/styles/theme.css'
|
|
9
|
+
]
|
|
6
10
|
|
|
7
|
-
test('emits the base href so relative links resolve', () => {
|
|
8
|
-
const html = buildPreviewHTML({ name: 'acme' }, baseUrl)
|
|
11
|
+
test('emits the base href so relative theme links resolve', () => {
|
|
12
|
+
const html = buildPreviewHTML({ name: 'acme' }, baseUrl, [])
|
|
9
13
|
expect(html).toContain(`<base href="${baseUrl}" />`)
|
|
10
14
|
})
|
|
11
15
|
|
|
12
|
-
test('
|
|
13
|
-
const html = buildPreviewHTML({ name: 'acme' }, baseUrl)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
expect(html).toContain('node_modules/@inkdropapp/base-ui-theme/styles/theme.css')
|
|
16
|
+
test('links each resolved Inkdrop base stylesheet as an absolute URL', () => {
|
|
17
|
+
const html = buildPreviewHTML({ name: 'acme' }, baseUrl, baseStyleSheetURLs)
|
|
18
|
+
for (const href of baseStyleSheetURLs) {
|
|
19
|
+
expect(html).toContain(`<link rel="stylesheet" href="${href}" />`)
|
|
20
|
+
}
|
|
18
21
|
})
|
|
19
22
|
|
|
20
23
|
test('links each declared theme stylesheet under styles/', () => {
|
|
21
24
|
const html = buildPreviewHTML(
|
|
22
25
|
{ name: 'acme', styleSheets: ['base.css', 'syntax.css'] },
|
|
23
|
-
baseUrl
|
|
26
|
+
baseUrl,
|
|
27
|
+
[]
|
|
24
28
|
)
|
|
25
29
|
expect(html).toContain('<link rel="stylesheet" href="styles/base.css" />')
|
|
26
30
|
expect(html).toContain('<link rel="stylesheet" href="styles/syntax.css" />')
|
|
27
31
|
})
|
|
28
32
|
|
|
29
33
|
test('omits theme stylesheet links when none are declared', () => {
|
|
30
|
-
const html = buildPreviewHTML({ name: 'acme' }, baseUrl)
|
|
34
|
+
const html = buildPreviewHTML({ name: 'acme' }, baseUrl, [])
|
|
31
35
|
expect(html).not.toContain('href="styles/')
|
|
32
36
|
})
|
|
33
37
|
|
|
34
38
|
test('sets the body class to the theme name', () => {
|
|
35
|
-
const html = buildPreviewHTML({ name: 'acme-dark' }, baseUrl)
|
|
39
|
+
const html = buildPreviewHTML({ name: 'acme-dark' }, baseUrl, [])
|
|
36
40
|
expect(html).toContain('<body class="acme-dark">')
|
|
37
41
|
})
|
|
38
42
|
|
|
39
43
|
test('appends an appearance-mode class when an appearance is forced', () => {
|
|
40
|
-
const html = buildPreviewHTML({ name: 'acme' }, baseUrl, 'dark')
|
|
44
|
+
const html = buildPreviewHTML({ name: 'acme' }, baseUrl, [], 'dark')
|
|
41
45
|
expect(html).toContain('<body class="acme dark-mode">')
|
|
42
46
|
})
|
|
43
47
|
|
|
44
48
|
test('adds no appearance class when appearance is omitted', () => {
|
|
45
|
-
const html = buildPreviewHTML({ name: 'acme' }, baseUrl)
|
|
49
|
+
const html = buildPreviewHTML({ name: 'acme' }, baseUrl, [])
|
|
46
50
|
expect(html).not.toContain('-mode')
|
|
47
51
|
})
|
|
48
52
|
})
|
package/src/palette.ts
CHANGED
|
@@ -17,12 +17,17 @@ export type ThemeAppearance = 'light' | 'dark'
|
|
|
17
17
|
* compute a theme's CSS custom properties.
|
|
18
18
|
*
|
|
19
19
|
* It pulls in Inkdrop's base CSS plus the theme's own stylesheets so that the
|
|
20
|
-
* computed style of `<body>` resolves every themed variable.
|
|
21
|
-
*
|
|
20
|
+
* computed style of `<body>` resolves every themed variable. Inkdrop's base
|
|
21
|
+
* stylesheets are passed in as already-resolved absolute URLs (they live in
|
|
22
|
+
* this package's own dependencies, not the theme's), while the theme's own
|
|
23
|
+
* `styles/` links stay relative and resolve against the `<base href>` — i.e.
|
|
22
24
|
* the theme project root.
|
|
23
25
|
*
|
|
24
26
|
* @param theme - The theme package's metadata (`name`, `styleSheets`).
|
|
25
|
-
* @param baseUrl - File URL used as the document `<base href
|
|
27
|
+
* @param baseUrl - File URL used as the document `<base href>`; the theme's own
|
|
28
|
+
* `styles/` links resolve against it.
|
|
29
|
+
* @param baseStyleSheetURLs - Absolute URLs of Inkdrop's base stylesheets,
|
|
30
|
+
* resolved from this package's dependency graph by the caller.
|
|
26
31
|
* @param appearance - Optional forced appearance; adds a `<appearance>-mode`
|
|
27
32
|
* body class when provided.
|
|
28
33
|
* @returns The full HTML document as a string.
|
|
@@ -30,8 +35,13 @@ export type ThemeAppearance = 'light' | 'dark'
|
|
|
30
35
|
export function buildPreviewHTML(
|
|
31
36
|
theme: ThemePackage,
|
|
32
37
|
baseUrl: string,
|
|
38
|
+
baseStyleSheetURLs: string[],
|
|
33
39
|
appearance?: ThemeAppearance
|
|
34
40
|
): string {
|
|
41
|
+
const baseCSSLinks = baseStyleSheetURLs
|
|
42
|
+
.map((href) => `<link rel="stylesheet" href="${href}" />`)
|
|
43
|
+
.join('\n')
|
|
44
|
+
|
|
35
45
|
const themeCSSLinks = (theme.styleSheets ?? [])
|
|
36
46
|
.map((filePath) => `<link rel="stylesheet" href="styles/${filePath}" />`)
|
|
37
47
|
.join('\n')
|
|
@@ -42,10 +52,7 @@ export function buildPreviewHTML(
|
|
|
42
52
|
<html>
|
|
43
53
|
<head>
|
|
44
54
|
<base href="${baseUrl}" />
|
|
45
|
-
|
|
46
|
-
<link rel="stylesheet" href="node_modules/@inkdropapp/css/tokens.css" />
|
|
47
|
-
<link rel="stylesheet" href="node_modules/@inkdropapp/css/tags.css" />
|
|
48
|
-
<link rel="stylesheet" href="node_modules/@inkdropapp/base-ui-theme/styles/theme.css" />
|
|
55
|
+
${baseCSSLinks}
|
|
49
56
|
${themeCSSLinks}
|
|
50
57
|
</head>
|
|
51
58
|
<body class="${bodyClass}">
|