serpentine-border 1.0.2 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,8 +23,11 @@ function setAttributes(el, attrs) {
23
23
  }
24
24
 
25
25
  const wrapperEl = document.getElementById('wrapper')
26
- const { wrapperStyle, svgAttributes, paths } = serpentineBorder({ wrapperEl })
26
+ const result = serpentineBorder({ wrapperEl })
27
+ if (!result) return
28
+ const { wrapperStyle, svgAttributes, paths } = result
27
29
  Object.assign(wrapperEl.style, wrapperStyle)
30
+ // Optionally: getSectionsPadding({ sectionCount: n, strokeCount, strokeWidth, horizontalOverflow }) for per-section padding
28
31
 
29
32
  const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
30
33
  setAttributes(svg, svgAttributes)
@@ -41,7 +44,7 @@ wrapperEl.insertBefore(svg, wrapperEl.firstChild)
41
44
 
42
45
  ### serpentineBorder(options)
43
46
 
44
- Returns `wrapperStyle`, `svgAttributes` (class, viewBox, style), and `paths`. Pass either `wrapperEl` (measures from the DOM; returns `null` when DOM is unavailable, e.g. SSR) or `width` + `sectionBottomYs` (pure; never returns null).
47
+ Returns `wrapperStyle`, `svgAttributes` (class, viewBox, style), and `paths`. Pass either `wrapperEl` (measures from the DOM; returns `null` when DOM is unavailable, e.g. SSR) or `width` + `sectionBottomYs` (pure; never returns null). Use **`getSectionsPadding({ sectionCount, strokeCount, strokeWidth, horizontalOverflow })`** for `{ even, odd, last }` — padding objects for even-indexed sections, odd-indexed sections, and the last section so content does not overlap the border.
45
48
 
46
49
  | Option | Type | Default | Description |
47
50
  |--------|------|---------|-------------|
@@ -51,13 +54,24 @@ Returns `wrapperStyle`, `svgAttributes` (class, viewBox, style), and `paths`. Pa
51
54
  | `strokeCount` | `number` | `5` | Number of parallel strokes. |
52
55
  | `strokeWidth` | `number` | `8` | Width of each stroke in px. |
53
56
  | `radius` | `number` | `50` | Radius of the wavy turns in px. |
54
- | `horizontalOverlap` | `number \| 'borderWidth' \| 'halfBorderWidth'` | `0` | Extra width per side (px or keyword). |
57
+ | `horizontalOverflow` | `number \| 'borderWidth' \| 'halfBorderWidth'` | `0` | Horizontal overflow per side so the border extends past content (px or keyword). |
55
58
  | `colors` | `string[]` | `['#ffffff', '#000000']` | Stroke colors (hex/CSS). |
56
59
  | `layoutMode` | `'content' \| 'border'` | `'border'` | See note below. |
57
60
  | `svgClassName` | `string` | `'serpentine-border-svg'` | Class applied to the SVG (and used to exclude it when measuring). |
58
61
 
59
62
  **Layout mode:** In some instances, you may want the border to be an overlay that doesn't affect flow and content size. With `'content'`, the wrapper’s size follows its content and the border is drawn around it (the SVG can extend outside). With `'border'`, the outer edge of the border defines the box: the full border fits inside the layout, and content sits inside that box. This mode avoids the border spilling out and overlapping neighboring elements.
60
63
 
64
+ ### getSectionsPadding(options)
65
+
66
+ Returns `{ even, odd, last }` — each is a `{ top, right, bottom, left }` (px) padding object. Use `even` for even-indexed sections (0, 2, …), `odd` for odd-indexed sections (1, 3, …), and `last` for the final section (which has `bottom: 0`). Use the same `strokeCount`, `strokeWidth`, and `horizontalOverflow` as your border; `sectionCount` is the number of sections (e.g. `sectionBottomYs.length - 1`). Handy with the React component: call with the section count and props, then apply `even`/`odd`/`last` to the corresponding section elements.
67
+
68
+ | Option | Type | Description |
69
+ |--------|------|-------------|
70
+ | `sectionCount` | `number` | Number of sections. |
71
+ | `strokeCount` | `number` | Same as serpentineBorder. |
72
+ | `strokeWidth` | `number` | Same as serpentineBorder. |
73
+ | `horizontalOverflow` | `number \| 'borderWidth' \| 'halfBorderWidth'` | Same as serpentineBorder. |
74
+
61
75
  ### React: SerpentineBorder
62
76
 
63
77
  Wrap your content with the React component; it accepts the same options as `serpentineBorder` as props.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("react/jsx-runtime"),D=require("react"),Z=["#ffffff","#000000"];function q(t,s,e){if(typeof t=="number")return t;const n=s*e;return t==="borderWidth"?n:t==="halfBorderWidth"?n/2:0}function J(t){return Object.entries(t).map(([s,e])=>{const n=s.replace(/([A-Z])/g,"-$1").toLowerCase(),i=typeof e=="number"&&!Number.isNaN(e)?`${e}px`:String(e);return`${n}: ${i}`}).join("; ")}function Q(t,s,e,n,i,g,u,o,c,f){const r=i*(e-1),a=i/2,p=s.length-1,l=[];for(let h=0;h<e;h++){const d=h*i,b=(e-1-h)*i,m=n-d,B=n-b,k=r-b,N=c-f+a,x=d-c+N,L=f,y=t+L-b-a,j=x+(n-d),A=t+L-n-a,z=t+L-r-a,w=c+o,$=[`M ${y} ${w-r-i/2-u}`,`L ${y} ${w-r-u}`,`A ${k} ${k} 0 0 1 ${z} ${w-b-u}`,`L ${j} ${d+o-u}`,`A ${m} ${m} 0 0 0 ${x} ${n+o-u}`,`L ${x} ${n+o}`];for(let C=0;C<p-1;C++){const v=s[C+1],U=s[C+2],X=v+n-c+o;C%2===0?($.push(`L ${x} ${v-n+o}`),$.push(`A ${m} ${m} 0 0 0 ${j} ${v-d+o}`),$.push(`L ${A} ${v-d+o}`),$.push(`A ${B} ${B} 0 0 1 ${y} ${X}`),$.push(`L ${y} ${U-n+o}`)):($.push(`L ${y} ${v-n+o}`),$.push(`A ${B} ${B} 0 0 1 ${A} ${v-b+o}`),$.push(`L ${j} ${v-b+o}`),$.push(`A ${m} ${m} 0 0 0 ${x} ${X}`),$.push(`L ${x} ${U-n+o}`))}const R=s[p];(p-2)%2===0?$.push(`L ${y} ${R}`):$.push(`L ${x} ${R}`),l.push({d:$.join(" "),stroke:g[h%g.length],"stroke-width":i,fill:"none"})}return l}const G="serpentine-border-svg",M={strokeCount:5,strokeWidth:8,radius:50,horizontalOverlap:0,layoutMode:"border"};function P(t){const s=t.strokeCount??M.strokeCount,e=t.strokeWidth??M.strokeWidth,n=t.radius??M.radius,i=t.horizontalOverlap??M.horizontalOverlap,g=t.colors??Z,u=t.layoutMode??M.layoutMode,o=t.svgClassName??G;let c,f;if(t.wrapperEl!=null){const A=t.wrapperEl;if(!(typeof document<"u"&&typeof A.getBoundingClientRect=="function"))return null;const w=V(A,{layoutMode:u,horizontalOverlap:i,strokeCount:s,strokeWidth:e,excludeClassName:o});if(!w)return null;c=w.width,f=w.sectionBottomYs}else{if(t.width==null||t.sectionBottomYs==null)return null;c=t.width,f=t.sectionBottomYs}const r=q(i,s,e),a=(s-1)*e,p=s*e,l=2*e,h=a/2,d=(s-1)/2*e+h,W=u==="border"?{boxSizing:"border-box",position:"relative",marginTop:`${p/2}px`,...r>0&&{paddingLeft:`${r}px`,paddingRight:`${r}px`}}:{position:"relative",boxSizing:"border-box"},b=u==="border"?{position:"absolute",overflow:"hidden",width:"100%",left:0,top:-(l+d),height:`calc(100% + ${l+d}px)`}:{position:"absolute",overflow:"hidden",width:`calc(100% + ${2*r}px)`,left:-r,top:-(l+d),height:`calc(100% + ${l+d}px)`},m=J(b),B=Q(c,f,s,n,e,g,d,h,a,r),k=f[f.length-1]??0,N=Math.max(1,c+2*r),x=k+l+d,L=r>0?-r:0,y=-e*2-d,j=`${L} ${y} ${N} ${x}`;return{wrapperStyle:W,svgAttributes:{class:o,viewBox:j,style:m},paths:B}}function V(t,s){const{layoutMode:e,horizontalOverlap:n=0,strokeCount:i,strokeWidth:g,excludeClassName:u=G}=s,o=q(n,i,g);if(!t)return null;const c=u?Array.from(t.children).filter(l=>!l.classList.contains(u)):Array.from(t.children);if(c.length===0)return null;const f=t.getBoundingClientRect(),r=f.width,a=e==="border"?Math.max(1,r-2*o):Math.max(1,r),p=[0];for(let l=0;l<c.length;l++){const h=c[l].getBoundingClientRect();p.push(h.top-f.top+h.height)}return{width:a,sectionBottomYs:p}}function E(t){const s={};if(!t||typeof t!="string")return s;for(const e of t.split(";")){const n=e.indexOf(":");if(n===-1)continue;const i=e.slice(0,n).trim().replace(/-([a-z])/g,(u,o)=>o.toUpperCase()),g=e.slice(n+1).trim();i&&(s[i]=g)}return s}function O(t){return Object.fromEntries(Object.entries(t).map(([s,e])=>[s==="stroke-width"?"strokeWidth":s,e]))}function H({children:t,strokeCount:s,strokeWidth:e,radius:n,horizontalOverlap:i,colors:g,layoutMode:u}){const o=D.useRef(null),[c,f]=D.useState(null);return D.useEffect(()=>{const r=o.current;if(!r)return;const a=()=>{const l=V(r,{layoutMode:u,horizontalOverlap:i,strokeCount:s,strokeWidth:e});if(!l)return;const h=P({width:l.width,sectionBottomYs:l.sectionBottomYs,strokeCount:s,strokeWidth:e,radius:n,horizontalOverlap:i,colors:g,layoutMode:u});f(h)};a();const p=new ResizeObserver(a);return p.observe(r),()=>p.disconnect()},[s,e,n,i,g,u]),S.jsxs("div",{ref:o,className:"serpentine-wrapper",style:(c==null?void 0:c.wrapperStyle)??{position:"relative",boxSizing:"border-box"},"data-testid":"serpentine-wrapper",children:[c&&(()=>{const{class:r,style:a,...p}=c.svgAttributes,l=typeof a=="string"?E(a):a;return S.jsx("svg",{"data-testid":"serpentine-svg",className:r,style:l,...p,children:c.paths.map((h,d)=>S.jsx("path",{...O(h)},d))})})(),t]})}exports.SerpentineBorder=H;exports.serpentineBorder=P;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("react/jsx-runtime"),S=require("react"),G=["#ffffff","#000000"];function D(t,n,e){if(typeof t=="number")return t;const o=n*e;return t==="borderWidth"?o:t==="halfBorderWidth"?o/2:0}function V(t){return Object.entries(t).map(([n,e])=>{const o=n.replace(/([A-Z])/g,"-$1").toLowerCase(),c=typeof e=="number"&&!Number.isNaN(e)?`${e}px`:String(e);return`${o}: ${c}`}).join("; ")}function Z(t,n,e,o,c,p,u,s,r,h){const i=c*(e-1),a=c/2,$=n.length-1,l=[];for(let f=0;f<e;f++){const d=f*c,m=(e-1-f)*c,x=o-d,B=o-m,M=i-m,N=r-h+a,b=d-r+N,L=h,y=t+L-m-a,j=b+(o-d),A=t+L-o-a,z=t+L-i-a,v=r+s,g=[`M ${y} ${v-i-c/2-u}`,`L ${y} ${v-i-u}`,`A ${M} ${M} 0 0 1 ${z} ${v-m-u}`,`L ${j} ${d+s-u}`,`A ${x} ${x} 0 0 0 ${b} ${o+s-u}`,`L ${b} ${o+s}`];for(let C=0;C<$-1;C++){const w=n[C+1],O=n[C+2],U=w+o-r+s;C%2===0?(g.push(`L ${b} ${w-o+s}`),g.push(`A ${x} ${x} 0 0 0 ${j} ${w-d+s}`),g.push(`L ${A} ${w-d+s}`),g.push(`A ${B} ${B} 0 0 1 ${y} ${U}`),g.push(`L ${y} ${O-o+s}`)):(g.push(`L ${y} ${w-o+s}`),g.push(`A ${B} ${B} 0 0 1 ${A} ${w-m+s}`),g.push(`L ${j} ${w-m+s}`),g.push(`A ${x} ${x} 0 0 0 ${b} ${U}`),g.push(`L ${b} ${O-o+s}`))}const E=n[$];($-2)%2===0?g.push(`L ${y} ${E}`):g.push(`L ${b} ${E}`),l.push({d:g.join(" "),stroke:p[f%p.length],"stroke-width":c,fill:"none"})}return l}const X="serpentine-border-svg",k={strokeCount:5,strokeWidth:8,radius:50,horizontalOverflow:0,layoutMode:"border"};function P(t){const n=t.strokeCount??k.strokeCount,e=t.strokeWidth??k.strokeWidth,o=t.radius??k.radius,c=t.horizontalOverflow??k.horizontalOverflow,p=t.colors??G,u=t.layoutMode??k.layoutMode,s=t.svgClassName??X;let r,h;if(t.wrapperEl!=null){const A=t.wrapperEl;if(!(typeof document<"u"&&typeof A.getBoundingClientRect=="function"))return null;const v=q(A,{layoutMode:u,horizontalOverflow:c,strokeCount:n,strokeWidth:e,excludeClassName:s});if(!v)return null;r=v.width,h=v.sectionBottomYs}else{if(t.width==null||t.sectionBottomYs==null)return null;r=t.width,h=t.sectionBottomYs}const i=D(c,n,e),a=(n-1)*e,$=n*e,l=2*e,f=a/2,d=(n-1)/2*e+f,W=u==="border"?{boxSizing:"border-box",position:"relative",marginTop:`${$/2}px`,...i>0&&{paddingLeft:`${i}px`,paddingRight:`${i}px`}}:{position:"relative",boxSizing:"border-box"},m=u==="border"?{position:"absolute",overflow:"hidden",width:"100%",left:0,top:-(l+d),height:`calc(100% + ${l+d}px)`}:{position:"absolute",overflow:"hidden",width:`calc(100% + ${2*i}px)`,left:-i,top:-(l+d),height:`calc(100% + ${l+d}px)`},x=V(m),B=Z(r,h,n,o,e,p,d,f,a,i),M=h[h.length-1]??0,N=Math.max(1,r+2*i),b=M+l+d,L=i>0?-i:0,y=-e*2-d,j=`${L} ${y} ${N} ${b}`;return{wrapperStyle:W,svgAttributes:{class:s,viewBox:j,style:x},paths:B}}function J(t){const{sectionCount:n,strokeCount:e,strokeWidth:o}=t,c=t.horizontalOverflow??0,p=e*o,u=D(c,e,o),s=p/2,r=p-u,h={top:s,right:0,bottom:s,left:r},i={top:s,right:r,bottom:s,left:0},a=n>0&&(n-1)%2===0;return{even:h,odd:i,last:{top:s,right:a?0:r,bottom:0,left:a?r:0}}}function q(t,n){const{layoutMode:e,horizontalOverflow:o=0,strokeCount:c,strokeWidth:p,excludeClassName:u=X}=n,s=D(o,c,p);if(!t)return null;const r=u?Array.from(t.children).filter(l=>!l.classList.contains(u)):Array.from(t.children);if(r.length===0)return null;const h=t.getBoundingClientRect(),i=h.width,a=e==="border"?Math.max(1,i-2*s):Math.max(1,i),$=[0];for(let l=0;l<r.length;l++){const f=r[l].getBoundingClientRect();$.push(f.top-h.top+f.height)}return{width:a,sectionBottomYs:$}}function Q(t){const n={};if(!t||typeof t!="string")return n;for(const e of t.split(";")){const o=e.indexOf(":");if(o===-1)continue;const c=e.slice(0,o).trim().replace(/-([a-z])/g,(u,s)=>s.toUpperCase()),p=e.slice(o+1).trim();c&&(n[c]=p)}return n}function H(t){return Object.fromEntries(Object.entries(t).map(([n,e])=>[n==="stroke-width"?"strokeWidth":n,e]))}function I({children:t,strokeCount:n,strokeWidth:e,radius:o,horizontalOverflow:c,colors:p,layoutMode:u}){const s=S.useRef(null),[r,h]=S.useState(null);return S.useEffect(()=>{const i=s.current;if(!i)return;const a=()=>{const l=q(i,{layoutMode:u,horizontalOverflow:c,strokeCount:n,strokeWidth:e});if(!l)return;const f=P({width:l.width,sectionBottomYs:l.sectionBottomYs,strokeCount:n,strokeWidth:e,radius:o,horizontalOverflow:c,colors:p,layoutMode:u});h(f)};a();const $=new ResizeObserver(a);return $.observe(i),()=>$.disconnect()},[n,e,o,c,p,u]),R.jsxs("div",{ref:s,className:"serpentine-wrapper",style:(r==null?void 0:r.wrapperStyle)??{position:"relative",boxSizing:"border-box"},"data-testid":"serpentine-wrapper",children:[r&&(()=>{const{class:i,style:a,...$}=r.svgAttributes,l=typeof a=="string"?Q(a):a;return R.jsx("svg",{"data-testid":"serpentine-svg",className:i,style:l,...$,children:r.paths.map((f,d)=>R.jsx("path",{...H(f)},d))})})(),t]})}exports.SerpentineBorder=I;exports.getSectionsPadding=J;exports.serpentineBorder=P;
