@turbowarp/paper 0.12.202407161743

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 (139) hide show
  1. package/AUTHORS.md +18 -0
  2. package/CHANGELOG.md +701 -0
  3. package/LICENSE.txt +23 -0
  4. package/README.md +381 -0
  5. package/dist/node/canvas.js +66 -0
  6. package/dist/node/extend.js +156 -0
  7. package/dist/node/self.js +58 -0
  8. package/dist/node/xml.js +40 -0
  9. package/dist/paper-core.js +15805 -0
  10. package/dist/paper-full.js +17574 -0
  11. package/examples/Animated/AnimatedStar.html +53 -0
  12. package/examples/Animated/BooleanOperations.html +115 -0
  13. package/examples/Animated/CandyCrash.html +151 -0
  14. package/examples/Animated/Extruded.html +50 -0
  15. package/examples/Animated/Lines.html +53 -0
  16. package/examples/Animated/Smoothing.html +70 -0
  17. package/examples/Animated/Space.html +86 -0
  18. package/examples/Animated/SpaceUsingShapes.html +79 -0
  19. package/examples/Games/Paperoids.html +569 -0
  20. package/examples/JSON/Circle Testing.html +34 -0
  21. package/examples/JSON/Compound Path.html +25 -0
  22. package/examples/JSON/Empty Path Testing.html +31 -0
  23. package/examples/JSON/Gradients.html +34 -0
  24. package/examples/JSON/Group Transform.html +28 -0
  25. package/examples/JSON/Line Testing.html +44 -0
  26. package/examples/JSON/Random Path Testing.html +42 -0
  27. package/examples/JSON/Raster.html +29 -0
  28. package/examples/JSON/Rect and Attribute Testing.html +56 -0
  29. package/examples/JSON/Rotated Primitives.html +55 -0
  30. package/examples/JSON/Selection.html +43 -0
  31. package/examples/JSON/Shapes.html +54 -0
  32. package/examples/JSON/Symbols.html +30 -0
  33. package/examples/JSON/Text Testing.html +38 -0
  34. package/examples/JSON/Tiger.html +19 -0
  35. package/examples/JSON/Transform Test 1.html +32 -0
  36. package/examples/JSON/Transform Test 2.html +30 -0
  37. package/examples/Node.js/AnimatedStar.js +52 -0
  38. package/examples/Node.js/BooleanOperations.js +36 -0
  39. package/examples/Node.js/JSONtoPDF.js +20 -0
  40. package/examples/Node.js/Raster.js +32 -0
  41. package/examples/Node.js/RasterRemote.js +33 -0
  42. package/examples/Node.js/SvgExport.js +52 -0
  43. package/examples/Node.js/SvgImport.js +23 -0
  44. package/examples/Node.js/Tadpoles.js +16 -0
  45. package/examples/Node.js/Tadpoles.pjs +278 -0
  46. package/examples/Node.js/in.json +1 -0
  47. package/examples/Node.js/in.svg +16 -0
  48. package/examples/Paperjs.org/BooleanOperattions.html +115 -0
  49. package/examples/Paperjs.org/BouncingBalls.html +103 -0
  50. package/examples/Paperjs.org/Chain.html +54 -0
  51. package/examples/Paperjs.org/DivisionRaster.html +72 -0
  52. package/examples/Paperjs.org/FutureSplash.html +122 -0
  53. package/examples/Paperjs.org/HitTesting.html +103 -0
  54. package/examples/Paperjs.org/InteractiveTiger.html +777 -0
  55. package/examples/Paperjs.org/MetaBalls.html +132 -0
  56. package/examples/Paperjs.org/NyanRainbow.html +202 -0
  57. package/examples/Paperjs.org/PathIntersections.html +76 -0
  58. package/examples/Paperjs.org/Qbertify.html +146 -0
  59. package/examples/Paperjs.org/RadialRainbows.html +80 -0
  60. package/examples/Paperjs.org/RoundedRectangles.html +41 -0
  61. package/examples/Paperjs.org/SatieLikedToDraw.html +140 -0
  62. package/examples/Paperjs.org/Simplify.html +63 -0
  63. package/examples/Paperjs.org/SpiralRaster.html +120 -0
  64. package/examples/Paperjs.org/Tadpoles.html +283 -0
  65. package/examples/Paperjs.org/Voronoi.html +134 -0
  66. package/examples/Rasters/PhyllotaxisRaster.html +96 -0
  67. package/examples/Rasters/Raster.html +34 -0
  68. package/examples/Rasters/RotationRaster.html +44 -0
  69. package/examples/Rasters/Smoothing.html +48 -0
  70. package/examples/SVG Export/Circle Testing.html +32 -0
  71. package/examples/SVG Export/Clipping.html +17 -0
  72. package/examples/SVG Export/Compound Path.html +22 -0
  73. package/examples/SVG Export/Empty Path Testing.html +28 -0
  74. package/examples/SVG Export/Gradients.html +52 -0
  75. package/examples/SVG Export/Group Transform.html +25 -0
  76. package/examples/SVG Export/Line Testing.html +41 -0
  77. package/examples/SVG Export/Random Path Testing.html +39 -0
  78. package/examples/SVG Export/Raster.html +21 -0
  79. package/examples/SVG Export/Rect and Attribute Testing.html +53 -0
  80. package/examples/SVG Export/Rotated Primitives.html +80 -0
  81. package/examples/SVG Export/Shapes.html +58 -0
  82. package/examples/SVG Export/Symbols.html +27 -0
  83. package/examples/SVG Export/Text Testing.html +45 -0
  84. package/examples/SVG Export/Tiger.html +23 -0
  85. package/examples/SVG Export/Transform Test 1.html +29 -0
  86. package/examples/SVG Export/Transform Test 2.html +27 -0
  87. package/examples/SVG Import/Arcs.html +78 -0
  88. package/examples/SVG Import/Butterfly.html +223 -0
  89. package/examples/SVG Import/Circle and Ellipse Testing.html +26 -0
  90. package/examples/SVG Import/Clipping.html +100 -0
  91. package/examples/SVG Import/From File.html +30 -0
  92. package/examples/SVG Import/Gradient.html +138 -0
  93. package/examples/SVG Import/Gradients.html +30 -0
  94. package/examples/SVG Import/Inkscape Pivot.html +52 -0
  95. package/examples/SVG Import/Inkscape.html +88 -0
  96. package/examples/SVG Import/Line Testing.html +24 -0
  97. package/examples/SVG Import/MoreGradients.html +107 -0
  98. package/examples/SVG Import/Multiple Paths Test 1.html +42 -0
  99. package/examples/SVG Import/Multiple Paths Test 2.html +33 -0
  100. package/examples/SVG Import/Nested Groups Test.html +78 -0
  101. package/examples/SVG Import/Polybezier.html +43 -0
  102. package/examples/SVG Import/Rect Testing.html +25 -0
  103. package/examples/SVG Import/Symbols.html +24 -0
  104. package/examples/SVG Import/Testing.html +40 -0
  105. package/examples/SVG Import/Text Testing.html +19 -0
  106. package/examples/SVG Import/Tiger.html +742 -0
  107. package/examples/SVG Import/Transform Testing.html +22 -0
  108. package/examples/SVG Import/Viewbox.html +38 -0
  109. package/examples/Scripts/Arcs.html +39 -0
  110. package/examples/Scripts/BlendModes.html +77 -0
  111. package/examples/Scripts/BooleanOperations.html +937 -0
  112. package/examples/Scripts/CompoundPath.html +19 -0
  113. package/examples/Scripts/CurveTimeParameterization.html +61 -0
  114. package/examples/Scripts/HslColor.html +53 -0
  115. package/examples/Scripts/PathStructure.html +82 -0
  116. package/examples/Scripts/PathTangents.html +73 -0
  117. package/examples/Scripts/Resize.html +42 -0
  118. package/examples/Scripts/RoundRectangle.html +28 -0
  119. package/examples/Scripts/Shapes.html +54 -0
  120. package/examples/Scripts/StrokeBounds.html +101 -0
  121. package/examples/Scripts/StrokeScaling.html +65 -0
  122. package/examples/Tools/BezierTool.html +90 -0
  123. package/examples/Tools/Circles.html +28 -0
  124. package/examples/Tools/Clouds.html +35 -0
  125. package/examples/Tools/DrippingBrush.html +73 -0
  126. package/examples/Tools/FancyBrush.html +82 -0
  127. package/examples/Tools/Grid.html +44 -0
  128. package/examples/Tools/MultiLines.html +44 -0
  129. package/examples/Tools/MultipleTools.html +44 -0
  130. package/examples/Tools/PathEditing.html +95 -0
  131. package/examples/Tools/SquareRounded.html +76 -0
  132. package/examples/Tools/Stars.html +38 -0
  133. package/examples/Tools/Vektor.html +200 -0
  134. package/examples/Tools/Wave.html +50 -0
  135. package/examples/Tools/WormFarm.html +88 -0
  136. package/examples/Worker/Main.html +53 -0
  137. package/examples/Worker/Worker.js +14 -0
  138. package/examples/css/style.css +12 -0
  139. package/package.json +109 -0
