Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add input URL encoding
As you type, the input CSS will be zipped and turned into a URL safe string and stored in the URL Params. This allows sharing links to the playground that pre-load the CSS. Uses `fflate` for the zipping/unzipping, because it's small and fast.
  • Loading branch information
TheJaredWilcurt authored Jul 20, 2026
commit 368805a3bab14da5c4db19c04001436e51d3f6b1
36 changes: 36 additions & 0 deletions csso.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<script src="libs/cssbeautify.js"></script>
<script src="libs/base64.js"></script>
<script src="libs/diff.js"></script>
<script src="libs/fflate.js"></script>

<section>
<div class="header">
Expand Down Expand Up @@ -147,6 +148,38 @@
'</div>';
}

function urlEncode(data) {
const buffer = window.fflate.strToU8(data);
const zipped = window.fflate.zlibSync(buffer, { level: 9 });
const binary = window.fflate.strFromU8(zipped, true);
return btoa(binary);
}
function urlDecode(base64) {
const binary = atob(base64);
if (binary.startsWith('\x78\xDA')) {
const buffer = window.fflate.strToU8(binary, true);
const unzipped = window.fflate.unzlibSync(buffer);
return window.fflate.strFromU8(unzipped);
}
return decodeURIComponent(escape(binary));
}
function setUrlParams(input) {
let value = '';
if (input) {
value = urlEncode(input);
}
const url = new URL(window.location);
url.searchParams.set('v', value);
history.replaceState({}, '', url);
}
function loadUrlParams() {
const url = new URL(window.location);
const value = url.searchParams.get('v')
if (value) {
source.value = urlDecode(value);
}
}

function process(force) {
var time;

Expand All @@ -161,6 +194,8 @@

try {
lastSource = source.value;
setUrlParams(lastSource);

lastResult = csso.minify(source.value, {
restructure: restructure.checked,
sourceMap: sourceMap.checked,
Expand Down Expand Up @@ -213,6 +248,7 @@
}, false);

document.getElementById('version').innerHTML = csso.version;
loadUrlParams();
process();
</script>

Expand Down