/*
{
style: create|replace|append
}
348014
function exists(name, db) {
  return db(db.raw('information_schema.tables')).count('table_name').where('table_name', name).then(function (resp) {
    if (resp.length !== 1) {
      throw new Error('invalid response');
    }
    if (typeof resp[0].count !== 'number') {
      throw new Error('invalid response');
    }
    return resp[0].count;
  });
}
960325
function append(element, content) {
  if (isElement(content)) {
    element.appendChild(content);
  } else {
    const div = document.createElement('div');
    div.innerHTML = content || '';

    while (div.firstChild) {
      element.appendChild(div.firstChild);
    }
  }
}
354298
function (key, regexp, replacement, editor) {
            key = key.toLowerCase();

            return getPreviousKeyForEditing(key, editor)
            .then(bindr(Result.andThen, editOnlyWhenPreviousKeyExists))
            .then(bindr(Result.andThen, function (description) {
                const old_message = description.message;
                const new_message = old_message
                    .replace(regexp, replacement)
                    .replace(/\s+/, " ");

                if (old_message === new_message) {
                    return Fail("unchanged");
                }

                if (new_message.length > maxMessageLength) {
                    return Fail("message-length-exceeded");
                }

                if (new_message === "") {
                    return Fail("no-message-left");
                }

                description.message = new_message;
                description.editor = editor;
                description.time = now();

                return Ok(description);
            }))
            .then(bindr(Result.andThen, beforeUpdate))
            .then(bindr(Result.map, function (value) {
                db.set(key, value);
                return value;
            }));
        }
1197384
function append(source) {
            if (s === '') return;
            var index = 0,
                expr = /\n/g,
                s,
                match;
            while (match = expr.exec(source)) {
                s = source.substring(index, match.index+1);
                if (s !== '') out.push('  write(\''+escapestr(s)+'\');\n');
                index = match.index+1;
            }
            s = source.substring(index, source.length);
            if (s !== '') out.push('  write(\''+escapestr(s)+'\');\n');
        }
454635
function createStyleProperty(el) {
	var style = el.style;
	var output = {};
	for (var i = 0; i < style.length; ++i) {
		var item = style.item(i);
		output[item] = String(style[item]);
		// hack to workaround browser inconsistency with url()
		if (output[item].indexOf('url') > -1) {
			output[item] = output[item].replace(/\"/g, '')
		}
	}
	return { name: 'style', value: output };
}
964516
function createStylefromCode(styles, abspath) {
    //may import other file
    const arr = queryImport(styles)
    const baseRes = handleImportStyle(styles, abspath)
    const obj = {}
    const ast = csstree.parse(baseRes);
    csstree.walk(ast, {
        enter: function (node) {
            if (node.type === 'Rule' && node.prelude && node.prelude.type === 'SelectorList') {
                const clzName = []
                node.prelude.children.forEach(e => {
                    //we may handle each class selector here
                    let ans = selectorBlockHandler(e)
                    if (ans) {
                        //to save before value
                        obj[ans] = obj[ans] || {}
                        //save ans to log which to give value
                        clzName.push(ans)
                    }
                })
                const styleArray = []
                node.block.children.forEach(e => {
                    //handle with unit or function case
                    const styleItem = styleBlockHandler(e)
                    styleItem.length > 0 && styleArray.push(styleItem)
                })
                clzName.forEach(e => {
                    try {
                        const styleObject = transform(styleArray)
                        if (styleObject.fontWeight) {
                            //fontWeight must be string
                            styleObject.fontWeight = styleObject.fontWeight + ""
                        }
                        Object.assign(obj[e], styleObject)
                    } catch (e) {
                        console.error("convert ", abspath, " error:", e.message)
                    }

                })
            }
        },
    })
    return {styles: obj, imports: arr}
}
922248
function(objName, createObj, templateName, contents, quoteChar, indentString, useStrict, htmlmin) {

  var content = getContent(contents, quoteChar, indentString, htmlmin);
  var doubleIndent = indentString + indentString;
  var strict = (useStrict) ? indentString + quoteChar + 'use strict' + quoteChar + ';\n' : '';
  var result = '';
  if(createObj) {
    result += 'if(typeof ' + objName + ' === \'undefined\') {' +
    	'var ' +  objName + ' = {};' +
    '}\n';
  }

  result += objName + '[\'' + templateName + '\'] = ' +
  quoteChar +  content + quoteChar + '; ';

  return result;
}
899248
function injectStyles() {
  if (_stylesInjected) return;
  _stylesInjected = true;

  let node = doc.createElement('style');
  node.innerHTML = css;
  node.type = 'text/css';

  if (doc.head.childNodes.length > 0) {
    doc.head.insertBefore(node, doc.head.childNodes[0]);
  } else {
    doc.head.appendChild(node);
  }
}
229881
function(id) {
    // if the style doesn't exist return null
    var style = this.model.styles[id];
    if (!style) return null;

    // have we built this model before?
    var model = this.index.model[id];
    if (model) return model;

    // build a new model
    model = this.index.model[id] = {};

    // -------------------------------------------------------
    // number format
    if (style.numFmtId) {
      var numFmt = this.index.numFmt[style.numFmtId] || NumFmtXform.getDefaultFmtCode(style.numFmtId);
      if (numFmt) {
        model.numFmt = numFmt;
      }
    }

    function addStyle(name, group, styleId) {
      if (styleId) {
        var part = group[styleId];
        if (part) {
          model[name] = part;
        }
      }
    }

    addStyle('font', this.model.fonts, style.fontId);
    addStyle('border', this.model.borders, style.borderId);
    addStyle('fill', this.model.fills, style.fillId);

    // -------------------------------------------------------
    // alignment
    if (style.alignment) {
      model.alignment = style.alignment;
    }

    return model;
  }
1300267
function ( type, css, obj, dom, id ) {

        type = type || 'div';

        if( Tools.SVG_TYPE_D.indexOf(type) !== -1 || Tools.SVG_TYPE_G.indexOf(type) !== -1 ){ // is svg element

            // create new svg if not def
            if( dom === undefined ) dom = Tools.doc.createElementNS( Tools.svgns, 'svg' );

            Tools.addAttributes( dom, type, obj, id );
            
        } else { // is html element

            if( dom === undefined ) dom = Tools.doc.createElementNS( Tools.htmls, type );
            else dom = dom.appendChild( Tools.doc.createElementNS( Tools.htmls, type ) );

        }

        if( css ) dom.style.cssText = css; 

        if( id === undefined ) return dom;
        else return dom.childNodes[ id || 0 ];

    }
956060
function setStylesheet(s) {
	var id = "AMMLcustomStyleSheet";
	var n = document.getElementById(id);
	if(document.createStyleSheet) {
		// Test for IE's non-standard createStyleSheet method
		if(n)
			n.parentNode.removeChild(n);
		// This failed without the &nbsp;
		document.getElementsByTagName("head")[0].insertAdjacentHTML("beforeEnd","&nbsp;<style id='" + id + "'>" + s + "</style>");
	} else {
		if(n) {
			n.replaceChild(document.createTextNode(s),n.firstChild);
		} else {
			n = document.createElement("style");
			n.type = "text/css";
			n.id = id;
			n.appendChild(document.createTextNode(s));
			document.getElementsByTagName("head")[0].appendChild(n);
		}
	}
}
367251
function genStyleSection(style, styles, options) {
    if (shouldReplaceCurrentSection(style, styles, options)) {
        replaceWithSpacer(style);
    }

    // Remove the 'id', theme' and 'replace' attributes from the output set of
    // attributes since they're not really valid SFC <style> attributes
    _.set(style, 'attrs', _.omit(style.attrs, 'id', 'theme', 'replace'));

    return genSection('style', style);
}
633969
function hstyle(st) {
			// Prepare string
			var s = '';
			for (var key in st) {
				s += '<' + key;
				for (var attr in st[key]) {
					s += ' ';
					if (attr.substr(0, 2) == 'x:') {
						s += attr;
					} else {
						s += 'ss:';
					}
					s += attr + '="' + st[key][attr] + '"';
				}
				s += '/>';
			}

			var hh = hash(s);
			// Store in hash
			if (styles[hh]) {
			} else {
				styles[hh] = {styleid: stylesn};
				s2 += '<Style ss:ID="s' + stylesn + '">';
				s2 += s;
				s2 += '</Style>';
				stylesn++;
			}
			return 's' + styles[hh].styleid;
		}
382827
function inject() {
        if (!WIN || !needsInject) { return }
        needsInject = false;
        var style = Object.keys(byName)
          .map(function (k) { return byName[k]; })
          .concat(remainder).join('\n');
        /* istanbul ignore next */
        if (cssTextProp) { cssTextProp.cssText = style; }
        else { styleNode.innerHTML = style; }
      }
