@scena/ruler
Version:
A Vanilla Ruler component that can draw grids and scroll infinitely.
11 lines (10 loc) • 22.6 kB
JavaScript
/*
Copyright (c) Daybrush
name: @scena/ruler
license: MIT
author: Daybrush
repository: git+https://github.com/daybrush/ruler.git
version: 0.20.0
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Ruler=e()}(this,function(){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};var s=function(){return(s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function c(e,n){return function(t){t&&(e[n]=t)}}var M="function",B="object",N="string",L="undefined",u={cm:function(t){return 96*t/2.54},mm:function(t){return 96*t/254},in:function(t){return 96*t},pt:function(t){return 96*t/72},pc:function(t){return 96*t/6},"%":function(t,e){return t*e/100},vw:function(t,e){return t/100*(e=void 0===e?window.innerWidth:e)},vh:function(t,e){return t/100*(e=void 0===e?window.innerHeight:e)},vmax:function(t,e){return t/100*(e=void 0===e?Math.max(window.innerWidth,window.innerHeight):e)},vmin:function(t,e){return t/100*(e=void 0===e?Math.min(window.innerWidth,window.innerHeight):e)}};function v(t){return typeof t===N}function C(t,r){return void 0===r&&(r="-"),t.replace(/([a-z])([A-Z])/g,function(t,e,n){return""+e+r+n.toLowerCase()})}function rt(t,e){e=function(t,e,n){void 0===n&&(n=-1);for(var r=t.length-1;0<=r;--r)if(e(t[r],r,t))return r;return n}(t,e);-1<e&&t[e]}function U(t,e,n){e=function(t,e,n){void 0===n&&(n=-1);for(var r=t.length,o=0;o<r;++o)if(e(t[o],o,t))return o;return n}(t,e);return-1<e?t[e]:n}function l(t){return Object.keys(t)}function nt(t,e){var n=(t=/^([^\d|e|\-|\+]*)((?:\d|\.|-|e-|e\+)+)(\S*)$/g.exec(t=t))?(n=t[1],r=t[2],{prefix:n,unit:t[3],value:parseFloat(r)}):{prefix:"",unit:"",value:NaN},t=n.value,r=n.unit;if((o=e)&&typeof o===B){var o=e[r];if(o){if(typeof o===M)return o(t);if(u[r])return u[r](t,o)}}else if("%"===r)return t*e/100;return u[r]?u[r](t):t}function a(t,e,n,r){t.removeEventListener(e,n,r)}var W=function(){function t(){this.keys=[],this.values=[]}var e=t.prototype;return e.get=function(t){return this.values[this.keys.indexOf(t)]},e.set=function(t,e){var n=this.keys,r=this.values,o=n.indexOf(t),o=-1===o?n.length:o;n[o]=t,r[o]=e},t}(),D=function(){function t(){this.object={}}var e=t.prototype;return e.get=function(t){return this.object[t]},e.set=function(t,e){this.object[t]=e},t}(),I="function"==typeof Map,H=function(){function t(){}var e=t.prototype;return e.connect=function(t,e){this.prev=t,this.next=e,t&&(t.next=this),e&&(e.prev=this)},e.disconnect=function(){var t=this.prev,e=this.next;t&&(t.next=e),e&&(e.prev=t)},e.getIndex=function(){for(var t=this,e=-1;t;)t=t.prev,++e;return e},t}();var F=function(){function t(t,e,n,r,o,i,s,c){this.prevList=t,this.list=e,this.added=n,this.removed=r,this.changed=o,this.maintained=i,this.changedBeforeAdded=s,this.fixed=c}var e=t.prototype;return Object.defineProperty(e,"ordered",{get:function(){return this.cacheOrdered||this.caculateOrdered(),this.cacheOrdered},enumerable:!0,configurable:!0}),Object.defineProperty(e,"pureChanged",{get:function(){return this.cachePureChanged||this.caculateOrdered(),this.cachePureChanged},enumerable:!0,configurable:!0}),e.caculateOrdered=function(){t=this.changedBeforeAdded,n=this.fixed,o=[],i=[],t.forEach(function(t){var e=t[0],t=t[1],n=new H;i[t]=o[e]=n}),o.forEach(function(t,e){t.connect(o[e-1])});var n,o,i,t=t.filter(function(t,e){return!n[e]}).map(function(t,e){var n,r=t[0],t=t[1];return r===t?[0,0]:(t=i[t-1],n=(r=o[r]).getIndex(),r.disconnect(),t?r.connect(t,t.next):r.connect(void 0,o[0]),[n,r.getIndex()])}),s=this.changed,c=[];this.cacheOrdered=t.filter(function(t,e){var n=t[0],t=t[1],e=s[e],r=e[0],e=e[1];if(n!==t)return c.push([r,e]),!0}),this.cachePureChanged=c},t}();function y(t,e,n){var r=I?Map:n?D:W,n=n||function(t){return t},o=[],i=[],s=[],c=t.map(n),n=e.map(n),u=new r,a=new r,l=[],f=[],h={},d=[],p=0,v=0;return c.forEach(function(t,e){u.set(t,e)}),n.forEach(function(t,e){a.set(t,e)}),c.forEach(function(t,e){t=a.get(t);void 0===t?(++v,i.push(e)):h[t]=v}),n.forEach(function(t,e){t=u.get(t);void 0===t?(o.push(e),++p):(s.push([t,e]),v=h[e]||0,l.push([t-v,e-p]),f.push(e===t),t!==e&&d.push([t,e]))}),i.reverse(),new F(t,e,o,i,d,s,l,f)}var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};function o(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var g=function(){return(g=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function f(t,e){var n={};for(o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,o=Object.getOwnPropertySymbols(t);r<o.length;r++)e.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(t,o[r])&&(n[o[r]]=t[o[r]]);return n}function m(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||((r=r||Array.prototype.slice.call(e,0,o))[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function _(t){var e=0;return t.map(function(t){return null==t?"$compat".concat(++e):"".concat(t)})}function h(t){var e=[];return t.forEach(function(t){e=e.concat(Array.isArray(t)?h(t):t)}),e}function b(t,e){if(e)for(var n in e)typeof t[n]===L&&(t[n]=e[n]);return t}function d(t,e){if(t!==e){for(var n in t)if(!(n in e))return!0;for(var n in e)if(t[n]!==e[n])return!0}return!1}function E(t){var e=t.className,t=f(t,["className"]);return null!=e&&(t.class=e),delete t.style,delete t.children,t}function R(t){var e,n={},r={};for(e in t)0===e.indexOf("on")?r[e]=t[e]:n[e]=t[e];return[n,r]}function k(t){var e;return t?(e=t.b)instanceof Node?e:k(t.c):null}function p(t){var e=t.parentNode;e&&e.removeChild(t)}function x(t){t.forEach(function(t){t()})}function q(){return this.constructor(this.props,this.context)}var t=function(){function t(t,e,n,r,o,i,s){void 0===s&&(s={}),this.t=t,this.d=e,this.k=n,this.i=r,this.c=o,this.ref=i,this.ps=s,this.typ="prov",this._ps=[],this._cs={},this._hyd=null,this._sel=!1}var e=t.prototype;return e.s=function(){return!0},e.u=function(e,n,t,r,o){var i,s=this,c=s.d,u=h(l(i=n).map(function(t){return i[t]}).filter(function(t){return t.$_req}).map(function(t){return t.$_subs})),a=U(u,function(t){return t.d===c});if(s.b&&!v(t)&&!o&&!s.s(t.props,r)&&!a)return u.reduce(function(t,e){var n=e.d;return t[0]?t[0].d===n&&t.push(e):c<n&&t.push(e),t},[]).forEach(function(t){$(t,t._ps,[t.o],e,n,!0)}),!1;s.o=t,s.ss(r);o=s.ps;return v(t)||(s.ps=t.props,s.ref=t.ref),w(this),s.r(e,n,s.b?o:{},r),!0},e.md=function(){this.rr()},e.ss=function(){},e.ud=function(){this.rr()},e.rr=function(){var t=this.ref,e=this.fr;t&&t(e?e.current:this.b)},t}();function w(t){Object.__CROACT_CURRENT_INSTNACE__=t}var O=function(){function t(t,e){this.props=t=void 0===t?{}:t,this.context=e,this.state={},this.$_timer=0,this.$_state={},this.$_subs=[],this.$_cs={}}var e=t.prototype;return e.render=function(){return null},e.shouldComponentUpdate=function(t,e){return this.props!==t||this.state!==e},e.setState=function(t,e,n){var r=this;r.$_timer||(r.$_state={}),clearTimeout(r.$_timer),r.$_timer=0,r.$_state=g(g({},r.$_state),t),n?r.$_setState(e,n):r.$_timer=window.setTimeout(function(){r.$_timer=0,r.$_setState(e,n)})},e.forceUpdate=function(t){this.setState({},t,!0)},e.componentDidMount=function(){},e.componentDidUpdate=function(t,e){},e.componentWillUnmount=function(){},e.$_setState=function(t,e){var n=[],r=this.$_p;$(r.c,[r],[r.o],n,r._cs,g(g({},this.state),this.$_state),e)&&(t&&n.push(t),x(n),w(null))},t}(),G=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.shouldComponentUpdate=function(t,e){return d(this.props,t)||d(this.state,e)},e}(O);function V(t){function e(t){e.current=t}return e.current=t,e}var Z=function(c){function t(t,e,n,r,o,i,s){e=c.call(this,t,e,n,r,o,i,b(s=void 0===s?{}:s,t.defaultProps))||this;return e.typ="comp",e._usefs=[],e._uefs=[],e._defs=[],e}o(t,c);var e=t.prototype;return e.s=function(t,e){var n=this.b;return!1!==n.shouldComponentUpdate(b(t,this.t.defaultProps),e||n.state)},e.r=function(t,e,n){var r,o,i,s,c=this,u=c.t,a=(c.ps=b(c.ps,c.t.defaultProps),c.ps),l=!c.b,f=u.contextType,h=c.b,d=null==f?void 0:f.get(c),p=(c._cs=e,l?(r=a,o=d,i=c,null!=(v=null==(u=u)?void 0:u.prototype)&&v.render?s=new u(r,o):((s=new O(r,o)).constructor=u)._fr?(i.fr=V(),s.render=function(){return this.constructor(this.props,i.fr)}):s.render=q,s.$_p=i,h=s,c.b=h):(h.props=a,h.context=d),h.state),v=(c._usefs=[],c._uefs=[],h.render()),u=(0===(null==(o=null==(r=null==v?void 0:v.props)?void 0:r.children)?void 0:o.length)&&(v.props.children=c.ps.children),g(g({},e),h.$_cs));$(c,c._ps,v?[v]:[],t,u),l?c._uefs.push(function(){null!=f&&f.register(c),h.componentDidMount()}):c._uefs.push(function(){h.componentDidUpdate(n,p)}),t.push(function(){c._usefs.forEach(function(t){t()}),l?c.md():c.ud(),c._defs=c._uefs.map(function(t){return t()})})},e.ss=function(t){var e=this.b;e&&t&&(e.state=t)},e.un=function(){var t,e=this;e._ps.forEach(function(t){t.un()}),null!=(t=e.t.contextType)&&t.unregister(e),clearTimeout(e.b.$_timer),e._defs.forEach(function(t){t&&t()}),e.b.componentWillUnmount()},t}(t);function z(n,r){var o=l(n),e=l(r),t=y(o,e,function(t){return t}),i={},s={},c={};return t.added.forEach(function(t){t=e[t];i[t]=r[t]}),t.removed.forEach(function(t){t=o[t];s[t]=n[t]}),t.maintained.forEach(function(t){var t=t[0],t=o[t],e=[n[t],r[t]];n[t]!==r[t]&&(c[t]=e)}),{added:i,removed:s,changed:c}}var J=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.typ="elem",t._es={},t._svg=!1,t}o(t,e);var n=t.prototype;return n.e=function(r,t){var e,o=this,n=o._es,i=o.b,s=r.replace(/^on/g,"").toLowerCase();t?(a(i,s,n[r]),delete n[r]):(n[r]=function(t){var e,n;null!=(n=(e=o.ps)[r])&&n.call(e,t)},t=n[r],i.addEventListener(s,t,e))},n.s=function(t){return d(this.ps,t)},n.r=function(t,e,n){var r,o,i,s=this,c=!s.b,u=s.ps,a=(c&&(a=!1,a=!(!s._svg&&"svg"!==s.t)||(f=k(s.c))&&f.ownerSVGElement,s._svg=a,f=null==(f=s._hyd)?void 0:f.splice(0,1)[0],l=s.t,f?s._hyd=[].slice.call(f.children||[]):f=a?document.createElementNS("http://www.w3.org/2000/svg",l):document.createElement(l),s.b=f),$(s,s._ps,u.children,t,e),s.b),l=R(n),f=l[0],e=l[1],l=R(u),h=l[0],l=l[1],d=a,p=(f=z(E(f),E(h))).added,h=f.removed,v=f.changed;for(r in p)d.setAttribute(r,p[r]);for(o in v)d.setAttribute(o,v[o][1]);for(i in h)d.removeAttribute(i);var y,g,h=e,m=s,e=(h=z(e,e=l)).added;for(y in h.removed)m.e(y,!0);for(g in e)m.e(g);var _,h=n.style||{},e=u.style||{},n=a,b=n.style,x=(n=z(h,e)).added,h=n.removed,w=n.changed;for(_ in x){var O=C(_,"-");b.setProperty(O,x[_])}for(_ in w){var S=C(_,"-");b.setProperty(S,w[_][1])}for(_ in h){var P=C(_,"-");b.removeProperty(P)}return t.push(function(){c?s.md():s.ud()}),!0},n.un=function(){var t,e=this,n=e._es,r=e.b;for(t in n)a(r,t,n[t]);e._ps.forEach(function(t){t.un()}),e._es={},e._sel||p(r)},t}(t);function S(t){return!t||t instanceof Node?t:(t=t.$_p._ps).length?S(t[0].b):null}function P(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var e=e||{},o=e.key,i=e.ref,e=f(e,["key","ref"]);return{type:t,key:o,ref:i,props:g(g({},e),{children:n.reduce(function(t,e){return t.concat(e)},[]).filter(function(t){return null!=t&&!1!==t})})}}var j=function(n){function t(t,e){e=n.call(this,"container",e=void 0===e?0:e,"container",0,null)||this;return e.typ="container",e.b=t,e}o(t,n);var e=t.prototype;return e.r=function(){return!0},e.un=function(){},t}(t),K=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.typ="text",t}o(t,e);var n=t.prototype;return n.r=function(t){var e,n=this,r=!n.b;return r&&(e=null==(e=n._hyd)?void 0:e.splice(0,1)[0],n.b=e||document.createTextNode(n.t.replace("text_",""))),t.push(function(){r?n.md():n.ud()}),!0},n.un=function(){p(this.b)},t}(t);function T(t,e,n,r){var o,i=r.d+1;return v(t)||"number"==typeof t?new K("text_".concat(t),i,e,n,r,null,{}):new("string"==typeof(o=t.type)?J:Z)(o,i,e,n,r,t.ref,t.props)}function $(n,r,o,i,s,c,u){a=n,l=r,h=(f=o).map(function(t){return v(t)?null:t.key}),(t=y(_(l.map(function(t){return t.k})),_(h),function(t){return t})).removed.forEach(function(t){l.splice(t,1)[0].un()}),t.ordered.forEach(function(t){var e=t[0],t=t[1],e=l.splice(e,1)[0],e=(l.splice(t,0,e),S(e.b)),t=S(l[t+1]&&l[t+1].b);e&&e.parentNode.insertBefore(e,t)}),t.added.forEach(function(t){l.splice(t,0,T(f[t],h[t],t,a))}),e=t.maintained.filter(function(t){t[0];var t=t[1],e=f[t],n=l[t];return(v(e)?"text_".concat(e):e.type)!==n.t?(n.un(),l.splice(t,1,T(e,h[t],t,a)),!0):(n.i=t,!1)});var a,l,f,h,t=m(m([],t.added,!0),e.map(function(t){return t[0],t[1]}),!0),d=n._hyd,e=r.filter(function(t,e){return t._hyd=d,t.u(i,s,o[e],c,u)}),p=("container"===n.typ&&n._sel&&r.forEach(function(t){t=function t(e){if(e)return e.b&&e.b instanceof Node?e:(e=e._ps).length?t(e[0]):null}(t);t&&(t._sel=!0)}),n._hyd=null,k(n));return p&&t.reverse().forEach(function(t){var t=r[t],e=S(t.b);e&&p!==e&&!e.parentNode&&(t=function(t,e){for(var n=t._ps,r=n.length,o=e.i+1;o<r;++o){var i=S(n[o].b);if(i)return i}return null}(n,t),p.insertBefore(e,t))}),0<e.length}function A(t,e,n){var r,o,i;!n&&t&&((n=new j(e.parentElement))._hyd=[e],n._sel=!0),t=t,e=e,void 0===r&&(r={}),o=!!(n=void 0===(n=n)?e.__CROACT__:n),i=[],$(n=n||new j(e),n._ps,t?[t]:[],i,r,void 0,void 0),x(i),w(null),o||(e.__CROACT__=n)}var Q=function(t,e){return(Q=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};var e,X=function(e){var t=o,n=e;if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.state={scrollPos:0},t.width=0,t.height=0,t._zoom=0,t._rulerScale=0,t._observer=null,t._checkResize=function(){t.resize()},t}Q(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r);n=o.prototype;return n.render=function(){var t=this.props;return this._zoom=t.zoom,P("canvas",{ref:c(this,"canvasElement"),style:this.props.style})},n.componentDidMount=function(){var t=this.props,e=(this.state.scrollPos=t.defaultScrollPos||0,this.canvasElement),n=e.getContext("2d",{alpha:!0});this.canvasContext=n,t.useResizeObserver?(this._observer=new ResizeObserver(this._checkResize),this._observer.observe(e,{box:"border-box"})):this.resize()},n.componentDidUpdate=function(){this.resize()},n.componentWillUnmount=function(){var t;this.state.scrollPos=0,null!=(t=this._observer)&&t.disconnect()},n.getScrollPos=function(){return this.state.scrollPos},n.scroll=function(t,e){this.draw({scrollPos:t,zoom:e})},n.resize=function(t){var e=this.canvasElement,n=this.props,r=n.width,o=n.height,n=n.scrollPos,i=this._getRulerScale();this.width=r||e.offsetWidth,this.height=o||e.offsetHeight,e.width=this.width*i,e.height=this.height*i,this.draw({scrollPos:n,zoom:t})},n.draw=function(t){var e=this.props,n=(t=void 0===t?{}:t).zoom,a=void 0===n?this._zoom:n,n=t.scrollPos,l=void 0===n?this.state.scrollPos:n,n=t.marks,n=void 0===n?e.marks:n,r=t.selectedRanges,r=void 0===r?e.selectedRanges:r,o=t.segment,i=void 0===o?e.segment||10:o,o=t.unit,f=void 0===o?e.unit:o;this._zoom=a;var t=e.type,o=e.backgroundColor,B=e.lineColor,N=e.textColor,L=e.textBackgroundColor,h=e.direction,s=e.negativeRuler,U=void 0===s||s,c=e.textFormat,s=e.range,d=void 0===s?[-1/0,1/0]:s,s=e.rangeBackgroundColor,W=e.selectedBackgroundColor,u=e.lineWidth,u=void 0===u?1:u,D=e.selectedRangesText,p=e.selectedRangesTextColor,I=void 0===p?"#44aaff":p,p=e.selectedRangesTextOffset,H=void 0===p?[0,0]:p,p=e.markColor,p=void 0===p?"#ff5":p,v=this._getRulerScale(),y=this.width,g=this.height,m=(this.state.scrollPos=l,this.canvasContext),_="horizontal"===t,F=!1!==U,t=e.font||"10px sans-serif",b=e.textAlign||"left",q=e.textOffset||[0,0],x=_?g:y,w=nt("".concat(e.mainLineSize||"100%"),x),G=nt("".concat(e.longLineSize||10),x),V=nt("".concat(e.shortLineSize||7),x),O=e.lineOffset||[0,0];switch("transparent"===o?m.clearRect(0,0,y*v,g*v):(m.rect(0,0,y*v,g*v),m.fillStyle=o,m.fill()),m.save(),m.scale(v,v),m.strokeStyle=B,m.lineWidth=u,m.font=t,m.fillStyle=N,m.textAlign=b,h){case"start":m.textBaseline="top";break;case"center":m.textBaseline="middle";break;case"end":m.textBaseline="bottom"}m.translate(.5,0),m.beginPath();for(var S=_?y:g,P=a*f,C=Math.floor(l*a/P),Z=Math.ceil((l*a+S)/P)-C,J=Math.max(["left","center","right"].indexOf(b)-1,-1),E=_?g:y,R=[],k=0;k<=Z;++k){var z=(k+C)*f,K="".concat(z),Q=(c&&(K=c(z)),m.measureText(K).width);R.push({color:N,offset:q,backgroundColor:L,value:z,text:K,textSize:Q})}"transparent"!==W&&null!=r&&r.length&&r.forEach(function(t){var e=Math.max(t[0],d[0],U?-1/0:0),n=Math.min(t[1],d[1]),r=(e-l)*a,n=(n-e)*a;D&&t.forEach(function(t){var e="".concat(t),n=(c&&(e=c(t)),m.measureText(e).width),r=t*a,o=r+n;rt(R,function(t,e){var n=t.value,t=t.textSize,n=n*a;n<=o&&r<=n+t&&R.splice(e,1)}),R.push({value:t,color:I,offset:H,text:e,textSize:n})}),n<=0||(m.save(),m.fillStyle=W,_?m.fillRect(r,0,n,E):m.fillRect(0,r,E,n),m.restore())}),"transparent"!==s&&d[0]!==-1/0&&d[1]!==1/0&&(e=(d[0]-l)*a,o=(d[1]-d[0])*a,m.save(),m.fillStyle=s,_?m.fillRect(e,0,o,E):m.fillRect(0,e,E,o),m.restore());for(k=0;k<=Z;++k){z=k+C;if(F||!(z<0))for(var X=z*f,Y=(X-l)*a,j=0;j<i;++j){var T=Y+j/i*P,$=X+j/i*f;if(!(T<0||S<=T||$<d[0]||$>d[1])){var A=0===j?w:j%2==0?G:V,M=0;switch(h){case"start":M=0;break;case"center":M=E/2-A/2;break;case"end":M=E-A}var $=_?[T+O[0],M+O[1]]:[M+O[0],T+O[1]],T=$[0],$=$[1],tt=_?[T,$+A]:[T+A,$],et=tt[0],tt=tt[1];m.moveTo(T+O[0],$+O[1]),m.lineTo(et+O[0],tt+O[1])}}}m.stroke(),m.beginPath(),m.strokeStyle=p,m.lineWidth=1,(n||[]).forEach(function(t){var e,n,r=(-l+t)*a;r<0||S<=r||t<d[0]||t>d[1]||(r=(t=_?[r+O[0],O[1]]:[O[0],r+O[1]])[0],t=t[1],e=(n=_?[r,t+x]:[r+x,t])[0],n=n[1],m.moveTo(r+O[0],t+O[1]),m.lineTo(e+O[0],n+O[1]))}),m.stroke(),R.forEach(function(t){var e=t.value,n=t.offset,r=t.backgroundColor,o=t.color,i=t.text,s=t.textSize;if(F||!(e<0)){t=(e-l)*a;if(!(t<-P||S+f*a<=t||e<d[0]||e>d[1])){var c=0;switch(h){case"start":c=17;break;case"center":c=E/2;break;case"end":c=E-17}e=_?[t+-3*J,c]:[c,t+3*J],t=e[0],e=e[1];if(r){var u=0;switch(b){case"left":u=0;break;case"center":u=-s/2;break;case"right":u=-s}m.save(),m.fillStyle=r,_?m.fillRect(t+n[0]+u,0,s,w):(m.translate(0,e+n[1]),m.rotate(-Math.PI/2),m.fillRect(u,0,s,w)),m.restore()}m.save(),m.fillStyle=o,_?m.fillText(i,t+n[0],e+n[1]):(m.translate(t+n[0],e+n[1]),m.rotate(-Math.PI/2),m.fillText(i,0,0)),m.restore()}}}),m.restore()},n._getRulerScale=function(){var t,e,n=this.props.defaultPixelScale||2;return this._rulerScale||(!(e=1<window.devicePixelRatio)&&window.matchMedia&&(e=(t=window.matchMedia("only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)"))&&t.matches),this._rulerScale=e?3:n),this._rulerScale},o.defaultProps={type:"horizontal",zoom:1,width:0,height:0,unit:50,negativeRuler:!0,mainLineSize:"100%",longLineSize:10,shortLineSize:7,segment:10,direction:"end",style:{width:"100%",height:"100%"},backgroundColor:"#333333",font:"10px sans-serif",textColor:"#ffffff",textBackgroundColor:"transparent",lineColor:"#777777",range:[-1/0,1/0],rangeBackgroundColor:"transparent",lineWidth:1,selectedBackgroundColor:"#555555",defaultScrollPos:0,markColor:"#f55",marks:[]},o}(G),Y=["type","width","height","unit","zoom","direction","textAlign","font","segment","mainLineSize","longLineSize","shortLineSize","lineOffset","textOffset","negativeRuler","range","scrollPos","defaultScrollPos","style","backgroundColor","rangeBackgroundColor","lineColor","textColor","textBackgroundColor","textFormat","warpSelf","selectedBackgroundColor","selectedRanges","defaultPixelScale","useResizeObserver","selectedRangesText","selectedRangesTextColor","selectedRangesTextOffset","marks","markColor"],t=["scroll","resize","getScrollPos","draw"],tt=function(e){var t=o,n=e;if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}function o(t){t=e.call(this,t)||this;return t.state={},t.state=t.props,t}return i(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r),o.prototype.render=function(){return P(X,s({ref:c(this,"ruler")},this.state))},o}(O),n=function(){function t(t,e){var n;void 0===e&&(e={}),this.containerProvider=null,this.selfElement=null,this._warp=!1,e.warpSelf?(delete e.warpSelf,this._warp=!0,n=t):(n=document.createElement("canvas"),t.appendChild(n)),A(P(tt,s({ref:c(this,"innerRuler")},e)),n)}var n,r,e=t.prototype;return e.scroll=function(t){this.getRuler().scroll(t)},e.resize=function(){this.getRuler().resize()},e.getScrollPos=function(){return this.getRuler().getScrollPos()},e.draw=function(t){this.getRuler().draw(t)},e.destroy=function(){var t,e=this.selfElement;A(null,e,this.containerProvider),this._warp||null!=(t=null==e?void 0:e.parentElement)&&t.removeChild(e),this.selfElement=null,this.innerRuler=null},e.getRuler=function(){return this.innerRuler.ruler},function(t,e,n,r){var o,i=arguments.length,s=i<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var c=t.length-1;0<=c;c--)(o=t[c])&&(s=(i<3?o(s):3<i?o(e,n,s):o(e,n))||s);return 3<i&&s&&Object.defineProperty(e,n,s),s}([(n=Y,r=function(t,n){Object.defineProperty(t,n,{get:function(){return this.getRuler().props[n]},set:function(t){var e;this.innerRuler.setState(((e={})[n]=t,e))},enumerable:!0,configurable:!0})},function(t){var e=t.prototype;n.forEach(function(t){r(e,t)})})],t)}(),et={__proto__:null,default:n,PROPERTIES:Y,METHODS:t};for(e in et)n[e]=et[e];return n});
//# sourceMappingURL=ruler.min.js.map