@marwes-ui/core 1.0.3 → 1.0.5

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
@@ -122,6 +122,23 @@ resolveMode(ThemeMode.dark)
122
122
 
123
123
  Most apps should use `useThemeMode()` from `@marwes-ui/react` or `@marwes-ui/vue`. Core is the framework-agnostic piece that makes the resolved variables and mode classes consistent across adapters.
124
124
 
125
+ ### SSR Theme Rules
126
+
127
+ SSR adapters can use the same core theme engine to emit light and dark CSS variable rules before hydration. These helpers are pure string utilities; React and Vue expose framework-specific SSR helpers on top.
128
+
129
+ ```ts
130
+ import { ThemeMode, resolveThemeInput, themeModesToCSSRules } from "@marwes-ui/core"
131
+
132
+ const css = themeModesToCSSRules({
133
+ light: resolveThemeInput({ mode: ThemeMode.light }),
134
+ dark: resolveThemeInput({ mode: ThemeMode.dark }),
135
+ rootTarget: "html",
136
+ rootAttribute: "class",
137
+ })
138
+ ```
139
+
140
+ The generated rules target `[data-marwes-theme][data-marwes-mode="light"]` and `[data-marwes-theme][data-marwes-mode="dark"]`. When `rootTarget` is provided, matching `html.light` / `html.dark` or data-attribute selectors are included so a pre-hydration script can switch the resolved mode before provider roots hydrate.
141
+
125
142
  ## Theme Variables
126
143
 
127
144
  Marwes components are styled by CSS custom properties on the `MarwesProvider` root. The theme variable helpers expose that same token surface to application code, adapters, and tooling without creating a second runtime theme system.
