refactor(kiwi): isolate FIG codec types
This commit is contained in:
parent
086ab2d2ae
commit
0c4429d3ff
|
|
@ -17,10 +17,9 @@ import {
|
|||
encodeNodeChangeWithVariables as encodeNodeChangeVariableBindings,
|
||||
parseVariableId
|
||||
} from '@open-pencil/kiwi/fig'
|
||||
import type { Color, GUID, Matrix, Vector } from '@open-pencil/kiwi/fig'
|
||||
import { compileSchema, encodeBinarySchema } from '@open-pencil/kiwi/schema-runtime'
|
||||
|
||||
import { parseColor } from '#core/color'
|
||||
|
||||
interface CompiledSchema {
|
||||
encodeMessage(message: unknown): Uint8Array
|
||||
decodeMessage(data: Uint8Array): unknown
|
||||
|
|
@ -173,11 +172,7 @@ export function peekMessageType(data: Uint8Array): number | null {
|
|||
|
||||
// Type definitions
|
||||
|
||||
export type { GUID, Color } from '#core/types'
|
||||
|
||||
import type { Color, GUID, Matrix, Vector } from '#core/types'
|
||||
|
||||
export type { Matrix, Vector }
|
||||
export type { Color, GUID, Matrix, Vector } from '@open-pencil/kiwi/fig'
|
||||
|
||||
export interface ParentIndex {
|
||||
guid: GUID
|
||||
|
|
@ -490,8 +485,8 @@ export function createNodeChange(opts: {
|
|||
y: number
|
||||
width: number
|
||||
height: number
|
||||
fill?: Color | string
|
||||
stroke?: Color | string
|
||||
fill?: Color
|
||||
stroke?: Color
|
||||
strokeWeight?: number
|
||||
cornerRadius?: number
|
||||
opacity?: number
|
||||
|
|
@ -519,11 +514,10 @@ export function createNodeChange(opts: {
|
|||
}
|
||||
|
||||
if (opts.fill) {
|
||||
const color = typeof opts.fill === 'string' ? parseColor(opts.fill) : opts.fill
|
||||
change.fillPaints = [
|
||||
{
|
||||
type: 'SOLID',
|
||||
color,
|
||||
color: opts.fill,
|
||||
opacity: 1.0,
|
||||
visible: true,
|
||||
blendMode: 'NORMAL'
|
||||
|
|
@ -532,11 +526,10 @@ export function createNodeChange(opts: {
|
|||
}
|
||||
|
||||
if (opts.stroke) {
|
||||
const color = typeof opts.stroke === 'string' ? parseColor(opts.stroke) : opts.stroke
|
||||
change.strokePaints = [
|
||||
{
|
||||
type: 'SOLID',
|
||||
color,
|
||||
color: opts.stroke,
|
||||
opacity: 1.0,
|
||||
visible: true,
|
||||
blendMode: 'NORMAL'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export { default as figmaSchema } from './schema'
|
||||
export * from './protocol'
|
||||
export * from './types'
|
||||
export * from './variable-bindings'
|
||||
|
|
|
|||
25
packages/kiwi/src/fig/types.ts
Normal file
25
packages/kiwi/src/fig/types.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
export interface GUID {
|
||||
sessionID: number
|
||||
localID: number
|
||||
}
|
||||
|
||||
export interface Color {
|
||||
r: number
|
||||
g: number
|
||||
b: number
|
||||
a: number
|
||||
}
|
||||
|
||||
export interface Vector {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
export interface Matrix {
|
||||
m00: number
|
||||
m01: number
|
||||
m02: number
|
||||
m10: number
|
||||
m11: number
|
||||
m12: number
|
||||
}
|
||||
|
|
@ -1,7 +1,4 @@
|
|||
export interface GUID {
|
||||
sessionID: number
|
||||
localID: number
|
||||
}
|
||||
import type { GUID } from './types'
|
||||
|
||||
export interface VariableBinding {
|
||||
variableID: GUID
|
||||
|
|
|
|||
Loading…
Reference in a new issue