serpentine-border 2.0.0 → 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 +14 -3
- package/dist/serpentine-border.cjs +1 -1
- package/dist/serpentine-border.cjs.map +1 -1
- package/dist/serpentine-border.js +108 -103
- package/dist/serpentine-border.js.map +1 -1
- package/index.d.ts +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,9 +25,9 @@ function setAttributes(el, attrs) {
|
|
|
25
25
|
const wrapperEl = document.getElementById('wrapper')
|
|
26
26
|
const result = serpentineBorder({ wrapperEl })
|
|
27
27
|
if (!result) return
|
|
28
|
-
const { wrapperStyle, svgAttributes, paths
|
|
28
|
+
const { wrapperStyle, svgAttributes, paths } = result
|
|
29
29
|
Object.assign(wrapperEl.style, wrapperStyle)
|
|
30
|
-
// Optionally
|
|
30
|
+
// Optionally: getSectionsPadding({ sectionCount: n, strokeCount, strokeWidth, horizontalOverflow }) for per-section padding
|
|
31
31
|
|
|
32
32
|
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
|
33
33
|
setAttributes(svg, svgAttributes)
|
|
@@ -44,7 +44,7 @@ wrapperEl.insertBefore(svg, wrapperEl.firstChild)
|
|
|
44
44
|
|
|
45
45
|
### serpentineBorder(options)
|
|
46
46
|
|
|
47
|
-
Returns `wrapperStyle`, `svgAttributes` (class, viewBox, style),
|
|
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.
|
|
48
48
|
|
|
49
49
|
| Option | Type | Default | Description |
|
|
50
50
|
|--------|------|---------|-------------|
|
|
@@ -61,6 +61,17 @@ Returns `wrapperStyle`, `svgAttributes` (class, viewBox, style), `paths`, and `s
|
|
|
61
61
|
|
|
62
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.
|
|
63
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
|
+
|
|
64
75
|
### React: SerpentineBorder
|
|
65
76
|
|
|
66
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 R=require("react/jsx-runtime"),
|
|
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 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 * sectionsPadding: Array<{ top: number, right: number, bottom: number, left: number }>\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 const n = Y.length - 1\n const halfBorderWidth = TOTAL_BORDER_WIDTH / 2\n const insetSide = TOTAL_BORDER_WIDTH - BORDER_EXTRA\n const sectionsPadding = []\n for (let i = 0; i < n; i++) {\n const top = halfBorderWidth\n const bottom = i === n - 1 ? 0 : halfBorderWidth\n const left = i % 2 === 0 ? insetSide : 0\n const right = i % 2 === 0 ? 0 : insetSide\n sectionsPadding.push({ top, right, bottom, left })\n }\n\n return {\n wrapperStyle,\n svgAttributes: {\n class: svgClassName,\n viewBox: viewBoxStr,\n style: svgStyle,\n },\n paths,\n sectionsPadding,\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 * 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","halfBorderWidth","insetSide","sectionsPadding","top","bottom","left","right","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,OAAOF,GAAuB,SAAU,OAAOA,EACnD,MAAMG,EAAmBF,EAAIC,EAC7B,OAAIF,IAAuB,cAAsBG,EAC7CH,IAAuB,kBAA0BG,EAAmB,EACjE,CACT,CAEA,SAASC,EAAiBC,EAAK,CAC7B,OAAO,OAAO,QAAQA,CAAG,EACtB,IAAI,CAAC,CAACC,EAAGC,CAAC,IAAM,CACf,MAAMC,EAAMF,EAAE,QAAQ,WAAY,KAAK,EAAE,YAAW,EAC9CG,EAAM,OAAOF,GAAM,UAAY,CAAC,OAAO,MAAMA,CAAC,EAAI,GAAGA,CAAC,KAAO,OAAOA,CAAC,EAC3E,MAAO,GAAGC,CAAG,KAAKC,CAAG,EACvB,CAAC,EACA,KAAK,IAAI,CACd,CAEA,SAASC,EAAWC,EAAGC,EAAGX,EAAGY,EAAGX,EAAcY,EAAQC,EAAeC,EAAUC,EAASC,EAAc,CACpG,MAAMC,EAAKjB,GAAgBD,EAAI,GACzBmB,EAAelB,EAAe,EAC9BmB,EAAIT,EAAE,OAAS,EACfU,EAAQ,CAAA,EACd,QAASC,EAAI,EAAGA,EAAItB,EAAGsB,IAAK,CAC1B,MAAMC,EAAID,EAAIrB,EAERuB,GADIxB,EAAI,EAAIsB,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AACM,EAAS,OAEd,MAAMC,EAAU,IAAM,CACpB,MAAMhD,EAAWC,EAAgB8C,EAAS,CACxC,WAAAlD,EACA,mBAAA/C,EACA,YAAAuE,EACA,YAAAC,CAAA,CACD,EACD,GAAI,CAACtB,EAAU,OAEf,MAAMiD,EAAOtD,EAAiB,CAC5B,MAAOK,EAAS,MAChB,gBAAiBA,EAAS,gBAC1B,YAAAqB,EACA,YAAAC,EACA,OAAAiB,EACA,mBAAAzF,EACA,OAAA0F,EACA,WAAA3C,CAAA,CACD,EACD+C,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,EAAQzF,EAAoB0F,EAAQ3C,CAAU,CAAC,EAG3EsD,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,EAAgBpF,IACrCmF,MAAC,OAAA,CAAc,GAAGrB,EAAkBsB,CAAc,CAAA,EAAvCpF,CAA0C,CACtD,CAAA,CAAA,CAGP,GAAA,EACCiE,CAAA,CAAA,CAAA,CAGP"}
|
|
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 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,OAAOF,GAAuB,SAAU,OAAOA,EACnD,MAAMG,EAAmBF,EAAIC,EAC7B,OAAIF,IAAuB,cAAsBG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AAK,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,80 +1,80 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useRef as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
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 =
|
|
6
|
+
const n = o * e;
|
|
7
7
|
return t === "borderWidth" ? n : t === "halfBorderWidth" ? n / 2 : 0;
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
return Object.entries(t).map(([
|
|
11
|
-
const n =
|
|
12
|
-
return `${n}: ${
|
|
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
|
+
return `${n}: ${i}`;
|
|
13
13
|
}).join("; ");
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
for (let
|
|
18
|
-
const d =
|
|
19
|
-
`M ${
|
|
20
|
-
`L ${
|
|
21
|
-
`A ${
|
|
22
|
-
`L ${
|
|
23
|
-
`A ${
|
|
24
|
-
`L ${
|
|
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
|
|
27
|
-
const
|
|
28
|
-
|
|
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
|
|
31
|
-
(
|
|
32
|
-
d:
|
|
33
|
-
stroke:
|
|
34
|
-
"stroke-width":
|
|
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
|
+
"stroke-width": i,
|
|
35
35
|
fill: "none"
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
return l;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const X = "serpentine-border-svg", k = {
|
|
41
41
|
strokeCount: 5,
|
|
42
42
|
strokeWidth: 8,
|
|
43
43
|
radius: 50,
|
|
44
44
|
horizontalOverflow: 0,
|
|
45
45
|
layoutMode: "border"
|
|
46
46
|
};
|
|
47
|
-
function
|
|
48
|
-
const
|
|
49
|
-
let
|
|
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
|
|
52
|
-
if (!(typeof document < "u" && typeof
|
|
53
|
-
const
|
|
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
|
-
horizontalOverflow:
|
|
56
|
-
strokeCount:
|
|
55
|
+
horizontalOverflow: i,
|
|
56
|
+
strokeCount: o,
|
|
57
57
|
strokeWidth: e,
|
|
58
|
-
excludeClassName:
|
|
58
|
+
excludeClassName: s
|
|
59
59
|
});
|
|
60
|
-
if (!
|
|
61
|
-
|
|
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
|
-
|
|
64
|
+
r = t.width, h = t.sectionBottomYs;
|
|
65
65
|
}
|
|
66
|
-
const
|
|
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: `${
|
|
70
|
-
...
|
|
71
|
-
paddingLeft: `${
|
|
72
|
-
paddingRight: `${
|
|
69
|
+
marginTop: `${$ / 2}px`,
|
|
70
|
+
...c > 0 && {
|
|
71
|
+
paddingLeft: `${c}px`,
|
|
72
|
+
paddingRight: `${c}px`
|
|
73
73
|
}
|
|
74
74
|
} : {
|
|
75
75
|
position: "relative",
|
|
76
76
|
boxSizing: "border-box"
|
|
77
|
-
},
|
|
77
|
+
}, x = u === "border" ? {
|
|
78
78
|
position: "absolute",
|
|
79
79
|
overflow: "hidden",
|
|
80
80
|
width: "100%",
|
|
@@ -84,108 +84,112 @@ function O(t) {
|
|
|
84
84
|
} : {
|
|
85
85
|
position: "absolute",
|
|
86
86
|
overflow: "hidden",
|
|
87
|
-
width: `calc(100% + ${2 *
|
|
88
|
-
left: -
|
|
87
|
+
width: `calc(100% + ${2 * c}px)`,
|
|
88
|
+
left: -c,
|
|
89
89
|
top: -(l + d),
|
|
90
90
|
height: `calc(100% + ${l + d}px)`
|
|
91
|
-
},
|
|
92
|
-
for (let x = 0; x < k; x++) {
|
|
93
|
-
const B = W, g = x === k - 1 ? 0 : W, D = x % 2 === 0 ? j : 0, z = x % 2 === 0 ? 0 : j;
|
|
94
|
-
h.push({ top: B, right: z, bottom: g, left: D });
|
|
95
|
-
}
|
|
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}`;
|
|
96
92
|
return {
|
|
97
93
|
wrapperStyle: R,
|
|
98
94
|
svgAttributes: {
|
|
99
|
-
class:
|
|
100
|
-
viewBox:
|
|
101
|
-
style:
|
|
95
|
+
class: s,
|
|
96
|
+
viewBox: A,
|
|
97
|
+
style: b
|
|
102
98
|
},
|
|
103
|
-
paths:
|
|
104
|
-
sectionsPadding: h
|
|
99
|
+
paths: B
|
|
105
100
|
};
|
|
106
101
|
}
|
|
107
|
-
function
|
|
108
|
-
const {
|
|
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);
|
|
109
113
|
if (!t) return null;
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
const
|
|
113
|
-
for (let l = 0; l <
|
|
114
|
-
const
|
|
115
|
-
|
|
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);
|
|
116
120
|
}
|
|
117
|
-
return { width: a, sectionBottomYs:
|
|
121
|
+
return { width: a, sectionBottomYs: $ };
|
|
118
122
|
}
|
|
119
|
-
function
|
|
120
|
-
const
|
|
121
|
-
if (!t || typeof t != "string") return
|
|
123
|
+
function I(t) {
|
|
124
|
+
const o = {};
|
|
125
|
+
if (!t || typeof t != "string") return o;
|
|
122
126
|
for (const e of t.split(";")) {
|
|
123
127
|
const n = e.indexOf(":");
|
|
124
128
|
if (n === -1) continue;
|
|
125
|
-
const
|
|
126
|
-
|
|
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);
|
|
127
131
|
}
|
|
128
|
-
return
|
|
132
|
+
return o;
|
|
129
133
|
}
|
|
130
|
-
function
|
|
134
|
+
function K(t) {
|
|
131
135
|
return Object.fromEntries(
|
|
132
|
-
Object.entries(t).map(([
|
|
136
|
+
Object.entries(t).map(([o, e]) => [o === "stroke-width" ? "strokeWidth" : o, e])
|
|
133
137
|
);
|
|
134
138
|
}
|
|
135
|
-
function
|
|
139
|
+
function F({
|
|
136
140
|
children: t,
|
|
137
|
-
strokeCount:
|
|
141
|
+
strokeCount: o,
|
|
138
142
|
strokeWidth: e,
|
|
139
143
|
radius: n,
|
|
140
|
-
horizontalOverflow:
|
|
141
|
-
colors:
|
|
144
|
+
horizontalOverflow: i,
|
|
145
|
+
colors: p,
|
|
142
146
|
layoutMode: u
|
|
143
147
|
}) {
|
|
144
|
-
const
|
|
145
|
-
return
|
|
146
|
-
const
|
|
147
|
-
if (!
|
|
148
|
+
const s = P(null), [r, h] = V(null);
|
|
149
|
+
return Z(() => {
|
|
150
|
+
const c = s.current;
|
|
151
|
+
if (!c) return;
|
|
148
152
|
const a = () => {
|
|
149
|
-
const l =
|
|
153
|
+
const l = O(c, {
|
|
150
154
|
layoutMode: u,
|
|
151
|
-
horizontalOverflow:
|
|
152
|
-
strokeCount:
|
|
155
|
+
horizontalOverflow: i,
|
|
156
|
+
strokeCount: o,
|
|
153
157
|
strokeWidth: e
|
|
154
158
|
});
|
|
155
159
|
if (!l) return;
|
|
156
|
-
const
|
|
160
|
+
const f = H({
|
|
157
161
|
width: l.width,
|
|
158
162
|
sectionBottomYs: l.sectionBottomYs,
|
|
159
|
-
strokeCount:
|
|
163
|
+
strokeCount: o,
|
|
160
164
|
strokeWidth: e,
|
|
161
165
|
radius: n,
|
|
162
|
-
horizontalOverflow:
|
|
163
|
-
colors:
|
|
166
|
+
horizontalOverflow: i,
|
|
167
|
+
colors: p,
|
|
164
168
|
layoutMode: u
|
|
165
169
|
});
|
|
166
|
-
|
|
170
|
+
h(f);
|
|
167
171
|
};
|
|
168
172
|
a();
|
|
169
|
-
const
|
|
170
|
-
return
|
|
171
|
-
}, [
|
|
173
|
+
const $ = new ResizeObserver(a);
|
|
174
|
+
return $.observe(c), () => $.disconnect();
|
|
175
|
+
}, [o, e, n, i, p, u]), /* @__PURE__ */ G(
|
|
172
176
|
"div",
|
|
173
177
|
{
|
|
174
|
-
ref:
|
|
178
|
+
ref: s,
|
|
175
179
|
className: "serpentine-wrapper",
|
|
176
|
-
style: (
|
|
180
|
+
style: (r == null ? void 0 : r.wrapperStyle) ?? { position: "relative", boxSizing: "border-box" },
|
|
177
181
|
"data-testid": "serpentine-wrapper",
|
|
178
182
|
children: [
|
|
179
|
-
|
|
180
|
-
const { class:
|
|
183
|
+
r && (() => {
|
|
184
|
+
const { class: c, style: a, ...$ } = r.svgAttributes, l = typeof a == "string" ? I(a) : a;
|
|
181
185
|
return /* @__PURE__ */ U(
|
|
182
186
|
"svg",
|
|
183
187
|
{
|
|
184
188
|
"data-testid": "serpentine-svg",
|
|
185
|
-
className:
|
|
189
|
+
className: c,
|
|
186
190
|
style: l,
|
|
187
|
-
|
|
188
|
-
children:
|
|
191
|
+
...$,
|
|
192
|
+
children: r.paths.map((f, d) => /* @__PURE__ */ U("path", { ...K(f) }, d))
|
|
189
193
|
}
|
|
190
194
|
);
|
|
191
195
|
})(),
|
|
@@ -195,7 +199,8 @@ function _({
|
|
|
195
199
|
);
|
|
196
200
|
}
|
|
197
201
|
export {
|
|
198
|
-
|
|
199
|
-
|
|
202
|
+
F as SerpentineBorder,
|
|
203
|
+
_ as getSectionsPadding,
|
|
204
|
+
H as serpentineBorder
|
|
200
205
|
};
|
|
201
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 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 * sectionsPadding: Array<{ top: number, right: number, bottom: number, left: number }>\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 const n = Y.length - 1\n const halfBorderWidth = TOTAL_BORDER_WIDTH / 2\n const insetSide = TOTAL_BORDER_WIDTH - BORDER_EXTRA\n const sectionsPadding = []\n for (let i = 0; i < n; i++) {\n const top = halfBorderWidth\n const bottom = i === n - 1 ? 0 : halfBorderWidth\n const left = i % 2 === 0 ? insetSide : 0\n const right = i % 2 === 0 ? 0 : insetSide\n sectionsPadding.push({ top, right, bottom, left })\n }\n\n return {\n wrapperStyle,\n svgAttributes: {\n class: svgClassName,\n viewBox: viewBoxStr,\n style: svgStyle,\n },\n paths,\n sectionsPadding,\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 * 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","halfBorderWidth","insetSide","sectionsPadding","top","bottom","left","right","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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AA;AAAA,UAAA;AAAA,QAGP,GAAA;AAAA,QACCiE;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","j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AOC,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
|
@@ -40,7 +40,21 @@ export interface SerpentineBorderResult {
|
|
|
40
40
|
wrapperStyle: Record<string, unknown>
|
|
41
41
|
svgAttributes: { class?: string; viewBox: string; style: string }
|
|
42
42
|
paths: Array<{ d: string; stroke: string; 'stroke-width': number; fill: string }>
|
|
43
|
-
sectionsPadding: SectionPadding[]
|
|
44
43
|
}
|
|
45
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
|
+
|
|
46
60
|
export declare function serpentineBorder(options: SerpentineBorderOptions): SerpentineBorderResult | null
|