(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/core'), require('@angular/platform-browser'), require('quill'), require('quill-delta'), require('rxjs'), require('rxjs/operators'), require('@angular/forms'), require('quill-better-table')) :
    typeof define === 'function' && define.amd ? define('@eui/externals/quill', ['exports', '@angular/common', '@angular/core', '@angular/platform-browser', 'quill', 'quill-delta', 'rxjs', 'rxjs/operators', '@angular/forms', 'quill-better-table'], factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.eui = global.eui || {}, global.eui.externals = global.eui.externals || {}, global.eui.externals.quill = {}), global.ng.common, global.ng.core, global.ng.platformBrowser, global.QuillType, global.Delta, global.rxjs, global.rxjs.operators, global.ng.forms, global.QuillBetterTable));
})(this, (function (exports, i3, i0, i1, QuillType, Delta, rxjs, operators, forms, QuillBetterTable) { 'use strict';

    function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

    function _interopNamespace(e) {
        if (e && e.__esModule) return e;
        var n = Object.create(null);
        if (e) {
            Object.keys(e).forEach(function (k) {
                if (k !== 'default') {
                    var d = Object.getOwnPropertyDescriptor(e, k);
                    Object.defineProperty(n, k, d.get ? d : {
                        enumerable: true,
                        get: function () { return e[k]; }
                    });
                }
            });
        }
        n["default"] = e;
        return Object.freeze(n);
    }

    var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
    var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
    var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
    var QuillType__default = /*#__PURE__*/_interopDefaultLegacy(QuillType);
    var Delta__default = /*#__PURE__*/_interopDefaultLegacy(Delta);
    var QuillBetterTable__default = /*#__PURE__*/_interopDefaultLegacy(QuillBetterTable);

    /*! *****************************************************************************
    Copyright (c) Microsoft Corporation.

    Permission to use, copy, modify, and/or distribute this software for any
    purpose with or without fee is hereby granted.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
    AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
    OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
    PERFORMANCE OF THIS SOFTWARE.
    ***************************************************************************** */
    /* global Reflect, Promise */
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b)
                if (Object.prototype.hasOwnProperty.call(b, p))
                    d[p] = b[p]; };
        return extendStatics(d, b);
    };
    function __extends(d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    }
    var __assign = function () {
        __assign = Object.assign || function __assign(t) {
            for (var s, i = 1, n = arguments.length; i < n; i++) {
                s = arguments[i];
                for (var p in s)
                    if (Object.prototype.hasOwnProperty.call(s, p))
                        t[p] = s[p];
            }
            return t;
        };
        return __assign.apply(this, arguments);
    };
    function __rest(s, e) {
        var t = {};
        for (var p in s)
            if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
                t[p] = s[p];
        if (s != null && typeof Object.getOwnPropertySymbols === "function")
            for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
                if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                    t[p[i]] = s[p[i]];
            }
        return t;
    }
    function __decorate(decorators, target, key, desc) {
        var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
        if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
            r = Reflect.decorate(decorators, target, key, desc);
        else
            for (var i = decorators.length - 1; i >= 0; i--)
                if (d = decorators[i])
                    r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
        return c > 3 && r && Object.defineProperty(target, key, r), r;
    }
    function __param(paramIndex, decorator) {
        return function (target, key) { decorator(target, key, paramIndex); };
    }
    function __metadata(metadataKey, metadataValue) {
        if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
            return Reflect.metadata(metadataKey, metadataValue);
    }
    function __awaiter(thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try {
                step(generator.next(value));
            }
            catch (e) {
                reject(e);
            } }
            function rejected(value) { try {
                step(generator["throw"](value));
            }
            catch (e) {
                reject(e);
            } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    }
    function __generator(thisArg, body) {
        var _ = { label: 0, sent: function () { if (t[0] & 1)
                throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f)
                throw new TypeError("Generator is already executing.");
            while (_)
                try {
                    if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
                        return t;
                    if (y = 0, t)
                        op = [op[0] & 2, t.value];
                    switch (op[0]) {
                        case 0:
                        case 1:
                            t = op;
                            break;
                        case 4:
                            _.label++;
                            return { value: op[1], done: false };
                        case 5:
                            _.label++;
                            y = op[1];
                            op = [0];
                            continue;
                        case 7:
                            op = _.ops.pop();
                            _.trys.pop();
                            continue;
                        default:
                            if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                                _ = 0;
                                continue;
                            }
                            if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
                                _.label = op[1];
                                break;
                            }
                            if (op[0] === 6 && _.label < t[1]) {
                                _.label = t[1];
                                t = op;
                                break;
                            }
                            if (t && _.label < t[2]) {
                                _.label = t[2];
                                _.ops.push(op);
                                break;
                            }
                            if (t[2])
                                _.ops.pop();
                            _.trys.pop();
                            continue;
                    }
                    op = body.call(thisArg, _);
                }
                catch (e) {
                    op = [6, e];
                    y = 0;
                }
                finally {
                    f = t = 0;
                }
            if (op[0] & 5)
                throw op[1];
            return { value: op[0] ? op[1] : void 0, done: true };
        }
    }
    var __createBinding = Object.create ? (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
    }) : (function (o, m, k, k2) {
        if (k2 === undefined)
            k2 = k;
        o[k2] = m[k];
    });
    function __exportStar(m, o) {
        for (var p in m)
            if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
                __createBinding(o, m, p);
    }
    function __values(o) {
        var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
        if (m)
            return m.call(o);
        if (o && typeof o.length === "number")
            return {
                next: function () {
                    if (o && i >= o.length)
                        o = void 0;
                    return { value: o && o[i++], done: !o };
                }
            };
        throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
    }
    function __read(o, n) {
        var m = typeof Symbol === "function" && o[Symbol.iterator];
        if (!m)
            return o;
        var i = m.call(o), r, ar = [], e;
        try {
            while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
                ar.push(r.value);
        }
        catch (error) {
            e = { error: error };
        }
        finally {
            try {
                if (r && !r.done && (m = i["return"]))
                    m.call(i);
            }
            finally {
                if (e)
                    throw e.error;
            }
        }
        return ar;
    }
    /** @deprecated */
    function __spread() {
        for (var ar = [], i = 0; i < arguments.length; i++)
            ar = ar.concat(__read(arguments[i]));
        return ar;
    }
    /** @deprecated */
    function __spreadArrays() {
        for (var s = 0, i = 0, il = arguments.length; i < il; i++)
            s += arguments[i].length;
        for (var r = Array(s), k = 0, i = 0; i < il; i++)
            for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
                r[k] = a[j];
        return r;
    }
    function __spreadArray(to, from) {
        for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
            to[j] = from[i];
        return to;
    }
    function __await(v) {
        return this instanceof __await ? (this.v = v, this) : new __await(v);
    }
    function __asyncGenerator(thisArg, _arguments, generator) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var g = generator.apply(thisArg, _arguments || []), i, q = [];
        return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
        function verb(n) { if (g[n])
            i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
        function resume(n, v) { try {
            step(g[n](v));
        }
        catch (e) {
            settle(q[0][3], e);
        } }
        function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
        function fulfill(value) { resume("next", value); }
        function reject(value) { resume("throw", value); }
        function settle(f, v) { if (f(v), q.shift(), q.length)
            resume(q[0][0], q[0][1]); }
    }
    function __asyncDelegator(o) {
        var i, p;
        return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
        function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
    }
    function __asyncValues(o) {
        if (!Symbol.asyncIterator)
            throw new TypeError("Symbol.asyncIterator is not defined.");
        var m = o[Symbol.asyncIterator], i;
        return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
        function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
        function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
    }
    function __makeTemplateObject(cooked, raw) {
        if (Object.defineProperty) {
            Object.defineProperty(cooked, "raw", { value: raw });
        }
        else {
            cooked.raw = raw;
        }
        return cooked;
    }
    ;
    var __setModuleDefault = Object.create ? (function (o, v) {
        Object.defineProperty(o, "default", { enumerable: true, value: v });
    }) : function (o, v) {
        o["default"] = v;
    };
    function __importStar(mod) {
        if (mod && mod.__esModule)
            return mod;
        var result = {};
        if (mod != null)
            for (var k in mod)
                if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
                    __createBinding(result, mod, k);
        __setModuleDefault(result, mod);
        return result;
    }
    function __importDefault(mod) {
        return (mod && mod.__esModule) ? mod : { default: mod };
    }
    function __classPrivateFieldGet(receiver, privateMap) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to get private field on non-instance");
        }
        return privateMap.get(receiver);
    }
    function __classPrivateFieldSet(receiver, privateMap, value) {
        if (!privateMap.has(receiver)) {
            throw new TypeError("attempted to set private field on non-instance");
        }
        privateMap.set(receiver, value);
        return value;
    }

    var defaultModules = {
        toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            ['blockquote', 'code-block'],
            [{ header: 1 }, { header: 2 }],
            [{ list: 'ordered' }, { list: 'bullet' }],
            [{ script: 'sub' }, { script: 'super' }],
            [{ indent: '-1' }, { indent: '+1' }],
            [{ direction: 'rtl' }],
            [{ size: ['small', false, 'large', 'huge'] }],
            [{ header: [1, 2, 3, 4, 5, 6, false] }],
            [
                { color: [] },
                { background: [] }
            ],
            [{ font: [] }],
            [{ align: [] }],
            ['clean'],
            ['link', 'image', 'video'] // link and image, video
        ]
    };

    var getFormat = function (format, configFormat) {
        var passedFormat = format || configFormat;
        return passedFormat || 'html';
    };

    var QUILL_CONFIG_TOKEN = new i0.InjectionToken('config', {
        providedIn: 'root',
        factory: function () { return ({
            modules: defaultModules,
            customModules: [
                {
                    path: 'modules/better-table',
                    implementation: QuillBetterTable__default["default"]
                }
            ]
        }); }
    });

    var QuillService = /** @class */ (function () {
        function QuillService(injector, config) {
            this.config = config;
            this.count = 0;
            this.document = injector.get(i3.DOCUMENT);
            if (!this.config) {
                this.config = { modules: defaultModules };
            }
        }
        QuillService.prototype.getQuill = function () {
            var _this = this;
            this.count++;
            if (!this.quill && this.count === 1) {
                this.$importPromise = new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
                    var _a, _b, maybePatchedAddEventListener, quillImport;
                    var _this = this;
                    return __generator(this, function (_c) {
                        switch (_c.label) {
                            case 0:
                                maybePatchedAddEventListener = this.document.addEventListener;
                                // There're 2 types of Angular applications:
                                // 1) zone-full (by default)
                                // 2) zone-less
                                // The developer can avoid importing the `zone.js` package and tells Angular that he/she is responsible for running
                                // the change detection by himself. This is done by "nooping" the zone through `CompilerOptions` when bootstrapping
                                // the root module. We fallback to `document.addEventListener` if `__zone_symbol__addEventListener` is not defined,
                                // this means the `zone.js` is not imported.
                                // The `__zone_symbol__addEventListener` is basically a native DOM API, which is not patched by zone.js, thus not even going
                                // through the `zone.js` task lifecycle. You can also access the native DOM API as follows
                                // `target[Zone.__symbol__('methodName')]`.
                                // eslint-disable-next-line @typescript-eslint/dot-notation
                                this.document.addEventListener = this.document['__zone_symbol__addEventListener'] || this.document.addEventListener;
                                return [4 /*yield*/, import('quill')];
                            case 1:
                                quillImport = _c.sent();
                                this.document.addEventListener = maybePatchedAddEventListener;
                                this.quill = (quillImport.default ? quillImport.default : quillImport);
                                // Only register custom options and modules once
                                (_a = this.config.customOptions) === null || _a === void 0 ? void 0 : _a.forEach(function (customOption) {
                                    var newCustomOption = QuillType__default["default"].import(customOption.import);
                                    newCustomOption.whitelist = customOption.whitelist;
                                    QuillType__default["default"].register(newCustomOption, true, _this.config.suppressGlobalRegisterWarning);
                                });
                                (_b = this.config.customModules) === null || _b === void 0 ? void 0 : _b.forEach(function (_c) {
                                    var implementation = _c.implementation, path = _c.path;
                                    QuillType__default["default"].register(path, implementation, _this.config.suppressGlobalRegisterWarning);
                                });
                                resolve(this.quill);
                                return [2 /*return*/];
                        }
                    });
                }); });
            }
            return this.$importPromise;
        };
        return QuillService;
    }());
    /** @nocollapse */ QuillService.ɵfac = function QuillService_Factory(t) { return new (t || QuillService)(i0__namespace.ɵɵinject(i0__namespace.Injector), i0__namespace.ɵɵinject(QUILL_CONFIG_TOKEN, 8)); };
    /** @nocollapse */ QuillService.ɵprov = i0__namespace.ɵɵdefineInjectable({ token: QuillService, factory: QuillService.ɵfac });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(QuillService, [{
                type: i0.Injectable
            }], function () {
            return [{ type: i0__namespace.Injector }, { type: undefined, decorators: [{
                            type: i0.Optional
                        }, {
                            type: i0.Inject,
                            args: [QUILL_CONFIG_TOKEN]
                        }] }];
        }, null);
    })();

    var _c0 = [[["", "quill-editor-toolbar", ""]]];
    var _c1 = ["[quill-editor-toolbar]"];
    // eslint-disable-next-line @angular-eslint/directive-class-suffix
    // tslint:disable-next-line:directive-class-suffix
    var QuillEditorBase = /** @class */ (function () {
        function QuillEditorBase(injector, elementRef, cd, domSanitizer, platformId, renderer, zone, service) {
            var _this = this;
            this.elementRef = elementRef;
            this.cd = cd;
            this.domSanitizer = domSanitizer;
            this.platformId = platformId;
            this.renderer = renderer;
            this.zone = zone;
            this.service = service;
            this.required = false;
            this.customToolbarPosition = 'top';
            this.sanitize = false;
            this.styles = null;
            this.strict = true;
            this.customOptions = [];
            this.customModules = [];
            this.preserveWhitespace = false;
            this.trimOnValidation = false;
            this.compareValues = false;
            this.filterNull = false;
            /*
            https://github.com/KillerCodeMonkey/ngx-quill/issues/1257 - fix null value set
          
            provide default empty value
            by default null
          
            e.g. defaultEmptyValue="" - empty string
          
            <quill-editor
              defaultEmptyValue=""
              formControlName="message"
            ></quill-editor>
            */
            this.defaultEmptyValue = null;
            this.onEditorCreated = new i0.EventEmitter();
            this.onEditorChanged = new i0.EventEmitter();
            this.onContentChanged = new i0.EventEmitter();
            this.onSelectionChanged = new i0.EventEmitter();
            this.onFocus = new i0.EventEmitter();
            this.onBlur = new i0.EventEmitter();
            this.disabled = false; // used to store initial value before ViewInit
            this.subscription = null;
            this.valueGetter = function (quillEditor, editorElement) {
                var html = editorElement.querySelector('.ql-editor').innerHTML;
                if (html === '<p><br></p>' || html === '<div><br></div>') {
                    html = _this.defaultEmptyValue;
                }
                var modelValue = html;
                var format = getFormat(_this.format, _this.service.config.format);
                if (format === 'text') {
                    modelValue = quillEditor.getText();
                }
                else if (format === 'object') {
                    modelValue = quillEditor.getContents();
                }
                else if (format === 'json') {
                    try {
                        modelValue = JSON.stringify(quillEditor.getContents());
                    }
                    catch (e) {
                        modelValue = quillEditor.getText();
                    }
                }
                return modelValue;
            };
            this.valueSetter = function (quillEditor, value) {
                var format = getFormat(_this.format, _this.service.config.format);
                if (format === 'html') {
                    if (_this.sanitize) {
                        value = _this.domSanitizer.sanitize(i0.SecurityContext.HTML, value);
                    }
                    return value ? quillEditor.clipboard.convert({ html: value }) : new Delta__default["default"]();
                }
                else if (format === 'json') {
                    try {
                        return JSON.parse(value);
                    }
                    catch (e) {
                        return new Delta__default["default"]([{ insert: value }]);
                    }
                }
                return value;
            };
            this.selectionChangeHandler = function (range, oldRange, source) {
                var shouldTriggerOnModelTouched = !range && !!_this.onModelTouched;
                // only emit changes when there's any listener
                if (!_this.onBlur.observers.length &&
                    !_this.onFocus.observers.length &&
                    !_this.onSelectionChanged.observers.length &&
                    !shouldTriggerOnModelTouched) {
                    return;
                }
                _this.zone.run(function () {
                    if (range === null) {
                        _this.onBlur.emit({
                            editor: _this.quillEditor,
                            source: source
                        });
                    }
                    else if (oldRange === null) {
                        _this.onFocus.emit({
                            editor: _this.quillEditor,
                            source: source
                        });
                    }
                    _this.onSelectionChanged.emit({
                        editor: _this.quillEditor,
                        oldRange: oldRange,
                        range: range,
                        source: source
                    });
                    if (shouldTriggerOnModelTouched) {
                        _this.onModelTouched();
                    }
                    _this.cd.markForCheck();
                });
            };
            this.textChangeHandler = function (delta, oldDelta, source) {
                // only emit changes emitted by user interactions
                var text = _this.quillEditor.getText();
                var content = _this.quillEditor.getContents();
                var html = _this.editorElem.querySelector('.ql-editor').innerHTML;
                if (html === '<p><br></p>' || html === '<div><br></div>') {
                    html = _this.defaultEmptyValue;
                }
                var trackChanges = _this.trackChanges || _this.service.config.trackChanges;
                var shouldTriggerOnModelChange = (source === 'user' || trackChanges && trackChanges === 'all') && !!_this.onModelChange;
                // only emit changes when there's any listener
                if (!_this.onContentChanged.observers.length && !shouldTriggerOnModelChange) {
                    return;
                }
                _this.zone.run(function () {
                    if (shouldTriggerOnModelChange) {
                        _this.onModelChange(_this.valueGetter(_this.quillEditor, _this.editorElem));
                    }
                    _this.onContentChanged.emit({
                        content: content,
                        delta: delta,
                        editor: _this.quillEditor,
                        html: html,
                        oldDelta: oldDelta,
                        source: source,
                        text: text
                    });
                    _this.cd.markForCheck();
                });
            };
            // eslint-disable-next-line max-len
            this.editorChangeHandler = function (event, current, old, source) {
                // only emit changes when there's any listener
                if (!_this.onEditorChanged.observers.length) {
                    return;
                }
                // only emit changes emitted by user interactions
                if (event === 'text-change') {
                    var text_1 = _this.quillEditor.getText();
                    var content_1 = _this.quillEditor.getContents();
                    var html_1 = _this.editorElem.querySelector('.ql-editor').innerHTML;
                    if (html_1 === '<p><br></p>' || html_1 === '<div><br></div>') {
                        html_1 = _this.defaultEmptyValue;
                    }
                    _this.zone.run(function () {
                        _this.onEditorChanged.emit({
                            content: content_1,
                            delta: current,
                            editor: _this.quillEditor,
                            event: event,
                            html: html_1,
                            oldDelta: old,
                            source: source,
                            text: text_1
                        });
                        _this.cd.markForCheck();
                    });
                }
                else {
                    _this.zone.run(function () {
                        _this.onEditorChanged.emit({
                            editor: _this.quillEditor,
                            event: event,
                            oldRange: old,
                            range: current,
                            source: source
                        });
                        _this.cd.markForCheck();
                    });
                }
            };
            this.document = injector.get(i3.DOCUMENT);
        }
        QuillEditorBase.normalizeClassNames = function (classes) {
            var classList = classes.trim().split(' ');
            return classList.reduce(function (prev, cur) {
                var trimmed = cur.trim();
                if (trimmed) {
                    prev.push(trimmed);
                }
                return prev;
            }, []);
        };
        QuillEditorBase.prototype.ngAfterViewInit = function () {
            return __awaiter(this, void 0, void 0, function () {
                var Quill, toolbarElem, modules, placeholder, bounds, debug, readOnly, defaultEmptyValue, scrollingContainer, formats, format, newValue;
                var _this = this;
                return __generator(this, function (_d) {
                    switch (_d.label) {
                        case 0:
                            if (i3.isPlatformServer(this.platformId)) {
                                return [2 /*return*/];
                            }
                            return [4 /*yield*/, this.service.getQuill()];
                        case 1:
                            Quill = _d.sent();
                            this.elementRef.nativeElement.insertAdjacentHTML(this.customToolbarPosition === 'top' ? 'beforeend' : 'afterbegin', this.preserveWhitespace ? '<pre quill-editor-element></pre>' : '<div quill-editor-element></div>');
                            this.editorElem = this.elementRef.nativeElement.querySelector('[quill-editor-element]');
                            toolbarElem = this.elementRef.nativeElement.querySelector('[quill-editor-toolbar]');
                            modules = Object.assign({}, this.modules || this.service.config.modules);
                            if (toolbarElem) {
                                modules.toolbar = toolbarElem;
                            }
                            else if (modules.toolbar === undefined) {
                                modules.toolbar = defaultModules.toolbar;
                            }
                            placeholder = this.placeholder !== undefined ? this.placeholder : this.service.config.placeholder;
                            if (placeholder === undefined) {
                                placeholder = 'Insert text here ...';
                            }
                            if (this.styles) {
                                Object.keys(this.styles).forEach(function (key) {
                                    _this.renderer.setStyle(_this.editorElem, key, _this.styles[key]);
                                });
                            }
                            if (this.classes) {
                                this.addClasses(this.classes);
                            }
                            this.customOptions.forEach(function (customOption) {
                                var newCustomOption = QuillType__default["default"].import(customOption.import);
                                newCustomOption.whitelist = customOption.whitelist;
                                QuillType__default["default"].register(newCustomOption, true);
                            });
                            this.customModules.forEach(function (_d) {
                                var implementation = _d.implementation, path = _d.path;
                                QuillType__default["default"].register(path, implementation);
                            });
                            bounds = this.bounds && this.bounds === 'self' ? this.editorElem : this.bounds;
                            if (!bounds) {
                                bounds = this.service.config.bounds ? this.service.config.bounds : this.document.body;
                            }
                            debug = this.debug;
                            if (!debug && debug !== false && this.service.config.debug) {
                                debug = this.service.config.debug;
                            }
                            readOnly = this.readOnly;
                            if (!readOnly && this.readOnly !== false) {
                                readOnly = this.service.config.readOnly !== undefined ? this.service.config.readOnly : false;
                            }
                            defaultEmptyValue = this.defaultEmptyValue;
                            if (this.service.config.hasOwnProperty('defaultEmptyValue')) {
                                defaultEmptyValue = this.service.config.defaultEmptyValue;
                            }
                            scrollingContainer = this.scrollingContainer;
                            if (!scrollingContainer && this.scrollingContainer !== null) {
                                scrollingContainer =
                                    this.service.config.scrollingContainer === null
                                        || this.service.config.scrollingContainer ? this.service.config.scrollingContainer : null;
                            }
                            formats = this.formats;
                            if (!formats && formats === undefined) {
                                formats = this.service.config.formats ? __spread(this.service.config.formats) : (this.service.config.formats === null ? null : undefined);
                            }
                            this.zone.runOutsideAngular(function () {
                                var _a, _b, _c;
                                _this.quillEditor = new QuillType__default["default"](_this.editorElem, {
                                    bounds: bounds,
                                    debug: debug,
                                    formats: formats,
                                    modules: modules,
                                    placeholder: placeholder,
                                    readOnly: readOnly,
                                    scrollingContainer: scrollingContainer,
                                    strict: _this.strict,
                                    theme: _this.theme || (_this.service.config.theme ? _this.service.config.theme : 'snow')
                                });
                                // Set optional link placeholder, Quill has no native API for it so using workaround
                                if (_this.linkPlaceholder) {
                                    var tooltip = (_b = (_a = _this.quillEditor) === null || _a === void 0 ? void 0 : _a.theme) === null || _b === void 0 ? void 0 : _b.tooltip;
                                    var input = (_c = tooltip === null || tooltip === void 0 ? void 0 : tooltip.root) === null || _c === void 0 ? void 0 : _c.querySelector('input[data-link]');
                                    if (input === null || input === void 0 ? void 0 : input.dataset) {
                                        input.dataset.link = _this.linkPlaceholder;
                                    }
                                }
                            });
                            if (this.content) {
                                format = getFormat(this.format, this.service.config.format);
                                if (format === 'text') {
                                    this.quillEditor.setText(this.content, 'silent');
                                }
                                else {
                                    newValue = this.valueSetter(this.quillEditor, this.content);
                                    this.quillEditor.setContents(newValue, 'silent');
                                }
                                this.quillEditor.getModule('history').clear();
                            }
                            // initialize disabled status based on this.disabled as default value
                            this.setDisabledState();
                            this.addQuillEventListeners();
                            // The `requestAnimationFrame` triggers change detection. There's no sense to invoke the `requestAnimationFrame` if anyone is
                            // listening to the `onEditorCreated` event inside the template, for instance `<quill-view (onEditorCreated)="...">`.
                            if (!this.onEditorCreated.observers.length && !this.onValidatorChanged) {
                                return [2 /*return*/];
                            }
                            // The `requestAnimationFrame` will trigger change detection and `onEditorCreated` will also call `markDirty()`
                            // internally, since Angular wraps template event listeners into `listener` instruction. We're using the `requestAnimationFrame`
                            // to prevent the frame drop and avoid `ExpressionChangedAfterItHasBeenCheckedError` error.
                            requestAnimationFrame(function () {
                                if (_this.onValidatorChanged) {
                                    _this.onValidatorChanged();
                                }
                                _this.onEditorCreated.emit(_this.quillEditor);
                            });
                            return [2 /*return*/];
                    }
                });
            });
        };
        QuillEditorBase.prototype.ngOnDestroy = function () {
            this.dispose();
        };
        QuillEditorBase.prototype.ngOnChanges = function (changes) {
            var _this = this;
            if (!this.quillEditor) {
                return;
            }
            /* eslint-disable @typescript-eslint/dot-notation */
            if (changes.readOnly) {
                this.quillEditor.enable(!changes.readOnly.currentValue);
            }
            if (changes.placeholder) {
                this.quillEditor.root.dataset.placeholder =
                    changes.placeholder.currentValue;
            }
            if (changes.defaultEmptyValue) {
                this.quillEditor.root.dataset.defaultEmptyValue =
                    changes.defaultEmptyValue.currentValue;
            }
            if (changes.styles) {
                var currentStyling = changes.styles.currentValue;
                var previousStyling = changes.styles.previousValue;
                if (previousStyling) {
                    Object.keys(previousStyling).forEach(function (key) {
                        _this.renderer.removeStyle(_this.editorElem, key);
                    });
                }
                if (currentStyling) {
                    Object.keys(currentStyling).forEach(function (key) {
                        _this.renderer.setStyle(_this.editorElem, key, _this.styles[key]);
                    });
                }
            }
            if (changes.classes) {
                var currentClasses = changes.classes.currentValue;
                var previousClasses = changes.classes.previousValue;
                if (previousClasses) {
                    this.removeClasses(previousClasses);
                }
                if (currentClasses) {
                    this.addClasses(currentClasses);
                }
            }
            // We'd want to re-apply event listeners if the `debounceTime` binding changes to apply the
            // `debounceTime` operator or vice-versa remove it.
            if (changes.debounceTime) {
                this.addQuillEventListeners();
            }
            /* eslint-enable @typescript-eslint/dot-notation */
        };
        QuillEditorBase.prototype.addClasses = function (classList) {
            var _this = this;
            QuillEditorBase.normalizeClassNames(classList).forEach(function (c) {
                _this.renderer.addClass(_this.editorElem, c);
            });
        };
        QuillEditorBase.prototype.removeClasses = function (classList) {
            var _this = this;
            QuillEditorBase.normalizeClassNames(classList).forEach(function (c) {
                _this.renderer.removeClass(_this.editorElem, c);
            });
        };
        QuillEditorBase.prototype.writeValue = function (currentValue) {
            // optional fix for https://github.com/angular/angular/issues/14988
            if (this.filterNull && currentValue === null) {
                return;
            }
            this.content = currentValue;
            if (!this.quillEditor) {
                return;
            }
            var format = getFormat(this.format, this.service.config.format);
            var newValue = this.valueSetter(this.quillEditor, currentValue);
            if (this.compareValues) {
                var currentEditorValue = this.quillEditor.getContents();
                if (JSON.stringify(currentEditorValue) === JSON.stringify(newValue)) {
                    return;
                }
            }
            if (currentValue) {
                if (format === 'text') {
                    this.quillEditor.setText(currentValue);
                }
                else {
                    this.quillEditor.setContents(newValue);
                }
                return;
            }
            this.quillEditor.setText('');
        };
        QuillEditorBase.prototype.setDisabledState = function (isDisabled) {
            if (isDisabled === void 0) { isDisabled = this.disabled; }
            // store initial value to set appropriate disabled status after ViewInit
            this.disabled = isDisabled;
            if (this.quillEditor) {
                if (isDisabled) {
                    this.quillEditor.disable();
                    this.renderer.setAttribute(this.elementRef.nativeElement, 'disabled', 'disabled');
                }
                else {
                    if (!this.readOnly) {
                        this.quillEditor.enable();
                    }
                    this.renderer.removeAttribute(this.elementRef.nativeElement, 'disabled');
                }
            }
        };
        QuillEditorBase.prototype.registerOnChange = function (fn) {
            this.onModelChange = fn;
        };
        QuillEditorBase.prototype.registerOnTouched = function (fn) {
            this.onModelTouched = fn;
        };
        QuillEditorBase.prototype.registerOnValidatorChange = function (fn) {
            this.onValidatorChanged = fn;
        };
        QuillEditorBase.prototype.validate = function () {
            if (!this.quillEditor) {
                return null;
            }
            var err = {};
            var valid = true;
            var text = this.quillEditor.getText();
            // trim text if wanted + handle special case that an empty editor contains a new line
            var textLength = this.trimOnValidation ? text.trim().length :
                (text.length === 1 && text.trim().length === 0 ? 0 : text.length - 1);
            var deltaOperations = this.quillEditor.getContents().ops;
            var onlyEmptyOperation = deltaOperations && deltaOperations.length === 1 && ['\n', '']
                .includes(deltaOperations[0].insert.toString());
            if (this.minLength && textLength && textLength < this.minLength) {
                err.minLengthError = {
                    given: textLength,
                    minLength: this.minLength
                };
                valid = false;
            }
            if (this.maxLength && textLength > this.maxLength) {
                err.maxLengthError = {
                    given: textLength,
                    maxLength: this.maxLength
                };
                valid = false;
            }
            if (this.required && !textLength && onlyEmptyOperation) {
                err.requiredError = {
                    empty: true
                };
                valid = false;
            }
            return valid ? null : err;
        };
        QuillEditorBase.prototype.addQuillEventListeners = function () {
            var _this = this;
            this.dispose();
            // We have to enter the `<root>` zone when adding event listeners, so `debounceTime` will spawn the
            // `AsyncAction` there w/o triggering change detections. We still re-enter the Angular's zone through
            // `zone.run` when we emit an event to the parent component.
            this.zone.runOutsideAngular(function () {
                _this.subscription = new rxjs.Subscription();
                _this.subscription.add(
                // mark model as touched if editor lost focus
                rxjs.fromEvent(_this.quillEditor, 'selection-change').subscribe(function (_d) {
                    var _e = __read(_d, 3), range = _e[0], oldRange = _e[1], source = _e[2];
                    _this.selectionChangeHandler(range, oldRange, source);
                }));
                // The `fromEvent` supports passing JQuery-style event targets, the editor has `on` and `off` methods which
                // will be invoked upon subscription and teardown.
                var textChange$ = rxjs.fromEvent(_this.quillEditor, 'text-change');
                var editorChange$ = rxjs.fromEvent(_this.quillEditor, 'editor-change');
                if (typeof _this.debounceTime === 'number') {
                    textChange$ = textChange$.pipe(operators.debounceTime(_this.debounceTime));
                    editorChange$ = editorChange$.pipe(operators.debounceTime(_this.debounceTime));
                }
                _this.subscription.add(
                // update model if text changes
                textChange$.subscribe(function (_d) {
                    var _e = __read(_d, 3), delta = _e[0], oldDelta = _e[1], source = _e[2];
                    _this.textChangeHandler(delta, oldDelta, source);
                }));
                _this.subscription.add(
                // triggered if selection or text changed
                editorChange$.subscribe(function (_d) {
                    var _e = __read(_d, 4), event = _e[0], current = _e[1], old = _e[2], source = _e[3];
                    _this.editorChangeHandler(event, current, old, source);
                }));
            });
        };
        QuillEditorBase.prototype.dispose = function () {
            if (this.subscription !== null) {
                this.subscription.unsubscribe();
                this.subscription = null;
            }
        };
        return QuillEditorBase;
    }());
    /** @nocollapse */ QuillEditorBase.ɵfac = function QuillEditorBase_Factory(t) { return new (t || QuillEditorBase)(i0__namespace.ɵɵdirectiveInject(i0__namespace.Injector), i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i0__namespace.ChangeDetectorRef), i0__namespace.ɵɵdirectiveInject(i1__namespace.DomSanitizer), i0__namespace.ɵɵdirectiveInject(i0.PLATFORM_ID), i0__namespace.ɵɵdirectiveInject(i0__namespace.Renderer2), i0__namespace.ɵɵdirectiveInject(i0__namespace.NgZone), i0__namespace.ɵɵdirectiveInject(QuillService)); };
    /** @nocollapse */ QuillEditorBase.ɵdir = i0__namespace.ɵɵdefineDirective({ type: QuillEditorBase, inputs: { format: "format", theme: "theme", modules: "modules", debug: "debug", readOnly: "readOnly", placeholder: "placeholder", maxLength: "maxLength", minLength: "minLength", required: "required", formats: "formats", customToolbarPosition: "customToolbarPosition", sanitize: "sanitize", styles: "styles", strict: "strict", scrollingContainer: "scrollingContainer", bounds: "bounds", customOptions: "customOptions", customModules: "customModules", trackChanges: "trackChanges", preserveWhitespace: "preserveWhitespace", classes: "classes", trimOnValidation: "trimOnValidation", linkPlaceholder: "linkPlaceholder", compareValues: "compareValues", filterNull: "filterNull", debounceTime: "debounceTime", defaultEmptyValue: "defaultEmptyValue", valueGetter: "valueGetter", valueSetter: "valueSetter" }, outputs: { onEditorCreated: "onEditorCreated", onEditorChanged: "onEditorChanged", onContentChanged: "onContentChanged", onSelectionChanged: "onSelectionChanged", onFocus: "onFocus", onBlur: "onBlur" }, features: [i0__namespace.ɵɵNgOnChangesFeature] });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(QuillEditorBase, [{
                type: i0.Directive
            }], function () {
            return [{ type: i0__namespace.Injector }, { type: i0__namespace.ElementRef }, { type: i0__namespace.ChangeDetectorRef }, { type: i1__namespace.DomSanitizer }, { type: undefined, decorators: [{
                            type: i0.Inject,
                            args: [i0.PLATFORM_ID]
                        }] }, { type: i0__namespace.Renderer2 }, { type: i0__namespace.NgZone }, { type: QuillService }];
        }, { format: [{
                    type: i0.Input
                }], theme: [{
                    type: i0.Input
                }], modules: [{
                    type: i0.Input
                }], debug: [{
                    type: i0.Input
                }], readOnly: [{
                    type: i0.Input
                }], placeholder: [{
                    type: i0.Input
                }], maxLength: [{
                    type: i0.Input
                }], minLength: [{
                    type: i0.Input
                }], required: [{
                    type: i0.Input
                }], formats: [{
                    type: i0.Input
                }], customToolbarPosition: [{
                    type: i0.Input
                }], sanitize: [{
                    type: i0.Input
                }], styles: [{
                    type: i0.Input
                }], strict: [{
                    type: i0.Input
                }], scrollingContainer: [{
                    type: i0.Input
                }], bounds: [{
                    type: i0.Input
                }], customOptions: [{
                    type: i0.Input
                }], customModules: [{
                    type: i0.Input
                }], trackChanges: [{
                    type: i0.Input
                }], preserveWhitespace: [{
                    type: i0.Input
                }], classes: [{
                    type: i0.Input
                }], trimOnValidation: [{
                    type: i0.Input
                }], linkPlaceholder: [{
                    type: i0.Input
                }], compareValues: [{
                    type: i0.Input
                }], filterNull: [{
                    type: i0.Input
                }], debounceTime: [{
                    type: i0.Input
                }], defaultEmptyValue: [{
                    type: i0.Input
                }], onEditorCreated: [{
                    type: i0.Output
                }], onEditorChanged: [{
                    type: i0.Output
                }], onContentChanged: [{
                    type: i0.Output
                }], onSelectionChanged: [{
                    type: i0.Output
                }], onFocus: [{
                    type: i0.Output
                }], onBlur: [{
                    type: i0.Output
                }], valueGetter: [{
                    type: i0.Input
                }], valueSetter: [{
                    type: i0.Input
                }] });
    })();
    var QuillEditorComponent = /** @class */ (function (_super) {
        __extends(QuillEditorComponent, _super);
        function QuillEditorComponent(injector, elementRef, cd, domSanitizer, platformId, renderer, zone, service) {
            return _super.call(this, injector, elementRef, cd, domSanitizer, platformId, renderer, zone, service) || this;
        }
        return QuillEditorComponent;
    }(QuillEditorBase));
    /** @nocollapse */ QuillEditorComponent.ɵfac = function QuillEditorComponent_Factory(t) { return new (t || QuillEditorComponent)(i0__namespace.ɵɵdirectiveInject(i0__namespace.Injector), i0__namespace.ɵɵdirectiveInject(i0.ElementRef), i0__namespace.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0__namespace.ɵɵdirectiveInject(i1.DomSanitizer), i0__namespace.ɵɵdirectiveInject(i0.PLATFORM_ID), i0__namespace.ɵɵdirectiveInject(i0.Renderer2), i0__namespace.ɵɵdirectiveInject(i0.NgZone), i0__namespace.ɵɵdirectiveInject(QuillService)); };
    /** @nocollapse */ QuillEditorComponent.ɵcmp = i0__namespace.ɵɵdefineComponent({ type: QuillEditorComponent, selectors: [["quill-editor"]], features: [i0__namespace.ɵɵProvidersFeature([
                {
                    multi: true,
                    provide: forms.NG_VALUE_ACCESSOR,
                    // eslint-disable-next-line @typescript-eslint/no-use-before-define
                    useExisting: i0.forwardRef((function () { return QuillEditorComponent; }))
                },
                {
                    multi: true,
                    provide: forms.NG_VALIDATORS,
                    // eslint-disable-next-line @typescript-eslint/no-use-before-define
                    useExisting: i0.forwardRef((function () { return QuillEditorComponent; }))
                }
            ]), i0__namespace.ɵɵInheritDefinitionFeature], ngContentSelectors: _c1, decls: 1, vars: 0, template: function QuillEditorComponent_Template(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵprojectionDef(_c0);
                i0__namespace.ɵɵprojection(0);
            }
        }, styles: ["\n    :host {\n      display: inline-block;\n    }\n    "], encapsulation: 2 });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(QuillEditorComponent, [{
                type: i0.Component,
                args: [{
                        encapsulation: i0.ViewEncapsulation.None,
                        providers: [
                            {
                                multi: true,
                                provide: forms.NG_VALUE_ACCESSOR,
                                // eslint-disable-next-line @typescript-eslint/no-use-before-define
                                useExisting: i0.forwardRef((function () { return QuillEditorComponent; }))
                            },
                            {
                                multi: true,
                                provide: forms.NG_VALIDATORS,
                                // eslint-disable-next-line @typescript-eslint/no-use-before-define
                                useExisting: i0.forwardRef((function () { return QuillEditorComponent; }))
                            }
                        ],
                        // tslint:disable-next-line:component-selector
                        selector: 'quill-editor',
                        template: "\n  <ng-content select=\"[quill-editor-toolbar]\"></ng-content>\n",
                        styles: [
                            "\n    :host {\n      display: inline-block;\n    }\n    "
                        ]
                    }]
            }], function () {
            return [{ type: i0__namespace.Injector }, { type: i0__namespace.ElementRef, decorators: [{
                            type: i0.Inject,
                            args: [i0.ElementRef]
                        }] }, { type: i0__namespace.ChangeDetectorRef, decorators: [{
                            type: i0.Inject,
                            args: [i0.ChangeDetectorRef]
                        }] }, { type: i1__namespace.DomSanitizer, decorators: [{
                            type: i0.Inject,
                            args: [i1.DomSanitizer]
                        }] }, { type: undefined, decorators: [{
                            type: i0.Inject,
                            args: [i0.PLATFORM_ID]
                        }] }, { type: i0__namespace.Renderer2, decorators: [{
                            type: i0.Inject,
                            args: [i0.Renderer2]
                        }] }, { type: i0__namespace.NgZone, decorators: [{
                            type: i0.Inject,
                            args: [i0.NgZone]
                        }] }, { type: QuillService, decorators: [{
                            type: i0.Inject,
                            args: [QuillService]
                        }] }];
        }, null);
    })();

    var QuillViewHTMLComponent = /** @class */ (function () {
        function QuillViewHTMLComponent(sanitizer, service) {
            this.sanitizer = sanitizer;
            this.service = service;
            this.content = '';
            this.sanitize = false;
            this.innerHTML = '';
            this.themeClass = 'ql-snow';
        }
        QuillViewHTMLComponent.prototype.ngOnChanges = function (changes) {
            if (changes.theme) {
                var theme = changes.theme.currentValue || (this.service.config.theme ? this.service.config.theme : 'snow');
                this.themeClass = "ql-" + theme + " ngx-quill-view-html";
            }
            else if (!this.theme) {
                var theme = this.service.config.theme ? this.service.config.theme : 'snow';
                this.themeClass = "ql-" + theme + " ngx-quill-view-html";
            }
            if (changes.content) {
                var content = changes.content.currentValue;
                this.innerHTML = this.sanitize ? content : this.sanitizer.bypassSecurityTrustHtml(content);
            }
        };
        return QuillViewHTMLComponent;
    }());
    /** @nocollapse */ QuillViewHTMLComponent.ɵfac = function QuillViewHTMLComponent_Factory(t) { return new (t || QuillViewHTMLComponent)(i0__namespace.ɵɵdirectiveInject(i1.DomSanitizer), i0__namespace.ɵɵdirectiveInject(QuillService)); };
    /** @nocollapse */ QuillViewHTMLComponent.ɵcmp = i0__namespace.ɵɵdefineComponent({ type: QuillViewHTMLComponent, selectors: [["quill-view-html"]], inputs: { content: "content", theme: "theme", sanitize: "sanitize" }, features: [i0__namespace.ɵɵNgOnChangesFeature], decls: 2, vars: 2, consts: [[1, "ql-container", 3, "ngClass"], [1, "ql-editor", 3, "innerHTML"]], template: function QuillViewHTMLComponent_Template(rf, ctx) {
            if (rf & 1) {
                i0__namespace.ɵɵelementStart(0, "div", 0);
                i0__namespace.ɵɵelement(1, "div", 1);
                i0__namespace.ɵɵelementEnd();
            }
            if (rf & 2) {
                i0__namespace.ɵɵproperty("ngClass", ctx.themeClass);
                i0__namespace.ɵɵadvance(1);
                i0__namespace.ɵɵproperty("innerHTML", ctx.innerHTML, i0__namespace.ɵɵsanitizeHtml);
            }
        }, directives: [i3__namespace.NgClass], styles: ["\n        .ql-container.ngx-quill-view-html {\n          border: 0;\n        }\n    "], encapsulation: 2 });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(QuillViewHTMLComponent, [{
                type: i0.Component,
                args: [{
                        encapsulation: i0.ViewEncapsulation.None,
                        // tslint:disable-next-line:component-selector
                        selector: 'quill-view-html',
                        styles: ["\n        .ql-container.ngx-quill-view-html {\n          border: 0;\n        }\n    "],
                        template: "\n      <div class=\"ql-container\" [ngClass]=\"themeClass\">\n        <div class=\"ql-editor\" [innerHTML]=\"innerHTML\">\n        </div>\n      </div>\n    "
                    }]
            }], function () {
            return [{ type: i1__namespace.DomSanitizer, decorators: [{
                            type: i0.Inject,
                            args: [i1.DomSanitizer]
                        }] }, { type: QuillService }];
        }, { content: [{
                    type: i0.Input
                }], theme: [{
                    type: i0.Input
                }], sanitize: [{
                    type: i0.Input
                }] });
    })();

    var QuillViewComponent = /** @class */ (function () {
        function QuillViewComponent(elementRef, renderer, zone, service, domSanitizer, platformId) {
            var _this = this;
            this.elementRef = elementRef;
            this.renderer = renderer;
            this.zone = zone;
            this.service = service;
            this.domSanitizer = domSanitizer;
            this.platformId = platformId;
            this.sanitize = false;
            this.strict = true;
            this.customModules = [];
            this.customOptions = [];
            this.preserveWhitespace = false;
            this.onEditorCreated = new i0.EventEmitter();
            this.valueSetter = function (quillEditor, value) {
                var format = getFormat(_this.format, _this.service.config.format);
                var content = value;
                if (format === 'text') {
                    quillEditor.setText(content);
                }
                else {
                    if (format === 'html') {
                        if (_this.sanitize) {
                            value = _this.domSanitizer.sanitize(i0.SecurityContext.HTML, value);
                        }
                        content = quillEditor.clipboard.convert({ html: value });
                    }
                    else if (format === 'json') {
                        try {
                            content = JSON.parse(value);
                        }
                        catch (e) {
                            content = [{ insert: value }];
                        }
                    }
                    quillEditor.setContents(content);
                }
            };
        }
        QuillViewComponent.prototype.ngOnChanges = function (changes) {
            if (!this.quillEditor) {
                return;
            }
            if (changes.content) {
                this.valueSetter(this.quillEditor, changes.content.currentValue);
            }
        };
        QuillViewComponent.prototype.ngAfterViewInit = function () {
            return __awaiter(this, void 0, void 0, function () {
                var Quill, modules, debug, formats, theme;
                var _this = this;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0:
                            if (i3.isPlatformServer(this.platformId)) {
                                return [2 /*return*/];
                            }
                            return [4 /*yield*/, this.service.getQuill()];
                        case 1:
                            Quill = _a.sent();
                            modules = Object.assign({}, this.modules || this.service.config.modules);
                            modules.toolbar = false;
                            this.customOptions.forEach(function (customOption) {
                                var newCustomOption = QuillType__default["default"].import(customOption.import);
                                newCustomOption.whitelist = customOption.whitelist;
                                QuillType__default["default"].register(newCustomOption, true);
                            });
                            this.customModules.forEach(function (_a) {
                                var implementation = _a.implementation, path = _a.path;
                                QuillType__default["default"].register(path, implementation);
                            });
                            debug = this.debug;
                            if (!debug && debug !== false && this.service.config.debug) {
                                debug = this.service.config.debug;
                            }
                            formats = this.formats;
                            if (!formats && formats === undefined) {
                                formats = this.service.config.formats ?
                                    Object.assign({}, this.service.config.formats) : (this.service.config.formats === null ? null : undefined);
                            }
                            theme = this.theme || (this.service.config.theme ? this.service.config.theme : 'snow');
                            this.elementRef.nativeElement.insertAdjacentHTML('afterbegin', this.preserveWhitespace ? '<pre quill-view-element></pre>' : '<div quill-view-element></div>');
                            this.editorElem = this.elementRef.nativeElement.querySelector('[quill-view-element]');
                            this.zone.runOutsideAngular(function () {
                                _this.quillEditor = new QuillType__default["default"](_this.editorElem, {
                                    debug: debug,
                                    formats: formats,
                                    modules: modules,
                                    readOnly: true,
                                    strict: _this.strict,
                                    theme: theme
                                });
                            });
                            this.renderer.addClass(this.editorElem, 'ngx-quill-view');
                            if (this.content) {
                                this.valueSetter(this.quillEditor, this.content);
                            }
                            // The `requestAnimationFrame` triggers change detection. There's no sense to invoke the `requestAnimationFrame` if anyone is
                            // listening to the `onEditorCreated` event inside the template, for instance `<quill-view (onEditorCreated)="...">`.
                            if (!this.onEditorCreated.observers.length) {
                                return [2 /*return*/];
                            }
                            // The `requestAnimationFrame` will trigger change detection and `onEditorCreated` will also call `markDirty()`
                            // internally, since Angular wraps template event listeners into `listener` instruction. We're using the `requestAnimationFrame`
                            // to prevent the frame drop and avoid `ExpressionChangedAfterItHasBeenCheckedError` error.
                            requestAnimationFrame(function () {
                                _this.onEditorCreated.emit(_this.quillEditor);
                            });
                            return [2 /*return*/];
                    }
                });
            });
        };
        return QuillViewComponent;
    }());
    /** @nocollapse */ QuillViewComponent.ɵfac = function QuillViewComponent_Factory(t) { return new (t || QuillViewComponent)(i0__namespace.ɵɵdirectiveInject(i0__namespace.ElementRef), i0__namespace.ɵɵdirectiveInject(i0__namespace.Renderer2), i0__namespace.ɵɵdirectiveInject(i0__namespace.NgZone), i0__namespace.ɵɵdirectiveInject(QuillService), i0__namespace.ɵɵdirectiveInject(i1__namespace.DomSanitizer), i0__namespace.ɵɵdirectiveInject(i0.PLATFORM_ID)); };
    /** @nocollapse */ QuillViewComponent.ɵcmp = i0__namespace.ɵɵdefineComponent({ type: QuillViewComponent, selectors: [["quill-view"]], inputs: { format: "format", theme: "theme", modules: "modules", debug: "debug", formats: "formats", sanitize: "sanitize", strict: "strict", content: "content", customModules: "customModules", customOptions: "customOptions", preserveWhitespace: "preserveWhitespace" }, outputs: { onEditorCreated: "onEditorCreated" }, features: [i0__namespace.ɵɵNgOnChangesFeature], decls: 0, vars: 0, template: function QuillViewComponent_Template(rf, ctx) { }, styles: ["\n        .ql-container.ngx-quill-view {\n          border: 0;\n        }\n    "], encapsulation: 2 });
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(QuillViewComponent, [{
                type: i0.Component,
                args: [{
                        encapsulation: i0.ViewEncapsulation.None,
                        // tslint:disable-next-line:component-selector
                        selector: 'quill-view',
                        styles: ["\n        .ql-container.ngx-quill-view {\n          border: 0;\n        }\n    "],
                        template: ""
                    }]
            }], function () {
            return [{ type: i0__namespace.ElementRef }, { type: i0__namespace.Renderer2 }, { type: i0__namespace.NgZone }, { type: QuillService }, { type: i1__namespace.DomSanitizer }, { type: undefined, decorators: [{
                            type: i0.Inject,
                            args: [i0.PLATFORM_ID]
                        }] }];
        }, { format: [{
                    type: i0.Input
                }], theme: [{
                    type: i0.Input
                }], modules: [{
                    type: i0.Input
                }], debug: [{
                    type: i0.Input
                }], formats: [{
                    type: i0.Input
                }], sanitize: [{
                    type: i0.Input
                }], strict: [{
                    type: i0.Input
                }], content: [{
                    type: i0.Input
                }], customModules: [{
                    type: i0.Input
                }], customOptions: [{
                    type: i0.Input
                }], preserveWhitespace: [{
                    type: i0.Input
                }], onEditorCreated: [{
                    type: i0.Output
                }] });
    })();

    var QuillModule = /** @class */ (function () {
        function QuillModule() {
        }
        QuillModule.forRoot = function (config) {
            return {
                ngModule: QuillModule,
                providers: [
                    {
                        provide: QUILL_CONFIG_TOKEN,
                        useValue: config || { modules: defaultModules }
                    }
                ]
            };
        };
        return QuillModule;
    }());
    /** @nocollapse */ QuillModule.ɵmod = i0__namespace.ɵɵdefineNgModule({ type: QuillModule });
    /** @nocollapse */ QuillModule.ɵinj = i0__namespace.ɵɵdefineInjector({ factory: function QuillModule_Factory(t) { return new (t || QuillModule)(); }, providers: [
            QuillService
        ], imports: [[i3.CommonModule]] });
    (function () {
        (typeof ngJitMode === "undefined" || ngJitMode) && i0__namespace.ɵɵsetNgModuleScope(QuillModule, { declarations: [QuillEditorComponent,
                QuillViewComponent,
                QuillViewHTMLComponent], imports: [i3.CommonModule], exports: [QuillEditorComponent, QuillViewComponent, QuillViewHTMLComponent] });
    })();
    /*@__PURE__*/ (function () {
        i0__namespace.ɵsetClassMetadata(QuillModule, [{
                type: i0.NgModule,
                args: [{
                        declarations: [
                            QuillEditorComponent,
                            QuillViewComponent,
                            QuillViewHTMLComponent
                        ],
                        providers: [
                            QuillService
                        ],
                        exports: [QuillEditorComponent, QuillViewComponent, QuillViewHTMLComponent],
                        imports: [i3.CommonModule],
                    }]
            }], null, null);
    })();

    /**
     * Generated bundle index. Do not edit.
     */

    exports.QUILL_CONFIG_TOKEN = QUILL_CONFIG_TOKEN;
    exports.QuillEditorBase = QuillEditorBase;
    exports.QuillEditorComponent = QuillEditorComponent;
    exports.QuillModule = QuillModule;
    exports.QuillService = QuillService;
    exports.QuillViewComponent = QuillViewComponent;
    exports.QuillViewHTMLComponent = QuillViewHTMLComponent;
    exports.defaultModules = defaultModules;
    exports.getFormat = getFormat;

    Object.defineProperty(exports, '__esModule', { value: true });

}));
//# sourceMappingURL=eui-externals-quill.umd.js.map
