paper 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +158 -0
  2. package/README.md +24 -16
  3. package/dist/docs/assets/js/paper.js +4811 -808
  4. package/dist/docs/classes/AreaText.html +771 -243
  5. package/dist/docs/classes/ChangeFlag.html +1 -1
  6. package/dist/docs/classes/Color.html +218 -21
  7. package/dist/docs/classes/CompoundPath.html +1174 -274
  8. package/dist/docs/classes/Curve.html +2 -2
  9. package/dist/docs/classes/CurveLocation.html +1 -1
  10. package/dist/docs/classes/DrawEvent.html +69 -0
  11. package/dist/docs/classes/Effect.html +434 -0
  12. package/dist/docs/classes/EffectInstance.html +304 -0
  13. package/dist/docs/classes/Event.html +1 -1
  14. package/dist/docs/classes/Gradient.html +1 -1
  15. package/dist/docs/classes/GradientStop.html +1 -1
  16. package/dist/docs/classes/Group.html +842 -243
  17. package/dist/docs/classes/HitResult.html +1 -1
  18. package/dist/docs/classes/HostItem.html +770 -242
  19. package/dist/docs/classes/Item.html +827 -242
  20. package/dist/docs/classes/Key.html +1 -1
  21. package/dist/docs/classes/KeyEvent.html +1 -1
  22. package/dist/docs/classes/Layer.html +784 -185
  23. package/dist/docs/classes/Matrix.html +1 -1
  24. package/dist/docs/classes/MouseEvent.html +1 -1
  25. package/dist/docs/classes/PaperScope.html +1 -1
  26. package/dist/docs/classes/PaperScript.html +4 -2
  27. package/dist/docs/classes/Path.html +1366 -352
  28. package/dist/docs/classes/PathItem.html +1198 -298
  29. package/dist/docs/classes/PathText.html +772 -244
  30. package/dist/docs/classes/PatternDefinition.html +367 -0
  31. package/dist/docs/classes/Point.html +33 -5
  32. package/dist/docs/classes/PointText.html +771 -243
  33. package/dist/docs/classes/Project.html +251 -9
  34. package/dist/docs/classes/Raster.html +770 -242
  35. package/dist/docs/classes/Rectangle.html +50 -8
  36. package/dist/docs/classes/Segment.html +79 -2
  37. package/dist/docs/classes/Shape.html +770 -242
  38. package/dist/docs/classes/Size.html +31 -3
  39. package/dist/docs/classes/StrokeProfileStop.html +346 -0
  40. package/dist/docs/classes/Style.html +67 -6
  41. package/dist/docs/classes/SymbolDefinition.html +28 -2
  42. package/dist/docs/classes/SymbolItem.html +807 -242
  43. package/dist/docs/classes/TextItem.html +771 -243
  44. package/dist/docs/classes/TextRange.html +1 -1
  45. package/dist/docs/classes/TextStory.html +1 -1
  46. package/dist/docs/classes/Tool.html +2 -2
  47. package/dist/docs/classes/ToolEvent.html +1 -1
  48. package/dist/docs/classes/Tween.html +1 -1
  49. package/dist/docs/classes/View.html +2 -2
  50. package/dist/docs/classes/global.html +1 -1
  51. package/dist/docs/classes/index.html +2 -2
  52. package/dist/docs/index.html +1 -1
  53. package/dist/node/browser.js +15 -0
  54. package/dist/paper-core.js +4701 -728
  55. package/dist/paper-core.min.js +3 -3
  56. package/dist/paper-full.js +4811 -808
  57. package/dist/paper-full.min.js +3 -3
  58. package/dist/paper-hosted.js +5389 -892
  59. package/dist/paper.d.ts +1058 -69
  60. package/examples/Paperjs.org/LiveEffects.html +366 -0
  61. package/examples/Paperjs.org/Offsetting.html +379 -0
  62. package/examples/Paperjs.org/StrokeProfiles.html +706 -0
  63. package/examples/Scripts/Patterns.html +57 -0
  64. package/package.json +21 -11
