quill-delta-to-html
Version:
Converts Quill's delta ops to HTML
3,567 lines • 118 kB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.QuillDeltaToHtmlConverter = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var value_types_1 = require("./value-types");
var InsertData_1 = require("./InsertData");
var lodash_isequal_1 = __importDefault(require("lodash.isequal"));
var DeltaInsertOp = (function () {
function DeltaInsertOp(insertVal, attrs) {
if (typeof insertVal === 'string') {
insertVal = new InsertData_1.InsertDataQuill(value_types_1.DataType.Text, insertVal + '');
}
this.insert = insertVal;
this.attributes = attrs || {};
}
DeltaInsertOp.createNewLineOp = function () {
return new DeltaInsertOp(value_types_1.NewLine);
};
DeltaInsertOp.prototype.isContainerBlock = function () {
return (this.isBlockquote() ||
this.isList() ||
this.isTable() ||
this.isCodeBlock() ||
this.isHeader() ||
this.isBlockAttribute() ||
this.isCustomTextBlock());
};
DeltaInsertOp.prototype.isBlockAttribute = function () {
var attrs = this.attributes;
return !!(attrs.align || attrs.direction || attrs.indent);
};
DeltaInsertOp.prototype.isBlockquote = function () {
return !!this.attributes.blockquote;
};
DeltaInsertOp.prototype.isHeader = function () {
return !!this.attributes.header;
};
DeltaInsertOp.prototype.isTable = function () {
return !!this.attributes.table;
};
DeltaInsertOp.prototype.isSameHeaderAs = function (op) {
return op.attributes.header === this.attributes.header && this.isHeader();
};
DeltaInsertOp.prototype.hasSameAdiAs = function (op) {
return (this.attributes.align === op.attributes.align &&
this.attributes.direction === op.attributes.direction &&
this.attributes.indent === op.attributes.indent);
};
DeltaInsertOp.prototype.hasSameIndentationAs = function (op) {
return this.attributes.indent === op.attributes.indent;
};
DeltaInsertOp.prototype.hasSameAttr = function (op) {
return lodash_isequal_1.default(this.attributes, op.attributes);
};
DeltaInsertOp.prototype.hasHigherIndentThan = function (op) {
return ((Number(this.attributes.indent) || 0) >
(Number(op.attributes.indent) || 0));
};
DeltaInsertOp.prototype.isInline = function () {
return !(this.isContainerBlock() ||
this.isVideo() ||
this.isCustomEmbedBlock());
};
DeltaInsertOp.prototype.isCodeBlock = function () {
return !!this.attributes['code-block'];
};
DeltaInsertOp.prototype.hasSameLangAs = function (op) {
return this.attributes['code-block'] === op.attributes['code-block'];
};
DeltaInsertOp.prototype.isJustNewline = function () {
return this.insert.value === value_types_1.NewLine;
};
DeltaInsertOp.prototype.isList = function () {
return (this.isOrderedList() ||
this.isBulletList() ||
this.isCheckedList() ||
this.isUncheckedList());
};
DeltaInsertOp.prototype.isOrderedList = function () {
return this.attributes.list === value_types_1.ListType.Ordered;
};
DeltaInsertOp.prototype.isBulletList = function () {
return this.attributes.list === value_types_1.ListType.Bullet;
};
DeltaInsertOp.prototype.isCheckedList = function () {
return this.attributes.list === value_types_1.ListType.Checked;
};
DeltaInsertOp.prototype.isUncheckedList = function () {
return this.attributes.list === value_types_1.ListType.Unchecked;
};
DeltaInsertOp.prototype.isACheckList = function () {
return (this.attributes.list == value_types_1.ListType.Unchecked ||
this.attributes.list === value_types_1.ListType.Checked);
};
DeltaInsertOp.prototype.isSameListAs = function (op) {
return (!!op.attributes.list &&
(this.attributes.list === op.attributes.list ||
(op.isACheckList() && this.isACheckList())));
};
DeltaInsertOp.prototype.isSameTableRowAs = function (op) {
return (!!op.isTable() &&
this.isTable() &&
this.attributes.table === op.attributes.table);
};
DeltaInsertOp.prototype.isText = function () {
return this.insert.type === value_types_1.DataType.Text;
};
DeltaInsertOp.prototype.isImage = function () {
return this.insert.type === value_types_1.DataType.Image;
};
DeltaInsertOp.prototype.isFormula = function () {
return this.insert.type === value_types_1.DataType.Formula;
};
DeltaInsertOp.prototype.isVideo = function () {
return this.insert.type === value_types_1.DataType.Video;
};
DeltaInsertOp.prototype.isLink = function () {
return this.isText() && !!this.attributes.link;
};
DeltaInsertOp.prototype.isCustomEmbed = function () {
return this.insert instanceof InsertData_1.InsertDataCustom;
};
DeltaInsertOp.prototype.isCustomEmbedBlock = function () {
return this.isCustomEmbed() && !!this.attributes.renderAsBlock;
};
DeltaInsertOp.prototype.isCustomTextBlock = function () {
return this.isText() && !!this.attributes.renderAsBlock;
};
DeltaInsertOp.prototype.isMentions = function () {
return this.isText() && !!this.attributes.mentions;
};
return DeltaInsertOp;
}());
exports.DeltaInsertOp = DeltaInsertOp;
},{"./InsertData":2,"./value-types":19,"lodash.isequal":20}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var InsertDataQuill = (function () {
function InsertDataQuill(type, value) {
this.type = type;
this.value = value;
}
return InsertDataQuill;
}());
exports.InsertDataQuill = InsertDataQuill;
var InsertDataCustom = (function () {
function InsertDataCustom(type, value) {
this.type = type;
this.value = value;
}
return InsertDataCustom;
}());
exports.InsertDataCustom = InsertDataCustom;
},{}],3:[function(require,module,exports){
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var value_types_1 = require("./value-types");
var str = __importStar(require("./helpers/string"));
var obj = __importStar(require("./helpers/object"));
var InsertOpDenormalizer = (function () {
function InsertOpDenormalizer() {
}
InsertOpDenormalizer.denormalize = function (op) {
if (!op || typeof op !== 'object') {
return [];
}
if (typeof op.insert === 'object' || op.insert === value_types_1.NewLine) {
return [op];
}
var newlinedArray = str.tokenizeWithNewLines(op.insert + '');
if (newlinedArray.length === 1) {
return [op];
}
var nlObj = obj.assign({}, op, { insert: value_types_1.NewLine });
return newlinedArray.map(function (line) {
if (line === value_types_1.NewLine) {
return nlObj;
}
return obj.assign({}, op, {
insert: line,
});
});
};
return InsertOpDenormalizer;
}());
exports.InsertOpDenormalizer = InsertOpDenormalizer;
},{"./helpers/object":15,"./helpers/string":16,"./value-types":19}],4:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var DeltaInsertOp_1 = require("./DeltaInsertOp");
var value_types_1 = require("./value-types");
var InsertData_1 = require("./InsertData");
var OpAttributeSanitizer_1 = require("./OpAttributeSanitizer");
var InsertOpDenormalizer_1 = require("./InsertOpDenormalizer");
var OpLinkSanitizer_1 = require("./OpLinkSanitizer");
var InsertOpsConverter = (function () {
function InsertOpsConverter() {
}
InsertOpsConverter.convert = function (deltaOps, options) {
if (!Array.isArray(deltaOps)) {
return [];
}
var denormalizedOps = [].concat.apply([], deltaOps.map(InsertOpDenormalizer_1.InsertOpDenormalizer.denormalize));
var results = [];
var insertVal, attributes;
for (var _i = 0, denormalizedOps_1 = denormalizedOps; _i < denormalizedOps_1.length; _i++) {
var op = denormalizedOps_1[_i];
if (!op.insert) {
continue;
}
insertVal = InsertOpsConverter.convertInsertVal(op.insert, options);
if (!insertVal) {
continue;
}
attributes = OpAttributeSanitizer_1.OpAttributeSanitizer.sanitize(op.attributes, options);
results.push(new DeltaInsertOp_1.DeltaInsertOp(insertVal, attributes));
}
return results;
};
InsertOpsConverter.convertInsertVal = function (insertPropVal, sanitizeOptions) {
if (typeof insertPropVal === 'string') {
return new InsertData_1.InsertDataQuill(value_types_1.DataType.Text, insertPropVal);
}
if (!insertPropVal || typeof insertPropVal !== 'object') {
return null;
}
var keys = Object.keys(insertPropVal);
if (!keys.length) {
return null;
}
return value_types_1.DataType.Image in insertPropVal
? new InsertData_1.InsertDataQuill(value_types_1.DataType.Image, OpLinkSanitizer_1.OpLinkSanitizer.sanitize(insertPropVal[value_types_1.DataType.Image] + '', sanitizeOptions))
: value_types_1.DataType.Video in insertPropVal
? new InsertData_1.InsertDataQuill(value_types_1.DataType.Video, OpLinkSanitizer_1.OpLinkSanitizer.sanitize(insertPropVal[value_types_1.DataType.Video] + '', sanitizeOptions))
: value_types_1.DataType.Formula in insertPropVal
? new InsertData_1.InsertDataQuill(value_types_1.DataType.Formula, insertPropVal[value_types_1.DataType.Formula])
:
new InsertData_1.InsertDataCustom(keys[0], insertPropVal[keys[0]]);
};
return InsertOpsConverter;
}());
exports.InsertOpsConverter = InsertOpsConverter;
},{"./DeltaInsertOp":1,"./InsertData":2,"./InsertOpDenormalizer":3,"./OpAttributeSanitizer":5,"./OpLinkSanitizer":6,"./value-types":19}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var value_types_1 = require("./value-types");
var MentionSanitizer_1 = require("./mentions/MentionSanitizer");
var array_1 = require("./helpers/array");
var OpLinkSanitizer_1 = require("./OpLinkSanitizer");
var OpAttributeSanitizer = (function () {
function OpAttributeSanitizer() {
}
OpAttributeSanitizer.sanitize = function (dirtyAttrs, sanitizeOptions) {
var cleanAttrs = {};
if (!dirtyAttrs || typeof dirtyAttrs !== 'object') {
return cleanAttrs;
}
var booleanAttrs = [
'bold',
'italic',
'underline',
'strike',
'code',
'blockquote',
'code-block',
'renderAsBlock',
];
var colorAttrs = ['background', 'color'];
var font = dirtyAttrs.font, size = dirtyAttrs.size, link = dirtyAttrs.link, script = dirtyAttrs.script, list = dirtyAttrs.list, header = dirtyAttrs.header, align = dirtyAttrs.align, direction = dirtyAttrs.direction, indent = dirtyAttrs.indent, mentions = dirtyAttrs.mentions, mention = dirtyAttrs.mention, width = dirtyAttrs.width, target = dirtyAttrs.target, rel = dirtyAttrs.rel;
var codeBlock = dirtyAttrs['code-block'];
var sanitizedAttrs = booleanAttrs.concat(colorAttrs, [
'font',
'size',
'link',
'script',
'list',
'header',
'align',
'direction',
'indent',
'mentions',
'mention',
'width',
'target',
'rel',
'code-block',
]);
booleanAttrs.forEach(function (prop) {
var v = dirtyAttrs[prop];
if (v) {
cleanAttrs[prop] = !!v;
}
});
colorAttrs.forEach(function (prop) {
var val = dirtyAttrs[prop];
if (val &&
(OpAttributeSanitizer.IsValidHexColor(val + '') ||
OpAttributeSanitizer.IsValidColorLiteral(val + '') ||
OpAttributeSanitizer.IsValidRGBColor(val + ''))) {
cleanAttrs[prop] = val;
}
});
if (font && OpAttributeSanitizer.IsValidFontName(font + '')) {
cleanAttrs.font = font;
}
if (size && OpAttributeSanitizer.IsValidSize(size + '')) {
cleanAttrs.size = size;
}
if (width && OpAttributeSanitizer.IsValidWidth(width + '')) {
cleanAttrs.width = width;
}
if (link) {
cleanAttrs.link = OpLinkSanitizer_1.OpLinkSanitizer.sanitize(link + '', sanitizeOptions);
}
if (target && OpAttributeSanitizer.isValidTarget(target)) {
cleanAttrs.target = target;
}
if (rel && OpAttributeSanitizer.IsValidRel(rel)) {
cleanAttrs.rel = rel;
}
if (codeBlock) {
if (OpAttributeSanitizer.IsValidLang(codeBlock)) {
cleanAttrs['code-block'] = codeBlock;
}
else {
cleanAttrs['code-block'] = !!codeBlock;
}
}
if (script === value_types_1.ScriptType.Sub || value_types_1.ScriptType.Super === script) {
cleanAttrs.script = script;
}
if (list === value_types_1.ListType.Bullet ||
list === value_types_1.ListType.Ordered ||
list === value_types_1.ListType.Checked ||
list === value_types_1.ListType.Unchecked) {
cleanAttrs.list = list;
}
if (Number(header)) {
cleanAttrs.header = Math.min(Number(header), 6);
}
if (array_1.find([value_types_1.AlignType.Center, value_types_1.AlignType.Right, value_types_1.AlignType.Justify, value_types_1.AlignType.Left], function (a) { return a === align; })) {
cleanAttrs.align = align;
}
if (direction === value_types_1.DirectionType.Rtl) {
cleanAttrs.direction = direction;
}
if (indent && Number(indent)) {
cleanAttrs.indent = Math.min(Number(indent), 30);
}
if (mentions && mention) {
var sanitizedMention = MentionSanitizer_1.MentionSanitizer.sanitize(mention, sanitizeOptions);
if (Object.keys(sanitizedMention).length > 0) {
cleanAttrs.mentions = !!mentions;
cleanAttrs.mention = mention;
}
}
return Object.keys(dirtyAttrs).reduce(function (cleaned, k) {
if (sanitizedAttrs.indexOf(k) === -1) {
cleaned[k] = dirtyAttrs[k];
}
return cleaned;
}, cleanAttrs);
};
OpAttributeSanitizer.IsValidHexColor = function (colorStr) {
return !!colorStr.match(/^#([0-9A-F]{6}|[0-9A-F]{3})$/i);
};
OpAttributeSanitizer.IsValidColorLiteral = function (colorStr) {
return !!colorStr.match(/^[a-z]{1,50}$/i);
};
OpAttributeSanitizer.IsValidRGBColor = function (colorStr) {
var re = /^rgb\(((0|25[0-5]|2[0-4]\d|1\d\d|0?\d?\d),\s*){2}(0|25[0-5]|2[0-4]\d|1\d\d|0?\d?\d)\)$/i;
return !!colorStr.match(re);
};
OpAttributeSanitizer.IsValidFontName = function (fontName) {
return !!fontName.match(/^[a-z\s0-9\- ]{1,30}$/i);
};
OpAttributeSanitizer.IsValidSize = function (size) {
return !!size.match(/^[a-z0-9\-]{1,20}$/i);
};
OpAttributeSanitizer.IsValidWidth = function (width) {
return !!width.match(/^[0-9]*(px|em|%)?$/);
};
OpAttributeSanitizer.isValidTarget = function (target) {
return !!target.match(/^[_a-zA-Z0-9\-]{1,50}$/);
};
OpAttributeSanitizer.IsValidRel = function (relStr) {
return !!relStr.match(/^[a-zA-Z\s\-]{1,250}$/i);
};
OpAttributeSanitizer.IsValidLang = function (lang) {
if (typeof lang === 'boolean') {
return true;
}
return !!lang.match(/^[a-zA-Z\s\-\\\/\+]{1,50}$/i);
};
return OpAttributeSanitizer;
}());
exports.OpAttributeSanitizer = OpAttributeSanitizer;
},{"./OpLinkSanitizer":6,"./helpers/array":14,"./mentions/MentionSanitizer":18,"./value-types":19}],6:[function(require,module,exports){
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var url = __importStar(require("./helpers/url"));
var funcs_html_1 = require("./funcs-html");
var OpLinkSanitizer = (function () {
function OpLinkSanitizer() {
}
OpLinkSanitizer.sanitize = function (link, options) {
var sanitizerFn = function () {
return undefined;
};
if (options && typeof options.urlSanitizer === 'function') {
sanitizerFn = options.urlSanitizer;
}
var result = sanitizerFn(link);
return typeof result === 'string' ? result : funcs_html_1.encodeLink(url.sanitize(link));
};
return OpLinkSanitizer;
}());
exports.OpLinkSanitizer = OpLinkSanitizer;
},{"./funcs-html":9,"./helpers/url":17}],7:[function(require,module,exports){
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var funcs_html_1 = require("./funcs-html");
var value_types_1 = require("./value-types");
var obj = __importStar(require("./helpers/object"));
var arr = __importStar(require("./helpers/array"));
var OpAttributeSanitizer_1 = require("./OpAttributeSanitizer");
var DEFAULT_INLINE_FONTS = {
serif: 'font-family: Georgia, Times New Roman, serif',
monospace: 'font-family: Monaco, Courier New, monospace',
};
exports.DEFAULT_INLINE_STYLES = {
font: function (value) { return DEFAULT_INLINE_FONTS[value] || 'font-family:' + value; },
size: {
small: 'font-size: 0.75em',
large: 'font-size: 1.5em',
huge: 'font-size: 2.5em',
},
indent: function (value, op) {
var indentSize = parseInt(value, 10) * 3;
var side = op.attributes['direction'] === 'rtl' ? 'right' : 'left';
return 'padding-' + side + ':' + indentSize + 'em';
},
direction: function (value, op) {
if (value === 'rtl') {
return ('direction:rtl' + (op.attributes['align'] ? '' : '; text-align:inherit'));
}
else {
return undefined;
}
},
};
var OpToHtmlConverter = (function () {
function OpToHtmlConverter(op, options) {
this.op = op;
this.options = obj.assign({}, {
classPrefix: 'ql',
inlineStyles: undefined,
encodeHtml: true,
listItemTag: 'li',
paragraphTag: 'p',
}, options);
}
OpToHtmlConverter.prototype.prefixClass = function (className) {
if (!this.options.classPrefix) {
return className + '';
}
return this.options.classPrefix + '-' + className;
};
OpToHtmlConverter.prototype.getHtml = function () {
var parts = this.getHtmlParts();
return parts.openingTag + parts.content + parts.closingTag;
};
OpToHtmlConverter.prototype.getHtmlParts = function () {
var _this = this;
if (this.op.isJustNewline() && !this.op.isContainerBlock()) {
return { openingTag: '', closingTag: '', content: value_types_1.NewLine };
}
var tags = this.getTags(), attrs = this.getTagAttributes();
if (!tags.length && attrs.length) {
tags.push('span');
}
var beginTags = [], endTags = [];
var imgTag = 'img';
var isImageLink = function (tag) {
return tag === imgTag && !!_this.op.attributes.link;
};
for (var _i = 0, tags_1 = tags; _i < tags_1.length; _i++) {
var tag = tags_1[_i];
if (isImageLink(tag)) {
beginTags.push(funcs_html_1.makeStartTag('a', this.getLinkAttrs()));
}
beginTags.push(funcs_html_1.makeStartTag(tag, attrs));
endTags.push(tag === 'img' ? '' : funcs_html_1.makeEndTag(tag));
if (isImageLink(tag)) {
endTags.push(funcs_html_1.makeEndTag('a'));
}
attrs = [];
}
endTags.reverse();
return {
openingTag: beginTags.join(''),
content: this.getContent(),
closingTag: endTags.join(''),
};
};
OpToHtmlConverter.prototype.getContent = function () {
if (this.op.isContainerBlock()) {
return '';
}
if (this.op.isMentions()) {
return this.op.insert.value;
}
var content = this.op.isFormula() || this.op.isText() ? this.op.insert.value : '';
return (this.options.encodeHtml && funcs_html_1.encodeHtml(content)) || content;
};
OpToHtmlConverter.prototype.getCssClasses = function () {
var attrs = this.op.attributes;
if (this.options.inlineStyles) {
return [];
}
var propsArr = ['indent', 'align', 'direction', 'font', 'size'];
if (this.options.allowBackgroundClasses) {
propsArr.push('background');
}
return (this.getCustomCssClasses() || []).concat(propsArr
.filter(function (prop) { return !!attrs[prop]; })
.filter(function (prop) {
return prop === 'background'
? OpAttributeSanitizer_1.OpAttributeSanitizer.IsValidColorLiteral(attrs[prop])
: true;
})
.map(function (prop) { return prop + '-' + attrs[prop]; })
.concat(this.op.isFormula() ? 'formula' : [])
.concat(this.op.isVideo() ? 'video' : [])
.concat(this.op.isImage() ? 'image' : [])
.map(this.prefixClass.bind(this)));
};
OpToHtmlConverter.prototype.getCssStyles = function () {
var _this = this;
var attrs = this.op.attributes;
var propsArr = [['color']];
if (!!this.options.inlineStyles || !this.options.allowBackgroundClasses) {
propsArr.push(['background', 'background-color']);
}
if (this.options.inlineStyles) {
propsArr = propsArr.concat([
['indent'],
['align', 'text-align'],
['direction'],
['font', 'font-family'],
['size'],
]);
}
return (this.getCustomCssStyles() || [])
.concat(propsArr
.filter(function (item) { return !!attrs[item[0]]; })
.map(function (item) {
var attribute = item[0];
var attrValue = attrs[attribute];
var attributeConverter = (_this.options.inlineStyles &&
_this.options.inlineStyles[attribute]) ||
exports.DEFAULT_INLINE_STYLES[attribute];
if (typeof attributeConverter === 'object') {
return attributeConverter[attrValue];
}
else if (typeof attributeConverter === 'function') {
var converterFn = attributeConverter;
return converterFn(attrValue, _this.op);
}
else {
return arr.preferSecond(item) + ':' + attrValue;
}
}))
.filter(function (item) { return item !== undefined; });
};
OpToHtmlConverter.prototype.getTagAttributes = function () {
if (this.op.attributes.code && !this.op.isLink()) {
return [];
}
var makeAttr = this.makeAttr.bind(this);
var customTagAttributes = this.getCustomTagAttributes();
var customAttr = customTagAttributes
? Object.keys(this.getCustomTagAttributes()).map(function (k) {
return makeAttr(k, customTagAttributes[k]);
})
: [];
var classes = this.getCssClasses();
var tagAttrs = classes.length
? customAttr.concat([makeAttr('class', classes.join(' '))])
: customAttr;
if (this.op.isImage()) {
this.op.attributes.width &&
(tagAttrs = tagAttrs.concat(makeAttr('width', this.op.attributes.width)));
return tagAttrs.concat(makeAttr('src', this.op.insert.value));
}
if (this.op.isACheckList()) {
return tagAttrs.concat(makeAttr('data-checked', this.op.isCheckedList() ? 'true' : 'false'));
}
if (this.op.isFormula()) {
return tagAttrs;
}
if (this.op.isVideo()) {
return tagAttrs.concat(makeAttr('frameborder', '0'), makeAttr('allowfullscreen', 'true'), makeAttr('src', this.op.insert.value));
}
if (this.op.isMentions()) {
var mention = this.op.attributes.mention;
if (mention.class) {
tagAttrs = tagAttrs.concat(makeAttr('class', mention.class));
}
if (mention['end-point'] && mention.slug) {
tagAttrs = tagAttrs.concat(makeAttr('href', mention['end-point'] + '/' + mention.slug));
}
else {
tagAttrs = tagAttrs.concat(makeAttr('href', 'about:blank'));
}
if (mention.target) {
tagAttrs = tagAttrs.concat(makeAttr('target', mention.target));
}
return tagAttrs;
}
var styles = this.getCssStyles();
if (styles.length) {
tagAttrs.push(makeAttr('style', styles.join(';')));
}
if (this.op.isCodeBlock() &&
typeof this.op.attributes['code-block'] === 'string') {
return tagAttrs.concat(makeAttr('data-language', this.op.attributes['code-block']));
}
if (this.op.isContainerBlock()) {
return tagAttrs;
}
if (this.op.isLink()) {
tagAttrs = tagAttrs.concat(this.getLinkAttrs());
}
return tagAttrs;
};
OpToHtmlConverter.prototype.makeAttr = function (k, v) {
return { key: k, value: v };
};
OpToHtmlConverter.prototype.getLinkAttrs = function () {
var tagAttrs = [];
var targetForAll = OpAttributeSanitizer_1.OpAttributeSanitizer.isValidTarget(this.options.linkTarget || '')
? this.options.linkTarget
: undefined;
var relForAll = OpAttributeSanitizer_1.OpAttributeSanitizer.IsValidRel(this.options.linkRel || '')
? this.options.linkRel
: undefined;
var target = this.op.attributes.target || targetForAll;
var rel = this.op.attributes.rel || relForAll;
return tagAttrs
.concat(this.makeAttr('href', this.op.attributes.link))
.concat(target ? this.makeAttr('target', target) : [])
.concat(rel ? this.makeAttr('rel', rel) : []);
};
OpToHtmlConverter.prototype.getCustomTag = function (format) {
if (this.options.customTag &&
typeof this.options.customTag === 'function') {
return this.options.customTag.apply(null, [format, this.op]);
}
};
OpToHtmlConverter.prototype.getCustomTagAttributes = function () {
if (this.options.customTagAttributes &&
typeof this.options.customTagAttributes === 'function') {
return this.options.customTagAttributes.apply(null, [this.op]);
}
};
OpToHtmlConverter.prototype.getCustomCssClasses = function () {
if (this.options.customCssClasses &&
typeof this.options.customCssClasses === 'function') {
var res = this.options.customCssClasses.apply(null, [this.op]);
if (res) {
return Array.isArray(res) ? res : [res];
}
}
};
OpToHtmlConverter.prototype.getCustomCssStyles = function () {
if (this.options.customCssStyles &&
typeof this.options.customCssStyles === 'function') {
var res = this.options.customCssStyles.apply(null, [this.op]);
if (res) {
return Array.isArray(res) ? res : [res];
}
}
};
OpToHtmlConverter.prototype.getTags = function () {
var _this = this;
var attrs = this.op.attributes;
if (!this.op.isText()) {
return [
this.op.isVideo() ? 'iframe' : this.op.isImage() ? 'img' : 'span',
];
}
var positionTag = this.options.paragraphTag || 'p';
var blocks = [
['blockquote'],
['code-block', 'pre'],
['list', this.options.listItemTag],
['header'],
['align', positionTag],
['direction', positionTag],
['indent', positionTag],
];
for (var _i = 0, blocks_1 = blocks; _i < blocks_1.length; _i++) {
var item = blocks_1[_i];
var firstItem = item[0];
if (attrs[firstItem]) {
var customTag = this.getCustomTag(firstItem);
return customTag
? [customTag]
: firstItem === 'header'
? ['h' + attrs[firstItem]]
: [arr.preferSecond(item)];
}
}
if (this.op.isCustomTextBlock()) {
var customTag = this.getCustomTag('renderAsBlock');
return customTag ? [customTag] : [positionTag];
}
var customTagsMap = Object.keys(attrs).reduce(function (res, it) {
var customTag = _this.getCustomTag(it);
if (customTag) {
res[it] = customTag;
}
return res;
}, {});
var inlineTags = [
['link', 'a'],
['mentions', 'a'],
['script'],
['bold', 'strong'],
['italic', 'em'],
['strike', 's'],
['underline', 'u'],
['code'],
];
return inlineTags.filter(function (item) { return !!attrs[item[0]]; }).concat(Object.keys(customTagsMap)
.filter(function (t) { return !inlineTags.some(function (it) { return it[0] == t; }); })
.map(function (t) { return [t, customTagsMap[t]]; })).map(function (item) {
return customTagsMap[item[0]]
? customTagsMap[item[0]]
: item[0] === 'script'
? attrs[item[0]] === value_types_1.ScriptType.Sub
? 'sub'
: 'sup'
: arr.preferSecond(item);
});
};
return OpToHtmlConverter;
}());
exports.OpToHtmlConverter = OpToHtmlConverter;
},{"./OpAttributeSanitizer":5,"./funcs-html":9,"./helpers/array":14,"./helpers/object":15,"./value-types":19}],8:[function(require,module,exports){
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var InsertOpsConverter_1 = require("./InsertOpsConverter");
var OpToHtmlConverter_1 = require("./OpToHtmlConverter");
var Grouper_1 = require("./grouper/Grouper");
var group_types_1 = require("./grouper/group-types");
var ListNester_1 = require("./grouper/ListNester");
var funcs_html_1 = require("./funcs-html");
var obj = __importStar(require("./helpers/object"));
var value_types_1 = require("./value-types");
var TableGrouper_1 = require("./grouper/TableGrouper");
var BrTag = '<br/>';
var QuillDeltaToHtmlConverter = (function () {
function QuillDeltaToHtmlConverter(deltaOps, options) {
this.rawDeltaOps = [];
this.callbacks = {};
this.options = obj.assign({
paragraphTag: 'p',
encodeHtml: true,
classPrefix: 'ql',
inlineStyles: false,
multiLineBlockquote: true,
multiLineHeader: true,
multiLineCodeblock: true,
multiLineParagraph: true,
multiLineCustomBlock: true,
allowBackgroundClasses: false,
linkTarget: '_blank',
}, options, {
orderedListTag: 'ol',
bulletListTag: 'ul',
listItemTag: 'li',
});
var inlineStyles;
if (!this.options.inlineStyles) {
inlineStyles = undefined;
}
else if (typeof this.options.inlineStyles === 'object') {
inlineStyles = this.options.inlineStyles;
}
else {
inlineStyles = {};
}
this.converterOptions = {
encodeHtml: this.options.encodeHtml,
classPrefix: this.options.classPrefix,
inlineStyles: inlineStyles,
listItemTag: this.options.listItemTag,
paragraphTag: this.options.paragraphTag,
linkRel: this.options.linkRel,
linkTarget: this.options.linkTarget,
allowBackgroundClasses: this.options.allowBackgroundClasses,
customTag: this.options.customTag,
customTagAttributes: this.options.customTagAttributes,
customCssClasses: this.options.customCssClasses,
customCssStyles: this.options.customCssStyles,
};
this.rawDeltaOps = deltaOps;
}
QuillDeltaToHtmlConverter.prototype._getListTag = function (op) {
return op.isOrderedList()
? this.options.orderedListTag + ''
: op.isBulletList()
? this.options.bulletListTag + ''
: op.isCheckedList()
? this.options.bulletListTag + ''
: op.isUncheckedList()
? this.options.bulletListTag + ''
: '';
};
QuillDeltaToHtmlConverter.prototype.getGroupedOps = function () {
var deltaOps = InsertOpsConverter_1.InsertOpsConverter.convert(this.rawDeltaOps, this.options);
var pairedOps = Grouper_1.Grouper.pairOpsWithTheirBlock(deltaOps);
var groupedSameStyleBlocks = Grouper_1.Grouper.groupConsecutiveSameStyleBlocks(pairedOps, {
blockquotes: !!this.options.multiLineBlockquote,
header: !!this.options.multiLineHeader,
codeBlocks: !!this.options.multiLineCodeblock,
customBlocks: !!this.options.multiLineCustomBlock,
});
var groupedOps = Grouper_1.Grouper.reduceConsecutiveSameStyleBlocksToOne(groupedSameStyleBlocks);
var tableGrouper = new TableGrouper_1.TableGrouper();
groupedOps = tableGrouper.group(groupedOps);
var listNester = new ListNester_1.ListNester();
return listNester.nest(groupedOps);
};
QuillDeltaToHtmlConverter.prototype.convert = function () {
var _this = this;
var groups = this.getGroupedOps();
return groups
.map(function (group) {
if (group instanceof group_types_1.ListGroup) {
return _this._renderWithCallbacks(value_types_1.GroupType.List, group, function () {
return _this._renderList(group);
});
}
else if (group instanceof group_types_1.TableGroup) {
return _this._renderWithCallbacks(value_types_1.GroupType.Table, group, function () {
return _this._renderTable(group);
});
}
else if (group instanceof group_types_1.BlockGroup) {
var g = group;
return _this._renderWithCallbacks(value_types_1.GroupType.Block, group, function () {
return _this._renderBlock(g.op, g.ops);
});
}
else if (group instanceof group_types_1.BlotBlock) {
return _this._renderCustom(group.op, null);
}
else if (group instanceof group_types_1.VideoItem) {
return _this._renderWithCallbacks(value_types_1.GroupType.Video, group, function () {
var g = group;
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(g.op, _this.converterOptions);
return converter.getHtml();
});
}
else {
return _this._renderWithCallbacks(value_types_1.GroupType.InlineGroup, group, function () {
return _this._renderInlines(group.ops, true);
});
}
})
.join('');
};
QuillDeltaToHtmlConverter.prototype._renderWithCallbacks = function (groupType, group, myRenderFn) {
var html = '';
var beforeCb = this.callbacks['beforeRender_cb'];
html =
typeof beforeCb === 'function'
? beforeCb.apply(null, [groupType, group])
: '';
if (!html) {
html = myRenderFn();
}
var afterCb = this.callbacks['afterRender_cb'];
html =
typeof afterCb === 'function'
? afterCb.apply(null, [groupType, html])
: html;
return html;
};
QuillDeltaToHtmlConverter.prototype._renderList = function (list) {
var _this = this;
var firstItem = list.items[0];
return (funcs_html_1.makeStartTag(this._getListTag(firstItem.item.op)) +
list.items.map(function (li) { return _this._renderListItem(li); }).join('') +
funcs_html_1.makeEndTag(this._getListTag(firstItem.item.op)));
};
QuillDeltaToHtmlConverter.prototype._renderListItem = function (li) {
li.item.op.attributes.indent = 0;
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(li.item.op, this.converterOptions);
var parts = converter.getHtmlParts();
var liElementsHtml = this._renderInlines(li.item.ops, false);
return (parts.openingTag +
liElementsHtml +
(li.innerList ? this._renderList(li.innerList) : '') +
parts.closingTag);
};
QuillDeltaToHtmlConverter.prototype._renderTable = function (table) {
var _this = this;
return (funcs_html_1.makeStartTag('table') +
funcs_html_1.makeStartTag('tbody') +
table.rows.map(function (row) { return _this._renderTableRow(row); }).join('') +
funcs_html_1.makeEndTag('tbody') +
funcs_html_1.makeEndTag('table'));
};
QuillDeltaToHtmlConverter.prototype._renderTableRow = function (row) {
var _this = this;
return (funcs_html_1.makeStartTag('tr') +
row.cells.map(function (cell) { return _this._renderTableCell(cell); }).join('') +
funcs_html_1.makeEndTag('tr'));
};
QuillDeltaToHtmlConverter.prototype._renderTableCell = function (cell) {
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(cell.item.op, this.converterOptions);
var parts = converter.getHtmlParts();
var cellElementsHtml = this._renderInlines(cell.item.ops, false);
return (funcs_html_1.makeStartTag('td', {
key: 'data-row',
value: cell.item.op.attributes.table,
}) +
parts.openingTag +
cellElementsHtml +
parts.closingTag +
funcs_html_1.makeEndTag('td'));
};
QuillDeltaToHtmlConverter.prototype._renderBlock = function (bop, ops) {
var _this = this;
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(bop, this.converterOptions);
var htmlParts = converter.getHtmlParts();
if (bop.isCodeBlock()) {
return (htmlParts.openingTag +
funcs_html_1.encodeHtml(ops
.map(function (iop) {
return iop.isCustomEmbed()
? _this._renderCustom(iop, bop)
: iop.insert.value;
})
.join('')) +
htmlParts.closingTag);
}
var inlines = ops.map(function (op) { return _this._renderInline(op, bop); }).join('');
return htmlParts.openingTag + (inlines || BrTag) + htmlParts.closingTag;
};
QuillDeltaToHtmlConverter.prototype._renderInlines = function (ops, isInlineGroup) {
var _this = this;
if (isInlineGroup === void 0) { isInlineGroup = true; }
var opsLen = ops.length - 1;
var html = ops
.map(function (op, i) {
if (i > 0 && i === opsLen && op.isJustNewline()) {
return '';
}
return _this._renderInline(op, null);
})
.join('');
if (!isInlineGroup) {
return html;
}
var startParaTag = funcs_html_1.makeStartTag(this.options.paragraphTag);
var endParaTag = funcs_html_1.makeEndTag(this.options.paragraphTag);
if (html === BrTag || this.options.multiLineParagraph) {
return startParaTag + html + endParaTag;
}
return (startParaTag +
html
.split(BrTag)
.map(function (v) {
return v === '' ? BrTag : v;
})
.join(endParaTag + startParaTag) +
endParaTag);
};
QuillDeltaToHtmlConverter.prototype._renderInline = function (op, contextOp) {
if (op.isCustomEmbed()) {
return this._renderCustom(op, contextOp);
}
var converter = new OpToHtmlConverter_1.OpToHtmlConverter(op, this.converterOptions);
return converter.getHtml().replace(/\n/g, BrTag);
};
QuillDeltaToHtmlConverter.prototype._renderCustom = function (op, contextOp) {
var renderCb = this.callbacks['renderCustomOp_cb'];
if (typeof renderCb === 'function') {
return renderCb.apply(null, [op, contextOp]);
}
return '';
};
QuillDeltaToHtmlConverter.prototype.beforeRender = function (cb) {
if (typeof cb === 'function') {
this.callbacks['beforeRender_cb'] = cb;
}
};
QuillDeltaToHtmlConverter.prototype.afterRender = function (cb) {
if (typeof cb === 'function') {
this.callbacks['afterRender_cb'] = cb;
}
};
QuillDeltaToHtmlConverter.prototype.renderCustomWith = function (cb) {
this.callbacks['renderCustomOp_cb'] = cb;
};
return QuillDeltaToHtmlConverter;
}());
exports.QuillDeltaToHtmlConverter = QuillDeltaToHtmlConverter;
},{"./InsertOpsConverter":4,"./OpToHtmlConverter":7,"./funcs-html":9,"./grouper/Grouper":10,"./grouper/ListNester":11,"./grouper/TableGrouper":12,"./grouper/group-types":13,"./helpers/object":15,"./value-types":19}],9:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var EncodeTarget;
(function (EncodeTarget) {
EncodeTarget[EncodeTarget["Html"] = 0] = "Html";
EncodeTarget[EncodeTarget["Url"] = 1] = "Url";
})(EncodeTarget || (EncodeTarget = {}));
function makeStartTag(tag, attrs) {
if (attrs === void 0) { attrs = undefined; }
if (!tag) {
return '';
}
var attrsStr = '';
if (attrs) {
var arrAttrs = [].concat(attrs);
attrsStr = arrAttrs
.map(function (attr) {
return attr.key + (attr.value ? '="' + attr.value + '"' : '');
})
.join(' ');
}
var closing = '>';
if (tag === 'img' || tag === 'br') {
closing = '/>';
}
return attrsStr ? "<" + tag + " " + attrsStr + closing : "<" + tag + closing;
}
exports.makeStartTag = makeStartTag;
function makeEndTag(tag) {
if (tag === void 0) { tag = ''; }
return (tag && "</" + tag + ">") || '';
}
exports.makeEndTag = makeEndTag;
function decodeHtml(str) {
return encodeMappings(EncodeTarget.Html).reduce(decodeMapping, str);
}
exports.decodeHtml = decodeHtml;
function encodeHtml(str, preventDoubleEncoding) {
if (preventDoubleEncoding === void 0) { preventDoubleEncoding = true; }
if (preventDoubleEncoding) {
str = decodeHtml(str);
}
return encodeMappings(EncodeTarget.Html).reduce(encodeMapping, str);
}
exports.encodeHtml = encodeHtml;
function encodeLink(str) {
var linkMaps = encodeMappings(EncodeTarget.Url);
var decoded = linkMaps.reduce(decodeMapping, str);
return linkMaps.reduce(encodeMapping, decoded);
}
exports.encodeLink = encodeLink;
function encodeMappings(mtype) {
var maps = [
['&', '&'],
['<', '<'],
['>', '>'],
['"', '"'],
["'", '''],
['\\/', '/'],
['\\(', '('],
['\\)', ')'],
];
if (mtype === EncodeTarget.Html) {
return maps.filter(function (_a) {
var v = _a[0], _ = _a[1];
return v.indexOf('(') === -1 && v.indexOf(')') === -1;
});
}
else {
return maps.filter(function (_a) {
var v = _a[0], _ = _a[1];
return v.indexOf('/') === -1;
});
}
}
function encodeMapping(str, mapping) {
return str.replace(new RegExp(mapping[0], 'g'), mapping[1]);
}
function decodeMapping(str, mapping) {
return str.replace(new RegExp(mapping[1], 'g'), mapping[0].replace('\\', ''));
}
},{}],10:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var DeltaInsertOp_1 = require("./../DeltaInsertOp");
var array_1 = require("./../helpers/array");
var group_types_1 = require("./group-types");
var Grouper = (function () {
function Grouper() {
}
Grouper.pairOpsWithTheirBlock = function (ops) {
var result = [];
var canBeInBlock = function (op) {
return !(op.isJustNewline() ||
op.isCustomEmbedBlock() ||
op.isVideo() ||
op.isContainerBlock());
};
var isInlineData = function (op) { return op.isInline(); };
var lastInd = ops.length - 1;
var opsSlice;
for (var i = lastInd; i >= 0; i--) {
var op = ops[i];
if (op.isVideo()) {
result.push(new group_types_1.VideoItem(op));
}
else if (op.isCustomEmbedBlock()) {
result.push(new group_types_1.BlotBlock(op));
}
else if (op.isContainerBlock()) {
opsSlice = array_1.sliceFromReverseWhile(ops, i - 1, canBeInBlock);
result.push(new group_types_1.BlockGroup(op, opsSlice.elements));
i = opsSlice.sliceStartsAt > -1 ? opsSlice.sliceStartsAt : i;
}
else {
opsSlice = array_1.sliceFromReverseWhile(ops, i - 1, isInlineData);
result.push(new group_types_1.InlineGroup(opsSlice.elements.concat(op)));
i = opsSlice.sliceStartsAt > -1 ? opsSlice.sliceStartsAt : i;
}
}
result.reverse();
return result;
};
Grouper.groupConsecutiveSameStyleBlocks = function (groups, blocksOf) {
if (blocksOf === void 0) { blocksOf = {
header: true,
codeBlocks: true,
blockquotes: true,
customBlocks: true,
}; }
return array_1.groupConsecutiveElementsWhile(groups, function (g, gPrev) {
if (!(g instanceof group_types_1.BlockGroup) || !(gPrev instanceof group_types_1.BlockGroup)) {
return false;
}
return ((blocksOf.codeBlocks &&
Grouper.areBothCodeblocksWithSameLang(g, gPrev)) ||
(blocksOf.blockquotes &&
Grouper.areBothBlockquotesWithSameAdi(g, gPrev)) ||
(blocksOf.header &&
Grouper.areBothSameHeadersWithSameAdi(g, gPrev)) ||
(blocksOf.customBlocks &&
Grouper.areBothCustomBlockWithSameAttr(g, gPrev)));
});
};
Grouper.reduceConsecutiveSameStyleBlocksToOne = function (groups) {
var newLineOp = DeltaInsertOp_1.DeltaInsertOp.createNewLineOp();
return groups.map(function (elm) {
if (!Array.isArray(elm)) {
if (elm instanceof group_types_1.BlockGroup && !elm.ops.length) {
elm.ops.push(newLineOp);
}
return elm;
}
var groupsLastInd = elm.length - 1;
elm[0].ops = array_1.flatten(elm.map(function (g, i) {
if (!g.ops.length) {
return [newLineOp];
}
return g.ops.concat(i < groupsLastInd ? [newLineOp] : []);
}));
return elm[0];
});
};
Grouper.areBothCodeblocksWithSameLang = function (g1, gOther) {
return (g1.op.isCodeBlock() &&
gOther.op.isCodeBlock() &&
g1.op.hasSameLangAs(gOther.op));
};
Grouper.areBothSameHeadersWithSameAdi = function (g1, gOther) {
return g1.op.isSameHeaderAs(gOther.op) && g1.op.hasSameAdiAs(gOther.op);
};
Grouper.areBothBlockquotesWithSameAdi = function (g, gOther) {
return (g.op.isBlockquote() &&
gOther.op.isBlockquote() &&
g.op.hasSameAdiAs(gOther.op));
};
Grouper.areBothCustomBlockWithSameAttr = function (g, gOther) {
return (g.op.isCustomTextBlock() &&
gOther.op.isCustomTextBlock() &&
g.op.hasSameAttr(gOther.op));
};
return Grouper;
}());
exports.Grouper = Grouper;
},{"./../DeltaInsertOp":1,"./../helpers/array":14,"./group-types":13}],11:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var group_types_1 = require("./group-types");
var array_1 = require("./../helpers/array");
var ListNester = (function () {
function ListNester() {
}
ListNester.prototype.nest = function (groups) {
var _this = this;
var listBlocked = this.convertListBlocksToListGroups(groups);
var groupedByListGroups = this.groupConsecutiveListGroups(listBlocked);
var nested = array_1.flatten(groupedByListGroups.map(function (group) {
if (!Array.isArray(group)) {
return group;
}
return _this.nestListSection(group);
}));
var groupRootLists = array_1.groupConsecutiveElementsWhile(nested, function (curr, prev) {
if (!(curr instanceof group_types_1.ListGroup && prev instanceof group_types_1.ListGroup)) {
return false;
}
return curr.items[0].item.op.isSameListAs(prev.items[0].item.op);
});
return groupRootLists.map(function (v) {
if (!Array.isArray(v)) {
return v;
}
var litems = v.map(function (g) { return g.items; });
return new group_types_1.ListGroup(array_1.flatten(litems));
});
};
ListNester.prototype.convertListBlocksToListGroups = function (items) {
var grouped = array_1.groupConsecutiveElementsWhile(items, function (g, gPrev) {
return (g instanceof group_types_1.BlockGroup &&
gPrev instanceof group_types_1.BlockGroup &&
g.op.isList() &&
gPrev.op.isList() &&
g.op.isSameListAs(gPrev.op) &&
g.op.hasSameIndentationAs(gPrev.op));
});
return grouped.map(function (item) {
if (!Array.isArray(item)) {
if (item instanceof group_types_1.BlockGroup && item.op.isList()) {
return new group_types_1.ListGroup([new group_types_1.ListItem(item)]);
}
return item;
}
return new group_types_1.ListGroup(item.map(function (g) { return new group_types_1.ListItem(g); }));
});
};
ListNester.prototype.groupConsecutiveListGroups = function (items) {
return array_1.groupConsecutiveElementsWhile(items, function (curr, prev) {
return curr instanceof group_types_1.ListGroup && prev instanceof group_types_1.ListGroup;
});
};
ListNester.prototype.nestListSection = function (sectionItems) {
var _this = this;
var indentGroups = this.groupByIndent(sectionItems);
Object.keys(indentGroups)
.map(Number)
.sort()
.reverse()
.forEach(function (indent) {
indentGroups[indent].forEach(function (lg) {
var idx = sectionItems.indexOf(lg);
if (_this.placeUnderParent(lg, sectionItems.slice(0, idx))) {
sectionItems.splice(idx, 1);
}
});
});
return sectionItems;
};
ListNester.prototype.groupByIndent = function (items) {
return items.reduce(function (pv, cv) {
var indent = cv.items[0].item.op.attributes.indent;
if (indent) {
pv[indent] = pv[indent] || [];
pv[indent].push(cv);
}
return pv;
}, {});
};
ListNester.prototype.placeUnderParent = function (target, items) {
for (var i = items.length - 1; i >= 0; i--) {
var elm = items[i];
if (target.items[0].item.op.hasHigherIndentThan(elm.items[0].item.op)) {
var parent = elm.items[elm.items.length - 1];
if (parent.innerList) {
parent.innerList.items = parent.innerList.items.concat(target.items);
}
else {
parent.innerList = target;
}
return true;
}
}
return false;
};
return ListNester;
}());
exports.ListNester = ListNester;
},{"./../helpers/array":14,"./group-types":13}],12:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var group_types_1 = require("./group-types");
var array_1 = require("../helpers/array");
var TableGrouper = (function () {
function TableGrouper() {
}
TableGrouper.prototype.group = function (groups) {
var tableBlocked = this.convertTableBlocksToTableGroups(groups);
return tableBlocked;
};
TableGrouper.prototype.convertTableBlocksToTableGroups = function (items) {
var _this = this;
var grouped = array_1.groupConsecutiveElementsWhile(items, function (g, gPrev) {
return (g instanceof group_types_1.BlockGroup &&
gPrev instanceof group_types_1.BlockGroup &&
g.op.isTable() &&
gPrev.op.isTable());
});
return grouped.map(function (item) {
if (!Array.isArray(item)) {
if (item instanceof group_types_1.BlockGroup && item.op.isTable()) {
return new group_types_1.TableGroup([new group_types_1.TableRow([new group_types_1.TableCell(item)])]);
}
return item;
}
return new group_types_1.TableGroup(_this.convertTableBlocksToTableRows(item));
});
};
TableGrouper.prototype.convertTableBlocksToTableRows = function (items) {
var grouped = array_1.groupConsecutiveElementsWhile(items, function (g, gPrev) {
return (g instanceof group_types_1.BlockGroup &&
gPrev instanceof group_types_1.BlockGroup &&
g.op.isTable() &&
gPrev.op.isTable() &&
g.op.isSameTableRowAs(gPrev.op));
});
return grouped.map(function (item) {
return new group_types_1.TableRow(Array.isArray(item)
? item.map(function (it) { return new group_types_1.TableCell(it); })
: [new group_types_1.TableCell(item)]);
});
};
return TableGrouper;
}());
exports.TableGrouper = TableGrouper;
},{"../helpers/array":14,"./group-types":13}],13:[function(require,module,exports){
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var InlineGroup = (function () {
function InlineGroup(ops) {
this.ops = ops;
}
return InlineGroup;
}());
exports.InlineGroup = InlineGroup;
var SingleItem = (function () {
function SingleItem(op) {
this.op = op;
}
return SingleItem;
}());
var VideoItem = (function (_super) {
__extends(VideoItem, _super);
function VideoItem() {
return _super !== null && _super.apply(this, arguments) || this;
}
return VideoItem;
}(SingleItem));
exports.VideoItem = VideoItem;
var BlotBlock = (function (_super) {
__extends(BlotBlock, _super);
function BlotBlock() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BlotBlock;
}(SingleItem));
exports.BlotBlock = BlotBlock;
var BlockGroup = (function () {
function BlockGroup(op, ops) {
this.op = op;
this.ops = ops;
}
return BlockGroup;
}());
exports.BlockGroup = BlockGroup;
var ListGroup = (function () {
function ListGroup(items) {
this.items = items;
}
return ListGroup;
}());
exports.ListGroup = ListGroup;
var ListItem = (function () {
function ListItem(item, innerList) {
if (innerList === void 0) { innerList = null; }
this.item = item;
this.innerList = innerList;
}
return ListItem;
}());
exports.ListItem = ListItem;
var TableGroup = (function () {
function TableGroup(rows) {
this.rows = rows;
}
return TableGroup;
}());
exports.TableGroup = TableGroup;
var TableRow = (function () {
function TableRow(cells) {
this.cells = cells;
}
return TableRow;
}());
exports.TableRow = TableRow;
var TableCell = (function () {
function TableCell(item) {
this.item = item;
}
return TableCell;
}());
exports.TableCell = TableCell;
},{}],14:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function preferSecond(arr) {
if (arr.length === 0) {
return null;
}
return arr.length >= 2 ? arr[1] : arr[0];
}
exports.preferSecond = preferSecond;
function flatten(arr) {
return arr.reduce(function (pv, v) {
return pv.concat(Array.isArray(v) ? flatten(v) : v);
}, []);
}
exports.flatten = flatten;
function find(arr, predicate) {
if (Array.prototype.find) {
return Array.prototype.find.call(arr, predicate);
}
for (var i = 0; i < arr.length; i++) {
if (predicate(arr[i]))
return arr[i];
}
return undefined;
}
exports.find = find;
function groupConsecutiveElementsWhile(arr, predicate) {
var groups = [];
var currElm, currGroup;
for (var i = 0; i < arr.length; i++) {
currElm = arr[i];
if (i > 0 && predicate(currElm, arr[i - 1])) {
currGroup = groups[groups.length - 1];
currGroup.push(currElm);
}
else {
groups.push([currElm]);
}
}
return groups.map(function (g) { return (g.length === 1 ? g[0] : g); });
}
exports.groupConsecutiveElementsWhile = groupConsecutiveElementsWhile;
function sliceFromReverseWhile(arr, startIndex, predicate) {
var result = {
elements: [],
sliceStartsAt: -1,
};
for (var i = startIndex; i >= 0; i--) {
if (!predicate(arr[i])) {
break;
}
result.sliceStartsAt = i;
result.elements.unshift(arr[i]);
}
return result;
}
exports.sliceFromReverseWhile = sliceFromReverseWhile;
function intersperse(arr, item) {
return arr.reduce(function (pv, v, index) {
pv.push(v);
if (index < arr.length - 1) {
pv.push(item);
}
return pv;
}, []);
}
exports.intersperse = intersperse;
},{}],15:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function assign(target) {
var sources = [];
for (var _i = 1; _i < arguments.length; _i++) {
sources[_i - 1] = arguments[_i];
}
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 0; index < sources.length; index++) {
var nextSource = sources[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
}
exports.assign = assign;
},{}],16:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function tokenizeWithNewLines(str) {
var NewLine = '\n';
if (str === NewLine) {
return [str];
}
var lines = str.split(NewLine);
if (lines.length === 1) {
return lines;
}
var lastIndex = lines.length - 1;
return lines.reduce(function (pv, line, ind) {
if (ind !== lastIndex) {
if (line !== '') {
pv = pv.concat(line, NewLine);
}
else {
pv.push(NewLine);
}
}
else if (line !== '') {
pv.push(line);
}
return pv;
}, []);
}
exports.tokenizeWithNewLines = tokenizeWithNewLines;
},{}],17:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function sanitize(str) {
var val = str;
val = val.replace(/^\s*/gm, '');
var whiteList = /^((https?|s?ftp|file|blob|mailto|tel):|#|\/|data:image\/)/;
if (whiteList.test(val)) {
return val;
}
return 'unsafe:' + val;
}
exports.sanitize = sanitize;
},{}],18:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var OpLinkSanitizer_1 = require("../OpLinkSanitizer");
var MentionSanitizer = (function () {
function MentionSanitizer() {
}
MentionSanitizer.sanitize = function (dirtyObj, sanitizeOptions) {
var cleanObj = {};
if (!dirtyObj || typeof dirtyObj !== 'object') {
return cleanObj;
}
if (dirtyObj.class && MentionSanitizer.IsValidClass(dirtyObj.class)) {
cleanObj.class = dirtyObj.class;
}
if (dirtyObj.id && MentionSanitizer.IsValidId(dirtyObj.id)) {
cleanObj.id = dirtyObj.id;
}
if (MentionSanitizer.IsValidTarget(dirtyObj.target + '')) {
cleanObj.target = dirtyObj.target;
}
if (dirtyObj.avatar) {
cleanObj.avatar = OpLinkSanitizer_1.OpLinkSanitizer.sanitize(dirtyObj.avatar + '', sanitizeOptions);
}
if (dirtyObj['end-point']) {
cleanObj['end-point'] = OpLinkSanitizer_1.OpLinkSanitizer.sanitize(dirtyObj['end-point'] + '', sanitizeOptions);
}
if (dirtyObj.slug) {
cleanObj.slug = dirtyObj.slug + '';
}
return cleanObj;
};
MentionSanitizer.IsValidClass = function (classAttr) {
return !!classAttr.match(/^[a-zA-Z0-9_\-]{1,500}$/i);
};
MentionSanitizer.IsValidId = function (idAttr) {
return !!idAttr.match(/^[a-zA-Z0-9_\-\:\.]{1,500}$/i);
};
MentionSanitizer.IsValidTarget = function (target) {
return ['_self', '_blank', '_parent', '_top'].indexOf(target) > -1;
};
return MentionSanitizer;
}());
exports.MentionSanitizer = MentionSanitizer;
},{"../OpLinkSanitizer":6}],19:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var NewLine = '\n';
exports.NewLine = NewLine;
var ListType;
(function (ListType) {
ListType["Ordered"] = "ordered";
ListType["Bullet"] = "bullet";
ListType["Checked"] = "checked";
ListType["Unchecked"] = "unchecked";
})(ListType || (ListType = {}));
exports.ListType = ListType;
var ScriptType;
(function (ScriptType) {
ScriptType["Sub"] = "sub";
ScriptType["Super"] = "super";
})(ScriptType || (ScriptType = {}));
exports.ScriptType = ScriptType;
var DirectionType;
(function (DirectionType) {
DirectionType["Rtl"] = "rtl";
})(DirectionType || (DirectionType = {}));
exports.DirectionType = DirectionType;
var AlignType;
(function (AlignType) {
AlignType["Left"] = "left";
AlignType["Center"] = "center";
AlignType["Right"] = "right";
AlignType["Justify"] = "justify";
})(AlignType || (AlignType = {}));
exports.AlignType = AlignType;
var DataType;
(function (DataType) {
DataType["Image"] = "image";
DataType["Video"] = "video";
DataType["Formula"] = "formula";
DataType["Text"] = "text";
})(DataType || (DataType = {}));
exports.DataType = DataType;
var GroupType;
(function (GroupType) {
GroupType["Block"] = "block";
GroupType["InlineGroup"] = "inline-group";
GroupType["List"] = "list";
GroupType["Video"] = "video";
GroupType["Table"] = "table";
})(GroupType || (GroupType = {}));
exports.GroupType = GroupType;
},{}],20:[function(require,module,exports){
(function (global){
/**
* Lodash (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright JS Foundation and other contributors <https://js.foundation/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED = '__lodash_hash_undefined__';
/** Used to compose bitmasks for value comparisons. */
var COMPARE_PARTIAL_FLAG = 1,
COMPARE_UNORDERED_FLAG = 2;
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;
/** `Object#toString` result references. */
var argsTag = '[object Arguments]',
arrayTag = '[object Array]',
asyncTag = '[object AsyncFunction]',
boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
mapTag = '[object Map]',
numberTag = '[object Number]',
nullTag = '[object Null]',
objectTag = '[object Object]',
promiseTag = '[object Promise]',
proxyTag = '[object Proxy]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
symbolTag = '[object Symbol]',
undefinedTag = '[object Undefined]',
weakMapTag = '[object WeakMap]';
var arrayBufferTag = '[object ArrayBuffer]',
dataViewTag = '[object DataView]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]';
/**
* Used to match `RegExp`
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
*/
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
/** Used to detect host constructors (Safari). */
var reIsHostCtor = /^\[object .+?Constructor\]$/;
/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/** Used to identify `toStringTag` values of typed arrays. */
var typedArrayTags = {};
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
typedArrayTags[uint32Tag] = true;
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
typedArrayTags[errorTag] = typedArrayTags[funcTag] =
typedArrayTags[mapTag] = typedArrayTags[numberTag] =
typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
typedArrayTags[setTag] = typedArrayTags[stringTag] =
typedArrayTags[weakMapTag] = false;
/** Detect free variable `global` from Node.js. */
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
/** Detect free variable `self`. */
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
/** Used as a reference to the global object. */
var root = freeGlobal || freeSelf || Function('return this')();
/** Detect free variable `exports`. */
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
/** Detect free variable `module`. */
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
/** Detect the popular CommonJS extension `module.exports`. */
var moduleExports = freeModule && freeModule.exports === freeExports;
/** Detect free variable `process` from Node.js. */
var freeProcess = moduleExports && freeGlobal.process;
/** Used to access faster Node.js helpers. */
var nodeUtil = (function() {
try {
return freeProcess && freeProcess.binding && freeProcess.binding('util');
} catch (e) {}
}());
/* Node.js helper references. */
var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
/**
* A specialized version of `_.filter` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
*/
function arrayFilter(array, predicate) {
var index = -1,
length = array == null ? 0 : array.length,
resIndex = 0,
result = [];
while (++index < length) {
var value = array[index];
if (predicate(value, index, array)) {
result[resIndex++] = value;
}
}
return result;
}
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
}
/**
* A specialized version of `_.some` for arrays without support for iteratee
* shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
*/
function arraySome(array, predicate) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (predicate(array[index], index, array)) {
return true;
}
}
return false;
}
/**
* The base implementation of `_.times` without support for iteratee shorthands
* or max array length checks.
*
* @private
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the array of results.
*/
function baseTimes(n, iteratee) {
var index = -1,
result = Array(n);
while (++index < n) {
result[index] = iteratee(index);
}
return result;
}
/**
* The base implementation of `_.unary` without support for storing metadata.
*
* @private
* @param {Function} func The function to cap arguments for.
* @returns {Function} Returns the new capped function.
*/
function baseUnary(func) {
return function(value) {
return func(value);
};
}
/**
* Checks if a `cache` value for `key` exists.
*
* @private
* @param {Object} cache The cache to query.
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function cacheHas(cache, key) {
return cache.has(key);
}
/**
* Gets the value at `key` of `object`.
*
* @private
* @param {Object} [object] The object to query.
* @param {string} key The key of the property to get.
* @returns {*} Returns the property value.
*/
function getValue(object, key) {
return object == null ? undefined : object[key];
}
/**
* Converts `map` to its key-value pairs.
*
* @private
* @param {Object} map The map to convert.
* @returns {Array} Returns the key-value pairs.
*/
function mapToArray(map) {
var index = -1,
result = Array(map.size);
map.forEach(function(value, key) {
result[++index] = [key, value];
});
return result;
}
/**
* Creates a unary function that invokes `func` with its argument transformed.
*
* @private
* @param {Function} func The function to wrap.
* @param {Function} transform The argument transform.
* @returns {Function} Returns the new function.
*/
function overArg(func, transform) {
return function(arg) {
return func(transform(arg));
};
}
/**
* Converts `set` to an array of its values.
*
* @private
* @param {Object} set The set to convert.
* @returns {Array} Returns the values.
*/
function setToArray(set) {
var index = -1,
result = Array(set.size);
set.forEach(function(value) {
result[++index] = value;
});
return result;
}
/** Used for built-in method references. */
var arrayProto = Array.prototype,
funcProto = Function.prototype,
objectProto = Object.prototype;
/** Used to detect overreaching core-js shims. */
var coreJsData = root['__core-js_shared__'];
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to detect methods masquerading as native. */
var maskSrcKey = (function() {
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
return uid ? ('Symbol(src)_1.' + uid) : '';
}());
/**
* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* of values.
*/
var nativeObjectToString = objectProto.toString;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
);
/** Built-in value references. */
var Buffer = moduleExports ? root.Buffer : undefined,
Symbol = root.Symbol,
Uint8Array = root.Uint8Array,
propertyIsEnumerable = objectProto.propertyIsEnumerable,
splice = arrayProto.splice,
symToStringTag = Symbol ? Symbol.toStringTag : undefined;
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetSymbols = Object.getOwnPropertySymbols,
nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
nativeKeys = overArg(Object.keys, Object);
/* Built-in method references that are verified to be native. */
var DataView = getNative(root, 'DataView'),
Map = getNative(root, 'Map'),
Promise = getNative(root, 'Promise'),
Set = getNative(root, 'Set'),
WeakMap = getNative(root, 'WeakMap'),
nativeCreate = getNative(Object, 'create');
/** Used to detect maps, sets, and weakmaps. */
var dataViewCtorString = toSource(DataView),
mapCtorString = toSource(Map),
promiseCtorString = toSource(Promise),
setCtorString = toSource(Set),
weakMapCtorString = toSource(WeakMap);
/** Used to convert symbols to primitives and strings. */
var symbolProto = Symbol ? Symbol.prototype : undefined,
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
/**
* Creates a hash object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Hash(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the hash.
*
* @private
* @name clear
* @memberOf Hash
*/
function hashClear() {
this.__data__ = nativeCreate ? nativeCreate(null) : {};
this.size = 0;
}
/**
* Removes `key` and its value from the hash.
*
* @private
* @name delete
* @memberOf Hash
* @param {Object} hash The hash to modify.
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function hashDelete(key) {
var result = this.has(key) && delete this.__data__[key];
this.size -= result ? 1 : 0;
return result;
}
/**
* Gets the hash value for `key`.
*
* @private
* @name get
* @memberOf Hash
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function hashGet(key) {
var data = this.__data__;
if (nativeCreate) {
var result = data[key];
return result === HASH_UNDEFINED ? undefined : result;
}
return hasOwnProperty.call(data, key) ? data[key] : undefined;
}
/**
* Checks if a hash value for `key` exists.
*
* @private
* @name has
* @memberOf Hash
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function hashHas(key) {
var data = this.__data__;
return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
}
/**
* Sets the hash `key` to `value`.
*
* @private
* @name set
* @memberOf Hash
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the hash instance.
*/
function hashSet(key, value) {
var data = this.__data__;
this.size += this.has(key) ? 0 : 1;
data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
return this;
}
// Add methods to `Hash`.
Hash.prototype.clear = hashClear;
Hash.prototype['delete'] = hashDelete;
Hash.prototype.get = hashGet;
Hash.prototype.has = hashHas;
Hash.prototype.set = hashSet;
/**
* Creates an list cache object.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function ListCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the list cache.
*
* @private
* @name clear
* @memberOf ListCache
*/
function listCacheClear() {
this.__data__ = [];
this.size = 0;
}
/**
* Removes `key` and its value from the list cache.
*
* @private
* @name delete
* @memberOf ListCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function listCacheDelete(key) {
var data = this.__data__,
index = assocIndexOf(data, key);
if (index < 0) {
return false;
}
var lastIndex = data.length - 1;
if (index == lastIndex) {
data.pop();
} else {
splice.call(data, index, 1);
}
--this.size;
return true;
}
/**
* Gets the list cache value for `key`.
*
* @private
* @name get
* @memberOf ListCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function listCacheGet(key) {
var data = this.__data__,
index = assocIndexOf(data, key);
return index < 0 ? undefined : data[index][1];
}
/**
* Checks if a list cache value for `key` exists.
*
* @private
* @name has
* @memberOf ListCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function listCacheHas(key) {
return assocIndexOf(this.__data__, key) > -1;
}
/**
* Sets the list cache `key` to `value`.
*
* @private
* @name set
* @memberOf ListCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the list cache instance.
*/
function listCacheSet(key, value) {
var data = this.__data__,
index = assocIndexOf(data, key);
if (index < 0) {
++this.size;
data.push([key, value]);
} else {
data[index][1] = value;
}
return this;
}
// Add methods to `ListCache`.
ListCache.prototype.clear = listCacheClear;
ListCache.prototype['delete'] = listCacheDelete;
ListCache.prototype.get = listCacheGet;
ListCache.prototype.has = listCacheHas;
ListCache.prototype.set = listCacheSet;
/**
* Creates a map cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function MapCache(entries) {
var index = -1,
length = entries == null ? 0 : entries.length;
this.clear();
while (++index < length) {
var entry = entries[index];
this.set(entry[0], entry[1]);
}
}
/**
* Removes all key-value entries from the map.
*
* @private
* @name clear
* @memberOf MapCache
*/
function mapCacheClear() {
this.size = 0;
this.__data__ = {
'hash': new Hash,
'map': new (Map || ListCache),
'string': new Hash
};
}
/**
* Removes `key` and its value from the map.
*
* @private
* @name delete
* @memberOf MapCache
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function mapCacheDelete(key) {
var result = getMapData(this, key)['delete'](key);
this.size -= result ? 1 : 0;
return result;
}
/**
* Gets the map value for `key`.
*
* @private
* @name get
* @memberOf MapCache
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function mapCacheGet(key) {
return getMapData(this, key).get(key);
}
/**
* Checks if a map value for `key` exists.
*
* @private
* @name has
* @memberOf MapCache
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function mapCacheHas(key) {
return getMapData(this, key).has(key);
}
/**
* Sets the map `key` to `value`.
*
* @private
* @name set
* @memberOf MapCache
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the map cache instance.
*/
function mapCacheSet(key, value) {
var data = getMapData(this, key),
size = data.size;
data.set(key, value);
this.size += data.size == size ? 0 : 1;
return this;
}
// Add methods to `MapCache`.
MapCache.prototype.clear = mapCacheClear;
MapCache.prototype['delete'] = mapCacheDelete;
MapCache.prototype.get = mapCacheGet;
MapCache.prototype.has = mapCacheHas;
MapCache.prototype.set = mapCacheSet;
/**
*
* Creates an array cache object to store unique values.
*
* @private
* @constructor
* @param {Array} [values] The values to cache.
*/
function SetCache(values) {
var index = -1,
length = values == null ? 0 : values.length;
this.__data__ = new MapCache;
while (++index < length) {
this.add(values[index]);
}
}
/**
* Adds `value` to the array cache.
*
* @private
* @name add
* @memberOf SetCache
* @alias push
* @param {*} value The value to cache.
* @returns {Object} Returns the cache instance.
*/
function setCacheAdd(value) {
this.__data__.set(value, HASH_UNDEFINED);
return this;
}
/**
* Checks if `value` is in the array cache.
*
* @private
* @name has
* @memberOf SetCache
* @param {*} value The value to search for.
* @returns {number} Returns `true` if `value` is found, else `false`.
*/
function setCacheHas(value) {
return this.__data__.has(value);
}
// Add methods to `SetCache`.
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
SetCache.prototype.has = setCacheHas;
/**
* Creates a stack cache object to store key-value pairs.
*
* @private
* @constructor
* @param {Array} [entries] The key-value pairs to cache.
*/
function Stack(entries) {
var data = this.__data__ = new ListCache(entries);
this.size = data.size;
}
/**
* Removes all key-value entries from the stack.
*
* @private
* @name clear
* @memberOf Stack
*/
function stackClear() {
this.__data__ = new ListCache;
this.size = 0;
}
/**
* Removes `key` and its value from the stack.
*
* @private
* @name delete
* @memberOf Stack
* @param {string} key The key of the value to remove.
* @returns {boolean} Returns `true` if the entry was removed, else `false`.
*/
function stackDelete(key) {
var data = this.__data__,
result = data['delete'](key);
this.size = data.size;
return result;
}
/**
* Gets the stack value for `key`.
*
* @private
* @name get
* @memberOf Stack
* @param {string} key The key of the value to get.
* @returns {*} Returns the entry value.
*/
function stackGet(key) {
return this.__data__.get(key);
}
/**
* Checks if a stack value for `key` exists.
*
* @private
* @name has
* @memberOf Stack
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function stackHas(key) {
return this.__data__.has(key);
}
/**
* Sets the stack `key` to `value`.
*
* @private
* @name set
* @memberOf Stack
* @param {string} key The key of the value to set.
* @param {*} value The value to set.
* @returns {Object} Returns the stack cache instance.
*/
function stackSet(key, value) {
var data = this.__data__;
if (data instanceof ListCache) {
var pairs = data.__data__;
if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
pairs.push([key, value]);
this.size = ++data.size;
return this;
}
data = this.__data__ = new MapCache(pairs);
}
data.set(key, value);
this.size = data.size;
return this;
}
// Add methods to `Stack`.
Stack.prototype.clear = stackClear;
Stack.prototype['delete'] = stackDelete;
Stack.prototype.get = stackGet;
Stack.prototype.has = stackHas;
Stack.prototype.set = stackSet;
/**
* Creates an array of the enumerable property names of the array-like `value`.
*
* @private
* @param {*} value The value to query.
* @param {boolean} inherited Specify returning inherited property names.
* @returns {Array} Returns the array of property names.
*/
function arrayLikeKeys(value, inherited) {
var isArr = isArray(value),
isArg = !isArr && isArguments(value),
isBuff = !isArr && !isArg && isBuffer(value),
isType = !isArr && !isArg && !isBuff && isTypedArray(value),
skipIndexes = isArr || isArg || isBuff || isType,
result = skipIndexes ? baseTimes(value.length, String) : [],
length = result.length;
for (var key in value) {
if ((inherited || hasOwnProperty.call(value, key)) &&
!(skipIndexes && (
// Safari 9 has enumerable `arguments.length` in strict mode.
key == 'length' ||
// Node.js 0.10 has enumerable non-index properties on buffers.
(isBuff && (key == 'offset' || key == 'parent')) ||
// PhantomJS 2 has enumerable non-index properties on typed arrays.
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
// Skip index properties.
isIndex(key, length)
))) {
result.push(key);
}
}
return result;
}
/**
* Gets the index at which the `key` is found in `array` of key-value pairs.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} key The key to search for.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function assocIndexOf(array, key) {
var length = array.length;
while (length--) {
if (eq(array[length][0], key)) {
return length;
}
}
return -1;
}
/**
* The base implementation of `getAllKeys` and `getAllKeysIn` which uses
* `keysFunc` and `symbolsFunc` to get the enumerable property names and
* symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Function} keysFunc The function to get the keys of `object`.
* @param {Function} symbolsFunc The function to get the symbols of `object`.
* @returns {Array} Returns the array of property names and symbols.
*/
function baseGetAllKeys(object, keysFunc, symbolsFunc) {
var result = keysFunc(object);
return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
}
/**
* The base implementation of `getTag` without fallbacks for buggy environments.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
function baseGetTag(value) {
if (value == null) {
return value === undefined ? undefinedTag : nullTag;
}
return (symToStringTag && symToStringTag in Object(value))
? getRawTag(value)
: objectToString(value);
}
/**
* The base implementation of `_.isArguments`.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
*/
function baseIsArguments(value) {
return isObjectLike(value) && baseGetTag(value) == argsTag;
}
/**
* The base implementation of `_.isEqual` which supports partial comparisons
* and tracks traversed objects.
*
* @private
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @param {boolean} bitmask The bitmask flags.
* 1 - Unordered comparison
* 2 - Partial comparison
* @param {Function} [customizer] The function to customize comparisons.
* @param {Object} [stack] Tracks traversed `value` and `other` objects.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
*/
function baseIsEqual(value, other, bitmask, customizer, stack) {
if (value === other) {
return true;
}
if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
}
/**
* A specialized version of `baseIsEqual` for arrays and objects which performs
* deep comparisons and tracks traversed objects enabling objects with circular
* references to be compared.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} [stack] Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
var objIsArr = isArray(object),
othIsArr = isArray(other),
objTag = objIsArr ? arrayTag : getTag(object),
othTag = othIsArr ? arrayTag : getTag(other);
objTag = objTag == argsTag ? objectTag : objTag;
othTag = othTag == argsTag ? objectTag : othTag;
var objIsObj = objTag == objectTag,
othIsObj = othTag == objectTag,
isSameTag = objTag == othTag;
if (isSameTag && isBuffer(object)) {
if (!isBuffer(other)) {
return false;
}
objIsArr = true;
objIsObj = false;
}
if (isSameTag && !objIsObj) {
stack || (stack = new Stack);
return (objIsArr || isTypedArray(object))
? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
: equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
}
if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (objIsWrapped || othIsWrapped) {
var objUnwrapped = objIsWrapped ? object.value() : object,
othUnwrapped = othIsWrapped ? other.value() : other;
stack || (stack = new Stack);
return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
}
}
if (!isSameTag) {
return false;
}
stack || (stack = new Stack);
return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
}
/**
* The base implementation of `_.isNative` without bad shim checks.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a native function,
* else `false`.
*/
function baseIsNative(value) {
if (!isObject(value) || isMasked(value)) {
return false;
}
var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
return pattern.test(toSource(value));
}
/**
* The base implementation of `_.isTypedArray` without Node.js optimizations.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
*/
function baseIsTypedArray(value) {
return isObjectLike(value) &&
isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
}
/**
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
if (!isPrototype(object)) {
return nativeKeys(object);
}
var result = [];
for (var key in Object(object)) {
if (hasOwnProperty.call(object, key) && key != 'constructor') {
result.push(key);
}
}
return result;
}
/**
* A specialized version of `baseIsEqualDeep` for arrays with support for
* partial deep comparisons.
*
* @private
* @param {Array} array The array to compare.
* @param {Array} other The other array to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `array` and `other` objects.
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
*/
function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
arrLength = array.length,
othLength = other.length;
if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(array);
if (stacked && stack.get(other)) {
return stacked == other;
}
var index = -1,
result = true,
seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
stack.set(array, other);
stack.set(other, array);
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index],
othValue = other[index];
if (customizer) {
var compared = isPartial
? customizer(othValue, arrValue, index, other, array, stack)
: customizer(arrValue, othValue, index, array, other, stack);
}
if (compared !== undefined) {
if (compared) {
continue;
}
result = false;
break;
}
// Recursively compare arrays (susceptible to call stack limits).
if (seen) {
if (!arraySome(other, function(othValue, othIndex) {
if (!cacheHas(seen, othIndex) &&
(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
return seen.push(othIndex);
}
})) {
result = false;
break;
}
} else if (!(
arrValue === othValue ||
equalFunc(arrValue, othValue, bitmask, customizer, stack)
)) {
result = false;
break;
}
}
stack['delete'](array);
stack['delete'](other);
return result;
}
/**
* A specialized version of `baseIsEqualDeep` for comparing objects of
* the same `toStringTag`.
*
* **Note:** This function only supports comparing values with tags of
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {string} tag The `toStringTag` of the objects to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
switch (tag) {
case dataViewTag:
if ((object.byteLength != other.byteLength) ||
(object.byteOffset != other.byteOffset)) {
return false;
}
object = object.buffer;
other = other.buffer;
case arrayBufferTag:
if ((object.byteLength != other.byteLength) ||
!equalFunc(new Uint8Array(object), new Uint8Array(other))) {
return false;
}
return true;
case boolTag:
case dateTag:
case numberTag:
// Coerce booleans to `1` or `0` and dates to milliseconds.
// Invalid dates are coerced to `NaN`.
return eq(+object, +other);
case errorTag:
return object.name == other.name && object.message == other.message;
case regexpTag:
case stringTag:
// Coerce regexes to strings and treat strings, primitives and objects,
// as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
// for more details.
return object == (other + '');
case mapTag:
var convert = mapToArray;
case setTag:
var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
convert || (convert = setToArray);
if (object.size != other.size && !isPartial) {
return false;
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked) {
return stacked == other;
}
bitmask |= COMPARE_UNORDERED_FLAG;
// Recursively compare objects (susceptible to call stack limits).
stack.set(object, other);
var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
stack['delete'](object);
return result;
case symbolTag:
if (symbolValueOf) {
return symbolValueOf.call(object) == symbolValueOf.call(other);
}
}
return false;
}
/**
* A specialized version of `baseIsEqualDeep` for objects with support for
* partial deep comparisons.
*
* @private
* @param {Object} object The object to compare.
* @param {Object} other The other object to compare.
* @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
* @param {Function} customizer The function to customize comparisons.
* @param {Function} equalFunc The function to determine equivalents of values.
* @param {Object} stack Tracks traversed `object` and `other` objects.
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
*/
function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
objProps = getAllKeys(object),
objLength = objProps.length,
othProps = getAllKeys(other),
othLength = othProps.length;
if (objLength != othLength && !isPartial) {
return false;
}
var index = objLength;
while (index--) {
var key = objProps[index];
if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
return false;
}
}
// Assume cyclic values are equal.
var stacked = stack.get(object);
if (stacked && stack.get(other)) {
return stacked == other;
}
var result = true;
stack.set(object, other);
stack.set(other, object);
var skipCtor = isPartial;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key];
if (customizer) {
var compared = isPartial
? customizer(othValue, objValue, key, other, object, stack)
: customizer(objValue, othValue, key, object, other, stack);
}
// Recursively compare objects (susceptible to call stack limits).
if (!(compared === undefined
? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
: compared
)) {
result = false;
break;
}
skipCtor || (skipCtor = key == 'constructor');
}
if (result && !skipCtor) {
var objCtor = object.constructor,
othCtor = other.constructor;
// Non `Object` object instances with different constructors are not equal.
if (objCtor != othCtor &&
('constructor' in object && 'constructor' in other) &&
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
result = false;
}
}
stack['delete'](object);
stack['delete'](other);
return result;
}
/**
* Creates an array of own enumerable property names and symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names and symbols.
*/
function getAllKeys(object) {
return baseGetAllKeys(object, keys, getSymbols);
}
/**
* Gets the data for `map`.
*
* @private
* @param {Object} map The map to query.
* @param {string} key The reference key.
* @returns {*} Returns the map data.
*/
function getMapData(map, key) {
var data = map.__data__;
return isKeyable(key)
? data[typeof key == 'string' ? 'string' : 'hash']
: data.map;
}
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = getValue(object, key);
return baseIsNative(value) ? value : undefined;
}
/**
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag),
tag = value[symToStringTag];
try {
value[symToStringTag] = undefined;
var unmasked = true;
} catch (e) {}
var result = nativeObjectToString.call(value);
if (unmasked) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}
/**
* Creates an array of the own enumerable symbols of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the array of symbols.
*/
var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
if (object == null) {
return [];
}
object = Object(object);
return arrayFilter(nativeGetSymbols(object), function(symbol) {
return propertyIsEnumerable.call(object, symbol);
});
};
/**
* Gets the `toStringTag` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
var getTag = baseGetTag;
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
(Map && getTag(new Map) != mapTag) ||
(Promise && getTag(Promise.resolve()) != promiseTag) ||
(Set && getTag(new Set) != setTag) ||
(WeakMap && getTag(new WeakMap) != weakMapTag)) {
getTag = function(value) {
var result = baseGetTag(value),
Ctor = result == objectTag ? value.constructor : undefined,
ctorString = Ctor ? toSource(Ctor) : '';
if (ctorString) {
switch (ctorString) {
case dataViewCtorString: return dataViewTag;
case mapCtorString: return mapTag;
case promiseCtorString: return promiseTag;
case setCtorString: return setTag;
case weakMapCtorString: return weakMapTag;
}
}
return result;
};
}
/**
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isIndex(value, length) {
length = length == null ? MAX_SAFE_INTEGER : length;
return !!length &&
(typeof value == 'number' || reIsUint.test(value)) &&
(value > -1 && value % 1 == 0 && value < length);
}
/**
* Checks if `value` is suitable for use as unique object key.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is suitable, else `false`.
*/
function isKeyable(value) {
var type = typeof value;
return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
? (value !== '__proto__')
: (value === null);
}
/**
* Checks if `func` has its source masked.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` is masked, else `false`.
*/
function isMasked(func) {
return !!maskSrcKey && (maskSrcKey in func);
}
/**
* Checks if `value` is likely a prototype object.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
*/
function isPrototype(value) {
var Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
return value === proto;
}
/**
* Converts `value` to a string using `Object.prototype.toString`.
*
* @private
* @param {*} value The value to convert.
* @returns {string} Returns the converted string.
*/
function objectToString(value) {
return nativeObjectToString.call(value);
}
/**
* Converts `func` to its source code.
*
* @private
* @param {Function} func The function to convert.
* @returns {string} Returns the source code.
*/
function toSource(func) {
if (func != null) {
try {
return funcToString.call(func);
} catch (e) {}
try {
return (func + '');
} catch (e) {}
}
return '';
}
/**
* Performs a
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* comparison between two values to determine if they are equivalent.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.eq(object, object);
* // => true
*
* _.eq(object, other);
* // => false
*
* _.eq('a', 'a');
* // => true
*
* _.eq('a', Object('a'));
* // => false
*
* _.eq(NaN, NaN);
* // => true
*/
function eq(value, other) {
return value === other || (value !== value && other !== other);
}
/**
* Checks if `value` is likely an `arguments` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
* else `false`.
* @example
*
* _.isArguments(function() { return arguments; }());
* // => true
*
* _.isArguments([1, 2, 3]);
* // => false
*/
var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
!propertyIsEnumerable.call(value, 'callee');
};
/**
* Checks if `value` is classified as an `Array` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array, else `false`.
* @example
*
* _.isArray([1, 2, 3]);
* // => true
*
* _.isArray(document.body.children);
* // => false
*
* _.isArray('abc');
* // => false
*
* _.isArray(_.noop);
* // => false
*/
var isArray = Array.isArray;
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null && isLength(value.length) && !isFunction(value);
}
/**
* Checks if `value` is a buffer.
*
* @static
* @memberOf _
* @since 4.3.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
* @example
*
* _.isBuffer(new Buffer(2));
* // => true
*
* _.isBuffer(new Uint8Array(2));
* // => false
*/
var isBuffer = nativeIsBuffer || stubFalse;
/**
* Performs a deep comparison between two values to determine if they are
* equivalent.
*
* **Note:** This method supports comparing arrays, array buffers, booleans,
* date objects, error objects, maps, numbers, `Object` objects, regexes,
* sets, strings, symbols, and typed arrays. `Object` objects are compared
* by their own, not inherited, enumerable properties. Functions and DOM
* nodes are compared by strict equality, i.e. `===`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'a': 1 };
* var other = { 'a': 1 };
*
* _.isEqual(object, other);
* // => true
*
* object === other;
* // => false
*/
function isEqual(value, other) {
return baseIsEqual(value, other);
}
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a function, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
if (!isObject(value)) {
return false;
}
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 9 which returns 'object' for typed arrays and other constructors.
var tag = baseGetTag(value);
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This method is loosely based on
* [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' &&
value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is the
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @since 0.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return value != null && typeof value == 'object';
}
/**
* Checks if `value` is classified as a typed array.
*
* @static
* @memberOf _
* @since 3.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
* @example
*
* _.isTypedArray(new Uint8Array);
* // => true
*
* _.isTypedArray([]);
* // => false
*/
var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
* for more details.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.keys(new Foo);
* // => ['a', 'b'] (iteration order is not guaranteed)
*
* _.keys('hi');
* // => ['0', '1']
*/
function keys(object) {
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
}
/**
* This method returns a new empty array.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {Array} Returns the new empty array.
* @example
*
* var arrays = _.times(2, _.stubArray);
*
* console.log(arrays);
* // => [[], []]
*
* console.log(arrays[0] === arrays[1]);
* // => false
*/
function stubArray() {
return [];
}
/**
* This method returns `false`.
*
* @static
* @memberOf _
* @since 4.13.0
* @category Util
* @returns {boolean} Returns `false`.
* @example
*
* _.times(2, _.stubFalse);
* // => [false, false]
*/
function stubFalse() {
return false;
}
module.exports = isEqual;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}]},{},[8])(8)
});
; window.QuillDeltaToHtmlConverter = window.QuillDeltaToHtmlConverter ? window.QuillDeltaToHtmlConverter.QuillDeltaToHtmlConverter : window.QuillDeltaToHtmlConverter;