@inkdropapp/theme-dev-helpers 0.3.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkdropapp/theme-dev-helpers",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "A helper module for creating themes for Inkdrop",
5
5
  "keywords": [
6
6
  "inkdrop",
@@ -24,8 +24,8 @@
24
24
  "test": "bun test"
25
25
  },
26
26
  "dependencies": {
27
- "@inkdropapp/base-ui-theme": "^0.7.3",
28
- "@inkdropapp/css": "^0.6.3",
27
+ "@inkdropapp/base-ui-theme": "^0.7.5",
28
+ "@inkdropapp/css": "^0.6.7",
29
29
  "@vitejs/plugin-react": "^6.0.2",
30
30
  "commander": "^15.0.0",
31
31
  "puppeteer": "^25.1.0",
@@ -1,3 +1,6 @@
1
1
  allowBuilds:
2
- esbuild: set this to true or false
3
- puppeteer: set this to true or false
2
+ esbuild: true
3
+ puppeteer: true
4
+ minimumReleaseAgeExclude:
5
+ - '@inkdropapp/base-ui-theme'
6
+ - '@inkdropapp/css'
@@ -1,4 +1,4 @@
1
- import themeVariableNames from '@inkdropapp/base-ui-theme/lib/variable-names.json'
1
+ import themeVariableNames from '@inkdropapp/css/ui.json'
2
2
  import { getCSSVariables } from './get-css-variables'
3
3
 
4
4
  export const VariablesPage = () => {
@@ -22,12 +22,19 @@ 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'))
28
- const themeVariableNames: string[] = (
29
- await import(`@inkdropapp/base-ui-theme/lib/variable-names.json`)
30
- ).default
37
+ const themeVariableNames: string[] = (await import(`@inkdropapp/css/ui.json`)).default
31
38
 
32
39
  const browser = await puppeteer.launch()
33
40
  const page = await browser.newPage()
@@ -41,7 +48,8 @@ async function extractPalette(outputPath: string) {
41
48
  .on('pageerror', (error) => console.error(error instanceof Error ? error.message : error))
42
49
 
43
50
  const baseUrl = pathToFileURL(process.cwd()).toString() + '/'
44
- const content = buildPreviewHTML(themePackageJson, baseUrl, appearance)
51
+ const baseStyleSheetURLs = baseStyleSheetSpecifiers.map((spec) => import.meta.resolve(spec))
52
+ const content = buildPreviewHTML(themePackageJson, baseUrl, baseStyleSheetURLs, appearance)
45
53
 
46
54
  await page.goto(baseUrl)
47
55
  await page.setContent(content)
@@ -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('always includes the Inkdrop base stylesheets', () => {
13
- const html = buildPreviewHTML({ name: 'acme' }, baseUrl)
14
- expect(html).toContain('node_modules/@inkdropapp/css/reset.css')
15
- expect(html).toContain('node_modules/@inkdropapp/css/tokens.css')
16
- expect(html).toContain('node_modules/@inkdropapp/css/tags.css')
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. A `<base href>` is
21
- * emitted so the relative `node_modules/` and `styles/` links resolve against
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
- <link rel="stylesheet" href="node_modules/@inkdropapp/css/reset.css" />
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}">