@vlian/framework 2.0.3 → 2.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 +1 -0
- package/dist/index.umd.js +1 -1
- package/dist/kernel/custom-manager/theme/theme.dom.cjs +1 -1
- package/dist/kernel/custom-manager/theme/theme.dom.js +1 -1
- package/dist/kernel/custom-manager/theme/theme.schema.cjs +1 -1
- package/dist/kernel/custom-manager/theme/theme.schema.js +1 -1
- package/dist/kernel/custom-manager/theme/types.d.ts +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get applyThemeToDocument(){return applyThemeToDocument},get observeSystemThemeChange(){return observeSystemThemeChange},get resolveThemeMode(){return resolveThemeMode}});function canUseDom(){return typeof document!=="undefined"}function canUseMatchMedia(){return typeof window!=="undefined"&&typeof window.matchMedia==="function"}function resolveThemeMode(theme){if(theme.mode!=="system"){return theme.mode}if(canUseMatchMedia()&&window.matchMedia("(prefers-color-scheme: dark)").matches){return"dark"}return"light"}function applyThemeToDocument(nextTheme,options={}){if(!canUseDom()){return}const root=document.documentElement;const nextMode=options.nextResolvedMode??resolveThemeMode(nextTheme);const prevTheme=options.prevTheme;const prevMode=options.prevResolvedMode??(prevTheme?resolveThemeMode(prevTheme):undefined);if(!prevMode||prevMode!==nextMode){root.classList.remove("light","dark");root.classList.add(nextMode)}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get applyThemeToDocument(){return applyThemeToDocument},get observeSystemThemeChange(){return observeSystemThemeChange},get resolveThemeMode(){return resolveThemeMode}});const THEME_TOKEN_STYLE_ELEMENT_ID="vlian-theme-tokens";function canUseDom(){return typeof document!=="undefined"}function canUseMatchMedia(){return typeof window!=="undefined"&&typeof window.matchMedia==="function"}function getThemeTokenStyleElement(){const existing=document.getElementById(THEME_TOKEN_STYLE_ELEMENT_ID);if(existing instanceof HTMLStyleElement){return existing}if(!document.head){return null}const styleElement=document.createElement("style");styleElement.id=THEME_TOKEN_STYLE_ELEMENT_ID;styleElement.setAttribute("data-vlian-theme-tokens","true");document.head.appendChild(styleElement);return styleElement}function buildThemeTokenCssText(tokens){if(!tokens||Object.keys(tokens).length===0){return""}const declaration=document.createElement("div").style;for(const[token,value]of Object.entries(tokens)){declaration.setProperty(`--${token}`,String(value))}return declaration.cssText?`:root { ${declaration.cssText} }`:""}function syncThemeTokensToDocument(tokens){const styleElement=getThemeTokenStyleElement();if(!styleElement){return}const cssText=buildThemeTokenCssText(tokens);if(styleElement.textContent!==cssText){styleElement.textContent=cssText}}function resolveThemeMode(theme){if(theme.mode!=="system"){return theme.mode}if(canUseMatchMedia()&&window.matchMedia("(prefers-color-scheme: dark)").matches){return"dark"}return"light"}function applyThemeToDocument(nextTheme,options={}){if(!canUseDom()){return}const root=document.documentElement;const nextMode=options.nextResolvedMode??resolveThemeMode(nextTheme);const prevTheme=options.prevTheme;const prevMode=options.prevResolvedMode??(prevTheme?resolveThemeMode(prevTheme):undefined);if(!prevMode||prevMode!==nextMode){root.classList.remove("light","dark");root.classList.add(nextMode)}syncThemeTokensToDocument(nextTheme.tokens)}function observeSystemThemeChange(listener){if(!canUseMatchMedia()){return null}const mediaQuery=window.matchMedia("(prefers-color-scheme: dark)");const handleChange=()=>{listener(mediaQuery.matches?"dark":"light")};if(typeof mediaQuery.addEventListener==="function"){mediaQuery.addEventListener("change",handleChange);return()=>{mediaQuery.removeEventListener("change",handleChange)}}mediaQuery.addListener(handleChange);return()=>{mediaQuery.removeListener(handleChange)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function canUseDom(){return typeof document!=="undefined"}function canUseMatchMedia(){return typeof window!=="undefined"&&typeof window.matchMedia==="function"}export function resolveThemeMode(theme){if(theme.mode!=="system"){return theme.mode}if(canUseMatchMedia()&&window.matchMedia("(prefers-color-scheme: dark)").matches){return"dark"}return"light"}export function applyThemeToDocument(nextTheme,options={}){if(!canUseDom()){return}const root=document.documentElement;const nextMode=options.nextResolvedMode??resolveThemeMode(nextTheme);const prevTheme=options.prevTheme;const prevMode=options.prevResolvedMode??(prevTheme?resolveThemeMode(prevTheme):undefined);if(!prevMode||prevMode!==nextMode){root.classList.remove("light","dark");root.classList.add(nextMode)}
|
|
1
|
+
const THEME_TOKEN_STYLE_ELEMENT_ID="vlian-theme-tokens";function canUseDom(){return typeof document!=="undefined"}function canUseMatchMedia(){return typeof window!=="undefined"&&typeof window.matchMedia==="function"}function getThemeTokenStyleElement(){const existing=document.getElementById(THEME_TOKEN_STYLE_ELEMENT_ID);if(existing instanceof HTMLStyleElement){return existing}if(!document.head){return null}const styleElement=document.createElement("style");styleElement.id=THEME_TOKEN_STYLE_ELEMENT_ID;styleElement.setAttribute("data-vlian-theme-tokens","true");document.head.appendChild(styleElement);return styleElement}function buildThemeTokenCssText(tokens){if(!tokens||Object.keys(tokens).length===0){return""}const declaration=document.createElement("div").style;for(const[token,value]of Object.entries(tokens)){declaration.setProperty(`--${token}`,String(value))}return declaration.cssText?`:root { ${declaration.cssText} }`:""}function syncThemeTokensToDocument(tokens){const styleElement=getThemeTokenStyleElement();if(!styleElement){return}const cssText=buildThemeTokenCssText(tokens);if(styleElement.textContent!==cssText){styleElement.textContent=cssText}}export function resolveThemeMode(theme){if(theme.mode!=="system"){return theme.mode}if(canUseMatchMedia()&&window.matchMedia("(prefers-color-scheme: dark)").matches){return"dark"}return"light"}export function applyThemeToDocument(nextTheme,options={}){if(!canUseDom()){return}const root=document.documentElement;const nextMode=options.nextResolvedMode??resolveThemeMode(nextTheme);const prevTheme=options.prevTheme;const prevMode=options.prevResolvedMode??(prevTheme?resolveThemeMode(prevTheme):undefined);if(!prevMode||prevMode!==nextMode){root.classList.remove("light","dark");root.classList.add(nextMode)}syncThemeTokensToDocument(nextTheme.tokens)}export function observeSystemThemeChange(listener){if(!canUseMatchMedia()){return null}const mediaQuery=window.matchMedia("(prefers-color-scheme: dark)");const handleChange=()=>{listener(mediaQuery.matches?"dark":"light")};if(typeof mediaQuery.addEventListener==="function"){mediaQuery.addEventListener("change",handleChange);return()=>{mediaQuery.removeEventListener("change",handleChange)}}mediaQuery.addListener(handleChange);return()=>{mediaQuery.removeListener(handleChange)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get cloneResolvedTheme(){return cloneResolvedTheme},get cloneTheme(){return cloneTheme},get isResolvedThemeModeEqual(){return isResolvedThemeModeEqual},get isThemeEqual(){return isThemeEqual},get mergeTheme(){return mergeTheme},get normalizeTheme(){return normalizeTheme},get sanitizeTokens(){return sanitizeTokens}});const VALID_THEME_MODES=new Set(["light","dark","system"]);const TOKEN_NAME_PATTERN=/^[A-Za-z_][A-Za-z0-9_-]*$/;function isPlainObject(value){return Object.prototype.toString.call(value)==="[object Object]"}function hasOwnProperty(value,key){return Object.prototype.hasOwnProperty.call(value,key)}function cloneTheme(theme){return{...theme,...theme.tokens?{tokens:{...theme.tokens}}:{}}}function cloneResolvedTheme(theme){return{...cloneTheme(theme),resolvedMode:theme.resolvedMode}}function sanitizeTokens(tokens){if(!isPlainObject(tokens)){return undefined}const sanitizedTokens={};for(const[token,tokenValue]of Object.entries(tokens)){if(!TOKEN_NAME_PATTERN.test(token)){continue}if(typeof tokenValue==="string"||typeof tokenValue==="number"){sanitizedTokens[token]=tokenValue}}return Object.keys(sanitizedTokens).length>0?sanitizedTokens:undefined}function normalizeTheme(value,fallback){const source=isPlainObject(value)?value:{};const mode=VALID_THEME_MODES.has(source.mode)?source.mode:fallback.mode;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:Object.getOwnPropertyDescriptor(all,name).get})}_export(exports,{get cloneResolvedTheme(){return cloneResolvedTheme},get cloneTheme(){return cloneTheme},get isResolvedThemeModeEqual(){return isResolvedThemeModeEqual},get isThemeEqual(){return isThemeEqual},get mergeTheme(){return mergeTheme},get normalizeTheme(){return normalizeTheme},get sanitizeTokens(){return sanitizeTokens}});const VALID_THEME_MODES=new Set(["light","dark","system"]);const TOKEN_NAME_PATTERN=/^[A-Za-z_][A-Za-z0-9_-]*$/;function isPlainObject(value){return Object.prototype.toString.call(value)==="[object Object]"}function hasOwnProperty(value,key){return Object.prototype.hasOwnProperty.call(value,key)}function cloneTheme(theme){return{...theme,...theme.tokens?{tokens:{...theme.tokens}}:{}}}function cloneResolvedTheme(theme){return{...cloneTheme(theme),resolvedMode:theme.resolvedMode}}function sanitizeTokens(tokens){if(!isPlainObject(tokens)){return undefined}const sanitizedTokens={};for(const[token,tokenValue]of Object.entries(tokens)){if(!TOKEN_NAME_PATTERN.test(token)){continue}if(typeof tokenValue==="string"||typeof tokenValue==="number"){sanitizedTokens[token]=tokenValue}}return Object.keys(sanitizedTokens).length>0?sanitizedTokens:undefined}function normalizeTheme(value,fallback){const source=isPlainObject(value)?value:{};const mode=VALID_THEME_MODES.has(source.mode)?source.mode:fallback.mode;const fallbackTokens=sanitizeTokens(fallback.tokens);const incomingTokens=sanitizeTokens(source.tokens);return{mode,...incomingTokens||fallbackTokens?{tokens:{...fallbackTokens||{},...incomingTokens||{}}}:{}}}function mergeTheme(current,next){const nextTokens=hasOwnProperty(next,"tokens")?sanitizeTokens(next.tokens):undefined;const mergedTheme={mode:hasOwnProperty(next,"mode")&&VALID_THEME_MODES.has(next.mode)?next.mode:current.mode,...hasOwnProperty(next,"tokens")?nextTokens?{tokens:nextTokens}:{}:current.tokens?{tokens:{...current.tokens}}:{}};return normalizeTheme(mergedTheme,DEFAULT_EMPTY_THEME)}const DEFAULT_EMPTY_THEME={mode:"light"};function isThemeEqual(left,right){if(left.mode!==right.mode){return false}const leftTokens=left.tokens||{};const rightTokens=right.tokens||{};const leftKeys=Object.keys(leftTokens);const rightKeys=Object.keys(rightTokens);if(leftKeys.length!==rightKeys.length){return false}for(const key of leftKeys){if(leftTokens[key]!==rightTokens[key]){return false}}return true}function isResolvedThemeModeEqual(left,right){return left===right}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const VALID_THEME_MODES=new Set(["light","dark","system"]);const TOKEN_NAME_PATTERN=/^[A-Za-z_][A-Za-z0-9_-]*$/;function isPlainObject(value){return Object.prototype.toString.call(value)==="[object Object]"}function hasOwnProperty(value,key){return Object.prototype.hasOwnProperty.call(value,key)}export function cloneTheme(theme){return{...theme,...theme.tokens?{tokens:{...theme.tokens}}:{}}}export function cloneResolvedTheme(theme){return{...cloneTheme(theme),resolvedMode:theme.resolvedMode}}export function sanitizeTokens(tokens){if(!isPlainObject(tokens)){return undefined}const sanitizedTokens={};for(const[token,tokenValue]of Object.entries(tokens)){if(!TOKEN_NAME_PATTERN.test(token)){continue}if(typeof tokenValue==="string"||typeof tokenValue==="number"){sanitizedTokens[token]=tokenValue}}return Object.keys(sanitizedTokens).length>0?sanitizedTokens:undefined}export function normalizeTheme(value,fallback){const source=isPlainObject(value)?value:{};const mode=VALID_THEME_MODES.has(source.mode)?source.mode:fallback.mode;const
|
|
1
|
+
const VALID_THEME_MODES=new Set(["light","dark","system"]);const TOKEN_NAME_PATTERN=/^[A-Za-z_][A-Za-z0-9_-]*$/;function isPlainObject(value){return Object.prototype.toString.call(value)==="[object Object]"}function hasOwnProperty(value,key){return Object.prototype.hasOwnProperty.call(value,key)}export function cloneTheme(theme){return{...theme,...theme.tokens?{tokens:{...theme.tokens}}:{}}}export function cloneResolvedTheme(theme){return{...cloneTheme(theme),resolvedMode:theme.resolvedMode}}export function sanitizeTokens(tokens){if(!isPlainObject(tokens)){return undefined}const sanitizedTokens={};for(const[token,tokenValue]of Object.entries(tokens)){if(!TOKEN_NAME_PATTERN.test(token)){continue}if(typeof tokenValue==="string"||typeof tokenValue==="number"){sanitizedTokens[token]=tokenValue}}return Object.keys(sanitizedTokens).length>0?sanitizedTokens:undefined}export function normalizeTheme(value,fallback){const source=isPlainObject(value)?value:{};const mode=VALID_THEME_MODES.has(source.mode)?source.mode:fallback.mode;const fallbackTokens=sanitizeTokens(fallback.tokens);const incomingTokens=sanitizeTokens(source.tokens);return{mode,...incomingTokens||fallbackTokens?{tokens:{...fallbackTokens||{},...incomingTokens||{}}}:{}}}export function mergeTheme(current,next){const nextTokens=hasOwnProperty(next,"tokens")?sanitizeTokens(next.tokens):undefined;const mergedTheme={mode:hasOwnProperty(next,"mode")&&VALID_THEME_MODES.has(next.mode)?next.mode:current.mode,...hasOwnProperty(next,"tokens")?nextTokens?{tokens:nextTokens}:{}:current.tokens?{tokens:{...current.tokens}}:{}};return normalizeTheme(mergedTheme,DEFAULT_EMPTY_THEME)}const DEFAULT_EMPTY_THEME={mode:"light"};export function isThemeEqual(left,right){if(left.mode!==right.mode){return false}const leftTokens=left.tokens||{};const rightTokens=right.tokens||{};const leftKeys=Object.keys(leftTokens);const rightKeys=Object.keys(rightTokens);if(leftKeys.length!==rightKeys.length){return false}for(const key of leftKeys){if(leftTokens[key]!==rightTokens[key]){return false}}return true}export function isResolvedThemeModeEqual(left,right){return left===right}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PersistenceOptions } from '../../types';
|
|
2
2
|
export interface ThemeSnapshot {
|
|
3
3
|
mode: 'light' | 'dark' | 'system';
|
|
4
|
-
primaryColor?: string;
|
|
5
4
|
tokens?: Record<string, string | number>;
|
|
6
5
|
}
|
|
7
6
|
export type ResolvedThemeMode = Exclude<ThemeSnapshot['mode'], 'system'>;
|