source: node_modules/d3-transition/src/transition/style.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 2.7 KB
Line 
1import {interpolateTransformCss as interpolateTransform} from "d3-interpolate";
2import {style} from "d3-selection";
3import {set} from "./schedule.js";
4import {tweenValue} from "./tween.js";
5import interpolate from "./interpolate.js";
6
7function styleNull(name, interpolate) {
8 var string00,
9 string10,
10 interpolate0;
11 return function() {
12 var string0 = style(this, name),
13 string1 = (this.style.removeProperty(name), style(this, name));
14 return string0 === string1 ? null
15 : string0 === string00 && string1 === string10 ? interpolate0
16 : interpolate0 = interpolate(string00 = string0, string10 = string1);
17 };
18}
19
20function styleRemove(name) {
21 return function() {
22 this.style.removeProperty(name);
23 };
24}
25
26function styleConstant(name, interpolate, value1) {
27 var string00,
28 string1 = value1 + "",
29 interpolate0;
30 return function() {
31 var string0 = style(this, name);
32 return string0 === string1 ? null
33 : string0 === string00 ? interpolate0
34 : interpolate0 = interpolate(string00 = string0, value1);
35 };
36}
37
38function styleFunction(name, interpolate, value) {
39 var string00,
40 string10,
41 interpolate0;
42 return function() {
43 var string0 = style(this, name),
44 value1 = value(this),
45 string1 = value1 + "";
46 if (value1 == null) string1 = value1 = (this.style.removeProperty(name), style(this, name));
47 return string0 === string1 ? null
48 : string0 === string00 && string1 === string10 ? interpolate0
49 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
50 };
51}
52
53function styleMaybeRemove(id, name) {
54 var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
55 return function() {
56 var schedule = set(this, id),
57 on = schedule.on,
58 listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
59
60 // If this node shared a dispatch with the previous node,
61 // just assign the updated shared dispatch and we’re done!
62 // Otherwise, copy-on-write.
63 if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
64
65 schedule.on = on1;
66 };
67}
68
69export default function(name, value, priority) {
70 var i = (name += "") === "transform" ? interpolateTransform : interpolate;
71 return value == null ? this
72 .styleTween(name, styleNull(name, i))
73 .on("end.style." + name, styleRemove(name))
74 : typeof value === "function" ? this
75 .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
76 .each(styleMaybeRemove(this._id, name))
77 : this
78 .styleTween(name, styleConstant(name, i, value), priority)
79 .on("end.style." + name, null);
80}
Note: See TracBrowser for help on using the repository browser.