paper 0.16.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 (63) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/dist/docs/assets/js/paper.js +4565 -733
  3. package/dist/docs/classes/AreaText.html +720 -242
  4. package/dist/docs/classes/ChangeFlag.html +1 -1
  5. package/dist/docs/classes/Color.html +218 -21
  6. package/dist/docs/classes/CompoundPath.html +1146 -296
  7. package/dist/docs/classes/Curve.html +1 -1
  8. package/dist/docs/classes/CurveLocation.html +1 -1
  9. package/dist/docs/classes/DrawEvent.html +69 -0
  10. package/dist/docs/classes/Effect.html +434 -0
  11. package/dist/docs/classes/EffectInstance.html +304 -0
  12. package/dist/docs/classes/Event.html +1 -1
  13. package/dist/docs/classes/Gradient.html +1 -1
  14. package/dist/docs/classes/GradientStop.html +1 -1
  15. package/dist/docs/classes/Group.html +792 -243
  16. package/dist/docs/classes/HitResult.html +1 -1
  17. package/dist/docs/classes/HostItem.html +720 -242
  18. package/dist/docs/classes/Item.html +777 -242
  19. package/dist/docs/classes/Key.html +1 -1
  20. package/dist/docs/classes/KeyEvent.html +1 -1
  21. package/dist/docs/classes/Layer.html +734 -185
  22. package/dist/docs/classes/Matrix.html +1 -1
  23. package/dist/docs/classes/MouseEvent.html +1 -1
  24. package/dist/docs/classes/PaperScope.html +1 -1
  25. package/dist/docs/classes/PaperScript.html +4 -2
  26. package/dist/docs/classes/Path.html +1195 -252
  27. package/dist/docs/classes/PathItem.html +1148 -298
  28. package/dist/docs/classes/PathText.html +720 -242
  29. package/dist/docs/classes/PatternDefinition.html +367 -0
  30. package/dist/docs/classes/Point.html +1 -1
  31. package/dist/docs/classes/PointText.html +720 -242
  32. package/dist/docs/classes/Project.html +177 -7
  33. package/dist/docs/classes/Raster.html +720 -242
  34. package/dist/docs/classes/Rectangle.html +1 -1
  35. package/dist/docs/classes/Segment.html +3 -3
  36. package/dist/docs/classes/Shape.html +720 -242
  37. package/dist/docs/classes/Size.html +1 -1
  38. package/dist/docs/classes/StrokeProfileStop.html +346 -0
  39. package/dist/docs/classes/Style.html +1 -1
  40. package/dist/docs/classes/SymbolDefinition.html +28 -2
  41. package/dist/docs/classes/SymbolItem.html +720 -242
  42. package/dist/docs/classes/TextItem.html +720 -242
  43. package/dist/docs/classes/TextRange.html +1 -1
  44. package/dist/docs/classes/TextStory.html +1 -1
  45. package/dist/docs/classes/Tool.html +2 -2
  46. package/dist/docs/classes/ToolEvent.html +1 -1
  47. package/dist/docs/classes/Tween.html +1 -1
  48. package/dist/docs/classes/View.html +2 -2
  49. package/dist/docs/classes/global.html +1 -1
  50. package/dist/docs/classes/index.html +2 -2
  51. package/dist/docs/index.html +1 -1
  52. package/dist/node/browser.js +15 -0
  53. package/dist/paper-core.js +4476 -674
  54. package/dist/paper-core.min.js +3 -3
  55. package/dist/paper-full.js +4565 -733
  56. package/dist/paper-full.min.js +3 -3
  57. package/dist/paper-hosted.js +5111 -823
  58. package/dist/paper.d.ts +898 -47
  59. package/examples/Paperjs.org/LiveEffects.html +366 -0
  60. package/examples/Paperjs.org/Offsetting.html +379 -0
  61. package/examples/Paperjs.org/StrokeProfiles.html +706 -0
  62. package/examples/Scripts/Patterns.html +57 -0
  63. package/package.json +5 -3
