use helper for setting styles

pull/810/head
Rich Harris 7 years ago
parent d54d00cac1
commit 186b770ef4

@ -60,7 +60,7 @@ export default function visitStyleAttribute(
block.builders.update.addConditional(
condition,
`${node.var}.style.setProperty('${prop.key}', ${value});`
`@setStyle(${node.var}, '${prop.key}', ${value});`
);
}
} else {
@ -68,7 +68,7 @@ export default function visitStyleAttribute(
}
block.builders.hydrate.addLine(
`${node.var}.style.setProperty('${prop.key}', ${value});`
`@setStyle(${node.var}, '${prop.key}', ${value});`
);
});
}

@ -137,4 +137,8 @@ export function setInputType(input, type) {
try {
input.type = type;
} catch (e) {}
}
export function setStyle(node, key, value) {
node.style.setProperty(key, value);
}

@ -25,6 +25,10 @@ function createElement(name) {
return document.createElement(name);
}
function setStyle(node, key, value) {
node.style.setProperty(key, value);
}
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
@ -163,8 +167,8 @@ function create_main_fragment ( state, component ) {
},
hydrate: function ( nodes ) {
div.style.setProperty('color', state.color);
div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)");
setStyle(div, 'color', state.color);
setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)");
},
mount: function ( target, anchor ) {
@ -173,11 +177,11 @@ function create_main_fragment ( state, component ) {
update: function ( changed, state ) {
if ( changed.color ) {
div.style.setProperty('color', state.color);
setStyle(div, 'color', state.color);
}
if ( changed.x || changed.y ) {
div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)");
setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)");
}
},

@ -1,4 +1,4 @@
import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js";
import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js";
function create_main_fragment ( state, component ) {
var div;
@ -10,8 +10,8 @@ function create_main_fragment ( state, component ) {
},
hydrate: function ( nodes ) {
div.style.setProperty('color', state.color);
div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)");
setStyle(div, 'color', state.color);
setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)");
},
mount: function ( target, anchor ) {
@ -20,11 +20,11 @@ function create_main_fragment ( state, component ) {
update: function ( changed, state ) {
if ( changed.color ) {
div.style.setProperty('color', state.color);
setStyle(div, 'color', state.color);
}
if ( changed.x || changed.y ) {
div.style.setProperty('transform', "translate(" + state.x + "px," + state.y + "px)");
setStyle(div, 'transform', "translate(" + state.x + "px," + state.y + "px)");
}
},

@ -25,6 +25,10 @@ function createElement(name) {
return document.createElement(name);
}
function setStyle(node, key, value) {
node.style.setProperty(key, value);
}
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
@ -163,7 +167,7 @@ function create_main_fragment ( state, component ) {
},
hydrate: function ( nodes ) {
div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")");
setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")");
},
mount: function ( target, anchor ) {
@ -172,7 +176,7 @@ function create_main_fragment ( state, component ) {
update: function ( changed, state ) {
if ( changed.data ) {
div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")");
setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")");
}
},

@ -1,4 +1,4 @@
import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js";
import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js";
function create_main_fragment ( state, component ) {
var div;
@ -10,7 +10,7 @@ function create_main_fragment ( state, component ) {
},
hydrate: function ( nodes ) {
div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")");
setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")");
},
mount: function ( target, anchor ) {
@ -19,7 +19,7 @@ function create_main_fragment ( state, component ) {
update: function ( changed, state ) {
if ( changed.data ) {
div.style.setProperty('background', "url(data:image/png;base64," + state.data + ")");
setStyle(div, 'background', "url(data:image/png;base64," + state.data + ")");
}
},

@ -25,6 +25,10 @@ function createElement(name) {
return document.createElement(name);
}
function setStyle(node, key, value) {
node.style.setProperty(key, value);
}
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
@ -163,7 +167,7 @@ function create_main_fragment ( state, component ) {
},
hydrate: function ( nodes ) {
div.style.setProperty('color', state.color);
setStyle(div, 'color', state.color);
},
mount: function ( target, anchor ) {
@ -172,7 +176,7 @@ function create_main_fragment ( state, component ) {
update: function ( changed, state ) {
if ( changed.color ) {
div.style.setProperty('color', state.color);
setStyle(div, 'color', state.color);
}
},

@ -1,4 +1,4 @@
import { assign, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js";
import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js";
function create_main_fragment ( state, component ) {
var div;
@ -10,7 +10,7 @@ function create_main_fragment ( state, component ) {
},
hydrate: function ( nodes ) {
div.style.setProperty('color', state.color);
setStyle(div, 'color', state.color);
},
mount: function ( target, anchor ) {
@ -19,7 +19,7 @@ function create_main_fragment ( state, component ) {
update: function ( changed, state ) {
if ( changed.color ) {
div.style.setProperty('color', state.color);
setStyle(div, 'color', state.color);
}
},

Loading…
Cancel
Save