@phun-ky/speccer 4.3.0 โ 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/package.json +5 -15
- package/speccer.js +1 -1
- package/src/browser.js +18 -12
- package/src/dissect.js +16 -9
- package/src/index.js +3 -0
- package/src/measure.js +12 -1
- package/src/spec.js +32 -1
- package/src/typography.js +16 -13
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.0.0](https://github.com/phun-ky/speccer/compare/v4.3.2...v5.0.0) (2022-02-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### โ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
* ๐งจ Speccer is not supporting older browsers any more, to cut down on
|
|
11
|
+
maintenance. Babel is now removed, but you can still polyfill or use
|
|
12
|
+
babel for your own needs if you import the source files instead of the
|
|
13
|
+
build files.
|
|
14
|
+
|
|
15
|
+
### Tasks
|
|
16
|
+
|
|
17
|
+
* ๐ค Remove babel, do not support older browsers anymore ([9ed11c0](https://github.com/phun-ky/speccer/commit/9ed11c06da3d1ac1b80d4cbbc6859146c596cd6f))
|
|
18
|
+
|
|
19
|
+
### [4.3.2](https://github.com/phun-ky/speccer/compare/v4.3.1...v4.3.2) (2022-02-22)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug
|
|
23
|
+
|
|
24
|
+
* And supply the minified version.. ([8cfb69a](https://github.com/phun-ky/speccer/commit/8cfb69a5dc86f1e9c9ccea3f890781a3961a0a7f))
|
|
25
|
+
|
|
26
|
+
### [4.3.1](https://github.com/phun-ky/speccer/compare/v4.3.0...v4.3.1) (2022-02-22)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Bug
|
|
30
|
+
|
|
31
|
+
* Use named exports ([7a4535e](https://github.com/phun-ky/speccer/commit/7a4535e65c04b33365258323376d6710fcb813c3))
|
|
32
|
+
|
|
5
33
|
## [4.3.0](https://github.com/phun-ky/speccer/compare/v4.2.1...v4.3.0) (2022-02-22)
|
|
6
34
|
|
|
7
35
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phun-ky/speccer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements",
|
|
5
5
|
"main": "speccer.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -100,39 +100,29 @@
|
|
|
100
100
|
},
|
|
101
101
|
"homepage": "https://github.com/phun-ky/speccer#readme",
|
|
102
102
|
"devDependencies": {
|
|
103
|
-
"@babel/core": "^7.2.2",
|
|
104
|
-
"@babel/plugin-proposal-export-default-from": "^7.12.13",
|
|
105
|
-
"@babel/plugin-transform-runtime": "^7.12.17",
|
|
106
|
-
"@babel/preset-env": "^7.2.3",
|
|
107
|
-
"@babel/register": "^7.12.13",
|
|
108
|
-
"@babel/runtime": "^7.12.18",
|
|
109
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
110
103
|
"@rollup/plugin-commonjs": "^17.1.0",
|
|
111
104
|
"@rollup/plugin-node-resolve": "^11.2.0",
|
|
112
105
|
"@testing-library/dom": "^7.29.4",
|
|
113
106
|
"@testing-library/jest-dom": "^5.11.9",
|
|
114
107
|
"@testing-library/user-event": "^12.7.1",
|
|
115
|
-
"babel-eslint": "^10.1.0",
|
|
116
|
-
"babel-jest": "^26.6.3",
|
|
117
108
|
"browser-sync": "^2.27.7",
|
|
118
109
|
"cssnano": "^5.0.4",
|
|
119
110
|
"eslint": "^7.32.0",
|
|
120
111
|
"eslint-config-airbnb": "^18.2.1",
|
|
121
112
|
"eslint-config-prettier": "^8.3.0",
|
|
113
|
+
"eslint-plugin-compat": "^3.13.0",
|
|
122
114
|
"eslint-plugin-import": "^2.24.2",
|
|
123
115
|
"eslint-plugin-jest": "^24.4.2",
|
|
124
116
|
"eslint-plugin-prettier": "^4.0.0",
|
|
117
|
+
"eslint-plugin-react": "^7.23.2",
|
|
118
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
125
119
|
"jest": "^26.6.3",
|
|
126
120
|
"postcss": "^8.3.0",
|
|
127
121
|
"postcss-cli": "^8.3.1",
|
|
128
122
|
"prettier": "^2.4.1",
|
|
129
123
|
"prettier-eslint": "^13.0.0",
|
|
130
|
-
"regenerator-runtime": "^0.13.7",
|
|
131
124
|
"rollup": "^2.39.0",
|
|
132
125
|
"rollup-plugin-terser": "^7.0.2",
|
|
133
|
-
"stylus": "^0.56.0"
|
|
134
|
-
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
135
|
-
"eslint-plugin-react": "^7.23.2",
|
|
136
|
-
"eslint-plugin-react-hooks": "^4.2.0"
|
|
126
|
+
"stylus": "^0.56.0"
|
|
137
127
|
}
|
|
138
128
|
}
|
package/speccer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).speccer={})}(this,(function(t){"use strict";const e=(t,e)=>t.insertAdjacentElement("afterend",e),n=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:document;[].forEach.call(e.querySelectorAll(t),(function(t){t.remove()}))};function r(t,e,n,r,i,o,a){try{var c=t[o](a),s=c.value}catch(t){return void n(t)}c.done?e(s):Promise.resolve(s).then(r,i)}function i(t){return function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function c(t){r(a,i,o,c,s,"next",t)}function s(t){r(a,i,o,c,s,"throw",t)}c(void 0)}))}}var o=function(t){var e={exports:{}};return t(e,e.exports),e.exports}((function(t){var e=function(t){var e,n=Object.prototype,r=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function l(t,e,n,r){var i=e&&e.prototype instanceof x?e:x,o=Object.create(i.prototype),a=new S(r||[]);return o._invoke=function(t,e,n){var r=h;return function(i,o){if(r===d)throw new Error("Generator is already running");if(r===u){if("throw"===i)throw o;return C()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var c=R(a,n);if(c){if(c===g)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===h)throw r=u,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=d;var s=p(t,e,n);if("normal"===s.type){if(r=n.done?u:f,s.arg===g)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r=u,n.method="throw",n.arg=s.arg)}}}(t,n,a),o}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var h="suspendedStart",f="suspendedYield",d="executing",u="completed",g={};function x(){}function y(){}function m(){}var w={};s(w,o,(function(){return this}));var v=Object.getPrototypeOf,b=v&&v(v(A([])));b&&b!==n&&r.call(b,o)&&(w=b);var O=m.prototype=x.prototype=Object.create(w);function E(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function L(t,e){function n(i,o,a,c){var s=p(t[i],t,o);if("throw"!==s.type){var l=s.arg,h=l.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(h).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,c)}))}c(s.arg)}var i;this._invoke=function(t,r){function o(){return new e((function(e,i){n(t,r,e,i)}))}return i=i?i.then(o,o):o()}}function R(t,n){var r=t.iterator[n.method];if(r===e){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=e,R(t,n),"throw"===n.method))return g;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return g}var i=p(r,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,g;var o=i.arg;return o?o.done?(n[t.resultName]=o.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,g):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,g)}function B(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(B,this),this.reset(!0)}function A(t){if(t){var n=t[o];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,a=function n(){for(;++i<t.length;)if(r.call(t,i))return n.value=t[i],n.done=!1,n;return n.value=e,n.done=!0,n};return a.next=a}}return{next:C}}function C(){return{value:e,done:!0}}return y.prototype=m,s(O,"constructor",m),s(m,"constructor",y),y.displayName=s(m,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,s(t,c,"GeneratorFunction")),t.prototype=Object.create(O),t},t.awrap=function(t){return{__await:t}},E(L.prototype),s(L.prototype,a,(function(){return this})),t.AsyncIterator=L,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var a=new L(l(e,n,r,i),o);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(O),s(O,c,"Generator"),s(O,o,(function(){return this})),s(O,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=A,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(T),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function i(r,i){return c.type="throw",c.arg=t,n.next=r,i&&(n.method="next",n.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),l=r.call(a,"finallyLoc");if(s&&l){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;T(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:A(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),g}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})),a=o;const c=function(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"noop";t&&(!e||e&&0===e.length||e.trim().split(" ").filter((t=>t!==n)).forEach((e=>t.classList.add(e))))},s=t=>parseInt(t,10),l=t=>{const e=parseFloat(t);return e>=0&&e<1||e<=0&&e>-1?0:e},p=t=>{const{marginTop:e,marginBottom:n,marginLeft:r,marginRight:i,paddingTop:o,paddingBottom:a,paddingLeft:c,paddingRight:s}=t;return{marginTop:e,marginBottom:n,marginLeft:r,marginRight:i,paddingTop:o,paddingBottom:a,paddingLeft:c,paddingRight:s}},h=t=>{const{lineHeight:e,letterSpacing:n,fontFamily:r,fontSize:i,fontStyle:o,fontVariationSettings:a,fontWeight:c}=t;return{lineHeight:e,letterSpacing:n,fontFamily:r,fontSize:i,fontStyle:o,fontVariationSettings:a,fontWeight:c}},f=()=>new Promise(requestAnimationFrame),d=function(){var t=i(a.mark((function t(e,n){return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=2;break}return t.abrupt("return");case 2:if(!(!n||n&&0===n.length&&n.constructor===String||n&&0===n.length&&n.constructor===Array||n&&0===Object.keys(n).length&&n.constructor===Object)){t.next=4;break}return t.abrupt("return");case 4:return t.next=6,f();case 6:"string"==typeof n||Array.isArray(n)?n.forEach((t=>e.style[t.key]=t.value)):Object.keys(n).forEach((t=>e.style[t]=n[t]));case 7:case"end":return t.stop()}}),t)})));return function(e,n){return t.apply(this,arguments)}}(),u=function(){var t=i(a.mark((function t(e){return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,f();case 2:return t.abrupt("return",window.getComputedStyle?getComputedStyle(e,null):e.currentStyle);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),g=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"],x=["TR","TH","TD","TBODY","THEAD","TFOOT"],y=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"span";const n=document.createElement(e),r=document.createTextNode(t);return n.appendChild(r),n.setAttribute("title",t+"px"),c(n,"ph speccer spacing"),n},m=function(){var t=i(a.mark((function t(n){var r,i,o,h,f,g,m,w,v,b;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={},t.next=3,u(n);case 3:if("none"!==(i=t.sent).display&&"hidden"!==i.visibility){t.next=6;break}return t.abrupt("return");case 6:n.classList.add("is-specced"),"static"===u(n.parentElement).position&&window.requestAnimationFrame((()=>{n.parentElement.style.position="relative"})),r.styles=p(i),r.rect=n.getBoundingClientRect(),"0px"!==r.styles.marginTop&&(o=y(s(r.styles.marginTop)),c(o,"margin top"),d(o,{height:r.styles.marginTop,width:r.rect.width+"px",left:l(r.rect.x-n.parentElement.getBoundingClientRect().x)+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y-parseInt(r.styles.marginTop,10))+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),o):e(n,o)),"0px"!==r.styles.marginRight&&(h=y(s(r.styles.marginRight)),c(h,"margin right"),d(h,{height:r.rect.height+"px",width:r.styles.marginRight,left:l(r.rect.x-n.parentElement.getBoundingClientRect().x+parseInt(r.rect.width,10))+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y)+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),h):e(n,h)),"0px"!==r.styles.marginBottom&&(f=y(s(r.styles.marginBottom)),c(f,"margin bottom"),d(f,{height:r.styles.marginBottom,width:r.rect.width+"px",left:l(r.rect.x-n.parentElement.getBoundingClientRect().x)+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y+parseInt(r.rect.height,10))+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),f):e(n,f)),"0px"!==r.styles.marginLeft&&(g=y(s(r.styles.marginLeft)),c(g,"margin left"),d(g,{height:r.rect.height+"px",width:r.styles.marginLeft,left:l(r.rect.x-n.parentElement.getBoundingClientRect().x-parseInt(r.styles.marginLeft,10))+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y)+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),g):e(n,g)),"0px"!==r.styles.paddingTop&&(m=y(s(r.styles.paddingTop)),c(m,"padding top"),d(m,{height:r.styles.paddingTop,width:r.rect.width+"px",left:l(r.rect.x-n.parentElement.getBoundingClientRect().x)+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y)+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),m):e(n,m)),"0px"!==r.styles.paddingBottom&&(w=y(s(r.styles.paddingBottom)),c(w,"padding bottom"),d(w,{height:r.styles.paddingBottom,width:r.rect.width+"px",left:l(r.rect.x-n.parentElement.getBoundingClientRect().x)+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y+(parseInt(r.rect.height,10)-parseInt(r.styles.paddingBottom,10)))+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),w):e(n,w)),"0px"!==r.styles.paddingRight&&(v=y(s(r.styles.paddingRight)),c(v,"padding right"),d(v,{height:r.rect.height+"px",width:r.styles.paddingRight,left:l(r.rect.x-n.parentElement.getBoundingClientRect().x+(parseInt(r.rect.width,10)-parseInt(r.styles.paddingRight,10)))+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y)+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),v):e(n,v)),"0px"!==r.styles.paddingLeft&&(b=y(s(r.styles.paddingLeft)),c(b,"padding left"),d(b,{height:r.rect.height+"px",width:r.styles.paddingLeft,left:l(r.rect.x-n.parentElement.getBoundingClientRect().x)+"px",top:l(r.rect.y-n.parentElement.getBoundingClientRect().y)+"px"}),x.indexOf(n.nodeName)>=0?e(n.closest("table"),b):e(n,b));case 19:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();var w=Object.freeze({__proto__:null,create:y,element:m});const v=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"span";const r=document.createElement(n),i=document.createTextNode(t);return-1===e.indexOf("full")&&-1===e.indexOf("enclose")?r.appendChild(i):-1===e.indexOf("full")&&-1===e.indexOf("enclose")||r.setAttribute("data-dissection-counter",t),c(r,`ph speccer dissection ${e}`),r},b=(t,n)=>{const r=t.getBoundingClientRect(),i=t.getAttribute("data-anatomy"),o=v(g[n],i),a=x.indexOf(t.nodeName)>=0;let c=0,s=0;if(a){const n=t.closest("table"),r=u(n.parentElement);e(n,o);const i=n.getBoundingClientRect();c=i.top-parseInt(r.getPropertyValue("padding-top"),10),s=i.left-parseInt(r.getPropertyValue("padding-left"),10)}else e(t,o);const l=t.offsetLeft,p=t.offsetTop,h=o.getBoundingClientRect();let f=(a?r.left-s:l)-h.width-48+"px",y=(a?r.top-c:p)+r.height/2-h.height/2+"px",m=(a?r.left-s:l)+r.width+48+"px",w=(a?r.top-c:p)+r.height/2-h.height/2+"px",b=(a?r.left-s:l)+r.width/2-h.width/2+"px",O=(a?r.top-c:p)-h.height-48+"px",E=(a?r.left-s:l)+r.width/2-h.width/2+"px",L=(a?r.top-c:p)+r.height+48+"px",R={};R=-1!==i.indexOf("outline")?-1!==i.indexOf("left")?-1!==i.indexOf("full")?{left:l-8+"px",top:p+-1+"px",height:r.height+"px"}:-1!==i.indexOf("enclose")?{left:l-1+"px",top:p+-1+"px",height:r.height+"px",width:r.width+"px"}:{left:f,top:y}:-1!==i.indexOf("right")?-1!==i.indexOf("full")?{left:l+r.width+"px",top:p+-1+"px",height:r.height+"px"}:-1!==i.indexOf("enclose")?{left:l+-1+"px",top:p+-1+"px",height:r.height+"px",width:r.width+"px"}:{left:m,top:w}:-1!==i.indexOf("top")?-1!==i.indexOf("full")?{top:p+-8+"px",left:l+-1+"px",width:r.width+"px"}:-1!==i.indexOf("enclose")?{top:p+-1+"px",left:l+-1+"px",height:r.height+"px",width:r.width+"px"}:{left:b,top:O}:-1!==i.indexOf("bottom")?-1!==i.indexOf("full")?{top:p+r.height+"px",left:l+-1+"px",width:r.width+"px"}:-1!==i.indexOf("enclose")?{top:p+-1+"px",left:l+-1+"px",height:r.height+"px",width:r.width+"px"}:{left:E,top:L}:-1!==i.indexOf("full")?{left:l+r.width+"px",top:p+"px",height:r.height+"px"}:-1!==i.indexOf("enclose")?{left:l+r.width+"px",top:p+-1+"px",height:r.height+"px",width:r.width+"px"}:{left:f,top:y}:-1!==i.indexOf("full")?{left:l-8+"px",top:p+-1+"px",height:r.height+"px"}:-1!==i.indexOf("enclose")?{left:l-1+"px",top:p+-1+"px",height:r.height+"px",width:r.width+"px"}:{left:f,top:y},d(o,R)};var O=Object.freeze({__proto__:null,create:v,element:b});const E=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"span";const r=document.createElement(n);return r.setAttribute("title",t+"px"),r.setAttribute("data-measure",parseInt(t,10)+"px"),c(r,`ph speccer measure ${e}`),r},L=t=>{if(!t)return;const n=t.getBoundingClientRect(),r=t.getAttribute("data-speccer-measure");if(""===r)return;const i=t.offsetTop,o=t.offsetLeft;if(-1!==r.indexOf("width"))if(-1!==r.indexOf("bottom")){const r=E(n.width,"width bottom");x.indexOf(t.nodeName)>=0?e(t.closest("table"),r):e(t,r),d(r,{left:o+"px",top:i+n.height+1+"px",width:n.width+"px"})}else{const r=E(n.width,"width top");x.indexOf(t.nodeName)>=0?e(t.closest("table"),r):e(t,r);const a=r.getBoundingClientRect();d(r,{left:o+"px",top:i-a.height+1+"px",width:n.width+"px"})}else if(-1!==r.indexOf("height"))if(-1!==r.indexOf("right")){const r=E(n.height,"height right");x.indexOf(t.nodeName)>=0?e(t.closest("table"),r):e(t,r),d(r,{left:o+n.width+"px",top:i+"px",height:n.height+"px"})}else{const r=E(n.height,"height left");x.indexOf(t.nodeName)>=0?e(t.closest("table"),r):e(t,r);const a=r.getBoundingClientRect();d(r,{left:o-a.width+"px",top:i+"px",height:n.height+"px"})}};var R=Object.freeze({__proto__:null,element:L});const B=t=>parseFloat(t).toFixed(3),T=(t,e)=>{const n=document.createElement("div");return n.innerHTML=t,c(n,`ph speccer typography ${e}`),n},S=function(){var t=i(a.mark((function t(n){var r,i,o,c,s,l,p,f,g,y,m,w,v,b,O,E,L,R,S,A,C;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.getAttribute("data-speccer-typography"),t.next=3,u(n);case 3:if("none"!==(i=t.sent).display&&"hidden"!==i.visibility){t.next=6;break}return t.abrupt("return");case 6:n.classList.add("is-specced"),"static"===u(n.parentElement).position&&window.requestAnimationFrame((()=>{n.parentElement.style.position="relative"})),o=h(i),c=n.getBoundingClientRect(),s=`\n font-styles: {<ul class="speccer-styles"> <li><span class="property">font-family:</span> ${o.fontFamily};</li> <li><span class="property">font-size:</span> ${o.fontSize} / ${parseInt(o.fontSize,10)/16}rem;</li> <li><span class="property">font-weight:</span> ${o.fontWeight};</li> <li><span class="property">font-variation-settings:</span> ${o.fontVariationSettings};</li> <li><span class="property">line-height:</span> ${o.lineHeight} / ${parseInt(o.lineHeight,10)/16}rem;</li> <li><span class="property">letter-spacing:</span> ${o.letterSpacing};</li> <li><span class="property">font-style:</span> ${o.fontStyle};</li></ul>}`,l=T(s,r),p=0,f=0,(g=x.indexOf(n.nodeName)>=0)?(y=n.parentElement,m=window.getComputedStyle(y.parentElement),e(y,l),p=y.getBoundingClientRect().top-parseInt(m.getPropertyValue("padding-top"),10),f=y.getBoundingClientRect().left-parseInt(m.getPropertyValue("padding-left"),10)):e(n,l),w=l.getBoundingClientRect(),v=(g?w.left-f:n.offsetLeft)-w.width-48+"px",b=B((g?w.top-p:n.offsetTop)-w.height/2+c.height/2)+"px",O=(g?w.left-f:n.offsetLeft)+c.width+48+"px",E=B((g?w.top-p:n.offsetTop)-w.height/2+c.height/2)+"px",L=B((g?w.left-f:n.offsetLeft)-w.width/2+c.width/2)+"px",R=(g?w.top-p:n.offsetTop)-w.height-48+"px",S=B((g?w.left-f:n.offsetLeft)-w.width/2+c.width/2)+"px",A=(g?w.top-p:n.offsetTop)+c.height+48+"px",C={left:v,top:b},-1!==r.indexOf("right")?C={left:O,top:E}:-1!==r.indexOf("top")?C={left:L,top:R}:-1!==r.indexOf("bottom")&&(C={left:S,top:A}),d(l,C);case 29:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();const A=t=>{const e=(n=()=>{t()},r=300,function(){var t=this,e=arguments,a=function(){o=null,i||n.apply(t,e)},c=i&&!o;clearTimeout(o),o=setTimeout(a,r),c&&n.apply(t,e)});var n,r,i,o;window.removeEventListener("resize",e),window.addEventListener("resize",e)},C=t=>{"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t()},_=()=>{n(".speccer"),n(".dissection");const t=document.querySelectorAll("[data-speccer],[data-speccer] *:not(td)"),e=document.querySelectorAll("[data-speccer-measure]"),r=document.querySelectorAll("[data-speccer-typography]"),i=document.querySelectorAll("[data-anatomy-section] [data-anatomy]");t.forEach(m),e.forEach(L),r.forEach(S),i.forEach(b)},N=w,j=O,I=R,k=Object.freeze({__proto__:null,create:T,element:S});(t=>{const e=document.currentScript;if(e){const n=e.getAttribute("src");-1===n.indexOf("speccer.js")&&-1===n.indexOf("JaXpOK.js")||(e.hasAttribute("data-manual")?(t=>{window.speccer=t})(t):e.hasAttribute("data-instant")?t():e.hasAttribute("data-dom")?C(t):e.hasAttribute("data-lazy")?(()=>{let t=new IntersectionObserver(((t,e)=>{t.forEach((t=>{t.intersectionRatio>0&&(m(t.target),e.unobserve(t.target))}))}));document.querySelectorAll("[data-speccer],[data-speccer] *:not(td)").forEach((e=>{t.observe(e)}));let e=new IntersectionObserver(((t,e)=>{t.forEach((t=>{t.intersectionRatio>0&&(L(t.target),e.unobserve(t.target))}))}));document.querySelectorAll("[data-speccer-measure]").forEach((t=>{e.observe(t)}));let n=new IntersectionObserver(((t,e)=>{t.forEach((t=>{const n=t.target.querySelectorAll("[data-anatomy]");t.intersectionRatio>0&&(n.forEach(b),e.unobserve(t.target))}))}));document.querySelectorAll("[data-anatomy-section]").forEach((t=>{n.observe(t)}))})():C(t),e.hasAttribute("data-manual")||e.hasAttribute("data-lazy")||A(t))}})(_),t.default=_,t.dissect=j,t.measure=I,t.spacing=N,t.typography=k,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).speccer={})}(this,(function(t){"use strict";const e=(t,e)=>t.insertAdjacentElement("afterend",e),n=(t,e=document)=>{[].forEach.call(e.querySelectorAll(t),(function(t){t.remove()}))},i=(t,e,n="noop")=>{t&&(!e||e&&0===e.length||e.trim().split(" ").filter((t=>t!==n)).forEach((e=>t.classList.add(e))))},o=t=>parseInt(t,10),p=t=>{const e=parseFloat(t);return e>=0&&e<1||e<=0&&e>-1?0:e},s=()=>new Promise(requestAnimationFrame),a=async(t,e)=>{t&&(!e||e&&0===e.length&&e.constructor===String||e&&0===e.length&&e.constructor===Array||e&&0===Object.keys(e).length&&e.constructor===Object||(await s(),"string"==typeof e||Array.isArray(e)?e.forEach((e=>t.style[e.key]=e.value)):Object.keys(e).forEach((n=>t.style[n]=e[n]))))},l=async t=>(await s(),window.getComputedStyle?getComputedStyle(t,null):t.currentStyle),r=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"],d=["TR","TH","TD","TBODY","THEAD","TFOOT"],c=(t="",e="span")=>{const n=document.createElement(e),o=document.createTextNode(t);return n.appendChild(o),n.setAttribute("title",t+"px"),i(n,"ph speccer spacing"),n},h=async t=>{const n={},s=await l(t);if("none"===s.display||"hidden"===s.visibility)return;t.classList.add("is-specced");if("static"===l(t.parentElement).position&&window.requestAnimationFrame((()=>{t.parentElement.style.position="relative"})),n.styles=(t=>{const{marginTop:e,marginBottom:n,marginLeft:i,marginRight:o,paddingTop:p,paddingBottom:s,paddingLeft:a,paddingRight:l}=t;return{marginTop:e,marginBottom:n,marginLeft:i,marginRight:o,paddingTop:p,paddingBottom:s,paddingLeft:a,paddingRight:l}})(s),n.rect=t.getBoundingClientRect(),"0px"!==n.styles.marginTop){const s=c(o(n.styles.marginTop));i(s,"margin top"),a(s,{height:n.styles.marginTop,width:n.rect.width+"px",left:p(n.rect.x-t.parentElement.getBoundingClientRect().x)+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y-parseInt(n.styles.marginTop,10))+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.marginRight){const s=c(o(n.styles.marginRight));i(s,"margin right"),a(s,{height:n.rect.height+"px",width:n.styles.marginRight,left:p(n.rect.x-t.parentElement.getBoundingClientRect().x+parseInt(n.rect.width,10))+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y)+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.marginBottom){const s=c(o(n.styles.marginBottom));i(s,"margin bottom"),a(s,{height:n.styles.marginBottom,width:n.rect.width+"px",left:p(n.rect.x-t.parentElement.getBoundingClientRect().x)+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y+parseInt(n.rect.height,10))+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.marginLeft){const s=c(o(n.styles.marginLeft));i(s,"margin left"),a(s,{height:n.rect.height+"px",width:n.styles.marginLeft,left:p(n.rect.x-t.parentElement.getBoundingClientRect().x-parseInt(n.styles.marginLeft,10))+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y)+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.paddingTop){const s=c(o(n.styles.paddingTop));i(s,"padding top"),a(s,{height:n.styles.paddingTop,width:n.rect.width+"px",left:p(n.rect.x-t.parentElement.getBoundingClientRect().x)+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y)+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.paddingBottom){const s=c(o(n.styles.paddingBottom));i(s,"padding bottom"),a(s,{height:n.styles.paddingBottom,width:n.rect.width+"px",left:p(n.rect.x-t.parentElement.getBoundingClientRect().x)+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y+(parseInt(n.rect.height,10)-parseInt(n.styles.paddingBottom,10)))+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.paddingRight){const s=c(o(n.styles.paddingRight));i(s,"padding right"),a(s,{height:n.rect.height+"px",width:n.styles.paddingRight,left:p(n.rect.x-t.parentElement.getBoundingClientRect().x+(parseInt(n.rect.width,10)-parseInt(n.styles.paddingRight,10)))+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y)+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}if("0px"!==n.styles.paddingLeft){const s=c(o(n.styles.paddingLeft));i(s,"padding left"),a(s,{height:n.rect.height+"px",width:n.styles.paddingLeft,left:p(n.rect.x-t.parentElement.getBoundingClientRect().x)+"px",top:p(n.rect.y-t.parentElement.getBoundingClientRect().y)+"px"}),d.indexOf(t.nodeName)>=0?e(t.closest("table"),s):e(t,s)}};const g=(t="",e,n="span")=>{const o=document.createElement(n),p=document.createTextNode(t);return-1===e.indexOf("full")&&-1===e.indexOf("enclose")?o.appendChild(p):-1===e.indexOf("full")&&-1===e.indexOf("enclose")||o.setAttribute("data-dissection-counter",t),i(o,`ph speccer dissection ${e}`),o},f=(t,n)=>{const i=t.getBoundingClientRect(),o=t.getAttribute("data-anatomy"),p=g(r[n],o),s=d.indexOf(t.nodeName)>=0;let c=0,h=0;if(s){const n=t.closest("table"),i=l(n.parentElement);e(n,p);const o=n.getBoundingClientRect();c=o.top-parseInt(i.getPropertyValue("padding-top"),10),h=o.left-parseInt(i.getPropertyValue("padding-left"),10)}else e(t,p);const f=t.offsetLeft,x=t.offsetTop,m=p.getBoundingClientRect(),u=(s?i.left-h:f)-m.width-48+"px",y=(s?i.top-c:x)+i.height/2-m.height/2+"px",w=(s?i.left-h:f)+i.width+48+"px",O=(s?i.top-c:x)+i.height/2-m.height/2+"px",b=(s?i.left-h:f)+i.width/2-m.width/2+"px",E=(s?i.top-c:x)-m.height-48+"px",R=(s?i.left-h:f)+i.width/2-m.width/2+"px",B=(s?i.top-c:x)+i.height+48+"px";let C={};C=-1!==o.indexOf("outline")?-1!==o.indexOf("left")?-1!==o.indexOf("full")?{left:f-8+"px",top:x+-1+"px",height:i.height+"px"}:-1!==o.indexOf("enclose")?{left:f-1+"px",top:x+-1+"px",height:i.height+"px",width:i.width+"px"}:{left:u,top:y}:-1!==o.indexOf("right")?-1!==o.indexOf("full")?{left:f+i.width+"px",top:x+-1+"px",height:i.height+"px"}:-1!==o.indexOf("enclose")?{left:f+-1+"px",top:x+-1+"px",height:i.height+"px",width:i.width+"px"}:{left:w,top:O}:-1!==o.indexOf("top")?-1!==o.indexOf("full")?{top:x+-8+"px",left:f+-1+"px",width:i.width+"px"}:-1!==o.indexOf("enclose")?{top:x+-1+"px",left:f+-1+"px",height:i.height+"px",width:i.width+"px"}:{left:b,top:E}:-1!==o.indexOf("bottom")?-1!==o.indexOf("full")?{top:x+i.height+"px",left:f+-1+"px",width:i.width+"px"}:-1!==o.indexOf("enclose")?{top:x+-1+"px",left:f+-1+"px",height:i.height+"px",width:i.width+"px"}:{left:R,top:B}:-1!==o.indexOf("full")?{left:f+i.width+"px",top:x+"px",height:i.height+"px"}:-1!==o.indexOf("enclose")?{left:f+i.width+"px",top:x+-1+"px",height:i.height+"px",width:i.width+"px"}:{left:u,top:y}:-1!==o.indexOf("full")?{left:f-8+"px",top:x+-1+"px",height:i.height+"px"}:-1!==o.indexOf("enclose")?{left:f-1+"px",top:x+-1+"px",height:i.height+"px",width:i.width+"px"}:{left:u,top:y},a(p,C)};const x=(t="",e="",n="span")=>{const o=document.createElement(n);return o.setAttribute("title",t+"px"),o.setAttribute("data-measure",parseInt(t,10)+"px"),i(o,`ph speccer measure ${e}`),o},m=t=>{if(!t)return;const n=t.getBoundingClientRect(),i=t.getAttribute("data-speccer-measure");if(""===i)return;const o=t.offsetTop,p=t.offsetLeft;if(-1!==i.indexOf("width"))if(-1!==i.indexOf("bottom")){const i=x(n.width,"width bottom");d.indexOf(t.nodeName)>=0?e(t.closest("table"),i):e(t,i),a(i,{left:p+"px",top:o+n.height+1+"px",width:n.width+"px"})}else{const i=x(n.width,"width top");d.indexOf(t.nodeName)>=0?e(t.closest("table"),i):e(t,i);const s=i.getBoundingClientRect();a(i,{left:p+"px",top:o-s.height+1+"px",width:n.width+"px"})}else if(-1!==i.indexOf("height"))if(-1!==i.indexOf("right")){const i=x(n.height,"height right");d.indexOf(t.nodeName)>=0?e(t.closest("table"),i):e(t,i),a(i,{left:p+n.width+"px",top:o+"px",height:n.height+"px"})}else{const i=x(n.height,"height left");d.indexOf(t.nodeName)>=0?e(t.closest("table"),i):e(t,i);const s=i.getBoundingClientRect();a(i,{left:p-s.width+"px",top:o+"px",height:n.height+"px"})}};const u=t=>parseFloat(t).toFixed(3),y=(t,e)=>{const n=document.createElement("div");return n.innerHTML=t,i(n,`ph speccer typography ${e}`),n},w=async t=>{const n=t.getAttribute("data-speccer-typography"),i=await l(t);if("none"===i.display||"hidden"===i.visibility)return;t.classList.add("is-specced");"static"===l(t.parentElement).position&&window.requestAnimationFrame((()=>{t.parentElement.style.position="relative"}));const o=(t=>{const{lineHeight:e,letterSpacing:n,fontFamily:i,fontSize:o,fontStyle:p,fontVariationSettings:s,fontWeight:a}=t;return{lineHeight:e,letterSpacing:n,fontFamily:i,fontSize:o,fontStyle:p,fontVariationSettings:s,fontWeight:a}})(i),p=t.getBoundingClientRect(),s=`\n font-styles: {<ul class="speccer-styles"> <li><span class="property">font-family:</span> ${o.fontFamily};</li> <li><span class="property">font-size:</span> ${o.fontSize} / ${parseInt(o.fontSize,10)/16}rem;</li> <li><span class="property">font-weight:</span> ${o.fontWeight};</li> <li><span class="property">font-variation-settings:</span> ${o.fontVariationSettings};</li> <li><span class="property">line-height:</span> ${o.lineHeight} / ${parseInt(o.lineHeight,10)/16}rem;</li> <li><span class="property">letter-spacing:</span> ${o.letterSpacing};</li> <li><span class="property">font-style:</span> ${o.fontStyle};</li></ul>}`,r=y(s,n);let c=0,h=0;const g=d.indexOf(t.nodeName)>=0;if(g){const n=t.parentElement,i=window.getComputedStyle(n.parentElement);e(n,r),c=n.getBoundingClientRect().top-parseInt(i.getPropertyValue("padding-top"),10),h=n.getBoundingClientRect().left-parseInt(i.getPropertyValue("padding-left"),10)}else e(t,r);const f=r.getBoundingClientRect(),x=(g?f.left-h:t.offsetLeft)-f.width-48+"px",m=u((g?f.top-c:t.offsetTop)-f.height/2+p.height/2)+"px",w=(g?f.left-h:t.offsetLeft)+p.width+48+"px",O=u((g?f.top-c:t.offsetTop)-f.height/2+p.height/2)+"px",b=u((g?f.left-h:t.offsetLeft)-f.width/2+p.width/2)+"px",E=(g?f.top-c:t.offsetTop)-f.height-48+"px",R=u((g?f.left-h:t.offsetLeft)-f.width/2+p.width/2)+"px",B=(g?f.top-c:t.offsetTop)+p.height+48+"px";let C={left:x,top:m};-1!==n.indexOf("right")?C={left:w,top:O}:-1!==n.indexOf("top")?C={left:b,top:E}:-1!==n.indexOf("bottom")&&(C={left:R,top:B}),a(r,C)};const O=t=>{const e=(n=()=>{t()},i=300,function(){var t=this,e=arguments,s=function(){p=null,o||n.apply(t,e)},a=o&&!p;clearTimeout(p),p=setTimeout(s,i),a&&n.apply(t,e)});var n,i,o,p;window.removeEventListener("resize",e),window.addEventListener("resize",e)},b=t=>{"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t):t()},E=()=>{n(".speccer"),n(".dissection");const t=document.querySelectorAll("[data-speccer],[data-speccer] *:not(td)"),e=document.querySelectorAll("[data-speccer-measure]"),i=document.querySelectorAll("[data-speccer-typography]"),o=document.querySelectorAll("[data-anatomy-section] [data-anatomy]");t.forEach(h),e.forEach(m),i.forEach(w),o.forEach(f)},R=Object.freeze({__proto__:null,create:c,element:h}),B=Object.freeze({__proto__:null,create:g,element:f}),C=Object.freeze({__proto__:null,element:m}),A=Object.freeze({__proto__:null,create:y,element:w});(t=>{const e=document.currentScript;if(e){const n=e.getAttribute("src");-1===n.indexOf("speccer.js")&&-1===n.indexOf("JaXpOK.js")||(e.hasAttribute("data-manual")?(t=>{window.speccer=t})(t):e.hasAttribute("data-instant")?t():e.hasAttribute("data-dom")?b(t):e.hasAttribute("data-lazy")?(()=>{const t=new IntersectionObserver(((t,e)=>{t.forEach((t=>{t.intersectionRatio>0&&(h(t.target),e.unobserve(t.target))}))}));document.querySelectorAll("[data-speccer],[data-speccer] *:not(td)").forEach((e=>{t.observe(e)}));const e=new IntersectionObserver(((t,e)=>{t.forEach((t=>{t.intersectionRatio>0&&(m(t.target),e.unobserve(t.target))}))}));document.querySelectorAll("[data-speccer-measure]").forEach((t=>{e.observe(t)}));const n=new IntersectionObserver(((t,e)=>{t.forEach((t=>{const n=t.target.querySelectorAll("[data-anatomy]");t.intersectionRatio>0&&(n.forEach(f),e.unobserve(t.target))}))}));document.querySelectorAll("[data-anatomy-section]").forEach((t=>{n.observe(t)}))})():b(t),e.hasAttribute("data-manual")||e.hasAttribute("data-lazy")||O(t))}})(E),t.default=E,t.dissect=B,t.measure=C,t.spacing=R,t.typography=A,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/src/browser.js
CHANGED
|
@@ -6,7 +6,7 @@ import * as spec from './spec';
|
|
|
6
6
|
import * as measure from './measure';
|
|
7
7
|
import * as dissect from './dissect';
|
|
8
8
|
|
|
9
|
-
export const dom = speccer => {
|
|
9
|
+
export const dom = (speccer) => {
|
|
10
10
|
if (document.readyState === 'loading') {
|
|
11
11
|
document.addEventListener('DOMContentLoaded', speccer);
|
|
12
12
|
} else {
|
|
@@ -16,31 +16,36 @@ export const dom = speccer => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export const lazy = () => {
|
|
19
|
-
|
|
20
|
-
els.forEach(el => {
|
|
19
|
+
const _spec_observer = new IntersectionObserver((els, observer) => {
|
|
20
|
+
els.forEach((el) => {
|
|
21
21
|
if (el.intersectionRatio > 0) {
|
|
22
22
|
spec.element(el.target);
|
|
23
23
|
observer.unobserve(el.target);
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
document.querySelectorAll('[data-speccer],[data-speccer] *:not(td)').forEach((el) => {
|
|
28
29
|
_spec_observer.observe(el);
|
|
29
30
|
});
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
const _measure_observer = new IntersectionObserver((els, observer) => {
|
|
33
|
+
els.forEach((el) => {
|
|
32
34
|
if (el.intersectionRatio > 0) {
|
|
33
35
|
measure.element(el.target);
|
|
34
36
|
observer.unobserve(el.target);
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
});
|
|
38
|
-
|
|
40
|
+
|
|
41
|
+
document.querySelectorAll('[data-speccer-measure]').forEach((el) => {
|
|
39
42
|
_measure_observer.observe(el);
|
|
40
43
|
});
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
|
|
45
|
+
const _dissect_observer = new IntersectionObserver((els, observer) => {
|
|
46
|
+
els.forEach((el) => {
|
|
43
47
|
const targets = el.target.querySelectorAll('[data-anatomy]');
|
|
48
|
+
|
|
44
49
|
if (el.intersectionRatio > 0) {
|
|
45
50
|
targets.forEach(dissect.element);
|
|
46
51
|
observer.unobserve(el.target);
|
|
@@ -48,20 +53,21 @@ export const lazy = () => {
|
|
|
48
53
|
});
|
|
49
54
|
});
|
|
50
55
|
|
|
51
|
-
document.querySelectorAll('[data-anatomy-section]').forEach(el => {
|
|
56
|
+
document.querySelectorAll('[data-anatomy-section]').forEach((el) => {
|
|
52
57
|
_dissect_observer.observe(el);
|
|
53
58
|
});
|
|
54
59
|
};
|
|
55
60
|
|
|
56
|
-
export const manual = speccer => {
|
|
61
|
+
export const manual = (speccer) => {
|
|
57
62
|
window.speccer = speccer;
|
|
58
63
|
};
|
|
59
64
|
|
|
60
|
-
export const activate = speccer => {
|
|
65
|
+
export const activate = (speccer) => {
|
|
61
66
|
const _script = document.currentScript;
|
|
62
67
|
|
|
63
68
|
if (_script) {
|
|
64
69
|
const _speccer_script_src = _script.getAttribute('src');
|
|
70
|
+
|
|
65
71
|
if (
|
|
66
72
|
_speccer_script_src.indexOf('speccer.js') !== -1 ||
|
|
67
73
|
// for codepen
|
package/src/dissect.js
CHANGED
|
@@ -8,12 +8,15 @@ import { SPECCER_LITERALS, SPECCER_TAGS_TO_AVOID } from './lib/constants';
|
|
|
8
8
|
export const create = (e = '', t, n = 'span') => {
|
|
9
9
|
const _el = document.createElement(n);
|
|
10
10
|
const o = document.createTextNode(e);
|
|
11
|
+
|
|
11
12
|
if (t.indexOf('full') === -1 && t.indexOf('enclose') === -1) {
|
|
12
13
|
_el.appendChild(o);
|
|
13
14
|
} else if (t.indexOf('full') !== -1 || t.indexOf('enclose') !== -1) {
|
|
14
15
|
_el.setAttribute('data-dissection-counter', e);
|
|
15
16
|
}
|
|
17
|
+
|
|
16
18
|
classnames.set(_el, `ph speccer dissection ${t}`);
|
|
19
|
+
|
|
17
20
|
return _el;
|
|
18
21
|
};
|
|
19
22
|
|
|
@@ -29,8 +32,11 @@ export const element = (el, dissectIndex) => {
|
|
|
29
32
|
if (_is_table_correction_needed) {
|
|
30
33
|
const table = el.closest('table');
|
|
31
34
|
const tableStyle = styles.get(table.parentElement);
|
|
35
|
+
|
|
32
36
|
node.after(table, _dissection_node);
|
|
37
|
+
|
|
33
38
|
const _table_rect = table.getBoundingClientRect();
|
|
39
|
+
|
|
34
40
|
_table_top = _table_rect.top - parseInt(tableStyle.getPropertyValue('padding-top'), 10);
|
|
35
41
|
_table_left = _table_rect.left - parseInt(tableStyle.getPropertyValue('padding-left'), 10);
|
|
36
42
|
} else {
|
|
@@ -39,44 +45,44 @@ export const element = (el, dissectIndex) => {
|
|
|
39
45
|
|
|
40
46
|
const _el_offset_left = el.offsetLeft;
|
|
41
47
|
const _el_offset_top = el.offsetTop;
|
|
42
|
-
|
|
43
48
|
const _dissection_node_rect = _dissection_node.getBoundingClientRect();
|
|
44
|
-
|
|
49
|
+
const _outline_left_position_left =
|
|
45
50
|
(_is_table_correction_needed ? _el_rect.left - _table_left : _el_offset_left) -
|
|
46
51
|
_dissection_node_rect.width -
|
|
47
52
|
48 +
|
|
48
53
|
'px';
|
|
49
|
-
|
|
54
|
+
const _outline_left_position_top =
|
|
50
55
|
(_is_table_correction_needed ? _el_rect.top - _table_top : _el_offset_top) +
|
|
51
56
|
_el_rect.height / 2 -
|
|
52
57
|
_dissection_node_rect.height / 2 +
|
|
53
58
|
'px';
|
|
54
|
-
|
|
59
|
+
const _outline_right_position_left =
|
|
55
60
|
(_is_table_correction_needed ? _el_rect.left - _table_left : _el_offset_left) + _el_rect.width + 48 + 'px';
|
|
56
|
-
|
|
61
|
+
const _outline_right_position_top =
|
|
57
62
|
(_is_table_correction_needed ? _el_rect.top - _table_top : _el_offset_top) +
|
|
58
63
|
_el_rect.height / 2 -
|
|
59
64
|
_dissection_node_rect.height / 2 +
|
|
60
65
|
'px';
|
|
61
|
-
|
|
66
|
+
const _outline_top_position_left =
|
|
62
67
|
(_is_table_correction_needed ? _el_rect.left - _table_left : _el_offset_left) +
|
|
63
68
|
_el_rect.width / 2 -
|
|
64
69
|
_dissection_node_rect.width / 2 +
|
|
65
70
|
'px';
|
|
66
|
-
|
|
71
|
+
const _outline_top_position_top =
|
|
67
72
|
(_is_table_correction_needed ? _el_rect.top - _table_top : _el_offset_top) -
|
|
68
73
|
_dissection_node_rect.height -
|
|
69
74
|
48 +
|
|
70
75
|
'px';
|
|
71
|
-
|
|
76
|
+
const _outline_bottom_position_left =
|
|
72
77
|
(_is_table_correction_needed ? _el_rect.left - _table_left : _el_offset_left) +
|
|
73
78
|
_el_rect.width / 2 -
|
|
74
79
|
_dissection_node_rect.width / 2 +
|
|
75
80
|
'px';
|
|
76
|
-
|
|
81
|
+
const _outline_bottom_position_top =
|
|
77
82
|
(_is_table_correction_needed ? _el_rect.top - _table_top : _el_offset_top) + _el_rect.height + 48 + 'px';
|
|
78
83
|
|
|
79
84
|
let _dissection_node_styles = {};
|
|
85
|
+
|
|
80
86
|
if (_area.indexOf('outline') !== -1) {
|
|
81
87
|
if (_area.indexOf('left') !== -1) {
|
|
82
88
|
if (_area.indexOf('full') !== -1) {
|
|
@@ -200,5 +206,6 @@ export const element = (el, dissectIndex) => {
|
|
|
200
206
|
};
|
|
201
207
|
}
|
|
202
208
|
}
|
|
209
|
+
|
|
203
210
|
styles.add(_dissection_node, _dissection_node_styles);
|
|
204
211
|
};
|
package/src/index.js
CHANGED
package/src/measure.js
CHANGED
|
@@ -9,6 +9,7 @@ import { SPECCER_TAGS_TO_AVOID } from './lib/constants';
|
|
|
9
9
|
|
|
10
10
|
const create = (text = '', area = '', tag = 'span') => {
|
|
11
11
|
const _el = document.createElement(tag);
|
|
12
|
+
|
|
12
13
|
_el.setAttribute('title', text + 'px');
|
|
13
14
|
_el.setAttribute('data-measure', parseInt(text, 10) + 'px');
|
|
14
15
|
|
|
@@ -17,7 +18,7 @@ const create = (text = '', area = '', tag = 'span') => {
|
|
|
17
18
|
return _el;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
export const element = el => {
|
|
21
|
+
export const element = (el) => {
|
|
21
22
|
if (!el) return;
|
|
22
23
|
|
|
23
24
|
const _el_rect = el.getBoundingClientRect();
|
|
@@ -33,11 +34,13 @@ export const element = el => {
|
|
|
33
34
|
if (_area.indexOf('width') !== -1) {
|
|
34
35
|
if (_area.indexOf('bottom') !== -1) {
|
|
35
36
|
const _measure_node = create(_el_rect.width, 'width bottom');
|
|
37
|
+
|
|
36
38
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
37
39
|
node.after(el.closest('table'), _measure_node);
|
|
38
40
|
} else {
|
|
39
41
|
node.after(el, _measure_node);
|
|
40
42
|
}
|
|
43
|
+
|
|
41
44
|
styles.add(_measure_node, {
|
|
42
45
|
left: _el_offset_left + 'px',
|
|
43
46
|
top: _el_offset_top + _el_rect.height + 1 + 'px',
|
|
@@ -45,12 +48,15 @@ export const element = el => {
|
|
|
45
48
|
});
|
|
46
49
|
} else {
|
|
47
50
|
const _measure_node = create(_el_rect.width, 'width top');
|
|
51
|
+
|
|
48
52
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
49
53
|
node.after(el.closest('table'), _measure_node);
|
|
50
54
|
} else {
|
|
51
55
|
node.after(el, _measure_node);
|
|
52
56
|
}
|
|
57
|
+
|
|
53
58
|
const _measure_node_rect = _measure_node.getBoundingClientRect();
|
|
59
|
+
|
|
54
60
|
styles.add(_measure_node, {
|
|
55
61
|
left: _el_offset_left + 'px',
|
|
56
62
|
top: _el_offset_top - _measure_node_rect.height + 1 + 'px',
|
|
@@ -60,11 +66,13 @@ export const element = el => {
|
|
|
60
66
|
} else if (_area.indexOf('height') !== -1) {
|
|
61
67
|
if (_area.indexOf('right') !== -1) {
|
|
62
68
|
const _measure_node = create(_el_rect.height, 'height right');
|
|
69
|
+
|
|
63
70
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
64
71
|
node.after(el.closest('table'), _measure_node);
|
|
65
72
|
} else {
|
|
66
73
|
node.after(el, _measure_node);
|
|
67
74
|
}
|
|
75
|
+
|
|
68
76
|
styles.add(_measure_node, {
|
|
69
77
|
left: _el_offset_left + _el_rect.width + 'px',
|
|
70
78
|
top: _el_offset_top + 'px',
|
|
@@ -72,12 +80,15 @@ export const element = el => {
|
|
|
72
80
|
});
|
|
73
81
|
} else {
|
|
74
82
|
const _measure_node = create(_el_rect.height, 'height left');
|
|
83
|
+
|
|
75
84
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
76
85
|
node.after(el.closest('table'), _measure_node);
|
|
77
86
|
} else {
|
|
78
87
|
node.after(el, _measure_node);
|
|
79
88
|
}
|
|
89
|
+
|
|
80
90
|
const _measure_node_rect = _measure_node.getBoundingClientRect();
|
|
91
|
+
|
|
81
92
|
styles.add(_measure_node, {
|
|
82
93
|
left: _el_offset_left - _measure_node_rect.width + 'px',
|
|
83
94
|
top: _el_offset_top + 'px',
|
package/src/spec.js
CHANGED
|
@@ -10,29 +10,38 @@ import { SPECCER_TAGS_TO_AVOID } from './lib/constants';
|
|
|
10
10
|
export const create = (text = '', tag = 'span') => {
|
|
11
11
|
const _el = document.createElement(tag);
|
|
12
12
|
const textContent = document.createTextNode(text);
|
|
13
|
+
|
|
13
14
|
_el.appendChild(textContent);
|
|
14
15
|
_el.setAttribute('title', text + 'px');
|
|
15
16
|
classnames.set(_el, 'ph speccer spacing');
|
|
17
|
+
|
|
16
18
|
return _el;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
|
-
export const element = async el => {
|
|
21
|
+
export const element = async (el) => {
|
|
20
22
|
const _speccer_el = {};
|
|
21
23
|
const _el_style = await styles.get(el);
|
|
24
|
+
|
|
22
25
|
if (_el_style.display === 'none' || _el_style.visibility === 'hidden') {
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
28
|
+
|
|
25
29
|
el.classList.add('is-specced');
|
|
30
|
+
|
|
26
31
|
const _parent_el_style = styles.get(el.parentElement);
|
|
32
|
+
|
|
27
33
|
if (_parent_el_style.position === 'static') {
|
|
28
34
|
window.requestAnimationFrame(() => {
|
|
29
35
|
el.parentElement.style.position = 'relative';
|
|
30
36
|
});
|
|
31
37
|
}
|
|
38
|
+
|
|
32
39
|
_speccer_el.styles = css.getSpacing(_el_style);
|
|
33
40
|
_speccer_el.rect = el.getBoundingClientRect();
|
|
41
|
+
|
|
34
42
|
if (_speccer_el.styles['marginTop'] !== '0px') {
|
|
35
43
|
const _speccer_margin_top_el = create(css.getNumberValue(_speccer_el.styles.marginTop));
|
|
44
|
+
|
|
36
45
|
classnames.set(_speccer_margin_top_el, 'margin top');
|
|
37
46
|
styles.add(_speccer_margin_top_el, {
|
|
38
47
|
height: _speccer_el.styles.marginTop,
|
|
@@ -43,14 +52,17 @@ export const element = async el => {
|
|
|
43
52
|
_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y - parseInt(_speccer_el.styles.marginTop, 10)
|
|
44
53
|
) + 'px'
|
|
45
54
|
});
|
|
55
|
+
|
|
46
56
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
47
57
|
node.after(el.closest('table'), _speccer_margin_top_el);
|
|
48
58
|
} else {
|
|
49
59
|
node.after(el, _speccer_margin_top_el);
|
|
50
60
|
}
|
|
51
61
|
}
|
|
62
|
+
|
|
52
63
|
if (_speccer_el.styles['marginRight'] !== '0px') {
|
|
53
64
|
const _speccer_margin_right_el = create(css.getNumberValue(_speccer_el.styles.marginRight));
|
|
65
|
+
|
|
54
66
|
classnames.set(_speccer_margin_right_el, 'margin right');
|
|
55
67
|
|
|
56
68
|
styles.add(_speccer_margin_right_el, {
|
|
@@ -62,14 +74,17 @@ export const element = async el => {
|
|
|
62
74
|
) + 'px',
|
|
63
75
|
top: css.normalizeNumberValue(_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y) + 'px'
|
|
64
76
|
});
|
|
77
|
+
|
|
65
78
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
66
79
|
node.after(el.closest('table'), _speccer_margin_right_el);
|
|
67
80
|
} else {
|
|
68
81
|
node.after(el, _speccer_margin_right_el);
|
|
69
82
|
}
|
|
70
83
|
}
|
|
84
|
+
|
|
71
85
|
if (_speccer_el.styles['marginBottom'] !== '0px') {
|
|
72
86
|
const _speccer_margin_bottom_el = create(css.getNumberValue(_speccer_el.styles.marginBottom));
|
|
87
|
+
|
|
73
88
|
classnames.set(_speccer_margin_bottom_el, 'margin bottom');
|
|
74
89
|
|
|
75
90
|
styles.add(_speccer_margin_bottom_el, {
|
|
@@ -81,14 +96,17 @@ export const element = async el => {
|
|
|
81
96
|
_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y + parseInt(_speccer_el.rect.height, 10)
|
|
82
97
|
) + 'px'
|
|
83
98
|
});
|
|
99
|
+
|
|
84
100
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
85
101
|
node.after(el.closest('table'), _speccer_margin_bottom_el);
|
|
86
102
|
} else {
|
|
87
103
|
node.after(el, _speccer_margin_bottom_el);
|
|
88
104
|
}
|
|
89
105
|
}
|
|
106
|
+
|
|
90
107
|
if (_speccer_el.styles['marginLeft'] !== '0px') {
|
|
91
108
|
const _speccer_margin_left_el = create(css.getNumberValue(_speccer_el.styles.marginLeft));
|
|
109
|
+
|
|
92
110
|
classnames.set(_speccer_margin_left_el, 'margin left');
|
|
93
111
|
|
|
94
112
|
styles.add(_speccer_margin_left_el, {
|
|
@@ -100,14 +118,17 @@ export const element = async el => {
|
|
|
100
118
|
) + 'px',
|
|
101
119
|
top: css.normalizeNumberValue(_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y) + 'px'
|
|
102
120
|
});
|
|
121
|
+
|
|
103
122
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
104
123
|
node.after(el.closest('table'), _speccer_margin_left_el);
|
|
105
124
|
} else {
|
|
106
125
|
node.after(el, _speccer_margin_left_el);
|
|
107
126
|
}
|
|
108
127
|
}
|
|
128
|
+
|
|
109
129
|
if (_speccer_el.styles['paddingTop'] !== '0px') {
|
|
110
130
|
const _speccer_padding_top_el = create(css.getNumberValue(_speccer_el.styles.paddingTop));
|
|
131
|
+
|
|
111
132
|
classnames.set(_speccer_padding_top_el, 'padding top');
|
|
112
133
|
|
|
113
134
|
styles.add(_speccer_padding_top_el, {
|
|
@@ -116,14 +137,17 @@ export const element = async el => {
|
|
|
116
137
|
left: css.normalizeNumberValue(_speccer_el.rect.x - el.parentElement.getBoundingClientRect().x) + 'px',
|
|
117
138
|
top: css.normalizeNumberValue(_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y) + 'px'
|
|
118
139
|
});
|
|
140
|
+
|
|
119
141
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
120
142
|
node.after(el.closest('table'), _speccer_padding_top_el);
|
|
121
143
|
} else {
|
|
122
144
|
node.after(el, _speccer_padding_top_el);
|
|
123
145
|
}
|
|
124
146
|
}
|
|
147
|
+
|
|
125
148
|
if (_speccer_el.styles['paddingBottom'] !== '0px') {
|
|
126
149
|
const _speccer_padding_bottom_el = create(css.getNumberValue(_speccer_el.styles.paddingBottom));
|
|
150
|
+
|
|
127
151
|
classnames.set(_speccer_padding_bottom_el, 'padding bottom');
|
|
128
152
|
|
|
129
153
|
styles.add(_speccer_padding_bottom_el, {
|
|
@@ -137,14 +161,17 @@ export const element = async el => {
|
|
|
137
161
|
(parseInt(_speccer_el.rect.height, 10) - parseInt(_speccer_el.styles.paddingBottom, 10))
|
|
138
162
|
) + 'px'
|
|
139
163
|
});
|
|
164
|
+
|
|
140
165
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
141
166
|
node.after(el.closest('table'), _speccer_padding_bottom_el);
|
|
142
167
|
} else {
|
|
143
168
|
node.after(el, _speccer_padding_bottom_el);
|
|
144
169
|
}
|
|
145
170
|
}
|
|
171
|
+
|
|
146
172
|
if (_speccer_el.styles['paddingRight'] !== '0px') {
|
|
147
173
|
const _speccer_padding_right_el = create(css.getNumberValue(_speccer_el.styles.paddingRight));
|
|
174
|
+
|
|
148
175
|
classnames.set(_speccer_padding_right_el, 'padding right');
|
|
149
176
|
|
|
150
177
|
styles.add(_speccer_padding_right_el, {
|
|
@@ -158,14 +185,17 @@ export const element = async el => {
|
|
|
158
185
|
) + 'px',
|
|
159
186
|
top: css.normalizeNumberValue(_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y) + 'px'
|
|
160
187
|
});
|
|
188
|
+
|
|
161
189
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
162
190
|
node.after(el.closest('table'), _speccer_padding_right_el);
|
|
163
191
|
} else {
|
|
164
192
|
node.after(el, _speccer_padding_right_el);
|
|
165
193
|
}
|
|
166
194
|
}
|
|
195
|
+
|
|
167
196
|
if (_speccer_el.styles['paddingLeft'] !== '0px') {
|
|
168
197
|
const _speccer_padding_left_el = create(css.getNumberValue(_speccer_el.styles.paddingLeft));
|
|
198
|
+
|
|
169
199
|
classnames.set(_speccer_padding_left_el, 'padding left');
|
|
170
200
|
|
|
171
201
|
styles.add(_speccer_padding_left_el, {
|
|
@@ -174,6 +204,7 @@ export const element = async el => {
|
|
|
174
204
|
left: css.normalizeNumberValue(_speccer_el.rect.x - el.parentElement.getBoundingClientRect().x) + 'px',
|
|
175
205
|
top: css.normalizeNumberValue(_speccer_el.rect.y - el.parentElement.getBoundingClientRect().y) + 'px'
|
|
176
206
|
});
|
|
207
|
+
|
|
177
208
|
if (SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0) {
|
|
178
209
|
node.after(el.closest('table'), _speccer_padding_left_el);
|
|
179
210
|
} else {
|
package/src/typography.js
CHANGED
|
@@ -10,13 +10,15 @@ import { SPECCER_TAGS_TO_AVOID } from './lib/constants';
|
|
|
10
10
|
|
|
11
11
|
export const create = (html, area) => {
|
|
12
12
|
const _el = document.createElement('div');
|
|
13
|
+
|
|
13
14
|
_el.innerHTML = html;
|
|
14
15
|
|
|
15
16
|
classnames.set(_el, `ph speccer typography ${area}`);
|
|
17
|
+
|
|
16
18
|
return _el;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
|
-
export const element = async el => {
|
|
21
|
+
export const element = async (el) => {
|
|
20
22
|
const _area = el.getAttribute('data-speccer-typography');
|
|
21
23
|
const _el_style = await styles.get(el);
|
|
22
24
|
|
|
@@ -25,6 +27,7 @@ export const element = async el => {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
el.classList.add('is-specced');
|
|
30
|
+
|
|
28
31
|
const _parent_style = styles.get(el.parentElement);
|
|
29
32
|
|
|
30
33
|
if (_parent_style.position === 'static') {
|
|
@@ -35,7 +38,6 @@ export const element = async el => {
|
|
|
35
38
|
|
|
36
39
|
const _styles = css.getTypography(_el_style);
|
|
37
40
|
const _el_rect = el.getBoundingClientRect();
|
|
38
|
-
|
|
39
41
|
const html =
|
|
40
42
|
`
|
|
41
43
|
` +
|
|
@@ -58,10 +60,13 @@ export const element = async el => {
|
|
|
58
60
|
|
|
59
61
|
let tableCorrectionTop = 0;
|
|
60
62
|
let tableCorrectionLeft = 0;
|
|
63
|
+
|
|
61
64
|
const tableCorrection = SPECCER_TAGS_TO_AVOID.indexOf(el.nodeName) >= 0;
|
|
65
|
+
|
|
62
66
|
if (tableCorrection) {
|
|
63
67
|
const table = el.parentElement;
|
|
64
68
|
const tableStyle = window.getComputedStyle(table.parentElement);
|
|
69
|
+
|
|
65
70
|
node.after(table, speccerNode);
|
|
66
71
|
tableCorrectionTop = table.getBoundingClientRect().top - parseInt(tableStyle.getPropertyValue('padding-top'), 10);
|
|
67
72
|
tableCorrectionLeft =
|
|
@@ -71,52 +76,50 @@ export const element = async el => {
|
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
const rectOfSpeccerNode = speccerNode.getBoundingClientRect();
|
|
74
|
-
|
|
75
|
-
let outlineLeftLeft =
|
|
79
|
+
const outlineLeftLeft =
|
|
76
80
|
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) -
|
|
77
81
|
rectOfSpeccerNode.width -
|
|
78
82
|
48 +
|
|
79
83
|
'px';
|
|
80
|
-
|
|
81
|
-
let outlineLeftTop =
|
|
84
|
+
const outlineLeftTop =
|
|
82
85
|
number.to3Decimals(
|
|
83
86
|
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) -
|
|
84
87
|
rectOfSpeccerNode.height / 2 +
|
|
85
88
|
_el_rect.height / 2
|
|
86
89
|
) + 'px';
|
|
87
|
-
|
|
90
|
+
const outlineRightLeft =
|
|
88
91
|
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) + _el_rect.width + 48 + 'px';
|
|
89
|
-
|
|
90
|
-
let outlineRightTop =
|
|
92
|
+
const outlineRightTop =
|
|
91
93
|
number.to3Decimals(
|
|
92
94
|
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) -
|
|
93
95
|
rectOfSpeccerNode.height / 2 +
|
|
94
96
|
_el_rect.height / 2
|
|
95
97
|
) + 'px';
|
|
96
|
-
|
|
98
|
+
const outlineTopLeft =
|
|
97
99
|
number.to3Decimals(
|
|
98
100
|
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) -
|
|
99
101
|
rectOfSpeccerNode.width / 2 +
|
|
100
102
|
_el_rect.width / 2
|
|
101
103
|
) + 'px';
|
|
102
|
-
|
|
104
|
+
const outlineTopTop =
|
|
103
105
|
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) -
|
|
104
106
|
rectOfSpeccerNode.height -
|
|
105
107
|
48 +
|
|
106
108
|
'px';
|
|
107
|
-
|
|
109
|
+
const outlineBottomleft =
|
|
108
110
|
number.to3Decimals(
|
|
109
111
|
(tableCorrection ? rectOfSpeccerNode.left - tableCorrectionLeft : el.offsetLeft) -
|
|
110
112
|
rectOfSpeccerNode.width / 2 +
|
|
111
113
|
_el_rect.width / 2
|
|
112
114
|
) + 'px';
|
|
113
|
-
|
|
115
|
+
const outlineBottomTop =
|
|
114
116
|
(tableCorrection ? rectOfSpeccerNode.top - tableCorrectionTop : el.offsetTop) + _el_rect.height + 48 + 'px';
|
|
115
117
|
|
|
116
118
|
let position = {
|
|
117
119
|
left: outlineLeftLeft,
|
|
118
120
|
top: outlineLeftTop
|
|
119
121
|
};
|
|
122
|
+
|
|
120
123
|
if (_area.indexOf('right') !== -1) {
|
|
121
124
|
position = {
|
|
122
125
|
left: outlineRightLeft,
|