Merge pull request #680 from tidalcycles/emoji-support
add emoji support
This commit is contained in:
commit
2dc079b950
2 changed files with 30 additions and 12 deletions
|
|
@ -5,15 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { cleanupDraw, cleanupUi, controls, evalScope, getDrawContext, logger } from '@strudel.cycles/core';
|
import { cleanupDraw, cleanupUi, controls, evalScope, getDrawContext, logger } from '@strudel.cycles/core';
|
||||||
import {
|
import { CodeMirror, cx, flash, useHighlighting, useStrudel, useKeydown } from '@strudel.cycles/react';
|
||||||
CodeMirror,
|
|
||||||
cx,
|
|
||||||
flash,
|
|
||||||
useHighlighting,
|
|
||||||
useStrudel,
|
|
||||||
useKeydown,
|
|
||||||
updateMiniLocations,
|
|
||||||
} from '@strudel.cycles/react';
|
|
||||||
import { getAudioContext, initAudioOnFirstClick, resetLoadedSounds, webaudioOutput } from '@strudel.cycles/webaudio';
|
import { getAudioContext, initAudioOnFirstClick, resetLoadedSounds, webaudioOutput } from '@strudel.cycles/webaudio';
|
||||||
import { createClient } from '@supabase/supabase-js';
|
import { createClient } from '@supabase/supabase-js';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
|
@ -28,6 +20,7 @@ import { themes } from './themes.mjs';
|
||||||
import { settingsMap, useSettings, setLatestCode } from '../settings.mjs';
|
import { settingsMap, useSettings, setLatestCode } from '../settings.mjs';
|
||||||
import Loader from './Loader';
|
import Loader from './Loader';
|
||||||
import { settingPatterns } from '../settings.mjs';
|
import { settingPatterns } from '../settings.mjs';
|
||||||
|
import { code2hash, hash2code } from './helpers.mjs';
|
||||||
|
|
||||||
const { latestCode } = settingsMap.get();
|
const { latestCode } = settingsMap.get();
|
||||||
|
|
||||||
|
|
@ -73,11 +66,11 @@ async function initCode() {
|
||||||
try {
|
try {
|
||||||
const initialUrl = window.location.href;
|
const initialUrl = window.location.href;
|
||||||
const hash = initialUrl.split('?')[1]?.split('#')?.[0];
|
const hash = initialUrl.split('?')[1]?.split('#')?.[0];
|
||||||
const codeParam = window.location.href.split('#')[1];
|
const codeParam = window.location.href.split('#')[1] || '';
|
||||||
// looking like https://strudel.tidalcycles.org/?J01s5i1J0200 (fixed hash length)
|
// looking like https://strudel.tidalcycles.org/?J01s5i1J0200 (fixed hash length)
|
||||||
if (codeParam) {
|
if (codeParam) {
|
||||||
// looking like https://strudel.tidalcycles.org/#ImMzIGUzIg%3D%3D (hash length depends on code length)
|
// looking like https://strudel.tidalcycles.org/#ImMzIGUzIg%3D%3D (hash length depends on code length)
|
||||||
return atob(decodeURIComponent(codeParam || ''));
|
return hash2code(codeParam);
|
||||||
} else if (hash) {
|
} else if (hash) {
|
||||||
return supabase
|
return supabase
|
||||||
.from('code')
|
.from('code')
|
||||||
|
|
@ -142,7 +135,7 @@ export function Repl({ embedded = false }) {
|
||||||
setMiniLocations(meta.miniLocations);
|
setMiniLocations(meta.miniLocations);
|
||||||
setPending(false);
|
setPending(false);
|
||||||
setLatestCode(code);
|
setLatestCode(code);
|
||||||
window.location.hash = '#' + encodeURIComponent(btoa(code));
|
window.location.hash = '#' + code2hash(code);
|
||||||
},
|
},
|
||||||
onEvalError: (err) => {
|
onEvalError: (err) => {
|
||||||
setPending(false);
|
setPending(false);
|
||||||
|
|
|
||||||
25
website/src/repl/helpers.mjs
Normal file
25
website/src/repl/helpers.mjs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
export function unicodeToBase64(text) {
|
||||||
|
const utf8Bytes = new TextEncoder().encode(text);
|
||||||
|
const base64String = btoa(String.fromCharCode(...utf8Bytes));
|
||||||
|
return base64String;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function base64ToUnicode(base64String) {
|
||||||
|
const utf8Bytes = new Uint8Array(
|
||||||
|
atob(base64String)
|
||||||
|
.split('')
|
||||||
|
.map((char) => char.charCodeAt(0)),
|
||||||
|
);
|
||||||
|
const decodedText = new TextDecoder().decode(utf8Bytes);
|
||||||
|
return decodedText;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function code2hash(code) {
|
||||||
|
return encodeURIComponent(unicodeToBase64(code));
|
||||||
|
//return '#' + encodeURIComponent(btoa(code));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hash2code(hash) {
|
||||||
|
return base64ToUnicode(decodeURIComponent(hash));
|
||||||
|
//return atob(decodeURIComponent(codeParam || ''));
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue