MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / getFillSpec

Function getFillSpec

src/tools/shape-magic/svgRenderers.js:125–170  ·  view source on GitHub ↗
(style, bbox, idSuffix = '')

Source from the content-addressed store, hash-verified

123// `bbox` must be in the same coordinate space as the drawn paths so a gradient
124// spans the whole merged silhouette seamlessly (gradientUnits=userSpaceOnUse).
125export const getFillSpec = (style, bbox, idSuffix = '') => {
126 const id = `sm-fill-${idSuffix}`;
127 const type = style.fillType || 'solid';
128 if (type === 'solid') {
129 return { type: 'solid', id, paint: style.fill };
130 }
131
132 const c1 = style.fill;
133 const c2 = style.fillColor2 || style.fill;
134 const cx = bbox.x + bbox.w / 2;
135 const cy = bbox.y + bbox.h / 2;
136
137 if (type === 'linear') {
138 const angle = (((style.gradientAngle ?? 135) - 90) * Math.PI) / 180;
139 const half = (Math.abs(Math.cos(angle)) * bbox.w + Math.abs(Math.sin(angle)) * bbox.h) / 2;
140 const dx = Math.cos(angle) * half;
141 const dy = Math.sin(angle) * half;
142 return {
143 type: 'linear',
144 id,
145 paint: `url(#${id})`,
146 x1: cx - dx,
147 y1: cy - dy,
148 x2: cx + dx,
149 y2: cy + dy,
150 stops: [
151 { offset: 0, color: c1 },
152 { offset: 1, color: c2 }
153 ]
154 };
155 }
156
157 // radial
158 return {
159 type: 'radial',
160 id,
161 paint: `url(#${id})`,
162 cx,
163 cy,
164 r: Math.max(bbox.w, bbox.h) / 2,
165 stops: [
166 { offset: 0, color: c1 },
167 { offset: 1, color: c2 }
168 ]
169 };
170};
171
172// Description of the shadow + outer-stroke filter applied to the merged group.
173export const getFxSpec = (style, idSuffix = '') => {

Callers 3

Canvas.jsxFile · 0.90
generateMergedSVGFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected