-
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.
Improve speed at recolect fonts and improve treating modifications (#175
- Loading branch information
1 parent
beb3caa
commit 33d2502
Showing
5 changed files
with
71 additions
and
14 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": patch | ||
--- | ||
|
||
Improve detection of changed fonts |
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,33 @@ | ||
export const registerChange = () => { | ||
import { findMissingFonts } from './findAllTextnodes'; | ||
|
||
export const registerChange = (event: NodeChangeEvent) => { | ||
if (!changesAreRelevant(event.nodeChanges)) return; | ||
|
||
figma.ui.postMessage({ type: 'CHANGES_DETECTED' }); | ||
}; | ||
|
||
const changesAreRelevant = (changes: NodeChange[]): boolean => { | ||
for (const change of changes) { | ||
if (changeIsRelevant(change)) return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
const changeIsRelevant = (change: NodeChange): boolean => { | ||
const node = change.node; | ||
|
||
if (!isTextNode(node) || change.type === 'DELETE') return false; | ||
|
||
return ( | ||
(change.type === 'CREATE' || | ||
(change.type === 'PROPERTY_CHANGE' && | ||
change.properties.some( | ||
property => property === 'fontName' || property === 'styledTextSegments' | ||
))) && | ||
findMissingFonts(node).length > 0 | ||
); | ||
}; | ||
|
||
const isTextNode = (node: SceneNode | RemovedNode): node is TextNode => | ||
node.type === 'TEXT' && 'name' in node; |
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