RedactorX.add('plugin', 'fontsize', {
    translations: {
        en: {
            "fontsize": {
                "font-size": "Font Size",
                "reset": "Reset to default"
            }
        }
    },
    defaults: {
        icon: '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 512 512"><path d="M292.6,407.78l-120-320a22,22,0,0,0-41.2,0l-120,320a22,22,0,0,0,41.2,15.44L88.76,326.8a2,2,0,0,1,1.87-1.3H213.37a2,2,0,0,1,1.87,1.3l36.16,96.42a22,22,0,0,0,41.2-15.44Zm-185.84-129,43.37-115.65a2,2,0,0,1,3.74,0L197.24,278.8a2,2,0,0,1-1.87,2.7H108.63A2,2,0,0,1,106.76,278.8Z"/><path d="M400.77,169.5c-41.72-.3-79.08,23.87-95,61.4a22,22,0,0,0,40.5,17.2c8.88-20.89,29.77-34.44,53.32-34.6C431.91,213.28,458,240,458,272.35h0a1.5,1.5,0,0,1-1.45,1.5c-21.92.61-47.92,2.07-71.12,4.8C330.68,285.09,298,314.94,298,358.5c0,23.19,8.76,44,24.67,58.68C337.6,430.93,358,438.5,380,438.5c31,0,57.69-8,77.94-23.22,0,0,.06,0,.06,0h0a22,22,0,1,0,44,.19v-143C502,216.29,457,169.91,400.77,169.5ZM380,394.5c-17.53,0-38-9.43-38-36,0-10.67,3.83-18.14,12.43-24.23,8.37-5.93,21.2-10.16,36.14-11.92,21.12-2.49,44.82-3.86,65.14-4.47a2,2,0,0,1,2,2.1C455,370.1,429.46,394.5,380,394.5Z"/></svg>',
        items: ['8px', '9px', '10px', '11px', '12px', '14px', '18px', '24px', '30px'],
        itemsObj: {
            '8px': {
                title: '<span style="font-size: 8px;">8px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 8px;'
                    }
                }
            },
            '9px': {
                title: '<span style="font-size: 9px;">9px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 9px;'
                    }
                }
            },
            '10px': {
                title: '<span style="font-size: 10px;">10px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 10px;'
                    }
                }
            },
            '11px': {
                title: '<span style="font-size: 11px;">11px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 11px;'
                    }
                }
            },
            '12px': {
                title: '<span style="font-size: 12px;">12px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 12px;'
                    }
                }
            },
            '14px': {
                title: '<span style="font-size: 14px;">14px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 14px;'
                    }
                }
            },
            '18px': {
                title: '<span style="font-size: 18px;">18px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 18px;'
                    }
                }
            },
            '24px': {
                title: '<span style="font-size: 24px;">24px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 24px;'
                    }
                }
            },
            '30px': {
                title: '<span style="font-size: 30px;">30px</span>',
                params: {
                    tag: 'span',
                    attr: {
                        'style': 'font-size: 30px;'
                    }
                }
            },
        }
    },
    start: function() {
        this.app.toolbar.add('fontsize', {
            title: '## fontsize.font-size ##',
            icon: this.opts.fontsize.icon,
            command: 'fontsize.popup',
            position: { after: 'deleted' },
            blocks: {
                all: 'editable'
            }
        });
    },
    popup: function(params, button) {
        var arr = this.opts.fontsize.items;
        var inlines = this.app.selection.getNodes({ type: 'inline' });
        var items = {};
        for (var i = 0; i < arr.length; i++) {
            var key = arr[i];
            items[key] = this.opts.fontsize.itemsObj[key];
            items[key].command = 'inline.set'
        }

        // remove format
        if (inlines.length !== 0) {
            items['remove'] = {
                title: '## fontsize.reset ##',
                divider: 'top',
                command: 'inline.removeFormat'
            };
        }

        this.app.popup.create('fontsize', {
            width: '300px',
            items: items
        });
        this.app.popup.open({ button: button });
    }
});