-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(50%): move the basic lib of v1.0.0 into next version
- Loading branch information
1 parent
dfc3be5
commit d39e1f9
Showing
8 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './move' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Base } from '@newcar/core' | ||
import { withProcess } from '@newcar/core' | ||
|
||
withProcess<Base>((ctx, process) => { | ||
ctx.widget.x.value = ctx.widget.x.value * process | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './animations' | ||
export * from './widgets' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Vector2 = [number, number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { def, defineWidgetBuilder } from '@newcar/core' | ||
import { deepMerge } from '@newcar/utils' | ||
import type { ArcOptions } from './arc' | ||
import { createArc } from './arc' | ||
|
||
export function createCircle(radius: number, options: ArcOptions) { | ||
return defineWidgetBuilder((ck) => { | ||
const arc = createArc(radius, 0, 360, options)(ck) | ||
const radiusProp = def(radius) | ||
|
||
return deepMerge(arc, { | ||
...options, | ||
radius: radiusProp, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { Prop } from '@newcar/core' | ||
import { changed, def, defineWidgetBuilder } from '@newcar/core' | ||
import { Canvas, CanvasKit } from 'canvaskit-wasm' | ||
import { deepMerge } from '@newcar/utils' | ||
import type { Vector2 } from '../utils/vector2' | ||
import type { PathOptions, PathStyle } from './path' | ||
import { createPath } from './path' | ||
|
||
export interface LineOptions extends PathOptions { | ||
style?: LineStyle | ||
} | ||
|
||
export interface LineStyle extends PathStyle { | ||
|
||
/** | ||
* The line width of this line. | ||
*/ | ||
width?: number | ||
} | ||
|
||
export function createLine(from: Vector2, to: Vector2, options: LineOptions) { | ||
return defineWidgetBuilder((ck) => { | ||
const path = createPath(options)(ck) | ||
|
||
const fromProp = def(from) | ||
const toProp = def(to) | ||
options.style ??= {} | ||
const style = { | ||
width: options.style.width ?? 2, | ||
} | ||
|
||
path.path.moveTo(from[0], from[1]) | ||
path.path.lineTo(to[0], to[1]) | ||
|
||
function reset(v: Prop<Vector2>) { | ||
path.path.reset() | ||
path.path.moveTo(v.value[0], v.value[1]) | ||
path.path.lineTo(v.value[0], v.value[1]) | ||
} | ||
|
||
changed(fromProp, reset) | ||
changed(toProp, reset) | ||
|
||
return deepMerge(path, { | ||
style, | ||
from: fromProp, | ||
to: toProp, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters