From cec54109e02db332718920cbcb0f17b38621705d Mon Sep 17 00:00:00 2001 From: MinhHNguyen Date: Thu, 3 Aug 2017 23:02:37 -0700 Subject: [PATCH] Update: move rbush from static to npm module (#275) * Update: move rbush from static to npm module * Fix: do not include drawing --- package.json | 1 + src/lib/annotations/drawing/DrawingThread.js | 10 ++++++---- src/lib/viewers/doc/docAssets.js | 3 +-- src/third-party/doc/0.130.0/rbush.min.js | 2 -- yarn.lock | 10 ++++++++++ 5 files changed, 18 insertions(+), 8 deletions(-) delete mode 100644 src/third-party/doc/0.130.0/rbush.min.js diff --git a/package.json b/package.json index db330b5fe..12ee8065e 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "prettier-eslint-cli": "^4.1.1", "rangy": "^1.3.0", "raw-loader": "^0.5.1", + "rbush": "^2.0.1", "react": "^15.6.1", "react-addons-shallow-compare": "^15.6.0", "react-dom": "^15.6.1", diff --git a/src/lib/annotations/drawing/DrawingThread.js b/src/lib/annotations/drawing/DrawingThread.js index bff922f06..97a01d180 100644 --- a/src/lib/annotations/drawing/DrawingThread.js +++ b/src/lib/annotations/drawing/DrawingThread.js @@ -1,4 +1,4 @@ -/* global Rbush */ +import rbush from 'rbush'; import AnnotationThread from '../AnnotationThread'; import { STATES_DRAW, DRAW_RENDER_THRESHOLD } from '../annotationConstants'; @@ -9,8 +9,10 @@ class DrawingThread extends AnnotationThread { /** @property {number} - Drawing state */ drawingFlag = STATES_DRAW.idle; - /** @property {Rbush} - Rtree path container */ - pathContainer = new Rbush(RTREE_WIDTH); + /** @property {rbush} - Rtree path container */ + /* eslint-disable new-cap */ + pathContainer = new rbush(RTREE_WIDTH); + /* eslint-enable new-cap */ /** @property {CanvasContext} - A canvas for drawing new strokes */ memoryCanvas; @@ -143,7 +145,7 @@ class DrawingThread extends AnnotationThread { drawings.forEach((drawing) => drawing.drawPath(this.drawingContext)); if (this.pendingPath) { - this.pendingPath.drawPath(context); + this.pendingPath.drawPath(this.drawingContext); } } diff --git a/src/lib/viewers/doc/docAssets.js b/src/lib/viewers/doc/docAssets.js index b14c1db34..b03586cd8 100644 --- a/src/lib/viewers/doc/docAssets.js +++ b/src/lib/viewers/doc/docAssets.js @@ -5,7 +5,6 @@ export const JS = [ `${STATIC_URI}pdf.min.js`, `${STATIC_URI}pdf_viewer.min.js`, `${STATIC_URI}pdf.worker.min.js`, - `${STATIC_URI}exif.min.js`, - `${STATIC_URI}rbush.min.js` + `${STATIC_URI}exif.min.js` ]; export const CSS = [`${STATIC_URI}pdf_viewer.min.css`]; diff --git a/src/third-party/doc/0.130.0/rbush.min.js b/src/third-party/doc/0.130.0/rbush.min.js deleted file mode 100644 index 18c3cab79..000000000 --- a/src/third-party/doc/0.130.0/rbush.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/** eslint-disable */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,i.Rbush=t()}}(function(){return function t(i,n,e){function r(h,o){if(!n[h]){if(!i[h]){var s="function"==typeof require&&require;if(!o&&s)return s(h,!0);if(a)return a(h,!0);var f=new Error("Cannot find module '"+h+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[h]={exports:{}};i[h][0].call(l.exports,function(t){var n=i[h][1][t];return r(n||t)},l,l.exports,t,i,n,e)}return n[h].exports}for(var a="function"==typeof require&&require,h=0;h=t.minX&&i.maxY>=t.minY}function p(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(t,i,n,e,r){for(var a,h=[i,n];h.length;)n=h.pop(),i=h.pop(),n-i<=e||(a=i+Math.ceil((n-i)/e/2)*e,g(t,a,i,n,r),h.push(i,a,a,n))}i.exports=e;var g=t("quickselect");e.prototype={all:function(){return this._all(this.data,[])},search:function(t){var i=this.data,n=[],e=this.toBBox;if(!x(t,i))return n;for(var r,a,h,o,s=[];i;){for(r=0,a=i.children.length;r=0&&a[i].children.length>this._maxEntries;)this._split(a,i),i--;this._adjustParentBBoxes(r,a,i)},_split:function(t,i){var n=t[i],e=n.children.length,r=this._minEntries;this._chooseSplitAxis(n,r,e);var h=this._chooseSplitIndex(n,r,e),o=p(n.children.splice(h,n.children.length-h));o.height=n.height,o.leaf=n.leaf,a(n,this.toBBox),a(o,this.toBBox),i?t[i-1].children.push(o):this._splitRoot(n,o)},_splitRoot:function(t,i){this.data=p([t,i]),this.data.height=t.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},_chooseSplitIndex:function(t,i,n){var e,r,a,o,s,f,u,c;for(f=u=1/0,e=i;e<=n-i;e++)r=h(t,0,e,this.toBBox),a=h(t,e,n,this.toBBox),o=m(r,a),s=l(r)+l(a),o=i;r--)a=t.children[r],o(l,t.leaf?s(a):a),c+=u(l);return c},_adjustParentBBoxes:function(t,i,n){for(var e=n;e>=0;e--)o(i[e],t)},_condense:function(t){for(var i,n=t.length-1;n>=0;n--)0===t[n].children.length?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():a(t[n],this.toBBox)},_initFormat:function(t){var i=["return a"," - b",";"];this.compareMinX=new Function("a","b",i.join(t[0])),this.compareMinY=new Function("a","b",i.join(t[1])),this.toBBox=new Function("a","return {minX: a"+t[0]+", minY: a"+t[1]+", maxX: a"+t[2]+", maxY: a"+t[3]+"};")}}},{quickselect:2}],2:[function(t,i,n){"use strict";function e(t,i,n,h,o){for(n=n||0,h=h||t.length-1,o=o||a;h>n;){if(h-n>600){var s=h-n+1,f=i-n+1,l=Math.log(s),u=.5*Math.exp(2*l/3),c=.5*Math.sqrt(l*u*(s-u)/s)*(f-s/2<0?-1:1);e(t,i,Math.max(n,Math.floor(i-f*u/s+c)),Math.min(h,Math.floor(i+(s-f)*u/s+c)),o)}var m=t[i],d=n,x=h;for(r(t,n,i),o(t[h],m)>0&&r(t,n,h);d0;)x--}0===o(t[n],m)?r(t,n,x):(x++,r(t,x,h)),x<=i&&(n=x+1),i<=x&&(h=x-1)}}function r(t,i,n){var e=t[i];t[i]=t[n],t[n]=e}function a(t,i){return ti?1:0}i.exports=e},{}]},{},[1])(1)}); diff --git a/yarn.lock b/yarn.lock index 758f36035..543ab238f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5556,6 +5556,10 @@ quick-lru@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-1.0.0.tgz#7fa80304ab72c1f81cef738739cd47d7cc0c8bff" +quickselect@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/quickselect/-/quickselect-1.0.0.tgz#02630818f9aae4ecab26f0103f98d061c17c58f3" + randomatic@^1.1.3: version "1.1.7" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c" @@ -5589,6 +5593,12 @@ raw-loader@^0.5.1: version "0.5.1" resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-0.5.1.tgz#0c3d0beaed8a01c966d9787bf778281252a979aa" +rbush@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/rbush/-/rbush-2.0.1.tgz#4cfaca28c3064bc0ee75431a1b79990e875eefa9" + dependencies: + quickselect "^1.0.0" + rc@1.1.7, rc@^1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/rc/-/rc-1.1.7.tgz#c5ea564bb07aff9fd3a5b32e906c1d3a65940fea"