animot-presenter 0.2.6 → 0.2.7

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.
@@ -1240,6 +1240,27 @@
1240
1240
  </div>
1241
1241
 
1242
1242
  <script module lang="ts">
1243
+ function roundedPolygonPath(pointsStr: string, radius: number): string {
1244
+ const pts = pointsStr.split(/\s+/).map(p => { const [x, y] = p.split(',').map(Number); return { x, y }; });
1245
+ if (pts.length < 3 || radius <= 0) return 'M' + pts.map(p => `${p.x},${p.y}`).join('L') + 'Z';
1246
+ const n = pts.length;
1247
+ const parts: string[] = [];
1248
+ for (let i = 0; i < n; i++) {
1249
+ const prev = pts[(i - 1 + n) % n], curr = pts[i], next = pts[(i + 1) % n];
1250
+ const dx1 = prev.x - curr.x, dy1 = prev.y - curr.y;
1251
+ const dx2 = next.x - curr.x, dy2 = next.y - curr.y;
1252
+ const len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
1253
+ const len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
1254
+ const r = Math.min(radius, len1 / 2, len2 / 2);
1255
+ const sx = curr.x + (dx1 / len1) * r, sy = curr.y + (dy1 / len1) * r;
1256
+ const ex = curr.x + (dx2 / len2) * r, ey = curr.y + (dy2 / len2) * r;
1257
+ parts.push(i === 0 ? `M${sx},${sy}` : `L${sx},${sy}`);
1258
+ parts.push(`Q${curr.x},${curr.y} ${ex},${ey}`);
1259
+ }
1260
+ parts.push('Z');
1261
+ return parts.join(' ');
1262
+ }
1263
+
1243
1264
  function renderShape(type: string, w: number, h: number, br: number, fill: string, stroke: string, sw: number, strokeStyle?: string, strokeDashGap?: number): string {
1244
1265
  let dashAttr = '';
1245
1266
  if (strokeStyle && strokeStyle !== 'solid') {
@@ -1249,20 +1270,24 @@
1249
1270
  const lc = strokeStyle === 'dotted' ? 'round' : 'butt';
1250
1271
  dashAttr = ` stroke-dasharray="${da}" stroke-linecap="${lc}"`;
1251
1272
  }
1273
+ const polyOrPath = (pts: string) => {
1274
+ if (br > 0) return `<path d="${roundedPolygonPath(pts, br)}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr}/>`;
1275
+ return `<polygon points="${pts}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr} stroke-linejoin="round"/>`;
1276
+ };
1252
1277
  switch (type) {
1253
1278
  case 'rectangle': return `<rect x="${sw/2}" y="${sw/2}" width="${w-sw}" height="${h-sw}" rx="${br}" ry="${br}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr}/>`;
1254
1279
  case 'circle': return `<circle cx="${w/2}" cy="${h/2}" r="${Math.min(w,h)/2-sw/2}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr}/>`;
1255
1280
  case 'ellipse': return `<ellipse cx="${w/2}" cy="${h/2}" rx="${w/2-sw/2}" ry="${h/2-sw/2}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr}/>`;
1256
- case 'triangle': return `<polygon points="${w/2},${sw/2} ${sw/2},${h-sw/2} ${w-sw/2},${h-sw/2}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr} stroke-linejoin="round"/>`;
1281
+ case 'triangle': return polyOrPath(`${w/2},${sw/2} ${sw/2},${h-sw/2} ${w-sw/2},${h-sw/2}`);
1257
1282
  case 'star': {
1258
1283
  const cx = w/2, cy = h/2, outerR = Math.min(w,h)/2-sw/2, innerR = outerR*0.4;
1259
1284
  const pts = Array.from({length:10},(_,i)=>{const a=(i*Math.PI/5)-Math.PI/2;const r=i%2===0?outerR:innerR;return`${cx+r*Math.cos(a)},${cy+r*Math.sin(a)}`;}).join(' ');
1260
- return `<polygon points="${pts}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr} stroke-linejoin="round"/>`;
1285
+ return polyOrPath(pts);
1261
1286
  }
1262
1287
  case 'hexagon': {
1263
1288
  const cx = w/2, cy = h/2, r = Math.min(w,h)/2-sw/2;
1264
1289
  const pts = Array.from({length:6},(_,i)=>{const a=(i*Math.PI/3)-Math.PI/2;return`${cx+r*Math.cos(a)},${cy+r*Math.sin(a)}`;}).join(' ');
1265
- return `<polygon points="${pts}" fill="${fill}" stroke="${stroke}" stroke-width="${sw}"${dashAttr} stroke-linejoin="round"/>`;
1290
+ return polyOrPath(pts);
1266
1291
  }
1267
1292
  default: return '';
1268
1293
  }