### Install Dependencies (npm)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/README.md
Installs the necessary project dependencies using npm. This command should be run first to set up the project environment.
```bash
npm install
```
--------------------------------
### Including SVG.js Script in HTML
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Provides the basic HTML structure required to use SVG.js by including the library script from a CDN in the
section of the document.
```html
SVG.js
```
--------------------------------
### Creating and Adding SVG Document in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Demonstrates how to initialize a new SVG document using SVG(), add it to a target element (like body), set its size, and draw a basic shape like a rectangle.
```javascript
var draw = SVG().addTo('body').size(300, 300)
var rect = draw.rect(100, 100).attr({ fill: '#f06' })
```
--------------------------------
### Sizing SVG Document with Percentages in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Shows how to create an SVG document and set its dimensions using percentage values relative to its parent container, targeting an element by its ID.
```javascript
var draw = SVG().addTo('#someId').size('100%', '100%')
```
--------------------------------
### Importing SVG.js Module in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Shows how to import the necessary SVG object when using SVG.js in a modern JavaScript module environment.
```javascript
import { SVG } from '@svgdotjs/svg.js'
```
--------------------------------
### Waiting for DOMContentLoaded in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Illustrates how to use SVG.on to ensure that SVG.js code that interacts with the DOM runs only after the entire HTML document has been fully loaded and parsed.
```javascript
SVG.on(document, 'DOMContentLoaded', function() {
var draw = SVG().addTo('body')
})
```
--------------------------------
### Using SVG.js in Pure SVG Document
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Provides an example of embedding SVG.js and its usage directly within a standalone XML/SVG file, demonstrating how to select an element and perform actions using embedded JavaScript within a CDATA section.
```xml
```
--------------------------------
### Demonstrating SVG() Function Uses in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/3-getting-started/default.txt
Explains the versatility of the core SVG() function, showing how it can be used to create new documents, retrieve existing SVG.js elements from the DOM using various selectors, create elements from SVG fragments, or convert DOM nodes into SVG.js objects.
```javascript
// new document
var draw = SVG()
// get rect from dom
var rect = SVG('#myRectId')
// or
var rect = SVG('rect')
// any css selector will do
var path = SVG('#group1 path.myClass')
// create new object from fragment
var circle = SVG('')
// convert node to svg.js object
var obj = SVG(node)
```
--------------------------------
### Install Node.js Dependencies
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/2-documentation/default.txt
This command installs all required Node.js packages listed in the project's package.json file. It is typically only necessary to run this command once after cloning the repository.
```Shell
npm install
```
--------------------------------
### Install Dependencies (npm)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/default.txt
Installs the project's dependencies using npm. This is required before building or testing the library.
```sh
$ npm install
```
--------------------------------
### Run Test Suite (npm)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/default.txt
Executes the project's test suite from the command line. Requires Firefox to be installed.
```sh
$ npm test
```
--------------------------------
### Install SVG.js using Npm
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/2-installation/default.txt
Install the SVG.js library using the npm package manager. This command downloads and installs the package into the project's node_modules directory.
```sh
npm install @svgdotjs/svg.js
```
--------------------------------
### Install SVG.js using Yarn
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/2-installation/default.txt
Install the SVG.js library using the Yarn package manager. This command adds the package as a dependency to the project.
```sh
yarn add @svgdotjs/svg.js
```
--------------------------------
### Creating an Email Input Field in HTML
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/test/etc/kirbytext/input-with-placeholder/test.txt
This snippet shows how to create a standard HTML input field specifically for capturing email addresses. It uses the 'text' type and includes a placeholder attribute to guide the user.
```HTML
```
--------------------------------
### Printing 'Hello World' in PHP
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/erusev/parsedown/test/data/code_block.md
This snippet initializes a string variable and prints its value to the standard output using the `echo` statement in PHP.
```php
returns rect
draw.get(1) //-> returns circle
```
--------------------------------
### Using a Custom SVG Element (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/12-extending/default.txt
Provides a simple example of how to create an instance of the custom `SVG.Rounded` element using the factory method (`rounded`) added to the drawing container.
```javascript
var rounded = draw.rounded(200, 100)
```
--------------------------------
### Good Style: Variable Declaration at Start (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/1-coding-style/default.txt
Shows the preferred method for declaring multiple local variables at the beginning of a function or method, separating declaration from assignment.
```javascript
function reading_board() {
var aap, noot, mies
aap = 1
noot = 2
mies = aap + noot
}
```
--------------------------------
### Animation with Duration, Delay, When - SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Illustrates passing duration, delay, and `when` parameters to the `animate()` method to control timing and start point, followed by animating attributes.
```javascript
rect.animate(2000, 1000, 'now').attr({ fill: '#f03' })
```
--------------------------------
### Bad Style: Compressed Code (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/1-coding-style/default.txt
Example of coding style to avoid, showing overly compressed code without sufficient spacing or newlines, which reduces readability.
```javascript
var nest=draw.nested().attr({x:10,y:20,width:200,height:300});
for(var i=0;i<5;i++)nest.circle(100);
```
--------------------------------
### Getting the First Child using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet shows how to use the first() method on a parent element (like a drawing or group) to retrieve its first direct child element as an SVG.js instance.
```javascript
draw.first()
```
--------------------------------
### Echoing a Variable in PHP
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/erusev/parsedown/test/data/fenced_code_block.md
This snippet declares a string variable and then prints its value to the output using the echo statement. It demonstrates a basic variable assignment and output operation in PHP.
```php
```
--------------------------------
### Getting Bounding Box of PointArray (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to calculate the bounding box of the points contained within an SVG.PointArray instance using the `bbox()` method.
```javascript
array.bbox()
```
--------------------------------
### Applying Easing to SVG.js Runner (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Demonstrates how to set the easing function for an animation runner using the `ease()` method. It shows examples using a predefined string alias and passing a custom easing function created by `SVG.easing.beziere` or `SVG.easing.step`.
```JavaScript
var runner = new SVG.Runner({duration: 1000})
// use a string
runner.ease('<>')
// or pass a function
runner.ease(SVG.easing.beziere(x1, y1, x2, y2))
runner.ease(SVG.easing.step(5, 'jump-end'))
```
--------------------------------
### Getting Bounding Box of PathArray (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to calculate the bounding box of the geometry defined by an SVG.PathArray instance using the `bbox()` method.
```javascript
array.bbox()
```
--------------------------------
### Getting Hex Value of SVG.Color (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Shows how to retrieve the hexadecimal string representation of an SVG.Color instance using the `toHex()` method.
```javascript
color.toHex() //-> returns '#ff0066'
```
--------------------------------
### Styling Paragraphs with CSS
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/erusev/parsedown/test/data/block-level_html.md
This CSS rule targets all paragraph elements (`p`) and sets their text color to the hexadecimal value #789.
```css
p {color: #789;}
```
--------------------------------
### Getting RGB String of SVG.Color (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Shows how to retrieve the CSS RGB string representation of an SVG.Color instance using the `toRgb()` method.
```javascript
color.toRgb() //-> returns 'rgb(255,0,102)'
```
--------------------------------
### Getting Pattern URL in SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Illustrates how to retrieve the URL reference string for a created pattern element, which can be used in CSS or other contexts.
```javascript
pattern.url() //-> returns 'url(#SvgjsPattern1234)'
```
--------------------------------
### Getting the Root SVG Element using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet demonstrates the root() method, which can be called on any SVG.js element instance to traverse up the parent chain and return the top-level SVG.Svg drawing element.
```javascript
var draw = SVG().addTo('#drawing')
var rect = draw.rect(100, 100)
rect.root() //-> returns draw
```
--------------------------------
### Getting PathArray from SVG Element (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Shows how to retrieve the underlying SVG.PathArray instance from an SVG path element using the `array()` method.
```javascript
path.array() //-> returns the SVG.PathArray instance
```
--------------------------------
### Bad Style: Multi-Line Comments, Cryptic Names (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/1-coding-style/default.txt
Example of commenting style to avoid, using multi-line block comments and cryptic method names, which is less preferred than concise single-line comments and readable names.
```javascript
/*
*
* does something with orange and opacity
*
*/
SVG.extend(SVG.Rect, {
orgf: function() {
return this.fill('orange').opacity(0.85)
}
})
```
--------------------------------
### Getting Memory Data with SVG.js remember() in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves data stored temporarily in memory on an SVG element using a specified key.
```javascript
rect.remember('oldBBox')
```
--------------------------------
### Calling parents() to get ancestors (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Retrieves all ancestor elements of the current element up to a specified matcher or the root SVG element, returning an SVG.List. If no matcher is provided, it returns all ancestors up to the root.
```javascript
var group1 = draw.group().addClass('test')
, group2 = group1.group()
, rect = group2.rect(100,100)
rect.parents() // returns [group2, group1, draw]
rect.parents('.test') // returns [group2, group1]
rect.parents(group2) // returns [group2]
rect.parents(group1) // returns [group2, group1]
```
--------------------------------
### Initializing and Parsing Markdown with Parsedown in PHP
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/erusev/parsedown/README.md
This snippet demonstrates how to initialize the Parsedown class and use its `text` method to convert a Markdown string into HTML. It shows a basic example of parsing italic text.
```php
$Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: Hello Parsedown !
```
--------------------------------
### Bad Style: Individual Variable Declaration (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/1-coding-style/default.txt
Example of variable declaration style to avoid, where each variable is declared and assigned individually rather than declaring all at the beginning of the function.
```javascript
function reading_board() {
var aap = 1
var noot = 2
var mies = aap + noot
}
```
--------------------------------
### Get Morphable Point with SVG.js to() - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Creates a morphable object from an SVG.Point instance, allowing interpolation between the original point and a target point at a specified position.
```javascript
var point = new SVG.Point(1,1).to(11,10)
point.at(0.5) //-> {x: 6, y: 5.5}
```
--------------------------------
### Getting Link Element with linker() - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/4-container-elements/default.txt
Demonstrates how to use the `linker()` method on an SVG element to retrieve the associated `` element if the element is part of a link. Returns the ` ` element or `null` if not a link.
```javascript
rect.linker() // returns the link
```
--------------------------------
### Getting PointArray from SVG Element (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Shows how to retrieve the underlying SVG.PointArray instance from an SVG element like a polygon or polyline using the `array()` method.
```javascript
polygon.array() //-> returns the SVG.PointArray instance
```
--------------------------------
### Playing/Resuming SVG.js Timeline Animations (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Shows how to resume the execution of paused animations on a timeline using the `play()` method. This example demonstrates pausing on mouseover and resuming on mouseout.
```JavaScript
rect.animate().move(200, 200)
rect.mouseover(function() { this.timeline().pause() })
rect.mouseout(function() { this.timeline().play() })
```
--------------------------------
### Build SVG.js Library (npm)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/default.txt
Builds the SVG.js library using the configured build script (likely Rollup). The output files are placed in the `dist` folder.
```sh
$ npm run build
```
--------------------------------
### Getting All Direct Children using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet shows how to use the children() method on an SVG.js element (like a drawing or group) to retrieve an SVG.List containing all of its direct child elements. This list can then be iterated or manipulated.
```javascript
draw.children()
```
--------------------------------
### Merging SVG.Box instances in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to merge two SVG.Box instances to create a new box representing their combined bounding area. It shows creating two rectangles, getting their bounding boxes, and then merging them.
```javascript
var box1 = draw.rect(100,100).move(50,50).bbox()
var box2 = draw.rect(100,100).move(200,200).bbox()
var box3 = box1.merge(box2)
```
--------------------------------
### Getting Data with SVG.js data() in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves data stored on an SVG element. Can fetch all data as an object, a single value by key, or multiple values by an array of keys.
```javascript
var obj = rect.data()
var value = rect.data('key')
var obj2 = rect.data(['key1', 'key2'])
```
--------------------------------
### Creating a new SVG document with SVG() (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Creates and returns a new SVG.Svg document instance, which serves as the root for drawing SVG content.
```javascript
var draw = SVG()
```
--------------------------------
### Getting Path Length in SVG.js (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Retrieves the total calculated length of the path element.
```javascript
var length = path.length()
```
--------------------------------
### Using SVG.Number Class in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates creating an SVG.Number instance from a string value (like '78%'), performing operations like addition using plus(), and converting it back to a string or getting its numeric value using valueOf().
```javascript
var number = new SVG.Number('78%')
number.plus('3%').toString() //-> returns '81%'
number.valueOf() //-> returns 0.81
```
--------------------------------
### Creating SVG Line Element with line() - svg.js - Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Creates an SVG Line element using the line() constructor method on an SVG container. The method takes four arguments representing the start point (x1, y1) and end point (x2, y2) coordinates. It also shows setting the stroke.
```Javascript
var line = draw.line(0, 0, 100, 150).stroke({ width: 1 })
```
--------------------------------
### Creating an HTML element with SVG() (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Creates and returns an HTML element instance by parsing the provided markup string and specifying the HTML namespace as the second parameter.
```javascript
var rect = SVG('', true)
```
--------------------------------
### Orchestrating Multiple SVG.js Animations on Timeline (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Demonstrates how to coordinate animations of multiple elements by assigning them to a single `SVG.Timeline`. Animations are scheduled with absolute start times relative to the timeline, allowing for complex sequences.
```JavaScript
var timeline = new SVG.Timeline()
var rect1 = draw.rect(100, 200)
var rect2 = draw.rect(200, 100)
rect1.timeline(timeline)
rect2.timeline(timeline)
rect1.animate(300, 0, 'absolute').move(300, 300) // start at time 0 of timeline
rect2.animate(400, 200, 'absolute').move(500, 500) // start at time 200 of timeline
```
--------------------------------
### Get All Siblings - SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves an array containing all sibling elements of the current element, including the element itself.
```javascript
rect.siblings()
```
--------------------------------
### Getting the Last Child using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet shows how to use the last() method on a parent element (like a drawing or group) to retrieve its last direct child element as an SVG.js instance.
```javascript
draw.last()
```
--------------------------------
### Bad Style: Double Quotes, Semicolons, Braces (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/1-coding-style/default.txt
Example of coding style to avoid, showing the use of double quotes, unnecessary semicolons, and curly braces on new lines, which deviates from the preferred style.
```javascript
var text = draw.text("with double quotes here");
var nest = draw.nested().attr("x", "50%");
for (var i = 0; i < 5; i++) {
if (i != 3) {
nest.circle(100);
};
};
```
--------------------------------
### Get Previous Sibling - SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the previous sibling element of the current element within its parent.
```javascript
rect.prev()
```
--------------------------------
### Initialize SVG.js Point - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates various ways to construct an SVG.Point object using different input formats, including single number, x/y pair, array, object, or another SVG.Point.
```javascript
var vector1 = new SVG.Point(1)
var vector2 = new SVG.Point(1,1)
var vector3 = new SVG.Point([1,1])
var vector4 = new SVG.Point({x:1,y:1})
var vector5 = new SVG.Point(new SVG.Point(1,1))
```
--------------------------------
### Instantiating SVG.PointArray
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to explicitly create an instance of SVG.PointArray using the `new` keyword and providing a multi-dimensional array of points.
```javascript
new SVG.PointArray([
[0, 0]
, [100, 100]
])
```
--------------------------------
### Get Next Sibling - SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the next sibling element of the current element within its parent.
```javascript
rect.next()
```
--------------------------------
### Getting Text Y Position by Baseline in SVG.js (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Retrieves the current y-coordinate of the text element based on its baseline.
```javascript
var x = text.ay()
```
--------------------------------
### Make Git Hook Executable (chmod)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/default.txt
Makes the specified file (`.git/hooks/pre-push`) executable using `chmod`. This is necessary for the Git hook script to run automatically.
```sh
sudo chmod +x .git/hooks/pre-push
```
--------------------------------
### Getting Specific CSS Properties by Array with svgdotjs JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the values of multiple specific CSS properties from the element's 'style' attribute. Pass an array of property names as the argument to the method.
```javascript
element.css(['cursor', 'fill'])
```
--------------------------------
### Get Element Position - SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the index position (a number) of the element among its siblings within its parent container.
```javascript
rect.position()
```
--------------------------------
### Including Kirby Toolkit Bootstrap in PHP
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/getkirby/toolkit/readme.md
This PHP snippet shows how to include the main bootstrap file for the Kirby Toolkit. Requiring this file makes the toolkit's classes and functions available for use in your PHP application.
```PHP
```
--------------------------------
### Initializing Root SVG Document - SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/4-container-elements/default.txt
Creates a root SVG document instance using the SVG() constructor and adds it to a specified DOM element.
```javascript
var draw = SVG().addTo('#drawing')
```
--------------------------------
### Getting Text X Position by Anchor in SVG.js (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Retrieves the current x-coordinate of the text element based on its text anchor.
```javascript
var x = text.ax()
```
--------------------------------
### Creating and using SVG.List in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Illustrates the creation of an SVG.List (inheriting from native array) and adding elements to it. It shows how to access elements by index and apply methods (like fill) to all elements in the list simultaneously, as well as retrieving properties from all elements.
```javascript
// create some elements
var rect = draw.rect(100,100)
var circle = draw.circle(100).move(100,100).fill('#f09')
// create a set and add the elements
var list = new SVG.List([rect])
list.push(circle)
// list[0] == rect
// list[1] == circle
// change the fill of all elements in the set at once
list.fill('#ff0')
var allfilles = list.fill() // get all the colors
```
--------------------------------
### Manually Creating and Scheduling SVG.Runner - SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Demonstrates how to instantiate an `SVG.Runner` directly, define its animation properties, associate it with an element later, and schedule it on an `SVG.Timeline` for execution.
```javascript
var runner = new SVG.Runner(1000)
runner.move(100, 100)
runner.element(someElement)
// Step animation by 20ms
runner.step(20)
// To animate, we need a timeline on which the runner is run
var timeline = new SVG.Timeline()
timeline.schedule(runner)
```
--------------------------------
### Getting Point on Path in SVG.js (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Returns an SVG.Point object representing the coordinates on the path at a specified distance along its length.
```javascript
var point = path.pointAt(105)
```
--------------------------------
### Scheduling SVG.js Runner on Timeline (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Explains how to explicitly schedule an SVG.js runner onto a timeline using the `schedule()` method. This allows controlling when a specific animation runner starts relative to the timeline's progression.
```JavaScript
var timeline = new SVG.Timeline()
var runner = new SVG.Runner()
runner.move(100, 100)
timeline.schedule(runner, 100, 'now') // runner, delay, when - see animate()
```
--------------------------------
### Instantiating SVG.PathArray
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to explicitly create an instance of SVG.PathArray using the `new` keyword and providing a multi-dimensional array of path segments.
```javascript
new SVG.PathArray([
['M', 0, 0]
, ['L', 100, 100]
, ['z']
])
```
--------------------------------
### Get TextPath from SVG.js Text
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Shows how to retrieve an existing textPath element associated with an SVG.js text element using the textPath() method. This allows further manipulation of the textPath, such as setting attributes like startOffset.
```javascript
var textpath = text.textPath().attr('startOffset', '50%')
```
--------------------------------
### Creating an SVG element from markup with SVG() (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Creates and returns an SVG element instance by parsing the provided SVG markup string. This is useful for creating elements from existing XML.
```javascript
var rect = SVG('')
```
--------------------------------
### Getting Index of Direct Child using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet demonstrates the index() method, which returns the zero-based index of a specified direct child element within its parent's children list. If the element is not a direct child, it returns -1.
```javascript
var rect = draw.rect(100, 50)
var group = draw.group()
draw.index(rect) //-> returns 0
group.index(rect) //-> returns -1
```
--------------------------------
### Code Block Escaping (Text)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/erusev/parsedown/test/data/escaping.md
This snippet illustrates that characters like the asterisk (`*`) are also rendered literally when placed within a Markdown code block, typically created by indenting lines or using fenced code blocks.
```text
escaped \*emphasis\* in a code block
```
--------------------------------
### Adopting Existing DOM Element using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet demonstrates how to wrap a native SVG DOM element, created using document.createElementNS, with an SVG.js instance. Passing the DOM element to the global SVG() function returns an SVG.js element instance, allowing you to use SVG.js methods on it.
```javascript
var polygon = document.createElementNS('http://www.w3.org/2000/svg', 'polygon')
var element = SVG(polygon)
element.fill('#f06')
```
--------------------------------
### Initializing SVG.Matrix in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Shows various ways to initialize an SVG.Matrix instance in SVG.js, including without arguments (default identity matrix), with six numerical arguments, a string representation, an object with matrix components, an object with transform properties, a native SVGMatrix, or an SVG.Element instance.
```javascript
var matrix = new SVG.Matrix
matrix.toString() //-> returns matrix(1,0,0,1,0,0)
```
```javascript
var matrix = new SVG.Matrix(1, 0, 0, 1, 100, 150)
matrix.toString() //-> returns matrix(1,0,0,1,100,150)
```
```javascript
var matrix = new SVG.Matrix('1,0,0,1,100,150')
matrix.toString() //-> returns matrix(1,0,0,1,100,150)
```
```javascript
var matrix = new SVG.Matrix({ a: 1, b: 0, c: 0, d: 1, e: 100, f: 150 })
matrix.toString() //-> returns matrix(1,0,0,1,100,150)
```
```javascript
var matrix = new SVG.Matrix({ translate: [20, 20] })
```
```javascript
var svgMatrix = svgElement.getCTM()
var matrix = new SVG.Matrix(svgMatrix)
matrix.toString() //-> returns matrix(1,0,0,1,0,0)
```
```javascript
var rect = draw.rect(50, 25)
var matrix = new SVG.Matrix(rect)
matrix.toString() //-> returns matrix(1,0,0,1,0,0)
```
--------------------------------
### Enable Build Mode for SVG.js Text
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Demonstrates how to manually enable build mode on an SVG.js text element using text.build(true). In build mode, subsequent calls to plain() and tspan() append content instead of replacing it. The example shows appending multiple parts and then disabling build mode.
```javascript
var text = draw.text('This is just the start, ')
text.build(true) // enables build mode
var tspan = text.tspan('something pink in the middle ').fill('#00ff97')
text.plain('and again boring at the end.')
text.build(false) // disables build mode
tspan.animate('2s').fill('#f06')
```
--------------------------------
### Reversing SVG.js Timeline Animations (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Explains how to reverse the playback direction of animations on a timeline using the `reverse()` method. It shows examples of reversing the current playback and explicitly setting the direction to backward or forward.
```JavaScript
// will run from 100,100 to rects initial position
rect.animate(3000).move(100, 100)
rect.timeline().reverse()
// sets direction to backwards
rect.timeline().reverse(true)
// sets direction to forwards
rect.timeline().reverse(false)
```
--------------------------------
### Get Leading from SVG.js Text
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Shows how to retrieve the current leading value set on an SVG.js text element using the leading() method as a getter.
```javascript
var leading = text.leading()
```
--------------------------------
### Git Pre-Push Hook Script
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/default.txt
A shell script intended for use as a Git pre-push hook. It builds the project, runs tests, reports the test result, and resets the working directory before exiting with the test status code.
```sh
#!/bin/sh
npm run build:test && npm run test:quick
# check how the test went
testCode=$?
[ "$testCode" = 0 ] || echo "Your current build does not pass our unit tests - please make them pass before you push"
# revert artifacts created during build
git reset --hard $(git log -1 --pretty=%H)
# exit with the test exit code
exit $testCode
```
--------------------------------
### Calling parent() with selector or class (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Demonstrates using the parent() method with a class or CSS selector argument to find a specific ancestor element.
```javascript
var draw = SVG().addTo('#drawing')
var nested = draw.nested().addClass('test')
var group = nested.group()
var rect = group.rect(100, 100)
rect.parent() //-> returns group
rect.parent(SVG.Svg) //-> returns nested
nested.parent(SVG.Svg) //-> returns draw
rect.parent(SVG.G) //-> returns group
rect.parent('.test') //-> returns nested
```
--------------------------------
### Using jQuery/Zepto Selectors with SVG.js Elements
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet illustrates how to use jQuery or Zepto selectors to find native SVG DOM elements created by SVG.js. It then accesses the corresponding SVG.js instance via the this.instance property within the jQuery/Zepto each() loop to apply SVG.js methods like animate() and fill().
```javascript
// add elements
var draw = SVG().addTo('#drawing')
var group = draw.group().addClass('my-group')
var rect = group.rect(100,100).addClass('my-element')
var circle = group.circle(100).addClass('my-element').move(100, 100)
// get elements in group
var elements = $('#drawing g.my-group .my-element').each(function() {
this.instance.animate().fill('#f09')
})
```
--------------------------------
### Getting Viewbox in SVG.js (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the current viewbox of an SVG element. This method is used as a getter and returns an `SVG.Box` object representing the viewbox properties.
```JavaScript
drawing.viewbox()
```
--------------------------------
### SVG.Runner Methods Overview - SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Provides a comprehensive list of methods available on the `SVG.Runner` instance, which is returned by the `animate()` method, allowing control over animation playback, scheduling, and properties.
```javascript
let rect = draw.rect(100, 100)
let runner = rect.animate()
runner.element() // returns or sets the element the runner is bound to
runner.timeline() // returns or sets the timeline the runner will be / is scheduled on
runner.animate() // for animation chaining. See element.animate()
runner.schedule(timeline, delay, when) // schedules the runner on the timeline. Timeline can be skipped if already set
runner.unschedule() // removes the runner from the timeline
runner.loop(times, swing, wait) // loops the animation by `times` times with `wait` milliseconds time between each loop
runner.queue(runOnceFn, runOnEveryStepFn) // Lets you chain functions which are not neccecarily animations
runner.during(fn) // Lets you bind a function to every animation step
runner.after(fn) // Lets you bind a function which is executed after the animation is finished
runner.time() // returns or sets the runner time
runner.duration() // returns the duration the runner will run
runner.loops() // Lets you jump to a specific iteration of the runner e.g. 3.5 for 4th loop half way through
runner.persist() // Make this runner persist on the timeline forever (true) or for a specific time. Usually a runner is deleted after execution to clean up memory.
runner.position() // returns or sets the current position of the runner ignoring the wait times (between 0 and 1)
runner.progress() // returns or sets the current position of the runner including the wait times (between 0 and 1)
runner.step(dt) // step the runner by a certain time (for manually stepping trough animations)
runner.reset() // set the runner back to zero time and all animations with it
runner.finish() // steps the runner to its finished state
runner.reverse() // execute the runner backwards
runner.ease() // change the easing of the animation
runner.active() // returns or sets the active state of the runner. Inactive runners are not executed
```
--------------------------------
### Get Morphable Number with SVG.js to() - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Creates a morphable object from an SVG.Number instance, allowing interpolation between the original number and a target value at a specified position.
```javascript
var number = new SVG.Number('79%').to('3%')
number.at(0.55).toString() //-> '37.2%'
```
--------------------------------
### Importing/Exporting HTML with svg.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/11-importing-exporting/default.txt
Use the `html()` method to handle HTML content. Pass an HTML string to import it with the correct namespace, or call it without arguments to export the element's HTML content.
```javascript
draw.html('
) // import html
draw.html() // export
```
--------------------------------
### Good Style: Single-Line Comments (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/15-contributing/1-coding-style/default.txt
Shows the preferred style for adding comments using concise, single-line comments to explain specific parts of the code.
```javascript
// Adds orange-specific methods
SVG.extend(SVG.Rect, {
// Add a nice, transparent orange
orangify: function() {
// fill with orange color
this.fill('orange')
// add a slight opacity
return this.opacity(0.85)
}
})
```
--------------------------------
### Referencing First Element by Selector using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet demonstrates how to use the global SVG() function to select the first SVG element in the document that matches the provided CSS selector. It returns an SVG.js element instance, allowing further manipulation like setting the fill color.
```javascript
var rect = SVG('rect.my-class').fill('#f06')
```
--------------------------------
### Extending Multiple SVG Elements Simultaneously (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/12-extending/default.txt
Demonstrates how to apply the same extension (the `paintRed` method filling with 'orangered') to an array of different SVG element types (`SVG.Ellipse`, `SVG.Path`, `SVG.Polygon`) using a single `SVG.extend` call.
```javascript
SVG.extend([SVG.Ellipse, SVG.Path, SVG.Polygon], {
paintRed: function() {
return this.fill('orangered')
}
})
```
--------------------------------
### Get Untransformed Bounding Box - SVG.js JS
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Returns the untransformed bounding box of an element as an SVG.Box object. This is the tightest box around the element before any transformations are applied.
```js
element.bbox()
```
--------------------------------
### Iterating Over Direct Children using SVG.js each()
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet shows how to use the each() method to iterate over the direct child elements of a parent. A callback function is executed for each child, with this referring to the current child element, and the index (i) and the children list (children) provided as arguments.
```javascript
draw.each(function(i, children) {
this.fill({ color: '#f06' })
})
```
--------------------------------
### Creating an SVG element using the constructor (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Creates a bare SVG element instance (e.g., SVG.Rect) directly using its constructor, without automatically attaching it to the DOM. This is useful for creating elements programmatically before adding them to the document tree.
```javascript
var rect = new SVG.Rect()
```
--------------------------------
### Getting Element ID with svgdotjs JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the 'id' attribute of the SVG element. If the element does not have an ID, this method will generate and assign a new unique ID before returning it.
```javascript
var id = rect.id()
```
--------------------------------
### Getting gradient stop by index - SVG.js - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Retrieves a specific color stop from an existing gradient definition by its index. The index corresponds to the order in which the stops were added.
```javascript
var gradient = draw.gradient('radial', function(add) {
add.stop({ offset: 0, color: '#000', opacity: 1 }) // -> first
add.stop({ offset: 0.5, color: '#f03', opacity: 1 }) // -> second
add.stop({ offset: 1, color: '#066', opacity: 1 }) // -> third
})
var s1 = gradient.get(0) // -> returns "first" stop
```
--------------------------------
### Referencing All Elements by Selector within Context using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet demonstrates using the static SVG.find() method with an optional second argument, which specifies a DOM node (or SVG.js element instance) to search within. It finds all matching elements only within that context and returns them as an SVG.List.
```javascript
var list = SVG.find('.someClass', group)
list.fill('#f06')
```
--------------------------------
### Creating SVG.Array from array in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to instantiate an SVG.Array by passing a standard JavaScript array to its constructor. This provides a more structured way to define the array's contents compared to a string.
```javascript
new SVG.Array([ .343, .669, .119, 0, 0
, .249, -.626, .130, 0, 0
, .172, .334, .111, 0, 0
, .000, .000, .000, 1, -0 ])
```
--------------------------------
### Pausing SVG.js Timeline Animations (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/8-animating/default.txt
Demonstrates how to pause the execution of all animations on a timeline using the `pause()` method. This example shows pausing the animation on a mouseover event.
```JavaScript
rect.animate().move(200, 200)
rect.mouseover(function() { this.timeline().pause() })
```
--------------------------------
### Getting Zoom Level in SVG.js (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the current zoom level of an SVG element. This method is used as a getter and returns a number representing the current zoom factor.
```JavaScript
drawing.zoom()
```
--------------------------------
### Extending SVG.Svg (Document) with a Custom Method (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/12-extending/default.txt
Illustrates extending the main `SVG.Svg` document object with a custom method, `paintAllPink`. This method iterates through all elements within the document and sets their fill color to 'pink'.
```javascript
SVG.extend(SVG.Svg, {
paintAllPink: function() {
this.each(function() {
this.fill('pink')
})
}
})
```
--------------------------------
### Creating a Custom SVG Element by Subclassing (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/12-extending/default.txt
Shows how to create a new custom element (`SVG.Rounded`) by extending `SVG.Rect`. It includes defining a custom `size` method that proportionally scales rounded corners and extending `SVG.Container` to add a factory method (`rounded`) for easily creating instances of the new element.
```javascript
SVG.Rounded = class extends SVG.Rect{
// Create method to proportionally scale the rounded corners
size: function(width, height) {
return this.attr({
width: width
, height: height
, rx: height / 5
, ry: height / 5
})
}
})
```
```javascript
// Add a method to create a rounded rect
SVG.extend(SVG.Container, {
// Create a rounded element
rounded: function(width, height) {
return this.put(new SVG.Rounded).size(width, height)
}
})
```
--------------------------------
### Get All Attributes SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves all attributes of an SVG element as an object using the `attr()` method without arguments. This method returns an object containing all attributes and their values.
```javascript
var attributes = rect.attr()
```
--------------------------------
### Creating a Rectangle with SVG.js - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/1-home/default.txt
Demonstrates how to create a 100x100 pixel rectangle filled with the color #f06 using SVG.js and add it to an element with the ID 'drawing'. This highlights the concise syntax of the library compared to vanilla JavaScript.
```JavaScript
// SVG.js
var draw = SVG().addTo('#drawing')
, rect = draw.rect(100, 100).fill('#f06')
```
--------------------------------
### Adding nested tspan - SVG.js - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Adds a new tspan element nested inside the current tspan element. The new tspan can then be further configured, for example, by setting its fill color.
```javascript
tspan.tspan('I am a child of my parent').fill('#f06')
```
--------------------------------
### Representing PathArray in SVG.js (Multi-dimensional Array)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Shows the multi-dimensional array representation, where each path segment is an inner array starting with the command and followed by its parameters. This is the format used internally by SVG.js.
```javascript
[
['M', 0, 0]
, ['L', 100, 100]
, ['z']
]
```
--------------------------------
### Exporting Full SVG with svg.js (Getter)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/11-importing-exporting/default.txt
Use the `svg()` method without arguments to export the full generated SVG content of an element or the entire drawing as a string.
```javascript
draw.svg()
```
--------------------------------
### Getting Element CSS Classes with svgdotjs JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves all CSS class names currently assigned to the SVG element. The method returns an array of strings, where each string is a class name.
```javascript
element.classes()
```
--------------------------------
### Getting SVG Element Height - svgdotjs height() [JavaScript]
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the current height of an SVG element using the height() method as a getter. This method returns the numeric value of the height.
```javascript
rect.height()
```
--------------------------------
### Iterating Over All Children (Deep) using SVG.js each()
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet demonstrates using the each() method with the optional second argument set to true to perform a deep traversal. The callback function is executed for every child element, including those nested within groups or other containers, allowing operations on the entire subtree.
```javascript
// draw.each(block, deep)
draw.each(function(i, children) {
this.fill({ color: '#f06' })
}, true)
```
--------------------------------
### Handling Custom Events - SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/9-events/default.txt
Shows how to bind a listener for a custom event type and how to fire that custom event, optionally passing data or event options.
```javascript
element.on('myevent', function() {
alert('ta-da!')
})
```
```javascript
function whenSomethingHappens() {
element.fire('myevent')
}
```
```javascript
function whenSomethingHappens(event) {
element.fire(event)
}
```
```javascript
function whenSomethingHappens() {
element.fire('myevent', {some:'data'})
}
```
```javascript
element.on('myevent', function(e) {
alert(e.detail.some) // outputs 'data'
})
```
```javascript
function whenSomethingHappens() {
element.fire('myevent', {some:'data'}, {cancelable: false})
}
```
--------------------------------
### Getting SVG Element Width - svgdotjs width() [JavaScript]
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the current width of an SVG element using the width() method as a getter. This method returns the numeric value of the width.
```javascript
var width = rect.width()
```
--------------------------------
### Applying ClipPath with Multiple Elements - SVG.JS - JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Demonstrates how to create a clip path using multiple SVG elements and apply it to another element using `clipWith`. The `clip()` constructor creates a clip path container, and `add()` is used to include elements within it.
```javascript
var ellipse = draw.ellipse(80, 40).move(10, 10)
var text = draw.text('SVG.JS').move(10, 10).font({ size: 36 })
var clip = draw.clip().add(text).add(ellipse)
rect.clipWith(clip)
```
--------------------------------
### Referencing All Elements by Selector using SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
This snippet uses the static SVG.find() method to locate all SVG elements in the document that match the specified CSS selector. It returns an SVG.List instance, which allows applying operations (like fill()) to all found elements simultaneously.
```javascript
var list = SVG.find('.someClass')
list.fill('#f06')
```
--------------------------------
### Get Center Y Position SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the absolute y-coordinate of the element's center using the `cy()` getter method. This method works for all element types and returns the numeric value.
```javascript
var cy = rect.cy()
```
--------------------------------
### Get Y Position SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the absolute y-coordinate of the element's upper left corner using the `y()` getter method. This method works for all element types and returns the numeric value.
```javascript
var y = rect.y()
```
--------------------------------
### Using Namespaced Events - SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/9-events/default.txt
Demonstrates how to attach and detach event handlers using namespaces (e.g., `event.namespace`) to manage groups of listeners.
```javascript
// attach
element.on('myevent.namespace', function(e) {
// do something
})
```
```javascript
// detach all handlers of namespace for myevent
element.off('myevent.namespace')
```
```javascript
// detach all handlers of namespace
element.off('.namespace')
```
```javascript
// detach all handlers including all namespaces
element.off('myevent')
```
--------------------------------
### Get Single Attribute SVG.js Javascript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/7-manipulating/default.txt
Retrieves the value of a single attribute from an SVG element using the `attr()` method. Takes the attribute name as an argument. This method returns the attribute value.
```javascript
var x = rect.attr('x')
```
--------------------------------
### Calling reference() to fetch linked elements (JavaScript)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/6-referencing-creating-elements/default.txt
Fetches the SVG.Element instance that is linked by a specific attribute (like 'href', 'fill', 'clip-path') on the current element. The attribute name is the only required argument.
```javascript
use.reference('href') //-> returns used element instance
// or
rect.reference('fill') //-> returns gradient or pattern instance for example
// or
circle.reference('clip-path') //-> returns clip instance
```
--------------------------------
### Creating a Pattern in SVG.js
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Demonstrates how to create a pattern element by specifying its dimensions and providing a callback function to add elements that compose the pattern.
```javascript
var pattern = draw.pattern(20, 20, function(add) {
add.rect(20,20).fill('#f06')
add.rect(10,10)
add.rect(10,10).move(10,10)
})
```
--------------------------------
### Get Font Property from SVG.js Text
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/5-shape-elements/default.txt
Illustrates using the font() method as a getter by passing a single property name (like 'leading') to retrieve its current value from an SVG.js text element.
```javascript
var leading = text.font('leading')
```
--------------------------------
### Animating SVG.List elements in JavaScript
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/content/10-classes/default.txt
Demonstrates how to apply animations to all elements contained within an SVG.List instance. It shows chaining the animate() method with a property change like fill.
```javascript
list.animate(3000).fill('#ff0')
```
--------------------------------
### Inline Code Span Escaping (Text)
Source: https://github.com/svgdotjs/svgdotjs.github.io/blob/source-3.2/kirby/vendor/erusev/parsedown/test/data/escaping.md
This snippet shows that characters like the asterisk (`*`), which normally indicate emphasis in Markdown, are rendered literally when enclosed within backticks (` `) as an inline code span.
```text
escaped \*emphasis\* in a code span
```