@claspo/common 7.0.1 → 7.0.3-rc0

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.
@@ -263,7 +263,6 @@ export interface ClIconEnvironmentParamsI {
263
263
  content: string;
264
264
  defaultIcon: boolean;
265
265
  color?: string;
266
- colorThemeToken?: string;
267
266
  size?: number;
268
267
  }
269
268
  export declare enum ClCloseButtonHorizontalPosition {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/common",
3
- "version": "7.0.1",
3
+ "version": "7.0.3rc0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -0,0 +1,13 @@
1
+ interface CacheEntry {
2
+ value: string | null;
3
+ expiration: number;
4
+ }
5
+ export default abstract class BaseCachingStorage {
6
+ cache: Record<string, CacheEntry>;
7
+ cacheTimeMs: number;
8
+ protected _process(operationCallback: () => string | null): string | null;
9
+ protected _getFromCache(key: string): string | null;
10
+ protected _setToCache(key: string, value: string | null): void;
11
+ protected _removeFromCache(key: string): void;
12
+ }
13
+ export {};
@@ -0,0 +1 @@
1
+ export default class BaseCachingStorage{constructor(){this.cache={},this.cacheTimeMs=2e3}_process(e){try{return e()}catch(e){return null}}_getFromCache(e){const t=Date.now(),c=this.cache[e];return c&&t<c.expiration?c.value:null}_setToCache(e,t){this.cache[e]={value:t,expiration:Date.now()+this.cacheTimeMs}}_removeFromCache(e){delete this.cache[e]}}
@@ -0,0 +1,13 @@
1
+ import BaseCachingStorage from './BaseCachingStorage';
2
+ interface CookieOptionsI {
3
+ path?: string;
4
+ expires?: Date | string;
5
+ [key: string]: string | Date | boolean | undefined;
6
+ }
7
+ declare class CachingCookieStorage extends BaseCachingStorage {
8
+ get(name: string): string | null;
9
+ set(name: string, value: string, options?: CookieOptionsI): void;
10
+ remove(name: string): void;
11
+ }
12
+ declare const _default: CachingCookieStorage;
13
+ export default _default;
@@ -0,0 +1 @@
1
+ import BaseCachingStorage from"./BaseCachingStorage";class CachingCookieStorage extends BaseCachingStorage{get(e){const o=this._getFromCache(e);return null!==o?o:this._process(()=>{const o=e.replace(/([$?*|{}()[\]\\/+^])/g,"\\$1"),t=document.cookie.match(new RegExp("(?:^|; )"+o+"=([^;]*)")),n=t?decodeURIComponent(t[1]):null;return this._setToCache(e,n),n})}set(e,o,t={}){const n=Object.assign({path:"/",expires:new Date((new Date).getFullYear()+5,0)},t);n.expires instanceof Date&&(n.expires=n.expires.toUTCString());let s=encodeURIComponent(e)+"="+encodeURIComponent(o);for(const e in n){s+="; "+e;const o=n[e];!0!==o&&(s+="="+o)}const c="string"==typeof o?o:this._process(()=>JSON.stringify(o));this._setToCache(e,c),this._process(()=>(document.cookie=s,null))}remove(e){this._removeFromCache(e),this._process(()=>(document.cookie=encodeURIComponent(e)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/",null))}}export default new CachingCookieStorage;
@@ -0,0 +1,8 @@
1
+ import BaseCachingStorage from './BaseCachingStorage';
2
+ declare class CachingLocalStorage extends BaseCachingStorage {
3
+ get(key: string): string | null;
4
+ set(key: string, value: string | object): void;
5
+ remove(key: string): void;
6
+ }
7
+ declare const _default: CachingLocalStorage;
8
+ export default _default;
@@ -0,0 +1 @@
1
+ import BaseCachingStorage from"./BaseCachingStorage";class CachingLocalStorage extends BaseCachingStorage{get(e){const t=this._getFromCache(e);return null!==t?t:this._process(()=>{const t=localStorage.getItem(e);return this._setToCache(e,t),t})}set(e,t){const o="string"==typeof t?t:this._process(()=>JSON.stringify(t));this._setToCache(e,o),this._process(()=>(localStorage.setItem(e,o),null))}remove(e){this._removeFromCache(e),this._process(()=>(localStorage.removeItem(e),null))}}export default new CachingLocalStorage;
@@ -1,7 +1,7 @@
1
1
  import { ThemeI } from "../document/Document.interface";
2
2
  export declare const THEME_CSS_VAR_PREFIX = "cl-schema-";
3
3
  export declare function toCssVarToken(token: string): string;
4
- export declare function formCssVarToSchemaToken(cssVar?: string): string;
4
+ export declare function fromCssVarToSchemaToken(cssVar?: string): string;
5
5
  export declare function extractRgbFromFallbackValue(value: string): string | null;
6
6
  export declare function extractColor(value: string, theme?: ThemeI | null): string | null;
7
7
  export declare function createTheme(schema?: Record<string, string>): ThemeI;
@@ -1 +1 @@
1
- export const THEME_CSS_VAR_PREFIX="cl-schema-";export function toCssVarToken(r){return`cl-schema-${r}`}export function formCssVarToSchemaToken(r=""){return r.replace(/var\(\s*(--[^,\s)]+).*\)/,"$1").replace("--cl-schema-","")}export function extractRgbFromFallbackValue(r){const e=String(r).match(/var\([^,]+,\s*(rgb(?:a)?\([^)]+\))\)/);return e&&e[1]?e[1]:null}export function extractColor(r,e){var t;const n=String(r||"");if(n.startsWith("var(")){if(!e)return null;const r=formCssVarToSchemaToken(n),a=null===(t=e.schema)||void 0===t?void 0:t[r];return a||(extractRgbFromFallbackValue(n)||null)}return n}export function createTheme(r={}){return{schema:Object.assign({},r)}}
1
+ export const THEME_CSS_VAR_PREFIX="cl-schema-";export function toCssVarToken(r){return`cl-schema-${r}`}export function fromCssVarToSchemaToken(r=""){return r.replace(/var\(\s*(--[^,\s)]+).*\)/,"$1").replace("--cl-schema-","")}export function extractRgbFromFallbackValue(r){const e=String(r).match(/var\([^,]+,\s*(rgb(?:a)?\([^)]+\))\)/);return e&&e[1]?e[1]:null}export function extractColor(r,e){var t;const n=String(r||"");if(n.startsWith("var(")){if(!e)return null;const r=fromCssVarToSchemaToken(n),a=null===(t=e.schema)||void 0===t?void 0:t[r];return a||(extractRgbFromFallbackValue(n)||null)}return n}export function createTheme(r={}){return{schema:Object.assign({},r)}}