pika-shared 1.4.12 → 1.5.0
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/types/chatbot/chatbot-types.d.mts +186 -4
- package/dist/types/chatbot/chatbot-types.d.ts +186 -4
- package/dist/types/chatbot/chatbot-types.js.map +1 -1
- package/dist/types/chatbot/chatbot-types.mjs.map +1 -1
- package/dist/types/chatbot/theme-schema.d.mts +95 -0
- package/dist/types/chatbot/theme-schema.d.ts +95 -0
- package/dist/types/chatbot/theme-schema.js +485 -0
- package/dist/types/chatbot/theme-schema.js.map +1 -0
- package/dist/types/chatbot/theme-schema.mjs +477 -0
- package/dist/types/chatbot/theme-schema.mjs.map +1 -0
- package/dist/types/chatbot/theme-types.d.mts +163 -0
- package/dist/types/chatbot/theme-types.d.ts +163 -0
- package/dist/types/chatbot/theme-types.js +62 -0
- package/dist/types/chatbot/theme-types.js.map +1 -0
- package/dist/types/chatbot/theme-types.mjs +60 -0
- package/dist/types/chatbot/theme-types.mjs.map +1 -0
- package/dist/util/server-utils.js.map +1 -1
- package/dist/util/server-utils.mjs.map +1 -1
- package/dist/util/wc-utils.d.mts +41 -1
- package/dist/util/wc-utils.d.ts +41 -1
- package/dist/util/wc-utils.js +75 -0
- package/dist/util/wc-utils.js.map +1 -1
- package/dist/util/wc-utils.mjs +74 -1
- package/dist/util/wc-utils.mjs.map +1 -1
- package/package.json +1 -1
package/dist/util/wc-utils.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PikaWCContext } from '../types/chatbot/webcomp-types.mjs';
|
|
2
|
+
import { SemanticColorVariable } from '../types/chatbot/theme-types.mjs';
|
|
2
3
|
import '../types/upload-types.mjs';
|
|
3
4
|
import '../types/chatbot/chatbot-types.mjs';
|
|
4
5
|
import '@aws-sdk/client-bedrock-agent-runtime';
|
|
@@ -18,5 +19,44 @@ import '@aws-sdk/client-bedrock-agentcore';
|
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
declare function getPikaContext(el: HTMLElement): Promise<PikaWCContext>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a single CSS variable value from the document.
|
|
24
|
+
* Useful for web components that need to read theme values.
|
|
25
|
+
*
|
|
26
|
+
* @param name - Variable name without the -- prefix (e.g., 'primary', 'background')
|
|
27
|
+
* @returns The computed value of the CSS variable, or empty string if not found
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const primaryColor = getThemeVariable('primary');
|
|
32
|
+
* console.log(primaryColor); // 'oklch(0.514 0.146 255.748)'
|
|
33
|
+
*
|
|
34
|
+
* // Use in dynamic styles - value already includes oklch()
|
|
35
|
+
* element.style.backgroundColor = getThemeVariable('primary');
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @since 0.16.0
|
|
39
|
+
*/
|
|
40
|
+
declare function getThemeVariable(name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get all Pika semantic theme tokens as an object.
|
|
43
|
+
* Useful for web components that need access to multiple theme values.
|
|
44
|
+
*
|
|
45
|
+
* Returns only the semantic color variables (primary, secondary, success, etc.),
|
|
46
|
+
* not the full palette variables (gold-500, blueish-300, etc.).
|
|
47
|
+
*
|
|
48
|
+
* @returns Object mapping variable names to their computed values
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const tokens = getPikaThemeTokens();
|
|
53
|
+
* console.log(tokens.primary); // 'oklch(0.514 0.146 255.748)'
|
|
54
|
+
* console.log(tokens.success); // 'oklch(0.55 0.16 142)'
|
|
55
|
+
* console.log(tokens['muted-foreground']); // 'oklch(0.551 0.027 264.364)'
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @since 0.16.0
|
|
59
|
+
*/
|
|
60
|
+
declare function getPikaThemeTokens(): Partial<Record<SemanticColorVariable, string>>;
|
|
21
61
|
|
|
22
|
-
export { getPikaContext };
|
|
62
|
+
export { getPikaContext, getPikaThemeTokens, getThemeVariable };
|
package/dist/util/wc-utils.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PikaWCContext } from '../types/chatbot/webcomp-types.js';
|
|
2
|
+
import { SemanticColorVariable } from '../types/chatbot/theme-types.js';
|
|
2
3
|
import '../types/upload-types.js';
|
|
3
4
|
import '../types/chatbot/chatbot-types.js';
|
|
4
5
|
import '@aws-sdk/client-bedrock-agent-runtime';
|
|
@@ -18,5 +19,44 @@ import '@aws-sdk/client-bedrock-agentcore';
|
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
21
|
declare function getPikaContext(el: HTMLElement): Promise<PikaWCContext>;
|
|
22
|
+
/**
|
|
23
|
+
* Get a single CSS variable value from the document.
|
|
24
|
+
* Useful for web components that need to read theme values.
|
|
25
|
+
*
|
|
26
|
+
* @param name - Variable name without the -- prefix (e.g., 'primary', 'background')
|
|
27
|
+
* @returns The computed value of the CSS variable, or empty string if not found
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const primaryColor = getThemeVariable('primary');
|
|
32
|
+
* console.log(primaryColor); // 'oklch(0.514 0.146 255.748)'
|
|
33
|
+
*
|
|
34
|
+
* // Use in dynamic styles - value already includes oklch()
|
|
35
|
+
* element.style.backgroundColor = getThemeVariable('primary');
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @since 0.16.0
|
|
39
|
+
*/
|
|
40
|
+
declare function getThemeVariable(name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Get all Pika semantic theme tokens as an object.
|
|
43
|
+
* Useful for web components that need access to multiple theme values.
|
|
44
|
+
*
|
|
45
|
+
* Returns only the semantic color variables (primary, secondary, success, etc.),
|
|
46
|
+
* not the full palette variables (gold-500, blueish-300, etc.).
|
|
47
|
+
*
|
|
48
|
+
* @returns Object mapping variable names to their computed values
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const tokens = getPikaThemeTokens();
|
|
53
|
+
* console.log(tokens.primary); // 'oklch(0.514 0.146 255.748)'
|
|
54
|
+
* console.log(tokens.success); // 'oklch(0.55 0.16 142)'
|
|
55
|
+
* console.log(tokens['muted-foreground']); // 'oklch(0.551 0.027 264.364)'
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @since 0.16.0
|
|
59
|
+
*/
|
|
60
|
+
declare function getPikaThemeTokens(): Partial<Record<SemanticColorVariable, string>>;
|
|
21
61
|
|
|
22
|
-
export { getPikaContext };
|
|
62
|
+
export { getPikaContext, getPikaThemeTokens, getThemeVariable };
|
package/dist/util/wc-utils.js
CHANGED
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/types/chatbot/theme-types.ts
|
|
4
|
+
var SEMANTIC_COLOR_VARIABLES = [
|
|
5
|
+
// Core
|
|
6
|
+
"background",
|
|
7
|
+
"foreground",
|
|
8
|
+
"card",
|
|
9
|
+
"card-foreground",
|
|
10
|
+
"popover",
|
|
11
|
+
"popover-foreground",
|
|
12
|
+
"primary",
|
|
13
|
+
"primary-foreground",
|
|
14
|
+
"secondary",
|
|
15
|
+
"secondary-foreground",
|
|
16
|
+
"muted",
|
|
17
|
+
"muted-foreground",
|
|
18
|
+
"accent",
|
|
19
|
+
"accent-foreground",
|
|
20
|
+
"destructive",
|
|
21
|
+
"destructive-foreground",
|
|
22
|
+
"border",
|
|
23
|
+
"input",
|
|
24
|
+
"ring",
|
|
25
|
+
// Charts
|
|
26
|
+
"chart-1",
|
|
27
|
+
"chart-2",
|
|
28
|
+
"chart-3",
|
|
29
|
+
"chart-4",
|
|
30
|
+
"chart-5",
|
|
31
|
+
// Sidebar
|
|
32
|
+
"sidebar-background",
|
|
33
|
+
"sidebar-foreground",
|
|
34
|
+
"sidebar-primary",
|
|
35
|
+
"sidebar-primary-foreground",
|
|
36
|
+
"sidebar-accent",
|
|
37
|
+
"sidebar-accent-foreground",
|
|
38
|
+
"sidebar-border",
|
|
39
|
+
"sidebar-ring",
|
|
40
|
+
// Extended
|
|
41
|
+
"success",
|
|
42
|
+
"success-foreground",
|
|
43
|
+
"success-bg",
|
|
44
|
+
"warning",
|
|
45
|
+
"warning-foreground",
|
|
46
|
+
"warning-bg",
|
|
47
|
+
"info",
|
|
48
|
+
"info-foreground",
|
|
49
|
+
"info-bg",
|
|
50
|
+
"ai",
|
|
51
|
+
"ai-foreground",
|
|
52
|
+
"ai-bg",
|
|
53
|
+
"danger-bg",
|
|
54
|
+
// Header/branding
|
|
55
|
+
"chat-app-icon",
|
|
56
|
+
"chat-app-header-icon-height",
|
|
57
|
+
"chat-app-header-icon-gap"
|
|
58
|
+
];
|
|
59
|
+
|
|
3
60
|
// src/util/wc-utils.ts
|
|
4
61
|
function getPikaContext(el) {
|
|
5
62
|
return new Promise((resolve, reject) => {
|
|
@@ -20,7 +77,25 @@ function getPikaContext(el) {
|
|
|
20
77
|
);
|
|
21
78
|
});
|
|
22
79
|
}
|
|
80
|
+
function getThemeVariable(name) {
|
|
81
|
+
if (typeof document === "undefined") return "";
|
|
82
|
+
return getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();
|
|
83
|
+
}
|
|
84
|
+
function getPikaThemeTokens() {
|
|
85
|
+
if (typeof document === "undefined") return {};
|
|
86
|
+
const style = getComputedStyle(document.documentElement);
|
|
87
|
+
const tokens = {};
|
|
88
|
+
for (const name of SEMANTIC_COLOR_VARIABLES) {
|
|
89
|
+
const value = style.getPropertyValue(`--${name}`).trim();
|
|
90
|
+
if (value) {
|
|
91
|
+
tokens[name] = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return tokens;
|
|
95
|
+
}
|
|
23
96
|
|
|
24
97
|
exports.getPikaContext = getPikaContext;
|
|
98
|
+
exports.getPikaThemeTokens = getPikaThemeTokens;
|
|
99
|
+
exports.getThemeVariable = getThemeVariable;
|
|
25
100
|
//# sourceMappingURL=wc-utils.js.map
|
|
26
101
|
//# sourceMappingURL=wc-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/wc-utils.ts"],"names":[],"mappings":";;;AAeO,SAAS,eAAe,EAAA,EAAyC;AACpE,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACpC,IAAA,MAAM,OAAA,GAAU,WAAW,MAAM;AAC7B,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,+EAA+E,CAAC,CAAA;AAAA,IACrG,GAAG,GAAI,CAAA;AAEP,IAAA,EAAA,CAAG,aAAA;AAAA,MACC,IAAI,YAAwC,yBAAA,EAA2B;AAAA,QACnE,OAAA,EAAS,IAAA;AAAA,QACT,QAAA,EAAU,IAAA;AAAA,QACV,MAAA,EAAQ;AAAA,UACJ,QAAA,EAAU,CAAC,GAAA,KAAuB;AAC9B,YAAA,YAAA,CAAa,OAAO,CAAA;AACpB,YAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,UACf;AAAA;AACJ,OACH;AAAA,KACL;AAAA,EACJ,CAAC,CAAA;AACL","file":"wc-utils.js","sourcesContent":["import { PikaWCContext, PikaWCContextRequestDetail } from '../types/chatbot/webcomp-types';\n\n/**\n * Web component authors can use this function to get the Pika context when their web component is rendered.\n *\n * The type of the context object is defined in the PikaWCContext interface.\n *\n * @see PikaWCContext\n *\n * @example\n * ```ts\n * const ctx: PikaWCContext = await getPikaContext(el);\n * console.log(ctx.appState.identity.user.fullName);\n * ```\n */\nexport function getPikaContext(el: HTMLElement): Promise<PikaWCContext> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error('Pika context not provided - component must be rendered within a Pika chat app'));\n }, 1000);\n\n el.dispatchEvent(\n new CustomEvent<PikaWCContextRequestDetail>('pika-wc-context-request', {\n bubbles: true,\n composed: true,\n detail: {\n callback: (ctx: PikaWCContext) => {\n clearTimeout(timeout);\n resolve(ctx);\n }\n }\n })\n );\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/chatbot/theme-types.ts","../../src/util/wc-utils.ts"],"names":[],"mappings":";;;AA+NO,IAAM,wBAAA,GAA6D;AAAA;AAAA,EAEtE,YAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,iBAAA;AAAA,EACA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,WAAA;AAAA,EACA,sBAAA;AAAA,EACA,OAAA;AAAA,EACA,kBAAA;AAAA,EACA,QAAA;AAAA,EACA,mBAAA;AAAA,EACA,aAAA;AAAA,EACA,wBAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA;AAAA,EAEA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA;AAAA,EAEA,oBAAA;AAAA,EACA,oBAAA;AAAA,EACA,iBAAA;AAAA,EACA,4BAAA;AAAA,EACA,gBAAA;AAAA,EACA,2BAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA;AAAA,EAEA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,iBAAA;AAAA,EACA,SAAA;AAAA,EACA,IAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA;AAAA,EAEA,eAAA;AAAA,EACA,6BAAA;AAAA,EACA;AACJ,CAAA;;;ACrQO,SAAS,eAAe,EAAA,EAAyC;AACpE,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACpC,IAAA,MAAM,OAAA,GAAU,WAAW,MAAM;AAC7B,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,+EAA+E,CAAC,CAAA;AAAA,IACrG,GAAG,GAAI,CAAA;AAEP,IAAA,EAAA,CAAG,aAAA;AAAA,MACC,IAAI,YAAwC,yBAAA,EAA2B;AAAA,QACnE,OAAA,EAAS,IAAA;AAAA,QACT,QAAA,EAAU,IAAA;AAAA,QACV,MAAA,EAAQ;AAAA,UACJ,QAAA,EAAU,CAAC,GAAA,KAAuB;AAC9B,YAAA,YAAA,CAAa,OAAO,CAAA;AACpB,YAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,UACf;AAAA;AACJ,OACH;AAAA,KACL;AAAA,EACJ,CAAC,CAAA;AACL;AAoBO,SAAS,iBAAiB,IAAA,EAAsB;AACnD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,EAAA;AAC5C,EAAA,OAAO,gBAAA,CAAiB,SAAS,eAAe,CAAA,CAAE,iBAAiB,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAA,CAAE,IAAA,EAAK;AACzF;AAqBO,SAAS,kBAAA,GAAqE;AACjF,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,EAAC;AAE7C,EAAA,MAAM,KAAA,GAAQ,gBAAA,CAAiB,QAAA,CAAS,eAAe,CAAA;AACvD,EAAA,MAAM,SAAyD,EAAC;AAEhE,EAAA,KAAA,MAAW,QAAQ,wBAAA,EAA0B;AACzC,IAAA,MAAM,QAAQ,KAAA,CAAM,gBAAA,CAAiB,KAAK,IAAI,CAAA,CAAE,EAAE,IAAA,EAAK;AACvD,IAAA,IAAI,KAAA,EAAO;AACP,MAAA,MAAA,CAAO,IAAI,CAAA,GAAI,KAAA;AAAA,IACnB;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX","file":"wc-utils.js","sourcesContent":["/**\n * Theme Types for Pika UI Customization\n *\n * These types define the structure of theme configuration for clone projects.\n * Import via: import type { ThemeConfig } from 'pika-shared/types/chatbot/theme-types';\n *\n * @since 0.16.0\n */\n\n/**\n * Theme configuration for Pika Chat\n *\n * Clone projects copy sample-purple-theme.ts, customize it, and update themeConfigPath\n * in pika-config.ts to point to their theme file.\n *\n * @example\n * ```typescript\n * import type { ThemeConfig } from 'pika-shared/types/chatbot/theme-types';\n *\n * export const themeConfig: ThemeConfig = {\n * name: 'Acme Corp Theme',\n * fontFamily: '\"Inter\", sans-serif',\n * cssVariables: {\n * light: {\n * 'primary': 'oklch(0.47 0.2 290)',\n * 'primary-foreground': 'oklch(1 0 0)',\n * },\n * dark: {\n * 'primary': 'oklch(0.70 0.18 290)',\n * }\n * }\n * };\n * ```\n *\n * @since 0.16.0\n */\nexport interface ThemeConfig {\n /**\n * Schema version of this theme configuration.\n * Used by `pika theme check` to notify you of new theme variables.\n * See theme-schema.ts for the changelog of schema versions.\n *\n * @default 1 (if not specified)\n * @example schemaVersion: 1\n */\n schemaVersion?: number;\n\n /**\n * Display name for this theme (for documentation/debugging)\n * @example 'Acme Corp Brand Theme'\n */\n name?: string;\n\n /**\n * Font family override. Applied to --font-sans CSS variable.\n * @example '\"Figtree\", Arial, Helvetica, sans-serif'\n */\n fontFamily?: string;\n\n /**\n * CSS custom properties to override.\n * Keys are CSS variable names WITHOUT the -- prefix.\n * Values should be valid CSS color values (oklch preferred for modern color handling).\n *\n * @example\n * ```typescript\n * cssVariables: {\n * light: {\n * 'primary': 'oklch(0.47 0.2 290)',\n * 'border': 'oklch(0.88 0.01 260)',\n * },\n * dark: {\n * 'primary': 'oklch(0.70 0.18 290)',\n * }\n * }\n * ```\n */\n cssVariables?: {\n /** Light mode variable overrides */\n light?: Record<string, string>;\n /** Dark mode variable overrides */\n dark?: Record<string, string>;\n };\n\n /**\n * Custom color palettes for your brand.\n * Creates CSS variables like --{paletteName}-{shade}\n *\n * @example\n * ```typescript\n * customPalettes: {\n * brand: {\n * '50': 'oklch(0.97 0.01 290)',\n * '500': 'oklch(0.47 0.2 290)',\n * '900': 'oklch(0.20 0.08 290)',\n * }\n * }\n * ```\n */\n customPalettes?: Record<string, Record<string, string>>;\n\n /**\n * Custom header icon for chat apps. Replaces the default AI sparkle icon.\n * The icon will be constrained to roughly 44x44px.\n *\n * Can be specified as:\n * - A single string URL (used for both light and dark modes)\n * - An object with separate light/dark URLs for mode-specific icons\n *\n * For sync-safe storage, place your icons in:\n * `apps/pika-chat/static/custom/assets/`\n *\n * @example Single icon for both modes:\n * ```typescript\n * chatAppHeaderIcon: '/custom/assets/my-logo.svg'\n * ```\n *\n * @example Separate icons for light/dark modes:\n * ```typescript\n * chatAppHeaderIcon: {\n * light: '/custom/assets/logo-dark.svg', // Dark logo on light background\n * dark: '/custom/assets/logo-light.svg' // Light logo on dark background\n * }\n * ```\n *\n * @since 0.16.4\n */\n chatAppHeaderIcon?: string | {\n /** Icon URL for light mode */\n light: string;\n /** Icon URL for dark mode (falls back to light if not provided) */\n dark?: string;\n };\n}\n\n/**\n * Configuration for the custom theme feature in pika-config.ts\n *\n * @since 0.16.0\n */\nexport interface CustomThemeConfig {\n /**\n * Whether custom theming is enabled.\n * If false, the default Pika theme is used and the theme config is not loaded.\n */\n enabled: boolean;\n\n /**\n * Path to theme config file relative to apps/pika-chat/\n * The file must export a `themeConfig` object of type ThemeConfig.\n *\n * @default 'src/lib/custom/sample-purple-theme'\n * @example 'src/lib/custom/my-theme' imports from 'apps/pika-chat/src/lib/custom/my-theme.ts'\n */\n themeConfigPath?: string;\n}\n\n/**\n * Standard semantic variable names that can be overridden in a theme.\n * These are the shadcn-svelte standard variables plus Pika extensions.\n *\n * @since 0.16.0\n */\nexport type SemanticColorVariable =\n // Core shadcn variables\n | 'background'\n | 'foreground'\n | 'card'\n | 'card-foreground'\n | 'popover'\n | 'popover-foreground'\n | 'primary'\n | 'primary-foreground'\n | 'secondary'\n | 'secondary-foreground'\n | 'muted'\n | 'muted-foreground'\n | 'accent'\n | 'accent-foreground'\n | 'destructive'\n | 'destructive-foreground'\n | 'border'\n | 'input'\n | 'ring'\n // Chart colors\n | 'chart-1'\n | 'chart-2'\n | 'chart-3'\n | 'chart-4'\n | 'chart-5'\n // Sidebar variants\n | 'sidebar-background'\n | 'sidebar-foreground'\n | 'sidebar-primary'\n | 'sidebar-primary-foreground'\n | 'sidebar-accent'\n | 'sidebar-accent-foreground'\n | 'sidebar-border'\n | 'sidebar-ring'\n // Pika extended semantic colors\n | 'success'\n | 'success-foreground'\n | 'success-bg'\n | 'warning'\n | 'warning-foreground'\n | 'warning-bg'\n | 'info'\n | 'info-foreground'\n | 'info-bg'\n | 'ai'\n | 'ai-foreground'\n | 'ai-bg'\n | 'danger-bg'\n // Header/branding\n | 'chat-app-icon'\n | 'chat-app-header-icon-height'\n | 'chat-app-header-icon-gap';\n\n/**\n * All semantic variables as a readonly array for iteration\n *\n * @since 0.16.0\n */\nexport const SEMANTIC_COLOR_VARIABLES: readonly SemanticColorVariable[] = [\n // Core\n 'background',\n 'foreground',\n 'card',\n 'card-foreground',\n 'popover',\n 'popover-foreground',\n 'primary',\n 'primary-foreground',\n 'secondary',\n 'secondary-foreground',\n 'muted',\n 'muted-foreground',\n 'accent',\n 'accent-foreground',\n 'destructive',\n 'destructive-foreground',\n 'border',\n 'input',\n 'ring',\n // Charts\n 'chart-1',\n 'chart-2',\n 'chart-3',\n 'chart-4',\n 'chart-5',\n // Sidebar\n 'sidebar-background',\n 'sidebar-foreground',\n 'sidebar-primary',\n 'sidebar-primary-foreground',\n 'sidebar-accent',\n 'sidebar-accent-foreground',\n 'sidebar-border',\n 'sidebar-ring',\n // Extended\n 'success',\n 'success-foreground',\n 'success-bg',\n 'warning',\n 'warning-foreground',\n 'warning-bg',\n 'info',\n 'info-foreground',\n 'info-bg',\n 'ai',\n 'ai-foreground',\n 'ai-bg',\n 'danger-bg',\n // Header/branding\n 'chat-app-icon',\n 'chat-app-header-icon-height',\n 'chat-app-header-icon-gap'\n] as const;\n","import { PikaWCContext, PikaWCContextRequestDetail } from '../types/chatbot/webcomp-types';\nimport { SEMANTIC_COLOR_VARIABLES, type SemanticColorVariable } from '../types/chatbot/theme-types';\n\n/**\n * Web component authors can use this function to get the Pika context when their web component is rendered.\n *\n * The type of the context object is defined in the PikaWCContext interface.\n *\n * @see PikaWCContext\n *\n * @example\n * ```ts\n * const ctx: PikaWCContext = await getPikaContext(el);\n * console.log(ctx.appState.identity.user.fullName);\n * ```\n */\nexport function getPikaContext(el: HTMLElement): Promise<PikaWCContext> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error('Pika context not provided - component must be rendered within a Pika chat app'));\n }, 1000);\n\n el.dispatchEvent(\n new CustomEvent<PikaWCContextRequestDetail>('pika-wc-context-request', {\n bubbles: true,\n composed: true,\n detail: {\n callback: (ctx: PikaWCContext) => {\n clearTimeout(timeout);\n resolve(ctx);\n }\n }\n })\n );\n });\n}\n\n/**\n * Get a single CSS variable value from the document.\n * Useful for web components that need to read theme values.\n *\n * @param name - Variable name without the -- prefix (e.g., 'primary', 'background')\n * @returns The computed value of the CSS variable, or empty string if not found\n *\n * @example\n * ```ts\n * const primaryColor = getThemeVariable('primary');\n * console.log(primaryColor); // 'oklch(0.514 0.146 255.748)'\n *\n * // Use in dynamic styles - value already includes oklch()\n * element.style.backgroundColor = getThemeVariable('primary');\n * ```\n *\n * @since 0.16.0\n */\nexport function getThemeVariable(name: string): string {\n if (typeof document === 'undefined') return '';\n return getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();\n}\n\n/**\n * Get all Pika semantic theme tokens as an object.\n * Useful for web components that need access to multiple theme values.\n *\n * Returns only the semantic color variables (primary, secondary, success, etc.),\n * not the full palette variables (gold-500, blueish-300, etc.).\n *\n * @returns Object mapping variable names to their computed values\n *\n * @example\n * ```ts\n * const tokens = getPikaThemeTokens();\n * console.log(tokens.primary); // 'oklch(0.514 0.146 255.748)'\n * console.log(tokens.success); // 'oklch(0.55 0.16 142)'\n * console.log(tokens['muted-foreground']); // 'oklch(0.551 0.027 264.364)'\n * ```\n *\n * @since 0.16.0\n */\nexport function getPikaThemeTokens(): Partial<Record<SemanticColorVariable, string>> {\n if (typeof document === 'undefined') return {};\n\n const style = getComputedStyle(document.documentElement);\n const tokens: Partial<Record<SemanticColorVariable, string>> = {};\n\n for (const name of SEMANTIC_COLOR_VARIABLES) {\n const value = style.getPropertyValue(`--${name}`).trim();\n if (value) {\n tokens[name] = value;\n }\n }\n\n return tokens;\n}\n"]}
|
package/dist/util/wc-utils.mjs
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
+
// src/types/chatbot/theme-types.ts
|
|
2
|
+
var SEMANTIC_COLOR_VARIABLES = [
|
|
3
|
+
// Core
|
|
4
|
+
"background",
|
|
5
|
+
"foreground",
|
|
6
|
+
"card",
|
|
7
|
+
"card-foreground",
|
|
8
|
+
"popover",
|
|
9
|
+
"popover-foreground",
|
|
10
|
+
"primary",
|
|
11
|
+
"primary-foreground",
|
|
12
|
+
"secondary",
|
|
13
|
+
"secondary-foreground",
|
|
14
|
+
"muted",
|
|
15
|
+
"muted-foreground",
|
|
16
|
+
"accent",
|
|
17
|
+
"accent-foreground",
|
|
18
|
+
"destructive",
|
|
19
|
+
"destructive-foreground",
|
|
20
|
+
"border",
|
|
21
|
+
"input",
|
|
22
|
+
"ring",
|
|
23
|
+
// Charts
|
|
24
|
+
"chart-1",
|
|
25
|
+
"chart-2",
|
|
26
|
+
"chart-3",
|
|
27
|
+
"chart-4",
|
|
28
|
+
"chart-5",
|
|
29
|
+
// Sidebar
|
|
30
|
+
"sidebar-background",
|
|
31
|
+
"sidebar-foreground",
|
|
32
|
+
"sidebar-primary",
|
|
33
|
+
"sidebar-primary-foreground",
|
|
34
|
+
"sidebar-accent",
|
|
35
|
+
"sidebar-accent-foreground",
|
|
36
|
+
"sidebar-border",
|
|
37
|
+
"sidebar-ring",
|
|
38
|
+
// Extended
|
|
39
|
+
"success",
|
|
40
|
+
"success-foreground",
|
|
41
|
+
"success-bg",
|
|
42
|
+
"warning",
|
|
43
|
+
"warning-foreground",
|
|
44
|
+
"warning-bg",
|
|
45
|
+
"info",
|
|
46
|
+
"info-foreground",
|
|
47
|
+
"info-bg",
|
|
48
|
+
"ai",
|
|
49
|
+
"ai-foreground",
|
|
50
|
+
"ai-bg",
|
|
51
|
+
"danger-bg",
|
|
52
|
+
// Header/branding
|
|
53
|
+
"chat-app-icon",
|
|
54
|
+
"chat-app-header-icon-height",
|
|
55
|
+
"chat-app-header-icon-gap"
|
|
56
|
+
];
|
|
57
|
+
|
|
1
58
|
// src/util/wc-utils.ts
|
|
2
59
|
function getPikaContext(el) {
|
|
3
60
|
return new Promise((resolve, reject) => {
|
|
@@ -18,7 +75,23 @@ function getPikaContext(el) {
|
|
|
18
75
|
);
|
|
19
76
|
});
|
|
20
77
|
}
|
|
78
|
+
function getThemeVariable(name) {
|
|
79
|
+
if (typeof document === "undefined") return "";
|
|
80
|
+
return getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();
|
|
81
|
+
}
|
|
82
|
+
function getPikaThemeTokens() {
|
|
83
|
+
if (typeof document === "undefined") return {};
|
|
84
|
+
const style = getComputedStyle(document.documentElement);
|
|
85
|
+
const tokens = {};
|
|
86
|
+
for (const name of SEMANTIC_COLOR_VARIABLES) {
|
|
87
|
+
const value = style.getPropertyValue(`--${name}`).trim();
|
|
88
|
+
if (value) {
|
|
89
|
+
tokens[name] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return tokens;
|
|
93
|
+
}
|
|
21
94
|
|
|
22
|
-
export { getPikaContext };
|
|
95
|
+
export { getPikaContext, getPikaThemeTokens, getThemeVariable };
|
|
23
96
|
//# sourceMappingURL=wc-utils.mjs.map
|
|
24
97
|
//# sourceMappingURL=wc-utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/wc-utils.ts"],"names":[],"mappings":";AAeO,SAAS,eAAe,EAAA,EAAyC;AACpE,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACpC,IAAA,MAAM,OAAA,GAAU,WAAW,MAAM;AAC7B,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,+EAA+E,CAAC,CAAA;AAAA,IACrG,GAAG,GAAI,CAAA;AAEP,IAAA,EAAA,CAAG,aAAA;AAAA,MACC,IAAI,YAAwC,yBAAA,EAA2B;AAAA,QACnE,OAAA,EAAS,IAAA;AAAA,QACT,QAAA,EAAU,IAAA;AAAA,QACV,MAAA,EAAQ;AAAA,UACJ,QAAA,EAAU,CAAC,GAAA,KAAuB;AAC9B,YAAA,YAAA,CAAa,OAAO,CAAA;AACpB,YAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,UACf;AAAA;AACJ,OACH;AAAA,KACL;AAAA,EACJ,CAAC,CAAA;AACL","file":"wc-utils.mjs","sourcesContent":["import { PikaWCContext, PikaWCContextRequestDetail } from '../types/chatbot/webcomp-types';\n\n/**\n * Web component authors can use this function to get the Pika context when their web component is rendered.\n *\n * The type of the context object is defined in the PikaWCContext interface.\n *\n * @see PikaWCContext\n *\n * @example\n * ```ts\n * const ctx: PikaWCContext = await getPikaContext(el);\n * console.log(ctx.appState.identity.user.fullName);\n * ```\n */\nexport function getPikaContext(el: HTMLElement): Promise<PikaWCContext> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error('Pika context not provided - component must be rendered within a Pika chat app'));\n }, 1000);\n\n el.dispatchEvent(\n new CustomEvent<PikaWCContextRequestDetail>('pika-wc-context-request', {\n bubbles: true,\n composed: true,\n detail: {\n callback: (ctx: PikaWCContext) => {\n clearTimeout(timeout);\n resolve(ctx);\n }\n }\n })\n );\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/chatbot/theme-types.ts","../../src/util/wc-utils.ts"],"names":[],"mappings":";AA+NO,IAAM,wBAAA,GAA6D;AAAA;AAAA,EAEtE,YAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,iBAAA;AAAA,EACA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,WAAA;AAAA,EACA,sBAAA;AAAA,EACA,OAAA;AAAA,EACA,kBAAA;AAAA,EACA,QAAA;AAAA,EACA,mBAAA;AAAA,EACA,aAAA;AAAA,EACA,wBAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA;AAAA,EAEA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA,EACA,SAAA;AAAA;AAAA,EAEA,oBAAA;AAAA,EACA,oBAAA;AAAA,EACA,iBAAA;AAAA,EACA,4BAAA;AAAA,EACA,gBAAA;AAAA,EACA,2BAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA;AAAA,EAEA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,YAAA;AAAA,EACA,SAAA;AAAA,EACA,oBAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,iBAAA;AAAA,EACA,SAAA;AAAA,EACA,IAAA;AAAA,EACA,eAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA;AAAA,EAEA,eAAA;AAAA,EACA,6BAAA;AAAA,EACA;AACJ,CAAA;;;ACrQO,SAAS,eAAe,EAAA,EAAyC;AACpE,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAAA,KAAW;AACpC,IAAA,MAAM,OAAA,GAAU,WAAW,MAAM;AAC7B,MAAA,MAAA,CAAO,IAAI,KAAA,CAAM,+EAA+E,CAAC,CAAA;AAAA,IACrG,GAAG,GAAI,CAAA;AAEP,IAAA,EAAA,CAAG,aAAA;AAAA,MACC,IAAI,YAAwC,yBAAA,EAA2B;AAAA,QACnE,OAAA,EAAS,IAAA;AAAA,QACT,QAAA,EAAU,IAAA;AAAA,QACV,MAAA,EAAQ;AAAA,UACJ,QAAA,EAAU,CAAC,GAAA,KAAuB;AAC9B,YAAA,YAAA,CAAa,OAAO,CAAA;AACpB,YAAA,OAAA,CAAQ,GAAG,CAAA;AAAA,UACf;AAAA;AACJ,OACH;AAAA,KACL;AAAA,EACJ,CAAC,CAAA;AACL;AAoBO,SAAS,iBAAiB,IAAA,EAAsB;AACnD,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,EAAA;AAC5C,EAAA,OAAO,gBAAA,CAAiB,SAAS,eAAe,CAAA,CAAE,iBAAiB,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAA,CAAE,IAAA,EAAK;AACzF;AAqBO,SAAS,kBAAA,GAAqE;AACjF,EAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,EAAC;AAE7C,EAAA,MAAM,KAAA,GAAQ,gBAAA,CAAiB,QAAA,CAAS,eAAe,CAAA;AACvD,EAAA,MAAM,SAAyD,EAAC;AAEhE,EAAA,KAAA,MAAW,QAAQ,wBAAA,EAA0B;AACzC,IAAA,MAAM,QAAQ,KAAA,CAAM,gBAAA,CAAiB,KAAK,IAAI,CAAA,CAAE,EAAE,IAAA,EAAK;AACvD,IAAA,IAAI,KAAA,EAAO;AACP,MAAA,MAAA,CAAO,IAAI,CAAA,GAAI,KAAA;AAAA,IACnB;AAAA,EACJ;AAEA,EAAA,OAAO,MAAA;AACX","file":"wc-utils.mjs","sourcesContent":["/**\n * Theme Types for Pika UI Customization\n *\n * These types define the structure of theme configuration for clone projects.\n * Import via: import type { ThemeConfig } from 'pika-shared/types/chatbot/theme-types';\n *\n * @since 0.16.0\n */\n\n/**\n * Theme configuration for Pika Chat\n *\n * Clone projects copy sample-purple-theme.ts, customize it, and update themeConfigPath\n * in pika-config.ts to point to their theme file.\n *\n * @example\n * ```typescript\n * import type { ThemeConfig } from 'pika-shared/types/chatbot/theme-types';\n *\n * export const themeConfig: ThemeConfig = {\n * name: 'Acme Corp Theme',\n * fontFamily: '\"Inter\", sans-serif',\n * cssVariables: {\n * light: {\n * 'primary': 'oklch(0.47 0.2 290)',\n * 'primary-foreground': 'oklch(1 0 0)',\n * },\n * dark: {\n * 'primary': 'oklch(0.70 0.18 290)',\n * }\n * }\n * };\n * ```\n *\n * @since 0.16.0\n */\nexport interface ThemeConfig {\n /**\n * Schema version of this theme configuration.\n * Used by `pika theme check` to notify you of new theme variables.\n * See theme-schema.ts for the changelog of schema versions.\n *\n * @default 1 (if not specified)\n * @example schemaVersion: 1\n */\n schemaVersion?: number;\n\n /**\n * Display name for this theme (for documentation/debugging)\n * @example 'Acme Corp Brand Theme'\n */\n name?: string;\n\n /**\n * Font family override. Applied to --font-sans CSS variable.\n * @example '\"Figtree\", Arial, Helvetica, sans-serif'\n */\n fontFamily?: string;\n\n /**\n * CSS custom properties to override.\n * Keys are CSS variable names WITHOUT the -- prefix.\n * Values should be valid CSS color values (oklch preferred for modern color handling).\n *\n * @example\n * ```typescript\n * cssVariables: {\n * light: {\n * 'primary': 'oklch(0.47 0.2 290)',\n * 'border': 'oklch(0.88 0.01 260)',\n * },\n * dark: {\n * 'primary': 'oklch(0.70 0.18 290)',\n * }\n * }\n * ```\n */\n cssVariables?: {\n /** Light mode variable overrides */\n light?: Record<string, string>;\n /** Dark mode variable overrides */\n dark?: Record<string, string>;\n };\n\n /**\n * Custom color palettes for your brand.\n * Creates CSS variables like --{paletteName}-{shade}\n *\n * @example\n * ```typescript\n * customPalettes: {\n * brand: {\n * '50': 'oklch(0.97 0.01 290)',\n * '500': 'oklch(0.47 0.2 290)',\n * '900': 'oklch(0.20 0.08 290)',\n * }\n * }\n * ```\n */\n customPalettes?: Record<string, Record<string, string>>;\n\n /**\n * Custom header icon for chat apps. Replaces the default AI sparkle icon.\n * The icon will be constrained to roughly 44x44px.\n *\n * Can be specified as:\n * - A single string URL (used for both light and dark modes)\n * - An object with separate light/dark URLs for mode-specific icons\n *\n * For sync-safe storage, place your icons in:\n * `apps/pika-chat/static/custom/assets/`\n *\n * @example Single icon for both modes:\n * ```typescript\n * chatAppHeaderIcon: '/custom/assets/my-logo.svg'\n * ```\n *\n * @example Separate icons for light/dark modes:\n * ```typescript\n * chatAppHeaderIcon: {\n * light: '/custom/assets/logo-dark.svg', // Dark logo on light background\n * dark: '/custom/assets/logo-light.svg' // Light logo on dark background\n * }\n * ```\n *\n * @since 0.16.4\n */\n chatAppHeaderIcon?: string | {\n /** Icon URL for light mode */\n light: string;\n /** Icon URL for dark mode (falls back to light if not provided) */\n dark?: string;\n };\n}\n\n/**\n * Configuration for the custom theme feature in pika-config.ts\n *\n * @since 0.16.0\n */\nexport interface CustomThemeConfig {\n /**\n * Whether custom theming is enabled.\n * If false, the default Pika theme is used and the theme config is not loaded.\n */\n enabled: boolean;\n\n /**\n * Path to theme config file relative to apps/pika-chat/\n * The file must export a `themeConfig` object of type ThemeConfig.\n *\n * @default 'src/lib/custom/sample-purple-theme'\n * @example 'src/lib/custom/my-theme' imports from 'apps/pika-chat/src/lib/custom/my-theme.ts'\n */\n themeConfigPath?: string;\n}\n\n/**\n * Standard semantic variable names that can be overridden in a theme.\n * These are the shadcn-svelte standard variables plus Pika extensions.\n *\n * @since 0.16.0\n */\nexport type SemanticColorVariable =\n // Core shadcn variables\n | 'background'\n | 'foreground'\n | 'card'\n | 'card-foreground'\n | 'popover'\n | 'popover-foreground'\n | 'primary'\n | 'primary-foreground'\n | 'secondary'\n | 'secondary-foreground'\n | 'muted'\n | 'muted-foreground'\n | 'accent'\n | 'accent-foreground'\n | 'destructive'\n | 'destructive-foreground'\n | 'border'\n | 'input'\n | 'ring'\n // Chart colors\n | 'chart-1'\n | 'chart-2'\n | 'chart-3'\n | 'chart-4'\n | 'chart-5'\n // Sidebar variants\n | 'sidebar-background'\n | 'sidebar-foreground'\n | 'sidebar-primary'\n | 'sidebar-primary-foreground'\n | 'sidebar-accent'\n | 'sidebar-accent-foreground'\n | 'sidebar-border'\n | 'sidebar-ring'\n // Pika extended semantic colors\n | 'success'\n | 'success-foreground'\n | 'success-bg'\n | 'warning'\n | 'warning-foreground'\n | 'warning-bg'\n | 'info'\n | 'info-foreground'\n | 'info-bg'\n | 'ai'\n | 'ai-foreground'\n | 'ai-bg'\n | 'danger-bg'\n // Header/branding\n | 'chat-app-icon'\n | 'chat-app-header-icon-height'\n | 'chat-app-header-icon-gap';\n\n/**\n * All semantic variables as a readonly array for iteration\n *\n * @since 0.16.0\n */\nexport const SEMANTIC_COLOR_VARIABLES: readonly SemanticColorVariable[] = [\n // Core\n 'background',\n 'foreground',\n 'card',\n 'card-foreground',\n 'popover',\n 'popover-foreground',\n 'primary',\n 'primary-foreground',\n 'secondary',\n 'secondary-foreground',\n 'muted',\n 'muted-foreground',\n 'accent',\n 'accent-foreground',\n 'destructive',\n 'destructive-foreground',\n 'border',\n 'input',\n 'ring',\n // Charts\n 'chart-1',\n 'chart-2',\n 'chart-3',\n 'chart-4',\n 'chart-5',\n // Sidebar\n 'sidebar-background',\n 'sidebar-foreground',\n 'sidebar-primary',\n 'sidebar-primary-foreground',\n 'sidebar-accent',\n 'sidebar-accent-foreground',\n 'sidebar-border',\n 'sidebar-ring',\n // Extended\n 'success',\n 'success-foreground',\n 'success-bg',\n 'warning',\n 'warning-foreground',\n 'warning-bg',\n 'info',\n 'info-foreground',\n 'info-bg',\n 'ai',\n 'ai-foreground',\n 'ai-bg',\n 'danger-bg',\n // Header/branding\n 'chat-app-icon',\n 'chat-app-header-icon-height',\n 'chat-app-header-icon-gap'\n] as const;\n","import { PikaWCContext, PikaWCContextRequestDetail } from '../types/chatbot/webcomp-types';\nimport { SEMANTIC_COLOR_VARIABLES, type SemanticColorVariable } from '../types/chatbot/theme-types';\n\n/**\n * Web component authors can use this function to get the Pika context when their web component is rendered.\n *\n * The type of the context object is defined in the PikaWCContext interface.\n *\n * @see PikaWCContext\n *\n * @example\n * ```ts\n * const ctx: PikaWCContext = await getPikaContext(el);\n * console.log(ctx.appState.identity.user.fullName);\n * ```\n */\nexport function getPikaContext(el: HTMLElement): Promise<PikaWCContext> {\n return new Promise((resolve, reject) => {\n const timeout = setTimeout(() => {\n reject(new Error('Pika context not provided - component must be rendered within a Pika chat app'));\n }, 1000);\n\n el.dispatchEvent(\n new CustomEvent<PikaWCContextRequestDetail>('pika-wc-context-request', {\n bubbles: true,\n composed: true,\n detail: {\n callback: (ctx: PikaWCContext) => {\n clearTimeout(timeout);\n resolve(ctx);\n }\n }\n })\n );\n });\n}\n\n/**\n * Get a single CSS variable value from the document.\n * Useful for web components that need to read theme values.\n *\n * @param name - Variable name without the -- prefix (e.g., 'primary', 'background')\n * @returns The computed value of the CSS variable, or empty string if not found\n *\n * @example\n * ```ts\n * const primaryColor = getThemeVariable('primary');\n * console.log(primaryColor); // 'oklch(0.514 0.146 255.748)'\n *\n * // Use in dynamic styles - value already includes oklch()\n * element.style.backgroundColor = getThemeVariable('primary');\n * ```\n *\n * @since 0.16.0\n */\nexport function getThemeVariable(name: string): string {\n if (typeof document === 'undefined') return '';\n return getComputedStyle(document.documentElement).getPropertyValue(`--${name}`).trim();\n}\n\n/**\n * Get all Pika semantic theme tokens as an object.\n * Useful for web components that need access to multiple theme values.\n *\n * Returns only the semantic color variables (primary, secondary, success, etc.),\n * not the full palette variables (gold-500, blueish-300, etc.).\n *\n * @returns Object mapping variable names to their computed values\n *\n * @example\n * ```ts\n * const tokens = getPikaThemeTokens();\n * console.log(tokens.primary); // 'oklch(0.514 0.146 255.748)'\n * console.log(tokens.success); // 'oklch(0.55 0.16 142)'\n * console.log(tokens['muted-foreground']); // 'oklch(0.551 0.027 264.364)'\n * ```\n *\n * @since 0.16.0\n */\nexport function getPikaThemeTokens(): Partial<Record<SemanticColorVariable, string>> {\n if (typeof document === 'undefined') return {};\n\n const style = getComputedStyle(document.documentElement);\n const tokens: Partial<Record<SemanticColorVariable, string>> = {};\n\n for (const name of SEMANTIC_COLOR_VARIABLES) {\n const value = style.getPropertyValue(`--${name}`).trim();\n if (value) {\n tokens[name] = value;\n }\n }\n\n return tokens;\n}\n"]}
|