Files
rough/bin/renderer-factory.js
2018-06-18 13:08:58 -07:00

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();
}