@@ -80,6 +80,32 @@
80
80
  <h2>Properties</h2>
81
81
 
82
82
 
83
+ <div id="currenttextstyle" class="member">
84
+ <div class="member-link">
85
+ <a name="currenttextstyle" href="#currenttextstyle"><tt><b>currentTextStyle</b></tt></a>
86
+ </div>
87
+ <div class="member-description hidden">
88
+
89
+ <div class="member-text">
90
+ <p>The style new text items take in a hosted project, in place of <a href="../classes/Project.html#currentstyle"><tt>currentStyle</tt></a>, when the host sets one: for hosts whose new text has defaults of its own, such as a black fill without a stroke whatever new paths take. Paths keep taking the current style.</p>
91
+
92
+
93
+
94
+ <ul class="member-list">
95
+ <h4>Type:</h4>
96
+ <li>
97
+ <a href="../classes/Style.html"><tt>Style</tt></a>
98
+ </li>
99
+ </ul>
100
+
101
+
102
+
103
+ </div>
104
+
105
+ </div>
106
+ </div>
107
+
108
+
83
109
  <div id="host" class="member">
84
110
  <div class="member-link">
85
111
  <a name="host" href="#host"><tt><b>host</b></tt></a>
@@ -87,10 +113,14 @@
87
113
  <div class="member-description hidden">
88
114
 
89
115
  <div class="member-text">
