diff --git a/integrations/nuxt/server/pinceau.server.mjs b/integrations/nuxt/server/pinceau.server.mjs index 7d1dc778..26644c81 100644 --- a/integrations/nuxt/server/pinceau.server.mjs +++ b/integrations/nuxt/server/pinceau.server.mjs @@ -18,6 +18,6 @@ export default async function (nitro) { if ($pinceauSSR.options?.ssr?.runtime) { htmlContext.head.splice(2, 0, ``) } // Theme sheet - if ($pinceauSSR.options?.ssr?.theme) { htmlContext.head.splice(2, 0, ``) } + if ($pinceauSSR.options?.ssr?.theme) { htmlContext.head.splice(2, 0, ``) } }) } diff --git a/integrations/react/src/unplugin.ts b/integrations/react/src/unplugin.ts index 475a7c55..72938021 100644 --- a/integrations/react/src/unplugin.ts +++ b/integrations/react/src/unplugin.ts @@ -4,6 +4,7 @@ import { createUnplugin } from 'unplugin' import type { UnpluginInstance } from 'unplugin' import { suite } from './transforms/suite' import { registerVirtualOutputs } from './utils/virtual' +import { pluginTypes } from './utils/plugin-types' export { registerVirtualOutputs } @@ -21,16 +22,7 @@ export const PinceauReactPlugin: UnpluginInstance = createUnplugin(() registerVirtualOutputs(ctx) - ctx.addTypes({ - imports: [ - 'import type { ReactStyledComponentFactory } from \'@pinceau/react\'', - ], - global: [ - 'export const $styled: { [Type in SupportedHTMLElements]: ReactStyledComponentFactory }', - ], - raw: [ - ], - }) + ctx.addTypes(pluginTypes) }, }, diff --git a/integrations/react/src/utils.ts b/integrations/react/src/utils.ts index 0f13749d..f0504938 100644 --- a/integrations/react/src/utils.ts +++ b/integrations/react/src/utils.ts @@ -1,2 +1,3 @@ export * from './utils/runtime-plugin' export * from './utils/virtual' +export * from './utils/plugin-types' diff --git a/integrations/react/src/utils/plugin-types.ts b/integrations/react/src/utils/plugin-types.ts new file mode 100644 index 00000000..b49b1397 --- /dev/null +++ b/integrations/react/src/utils/plugin-types.ts @@ -0,0 +1,10 @@ +export const pluginTypes = { + imports: [ + 'import type { ReactStyledComponentFactory } from \'@pinceau/react\'', + ], + global: [ + 'export const $styled: { [Type in SupportedHTMLElements]: ReactStyledComponentFactory }', + ], + raw: [ + ], +} diff --git a/integrations/repl/public/react-plugin-proxy.js b/integrations/repl/public/react-plugin-proxy.js index c305d9d1..edaa9023 100644 --- a/integrations/repl/public/react-plugin-proxy.js +++ b/integrations/repl/public/react-plugin-proxy.js @@ -1,20 +1,7 @@ -import { useRuntimeSheet, useThemeSheet } from '@pinceau/runtime' +const PinceauProvider = window.__modules__['@pinceau/outputs/react-plugin'].PinceauProvider -export const PinceauReactOptions = { dev: false, colorSchemeMode: 'media', computedStyles: true, variants: true, ssr: { theme: true, runtime: true }, appId: false } +const PinceauReactOptions = window.__modules__['@pinceau/outputs/react-plugin'].PinceauReactOptions -export const PinceauContext = React.createContext() +const usePinceauContext = window.__modules__['@pinceau/outputs/react-plugin'].usePinceauContext -export const usePinceauContext = () => React.useContext(PinceauContext) - -export function PinceauProvider({ options, children, cb }) { - const userOptions = { ...PinceauReactOptions, ...options } - - const themeSheet = useThemeSheet(userOptions) - const runtimeSheet = useRuntimeSheet({ themeSheet, ...userOptions }) - - const ssr = { toString: () => runtimeSheet.toString() } - - if (cb) { cb(ssr) } - - return React.createElement(PinceauContext.Provider, { value: { themeSheet, runtimeSheet, ssr }, children }) -} +export { PinceauProvider, PinceauReactOptions, usePinceauContext } diff --git a/integrations/repl/public/svelte-plugin-proxy.js b/integrations/repl/public/svelte-plugin-proxy.js index f5501d20..e52eda53 100644 --- a/integrations/repl/public/svelte-plugin-proxy.js +++ b/integrations/repl/public/svelte-plugin-proxy.js @@ -1,20 +1,11 @@ -import { useRuntimeSheet, useThemeSheet } from '@pinceau/runtime' +const getThemeSheet = window.__modules__['@pinceau/outputs/svelte-plugin'].getThemeSheet -export const PinceauSvelteOptions = { dev: false, colorSchemeMode: 'media', computedStyles: true, variants: true, ssr: { theme: true, runtime: true }, appId: false } +const getRuntimeSheet = window.__modules__['@pinceau/outputs/svelte-plugin'].getRuntimeSheet -let userOptions +const PinceauSvelteOptions = window.__modules__['@pinceau/outputs/svelte-plugin'].PinceauSvelteOptions -let themeSheet -export const getRuntimeSheet = () => runtimeSheet +const pinceauPlugin = window.__modules__['@pinceau/outputs/svelte-plugin'].pinceauPlugin -let runtimeSheet -export const getThemeSheet = () => themeSheet +const ssr = window.__modules__['@pinceau/outputs/svelte-plugin'].ssr -export function pinceauPlugin(options) { - userOptions = { ...PinceauSvelteOptions, ...options } - - themeSheet = useThemeSheet(userOptions) - runtimeSheet = useRuntimeSheet({ themeSheet, ...userOptions }) -} - -export const ssr = { toString: () => runtimeSheet.toString() } +export { getThemeSheet, getRuntimeSheet, PinceauSvelteOptions, pinceauPlugin, ssr } diff --git a/integrations/repl/public/vue-plugin-proxy.js b/integrations/repl/public/vue-plugin-proxy.js index 9f78b2a6..3768c341 100644 --- a/integrations/repl/public/vue-plugin-proxy.js +++ b/integrations/repl/public/vue-plugin-proxy.js @@ -1,17 +1,5 @@ -import { useRuntimeSheet, useThemeSheet } from '@pinceau/runtime' +const PinceauVueOptions = window.__modules__['@pinceau/outputs/vue-plugin'].PinceauVueOptions -export const PinceauVueOptions = { dev: false, colorSchemeMode: 'media', computedStyles: true, variants: true, ssr: { theme: true, runtime: true }, appId: false } +const PinceauVue = window.__modules__['@pinceau/outputs/vue-plugin'].PinceauVue -export const PinceauVue = { - install(app, options = {}) { - const _options = { ...PinceauVueOptions, ...options } - - const themeSheet = useThemeSheet(_options) - app.provide('pinceauThemeSheet', themeSheet) - - const runtimeSheet = useRuntimeSheet({ themeSheet, ..._options }) - app.provide('pinceauRuntimeSheet', runtimeSheet) - - app.config.globalProperties.$pinceauSSR = { toString: () => runtimeSheet.toString() } - }, -} +export { PinceauVueOptions, PinceauVue } diff --git a/integrations/repl/src/Logo full.svg b/integrations/repl/src/Logo full.svg deleted file mode 100644 index dee43c1a..00000000 --- a/integrations/repl/src/Logo full.svg +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/integrations/repl/src/compiler/index.ts b/integrations/repl/src/compiler/index.ts index c6a4fb67..e8b16943 100644 --- a/integrations/repl/src/compiler/index.ts +++ b/integrations/repl/src/compiler/index.ts @@ -45,7 +45,7 @@ const dynamicImportKey = '__dynamic_import__' const moduleKey = '__module__' // similar logic with Vite's SSR transform, except this is targeting the browser -function processFile( +export function processFile( store: Store, file: File, processed: string[], @@ -104,7 +104,7 @@ function processChildFiles( } } -function processModule(store: Store, src: string, filename: string) { +export function processModule(store: Store, src: string, filename: string) { const s = new MagicString(src) const ast = babelParse(src, { @@ -130,6 +130,17 @@ function processModule(store: Store, src: string, filename: string) { function defineImport(node: Node, source: string) { const filename = resolveImport(source.replace(/^\.\/+/, 'src/')) + + if (source.includes('@pinceau/outputs')) { + const id = `__import_${importedFiles.size}__` + importToIdMap.set(source, id) + s.appendLeft( + node.start!, + `const ${id} = ${modulesKey}[${JSON.stringify(source)}]\n`, + ) + return id + } + if (!filename) { throw new Error(`File "${source}" does not exist.`) } if (importedFiles.has(filename)) { return importToIdMap.get(filename)! } @@ -162,7 +173,8 @@ function processModule(store: Store, src: string, filename: string) { // import * as ok from 'foo' --> ok -> __import_foo__ if (node.type === 'ImportDeclaration') { const source = node.source.value - if (source.startsWith('./')) { + + if (source.startsWith('./') || source.startsWith('@pinceau/outputs')) { const importId = defineImport(node, node.source.value) for (const spec of node.specifiers) { if (spec.type === 'ImportSpecifier') { diff --git a/integrations/repl/src/components/Dropdown.vue b/integrations/repl/src/components/Dropdown.vue index 10a988a6..45c5f70d 100644 --- a/integrations/repl/src/components/Dropdown.vue +++ b/integrations/repl/src/components/Dropdown.vue @@ -25,7 +25,7 @@ function onChange(e: Event): void {