2
2
  //# sourceMappingURL=serpentine-border.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"serpentine-border.cjs","sources":["../src/constants.js","../src/serpentineCore.js","../src/SerpentineBorder.jsx"],"sourcesContent":["export const DEFAULT_COLORS = ['#ffffff', '#000000']\n","/**\n * Vanilla JS core for serpentine border SVG generation.\n * Single export: call with measured dimensions and options to get everything needed to render.\n */\n\nimport { DEFAULT_COLORS } from './constants.js'\n\nfunction resolveOverlapToPixels(horizontalOverlap, N, STROKE_WIDTH) {\n if (typeof horizontalOverlap === 'number') return horizontalOverlap\n const totalBorderWidth = N * STROKE_WIDTH\n if (horizontalOverlap === 'borderWidth') return totalBorderWidth\n if (horizontalOverlap === 'halfBorderWidth') return totalBorderWidth / 2\n return 0\n}\n\nfunction styleObjectToCss(obj) {\n return Object.entries(obj)\n .map(([k, v]) => {\n const key = k.replace(/([A-Z])/g, '-$1').toLowerCase()\n const val = typeof v === 'number' && !Number.isNaN(v) ? `${v}px` : String(v)\n return `${key}: ${val}`\n })\n .join('; ')\n}\n\nfunction buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA) {\n const R1 = STROKE_WIDTH * (N - 1)\n const RIGHT_EXTEND = STROKE_WIDTH / 2\n const n = Y.length - 1\n const parts = []\n for (let i = 0; i < N; i++) {\n const o = i * STROKE_WIDTH\n const j = N - 1 - i\n const oj = j * STROKE_WIDTH\n const r = R - o\n const rj = R - oj\n const r1 = R1 - o\n const rj1 = R1 - oj\n\n const leftOffset = O_TOTAL - BORDER_EXTRA + RIGHT_EXTEND\n const xLeft = o - O_TOTAL + leftOffset\n const rightExt = BORDER_EXTRA\n const xRight = W + rightExt - oj - RIGHT_EXTEND\n const xLeftArc = xLeft + (R - o)\n const xRightArc = W + rightExt - R - RIGHT_EXTEND\n const xRightR1 = W + rightExt - R1 - RIGHT_EXTEND\n\n const yCurrTop = O_TOTAL + Y_OFFSET\n const segs = [\n `M ${xRight} ${yCurrTop - R1 - STROKE_WIDTH / 2 - TOP_ARC_SHIFT}`,\n `L ${xRight} ${yCurrTop - R1 - TOP_ARC_SHIFT}`,\n `A ${rj1} ${rj1} 0 0 1 ${xRightR1} ${yCurrTop - oj - TOP_ARC_SHIFT}`,\n `L ${xLeftArc} ${o + Y_OFFSET - TOP_ARC_SHIFT}`,\n `A ${r} ${r} 0 0 0 ${xLeft} ${R + Y_OFFSET - TOP_ARC_SHIFT}`,\n `L ${xLeft} ${R + Y_OFFSET}`,\n ]\n\n for (let t = 0; t < n - 1; t++) {\n const yCurr = Y[t + 1]\n const yNext = Y[t + 2]\n const yExit = yCurr + R - O_TOTAL + Y_OFFSET\n\n if (t % 2 === 0) {\n segs.push(`L ${xLeft} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeftArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`L ${xRightArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRight} ${yExit}`)\n segs.push(`L ${xRight} ${yNext - R + Y_OFFSET}`)\n } else {\n segs.push(`L ${xRight} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRightArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`L ${xLeftArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeft} ${yExit}`)\n segs.push(`L ${xLeft} ${yNext - R + Y_OFFSET}`)\n }\n }\n\n const lastY = Y[n]\n if ((n - 2) % 2 === 0) {\n segs.push(`L ${xRight} ${lastY}`)\n } else {\n segs.push(`L ${xLeft} ${lastY}`)\n }\n parts.push({\n d: segs.join(' '),\n stroke: COLORS[i % COLORS.length],\n 'stroke-width': STROKE_WIDTH,\n fill: 'none',\n })\n }\n return parts\n}\n\nconst DEFAULT_SVG_CLASS = 'serpentine-border-svg'\n\nconst DEFAULTS = {\n strokeCount: 5,\n strokeWidth: 8,\n radius: 50,\n horizontalOverlap: 0,\n layoutMode: 'border',\n}\n\n/**\n * Compute everything needed to render the serpentine border.\n * Accepts either (width + sectionBottomYs) for pure/custom use, or wrapperEl to measure from the DOM.\n * When using wrapperEl, returns null in non-DOM environments (e.g. SSR) or when measurement fails.\n *\n * @param {{\n * width?: number\n * sectionBottomYs?: number[]\n * wrapperEl?: HTMLElement\n * strokeCount?: number\n * strokeWidth?: number\n * radius?: number\n * horizontalOverlap?: number | 'borderWidth' | 'halfBorderWidth'\n * colors?: string[]\n * layoutMode?: 'content' | 'border'\n * svgClassName?: string\n * }} options\n * @returns {{\n * wrapperStyle: Record<string, unknown>\n * svgAttributes: { class?: string, viewBox: string, style: string }\n * paths: Array<{ d: string, stroke: string, 'stroke-width': number, fill: string }>\n * } | null}\n */\nexport function serpentineBorder(options) {\n const N = options.strokeCount ?? DEFAULTS.strokeCount\n const STROKE_WIDTH = options.strokeWidth ?? DEFAULTS.strokeWidth\n const R = options.radius ?? DEFAULTS.radius\n const horizontalOverlap = options.horizontalOverlap ?? DEFAULTS.horizontalOverlap\n const COLORS = options.colors ?? DEFAULT_COLORS\n const layoutMode = options.layoutMode ?? DEFAULTS.layoutMode\n const svgClassName = options.svgClassName ?? DEFAULT_SVG_CLASS\n\n let W, Y\n if (options.wrapperEl != null) {\n const wrapperEl = options.wrapperEl\n const hasDOM = typeof document !== 'undefined' && typeof wrapperEl.getBoundingClientRect === 'function'\n if (!hasDOM) return null\n const measured = measureSections(wrapperEl, {\n layoutMode,\n horizontalOverlap,\n strokeCount: N,\n strokeWidth: STROKE_WIDTH,\n excludeClassName: svgClassName,\n })\n if (!measured) return null\n W = measured.width\n Y = measured.sectionBottomYs\n } else {\n if (options.width == null || options.sectionBottomYs == null) return null\n W = options.width\n Y = options.sectionBottomYs\n }\n\n const BORDER_EXTRA = resolveOverlapToPixels(horizontalOverlap, N, STROKE_WIDTH)\n const O_TOTAL = (N - 1) * STROKE_WIDTH\n const TOTAL_BORDER_WIDTH = N * STROKE_WIDTH\n const TOP_OFFSET = 2 * STROKE_WIDTH\n const Y_OFFSET = O_TOTAL / 2\n const TOP_ARC_SHIFT = ((N - 1) / 2) * STROKE_WIDTH + Y_OFFSET\n\n const wrapperStyle =\n layoutMode === 'border'\n ? {\n boxSizing: 'border-box',\n position: 'relative',\n marginTop: `${TOTAL_BORDER_WIDTH / 2}px`,\n ...(BORDER_EXTRA > 0 && {\n paddingLeft: `${BORDER_EXTRA}px`,\n paddingRight: `${BORDER_EXTRA}px`,\n }),\n }\n : {\n position: 'relative',\n boxSizing: 'border-box',\n }\n\n const svgStyleObj =\n layoutMode === 'border'\n ? {\n position: 'absolute',\n overflow: 'hidden',\n width: '100%',\n left: 0,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n : {\n position: 'absolute',\n overflow: 'hidden',\n width: `calc(100% + ${2 * BORDER_EXTRA}px)`,\n left: -BORDER_EXTRA,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n const svgStyle = styleObjectToCss(svgStyleObj)\n\n const paths = buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA)\n\n const totalHeight = Y[Y.length - 1] ?? 0\n const totalWidth = Math.max(1, W + 2 * BORDER_EXTRA)\n const viewBoxHeight = totalHeight + TOP_OFFSET + TOP_ARC_SHIFT\n const viewBoxMinX = BORDER_EXTRA > 0 ? -BORDER_EXTRA : 0\n const viewBoxMinY = -STROKE_WIDTH * 2 - TOP_ARC_SHIFT\n const viewBoxStr = `${viewBoxMinX} ${viewBoxMinY} ${totalWidth} ${viewBoxHeight}`\n\n return {\n wrapperStyle,\n svgAttributes: {\n class: svgClassName,\n viewBox: viewBoxStr,\n style: svgStyle,\n },\n paths,\n }\n}\n\n/**\n * Measure wrapper and section elements to get width and section bottom Ys.\n * Children with the excludeClassName (default: same class used on the SVG by serpentineBorder) are excluded.\n * horizontalOverlap is resolved to pixels using strokeCount and strokeWidth.\n *\n * @param {HTMLElement} wrapperEl\n * @param {{\n * layoutMode: 'content' | 'border'\n * horizontalOverlap?: number | 'borderWidth' | 'halfBorderWidth'\n * strokeCount: number\n * strokeWidth: number\n * excludeClassName?: string\n * }} options\n * @returns {{ width: number, sectionBottomYs: number[] } | null}\n */\nexport function measureSections(wrapperEl, options) {\n const { layoutMode, horizontalOverlap = 0, strokeCount, strokeWidth, excludeClassName = DEFAULT_SVG_CLASS } = options\n const BORDER_EXTRA = resolveOverlapToPixels(horizontalOverlap, strokeCount, strokeWidth)\n if (!wrapperEl) return null\n\n const sectionEls = excludeClassName\n ? Array.from(wrapperEl.children).filter((el) => !el.classList.contains(excludeClassName))\n : Array.from(wrapperEl.children)\n\n if (sectionEls.length === 0) return null\n\n const rect = wrapperEl.getBoundingClientRect()\n const baseWidth = rect.width\n\n const W =\n layoutMode === 'border'\n ? Math.max(1, baseWidth - 2 * BORDER_EXTRA)\n : Math.max(1, baseWidth)\n\n const Y = [0]\n for (let i = 0; i < sectionEls.length; i++) {\n const r = sectionEls[i].getBoundingClientRect()\n Y.push(r.top - rect.top + r.height)\n }\n\n return { width: W, sectionBottomYs: Y }\n}\n","import { useEffect, useRef, useState } from 'react'\nimport { measureSections, serpentineBorder } from './serpentineCore.js'\n\nfunction cssStringToStyleObject(css) {\n const obj = {}\n if (!css || typeof css !== 'string') return obj\n for (const decl of css.split(';')) {\n const colon = decl.indexOf(':')\n if (colon === -1) continue\n const key = decl.slice(0, colon).trim().replace(/-([a-z])/g, (_, c) => c.toUpperCase())\n const value = decl.slice(colon + 1).trim()\n if (key) obj[key] = value\n }\n return obj\n}\n\nfunction pathAttrsForReact(attrs) {\n return Object.fromEntries(\n Object.entries(attrs).map(([k, v]) => [k === 'stroke-width' ? 'strokeWidth' : k, v])\n )\n}\n\nfunction SerpentineBorder({\n children,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverlap,\n colors,\n layoutMode,\n}) {\n const wrapperRef = useRef(null)\n const [borderData, setBorderData] = useState(null)\n\n useEffect(() => {\n const wrapper = wrapperRef.current\n if (!wrapper) return\n\n const measure = () => {\n const measured = measureSections(wrapper, {\n layoutMode,\n horizontalOverlap,\n strokeCount,\n strokeWidth,\n })\n if (!measured) return\n\n const data = serpentineBorder({\n width: measured.width,\n sectionBottomYs: measured.sectionBottomYs,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverlap,\n colors,\n layoutMode,\n })\n setBorderData(data)\n }\n\n measure()\n const ro = new ResizeObserver(measure)\n ro.observe(wrapper)\n return () => ro.disconnect()\n }, [strokeCount, strokeWidth, radius, horizontalOverlap, colors, layoutMode])\n\n return (\n <div\n ref={wrapperRef}\n className=\"serpentine-wrapper\"\n style={borderData?.wrapperStyle ?? { position: 'relative', boxSizing: 'border-box' }}\n data-testid=\"serpentine-wrapper\"\n >\n {borderData && (() => {\n const { class: className, style: styleStr, ...restSvgAttrs } = borderData.svgAttributes\n const style = typeof styleStr === 'string' ? cssStringToStyleObject(styleStr) : styleStr\n return (\n <svg\n data-testid=\"serpentine-svg\"\n className={className}\n style={style}\n {...restSvgAttrs}\n >\n {borderData.paths.map((pathAttributes, i) => (\n <path key={i} {...pathAttrsForReact(pathAttributes)} />\n ))}\n </svg>\n )\n })()}\n {children}\n </div>\n )\n}\n\nexport default SerpentineBorder\n"],"names":["DEFAULT_COLORS","resolveOverlapToPixels","horizontalOverlap","N","STROKE_WIDTH","totalBorderWidth","styleObjectToCss","obj","k","v","key","val","buildPathD","W","Y","R","COLORS","TOP_ARC_SHIFT","Y_OFFSET","O_TOTAL","BORDER_EXTRA","R1","RIGHT_EXTEND","n","parts","i","o","oj","r","rj","rj1","leftOffset","xLeft","rightExt","xRight","xLeftArc","xRightArc","xRightR1","yCurrTop","segs","t","yCurr","yNext","yExit","lastY","DEFAULT_SVG_CLASS","DEFAULTS","serpentineBorder","options","layoutMode","svgClassName","wrapperEl","measured","measureSections","TOTAL_BORDER_WIDTH","TOP_OFFSET","wrapperStyle","svgStyleObj","svgStyle","paths","totalHeight","totalWidth","viewBoxHeight","viewBoxMinX","viewBoxMinY","viewBoxStr","strokeCount","strokeWidth","excludeClassName","sectionEls","el","rect","baseWidth","cssStringToStyleObject","css","decl","colon","_","c","value","pathAttrsForReact","attrs","SerpentineBorder","children","radius","colors","wrapperRef","useRef","borderData","setBorderData","useState","useEffect","wrapper","measure","data","ro","jsxs","className","styleStr","restSvgAttrs","style","jsx","pathAttributes"],"mappings":"wIAAaA,EAAiB,CAAC,UAAW,SAAS,ECOnD,SAASC,EAAuBC,EAAmBC,EAAGC,EAAc,CAClE,GAAI,OAAOF,GAAsB,SAAU,OAAOA,EAClD,MAAMG,EAAmBF,EAAIC,EAC7B,OAAIF,IAAsB,cAAsBG,EAC5CH,IAAsB,kBAA0BG,EAAmB,EAChE,CACT,CAEA,SAASC,EAAiBC,EAAK,CAC7B,OAAO,OAAO,QAAQA,CAAG,EACtB,IAAI,CAAC,CAACC,EAAGC,CAAC,IAAM,CACf,MAAMC,EAAMF,EA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ants.js","../src/serpentineCore.js","../src/SerpentineBorder.jsx"],"sourcesContent":["export const DEFAULT_COLORS = ['#ffffff', '#000000']\n","/**\n * Vanilla JS core for serpentine border SVG generation.\n * Single export: call with measured dimensions and options to get everything needed to render.\n */\n\nimport { DEFAULT_COLORS } from './constants.js'\n\nfunction resolveOverflowToPixels(horizontalOverflow, N, STROKE_WIDTH) {\n if (typeof horizontalOverflow === 'number') return horizontalOverflow\n const totalBorderWidth = N * STROKE_WIDTH\n if (horizontalOverflow === 'borderWidth') return totalBorderWidth\n if (horizontalOverflow === 'halfBorderWidth') return totalBorderWidth / 2\n return 0\n}\n\nfunction styleObjectToCss(obj) {\n return Object.entries(obj)\n .map(([k, v]) => {\n const key = k.replace(/([A-Z])/g, '-$1').toLowerCase()\n const val = typeof v === 'number' && !Number.isNaN(v) ? `${v}px` : String(v)\n return `${key}: ${val}`\n })\n .join('; ')\n}\n\nfunction buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA) {\n const R1 = STROKE_WIDTH * (N - 1)\n const RIGHT_EXTEND = STROKE_WIDTH / 2\n const n = Y.length - 1\n const parts = []\n for (let i = 0; i < N; i++) {\n const o = i * STROKE_WIDTH\n const j = N - 1 - i\n const oj = j * STROKE_WIDTH\n const r = R - o\n const rj = R - oj\n const r1 = R1 - o\n const rj1 = R1 - oj\n\n const leftOffset = O_TOTAL - BORDER_EXTRA + RIGHT_EXTEND\n const xLeft = o - O_TOTAL + leftOffset\n const rightExt = BORDER_EXTRA\n const xRight = W + rightExt - oj - RIGHT_EXTEND\n const xLeftArc = xLeft + (R - o)\n const xRightArc = W + rightExt - R - RIGHT_EXTEND\n const xRightR1 = W + rightExt - R1 - RIGHT_EXTEND\n\n const yCurrTop = O_TOTAL + Y_OFFSET\n const segs = [\n `M ${xRight} ${yCurrTop - R1 - STROKE_WIDTH / 2 - TOP_ARC_SHIFT}`,\n `L ${xRight} ${yCurrTop - R1 - TOP_ARC_SHIFT}`,\n `A ${rj1} ${rj1} 0 0 1 ${xRightR1} ${yCurrTop - oj - TOP_ARC_SHIFT}`,\n `L ${xLeftArc} ${o + Y_OFFSET - TOP_ARC_SHIFT}`,\n `A ${r} ${r} 0 0 0 ${xLeft} ${R + Y_OFFSET - TOP_ARC_SHIFT}`,\n `L ${xLeft} ${R + Y_OFFSET}`,\n ]\n\n for (let t = 0; t < n - 1; t++) {\n const yCurr = Y[t + 1]\n const yNext = Y[t + 2]\n const yExit = yCurr + R - O_TOTAL + Y_OFFSET\n\n if (t % 2 === 0) {\n segs.push(`L ${xLeft} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeftArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`L ${xRightArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRight} ${yExit}`)\n segs.push(`L ${xRight} ${yNext - R + Y_OFFSET}`)\n } else {\n segs.push(`L ${xRight} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRightArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`L ${xLeftArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeft} ${yExit}`)\n segs.push(`L ${xLeft} ${yNext - R + Y_OFFSET}`)\n }\n }\n\n const lastY = Y[n]\n if ((n - 2) % 2 === 0) {\n segs.push(`L ${xRight} ${lastY}`)\n } else {\n segs.push(`L ${xLeft} ${lastY}`)\n }\n parts.push({\n d: segs.join(' '),\n stroke: COLORS[i % COLORS.length],\n 'stroke-width': STROKE_WIDTH,\n fill: 'none',\n })\n }\n return parts\n}\n\nconst DEFAULT_SVG_CLASS = 'serpentine-border-svg'\n\nconst DEFAULTS = {\n strokeCount: 5,\n strokeWidth: 8,\n radius: 50,\n horizontalOverflow: 0,\n layoutMode: 'border',\n}\n\n/**\n * Compute everything needed to render the serpentine border.\n * Accepts either (width + sectionBottomYs) for pure/custom use, or wrapperEl to measure from the DOM.\n * When using wrapperEl, returns null in non-DOM environments (e.g. SSR) or when measurement fails.\n *\n * @param {{\n * width?: number\n * sectionBottomYs?: number[]\n * wrapperEl?: HTMLElement\n * strokeCount?: number\n * strokeWidth?: number\n * radius?: number\n * horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'\n * colors?: string[]\n * layoutMode?: 'content' | 'border'\n * svgClassName?: string\n * }} options\n * @returns {{\n * wrapperStyle: Record<string, unknown>\n * svgAttributes: { class?: string, viewBox: string, style: string }\n * paths: Array<{ d: string, stroke: string, 'stroke-width': number, fill: string }>\n * } | null}\n */\nexport function serpentineBorder(options) {\n const N = options.strokeCount ?? DEFAULTS.strokeCount\n const STROKE_WIDTH = options.strokeWidth ?? DEFAULTS.strokeWidth\n const R = options.radius ?? DEFAULTS.radius\n const horizontalOverflow = options.horizontalOverflow ?? DEFAULTS.horizontalOverflow\n const COLORS = options.colors ?? DEFAULT_COLORS\n const layoutMode = options.layoutMode ?? DEFAULTS.layoutMode\n const svgClassName = options.svgClassName ?? DEFAULT_SVG_CLASS\n\n let W, Y\n if (options.wrapperEl != null) {\n const wrapperEl = options.wrapperEl\n const hasDOM = typeof document !== 'undefined' && typeof wrapperEl.getBoundingClientRect === 'function'\n if (!hasDOM) return null\n const measured = measureSections(wrapperEl, {\n layoutMode,\n horizontalOverflow,\n strokeCount: N,\n strokeWidth: STROKE_WIDTH,\n excludeClassName: svgClassName,\n })\n if (!measured) return null\n W = measured.width\n Y = measured.sectionBottomYs\n } else {\n if (options.width == null || options.sectionBottomYs == null) return null\n W = options.width\n Y = options.sectionBottomYs\n }\n\n const BORDER_EXTRA = resolveOverflowToPixels(horizontalOverflow, N, STROKE_WIDTH)\n const O_TOTAL = (N - 1) * STROKE_WIDTH\n const TOTAL_BORDER_WIDTH = N * STROKE_WIDTH\n const TOP_OFFSET = 2 * STROKE_WIDTH\n const Y_OFFSET = O_TOTAL / 2\n const TOP_ARC_SHIFT = ((N - 1) / 2) * STROKE_WIDTH + Y_OFFSET\n\n const wrapperStyle =\n layoutMode === 'border'\n ? {\n boxSizing: 'border-box',\n position: 'relative',\n marginTop: `${TOTAL_BORDER_WIDTH / 2}px`,\n ...(BORDER_EXTRA > 0 && {\n paddingLeft: `${BORDER_EXTRA}px`,\n paddingRight: `${BORDER_EXTRA}px`,\n }),\n }\n : {\n position: 'relative',\n boxSizing: 'border-box',\n }\n\n const svgStyleObj =\n layoutMode === 'border'\n ? {\n position: 'absolute',\n overflow: 'hidden',\n width: '100%',\n left: 0,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n : {\n position: 'absolute',\n overflow: 'hidden',\n width: `calc(100% + ${2 * BORDER_EXTRA}px)`,\n left: -BORDER_EXTRA,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n const svgStyle = styleObjectToCss(svgStyleObj)\n\n const paths = buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA)\n\n const totalHeight = Y[Y.length - 1] ?? 0\n const totalWidth = Math.max(1, W + 2 * BORDER_EXTRA)\n const viewBoxHeight = totalHeight + TOP_OFFSET + TOP_ARC_SHIFT\n const viewBoxMinX = BORDER_EXTRA > 0 ? -BORDER_EXTRA : 0\n const viewBoxMinY = -STROKE_WIDTH * 2 - TOP_ARC_SHIFT\n const viewBoxStr = `${viewBoxMinX} ${viewBoxMinY} ${totalWidth} ${viewBoxHeight}`\n\n return {\n wrapperStyle,\n svgAttributes: {\n class: svgClassName,\n viewBox: viewBoxStr,\n style: svgStyle,\n },\n paths,\n }\n}\n\n/**\n * Compute padding for each section so content does not overlap the border.\n * Returns an object with even, odd, and last: use for even-indexed sections, odd-indexed sections, and the last section respectively.\n *\n * @param {{\n * sectionCount: number\n * strokeCount: number\n * strokeWidth: number\n * horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'\n * }} options\n * @returns {{ even: { top: number, right: number, bottom: number, left: number }, odd: { top: number, right: number, bottom: number, left: number }, last: { top: number, right: number, bottom: number, left: number } }}\n */\nexport function getSectionsPadding(options) {\n const { sectionCount: n, strokeCount: N, strokeWidth: STROKE_WIDTH } = options\n const horizontalOverflow = options.horizontalOverflow ?? 0\n const TOTAL_BORDER_WIDTH = N * STROKE_WIDTH\n const BORDER_EXTRA = resolveOverflowToPixels(horizontalOverflow, N, STROKE_WIDTH)\n const halfBorderWidth = TOTAL_BORDER_WIDTH / 2\n const insetSide = TOTAL_BORDER_WIDTH - BORDER_EXTRA\n const even = { top: halfBorderWidth, right: 0, bottom: halfBorderWidth, left: insetSide }\n const odd = { top: halfBorderWidth, right: insetSide, bottom: halfBorderWidth, left: 0 }\n const lastIsEven = n > 0 && (n - 1) % 2 === 0\n const last = {\n top: halfBorderWidth,\n right: lastIsEven ? 0 : insetSide,\n bottom: 0,\n left: lastIsEven ? insetSide : 0,\n }\n return { even, odd, last }\n}\n\n/**\n * Measure wrapper and section elements to get width and section bottom Ys.\n * Children with the excludeClassName (default: same class used on the SVG by serpentineBorder) are excluded.\n * horizontalOverflow is resolved to pixels using strokeCount and strokeWidth.\n *\n * @param {HTMLElement} wrapperEl\n * @param {{\n * layoutMode: 'content' | 'border'\n * horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'\n * strokeCount: number\n * strokeWidth: number\n * excludeClassName?: string\n * }} options\n * @returns {{ width: number, sectionBottomYs: number[] } | null}\n */\nexport function measureSections(wrapperEl, options) {\n const { layoutMode, horizontalOverflow = 0, strokeCount, strokeWidth, excludeClassName = DEFAULT_SVG_CLASS } = options\n const BORDER_EXTRA = resolveOverflowToPixels(horizontalOverflow, strokeCount, strokeWidth)\n if (!wrapperEl) return null\n\n const sectionEls = excludeClassName\n ? Array.from(wrapperEl.children).filter((el) => !el.classList.contains(excludeClassName))\n : Array.from(wrapperEl.children)\n\n if (sectionEls.length === 0) return null\n\n const rect = wrapperEl.getBoundingClientRect()\n const baseWidth = rect.width\n\n const W =\n layoutMode === 'border'\n ? Math.max(1, baseWidth - 2 * BORDER_EXTRA)\n : Math.max(1, baseWidth)\n\n const Y = [0]\n for (let i = 0; i < sectionEls.length; i++) {\n const r = sectionEls[i].getBoundingClientRect()\n Y.push(r.top - rect.top + r.height)\n }\n\n return { width: W, sectionBottomYs: Y }\n}\n","import { useEffect, useRef, useState } from 'react'\nimport { measureSections, serpentineBorder } from './serpentineCore.js'\n\nfunction cssStringToStyleObject(css) {\n const obj = {}\n if (!css || typeof css !== 'string') return obj\n for (const decl of css.split(';')) {\n const colon = decl.indexOf(':')\n if (colon === -1) continue\n const key = decl.slice(0, colon).trim().replace(/-([a-z])/g, (_, c) => c.toUpperCase())\n const value = decl.slice(colon + 1).trim()\n if (key) obj[key] = value\n }\n return obj\n}\n\nfunction pathAttrsForReact(attrs) {\n return Object.fromEntries(\n Object.entries(attrs).map(([k, v]) => [k === 'stroke-width' ? 'strokeWidth' : k, v])\n )\n}\n\nfunction SerpentineBorder({\n children,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverflow,\n colors,\n layoutMode,\n}) {\n const wrapperRef = useRef(null)\n const [borderData, setBorderData] = useState(null)\n\n useEffect(() => {\n const wrapper = wrapperRef.current\n if (!wrapper) return\n\n const measure = () => {\n const measured = measureSections(wrapper, {\n layoutMode,\n horizontalOverflow,\n strokeCount,\n strokeWidth,\n })\n if (!measured) return\n\n const data = serpentineBorder({\n width: measured.width,\n sectionBottomYs: measured.sectionBottomYs,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverflow,\n colors,\n layoutMode,\n })\n setBorderData(data)\n }\n\n measure()\n const ro = new ResizeObserver(measure)\n ro.observe(wrapper)\n return () => ro.disconnect()\n }, [strokeCount, strokeWidth, radius, horizontalOverflow, colors, layoutMode])\n\n return (\n <div\n ref={wrapperRef}\n className=\"serpentine-wrapper\"\n style={borderData?.wrapperStyle ?? { position: 'relative', boxSizing: 'border-box' }}\n data-testid=\"serpentine-wrapper\"\n >\n {borderData && (() => {\n const { class: className, style: styleStr, ...restSvgAttrs } = borderData.svgAttributes\n const style = typeof styleStr === 'string' ? cssStringToStyleObject(styleStr) : styleStr\n return (\n <svg\n data-testid=\"serpentine-svg\"\n className={className}\n style={style}\n {...restSvgAttrs}\n >\n {borderData.paths.map((pathAttributes, i) => (\n <path key={i} {...pathAttrsForReact(pathAttributes)} />\n ))}\n </svg>\n )\n })()}\n {children}\n </div>\n )\n}\n\nexport default SerpentineBorder\n"],"names":["DEFAULT_COLORS","resolveOverflowToPixels","horizontalOverflow","N","STROKE_WIDTH","totalBorderWidth","styleObjectToCss","obj","k","v","key","val","buildPathD","W","Y","R","COLORS","TOP_ARC_SHIFT","Y_OFFSET","O_TOTAL","BORDER_EXTRA","R1","RIGHT_EXTEND","n","parts","i","o","oj","r","rj","rj1","leftOffset","xLeft","rightExt","xRight","xLeftArc","xRightArc","xRightR1","yCurrTop","segs","t","yCurr","yNext","yExit","lastY","DEFAULT_SVG_CLASS","DEFAULTS","serpentineBorder","options","layoutMode","svgClassName","wrapperEl","measured","measureSections","TOTAL_BORDER_WIDTH","TOP_OFFSET","wrapperStyle","svgStyleObj","svgStyle","paths","totalHeight","totalWidth","viewBoxHeight","viewBoxMinX","viewBoxMinY","viewBoxStr","getSectionsPadding","halfBorderWidth","insetSide","even","odd","lastIsEven","strokeCount","strokeWidth","excludeClassName","sectionEls","el","rect","baseWidth","cssStringToStyleObject","css","decl","colon","_","c","value","pathAttrsForReact","attrs","SerpentineBorder","children","radius","colors","wrapperRef","useRef","borderData","setBorderData","useState","useEffect","wrapper","measure","data","ro","jsxs","className","styleStr","restSvgAttrs","style","jsx","pathAttributes"],"mappings":"wIAAaA,EAAiB,CAAC,UAAW,SAAS,ECOnD,SAASC,EAAwBC,EAAoBC,EAAGC,EAAc,CACpE,GAAI,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,OAAAyF,EACA,WAAA1C,CAAA,CACD,EACD8C,EAAcK,CAAI,CACpB,EAEAD,EAAA,EACA,MAAME,EAAK,IAAI,eAAeF,CAAO,EACrC,OAAAE,EAAG,QAAQH,CAAO,EACX,IAAMG,EAAG,WAAA,CAClB,EAAG,CAAC7B,EAAaC,EAAaiB,EAAQxF,EAAoByF,EAAQ1C,CAAU,CAAC,EAG3EqD,EAAAA,KAAC,MAAA,CACC,IAAKV,EACL,UAAU,qBACV,OAAOE,GAAA,YAAAA,EAAY,eAAgB,CAAE,SAAU,WAAY,UAAW,YAAA,EACtE,cAAY,qBAEX,SAAA,CAAAA,IAAe,IAAM,CACpB,KAAM,CAAE,MAAOS,EAAW,MAAOC,EAAU,GAAGC,CAAA,EAAiBX,EAAW,cACpEY,EAAQ,OAAOF,GAAa,SAAWzB,EAAuByB,CAAQ,EAAIA,EAChF,OACEG,EAAAA,IAAC,MAAA,CACC,cAAY,iBACZ,UAAAJ,EACA,MAAAG,EACC,GAAGD,EAEH,SAAAX,EAAW,MAAM,IAAI,CAACc,EAAgBnF,IACrCkF,MAAC,OAAA,CAAc,GAAGrB,EAAkBsB,CAAc,CAAA,EAAvCnF,CAA0C,CACtD,CAAA,CAAA,CAGP,GAAA,EACCgE,CAAA,CAAA,CAAA,CAGP"}
