@liquid-js/qr-code-styling 5.5.0 → 5.5.1-1

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.
@@ -1,2 +1,2 @@
1
- import{extendSVG as t,numToAttr as e,svgPath as i}from"./plugin-utils.js";import{c as o}from"./color-dXYWdVDW.js";var s,r=s||={};r.top="top",r.bottom="bottom",r.left="left",r.right="right";export default class{pluginOptions;idSuffix;constructor(t,e=Math.random().toFixed(10).substring(2)){this.pluginOptions=t,this.idSuffix=e}postProcess(r,n,a){var{document:p}=n,$=this.pluginOptions.proportional?n.size:1,h=this.pluginOptions.size*$,l=t(r,h+(this.pluginOptions.margin||0)*$);if(l){h=Math.abs(h);var d=(l.left+l.right)/2,u=(l.top+l.bottom)/2,g=n.size/2*(1-(this.pluginOptions.round||0)),f=Math.min(l.right-l.left-2*h,l.bottom-l.top-2*h)/2-g+h/2,w=this.pluginOptions.round?f:0,c=this.pluginOptions.round?g:g+f;(l=p.createElementNS("http://www.w3.org/2000/svg","rect")).setAttribute("width",e(2*(c+w))),l.setAttribute("height",e(2*(c+w))),l.setAttribute("x",e(d-c-w)),l.setAttribute("y",e(u-c-w)),l.setAttribute("rx",e(w)),l.setAttribute("fill","none"),l.setAttribute("stroke-width",e(h)),this.pluginOptions.dasharray&&l.setAttribute("stroke-dasharray",this.pluginOptions.dasharray),(n=o({options:this.pluginOptions.gradient,color:this.pluginOptions.color,additionalRotation:0,x:d-c-w,y:u-c-w,height:2*w,width:2*w,name:`border-color-${this.idSuffix}`,dotSize:n.dotsOptions.size,document:n.document}))?(n.gradient&&((a=Array.from(r.childNodes).find(t=>"DEFS"==t.tagName.toUpperCase()))||(a=p.createElementNS("http://www.w3.org/2000/svg","defs"),r.appendChild(a)),a.appendChild(n.gradient)),l.setAttribute("stroke",n.value),n.opacity<1&&l.setAttribute("stroke-opacity",n.opacity.toFixed(7))):a.dots&&(l.setAttribute("stroke",a.dots.value),a.dots.opacity<1&&l.setAttribute("stroke-opacity",a.dots.opacity.toFixed(7))),r.appendChild(l),[s.left,s.top,s.right,s.bottom].forEach(t=>{var o=this.pluginOptions.text,n=o?.[t];if(n){let a=Array.from(r.childNodes).find(t=>"DEFS"==t.tagName.toUpperCase());a||(a=p.createElementNS("http://www.w3.org/2000/svg","defs"),r.appendChild(a));let h=p.createElementNS("http://www.w3.org/2000/svg","path"),l=(n.size||o.size||1)*$;switch(w=this.pluginOptions.round?f-l/3:0,c=this.pluginOptions.round?g:g+(f-l/3),t){case s.top:h.setAttribute("d",i`M ${d} ${u+w+c} h ${-c} a ${w} ${w} 0 0 1 ${-w} ${-w} v ${-2*c} a ${w} ${w} 0 0 1 ${w} ${-w} h ${2*c} a ${w} ${w} 0 0 1 ${w} ${w} v ${2*c} a ${w} ${w} 0 0 1 ${-w} ${w} h ${-c}`);break;case s.bottom:this.pluginOptions.round?w+=2*l/3:c+=2*l/3,h.setAttribute("d",i`M ${d} ${u-w-c} h ${-c} a ${w} ${w} 0 0 0 ${-w} ${w} v ${2*c} a ${w} ${w} 0 0 0 ${w} ${w} h ${2*c} a ${w} ${w} 0 0 0 ${w} ${-w} v ${-2*c} a ${w} ${w} 0 0 0 ${-w} ${-w} h ${-c}`);break;case s.left:h.setAttribute("d",i`M ${d+w+c} ${u} v ${c} a ${w} ${w} 0 0 1 ${-w} ${w} h ${-2*c} a ${w} ${w} 0 0 1 ${-w} ${-w} v ${-2*c} a ${w} ${w} 0 0 1 ${w} ${-w} h ${2*c} a ${w} ${w} 0 0 1 ${w} ${w} v ${c}`);break;case s.right:h.setAttribute("d",i`M ${d-w-c} ${u} v ${-c} a ${w} ${w} 0 0 1 ${w} ${-w} h ${2*c} a ${w} ${w} 0 0 1 ${w} ${w} v ${2*c} a ${w} ${w} 0 0 1 ${-w} ${w} h ${-2*c} a ${w} ${w} 0 0 1 ${-w} ${-w} v ${-c}`)}t=`border-text-${t}-${this.idSuffix}`,h.setAttribute("id",t),h.setAttribute("fill","none");let b=p.createElementNS("http://www.w3.org/2000/svg","tspan");b.setAttribute("font-family",n.font||o.font||"sans-serif"),b.setAttribute("fill",n.color||o.color||"#000"),b.setAttribute("font-weight",e(n.fontWeight||o.fontWeight||"normal")),b.setAttribute("font-style",n.fontStyle||o.fontStyle||"normal"),b.setAttribute("font-size",e(l)),b.textContent=n.content,(o=p.createElementNS("http://www.w3.org/2000/svg","textPath")).setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","#"+t),o.setAttribute("startOffset","50%"),o.setAttribute("text-anchor","middle"),o.appendChild(b),(n=p.createElementNS("http://www.w3.org/2000/svg","text")).appendChild(o),a.appendChild(h),r.appendChild(n)}}),this.pluginOptions.fontFaces&&((a=Array.from(r.childNodes).find(t=>"DEFS"==t.tagName.toUpperCase()))||(a=p.createElementNS("http://www.w3.org/2000/svg","defs"),r.appendChild(a)),(l=p.createElementNS("http://www.w3.org/2000/svg","style")).textContent=this.pluginOptions.fontFaces,a.appendChild(l))}}}
1
+ import{extendSVG as t,numToAttr as e,svgPath as i}from"./plugin-utils.js";import{c as s}from"./color-dXYWdVDW.js";var o,r=o||={};r.top="top",r.bottom="bottom",r.left="left",r.right="right";export default class{pluginOptions;idSuffix;constructor(t,e=Math.random().toFixed(10).substring(2)){this.pluginOptions=t,this.idSuffix=e}postProcess(r,n,a){var{document:p}=n,$=this.pluginOptions.proportional?n.size:1,h=this.pluginOptions.size*$,l=t(r,h+(this.pluginOptions.margin||0)*$);if(l){h=Math.abs(h);var d=(l.left+l.right)/2,u=(l.top+l.bottom)/2,g=n.size/2*(1-(this.pluginOptions.round||0)),f=Math.min(l.right-l.left-2*h,l.bottom-l.top-2*h)/2-g+h/2,w=this.pluginOptions.round?f:0,c=this.pluginOptions.round?g:g+f;(l=p.createElementNS("http://www.w3.org/2000/svg","rect")).setAttribute("width",e(2*(c+w))),l.setAttribute("height",e(2*(c+w))),l.setAttribute("x",e(d-c-w)),l.setAttribute("y",e(u-c-w)),l.setAttribute("rx",e(w)),l.setAttribute("fill","none");var m=t=>t.endsWith("%")?(parseFloat(t.substring(0,t.length-1))||0)*b/100:t,b=2*Math.PI*w+8*c,A=this.pluginOptions.dasharray?.split(/[,\s]+/g).map(t=>t.trim()).filter(t=>!!t).map(m);l.setAttribute("stroke-width",e(h)),A?.length&&(l.setAttribute("stroke-dasharray",A.map(e).join(" ")),"string"==typeof(h=this.pluginOptions.dasharrayOffset?.trim()?m(this.pluginOptions.dasharrayOffset?.trim()):0)&&(h=parseFloat(h)),(h-=c)&&l.setAttribute("stroke-dashoffset",e(h))),(n=s({options:this.pluginOptions.gradient,color:this.pluginOptions.color,additionalRotation:0,x:d-c-w,y:u-c-w,height:2*w,width:2*w,name:`border-color-${this.idSuffix}`,dotSize:n.dotsOptions.size,document:n.document}))?(n.gradient&&((a=Array.from(r.childNodes).find(t=>"DEFS"==t.tagName.toUpperCase()))||(a=p.createElementNS("http://www.w3.org/2000/svg","defs"),r.appendChild(a)),a.appendChild(n.gradient)),l.setAttribute("stroke",n.value),n.opacity<1&&l.setAttribute("stroke-opacity",n.opacity.toFixed(7))):a.dots&&(l.setAttribute("stroke",a.dots.value),a.dots.opacity<1&&l.setAttribute("stroke-opacity",a.dots.opacity.toFixed(7))),r.appendChild(l),[o.left,o.top,o.right,o.bottom].forEach(t=>{var s=this.pluginOptions.text,n=s?.[t];if(n){let a=Array.from(r.childNodes).find(t=>"DEFS"==t.tagName.toUpperCase());a||(a=p.createElementNS("http://www.w3.org/2000/svg","defs"),r.appendChild(a));let h=p.createElementNS("http://www.w3.org/2000/svg","path"),l=(n.size||s.size||1)*$;switch(w=this.pluginOptions.round?f-l/3:0,c=this.pluginOptions.round?g:g+(f-l/3),t){case o.top:h.setAttribute("d",i`M ${d} ${u+w+c} h ${-c} a ${w} ${w} 0 0 1 ${-w} ${-w} v ${-2*c} a ${w} ${w} 0 0 1 ${w} ${-w} h ${2*c} a ${w} ${w} 0 0 1 ${w} ${w} v ${2*c} a ${w} ${w} 0 0 1 ${-w} ${w} h ${-c}`);break;case o.bottom:this.pluginOptions.round?w+=2*l/3:c+=2*l/3,h.setAttribute("d",i`M ${d} ${u-w-c} h ${-c} a ${w} ${w} 0 0 0 ${-w} ${w} v ${2*c} a ${w} ${w} 0 0 0 ${w} ${w} h ${2*c} a ${w} ${w} 0 0 0 ${w} ${-w} v ${-2*c} a ${w} ${w} 0 0 0 ${-w} ${-w} h ${-c}`);break;case o.left:h.setAttribute("d",i`M ${d+w+c} ${u} v ${c} a ${w} ${w} 0 0 1 ${-w} ${w} h ${-2*c} a ${w} ${w} 0 0 1 ${-w} ${-w} v ${-2*c} a ${w} ${w} 0 0 1 ${w} ${-w} h ${2*c} a ${w} ${w} 0 0 1 ${w} ${w} v ${c}`);break;case o.right:h.setAttribute("d",i`M ${d-w-c} ${u} v ${-c} a ${w} ${w} 0 0 1 ${w} ${-w} h ${2*c} a ${w} ${w} 0 0 1 ${w} ${w} v ${2*c} a ${w} ${w} 0 0 1 ${-w} ${w} h ${-2*c} a ${w} ${w} 0 0 1 ${-w} ${-w} v ${-c}`)}t=`border-text-${t}-${this.idSuffix}`,h.setAttribute("id",t),h.setAttribute("fill","none");let m=p.createElementNS("http://www.w3.org/2000/svg","tspan");m.setAttribute("font-family",n.font||s.font||"sans-serif"),m.setAttribute("fill",n.color||s.color||"#000"),m.setAttribute("font-weight",e(n.fontWeight||s.fontWeight||"normal")),m.setAttribute("font-style",n.fontStyle||s.fontStyle||"normal"),m.setAttribute("font-size",e(l)),m.textContent=n.content,(s=p.createElementNS("http://www.w3.org/2000/svg","textPath")).setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","#"+t),s.setAttribute("startOffset","50%"),s.setAttribute("text-anchor","middle"),s.appendChild(m),(n=p.createElementNS("http://www.w3.org/2000/svg","text")).appendChild(s),a.appendChild(h),r.appendChild(n)}}),this.pluginOptions.fontFaces&&((a=Array.from(r.childNodes).find(t=>"DEFS"==t.tagName.toUpperCase()))||(a=p.createElementNS("http://www.w3.org/2000/svg","defs"),r.appendChild(a)),(l=p.createElementNS("http://www.w3.org/2000/svg","style")).textContent=this.pluginOptions.fontFaces,a.appendChild(l))}}}
2
2
  //# sourceMappingURL=border-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"border-plugin.js","sources":["../src/plugins/border.ts"],"sourcesContent":["import { ColorElementValue, createColor } from '../utils/color.js'\r\nimport { Gradient } from '../utils/gradient.js'\r\nimport { Options, Plugin } from '../utils/options.js'\r\nimport { extendSVG, numToAttr, svgPath } from './utils.js'\r\n\r\nenum TextPosition {\r\n top = 'top',\r\n bottom = 'bottom',\r\n left = 'left',\r\n right = 'right'\r\n}\r\n\r\nexport interface TextConfig {\r\n font?: string\r\n color?: string\r\n size?: number\r\n fontWeight?: 'normal' | 'bold' | number\r\n fontStyle?: 'normal' | 'italic' | 'oblique'\r\n}\r\n\r\nexport interface BorderPluginOptions {\r\n /** Border roundnes, from 0 (square) to 1 (circle) */\r\n round?: number\r\n size: number\r\n color?: string\r\n gradient?: Gradient\r\n dasharray?: string\r\n margin?: number\r\n /**\r\n * If true, all dimensions are proportional to the code size,\r\n * i.e. `size: 0.1` means the border thickness is 1/10 of the QR code size\r\n *\r\n * This is useful to keep the border visually consistent regardless of the amount of data\r\n *\r\n * Note: if using dasharray, use percentage values to maintain consistency\r\n */\r\n proportional?: boolean\r\n text?: TextConfig & {\r\n [key in TextPosition]?: TextConfig & {\r\n content: string\r\n }\r\n }\r\n /**\r\n * A string of embedded CSS \\@font-face rules\r\n *\r\n * @deprecated Use @liquid-js/qr-code-styling/font-faces-plugin\r\n */\r\n fontFaces?: string\r\n}\r\n\r\nexport default class BorderPlugin implements Plugin {\r\n\r\n constructor(\r\n private readonly pluginOptions: BorderPluginOptions,\r\n /** @ignore Create unique id for SVG elements to prevent naming collisions; specify your own if neccesary e.g. for testing */\r\n private readonly idSuffix = Math.random().toFixed(10).substring(2)\r\n ) { }\r\n\r\n postProcess(svg: SVGSVGElement, options: Options, colors: {\r\n dots?: ColorElementValue\r\n background?: ColorElementValue\r\n }) {\r\n const { document } = options\r\n const sizeFactor = this.pluginOptions.proportional ? options.size : 1\r\n\r\n const margin = (this.pluginOptions.margin || 0) * sizeFactor\r\n let thickness = (this.pluginOptions.size) * sizeFactor\r\n const drawArea = extendSVG(svg, thickness + margin)\r\n if (!drawArea)\r\n return\r\n\r\n thickness = Math.abs(thickness)\r\n\r\n const cx = (drawArea.left + drawArea.right) / 2\r\n const cy = (drawArea.top + drawArea.bottom) / 2\r\n const lineSize = options.size / 2 * (1 - (this.pluginOptions.round || 0))\r\n const r = (Math.min(drawArea.right - drawArea.left - 2 * thickness, drawArea.bottom - drawArea.top - 2 * thickness) / 2) - lineSize + thickness / 2\r\n\r\n let pathR = this.pluginOptions.round ? r : 0\r\n let pathL = this.pluginOptions.round ? lineSize : lineSize + r\r\n\r\n const borderEl = document.createElementNS('http://www.w3.org/2000/svg', 'rect')\r\n borderEl.setAttribute('width', numToAttr((pathL + pathR) * 2))\r\n borderEl.setAttribute('height', numToAttr((pathL + pathR) * 2))\r\n borderEl.setAttribute('x', numToAttr(cx - pathL - pathR))\r\n borderEl.setAttribute('y', numToAttr(cy - pathL - pathR))\r\n borderEl.setAttribute('rx', numToAttr(pathR))\r\n borderEl.setAttribute('fill', 'none')\r\n borderEl.setAttribute('stroke-width', numToAttr(thickness))\r\n if (this.pluginOptions.dasharray) {\r\n borderEl.setAttribute('stroke-dasharray', this.pluginOptions.dasharray)\r\n }\r\n\r\n const value = createColor({\r\n options: this.pluginOptions.gradient,\r\n color: this.pluginOptions.color,\r\n additionalRotation: 0,\r\n x: cx - pathL - pathR,\r\n y: cy - pathL - pathR,\r\n height: 2 * pathR,\r\n width: 2 * pathR,\r\n name: `border-color-${this.idSuffix}`,\r\n dotSize: options.dotsOptions.size,\r\n document: options.document\r\n })\r\n\r\n if (value) {\r\n if (value.gradient) {\r\n let defs = Array.from(svg.childNodes).find(v => (v as HTMLElement).tagName.toUpperCase() == 'DEFS')\r\n if (!defs) {\r\n defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')\r\n svg.appendChild(defs)\r\n }\r\n defs.appendChild(value.gradient)\r\n }\r\n borderEl.setAttribute('stroke', value.value)\r\n\r\n if (value.opacity < 1) borderEl.setAttribute('stroke-opacity', value.opacity.toFixed(7))\r\n } else if (colors.dots) {\r\n borderEl.setAttribute('stroke', colors.dots.value)\r\n\r\n if (colors.dots.opacity < 1) borderEl.setAttribute('stroke-opacity', colors.dots.opacity.toFixed(7))\r\n }\r\n\r\n svg.appendChild(borderEl);\r\n\r\n [TextPosition.left, TextPosition.top, TextPosition.right, TextPosition.bottom].forEach(postion => {\r\n const textCfg = this.pluginOptions.text\r\n const config = textCfg?.[postion]\r\n if (config) {\r\n let defs = Array.from(svg.childNodes).find(v => (v as HTMLElement).tagName.toUpperCase() == 'DEFS')\r\n if (!defs) {\r\n defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')\r\n svg.appendChild(defs)\r\n }\r\n const element = document.createElementNS('http://www.w3.org/2000/svg', 'path')\r\n const size = (config.size || textCfg.size || 1) * sizeFactor\r\n pathR = this.pluginOptions.round ? r - size / 3 : 0\r\n pathL = this.pluginOptions.round ? lineSize : lineSize + (r - size / 3)\r\n switch (postion) {\r\n case TextPosition.top:\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx} ${cy + pathR + pathL}\r\n h ${-pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${-pathR}\r\n v ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${-pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${pathR}\r\n v ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${pathR}\r\n h ${-pathL}`\r\n )\r\n break\r\n case TextPosition.bottom:\r\n if (this.pluginOptions.round)\r\n pathR += size * 2 / 3\r\n else\r\n pathL += size * 2 / 3\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx} ${cy - pathR - pathL}\r\n h ${-pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${-pathR} ${pathR}\r\n v ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${pathR} ${pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${pathR} ${-pathR}\r\n v ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${-pathR} ${-pathR}\r\n h ${-pathL}`\r\n )\r\n break\r\n case TextPosition.left:\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx + pathR + pathL} ${cy}\r\n v ${pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${pathR}\r\n h ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${-pathR}\r\n v ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${-pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${pathR}\r\n v ${pathL}`\r\n )\r\n break\r\n case TextPosition.right:\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx - pathR - pathL} ${cy}\r\n v ${-pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${-pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${pathR}\r\n v ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${pathR}\r\n h ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${-pathR}\r\n v ${-pathL}`\r\n )\r\n break\r\n }\r\n const id = `border-text-${postion}-${this.idSuffix}`\r\n element.setAttribute('id', id)\r\n element.setAttribute('fill', 'none')\r\n\r\n const span = document.createElementNS('http://www.w3.org/2000/svg', 'tspan')\r\n span.setAttribute('font-family', config.font || textCfg.font || 'sans-serif')\r\n span.setAttribute('fill', config.color || textCfg.color || '#000')\r\n span.setAttribute('font-weight', numToAttr(config.fontWeight || textCfg.fontWeight || 'normal'))\r\n span.setAttribute('font-style', config.fontStyle || textCfg.fontStyle || 'normal')\r\n span.setAttribute('font-size', numToAttr(size))\r\n span.textContent = config.content\r\n\r\n const textPath = document.createElementNS('http://www.w3.org/2000/svg', 'textPath')\r\n textPath.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#' + id)\r\n textPath.setAttribute('startOffset', '50%')\r\n textPath.setAttribute('text-anchor', 'middle')\r\n textPath.appendChild(span)\r\n\r\n const text = document.createElementNS('http://www.w3.org/2000/svg', 'text')\r\n text.appendChild(textPath)\r\n\r\n defs.appendChild(element)\r\n svg.appendChild(text)\r\n }\r\n })\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n if (this.pluginOptions.fontFaces) {\r\n let defs = Array.from(svg.childNodes).find(v => (v as HTMLElement).tagName.toUpperCase() == 'DEFS')\r\n if (!defs) {\r\n defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')\r\n svg.appendChild(defs)\r\n }\r\n const style = document.createElementNS('http://www.w3.org/2000/svg', 'style')\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n style.textContent = this.pluginOptions.fontFaces\r\n defs.appendChild(style)\r\n }\r\n }\r\n}\r\n"],"names":["extendSVG","numToAttr","TextPosition","createColor","l","w","top","bottom","left","right","pluginOptions","idSuffix","constructor","Math","random","toFixed","substring","this","postProcess","svg","options","colors","document","sizeFactor","proportional","size","thickness","drawArea","margin","abs","cx","cy","round","min","lineSize","pathR","r","pathL","createElementNS","setAttribute","borderEl","dasharray","value","gradient","color","additionalRotation","x","y","height","width","name","dotSize","dotsOptions","defs","Array","from","childNodes","find","v","tagName","toUpperCase","appendChild","opacity","dots","forEach","postion","text","textCfg","config","element","svgPath","id","span","font","fontWeight","fontStyle","textContent","content","textPath","setAttributeNS","fontFaces","style"],"mappings":"oBAKKA,eACDC,aACAC,MAAA,gCAEAC,MAyCU,sBAAA,IAAAC,EAAAC,EAAAD,IAAA,CAAA,EAAAC,EAAAC,IAAA,MAAAD,EA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AAQ,cAChED,EAAKjC,aAAa,OAAQ6B,EAAOxB,OAASuB,EAAQvB,OAAS,QAC3D4B,EAAKjC,aAAa,cAAetC,EAAUmE,EAAOM,YAAcP,EAAQO,YAAc,WACtFF,EAAKjC,aAAa,aAAc6B,EAAOO,WAAaR,EAAQQ,WAAa,YACpEpC,aAAa,YAAatC,EAAUwB,IACzC+C,EAAKI,YAAcR,EAAOS,SAE1BC,EAAcxD,EAAGgB,6CAAqD,aAC7DyC,eAAe,+BAAgC,aAAc,IAAMR,GAC5EO,EAASvC,aAAa,cAAe,OACrCuC,EAASvC,aAAa,cAAe,UACrCuC,EAASjB,YAAYW,MAEXlD,EAAGgB,6CAAqD,SAC7DuB,YAAYiB,GAEjBzB,EAAKQ,YAAYQ,GACjBlD,EAAI0C,YAAYK,EAlGR,IAuGZjD,KAAKP,cAAcsE,aACf3B,EAAOC,MAAMC,KAAKpC,EAAIqC,YAAYC,KAAKC,GAAiD,QAA3CA,EAAkBC,QAAQC,kBAEvEP,EAAO/B,EAASgB,gBAAgB,6BAA8B,QAC9DnB,EAAI0C,YAAYR,KAEpB4B,EAAW3D,EAAGgB,6CAAqD,UAE7DsC,YAAc3D,KAAKP,cAAcsE,UACvC3B,EAAKQ,YAAYoB,GA7KrB,CAPH"}
1
+ {"version":3,"file":"border-plugin.js","sources":["../src/plugins/border.ts"],"sourcesContent":["import { ColorElementValue, createColor } from '../utils/color.js'\r\nimport { Gradient } from '../utils/gradient.js'\r\nimport { Options, Plugin } from '../utils/options.js'\r\nimport { extendSVG, numToAttr, svgPath } from './utils.js'\r\n\r\nenum TextPosition {\r\n top = 'top',\r\n bottom = 'bottom',\r\n left = 'left',\r\n right = 'right'\r\n}\r\n\r\nexport interface TextConfig {\r\n font?: string\r\n color?: string\r\n size?: number\r\n fontWeight?: 'normal' | 'bold' | number\r\n fontStyle?: 'normal' | 'italic' | 'oblique'\r\n}\r\n\r\nexport interface BorderPluginOptions {\r\n /** Border roundnes, from 0 (square) to 1 (circle) */\r\n round?: number\r\n size: number\r\n color?: string\r\n gradient?: Gradient\r\n dasharray?: string\r\n dasharrayOffset?: string\r\n margin?: number\r\n /**\r\n * If true, all dimensions are proportional to the code size,\r\n * i.e. `size: 0.1` means the border thickness is 1/10 of the QR code size\r\n *\r\n * This is useful to keep the border visually consistent regardless of the amount of data\r\n *\r\n * Note: if using dasharray, use percentage values to maintain consistency\r\n */\r\n proportional?: boolean\r\n text?: TextConfig & {\r\n [key in TextPosition]?: TextConfig & {\r\n content: string\r\n }\r\n }\r\n /**\r\n * A string of embedded CSS \\@font-face rules\r\n *\r\n * @deprecated Use @liquid-js/qr-code-styling/font-faces-plugin\r\n */\r\n fontFaces?: string\r\n}\r\n\r\nexport default class BorderPlugin implements Plugin {\r\n\r\n constructor(\r\n private readonly pluginOptions: BorderPluginOptions,\r\n /** @ignore Create unique id for SVG elements to prevent naming collisions; specify your own if neccesary e.g. for testing */\r\n private readonly idSuffix = Math.random().toFixed(10).substring(2)\r\n ) { }\r\n\r\n postProcess(svg: SVGSVGElement, options: Options, colors: {\r\n dots?: ColorElementValue\r\n background?: ColorElementValue\r\n }) {\r\n const { document } = options\r\n const sizeFactor = this.pluginOptions.proportional ? options.size : 1\r\n\r\n const margin = (this.pluginOptions.margin || 0) * sizeFactor\r\n let thickness = (this.pluginOptions.size) * sizeFactor\r\n const drawArea = extendSVG(svg, thickness + margin)\r\n if (!drawArea)\r\n return\r\n\r\n thickness = Math.abs(thickness)\r\n\r\n const cx = (drawArea.left + drawArea.right) / 2\r\n const cy = (drawArea.top + drawArea.bottom) / 2\r\n const lineSize = options.size / 2 * (1 - (this.pluginOptions.round || 0))\r\n const r = (Math.min(drawArea.right - drawArea.left - 2 * thickness, drawArea.bottom - drawArea.top - 2 * thickness) / 2) - lineSize + thickness / 2\r\n\r\n let pathR = this.pluginOptions.round ? r : 0\r\n let pathL = this.pluginOptions.round ? lineSize : lineSize + r\r\n\r\n const borderEl = document.createElementNS('http://www.w3.org/2000/svg', 'rect')\r\n borderEl.setAttribute('width', numToAttr((pathL + pathR) * 2))\r\n borderEl.setAttribute('height', numToAttr((pathL + pathR) * 2))\r\n borderEl.setAttribute('x', numToAttr(cx - pathL - pathR))\r\n borderEl.setAttribute('y', numToAttr(cy - pathL - pathR))\r\n borderEl.setAttribute('rx', numToAttr(pathR))\r\n borderEl.setAttribute('fill', 'none')\r\n\r\n const percenToLength = (dim: string) => {\r\n if (dim.endsWith('%')) {\r\n const val = (parseFloat(dim.substring(0, dim.length - 1)) || 0) * strokeLen / 100\r\n return val\r\n }\r\n return dim\r\n }\r\n\r\n const strokeLen = 2 * Math.PI * pathR + 8 * pathL\r\n const dashArray = this.pluginOptions.dasharray?.split(/[,\\s]+/g).map(v => v.trim()).filter(v => !!v).map(percenToLength)\r\n\r\n borderEl.setAttribute('stroke-width', numToAttr(thickness))\r\n if (dashArray?.length) {\r\n borderEl.setAttribute('stroke-dasharray', dashArray.map(numToAttr).join(' '))\r\n let dashOffset = (this.pluginOptions.dasharrayOffset?.trim() ? percenToLength(this.pluginOptions.dasharrayOffset?.trim()) : 0)\r\n if (typeof dashOffset == 'string')\r\n dashOffset = parseFloat(dashOffset)\r\n dashOffset -= pathL\r\n if (dashOffset)\r\n borderEl.setAttribute('stroke-dashoffset', numToAttr(dashOffset))\r\n }\r\n\r\n const value = createColor({\r\n options: this.pluginOptions.gradient,\r\n color: this.pluginOptions.color,\r\n additionalRotation: 0,\r\n x: cx - pathL - pathR,\r\n y: cy - pathL - pathR,\r\n height: 2 * pathR,\r\n width: 2 * pathR,\r\n name: `border-color-${this.idSuffix}`,\r\n dotSize: options.dotsOptions.size,\r\n document: options.document\r\n })\r\n\r\n if (value) {\r\n if (value.gradient) {\r\n let defs = Array.from(svg.childNodes).find(v => (v as HTMLElement).tagName.toUpperCase() == 'DEFS')\r\n if (!defs) {\r\n defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')\r\n svg.appendChild(defs)\r\n }\r\n defs.appendChild(value.gradient)\r\n }\r\n borderEl.setAttribute('stroke', value.value)\r\n\r\n if (value.opacity < 1) borderEl.setAttribute('stroke-opacity', value.opacity.toFixed(7))\r\n } else if (colors.dots) {\r\n borderEl.setAttribute('stroke', colors.dots.value)\r\n\r\n if (colors.dots.opacity < 1) borderEl.setAttribute('stroke-opacity', colors.dots.opacity.toFixed(7))\r\n }\r\n\r\n svg.appendChild(borderEl);\r\n\r\n [TextPosition.left, TextPosition.top, TextPosition.right, TextPosition.bottom].forEach(postion => {\r\n const textCfg = this.pluginOptions.text\r\n const config = textCfg?.[postion]\r\n if (config) {\r\n let defs = Array.from(svg.childNodes).find(v => (v as HTMLElement).tagName.toUpperCase() == 'DEFS')\r\n if (!defs) {\r\n defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')\r\n svg.appendChild(defs)\r\n }\r\n const element = document.createElementNS('http://www.w3.org/2000/svg', 'path')\r\n const size = (config.size || textCfg.size || 1) * sizeFactor\r\n pathR = this.pluginOptions.round ? r - size / 3 : 0\r\n pathL = this.pluginOptions.round ? lineSize : lineSize + (r - size / 3)\r\n switch (postion) {\r\n case TextPosition.top:\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx} ${cy + pathR + pathL}\r\n h ${-pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${-pathR}\r\n v ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${-pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${pathR}\r\n v ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${pathR}\r\n h ${-pathL}`\r\n )\r\n break\r\n case TextPosition.bottom:\r\n if (this.pluginOptions.round)\r\n pathR += size * 2 / 3\r\n else\r\n pathL += size * 2 / 3\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx} ${cy - pathR - pathL}\r\n h ${-pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${-pathR} ${pathR}\r\n v ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${pathR} ${pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${pathR} ${-pathR}\r\n v ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 0 ${-pathR} ${-pathR}\r\n h ${-pathL}`\r\n )\r\n break\r\n case TextPosition.left:\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx + pathR + pathL} ${cy}\r\n v ${pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${pathR}\r\n h ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${-pathR}\r\n v ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${-pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${pathR}\r\n v ${pathL}`\r\n )\r\n break\r\n case TextPosition.right:\r\n element.setAttribute(\r\n 'd',\r\n svgPath`M ${cx - pathR - pathL} ${cy}\r\n v ${-pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${-pathR}\r\n h ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${pathR} ${pathR}\r\n v ${2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${pathR}\r\n h ${-2 * pathL}\r\n a ${pathR} ${pathR} 0 0 1 ${-pathR} ${-pathR}\r\n v ${-pathL}`\r\n )\r\n break\r\n }\r\n const id = `border-text-${postion}-${this.idSuffix}`\r\n element.setAttribute('id', id)\r\n element.setAttribute('fill', 'none')\r\n\r\n const span = document.createElementNS('http://www.w3.org/2000/svg', 'tspan')\r\n span.setAttribute('font-family', config.font || textCfg.font || 'sans-serif')\r\n span.setAttribute('fill', config.color || textCfg.color || '#000')\r\n span.setAttribute('font-weight', numToAttr(config.fontWeight || textCfg.fontWeight || 'normal'))\r\n span.setAttribute('font-style', config.fontStyle || textCfg.fontStyle || 'normal')\r\n span.setAttribute('font-size', numToAttr(size))\r\n span.textContent = config.content\r\n\r\n const textPath = document.createElementNS('http://www.w3.org/2000/svg', 'textPath')\r\n textPath.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '#' + id)\r\n textPath.setAttribute('startOffset', '50%')\r\n textPath.setAttribute('text-anchor', 'middle')\r\n textPath.appendChild(span)\r\n\r\n const text = document.createElementNS('http://www.w3.org/2000/svg', 'text')\r\n text.appendChild(textPath)\r\n\r\n defs.appendChild(element)\r\n svg.appendChild(text)\r\n }\r\n })\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n if (this.pluginOptions.fontFaces) {\r\n let defs = Array.from(svg.childNodes).find(v => (v as HTMLElement).tagName.toUpperCase() == 'DEFS')\r\n if (!defs) {\r\n defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')\r\n svg.appendChild(defs)\r\n }\r\n const style = document.createElementNS('http://www.w3.org/2000/svg', 'style')\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n style.textContent = this.pluginOptions.fontFaces\r\n defs.appendChild(style)\r\n }\r\n }\r\n}\r\n"],"names":["extendSVG","numToAttr","TextPosition","createColor","m","w","top","bottom","left","right","pluginOptions","idSuffix","constructor","Math","random","toFixed","substring","this","postProcess","svg","options","colors","document","sizeFactor","proportional","size","thickness","drawArea","margin","abs","cx","cy","round","min","lineSize","pathR","r","pathL","borderEl","createElementNS","setAttribute","percenToLength","dim","endsWith","parseFloat","length","strokeLen","PI","split","map","v","trim","filter","dashArray","join","dashOffset","dasharrayOffset","value","gradient","color","additionalRotation","x","y","height","width","name","dotSize","dotsOptions","defs","Array","from","childNodes","find","tagName","toUpperCase","appendChild","opacity","dots","forEach","postion","text","textCfg","config","element","svgPath","id","span","font","fontWeight","fontStyle","textContent","content","textPath","setAttributeNS","fontFaces","style"],"mappings":"oBAKKA,eACDC,aACAC,MAAA,gCAEAC,MA0CU,sBAAA,IAAAC,EAAAC,EAAAD,IAAA,CAAA,EAAAC,EAAAC,IAAA,MAAAD,EAAAE,OAAA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AKP,cAAcoF,UACvC1B,EAAKO,YAAYoB,GA/LrB,CAPH"}
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-utils.js","sources":["../src/utils/svg.ts"],"sourcesContent":["import { RotateFigureArgs } from '../types/helper.js'\r\n\r\nconst rx = /\\.?0+$/\r\n\r\nexport function numToAttr(value: number | string) {\r\n if (typeof value == 'string') return value\r\n return value.toFixed(7).replace(rx, '')\r\n}\r\n\r\nexport function svgPath(strings: TemplateStringsArray, ...values: unknown[]) {\r\n return strings\r\n .reduce((t, v, i) => {\r\n let p: unknown = ''\r\n if (i) p = values[i - 1]\r\n if (typeof p == 'number') p = numToAttr(p)\r\n return `${t}${p}${v}`\r\n }, '')\r\n .trim()\r\n .replace(/[\\s\\n\\r]+/gim, ' ')\r\n}\r\n\r\nexport function rotateFigure<T extends SVGElement | ReadonlyArray<SVGElement>>({ draw, ...args }: RotateFigureArgs<T>) {\r\n const { x, y, size, rotation = 0 } = args\r\n const cx = x + size / 2\r\n const cy = y + size / 2\r\n\r\n const element = draw(args)\r\n if (rotation) (Array.isArray(element) ? element : [element])\r\n .forEach(el => el.setAttribute('transform', `rotate(${numToAttr((180 * rotation) / Math.PI)},${cx},${cy})`))\r\n return element\r\n}\r\n\r\nexport function scalePath(path: Array<string | number>, { x, y, size }: {\r\n x: number\r\n y: number\r\n size: number\r\n}) {\r\n let move = false\r\n let i = 0\r\n return path\r\n .map((v) => {\r\n if (typeof v == 'string') {\r\n i = 0\r\n move = v.toUpperCase() == v\r\n return v\r\n }\r\n i++\r\n v = v * size\r\n if (move) {\r\n v += i % 2 == 1 ? x : y\r\n }\r\n return numToAttr(v)\r\n })\r\n .join(' ')\r\n}\r\n\r\nexport function extendSVG(svg: SVGSVGElement, padding: number) {\r\n padding = Math.max(padding, 0)\r\n svg.setAttribute('width', numToAttr(parseFloat(svg.getAttribute('width') || '0') + 2 * padding))\r\n svg.setAttribute('height', numToAttr(parseFloat(svg.getAttribute('height') || '0') + 2 * padding))\r\n const vb = (svg.getAttribute('viewBox') || '').split(' ').map((v, i) => parseFloat(v) + (i < 2 ? -1 : 2) * padding)\r\n svg.setAttribute('viewBox', vb.map(numToAttr).join(' '))\r\n if (vb.length < 4)\r\n return undefined\r\n return {\r\n left: vb[0],\r\n right: vb[2] + vb[0],\r\n top: vb[1],\r\n bottom: vb[3] + vb[1]\r\n }\r\n}\r\n"],"names":["rx","numToAttr","value","toFixed","replace","extendSVG","svg","padding","max","k","parseFloat","c","a","setAttribute","getAttribute","b","split","h","map","i","length","left","right","vb","top","bottom","e","d","f","size","rotation","isArray","draw","args","forEach","Math","PI","cy","element","scalePath","path","y","v","toUpperCase","reduce","trim","rotateFigure","svgPath"],"mappings":"AAEA,IAAAA,WAEMC,SAAUA,EAAUC,GACtB,MAAoB,iBAATA,EAA0BA,EAC9BA,EAAMC,QAAQ,GAAGC,QAAQJ,EAAI,GAFQ,YAoD1CK,EAAAA,GAAAA,EAAoBC,KACtBC,MAAeC,GAAAA,EAAID,qBACFE,EAAAC,WAAmBA,EAAAA,uBAA4B,KAA5B,EAAwCC,IAAlDC,EAAAC,aACtBA,SAAaJ,EAAAC,WAAoBA,EAAAA,aAAeI,WAAa,KAA5B,EAAyCH,IAAnD,IAAAI,GAC3BH,EAAAE,aAAYA,gBAAJE,MAAqCA,KAAAA,KAArCC,EAAgDC,IAAER,WAASA,IAAAA,EAAA,GAAT,EAA2BS,GAAAR,GACzD,GADyDC,EAA3BC,uBACzCE,EAAAG,IAAjBT,GAA+BS,KAAH,QAA5BH,SACOK,GAAAA,MAAP,CAEAC,KAAAN,EACIM,GAAAA,MADGN,EAEHO,GAAAA,EAAOC,GAAAC,IAAWT,EAFf,GAGHS,OACAC,EAAAA,GAAAA,EAAQF,GAAA,qCA/C+DN,OAAAS,WAC3EC,EAAM,GAANhB,EAASiB,EAATb,EAAYW,EAAA,EAAAG,EAAMZ,EAAAS,EAAA,EAMyDI,OANzDlB,EAAAA,EAAAD,GAAlBgB,UAAAI,WAIaC,EAAGC,CAAHrB,IACbsB,QAAqBH,kBAChBG,YAAiBrB,UAAAA,EAAAA,IAAac,EAAAQ,KAAAC,mBAAyDA,CAAAA,CAA5C,SAAyDC,EACzGzB,GAAO0B,EAR0G3B,mBAW/G4B,SAAoBC,OAAmC5B,EAAA6B,IAAGb,oBAKjDA,GAGDc,EAAD,EACDhB,EAAAE,EAAIe,eAAYf,EAAhBA,IAGID,IAAAC,GAAOc,EAAAA,IADEC,GAAAA,EAAAA,GAAAA,EAAAA,EAAF5B,GAGXN,YAEA,IACa,oBAxCF,OACnBG,EAAAgC,OACKA,UAAWF,IAAJf,EAAY,GAGhB,OAFAD,IAAiBC,EACbR,EAAJO,EAAA,IACI,iBAAAC,QAAJA,IACA,GAAAZ,wBAEH8B,QACAzC,eAAQ,IAAA,QAT0DC,eAAAI,eAAAqC,kBAAAP,eAAAQ"}
1
+ {"version":3,"file":"plugin-utils.js","sources":["../src/utils/svg.ts"],"sourcesContent":["import { RotateFigureArgs } from '../types/helper.js'\n\nconst rx = /\\.?0+$/\n\nexport function numToAttr(value: number | string) {\n if (typeof value == 'string') return value\n return value.toFixed(7).replace(rx, '')\n}\n\nexport function svgPath(strings: TemplateStringsArray, ...values: unknown[]) {\n return strings\n .reduce((t, v, i) => {\n let p: unknown = ''\n if (i) p = values[i - 1]\n if (typeof p == 'number') p = numToAttr(p)\n return `${t}${p}${v}`\n }, '')\n .trim()\n .replace(/[\\s\\n\\r]+/gim, ' ')\n}\n\nexport function rotateFigure<T extends SVGElement | ReadonlyArray<SVGElement>>({ draw, ...args }: RotateFigureArgs<T>) {\n const { x, y, size, rotation = 0 } = args\n const cx = x + size / 2\n const cy = y + size / 2\n\n const element = draw(args)\n if (rotation) (Array.isArray(element) ? element : [element])\n .forEach(el => el.setAttribute('transform', `rotate(${numToAttr((180 * rotation) / Math.PI)},${cx},${cy})`))\n return element\n}\n\nexport function scalePath(path: Array<string | number>, { x, y, size }: {\n x: number\n y: number\n size: number\n}) {\n let move = false\n let i = 0\n return path\n .map((v) => {\n if (typeof v == 'string') {\n i = 0\n move = v.toUpperCase() == v\n return v\n }\n i++\n v = v * size\n if (move) {\n v += i % 2 == 1 ? x : y\n }\n return numToAttr(v)\n })\n .join(' ')\n}\n\nexport function extendSVG(svg: SVGSVGElement, padding: number) {\n padding = Math.max(padding, 0)\n svg.setAttribute('width', numToAttr(parseFloat(svg.getAttribute('width') || '0') + 2 * padding))\n svg.setAttribute('height', numToAttr(parseFloat(svg.getAttribute('height') || '0') + 2 * padding))\n const vb = (svg.getAttribute('viewBox') || '').split(' ').map((v, i) => parseFloat(v) + (i < 2 ? -1 : 2) * padding)\n svg.setAttribute('viewBox', vb.map(numToAttr).join(' '))\n if (vb.length < 4)\n return undefined\n return {\n left: vb[0],\n right: vb[2] + vb[0],\n top: vb[1],\n bottom: vb[3] + vb[1]\n }\n}\n"],"names":["rx","numToAttr","value","toFixed","replace","extendSVG","svg","padding","max","k","parseFloat","c","a","setAttribute","getAttribute","b","split","h","map","i","length","left","right","vb","top","bottom","e","d","f","size","rotation","isArray","draw","args","forEach","Math","PI","cy","element","scalePath","path","y","v","toUpperCase","reduce","trim","rotateFigure","svgPath"],"mappings":"AAEA,IAAAA,WAEMC,SAAUA,EAAUC,GACtB,MAAoB,iBAATA,EAA0BA,EAC9BA,EAAMC,QAAQ,GAAGC,QAAQJ,EAAI,GAFQ,YAoD1CK,EAAAA,GAAAA,EAAoBC,KACtBC,MAAeC,GAAAA,EAAID,qBACFE,EAAAC,WAAmBA,EAAAA,uBAA4B,KAA5B,EAAwCC,IAAlDC,EAAAC,aACtBA,SAAaJ,EAAAC,WAAoBA,EAAAA,aAAeI,WAAa,KAA5B,EAAyCH,IAAnD,IAAAI,GAC3BH,EAAAE,aAAYA,gBAAJE,MAAqCA,KAAAA,KAArCC,EAAgDC,IAAER,WAASA,IAAAA,EAAA,GAAT,EAA2BS,GAAAR,GACzD,GADyDC,EAA3BC,uBACzCE,EAAAG,IAAjBT,GAA+BS,KAAH,QAA5BH,SACOK,GAAAA,MAAP,CAEAC,KAAAN,EACIM,GAAAA,MADGN,EAEHO,GAAAA,EAAOC,GAAAC,IAAWT,EAFf,GAGHS,OACAC,EAAAA,GAAAA,EAAQF,GAAA,qCA/C+DN,OAAAS,WAC3EC,EAAM,GAANhB,EAASiB,EAATb,EAAYW,EAAA,EAAAG,EAAMZ,EAAAS,EAAA,EAMyDI,OANzDlB,EAAAA,EAAAD,GAAlBgB,UAAAI,WAIaC,EAAGC,CAAHrB,IACbsB,QAAqBH,kBAChBG,YAAiBrB,UAAAA,EAAAA,IAAac,EAAAQ,KAAAC,mBAAyDA,CAAAA,CAA5C,SAAyDC,EACzGzB,GAAO0B,EAR0G3B,mBAW/G4B,SAAoBC,OAAmC5B,EAAA6B,IAAGb,oBAKjDA,GAGDc,EAAD,EACDhB,EAAAE,EAAIe,eAAYf,EAAhBA,IAGID,IAAAC,GAAOc,EAAAA,IADEC,GAAAA,EAAAA,GAAAA,EAAAA,EAAF5B,GAGXN,YAEA,IACa,oBAxCF,OACnBG,EAAAgC,OACKA,UAAWF,IAAJf,EAAY,GAGhB,OAFAD,IAAiBC,EACbR,EAAJO,EAAA,IACI,iBAAAC,QAAJA,IACA,GAAAZ,wBAEH8B,QACAzC,eAAQ,IAAA,QAT0DC,eAAAI,eAAAqC,kBAAAP,eAAAQ"}
@@ -21,6 +21,7 @@ export interface BorderPluginOptions {
21
21
  color?: string;
22
22
  gradient?: Gradient;
23
23
  dasharray?: string;
24
+ dasharrayOffset?: string;
24
25
  margin?: number;
25
26
  /**
26
27
  * If true, all dimensions are proportional to the code size,