sketchmark 2.1.3 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/edit.js +39 -0
- package/package.json +1 -1
package/dist/src/edit.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.listTimelineTracks = listTimelineTracks;
|
|
|
9
9
|
exports.roundedRectClipPath = roundedRectClipPath;
|
|
10
10
|
exports.imageRoundedClip = imageRoundedClip;
|
|
11
11
|
const animatable_1 = require("./animatable");
|
|
12
|
+
const keyframes_1 = require("./keyframes");
|
|
12
13
|
const utils_1 = require("./utils");
|
|
13
14
|
const validate_1 = require("./validate");
|
|
14
15
|
function listElementReferences(document) {
|
|
@@ -29,6 +30,7 @@ function findElementById(document, id) {
|
|
|
29
30
|
}
|
|
30
31
|
function setElementProperty(document, id, property, value) {
|
|
31
32
|
const next = (0, utils_1.clone)(document);
|
|
33
|
+
repairLegacyTimelineCurves(next);
|
|
32
34
|
const element = requireElement(next, id);
|
|
33
35
|
applyProperty(element, property, value);
|
|
34
36
|
assertValid(next);
|
|
@@ -39,6 +41,7 @@ function setTimelineKeyframe(document, id, property, time, value, options = {})
|
|
|
39
41
|
if (!(0, utils_1.isFiniteNumber)(time) || time < 0)
|
|
40
42
|
throw new Error("Keyframe time must be a non-negative finite number.");
|
|
41
43
|
const next = (0, utils_1.clone)(document);
|
|
44
|
+
repairLegacyTimelineCurves(next);
|
|
42
45
|
const element = requireElement(next, id);
|
|
43
46
|
element.timeline ?? (element.timeline = {});
|
|
44
47
|
(_a = element.timeline).tracks ?? (_a.tracks = {});
|
|
@@ -157,6 +160,42 @@ function assertValid(document) {
|
|
|
157
160
|
throw new Error(first ? `${first.path}: ${first.message}` : "Invalid visual document.");
|
|
158
161
|
}
|
|
159
162
|
}
|
|
163
|
+
function repairLegacyTimelineCurves(document) {
|
|
164
|
+
visitElements(document.elements ?? [], (element) => {
|
|
165
|
+
for (const track of Object.values(element.timeline?.tracks ?? {})) {
|
|
166
|
+
repairTrackCurve(track);
|
|
167
|
+
for (const frame of track.keyframes ?? [])
|
|
168
|
+
repairKeyframeCurve(frame);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function repairTrackCurve(track) {
|
|
173
|
+
const record = track;
|
|
174
|
+
if (typeof record.curve === "string") {
|
|
175
|
+
const curve = legacyCurve(record.curve);
|
|
176
|
+
if (curve)
|
|
177
|
+
record.curve = curve;
|
|
178
|
+
else
|
|
179
|
+
delete record.curve;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function repairKeyframeCurve(frame) {
|
|
183
|
+
if (Array.isArray(frame))
|
|
184
|
+
return;
|
|
185
|
+
const record = frame;
|
|
186
|
+
for (const key of ["in", "out", "interpolation"]) {
|
|
187
|
+
if (typeof record[key] !== "string")
|
|
188
|
+
continue;
|
|
189
|
+
const curve = legacyCurve(record[key]);
|
|
190
|
+
if (curve)
|
|
191
|
+
record[key] = curve;
|
|
192
|
+
else
|
|
193
|
+
delete record[key];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function legacyCurve(value) {
|
|
197
|
+
return (0, keyframes_1.timelineCurvePreset)(value);
|
|
198
|
+
}
|
|
160
199
|
function finiteOrZero(value) {
|
|
161
200
|
return (0, utils_1.isFiniteNumber)(value) ? value : 0;
|
|
162
201
|
}
|