<commit_before>include('../background.js');
include('../image.js');

uki.background.Sliced9 = uki.newClass(new function() {
    var nativeCss = ['MozBorderImage', 'WebkitBorderImage', 'borderImage'],
        dom = uki.dom,
        geometry = uki.geometry;
        
    var LEFT = 'left:',
        TOP  = 'top:',
        RIGHT = 'right:',
        BOTTOM = 'bottom:',
        WIDTH = 'width:',
        HEIGHT = 'height:',
        PX = 'px',
        P100 = '100%';
        
    var cache = {};
    
    this.init = function(partSettings, inset, options) {
        this._settings  = uki.extend({}, partSettings);
        this._inset     = geometry.Inset.create(inset);
        this._size      = null;
        this._inited    = false;
        
        options = options || {};
        this._fixedSize = geometry.Size.create(options.fixedSize) || new geometry.Size();
        this._bgInset   = geometry.Inset.create(options.inset)    || new geometry.Inset();
        this._zIndex    = options.zIndex || -1;

        this._container = this._getContainer();
    };
    
    function makeDiv (name, style, inner) {
        return '<div class="' +  name + '" style="position:absolute;overflow:hidden;' + style + '">' + inner + '</div>';
    }
    
    function img (setting, style) {
        return uki.imageHTML(setting[0], setting[1], setting[2], ' style="position:absolute;' + style + '"');
    }
    
    function re (s) {
        return s.replace("sizingMethod='scale'", "sizingMethod='crop'");
    }
    
    this._getContainer = function() {
        var key = this._getKey();
        if (!cache[key]) {
            return cache[key] = this._createContainer();
        }
        return cache[key].cloneNode(true);
    };
    
    this._createContainer = function() {
        var inset = this._inset,
            bgInset = this._bgInset,
            settings = this._settings,
            width = inset.left + inset.right,
            height = inset.top + inset.bottom,
            css = [LEFT + bgInset.left + PX, RIGHT + bgInset.right + PX, TOP + bgInset.top + PX, BOTTOM + bgInset.bottom + PX].join(';'),
            html = [];
            
        if (inset.top && inset.left) {
            html[html.length] = makeDiv('tl',
                [LEFT + 0, TOP + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [LEFT + 0, TOP + 0, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        if (inset.top) {
            html[html.length] = makeDiv('t',
                [LEFT + inset.left + PX, TOP + 0, HEIGHT + inset.top + PX, RIGHT + inset.right + PX].join(';'),
                img(settings.h, [LEFT + 0, TOP + 0, WIDTH + P100, HEIGHT + height + PX].join(';'))
            );
        }
        if (inset.top && inset.right) {
            html[html.length] = makeDiv('tr',
                [RIGHT + 0, TOP + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [RIGHT + 0, TOP + 0, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        
        if (inset.left) {
            html[html.length] = makeDiv('l',
                [LEFT + 0, TOP + inset.top + PX, WIDTH + inset.left + PX, BOTTOM + inset.bottom + PX].join(';'),
                img(settings.v, [LEFT + 0, TOP + 0, HEIGHT + P100, WIDTH + width + PX].join(';'))
            );
        }
        if (settings.m) {
            html[html.length] = makeDiv('m',
                [LEFT + inset.left + PX, TOP + inset.top + PX, RIGHT + inset.left + PX, BOTTOM + inset.bottom + PX].join(';'),
                img(settings.m, [LEFT + 0, TOP + 0, HEIGHT + P100, WIDTH + P100].join(';'))
            );
        }
        if (inset.right) {
            html[html.length] = makeDiv('r',
                [RIGHT + 0, TOP + inset.top + PX, WIDTH + inset.right + PX, BOTTOM + inset.bottom + PX].join(';'),
                img(settings.v, [RIGHT + 0, TOP + 0, HEIGHT + P100, WIDTH + width + PX].join(';'))
            );
        }
        
        if (inset.bottom && inset.left) {
            html[html.length] = makeDiv('bl',
                [LEFT + 0, BOTTOM + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [LEFT + 0, TOP + '-' + inset.bottom + PX, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        if (inset.bottom) {
            html[html.length] = makeDiv('b',
                [LEFT + inset.left + PX, BOTTOM + 0, HEIGHT + inset.bottom + PX, RIGHT + inset.right + PX].join(';'),
                img(settings.h, [LEFT + 0, TOP + '-' + inset.bottom + PX, WIDTH + P100, HEIGHT + height + PX].join(';'))
            );
        }
        if (inset.bottom && inset.right) {
            html[html.length] = makeDiv('br',
                [RIGHT + 0, BOTTOM + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [RIGHT + 0, TOP + '-' + inset.bottom + PX, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        return uki.createElement('div', 'position:absolute;overflow:hidden;' + css, html.join(''));
    };
    
    this._getKey = function() {
        return uki.map(['v', 'h', 'm', 'c'], function(x) {
            return this._settings[x] && this._settings[x][0] || '';
        }, this).concat([this._inset, this._bgInset, this._fixedSize]).join(',');
    }
    
    this.attachTo = function(comp) {
        this._comp = comp;
        
        this._comp.dom().appendChild(this._container);
        
        if (!uki.supportNativeLayout) {
            var _this = this;
            this._layoutHandler = function(e) {
                if (_this._size && _this._size.eq(e.rect)) return;
                _this._size = e.rect;
                _this.layout();
            };
            this._comp.bind('layout', this._layoutHandler);
            this.layout();
        }<commit_msg>more bg fixes<commit_after>include('../background.js');
include('../image.js');

uki.background.Sliced9 = uki.newClass(new function() {
    var nativeCss = ['MozBorderImage', 'WebkitBorderImage', 'borderImage'],
        dom = uki.dom,
        geometry = uki.geometry;
        
    var LEFT = 'left:',
        TOP  = 'top:',
        RIGHT = 'right:',
        BOTTOM = 'bottom:',
        WIDTH = 'width:',
        HEIGHT = 'height:',
        PX = 'px',
        P100 = '100%';
        
    var cache = {};
    
    this.init = function(partSettings, inset, options) {
        this._settings  = uki.extend({}, partSettings);
        this._inset     = geometry.Inset.create(inset);
        this._size      = null;
        this._inited    = false;
        
        options = options || {};
        this._fixedSize = geometry.Size.create(options.fixedSize) || new geometry.Size();
        this._bgInset   = geometry.Inset.create(options.inset)    || new geometry.Inset();
        this._zIndex    = options.zIndex || -1;

        this._container = this._getContainer();
    };
    
    function makeDiv (name, style, inner) {
        return '<div class="' +  name + '" style="position:absolute;overflow:hidden;' + style + '">' + inner + '</div>';
    }
    
    function img (setting, style) {
        return uki.imageHTML(setting[0], setting[1], setting[2], ' style="position:absolute;' + style + '"');
    }
    
    function re (s) {
        return s.replace("sizingMethod='scale'", "sizingMethod='crop'");
    }
    
    this._getContainer = function() {
        var key = this._getKey();
        if (!cache[key]) {
            return cache[key] = this._createContainer();
        }
        return cache[key].cloneNode(true);
    };
    
    this._createContainer = function() {
        var inset = this._inset,
            bgInset = this._bgInset,
            settings = this._settings,
            width = inset.left + inset.right,
            height = inset.top + inset.bottom,
            css = [LEFT + bgInset.left + PX, RIGHT + bgInset.right + PX, TOP + bgInset.top + PX, BOTTOM + bgInset.bottom + PX].join(';'),
            html = [];
            
        if (inset.top && inset.left) {
            html[html.length] = makeDiv('tl',
                [LEFT + 0, TOP + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [LEFT + 0, TOP + 0, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        if (inset.top) {
            html[html.length] = makeDiv('t',
                [LEFT + inset.left + PX, TOP + 0, HEIGHT + inset.top + PX, RIGHT + inset.right + PX].join(';'),
                img(settings.h, [LEFT + 0, TOP + 0, WIDTH + P100, HEIGHT + height + PX].join(';'))
            );
        }
        if (inset.top && inset.right) {
            html[html.length] = makeDiv('tr',
                [RIGHT + 0, TOP + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [LEFT + '-' + inset.right + PX, TOP + 0, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        
        if (inset.left) {
            html[html.length] = makeDiv('l',
                [LEFT + 0, TOP + inset.top + PX, WIDTH + inset.left + PX, BOTTOM + inset.bottom + PX].join(';'),
                img(settings.v, [LEFT + 0, TOP + 0, HEIGHT + P100, WIDTH + width + PX].join(';'))
            );
        }
        if (settings.m) {
            html[html.length] = makeDiv('m',
                [LEFT + inset.left + PX, TOP + inset.top + PX, RIGHT + inset.left + PX, BOTTOM + inset.bottom + PX].join(';'),
                img(settings.m, [LEFT + 0, TOP + 0, HEIGHT + P100, WIDTH + P100].join(';'))
            );
        }
        if (inset.right) {
            html[html.length] = makeDiv('r',
                [RIGHT + 0, TOP + inset.top + PX, WIDTH + inset.right + PX, BOTTOM + inset.bottom + PX].join(';'),
                img(settings.v, [LEFT + '-' + inset.right + PX, TOP + 0, HEIGHT + P100, WIDTH + width + PX].join(';'))
            );
        }
        
        if (inset.bottom && inset.left) {
            html[html.length] = makeDiv('bl',
                [LEFT + 0, BOTTOM + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [LEFT + 0, TOP + '-' + inset.bottom + PX, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        if (inset.bottom) {
            html[html.length] = makeDiv('b',
                [LEFT + inset.left + PX, BOTTOM + 0, HEIGHT + inset.bottom + PX, RIGHT + inset.right + PX].join(';'),
                img(settings.h, [LEFT + 0, TOP + '-' + inset.bottom + PX, WIDTH + P100, HEIGHT + height + PX].join(';'))
            );
        }
        if (inset.bottom && inset.right) {
            html[html.length] = makeDiv('br',
                [RIGHT + 0, BOTTOM + 0, WIDTH + inset.left + PX, HEIGHT + inset.top + PX].join(';'),
                re(img(settings.c, [LEFT + '-' + inset.right + PX, TOP + '-' + inset.bottom + PX, WIDTH + width + PX, HEIGHT + height + PX].join(';')))
            );
        }
        return uki.createElement('div', 'position:absolute;overflow:hidden;' + css, html.join(''));
    };
    
    this._getKey = function() {
        return uki.map(['v', 'h', 'm', 'c'], function(x) {
            return this._settings[x] && this._settings[x][0] || '';
        }, this).concat([this._inset, this._bgInset, this._fixedSize]).join(',');
    }
    
    this.attachTo = function(comp) {
        this._comp = comp;
        
        this._comp.dom().appendChild(this._container);
        
        if (!uki.supportNativeLayout) {
            var _this = this;
            this._layoutHandler = function(e) {
                if (_this._size && _this._size.eq(e.rect)) return;
                _this._size = e.rect;
                _this.layout();
            };
            this._comp.bind('layout', this._layoutHandler);
            this.layout();
        }
{'fraction_non_alphanumeric': 0.17392761394101877, 'fraction_numerical': 0.009299597855227881, 'mean_word_length': 1.76, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7222118', 'n_tokens_mistral': 4122, 'n_tokens_neox': 3813, 'n_words': 813}