Comparing version 0.4.0-alpha.21 to 0.4.0-alpha.22
@@ -0,1 +1,2 @@ | ||
export declare const ID = "_inlines"; | ||
export declare let getSheet: () => any; |
@@ -1,2 +0,2 @@ | ||
let GOOBER_ID = '_goober'; | ||
export const ID = '_inlines'; | ||
let ssr = { | ||
@@ -7,6 +7,6 @@ data: '', | ||
? () => { | ||
return (window[GOOBER_ID] || | ||
return (window[ID] || | ||
Object.assign(document.head.appendChild(document.createElement('style')), { | ||
innerHTML: ' ', | ||
id: GOOBER_ID, | ||
id: ID, | ||
})).firstChild; | ||
@@ -13,0 +13,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export declare let hash: (compiled: any, sheet: any, keyframes?: boolean) => any; | ||
export declare let hash: (compiled: any, sheet: any, keyframes: boolean, bundle: any) => any; |
import { toHash } from './to-hash.js'; | ||
import { update } from './update.js'; | ||
import { astish } from './astish.js'; | ||
import { parse } from './parse.js'; | ||
@@ -15,3 +14,3 @@ let cache = {}; | ||
}; | ||
export let hash = (compiled, sheet, keyframes = false) => { | ||
export let hash = (compiled, sheet, keyframes = false, bundle) => { | ||
// Get a string representation of the object or the value that is called 'compiled' | ||
@@ -21,15 +20,10 @@ let stringifiedCompiled = stringify(compiled); | ||
let className = cache[stringifiedCompiled] || | ||
(cache[stringifiedCompiled] = toHash(stringifiedCompiled)); | ||
(cache[stringifiedCompiled] = toHash(stringifiedCompiled, bundle)); | ||
// If there's no entry for the current className | ||
if (!cache[className]) { | ||
// Build the _ast_-ish structure if needed | ||
let ast = stringifiedCompiled !== compiled ? compiled : astish(compiled); | ||
// Parse it | ||
cache[className] = parse( | ||
// For keyframes | ||
keyframes ? { ['@keyframes ' + className]: ast } : ast, '.' + className); | ||
keyframes ? { ['@keyframes ' + className]: compiled } : compiled, '.' + className); | ||
} | ||
// If the global flag is set, save the current stringified and compiled CSS to `cache.g` | ||
// to allow replacing styles in <style /> instead of appending them. | ||
// This is required for using `createGlobalStyles` with themes | ||
// add or update | ||
@@ -36,0 +30,0 @@ update(cache[className], sheet); |
@@ -1,1 +0,1 @@ | ||
export declare const toHash: (str: any) => any; | ||
export declare const toHash: (str: any, bundle: any) => any; |
import { stringHash } from '@saulx/hash'; | ||
const cache = {}; | ||
const c = {}; | ||
let i = 10; | ||
let j = 36; | ||
export const toHash = typeof window === 'object' | ||
? (str) => 'i' + (stringHash(str) >>> 0) | ||
: (str) => { | ||
// if it's ssr shorten it | ||
const h = stringHash(str); | ||
if (!(h in cache)) { | ||
export const toHash = (str, bundle) => { | ||
const h = stringHash(str); | ||
if (!(h in c)) { | ||
if (bundle) { | ||
if (i === j) { | ||
@@ -15,6 +13,12 @@ i *= 10; | ||
} | ||
cache[h] = Number(i++).toString(36); | ||
// means it's bundling | ||
c[h] = Number(i++).toString(36); | ||
} | ||
return cache[h]; | ||
}; | ||
else { | ||
const id = Number(h >>> 0).toString(36); | ||
c[h] = isNaN(Number(id)) ? id : `_${id}`; | ||
} | ||
} | ||
return c[h]; | ||
}; | ||
//# sourceMappingURL=to-hash.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const css: (obj: any) => any; | ||
export declare const keyframes: (obj: any) => any; | ||
export declare const css: (obj: any, bundle?: any) => any; | ||
export declare const keyframes: (obj: any, bundle?: any) => any; |
import { hash } from './core/hash.js'; | ||
import { getSheet } from './core/get-sheet.js'; | ||
export const css = (obj) => hash(obj, getSheet()); | ||
export const keyframes = (obj) => hash(obj, getSheet(), true); | ||
export const css = (obj, bundle) => hash(obj, getSheet(), false, bundle); | ||
export const keyframes = (obj, bundle) => hash(obj, getSheet(), true, bundle); | ||
//# sourceMappingURL=css.js.map |
@@ -55,3 +55,3 @@ import ts from 'typescript'; | ||
: prop.initializer.text, | ||
})); | ||
}, 1)); | ||
if (i < node.properties.length - 1) { | ||
@@ -58,0 +58,0 @@ const next = node.properties[i + 1]; |
{ | ||
"name": "inlines", | ||
"description": "When you just want to use the style prop in React", | ||
"version": "0.4.0-alpha.21", | ||
"version": "0.4.0-alpha.22", | ||
"main": "dist/src/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/src/index.d.ts", |
@@ -1,2 +0,2 @@ | ||
let GOOBER_ID = '_goober' | ||
export const ID = '_inlines' | ||
let ssr = { | ||
@@ -10,3 +10,3 @@ data: '', | ||
return ( | ||
window[GOOBER_ID] || | ||
window[ID] || | ||
Object.assign( | ||
@@ -16,3 +16,3 @@ document.head.appendChild(document.createElement('style')), | ||
innerHTML: ' ', | ||
id: GOOBER_ID, | ||
id: ID, | ||
}, | ||
@@ -19,0 +19,0 @@ ) |
import { toHash } from './to-hash.js' | ||
import { update } from './update.js' | ||
import { astish } from './astish.js' | ||
import { parse } from './parse.js' | ||
@@ -16,3 +15,3 @@ | ||
export let hash = (compiled, sheet, keyframes = false) => { | ||
export let hash = (compiled, sheet, keyframes = false, bundle) => { | ||
// Get a string representation of the object or the value that is called 'compiled' | ||
@@ -24,13 +23,10 @@ let stringifiedCompiled = stringify(compiled) | ||
cache[stringifiedCompiled] || | ||
(cache[stringifiedCompiled] = toHash(stringifiedCompiled)) | ||
(cache[stringifiedCompiled] = toHash(stringifiedCompiled, bundle)) | ||
// If there's no entry for the current className | ||
if (!cache[className]) { | ||
// Build the _ast_-ish structure if needed | ||
let ast = stringifiedCompiled !== compiled ? compiled : astish(compiled) | ||
// Parse it | ||
cache[className] = parse( | ||
// For keyframes | ||
keyframes ? { ['@keyframes ' + className]: ast } : ast, | ||
keyframes ? { ['@keyframes ' + className]: compiled } : compiled, | ||
'.' + className, | ||
@@ -40,6 +36,2 @@ ) | ||
// If the global flag is set, save the current stringified and compiled CSS to `cache.g` | ||
// to allow replacing styles in <style /> instead of appending them. | ||
// This is required for using `createGlobalStyles` with themes | ||
// add or update | ||
@@ -46,0 +38,0 @@ update(cache[className], sheet) |
import { stringHash } from '@saulx/hash' | ||
const cache = {} | ||
const c = {} | ||
let i = 10 | ||
let j = 36 | ||
export const toHash = | ||
typeof window === 'object' | ||
? (str) => 'i' + (stringHash(str) >>> 0) | ||
: (str) => { | ||
// if it's ssr shorten it | ||
const h = stringHash(str) | ||
if (!(h in cache)) { | ||
if (i === j) { | ||
i *= 10 | ||
j *= 36 | ||
} | ||
cache[h] = Number(i++).toString(36) | ||
} | ||
return cache[h] | ||
export const toHash = (str, bundle) => { | ||
const h = stringHash(str) | ||
if (!(h in c)) { | ||
if (bundle) { | ||
if (i === j) { | ||
i *= 10 | ||
j *= 36 | ||
} | ||
// means it's bundling | ||
c[h] = Number(i++).toString(36) | ||
} else { | ||
const id = Number(h >>> 0).toString(36) | ||
c[h] = isNaN(Number(id)) ? id : `_${id}` | ||
} | ||
} | ||
return c[h] | ||
} |
import { hash } from './core/hash.js' | ||
import { getSheet } from './core/get-sheet.js' | ||
export const css = (obj) => hash(obj, getSheet()) | ||
export const keyframes = (obj) => hash(obj, getSheet(), true) | ||
export const css = (obj, bundle?) => hash(obj, getSheet(), false, bundle) | ||
export const keyframes = (obj, bundle?) => hash(obj, getSheet(), true, bundle) |
@@ -69,7 +69,10 @@ import ts from 'typescript' | ||
classNames.push( | ||
css({ | ||
[key]: isNumber | ||
? Number(prop.initializer.text) | ||
: prop.initializer.text, | ||
}), | ||
css( | ||
{ | ||
[key]: isNumber | ||
? Number(prop.initializer.text) | ||
: prop.initializer.text, | ||
}, | ||
1, | ||
), | ||
) | ||
@@ -76,0 +79,0 @@ if (i < node.properties.length - 1) { |
36494
44
960