@phun-ky/speccer 11.0.0 → 11.1.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/dist/speccer.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @phun-ky/speccer
3
3
  * A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements
4
4
  * @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net>
5
- * @version 11.0.0
5
+ * @version 11.1.0
6
6
  * @license
7
7
  * Copyright (c) 2018 Alexander Vassbotn Røyne-Helgesen
8
8
  *
@@ -24,5 +24,5 @@
24
24
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
25
  * SOFTWARE.
26
26
  */
27
- !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";var e,n,o,i,s,r,a;!function(t){t.Empty="",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top"}(e||(e={})),function(t){t.Pin="pin",t.Parent="parent",t.Text="text",t.Enclose="enclose",t.Subtle="subtle",t.Bracket="bracket",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top",t.SVG="svg",t.Curly="curly"}(n||(n={})),function(t){t.Measure="measure",t.Slim="slim",t.Width="width",t.Height="height",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top"}(o||(o={})),function(t){t.Typography="typography",t.Syntax="syntax",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top"}(i||(i={})),function(t){t.Spacing="spacing"}(s||(s={})),function(t){t.Mark="mark"}(r||(r={})),function(t){t.Grid="grid"}(a||(a={}));const c=t=>"string"==typeof t,p=t=>!c(t),l=t=>"number"==typeof t,d=t=>!l(t),h=t=>void 0===t,u=(t,e,n="noop")=>{t&&(!e||e&&!e.length||e.trim().split(" ").filter((t=>t!==n)).filter((t=>""!==t)).forEach((e=>t.classList.add(e.trim()))))},f=(t,e)=>t?!e&&p(t)?Object.keys(t).filter((e=>t[e])).join(" ").trim():`${t.trim()} ${e?Object.keys(e).filter((t=>e[t])).join(" "):""}`.trim():"",g=t=>t.split(" "),m=t=>{if(null===t)return!1;return g(t).includes(n.Bracket)},y=t=>{if(null===t)return!1;return g(t).includes(n.Enclose)},w=t=>{if(null===t)return!1;return g(t).includes(n.Subtle)},x=t=>{if(null===t)return!1;return g(t).includes(n.Parent)},b=t=>{if(null===t)return!1;return g(t).includes(n.Text)},$=t=>{if(null===t)return!1;return g(t).includes(o.Height)},E=t=>{if(null===t)return!1;return g(t).includes(o.Slim)},k=t=>{if(null===t)return!1;return g(t).includes(o.Width)},S=t=>{if(null===t)return!1;const e=g(t);return(x(t)&&!y(t)&&!m(t)||b(t)||e.includes(n.SVG))&&!A(t)},A=t=>{if(null===t)return!1;const e=g(t);return e.includes(n.Curly)&&e.includes(n.Bracket)},L=t=>!!t&&t.split(" ").includes(i.Syntax),C=(t,e)=>(t=>null!==t&&t.split(" ").includes(n.Pin))(t)?"pin":((t,e)=>null!==t&&t.split(" ").includes(a.Grid)&&("grid"===e.display||e.display.includes("grid")))(t,e)?"grid":(t=>null!==t&&t.split(" ").includes(r.Mark))(t)?"mark":(t=>null!==t&&t.split(" ").includes(o.Measure))(t)?"measure":(t=>null!==t&&t.split(" ").includes(s.Spacing))(t)?"spacing":(t=>null!==t&&t.split(" ").includes(i.Typography))(t)?"typography":"pin",v=t=>(t=>null!==t&&g(t).includes(n.Left))(t)?"left":(t=>null!==t&&g(t).includes(n.Right))(t)?"right":(t=>null!==t&&g(t).includes(n.Bottom))(t)?"bottom":"top",B=(t,e)=>{const n=C(t,e),o={slug:(i=t,i.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").trim().toLowerCase().replace(/[^a-z0-9 -]/g,"").replace(/\s+/g," ").replace(/(?:^\w|[A-Z]|\b\w)/g,((t,e)=>0===e?t.toLowerCase():t.toUpperCase())).replace(/\s+/g,"")),position:v(t),type:n};var i;if("pin"===n&&(o.pin={bracket:m(t),enclose:y(t),subtle:w(t),parent:x(t),text:b(t),useSVGLine:S(t),useCurlyBrackets:A(t)}),"measure"===n&&(o.measure={slim:E(t),height:$(t),width:k(t)}),"typography"===n&&(o.typography={useSyntaxHighlighting:L(t)}),"grid"===n){let e="both";t?.includes("columns")&&(e="columns"),t?.includes("rows")&&(e="rows"),o.grid={toggle:e}}return o},P=t=>!t.checkVisibility({opacityProperty:!0,checkVisibilityCSS:!0}),R=()=>new Promise(requestAnimationFrame),T=async(t,e,n)=>{await R();return getComputedStyle(t)[e]===n},H=async(t,e,n)=>{if(!t.parentElement)return null;return await T(t.parentElement,e,n)?t.parentElement:await H(t.parentElement,e,n)},M=(t,e,n)=>t-e.width/2+n.width/2,N=(t,e,n)=>t-e.height/2+n.height/2,I=async t=>{await R();let e=t.getBoundingClientRect(),n=e.top+window.scrollY;const o=e.left+window.scrollX,i=await(async t=>await H(t,"position","sticky"))(t),s=await(async t=>await T(t,"position","sticky"))(t);if(s){const o=t.style.position;await R(),t.style.position="relative",await R(),e=t.getBoundingClientRect(),n=e.top,t.style.position=o}else if(i){const o=i.style.position;await R(),i.style.position="relative",await R(),e=t.getBoundingClientRect(),n=e.top,i.style.position=o}return{height:e.height,width:e.width,top:n,left:o}},q=async(t,e)=>{await R();const n=t.getBoundingClientRect(),o=await I(e),i=await(async(t,e)=>{await R();const n=t.getBoundingClientRect(),o=e.getBoundingClientRect(),i=o.top+window.scrollY,s=o.left+window.scrollX;return{height:o.height,width:o.width,top:N(i,n,o),left:M(s,n,o)}})(t,e),s=o.height,r=o.width,a=n.height,c=n.width;return{absolute:()=>({top:o.top,left:o.left,height:s,width:r}),toTop:({center:t=!1,sourceHeight:e=a,modifier:n=0}={})=>({top:o.top+e+n,left:t?i.left:o.left,height:s,width:r}),fromTop:({center:t=!1,sourceHeight:e=a,modifier:n=0}={})=>({top:o.top-e-n,left:t?i.left:o.left,height:s,width:r}),toBottom:({center:t=!1,sourceHeight:e=a,targetHeight:n=s,modifier:c=0}={})=>({top:o.top+n-(e+c),left:t?i.left:o.left,height:s,width:r}),fromBottom:({center:t=!1,targetHeight:e=s,modifier:n=0}={})=>({top:o.top+e+n,left:t?i.left:o.left,height:s,width:r}),toLeft:({center:t=!1,sourceWidth:e=c,modifier:n=0}={})=>({top:t?i.top:o.top,left:o.left+e+n,height:s,width:r}),fromLeft:({center:t=!1,sourceWidth:e=c,modifier:n=0}={})=>({top:t?i.top:o.top,left:o.left-e-n,height:s,width:r}),toRight:({center:t=!1,sourceWidth:e=c,targetWidth:n=r,modifier:a=0}={})=>({top:t?i.top:o.top,left:o.left+n-(e+a),height:s,width:r}),fromRight:({center:t=!1,targetWidth:e=r,modifier:n=0}={})=>({top:t?i.top:o.top,left:o.left+e+n,height:s,width:r})}},V=async(t,e)=>{var n;if(!(!t||!e||c(e)||l(e)||(n=e,"boolean"==typeof n)||Array.isArray(e)&&!e.length||!Object.keys(e).length&&e.constructor===Object))if(await R(),Array.isArray(e))for(const n of e)t.style[n.key]=n.value;else for(const n of Object.keys(e))t.style[n]=e[n]},O=async t=>(await R(),getComputedStyle(t,null)),z=(t="",e,n="span")=>{const o=document.createElement(n);o.setAttribute("title",`${t}px`),o.setAttribute("data-measure",`${parseInt(String(t),10)}px`);const{measure:i,position:s}=e,r=f("ph-speccer speccer measure",{height:i?.height||!1,width:i?.width||!1,slim:i?.slim||!1,[s]:!0});return u(o,r),o},G=async t=>{if(!t)return;const e=t.getAttribute("data-speccer")||"";await R();const n=B(e,getComputedStyle(t));if("measure"!==n.type||!n.measure)return;if(P(t))return;await R();const{measure:i,position:s}=n,r=t.getBoundingClientRect(),a=i.slim?0:48,c=i.slim?0:96;if(i.width)if(s===o.Bottom){const e=z(r.width,n);document.body.appendChild(e);const o=await q(e,t);if(i.slim){const{left:t,top:n,width:i}=o.fromBottom({center:!1});await V(e,{left:`${t}px`,top:`${n}px`,width:`${i}px`})}else{const{left:t,top:n,width:i,height:s}=o.absolute({center:!1});await V(e,{left:`${t}px`,top:`${n}px`,width:`${i}px`,height:`${s+a}px`})}}else{const e=z(r.width,n);document.body.appendChild(e);const o=await q(e,t);if(i.slim){const{left:t,top:n,width:i}=o.fromTop({center:!1});await V(e,{left:`${t}px`,top:`${n}px`,width:`${i}px`})}else{const{left:t,top:n,width:i,height:s}=o.absolute({center:!1});await V(e,{left:`${t}px`,top:n-a+"px",width:`${i}px`,height:`${s+a}px`})}}else if(i.height)if(s===o.Right){const e=z(r.height,n);document.body.appendChild(e);const o=await q(e,t);if(i.slim){const{left:t,top:n,height:i}=o.fromRight({center:!1});await V(e,{left:`${t}px`,top:`${n}px`,height:`${i}px`})}else{const{left:t,top:n,height:i,width:s}=o.absolute({center:!1});await V(e,{left:`${t}px`,top:`${n}px`,height:`${i}px`,width:`${s+c}px`})}}else{const e=z(r.height,n);document.body.appendChild(e);const o=await q(e,t);if(i.slim){const{left:t,top:n,height:i}=o.fromLeft({center:!1});await V(e,{left:`${t}px`,top:`${n}px`,height:`${i}px`})}else{const{left:t,top:n,height:i,width:s}=o.absolute({center:!1});await V(e,{left:t-c+"px",top:`${n}px`,height:`${i}px`,width:`${s+c}px`})}}},j=(t="",e,n="",o="span")=>{const i=document.createElement(o),s={},{position:r,pin:a={}}=e,{useSVGLine:c,useCurlyBrackets:p,text:l,parent:d,bracket:h,enclose:g,subtle:m}=a;s.text=l,s.parent=d,s.bracket=h,s.enclose=g,s.subtle=m,s.svg=c,s.curly=p,s[r]=!0,!d||h||p||m||(s.svg=!0),!h&&!g||h&&p?i.innerHTML=t:(h||g)&&i.setAttribute("data-pin-counter",t);const y=f("ph-speccer speccer pin",s);return u(i,y),i.setAttribute("id",n),i},W=()=>"_"+Math.random().toString(36).substring(2,11),D=t=>t.top,F=t=>t.left+t.width,_=t=>t.top+t.height,X=t=>t.left,Y=t=>t.left+t.width/2,K=t=>t.top+t.height/2,U={center:t=>({x:Y(t),y:K(t)}),top:t=>({x:Y(t),y:D(t)}),right:t=>({x:F(t),y:K(t)}),bottom:t=>({x:Y(t),y:_(t)}),left:t=>({x:X(t),y:K(t)}),"right-top":t=>({x:F(t),y:D(t)}),"right-bottom":t=>({x:F(t),y:_(t)}),"left-top":t=>({x:X(t),y:D(t)}),"left-bottom":t=>({x:X(t),y:_(t)}),"top-left":t=>({x:X(t),y:D(t)}),"top-right":t=>({x:F(t),y:D(t)}),"bottom-left":t=>({x:X(t),y:_(t)}),"bottom-right":t=>({x:F(t),y:_(t)}),"top-center":t=>({x:Y(t),y:D(t)}),"right-center":t=>({x:F(t),y:K(t)}),"bottom-center":t=>({x:Y(t),y:_(t)}),"left-center":t=>({x:X(t),y:K(t)})},Z=async(t,e="center")=>{if(!e)throw Error("No position given");if(p(e))throw Error("The position given is not the required type: pos: "+typeof e);const n=["center","left","right","top","bottom","right-top","right-bottom","left-top","left-bottom","top-left","top-right","bottom-left","bottom-right","top-center","right-center","bottom-center","left-center"];if(!n.includes(e))throw Error(`The position given does not match allowed positions to use! Valid positions are: ${n.join(", ")}`);await R();const o=t.getBoundingClientRect();return U[e](o)};class J{#t;el;circle;radius;options;constructor(t,e,n){this.#e(t,e,n)}#e(t,e,n){if(!t||!e||!n)throw new Error("Missing inputs el or radius or options");if(!document.body.contains(t))throw new Error("el is not in the DOM");if(this.el=t,this.radius=e,this.options=n,this.#t=document.getElementById("ph-speccer-svg"),!this.#t)throw new Error("Missing required SVG element to draw circles. Please see the documentation");const o=document.body,i=document.documentElement,s=Math.max(o.scrollHeight,o.offsetHeight,i.clientHeight,i.scrollHeight,i.offsetHeight);V(this.#t,{height:`${s}px`}),this.draw()}async draw(){const t=`ph_draw-circle-${W()}`;this.circle=document.createElementNS("http://www.w3.org/2000/svg","circle");const e=this.el.getAttribute("id")||W();if(this.el.setAttribute("id",e),this.circle.setAttribute("id",t),this.circle.setAttribute("data-el",e),this.circle.classList.add("ph-speccer"),this.circle.classList.add("speccer"),this.circle.classList.add("circle"),!this.#t)throw new Error("No parentNode found for circle");this.#t.appendChild(this.circle);const{x:n,y:o}=await Z(this.el,this.options.position);this.circle.setAttribute("r",this.radius+""),this.circle.setAttribute("cx",Math.round(n)+""),this.circle.setAttribute("cy",Math.round(o+document.documentElement.scrollTop)+""),this.circle.setAttribute("fill","currentColor")}}window.DrawCircle=J;const Q=async(t,e,n="center",o="center")=>{if(!t||!e)throw Error("No element given");const{x:i,y:s}=await Z(t,n),{x:r,y:a}=await Z(e,o);return{x1:i,y1:s,x2:r,y2:a}},tt=(t,e)=>{const{x1:n,x2:o,y1:i,y2:s}=t,{direct:r=!1,firstSet:a=!1,direction:c}=e;let p={x:n+(o-n)/2,y:i},l={x:n+(o-n)/2,y:s};return r&&(a?"west"===c?(p={x:n-32,y:i-8},l={x:o+32,y:s}):"south"===c?(p={x:n-8,y:i+32},l={x:o,y:s-32}):"east"===c?(p={x:n+32,y:i-8},l={x:o-32,y:s}):(p={x:n-8,y:i-32},l={x:o,y:s+32}):"west"===c?(p={x:n-32,y:i+8},l={x:o+32,y:s}):"south"===c?(p={x:n+8,y:i+32},l={x:o,y:s-32}):"east"===c?(p={x:n+32,y:i+8},l={x:o-32,y:s}):(p={x:n+8,y:i-32},l={x:o,y:s+32})),{firstPoint:{x:n,y:i},firstControl:p,lastPoint:{x:o,y:s},lastControl:l}},et=async(t,e,n)=>{const{pos1:o,pos2:i,firstSet:s=!1,direction:r}=n,{x1:a,y1:c,x2:p,y2:l}=await Q(t,e,o,i);let d=0,h=0;"north"===r?h=8:"west"===r?d=8:"east"===r?d=-8:"south"===r&&(h=-8);const{firstPoint:u,firstControl:f,lastControl:g,lastPoint:m}=tt({x1:a+0,x2:p+d,y1:c+0+document.documentElement.scrollTop,y2:l+h+document.documentElement.scrollTop},{direct:!0,firstSet:s,direction:r});return`M ${u.x} ${u.y}C ${f.x} ${f.y}, ${g.x} ${g.y}, ${m.x} ${m.y}`},nt=async({start:t,stop:e,crude:n=!1})=>{const{x1:o,y1:i,x2:s,y2:r}=await Q(t,e),a=((t,e,n,o,i=!0)=>{if(h(t)||h(e)||h(n)||h(o))throw new SyntaxError("Missing input for `angle`");if(d(t)||d(e)||d(n)||d(o))throw TypeError(`Parameters for \`angle\` do not have the required type. Requires number! Got: ${typeof t} ${typeof e} ${typeof n} ${typeof o}`);const s=o-e,r=n-t;let a=Math.atan2(s,r);return a*=180/Math.PI,i&&a<0&&(a+=360),a})(o,i,s,r);return n?(t=>{if(t>360)throw new RangeError("Parameter cannot exceed 360");if(t<0)throw new RangeError("Parameter cannot be lower than 0");return t>=45&&t<=135?"south":t>135&&t<=225?"west":t>225&&t<=315?"north":"east"})(a):(t=>{if(t>360)throw new RangeError("Parameter cannot exceed 360");if(t<0)throw new RangeError("Parameter cannot be lower than 0");return t>=0&&t<=22.5?"east":t>=22.5&&t<=67.5?"south-east":t>=67.5&&t<=112.5?"south":t>=112.5&&t<=157.5?"south-west":t>=157.5&&t<=202.5?"west":t>=202.5&&t<=247.5?"north-west":t>=247.5&&t<=292.5?"north":t>=292.5&&t<=337.5?"north-east":"east"})(a)};class ot{#t;#n;startElement;stopElement;firstPathElement;secondPathElement;constructor(t,e){this.#e(t,e)}#e(t,e){if(!t||!e)throw new Error("Missing inputs startElement and stopElement");if(!document.body.contains(e))throw new Error("stopElement is not in the DOM");if(!document.body.contains(t))throw new Error("startElement is not in the DOM");if(this.startElement=t,this.stopElement=e,this.#t=document.getElementById("ph-speccer-svg"),this.#n=document.getElementById("ph-speccer-path"),!this.#n||!this.#t)throw new Error("Missing required SVG element to draw lines. Please see the documentation");const n=document.body,o=document.documentElement,i=Math.max(n.scrollHeight,n.offsetHeight,o.clientHeight,o.scrollHeight,o.offsetHeight);V(this.#t,{height:`${i}px`}),this.connect()}connect(){this.draw(this.#n)}#o(t){if(!t)throw new Error("No path given to #getPathElement!");const e=`ph_draw_path-path-${W()}`,n=t.cloneNode(!1),o=this.startElement.getAttribute("id")||W();return this.startElement.setAttribute("id",o),n.setAttribute("data-start-el",o),n.setAttribute("id",e),n.classList.remove("original"),n.classList.add("speccer"),n}async draw(t){if(!t)throw new Error("No path given to draw!");const e=this.#o(t),n=this.#o(t);if(!t.parentNode)throw new Error("No parentNode found for path");this.firstPathElement=t.parentNode.insertBefore(e,t.nextSibling),this.secondPathElement=t.parentNode.insertBefore(n,t.nextSibling);const o=await nt({stop:this.stopElement,start:this.startElement,crude:!0}),{path1pos1:i,path1pos2:s,path2pos1:r,path2pos2:a}=(t=>{let e,n,o,i;switch(t){case"east":e="right-top",n="left-center",o="right-bottom",i="left-center";break;case"south":e="bottom-left",n="top-center",o="bottom-right",i="top-center";break;case"west":e="left-top",n="right-center",o="left-bottom",i="right-center";break;default:e="top-left",n="bottom-center",o="top-right",i="bottom-center"}return{path1pos1:e,path1pos2:n,path2pos1:o,path2pos2:i}})(o),c=await et(this.startElement,this.stopElement,{pos1:i,pos2:s,firstSet:!0,direction:o}),p=await et(this.startElement,this.stopElement,{pos1:r,pos2:a,direction:o});this.firstPathElement.setAttribute("data-direction",o),this.firstPathElement.setAttribute("data-pos1",i),this.firstPathElement.setAttribute("data-pos2",s),this.firstPathElement.setAttribute("d",c),this.secondPathElement.setAttribute("data-direction",o),this.secondPathElement.setAttribute("data-pos1",r),this.secondPathElement.setAttribute("data-pos2",a),this.secondPathElement.setAttribute("d",p)}}window.DrawSVGCurlyBracket=ot;class it{#t;#n;startElement;stopElement;options;line;constructor(t,e,n={}){this.#e(t,e,n)}#e(t,e,n={}){if(!t||!e)throw new Error("Missing inputs startElement and stopElement");if(!document.body.contains(e))throw new Error("stopElement is not in the DOM");if(!document.body.contains(t))throw new Error("startElement is not in the DOM");if(this.startElement=t,this.stopElement=e,this.options=n,this.#t=document.getElementById("ph-speccer-svg"),this.#n=document.getElementById("ph-speccer-path"),!this.#n||!this.#t)throw new Error("Missing required SVG element to draw lines. Please see the documentation");const o=document.body,i=document.documentElement,s=Math.max(o.scrollHeight,o.offsetHeight,i.clientHeight,i.scrollHeight,i.offsetHeight);V(this.#t,{height:`${s}px`}),this.connect()}connect(){this.draw(this.#n)}async draw(t){if(!t)throw new Error("No path given to draw!");const e=`ph_draw_path-path-${W()}`,n=t.cloneNode(!1),o=this.startElement.getAttribute("id")||W();this.startElement.setAttribute("id",o),n.setAttribute("id",e),n.setAttribute("data-start-el",o),n.classList.remove("original"),n.classList.add("speccer");const{pin:i}=this.options;if(i?.text&&n.classList.add("text"),!t.parentNode)throw new Error("No parentNode found for path");this.line=t.parentNode.insertBefore(n,t.nextSibling);const s=await nt({start:this.startElement,stop:this.stopElement,crude:!0}),{pos1:r,pos2:a}=(t=>{let e,n;switch(t){case"east":e="right",n="left";break;case"south":e="bottom",n="top";break;case"west":e="left",n="right";break;default:e="top",n="bottom"}return{pos1:e,pos2:n}})(s),c=await(async(t,e,n)=>{const{pos1:o,pos2:i}=n,{x1:s,y1:r,x2:a,y2:c}=await Q(t,e,o,i),{firstPoint:p,firstControl:l,lastControl:d,lastPoint:h}=tt({x1:s,x2:a,y1:r+document.documentElement.scrollTop,y2:c+document.documentElement.scrollTop},{direction:""});return`M ${p.x} ${p.y}C ${l.x} ${l.y}, ${d.x} ${d.y}, ${h.x} ${h.y}`})(this.startElement,this.stopElement,{pos1:r,pos2:a});this.line.setAttribute("data-direction",s),this.line.setAttribute("data-pos1",r),this.line.setAttribute("data-pos2",a),this.line.setAttribute("d",c)}}window.DrawSVGLine=it;const st=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"],rt="data-speccer",at="spacing",ct=t=>parseInt(t,10),pt=t=>ct(getComputedStyle(t).getPropertyValue("--ph-speccer-pin-space"))||48,lt=async(t,e,o,i)=>{await R();const{pin:s={},position:r}=i,{useCurlyBrackets:a,subtle:c,bracket:p,text:l,parent:d,enclose:h}=s,u=pt(e),f=ct(getComputedStyle(e).getPropertyValue("--ph-speccer-measure-size"))||8;const g=await q(e,t);if(h){const{left:t,top:e,height:n,width:o}=g.absolute();return{left:`${t}px`,top:`${e}px`,height:`${n}px`,width:`${o}px`}}if((d||l)&&!p&&!a&&!c){if(r===n.Right){const{top:t}=g.fromRight({center:!0});await R();const{left:e,width:n}=o.getBoundingClientRect();return{left:`${e+n+u}px`,top:`${t}px`}}if(r===n.Bottom){const{left:t}=g.toBottom({center:!0});await R();const{top:e,height:n}=o.getBoundingClientRect();return{left:`${t}px`,top:`${e+n+u}px`}}if(r===n.Left){const{top:t}=g.fromLeft({center:!0});await R();const{left:e}=o.getBoundingClientRect();return{left:e-1.5*u-(l?170:0)+"px",top:`${t}px`}}const{left:t}=g.fromTop({center:!0});await R();const{top:e}=o.getBoundingClientRect();return{left:`${t}px`,top:e-1.5*u+"px"}}if(r===n.Left){if(p&&!a){const{left:t,top:e,height:n}=g.fromLeft({sourceWidth:f});return{left:`${t}px`,top:`${e}px`,height:`${n}px`}}const{left:t,top:e}=g.fromLeft({center:!0,modifier:a?u/1.5:u});return{left:`${t}px`,top:`${e}px`}}if(r===n.Right){if(p&&!a){const{left:t,top:e,height:n}=g.fromRight({center:!1});return{left:`${t}px`,top:`${e}px`,height:`${n}px`}}const{left:t,top:e}=g.fromRight({center:!0,modifier:a?u/1.5:u});return{left:`${t}px`,top:`${e}px`}}if(r===n.Bottom){if(p&&!a){const{left:t,top:e,width:n}=g.fromBottom({center:!1});return{left:`${t}px`,top:`${e}px`,width:`${n}px`}}const{left:t,top:e}=g.fromBottom({center:!0,modifier:a?u/1.5:u});return{left:`${t}px`,top:`${e}px`}}if(p&&!a){const{left:t,top:e,width:n}=g.fromTop({center:!1});return{left:`${t}px`,top:`${e}px`,width:`${n}px`}}const{left:m,top:y}=g.fromTop({center:!0,modifier:a?u/1.5:u});return{left:`${m}px`,top:`${y}px`}},dt=async(t,e,n,o)=>{if(!t)return;if("pin"!==o.type||!o.pin)return;const i=`speccer-${o.slug}-${t.getAttribute("id")||W()}`,s=j(n,o,i);t.setAttribute("data-speccer-element-id",i),document.body.appendChild(s);const r=await lt(t,s,e,o);await V(s,r);const a=o.pin.text&&null!==t.getAttribute("data-speccer-title"),c=o.pin.parent&&!o.pin.enclose&&!o.pin.bracket&&!a;return o.pin.useSVGLine?(new it(t,s,o),c&&new J(t,5,o)):o.pin.useCurlyBrackets&&new ot(t,s),i};let ht=0;const ut=async t=>{if(!t)return;const e=t.querySelectorAll('[data-speccer^="pin"]');if(!e||0===e.length)return;const n=t.getAttribute("data-speccer-literals")||window.SPECCER_LITERALS||st;[...e].filter((async t=>!P(t))).forEach((async(e,o)=>{const i=((t,e)=>{let n=e[t];return 0===t&&(ht=0),n||(n=`${e[ht]}${e[ht].toLowerCase()}`,ht++),n})(o,n),s=e.getAttribute("data-speccer")||"";await R();const r=getComputedStyle(e),a=B(s,r),c=((t,e,n)=>{const{pin:o}=n;if(!o)return t;const{text:i}=o;if(!i||null===e.getAttribute("data-speccer-title"))return t;const s=e.getAttribute("data-speccer-title"),r=e.getAttribute("data-speccer-description"),a=0===e.nodeName.indexOf("H")?`<span class="ph-speccer heading">${e.nodeName}</span>`:"";return!r&&s?`${a}<span class="ph-speccer title">${s}</span>`:r&&s?`${a}<span class="ph-speccer title">${s}</span><span class="ph-speccer description">${r.replaceAll("\\n","<br/>")}</span>`:t})(i,e,a);await dt(e,t,c,a)}))},ft=(t="",e="span")=>{const n=document.createElement(e),o=document.createTextNode(`${t}px`);return n.appendChild(o),n.setAttribute("title",`${t}px`),u(n,"ph-speccer speccer spacing"),n},gt=async t=>{if(!t)return;const e=await O(t);if(P(t))return;const n=(t=>{const{marginTop:e,marginBottom:n,marginLeft:o,marginRight:i,paddingTop:s,paddingBottom:r,paddingLeft:a,paddingRight:c}=t;return{marginTop:e,marginBottom:n,marginLeft:o,marginRight:i,paddingTop:s,paddingBottom:r,paddingLeft:a,paddingRight:c}})(e),o=Object.keys(n).filter((t=>"0px"!==n[t]));o.length&&o.forEach((async e=>{const o=ct(n[e]),i=ft(o),s=(t=>t.includes("Top")?t.replace("Top"," top"):t.includes("Right")?t.replace("Right"," right"):t.includes("Bottom")?t.replace("Bottom"," bottom"):t.includes("Left")?t.replace("Left"," left"):"")(e);u(i,s),document.body.appendChild(i),t.classList.add("is-specced"),await(async(t,e,n,o)=>{await R();const i=o.getBoundingClientRect(),s=await I(o);"marginTop"===t&&V(n,{height:`${e}px`,width:i.width+96+"px",left:s.left-96+"px",top:s.top-e+"px"}),"marginRight"===t&&V(n,{height:i.height+48+"px",width:`${e}px`,left:s.left+parseInt(i.width+"",10)+"px",top:s.top+"px"}),"marginBottom"===t&&V(n,{height:`${e}px`,width:i.width+96+"px",left:s.left-96+"px",top:s.top+parseInt(i.height+"",10)+"px"}),"marginLeft"===t&&V(n,{height:i.height+48+"px",width:`${e}px`,left:s.left-e+"px",top:s.top+"px"}),"paddingTop"===t&&V(n,{height:`${e}px`,width:i.width+96+"px",left:s.left-96+"px",top:s.top+"px"}),"paddingBottom"===t&&V(n,{height:`${e}px`,width:i.width+96+"px",left:s.left-96+"px",top:s.top+(parseInt(i.height+"",10)-e)+"px"}),"paddingRight"===t&&V(n,{height:i.height+48+"px",width:`${e}px`,left:s.left+(parseInt(i.width+"",10)-e)+"px",top:s.top+"px"}),"paddingLeft"===t&&V(n,{height:i.height+48+"px",width:`${e}px`,left:s.left+"px",top:s.top+"px"})})(e,o,i,t)}))},mt=t=>{const e=()=>((t,e,n=!1)=>{let o;return function(i,...s){const r=n&&!o;o&&clearTimeout(o),o=setTimeout((function(){o=null,n||t.apply(i,s)}),e),r&&t.apply(i,s)}})((()=>{t()}),300);window.removeEventListener("resize",e),window.addEventListener("resize",e)},yt=t=>{"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{t()})):t()},wt=()=>{const t=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(gt(n.target),e.unobserve(n.target))}));for(const e of document.querySelectorAll('[data-speccer^="spacing"],[data-speccer^="spacing"] *:not(td):not(tr):not(th):not(tfoot):not(thead):not(tbody)'))t.observe(e);const e=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(G(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll('[data-speccer^="measure"]'))e.observe(t);const n=new IntersectionObserver((async(t,e)=>{for(const n of t)n.intersectionRatio>0&&(await ut(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll('[data-speccer="pin-area"]'))n.observe(t)},xt=t=>{window.speccer=t},bt=t=>{const e=document.currentScript;if(e){const n=e.getAttribute("src");n?.includes("speccer.js")&&(e.hasAttribute("data-manual")?xt(t):e.hasAttribute("data-instant")?t():e.hasAttribute("data-dom")?yt(t):e.hasAttribute("data-lazy")?wt():yt(t),e.hasAttribute("data-manual")||e.hasAttribute("data-lazy")||mt(t))}},$t=["alt","altgraph","capslock","control","fn","fnlock","hyper","meta","numlock","os","scrolllock","shift","super","symbol","command","ctrl","altgr","symbollock"],Et=["escape","esc","enter","return","⏎","␛"],kt=async(t,e,n)=>{await R();const o=pt(n),i=await q(n,e);if("tabstops"===t){let{left:t,top:e}=i.fromTop();return t-=32,e+=32,t<=0&&(t=32),e<=0&&(e=32),{left:`${t}px`,top:`${e}px`}}if("landmark"===t){let{left:t,top:e}=i.fromTop();return t-=16,e-=16,t<=0&&(t=32),e<=0&&(e=32),{left:`${t}px`,top:`${e}px`}}if("region"===t){const{left:t,top:e,height:n,width:o}=i.fromTop();return{height:`${n}px`,width:`${o}px`,left:`${t}px`,top:`${e}px`}}if("shortcut"===t){const{left:t,top:e}=i.fromBottom();return{left:`${t}px`,top:`${e}px`}}const{left:s,top:r}=i.fromTop({center:!0,modifier:o});return{left:s-32+"px",top:r-32+"px"}},St=async(t,e,n)=>{if(!t||!t.checkVisibility())return;const o=((t="tabstops",e,n="span")=>{const o=document.createElement(n),i=f("ph-speccer speccer a11y",{tabstops:"tabstops"===t,landmark:"landmark"===t,region:"region"===t});if("landmark"===t&&e){const t=document.createTextNode(String(e));o.appendChild(t)}return u(o,i),o})(n,e);if("landmark"===n){o.setAttribute("data-speccer-nodename",t.nodeName);const e=t.role||`semantic role: ${t.nodeName.toLowerCase()}`,n=t.getAttribute("aria-label")||"unnamed";o.setAttribute("title",`${n}: ${e}`)}document.body.appendChild(o);const i=await kt(n,t,o);await V(o,i)},At=async(t,e)=>{const n=e.split(/\s\+\s/).map((t=>t.trim())),o=document.createElement("div");o.classList.add("ph-speccer"),o.classList.add("speccer"),o.classList.add("a11y"),o.classList.add("shortcut-holder");for(const t of n){const e=document.createElement("kbd"),n=document.createTextNode(t);e.classList.add("ph-speccer"),e.classList.add("speccer"),e.classList.add("a11y"),e.classList.add("shortcut"),$t.includes(t.toLowerCase())&&e.classList.add("modifier"),Et.includes(t.toLowerCase())&&e.classList.add("physical"),e.appendChild(n),o.appendChild(e)}document.body.appendChild(o);const i=await kt("shortcut",t,o);await V(o,i)},Lt=async(t,e,n)=>{await R();const{grid:o}=n;if(!o)return;const{toggle:i}=o,{height:s,width:r}=t.getBoundingClientRect(),{top:a,left:c}=await I(t),{gridTemplateColumns:p,gridTemplateRows:l,padding:d}=e;if("columns"===i||"both"===i){const t=parseInt(e.columnGap),n=document.createElement("div");document.documentElement.style.setProperty("--ph-speccer-grid-gap-original",`${t}px`),document.documentElement.style.setProperty("--ph-speccer-grid-gap",`${t<24?24:t}px`),t<24&&n.classList.add("speccer-small-grid"),n.classList.add("ph-speccer"),n.classList.add("speccer"),n.classList.add("speccer-grid-container"),n.style.height=`${s+64}px`,n.style.width=`${r}px`,n.style.left=`${c}px`,n.style.top=a-32+"px",n.style.padding=d,n.style.gridTemplateColumns=p;const o=p.split(" ").length;for(let t=0;t<o;t++){const t=document.createElement("div");t.classList.add("ph-speccer"),t.classList.add("speccer"),t.classList.add("speccer-grid-item"),n.appendChild(t)}document.body.appendChild(n)}if("rows"===i||"both"===i){const t=parseInt(e.rowGap),n=document.createElement("div");document.documentElement.style.setProperty("--ph-speccer-grid-row-gap-original",`${t}px`),document.documentElement.style.setProperty("--ph-speccer-grid-row-gap",`${t<24?24:t}px`),t<24&&n.classList.add("speccer-small-grid"),n.classList.add("ph-speccer"),n.classList.add("speccer"),n.classList.add("speccer-grid-row-container"),n.style.width=`${r+64}px`,n.style.height=`${s}px`,n.style.top=`${a}px`,n.style.left=c-32+"px",n.style.padding=d,n.style.gridTemplateRows=l;const o=l.split(" ").length;for(let t=0;t<o;t++){const t=document.createElement("div");t.classList.add("ph-speccer"),t.classList.add("speccer"),t.classList.add("speccer-grid-row-item"),n.appendChild(t)}document.body.appendChild(n)}},Ct=async t=>{if(!t)return;const e=t.getAttribute(rt)||"",n=await O(t),o=B(e,n);"grid"===o.type&&o.grid&&(P(t)||(await R(),await Lt(t,n,o)))},vt=(t="span")=>{const e=document.createElement(t),n=f("ph-speccer speccer mark");return u(e,n),e},Bt=async t=>{if(!t)return;const e=t.getAttribute(rt)||"";await R();if("mark"!==B(e,getComputedStyle(t)).type)return;if(P(t))return;const n=vt();document.body.appendChild(n);const o=await q(n,t),{left:i,top:s,height:r,width:a}=o.absolute(),c={left:`${i}px`,top:`${s}px`,height:`${r}px`,width:`${a}px`};await V(n,c)},Pt=(t,e=3)=>parseFloat(String(t)).toFixed(e),Rt=(t,e)=>{const n=document.createElement("div"),{typography:o,position:i}=e,s=f("ph-speccer speccer typography",{syntax:o?.useSyntaxHighlighting||!1,[i]:!0});return n.innerHTML=t,u(n,s),n},Tt=async t=>{if(!t)return;const e=t.getAttribute("data-speccer")||"";await R();const n=B(e,getComputedStyle(t));if("typography"!==n.type||!n.typography)return;if(P(t))return;t.classList.add("is-specced");const o=await(async(t,e=!1)=>{const n=(t=>{const{lineHeight:e,letterSpacing:n,fontFamily:o,fontSize:i,fontStyle:s,fontVariationSettings:r,fontWeight:a}=t;return{lineHeight:e,letterSpacing:n,fontFamily:o,fontSize:i,fontStyle:s,fontVariationSettings:r,fontWeight:a}})(await O(t));if(e){const t=n.fontFamily.split(",").map((t=>t.includes("'")?`<span class="token string">${t}</span>`:t)).join('<span class="token punctuation">, </span>'),e=`<span class="token number">${parseInt(n.fontSize,10)}</span><span class="token unit">px</span> <span class="token operator">/</span> <span class="token number">${parseInt(n.fontSize,10)/16}</span><span class="token unit">rem</span>`,o=n.letterSpacing.includes("px")?`<span class="token number">${parseInt(n.letterSpacing,10)}</span><span class="token unit">px</span>`:n.letterSpacing,i="normal"!==n.lineHeight?`<span class="token number">${parseInt(n.lineHeight,10)}</span><span class="token unit">px</span> <span class="token operator">/</span> <span class="token number">${parseInt(n.lineHeight,10)/16}</span><span class="token unit">rem</span>`:"normal";return`\n<pre class="language-css" tabindex="-1"><code class="language-css"><span class="token selector"><span class="token class">.typography</span></span> <span class="token punctuation">{</span>\n <span class="token property">font-family</span><span class="token punctuation">:</span> ${t}<span class="token punctuation">;</span>\n <span class="token property">font-size</span><span class="token punctuation">:</span> ${e}<span class="token punctuation">;</span>\n <span class="token property">font-weight</span><span class="token punctuation">:</span> <span class="token number">${n.fontWeight}</span><span class="token punctuation">;</span>\n <span class="token property">font-variation-settings</span><span class="token punctuation">:</span> ${n.fontVariationSettings}<span class="token punctuation">;</span>\n <span class="token property">line-height</span><span class="token punctuation">:</span> ${i}<span class="token punctuation">;</span>\n <span class="token property">letter-spacing</span><span class="token punctuation">:</span> ${o}<span class="token punctuation">;</span>\n <span class="token property">font-style</span><span class="token punctuation">:</span> ${n.fontStyle}<span class="token punctuation">;</span>\n<span class="token punctuation">}</span></code></pre>`}return`\ntypography: {<ul class="speccer-styles"> <li><span class="property">font-family:</span> ${n.fontFamily};</li> <li><span class="property">font-size:</span> ${n.fontSize} / ${parseInt(n.fontSize,10)/16}rem;</li> <li><span class="property">font-weight:</span> ${n.fontWeight};</li> <li><span class="property">font-variation-settings:</span> ${n.fontVariationSettings};</li> <li><span class="property">line-height:</span> ${"normal"!==n.lineHeight?`${parseInt(n.lineHeight,10)}px / ${parseInt(n.lineHeight,10)/16}rem`:"normal"};</li> <li><span class="property">letter-spacing:</span> ${n.letterSpacing};</li> <li><span class="property">font-style:</span> ${n.fontStyle};</li></ul>}`})(t,n.typography.useSyntaxHighlighting),s=Rt(o,n);document.body.appendChild(s);const r=await(async(t,e,n)=>{const o=e.getBoundingClientRect(),s=pt(n),r=n.getBoundingClientRect(),a=await I(e),{typography:c,position:p}=t;if(c&&p===i.Right)return{left:a.left+o.width+s+"px",top:Pt(N(a.top,r,o))+"px"};if(c&&p===i.Top)return{left:Pt(M(a.left,r,o))+"px",top:a.top-r.height-s+"px"};if(c&&p===i.Bottom)return{left:Pt(M(a.left,r,o))+"px",top:a.top+o.height+s+"px"};return{left:a.left-r.width-s+"px",top:Pt(N(a.top,r,o))+"px"}})(n,t,s);V(s,r)},Ht={create:Lt,element:Ct},Mt={create:ft,element:gt},Nt={createPinElement:j,pinElement:dt,pinElements:ut},It={create:z,element:G},qt={create:vt,element:Bt},Vt={create:Rt,element:Tt},Ot={dom:yt,lazy:wt,manual:xt,activate:bt},zt=()=>{((t,e=document)=>{[].forEach.call(e.querySelectorAll(t),(function(t){t.remove()}))})(".ph-speccer.speccer");const t=document.querySelectorAll(`[${rt}^="${at}"],[${rt}^="${at}"] *:not(td):not(tr):not(th):not(tfoot):not(thead):not(tbody)`),e=document.querySelectorAll(`[${rt}^="measure"]`),n=document.querySelectorAll(`[${rt}^="typography"]`),o=document.querySelectorAll(`[${rt}="pin-area"]`),i=document.querySelectorAll(`[${rt}^="mark"]`),s=document.querySelectorAll(`[${rt}^="grid"]`);for(const t of i)Bt(t);for(const t of s)Ct(t);for(const e of t)gt(e);for(const t of e)G(t);for(const t of n)Tt(t);for(const t of o)ut(t);(()=>{const t=document.querySelectorAll('[data-speccer*="a11y tabstops"]'),e=document.querySelectorAll('[data-speccer*="a11y landmark"]'),n=document.querySelectorAll('[data-speccer*="a11y shortcut"]');if(n.length)for(const t of n){const e=t.getAttribute("data-speccer-a11y-shortcut");e&&""!==e&&!P(t)&&At(t,e)}if(t.length)for(const e of t){const t=e.querySelectorAll("\n a[href], area[href], input:not([disabled]):not([tabindex='-1']),\n button:not([disabled]):not([tabindex='-1']),select:not([disabled]):not([tabindex='-1']),\n textarea:not([disabled]):not([tabindex='-1']),\n iframe, object, embed, *[tabindex]:not([tabindex='-1']), *[contenteditable=true]\n");for(const e of t)P(e)||St(e,null,"tabstops")}if(e.length)for(const t of e){const e=t.querySelectorAll('\nheader, footer, section, form, main, nav, aside, [role="section"], [role="banner"],\n[role="complementary"], [role="contentinfo"], [role="form"], [role="main"],\n[role="navigation"], [role="region"], [role="search"]\n');for(const[t,n]of e.entries())P(n)||(St(n,t+1,"landmark"),St(n,null,"region"))}})()};bt(zt),t.default=zt,t.grid=Ht,t.mark=qt,t.measure=It,t.modes=Ot,t.pin=Nt,t.spacing=Mt,t.typography=Vt,Object.defineProperty(t,"__esModule",{value:!0})}));
27
+ !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=[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"],n="data-speccer",o="spacing",i="measure",s="typography",r="mark",a="grid",c="pin-area";var l,p,d,h,u,f,g;!function(t){t.Empty="",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top"}(l||(l={})),function(t){t.Pin="pin",t.Parent="parent",t.Text="text",t.Enclose="enclose",t.Subtle="subtle",t.Bracket="bracket",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top",t.SVG="svg",t.Curly="curly"}(p||(p={})),function(t){t.Measure="measure",t.Slim="slim",t.Width="width",t.Height="height",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top"}(d||(d={})),function(t){t.Typography="typography",t.Syntax="syntax",t.Left="left",t.Right="right",t.Bottom="bottom",t.Top="top"}(h||(h={})),function(t){t.Spacing="spacing"}(u||(u={})),function(t){t.Mark="mark"}(f||(f={})),function(t){t.Grid="grid"}(g||(g={}));const m=t=>t.split(" "),y=t=>{if(null===t)return!1;return m(t).includes(p.Bracket)},w=t=>{if(null===t)return!1;return m(t).includes(p.Enclose)},x=t=>{if(null===t)return!1;return m(t).includes(p.Subtle)},b=t=>{if(null===t)return!1;return m(t).includes(p.Parent)},$=t=>{if(null===t)return!1;return m(t).includes(p.Text)},E=t=>{if(null===t)return!1;return m(t).includes(d.Height)},A=t=>{if(null===t)return!1;return m(t).includes(d.Slim)},k=t=>{if(null===t)return!1;return m(t).includes(d.Width)},S=t=>{if(null===t)return!1;const e=m(t);return(b(t)&&!w(t)&&!y(t)||$(t)||e.includes(p.SVG))&&!C(t)},C=t=>{if(null===t)return!1;const e=m(t);return e.includes(p.Curly)&&e.includes(p.Bracket)},L=t=>!!t&&t.split(" ").includes(h.Syntax),v=(t,e)=>(t=>null!==t&&t.split(" ").includes(p.Pin))(t)?"pin":((t,e)=>null!==t&&t.split(" ").includes(g.Grid)&&("grid"===e.display||e.display.includes("grid")))(t,e)?"grid":(t=>null!==t&&t.split(" ").includes(f.Mark))(t)?"mark":(t=>null!==t&&t.split(" ").includes(d.Measure))(t)?"measure":(t=>null!==t&&t.split(" ").includes(u.Spacing))(t)?"spacing":(t=>null!==t&&t.split(" ").includes(h.Typography))(t)?"typography":"pin",P=t=>(t=>null!==t&&m(t).includes(p.Left))(t)?"left":(t=>null!==t&&m(t).includes(p.Right))(t)?"right":(t=>null!==t&&m(t).includes(p.Bottom))(t)?"bottom":"top",B=(t,e,n)=>{const o=v(t,e),i={slug:(s=t,s.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").trim().toLowerCase().replace(/[^a-z0-9 -]/g,"").replace(/\s+/g," ").replace(/(?:^\w|[A-Z]|\b\w)/g,((t,e)=>0===e?t.toLowerCase():t.toUpperCase())).replace(/\s+/g,"")),position:P(t),type:o};var s;if("pin"===o&&(i.pin={bracket:y(t),enclose:w(t),subtle:x(t),parent:b(t),text:$(t),useSVGLine:S(t),useCurlyBrackets:C(t)}),"measure"===o&&(i.measure={slim:A(t),height:E(t),width:k(t)}),"typography"===o&&(i.typography={useSyntaxHighlighting:L(t)}),"grid"===o){const e=(t=>t?.includes("columns")?"columns":t?.includes("rows")?"rows":"both")(t);i.grid={toggle:e,both:"both"===e,rows:"rows"===e,columns:"columns"===e}}if("spacing"===o){const e=(t=>t?.includes("margin")?"margin":t?.includes("padding")?"padding":"both")(t);i.spacing={both:"both"===e,margin:"margin"===e,padding:"padding"===e,bound:t.includes("bound")}}return{...i,...n}},R=()=>"_"+Math.random().toString(36).substring(2,11),T=t=>!t.checkVisibility({opacityProperty:!0,checkVisibilityCSS:!0}),H=()=>new Promise(requestAnimationFrame),I=async(t,e,n)=>{await H();return getComputedStyle(t)[e]===n},M=async(t,e,n)=>{if(!t.parentElement)return null;return await I(t.parentElement,e,n)?t.parentElement:await M(t.parentElement,e,n)},N=(t,e,n)=>t-e.width/2+n.width/2,q=(t,e,n)=>t-e.height/2+n.height/2,O=async t=>{await H();let e=t.getBoundingClientRect(),n=e.top+window.scrollY;const o=e.left+window.scrollX,i=await(async t=>await M(t,"position","sticky"))(t),s=await(async t=>await I(t,"position","sticky"))(t);if(s){const o=t.style.position;await H(),t.style.position="relative",await H(),e=t.getBoundingClientRect(),n=e.top,await H(),t.style.position=o}else if(i){const o=i.style.position;await H(),i.style.position="relative",await H(),e=t.getBoundingClientRect(),n=e.top,await H(),i.style.position=o}return{height:e.height,width:e.width,top:n,left:o}},V=async(t,e)=>{await H();const n=t.getBoundingClientRect(),o=await O(e),i=await(async(t,e)=>{await H();const n=t.getBoundingClientRect();await H();const o=e.getBoundingClientRect(),i=o.top+window.scrollY,s=o.left+window.scrollX;return{height:o.height,width:o.width,top:q(i,n,o),left:N(s,n,o)}})(t,e),s=o.height,r=o.width,a=n.height,c=n.width;return{absolute:()=>({top:o.top,left:o.left,height:s,width:r}),toTop:({center:t=!1,sourceHeight:e=a,modifier:n=0}={})=>({top:o.top+e+n,left:t?i.left:o.left,height:s,width:r}),fromTop:({center:t=!1,sourceHeight:e=a,modifier:n=0}={})=>({top:o.top-e-n,left:t?i.left:o.left,height:s,width:r}),toBottom:({center:t=!1,sourceHeight:e=a,targetHeight:n=s,modifier:c=0}={})=>({top:o.top+n-(e+c),left:t?i.left:o.left,height:s,width:r}),fromBottom:({center:t=!1,targetHeight:e=s,modifier:n=0}={})=>({top:o.top+e+n,left:t?i.left:o.left,height:s,width:r}),toLeft:({center:t=!1,sourceWidth:e=c,modifier:n=0}={})=>({top:t?i.top:o.top,left:o.left+e+n,height:s,width:r}),fromLeft:({center:t=!1,sourceWidth:e=c,modifier:n=0}={})=>({top:t?i.top:o.top,left:o.left-e-n,height:s,width:r}),toRight:({center:t=!1,sourceWidth:e=c,targetWidth:n=r,modifier:a=0}={})=>({top:t?i.top:o.top,left:o.left+n-(e+a),height:s,width:r}),fromRight:({center:t=!1,targetWidth:e=r,modifier:n=0}={})=>({top:t?i.top:o.top,left:o.left+e+n,height:s,width:r})}},z=t=>"string"==typeof t,G=t=>!z(t),j=t=>"number"==typeof t,W=t=>!j(t),D=t=>void 0===t,F=async(t,e)=>{var n;if(!(!t||!e||z(e)||j(e)||(n=e,"boolean"==typeof n)||Array.isArray(e)&&!e.length||!Object.keys(e).length&&e.constructor===Object))if(await H(),Array.isArray(e))for(const n of e)t.style[n.key]=n.value;else for(const n of Object.keys(e))t.style[n]=e[n]},_=async t=>(await H(),getComputedStyle(t,null)),X=async(t,e,n)=>{await H();const{grid:o}=n;if(!o)return;const{toggle:i}=o,{height:s,width:r}=t.getBoundingClientRect(),{top:a,left:c}=await O(t),{gridTemplateColumns:l,gridTemplateRows:p,padding:d}=e,h=`speccer-${n.slug}-${t.getAttribute("id")||R()}`;if(t.setAttribute("data-speccer-element-id",h),"columns"===i||"both"===i){const t=parseInt(e.columnGap),n=document.createElement("div");document.documentElement.style.setProperty("--ph-speccer-grid-gap-original",`${t}px`),document.documentElement.style.setProperty("--ph-speccer-grid-gap",`${t<24?24:t}px`),t<24&&n.classList.add("speccer-small-grid"),n.setAttribute("data-speccer-id",h),n.classList.add("ph-speccer"),n.classList.add("speccer"),n.classList.add("speccer-grid-container"),n.style.height=`${s+64}px`,n.style.width=`${r}px`,n.style.left=`${c}px`,n.style.top=a-32+"px",n.style.padding=d,n.style.gridTemplateColumns=l;const o=l.split(" ").length;for(let t=0;t<o;t++){const t=document.createElement("div");t.classList.add("ph-speccer"),t.classList.add("speccer"),t.classList.add("speccer-grid-item"),n.appendChild(t)}document.body.appendChild(n)}if("rows"===i||"both"===i){const t=parseInt(e.rowGap),n=document.createElement("div");document.documentElement.style.setProperty("--ph-speccer-grid-row-gap-original",`${t}px`),document.documentElement.style.setProperty("--ph-speccer-grid-row-gap",`${t<24?24:t}px`),t<24&&n.classList.add("speccer-small-grid"),n.setAttribute("data-speccer-id",h),n.classList.add("ph-speccer"),n.classList.add("speccer"),n.classList.add("speccer-grid-row-container"),n.style.width=`${r+64}px`,n.style.height=`${s}px`,n.style.top=`${a}px`,n.style.left=c-32+"px",n.style.padding=d,n.style.gridTemplateRows=p;const o=p.split(" ").length;for(let t=0;t<o;t++){const t=document.createElement("div");t.classList.add("ph-speccer"),t.classList.add("speccer"),t.classList.add("speccer-grid-row-item"),n.appendChild(t)}document.body.appendChild(n)}},Y=async(t,e)=>{if(!t)return;if(T(t))return;const o=t.getAttribute(n)||"",i=await _(t),s=B(o,i,e);"grid"===s.type&&s.grid&&(await H(),await X(t,i,s))},K=(t,e,n="noop")=>{t&&(!e||e&&!e.length||e.trim().split(" ").filter((t=>t!==n)).filter((t=>""!==t)).forEach((e=>t.classList.add(e.trim()))))},U=(t,e)=>t?!e&&G(t)?Object.keys(t).filter((e=>t[e])).join(" ").trim():`${t.trim()} ${e?Object.keys(e).filter((t=>e[t])).join(" "):""}`.trim():"",Z=(t,e="span")=>{const n=document.createElement(e);n.setAttribute("id",t);const o=U("ph-speccer speccer mark");return K(n,o),n},J=async t=>{if(!t)return;if(T(t))return;const e=t.getAttribute(n)||"";await H();const o=B(e,getComputedStyle(t));if("mark"!==o.type)return;const i=`speccer-${o.slug}-${t.getAttribute("id")||R()}`;t.setAttribute("data-speccer-element-id",i);const s=Z(i);document.body.appendChild(s);const r=await V(s,t),{left:a,top:c,height:l,width:p}=r.absolute(),d={left:`${a}px`,top:`${c}px`,height:`${l}px`,width:`${p}px`};await F(s,d)},Q=(t="",e,n,o="span")=>{const i=document.createElement(o);i.setAttribute("title",`${t}px`),i.setAttribute("id",n),i.setAttribute("data-measure",`${parseInt(String(t),10)}px`);const{measure:s,position:r}=e,a=U("ph-speccer speccer measure",{height:s?.height||!1,width:s?.width||!1,slim:s?.slim||!1,[r]:!0});return K(i,a),i},tt=async(t,e)=>{if(!t)return;if(T(t))return;const n=t.getAttribute("data-speccer")||"";await H();const o=B(n,getComputedStyle(t),e);if("measure"!==o.type||!o.measure)return;const{measure:i,position:s}=o;await H();const r=t.getBoundingClientRect(),a=i.slim?0:48,c=i.slim?0:96,l=`speccer-${o.slug}-${t.getAttribute("id")||R()}`;if(t.setAttribute("data-speccer-element-id",l),i.width)if(s===d.Bottom){const e=Q(r.width,o,l);document.body.appendChild(e);const n=await V(e,t);if(i.slim){const{left:t,top:o,width:i}=n.fromBottom({center:!1});await F(e,{left:`${t}px`,top:`${o}px`,width:`${i}px`})}else{const{left:t,top:o,width:i,height:s}=n.absolute({center:!1});await F(e,{left:`${t}px`,top:`${o}px`,width:`${i}px`,height:`${s+a}px`})}}else{const e=Q(r.width,o,l);document.body.appendChild(e);const n=await V(e,t);if(i.slim){const{left:t,top:o,width:i}=n.fromTop({center:!1});await F(e,{left:`${t}px`,top:`${o}px`,width:`${i}px`})}else{const{left:t,top:o,width:i,height:s}=n.absolute({center:!1});await F(e,{left:`${t}px`,top:o-a+"px",width:`${i}px`,height:`${s+a}px`})}}else if(i.height)if(s===d.Right){const e=Q(r.height,o,l);document.body.appendChild(e);const n=await V(e,t);if(i.slim){const{left:t,top:o,height:i}=n.fromRight({center:!1});await F(e,{left:`${t}px`,top:`${o}px`,height:`${i}px`})}else{const{left:t,top:o,height:i,width:s}=n.absolute({center:!1});await F(e,{left:`${t}px`,top:`${o}px`,height:`${i}px`,width:`${s+c}px`})}}else{const e=Q(r.height,o,l);document.body.appendChild(e);const n=await V(e,t);if(i.slim){const{left:t,top:o,height:i}=n.fromLeft({center:!1});await F(e,{left:`${t}px`,top:`${o}px`,height:`${i}px`})}else{const{left:t,top:o,height:i,width:s}=n.absolute({center:!1});await F(e,{left:t-c+"px",top:`${o}px`,height:`${i}px`,width:`${s+c}px`})}}},et=(t="",e,n="",o="span")=>{const i=document.createElement(o),s={},{position:r,pin:a={}}=e,{useSVGLine:c,useCurlyBrackets:l,text:p,parent:d,bracket:h,enclose:u,subtle:f}=a;s.text=p,s.parent=d,s.bracket=h,s.enclose=u,s.subtle=f,s.svg=c,s.curly=l,s[r]=!0,!d||h||l||f||(s.svg=!0),!h&&!u||h&&l?i.innerHTML=t:(h||u)&&i.setAttribute("data-pin-counter",t);const g=U("ph-speccer speccer pin",s);return K(i,g),i.setAttribute("id",n),i},nt=t=>t.top,ot=t=>t.left+t.width,it=t=>t.top+t.height,st=t=>t.left,rt=t=>t.left+t.width/2,at=t=>t.top+t.height/2,ct={center:t=>({x:rt(t),y:at(t)}),top:t=>({x:rt(t),y:nt(t)}),right:t=>({x:ot(t),y:at(t)}),bottom:t=>({x:rt(t),y:it(t)}),left:t=>({x:st(t),y:at(t)}),"right-top":t=>({x:ot(t),y:nt(t)}),"right-bottom":t=>({x:ot(t),y:it(t)}),"left-top":t=>({x:st(t),y:nt(t)}),"left-bottom":t=>({x:st(t),y:it(t)}),"top-left":t=>({x:st(t),y:nt(t)}),"top-right":t=>({x:ot(t),y:nt(t)}),"bottom-left":t=>({x:st(t),y:it(t)}),"bottom-right":t=>({x:ot(t),y:it(t)}),"top-center":t=>({x:rt(t),y:nt(t)}),"right-center":t=>({x:ot(t),y:at(t)}),"bottom-center":t=>({x:rt(t),y:it(t)}),"left-center":t=>({x:st(t),y:at(t)})},lt=async(t,e="center")=>{if(!e)throw Error("No position given");if(G(e))throw Error("The position given is not the required type: pos: "+typeof e);const n=["center","left","right","top","bottom","right-top","right-bottom","left-top","left-bottom","top-left","top-right","bottom-left","bottom-right","top-center","right-center","bottom-center","left-center"];if(!n.includes(e))throw Error(`The position given does not match allowed positions to use! Valid positions are: ${n.join(", ")}`);await H();const o=t.getBoundingClientRect();return ct[e](o)};class pt{#t;el;circle;radius;options;constructor(t,e,n){this.#e(t,e,n)}#e(t,e,n){if(!t||!e||!n)throw new Error("Missing inputs el or radius or options");if(!document.body.contains(t))throw new Error("el is not in the DOM");if(this.el=t,this.radius=e,this.options=n,this.#t=document.getElementById("ph-speccer-svg"),!this.#t)throw new Error("Missing required SVG element to draw circles. Please see the documentation");const o=document.body,i=document.documentElement,s=Math.max(o.scrollHeight,o.offsetHeight,i.clientHeight,i.scrollHeight,i.offsetHeight);F(this.#t,{height:`${s}px`}),this.draw()}async draw(){const t=`ph_draw-circle-${R()}`;this.circle=document.createElementNS("http://www.w3.org/2000/svg","circle");const e=this.el.getAttribute("id")||R();if(this.el.setAttribute("id",e),this.circle.setAttribute("id",t),this.circle.setAttribute("data-el",e),this.circle.classList.add("ph-speccer"),this.circle.classList.add("speccer"),this.circle.classList.add("circle"),!this.#t)throw new Error("No parentNode found for circle");this.#t.appendChild(this.circle);const{x:n,y:o}=await lt(this.el,this.options.position);this.circle.setAttribute("r",this.radius+""),this.circle.setAttribute("cx",Math.round(n)+""),this.circle.setAttribute("cy",Math.round(o+document.documentElement.scrollTop)+""),this.circle.setAttribute("fill","currentColor")}}window.DrawCircle=pt;const dt=async(t,e,n="center",o="center")=>{if(!t||!e)throw Error("No element given");const{x:i,y:s}=await lt(t,n),{x:r,y:a}=await lt(e,o);return{x1:i,y1:s,x2:r,y2:a}},ht=(t,e)=>{const{x1:n,x2:o,y1:i,y2:s}=t,{direct:r=!1,firstSet:a=!1,direction:c}=e,l={x:n,y:i},p={x:o,y:s};return r?a?"west"===c?{firstPoint:l,firstControl:{x:n-32,y:i-8},lastPoint:p,lastControl:{x:o+32,y:s}}:"south"===c?{firstPoint:l,firstControl:{x:n-8,y:i+32},lastPoint:p,lastControl:{x:o,y:s-32}}:"east"===c?{firstPoint:l,firstControl:{x:n+32,y:i-8},lastPoint:p,lastControl:{x:o-32,y:s}}:{firstPoint:l,firstControl:{x:n-8,y:i-32},lastPoint:p,lastControl:{x:o,y:s+32}}:"west"===c?{firstPoint:l,firstControl:{x:n-32,y:i+8},lastPoint:p,lastControl:{x:o+32,y:s}}:"south"===c?{firstPoint:l,firstControl:{x:n+8,y:i+32},lastPoint:p,lastControl:{x:o,y:s-32}}:"east"===c?{firstPoint:l,firstControl:{x:n+32,y:i+8},lastPoint:p,lastControl:{x:o-32,y:s}}:{firstPoint:l,firstControl:{x:n+8,y:i-32},lastPoint:p,lastControl:{x:o,y:s+32}}:{firstPoint:l,firstControl:{x:n+(o-n)/2,y:i},lastPoint:p,lastControl:{x:n+(o-n)/2,y:s}}},ut=async(t,e,n)=>{const{pos1:o,pos2:i,firstSet:s=!1,direction:r}=n,{x1:a,y1:c,x2:l,y2:p}=await dt(t,e,o,i);let d=0,h=0;"north"===r?h=8:"west"===r?d=8:"east"===r?d=-8:"south"===r&&(h=-8);const{firstPoint:u,firstControl:f,lastControl:g,lastPoint:m}=ht({x1:a+0,x2:l+d,y1:c+0+document.documentElement.scrollTop,y2:p+h+document.documentElement.scrollTop},{direct:!0,firstSet:s,direction:r});return`M ${u.x} ${u.y}C ${f.x} ${f.y}, ${g.x} ${g.y}, ${m.x} ${m.y}`},ft=async({start:t,stop:e,crude:n=!1})=>{const{x1:o,y1:i,x2:s,y2:r}=await dt(t,e),a=((t,e,n,o,i=!0)=>{if(D(t)||D(e)||D(n)||D(o))throw new SyntaxError("Missing input for `angle`");if(W(t)||W(e)||W(n)||W(o))throw TypeError(`Parameters for \`angle\` do not have the required type. Requires number! Got: ${typeof t} ${typeof e} ${typeof n} ${typeof o}`);const s=o-e,r=n-t;let a=Math.atan2(s,r);return a*=180/Math.PI,i&&a<0&&(a+=360),a})(o,i,s,r);return n?(t=>{if(t>360)throw new RangeError("Parameter cannot exceed 360");if(t<0)throw new RangeError("Parameter cannot be lower than 0");return t>=45&&t<=135?"south":t>135&&t<=225?"west":t>225&&t<=315?"north":"east"})(a):(t=>{if(t>360)throw new RangeError("Parameter cannot exceed 360");if(t<0)throw new RangeError("Parameter cannot be lower than 0");return t>=0&&t<=22.5?"east":t>=22.5&&t<=67.5?"south-east":t>=67.5&&t<=112.5?"south":t>=112.5&&t<=157.5?"south-west":t>=157.5&&t<=202.5?"west":t>=202.5&&t<=247.5?"north-west":t>=247.5&&t<=292.5?"north":t>=292.5&&t<=337.5?"north-east":"east"})(a)};class gt{#t;#n;startElement;stopElement;firstPathElement;secondPathElement;constructor(t,e){this.#e(t,e)}#e(t,e){if(!t||!e)throw new Error("Missing inputs startElement and stopElement");if(!document.body.contains(e))throw new Error("stopElement is not in the DOM");if(!document.body.contains(t))throw new Error("startElement is not in the DOM");if(this.startElement=t,this.stopElement=e,this.#t=document.getElementById("ph-speccer-svg"),this.#n=document.getElementById("ph-speccer-path"),!this.#n||!this.#t)throw new Error("Missing required SVG element to draw lines. Please see the documentation");const n=document.body,o=document.documentElement,i=Math.max(n.scrollHeight,n.offsetHeight,o.clientHeight,o.scrollHeight,o.offsetHeight);F(this.#t,{height:`${i}px`}),this.connect()}connect(){this.draw(this.#n)}#o(t){if(!t)throw new Error("No path given to #getPathElement!");const e=`ph_draw_path-path-${R()}`,n=t.cloneNode(!1),o=this.startElement.getAttribute("id")||R();return this.startElement.setAttribute("id",o),n.setAttribute("data-start-el",o),n.setAttribute("id",e),n.classList.remove("original"),n.classList.add("speccer"),n}async draw(t){if(!t)throw new Error("No path given to draw!");const e=this.#o(t),n=this.#o(t);if(!t.parentNode)throw new Error("No parentNode found for path");this.firstPathElement=t.parentNode.insertBefore(e,t.nextSibling),this.secondPathElement=t.parentNode.insertBefore(n,t.nextSibling);const o=await ft({stop:this.stopElement,start:this.startElement,crude:!0}),{path1pos1:i,path1pos2:s,path2pos1:r,path2pos2:a}=(t=>{let e,n,o,i;switch(t){case"east":e="right-top",n="left-center",o="right-bottom",i="left-center";break;case"south":e="bottom-left",n="top-center",o="bottom-right",i="top-center";break;case"west":e="left-top",n="right-center",o="left-bottom",i="right-center";break;default:e="top-left",n="bottom-center",o="top-right",i="bottom-center"}return{path1pos1:e,path1pos2:n,path2pos1:o,path2pos2:i}})(o),c=await ut(this.startElement,this.stopElement,{pos1:i,pos2:s,firstSet:!0,direction:o}),l=await ut(this.startElement,this.stopElement,{pos1:r,pos2:a,direction:o});this.firstPathElement.setAttribute("data-direction",o),this.firstPathElement.setAttribute("data-pos1",i),this.firstPathElement.setAttribute("data-pos2",s),this.firstPathElement.setAttribute("d",c),this.secondPathElement.setAttribute("data-direction",o),this.secondPathElement.setAttribute("data-pos1",r),this.secondPathElement.setAttribute("data-pos2",a),this.secondPathElement.setAttribute("d",l)}}window.DrawSVGCurlyBracket=gt;class mt{#t;#n;startElement;stopElement;options;line;constructor(t,e,n={}){this.#e(t,e,n)}#e(t,e,n={}){if(!t||!e)throw new Error("Missing inputs startElement and stopElement");if(!document.body.contains(e))throw new Error("stopElement is not in the DOM");if(!document.body.contains(t))throw new Error("startElement is not in the DOM");if(this.startElement=t,this.stopElement=e,this.options=n,this.#t=document.getElementById("ph-speccer-svg"),this.#n=document.getElementById("ph-speccer-path"),!this.#n||!this.#t)throw new Error("Missing required SVG element to draw lines. Please see the documentation");const o=document.body,i=document.documentElement,s=Math.max(o.scrollHeight,o.offsetHeight,i.clientHeight,i.scrollHeight,i.offsetHeight);F(this.#t,{height:`${s}px`}),this.connect()}connect(){this.draw(this.#n)}async draw(t){if(!t)throw new Error("No path given to draw!");const e=`ph_draw_path-path-${R()}`,n=t.cloneNode(!1),o=this.startElement.getAttribute("id")||R();this.startElement.setAttribute("id",o),n.setAttribute("id",e),n.setAttribute("data-start-el",o),n.classList.remove("original"),n.classList.add("speccer");const{pin:i}=this.options;if(i?.text&&n.classList.add("text"),!t.parentNode)throw new Error("No parentNode found for path");this.line=t.parentNode.insertBefore(n,t.nextSibling);const s=await ft({start:this.startElement,stop:this.stopElement,crude:!0}),{pos1:r,pos2:a}=(t=>{let e,n;switch(t){case"east":e="right",n="left";break;case"south":e="bottom",n="top";break;case"west":e="left",n="right";break;default:e="top",n="bottom"}return{pos1:e,pos2:n}})(s),c=await(async(t,e,n)=>{const{pos1:o,pos2:i}=n,{x1:s,y1:r,x2:a,y2:c}=await dt(t,e,o,i),{firstPoint:l,firstControl:p,lastControl:d,lastPoint:h}=ht({x1:s,x2:a,y1:r+document.documentElement.scrollTop,y2:c+document.documentElement.scrollTop},{direction:""});return`M ${l.x} ${l.y}C ${p.x} ${p.y}, ${d.x} ${d.y}, ${h.x} ${h.y}`})(this.startElement,this.stopElement,{pos1:r,pos2:a});this.line.setAttribute("data-direction",s),this.line.setAttribute("data-pos1",r),this.line.setAttribute("data-pos2",a),this.line.setAttribute("d",c)}}window.DrawSVGLine=mt;const yt=t=>parseInt(t,10),wt=t=>yt(getComputedStyle(t).getPropertyValue("--ph-speccer-pin-space"))||48,xt=async(t,e,n,o)=>{await H();const{pin:i={},position:s}=o,{useCurlyBrackets:r,subtle:a,bracket:c,text:l,parent:d,enclose:h}=i,u=wt(e),f=yt(getComputedStyle(e).getPropertyValue("--ph-speccer-measure-size"))||8;const g=await V(e,t);if(h){const{left:t,top:e,height:n,width:o}=g.absolute();return{left:`${t}px`,top:`${e}px`,height:`${n}px`,width:`${o}px`}}if((d||l)&&!c&&!r&&!a){if(s===p.Right){const{top:t}=g.fromRight({center:!0});await H();const{left:e,width:o}=n.getBoundingClientRect();return{left:`${e+o+u}px`,top:`${t}px`}}if(s===p.Bottom){const{left:t}=g.toBottom({center:!0});await H();const{top:e,height:o}=n.getBoundingClientRect();return{left:`${t}px`,top:`${e+o+u}px`}}if(s===p.Left){const{top:t}=g.fromLeft({center:!0});await H();const{left:e}=n.getBoundingClientRect();return{left:e-1.5*u-(l?170:0)+"px",top:`${t}px`}}const{left:t}=g.fromTop({center:!0});await H();const{top:e}=n.getBoundingClientRect();return{left:`${t}px`,top:e-1.5*u+"px"}}if(s===p.Left){if(c&&!r){const{left:t,top:e,height:n}=g.fromLeft({sourceWidth:f});return{left:`${t}px`,top:`${e}px`,height:`${n}px`}}const{left:t,top:e}=g.fromLeft({center:!0,modifier:r?u/1.5:u});return{left:`${t}px`,top:`${e}px`}}if(s===p.Right){if(c&&!r){const{left:t,top:e,height:n}=g.fromRight({center:!1});return{left:`${t}px`,top:`${e}px`,height:`${n}px`}}const{left:t,top:e}=g.fromRight({center:!0,modifier:r?u/1.5:u});return{left:`${t}px`,top:`${e}px`}}if(s===p.Bottom){if(c&&!r){const{left:t,top:e,width:n}=g.fromBottom({center:!1});return{left:`${t}px`,top:`${e}px`,width:`${n}px`}}const{left:t,top:e}=g.fromBottom({center:!0,modifier:r?u/1.5:u});return{left:`${t}px`,top:`${e}px`}}if(c&&!r){const{left:t,top:e,width:n}=g.fromTop({center:!1});return{left:`${t}px`,top:`${e}px`,width:`${n}px`}}const{left:m,top:y}=g.fromTop({center:!0,modifier:r?u/1.5:u});return{left:`${m}px`,top:`${y}px`}},bt=async(t,e,n,o)=>{if(!t)return;if("pin"!==o.type||!o.pin)return;const i=`speccer-${o.slug}-${t.getAttribute("id")||R()}`,s=et(n,o,i);t.setAttribute("data-speccer-element-id",i),document.body.appendChild(s);const r=await xt(t,s,e,o);await F(s,r);const a=o.pin.text&&null!==t.getAttribute("data-speccer-title"),c=o.pin.parent&&!o.pin.enclose&&!o.pin.bracket&&!a;return o.pin.useSVGLine?(new mt(t,s,o),c&&new pt(t,5,o)):o.pin.useCurlyBrackets&&new gt(t,s),i};let $t=0;const Et=async(t,n)=>{if(!t)return;const o=t.querySelectorAll('[data-speccer^="pin"]');if(!o||0===o.length)return;const i=t.getAttribute("data-speccer-literals")||window.SPECCER_LITERALS||e;[...o].filter((async t=>!T(t))).forEach((async(e,o)=>{const s=((t,e)=>{let n=e[t];return 0===t&&($t=0),n||(n=`${e[$t]}${e[$t].toLowerCase()}`,$t++),n})(o,i),r=e.getAttribute("data-speccer")||"";await H();const a=getComputedStyle(e),c=B(r,a,n),l=((t,e,n)=>{const{pin:o}=n;if(!o)return t;const{text:i}=o;if(!i||null===e.getAttribute("data-speccer-title"))return t;const s=e.getAttribute("data-speccer-title"),r=e.getAttribute("data-speccer-description"),a=0===e.nodeName.indexOf("H")?`<span class="ph-speccer heading">${e.nodeName}</span>`:"";return!r&&s?`${a}<span class="ph-speccer title">${s}</span>`:r&&s?`${a}<span class="ph-speccer title">${s}</span><span class="ph-speccer description">${r.replaceAll("\\n","<br/>")}</span>`:t})(s,e,c);await bt(e,t,l,c)}))},At=(t="",e="span")=>{const n=document.createElement(e),o=document.createTextNode(`${t}px`);return n.appendChild(o),n.setAttribute("title",`${t}px`),K(n,"ph-speccer speccer spacing"),n},kt=async(t,e)=>{if(!t)return;if(T(t))return;const n=t.getAttribute("data-speccer")||"",o=await _(t),i=B(n,o,e);if("spacing"!==i.type||!i.spacing)return;const s=((t,e)=>{const{marginTop:n,marginBottom:o,marginLeft:i,marginRight:s,paddingTop:r,paddingBottom:a,paddingLeft:c,paddingRight:l}=t;return e?.spacing?.padding?{paddingTop:r,paddingBottom:a,paddingLeft:c,paddingRight:l}:e?.spacing?.margin?{marginTop:n,marginBottom:o,marginLeft:i,marginRight:s}:{marginTop:n,marginBottom:o,marginLeft:i,marginRight:s,paddingTop:r,paddingBottom:a,paddingLeft:c,paddingRight:l}})(o,i),r=Object.keys(s).filter((t=>"0px"!==s[t]));if(!r.length)return;t.classList.add("is-specced");const a=`speccer-spacing-${t.getAttribute("id")||R()}`;t.setAttribute("data-speccer-element-id",a),r.forEach((async e=>{const n=yt(s[e]),o=At(n);o.setAttribute("data-speccer-id",a);const r=(t=>t.includes("Top")?t.replace("Top"," top"):t.includes("Right")?t.replace("Right"," right"):t.includes("Bottom")?t.replace("Bottom"," bottom"):t.includes("Left")?t.replace("Left"," left"):"")(e);K(o,U(r,{bound:!!i?.spacing?.bound})),document.body.appendChild(o);const c=await(async(t,e,n,o)=>{await H();const i=n.getBoundingClientRect(),s=await O(n),r=o?.spacing?.bound?0:96,a=o?.spacing?.bound?0:48;return"marginTop"===t?{height:`${e}px`,width:i.width+r+"px",left:s.left-r+"px",top:s.top-e+"px"}:"marginRight"===t?{height:i.height+a+"px",width:`${e}px`,left:s.left+parseInt(i.width+"",10)+"px",top:s.top+"px"}:"marginBottom"===t?{height:`${e}px`,width:i.width+r+"px",left:s.left-r+"px",top:s.top+parseInt(i.height+"",10)+"px"}:"marginLeft"===t?{height:i.height+a+"px",width:`${e}px`,left:s.left-e+"px",top:s.top+"px"}:"paddingTop"===t?{height:`${e}px`,width:i.width+r+"px",left:s.left-r+"px",top:s.top+"px"}:"paddingBottom"===t?{height:`${e}px`,width:i.width+r+"px",left:s.left-r+"px",top:s.top+(parseInt(i.height+"",10)-e)+"px"}:"paddingRight"===t?{height:i.height+a+"px",width:`${e}px`,left:s.left+(parseInt(i.width+"",10)-e)+"px",top:s.top+"px"}:"paddingLeft"===t?{height:i.height+a+"px",width:`${e}px`,left:s.left+"px",top:s.top+"px"}:void 0})(e,n,t,i);await F(o,c)}))},St=(t,e=3)=>parseFloat(String(t)).toFixed(e),Ct=(t,e,n)=>{const o=document.createElement("div"),{typography:i,position:s}=e,r=U("ph-speccer speccer typography",{syntax:i?.useSyntaxHighlighting||!1,[s]:!0});return o.setAttribute("id",n),o.innerHTML=t,K(o,r),o},Lt=async(t,e)=>{if(!t)return;if(T(t))return;const n=t.getAttribute("data-speccer")||"";await H();const o=B(n,getComputedStyle(t),e);if("typography"!==o.type||!o.typography)return;t.classList.add("is-specced");const i=await(async(t,e=!1)=>{const n=(t=>{const{lineHeight:e,letterSpacing:n,fontFamily:o,fontSize:i,fontStyle:s,fontVariationSettings:r,fontWeight:a}=t;return{lineHeight:e,letterSpacing:n,fontFamily:o,fontSize:i,fontStyle:s,fontVariationSettings:r,fontWeight:a}})(await _(t));if(e){const t=n.fontFamily.split(",").map((t=>t.includes("'")?`<span class="token string">${t}</span>`:t)).join('<span class="token punctuation">, </span>'),e=`<span class="token number">${parseInt(n.fontSize,10)}</span><span class="token unit">px</span> <span class="token operator">/</span> <span class="token number">${parseInt(n.fontSize,10)/16}</span><span class="token unit">rem</span>`,o=n.letterSpacing.includes("px")?`<span class="token number">${parseInt(n.letterSpacing,10)}</span><span class="token unit">px</span>`:n.letterSpacing,i="normal"!==n.lineHeight?`<span class="token number">${parseInt(n.lineHeight,10)}</span><span class="token unit">px</span> <span class="token operator">/</span> <span class="token number">${parseInt(n.lineHeight,10)/16}</span><span class="token unit">rem</span>`:"normal";return`\n<pre class="language-css" tabindex="-1"><code class="language-css"><span class="token selector"><span class="token class">.typography</span></span> <span class="token punctuation">{</span>\n <span class="token property">font-family</span><span class="token punctuation">:</span> ${t}<span class="token punctuation">;</span>\n <span class="token property">font-size</span><span class="token punctuation">:</span> ${e}<span class="token punctuation">;</span>\n <span class="token property">font-weight</span><span class="token punctuation">:</span> <span class="token number">${n.fontWeight}</span><span class="token punctuation">;</span>\n <span class="token property">font-variation-settings</span><span class="token punctuation">:</span> ${n.fontVariationSettings}<span class="token punctuation">;</span>\n <span class="token property">line-height</span><span class="token punctuation">:</span> ${i}<span class="token punctuation">;</span>\n <span class="token property">letter-spacing</span><span class="token punctuation">:</span> ${o}<span class="token punctuation">;</span>\n <span class="token property">font-style</span><span class="token punctuation">:</span> ${n.fontStyle}<span class="token punctuation">;</span>\n<span class="token punctuation">}</span></code></pre>`}return`\ntypography: {<ul class="speccer-styles"> <li><span class="property">font-family:</span> ${n.fontFamily};</li> <li><span class="property">font-size:</span> ${n.fontSize} / ${parseInt(n.fontSize,10)/16}rem;</li> <li><span class="property">font-weight:</span> ${n.fontWeight};</li> <li><span class="property">font-variation-settings:</span> ${n.fontVariationSettings};</li> <li><span class="property">line-height:</span> ${"normal"!==n.lineHeight?`${parseInt(n.lineHeight,10)}px / ${parseInt(n.lineHeight,10)/16}rem`:"normal"};</li> <li><span class="property">letter-spacing:</span> ${n.letterSpacing};</li> <li><span class="property">font-style:</span> ${n.fontStyle};</li></ul>}`})(t,o.typography.useSyntaxHighlighting),s=`speccer-${o.slug}-${t.getAttribute("id")||R()}`;t.setAttribute("data-speccer-element-id",s);const r=Ct(i,o,s);document.body.appendChild(r);const a=await(async(t,e,n)=>{const o=e.getBoundingClientRect(),i=wt(n),s=n.getBoundingClientRect(),r=await O(e),{typography:a,position:c}=t;if(a&&c===h.Right)return{left:r.left+o.width+i+"px",top:St(q(r.top,s,o))+"px"};if(a&&c===h.Top)return{left:St(N(r.left,s,o))+"px",top:r.top-s.height-i+"px"};if(a&&c===h.Bottom)return{left:St(N(r.left,s,o))+"px",top:r.top+o.height+i+"px"};return{left:r.left-s.width-i+"px",top:St(q(r.top,s,o))+"px"}})(o,t,r);F(r,a)},vt=t=>{const e=()=>((t,e,n=!1)=>{let o;return function(i,...s){const r=n&&!o;o&&clearTimeout(o),o=setTimeout((function(){o=null,n||t.apply(i,s)}),e),r&&t.apply(i,s)}})((()=>{t()}),300);window.removeEventListener("resize",e),window.addEventListener("resize",e)},Pt=t=>{"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(()=>{t()})):t()},Bt=()=>{const t=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(kt(n.target),e.unobserve(n.target))}));for(const e of document.querySelectorAll(`[${n}^="${o}"],[${n}^="${o}"] *:not(td):not(tr):not(th):not(tfoot):not(thead):not(tbody)`))t.observe(e);const e=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(tt(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll(`[${n}^="${i}"]`))e.observe(t);const l=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(J(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll(`[${n}^="${r}"]`))l.observe(t);const p=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(Lt(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll(`[${n}^="${s}"]`))p.observe(t);const d=new IntersectionObserver(((t,e)=>{for(const n of t)n.intersectionRatio>0&&(Y(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll(`[${n}^="${a}"]`))d.observe(t);const h=new IntersectionObserver((async(t,e)=>{for(const n of t)n.intersectionRatio>0&&(await Et(n.target),e.unobserve(n.target))}));for(const t of document.querySelectorAll(`[${n}="${c}"]`))h.observe(t)},Rt=t=>{window.speccer=t},Tt=t=>{const e=document.currentScript;if(e){const n=e.getAttribute("src");n?.includes("speccer.js")&&(e.hasAttribute("data-manual")?Rt(t):e.hasAttribute("data-instant")?t():e.hasAttribute("data-dom")?Pt(t):e.hasAttribute("data-lazy")?Bt():Pt(t),e.hasAttribute("data-manual")||e.hasAttribute("data-lazy")||vt(t))}},Ht=["alt","altgraph","capslock","control","fn","fnlock","hyper","meta","numlock","os","scrolllock","shift","super","symbol","command","ctrl","altgr","symbollock"],It=["escape","esc","enter","return","⏎","␛"],Mt=async(t,e,n)=>{await H();const o=wt(n),i=await V(n,e);if("tabstops"===t){let{left:t,top:e}=i.fromTop();return t-=32,e+=32,t<=0&&(t=32),e<=0&&(e=32),{left:`${t}px`,top:`${e}px`}}if("landmark"===t){let{left:t,top:e}=i.fromTop();return t-=16,e-=16,t<=0&&(t=32),e<=0&&(e=32),{left:`${t}px`,top:`${e}px`}}if("region"===t){const{left:t,top:e,height:n,width:o}=i.fromTop();return{height:`${n}px`,width:`${o}px`,left:`${t}px`,top:`${e}px`}}if("shortcut"===t){const{left:t,top:e}=i.fromBottom();return{left:`${t}px`,top:`${e}px`}}const{left:s,top:r}=i.fromTop({center:!0,modifier:o});return{left:s-32+"px",top:r-32+"px"}},Nt=async(t,e,n)=>{if(!t||!t.checkVisibility())return;const o=((t="tabstops",e,n="span")=>{const o=document.createElement(n),i=U("ph-speccer speccer a11y",{tabstops:"tabstops"===t,landmark:"landmark"===t,region:"region"===t});if("landmark"===t&&e){const t=document.createTextNode(String(e));o.appendChild(t)}return K(o,i),o})(n,e);if("landmark"===n){o.setAttribute("data-speccer-nodename",t.nodeName);const e=t.role||`semantic role: ${t.nodeName.toLowerCase()}`,n=t.getAttribute("aria-label")||"unnamed";o.setAttribute("title",`${n}: ${e}`)}document.body.appendChild(o);const i=await Mt(n,t,o);await F(o,i)},qt=async(t,e)=>{const n=e.split(/\s\+\s/).map((t=>t.trim())),o=document.createElement("div");o.classList.add("ph-speccer"),o.classList.add("speccer"),o.classList.add("a11y"),o.classList.add("shortcut-holder");for(const t of n){const e=document.createElement("kbd"),n=document.createTextNode(t);e.classList.add("ph-speccer"),e.classList.add("speccer"),e.classList.add("a11y"),e.classList.add("shortcut"),Ht.includes(t.toLowerCase())&&e.classList.add("modifier"),It.includes(t.toLowerCase())&&e.classList.add("physical"),e.appendChild(n),o.appendChild(e)}document.body.appendChild(o);const i=await Mt("shortcut",t,o);await F(o,i)},Ot={create:X,element:Y},Vt={create:At,element:kt},zt={createPinElement:et,pinElement:bt,pinElements:Et},Gt={create:Q,element:tt},jt={create:Z,element:J},Wt={create:Ct,element:Lt},Dt={dom:Pt,lazy:Bt,manual:Rt,activate:Tt},Ft=()=>{((t,e=document)=>{[].forEach.call(e.querySelectorAll(t),(function(t){t.remove()}))})(".ph-speccer.speccer");const t=document.querySelectorAll(`[${n}^="${o}"],[${n}^="${o}"] *:not(td):not(tr):not(th):not(tfoot):not(thead):not(tbody)`),e=document.querySelectorAll(`[${n}^="${i}"]`),l=document.querySelectorAll(`[${n}^="${s}"]`),p=document.querySelectorAll(`[${n}="${c}"]`),d=document.querySelectorAll(`[${n}^="${r}"]`),h=document.querySelectorAll(`[${n}^="${a}"]`);for(const t of d)J(t);for(const t of h)Y(t);for(const e of t)kt(e);for(const t of e)tt(t);for(const t of l)Lt(t);for(const t of p)Et(t);(()=>{const t=document.querySelectorAll('[data-speccer*="a11y tabstops"]'),e=document.querySelectorAll('[data-speccer*="a11y landmark"]'),n=document.querySelectorAll('[data-speccer*="a11y shortcut"]');if(n.length)for(const t of n){const e=t.getAttribute("data-speccer-a11y-shortcut");e&&""!==e&&!T(t)&&qt(t,e)}if(t.length)for(const e of t){const t=e.querySelectorAll("\n a[href], area[href], input:not([disabled]):not([tabindex='-1']),\n button:not([disabled]):not([tabindex='-1']),select:not([disabled]):not([tabindex='-1']),\n textarea:not([disabled]):not([tabindex='-1']),\n iframe, object, embed, *[tabindex]:not([tabindex='-1']), *[contenteditable=true]\n");for(const e of t)T(e)||Nt(e,null,"tabstops")}if(e.length)for(const t of e){const e=t.querySelectorAll('\nheader, footer, section, form, main, nav, aside, [role="section"], [role="banner"],\n[role="complementary"], [role="contentinfo"], [role="form"], [role="main"],\n[role="navigation"], [role="region"], [role="search"]\n');for(const[t,n]of e.entries())T(n)||(Nt(n,t+1,"landmark"),Nt(n,null,"region"))}})()};Tt(Ft),t.default=Ft,t.grid=Ot,t.mark=jt,t.measure=Gt,t.modes=Dt,t.pin=zt,t.removeSpeccerElement=t=>{const e=t.getAttribute("data-speccer-element-id");if(!e)return;const n=document.getElementById(e)||document.querySelectorAll(`[data-speccer-id="${e}"]`);if(n)if(Object.prototype.isPrototypeOf.call(NodeList.prototype,n))[...n].forEach((t=>{t.remove(),t.classList.remove("is-specced")}));else if(n.classList.contains("curly")||n.classList.contains("svg")){const e=t.getAttribute("id");document.querySelectorAll(`#ph-speccer-svg path[data-start-el="${e}"]`).forEach((t=>t.remove()))}},t.spacing=Vt,t.typography=Wt,Object.defineProperty(t,"__esModule",{value:!0})}));
28
28
  //# sourceMappingURL=speccer.js.map