Skip to content

Commit

Permalink
Output for glyphs and sprites (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
aparlato authored Apr 19, 2023
1 parent ee3dbc9 commit 530bb8d
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 32 deletions.
76 changes: 62 additions & 14 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

76 changes: 62 additions & 14 deletions dist/module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/module.js.map

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions src/lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ const isEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);

class diffTracker {
constructor() {
this.glyphs = null;
this.sprite = null;
this.sources = [];
this.layers = [];
this.layerProps = {};
}

changeGlyphs(change) {
this.glyphs = { change: change };
}

changeSprite(change) {
this.sprite = { change: change };
}

changeSource(source, change) {
this.sources.push({ source: source, change: change });
}
Expand Down Expand Up @@ -505,9 +515,17 @@ export function diffStylesSetStyle(before, after) {
}
if (!isEqual(before.sprite, after.sprite)) {
commands.push({ command: operations.setSprite, args: [after.sprite] });
differ.changeSprite({
command: 'setSprite',
args: [after.sprite, before.sprite]
});
}
if (!isEqual(before.glyphs, after.glyphs)) {
commands.push({ command: operations.setGlyphs, args: [after.glyphs] });
differ.changeGlyphs({
command: 'setGlyphs',
args: [after.glyphs, before.glyphs]
});
}
if (!isEqual(before.transition, after.transition)) {
commands.push({
Expand Down Expand Up @@ -554,6 +572,7 @@ export function diffStylesSetStyle(before, after) {
}

commands = detectMovedLayers(commands);

return differ;
}

Expand Down Expand Up @@ -587,7 +606,7 @@ function detectMovedLayers(commands) {
const diffStyles = (before, after) => {
const originalDiff = diffStylesSetStyle(before, after);

const { layerProps, layers, sources } = originalDiff;
const { layerProps, layers, sources, glyphs, sprite } = originalDiff;

// formatting for source additions and removals
const nextSources = sources.reduce((acc, s) => {
Expand Down Expand Up @@ -711,10 +730,24 @@ const diffStyles = (before, after) => {
return acc;
}, {});

let nextGlyphs;
if (glyphs?.change?.args) {
const [compareGlyph, currentGlyph] = glyphs?.change?.args;
nextGlyphs = { current: currentGlyph, compare: compareGlyph };
}

let nextSprite;
if (sprite?.change?.args) {
const [compareSprite, currentSprite] = sprite?.change?.args;
nextSprite = { current: currentSprite, compare: compareSprite };
}

return {
layerProps: nextLayerProps,
layers: nextLayers,
sources: nextSources
sources: nextSources,
glyphs: nextGlyphs,
sprite: nextSprite
};
};

Expand Down

0 comments on commit 530bb8d

Please sign in to comment.