paper 0.12.18 → 0.12.20

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 (231) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +5 -14
  3. package/dist/docs/assets/js/paper.js +94 -54
  4. package/dist/docs/classes/Color.html +2 -2
  5. package/dist/docs/classes/CompoundPath.html +2 -2
  6. package/dist/docs/classes/Curve.html +2 -2
  7. package/dist/docs/classes/CurveLocation.html +2 -2
  8. package/dist/docs/classes/Event.html +2 -2
  9. package/dist/docs/classes/Gradient.html +2 -2
  10. package/dist/docs/classes/GradientStop.html +2 -2
  11. package/dist/docs/classes/Group.html +2 -2
  12. package/dist/docs/classes/HitResult.html +2 -2
  13. package/dist/docs/classes/Item.html +2 -2
  14. package/dist/docs/classes/Key.html +2 -2
  15. package/dist/docs/classes/KeyEvent.html +2 -2
  16. package/dist/docs/classes/Layer.html +2 -2
  17. package/dist/docs/classes/Matrix.html +2 -2
  18. package/dist/docs/classes/MouseEvent.html +2 -2
  19. package/dist/docs/classes/PaperScope.html +2 -2
  20. package/dist/docs/classes/PaperScript.html +2 -2
  21. package/dist/docs/classes/Path.html +2 -2
  22. package/dist/docs/classes/PathItem.html +2 -2
  23. package/dist/docs/classes/Point.html +2 -2
  24. package/dist/docs/classes/PointText.html +2 -2
  25. package/dist/docs/classes/Project.html +2 -2
  26. package/dist/docs/classes/Raster.html +2 -2
  27. package/dist/docs/classes/Rectangle.html +2 -2
  28. package/dist/docs/classes/Segment.html +2 -2
  29. package/dist/docs/classes/Shape.html +2 -2
  30. package/dist/docs/classes/Size.html +2 -2
  31. package/dist/docs/classes/Style.html +2 -2
  32. package/dist/docs/classes/SymbolDefinition.html +2 -2
  33. package/dist/docs/classes/SymbolItem.html +2 -2
  34. package/dist/docs/classes/TextItem.html +2 -2
  35. package/dist/docs/classes/Tool.html +2 -2
  36. package/dist/docs/classes/ToolEvent.html +2 -2
  37. package/dist/docs/classes/Tween.html +2 -2
  38. package/dist/docs/classes/View.html +2 -2
  39. package/dist/docs/classes/global.html +2 -2
  40. package/dist/docs/classes/index.html +2 -2
  41. package/dist/docs/index.html +1 -1
  42. package/dist/node/canvas.js +9 -7
  43. package/dist/node/self.js +9 -1
  44. package/dist/paper-core.js +93 -53
  45. package/dist/paper-core.min.js +3 -3
  46. package/dist/paper-full.js +94 -54
  47. package/dist/paper-full.min.js +3 -3
  48. package/dist/paper.d.ts +2 -2
  49. package/package.json +11 -7
  50. package/dist/paperjs/LICENSE.txt +0 -23
  51. package/dist/paperjs/dist/node/canvas.js +0 -66
  52. package/dist/paperjs/dist/node/extend.js +0 -156
  53. package/dist/paperjs/dist/node/self.js +0 -58
  54. package/dist/paperjs/dist/node/xml.js +0 -40
  55. package/dist/paperjs/dist/paper-core.d.ts +0 -1
  56. package/dist/paperjs/dist/paper-core.js +0 -15703
  57. package/dist/paperjs/dist/paper-core.min.js +0 -32
  58. package/dist/paperjs/dist/paper-full.js +0 -17472
  59. package/dist/paperjs/dist/paper-full.min.js +0 -32
  60. package/dist/paperjs/dist/paper.d.ts +0 -7394
  61. package/dist/paperjs/docs/assets/css/docs.css +0 -414
  62. package/dist/paperjs/docs/assets/js/codemirror.js +0 -4
  63. package/dist/paperjs/docs/assets/js/docs.js +0 -493
  64. package/dist/paperjs/docs/assets/js/jquery.js +0 -6
  65. package/dist/paperjs/docs/assets/js/paper.js +0 -17472
  66. package/dist/paperjs/docs/classes/Color.html +0 -2188
  67. package/dist/paperjs/docs/classes/CompoundPath.html +0 -8877
  68. package/dist/paperjs/docs/classes/Curve.html +0 -2323
  69. package/dist/paperjs/docs/classes/CurveLocation.html +0 -672
  70. package/dist/paperjs/docs/classes/Event.html +0 -176
  71. package/dist/paperjs/docs/classes/Gradient.html +0 -240
  72. package/dist/paperjs/docs/classes/GradientStop.html +0 -273
  73. package/dist/paperjs/docs/classes/Group.html +0 -6864
  74. package/dist/paperjs/docs/classes/HitResult.html +0 -239
  75. package/dist/paperjs/docs/classes/Item.html +0 -6628
  76. package/dist/paperjs/docs/classes/Key.html +0 -139
  77. package/dist/paperjs/docs/classes/KeyEvent.html +0 -308
  78. package/dist/paperjs/docs/classes/Layer.html +0 -6850
  79. package/dist/paperjs/docs/classes/Matrix.html +0 -1744
  80. package/dist/paperjs/docs/classes/MouseEvent.html +0 -355
  81. package/dist/paperjs/docs/classes/PaperScope.html +0 -459
  82. package/dist/paperjs/docs/classes/PaperScript.html +0 -198
  83. package/dist/paperjs/docs/classes/Path.html +0 -11775
  84. package/dist/paperjs/docs/classes/PathItem.html +0 -8639
  85. package/dist/paperjs/docs/classes/Point.html +0 -2699
  86. package/dist/paperjs/docs/classes/PointText.html +0 -7029
  87. package/dist/paperjs/docs/classes/Project.html +0 -1305
  88. package/dist/paperjs/docs/classes/Raster.html +0 -7843
  89. package/dist/paperjs/docs/classes/Rectangle.html +0 -1654
  90. package/dist/paperjs/docs/classes/Segment.html +0 -939
  91. package/dist/paperjs/docs/classes/Shape.html +0 -7363
  92. package/dist/paperjs/docs/classes/Size.html +0 -1825
  93. package/dist/paperjs/docs/classes/Style.html +0 -919
  94. package/dist/paperjs/docs/classes/SymbolDefinition.html +0 -311
  95. package/dist/paperjs/docs/classes/SymbolItem.html +0 -6755
  96. package/dist/paperjs/docs/classes/TextItem.html +0 -6869
  97. package/dist/paperjs/docs/classes/Tool.html +0 -761
  98. package/dist/paperjs/docs/classes/ToolEvent.html +0 -446
  99. package/dist/paperjs/docs/classes/Tween.html +0 -374
  100. package/dist/paperjs/docs/classes/View.html +0 -1772
  101. package/dist/paperjs/docs/classes/global.html +0 -425
  102. package/dist/paperjs/docs/classes/index.html +0 -88
  103. package/dist/paperjs/docs/index.html +0 -11
  104. package/dist/paperjs/examples/Animated/AnimatedStar.html +0 -53
  105. package/dist/paperjs/examples/Animated/BooleanOperations.html +0 -115
  106. package/dist/paperjs/examples/Animated/CandyCrash.html +0 -151
  107. package/dist/paperjs/examples/Animated/Extruded.html +0 -50
  108. package/dist/paperjs/examples/Animated/Lines.html +0 -53
  109. package/dist/paperjs/examples/Animated/Smoothing.html +0 -70
  110. package/dist/paperjs/examples/Animated/Space.html +0 -86
  111. package/dist/paperjs/examples/Animated/SpaceUsingShapes.html +0 -79
  112. package/dist/paperjs/examples/Games/Paperoids.html +0 -569
  113. package/dist/paperjs/examples/JSON/Circle Testing.html +0 -34
  114. package/dist/paperjs/examples/JSON/Compound Path.html +0 -25
  115. package/dist/paperjs/examples/JSON/Empty Path Testing.html +0 -31
  116. package/dist/paperjs/examples/JSON/Gradients.html +0 -34
  117. package/dist/paperjs/examples/JSON/Group Transform.html +0 -28
  118. package/dist/paperjs/examples/JSON/Line Testing.html +0 -44
  119. package/dist/paperjs/examples/JSON/Random Path Testing.html +0 -42
  120. package/dist/paperjs/examples/JSON/Raster.html +0 -29
  121. package/dist/paperjs/examples/JSON/Rect and Attribute Testing.html +0 -56
  122. package/dist/paperjs/examples/JSON/Rotated Primitives.html +0 -55
  123. package/dist/paperjs/examples/JSON/Selection.html +0 -43
  124. package/dist/paperjs/examples/JSON/Shapes.html +0 -54
  125. package/dist/paperjs/examples/JSON/Symbols.html +0 -30
  126. package/dist/paperjs/examples/JSON/Text Testing.html +0 -38
  127. package/dist/paperjs/examples/JSON/Tiger.html +0 -19
  128. package/dist/paperjs/examples/JSON/Transform Test 1.html +0 -32
  129. package/dist/paperjs/examples/JSON/Transform Test 2.html +0 -30
  130. package/dist/paperjs/examples/Node.js/AnimatedStar.js +0 -52
  131. package/dist/paperjs/examples/Node.js/BooleanOperations.js +0 -36
  132. package/dist/paperjs/examples/Node.js/JSONtoPDF.js +0 -20
  133. package/dist/paperjs/examples/Node.js/Raster.js +0 -32
  134. package/dist/paperjs/examples/Node.js/RasterRemote.js +0 -33
  135. package/dist/paperjs/examples/Node.js/SvgExport.js +0 -52
  136. package/dist/paperjs/examples/Node.js/SvgImport.js +0 -23
  137. package/dist/paperjs/examples/Node.js/Tadpoles.js +0 -16
  138. package/dist/paperjs/examples/Node.js/Tadpoles.pjs +0 -278
  139. package/dist/paperjs/examples/Node.js/in.json +0 -1
  140. package/dist/paperjs/examples/Node.js/in.svg +0 -16
  141. package/dist/paperjs/examples/Paperjs.org/BooleanOperattions.html +0 -115
  142. package/dist/paperjs/examples/Paperjs.org/BouncingBalls.html +0 -103
  143. package/dist/paperjs/examples/Paperjs.org/Chain.html +0 -54
  144. package/dist/paperjs/examples/Paperjs.org/DivisionRaster.html +0 -72
  145. package/dist/paperjs/examples/Paperjs.org/FutureSplash.html +0 -122
  146. package/dist/paperjs/examples/Paperjs.org/HitTesting.html +0 -103
  147. package/dist/paperjs/examples/Paperjs.org/InteractiveTiger.html +0 -777
  148. package/dist/paperjs/examples/Paperjs.org/MetaBalls.html +0 -132
  149. package/dist/paperjs/examples/Paperjs.org/NyanRainbow.html +0 -202
  150. package/dist/paperjs/examples/Paperjs.org/PathIntersections.html +0 -76
  151. package/dist/paperjs/examples/Paperjs.org/Qbertify.html +0 -146
  152. package/dist/paperjs/examples/Paperjs.org/RadialRainbows.html +0 -80
  153. package/dist/paperjs/examples/Paperjs.org/RoundedRectangles.html +0 -41
  154. package/dist/paperjs/examples/Paperjs.org/SatieLikedToDraw.html +0 -140
  155. package/dist/paperjs/examples/Paperjs.org/Simplify.html +0 -63
  156. package/dist/paperjs/examples/Paperjs.org/SpiralRaster.html +0 -120
  157. package/dist/paperjs/examples/Paperjs.org/Tadpoles.html +0 -283
  158. package/dist/paperjs/examples/Paperjs.org/Voronoi.html +0 -134
  159. package/dist/paperjs/examples/Rasters/PhyllotaxisRaster.html +0 -96
  160. package/dist/paperjs/examples/Rasters/Raster.html +0 -34
  161. package/dist/paperjs/examples/Rasters/RotationRaster.html +0 -44
  162. package/dist/paperjs/examples/Rasters/Smoothing.html +0 -36
  163. package/dist/paperjs/examples/SVG Export/Circle Testing.html +0 -32
  164. package/dist/paperjs/examples/SVG Export/Clipping.html +0 -17
  165. package/dist/paperjs/examples/SVG Export/Compound Path.html +0 -22
  166. package/dist/paperjs/examples/SVG Export/Empty Path Testing.html +0 -28
  167. package/dist/paperjs/examples/SVG Export/Gradients.html +0 -52
  168. package/dist/paperjs/examples/SVG Export/Group Transform.html +0 -25
  169. package/dist/paperjs/examples/SVG Export/Line Testing.html +0 -41
  170. package/dist/paperjs/examples/SVG Export/Random Path Testing.html +0 -39
  171. package/dist/paperjs/examples/SVG Export/Raster.html +0 -21
  172. package/dist/paperjs/examples/SVG Export/Rect and Attribute Testing.html +0 -53
  173. package/dist/paperjs/examples/SVG Export/Rotated Primitives.html +0 -80
  174. package/dist/paperjs/examples/SVG Export/Shapes.html +0 -58
  175. package/dist/paperjs/examples/SVG Export/Symbols.html +0 -27
  176. package/dist/paperjs/examples/SVG Export/Text Testing.html +0 -45
  177. package/dist/paperjs/examples/SVG Export/Tiger.html +0 -23
  178. package/dist/paperjs/examples/SVG Export/Transform Test 1.html +0 -29
  179. package/dist/paperjs/examples/SVG Export/Transform Test 2.html +0 -27
  180. package/dist/paperjs/examples/SVG Import/Arcs.html +0 -78
  181. package/dist/paperjs/examples/SVG Import/Butterfly.html +0 -223
  182. package/dist/paperjs/examples/SVG Import/Circle and Ellipse Testing.html +0 -26
  183. package/dist/paperjs/examples/SVG Import/Clipping.html +0 -100
  184. package/dist/paperjs/examples/SVG Import/From File.html +0 -30
  185. package/dist/paperjs/examples/SVG Import/Gradient.html +0 -138
  186. package/dist/paperjs/examples/SVG Import/Gradients.html +0 -30
  187. package/dist/paperjs/examples/SVG Import/Inkscape Pivot.html +0 -52
  188. package/dist/paperjs/examples/SVG Import/Inkscape.html +0 -88
  189. package/dist/paperjs/examples/SVG Import/Line Testing.html +0 -24
  190. package/dist/paperjs/examples/SVG Import/MoreGradients.html +0 -107
  191. package/dist/paperjs/examples/SVG Import/Multiple Paths Test 1.html +0 -42
  192. package/dist/paperjs/examples/SVG Import/Multiple Paths Test 2.html +0 -33
  193. package/dist/paperjs/examples/SVG Import/Nested Groups Test.html +0 -78
  194. package/dist/paperjs/examples/SVG Import/Polybezier.html +0 -43
  195. package/dist/paperjs/examples/SVG Import/Rect Testing.html +0 -25
  196. package/dist/paperjs/examples/SVG Import/Symbols.html +0 -24
  197. package/dist/paperjs/examples/SVG Import/Testing.html +0 -40
  198. package/dist/paperjs/examples/SVG Import/Text Testing.html +0 -19
  199. package/dist/paperjs/examples/SVG Import/Tiger.html +0 -742
  200. package/dist/paperjs/examples/SVG Import/Transform Testing.html +0 -22
  201. package/dist/paperjs/examples/SVG Import/Viewbox.html +0 -38
  202. package/dist/paperjs/examples/Scripts/Arcs.html +0 -39
  203. package/dist/paperjs/examples/Scripts/BlendModes.html +0 -77
  204. package/dist/paperjs/examples/Scripts/BooleanOperations.html +0 -937
  205. package/dist/paperjs/examples/Scripts/CompoundPath.html +0 -19
  206. package/dist/paperjs/examples/Scripts/CurveTimeParameterization.html +0 -61
  207. package/dist/paperjs/examples/Scripts/HslColor.html +0 -53
  208. package/dist/paperjs/examples/Scripts/PathStructure.html +0 -82
  209. package/dist/paperjs/examples/Scripts/PathTangents.html +0 -73
  210. package/dist/paperjs/examples/Scripts/Resize.html +0 -42
  211. package/dist/paperjs/examples/Scripts/RoundRectangle.html +0 -28
  212. package/dist/paperjs/examples/Scripts/Shapes.html +0 -54
  213. package/dist/paperjs/examples/Scripts/StrokeBounds.html +0 -101
  214. package/dist/paperjs/examples/Scripts/StrokeScaling.html +0 -65
  215. package/dist/paperjs/examples/Tools/BezierTool.html +0 -90
  216. package/dist/paperjs/examples/Tools/Circles.html +0 -28
  217. package/dist/paperjs/examples/Tools/Clouds.html +0 -35
  218. package/dist/paperjs/examples/Tools/DrippingBrush.html +0 -73
  219. package/dist/paperjs/examples/Tools/FancyBrush.html +0 -82
  220. package/dist/paperjs/examples/Tools/Grid.html +0 -44
  221. package/dist/paperjs/examples/Tools/MultiLines.html +0 -44
  222. package/dist/paperjs/examples/Tools/MultipleTools.html +0 -44
  223. package/dist/paperjs/examples/Tools/PathEditing.html +0 -95
  224. package/dist/paperjs/examples/Tools/SquareRounded.html +0 -76
  225. package/dist/paperjs/examples/Tools/Stars.html +0 -38
  226. package/dist/paperjs/examples/Tools/Vektor.html +0 -200
  227. package/dist/paperjs/examples/Tools/Wave.html +0 -50
  228. package/dist/paperjs/examples/Tools/WormFarm.html +0 -88
  229. package/dist/paperjs/examples/Worker/Main.html +0 -53
  230. package/dist/paperjs/examples/Worker/Worker.js +0 -14
  231. package/dist/paperjs/examples/css/style.css +0 -12