@@ -234,6 +251,10 @@ This is intentionally practical. A destructive action can carry `data-destructiv
234
251
  Theme:
235
252
  - `resolveThemeInput`
236
253
  - `themeToCSSVars`
254
+ - `themeToCSSRule`
255
+ - `themeModesToCSSRules`
256
+ - `createMarwesThemeScript`
257
+ - `createMarwesThemeStyle`
237
258
  - `mwThemeVars`
238
259
  - `mwThemeVarNames`
239
260
  - `mwStyledTheme`
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ declare const ThemeMode: {
42
42
  };
43
43
  type ThemeMode = (typeof ThemeMode)[keyof typeof ThemeMode];
44
44
  type ThemePreference = ThemeMode | "system";
45
+ type ThemeVariableStrategy = "inline" | "style-tag";
45
46
  type Theme = {
46
47
  /**
47
48
  * The current theme mode. This determines which color defaults are applied.
@@ -173,19 +174,6 @@ declare function isThemePreference(value: unknown): value is ThemePreference;
173
174
  declare function resolveThemePreference(preference: ThemePreference, systemMode: SystemThemeMode): ThemeMode;
174
175
  declare function nextThemeMode(mode: ThemeMode): ThemeMode;
175
176
 
176
- /**
177
- * Light theme defaults (default mode).
178
- * Uses dark text on light backgrounds.
179
- * Colors mapped from Figma design tokens (node 1:120).
180
- */
181
- declare const lightThemeDefaults: Theme;
182
- /**
183
- * Dark theme defaults.
184
- * Uses light text on dark backgrounds.
185
- * Colors are inverted from light theme for optimal dark mode experience.
186
- */
187
- declare const darkThemeDefaults: Theme;
188
-
189
177
  interface ResolvedTheme {
190
178
  mode: ThemeMode;
191
179
  color: {
@@ -264,6 +252,51 @@ interface ResolvedTheme {
264
252
  * Variable naming follows D11: --mw-color-{role}-{state}, --mw-font-*, etc.
265
253
  */
266
254
  declare function themeToCSSVars(theme: ResolvedTheme): Record<string, string>;
255
+ type ThemeModeAttribute = "class" | "data-theme" | "data-mode";
256
+ type ThemeModeRootTarget = "html" | "body";
257
+ type ThemeModeCSSRulesOptions = {
258
+ light: ResolvedTheme;
259
+ dark: ResolvedTheme;
260
+ selector?: string;
261
+ rootTarget?: ThemeModeRootTarget;
262
+ rootAttribute?: ThemeModeAttribute;
263
+ };
264
+ declare function themeToCSSRule(selector: string, theme: ResolvedTheme): string;
265
+ declare function themeModesToCSSRules({ light, dark, selector, rootTarget, rootAttribute, }: ThemeModeCSSRulesOptions): string;
266
+
267
+ type MarwesThemeScriptOptions = {
268
+ storageKey?: string | false;
269
+ defaultPreference?: ThemePreference;
270
+ enableSystem?: boolean;
271
+ target?: ThemeModeRootTarget;
272
+ attribute?: ThemeModeAttribute;
273
+ };
274
+ type MarwesThemeStyleOptions = {
275
+ lightTheme?: ThemeInput;
276
+ darkTheme?: ThemeInput;
277
+ selector?: string;
278
+ target?: ThemeModeRootTarget;
279
+ attribute?: ThemeModeAttribute;
280
+ };
281
+ declare function createMarwesThemeScript({ storageKey, defaultPreference, enableSystem, target, attribute, }?: MarwesThemeScriptOptions): string;
282
+ declare function createMarwesThemeStyle({ lightTheme, darkTheme, selector, target, attribute, }?: MarwesThemeStyleOptions): string;
283
+ declare function resolveServerThemeMode({ preference, systemFallback, }?: {
284
+ preference?: ThemePreference;
285
+ systemFallback?: ThemeMode;
286
+ }): ThemeMode;
287
+
288
+ /**
289
+ * Light theme defaults (default mode).
290
+ * Uses dark text on light backgrounds.
291
+ * Colors mapped from Figma design tokens (node 1:120).
292
+ */
293
+ declare const lightThemeDefaults: Theme;
294
+ /**
295
+ * Dark theme defaults.
296
+ * Uses light text on dark backgrounds.
297
+ * Colors are inverted from light theme for optimal dark mode experience.
298
+ */
299
+ declare const darkThemeDefaults: Theme;
267
300
 
268
301
  /**
269
302
  * Converts a consumer ThemeInput into a fully-resolved ResolvedTheme.
@@ -9134,4 +9167,4 @@ type SpacingRenderKit = {
9134
9167
 
9135
9168
  declare function createSpacingRecipe(opts?: SpacingOptions): SpacingRenderKit;
9136
9169
 
9137
- export { type AccordionA11yProps, type AccordionOptions, type AccordionRenderKit, type AvatarA11yProps, type AvatarDataAttributes, type AvatarOptions, type AvatarRenderContent, type AvatarRenderKit, AvatarSize, AvatarType, type BadgeA11yProps, type BadgeOptions, type BadgeRenderKit, BadgeVariant, type ButtonA11yProps, ButtonAction, type ButtonLoadingOptions, type ButtonOptions, type ButtonRenderKit, ButtonSize, ButtonVariant, type CardOptions, type CardRenderKit, type CheckboxA11y, type CheckboxProps, type CheckboxRenderKit, type CheckboxState, type ColorInput, type ColorRole, type CssVars, type CurrencyCode, DENSITY_SCALES, type Density, type DensityScale, type DialogA11yProps, type DialogOptions, type DialogRenderKit, type DialogSize, type DividerA11y, type DividerDataAttributes, type DividerOptions, type DividerOrientation, type DividerRenderKit, type DividerSize, type FamilySemanticDefinition, type FieldComparisonRow, type FontLoadingConfig, type FontLoadingMode, type FontLoadingOptions, type HeadingA11y, type HeadingLevel, type HeadingOptions, type HeadingRenderKit, type HeadingSize, type IconA11yProps, type IconColor, IconName, IconName as IconNameType, type IconOptions, type IconPreset, type IconRenderKit, type IconSize, type IconSizeKey, type IconStrokeWidth, type IconStrokeWidthKey, type InputA11yProps, type InputOptions, type InputOtpA11yProps, type InputOtpOptions, type InputOtpRenderKit, type InputRenderKit, type InputTone, type LabeledCopy, type MwAvailableFont, type MwFontFallback, type MwGoogleFontFamily, type MwStyledTheme, type MwThemeVarName, type MwThemeVarNames, type MwThemeVarReference, type MwThemeVars, type ParagraphA11y, type ParagraphOptions, type ParagraphRenderKit, type ParagraphSize, type PurposeSemanticDefinition, type RadioA11y, type RadioOptions, type RadioRenderKit, type ResolvedButtonLoading, type ResolvedTheme, type RichTextA11yProps, type RichTextFormat, type RichTextOptions, type RichTextRenderKit, type SecondaryColorRole, type SelectA11yProps, type SelectAppearance, type SelectMode, type SelectOption, type SelectOptions, type SelectRenderKit, type SemanticAttributeDefinition, type SemanticAttributeName, type SemanticAttributeValue, type SemanticAttributes, type SemanticFamily, type SemanticIntent, type SemanticLayer, type SemanticOrientation, type SemanticOutcome, type SemanticPurpose, type SliderA11yProps, type SliderDataAttributes, type SliderOptions, type SliderRenderKit, type SpacingA11y, type SpacingDataAttributes, type SpacingOptions, type SpacingRenderKit, type SpacingSize, Spacings, type SpinnerA11yProps, type SpinnerDataAttributes, type SpinnerOptions, type SpinnerRenderKit, type SpinnerSize, type SpinnerSvgDefinition, type SpinnerSvgElement, type SpinnerSvgNode, SpinnerVariant, SpinnerVariants, type SvgElementType, type SvgNode, type SwitchA11yProps, type SwitchOptions, type SwitchRenderKit, SwitchSize, type SystemThemeMode, type TabA11yProps, type TabGroupA11yIds, type TabGroupItemState, type TabNavigationDirection, type TabOptions, type TabRenderKit, type TextareaA11yProps, type TextareaOptions, type TextareaRenderKit, type TextareaResize, type Theme, type ThemeInput, type ThemeInputColor, ThemeMode, type ThemePreference, type ToastA11yProps, type ToastContainerOptions, type ToastIntent, type ToastOptions, type ToastPlacement, type ToastRenderKit, type ToastVariant, type ToneName, type TooltipA11yProps, type TooltipDataAttributes, type TooltipOptions, type TooltipRenderKit, accordionPurposeComponentReference, accordionWhyPurposeComponents, avatarPurposeSemantics, avatarPurposes, badgePurposeComponentReference, badgePurposeSemantics, badgePurposes, badgeWhyPurposeComponents, buildAccordionFieldA11yIds, buildCheckboxA11y, buildCheckboxFieldA11yIds, buildCheckboxGroupFieldA11yIds, buildCurrencyHelperText, buildGoogleFontsUrl, buildHeadingA11y, buildInputFieldA11yIds, buildRadioA11y, buildRadioGroupFieldA11yIds, buildRichTextFieldA11yIds, buildSliderFieldA11yIds, buildSwitchFieldA11yIds, buildTabGroupA11yIds, buttonActionSemanticPurposes, buttonPurposeSemantics, buttonPurposes, buttonVariantVisualStyles, buttonWhySemanticComponents, canonicalSemanticAttributeNames, canonicalSemanticAttributeRegistry, canonicalSemanticAttributes, cardPurposeComponentReference, cardWhyPurposeComponents, checkboxRecipe, createAccordionRecipe, createAvatarRecipe, createBadgeRecipe, createButtonRecipe, createCardRecipe, createDialogRecipe, createDividerRecipe, createFamilySemanticAttributes, createFontStack, createIconRecipe, createInputOtpRecipe, createInputRecipe, createPurposeSemanticAttributes, createRichTextRecipe, createSelectRecipe, createSliderRecipe, createSpacingRecipe, createSpinnerRecipe, createSwitchRecipe, createTabRecipe, createTextareaRecipe, createToastRecipe, createTooltipRecipe, currencyCodes, darkThemeDefaults, densityToCSSVars, dialogPurposeComponentReference, dialogPurposeSemantics, dialogPurposes, dialogWhyPurposeComponents, emptySemanticAttributes, escapeRichTextHtml, extractFontFamilyName, extractUsedWeights, familySemanticsRegistry, fieldComparisonRows, fieldWhyPurposeComponents, filterUndefinedSemanticAttributes, getCurrencySymbol, headingRecipe, iconNames, iconNamesList, iconRegistry, iconSizeScale, iconStrokeWidthScale, isRichTextHtmlEmpty, isSystemFont, isThemeMode, isThemePreference, lightThemeDefaults, mergeIdRefs, mergeSemanticAttributes, moveTabSelection, mwAvailableFonts, mwFontFallbacks, mwGoogleFontFamilies, mwStyledTheme, mwThemeVarNames, mwThemeVars, mwVar, nextThemeMode, normalizeRichTextHtml, paragraphRecipe, purposeSemanticsRegistry, radioPurposeComponentReference, radioRecipe, radioWhyPurposeComponents, resolveAccordionA11y, resolveAvatarA11y, resolveBadgeA11y, resolveButtonLoading, resolveDialogA11y, resolveIconA11y, resolveIconSize, resolveIconStrokeWidth, resolveRichTextAllowedFormats, resolveSelectMode, resolveSliderA11y, resolveSpinnerA11y, resolveSpinnerSize, resolveSwitchA11y, resolveTabA11y, resolveTabValue, resolveThemeInput, resolveThemePreference, resolveToastA11y, resolveTone, resolveTooltipA11y, richTextCommandByFormat, richTextFormattingReference, richTextWhyUseIt, sanitizeCurrencyValue, sanitizeInputOtpValue, semanticFamilies, semanticFrameworkSupport, semanticIntents, semanticLayers, semanticOrientations, semanticOutcomes, semanticPurposes, shouldLoadGoogleFont, sliderPurposeComponentReference, sliderWhyPurposeComponents, spinnerSizeScale, spinnerSizes, spinnerVariants, storybookA11yPolicy, storybookButtonGeneralArgTypes, storybookButtonIconArgTypes, storybookButtonPurposeArgTypes, storybookCheckboxArgTypes, storybookDividerArgTypes, storybookDocsDescription, storybookIconGalleryArgTypes, storybookIconGalleryDefaults, storybookIconNames, storybookLayout, storybookOptionalIconNames, storybookRadioArgTypes, storybookSliderArgTypes, storybookSpacingArgTypes, storybookSpinnerArgTypes, switchPurposeComponentReference, switchWhyPurposeComponents, tabPurposeComponentReference, tabWhyPurposeComponents, themeToCSSVars, toastPurposeComponentReference, toastPurposeSemantics, toastPurposes, toastWhyPurposeComponents, validateSemanticRegistry };
9170
+ export { type AccordionA11yProps, type AccordionOptions, type AccordionRenderKit, type AvatarA11yProps, type AvatarDataAttributes, type AvatarOptions, type AvatarRenderContent, type AvatarRenderKit, AvatarSize, AvatarType, type BadgeA11yProps, type BadgeOptions, type BadgeRenderKit, BadgeVariant, type ButtonA11yProps, ButtonAction, type ButtonLoadingOptions, type ButtonOptions, type ButtonRenderKit, ButtonSize, ButtonVariant, type CardOptions, type CardRenderKit, type CheckboxA11y, type CheckboxProps, type CheckboxRenderKit, type CheckboxState, type ColorInput, type ColorRole, type CssVars, type CurrencyCode, DENSITY_SCALES, type Density, type DensityScale, type DialogA11yProps, type DialogOptions, type DialogRenderKit, type DialogSize, type DividerA11y, type DividerDataAttributes, type DividerOptions, type DividerOrientation, type DividerRenderKit, type DividerSize, type FamilySemanticDefinition, type FieldComparisonRow, type FontLoadingConfig, type FontLoadingMode, type FontLoadingOptions, type HeadingA11y, type HeadingLevel, type HeadingOptions, type HeadingRenderKit, type HeadingSize, type IconA11yProps, type IconColor, IconName, IconName as IconNameType, type IconOptions, type IconPreset, type IconRenderKit, type IconSize, type IconSizeKey, type IconStrokeWidth, type IconStrokeWidthKey, type InputA11yProps, type InputOptions, type InputOtpA11yProps, type InputOtpOptions, type InputOtpRenderKit, type InputRenderKit, type InputTone, type LabeledCopy, type MarwesThemeScriptOptions, type MarwesThemeStyleOptions, type MwAvailableFont, type MwFontFallback, type MwGoogleFontFamily, type MwStyledTheme, type MwThemeVarName, type MwThemeVarNames, type MwThemeVarReference, type MwThemeVars, type ParagraphA11y, type ParagraphOptions, type ParagraphRenderKit, type ParagraphSize, type PurposeSemanticDefinition, type RadioA11y, type RadioOptions, type RadioRenderKit, type ResolvedButtonLoading, type ResolvedTheme, type RichTextA11yProps, type RichTextFormat, type RichTextOptions, type RichTextRenderKit, type SecondaryColorRole, type SelectA11yProps, type SelectAppearance, type SelectMode, type SelectOption, type SelectOptions, type SelectRenderKit, type SemanticAttributeDefinition, type SemanticAttributeName, type SemanticAttributeValue, type SemanticAttributes, type SemanticFamily, type SemanticIntent, type SemanticLayer, type SemanticOrientation, type SemanticOutcome, type SemanticPurpose, type SliderA11yProps, type SliderDataAttributes, type SliderOptions, type SliderRenderKit, type SpacingA11y, type SpacingDataAttributes, type SpacingOptions, type SpacingRenderKit, type SpacingSize, Spacings, type SpinnerA11yProps, type SpinnerDataAttributes, type SpinnerOptions, type SpinnerRenderKit, type SpinnerSize, type SpinnerSvgDefinition, type SpinnerSvgElement, type SpinnerSvgNode, SpinnerVariant, SpinnerVariants, type SvgElementType, type SvgNode, type SwitchA11yProps, type SwitchOptions, type SwitchRenderKit, SwitchSize, type SystemThemeMode, type TabA11yProps, type TabGroupA11yIds, type TabGroupItemState, type TabNavigationDirection, type TabOptions, type TabRenderKit, type TextareaA11yProps, type TextareaOptions, type TextareaRenderKit, type TextareaResize, type Theme, type ThemeInput, type ThemeInputColor, ThemeMode, type ThemeModeAttribute, type ThemeModeCSSRulesOptions, type ThemeModeRootTarget, type ThemePreference, type ThemeVariableStrategy, type ToastA11yProps, type ToastContainerOptions, type ToastIntent, type ToastOptions, type ToastPlacement, type ToastRenderKit, type ToastVariant, type ToneName, type TooltipA11yProps, type TooltipDataAttributes, type TooltipOptions, type TooltipRenderKit, accordionPurposeComponentReference, accordionWhyPurposeComponents, avatarPurposeSemantics, avatarPurposes, badgePurposeComponentReference, badgePurposeSemantics, badgePurposes, badgeWhyPurposeComponents, buildAccordionFieldA11yIds, buildCheckboxA11y, buildCheckboxFieldA11yIds, buildCheckboxGroupFieldA11yIds, buildCurrencyHelperText, buildGoogleFontsUrl, buildHeadingA11y, buildInputFieldA11yIds, buildRadioA11y, buildRadioGroupFieldA11yIds, buildRichTextFieldA11yIds, buildSliderFieldA11yIds, buildSwitchFieldA11yIds, buildTabGroupA11yIds, buttonActionSemanticPurposes, buttonPurposeSemantics, buttonPurposes, buttonVariantVisualStyles, buttonWhySemanticComponents, canonicalSemanticAttributeNames, canonicalSemanticAttributeRegistry, canonicalSemanticAttributes, cardPurposeComponentReference, cardWhyPurposeComponents, checkboxRecipe, createAccordionRecipe, createAvatarRecipe, createBadgeRecipe, createButtonRecipe, createCardRecipe, createDialogRecipe, createDividerRecipe, createFamilySemanticAttributes, createFontStack, createIconRecipe, createInputOtpRecipe, createInputRecipe, createMarwesThemeScript, createMarwesThemeStyle, createPurposeSemanticAttributes, createRichTextRecipe, createSelectRecipe, createSliderRecipe, createSpacingRecipe, createSpinnerRecipe, createSwitchRecipe, createTabRecipe, createTextareaRecipe, createToastRecipe, createTooltipRecipe, currencyCodes, darkThemeDefaults, densityToCSSVars, dialogPurposeComponentReference, dialogPurposeSemantics, dialogPurposes, dialogWhyPurposeComponents, emptySemanticAttributes, escapeRichTextHtml, extractFontFamilyName, extractUsedWeights, familySemanticsRegistry, fieldComparisonRows, fieldWhyPurposeComponents, filterUndefinedSemanticAttributes, getCurrencySymbol, headingRecipe, iconNames, iconNamesList, iconRegistry, iconSizeScale, iconStrokeWidthScale, isRichTextHtmlEmpty, isSystemFont, isThemeMode, isThemePreference, lightThemeDefaults, mergeIdRefs, mergeSemanticAttributes, moveTabSelection, mwAvailableFonts, mwFontFallbacks, mwGoogleFontFamilies, mwStyledTheme, mwThemeVarNames, mwThemeVars, mwVar, nextThemeMode, normalizeRichTextHtml, paragraphRecipe, purposeSemanticsRegistry, radioPurposeComponentReference, radioRecipe, radioWhyPurposeComponents, resolveAccordionA11y, resolveAvatarA11y, resolveBadgeA11y, resolveButtonLoading, resolveDialogA11y, resolveIconA11y, resolveIconSize, resolveIconStrokeWidth, resolveRichTextAllowedFormats, resolveSelectMode, resolveServerThemeMode, resolveSliderA11y, resolveSpinnerA11y, resolveSpinnerSize, resolveSwitchA11y, resolveTabA11y, resolveTabValue, resolveThemeInput, resolveThemePreference, resolveToastA11y, resolveTone, resolveTooltipA11y, richTextCommandByFormat, richTextFormattingReference, richTextWhyUseIt, sanitizeCurrencyValue, sanitizeInputOtpValue, semanticFamilies, semanticFrameworkSupport, semanticIntents, semanticLayers, semanticOrientations, semanticOutcomes, semanticPurposes, shouldLoadGoogleFont, sliderPurposeComponentReference, sliderWhyPurposeComponents, spinnerSizeScale, spinnerSizes, spinnerVariants, storybookA11yPolicy, storybookButtonGeneralArgTypes, storybookButtonIconArgTypes, storybookButtonPurposeArgTypes, storybookCheckboxArgTypes, storybookDividerArgTypes, storybookDocsDescription, storybookIconGalleryArgTypes, storybookIconGalleryDefaults, storybookIconNames, storybookLayout, storybookOptionalIconNames, storybookRadioArgTypes, storybookSliderArgTypes, storybookSpacingArgTypes, storybookSpinnerArgTypes, switchPurposeComponentReference, switchWhyPurposeComponents, tabPurposeComponentReference, tabWhyPurposeComponents, themeModesToCSSRules, themeToCSSRule, themeToCSSVars, toastPurposeComponentReference, toastPurposeSemantics, toastPurposes, toastWhyPurposeComponents, validateSemanticRegistry };