@@ -0,0 +1,379 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Offsetting</title>
6
+ <link rel="stylesheet" href="../css/style.css">
7
+ <style>
8
+ body {
9
+ background: #f6f4f0;
10
+ font: 13px/1.4 -apple-system, 'Helvetica Neue', Helvetica, Arial, sans-serif;
11
+ color: #333;
12
+ }
13
+ .panel {
14
+ position: absolute;
15
+ top: 12px;
16
+ right: 12px;
17
+ width: 240px;
18
+ padding: 14px 16px;
19
+ background: rgba(255, 255, 255, 0.92);
20
+ border-radius: 12px;
21
+ box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
22
+ }
23
+ .panel h1 {
24
+ margin: 0 0 10px;
25
+ font-size: 16px;
26
+ }
27
+ .panel label {
28
+ display: flex;
29
+ align-items: center;
30
+ justify-content: space-between;
31
+ gap: 8px;
32
+ margin: 6px 0;
33
+ }
34
+ .panel input[type=range] {
35
+ width: 120px;
36
+ }
37
+ .panel select {
38
+ width: 128px;
39
+ }
40
+ .panel .info {
41
+ margin-top: 10px;
42
+ color: #888;
43
+ font-size: 11px;
44
+ }
45
+ .panel a {
46
+ color: #e0306a;
47
+ }
48
+ </style>
49
+ <script type="text/javascript" src="../../dist/paper-full.js"></script>
50
+ <script type="text/paperscript" canvas="canvas">
51
+ // Some of the paths that the offsetting of Bézier curves has to survive:
52
+ // cusps, loops, and turns much tighter than the stroke is wide.
53
+ var presets = {
54
+ 'Offsetting': 'M721.1909,218.83184c-1.028,-1.028 2.48827,-0.53606 2.50162,-0.53606c8.3842,0 16.62869,2.05447 23.94408,6.25405c11.27823,6.47454 29.60192,29.58754 13.40154,40.56199c-44.66606,30.25765 -136.47229,-19.05999 -62.36183,-51.99797',
55
+ 'Effed': 'M519.84665,296.07521c0,-2.30167 -0.21182,-4.33948 1.26052,-6.3026c9.17271,-12.23028 7.56313,20.20928 7.56313,23.31964c0,1.05043 1.05043,3.1513 0,3.1513c-0.93954,0 -0.89042,-1.65747 -1.26052,-2.52104c-4.03527,-9.41564 -6.42799,-18.85632 -11.97495,-27.73146c-0.6357,-1.01711 -8.14272,-10.86642 -8.19339,-10.71443c-0.59836,1.79508 0,5.00518 0,6.93287c0,16.71589 10.20873,2.01534 17.64729,9.45391c0.53031,0.53031 -3.78644,1.26052 -4.41182,1.26052',
56
+ 'Trouble': 'M518,66c0,0 34.29362,49.21334 24.29362,249.21334c10,-200 730.35501,322.08393 -447.29362,-31.21334',
57
+ 'Crazy': 'M466,467c0,0 -105,-235 0,0c-376.816,-119.63846 -469.06596,-146.09389 -650.61329,-266.59735c-282.68388,-230.49081 300.86045,-10.26825 452.77726,121.52815',
58
+ 'Islands': 'M466,467c-65,-34 136,64 0,0c308,-28 520,-471 522,-137c-214,-144 -1489,123 -923,-163',
59
+ 'Hook': 'M394.65374,254.50073c-48.30932,181.8027 -357.16038,-261.37014 40.83962,-261.37014c-191.72051,-24.33714 389.60133,-77.5846 501.29159,-7.53624c188.72013,-0.05602 -602.78495,84.40565 -871.78495,181.40565',
60
+ 'Swirl': 'M524,509c200,-253 -474,-399 -74,-399c-150,300 150,290 200,290c50,-150 -250,-220 -550,-120',
61
+ 'Star': null
62
+ };
63
+
64
+ var settings = {
65
+ preset: 'Offsetting',
66
+ mode: 'outline',
67
+ width: 62,
68
+ join: 'round',
69
+ cap: 'round',
70
+ miterLimit: 10,
71
+ closed: false,
72
+ breathe: false,
73
+ fullySelected: true,
74
+ selectionColor: '#00a0ff'
75
+ };
76
+
77
+ var results = new Group();
78
+ var path;
79
+ var drawing;
80
+ var hit;
81
+ var isDragging = false;
82
+ var isPanning = false;
83
+ var contoursTimer;
84
+ var info = document.getElementById('info');
85
+
86
+ function createPreset(name) {
87
+ if (path)
88
+ path.remove();
89
+ path = presets[name]
90
+ ? new Path(presets[name])
91
+ : new Path.Star({ center: [400, 300], points: 7, radius1: 90,
92
+ radius2: 220 });
93
+ path.set({
94
+ strokeColor: '#222',
95
+ strokeWidth: 1.5,
96
+ strokeScaling: false,
97
+ selectedColor: '#222'
98
+ });
99
+ path.fullySelected = true;
100
+ settings.closed = path.closed;
101
+ document.getElementById('closed').checked = path.closed;
102
+ fitView();
103
+ update();
104
+ }
105
+
106
+ function fitView() {
107
+ var bounds = path.bounds.expand(settings.width + 40),
108
+ size = view.viewSize - [280, 40];
109
+ view.zoom = 1;
110
+ view.zoom = Math.min(size.width / bounds.width,
111
+ size.height / bounds.height, 2);
112
+ view.center = bounds.center + [140 / view.zoom, 0];
113
+ }
114
+
115
+ function getOptions(width) {
116
+ return {
117
+ width: width,
118
+ join: settings.join,
119
+ cap: settings.cap,
120
+ miterLimit: settings.miterLimit,
121
+ insert: false
122
+ };
123
+ }
124
+
125
+ function update(width) {
126
+ console.log(path.pathData);
127
+ width = width || settings.width;
128
+ results.removeChildren();
129
+ var time = Date.now(),
130
+ showContours = settings.mode === 'contours' && !isDragging
131
+ && !settings.breathe,
132
+ outline = null;
133
+ if (showContours) {
134
+ // The outlines of ever wider strokes, from pink to yellow:
135
+ var count = 12;
136
+ for (var i = count; i >= 1; i--) {
137
+ var contour = path.outline(getOptions(width * i / count));
138
+ contour.set({
139
+ fillColor: null,
140
+ strokeColor: {
141
+ hue: 340 + i * 70 / count,
142
+ saturation: 0.8,
143
+ brightness: 1
144
+ },
145
+ strokeWidth: 2,
146
+ strokeScaling: false
147
+ });
148
+ results.addChild(contour);
149
+ }
150
+ } else {
151
+ outline = path.outline(getOptions(width));
152
+ if (settings.mode === 'compare') {
153
+ // The canvas' own stroke, beneath the outline's contour:
154
+ var stroke = path.clone({ insert: false });
155
+ stroke.set({
156
+ strokeColor: 'rgba(224, 48, 106, 0.35)',
157
+ strokeWidth: width,
158
+ strokeJoin: settings.join,
159
+ strokeCap: settings.cap,
160
+ miterLimit: settings.miterLimit,
161
+ strokeScaling: true,
162
+ selected: false
163
+ });
164
+ results.addChild(stroke);
165
+ outline.set({
166
+ fillColor: null,
167
+ strokeColor: '#1060ff',
168
+ strokeWidth: 1,
169
+ strokeScaling: false
170
+ });
171
+ } else {
172
+ var bounds = outline.bounds;
173
+ outline.set({
174
+ fillColor: {
175
+ gradient: { stops: ['#ff3d7f', '#ff9a3d', '#ffd23d'] },
176
+ origin: bounds.topLeft,
177
+ destination: bounds.bottomRight
178
+ },
179
+ strokeColor: '#7a1238',
180
+ strokeWidth: 1,
181
+ strokeScaling: false
182
+ });
183
+ }
184
+ results.addChild(outline);
185
+ }
186
+ // The results copy the path's selection, so select the outline on
187
+ // its own, fully with its handles, or only its segments:
188
+ results.selected = false;
189
+ if (outline) {
190
+ outline.selectedColor = settings.selectionColor;
191
+ outline[settings.fullySelected ? 'fullySelected' : 'selected']
192
+ = true;
193
+ }
194
+ results.insertBelow(path);
195
+ info.textContent = (showContours ? '12 outlines' : 'Outline') + ' in '
196
+ + (Date.now() - time) + ' ms, of ' + path.curves.length
197
+ + ' curves.';
198
+ if (settings.mode === 'contours' && !showContours)
199
+ scheduleContours();
200
+ }
201
+
202
+ // Contours take a while, so draw them once the path stops changing:
203
+ function scheduleContours() {
204
+ clearTimeout(contoursTimer);
205
+ contoursTimer = setTimeout(function() {
206
+ if (!isDragging && !settings.breathe)
207
+ update();
208
+ }, 200);
209
+ }
210
+
211
+ function onFrame(event) {
212
+ if (settings.breathe)
213
+ update(settings.width * (0.65 + 0.35 * Math.sin(event.time * 2)));
214
+ }
215
+
216
+ function onMouseDown(event) {
217
+ hit = path.hitTest(event.point, {
218
+ segments: true,
219
+ handles: true,
220
+ tolerance: 8 / view.zoom
221
+ });
222
+ isDragging = true;
223
+ if (!hit && !isPanning) {
224
+ // Draw a new path by hand:
225
+ drawing = new Path({
226
+ segments: [event.point],
227
+ strokeColor: '#222',
228
+ strokeWidth: 1.5,
229
+ strokeScaling: false
230
+ });
231
+ }
232
+ }
233
+
234
+ function onMouseDrag(event) {
235
+ if (isPanning) {
236
+ view.center -= event.delta;
237
+ // The view moved, so the event's next delta would be off:
238
+ event.point -= event.delta;
239
+ } else if (hit) {
240
+ var name = {
241
+ 'segment': 'point',
242
+ 'handle-in': 'handleIn',
243
+ 'handle-out': 'handleOut'
244
+ }[hit.type];
245
+ if (name) {
246
+ hit.segment[name] += event.delta;
247
+ update();
248
+ }
249
+ } else if (drawing) {
250
+ drawing.add(event.point);
251
+ }
252
+ }
253
+
254
+ function onMouseUp() {
255
+ isDragging = false;
256
+ if (drawing) {
257
+ if (drawing.segments.length > 2) {
258
+ drawing.simplify(10);
259
+ drawing.closed = settings.closed;
260
+ drawing.selectedColor = '#222';
261
+ drawing.fullySelected = true;
262
+ path.remove();
263
+ path = drawing;
264
+ } else {
265
+ drawing.remove();
266
+ }
267
+ drawing = null;
268
+ }
269
+ update();
270
+ }
271
+
272
+ function onKeyDown(event) {
273
+ if (event.key === 'space') {
274
+ isPanning = true;
275
+ return false;
276
+ }
277
+ }
278
+
279
+ function onKeyUp(event) {
280
+ if (event.key === 'space')
281
+ isPanning = false;
282
+ }
283
+
284
+ document.getElementById('canvas').addEventListener('wheel',
285
+ function(event) {
286
+ var point = view.viewToProject(
287
+ DomEvent.getOffset(event, view.element));
288
+ view.scale(Math.pow(1.002, -event.deltaY), point);
289
+ event.preventDefault();
290
+ });
291
+
292
+ function bind(id, key, convert) {
293
+ var input = document.getElementById(id);
294
+ input.addEventListener('input', function() {
295
+ settings[key] = convert ? convert(input) : input.value;
296
+ if (key === 'preset') {
297
+ createPreset(settings.preset);
298
+ } else {
299
+ if (key === 'closed')
300
+ path.closed = settings.closed;
301
+ update();
302
+ }
303
+ });
304
+ }
305
+
306
+ bind('preset', 'preset');
307
+ bind('mode', 'mode');
308
+ bind('width', 'width', function(input) { return +input.value; });
309
+ bind('join', 'join');
310
+ bind('cap', 'cap');
311
+ bind('miter-limit', 'miterLimit', function(input) { return +input.value; });
312
+ bind('closed', 'closed', function(input) { return input.checked; });
313
+ bind('breathe', 'breathe', function(input) { return input.checked; });
314
+ bind('fully-selected', 'fullySelected', function(input) {
315
+ return input.checked;
316
+ });
317
+ bind('selection-color', 'selectionColor');
318
+
319
+ document.getElementById('export').addEventListener('click', function() {
320
+ var svg = project.exportSVG({ asString: true });
321
+ this.href = URL.createObjectURL(new Blob([svg],
322
+ { type: 'image/svg+xml' }));
323
+ });
324
+
325
+ createPreset(settings.preset);
326
+ </script>
327
+ </head>
328
+ <body>
329
+ <canvas id="canvas" resize></canvas>
330
+ <div class="panel">
331
+ <h1>Offsetting</h1>
332
+ <label>Path
333
+ <select id="preset">
334
+ <option>Offsetting</option>
335
+ <option>Effed</option>
336
+ <option>Trouble</option>
337
+ <option>Crazy</option>
338
+ <option>Islands</option>
339
+ <option>Hook</option>
340
+ <option>Swirl</option>
341
+ <option>Star</option>
342
+ </select>
343
+ </label>
344
+ <label>Show
345
+ <select id="mode">
346
+ <option value="outline">Outline</option>
347
+ <option value="contours">Contour lines</option>
348
+ <option value="compare">Canvas stroke</option>
349
+ </select>
350
+ </label>
351
+ <label>Width <input id="width" type="range" min="2" max="200" value="62"></label>
352
+ <label>Join
353
+ <select id="join">
354
+ <option>round</option>
355
+ <option>miter</option>
356
+ <option>bevel</option>
357
+ </select>
358
+ </label>
359
+ <label>Cap
360
+ <select id="cap">
361
+ <option>round</option>
362
+ <option>square</option>
363
+ <option>butt</option>
364
+ </select>
365
+ </label>
366
+ <label>Miter limit <input id="miter-limit" type="range" min="1" max="20" value="10"></label>
367
+ <label>Closed <input id="closed" type="checkbox"></label>
368
+ <label>Breathe <input id="breathe" type="checkbox"></label>
369
+ <label>Handles <input id="fully-selected" type="checkbox" checked></label>
370
+ <label>Selection <input id="selection-color" type="color" value="#00a0ff"></label>
371
+ <div class="info">
372
+ <p id="info"></p>
373
+ <p>Drag the points and handles, or draw a new path in the empty
374
+ space. Zoom with the scroll wheel, pan with the space bar held.</p>
375
+ <a id="export" href="#" download="Offsetting.svg">Export SVG</a>
376
+ </div>
377
+ </div>
378
+ </body>
379
+ </html>