diff --git a/docs/content/examples.md b/docs/content/examples.md index 388b39200..59bffa742 100644 --- a/docs/content/examples.md +++ b/docs/content/examples.md @@ -3,7 +3,7 @@ ```typescript -import { CarEngine, Scene, Widget, Circle, create, move, easeBounce, easeInCirc } from "newcar"; +import { CarEngine, createScene, Widget, Circle, create, move, easeBounce, easeInCirc } from "newcar"; const engine = await new CarEngine().init( "https://unpkg.com/canvaskit-wasm@latest/bin/canvaskit.wasm" @@ -23,7 +23,7 @@ const root = new Widget().add( by: easeBounce }) ); -const scene = new Scene(root); +const scene = createScene(root); app.checkout(scene); app.play(); ``` @@ -35,7 +35,7 @@ app.play(); ```typescript -import { CarEngine, Scene, easeInCirc, Path, stroke } from "newcar"; +import { CarEngine, createScene, easeInCirc, Path, stroke } from "newcar"; const engine = await new CarEngine().init( "https://unpkg.com/canvaskit-wasm@latest/bin/canvaskit.wasm" @@ -56,7 +56,7 @@ const root = new Path({ root.addPathFromSVGString(` M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z `); -const scene = new Scene(root); +const scene = createScene(root); app.checkout(scene); app.play(); ``` diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index e56248590..76a751bbf 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -110,7 +110,7 @@ import * as nc from "newcar"; const engine = await new nc.CarEngine().init("../node_modules/canvaskit-wasm/bin/canvaskit.wasm"); const app = engine.createApp(document.querySelector("#canvas")); const root = new nc.Circle(100); -const scene = new nc.Scene(root); +const scene = nc.createScene(root); app.checkout(scene); app.play(); ``` diff --git a/examples/package.json b/examples/package.json index 5dbd14f3c..6b80d0e7a 100644 --- a/examples/package.json +++ b/examples/package.json @@ -8,7 +8,7 @@ "@newcar/mod-markdown": "workspace:0.3.0", "@newcar/mod-math": "workspace:*", "canvaskit-wasm": "0.39.1", - "newcar": "workspace:1.0.0-alpha.0", + "newcar": "workspace:1.0.0-alpha.1", "vite-plugin-node-polyfills": "^0.21.0" } } diff --git a/packages/basic/package.json b/packages/basic/package.json index 069699663..5fffa9919 100644 --- a/packages/basic/package.json +++ b/packages/basic/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/basic", - "version": "1.0.0-alpha.0", + "version": "1.0.0-alpha.1", "description": "The basic objects, animations and interpolators of newcar.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/basic/src/widgets/figures/arc.ts b/packages/basic/src/widgets/figures/arc.ts index 3dba0b608..0399d8e72 100644 --- a/packages/basic/src/widgets/figures/arc.ts +++ b/packages/basic/src/widgets/figures/arc.ts @@ -22,7 +22,7 @@ export class Arc extends Figure { this.strokePaint.setColor(this.style.borderColor.toFloat4()) this.strokePaint.setStrokeWidth(this.style.borderWidth) this.strokePaint.setAlphaf(this.style.transparency * this.style.borderColor.alpha) - + this.strokePaint.setAntiAlias(this.style.antiAlias) try { const dash = ck.PathEffect.MakeDash( this.style.interval, @@ -37,6 +37,7 @@ export class Arc extends Figure { this.fillPaint.setColor(this.style.fillColor.toFloat4()) this.fillPaint.setStyle(ck.PaintStyle.Fill) this.fillPaint.setAlphaf(this.style.transparency * this.style.fillColor.alpha) + this.fillPaint.setAntiAlias(this.style.antiAlias) // Blend Mode this.strokePaint.setBlendMode(str2BlendMode(ck, this.style.blendMode)) diff --git a/packages/basic/src/widgets/figures/line.ts b/packages/basic/src/widgets/figures/line.ts index d062f6bfe..2d7c40d3c 100644 --- a/packages/basic/src/widgets/figures/line.ts +++ b/packages/basic/src/widgets/figures/line.ts @@ -32,6 +32,7 @@ export class Line extends Widget { this.paint.setStrokeWidth(this.style.width) this.paint.setAlphaf(this.style.transparency * this.style.color.alpha) this.paint.setBlendMode(str2BlendMode(ck, this.style.blendMode)) + this.paint.setAntiAlias(this.style.antiAlias) } predraw(ck: CanvasKit, propertyChanged: string): void { diff --git a/packages/basic/src/widgets/figures/path.ts b/packages/basic/src/widgets/figures/path.ts index bef22529b..839959308 100644 --- a/packages/basic/src/widgets/figures/path.ts +++ b/packages/basic/src/widgets/figures/path.ts @@ -26,6 +26,7 @@ export class Path extends Figure { this.strokePaint.setStrokeWidth(this.style.borderWidth) this.strokePaint.setStrokeJoin(str2StrokeJoin(ck, this.style.join)) this.strokePaint.setStrokeCap(str2StrokeCap(ck, this.style.cap)) + this.strokePaint.setAntiAlias(this.style.antiAlias) try { const dash = ck.PathEffect.MakeDash( this.style.interval, @@ -38,6 +39,7 @@ export class Path extends Figure { this.fillPaint.setStyle(ck.PaintStyle.Fill) this.fillPaint.setColor(this.style.fillColor.toFloat4()) this.fillPaint.setAlphaf(this.style.transparency * this.style.fillColor.alpha) + this.fillPaint.setAntiAlias(this.style.antiAlias) } predraw(ck: CanvasKit, propertyChanged: string): void { diff --git a/packages/basic/src/widgets/figures/polygon.ts b/packages/basic/src/widgets/figures/polygon.ts index 80bb96dc4..0857654c1 100644 --- a/packages/basic/src/widgets/figures/polygon.ts +++ b/packages/basic/src/widgets/figures/polygon.ts @@ -33,6 +33,7 @@ export class Polygon extends Figure { this.strokePaint.setStrokeWidth(this.style.borderWidth) this.strokePaint.setStrokeJoin(str2StrokeJoin(ck, this.style.join)) this.strokePaint.setStrokeCap(str2StrokeCap(ck, this.style.cap)) + this.strokePaint.setAntiAlias(this.style.antiAlias) try { const dash = ck.PathEffect.MakeDash( this.style.interval, @@ -54,6 +55,8 @@ export class Polygon extends Figure { // Blend Mode this.strokePaint.setBlendMode(str2BlendMode(ck, this.style.blendMode)) this.fillPaint.setBlendMode(str2BlendMode(ck, this.style.blendMode)) + + this.fillPaint.setAntiAlias(this.style.antiAlias) } predraw(ck: CanvasKit, propertyChanged: string): void { diff --git a/packages/basic/src/widgets/figures/rect.ts b/packages/basic/src/widgets/figures/rect.ts index d2b05cfc4..1cf8d200a 100644 --- a/packages/basic/src/widgets/figures/rect.ts +++ b/packages/basic/src/widgets/figures/rect.ts @@ -34,6 +34,7 @@ export class Rect extends Figure { this.strokePaint.setStrokeWidth(this.style.borderWidth) this.strokePaint.setStrokeJoin(str2StrokeJoin(ck, this.style.join)) this.strokePaint.setStrokeCap(str2StrokeCap(ck, this.style.cap)) + this.strokePaint.setAntiAlias(this.style.antiAlias) try { const dash = ck.PathEffect.MakeDash( this.style.interval, @@ -46,10 +47,12 @@ export class Rect extends Figure { this.fillPaint.setStyle(ck.PaintStyle.Fill) this.fillPaint.setColor(this.style.fillColor.toFloat4()) this.fillPaint.setAlphaf(this.style.transparency * this.style.fillColor.alpha) + this.fillPaint.setAntiAlias(this.style.antiAlias) // Blend Mode this.strokePaint.setBlendMode(str2BlendMode(ck, this.style.blendMode)) this.fillPaint.setBlendMode(str2BlendMode(ck, this.style.blendMode)) + this.fillPaint.setAntiAlias(this.style.antiAlias) } predraw(ck: CanvasKit, propertyChanged: string): void { diff --git a/packages/basic/src/widgets/imageWidget.ts b/packages/basic/src/widgets/imageWidget.ts index 088256e45..986de07ec 100644 --- a/packages/basic/src/widgets/imageWidget.ts +++ b/packages/basic/src/widgets/imageWidget.ts @@ -16,6 +16,7 @@ export class ImageWidget extends Widget { init(ck: CanvasKit) { this.paint = new ck.Paint() this.paint.setAlphaf(this.style.transparency) + this.paint.setAntiAlias(this.style.antiAlias) try { this.image = ck.MakeImageFromEncoded(this.imageArray) } diff --git a/packages/core/package.json b/packages/core/package.json index 11de0dda3..170083f78 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/core", - "version": "1.0.0-alpha.0", + "version": "1.0.0-alpha.1", "description": "The core of newcar.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/core/src/widget.ts b/packages/core/src/widget.ts index a774ea999..2dc04e79f 100644 --- a/packages/core/src/widget.ts +++ b/packages/core/src/widget.ts @@ -26,6 +26,7 @@ export interface WidgetStyle { rotation?: number transparency?: number blendMode?: BlendMode + antiAlias?: boolean } export class Widget { @@ -69,6 +70,7 @@ export class Widget { this.style.rotation = options.style.rotation ?? 0 this.style.transparency = options.style.transparency ?? 1 this.style.blendMode = options.style.blendMode ?? 'srcOver' + this.style.antiAlias = options.style.antiAlias ?? true } /** diff --git a/packages/newcar/package.json b/packages/newcar/package.json index 2c9d7b8e6..daf9f4521 100644 --- a/packages/newcar/package.json +++ b/packages/newcar/package.json @@ -1,7 +1,7 @@ { "name": "newcar", "type": "module", - "version": "1.0.0-alpha.0", + "version": "1.0.0-alpha.1", "description": "A Highly configurable universal advanced engine, Born for creating animation rapidly.", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/recorder/package.json b/packages/recorder/package.json index 66768605b..68329d045 100644 --- a/packages/recorder/package.json +++ b/packages/recorder/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/recorder", - "version": "1.0.0-alpha.0", + "version": "1.0.0-alpha.1", "description": "The utils of newcar", "author": "BugDuck Team", "license": "Apache-2.0", diff --git a/packages/utils/package.json b/packages/utils/package.json index 869691f02..aea557a5e 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@newcar/utils", - "version": "1.0.0-alpha.0", + "version": "1.0.0-alpha.1", "description": "The utils of newcar", "author": "BugDuck Team", "license": "Apache-2.0",