/** * Super simple wysiwyg editor v2.0.0 xxx * http://materialnote.org/ * * materialnote.js * Copyright 2017 CK and other contributors * based on summernote.js, copyright 2013- Alan Hong. and other contributors * materialnote may be freely distributed under the MIT license./ * * Date: 2017-11-21T02:27Z */ (function (factory) { /* global define */ if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else if (typeof module === 'object' && module.exports) { // Node/CommonJS module.exports = factory(require('jquery')); } else { // Browser globals factory(window.jQuery); } }(function ($) { 'use strict'; var isSupportAmd = typeof define === 'function' && define.amd; /** * returns whether font is installed or not. * * @param {String} fontName * @return {Boolean} */ var isFontInstalled = function (fontName) { var testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS'; var $tester = $('
] var ancestors = listAncestor(point.node, func.eq(root)); if (!ancestors.length) { return null; } else if (ancestors.length === 1) { return splitNode(point, options); } return ancestors.reduce(function (node, parent) { if (node === point.node) { node = splitNode(point, options); } return splitNode({ node: parent, offset: node ? dom.position(node) : nodeLength(parent) }, options); }); }; /** * split point * * @param {Point} point * @param {Boolean} isInline * @return {Object} */ var splitPoint = function (point, isInline) { // find splitRoot, container // - inline: splitRoot is a child of paragraph // - block: splitRoot is a child of bodyContainer var pred = isInline ? isPara : isBodyContainer; var ancestors = listAncestor(point.node, pred); var topAncestor = list.last(ancestors) || point.node; var splitRoot, container; if (pred(topAncestor)) { splitRoot = ancestors[ancestors.length - 2]; container = topAncestor; } else { splitRoot = topAncestor; container = splitRoot.parentNode; } // if splitRoot is exists, split with splitTree var pivot = splitRoot && splitTree(splitRoot, point, { isSkipPaddingBlankHTML: isInline, isNotSplitEdgePoint: isInline }); // if container is point.node, find pivot with point.offset if (!pivot && container === point.node) { pivot = point.node.childNodes[point.offset]; } return { rightNode: pivot, container: container }; }; var create = function (nodeName) { return document.createElement(nodeName); }; var createText = function (text) { return document.createTextNode(text); }; /** * @method remove * * remove node, (isRemoveChild: remove child or not) * * @param {Node} node * @param {Boolean} isRemoveChild */ var remove = function (node, isRemoveChild) { if (!node || !node.parentNode) { return; } if (node.removeNode) { return node.removeNode(isRemoveChild); } var parent = node.parentNode; if (!isRemoveChild) { var nodes = []; var i, len; for (i = 0, len = node.childNodes.length; i < len; i++) { nodes.push(node.childNodes[i]); } for (i = 0, len = nodes.length; i < len; i++) { parent.insertBefore(nodes[i], node); } } parent.removeChild(node); }; /** * @method removeWhile * * @param {Node} node * @param {Function} pred */ var removeWhile = function (node, pred) { while (node) { if (isEditable(node) || !pred(node)) { break; } var parent = node.parentNode; remove(node); node = parent; } }; /** * @method replace * * replace node with provided nodeName * * @param {Node} node * @param {String} nodeName * @return {Node} - new node */ var replace = function (node, nodeName) { if (node.nodeName.toUpperCase() === nodeName.toUpperCase()) { return node; } var newNode = create(nodeName); if (node.style.cssText) { newNode.style.cssText = node.style.cssText; } appendChildNodes(newNode, list.from(node.childNodes)); insertAfter(newNode, node); remove(node); return newNode; }; var isTextarea = makePredByNodeName('TEXTAREA'); /** * @param {jQuery} $node * @param {Boolean} [stripLinebreaks] - default: false */ var value = function ($node, stripLinebreaks) { var val = isTextarea($node[0]) ? $node.val() : $node.html(); if (stripLinebreaks) { return val.replace(/[\n\r]/g, ''); } return val; }; /** * @method html * * get the HTML contents of node * * @param {jQuery} $node * @param {Boolean} [isNewlineOnBlock] */ var html = function ($node, isNewlineOnBlock) { var markup = value($node); if (isNewlineOnBlock) { var regexTag = /<(\/?)(\b(?!!)[^>\s]*)(.*?)(\s*\/?>)/g; markup = markup.replace(regexTag, function (match, endSlash, name) { name = name.toUpperCase(); var isEndOfInlineContainer = /^DIV|^TD|^TH|^P|^LI|^H[1-7]/.test(name) && !!endSlash; var isBlockNode = /^BLOCKQUOTE|^TABLE|^TBODY|^TR|^HR|^UL|^OL/.test(name); return match + ((isEndOfInlineContainer || isBlockNode) ? '\n' : ''); }); markup = $.trim(markup); } return markup; }; var posFromPlaceholder = function (placeholder) { var $placeholder = $(placeholder); var pos = $placeholder.offset(); var height = $placeholder.outerHeight(true); // include margin return { left: pos.left, top: pos.top + height }; }; var attachEvents = function ($node, events) { Object.keys(events).forEach(function (key) { $node.on(key, events[key]); }); }; var detachEvents = function ($node, events) { Object.keys(events).forEach(function (key) { $node.off(key, events[key]); }); }; /** * @method isCustomStyleTag * * assert if a node contains a "note-styletag" class, * which implies that's a custom-made style tag node * * @param {Node} an HTML DOM node */ var isCustomStyleTag = function (node) { return node && !dom.isText(node) && list.contains(node.classList, 'note-styletag'); }; return { /** @property {String} NBSP_CHAR */ NBSP_CHAR: NBSP_CHAR, /** @property {String} ZERO_WIDTH_NBSP_CHAR */ ZERO_WIDTH_NBSP_CHAR: ZERO_WIDTH_NBSP_CHAR, /** @property {String} blank */ blank: blankHTML, /** @property {String} emptyPara */ emptyPara: '
' + blankHTML + '
', emptyTableCell: '(table)', emptyTableHeaderCell: '(header)', makePredByNodeName: makePredByNodeName, isEditable: isEditable, isControlSizing: isControlSizing, isText: isText, isElement: isElement, isVoid: isVoid, isPara: isPara, isPurePara: isPurePara, isHeading: isHeading, isInline: isInline, isBlock: func.not(isInline), isBodyInline: isBodyInline, isBody: isBody, isParaInline: isParaInline, isPre: isPre, isList: isList, isTable: isTable, isData: isData, isCell: isCell, isBlockquote: isBlockquote, isBodyContainer: isBodyContainer, isAnchor: isAnchor, isDiv: makePredByNodeName('DIV'), isLi: isLi, isBR: makePredByNodeName('BR'), isSpan: makePredByNodeName('SPAN'), isB: makePredByNodeName('B'), isU: makePredByNodeName('U'), isS: makePredByNodeName('S'), isI: makePredByNodeName('I'), isImg: makePredByNodeName('IMG'), isTextarea: isTextarea, isEmpty: isEmpty, isEmptyAnchor: func.and(isAnchor, isEmpty), isClosestSibling: isClosestSibling, withClosestSiblings: withClosestSiblings, nodeLength: nodeLength, isLeftEdgePoint: isLeftEdgePoint, isRightEdgePoint: isRightEdgePoint, isEdgePoint: isEdgePoint, isLeftEdgeOf: isLeftEdgeOf, isRightEdgeOf: isRightEdgeOf, isLeftEdgePointOf: isLeftEdgePointOf, isRightEdgePointOf: isRightEdgePointOf, prevPoint: prevPoint, nextPoint: nextPoint, isSamePoint: isSamePoint, isVisiblePoint: isVisiblePoint, prevPointUntil: prevPointUntil, nextPointUntil: nextPointUntil, isCharPoint: isCharPoint, walkPoint: walkPoint, ancestor: ancestor, singleChildAncestor: singleChildAncestor, listAncestor: listAncestor, lastAncestor: lastAncestor, listNext: listNext, listPrev: listPrev, listDescendant: listDescendant, commonAncestor: commonAncestor, wrap: wrap, insertAfter: insertAfter, appendChildNodes: appendChildNodes, position: position, hasChildren: hasChildren, makeOffsetPath: makeOffsetPath, fromOffsetPath: fromOffsetPath, splitTree: splitTree, splitPoint: splitPoint, create: create, createText: createText, remove: remove, removeWhile: removeWhile, replace: replace, html: html, value: value, posFromPlaceholder: posFromPlaceholder, attachEvents: attachEvents, detachEvents: detachEvents, isCustomStyleTag: isCustomStyleTag }; })(); /** * @param {jQuery} $note * @param {Object} options * @return {Context} */ var Context = function ($note, options) { var self = this; var ui = $.materialnote.ui; this.memos = {}; this.modules = {}; this.layoutInfo = {}; this.options = options; /** * create layout and initialize modules and other resources */ this.initialize = function () { this.layoutInfo = ui.createLayout($note, options); this._initialize(); $note.hide(); return this; }; /** * destroy modules and other resources and remove layout */ this.destroy = function () { this._destroy(); $note.removeData('materialnote'); ui.removeLayout($note, this.layoutInfo); }; /** * destory modules and other resources and initialize it again */ this.reset = function () { var disabled = self.isDisabled(); this.code(dom.emptyPara); this._destroy(); this._initialize(); if (disabled) { self.disable(); } }; this._initialize = function () { // add optional buttons var buttons = $.extend({}, this.options.buttons); Object.keys(buttons).forEach(function (key) { self.memo('button.' + key, buttons[key]); }); var modules = $.extend({}, this.options.modules, $.materialnote.plugins || {}); // add and initialize modules Object.keys(modules).forEach(function (key) { self.module(key, modules[key], true); }); Object.keys(this.modules).forEach(function (key) { self.initializeModule(key); }); }; this._destroy = function () { // destroy modules with reversed order Object.keys(this.modules).reverse().forEach(function (key) { self.removeModule(key); }); Object.keys(this.memos).forEach(function (key) { self.removeMemo(key); }); // trigger custom onDestroy callback this.triggerEvent('destroy', this); }; this.code = function (html) { var isActivated = this.invoke('codeview.isActivated'); if (html === undefined) { this.invoke('codeview.sync'); return isActivated ? this.layoutInfo.codable.val() : this.layoutInfo.editable.html(); } else { if (isActivated) { this.layoutInfo.codable.val(html); } else { this.layoutInfo.editable.html(html); } $note.val(html); this.triggerEvent('change', html); } }; this.isDisabled = function () { return this.layoutInfo.editable.attr('contenteditable') === 'false'; }; this.enable = function () { this.layoutInfo.editable.attr('contenteditable', true); this.invoke('toolbar.activate', true); this.triggerEvent('disable', false); }; this.disable = function () { // close codeview if codeview is opend if (this.invoke('codeview.isActivated')) { this.invoke('codeview.deactivate'); } this.layoutInfo.editable.attr('contenteditable', false); this.invoke('toolbar.deactivate', true); this.triggerEvent('disable', true); }; this.triggerEvent = function () { var namespace = list.head(arguments); var args = list.tail(list.from(arguments)); var callback = this.options.callbacks[func.namespaceToCamel(namespace, 'on')]; if (callback) { callback.apply($note[0], args); } $note.trigger('materialnote.' + namespace, args); }; this.initializeModule = function (key) { var module = this.modules[key]; module.shouldInitialize = module.shouldInitialize || func.ok; if (!module.shouldInitialize()) { return; } // initialize module if (module.initialize) { module.initialize(); } // attach events if (module.events) { dom.attachEvents($note, module.events); } }; this.module = function (key, ModuleClass, withoutIntialize) { if (arguments.length === 1) { return this.modules[key]; } this.modules[key] = new ModuleClass(this); if (!withoutIntialize) { this.initializeModule(key); } }; this.getInlineStyles = function($target) { var inlineStyle = $target.attr('style'); var styles = {}; if (inlineStyle) { inlineStyle = inlineStyle.split(';'); for (let i = 0; i < inlineStyle.length; i++) { if (inlineStyle[i] === '') { continue; } let keyValue = inlineStyle[i].split(':'); let key = keyValue[0].trim(); let value = keyValue[1].trim(); styles[key] = value; } } return styles; }; this.removeModule = function (key) { var module = this.modules[key]; if (module.shouldInitialize()) { if (module.events) { dom.detachEvents($note, module.events); } if (module.destroy) { module.destroy(); } } delete this.modules[key]; }; this.memo = function (key, obj) { if (arguments.length === 1) { return this.memos[key]; } this.memos[key] = obj; }; this.removeMemo = function (key) { if (this.memos[key] && this.memos[key].destroy) { this.memos[key].destroy(); } delete this.memos[key]; }; /** *Some buttons need to change their visual style immediately once they get pressed */ this.createInvokeHandlerAndUpdateState = function (namespace, value) { return function (event) { self.createInvokeHandler(namespace, value)(event); self.invoke('buttons.updateCurrentStyle'); }; }; this.createInvokeHandler = function (namespace, value) { return function (event) { event.preventDefault(); var $target = $(event.target); if (namespace === 'editor.insertTable') { let optionsContainer = $target.closest('.row').prev(); value = { dim: $target.closest('[data-value]').data('value'), bordered: optionsContainer.find('#note-table-bordered').prop('checked'), striped: optionsContainer.find('#note-table-striped').prop('checked'), highlight: optionsContainer.find('#note-table-highlight').prop('checked'), responsive: optionsContainer.find('#note-table-responsive').prop('checked'), centered: optionsContainer.find('#note-table-centered').prop('checked') }; } self.invoke(namespace, value || $target.closest('[data-value]').data('value'), $target); }; }; this.invoke = function () { var namespace = list.head(arguments); var args = list.tail(list.from(arguments)); var splits = namespace.split('.'); var hasSeparator = splits.length > 1; var moduleName = hasSeparator && list.head(splits); var methodName = hasSeparator ? list.last(splits) : list.head(splits); var module = this.modules[moduleName || 'editor']; if (!moduleName && this[methodName]) { return this[methodName].apply(this, args); } else if (module && module[methodName] && module.shouldInitialize()) { return module[methodName].apply(module, args); } }; return this.initialize(); }; $.fn.extend({ /** * materialnote API * * @param {Object|String} * @return {this} */ materialnote: function () { var type = $.type(list.head(arguments)); var isExternalAPICalled = type === 'string'; var hasInitOptions = type === 'object'; var options = hasInitOptions ? list.head(arguments) : {}; options = $.extend({}, $.materialnote.options, options); // Update options options.langInfo = $.extend(true, {}, $.materialnote.lang['en-US'], $.materialnote.lang[options.lang]); options.icons = $.extend(true, {}, $.materialnote.options.icons, options.icons); options.tooltip = options.tooltip === 'auto' ? !agent.isSupportTouch : options.tooltip; this.each(function (idx, note) { var $note = $(note); if (!$note.data('materialnote')) { var context = new Context($note, options); $note.data('materialnote', context); $note.data('materialnote').triggerEvent('init', context.layoutInfo); } }); var $note = this.first(); if ($note.length) { var context = $note.data('materialnote'); if (isExternalAPICalled) { return context.invoke.apply(context, list.from(arguments)); } else if (options.focus) { context.invoke('editor.focus'); } } // activate plugins var $noteEditor = $note.next('.note-editor'); $noteEditor.find('.dropdown-trigger').dropdown({ inDuration: 300, outDuration: 225, constrainWidth: false, // Does not change width of dropdown to that of the activator //hover: true, // Activate on hover gutter: 0, // Spacing from edge coverTrigger: false, // Displays dropdown below the button alignment: 'left', // Displays dropdown with edge aligned to the left of button stopPropagation: false // Stops event propagation } ); return this; } }); var Renderer = function (markup, children, options, callback) { this.render = function ($parent) { var $node = $(markup); if (options && options.id) { //>>> add id to dropdown-content $element $node.attr('id', options.id); } if (options && options.contents) { $node.html(options.contents); } if (options && options.className) { $node.addClass(options.className); } if (options && options.data) { $.each(options.data, function (k, v) { $node.attr('data-' + k, v); }); } if (options && options.click) { $node.on('click', options.click); } if (children) { var $container = $node.find('.note-children-container'); children.forEach(function (child) { child.render($container.length ? $container : $node); }); } if (callback) { callback($node, options); } if (options && options.callback) { options.callback($node); } if ($parent) { $parent.append($node); } return $node; }; }; var renderer = { create: function (markup, callback) { return function () { var children = $.isArray(arguments[0]) ? arguments[0] : []; var options = typeof arguments[1] === 'object' ? arguments[1] : arguments[0]; if (options && options.children) { children = options.children; } return new Renderer(markup, children, options, callback); }; } }; var editor = renderer.create(''); var toolbar = renderer.create(' '); var editingArea = renderer.create(''); var codable = renderer.create(''); var editable = renderer.create(''); var statusbar = renderer.create([ ' ' ].join('')); var airEditor = renderer.create(''); var airEditable = renderer.create(''); var buttonGroup = renderer.create('text
| * - chrome:|text|
*/ var rng = this.normalize(); if (dom.isParaInline(sc) || dom.isPara(sc)) { return rng; } // find inline top ancestor var topAncestor; if (dom.isInline(rng.sc)) { var ancestors = dom.listAncestor(rng.sc, func.not(dom.isInline)); topAncestor = list.last(ancestors); if (!dom.isInline(topAncestor)) { topAncestor = ancestors[ancestors.length - 2] || rng.sc.childNodes[rng.so]; } } else { topAncestor = rng.sc.childNodes[rng.so > 0 ? rng.so - 1 : 0]; } // siblings not in paragraph var inlineSiblings = dom.listPrev(topAncestor, dom.isParaInline).reverse(); inlineSiblings = inlineSiblings.concat(dom.listNext(topAncestor.nextSibling, dom.isParaInline)); // wrap with paragraph if (inlineSiblings.length) { var para = dom.wrap(list.head(inlineSiblings), 'p'); dom.appendChildNodes(para, list.tail(inlineSiblings)); } return this.normalize(); }; /** * insert node at current cursor * * @param {Node} node * @return {Node} */ this.insertNode = function (node) { var rng = this.wrapBodyInlineWithPara().deleteContents(); var info = dom.splitPoint(rng.getStartPoint(), dom.isInline(node)); if (info.rightNode) { info.rightNode.parentNode.insertBefore(node, info.rightNode); } else { info.container.appendChild(node); } return node; }; /** * insert html at current cursor */ this.pasteHTML = function (markup) { var contentsContainer = $('').html(markup)[0]; var childNodes = list.from(contentsContainer.childNodes); var rng = this.wrapBodyInlineWithPara().deleteContents(); return childNodes.reverse().map(function (childNode) { return rng.insertNode(childNode); }).reverse(); }; /** * returns text in range * * @return {String} */ this.toString = function () { var nativeRng = nativeRange(); return agent.isW3CRangeSupport ? nativeRng.toString() : nativeRng.text; }; /** * returns range for word before cursor * * @param {Boolean} [findAfter] - find after cursor, default: false * @return {WrappedRange} */ this.getWordRange = function (findAfter) { var endPoint = this.getEndPoint(); if (!dom.isCharPoint(endPoint)) { return this; } var startPoint = dom.prevPointUntil(endPoint, function (point) { return !dom.isCharPoint(point); }); if (findAfter) { endPoint = dom.nextPointUntil(endPoint, function (point) { return !dom.isCharPoint(point); }); } return new WrappedRange( startPoint.node, startPoint.offset, endPoint.node, endPoint.offset ); }; /** * create offsetPath bookmark * * @param {Node} editable */ this.bookmark = function (editable) { return { s: { path: dom.makeOffsetPath(editable, sc), offset: so }, e: { path: dom.makeOffsetPath(editable, ec), offset: eo } }; }; /** * create offsetPath bookmark base on paragraph * * @param {Node[]} paras */ this.paraBookmark = function (paras) { return { s: { path: list.tail(dom.makeOffsetPath(list.head(paras), sc)), offset: so }, e: { path: list.tail(dom.makeOffsetPath(list.last(paras), ec)), offset: eo } }; }; /** * getClientRects * @return {Rect[]} */ this.getClientRects = function () { var nativeRng = nativeRange(); return nativeRng.getClientRects(); }; }; /** * @class core.range * * Data structure * * BoundaryPoint: a point of dom tree * * BoundaryPoints: two boundaryPoints corresponding to the start and the end of the Range * * See to http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Position * * @singleton * @alternateClassName range */ return { /** * create Range Object From arguments or Browser Selection * * @param {Node} sc - start container * @param {Number} so - start offset * @param {Node} ec - end container * @param {Number} eo - end offset * @return {WrappedRange} */ create: function (sc, so, ec, eo) { if (arguments.length === 4) { return new WrappedRange(sc, so, ec, eo); } else if (arguments.length === 2) { //collapsed ec = sc; eo = so; return new WrappedRange(sc, so, ec, eo); } else { var wrappedRange = this.createFromSelection(); if (!wrappedRange && arguments.length === 1) { wrappedRange = this.createFromNode(arguments[0]); return wrappedRange.collapse(dom.emptyPara === arguments[0].innerHTML); } return wrappedRange; } }, createFromSelection: function () { var sc, so, ec, eo; if (agent.isW3CRangeSupport) { var selection = document.getSelection(); if (!selection || selection.rangeCount === 0) { return null; } else if (dom.isBody(selection.anchorNode)) { // Firefox: returns entire body as range on initialization. // We won't never need it. return null; } var nativeRng = selection.getRangeAt(0); sc = nativeRng.startContainer; so = nativeRng.startOffset; ec = nativeRng.endContainer; eo = nativeRng.endOffset; } else { // IE8: TextRange var textRange = document.selection.createRange(); var textRangeEnd = textRange.duplicate(); textRangeEnd.collapse(false); var textRangeStart = textRange; textRangeStart.collapse(true); var startPoint = textRangeToPoint(textRangeStart, true), endPoint = textRangeToPoint(textRangeEnd, false); // same visible point case: range was collapsed. if (dom.isText(startPoint.node) && dom.isLeftEdgePoint(startPoint) && dom.isTextNode(endPoint.node) && dom.isRightEdgePoint(endPoint) && endPoint.node.nextSibling === startPoint.node) { startPoint = endPoint; } sc = startPoint.cont; so = startPoint.offset; ec = endPoint.cont; eo = endPoint.offset; } return new WrappedRange(sc, so, ec, eo); }, /** * @method * * create WrappedRange from node * * @param {Node} node * @return {WrappedRange} */ createFromNode: function (node) { var sc = node; var so = 0; var ec = node; var eo = dom.nodeLength(ec); // browsers can't target a picture or void node if (dom.isVoid(sc)) { so = dom.listPrev(sc).length - 1; sc = sc.parentNode; } if (dom.isBR(ec)) { eo = dom.listPrev(ec).length - 1; ec = ec.parentNode; } else if (dom.isVoid(ec)) { eo = dom.listPrev(ec).length; ec = ec.parentNode; } return this.create(sc, so, ec, eo); }, /** * create WrappedRange from node after position * * @param {Node} node * @return {WrappedRange} */ createFromNodeBefore: function (node) { return this.createFromNode(node).collapse(true); }, /** * create WrappedRange from node after position * * @param {Node} node * @return {WrappedRange} */ createFromNodeAfter: function (node) { return this.createFromNode(node).collapse(); }, /** * @method * * create WrappedRange from bookmark * * @param {Node} editable * @param {Object} bookmark * @return {WrappedRange} */ createFromBookmark: function (editable, bookmark) { var sc = dom.fromOffsetPath(editable, bookmark.s.path); var so = bookmark.s.offset; var ec = dom.fromOffsetPath(editable, bookmark.e.path); var eo = bookmark.e.offset; return new WrappedRange(sc, so, ec, eo); }, /** * @method * * create WrappedRange from paraBookmark * * @param {Object} bookmark * @param {Node[]} paras * @return {WrappedRange} */ createFromParaBookmark: function (bookmark, paras) { var so = bookmark.s.offset; var eo = bookmark.e.offset; var sc = dom.fromOffsetPath(list.head(paras), bookmark.s.path); var ec = dom.fromOffsetPath(list.last(paras), bookmark.e.path); return new WrappedRange(sc, so, ec, eo); } }; })(); /** * @class core.async * * Async functions which returns `Promise` * * @singleton * @alternateClassName async */ var async = (function () { /** * @method readFileAsDataURL * * read contents of file as representing URL * * @param {File} file * @return {Promise} - then: dataUrl */ var readFileAsDataURL = function (file) { return $.Deferred(function (deferred) { $.extend(new FileReader(), { onload: function (e) { var dataURL = e.target.result; deferred.resolve(dataURL); }, onerror: function () { deferred.reject(this); } }).readAsDataURL(file); }).promise(); }; /** * @method createImage * * create `