@@ -1,493 +0,0 @@
1
- // Install some useful jQuery extensions that we use a lot
2
-
3
- $.support.touch = 'ontouchstart' in window;
4
-
5
- $.extend($.fn, {
6
- orNull: function() {
7
- return this.length > 0 ? this : null;
8
- },
9
-
10
- findAndSelf: function(selector) {
11
- return this.find(selector).add(this.filter(selector));
12
- }
13
- });
14
-
15
- // Little Helpers
16
-
17
- function hyphenate(str) {
18
- return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
19
- }
20
-
21
- function isVisible(el) {
22
- if (el.is(':hidden'))
23
- return false;
24
- var viewTop = $(window).scrollTop();
25
- var viewBottom = viewTop + $(window).height();
26
- var top = el.offset().top;
27
- var bottom = top + el.height();
28
- return top >= viewTop && bottom <= viewBottom
29
- || top <= viewTop && bottom >= viewTop
30
- || top <= viewBottom && bottom >= viewBottom;
31
- }
32
-
33
- function smoothScrollTo(el, callback) {
34
- $('html, body').animate({
35
- scrollTop: el.offset().top
36
- }, 250, callback);
37
- }
38
-
39
- var behaviors = {};
40
-
41
- behaviors.hiDPI = function() {
42
- // Turn off hiDPI for all touch devices for now, until the site is built
43
- // true to scale.
44
- if ($.support.touch)
45
- $('canvas').attr('hidpi', 'off');
46
- };
47
-
48
- behaviors.sections = function() {
49
- var toc = $('.toc');
50
- var checks = [];
51
- var active;
52
-
53
- function update() {
54
- $.each(checks, function() {
55
- if (this())
56
- return false;
57
- });
58
- }
59
-
60
- $(document).scroll(update);
61
- $(window).resize(update);
62
- setTimeout(update, 0);
63
-
64
- $('article section').each(function() {
65
- var section = $(this);
66
- var anchor = $('a', section);
67
- // Move content until next section inside section
68
- section.append(section.nextUntil('section'));
69
- var title = anchor.attr('title') || $('h1,h2', section).first().text();
70
- var id = section.attr('id');
71
- if (!id) {
72
- id = hyphenate(title)
73
- .replace(/\s+/g, '-')
74
- .replace(/^#/, '')
75
- .replace(/[!"#$%&'\()*+,.\/:;<=>?@\[\\\]\^_`{|}~]+/g, '-')
76
- .replace(/-+/g, '-');
77
- section.attr('id', id);
78
- anchor.attr('name', id);
79
- }
80
-
81
- function activate() {
82
- if (active)
83
- active.removeClass('active');
84
- selector.addClass('active');
85
- active = selector;
86
- }
87
-
88
- // Create table of contents on the fly
89
- if (toc) {
90
- var selector = $('<li class="entry selector"><a href="#' + id + '">'
91
- + title + '</a></li>').appendTo(toc);
92
- if (section.is('.spacer'))
93
- selector.addClass('spacer');
94
- $('a', selector).click(function() {
95
- smoothScrollTo(section, function() {
96
- window.location.hash = id;
97
- });
98
- return false;
99
- });
100
-
101
- checks.push(function() {
102
- var visible = isVisible(section);
103
- if (visible)
104
- activate();
105
- return visible;
106
- });
107
- }
108
- });
109
-
110
- // Adjust height of last section so that the last anchor aligns perfectly
111
- // with the top of the browser window.
112
- var lastSection = $('article section:last');
113
- var lastAnchor = $('a[name]', lastSection);
114
-
115
- function resize() {
116
- lastSection.height('auto');
117
- var bottom = $(document).height() - lastAnchor.offset().top - $(window).height();
118
- if (bottom < 0)
119
- lastSection.height(lastSection.height() - bottom);
120
- }
121
-
122
- if (lastSection.length && lastAnchor.length) {
123
- $(window).on({
124
- load: resize,
125
- resize: resize
126
- });
127
- resize();
128
- }
129
- };
130
-
131
- behaviors.sticky = function() {
132
- $('.sticky').each(function() {
133
- me = $(this);
134
- container = $('<div/>').append(me.contents()).appendTo(me);
135
- // Insert a div wrapper of which the fixed class is modified depending on position
136
- $(window).scroll(function() {
137
- if (container.is(':visible'))
138
- container.toggleClass('fixed', me.offset().top - $(this).scrollTop() <= 0);
139
- });
140
- });
141
- };
142
-
143
- behaviors.hash = function() {
144
- var hash = unescape(window.location.hash);
145
- if (hash) {
146
- // First see if there's a class member to open
147
- var target = $(hash);
148
- if (target.length) {
149
- if (target.hasClass('member'))
150
- toggleMember(target);
151
- smoothScrollTo(target);
152
- }
153
- }
154
- };
155
-
156
- behaviors.thumbnails = function() {
157
- var thumbnails = $('.thumbnail');
158
- var height = 0;
159
- thumbnails.each(function() {
160
- height = Math.max(height, $(this).height());
161
- });
162
- $('.thumbnail').height(height);
163
- };
164
-
165
- behaviors.expandableLists = function() {
166
- $('.expandable-list').each(function() {
167
- var list = $(this);
168
- $('<a href="#" class="arrow"/>')
169
- .prependTo(list)
170
- .click(function() {
171
- list.toggleClass('expanded');
172
- });
173
- });
174
- };
175
-
176
- behaviors.referenceClass = function() {
177
- var classes = $('.reference-classes');
178
- if (classes.length) {
179
- // Mark currently selected class as active. Do it client-sided
180
- // since the menu is generated by jsdocs.
181
- var path = window.location.pathname.toLowerCase();
182
- $('a[href="' + path + '"]', classes).addClass('active');
183
- }
184
- };
185
-
186
- behaviors.hover = function() {
187
- $('.hover').hover(function() {
188
- $('.normal', this).toggleClass('hidden');
189
- $('.over', this).toggleClass('hidden');
190
- });
191
- };
192
-
193
- behaviors.code = function() {
194
- $('.code:visible, pre:visible code').each(function() {
195
- createCode($(this));
196
- });
197
- };
198
-
199
- behaviors.paperscript = function() {
200
- // Ignore all paperscripts in the automatic load event, and load them
201
- // separately in createPaperScript() when needed.
202
- $('script[type="text/paperscript"]').attr('ignore', 'true');
203
- $('.paperscript:visible').each(function() {
204
- createPaperScript($(this));
205
- });
206
- };
207
-
208
- function createCodeMirror(place, options, source) {
209
- return new CodeMirror(place, $.extend({}, {
210
- mode: 'javascript',
211
- lineNumbers: true,
212
- matchBrackets: true,
213
- tabSize: 4,
214
- indentUnit: 4,
215
- indentWithTabs: true,
216
- tabMode: 'shift',
217
- value: source.text().match(
218
- // Remove first & last empty line
219
- /^\s*?[\n\r]?([\u0000-\uffff]*?)[\n\r]?\s*?$/)[1]
220
- }, options));
221
- }
222
-
223
- function createCode(element) {
224
- if (element.data('initialized'))
225
- return;
226
- var start = element.attr('start');
227
- var highlight = element.attr('highlight');
228
- var editor = createCodeMirror(function(el) {
229
- element.replaceWith(el);
230
- }, {
231
- lineNumbers: !element.parent('.resource-text').length,
232
- firstLineNumber: parseInt(start || 1, 10),
233
- mode: element.attr('mode') || 'javascript',
234
- readOnly: true
235
- }, element);
236
- if (highlight) {
237
- var highlights = highlight.split(',');
238
- for (var i = 0, l = highlights.length; i < l; i++) {
239
- var highlight = highlights[i].split('-');
240
- var hlStart = parseInt(highlight[0], 10) - 1;
241
- var hlEnd = highlight.length == 2
242
- ? parseInt(highlight[1], 10) - 1 : hlStart;
243
- if (start) {
244
- hlStart -= start - 1;
245
- hlEnd -= start - 1;
246
- }
247
- for (var j = hlStart; j <= hlEnd; j++) {
248
- editor.setLineClass(j, 'highlight');
249
- }
250
- }
251
- }
252
- element.data('initialized', true);
253
- }
254
-
255
- function createPaperScript(element) {
256
- if (element.data('initialized'))
257
- return;
258
-
259
- var script = $('script', element).orNull(),
260
- runButton = $('.button.run', element).orNull();
261
- if (!script)
262
- return;
263
- // Now load / parse / execute the script
264
- script.removeAttr('ignore');
265
- var scope = paper.PaperScript.load(script[0]);
266
- if (!runButton)
267
- return;
268
-
269
- var canvas = $('canvas', element),
270
- hasResize = canvas.attr('resize'),
271
- showSplit = element.hasClass('split'),
272
- sourceFirst = element.hasClass('source'),
273
- editor = null,
274
- hasBorders = true,
275
- edited = false,
276
- animateExplain,
277
- explain = $('.explain', element).orNull(),
278
- source = $('<div class="source hidden"/>').insertBefore(script);
279
-
280
- if (explain) {
281
- explain.addClass('hidden');
282
- var text = explain.html().replace(/http:\/\/([\w.]+)/g, function(url, domain) {
283
- return '<a href="' + url + '">' + domain + '</a>';
284
- }).trim();
285
- // Add explanation bubbles to tickle the visitor's fancy
286
- var explanations = [{
287
- index: 0,
288
- list: [
289
- [text ? 4 : 3, text || ''],
290
- [1, ''],
291
- [4, '<b>Note:</b> You can view and even edit<br>the source right here in the browser'],
292
- [1, ''],
293
- [3, 'To do so, simply press the <b>Source</b> button &rarr;']
294
- ]
295
- }, {
296
- index: 0,
297
- indexIfEdited: 3, // Skip first sentence if user has already edited code
298
- list: [
299
- [4, ''],
300
- [3, 'Why don\'t you try editing the code?'],
301
- [1, ''],
302
- [4, 'To run it again, simply press press <b>Run</b> &rarr;']
303
- ]
304
- }];
305
- var timer,
306
- mode;
307
- animateExplain = function(clearPrevious) {
308
- if (timer)
309
- timer = clearTimeout(timer);
310
- // Set previous mode's index to the end?
311
- if (mode && clearPrevious)
312
- mode.index = mode.list.length;
313
- mode = explanations[source.hasClass('hidden') ? 0 : 1];
314
- if (edited && mode.index < mode.indexIfEdited)
315
- mode.index = mode.indexIfEdited;
316
- var entry = mode.list[mode.index];
317
- if (entry) {
318
- explain.removeClass('hidden');
319
- explain.html(entry[1]);
320
- timer = setTimeout(function() {
321
- // Only increase once we're stepping, not in animate()
322
- // itself, as entering & leaving would continuosly step
323
- mode.index++;
324
- animateExplain();
325
- }, entry[0] * 1000);
326
- }
327
- if (!entry || !entry[1])
328
- explain.addClass('hidden');
329
- };
330
- element
331
- .mouseover(function() {
332
- if (!timer)
333
- animateExplain();
334
- })
335
- .mouseout(function() {
336
- // Check the effect of :hover on button to see if we need
337
- // to turn off...
338
- // TODO: make mouseenter / mouseleave events work again
339
- if (timer && runButton.css('display') == 'none') {
340
- timer = clearTimeout(timer);
341
- explain.addClass('hidden');
342
- }
343
- });
344
- }
345
-
346
- function showSource(show) {
347
- source.toggleClass('hidden', !show);
348
- runButton.text(show ? 'Run' : 'Source');
349
- if (explain)
350
- animateExplain(true);
351
- if (show && !editor) {
352
- editor = createCodeMirror(source[0], {
353
- onKeyEvent: function(editor, event) {
354
- edited = true;
355
- }
356
- }, script);
357
- }
358
- }
359
-
360
- function runScript() {
361
- // Update script to edited version
362
- var code = editor.getValue();
363
- script.text(code);
364
- // Keep a reference to the used canvas, since we're going to
365
- // fully clear the scope and initialize again with this canvas.
366
- // Support both old and new versions of paper.js for now:
367
- var element = scope.view.element;
368
- // Clear scope first, then evaluate a new script.
369
- scope.clear();
370
- scope.initialize(script[0]);
371
- scope.setup(element);
372
- scope.execute(code);
373
- }
374
-
375
- function resize() {
376
- source
377
- .width(element.width() - (hasBorders ? 2 : 1))
378
- .height(element.height() - (hasBorders ? 2 : 0));
379
- if (editor)
380
- editor.refresh();
381
- }
382
-
383
- function toggleView() {
384
- var show = source.hasClass('hidden');
385
- resize();
386
- canvas.toggleClass('hidden', show);
387
- showSource(show);
388
- if (!show)
389
- runScript();
390
- // Add extra margin if there is scrolling
391
- var scrollHeight = $('.CodeMirror .CodeMirror-scroll', source).height();
392
- runButton.css('margin-right', scrollHeight > element.height() ? 25 : 8);
393
- }
394
-
395
- if (hasResize) {
396
- paper.view.on('resize', resize);
397
- hasBorders = false;
398
- source.css('border-width', '0 0 0 1px');
399
- }
400
-
401
- if (showSplit) {
402
- showSource(true);
403
- } else if (sourceFirst) {
404
- toggleView();
405
- }
406
-
407
- runButton
408
- .click(function() {
409
- if (showSplit) {
410
- runScript();
411
- } else {
412
- toggleView();
413
- }
414
- return false;
415
- })
416
- .mousedown(function() {
417
- return false;
418
- });
419
-
420
- element.data('initialized', true);
421
- }
422
-
423
- // Reference (before behaviors)
424
-
425
- var lastMember = null;
426
- function toggleMember(member, dontScroll, offsetElement) {
427
- var link = $('.member-link:first', member);
428
- if (!link.length)
429
- return true;
430
- var desc = $('.member-description', member);
431
- var visible = !link.hasClass('hidden');
432
- // Retrieve y-offset before any changes, so we can correct scrolling after
433
- var offset = (offsetElement || member).offset().top;
434
- if (lastMember && !lastMember.is(member)) {
435
- var prev = lastMember;
436
- lastMember = null;
437
- toggleMember(prev, true);
438
- }
439
- lastMember = visible && member;
440
- link.toggleClass('hidden', visible);
441
- desc.toggleClass('hidden', !visible);
442
- if (!dontScroll) {
443
- // Correct scrolling relatively to where we are, by checking the amount
444
- // the element has shifted due to the above toggleMember call, and
445
- // correcting by 11px offset, caused by 1px border and 10px padding.
446
- var scroll = $(document).scrollTop();
447
- // Only change hash if we're not in frames, since there are redrawing
448
- // issues with that on Chrome.
449
- if (parent === self)
450
- window.location.hash = visible ? member.attr('id') : '';
451
- $(document).scrollTop(scroll
452
- + (visible ? desc : link).offset().top - offset
453
- + 11 * (visible ? 1 : -1));
454
- }
455
- if (!member.data('initialized') && visible) {
456
- behaviors.code();
457
- behaviors.paperscript();
458
- member.data('initialized', true);
459
- }
460
- return false;
461
- }
462
-
463
- $(function() {
464
- $('.reference .member').each(function() {
465
- var member = $(this);
466
- var link = $('.member-link', member);
467
- // Add header to description, with link and closing button
468
- var header = $('<div class="member-header"/>').prependTo($('.member-description', member));
469
- // Clone link, but remove name, id and change href
470
- link.clone().removeAttr('name').removeAttr('id').attr('href', '#').appendTo(header);
471
- // Add closing button.
472
- header.append('<div class="member-close"><input type="button" value="Close"></div>');
473
- });
474
-
475
- // Give open / close buttons behavior
476
- $('.reference')
477
- .on('click', '.member-link, .member-close', function() {
478
- return toggleMember($(this).parents('.member'));
479
- })
480
- .on('click', '.member-text a', function() {
481
- if (this.href.match(/^(.*?)\/?#|$/)[1] === document.location.href.match(/^(.*?)\/?(?:#|$)/)[1]) {
482
- toggleMember($(this.href.match(/(#.*)$/)[1]), false, $(this));
483
- return false;
484
- }
485
- });
486
- });
487
-
488
- // DOM-Ready
489
-
490
- $(function() {
491
- for (var i in behaviors)
492
- behaviors[i]();
493
- });