mirror of
https://github.com/rough-stuff/rough.git
synced 2026-01-21 04:07:55 -05:00
15 lines
769 B
JavaScript
15 lines
769 B
JavaScript
import { RoughRenderer } from './renderer';
|
|
const hasSelf = typeof self !== 'undefined';
|
|
const roughScript = hasSelf && self && self.document && self.document.currentScript && self.document.currentScript.src;
|
|
export function createRenderer(config) {
|
|
if (hasSelf && roughScript && self && self.workly && config.async && (!config.noWorker)) {
|
|
const worklySource = config.worklyURL || 'https://cdn.jsdelivr.net/gh/pshihn/workly/dist/workly.min.js';
|
|
if (worklySource) {
|
|
const code = `importScripts('${worklySource}', '${roughScript}');\nworkly.expose(self.rough.createRenderer());`;
|
|
const ourl = URL.createObjectURL(new Blob([code]));
|
|
return self.workly.proxy(ourl);
|
|
}
|
|
}
|
|
return new RoughRenderer();
|
|
}
|