mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-06-04 09:13:55 -04:00
Rename Json acronyms in API to JSON.
This commit is contained in:
parent
86e77e12bc
commit
cebeb11301
23 changed files with 62 additions and 62 deletions
examples
Animated
JSON
Circle Testing.htmlCompound Path.htmlEmpty Path Testing.htmlGradients.htmlGroup Transform.htmlLine Testing.htmlRandom Path Testing.htmlRaster.htmlRect and Attribute Testing.htmlRotated Primitives.htmlSymbols.htmlText Testing.htmlTransform Test 1.htmlTransform Test 2.html
Paperjs.org
SVG Export
SVG Import
src
test/tests
|
@ -14,7 +14,7 @@
|
|||
}
|
||||
lineGroup.strokeColor = 'red';
|
||||
|
||||
var path1 = project.importJson('["Path",{"pathData":"M63.39307,265.71387c10.8667,6.96631 26.4707,12.26025 43.18896,12.26025c24.79932,0 39.28857,-13.09619 39.28857,-32.04346c0,-17.27588 -10.03125,-27.58545 -35.38721,-37.05908c-30.65088,-11.146 -49.59814,-27.30713 -49.59814,-53.49902c0,-29.25732 24.2417,-50.9917 60.74365,-50.9917c18.94727,0 33.1582,4.4585 41.23877,9.19531L156.18018,133.35986c-5.85156,-3.62256 -18.39014,-8.9165 -35.38721,-8.9165c-25.63525,0 -35.3877,15.3252 -35.3877,28.14258c0,17.5542 11.42432,26.19238 37.33789,36.22314c31.76514,12.26025 47.64795,27.58545 47.64795,55.1709c0,28.979 -21.17676,54.33496 -65.48096,54.33496c-18.11133,0 -37.89502,-5.57275 -47.92578,-12.26025z"}]');
|
||||
var path1 = project.importJSON('["Path",{"pathData":"M63.39307,265.71387c10.8667,6.96631 26.4707,12.26025 43.18896,12.26025c24.79932,0 39.28857,-13.09619 39.28857,-32.04346c0,-17.27588 -10.03125,-27.58545 -35.38721,-37.05908c-30.65088,-11.146 -49.59814,-27.30713 -49.59814,-53.49902c0,-29.25732 24.2417,-50.9917 60.74365,-50.9917c18.94727,0 33.1582,4.4585 41.23877,9.19531L156.18018,133.35986c-5.85156,-3.62256 -18.39014,-8.9165 -35.38721,-8.9165c-25.63525,0 -35.3877,15.3252 -35.3877,28.14258c0,17.5542 11.42432,26.19238 37.33789,36.22314c31.76514,12.26025 47.64795,27.58545 47.64795,55.1709c0,28.979 -21.17676,54.33496 -65.48096,54.33496c-18.11133,0 -37.89502,-5.57275 -47.92578,-12.26025z"}]');
|
||||
path1.position = view.center;
|
||||
|
||||
var path2 = path1.clone();
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
|
||||
var path = new Path.Circle(new Point(50, 50), 25);
|
||||
path.fillColor = 'red';
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
var path2 = new Path.Rectangle([50, 50], [200, 200]);
|
||||
var path3 = new Path.Rectangle([0, 0], [400, 400]);
|
||||
new CompoundPath(path1, path2, path3);
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -17,11 +17,11 @@
|
|||
|
||||
var path3 = new Path();
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
destination: path.bounds.rightCenter
|
||||
}
|
||||
path.strokeColor = 'black';
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
group.translate([100, 100]);
|
||||
group.scale(0.5);
|
||||
group.rotate(10);
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
line3.strokeColor = "yellow";
|
||||
line3.strokeWidth = "5";
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
var path = new Path.Star(center, points, radius1, radius2);
|
||||
path.fillColor = 'black';
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
raster.onLoad = function() {
|
||||
raster.position = view.center;
|
||||
raster.rotate(45);
|
||||
window.importJson(project.exportJson());
|
||||
window.importJSON(project.exportJSON());
|
||||
}
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
window.importJson = function(json) {
|
||||
window.importJSON = function(json) {
|
||||
project.activate();
|
||||
console.log(json);
|
||||
project.importJson(json);
|
||||
project.importJSON(json);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
|
|
@ -42,11 +42,11 @@
|
|||
path4.strokeColor= 'yellow';
|
||||
path4.fillColor='purple';
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
rect.fillColor = 'yellow';
|
||||
rect.rotate(-20);
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
p1.rotate(45);
|
||||
var p2 = symbol.place([300, 200]);
|
||||
p2.rotate(-30);
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
text.shear(.85, .15);
|
||||
text.scale(.85, 2);
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
clonedPath.rotate(angle * i, circlePath.bounds.topLeft);
|
||||
};
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
copy.rotate(-45);
|
||||
copy.scale(0.5);
|
||||
|
||||
window._json = project.exportJson();
|
||||
window._json = project.exportJSON();
|
||||
console.log(window._json);
|
||||
</script>
|
||||
<script type="text/paperscript" canvas="canvas2">
|
||||
project.importJson(window._json);
|
||||
project.importJSON(window._json);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -236,7 +236,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
var heartPath = Project.importJson('["Path",{"pathData":"M514.69629,624.70313c-7.10205,-27.02441 -17.2373,-52.39453 -30.40576,-76.10059c-13.17383,-23.70703 -38.65137,-60.52246 -76.44434,-110.45801c-27.71631,-36.64355 -44.78174,-59.89355 -51.19189,-69.74414c-10.5376,-16.02979 -18.15527,-30.74951 -22.84717,-44.14893c-4.69727,-13.39893 -7.04297,-26.97021 -7.04297,-40.71289c0,-25.42432 8.47119,-46.72559 25.42383,-63.90381c16.94775,-17.17871 37.90527,-25.76758 62.87354,-25.76758c25.19287,0 47.06885,8.93262 65.62158,26.79834c13.96826,13.28662 25.30615,33.10059 34.01318,59.4375c7.55859,-25.88037 18.20898,-45.57666 31.95215,-59.09424c19.00879,-18.32178 40.99707,-27.48535 65.96484,-27.48535c24.7373,0 45.69531,8.53564 62.87305,25.5957c17.17871,17.06592 25.76855,37.39551 25.76855,60.98389c0,20.61377 -5.04102,42.08691 -15.11719,64.41895c-10.08203,22.33203 -29.54687,51.59521 -58.40723,87.78271c-37.56738,47.41211 -64.93457,86.35352 -82.11328,116.8125c-13.51758,24.0498 -23.82422,49.24902 -30.9209,75.58594z","strokeWidth":2,"strokeCap":"round"}]');
|
||||
var heartPath = Project.importJSON('["Path",{"pathData":"M514.69629,624.70313c-7.10205,-27.02441 -17.2373,-52.39453 -30.40576,-76.10059c-13.17383,-23.70703 -38.65137,-60.52246 -76.44434,-110.45801c-27.71631,-36.64355 -44.78174,-59.89355 -51.19189,-69.74414c-10.5376,-16.02979 -18.15527,-30.74951 -22.84717,-44.14893c-4.69727,-13.39893 -7.04297,-26.97021 -7.04297,-40.71289c0,-25.42432 8.47119,-46.72559 25.42383,-63.90381c16.94775,-17.17871 37.90527,-25.76758 62.87354,-25.76758c25.19287,0 47.06885,8.93262 65.62158,26.79834c13.96826,13.28662 25.30615,33.10059 34.01318,59.4375c7.55859,-25.88037 18.20898,-45.57666 31.95215,-59.09424c19.00879,-18.32178 40.99707,-27.48535 65.96484,-27.48535c24.7373,0 45.69531,8.53564 62.87305,25.5957c17.17871,17.06592 25.76855,37.39551 25.76855,60.98389c0,20.61377 -5.04102,42.08691 -15.11719,64.41895c-10.08203,22.33203 -29.54687,51.59521 -58.40723,87.78271c-37.56738,47.41211 -64.93457,86.35352 -82.11328,116.8125c-13.51758,24.0498 -23.82422,49.24902 -30.9209,75.58594z","strokeWidth":2,"strokeCap":"round"}]');
|
||||
var pathLength = heartPath.length;
|
||||
|
||||
var boids = [];
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@
|
|||
var start = Date.now();
|
||||
project.importSvg(document.getElementById('svg2'));
|
||||
console.log(Date.now() - start);
|
||||
// console.log(project.exportJson());
|
||||
// console.log(project.exportJSON());
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
var start = Date.now();
|
||||
project.importSvg(document.getElementById('svg'));
|
||||
console.log(Date.now() - start);
|
||||
// console.log(project.exportJson());
|
||||
// console.log(project.exportJSON());
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -55,8 +55,8 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
*
|
||||
* @param {Object} [options={ precision: 5 }]
|
||||
*/
|
||||
exportJson: function(options) {
|
||||
return Base.exportJson(this, options);
|
||||
exportJSON: function(options) {
|
||||
return Base.exportJSON(this, options);
|
||||
},
|
||||
|
||||
// To support JSON.stringify:
|
||||
|
@ -379,11 +379,11 @@ this.Base = Base.inject(/** @lends Base# */{
|
|||
return res;
|
||||
},
|
||||
|
||||
exportJson: function(obj, options) {
|
||||
exportJSON: function(obj, options) {
|
||||
return JSON.stringify(Base.serialize(obj, options));
|
||||
},
|
||||
|
||||
importJson: function(json) {
|
||||
importJSON: function(json) {
|
||||
return Base.deserialize(
|
||||
typeof json === 'string' ? JSON.parse(json) : json);
|
||||
},
|
||||
|
|
|
@ -2340,12 +2340,12 @@ var Item = this.Item = Base.extend(Callback, {
|
|||
this.setBounds(newBounds);
|
||||
},
|
||||
|
||||
// DOCS: document exportJson (documented in @private Base)
|
||||
// DOCS: document importJson
|
||||
// DOCS: document exportJSON (documented in @private Base)
|
||||
// DOCS: document importJSON
|
||||
// DOCS: Figure out a way to group these together with importSvg / exportSvg
|
||||
|
||||
importJson: function(json) {
|
||||
return this.addChild(Base.importJson(json));
|
||||
importJSON: function(json) {
|
||||
return this.addChild(Base.importJSON(json));
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -266,12 +266,12 @@ var Project = this.Project = PaperScopeItem.extend(/** @lends Project# */{
|
|||
return null;
|
||||
},
|
||||
|
||||
// DOCS: document exportJson (documented in @private Base)
|
||||
// DOCS: document importJson
|
||||
// DOCS: document exportJSON (documented in @private Base)
|
||||
// DOCS: document importJSON
|
||||
// DOCS: Figure out a way to group these together with importSvg / exportSvg
|
||||
|
||||
importJson: function(json) {
|
||||
return Base.importJson(json);
|
||||
importJSON: function(json) {
|
||||
return Base.importJSON(json);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
module('JSON');
|
||||
|
||||
function testExportImportJson(project) {
|
||||
function testExportImportJSON(project) {
|
||||
// Use higher precision than in comparissons, for bounds
|
||||
var json = project.exportJson({ precision: 8 });
|
||||
var json = project.exportJSON({ precision: 8 });
|
||||
var project2 = new Project();
|
||||
project2.clear();
|
||||
project2.importJson(json);
|
||||
project2.importJSON(json);
|
||||
compareProjects(project2, project);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ test('Circles', function() {
|
|||
var rectangle = new Rectangle(topLeft, size);
|
||||
var path = new Path.Ellipse(rectangle);
|
||||
path.fillColor = 'black';
|
||||
console.log('JSON', path.exportJson());
|
||||
console.log('JSON', path.exportJSON());
|
||||
|
||||
var topLeft = new Point(5, 400);
|
||||
var size = new Size(100, 50);
|
||||
|
@ -38,7 +38,7 @@ test('Circles', function() {
|
|||
var path = new Path.Circle(new Point(50, 50), 25);
|
||||
path.fillColor = 'red';
|
||||
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('CompoundPath', function() {
|
||||
|
@ -48,12 +48,12 @@ test('CompoundPath', function() {
|
|||
var path3 = new Path.Rectangle([0, 0], [400, 400]);
|
||||
new CompoundPath(path1, path2, path3);
|
||||
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Empty Path', function() {
|
||||
new Path();
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Gradients', function() {
|
||||
|
@ -64,7 +64,7 @@ test('Gradients', function() {
|
|||
var gradientColor = new Color(gradient, from, to);
|
||||
path.fillColor = gradientColor;
|
||||
path.strokeColor = 'black';
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Group transform', function() {
|
||||
|
@ -76,7 +76,7 @@ test('Group transform', function() {
|
|||
group.translate([100, 100]);
|
||||
group.scale(0.5);
|
||||
group.rotate(10);
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Rectangle testing', function() {
|
||||
|
@ -114,7 +114,7 @@ test('Rectangle testing', function() {
|
|||
var path4 = new Path.Rectangle(rectangle4, cornerSize4);
|
||||
path4.strokeColor= 'yellow';
|
||||
path4.fillColor='purple';
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Symbols', function() {
|
||||
|
@ -129,7 +129,7 @@ test('Symbols', function() {
|
|||
var p2 = symbol.place([300, 200]);
|
||||
p2.rotate(-30);
|
||||
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('PointText testing', function() {
|
||||
|
@ -145,7 +145,7 @@ test('PointText testing', function() {
|
|||
text.rotate(45);
|
||||
text.shear(0.85, 0.15);
|
||||
text.scale(0.85, 2);
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('transform test 1', function() {
|
||||
|
@ -160,7 +160,7 @@ test('transform test 1', function() {
|
|||
var clonedPath = circlePath.clone();
|
||||
clonedPath.rotate(angle * i, circlePath.bounds.topLeft);
|
||||
};
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('transform test 2', function() {
|
||||
|
@ -173,14 +173,14 @@ test('transform test 2', function() {
|
|||
copy.strokeColor = 'red';
|
||||
copy.rotate(-45);
|
||||
copy.scale(0.5);
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Item#name', function() {
|
||||
var path = new Path({
|
||||
name: 'dave'
|
||||
});
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
test('Item#data', function() {
|
||||
|
@ -200,6 +200,6 @@ test('Item#data', function() {
|
|||
}
|
||||
}
|
||||
};
|
||||
testExportImportJson(paper.project);
|
||||
testExportImportJSON(paper.project);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue