Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <script type="text/js-worker">
    // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
    async function sha256(message) {
        // encode as UTF-8
        const msgBuffer = new TextEncoder('utf-8').encode(message);

        // hash the message
        const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);

        // convert ArrayBuffer to Array
        const hashArray = Array.from(new Uint8Array(hashBuffer));

        // convert bytes to hex string
        const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
        return hashHex;
    }


    self.addEventListener('message', async function (e) {
        const hash = await sha256(e.data);
        self.postMessage(hash);
    }, false); 
</script>

<label>
    <input type="text">
    <span>Text to hash</span>
</label>
<output></output>
            
          
!

CSS

            
              @use postcss-nested;
@use postcss-cssnext;

body {
    background: #002F47;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    flex-flow: column nowrap;
    font-family: "Roboto", sans-serif;
}


label {
    position: relative;
    
    & span {
        position: absolute;
        top: 0;
        display: block;
        color: #A9CEB7;
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
        text-transform: uppercase;
        font-weight: 700;
        opacity: 0.5;
        transform: translatey(calc(-100% - 5px));
    }
}

input {
    border: 5px solid #1C7F81;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
    padding: 1rem;
    border-radius: 5px;
    font-size: 2rem;
    outline: none;
    
    &:focus,
    &:active {
        border-color: #289B80;
        
        & + span {
            opacity: 1;
        }
    }
}

output {
    color: #91DCC5;
    padding: 25px;
    font-size: 3rem;
    width:50%;
    word-wrap: break-word;
    font-family: 'Roboto Mono', monospace;
}
            
          
!

JS

            
              const { createStore, compose, applyMiddleware } = Redux;
const { runSaga, eventChannel } = ReduxSaga;
const { call, take } = ReduxSaga.effects;

const reducer = ()=>({});
const sagaMiddleware = ReduxSaga.default();
const store = createStore(reducer, {}, compose(
    applyMiddleware(
        sagaMiddleware
    )
));
store.runSagas = sagaMiddleware.run;

// ------------ Worker

function createWorker(){
    const scripts = Array.from(document.querySelectorAll('script[type="text\/js-worker"]'));
    const blob = new Blob(
        scripts.map( script => script.textContent),
        {type: 'text/javascript'}
    );
    const url = window.URL.createObjectURL(blob);
    return new Worker(url);
}

// ------------ Sagas

function createWorkerChannel(worker) {
    return eventChannel(emit => {

        const onMessage = (event) => emit(event.data);
        worker.addEventListener('message', onMessage, false);
        
        const unsubscribe = () => worker.terminate();
        return unsubscribe
    })
}

function* outputHash(hash){
    const node = yield call([document, 'querySelector'], 'output');
    node.textContent = hash;
}

function* addListeners(worker){
    const node = yield call([document, 'querySelector'], 'input');
    node.addEventListener('input', (e)=> worker.postMessage(e.target.value));
    worker.postMessage(node.value);
}

function* initialize(){
    const worker = yield call(createWorker);
    const channel = yield call(createWorkerChannel, worker)
    yield call(addListeners, worker);
            
    while(true){
        const payload = yield take(channel);
        yield call(outputHash, payload);
    }
}

// ------------ Run

store.runSagas(initialize);
            
          
!
999px

Console