90
- <p>The host document that the project&rsquo;s items come from. Setting it creates the project&rsquo;s layers from the host&rsquo;s records. All items are created as shells that load their content and children from the host on first access.</p>
91
- <p>The host provides: - <code>getChildren(key)</code>, which returns the records of the children of the node with the given key, or of the top level for <code>null</code>, as columns: <code>keys</code>, <code>types</code> (indices into <code>typeNames</code>), <code>typeNames</code>, <code>flags</code> (selected: 1, visible: 2, locked: 4, strokeScaling: 8, clipMask: 64, guide: 128, empty: 256), <code>boxes</code> (bounds, strokeBounds and roughBounds in the item&rsquo;s coordinates, 12 numbers per item), and the sparse objects <code>names</code> and <code>matrices</code>. - <code>getItem(key)</code>, which returns the node&rsquo;s own content in the form of <a href="../classes/Item.html#importjson-json"><tt>item.importJSON(json)</tt></a>, without children. Linked text gives <code>linked</code>, the keys of its story&rsquo;s text items in order, and leaves out its story. - <code>getStory(key)</code>, for linked text, which returns its story with the key of any of its text items: <code>content</code> or <code>runs</code>, <code>paragraphs</code>, and the character and paragraph styles, as <a href="../classes/Item.html#exportjson-options"><tt>item.exportJSON(options)</tt></a> writes them in the JSON of a text item. - <code>getAncestorKeys(key)</code>, which returns the keys from the top level down to the node&rsquo;s parent. - Optionally <code>layOut(json, start, key)</code>, which lays out a text item from <code>start</code> in its story, given as the JSON string that <a href="../classes/Item.html#exportjson-options"><tt>item.exportJSON(options)</tt></a> writes of it as the script holds it, or as <code>null</code> where the script didn&rsquo;t change it since it loaded or the host took its changes with <a href="../classes/Project.html#takechanges"><tt>project.takeChanges</tt></a>(), for the host to lay out its own node, and returns <code>{ end, lines }</code>: where its visible text ends, and its lines, each <code>{ start, end, x, y, width, lineHeight, ascent,
116
+ <p>The host document that the project&rsquo;s items come from. Setting it creates the project&rsquo;s layers from the host&rsquo;s records. All items are created as shells that load their content and children from the host on first access. The host draws its items, so setting it also turns off <a href="../classes/View.html#autoupdate"><tt>view.autoUpdate</tt></a>, which would draw them all and load them in full.</p>
117
+ <p>The host provides: - <code>getChildren(key)</code>, which returns the records of the children of the node with the given key, or of the top level for <code>null</code>, as columns: <code>keys</code>, <code>types</code> (indices into <code>typeNames</code>), <code>typeNames</code>, <code>flags</code> (selected: 1, visible: 2, locked: 4, strokeScaling: 8, clipMask: 64, guide: 128, empty: 256), optionally <code>boxes</code> (bounds, strokeBounds and roughBounds in the item&rsquo;s coordinates, 12 numbers per item), and the sparse objects <code>names</code> and <code>matrices</code>. - <code>getBounds(key)</code>, for hosts that don&rsquo;t send <code>boxes</code>, which returns the node&rsquo;s 12 numbers, or <code>null</code> for an empty node. Items ask for them when their bounds are needed, and again after the host sent their record again. - <code>getItem(key)</code>, which returns the node&rsquo;s own content in the form of <a href="../classes/Item.html#importjson-json"><tt>item.importJSON(json)</tt></a>, without children. Linked text gives <code>linked</code>, the keys of its story&rsquo;s text items in order, and leaves out its story. Rasters give their <code>size</code> without a <code>source</code> and <code>crossOrigin</code>. - <code>getImage(key)</code>, for rasters, which returns the node&rsquo;s pixels as a canvas with a 2D context, of the size that <code>getItem()</code> gives. Rasters load them on first access to their pixels, and Paper.js never loads them by itself, except to draw them. Rasters whose pixels the host fails to give draw nothing. - <code>getStory(key)</code>, for linked text, which returns its story with the key of any of its text items: <code>content</code> or <code>runs</code>, <code>paragraphs</code>, and the character and paragraph styles, as <a href="../classes/Item.html#exportjson-options"><tt>item.exportJSON(options)</tt></a> writes them in the JSON of a text item. - <code>getAncestorKeys(key)</code>, which returns the keys from the top level down to the node&rsquo;s parent. - Optionally <code>layOut(json, start, key)</code>, which lays out a text item from <code>start</code> in its story, given as the JSON string that <a href="../classes/Item.html#exportjson-options"><tt>item.exportJSON(options)</tt></a> writes of it as the script holds it, or as <code>null</code> where the script didn&rsquo;t change it since it loaded or the host took its changes with <a href="../classes/Project.html#takechanges"><tt>project.takeChanges</tt></a>(), for the host to lay out its own node, and returns <code>{ end, lines }</code>: where its visible text ends, and its lines, each <code>{ start, end, x, y, width, lineHeight, ascent,
92
118
  descent, pieces }</code>, with pieces <code>{ start, end, x, y, dx, width,
93
- rotation, size, ascent, descent, lineHeight }</code> and an optional <code>content</code>, as for a hyphen, all in the item&rsquo;s coordinates. <code>key</code> is null for text that the host doesn&rsquo;t know yet. Without it, Paper.js lays out text itself.</p>
119
+ rotation, size, ascent, descent, lineHeight }</code> and an optional <code>content</code>, as for a hyphen, all in the item&rsquo;s coordinates. <code>key</code> is null for text that the host doesn&rsquo;t know yet. Without it, Paper.js lays out text itself. - <code>getDefinition(key)</code>, for the pattern and symbol definitions that the host shares between its items, which the JSON of its items refers to as <code>[&#39;@key&#39;]</code>, as in <code>fillColor: [&#39;pattern&#39;,
120
+ [&#39;@pattern/Dots&#39;], matrix]</code> or <code>definition: [&#39;@symbol/Star&#39;]</code>. It returns the definition in the form of <a href="../classes/Item.html#exportjson-options"><tt>item.exportJSON(options)</tt></a>, with its whole item: <code>[&#39;PatternDefinition&#39;, item, { tile, spacing }]</code> or <code>[&#39;SymbolDefinition&#39;, item]</code>, always: for a key that it has no definition of, an empty one of the type, as <code>[&#39;SymbolDefinition&#39;, [&#39;Group&#39;, {}]]</code>. Each definition loads once, and the JSON of the items that use it, as <a href="../classes/Item.html#exportjson-options"><tt>item.exportJSON(options)</tt></a> writes it, refers to it by its key again. Definitions that scripts create have no key, and are written out whole, until the host sets their <code>key</code>, which it can only set once. <a href="../classes/Project.html#takechanges"><tt>project.takeChanges</tt></a>() lists those that the changed items use first, nested ones first, as <code>{ definition, flags }</code> with the <code>ChangeFlag.INSERTION</code> flag, followed by the changes of the host&rsquo;s definitions. Renaming those isn&rsquo;t supported. - <code>getDefinitionKeys(type)</code>, which returns the keys of all the host&rsquo;s definitions of the type, <code>&#39;SymbolDefinition&#39;</code> or <code>&#39;PatternDefinition&#39;</code>, for <a href="../classes/Project.html#symboldefinitions"><tt>symbolDefinitions</tt></a> and <a href="../classes/Project.html#patterndefinitions"><tt>patternDefinitions</tt></a>.</p>
121
+ <p>Items that move into a project with another host load in full from their own host first, and drop their keys, so they are new items there. They bring copies without keys of the symbol and pattern definitions of their host along, shared by the items of one insertion or copy, so the new host takes them as new ones too. Linked text brings a copy of its story along, which flows on through the items that stay. Host items can&rsquo;t enter the project of another host.</p>
122
+ <p>The host draws the items, and the selection. To show what scripts draw in <a href="../classes/Item.html#ondraw"><tt>item.onDraw</tt></a> and <a href="../classes/Item.html#ondrawselection"><tt>item.onDrawSelection</tt></a>, it calls <code>project.draw(ctx, matrix, pixelRatio)</code>, which in a hosted project only calls these handlers, with the context, the view&rsquo;s matrix and pixel ratio that the host gives, for the visible items that have them, and for the selected ones. Handlers of classes, such as <code>Path.onDraw</code>, load all items once. The host asks <a href="../classes/Project.html#hasdrawhandlers"><tt>hasDrawHandlers</tt></a>() whether it needs to call it.</p>
123
+ <p><a href="../classes/Project.html#takechanges"><tt>project.takeChanges</tt></a>() marks the changes of the items whose children changed in order other than by new items inserted and items removed, which the other changes don&rsquo;t tell, with <code>reordered: true</code>: the host reads their children whole, and can place the others&rsquo; new items by their indices.</p>
94
124
 
95
125
 
96
126
 
@@ -134,6 +164,58 @@
134
164
 
135
165
 
136
166
 
167
+ </div>
168
+
169
+ </div>
170
+ </div>
171
+
172
+
173
+ <div id="onactivate" class="member">
174
+ <div class="member-link">
175
+ <a name="onactivate" href="#onactivate"><tt><b>onActivate</b></tt></a>
176
+ </div>
177
+ <div class="member-description hidden">
178
+
179
+ <div class="member-text">
180
+ <p>The function to be called when the project is activated through <a href="../classes/Project.html#activate"><tt>activate</tt></a>(). The function receives the previously active project, which is the project itself when it was already active.</p>
181
+
182
+
183
+
184
+ <ul class="member-list">
185
+ <h4>Type:</h4>
186
+ <li>
187
+ <tt>Function</tt>⟋<tt>null</tt>
188
+ </li>
189
+ </ul>
190
+
191
+
192
+
193
+ </div>
194
+
195
+ </div>
196
+ </div>
197
+
198
+
199
+ <div id="ondeactivate" class="member">
200
+ <div class="member-link">
201
+ <a name="ondeactivate" href="#ondeactivate"><tt><b>onDeactivate</b></tt></a>
202
+ </div>
203
+ <div class="member-description hidden">
204
+
205
+ <div class="member-text">
206
+ <p>The function to be called when another project is activated through <a href="../classes/Project.html#activate"><tt>activate</tt></a>() while this one is active, or when this one is removed while active.</p>
207
+
208
+
209
+
210
+ <ul class="member-list">
211
+ <h4>Type:</h4>
212
+ <li>
213
+ <tt>Function</tt>⟋<tt>null</tt>
214
+ </li>
215
+ </ul>
216
+
217
+
218
+
137
219
  </div>
138
220
 
139
221
  </div>
@@ -372,6 +454,34 @@ var path2 = new Path.Circle(new Point(175, 50), 20);
372
454
 
373
455
 
374
456
 
457
+ </div>
458
+
459
+ </div>
460
+ </div>
461
+
462
+
463
+ <div id="patterndefinitions" class="member">
464
+ <div class="member-link">
465
+ <a name="patterndefinitions" href="#patterndefinitions"><tt><b>patternDefinitions</b></tt></a>
466
+ </div>
467
+ <div class="member-description hidden">
468
+
469
+ <div class="member-text">
470
+ <p>The pattern definitions that the fill and stroke colors of the items in the project use.</p>
471
+
472
+ <p>Read only.</p>
473
+
474
+
475
+
476
+ <ul class="member-list">
477
+ <h4>Type:</h4>
478
+ <li>
479
+ Array of <a href="../classes/PatternDefinition.html"><tt>PatternDefinition</tt></a> objects
480
+ </li>
481
+ </ul>
482
+
483
+
484
+
375
485
  </div>
376
486
 
377
487
  </div>
@@ -409,6 +519,63 @@ var path2 = new Path.Circle(new Point(175, 50), 20);
409
519
 
410
520
 
411
521
 
522
+ <div class="reference-members">
523
+ <h2>Static Properties</h2>
524
+
525
+
526
+ <div id="onactivate" class="member">
527
+ <div class="member-link">
528
+ <a name="onactivate" href="#onactivate"><tt><b>Project.onActivate</b></tt></a>
529
+ </div>
530
+ <div class="member-description hidden">
531
+
532
+ <div class="member-text">
533
+ <p>The function to be called when any project is activated, as <a href="../classes/Project.html#onactivate"><tt>onActivate</tt></a> is for a single project, including the projects that activate themselves when they are created, with <code>this</code> set to the project. <code>Project.on(&#39;activate&#39;, handler)</code> and <code>Project.off(&#39;activate&#39;, handler)</code> attach and detach them too. Classes are shared by all <a href="../classes/PaperScope.html"><tt>PaperScope</tt></a> objects, and so are their handlers.</p>
534
+
535
+
536
+
537
+ <ul class="member-list">
538
+ <h4>Type:</h4>
539
+ <li>
540
+ <tt>Function</tt>⟋<tt>null</tt>
541
+ </li>
542
+ </ul>
543
+
544
+
545
+
546
+ </div>
547
+
548
+ </div>
549
+ </div>
550
+
551
+
552
+ <div id="ondeactivate" class="member">
553
+ <div class="member-link">
554
+ <a name="ondeactivate" href="#ondeactivate"><tt><b>Project.onDeactivate</b></tt></a>
555
+ </div>
556
+ <div class="member-description hidden">
557
+
558
+ <div class="member-text">
559
+ <p>The function to be called when any project is deactivated, as <a href="../classes/Project.html#ondeactivate"><tt>onDeactivate</tt></a> is for a single project, see <a href="../classes/Project.html#onactivate"><tt>Project.onActivate</tt></a>.</p>
560
+
561
+
562
+
563
+ <ul class="member-list">
564
+ <h4>Type:</h4>
565
+ <li>
566
+ <tt>Function</tt>⟋<tt>null</tt>
567
+ </li>
568
+ </ul>
569
+
570
+
571
+
572
+ </div>
573
+
574
+ </div>
575
+ </div>
576
+
577
+ </div>
578
+
412
579
 
413
580
 
414
581
  <!-- ============================== methods ================================ -->
@@ -452,6 +619,35 @@ var path2 = new Path.Circle(new Point(175, 50), 20);
452
619
 
453
620
 
454
621
 
622
+ </div>
623
+ </div>
624
+ </div>
625
+
626
+
627
+ <div id="hasdrawhandlers" class="member">
628
+ <div class="member-link">
629
+ <a name="hasdrawhandlers" href="#hasdrawhandlers"><tt><b>hasDrawHandlers</b>()</tt></a>
630
+ </div>
631
+ <div class="member-description hidden">
632
+ <div class="member-text">
633
+ <p>Checks whether any item of the project or class has draw handlers, <a href="../classes/Item.html#ondraw"><tt>item.onDraw</tt></a> or, for the selected items, <a href="../classes/Item.html#ondrawselection"><tt>item.onDrawSelection</tt></a>, for hosts that draw the items themselves, see <a href="../classes/Project.html#host"><tt>host</tt></a>.</p>
634
+
635
+
636
+
637
+ <ul class="member-list">
638
+ <h4>Returns:</h4>
639
+
640
+ <li>
641
+ <tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;<tt>true</tt> if drawing the project calls any handlers, <tt>false</tt> otherwise
642
+ </li>
643
+
644
+
645
+ </ul>
646
+
647
+
648
+
649
+
650
+
455
651
  </div>
456
652
  </div>
457
653
  </div>
@@ -463,7 +659,7 @@ var path2 = new Path.Circle(new Point(175, 50), 20);
463
659
  </div>
464
660
  <div class="member-description hidden">
465
661
  <div class="member-text">
466
- <p>Updates the items of changed host nodes, given in the column format of the host&rsquo;s <code>getChildren()</code>, with two more flags: 16 when the node&rsquo;s own content changed, so the item loads it again on next access, and 32 when its list of children changed, so it loads them again right away if it had loaded them, keeping the items of nodes that remain. Nodes without items are skipped.</p>
662
+ <p>Updates the items of changed host nodes, given in the column format of the host&rsquo;s <code>getChildren()</code>, with two more flags: 16 when the node&rsquo;s own content changed, so the item loads it again on next access, and 32 when its list of children changed, so it loads them again right away if it had loaded them, keeping the items of nodes that remain. Nodes without items are skipped. <code>definitions</code> lists the keys of changed definitions of the host&rsquo;s <code>getDefinition()</code>, which load again right away into the same objects, so the colors and symbol items that use them change along. A definition that the host no longer has, for which <code>getDefinition()</code> may return <code>null</code> here, is emptied and draws nothing. The columns may hold only definitions.</p>
467
663
 
468
664
 
469
665
  <ul class="member-list">
@@ -494,7 +690,7 @@ var path2 = new Path.Circle(new Point(175, 50), 20);
494
690
  </div>
495
691
  <div class="member-description hidden">
496
692
  <div class="member-text">
497
- <p>Returns the changes logged since tracking was activated or since the last call, and clears the log. Each item is listed once, with the <a href="../classes/ChangeFlag.html"><tt>ChangeFlag</tt></a> values of all its changes combined. Removed items are listed with the <code>ChangeFlag.INSERTION</code> flag.</p>
693
+ <p>Returns the changes logged since tracking was activated or since the last call, and clears the log. Each item is listed once, with the <a href="../classes/ChangeFlag.html"><tt>ChangeFlag</tt></a> values of all its changes combined. Removed items are listed with the <code>ChangeFlag.INSERTION</code> flag, and items that moved to another project are left out, as that one lists them. Symbol and pattern definitions whose item, tile, spacing or name changed are listed too, as <code>{ definition, flags }</code>.</p>
498
694
 
499
695
 
500
696
 
@@ -502,7 +698,7 @@ var path2 = new Path.Circle(new Point(175, 50), 20);
502
698
  <h4>Returns:</h4>
503
699
 
504
700
  <li>
505
- <tt>Array of <tt>Object</tt> objects</tt>&nbsp;&mdash;&nbsp;the changes as <code>{ item, flags }</code> objects, or <code>null</code> if <a href="../classes/Project.html#trackchanges"><tt>trackChanges</tt></a> is off
701
+ <tt>Array of <tt>Object</tt> objects</tt>&nbsp;&mdash;&nbsp;the changes as <code>{ item, flags }</code> and <code>{ definition, flags }</code> objects, or <code>null</code> if <a href="../classes/Project.html#trackchanges"><tt>trackChanges</tt></a> is off
506
702
  </li>
507
703
 
508
704
 
@@ -1373,6 +1569,12 @@ for (var i = 0; i < items.length; i++) {
1373
1569
  <li><tt>options.reuseImages: <tt>Boolean</tt></tt> &mdash; whether raster images with the same content should only be exported once into the <code>&lt;defs&gt;</code> element, and placed through <code>&lt;use&gt;</code> elements referencing it &mdash;&nbsp;default: <tt>false</tt></li>
1374
1570
  <li><tt>options.idPrefix: <tt>String</tt></tt> &mdash; a prefix for the ids generated for definitions such as gradients, clip paths and symbols, to keep them unique when several exported SVGs are placed in one document &mdash;&nbsp;default: <tt>&rsquo;&rsquo;</tt></li>
1375
1571
  <li><tt>options.reduceAttributes: <tt>Boolean</tt></tt> &mdash; wether to only include style attributes in the SVG output that differ from their parents, or to always include them (much faster but leading to redundancies). &mdash;&nbsp;default: <tt>true</tt></li>
1572
+ <li>[options.processNode] {Function} the function to process the
1573
+ SVG node made for each exported item, receiving an object with the
1574
+ `item` and its `node`: It can change the node, e.g. to add attributes
1575
+ that Paper.js doesn't export, or return a node to replace it with. It
1576
+ is called before the item's name, style, visibility and data are set
1577
+ on the node, which replace attributes of the same names.</li>
1376
1578
  </ul>
1377
1579
 
1378
1580
  <ul class="member-list">
@@ -1401,7 +1603,22 @@ for (var i = 0; i < items.length; i++) {
1401
1603
 
1402
1604
 
1403
1605
 
1404
-
1606
+ <h4>Example:<span class="description">Export layers as Inkscape layers. Setting the attributes with their namespace has the exported SVG declare it:</span></h4>
1607
+
1608
+
1609
+ <pre><code>var ns = 'http://www.inkscape.org/namespaces/inkscape';
1610
+ var svg = project.exportSVG({
1611
+ asString: true,
1612
+ processNode: function(arg) {
1613
+ var item = arg.item;
1614
+ if (item instanceof Layer) {
1615
+ arg.node.setAttributeNS(ns, 'inkscape:groupmode', 'layer');
1616
+ if (item.name)
1617
+ arg.node.setAttributeNS(ns, 'inkscape:label', item.name);
1618
+ }
1619
+ }
1620
+ });</code></pre>
1621
+
1405
1622
  </div>
1406
1623
  </div>
1407
1624
  </div>
@@ -1415,6 +1632,7 @@ for (var i = 0; i < items.length; i++) {
1415
1632
  <div class="member-text">
1416
1633
  <p>Converts the provided SVG content into Paper.js items and adds them to the active layer of this project. Note that the project is not cleared first. You can call <a href="../classes/Project.html#clear"><tt>project.clear</tt></a>() to do so.</p>
1417
1634
  <p><code>&lt;symbol&gt;</code> elements are imported as <a href="../classes/SymbolDefinition.html"><tt>SymbolDefinition</tt></a> items, and the <code>&lt;use&gt;</code> elements that place them as <a href="../classes/SymbolItem.html"><tt>SymbolItem</tt></a> items. The styles that <code>&lt;use&gt;</code> elements inherit don&rsquo;t reach the symbols&rsquo; content.</p>
1635
+ <p>The layers in SVG content that Paper.js exported come back as <a href="../classes/Layer.html"><tt>Layer</tt></a> items inside the imported group. To make the layers of a project&rsquo;s SVG the layers of a project again, add them to it with <code>item.children.slice().forEach(project.addLayer, project)</code>.</p>
1418
1636
  <p>URLs are fetched as they are, so validate URLs that come from untrusted sources first, especially on servers, where they could reach internal addresses.</p>
1419
1637
  <ul class="member-list">
1420
1638
  <h4>Options:</h4>
@@ -1426,6 +1644,13 @@ for (var i = 0; i < items.length; i++) {
1426
1644
  <li><tt>options.onError: <tt>Function</tt></tt> &mdash; the callback function to call if an error occurs during loading. Only required when loading from external resources.</li>
1427
1645
  <li><tt>options.insert: <tt>Boolean</tt></tt> &mdash; whether the imported items should be added to the project that <code>importSVG()</code> is called on &mdash;&nbsp;default: <tt>true</tt></li>
1428
1646
  <li><tt>options.applyMatrix: <tt>Boolean</tt></tt> &mdash; whether the imported items should have their transformation matrices applied to their contents or not &mdash;&nbsp;default: <tt><a href="../classes/PaperScope.html#settings"><tt>paperScope.settings</tt></a>.applyMatrix</tt></li>
1647
+ <li>[options.processItem] {Function} the function to process the
1648
+ item made for each imported SVG element, receiving an object with
1649
+ the `item` and its `node`: It can read attributes that Paper.js
1650
+ doesn't import, or return an item to replace it with. It is called
1651
+ after the element's attributes and data are applied to the item, so
1652
+ it can extend `item.data`. A replacement item doesn't receive them:
1653
+ copy them over from `item` as needed.</li>
1429
1654
  </ul>
1430
1655
 
1431
1656
  <ul class="member-list">
@@ -1461,7 +1686,24 @@ for (var i = 0; i < items.length; i++) {
1461
1686
 
1462
1687
 
1463
1688
 
1464
-
1689
+ <h4>Example:<span class="description">Keep the SVG `class` attribute of items in their data, and export it again:</span></h4>
1690
+
1691
+
1692
+ <pre><code>var item = project.importSVG(svg, {
1693
+ processItem: function(arg) {
1694
+ var className = arg.node.getAttribute('class');
1695
+ if (className)
1696
+ arg.item.data.className = className;
1697
+ }
1698
+ });
1699
+ var exported = project.exportSVG({
1700
+ processNode: function(arg) {
1701
+ var className = arg.item.data.className;
1702
+ if (className)
1703
+ arg.node.setAttribute('class', className);
1704
+ }
1705
+ });</code></pre>
1706
+
1465
1707
  </div>
1466
1708
  </div>
1467
1709
  </div>
@@ -1523,7 +1765,7 @@ for (var i = 0; i < items.length; i++) {
1523
1765
 
1524
1766
  <!-- =========================== copyright notice ========================== -->
1525
1767
  <p class="footer">
1526
- Paper.js v0.15.0<br>
1768
+ Paper.js v0.17.0<br>
1527
1769
  Copyright &#169; 2011—2026 <a href="http://www.lehni.org" target="_blank">J&uuml;rg Lehni</a> &amp; <a href="http://www.jonathanpuckey.com" target="_blank">Jonathan Puckey</a>. All Rights Reserved.</p>
1528
1770
  <div class="content-end"></div>
1529
1771