Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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 => b.toString(16).padStart(2, '0')).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