lukejacksonn / csz Goto Github PK
View Code? Open in Web Editor NEWRuntime CSS modules with SASS like preprocessing
License: MIT License
Runtime CSS modules with SASS like preprocessing
License: MIT License
Please add a license.
i have put this question on pika discuss forum as well. putting it here as i think its intertwined with snowpack's way of importing css files.
i have one component.css file which i am importing like this in component.tsx file.
const componentStyle = css`/component.css`
// usage
<div className={componentStyle}>
// ..some html here//
</div>
since this css file is not imported using top level import but is inside csz's template literal.
any changes made to this landing.css file doesn't reflect .. i have to restart the snowpack's dev server to see the new changes.
i explored my sources tab in chrome's console tool. since snowpack didn't encountered any import of css file it was not served and hence this doesn't work.
but some where down the line csz's framework takes care of that adding the style to the dom.
i am not sure this is the ideal scenario for snowpack to pick up file (which is not imported using import but is inside css string literal )and serve it.
is there a setup or repo which i can use it as a reference where csz is used in a snowpack setup and also css files are imported in .jsx/.tsx files.
My rudimentary regex implementation is not going to cut it. I would like to employ something like stylis
Do you think adding custom css class name support is worth it from a debugging perspective?
Example:
.my-class-name-af28f1eb
.another-class-name-e3fd91bc
instead of
.csz-af28f1eb
.csz-e3fd91bc
I'm not sure how you would support this since your css function call uses a template string.
css('background: blue', 'my-class-name')
Use the string as the key for the cache and the hash as the data value. Calculate the hash only when creating a new key. Store the hash values in a second lookup map and check when creating a new hash value to detect collisions.
OR
Do what picostyle does and increment a classname counter for each new unique string value.
Hi, I am using this library in a project that deploy itself in a path under the root domain. All my dependecies work well because I use a <base href=/PATH/
> in my index.html
but the library is using fetch with absolute paths so it ignores the base. I have solved my problem using a helper function that prepend the preffix before calling css
but I think that maybe it will be useful for other users (and it is easy to add, I think).
Suggest replacing Math.random() with a perfect 32bit hash function to avoid collisions which could cause duplicate css class names
import stylis from './stylis.js'
const cache = {}
let seed = 0; // or Math.random() * 4294967295;
const p = new Uint32Array(1);
const hash = () => {
//Math.random()
p[0] = seed++;
p[0] = (p[0]+0x7ed55d16) + (p[0]<<12);
p[0] = (p[0]^0xc761c23c) ^ (p[0]>>19);
p[0] = (p[0]+0x165667b1) + (p[0]<<5);
p[0] = (p[0]+0xd3a2646c) ^ (p[0]<<9);
p[0] = (p[0]+0xfd7046c5) + (p[0]<<3);
p[0] = (p[0]^0xb55a4f09) ^ (p[0]>>16);
return p[0].toString(16);
}
const sheet = document.createElement('style')
document.head.appendChild(sheet)
"1: b48681b6"
"2: e267b84c"
"3: b0910e9c"
"4: c797201d"
"5: fe0d66ee"
"6: f2b32b34"
"7: f3ced760"
"8: 92daf2f4"
"9: b5b9ef41"
const cache = {
abc123: true,
def123: true,
aba123: true,
bab123: true,
bcb123: true,
cdc123: true,
dde123: true,
}
const hash = Math.random().toString(36).replace('0.', '')
cache[hash]
844,675 ops/s ±2.41%
65.03% slower
let seed = 0; // or Math.random() * 4294967295;
const p = new Uint32Array(1);
p[0] = seed++;
p[0] = (p[0]+0x7ed55d16) + (p[0]<<12);
p[0] = (p[0]^0xc761c23c) ^ (p[0]>>19);
p[0] = (p[0]+0x165667b1) + (p[0]<<5);
p[0] = (p[0]+0xd3a2646c) ^ (p[0]<<9);
p[0] = (p[0]+0xfd7046c5) + (p[0]<<3);
p[0] = (p[0]^0xb55a4f09) ^ (p[0]>>16);
p[0].toString(16);
2,415,448 ops/s ±0.52%
fastest
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.