x4js 2.0.26 → 2.0.30

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.
Files changed (73) hide show
  1. package/.vscode/launch.json +14 -0
  2. package/.vscode/settings.json +2 -0
  3. package/ai-comments.txt +97 -0
  4. package/demo/assets/house-light.svg +1 -0
  5. package/demo/assets/radio.svg +4 -0
  6. package/demo/index.html +12 -0
  7. package/demo/main.scss +23 -0
  8. package/demo/main.ts +324 -0
  9. package/demo/package.json +26 -0
  10. package/demo/scss.d.ts +4 -0
  11. package/demo/svg.d.ts +1 -0
  12. package/demo/tsconfig.json +14 -0
  13. package/lib/types/x4js.d.ts +0 -2374
  14. package/package.json +23 -47
  15. package/prepack.mjs +3 -0
  16. package/scripts/prepack.mjs +342 -0
  17. package/src/colors.scss +246 -0
  18. package/src/components/boxes/boxes.module.scss +1 -1
  19. package/src/components/boxes/boxes.ts +139 -28
  20. package/src/components/button/button.ts +80 -33
  21. package/src/components/combobox/combobox.ts +1 -1
  22. package/src/components/dialog/dialog.ts +4 -0
  23. package/src/components/gauge/gauge.module.scss +3 -0
  24. package/src/components/gauge/gauge.ts +1 -1
  25. package/src/components/gridview/gridview.ts +106 -8
  26. package/src/components/icon/icon.ts +42 -14
  27. package/src/components/input/input.ts +155 -76
  28. package/src/components/keyboard/keyboard.module.scss +1 -1
  29. package/src/components/keyboard/keyboard.ts +31 -9
  30. package/src/components/label/label.module.scss +9 -0
  31. package/src/components/label/label.ts +10 -6
  32. package/src/components/link/link.module.scss +44 -0
  33. package/src/components/link/link.ts +7 -1
  34. package/src/components/listbox/listbox.module.scss +18 -4
  35. package/src/components/listbox/listbox.ts +34 -15
  36. package/src/components/menu/menu.module.scss +14 -2
  37. package/src/components/menu/menu.ts +1 -1
  38. package/src/components/messages/messages.ts +13 -5
  39. package/src/components/panel/panel.module.scss +7 -0
  40. package/src/components/popup/popup.ts +14 -10
  41. package/src/components/propgrid/propgrid.ts +13 -3
  42. package/src/components/shared.scss +4 -0
  43. package/src/components/spreadsheet/spreadsheet.module.scss +308 -0
  44. package/src/components/spreadsheet/spreadsheet.ts +1223 -0
  45. package/src/components/tabs/tabs.module.scss +1 -0
  46. package/src/components/textarea/textarea.ts +8 -2
  47. package/src/components/textedit/textedit.ts +7 -0
  48. package/src/components/themes.scss +2 -0
  49. package/src/components/tooltips/tooltips.ts +15 -3
  50. package/src/core/component.ts +358 -162
  51. package/src/core/core_application.ts +129 -32
  52. package/src/core/core_colors.ts +382 -119
  53. package/src/core/core_data.ts +73 -86
  54. package/src/core/core_dom.ts +10 -0
  55. package/src/core/core_dragdrop.ts +32 -7
  56. package/src/core/core_element.ts +111 -4
  57. package/src/core/core_events.ts +48 -11
  58. package/src/core/core_i18n.ts +2 -0
  59. package/src/core/core_pdf.ts +454 -0
  60. package/src/core/core_router.ts +64 -5
  61. package/src/core/core_state.ts +1 -0
  62. package/src/core/core_styles.ts +11 -12
  63. package/src/core/core_svg.ts +348 -51
  64. package/src/core/core_tools.ts +105 -17
  65. package/src/x4.ts +1 -0
  66. package/src/x4tsx.d.ts +2 -1
  67. package/tsconfig.json +11 -0
  68. package/lib/README.txt +0 -20
  69. package/lib/cjs/x4.css +0 -1
  70. package/lib/cjs/x4.js +0 -2
  71. package/lib/esm/x4.css +0 -1
  72. package/lib/esm/x4.mjs +0 -2
  73. package/lib/styles/x4.css +0 -1