package/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
2
+ http://juerglehni.com/ & https://puckey.studio/
3
+ All rights reserved.
4
+
5
+ The MIT License (MIT)
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,381 @@
1
+ # Fork of Paper.js
2
+
3
+ This is a fork of Paper.js. Please do not contact the Paper.js authors to support this fork.
4
+
5
+ _Original README.md below_
6
+
7
+ # Paper.js - The Swiss Army Knife of Vector Graphics Scripting
8
+
9
+ If you want to work with Paper.js, simply download the latest "stable" version
10
+ from [http://paperjs.org/download/](http://paperjs.org/download/)
11
+
12
+ - Website: <http://paperjs.org/>
13
+ - Questions: <https://stackoverflow.com/questions/tagged/paperjs>
14
+ - Discussion forum: <https://groups.google.com/group/paperjs>
15
+ - Mainline source code: <https://github.com/paperjs/paper.js>
16
+ - Twitter: [@paperjs](https://twitter.com/paperjs)
17
+ - Latest releases: <http://paperjs.org/download/>
18
+ - Pre-built development versions:
19
+ [`prebuilt/module`](https://github.com/paperjs/paper.js/tree/prebuilt/module)
20
+ and [`prebuilt/dist`](https://github.com/paperjs/paper.js/tree/prebuilt/dist)
21
+ branches.
22
+
23
+ ## Installing Paper.js
24
+
25
+ The recommended way to install and maintain Paper.js as a dependency in your
26
+ project is through the [Node.js Package Manager (NPM)](https://www.npmjs.com/)
27
+ for browsers, Node.js or Electron.
28
+
29
+ If NPM is already installed, simply type one of these commands in your project
30
+ folder:
31
+
32
+ ```sh
33
+ npm install paper
34
+ ```
35
+
36
+ Upon execution, you will find a `paper` folder inside the project's
37
+ `node_modules` folder.
38
+
39
+ For more information on how to install Node.js and NPM, read the chapter
40
+ [Installing Node.js and NPM](#installing-nodejs-and-npm).
41
+
42
+ ### Which Version to Use
43
+
44
+ The various distributions come with two different pre-build versions of
45
+ Paper.js, in minified and normal variants:
46
+
47
+ - `paper-full.js` – The full version for the browser, including PaperScript
48
+ support and Acorn.js
49
+ - `paper-core.js` – The core version for the browser, without PaperScript
50
+ support nor Acorn.js. You can use this to shave off some bytes and compilation
51
+ time when working with JavaScript directly.
52
+
53
+ ### Installing Node.js and NPM
54
+
55
+ Node.js comes with the Node Package Manager (NPM). There are many tutorials
56
+ explaining the different ways to install Node.js on different platforms. It is
57
+ generally not recommended to install Node.js through OS-supplied package
58
+ managers, as the its development cycles move fast and these versions are often
59
+ out-of-date.
60
+
61
+ On macOS, [Homebrew](https://brew.sh/) is a good option if one version of
62
+ Node.js that is kept up to date with `brew upgrade` is enough:
63
+ <https://treehouse.github.io/installation-guides/mac/node-mac.html>
64
+
65
+ [NVM](https://github.com/creationix/nvm) can be used instead to install and
66
+ maintain multiple versions of Node.js on the same platform, as often required by
67
+ different projects:
68
+ <https://nodesource.com/blog/installing-node-js-tutorial-using-nvm-on-mac-os-x-and-ubuntu/>
69
+
70
+ Homebrew is recommended on macOS also if you intend to install Paper.js with
71
+ rendering to the Canvas on Node.js, as described in the next paragraph.
72
+
73
+ For Linux, see <https://nodejs.org/download/> to locate 32-bit and 64-bit Node.js
74
+ binaries as well as sources, or use NVM, as described in the paragraph above.
75
+
76
+ ### Installing Paper.js Using NPM
77
+
78
+ Paper.js comes in three different versions on NPM: `paper`, `paper-jsdom` and
79
+ `paper-jsdom-canvas`. Depending on your use case, you need to required a
80
+ different one:
81
+
82
+ - `paper` is the main library, and can be used directly in a browser
83
+ context, e.g. a web browser or worker.
84
+ - `paper-jsdom` is a shim module for Node.js, offering headless use with SVG
85
+ importing and exporting through [jsdom](https://github.com/tmpvar/jsdom).
86
+ - `paper-jsdom-canvas` is a shim module for Node.js, offering canvas rendering
87
+ through [Node-Canvas](https://github.com/Automattic/node-canvas) as well as
88
+ SVG importing and exporting through [jsdom](https://github.com/tmpvar/jsdom).
89
+
90
+ In order to install `paper-jsdom-canvas`, you need the [Cairo Graphics
91
+ library](https://cairographics.org/) installed in your system:
92
+
93
+ ### Installing Native Dependencies
94
+
95
+ Paper.js relies on [Node-Canvas](https://github.com/Automattic/node-canvas) for
96
+ rendering, which in turn relies on the native libraries
97
+ [Cairo](https://cairographics.org/) and [Pango](https://www.pango.org/).
98
+
99
+ #### Installing Native Dependencies on macOS
100
+
101
+ Paper.js relies on Node-Canvas for rendering, which in turn relies on Cairo and
102
+ Pango. The easiest way to install Cairo is through
103
+ [Homebrew](https://brew.sh/), by issuing the command:
104
+
105
+ brew install cairo pango
106
+
107
+ Note that currently there is an issue on macOS with Cairo. If the above causes
108
+ errors, the following will most likely fix it:
109
+
110
+ PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm install paper
111
+
112
+ Also, whenever you would like to update the modules, you will need to execute:
113
+
114
+ PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ npm update
115
+
116
+ If you keep forgetting about this requirement, or would like to be able to type
117
+ simple and clean commands, add this to your `.bash_profile` file:
118
+
119
+ # PKG Config for Pango / Cairo
120
+ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig
121
+
122
+ After adding this line, your commands should work in the expected way:
123
+
124
+ npm install paper
125
+ npm update
126
+
127
+ #### Installing Native Dependencies on Debian/Ubuntu Linux
128
+
129
+ sudo apt-get install pkg-config libcairo2-dev libpango1.0-dev libssl-dev libjpeg62-dev libgif-dev
130
+
131
+ You might also need to install the build-essential package if you don't usually
132
+ build from c++ sources:
133
+
134
+ sudo apt-get install build-essential
135
+
136
+ #### Installing Native Dependencies for Electron
137
+
138
+ In order to build Node-Canvas for use of `paper-jsdom-canvas` in Electron, which
139
+ is likely to use a different version of V8 than the Node binary installed in
140
+ your system, you need to manually specify the location of Electron’s headers.
141
+ Follow these steps to do so:
142
+
143
+ [Electron — Using Native Node
144
+ Modules](https://electron.atom.io/docs/tutorial/using-native-node-modules/)
145
+
146
+ #### After Native Dependencies have been installed
147
+
148
+ You should now be able to install the Paper.js module with jsdom and Canvas
149
+ rendering from NPM:
150
+
151
+ npm install paper-jsdom-canvas
152
+
153
+ ## Development
154
+
155
+ The main Paper.js source tree is hosted on
156
+ [GitHub](https://github.com/paperjs/paper.js/). `git` is required to create a
157
+ clone of the repository, and can be easily installed through your preferred
158
+ package manager on your platform.
159
+
160
+ ### Get the Source
161
+
162
+ git clone --recursive git://github.com/paperjs/paper.js.git
163
+ cd paper.js
164
+
165
+ To refresh your clone and fetch changes from origin, run:
166
+
167
+ git fetch origin
168
+
169
+ To update the `jsdoc-toolkit` submodule, used to generate the documentation,
170
+ run:
171
+
172
+ git submodule update --init --recursive
173
+
174
+ ### Setting Up For Building
175
+
176
+ As of 2016, Paper.js uses [Gulp.js](https://gulpjs.com/) for building, and has a
177
+ couple of dependencies as NPM modules. Read the chapter [Installing
178
+ Node.js and NPM](#installing-nodejs-and-npm) if you still need to
179
+ install these.
180
+
181
+ In order to be able to build Paper.js, after checking out the repository, paper
182
+ has dependencies that need to be installed. Install them by issuing the
183
+ following commands from the Paper.js directory:
184
+
185
+ npm install
186
+
187
+ It is also recommended to install Gulp.js globally, so you can easier execute
188
+ the build commands from anywhere in the command line:
189
+
190
+ npm install -g gulp
191
+
192
+ ### Building the Library
193
+
194
+ The Paper.js sources are distributed across many separate files, organised in
195
+ subfolders inside the `src` folder. To compile them all into distributable
196
+ files, you can run the `build` task:
197
+
198
+ gulp build
199
+
200
+ You will then find the built library files inside the `dist` folder, named
201
+ `paper-full.js` and `paper-core.js`, along with their minified versions. Read
202
+ more about this in [Which Version to Use?](#which-version-to-use).
203
+
204
+ ### Running Directly from Separate Source Files
205
+
206
+ As a handy alternative to building the library after each change to try it out
207
+ in your scripts, there is the `load` task, that replaces the built libraries
208
+ with symbolic links to the `scrc/load.js` script. This script then load the
209
+ library directly from all the separate source files in the `src` folder, through
210
+ the [Prepro.js](https://github.com/lehni/prepro.js) JavaScript preprocessing
211
+ library.
212
+
213
+ This means you can switch between loading from sources and loading a built
214
+ library simply by running.
215
+
216
+ gulp load
217
+
218
+ And to go back to a built library
219
+
220
+ gulp build
221
+
222
+ Note that your PaperScripts examples do not need to change, they can keep
223
+ loading `dist/paper-full.js`, which will always do the right thing. Note also
224
+ that `src/load.js` handles both browsers and Node.js, as supported by Prepro.js.
225
+
226
+ ### Other Build Tasks
227
+
228
+ Create a final zipped distribution file inside the `dist` folder:
229
+
230
+ gulp dist
231
+
232
+ And since `dist` is the default task, this is the same:
233
+
234
+ gulp
235
+
236
+ ### Branch structure
237
+
238
+ Since the release of version `0.9.22`, Paper.js has adopted aspects of the Git-
239
+ Flow workflow. All development is taking place in the
240
+ [`develop`](https://github.com/paperjs/paper.js/tree/develop) branch, which is
241
+ only merged into [`master`](https://github.com/paperjs/paper.js/tree/master)
242
+ when a new release occurs.
243
+
244
+ As of version `0.9.26`, the `dist` folder is excluded on all branches, and the
245
+ building is now part of the `npm publish` process by way of the `prepublish`
246
+ script.
247
+
248
+ We also offer prebuilt versions of the latest state of the `develop` branch on
249
+ [`prebuilt/module`](https://github.com/paperjs/paper.js/tree/prebuilt/module)
250
+ and [`prebuilt/dist`](https://github.com/paperjs/paper.js/tree/prebuilt/dist).
251
+
252
+ ### Building the Documentation
253
+
254
+ Similarly to building the library, you can run the `docs` task to build the
255
+ documentation:
256
+
257
+ gulp docs
258
+
259
+ Your docs will then be located at `dist/docs`.
260
+
261
+ ### Testing
262
+
263
+ Paper.js was developed and tested from day 1 using proper unit testing through
264
+ jQuery's [Qunit](https://qunitjs.com/). To run the tests after any
265
+ change to the library's source, simply open `index.html` inside the `test`
266
+ folder in your web browser. There should be a green bar at the top, meaning all
267
+ tests have passed. If the bar is red, some tests have not passed. These will be
268
+ highlighted and become visible when scrolling down.
269
+
270
+ If you are testing on Chrome, some of the tests will fail due to the browser's
271
+ CORS restrictions. In order to run the browser based tests on Chrome, you need
272
+ to run a local web-server through Gulp.js. The following command will handle it
273
+ for you, and will also open the browser at the right address straight away:
274
+
275
+ gulp test:browser
276
+
277
+ You can also run the unit tests through PhantomJS in Gulp directly on the
278
+ command line:
279
+
280
+ gulp test:phantom
281
+
282
+ To test the Node.js version of Paper.js, use this command:
283
+
284
+ gulp test:node
285
+
286
+ And to test both the PhantomJS and Node.js environments together, simply run:
287
+
288
+ gulp test
289
+
290
+ ### Contributing [![Open Source Helpers](https://www.codetriage.com/paperjs/paper.js/badges/users.svg)](https://www.codetriage.com/paperjs/paper.js)
291
+
292
+ The main Paper.js source tree is hosted on GitHub, thus you should create a fork
293
+ of the repository in which you perform development. See
294
+ <https://help.github.com/articles/fork-a-repo/>.
295
+
296
+ We prefer that you send a
297
+ [pull request on GitHub](https://help.github.com/articles/about-pull-requests/)
298
+ which will then be merged into the official main line repository.
299
+ You need to sign the Paper.js CLA to be able to contribute (see below).
300
+
301
+ Also, in your first contribution, add yourself to the end of `AUTHORS.md` (which
302
+ of course is optional).
303
+
304
+ In addition to contributing code you can also triage issues which may include
305
+ reproducing bug reports or asking for vital information, such as version numbers
306
+ or reproduction instructions. If you would like to start triaging issues, one
307
+ easy way to get started is to
308
+ [subscribe to paper.js on CodeTriage](https://www.codetriage.com/paperjs/paper.js).
309
+
310
+ **Get the source (for contributing):**
311
+
312
+ If you want to contribute to the project you will have to [make a
313
+ fork](https://help.github.com/articles/fork-a-repo/). Then do this:
314
+
315
+ git clone --recursive git@github.com:yourusername/paper.js.git
316
+ cd paper.js
317
+ git remote add upstream git://github.com/paperjs/paper.js.git
318
+
319
+ To then fetch changes from upstream, run
320
+
321
+ git fetch upstream
322
+
323
+ #### Creating and Submitting a Patch
324
+
325
+ As mentioned above, we prefer that you send a
326
+ [pull request](https://help.github.com/articles/about-pull-requests/) on GitHub:
327
+
328
+ 1. Create a fork of the upstream repository by visiting
329
+ <https://github.com/paperjs/paper.js/fork>. If you feel insecure, here's a
330
+ great guide: <https://help.github.com/articles/fork-a-repo/>
331
+
332
+ 2. Clone of your repository: `git clone
333
+ https://yourusername@github.com/yourusername/paper.js.git`
334
+
335
+ 3. This is important: Create a so-called *topic branch* based on the `develop`
336
+ branch: `git checkout -tb name-of-my-patch develop` where `name-of-my-patch`
337
+ is a short but descriptive name of the patch you're about to create. Don't
338
+ worry about the perfect name though -- you can change this name at any time
339
+ later on.
340
+
341
+ 4. Hack! Make your changes, additions, etc., commit them then push them to your
342
+ GitHub fork: `git push origin name-of-my-patch`
343
+
344
+ 5. Send a pull request to the upstream repository's owner by visiting your
345
+ repository's site at GitHub (i.e. https://github.com/yourusername/paper.js)
346
+ and press the "Pull Request" button. Make sure you are creating the pull
347
+ request to the `develop` branch, not the `master` branch. Here's a good guide
348
+ on pull requests: <https://help.github.com/articles/about-pull-requests/>
349
+
350
+ ##### Use one topic branch per feature:
351
+
352
+ Don't mix different kinds of patches in the same branch. Instead, merge them all
353
+ together into your `develop` branch (or develop everything in your `develop`
354
+ branch and then cherry-pick-and-merge into the different topic branches). Git
355
+ provides for an extremely flexible workflow, which in many ways causes more
356
+ confusion than it helps you when new to collaborative software development. The
357
+ guides provided by GitHub at <https://help.github.com/> are a really good
358
+ starting point and reference. If you are fixing an issue, a convenient way to
359
+ name the branch is to use the issue number as a prefix, like this: `git checkout
360
+ -tb issue-937-feature-add-text-styling`.
361
+
362
+ #### Contributor License Agreement
363
+
364
+ Before we can accept any contributions to Paper.js, you need to sign this
365
+ [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement):
366
+
367
+ [Contributor License Agreement](https://spreadsheets.google.com/a/paperjs.org/spreadsheet/embeddedform?formkey=dENxd0JBVDY2REo3THVuRmh4YjdWRlE6MQ)
368
+
369
+ > The purpose of this agreement is to clearly define the terms under which
370
+ > intellectual property has been contributed to Paper.js and thereby allow us to
371
+ > defend the project should there be a legal dispute regarding the software at
372
+ > some future time.
373
+
374
+ For a list of authors and contributors, please see
375
+ [AUTHORS](https://github.com/paperjs/paper.js/blob/master/AUTHORS.md).
376
+
377
+ ## License
378
+
379
+ Distributed under the MIT license. See
380
+ [LICENSE](https://github.com/paperjs/paper.js/blob/master/LICENSE.txt)
381
+ fo details.
@@ -0,0 +1,66 @@
1
+ /*
2
+ * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
3
+ * http://paperjs.org/
4
+ *
5
+ * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
6
+ * http://juerglehni.com/ & https://puckey.studio/
7
+ *
8
+ * Distributed under the MIT license. See LICENSE file for details.
9
+ *
10
+ * All rights reserved.
11
+ */
12
+
13
+ // Add some useful extensions to HTMLCanvasElement:
14
+ // - HTMLCanvasElement#type, so we can switch to a PDF canvas
15
+ // - Various Node-Canvas methods, routed through from HTMLCanvasElement:
16
+ // toBuffer, pngStream, createPNGStream, jpegStream, createJPEGStream
17
+
18
+ module.exports = function(self, requireName) {
19
+ var Canvas;
20
+ try {
21
+ Canvas = require('canvas').Canvas;
22
+ } catch(error) {
23
+ // Remove `self.window`, so we still have the global `self` reference,
24
+ // but no `window` object:
25
+ // - On the browser, this corresponds to a worker context.
26
+ // - On Node.js, it basically means the canvas is missing or not working
27
+ // which can be treated the same way.
28
+ delete self.window;
29
+ // Check the required module's name to see if it contains canvas, and
30
+ // only complain about its lack if the module requires it.
31
+ if (/\bcanvas\b/.test(requireName)) {
32
+ throw new Error('Unable to load canvas module.');
33
+ }
34
+ return;
35
+ }
36
+
37
+ var HTMLCanvasElement = self.HTMLCanvasElement,
38
+ idlUtils = require('jsdom/lib/jsdom/living/generated/utils');
39
+
40
+ // Add fake HTMLCanvasElement#type property:
41
+ Object.defineProperty(HTMLCanvasElement.prototype, 'type', {
42
+ get: function() {
43
+ var canvas = idlUtils.implForWrapper(this)._canvas;
44
+ return canvas && canvas.type || 'image';
45
+ },
46
+
47
+ set: function(type) {
48
+ // Allow replacement of internal node-canvas, so we can switch to a
49
+ // PDF canvas.
50
+ var impl = idlUtils.implForWrapper(this),
51
+ size = impl._canvas || impl;
52
+ impl._canvas = new Canvas(size.width, size.height, type);
53
+ impl._context = null;
54
+ }
55
+ });
56
+
57
+ // Extend HTMLCanvasElement with useful methods from the underlying Canvas:
58
+ var methods = ['toBuffer', 'pngStream', 'createPNGStream', 'jpegStream',
59
+ 'createJPEGStream'];
60
+ methods.forEach(function(key) {
61
+ HTMLCanvasElement.prototype[key] = function() {
62
+ var canvas = idlUtils.implForWrapper(this)._canvas;
63
+ return canvas[key].apply(canvas, arguments);
64
+ };
65
+ });
66
+ };
@@ -0,0 +1,156 @@
1
+ /*
2
+ * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
3
+ * http://paperjs.org/
4
+ *
5
+ * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
6
+ * http://juerglehni.com/ & https://puckey.studio/
7
+ *
8
+ * Distributed under the MIT license. See LICENSE file for details.
9
+ *
10
+ * All rights reserved.
11
+ */
12
+
13
+ var fs = require('fs'),
14
+ path = require('path');
15
+
16
+ module.exports = function(paper) {
17
+ if (paper.PaperScript) {
18
+ var sourceMapSupport = 'require("source-map-support").install(paper.PaperScript.sourceMapSupport);\n',
19
+ sourceMaps = {};
20
+
21
+ paper.PaperScript.sourceMapSupport = {
22
+ retrieveSourceMap: function(source) {
23
+ var map = sourceMaps[source];
24
+ return map ? { url: source, map: map } : null;
25
+ }
26
+ };
27
+
28
+ // Register the .pjs extension for automatic compilation as PaperScript
29
+ require.extensions['.pjs'] = function(module, filename) {
30
+ // Requiring a PaperScript on Node.js returns an initialize method which
31
+ // needs to receive a Canvas object when called and returns the
32
+ // PaperScope.
33
+ module.exports = function(canvas) {
34
+ var source = fs.readFileSync(filename, 'utf8'),
35
+ code = sourceMapSupport + source,
36
+ compiled = paper.PaperScript.compile(code, {
37
+ url: filename,
38
+ source: source,
39
+ sourceMaps: true,
40
+ offset: -1 // remove sourceMapSupport...
41
+ }),
42
+ scope = new paper.PaperScope();
43
+ // Keep track of sourceMaps so retrieveSourceMap() can link them up
44
+ scope.setup(canvas);
45
+ scope.__filename = filename;
46
+ scope.__dirname = path.dirname(filename);
47
+ // Expose core methods and values
48
+ scope.require = require;
49
+ scope.console = console;
50
+ sourceMaps[filename] = compiled.map;
51
+ paper.PaperScript.execute(compiled, scope);
52
+ return scope;
53
+ };
54
+ };
55
+ }
56
+
57
+ paper.PaperScope.inject({
58
+ createCanvas: function(width, height, type) {
59
+ // Do not use CanvasProvider.getCanvas(), since we may be changing
60
+ // the underlying node-canvas when requesting PDF support, and don't
61
+ // want to release it after back into the pool.
62
+ var canvas = paper.document.createElement('canvas');
63
+ canvas.width = width;
64
+ canvas.height = height;
65
+ canvas.type = type;
66
+ return canvas;
67
+ },
68
+
69
+ /**
70
+ * @deprecated, use use {@link #createCanvas(width, height)} instead.
71
+ */
72
+ Canvas: '#createCanvas'
73
+ });
74
+
75
+ // Override requestAnimationFrame() to avoid setInterval() timers.
76
+ // NOTE: In Node.js, we only support manual updating for now, but
77
+ // View#exportFrames() below offers a way to emulate animations by exporting
78
+ // them frame by frame at the given frame-rate.
79
+ paper.DomEvent.requestAnimationFrame = function(callback) {
80
+ };
81
+
82
+ // Node.js based image exporting code.
83
+ paper.CanvasView.inject({
84
+ // DOCS: CanvasView#exportFrames(options);
85
+ exportFrames: function(options) {
86
+ options = paper.Base.set({
87
+ fps: 30,
88
+ prefix: 'frame-',
89
+ amount: 1,
90
+ format: 'png' // Supported: 'png' or 'jpeg'
91
+ }, options);
92
+ if (!options.directory)
93
+ throw new Error('Missing options.directory');
94
+ if (options.format && !/^(jpeg|png)$/.test(options.format))
95
+ throw new Error('Unsupported format. Use "png" or "jpeg"');
96
+ var view = this,
97
+ count = 0,
98
+ frameDuration = 1 / options.fps,
99
+ startTime = Date.now(),
100
+ lastTime = startTime,
101
+ padding = options.padding || ((options.amount - 1) + '').length,
102
+ paddedStr = Array(padding + 1).join('0');
103
+
104
+ // Start exporting frames by exporting the first frame:
105
+ exportFrame(options);
106
+
107
+ function exportFrame() {
108
+ // Convert to a Base object, for #toString()
109
+ view.emit('frame', new paper.Base({
110
+ delta: frameDuration,
111
+ time: frameDuration * count,
112
+ count: count
113
+ }));
114
+ var file = path.join(options.directory,
115
+ options.prefix + (paddedStr + count).slice(-padding)
116
+ + '.' + options.format);
117
+ var out = view.exportImage(file, function() {
118
+ // Once the file has been closed, export the next fame:
119
+ var then = Date.now();
120
+ if (options.onProgress) {
121
+ options.onProgress({
122
+ count: count,
123
+ amount: options.amount,
124
+ percentage: Math.round((count + 1) / options.amount
125
+ * 10000) / 100,
126
+ time: then - startTime,
127
+ delta: then - lastTime
128
+ });
129
+ }
130
+ lastTime = then;
131
+ if (++count < options.amount) {
132
+ exportFrame();
133
+ } else {
134
+ // Call onComplete handler when finished:
135
+ if (options.onComplete) {
136
+ options.onComplete();
137
+ }
138
+ }
139
+ });
140
+ }
141
+ },
142
+
143
+ // DOCS: CanvasView#exportImage(path, callback);
144
+ exportImage: function(path, callback) {
145
+ this.update();
146
+ var out = fs.createWriteStream(path),
147
+ format = /\.jp(e?)g$/.test(path) ? 'jpeg' : 'png',
148
+ stream = this._element[format + 'Stream']();
149
+ stream.pipe(out);
150
+ if (callback) {
151
+ out.on('close', callback);
152
+ }
153
+ return out;
154
+ }
155
+ });
156
+ };
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
3
+ * http://paperjs.org/
4
+ *
5
+ * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
6
+ * http://juerglehni.com/ & https://puckey.studio/
7
+ *
8
+ * Distributed under the MIT license. See LICENSE file for details.
9
+ *
10
+ * All rights reserved.
11
+ */
12
+
13
+ // Node.js emulation layer of browser environment, based on jsdom with node-
14
+ // canvas integration.
15
+
16
+ var path = require('path');
17
+ // Determine the name by which name the module was required (either 'paper',
18
+ // 'paper-jsdom' or 'paper-jsdom-canvas'), and use this to determine if error
19
+ // exceptions should be thrown or if loading should fail silently.
20
+ var parent = module.parent && module.parent.parent,
21
+ requireName = parent && path.basename(path.dirname(parent.filename));
22
+ requireName = /^paper/.test(requireName) ? requireName : 'paper';
23
+
24
+ var jsdom,
25
+ self;
26
+
27
+ try {
28
+ jsdom = require('jsdom');
29
+ } catch(e) {
30
+ // Check the required module's name to see if it contains jsdom, and only
31
+ // complain about its lack if the module requires it.
32
+ if (/\bjsdom\b/.test(requireName)) {
33
+ throw new Error('Unable to load jsdom module.');
34
+ }
35
+ }
36
+
37
+ if (jsdom) {
38
+ // Create our document and window objects through jsdom.
39
+ /* global document:true, window:true */
40
+ var document = new jsdom.JSDOM('<html><body></body></html>', {
41
+ // Use the current working directory as the document's origin, so
42
+ // requests to local files work correctly with CORS.
43
+ url: 'file://' + process.cwd() + '/',
44
+ resources: 'usable'
45
+ });
46
+ self = document.window;
47
+ require('./canvas.js')(self, requireName);
48
+ require('./xml.js')(self);
49
+ } else {
50
+ self = {
51
+ navigator: {
52
+ userAgent: 'Node.js (' + process.platform + '; U; rv:' +
53
+ process.version + ')'
54
+ }
55
+ };
56
+ }
57
+
58
+ module.exports = self;