refactor(fig): extract paint import policy
- Move paint/effect normalization and derived glyph conversion into the Fig package\n- Rewire core import and instance paths through the public node-change boundary\n- Keep static renderer evidence pointed at the new format-policy source
This commit is contained in:
parent
a10911c772
commit
db056317a8
|
|
@ -1,3 +1,4 @@
|
|||
import { convertFigmaDerivedTextGlyphs } from '@open-pencil/fig/node-change'
|
||||
import type { SceneNode } from '@open-pencil/scene-graph'
|
||||
|
||||
import type {
|
||||
|
|
@ -5,7 +6,6 @@ import type {
|
|||
OverrideContext
|
||||
} from '#core/kiwi/fig/instance-overrides/types'
|
||||
import { convertLetterSpacing, convertLineHeight } from '#core/kiwi/fig/node-change/convert'
|
||||
import { convertFigmaDerivedTextGlyphs } from '#core/kiwi/fig/node-change/derived-text-glyphs'
|
||||
|
||||
import { resolveDsdGeometry } from './geometry'
|
||||
|
||||
|
|
|
|||
|
|
@ -5,14 +5,17 @@ import { parseVariantName } from '@open-pencil/scene-graph/variant-name'
|
|||
import { DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT } from '#core/constants'
|
||||
import { styleToWeight } from '#core/text/fonts'
|
||||
|
||||
import { convertEffects, convertFills, convertStrokes } from './paint'
|
||||
import { importStyleRuns } from './style-runs'
|
||||
export { importStyleRuns } from './style-runs'
|
||||
import {
|
||||
convertEffects,
|
||||
convertFigmaDerivedTextGlyphs,
|
||||
convertFills,
|
||||
convertFontFeatures,
|
||||
convertFontVariations,
|
||||
convertLetterSpacing,
|
||||
convertLineHeight,
|
||||
convertStrokes,
|
||||
extractBoundVariables,
|
||||
extractExportSettings,
|
||||
extractPluginData,
|
||||
|
|
@ -24,12 +27,14 @@ import {
|
|||
mapTextDecoration
|
||||
} from '@open-pencil/fig/node-change'
|
||||
|
||||
import { convertFigmaDerivedTextGlyphs } from './derived-text-glyphs'
|
||||
export { convertEffects, convertFills, convertStrokes, setVariableColorResolver } from './paint'
|
||||
export {
|
||||
convertEffects,
|
||||
convertFills,
|
||||
convertLetterSpacing,
|
||||
convertLineHeight,
|
||||
mapTextDecoration
|
||||
convertStrokes,
|
||||
mapTextDecoration,
|
||||
setVariableColorResolver
|
||||
} from '@open-pencil/fig/node-change'
|
||||
import { resolveGeometryPaths, resolveVectorNetwork } from './vector-geometry'
|
||||
export { resolveGeometryPaths } from './vector-geometry'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
convertFontFeatures,
|
||||
convertFontVariations,
|
||||
convertFills,
|
||||
convertLetterSpacing,
|
||||
convertLineHeight,
|
||||
mapTextDecoration
|
||||
|
|
@ -10,8 +11,6 @@ import type { CharacterStyleOverride, StyleRun } from '@open-pencil/scene-graph'
|
|||
|
||||
import { styleToWeight } from '#core/text/fonts'
|
||||
|
||||
import { convertFills } from './paint'
|
||||
|
||||
function applyTextDecorationOverride(style: CharacterStyleOverride, override: NodeChange): void {
|
||||
const deco = override.textDecoration
|
||||
if (deco) style.textDecoration = mapTextDecoration(deco)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
export * from './derived-text-glyphs'
|
||||
export * from './font/features'
|
||||
export * from './font/variations'
|
||||
export * from './paint'
|
||||
export * from './plugin-data'
|
||||
export * from './style-refs'
|
||||
export * from './text-values'
|
||||
|
|
|
|||
|
|
@ -11,11 +11,13 @@ import type {
|
|||
StrokeCap,
|
||||
StrokeJoin
|
||||
} from '@open-pencil/scene-graph'
|
||||
import { BLACK } from '@open-pencil/scene-graph/constants'
|
||||
import type { Color, Matrix } from '@open-pencil/scene-graph/primitives'
|
||||
|
||||
import { normalizeColor } from '#core/color'
|
||||
|
||||
const convertColor = normalizeColor
|
||||
function convertColor(color?: Partial<Color>): Color {
|
||||
if (!color) return { ...BLACK }
|
||||
return { r: color.r ?? 0, g: color.g ?? 0, b: color.b ?? 0, a: color.a ?? 1 }
|
||||
}
|
||||
|
||||
function imageHashToString(hash: Record<string, number>): string {
|
||||
const bytes = Object.keys(hash)
|
||||
|
|
@ -2,6 +2,8 @@ import { describe, expect, test } from 'bun:test'
|
|||
|
||||
import {
|
||||
applyStyleRefsToFields,
|
||||
convertEffects,
|
||||
convertFills,
|
||||
convertFontFeatures,
|
||||
convertLetterSpacing,
|
||||
convertLineHeight,
|
||||
|
|
@ -27,6 +29,19 @@ describe('@open-pencil/fig NodeChange policy', () => {
|
|||
])
|
||||
})
|
||||
|
||||
test('normalizes imported paints and effects', () => {
|
||||
expect(convertFills([{ type: 'SOLID' }])[0]).toMatchObject({
|
||||
color: { r: 0, g: 0, b: 0, a: 1 },
|
||||
opacity: 1,
|
||||
visible: true
|
||||
})
|
||||
expect(convertEffects([{ type: 'DROP_SHADOW' }])[0]).toMatchObject({
|
||||
type: 'DROP_SHADOW',
|
||||
radius: 0,
|
||||
visible: true
|
||||
})
|
||||
})
|
||||
|
||||
test('resolves imported style references before SceneGraph conversion', () => {
|
||||
const fields: Record<string, unknown> = {
|
||||
styleIdForFill: { guid: { sessionID: 2, localID: 3 } }
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ const scenePath = coreSourcePath('canvas/scene.ts')
|
|||
const rendererPath = coreSourcePath('canvas/renderer.ts')
|
||||
const sgTypesPath = repoPath('packages/scene-graph/src/types.ts')
|
||||
const nodeExportPath = coreSourcePath('kiwi/fig/node-change/export-node.ts')
|
||||
const convertPath = coreSourcePath('kiwi/fig/node-change/paint.ts')
|
||||
const convertPath = repoPath('packages/fig/src/node-change/paint.ts')
|
||||
const schemaPath = repoPath('packages/kiwi/src/fig/schema/fig.kiwi')
|
||||
const codecPath = repoPath('packages/kiwi/src/fig/codec.ts')
|
||||
const lifecyclePath = coreSourcePath('canvas/renderer/lifecycle.ts')
|
||||
|
|
|
|||
Loading…
Reference in a new issue