@@ -56,11 +56,45 @@ function clean( a: any, ...b: any ) {
56
56
 
57
57
 
58
58
 
59
-
60
-
61
-
62
-
63
-
59
+ /**
60
+ * Represents a lightweight wrapper around an SVG DOM element that provides
61
+ * convenient, chainable helpers for common SVG manipulations (attributes,
62
+ * styles, transforms, classes and events).
63
+ *
64
+ * The class encapsulates an underlying SVGElement and
65
+ * exposes methods that operate directly on that element while allowing fluent chaining.
66
+ *
67
+ * Key behaviors:
68
+ * - Creation: instances are constructed with the local name of the SVG tag
69
+ * (e.g. "rect", "circle", "g") and internally create the element in the
70
+ * SVG namespace.
71
+ * - Attribute management: `getAttr`, `getNumAttr`, and `setAttr` let you read
72
+ * and write attributes. Passing `null` or `undefined` to `setAttr` removes
73
+ * the attribute.
74
+ * - Styling: `setStyle` assigns CSS properties on the element. When a numeric
75
+ * value is provided, a "px" unit is appended unless the property is known
76
+ * to be unitless (the implementation relies on a small helper to detect
77
+ * unitless properties).
78
+ * - Geometry & transforms: helpers exist for setting or appending transforms
79
+ * (`transform`, `add_transformation`, `clear_transform`), and higher-level
80
+ * helpers for rotate, translate and scale (both replace and append forms).
81
+ * - Stroke & fill helpers: `stroke`, `strokeWidth`, `strokeCap`, `strokeOpacity`,
82
+ * `fill`, and `no_fill` provide convenient setters for common paint
83
+ * properties. These methods return `this` so they can be chained.
84
+ * - Classes & clipping: `addClass` / `removeClass` manipulate the element's
85
+ * class list (supporting space-separated lists) and `clip` sets a clip-path
86
+ * reference using an id.
87
+ * - Reset: `reset` removes all attributes from the element (but does not
88
+ * remove the element itself).
89
+ * - Events: `addDOMEvent` attaches DOM events to the underlying element.
90
+ *
91
+ * Notes and caveats:
92
+ * - This class is not a full DOM abstraction; it intentionally focuses on a
93
+ * small, ergonomic surface for building and manipulating SVG elements.
94
+ * - Some behaviors depend on small utility helpers (e.g. numeric/unit detection
95
+ * and event-attachment helpers) provided elsewhere in the codebase.
96
+ *
97
+ */
64
98
 
65
99
  class SvgItem {
66
100
  protected _dom : SVGElement;
@@ -81,6 +115,10 @@ class SvgItem {
81
115
  *
82
116
  */
83
117
 
118
+ /**
119
+ * Remove all attributes from the underlying DOM element.
120
+ * @returns The current instance (this) to allow method chaining.
121
+ */
84
122
  reset( ) {
85
123
  const attrs = this._dom.attributes;
86
124
  for (let i = attrs.length - 1; i >= 0; i--) {
@@ -113,16 +151,34 @@ class SvgItem {
113
151
  return this;
114
152
  }
115
153
 
154
+ /**
155
+ * change the stroke cap
156
+ * @param cap
157
+ */
158
+
116
159
  strokeCap( cap: "butt" | "round" | "sqaure" ) {
117
160
  return this.setAttr( "stroke-linecap", cap );
118
161
  }
119
162
 
163
+ /**
164
+ * change the stroke opacity attribute on the element.
165
+ * @param opacity - Opacity value where 0 is fully transparent and 1 is fully opaque.
166
+ * @returns The current instance to allow method chaining.
167
+ */
168
+
120
169
  strokeOpacity( opacity: number ) {
121
170
  return this.setAttr( "stroke-opacity", opacity+"" );
122
171
  }
123
172
 
124
173
  /**
125
- *
174
+ * Set the shape rendering attribute to control anti-aliasing for shapes.
175
+ *
176
+ * When enabled, the attribute is set to "auto" to allow smoothing/anti-aliasing.
177
+ * When disabled, the attribute is set to "crispEdges" to favor pixel-aligned,
178
+ * non-anti-aliased rendering.
179
+ *
180
+ * @param set - True to enable anti-aliasing ("auto"), false to disable ("crispEdges").
181
+ * @returns the current instance to allow chaining).
126
182
  */
127
183
 
128
184
  antiAlias( set: boolean ) {
@@ -139,6 +195,10 @@ class SvgItem {
139
195
  return this;
140
196
  }
141
197
 
198
+ /**
199
+ * the element is not filled
200
+ */
201
+
142
202
  no_fill( ): this {
143
203
  this.setAttr( 'fill', "transparent" );
144
204
  return this;
@@ -153,6 +213,10 @@ class SvgItem {
153
213
  return a;
154
214
  }
155
215
 
216
+ /**
217
+ * return the attribute as number
218
+ */
219
+
156
220
  getNumAttr( name: string ) {
157
221
  const a = this._dom.getAttribute( name )
158
222
  if( a=='' ) {
@@ -180,7 +244,7 @@ class SvgItem {
180
244
  }
181
245
 
182
246
  /**
183
- *
247
+ * change one style value
184
248
  */
185
249
 
186
250
  setStyle<K extends keyof CSSStyleDeclaration>( name: K, value: string | number ) : this {
@@ -248,10 +312,9 @@ class SvgItem {
248
312
  this.setAttr( "clip-path", `url(#${id})` );
249
313
  return this;
250
314
  }
251
-
252
315
 
253
316
  /**
254
- *
317
+ * define the whole transformation
255
318
  */
256
319
 
257
320
  transform( tr: string ): this {
@@ -259,19 +322,27 @@ class SvgItem {
259
322
  return this;
260
323
  }
261
324
 
325
+ /**
326
+ * add a transformation to the current transformation
327
+ */
328
+
262
329
  add_transformation( tr: string ): this {
263
330
  const t = this.getAttr( "transform" );
264
331
  this.setAttr( "transform", t+' '+tr );
265
332
  return this;
266
333
  }
267
334
 
335
+ /**
336
+ * remove all transformations
337
+ */
338
+
268
339
  clear_transform( ) {
269
340
  this.setAttr( "transform", null );
270
341
  return this;
271
342
  }
272
343
 
273
344
  /**
274
- *
345
+ * rotation
275
346
  */
276
347
 
277
348
  rotate( deg: number, cx: number, cy: number ): this {
@@ -284,6 +355,10 @@ class SvgItem {
284
355
  return this;
285
356
  }
286
357
 
358
+ /**
359
+ * translation
360
+ */
361
+
287
362
  translate( dx: number, dy: number ): this {
288
363
  this.transform( `translate( ${dx} ${dy} )` );
289
364
  return this;
@@ -294,6 +369,10 @@ class SvgItem {
294
369
  return this;
295
370
  }
296
371
 
372
+ /**
373
+ * scaling
374
+ */
375
+
297
376
  scale( x: number ): this {
298
377
  this.transform( `scale( ${x} )` );
299
378
  return this;
@@ -304,9 +383,8 @@ class SvgItem {
304
383
  return this;
305
384
  }
306
385
 
307
-
308
386
  /**
309
- *
387
+ * handle SVG DOM event
310
388
  */
311
389
 
312
390
  addDOMEvent<K extends keyof GlobalDOMEvents>( name: K, listener: GlobalDOMEvents[K], prepend = false ) {
@@ -318,7 +396,8 @@ class SvgItem {
318
396
 
319
397
 
320
398
  /**
321
- *
399
+ * Represents an SVG path element, providing methods for constructing and manipulating SVG paths.
400
+ * It extends `SvgItem` to inherit common SVG element functionalities.
322
401
  */
323
402
 
324
403
  export class SvgPath extends SvgItem {
@@ -334,6 +413,10 @@ export class SvgPath extends SvgItem {
334
413
  return this;
335
414
  }
336
415
 
416
+ /**
417
+ * Resets the path data and all attributes of the SVG path element.
418
+ * @returns The current `SvgPath` instance for chaining.
419
+ */
337
420
  reset( ) {
338
421
  this._path = "";
339
422
  super.reset( );
@@ -341,9 +424,11 @@ export class SvgPath extends SvgItem {
341
424
  }
342
425
 
343
426
  /**
344
- * move the current pos
345
- * @param x new pos x
346
- * @param y new pos y
427
+ * Moves the current drawing position to the specified coordinates without drawing a line.
428
+ * This is typically the first command in a path.
429
+ *
430
+ * @param x - The x-coordinate to move to.
431
+ * @param y - The y-coordinate to move to.
347
432
  * @returns this
348
433
  */
349
434
 
@@ -353,9 +438,10 @@ export class SvgPath extends SvgItem {
353
438
  }
354
439
 
355
440
  /**
356
- * draw aline to the given point
357
- * @param x end x
358
- * @param y end y
441
+ * Draws a straight line from the current position to the specified coordinates.
442
+ *
443
+ * @param x - The x-coordinate of the end point.
444
+ * @param y - The y-coordinate of the end point.
359
445
  * @returns this
360
446
  */
361
447
 
@@ -365,7 +451,18 @@ export class SvgPath extends SvgItem {
365
451
  }
366
452
 
367
453
  /**
368
- * draw a curve
454
+ * Draws a cubic Bézier curve from the current point to `(x3, y3)` using `(x1, y1)`
455
+ * as the control point at the beginning of the curve and `(x2, y2)` as the
456
+ * control point at the end of the curve.
457
+ *
458
+ * @param x1 - The x-coordinate of the first control point.
459
+ * @param y1 - The y-coordinate of the first control point.
460
+ * @param x2 - The x-coordinate of the second control point.
461
+ * @param y2 - The y-coordinate of the second control point.
462
+ * @param x3 - The x-coordinate of the end point of the curve.
463
+ * @param y3 - The y-coordinate of the end point of the curve.
464
+ *
465
+ * @returns The current `SvgPath` instance for chaining.
369
466
  */
370
467
 
371
468
  curveTo( x1: number, y1: number, x2: number, y2: number, x3: number, y3: number ) {
@@ -375,7 +472,9 @@ export class SvgPath extends SvgItem {
375
472
 
376
473
 
377
474
  /**
378
- * close the currentPath
475
+ * Closes the current subpath by drawing a straight line from the current position
476
+ * to the initial point of the current subpath.
477
+ * @returns The current `SvgPath` instance for chaining.
379
478
  */
380
479
 
381
480
  closePath( ): this {
@@ -385,11 +484,15 @@ export class SvgPath extends SvgItem {
385
484
 
386
485
  /**
387
486
  * draw an arc
388
- * @param x center x
389
- * @param y center y
390
- * @param r radius
391
- * @param start angle start in degrees
392
- * @param end angle end in degrees
487
+ * Draws an elliptical arc from the current point to a new point.
488
+ *
489
+ * @param x - The x-coordinate of the center of the ellipse.
490
+ * @param y - The y-coordinate of the center of the ellipse.
491
+ * @param r - The radius of the arc.
492
+ * @param start - The start angle of the arc in degrees (0 is right, 90 is down).
493
+ * @param end - The end angle of the arc in degrees.
494
+ * @param clockwise - If `true`, the arc is drawn clockwise; otherwise, counter-clockwise. Defaults to `true`.
495
+ *
393
496
  * @returns this
394
497
  */
395
498
 
@@ -406,11 +509,17 @@ export class SvgPath extends SvgItem {
406
509
  }
407
510
 
408
511
  /**
409
- *
512
+ * Represents an SVG text element, providing methods for positioning and styling text.
513
+ * It extends `SvgItem` to inherit common SVG element functionalities.
410
514
  */
411
515
 
412
516
  export class SvgText extends SvgItem {
413
-
517
+ /**
518
+ * Creates an instance of `SvgText`.
519
+ * @param x - The x-coordinate for the text's starting position.
520
+ * @param y - The y-coordinate for the text's starting position.
521
+ * @param txt - The text content.
522
+ */
414
523
  constructor( x: number, y: number, txt: string ) {
415
524
  super( 'text' );
416
525
 
@@ -420,18 +529,38 @@ export class SvgText extends SvgItem {
420
529
  this._dom.innerHTML = txt;
421
530
  }
422
531
 
532
+ /**
533
+ * Sets the font family for the text.
534
+ * @param font - The font family name (e.g., "Arial", "sans-serif").
535
+ * @returns The current `SvgText` instance for chaining.
536
+ */
423
537
  font( font: string ): this {
424
538
  return this.setAttr( 'font-family', font );
425
539
  }
426
540
 
541
+ /**
542
+ * Sets the font size for the text.
543
+ * @param size - The font size, either as a number (e.g., 12) or a string (e.g., "1.2em").
544
+ * @returns The current `SvgText` instance for chaining.
545
+ */
427
546
  fontSize( size: number | string ): this {
428
547
  return this.setAttr( 'font-size', size+'' );
429
548
  }
430
549
 
550
+ /**
551
+ * Sets the font weight for the text.
552
+ * @param weight - The font weight ("light", "normal", or "bold").
553
+ * @returns The current `SvgText` instance for chaining.
554
+ */
431
555
  fontWeight( weight: 'light' | 'normal' | 'bold' ): this {
432
556
  return this.setAttr( 'font-weight', weight );
433
557
  }
434
558
 
559
+ /**
560
+ * Sets the horizontal text alignment.
561
+ * @param align - The horizontal alignment ("left", "center", or "right").
562
+ * @returns The current `SvgText` instance for chaining.
563
+ */
435
564
  textAlign( align: 'left' | 'center' | 'right' ): this {
436
565
 
437
566
  let al;
@@ -439,12 +568,19 @@ export class SvgText extends SvgItem {
439
568
  case 'left': al = 'start'; break;
440
569
  case 'center': al = 'middle'; break;
441
570
  case 'right': al = 'end'; break;
442
- default: return this;
571
+ default:
572
+ // If an invalid alignment is provided, do nothing and return this for chaining.
573
+ // This prevents setting an invalid attribute value.
574
+ console.warn(`Invalid textAlign value: ${align}. Must be 'left', 'center', or 'right'.`);
575
+ return this;
443
576
  }
444
577
 
445
578
  return this.setAttr( 'text-anchor', al );
446
579
  }
447
580
 
581
+ /**
582
+ * change the vertical alignment
583
+ */
448
584
  verticalAlign( align: 'top' | 'center' | 'bottom' | 'baseline' ): this {
449
585
 
450
586
  let al;
@@ -453,7 +589,10 @@ export class SvgText extends SvgItem {
453
589
  case 'center': al = 'middle'; break;
454
590
  case 'bottom': al = 'baseline'; break;
455
591
  case 'baseline': al = 'mathematical'; break;
456
- default: return;
592
+ default:
593
+ // If an invalid alignment is provided, do nothing and return this for chaining.
594
+ console.warn(`Invalid verticalAlign value: ${align}. Must be 'top', 'center', 'bottom', or 'baseline'.`);
595
+ return this;
457
596
  }
458
597
 
459
598
  return this.setAttr( 'alignment-baseline', al );
@@ -461,10 +600,15 @@ export class SvgText extends SvgItem {
461
600
  }
462
601
 
463
602
  /**
464
- *
603
+ * Represents an SVG icon, which is essentially an SVG element embedded within another.
604
+ * It extends `SvgItem` to inherit common SVG element functionalities.
465
605
  */
466
606
 
467
607
  export class SvgIcon extends SvgItem {
608
+ /**
609
+ * Creates an instance of `SvgIcon` from an SVG string.
610
+ * @param svg - The SVG string, optionally prefixed with "data:image/svg+xml,".
611
+ */
468
612
  constructor( svg: string ) {
469
613
  super( "svg" );
470
614
 
@@ -497,7 +641,8 @@ export class SvgIcon extends SvgItem {
497
641
 
498
642
 
499
643
  /**
500
- *
644
+ * Represents a generic SVG shape element.
645
+ * It extends `SvgItem` to inherit common SVG element functionalities.
501
646
  */
502
647
 
503
648
  export class SvgShape extends SvgItem {
@@ -508,10 +653,15 @@ export class SvgShape extends SvgItem {
508
653
 
509
654
  /**
510
655
  *
656
+ * Type alias for a number or a percentage string.
511
657
  */
512
658
 
513
659
  type number_or_perc = number | `${string}%`
514
660
 
661
+ /**
662
+ * Represents an SVG linear gradient element.
663
+ * It extends `SvgItem` to inherit common SVG element functionalities.
664
+ */
515
665
  export class SvgGradient extends SvgItem {
516
666
 
517
667
  private static g_id = 1;
@@ -519,6 +669,14 @@ export class SvgGradient extends SvgItem {
519
669
  private _id: string;
520
670
  private _stops: { offset: number_or_perc, color: string } [];
521
671
 
672
+ /**
673
+ * Creates an instance of `SvgGradient`.
674
+ * @param x1 - The x-coordinate of the starting point of the gradient vector.
675
+ * @param y1 - The y-coordinate of the starting point of the gradient vector.
676
+ * @param x2 - The x-coordinate of the ending point of the gradient vector.
677
+ * @param y2 - The y-coordinate of the ending point of the gradient vector.
678
+ * @returns The current `SvgGradient` instance for chaining.
679
+ */
522
680
  constructor( x1: number_or_perc, y1: number_or_perc, x2: number_or_perc, y2: number_or_perc ) {
523
681
  super( 'linearGradient')
524
682
 
@@ -534,10 +692,20 @@ export class SvgGradient extends SvgItem {
534
692
  this._stops = [];
535
693
  }
536
694
 
695
+ /**
696
+ * Gets the URL reference to this gradient, suitable for use in `fill` or `stroke` attributes.
697
+ * @returns A string in the format `url(#<gradient_id>)`.
698
+ */
537
699
  get id( ) {
538
700
  return 'url(#'+this._id+')';
539
701
  }
540
702
 
703
+ /**
704
+ * Adds a color stop to the gradient.
705
+ * @param offset - The offset of the color stop, either as a number (0-100) or a percentage string.
706
+ * @param color - The color at this stop.
707
+ * @returns The current `SvgGradient` instance for chaining.
708
+ */
541
709
  addStop( offset: number_or_perc, color: string ): this {
542
710
  this._dom.insertAdjacentHTML( "beforeend", `<stop offset="${offset}%" stop-color="${color}"></stop>`);
543
711
  return this;
@@ -545,18 +713,29 @@ export class SvgGradient extends SvgItem {
545
713
  }
546
714
 
547
715
  /**
548
- *
716
+ * Represents an SVG group element (`<g>`), which can contain other SVG elements.
717
+ * It extends `SvgItem` and provides methods for appending various SVG shapes and gradients.
549
718
  */
550
719
 
551
720
  export class SvgGroup extends SvgItem {
552
721
 
722
+ /**
723
+ * Creates an instance of `SvgGroup`.
724
+ * @param tag - The SVG tag name for the group element (defaults to "g").
725
+ */
553
726
  constructor( tag = "g" ) {
554
727
  super( tag )
555
728
  }
556
729
 
557
730
  /**
558
- *
731
+ * Appends an `SvgItem` to this group.
732
+ *
733
+ * @template K - The type of the `SvgItem` being appended.
734
+ * @param item - The `SvgItem` instance to append.
735
+ *
736
+ * @returns The appended `SvgItem` instance.
559
737
  */
738
+
560
739
 
561
740
  append<K extends SvgItem>( item: K ): K {
562
741
  this._dom.appendChild( item.getDom() );
@@ -570,7 +749,8 @@ export class SvgGroup extends SvgItem {
570
749
  }
571
750
 
572
751
  /**
573
- *
752
+ * Creates and appends an `SvgPath` element to this group.
753
+ * @returns The newly created `SvgPath` instance.
574
754
  */
575
755
 
576
756
  path( ): SvgPath {
@@ -578,20 +758,46 @@ export class SvgGroup extends SvgItem {
578
758
  return this.append( path );
579
759
  }
580
760
 
761
+ /**
762
+ * Creates and appends an `SvgText` element to this group.
763
+ * @param x - The x-coordinate for the text.
764
+ * @param y - The y-coordinate for the text.
765
+ * @param txt - The text content.
766
+ * @returns The newly created `SvgText` instance.
767
+ */
581
768
  text( x: number, y: number, txt: string ) {
582
769
  const text = new SvgText( x, y, txt );
583
770
  return this.append( text );
584
771
  }
585
772
 
586
- ellipse( x: number, y: number, r1: number, r2: number ): SvgShape {
773
+ /**
774
+ * Creates and appends an SVG ellipse element to this group.
775
+ *
776
+ * @param x - The x-coordinate of the center of the ellipse.
777
+ * @param y - The y-coordinate of the center of the ellipse.
778
+ * @param r1 - The x-radius of the ellipse.
779
+ * @param r2 - The y-radius of the ellipse.
780
+ *
781
+ * @returns The newly created `SvgShape` instance representing the ellipse.
782
+ */
783
+ ellipse( x: number, y: number, r1: number, r2?: number ): SvgShape {
587
784
  const shape = new SvgShape( 'ellipse' );
588
785
  shape.setAttr( 'cx', num(x)+'' );
589
786
  shape.setAttr( 'cy', num(y)+'' );
590
787
  shape.setAttr( 'rx', num(r1)+'' );
591
- shape.setAttr( 'ry', num(r2)+'' );
788
+ shape.setAttr( 'ry', num(r2 ?? r1)+'' );
592
789
  return this.append( shape );
593
790
  }
594
791
 
792
+ /**
793
+ * Creates and appends an SVG circle element to this group.
794
+ * (Internally uses an ellipse with equal x and y radii).
795
+ *
796
+ * @param x - The x-coordinate of the center of the circle.
797
+ * @param y - The y-coordinate of the center of the circle.
798
+ * @param r1 - The radius of the circle.
799
+ * @returns The newly created `SvgShape` instance representing the circle.
800
+ */
595
801
  circle( x: number, y: number, r1: number ): SvgShape {
596
802
  const shape = new SvgShape( 'ellipse' );
597
803
  shape.setAttr( 'cx', num(x)+'' );
@@ -601,15 +807,37 @@ export class SvgGroup extends SvgItem {
601
807
  return this.append( shape );
602
808
  }
603
809
 
810
+ /**
811
+ * Creates and appends an `SvgIcon` element to this group.
812
+ *
813
+ * @param svg - The SVG string content for the icon.
814
+ * @param x - The x-coordinate for the icon's position.
815
+ * @param y - The y-coordinate for the icon's position.
816
+ * @param w - The width of the icon.
817
+ * @param h - The height of the icon.
818
+ * @returns The newly created `SvgIcon` instance.
819
+ */
604
820
  icon( svg: string, x: number, y: number, w: number, h: number ): SvgIcon {
605
821
  const icon = new SvgIcon( svg );
606
822
  icon.setAttr( 'x', num(x)+'' );
607
823
  icon.setAttr( 'y', num(y)+'' );
608
824
  icon.setAttr( 'width', num(w)+'' );
609
825
  icon.setAttr( 'height', num(h)+'' );
826
+ icon.setStyle( 'width', num(w)+'px' );
827
+ icon.setStyle( 'height', num(h)+'px' );
610
828
  return this.append( icon );
611
829
  }
612
830
 
831
+ /**
832
+ * Creates and appends an SVG rectangle element to this group.
833
+ * Handles negative height by adjusting `y` and `h` accordingly.
834
+ *
835
+ * @param x - The x-coordinate of the top-left corner of the rectangle.
836
+ * @param y - The y-coordinate of the top-left corner of the rectangle.
837
+ * @param w - The width of the rectangle.
838
+ * @param h - The height of the rectangle.
839
+ * @returns The newly created `SvgShape` instance representing the rectangle.
840
+ */
613
841
  rect( x: number, y: number, w: number, h: number ): SvgShape {
614
842
 
615
843
  if( h<0 ) {
@@ -625,6 +853,11 @@ export class SvgGroup extends SvgItem {
625
853
  return this.append( shape );
626
854
  }
627
855
 
856
+ /**
857
+ * Creates and appends an SVG group element (`<g>`) to this group.
858
+ * @param id - Optional. An ID for the new group.
859
+ * @returns The newly created `SvgGroup` instance.
860
+ */
628
861
  group( id?: string ) {
629
862
  const group = new SvgGroup( );
630
863
  if( id ) {
@@ -636,16 +869,20 @@ export class SvgGroup extends SvgItem {
636
869
 
637
870
  /**
638
871
  *
639
- * example
640
- * ```ts
641
- * const g = c.linear_gradient( '0%', '0%', '0%', '100%' )
642
- * .addStop( 0, 'red' )
643
- * .addStop( 100, 'green' );
644
- *
645
- * p.rect( 0, 0, 100, 100 )
646
- * .stroke( g.id );
647
- *
872
+ * Creates and appends an SVG linear gradient definition to this group.
873
+ *
874
+ * @example
875
+ * ```typescript
876
+ * const gradient = svgGroup.linear_gradient('0%', '0%', '0%', '100%')
877
+ * .addStop(0, 'red')
878
+ * .addStop(100, 'green');
879
+ * svgGroup.rect(0, 0, 100, 100).fill(gradient.id);
648
880
  * ```
881
+ * @param x1 - The x-coordinate of the starting point of the gradient vector.
882
+ * @param y1 - The y-coordinate of the starting point of the gradient vector.
883
+ * @param x2 - The x-coordinate of the ending point of the gradient vector.
884
+ * @param y2 - The y-coordinate of the ending point of the gradient vector.
885
+ * @returns The newly created `SvgGradient` instance.
649
886
  */
650
887
 
651
888
  linear_gradient( x1: number_or_perc, y1: number_or_perc, x2: number_or_perc, y2: number_or_perc ) {
@@ -654,7 +891,9 @@ export class SvgGroup extends SvgItem {
654
891
  }
655
892
 
656
893
  /**
657
- * clear
894
+ * Clears all child elements from this SVG group.
895
+ *
896
+ * @returns void
658
897
  */
659
898
 
660
899
  clear( ) {
@@ -669,15 +908,40 @@ export class SvgGroup extends SvgItem {
669
908
 
670
909
 
671
910
 
911
+ /**
912
+ * A specialized `SvgGroup` that provides methods for adding SVG definitions like clip paths and patterns.
913
+ * It extends `SvgGroup` to inherit common SVG element functionalities and acts as a container for definitions.
914
+ */
672
915
  export class SvgBuilder extends SvgGroup {
673
916
  private static g_clip_id = 1;
674
917
  private static g_pat_id = 1;
675
918
 
919
+ /**
920
+ * Creates an instance of `SvgBuilder`.
921
+ */
676
922
  constructor( ) {
677
923
  super( );
678
924
  }
679
925
 
926
+ /**
927
+ * Adds an SVG clip path definition to the builder.
928
+ *
929
+ * @param x - The x-coordinate of the top-left corner of the clipping rectangle.
930
+ * @param y - The y-coordinate of the top-left corner of the clipping rectangle.
931
+ * @param w - The width of the clipping rectangle.
932
+ * @param h - The height of the clipping rectangle.
933
+ * @returns An object containing the generated `id` for the clip path and the `SvgGroup` instance representing the clip path.
934
+ */
680
935
  addClip( x: number, y: number, w: number, h: number ) {
936
+ /**
937
+ * Adds an SVG clip path definition to the builder.
938
+ *
939
+ * @param x - The x-coordinate of the top-left corner of the clipping rectangle.
940
+ * @param y - The y-coordinate of the top-left corner of the clipping rectangle.
941
+ * @param w - The width of the clipping rectangle.
942
+ * @param h - The height of the clipping rectangle.
943
+ * @returns An object containing the generated `id` for the clip path and the `SvgGroup` instance representing the clip path.
944
+ */
681
945
  const id = 'clip-'+SvgBuilder.g_clip_id++;
682
946
  const clip = new SvgGroup( 'clipPath' );
683
947
  clip.setAttr('id', id );
@@ -687,7 +951,25 @@ export class SvgBuilder extends SvgGroup {
687
951
  return {id,clip};
688
952
  }
689
953
 
954
+ /**
955
+ * Adds an SVG pattern definition to the builder.
956
+ *
957
+ * @param x - The x-coordinate of the pattern tile's top-left corner.
958
+ * @param y - The y-coordinate of the pattern tile's top-left corner.
959
+ * @param w - The width of the pattern tile.
960
+ * @param h - The height of the pattern tile.
961
+ * @returns An object containing the generated `id` for the pattern and the `SvgGroup` instance representing the pattern.
962
+ */
690
963
  addPattern( x: number, y: number, w: number, h: number ) {
964
+ /**
965
+ * Adds an SVG pattern definition to the builder.
966
+ *
967
+ * @param x - The x-coordinate of the pattern tile's top-left corner.
968
+ * @param y - The y-coordinate of the pattern tile's top-left corner.
969
+ * @param w - The width of the pattern tile.
970
+ * @param h - The height of the pattern tile.
971
+ * @returns An object containing the generated `id` for the pattern and the `SvgGroup` instance representing the pattern.
972
+ */
691
973
  const id = 'pat-'+SvgBuilder.g_pat_id++;
692
974
 
693
975
  const pat = new SvgGroup( 'pattern' );
@@ -706,20 +988,25 @@ export class SvgBuilder extends SvgGroup {
706
988
 
707
989
 
708
990
  /**
709
- *
991
+ * Properties for the `SvgComponent`.
710
992
  */
711
993
 
712
- interface SvgProps extends ComponentProps {
994
+ export interface SvgProps extends ComponentProps {
713
995
  viewbox?: string;
714
- svg: SvgBuilder;
996
+ svg?: SvgBuilder;
715
997
  }
716
998
 
717
999
  /**
718
- *
1000
+ * A component that renders an SVG element, acting as a container for SVG graphics.
1001
+ * It extends `Component` and provides methods for setting SVG content.
719
1002
  */
720
1003
 
721
1004
  export class SvgComponent<P extends SvgProps = SvgProps> extends Component<P> {
722
1005
 
1006
+ /**
1007
+ * Creates an instance of `SvgComponent`.
1008
+ * @param props - The properties for the SVG component.
1009
+ */
723
1010
  constructor( props: P ) {
724
1011
  super( { ...props, tag: "svg", ns: SVG_NS } );
725
1012
 
@@ -734,11 +1021,21 @@ export class SvgComponent<P extends SvgProps = SvgProps> extends Component<P> {
734
1021
  }
735
1022
  }
736
1023
 
1024
+ /**
1025
+ * Sets the entire SVG content of the component using an `SvgBuilder`.
1026
+ * Any existing content will be cleared.
1027
+ * @param bld - The `SvgBuilder` instance containing the SVG elements to render.
1028
+ */
737
1029
  setSvg( bld: SvgBuilder ) {
738
1030
  this.clearContent( );
739
1031
  this.dom.appendChild( bld.getDom() );
740
1032
  }
741
1033
 
1034
+ /**
1035
+ * Appends one or more `SvgItem` instances directly to the SVG component's DOM.
1036
+ *
1037
+ * @param items - A spread array of `SvgItem` instances to append.
1038
+ */
742
1039
  addItems( ...items: SvgItem[] ) {
743
1040
  items.forEach( item => this.dom.appendChild( item.getDom() ) );
744
1041
  }