1374705
function insert(sheet, [selectors, styles]) {
  if (sheet.scopedStyleId) {
    selectors = scopifySelectors(selectors, sheet.scopedStyleId);
  }

  var idx = sheet.insertRule(`${selectors} { }`, sheet.rules.length);
  var rule = sheet.rules[idx];

  if (typeof styles === 'string') { rule.style = styles; }
  else {
    // @TODO Fix this to be upward-friendly, and valueize style object.
    assign(rule.style, styles);
    //mirrorProperties(rule.style, styles);
  }

  return rule;
}
428055
function populateThemes(){
		this.preferences.getTheme(function(themeStyles) {
			var selectElement = document.getElementById('editorTheme');//$NON-NLS-0$
			while (selectElement.hasChildNodes() ){
				selectElement.removeChild(selectElement.lastChild);
			}
			for (var i =0; i < themeStyles.styles.length; i++) {
				var option = document.createElement('option');
				option.setAttribute('value', themeStyles.styles[i].name);
				//checks if a theme is the current theme 
				if (themeStyles.styles[i].name === themeStyles.style.name){
					option.setAttribute('selected', 'true');
				}
				option.appendChild(document.createTextNode(themeStyles.styles[i].name));
				selectElement.appendChild(option);
			}
			this.selectTheme(themeStyles.style.name);
		}.bind(this));
	}
590624
function(element)
    {
        // Loop through all saved transform functions to generate the style text
        var funcs = Object.keys(element.transform);
        var style = [];

        funcs.forEach(function(func)
        {
            var args = element.transform[func];

            // If we have an array of arguments, join them with commas
            if(Array.isArray(args))
            {
                args = args.join(', ');
            }
            
            style.push(func + "("+args+") ");
        });

        // Update the element
        element.style['transform'] = style.join(" ");
        element.style['-webkit-transform'] = style.join(" ");
    }