mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
📎 Prepare for release 1.0.1 of the penpot library
This commit is contained in:
11
library/CHANGES.md
Normal file
11
library/CHANGES.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.0.1
|
||||
|
||||
- Make the library generate a .penpot file compatible with penpot 2.7.x
|
||||
|
||||
|
||||
## 1.0.0
|
||||
|
||||
- Initial release after big refactor (from the first MVP prototype)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@penpot/library",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"license": "MPL-2.0",
|
||||
"author": "Kaleidos INC",
|
||||
"packageManager": "yarn@4.9.1+sha512.f95ce356460e05be48d66401c1ae64ef84d163dd689964962c6888a9810865e39097a5e9de748876c2e0bf89b232d583c33982773e9903ae7a76257270986538",
|
||||
|
||||
106
library/playground/sample2.js
Normal file
106
library/playground/sample2.js
Normal file
@@ -0,0 +1,106 @@
|
||||
import * as penpot from "#self";
|
||||
import { writeFile, readFile } from "fs/promises";
|
||||
import { createWriteStream } from "fs";
|
||||
import { Writable } from "stream";
|
||||
|
||||
// console.log(penpot);
|
||||
|
||||
(async function () {
|
||||
const context = penpot.createBuildContext();
|
||||
|
||||
{
|
||||
context.addFile({ name: "Test File 1" });
|
||||
context.addPage({ name: "Foo Page" });
|
||||
|
||||
// Add image media
|
||||
const buffer = await readFile("./playground/sample.jpg");
|
||||
const blob = new Blob([buffer], { type: "image/jpeg" });
|
||||
|
||||
const mediaId = context.addFileMedia(
|
||||
{
|
||||
name: "avatar.jpg",
|
||||
width: 512,
|
||||
height: 512,
|
||||
},
|
||||
blob
|
||||
);
|
||||
|
||||
// Add image color asset
|
||||
const assetColorId = context.addLibraryColor({
|
||||
name: "Avatar",
|
||||
opacity: 1,
|
||||
image: {
|
||||
...context.getMediaAsImage(mediaId),
|
||||
keepAspectRatio: true,
|
||||
},
|
||||
});
|
||||
|
||||
const boardId = context.addBoard({
|
||||
name: "Foo Board",
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 500,
|
||||
height: 1000,
|
||||
});
|
||||
|
||||
const fill = {
|
||||
fillColorRefId: assetColorId,
|
||||
fillColorRefFile: context.currentFileId,
|
||||
fillImage: {
|
||||
...context.getMediaAsImage(mediaId),
|
||||
keepAspectRatio: true,
|
||||
},
|
||||
};
|
||||
|
||||
const stroke = {
|
||||
strokeColorRefId: assetColorId,
|
||||
strokeColorRefFile: context.currentFileId,
|
||||
strokeWidth: 48,
|
||||
strokeAlignment: "inner",
|
||||
strokeStyle: "solid",
|
||||
strokeOpacity: 1,
|
||||
strokeImage: {
|
||||
...context.getMediaAsImage(mediaId),
|
||||
keepAspectRatio: true,
|
||||
},
|
||||
};
|
||||
|
||||
context.addRect({
|
||||
name: "Rect 1",
|
||||
x: 20,
|
||||
y: 20,
|
||||
width: 500,
|
||||
height: 1000,
|
||||
fills: [fill],
|
||||
strokes: [stroke],
|
||||
});
|
||||
|
||||
context.closeBoard();
|
||||
context.closeFile();
|
||||
}
|
||||
|
||||
{
|
||||
let result = await penpot.exportAsBytes(context);
|
||||
await writeFile("sample-sync.zip", result);
|
||||
}
|
||||
|
||||
// {
|
||||
// // Create a file stream to write the zip to
|
||||
// const output = createWriteStream('sample-stream.zip');
|
||||
// // Wrap Node's stream in a WHATWG WritableStream
|
||||
// const writable = Writable.toWeb(output);
|
||||
// await penpot.exportStream(context, writable);
|
||||
// }
|
||||
})()
|
||||
.catch((cause) => {
|
||||
console.error(cause);
|
||||
|
||||
const innerCause = cause.cause;
|
||||
if (innerCause) {
|
||||
console.error("Inner cause:", innerCause);
|
||||
}
|
||||
process.exit(-1);
|
||||
})
|
||||
.finally(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
68
library/playground/sample3.js
Normal file
68
library/playground/sample3.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import * as penpot from "#self";
|
||||
import { writeFile, readFile } from "fs/promises";
|
||||
|
||||
(async function () {
|
||||
const context = penpot.createBuildContext();
|
||||
|
||||
{
|
||||
context.addFile({ name: "Test File 1" });
|
||||
context.addPage({ name: "Foo Page" });
|
||||
|
||||
const pathContent = [
|
||||
{
|
||||
"command": "move-to",
|
||||
"params": {
|
||||
"x": 480.0,
|
||||
"y": 839.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "line-to",
|
||||
"params": {
|
||||
"x": 439.0,
|
||||
"y": 802.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "curve-to",
|
||||
"params": {
|
||||
"c1x": 368.0,
|
||||
"c1y": 737.0,
|
||||
"c2x": 310.0,
|
||||
"c2y": 681.0,
|
||||
"x": 264.0,
|
||||
"y": 634.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"command": "close-path",
|
||||
"params": {}
|
||||
}
|
||||
];
|
||||
|
||||
context.addPath({
|
||||
name: "Path 1",
|
||||
content: pathContent
|
||||
});
|
||||
|
||||
context.closeBoard();
|
||||
context.closeFile();
|
||||
}
|
||||
|
||||
{
|
||||
let result = await penpot.exportAsBytes(context);
|
||||
await writeFile("sample-path.zip", result);
|
||||
}
|
||||
})()
|
||||
.catch((cause) => {
|
||||
console.error(cause);
|
||||
|
||||
const innerCause = cause.cause;
|
||||
if (innerCause) {
|
||||
console.error("Inner cause:", innerCause);
|
||||
}
|
||||
process.exit(-1);
|
||||
})
|
||||
.finally(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
Reference in New Issue
Block a user