This commit is contained in:
Preet Shihn
2018-03-08 17:07:17 -08:00
parent 850dd88408
commit f2a9a53ba6
3 changed files with 17 additions and 11 deletions

11
dist/rough.2.0.js vendored
View File

@@ -647,12 +647,15 @@ class RoughCanvas {
async lib() {
if (!this._renderer) {
if (this.useWorker) {
if (this.useWorker && window.workly) {
const tos = Function.prototype.toString;
let code = `importScripts('https://cdn.jsdelivr.net/gh/pshihn/workly/dist/workly.min.js');\n${tos.call(RoughSegmentRelation)}\n${tos.call(RoughSegment)}\n${tos.call(RoughHachureIterator)}\n${tos.call(RoughRenderer)}\nworkly.expose(RoughRenderer);`;
let ourl = URL.createObjectURL(new Blob([code]));
let RenderedWorker = workly.proxy(ourl);
this._renderer = await new RenderedWorker();
// let Renderer = workly.proxy(RoughRenderer);
// this._renderer = await new Renderer();
this._renderer = new RoughRenderer();
// this._renderer = new RoughRenderer();
} else {
this._renderer = new RoughRenderer();
}

View File

@@ -2,6 +2,7 @@
<head>
<title>RoughJS sample</title>
<script src="https://cdn.jsdelivr.net/gh/pshihn/workly/dist/workly.js"></script>
<script src="../../dist/rough.2.0.js"></script>
<style>
canvas {
@@ -15,7 +16,7 @@
<script>
(async () => {
const rough = new RoughCanvas(document.getElementById('canvas'));
const rough = new RoughCanvas(document.getElementById('canvas'), true);
await rough.line(60, 60, 190, 60);
await rough.rectangle(10, 10, 100, 100);
await rough.rectangle(140, 10, 100, 100, {

View File

@@ -1,3 +1,5 @@
import { RoughSegmentRelation, RoughSegment } from './core/segment.js';
import { RoughHachureIterator } from './core/hachure.js';
import { RoughRenderer } from './core/renderer.js';
export default class RoughCanvas {
@@ -23,12 +25,12 @@ export default class RoughCanvas {
async lib() {
if (!this._renderer) {
if (this.useWorker) {
// let Renderer = workly.proxy(RoughRenderer);
// this._renderer = await new Renderer();
this._renderer = new RoughRenderer();
if (this.useWorker && window.workly) {
const tos = Function.prototype.toString;
let code = `importScripts('https://cdn.jsdelivr.net/gh/pshihn/workly/dist/workly.min.js');\n${tos.call(RoughSegmentRelation)}\n${tos.call(RoughSegment)}\n${tos.call(RoughHachureIterator)}\n${tos.call(RoughRenderer)}\nworkly.expose(RoughRenderer);`;
let ourl = URL.createObjectURL(new Blob([code]));
let RenderedWorker = workly.proxy(ourl);
this._renderer = await new RenderedWorker();
} else {
this._renderer = new RoughRenderer();
}