@@ -1,75 +1,75 @@
1
- import { jsxs as Z, jsx as U } from "react/jsx-runtime";
2
- import { useRef as q, useState as J, useEffect as P } from "react";
3
- const Q = ["#ffffff", "#000000"];
4
- function X(t, s, e) {
1
+ import { jsxs as G, jsx as U } from "react/jsx-runtime";
2
+ import { useRef as P, useState as V, useEffect as Z } from "react";
3
+ const q = ["#ffffff", "#000000"];
4
+ function D(t, o, e) {
5
5
  if (typeof t == "number") return t;
6
- const n = s * e;
6
+ const n = o * e;
7
7
  return t === "borderWidth" ? n : t === "halfBorderWidth" ? n / 2 : 0;
8
8
  }
9
- function E(t) {
10
- return Object.entries(t).map(([s, e]) => {
11
- const n = s.replace(/([A-Z])/g, "-$1").toLowerCase(), i = typeof e == "number" && !Number.isNaN(e) ? `${e}px` : String(e);
9
+ function J(t) {
10
+ return Object.entries(t).map(([o, e]) => {
11
+ const n = o.replace(/([A-Z])/g, "-$1").toLowerCase(), i = typeof e == "number" && !Number.isNaN(e) ? `${e}px` : String(e);
12
12
  return `${n}: ${i}`;
13
13
  }).join("; ");
14
14
  }
15
- function H(t, s, e, n, i, g, u, o, c, f) {
16
- const r = i * (e - 1), a = i / 2, p = s.length - 1, l = [];
17
- for (let h = 0; h < e; h++) {
18
- const d = h * i, x = (e - 1 - h) * i, b = n - d, B = n - x, M = r - x, N = c - f + a, m = d - c + N, L = f, y = t + L - x - a, j = m + (n - d), A = t + L - n - a, W = t + L - r - a, w = c + o, $ = [
19
- `M ${y} ${w - r - i / 2 - u}`,
20
- `L ${y} ${w - r - u}`,
21
- `A ${M} ${M} 0 0 1 ${W} ${w - x - u}`,
22
- `L ${j} ${d + o - u}`,
23
- `A ${b} ${b} 0 0 0 ${m} ${n + o - u}`,
24
- `L ${m} ${n + o}`
15
+ function Q(t, o, e, n, i, p, u, s, r, h) {
16
+ const c = i * (e - 1), a = i / 2, $ = o.length - 1, l = [];
17
+ for (let f = 0; f < e; f++) {
18
+ const d = f * i, x = (e - 1 - f) * i, b = n - d, B = n - x, M = c - x, N = r - h + a, m = d - r + N, L = h, w = t + L - x - a, A = m + (n - d), j = t + L - n - a, W = t + L - c - a, v = r + s, g = [
19
+ `M ${w} ${v - c - i / 2 - u}`,
20
+ `L ${w} ${v - c - u}`,
21
+ `A ${M} ${M} 0 0 1 ${W} ${v - x - u}`,
22
+ `L ${A} ${d + s - u}`,
23
+ `A ${b} ${b} 0 0 0 ${m} ${n + s - u}`,
24
+ `L ${m} ${n + s}`
25
25
  ];
26
- for (let C = 0; C < p - 1; C++) {
27
- const v = s[C + 1], R = s[C + 2], S = v + n - c + o;
28
- C % 2 === 0 ? ($.push(`L ${m} ${v - n + o}`), $.push(`A ${b} ${b} 0 0 0 ${j} ${v - d + o}`), $.push(`L ${A} ${v - d + o}`), $.push(`A ${B} ${B} 0 0 1 ${y} ${S}`), $.push(`L ${y} ${R - n + o}`)) : ($.push(`L ${y} ${v - n + o}`), $.push(`A ${B} ${B} 0 0 1 ${A} ${v - x + o}`), $.push(`L ${j} ${v - x + o}`), $.push(`A ${b} ${b} 0 0 0 ${m} ${S}`), $.push(`L ${m} ${R - n + o}`));
26
+ for (let C = 0; C < $ - 1; C++) {
27
+ const y = o[C + 1], S = o[C + 2], E = y + n - r + s;
28
+ C % 2 === 0 ? (g.push(`L ${m} ${y - n + s}`), g.push(`A ${b} ${b} 0 0 0 ${A} ${y - d + s}`), g.push(`L ${j} ${y - d + s}`), g.push(`A ${B} ${B} 0 0 1 ${w} ${E}`), g.push(`L ${w} ${S - n + s}`)) : (g.push(`L ${w} ${y - n + s}`), g.push(`A ${B} ${B} 0 0 1 ${j} ${y - x + s}`), g.push(`L ${A} ${y - x + s}`), g.push(`A ${b} ${b} 0 0 0 ${m} ${E}`), g.push(`L ${m} ${S - n + s}`));
29
29
  }
30
- const z = s[p];
31
- (p - 2) % 2 === 0 ? $.push(`L ${y} ${z}`) : $.push(`L ${m} ${z}`), l.push({
32
- d: $.join(" "),
33
- stroke: g[h % g.length],
30
+ const z = o[$];
31
+ ($ - 2) % 2 === 0 ? g.push(`L ${w} ${z}`) : g.push(`L ${m} ${z}`), l.push({
32
+ d: g.join(" "),
33
+ stroke: p[f % p.length],
34
34
  "stroke-width": i,
35
35
  fill: "none"
36
36
  });
37
37
  }
38
38
  return l;
39
39
  }
40
- const G = "serpentine-border-svg", k = {
40
+ const X = "serpentine-border-svg", k = {
41
41
  strokeCount: 5,
42
42
  strokeWidth: 8,
43
43
  radius: 50,
44
- horizontalOverlap: 0,
44
+ horizontalOverflow: 0,
45
45
  layoutMode: "border"
46
46
  };
47
- function O(t) {
48
- const s = t.strokeCount ?? k.strokeCount, e = t.strokeWidth ?? k.strokeWidth, n = t.radius ?? k.radius, i = t.horizontalOverlap ?? k.horizontalOverlap, g = t.colors ?? Q, u = t.layoutMode ?? k.layoutMode, o = t.svgClassName ?? G;
49
- let c, f;
47
+ function H(t) {
48
+ const o = t.strokeCount ?? k.strokeCount, e = t.strokeWidth ?? k.strokeWidth, n = t.radius ?? k.radius, i = t.horizontalOverflow ?? k.horizontalOverflow, p = t.colors ?? q, u = t.layoutMode ?? k.layoutMode, s = t.svgClassName ?? X;
49
+ let r, h;
50
50
  if (t.wrapperEl != null) {
51
- const A = t.wrapperEl;
52
- if (!(typeof document < "u" && typeof A.getBoundingClientRect == "function")) return null;
53
- const w = V(A, {
51
+ const j = t.wrapperEl;
52
+ if (!(typeof document < "u" && typeof j.getBoundingClientRect == "function")) return null;
53
+ const v = O(j, {
54
54
  layoutMode: u,
55
- horizontalOverlap: i,
56
- strokeCount: s,
55
+ horizontalOverflow: i,
56
+ strokeCount: o,
57
57
  strokeWidth: e,
58
- excludeClassName: o
58
+ excludeClassName: s
59
59
  });
60
- if (!w) return null;
61
- c = w.width, f = w.sectionBottomYs;
60
+ if (!v) return null;
61
+ r = v.width, h = v.sectionBottomYs;
62
62
  } else {
63
63
  if (t.width == null || t.sectionBottomYs == null) return null;
64
- c = t.width, f = t.sectionBottomYs;
64
+ r = t.width, h = t.sectionBottomYs;
65
65
  }
66
- const r = X(i, s, e), a = (s - 1) * e, p = s * e, l = 2 * e, h = a / 2, d = (s - 1) / 2 * e + h, D = u === "border" ? {
66
+ const c = D(i, o, e), a = (o - 1) * e, $ = o * e, l = 2 * e, f = a / 2, d = (o - 1) / 2 * e + f, R = u === "border" ? {
67
67
  boxSizing: "border-box",
68
68
  position: "relative",
69
- marginTop: `${p / 2}px`,
70
- ...r > 0 && {
71
- paddingLeft: `${r}px`,
72
- paddingRight: `${r}px`
69
+ marginTop: `${$ / 2}px`,
70
+ ...c > 0 && {
71
+ paddingLeft: `${c}px`,
72
+ paddingRight: `${c}px`
73
73
  }
74
74
  } : {
75
75
  position: "relative",
@@ -84,103 +84,112 @@ function O(t) {
84
84
  } : {
85
85
  position: "absolute",
86
86
  overflow: "hidden",
87
- width: `calc(100% + ${2 * r}px)`,
88
- left: -r,
87
+ width: `calc(100% + ${2 * c}px)`,
88
+ left: -c,
89
89
  top: -(l + d),
90
90
  height: `calc(100% + ${l + d}px)`
91
- }, b = E(x), B = H(c, f, s, n, e, g, d, h, a, r), M = f[f.length - 1] ?? 0, N = Math.max(1, c + 2 * r), m = M + l + d, L = r > 0 ? -r : 0, y = -e * 2 - d, j = `${L} ${y} ${N} ${m}`;
91
+ }, b = J(x), B = Q(r, h, o, n, e, p, d, f, a, c), M = h[h.length - 1] ?? 0, N = Math.max(1, r + 2 * c), m = M + l + d, L = c > 0 ? -c : 0, w = -e * 2 - d, A = `${L} ${w} ${N} ${m}`;
92
92
  return {
93
- wrapperStyle: D,
93
+ wrapperStyle: R,
94
94
  svgAttributes: {
95
- class: o,
96
- viewBox: j,
95
+ class: s,
96
+ viewBox: A,
97
97
  style: b
98
98
  },
99
99
  paths: B
100
100
  };
101
101
  }
102
- function V(t, s) {
103
- const { layoutMode: e, horizontalOverlap: n = 0, strokeCount: i, strokeWidth: g, excludeClassName: u = G } = s, o = X(n, i, g);
102
+ function _(t) {
103
+ const { sectionCount: o, strokeCount: e, strokeWidth: n } = t, i = t.horizontalOverflow ?? 0, p = e * n, u = D(i, e, n), s = p / 2, r = p - u, h = { top: s, right: 0, bottom: s, left: r }, c = { top: s, right: r, bottom: s, left: 0 }, a = o > 0 && (o - 1) % 2 === 0;
104
+ return { even: h, odd: c, last: {
105
+ top: s,
106
+ right: a ? 0 : r,
107
+ bottom: 0,
108
+ left: a ? r : 0
109
+ } };
110
+ }
111
+ function O(t, o) {
112
+ const { layoutMode: e, horizontalOverflow: n = 0, strokeCount: i, strokeWidth: p, excludeClassName: u = X } = o, s = D(n, i, p);
104
113
  if (!t) return null;
105
- const c = u ? Array.from(t.children).filter((l) => !l.classList.contains(u)) : Array.from(t.children);
106
- if (c.length === 0) return null;
107
- const f = t.getBoundingClientRect(), r = f.width, a = e === "border" ? Math.max(1, r - 2 * o) : Math.max(1, r), p = [0];
108
- for (let l = 0; l < c.length; l++) {
109
- const h = c[l].getBoundingClientRect();
110
- p.push(h.top - f.top + h.height);
114
+ const r = u ? Array.from(t.children).filter((l) => !l.classList.contains(u)) : Array.from(t.children);
115
+ if (r.length === 0) return null;
116
+ const h = t.getBoundingClientRect(), c = h.width, a = e === "border" ? Math.max(1, c - 2 * s) : Math.max(1, c), $ = [0];
117
+ for (let l = 0; l < r.length; l++) {
118
+ const f = r[l].getBoundingClientRect();
119
+ $.push(f.top - h.top + f.height);
111
120
  }
112
- return { width: a, sectionBottomYs: p };
121
+ return { width: a, sectionBottomYs: $ };
113
122
  }
114
- function K(t) {
115
- const s = {};
116
- if (!t || typeof t != "string") return s;
123
+ function I(t) {
124
+ const o = {};
125
+ if (!t || typeof t != "string") return o;
117
126
  for (const e of t.split(";")) {
118
127
  const n = e.indexOf(":");
119
128
  if (n === -1) continue;
120
- const i = e.slice(0, n).trim().replace(/-([a-z])/g, (u, o) => o.toUpperCase()), g = e.slice(n + 1).trim();
121
- i && (s[i] = g);
129
+ const i = e.slice(0, n).trim().replace(/-([a-z])/g, (u, s) => s.toUpperCase()), p = e.slice(n + 1).trim();
130
+ i && (o[i] = p);
122
131
  }
123
- return s;
132
+ return o;
124
133
  }
125
- function Y(t) {
134
+ function K(t) {
126
135
  return Object.fromEntries(
127
- Object.entries(t).map(([s, e]) => [s === "stroke-width" ? "strokeWidth" : s, e])
136
+ Object.entries(t).map(([o, e]) => [o === "stroke-width" ? "strokeWidth" : o, e])
128
137
  );
129
138
  }
130
- function _({
139
+ function F({
131
140
  children: t,
132
- strokeCount: s,
141
+ strokeCount: o,
133
142
  strokeWidth: e,
134
143
  radius: n,
135
- horizontalOverlap: i,
136
- colors: g,
144
+ horizontalOverflow: i,
145
+ colors: p,
137
146
  layoutMode: u
138
147
  }) {
139
- const o = q(null), [c, f] = J(null);
140
- return P(() => {
141
- const r = o.current;
142
- if (!r) return;
148
+ const s = P(null), [r, h] = V(null);
149
+ return Z(() => {
150
+ const c = s.current;
151
+ if (!c) return;
143
152
  const a = () => {
144
- const l = V(r, {
153
+ const l = O(c, {
145
154
  layoutMode: u,
146
- horizontalOverlap: i,
147
- strokeCount: s,
155
+ horizontalOverflow: i,
156
+ strokeCount: o,
148
157
  strokeWidth: e
149
158
  });
150
159
  if (!l) return;
151
- const h = O({
160
+ const f = H({
152
161
  width: l.width,
153
162
  sectionBottomYs: l.sectionBottomYs,
154
- strokeCount: s,
163
+ strokeCount: o,
155
164
  strokeWidth: e,
156
165
  radius: n,
157
- horizontalOverlap: i,
158
- colors: g,
166
+ horizontalOverflow: i,
167
+ colors: p,
159
168
  layoutMode: u
160
169
  });
161
- f(h);
170
+ h(f);
162
171
  };
163
172
  a();
164
- const p = new ResizeObserver(a);
165
- return p.observe(r), () => p.disconnect();
166
- }, [s, e, n, i, g, u]), /* @__PURE__ */ Z(
173
+ const $ = new ResizeObserver(a);
174
+ return $.observe(c), () => $.disconnect();
175
+ }, [o, e, n, i, p, u]), /* @__PURE__ */ G(
167
176
  "div",
168
177
  {
169
- ref: o,
178
+ ref: s,
170
179
  className: "serpentine-wrapper",
171
- style: (c == null ? void 0 : c.wrapperStyle) ?? { position: "relative", boxSizing: "border-box" },
180
+ style: (r == null ? void 0 : r.wrapperStyle) ?? { position: "relative", boxSizing: "border-box" },
172
181
  "data-testid": "serpentine-wrapper",
173
182
  children: [
174
- c && (() => {
175
- const { class: r, style: a, ...p } = c.svgAttributes, l = typeof a == "string" ? K(a) : a;
183
+ r && (() => {
184
+ const { class: c, style: a, ...$ } = r.svgAttributes, l = typeof a == "string" ? I(a) : a;
176
185
  return /* @__PURE__ */ U(
177
186
  "svg",
178
187
  {
179
188
  "data-testid": "serpentine-svg",
180
- className: r,
189
+ className: c,
181
190
  style: l,
182
- ...p,
183
- children: c.paths.map((h, d) => /* @__PURE__ */ U("path", { ...Y(h) }, d))
191
+ ...$,
192
+ children: r.paths.map((f, d) => /* @__PURE__ */ U("path", { ...K(f) }, d))
184
193
  }
185
194
  );
186
195
  })(),
@@ -190,7 +199,8 @@ function _({
190
199
  );
191
200
  }
192
201
  export {
193
- _ as SerpentineBorder,
194
- O as serpentineBorder
202
+ F as SerpentineBorder,
203
+ _ as getSectionsPadding,
204
+ H as serpentineBorder
195
205
  };
196
206
  //# sourceMappingURL=serpentine-border.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serpentine-border.js","sources":["../src/constants.js","../src/serpentineCore.js","../src/SerpentineBorder.jsx"],"sourcesContent":["export const DEFAULT_COLORS = ['#ffffff', '#000000']\n","/**\n * Vanilla JS core for serpentine border SVG generation.\n * Single export: call with measured dimensions and options to get everything needed to render.\n */\n\nimport { DEFAULT_COLORS } from './constants.js'\n\nfunction resolveOverlapToPixels(horizontalOverlap, N, STROKE_WIDTH) {\n if (typeof horizontalOverlap === 'number') return horizontalOverlap\n const totalBorderWidth = N * STROKE_WIDTH\n if (horizontalOverlap === 'borderWidth') return totalBorderWidth\n if (horizontalOverlap === 'halfBorderWidth') return totalBorderWidth / 2\n return 0\n}\n\nfunction styleObjectToCss(obj) {\n return Object.entries(obj)\n .map(([k, v]) => {\n const key = k.replace(/([A-Z])/g, '-$1').toLowerCase()\n const val = typeof v === 'number' && !Number.isNaN(v) ? `${v}px` : String(v)\n return `${key}: ${val}`\n })\n .join('; ')\n}\n\nfunction buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA) {\n const R1 = STROKE_WIDTH * (N - 1)\n const RIGHT_EXTEND = STROKE_WIDTH / 2\n const n = Y.length - 1\n const parts = []\n for (let i = 0; i < N; i++) {\n const o = i * STROKE_WIDTH\n const j = N - 1 - i\n const oj = j * STROKE_WIDTH\n const r = R - o\n const rj = R - oj\n const r1 = R1 - o\n const rj1 = R1 - oj\n\n const leftOffset = O_TOTAL - BORDER_EXTRA + RIGHT_EXTEND\n const xLeft = o - O_TOTAL + leftOffset\n const rightExt = BORDER_EXTRA\n const xRight = W + rightExt - oj - RIGHT_EXTEND\n const xLeftArc = xLeft + (R - o)\n const xRightArc = W + rightExt - R - RIGHT_EXTEND\n const xRightR1 = W + rightExt - R1 - RIGHT_EXTEND\n\n const yCurrTop = O_TOTAL + Y_OFFSET\n const segs = [\n `M ${xRight} ${yCurrTop - R1 - STROKE_WIDTH / 2 - TOP_ARC_SHIFT}`,\n `L ${xRight} ${yCurrTop - R1 - TOP_ARC_SHIFT}`,\n `A ${rj1} ${rj1} 0 0 1 ${xRightR1} ${yCurrTop - oj - TOP_ARC_SHIFT}`,\n `L ${xLeftArc} ${o + Y_OFFSET - TOP_ARC_SHIFT}`,\n `A ${r} ${r} 0 0 0 ${xLeft} ${R + Y_OFFSET - TOP_ARC_SHIFT}`,\n `L ${xLeft} ${R + Y_OFFSET}`,\n ]\n\n for (let t = 0; t < n - 1; t++) {\n const yCurr = Y[t + 1]\n const yNext = Y[t + 2]\n const yExit = yCurr + R - O_TOTAL + Y_OFFSET\n\n if (t % 2 === 0) {\n segs.push(`L ${xLeft} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeftArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`L ${xRightArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRight} ${yExit}`)\n segs.push(`L ${xRight} ${yNext - R + Y_OFFSET}`)\n } else {\n segs.push(`L ${xRight} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRightArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`L ${xLeftArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeft} ${yExit}`)\n segs.push(`L ${xLeft} ${yNext - R + Y_OFFSET}`)\n }\n }\n\n const lastY = Y[n]\n if ((n - 2) % 2 === 0) {\n segs.push(`L ${xRight} ${lastY}`)\n } else {\n segs.push(`L ${xLeft} ${lastY}`)\n }\n parts.push({\n d: segs.join(' '),\n stroke: COLORS[i % COLORS.length],\n 'stroke-width': STROKE_WIDTH,\n fill: 'none',\n })\n }\n return parts\n}\n\nconst DEFAULT_SVG_CLASS = 'serpentine-border-svg'\n\nconst DEFAULTS = {\n strokeCount: 5,\n strokeWidth: 8,\n radius: 50,\n horizontalOverlap: 0,\n layoutMode: 'border',\n}\n\n/**\n * Compute everything needed to render the serpentine border.\n * Accepts either (width + sectionBottomYs) for pure/custom use, or wrapperEl to measure from the DOM.\n * When using wrapperEl, returns null in non-DOM environments (e.g. SSR) or when measurement fails.\n *\n * @param {{\n * width?: number\n * sectionBottomYs?: number[]\n * wrapperEl?: HTMLElement\n * strokeCount?: number\n * strokeWidth?: number\n * radius?: number\n * horizontalOverlap?: number | 'borderWidth' | 'halfBorderWidth'\n * colors?: string[]\n * layoutMode?: 'content' | 'border'\n * svgClassName?: string\n * }} options\n * @returns {{\n * wrapperStyle: Record<string, unknown>\n * svgAttributes: { class?: string, viewBox: string, style: string }\n * paths: Array<{ d: string, stroke: string, 'stroke-width': number, fill: string }>\n * } | null}\n */\nexport function serpentineBorder(options) {\n const N = options.strokeCount ?? DEFAULTS.strokeCount\n const STROKE_WIDTH = options.strokeWidth ?? DEFAULTS.strokeWidth\n const R = options.radius ?? DEFAULTS.radius\n const horizontalOverlap = options.horizontalOverlap ?? DEFAULTS.horizontalOverlap\n const COLORS = options.colors ?? DEFAULT_COLORS\n const layoutMode = options.layoutMode ?? DEFAULTS.layoutMode\n const svgClassName = options.svgClassName ?? DEFAULT_SVG_CLASS\n\n let W, Y\n if (options.wrapperEl != null) {\n const wrapperEl = options.wrapperEl\n const hasDOM = typeof document !== 'undefined' && typeof wrapperEl.getBoundingClientRect === 'function'\n if (!hasDOM) return null\n const measured = measureSections(wrapperEl, {\n layoutMode,\n horizontalOverlap,\n strokeCount: N,\n strokeWidth: STROKE_WIDTH,\n excludeClassName: svgClassName,\n })\n if (!measured) return null\n W = measured.width\n Y = measured.sectionBottomYs\n } else {\n if (options.width == null || options.sectionBottomYs == null) return null\n W = options.width\n Y = options.sectionBottomYs\n }\n\n const BORDER_EXTRA = resolveOverlapToPixels(horizontalOverlap, N, STROKE_WIDTH)\n const O_TOTAL = (N - 1) * STROKE_WIDTH\n const TOTAL_BORDER_WIDTH = N * STROKE_WIDTH\n const TOP_OFFSET = 2 * STROKE_WIDTH\n const Y_OFFSET = O_TOTAL / 2\n const TOP_ARC_SHIFT = ((N - 1) / 2) * STROKE_WIDTH + Y_OFFSET\n\n const wrapperStyle =\n layoutMode === 'border'\n ? {\n boxSizing: 'border-box',\n position: 'relative',\n marginTop: `${TOTAL_BORDER_WIDTH / 2}px`,\n ...(BORDER_EXTRA > 0 && {\n paddingLeft: `${BORDER_EXTRA}px`,\n paddingRight: `${BORDER_EXTRA}px`,\n }),\n }\n : {\n position: 'relative',\n boxSizing: 'border-box',\n }\n\n const svgStyleObj =\n layoutMode === 'border'\n ? {\n position: 'absolute',\n overflow: 'hidden',\n width: '100%',\n left: 0,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n : {\n position: 'absolute',\n overflow: 'hidden',\n width: `calc(100% + ${2 * BORDER_EXTRA}px)`,\n left: -BORDER_EXTRA,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n const svgStyle = styleObjectToCss(svgStyleObj)\n\n const paths = buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA)\n\n const totalHeight = Y[Y.length - 1] ?? 0\n const totalWidth = Math.max(1, W + 2 * BORDER_EXTRA)\n const viewBoxHeight = totalHeight + TOP_OFFSET + TOP_ARC_SHIFT\n const viewBoxMinX = BORDER_EXTRA > 0 ? -BORDER_EXTRA : 0\n const viewBoxMinY = -STROKE_WIDTH * 2 - TOP_ARC_SHIFT\n const viewBoxStr = `${viewBoxMinX} ${viewBoxMinY} ${totalWidth} ${viewBoxHeight}`\n\n return {\n wrapperStyle,\n svgAttributes: {\n class: svgClassName,\n viewBox: viewBoxStr,\n style: svgStyle,\n },\n paths,\n }\n}\n\n/**\n * Measure wrapper and section elements to get width and section bottom Ys.\n * Children with the excludeClassName (default: same class used on the SVG by serpentineBorder) are excluded.\n * horizontalOverlap is resolved to pixels using strokeCount and strokeWidth.\n *\n * @param {HTMLElement} wrapperEl\n * @param {{\n * layoutMode: 'content' | 'border'\n * horizontalOverlap?: number | 'borderWidth' | 'halfBorderWidth'\n * strokeCount: number\n * strokeWidth: number\n * excludeClassName?: string\n * }} options\n * @returns {{ width: number, sectionBottomYs: number[] } | null}\n */\nexport function measureSections(wrapperEl, options) {\n const { layoutMode, horizontalOverlap = 0, strokeCount, strokeWidth, excludeClassName = DEFAULT_SVG_CLASS } = options\n const BORDER_EXTRA = resolveOverlapToPixels(horizontalOverlap, strokeCount, strokeWidth)\n if (!wrapperEl) return null\n\n const sectionEls = excludeClassName\n ? Array.from(wrapperEl.children).filter((el) => !el.classList.contains(excludeClassName))\n : Array.from(wrapperEl.children)\n\n if (sectionEls.length === 0) return null\n\n const rect = wrapperEl.getBoundingClientRect()\n const baseWidth = rect.width\n\n const W =\n layoutMode === 'border'\n ? Math.max(1, baseWidth - 2 * BORDER_EXTRA)\n : Math.max(1, baseWidth)\n\n const Y = [0]\n for (let i = 0; i < sectionEls.length; i++) {\n const r = sectionEls[i].getBoundingClientRect()\n Y.push(r.top - rect.top + r.height)\n }\n\n return { width: W, sectionBottomYs: Y }\n}\n","import { useEffect, useRef, useState } from 'react'\nimport { measureSections, serpentineBorder } from './serpentineCore.js'\n\nfunction cssStringToStyleObject(css) {\n const obj = {}\n if (!css || typeof css !== 'string') return obj\n for (const decl of css.split(';')) {\n const colon = decl.indexOf(':')\n if (colon === -1) continue\n const key = decl.slice(0, colon).trim().replace(/-([a-z])/g, (_, c) => c.toUpperCase())\n const value = decl.slice(colon + 1).trim()\n if (key) obj[key] = value\n }\n return obj\n}\n\nfunction pathAttrsForReact(attrs) {\n return Object.fromEntries(\n Object.entries(attrs).map(([k, v]) => [k === 'stroke-width' ? 'strokeWidth' : k, v])\n )\n}\n\nfunction SerpentineBorder({\n children,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverlap,\n colors,\n layoutMode,\n}) {\n const wrapperRef = useRef(null)\n const [borderData, setBorderData] = useState(null)\n\n useEffect(() => {\n const wrapper = wrapperRef.current\n if (!wrapper) return\n\n const measure = () => {\n const measured = measureSections(wrapper, {\n layoutMode,\n horizontalOverlap,\n strokeCount,\n strokeWidth,\n })\n if (!measured) return\n\n const data = serpentineBorder({\n width: measured.width,\n sectionBottomYs: measured.sectionBottomYs,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverlap,\n colors,\n layoutMode,\n })\n setBorderData(data)\n }\n\n measure()\n const ro = new ResizeObserver(measure)\n ro.observe(wrapper)\n return () => ro.disconnect()\n }, [strokeCount, strokeWidth, radius, horizontalOverlap, colors, layoutMode])\n\n return (\n <div\n ref={wrapperRef}\n className=\"serpentine-wrapper\"\n style={borderData?.wrapperStyle ?? { position: 'relative', boxSizing: 'border-box' }}\n data-testid=\"serpentine-wrapper\"\n >\n {borderData && (() => {\n const { class: className, style: styleStr, ...restSvgAttrs } = borderData.svgAttributes\n const style = typeof styleStr === 'string' ? cssStringToStyleObject(styleStr) : styleStr\n return (\n <svg\n data-testid=\"serpentine-svg\"\n className={className}\n style={style}\n {...restSvgAttrs}\n >\n {borderData.paths.map((pathAttributes, i) => (\n <path key={i} {...pathAttrsForReact(pathAttributes)} />\n ))}\n </svg>\n )\n })()}\n {children}\n </div>\n )\n}\n\nexport default SerpentineBorder\n"],"names":["DEFAULT_COLORS","resolveOverlapToPixels","horizontalOverlap","N","STROKE_WIDTH","totalBorderWidth","styleObjectToCss","obj","k","v","key","val","buildPathD","W","Y","R","COLORS","TOP_ARC_SHIFT","Y_OFFSET","O_TOTAL","BORDER_EXTRA","R1","RIGHT_EXTEND","n","parts","i","o","oj","r","rj","rj1","leftOffset","xLeft","rightExt","xRight","xLeftArc","xRightArc","xRightR1","yCurrTop","segs","t","yCurr","yNext","yExit","lastY","DEFAULT_SVG_CLASS","DEFAULTS","serpentineBorder","options","layoutMode","svgClassName","wrapperEl","measured","measureSections","TOTAL_BORDER_WIDTH","TOP_OFFSET","wrapperStyle","svgStyleObj","svgStyle","paths","totalHeight","totalWidth","viewBoxHeight","viewBoxMinX","viewBoxMinY","viewBoxStr","strokeCount","strokeWidth","excludeClassName","sectionEls","el","rect","baseWidth","cssStringToStyleObject","css","decl","colon","_","c","value","pathAttrsForReact","attrs","SerpentineBorder","children","radius","colors","wrapperRef","useRef","borderData","setBorderData","useState","useEffect","wrapper","measure","data","ro","jsxs","className","styleStr","restSvgAttrs","style","jsx","pathAttributes"],"mappings":";;AAAO,MAAMA,IAAiB,CAAC,WAAW,SAAS;ACOnD,SAASC,EAAuBC,GAAmBC,GAAGC,GAAc;AAClE,MAAI,OAAOF,KAAsB,SAAU,QAAOA;AAClD,QAAMG,IAAmBF,IAAIC;AAC7B,SAAIF,MAAsB,gBAAsBG,IAC5CH,MAAsB,oBAA0BG,IAAmB,IAChE;AACT;AAEA,SAASC,EAAiBC,GAAK;AAC7B,SAAO,OAAO,QAAQA,CAAG,EACtB,IAAI,CAAC,CAACC,GAAGC,CAAC,MAAM;AACf,UAAMC,IAAMF,EAAE,QAAQ,YAAY,KAAK,EAAE,YAAW,GAC9CG,IAAM,OAAOF,KAAM,YAAY,CAAC,OAAO,MAAMA,CAAC,IAAI,GAAGA,CAAC,OAAO,OAAOA,CAAC;AAC3E,WAAO,GAAGC,CAAG,KAAKC,CAAG;AAAA,EACvB,CAAC,EACA,KAAK,IAAI;AACd;AAEA,SAASC,EAAWC,GAAGC,GAAGX,GAAGY,GAAGX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AAQ,OAAOF,KAAa,WAAWzB,EAAuByB,CAAQ,IAAIA;AAChF,iBACE,gBAAAG;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,eAAY;AAAA,cACZ,WAAAJ;AAAA,cACA,OAAAG;AAAA,cACC,GAAGD;AAAA,cAEH,UAAAX,EAAW,MAAM,IAAI,CAACc,GAAgB7E,MACrC,gBAAA4E,EAAC,QAAA,EAAc,GAAGrB,EAAkBsB,CAAc,EAAA,GAAvC7E,CAA0C,CACtD;AAAA,YAAA;AAAA,UAAA;AAAA,QAGP,GAAA;AAAA,QACC0D;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"serpentine-border.js","sources":["../src/constants.js","../src/serpentineCore.js","../src/SerpentineBorder.jsx"],"sourcesContent":["export const DEFAULT_COLORS = ['#ffffff', '#000000']\n","/**\n * Vanilla JS core for serpentine border SVG generation.\n * Single export: call with measured dimensions and options to get everything needed to render.\n */\n\nimport { DEFAULT_COLORS } from './constants.js'\n\nfunction resolveOverflowToPixels(horizontalOverflow, N, STROKE_WIDTH) {\n if (typeof horizontalOverflow === 'number') return horizontalOverflow\n const totalBorderWidth = N * STROKE_WIDTH\n if (horizontalOverflow === 'borderWidth') return totalBorderWidth\n if (horizontalOverflow === 'halfBorderWidth') return totalBorderWidth / 2\n return 0\n}\n\nfunction styleObjectToCss(obj) {\n return Object.entries(obj)\n .map(([k, v]) => {\n const key = k.replace(/([A-Z])/g, '-$1').toLowerCase()\n const val = typeof v === 'number' && !Number.isNaN(v) ? `${v}px` : String(v)\n return `${key}: ${val}`\n })\n .join('; ')\n}\n\nfunction buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA) {\n const R1 = STROKE_WIDTH * (N - 1)\n const RIGHT_EXTEND = STROKE_WIDTH / 2\n const n = Y.length - 1\n const parts = []\n for (let i = 0; i < N; i++) {\n const o = i * STROKE_WIDTH\n const j = N - 1 - i\n const oj = j * STROKE_WIDTH\n const r = R - o\n const rj = R - oj\n const r1 = R1 - o\n const rj1 = R1 - oj\n\n const leftOffset = O_TOTAL - BORDER_EXTRA + RIGHT_EXTEND\n const xLeft = o - O_TOTAL + leftOffset\n const rightExt = BORDER_EXTRA\n const xRight = W + rightExt - oj - RIGHT_EXTEND\n const xLeftArc = xLeft + (R - o)\n const xRightArc = W + rightExt - R - RIGHT_EXTEND\n const xRightR1 = W + rightExt - R1 - RIGHT_EXTEND\n\n const yCurrTop = O_TOTAL + Y_OFFSET\n const segs = [\n `M ${xRight} ${yCurrTop - R1 - STROKE_WIDTH / 2 - TOP_ARC_SHIFT}`,\n `L ${xRight} ${yCurrTop - R1 - TOP_ARC_SHIFT}`,\n `A ${rj1} ${rj1} 0 0 1 ${xRightR1} ${yCurrTop - oj - TOP_ARC_SHIFT}`,\n `L ${xLeftArc} ${o + Y_OFFSET - TOP_ARC_SHIFT}`,\n `A ${r} ${r} 0 0 0 ${xLeft} ${R + Y_OFFSET - TOP_ARC_SHIFT}`,\n `L ${xLeft} ${R + Y_OFFSET}`,\n ]\n\n for (let t = 0; t < n - 1; t++) {\n const yCurr = Y[t + 1]\n const yNext = Y[t + 2]\n const yExit = yCurr + R - O_TOTAL + Y_OFFSET\n\n if (t % 2 === 0) {\n segs.push(`L ${xLeft} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeftArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`L ${xRightArc} ${yCurr - o + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRight} ${yExit}`)\n segs.push(`L ${xRight} ${yNext - R + Y_OFFSET}`)\n } else {\n segs.push(`L ${xRight} ${yCurr - R + Y_OFFSET}`)\n segs.push(`A ${rj} ${rj} 0 0 1 ${xRightArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`L ${xLeftArc} ${yCurr - oj + Y_OFFSET}`)\n segs.push(`A ${r} ${r} 0 0 0 ${xLeft} ${yExit}`)\n segs.push(`L ${xLeft} ${yNext - R + Y_OFFSET}`)\n }\n }\n\n const lastY = Y[n]\n if ((n - 2) % 2 === 0) {\n segs.push(`L ${xRight} ${lastY}`)\n } else {\n segs.push(`L ${xLeft} ${lastY}`)\n }\n parts.push({\n d: segs.join(' '),\n stroke: COLORS[i % COLORS.length],\n 'stroke-width': STROKE_WIDTH,\n fill: 'none',\n })\n }\n return parts\n}\n\nconst DEFAULT_SVG_CLASS = 'serpentine-border-svg'\n\nconst DEFAULTS = {\n strokeCount: 5,\n strokeWidth: 8,\n radius: 50,\n horizontalOverflow: 0,\n layoutMode: 'border',\n}\n\n/**\n * Compute everything needed to render the serpentine border.\n * Accepts either (width + sectionBottomYs) for pure/custom use, or wrapperEl to measure from the DOM.\n * When using wrapperEl, returns null in non-DOM environments (e.g. SSR) or when measurement fails.\n *\n * @param {{\n * width?: number\n * sectionBottomYs?: number[]\n * wrapperEl?: HTMLElement\n * strokeCount?: number\n * strokeWidth?: number\n * radius?: number\n * horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'\n * colors?: string[]\n * layoutMode?: 'content' | 'border'\n * svgClassName?: string\n * }} options\n * @returns {{\n * wrapperStyle: Record<string, unknown>\n * svgAttributes: { class?: string, viewBox: string, style: string }\n * paths: Array<{ d: string, stroke: string, 'stroke-width': number, fill: string }>\n * } | null}\n */\nexport function serpentineBorder(options) {\n const N = options.strokeCount ?? DEFAULTS.strokeCount\n const STROKE_WIDTH = options.strokeWidth ?? DEFAULTS.strokeWidth\n const R = options.radius ?? DEFAULTS.radius\n const horizontalOverflow = options.horizontalOverflow ?? DEFAULTS.horizontalOverflow\n const COLORS = options.colors ?? DEFAULT_COLORS\n const layoutMode = options.layoutMode ?? DEFAULTS.layoutMode\n const svgClassName = options.svgClassName ?? DEFAULT_SVG_CLASS\n\n let W, Y\n if (options.wrapperEl != null) {\n const wrapperEl = options.wrapperEl\n const hasDOM = typeof document !== 'undefined' && typeof wrapperEl.getBoundingClientRect === 'function'\n if (!hasDOM) return null\n const measured = measureSections(wrapperEl, {\n layoutMode,\n horizontalOverflow,\n strokeCount: N,\n strokeWidth: STROKE_WIDTH,\n excludeClassName: svgClassName,\n })\n if (!measured) return null\n W = measured.width\n Y = measured.sectionBottomYs\n } else {\n if (options.width == null || options.sectionBottomYs == null) return null\n W = options.width\n Y = options.sectionBottomYs\n }\n\n const BORDER_EXTRA = resolveOverflowToPixels(horizontalOverflow, N, STROKE_WIDTH)\n const O_TOTAL = (N - 1) * STROKE_WIDTH\n const TOTAL_BORDER_WIDTH = N * STROKE_WIDTH\n const TOP_OFFSET = 2 * STROKE_WIDTH\n const Y_OFFSET = O_TOTAL / 2\n const TOP_ARC_SHIFT = ((N - 1) / 2) * STROKE_WIDTH + Y_OFFSET\n\n const wrapperStyle =\n layoutMode === 'border'\n ? {\n boxSizing: 'border-box',\n position: 'relative',\n marginTop: `${TOTAL_BORDER_WIDTH / 2}px`,\n ...(BORDER_EXTRA > 0 && {\n paddingLeft: `${BORDER_EXTRA}px`,\n paddingRight: `${BORDER_EXTRA}px`,\n }),\n }\n : {\n position: 'relative',\n boxSizing: 'border-box',\n }\n\n const svgStyleObj =\n layoutMode === 'border'\n ? {\n position: 'absolute',\n overflow: 'hidden',\n width: '100%',\n left: 0,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n : {\n position: 'absolute',\n overflow: 'hidden',\n width: `calc(100% + ${2 * BORDER_EXTRA}px)`,\n left: -BORDER_EXTRA,\n top: -(TOP_OFFSET + TOP_ARC_SHIFT),\n height: `calc(100% + ${TOP_OFFSET + TOP_ARC_SHIFT}px)`,\n }\n const svgStyle = styleObjectToCss(svgStyleObj)\n\n const paths = buildPathD(W, Y, N, R, STROKE_WIDTH, COLORS, TOP_ARC_SHIFT, Y_OFFSET, O_TOTAL, BORDER_EXTRA)\n\n const totalHeight = Y[Y.length - 1] ?? 0\n const totalWidth = Math.max(1, W + 2 * BORDER_EXTRA)\n const viewBoxHeight = totalHeight + TOP_OFFSET + TOP_ARC_SHIFT\n const viewBoxMinX = BORDER_EXTRA > 0 ? -BORDER_EXTRA : 0\n const viewBoxMinY = -STROKE_WIDTH * 2 - TOP_ARC_SHIFT\n const viewBoxStr = `${viewBoxMinX} ${viewBoxMinY} ${totalWidth} ${viewBoxHeight}`\n\n return {\n wrapperStyle,\n svgAttributes: {\n class: svgClassName,\n viewBox: viewBoxStr,\n style: svgStyle,\n },\n paths,\n }\n}\n\n/**\n * Compute padding for each section so content does not overlap the border.\n * Returns an object with even, odd, and last: use for even-indexed sections, odd-indexed sections, and the last section respectively.\n *\n * @param {{\n * sectionCount: number\n * strokeCount: number\n * strokeWidth: number\n * horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'\n * }} options\n * @returns {{ even: { top: number, right: number, bottom: number, left: number }, odd: { top: number, right: number, bottom: number, left: number }, last: { top: number, right: number, bottom: number, left: number } }}\n */\nexport function getSectionsPadding(options) {\n const { sectionCount: n, strokeCount: N, strokeWidth: STROKE_WIDTH } = options\n const horizontalOverflow = options.horizontalOverflow ?? 0\n const TOTAL_BORDER_WIDTH = N * STROKE_WIDTH\n const BORDER_EXTRA = resolveOverflowToPixels(horizontalOverflow, N, STROKE_WIDTH)\n const halfBorderWidth = TOTAL_BORDER_WIDTH / 2\n const insetSide = TOTAL_BORDER_WIDTH - BORDER_EXTRA\n const even = { top: halfBorderWidth, right: 0, bottom: halfBorderWidth, left: insetSide }\n const odd = { top: halfBorderWidth, right: insetSide, bottom: halfBorderWidth, left: 0 }\n const lastIsEven = n > 0 && (n - 1) % 2 === 0\n const last = {\n top: halfBorderWidth,\n right: lastIsEven ? 0 : insetSide,\n bottom: 0,\n left: lastIsEven ? insetSide : 0,\n }\n return { even, odd, last }\n}\n\n/**\n * Measure wrapper and section elements to get width and section bottom Ys.\n * Children with the excludeClassName (default: same class used on the SVG by serpentineBorder) are excluded.\n * horizontalOverflow is resolved to pixels using strokeCount and strokeWidth.\n *\n * @param {HTMLElement} wrapperEl\n * @param {{\n * layoutMode: 'content' | 'border'\n * horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'\n * strokeCount: number\n * strokeWidth: number\n * excludeClassName?: string\n * }} options\n * @returns {{ width: number, sectionBottomYs: number[] } | null}\n */\nexport function measureSections(wrapperEl, options) {\n const { layoutMode, horizontalOverflow = 0, strokeCount, strokeWidth, excludeClassName = DEFAULT_SVG_CLASS } = options\n const BORDER_EXTRA = resolveOverflowToPixels(horizontalOverflow, strokeCount, strokeWidth)\n if (!wrapperEl) return null\n\n const sectionEls = excludeClassName\n ? Array.from(wrapperEl.children).filter((el) => !el.classList.contains(excludeClassName))\n : Array.from(wrapperEl.children)\n\n if (sectionEls.length === 0) return null\n\n const rect = wrapperEl.getBoundingClientRect()\n const baseWidth = rect.width\n\n const W =\n layoutMode === 'border'\n ? Math.max(1, baseWidth - 2 * BORDER_EXTRA)\n : Math.max(1, baseWidth)\n\n const Y = [0]\n for (let i = 0; i < sectionEls.length; i++) {\n const r = sectionEls[i].getBoundingClientRect()\n Y.push(r.top - rect.top + r.height)\n }\n\n return { width: W, sectionBottomYs: Y }\n}\n","import { useEffect, useRef, useState } from 'react'\nimport { measureSections, serpentineBorder } from './serpentineCore.js'\n\nfunction cssStringToStyleObject(css) {\n const obj = {}\n if (!css || typeof css !== 'string') return obj\n for (const decl of css.split(';')) {\n const colon = decl.indexOf(':')\n if (colon === -1) continue\n const key = decl.slice(0, colon).trim().replace(/-([a-z])/g, (_, c) => c.toUpperCase())\n const value = decl.slice(colon + 1).trim()\n if (key) obj[key] = value\n }\n return obj\n}\n\nfunction pathAttrsForReact(attrs) {\n return Object.fromEntries(\n Object.entries(attrs).map(([k, v]) => [k === 'stroke-width' ? 'strokeWidth' : k, v])\n )\n}\n\nfunction SerpentineBorder({\n children,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverflow,\n colors,\n layoutMode,\n}) {\n const wrapperRef = useRef(null)\n const [borderData, setBorderData] = useState(null)\n\n useEffect(() => {\n const wrapper = wrapperRef.current\n if (!wrapper) return\n\n const measure = () => {\n const measured = measureSections(wrapper, {\n layoutMode,\n horizontalOverflow,\n strokeCount,\n strokeWidth,\n })\n if (!measured) return\n\n const data = serpentineBorder({\n width: measured.width,\n sectionBottomYs: measured.sectionBottomYs,\n strokeCount,\n strokeWidth,\n radius,\n horizontalOverflow,\n colors,\n layoutMode,\n })\n setBorderData(data)\n }\n\n measure()\n const ro = new ResizeObserver(measure)\n ro.observe(wrapper)\n return () => ro.disconnect()\n }, [strokeCount, strokeWidth, radius, horizontalOverflow, colors, layoutMode])\n\n return (\n <div\n ref={wrapperRef}\n className=\"serpentine-wrapper\"\n style={borderData?.wrapperStyle ?? { position: 'relative', boxSizing: 'border-box' }}\n data-testid=\"serpentine-wrapper\"\n >\n {borderData && (() => {\n const { class: className, style: styleStr, ...restSvgAttrs } = borderData.svgAttributes\n const style = typeof styleStr === 'string' ? cssStringToStyleObject(styleStr) : styleStr\n return (\n <svg\n data-testid=\"serpentine-svg\"\n className={className}\n style={style}\n {...restSvgAttrs}\n >\n {borderData.paths.map((pathAttributes, i) => (\n <path key={i} {...pathAttrsForReact(pathAttributes)} />\n ))}\n </svg>\n )\n })()}\n {children}\n </div>\n )\n}\n\nexport default SerpentineBorder\n"],"names":["DEFAULT_COLORS","resolveOverflowToPixels","horizontalOverflow","N","STROKE_WIDTH","totalBorderWidth","styleObjectToCss","obj","k","v","key","val","buildPathD","W","Y","R","COLORS","TOP_ARC_SHIFT","Y_OFFSET","O_TOTAL","BORDER_EXTRA","R1","RIGHT_EXTEND","n","parts","i","o","oj","r","rj","rj1","leftOffset","xLeft","rightExt","xRight","xLeftArc","xRightArc","xRightR1","yCurrTop","segs","t","yCurr","yNext","yExit","lastY","DEFAULT_SVG_CLASS","DEFAULTS","serpentineBorder","options","layoutMode","svgClassName","wrapperEl","measured","measureSections","TOTAL_BORDER_WIDTH","TOP_OFFSET","wrapperStyle","svgStyleObj","svgStyle","paths","totalHeight","totalWidth","viewBoxHeight","viewBoxMinX","viewBoxMinY","viewBoxStr","getSectionsPadding","halfBorderWidth","insetSide","even","odd","lastIsEven","strokeCount","strokeWidth","excludeClassName","sectionEls","el","rect","baseWidth","cssStringToStyleObject","css","decl","colon","_","c","value","pathAttrsForReact","attrs","SerpentineBorder","children","radius","colors","wrapperRef","useRef","borderData","setBorderData","useState","useEffect","wrapper","measure","data","ro","jsxs","className","styleStr","restSvgAttrs","style","jsx","pathAttributes"],"mappings":";;AAAO,MAAMA,IAAiB,CAAC,WAAW,SAAS;ACOnD,SAASC,EAAwBC,GAAoBC,GAAGC,GAAc;AACpE,MAAI,OAAOF,KAAuB,SAAU,QAAOA;AACnD,QAAMG,IAAmBF,IAAIC;AAC7B,SAAIF,MAAuB,gBAAsBG,IAC7CH,MAAuB,oBAA0BG,IAAmB,IACjE;AACT;AAEA,SAASC,EAAiBC,GAAK;AAC7B,SAAO,OAAO,QAAQA,CAAG,EACtB,IAAI,CAAC,CAACC,GAAGC,CAAC,MAAM;AACf,UAAMC,IAAMF,EAAE,QAAQ,YAAY,KAAK,EAAE,YAAW,GAC9CG,IAAM,OAAOF,KAAM,YAAY,CAAC,OAAO,MAAMA,CAAC,IAAI,GAAGA,CAAC,OAAO,OAAOA,CAAC;AAC3E,WAAO,GAAGC,CAAG,KAAKC,CAAG;AAAA,EACvB,CAAC,EACA,KAAK,IAAI;AACd;AAEA,SAASC,EAAWC,GAAGC,GAAGX,GAAGY,GAAGX,GAAcY,GAAQC,GAAeC,GAAUC,GAASC,GAAc;AACpG,QAAMC,IAAKjB,KAAgBD,IAAI,IACzBmB,IAAelB,IAAe,GAC9BmB,IAAIT,EAAE,SAAS,GACfU,IAAQ,CAAA;AACd,WAASC,IAAI,GAAGA,IAAItB,GAAGsB,KAAK;AAC1B,UAAMC,IAAID,IAAIrB,GAERuB,KADIxB,IAAI,IAAIsB,KACHrB,GACTwB,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AC7B,GAAaC,GAAaiB,GAAQxF,GAAoByF,GAAQ1C,CAAU,CAAC,GAG3E,gBAAAqD;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAKV;AAAA,MACL,WAAU;AAAA,MACV,QAAOE,KAAA,gBAAAA,EAAY,iBAAgB,EAAE,UAAU,YAAY,WAAW,aAAA;AAAA,MACtE,eAAY;AAAA,MAEX,UAAA;AAAA,QAAAA,MAAe,MAAM;AACpB,gBAAM,EAAE,OAAOS,GAAW,OAAOC,GAAU,GAAGC,EAAA,IAAiBX,EAAW,eACpEY,IAAQ,OAAOF,KAAa,WAAWzB,EAAuByB,CAAQ,IAAIA;AAChF,iBACE,gBAAAG;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,eAAY;AAAA,cACZ,WAAAJ;AAAA,cACA,OAAAG;AAAA,cACC,GAAGD;AAAA,cAEH,UAAAX,EAAW,MAAM,IAAI,CAACc,GAAgBnF,MACrC,gBAAAkF,EAAC,QAAA,EAAc,GAAGrB,EAAkBsB,CAAc,EAAA,GAAvCnF,CAA0C,CACtD;AAAA,YAAA;AAAA,UAAA;AAAA,QAGP,GAAA;AAAA,QACCgE;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGP;"}
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export interface SerpentineBorderProps {
5
5
  strokeCount?: number
6
6
  strokeWidth?: number
7
7
  radius?: number
8
- horizontalOverlap?: number | 'borderWidth' | 'halfBorderWidth'
8
+ horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'
9
9
  colors?: string[]
10
10
  layoutMode?: 'content' | 'border'
11
11
  }
@@ -23,16 +23,38 @@ export interface SerpentineBorderOptions {
23
23
  strokeCount?: number
24
24
  strokeWidth?: number
25
25
  radius?: number
26
- horizontalOverlap?: number | 'borderWidth' | 'halfBorderWidth'
26
+ horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'
27
27
  colors?: string[]
28
28
  layoutMode?: 'content' | 'border'
29
29
  svgClassName?: string
30
30
  }
31
31
 
32
+ export interface SectionPadding {
33
+ top: number
34
+ right: number
35
+ bottom: number
36
+ left: number
37
+ }
38
+
32
39
  export interface SerpentineBorderResult {
33
40
  wrapperStyle: Record<string, unknown>
34
41
  svgAttributes: { class?: string; viewBox: string; style: string }
35
42
  paths: Array<{ d: string; stroke: string; 'stroke-width': number; fill: string }>
36
43
  }
37
44
 
45
+ export interface GetSectionsPaddingOptions {
46
+ sectionCount: number
47
+ strokeCount: number
48
+ strokeWidth: number
49
+ horizontalOverflow?: number | 'borderWidth' | 'halfBorderWidth'
50
+ }
51
+
52
+ export interface SectionsPaddingMap {
53
+ even: SectionPadding
54
+ odd: SectionPadding
55
+ last: SectionPadding
56
+ }
57
+
58
+ export declare function getSectionsPadding(options: GetSectionsPaddingOptions): SectionsPaddingMap
59
+
38
60
  export declare function serpentineBorder(options: SerpentineBorderOptions): SerpentineBorderResult | null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serpentine-border",
3
- "version": "1.0.2",
3
+ "version": "3.0.0",
4
4
  "description": "Multi-stroke serpentine (wavy) border SVG — vanilla JS and React",
5
5
  "type": "module",
6
6
  "main": "./dist/serpentine-border.cjs",