8000 Merge pull request #2 from maxm123/master · devforth/scriptimate@c4aabb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit c4aabb3

Browse files
authored
Merge pull request #2 from maxm123/master
Add dashoffset animation
2 parents 0d4de0f + 91cbb95 commit c4aabb3

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

bin/scriptimate.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ const ACTION_HANDLERS = {
155155
}
156156
parts[svg].opacity = animationHandlersByMode[mode](i, freezer[svg].opacity, dstOpacity - freezer[svg].opacity, frames);
157157
},
158+
dashoffset: (i, ags_arr, first_frame_in_animate, frames, mode) => {
159+
const svg = ags_arr[0];
160+
if (!parts[svg]) {
161+
log(`WARN: dashoffset not applied, part not found: ${svg}, line: \n${cmd}\n`);
162+
return;
163+
}
164+
const dstOffset = +eval(ags_arr[1]);
165+
if (first_frame_in_animate) {
166+
freezer[svg] = {...freezer[svg], dashoffset: parts[svg].dashoffset};
167+
}
168+
parts[svg].dashoffset = animationHandlersByMode[mode](i, freezer[svg].dashoffset, dstOffset - freezer[svg].dashoffset, frames);
169+
},
158170
resize_div: (i, ags_arr, first_frame_in_animate, frames, mode) => {
159171
const svg = ags_arr[0];
160172
if (!parts[svg]) {
@@ -186,7 +198,7 @@ const genHtml = (allParts) => {
186198
if (p.type === 'part') {
187199
const bh = boxholes[p.toBoxHole] || {left: 0, top:0};
188200

189-
const partHTML = `<div style="position:${bh.name ? "absolute": "fixed"};top:${p.top-bh.top}px;left:${p.left-bh.left}px;opacity:${p.opacity};transform:scale(${p.scale}) rotate(${p.rotate}deg);${p.extrastyle}">${p.content}</div>`;
201+
const partHTML = `<div style="position:${bh.name ? "absolute": "fixed"};top:${p.top-bh.top}px;left:${p.left-bh.left}px;opacity:${p.opacity};transform:scale(${p.scale}) rotate(${p.rotate}deg);stroke-dashoffset:${p.dashoffset};${p.extrastyle}">${p.content}</div>`;
190202
if (p.toBoxHole) {
191203
return `${acc}<div style="position:fixed;overflow:hidden;top:${bh.top}px;left:${bh.left}px;width:${bh.w}px;height:${bh.h}px;">
192204
${partHTML}</div>`;
@@ -230,7 +242,7 @@ function firstDefined(...vals) {
230242
}
231243

232244

233-
const addPart = async (lang, filename, left, top, opacity, scale, toBoxHole) => {
245+
const addPart = async (lang, filename, left, top, opacity, scale, toBoxHole, dashoffset) => {
234246
let f;
235247

236248
const readFname = (fn) => {
@@ -289,6 +301,7 @@ const addPart = async (lang, filename, left, top, opacity, scale, toBoxHole) =>
289301
index: Object.values(parts).length,
290302
scale: +firstDefined(eval(scale), 1.0),
291303
rotate: +firstDefined(0, 0),
304+
dashoffset: +firstDefined(eval(dashoffset), 0),
292305
extrastyle: '',
293306
toBoxHole,
294307
};
@@ -308,6 +321,7 @@ const addDiv = (name, left, top, w, h, opacity, c, toBoxHole) => {
308321
h: +firstDefined(eval(h), 0),
309322
index: Object.values(parts).length,
310323
rotate: +firstDefined(0, 0),
324+
dashoffset: +firstDefined(0, 0),
311325
content: content,
312326
toBoxHole,
313327
}

0 commit comments

Comments
 (0)
0