-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * color library * fixes * fixes * fixes * fixes * changeset * fixes * fixes * fixes * fixes
- Loading branch information
Showing
19 changed files
with
248 additions
and
35 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,5 @@ | ||
--- | ||
"penpot-exporter": minor | ||
--- | ||
|
||
Support for color libraries |
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,27 +1,21 @@ | ||
import { Fill } from '@ui/lib/types/utils/fill'; | ||
|
||
class StyleLibrary { | ||
private styles: Map<string, Fill[]> = new Map(); | ||
private styles: Map<string, PaintStyle | undefined> = new Map(); | ||
|
||
public register(id: string, styles: Fill[]) { | ||
public register(id: string, styles?: PaintStyle | undefined) { | ||
this.styles.set(id, styles); | ||
} | ||
|
||
public get(id: string): Fill[] | undefined { | ||
public get(id: string): PaintStyle | undefined { | ||
return this.styles.get(id); | ||
} | ||
|
||
public has(id: string): boolean { | ||
return this.styles.has(id); | ||
} | ||
|
||
public all(): Record<string, Fill[]> { | ||
public all(): Record<string, PaintStyle | undefined> { | ||
return Object.fromEntries(this.styles.entries()); | ||
} | ||
|
||
public init(styles: Record<string, Fill[]>): void { | ||
this.styles = new Map(Object.entries(styles)); | ||
} | ||
} | ||
|
||
export const styleLibrary = new StyleLibrary(); |
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
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,3 +1,4 @@ | ||
export * from './translateFills'; | ||
export * from './translateImageFill'; | ||
export * from './translatePaintStyles'; | ||
export * from './translateSolidFill'; |
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,35 @@ | ||
import { translateFill } from '@plugin/translators/fills/translateFills'; | ||
|
||
import { FillStyle } from '@ui/lib/types/utils/fill'; | ||
|
||
export const translatePaintStyles = (figmaStyle: PaintStyle): FillStyle => { | ||
const fillStyle: FillStyle = { | ||
name: figmaStyle.name, | ||
fills: [], | ||
colors: [] | ||
}; | ||
|
||
const colorName = (figmaStyle: PaintStyle, index: number): string => { | ||
// @TODO: Think something better | ||
return figmaStyle.paints.length > 1 ? `Color ${index + 1}` : figmaStyle.name; | ||
}; | ||
|
||
let index = 0; | ||
const path = | ||
(figmaStyle.remote ? 'Remote / ' : '') + (figmaStyle.paints.length > 1 ? figmaStyle.name : ''); | ||
|
||
for (const fill of figmaStyle.paints) { | ||
const penpotFill = translateFill(fill); | ||
|
||
if (penpotFill) { | ||
fillStyle.fills.unshift(penpotFill); | ||
fillStyle.colors.unshift({ | ||
path, | ||
name: colorName(figmaStyle, index) | ||
}); | ||
} | ||
index++; | ||
} | ||
|
||
return fillStyle; | ||
}; |
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
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
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,41 @@ | ||
import { sleep } from '@plugin/utils/sleep'; | ||
|
||
import { sendMessage } from '@ui/context'; | ||
import { PenpotFile } from '@ui/lib/types/penpotFile'; | ||
import { uiColorLibraries } from '@ui/parser/libraries/UiColorLibraries'; | ||
|
||
export const createColorsLibrary = async (file: PenpotFile) => { | ||
let librariesBuilt = 1; | ||
const libraries = uiColorLibraries.all(); | ||
|
||
sendMessage({ | ||
type: 'PROGRESS_TOTAL_ITEMS', | ||
data: libraries.length | ||
}); | ||
|
||
sendMessage({ | ||
type: 'PROGRESS_STEP', | ||
data: 'libraries' | ||
}); | ||
|
||
for (const library of libraries) { | ||
for (let index = 0; index < library.fills.length; index++) { | ||
file.addLibraryColor({ | ||
...library.colors[index], | ||
id: library.fills[index].fillColorRefId, | ||
refFile: library.fills[index].fillColorRefFile, | ||
color: library.fills[index].fillColor, | ||
opacity: library.fills[index].fillOpacity, | ||
image: library.fills[index].fillImage, | ||
gradient: library.fills[index].fillColorGradient | ||
}); | ||
|
||
sendMessage({ | ||
type: 'PROGRESS_PROCESSED_ITEMS', | ||
data: librariesBuilt++ | ||
}); | ||
|
||
await sleep(0); | ||
} | ||
} | ||
}; |
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
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,19 @@ | ||
import { FillStyle } from '@ui/lib/types/utils/fill'; | ||
|
||
class UiColorLibraries { | ||
private libraries: Map<string, FillStyle> = new Map(); | ||
|
||
public register(id: string, fillStyle: FillStyle) { | ||
this.libraries.set(id, fillStyle); | ||
} | ||
|
||
public get(id: string): FillStyle | undefined { | ||
return this.libraries.get(id); | ||
} | ||
|
||
public all(): FillStyle[] { | ||
return Array.from(this.libraries.values()); | ||
} | ||
} | ||
|
||
export const uiColorLibraries = new UiColorLibraries(); |
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,2 +1,3 @@ | ||
export * from './UiComponents'; | ||
export * from './UiImages'; | ||
export * from './UiColorLibraries'; |
Oops, something went wrong.