{"version":3,"sources":["loader.js/loader.js","mobiledoc-text-renderer/cards/image.js","mobiledoc-text-renderer/index.js","mobiledoc-text-renderer/renderer-factory.js","mobiledoc-text-renderer/renderers/0-2.js","mobiledoc-text-renderer/renderers/0-3.js","mobiledoc-text-renderer/utils/marker-types.js","mobiledoc-text-renderer/utils/render-type.js","mobiledoc-text-renderer/utils/section-types.js"],"sourcesContent":["var loader, define, requireModule, require, requirejs;\n\n(function (global) {\n 'use strict';\n\n function dict() {\n var obj = Object.create(null);\n obj['__'] = undefined;\n delete obj['__'];\n return obj;\n }\n\n // Save off the original values of these globals, so we can restore them if someone asks us to\n var oldGlobals = {\n loader: loader,\n define: define,\n requireModule: requireModule,\n require: require,\n requirejs: requirejs\n };\n\n requirejs = require = requireModule = function (id) {\n var pending = [];\n var mod = findModule(id, '(require)', pending);\n\n for (var i = pending.length - 1; i >= 0; i--) {\n pending[i].exports();\n }\n\n return mod.module.exports;\n };\n\n loader = {\n noConflict: function (aliases) {\n var oldName, newName;\n\n for (oldName in aliases) {\n if (aliases.hasOwnProperty(oldName)) {\n if (oldGlobals.hasOwnProperty(oldName)) {\n newName = aliases[oldName];\n\n global[newName] = global[oldName];\n global[oldName] = oldGlobals[oldName];\n }\n }\n }\n },\n // Option to enable or disable the generation of default exports\n makeDefaultExport: true\n };\n\n var registry = dict();\n var seen = dict();\n\n var uuid = 0;\n\n function unsupportedModule(length) {\n throw new Error('an unsupported module was defined, expected `define(id, deps, module)` instead got: `' + length + '` arguments to define`');\n }\n\n var defaultDeps = ['require', 'exports', 'module'];\n\n function Module(id, deps, callback, alias) {\n this.uuid = uuid++;\n this.id = id;\n this.deps = !deps.length && callback.length ? defaultDeps : deps;\n this.module = { exports: {} };\n this.callback = callback;\n this.hasExportsAsDep = false;\n this.isAlias = alias;\n this.reified = new Array(deps.length);\n\n /*\n Each module normally passes through these states, in order:\n new : initial state\n pending : this module is scheduled to be executed\n reifying : this module's dependencies are being executed\n reified : this module's dependencies finished executing successfully\n errored : this module's dependencies failed to execute\n finalized : this module executed successfully\n */\n this.state = 'new';\n }\n\n Module.prototype.makeDefaultExport = function () {\n var exports = this.module.exports;\n if (exports !== null && (typeof exports === 'object' || typeof exports === 'function') && exports['default'] === undefined && Object.isExtensible(exports)) {\n exports['default'] = exports;\n }\n };\n\n Module.prototype.exports = function () {\n // if finalized, there is no work to do. If reifying, there is a\n // circular dependency so we must return our (partial) exports.\n if (this.state === 'finalized' || this.state === 'reifying') {\n return this.module.exports;\n }\n\n\n if (loader.wrapModules) {\n this.callback = loader.wrapModules(this.id, this.callback);\n }\n\n this.reify();\n\n var result = this.callback.apply(this, this.reified);\n this.reified.length = 0;\n this.state = 'finalized';\n\n if (!(this.hasExportsAsDep && result === undefined)) {\n this.module.exports = result;\n }\n if (loader.makeDefaultExport) {\n this.makeDefaultExport();\n }\n return this.module.exports;\n };\n\n Module.prototype.unsee = function () {\n this.state = 'new';\n this.module = { exports: {} };\n };\n\n Module.prototype.reify = function () {\n if (this.state === 'reified') {\n return;\n }\n this.state = 'reifying';\n try {\n this.reified = this._reify();\n this.state = 'reified';\n } finally {\n if (this.state === 'reifying') {\n this.state = 'errored';\n }\n }\n };\n\n Module.prototype._reify = function () {\n var reified = this.reified.slice();\n for (var i = 0; i < reified.length; i++) {\n var mod = reified[i];\n reified[i] = mod.exports ? mod.exports : mod.module.exports();\n }\n return reified;\n };\n\n Module.prototype.findDeps = function (pending) {\n if (this.state !== 'new') {\n return;\n }\n\n this.state = 'pending';\n\n var deps = this.deps;\n\n for (var i = 0; i < deps.length; i++) {\n var dep = deps[i];\n var entry = this.reified[i] = { exports: undefined, module: undefined };\n if (dep === 'exports') {\n this.hasExportsAsDep = true;\n entry.exports = this.module.exports;\n } else if (dep === 'require') {\n entry.exports = this.makeRequire();\n } else if (dep === 'module') {\n entry.exports = this.module;\n } else {\n entry.module = findModule(resolve(dep, this.id), this.id, pending);\n }\n }\n };\n\n Module.prototype.makeRequire = function () {\n var id = this.id;\n var r = function (dep) {\n return require(resolve(dep, id));\n };\n r['default'] = r;\n r.moduleId = id;\n r.has = function (dep) {\n return has(resolve(dep, id));\n };\n return r;\n };\n\n define = function (id, deps, callback) {\n var module = registry[id];\n\n // If a module for this id has already been defined and is in any state\n // other than `new` (meaning it has been or is currently being required),\n // then we return early to avoid redefinition.\n if (module && module.state !== 'new') {\n return;\n }\n\n if (arguments.length < 2) {\n unsupportedModule(arguments.length);\n }\n\n if (!Array.isArray(deps)) {\n callback = deps;\n deps = [];\n }\n\n if (callback instanceof Alias) {\n registry[id] = new Module(callback.id, deps, callback, true);\n } else {\n registry[id] = new Module(id, deps, callback, false);\n }\n };\n\n define.exports = function (name, defaultExport) {\n var module = registry[name];\n\n // If a module for this name has already been defined and is in any state\n // other than `new` (meaning it has been or is currently being required),\n // then we return early to avoid redefinition.\n if (module && module.state !== 'new') {\n return;\n }\n\n module = new Module(name, [], noop, null);\n module.module.exports = defaultExport;\n module.state = 'finalized';\n registry[name] = module;\n\n return module;\n };\n\n function noop() {}\n // we don't support all of AMD\n // define.amd = {};\n\n function Alias(id) {\n this.id = id;\n }\n\n define.alias = function (id, target) {\n if (arguments.length === 2) {\n return define(target, new Alias(id));\n }\n\n return new Alias(id);\n };\n\n function missingModule(id, referrer) {\n throw new Error('Could not find module `' + id + '` imported from `' + referrer + '`');\n }\n\n function findModule(id, referrer, pending) {\n var mod = registry[id] || registry[id + '/index'];\n\n while (mod && mod.isAlias) {\n mod = registry[mod.id] || registry[mod.id + '/index'];\n }\n\n if (!mod) {\n missingModule(id, referrer);\n }\n\n if (pending && mod.state !== 'pending' && mod.state !== 'finalized') {\n mod.findDeps(pending);\n pending.push(mod);\n }\n return mod;\n }\n\n function resolve(child, id) {\n if (child.charAt(0) !== '.') {\n return child;\n }\n\n\n var parts = child.split('/');\n var nameParts = id.split('/');\n var parentBase = nameParts.slice(0, -1);\n\n for (var i = 0, l = parts.length; i < l; i++) {\n var part = parts[i];\n\n if (part === '..') {\n if (parentBase.length === 0) {\n throw new Error('Cannot access parent module of root');\n }\n parentBase.pop();\n } else if (part === '.') {\n continue;\n } else {\n parentBase.push(part);\n }\n }\n\n return parentBase.join('/');\n }\n\n function has(id) {\n return !!(registry[id] || registry[id + '/index']);\n }\n\n requirejs.entries = requirejs._eak_seen = registry;\n requirejs.has = has;\n requirejs.unsee = function (id) {\n findModule(id, '(unsee)', false).unsee();\n };\n\n requirejs.clear = function () {\n requirejs.entries = requirejs._eak_seen = registry = dict();\n seen = dict();\n };\n\n // This code primes the JS engine for good performance by warming the\n // JIT compiler for these functions.\n define('foo', function () {});\n define('foo/bar', [], function () {});\n define('foo/asdf', ['module', 'exports', 'require'], function (module, exports, require) {\n if (require.has('foo/bar')) {\n require('foo/bar');\n }\n });\n define('foo/baz', [], define.alias('foo'));\n define('foo/quz', define.alias('foo'));\n define.alias('foo', 'foo/qux');\n define('foo/bar', ['foo', './quz', './baz', './asdf', './bar', '../foo'], function () {});\n define('foo/main', ['foo/bar'], function () {});\n define.exports('foo/exports', {});\n\n require('foo/exports');\n require('foo/main');\n require.unsee('foo/bar');\n\n requirejs.clear();\n\n if (typeof exports === 'object' && typeof module === 'object' && module.exports) {\n module.exports = { require: require, define: define };\n }\n})(this);","define('mobiledoc-text-renderer/cards/image', ['exports'], function (exports) {\n 'use strict';\n\n exports['default'] = {\n name: 'image-card',\n type: 'text',\n render: function render() {}\n };\n});","define('mobiledoc-text-renderer', ['exports', 'mobiledoc-text-renderer/renderer-factory', 'mobiledoc-text-renderer/utils/render-type'], function (exports, _mobiledocTextRendererRendererFactory, _mobiledocTextRendererUtilsRenderType) {\n 'use strict';\n\n exports.registerGlobal = registerGlobal;\n\n function registerGlobal(window) {\n window.MobiledocTextRenderer = _mobiledocTextRendererRendererFactory['default'];\n }\n\n exports.RENDER_TYPE = _mobiledocTextRendererUtilsRenderType['default'];\n exports['default'] = _mobiledocTextRendererRendererFactory['default'];\n});","define('mobiledoc-text-renderer/renderer-factory', ['exports', 'mobiledoc-text-renderer/renderers/0-2', 'mobiledoc-text-renderer/renderers/0-3', 'mobiledoc-text-renderer/utils/render-type'], function (exports, _mobiledocTextRendererRenderers02, _mobiledocTextRendererRenderers03, _mobiledocTextRendererUtilsRenderType) {\n 'use strict';\n\n var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();\n\n function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }\n\n /**\n * runtime Text renderer\n * renders a mobiledoc to Text\n *\n * input: mobiledoc\n * output: Text (string)\n */\n\n function validateCards(cards) {\n if (!Array.isArray(cards)) {\n throw new Error('`cards` must be passed as an array');\n }\n for (var i = 0; i < cards.length; i++) {\n var card = cards[i];\n if (card.type !== _mobiledocTextRendererUtilsRenderType['default']) {\n throw new Error('Card \"' + card.name + '\" must be type \"' + _mobiledocTextRendererUtilsRenderType['default'] + '\", was \"' + card.type + '\"');\n }\n if (!card.render) {\n throw new Error('Card \"' + card.name + '\" must define `render`');\n }\n }\n }\n\n function validateAtoms(atoms) {\n if (!Array.isArray(atoms)) {\n throw new Error('`atoms` must be passed as an array');\n }\n for (var i = 0; i < atoms.length; i++) {\n var atom = atoms[i];\n if (atom.type !== _mobiledocTextRendererUtilsRenderType['default']) {\n throw new Error('Atom \"' + atom.name + '\" must be type \"' + _mobiledocTextRendererUtilsRenderType['default'] + '\", was \"' + atom.type + '\"');\n }\n if (!atom.render) {\n throw new Error('Atom \"' + atom.name + '\" must define `render`');\n }\n }\n }\n\n var RendererFactory = (function () {\n function RendererFactory() {\n var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];\n\n var cards = _ref.cards;\n var atoms = _ref.atoms;\n var cardOptions = _ref.cardOptions;\n var unknownCardHandler = _ref.unknownCardHandler;\n var unknownAtomHandler = _ref.unknownAtomHandler;\n\n _classCallCheck(this, RendererFactory);\n\n cards = cards || [];\n validateCards(cards);\n atoms = atoms || [];\n validateAtoms(atoms);\n cardOptions = cardOptions || {};\n\n this.state = { cards: cards, atoms: atoms, cardOptions: cardOptions, unknownCardHandler: unknownCardHandler, unknownAtomHandler: unknownAtomHandler };\n }\n\n _createClass(RendererFactory, [{\n key: 'render',\n value: function render(mobiledoc) {\n var version = mobiledoc.version;\n\n switch (version) {\n case _mobiledocTextRendererRenderers02.MOBILEDOC_VERSION:\n return new _mobiledocTextRendererRenderers02['default'](mobiledoc, this.state).render();\n case undefined:\n case null:\n case _mobiledocTextRendererRenderers03.MOBILEDOC_VERSION_0_3:\n case _mobiledocTextRendererRenderers03.MOBILEDOC_VERSION_0_3_1:\n case _mobiledocTextRendererRenderers03.MOBILEDOC_VERSION_0_3_2:\n return new _mobiledocTextRendererRenderers03['default'](mobiledoc, this.state).render();\n default:\n throw new Error('Unexpected Mobiledoc version \"' + version + '\"');\n }\n }\n }]);\n\n return RendererFactory;\n })();\n\n exports['default'] = RendererFactory;\n});","define('mobiledoc-text-renderer/renderers/0-2', ['exports', 'mobiledoc-text-renderer/cards/image', 'mobiledoc-text-renderer/utils/render-type', 'mobiledoc-text-renderer/utils/section-types'], function (exports, _mobiledocTextRendererCardsImage, _mobiledocTextRendererUtilsRenderType, _mobiledocTextRendererUtilsSectionTypes) {\n /**\n * runtime Text renderer\n * renders a mobiledoc to Text\n *\n * input: mobiledoc\n * output: Text (string)\n */\n 'use strict';\n\n var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();\n\n var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();\n\n function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }\n\n var LINE_BREAK = '\\n';\n\n var MOBILEDOC_VERSION = '0.2.0';\n\n exports.MOBILEDOC_VERSION = MOBILEDOC_VERSION;\n function validateVersion(version) {\n if (version !== MOBILEDOC_VERSION) {\n throw new Error('Unexpected Mobiledoc version \"' + version + '\"');\n }\n }\n\n var Renderer = (function () {\n function Renderer(mobiledoc, state) {\n _classCallCheck(this, Renderer);\n\n var cards = state.cards;\n var cardOptions = state.cardOptions;\n var atoms = state.atoms;\n var unknownCardHandler = state.unknownCardHandler;\n var version = mobiledoc.version;\n var sectionData = mobiledoc.sections;\n\n validateVersion(version);\n\n var _sectionData = _slicedToArray(sectionData, 2);\n\n var sections = _sectionData[1];\n\n this.root = [];\n this.sections = sections;\n this.cards = cards;\n this.atoms = atoms;\n this.cardOptions = cardOptions;\n this.unknownCardHandler = unknownCardHandler || this._defaultUnknownCardHandler;\n\n this._teardownCallbacks = [];\n }\n\n _createClass(Renderer, [{\n key: 'render',\n value: function render() {\n var _this = this;\n\n this.sections.forEach(function (section) {\n _this.root.push(_this.renderSection(section));\n });\n\n var result = this.root.join(LINE_BREAK);\n return { result: result, teardown: function teardown() {\n return _this.teardown();\n } };\n }\n }, {\n key: 'teardown',\n value: function teardown() {\n for (var i = 0; i < this._teardownCallbacks.length; i++) {\n this._teardownCallbacks[i]();\n }\n }\n }, {\n key: 'renderSection',\n\n // for the text renderer, a missing card is a no-op\n value: function renderSection(section) {\n var _section = _slicedToArray(section, 1);\n\n var type = _section[0];\n\n switch (type) {\n case _mobiledocTextRendererUtilsSectionTypes.MARKUP_SECTION_TYPE:\n return this.renderMarkupSection(section);\n case _mobiledocTextRendererUtilsSectionTypes.IMAGE_SECTION_TYPE:\n return this.renderImageSection(section);\n case _mobiledocTextRendererUtilsSectionTypes.LIST_SECTION_TYPE:\n return this.renderListSection(section);\n case _mobiledocTextRendererUtilsSectionTypes.CARD_SECTION_TYPE:\n return this.renderCardSection(section);\n default:\n throw new Error('Unimplemented renderer for type ' + type);\n }\n }\n }, {\n key: 'renderImageSection',\n value: function renderImageSection() {\n return '';\n }\n }, {\n key: 'renderListSection',\n value: function renderListSection(_ref) {\n var _this2 = this;\n\n var _ref2 = _slicedToArray(_ref, 3);\n\n var type = _ref2[0];\n var tagName = _ref2[1];\n var items = _ref2[2];\n\n return items.map(function (li) {\n return _this2.renderListItem(li);\n }).join(LINE_BREAK);\n }\n }, {\n key: 'renderListItem',\n value: function renderListItem(markers) {\n return this.renderMarkers(markers);\n }\n }, {\n key: 'findCard',\n value: function findCard(name) {\n for (var i = 0; i < this.cards.length; i++) {\n if (this.cards[i].name === name) {\n return this.cards[i];\n }\n }\n if (name === _mobiledocTextRendererCardsImage['default'].name) {\n return _mobiledocTextRendererCardsImage['default'];\n }\n return this._createUnknownCard(name);\n }\n }, {\n key: '_createUnknownCard',\n value: function _createUnknownCard(name) {\n return {\n name: name,\n type: _mobiledocTextRendererUtilsRenderType['default'],\n render: this.unknownCardHandler\n };\n }\n }, {\n key: 'renderCardSection',\n value: function renderCardSection(_ref3) {\n var _ref32 = _slicedToArray(_ref3, 3);\n\n var type = _ref32[0];\n var name = _ref32[1];\n var payload = _ref32[2];\n\n var card = this.findCard(name);\n\n var cardArg = this._createCardArgument(card, payload);\n var rendered = card.render(cardArg);\n\n this._validateCardRender(rendered, card.name);\n\n return rendered || '';\n }\n }, {\n key: '_validateCardRender',\n value: function _validateCardRender(rendered, cardName) {\n if (!rendered) {\n return;\n }\n\n if (typeof rendered !== 'string') {\n throw new Error('Card \"' + cardName + '\" must render ' + _mobiledocTextRendererUtilsRenderType['default'] + ', but result was ' + typeof rendered + '\"');\n }\n }\n }, {\n key: '_registerTeardownCallback',\n value: function _registerTeardownCallback(callback) {\n this._teardownCallbacks.push(callback);\n }\n }, {\n key: '_createCardArgument',\n value: function _createCardArgument(card) {\n var _this3 = this;\n\n var payload = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];\n\n var env = {\n name: card.name,\n isInEditor: false,\n onTeardown: function onTeardown(callback) {\n return _this3._registerTeardownCallback(callback);\n }\n };\n\n var options = this.cardOptions;\n\n return { env: env, options: options, payload: payload };\n }\n }, {\n key: 'renderMarkupSection',\n value: function renderMarkupSection(_ref4) {\n var _ref42 = _slicedToArray(_ref4, 3);\n\n var type = _ref42[0];\n var tagName = _ref42[1];\n var markers = _ref42[2];\n\n return this.renderMarkers(markers);\n }\n }, {\n key: 'renderMarkers',\n value: function renderMarkers(markers) {\n var str = '';\n markers.forEach(function (m) {\n var _m = _slicedToArray(m, 3);\n\n var text = _m[2];\n\n str += text;\n });\n return str;\n }\n }, {\n key: '_defaultUnknownCardHandler',\n get: function get() {\n return function () {};\n }\n }]);\n\n return Renderer;\n })();\n\n exports['default'] = Renderer;\n});","define('mobiledoc-text-renderer/renderers/0-3', ['exports', 'mobiledoc-text-renderer/cards/image', 'mobiledoc-text-renderer/utils/render-type', 'mobiledoc-text-renderer/utils/section-types', 'mobiledoc-text-renderer/utils/marker-types'], function (exports, _mobiledocTextRendererCardsImage, _mobiledocTextRendererUtilsRenderType, _mobiledocTextRendererUtilsSectionTypes, _mobiledocTextRendererUtilsMarkerTypes) {\n /**\n * runtime Text renderer\n * renders a mobiledoc to Text\n *\n * input: mobiledoc\n * output: Text (string)\n */\n 'use strict';\n\n var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();\n\n var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();\n\n function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }\n\n var LINE_BREAK = '\\n';\n\n var MOBILEDOC_VERSION_0_3 = '0.3.0';\n exports.MOBILEDOC_VERSION_0_3 = MOBILEDOC_VERSION_0_3;\n var MOBILEDOC_VERSION_0_3_1 = '0.3.1';\n exports.MOBILEDOC_VERSION_0_3_1 = MOBILEDOC_VERSION_0_3_1;\n var MOBILEDOC_VERSION_0_3_2 = '0.3.2';\n\n exports.MOBILEDOC_VERSION_0_3_2 = MOBILEDOC_VERSION_0_3_2;\n function validateVersion(version) {\n if (version !== MOBILEDOC_VERSION_0_3 && version !== MOBILEDOC_VERSION_0_3_1 && version !== MOBILEDOC_VERSION_0_3_2) {\n throw new Error('Unexpected Mobiledoc version \"' + version + '\"');\n }\n }\n\n var Renderer = (function () {\n function Renderer(mobiledoc, state) {\n _classCallCheck(this, Renderer);\n\n var cards = state.cards;\n var cardOptions = state.cardOptions;\n var atoms = state.atoms;\n var unknownCardHandler = state.unknownCardHandler;\n var unknownAtomHandler = state.unknownAtomHandler;\n var version = mobiledoc.version;\n var sections = mobiledoc.sections;\n var atomTypes = mobiledoc.atoms;\n var cardTypes = mobiledoc.cards;\n\n validateVersion(version);\n\n this.root = [];\n this.sections = sections;\n this.atomTypes = atomTypes;\n this.cardTypes = cardTypes;\n this.cards = cards;\n this.atoms = atoms;\n this.cardOptions = cardOptions;\n this.unknownCardHandler = unknownCardHandler || this._defaultUnknownCardHandler;\n this.unknownAtomHandler = unknownAtomHandler || this._defaultUnknownAtomHandler;\n\n this._teardownCallbacks = [];\n }\n\n _createClass(Renderer, [{\n key: 'render',\n value: function render() {\n var _this = this;\n\n this.sections.forEach(function (section) {\n _this.root.push(_this.renderSection(section));\n });\n\n var result = this.root.join(LINE_BREAK);\n return { result: result, teardown: function teardown() {\n return _this.teardown();\n } };\n }\n }, {\n key: 'teardown',\n value: function teardown() {\n for (var i = 0; i < this._teardownCallbacks.length; i++) {\n this._teardownCallbacks[i]();\n }\n }\n }, {\n key: 'renderSection',\n value: function renderSection(section) {\n var _section = _slicedToArray(section, 1);\n\n var type = _section[0];\n\n switch (type) {\n case _mobiledocTextRendererUtilsSectionTypes.MARKUP_SECTION_TYPE:\n return this.renderMarkupSection(section);\n case _mobiledocTextRendererUtilsSectionTypes.IMAGE_SECTION_TYPE:\n return this.renderImageSection(section);\n case _mobiledocTextRendererUtilsSectionTypes.LIST_SECTION_TYPE:\n return this.renderListSection(section);\n case _mobiledocTextRendererUtilsSectionTypes.CARD_SECTION_TYPE:\n return this.renderCardSection(section);\n default:\n throw new Error('Unimplemented renderer for type ' + type);\n }\n }\n }, {\n key: 'renderImageSection',\n value: function renderImageSection() {\n return '';\n }\n }, {\n key: 'renderListSection',\n value: function renderListSection(_ref) {\n var _this2 = this;\n\n var _ref2 = _slicedToArray(_ref, 3);\n\n var type = _ref2[0];\n var tagName = _ref2[1];\n var items = _ref2[2];\n\n return items.map(function (li) {\n return _this2.renderListItem(li);\n }).join(LINE_BREAK);\n }\n }, {\n key: 'renderListItem',\n value: function renderListItem(markers) {\n return this.renderMarkers(markers);\n }\n }, {\n key: 'findCard',\n value: function findCard(name) {\n for (var i = 0; i < this.cards.length; i++) {\n if (this.cards[i].name === name) {\n return this.cards[i];\n }\n }\n if (name === _mobiledocTextRendererCardsImage['default'].name) {\n return _mobiledocTextRendererCardsImage['default'];\n }\n return this._createUnknownCard(name);\n }\n }, {\n key: '_findCardByIndex',\n value: function _findCardByIndex(index) {\n var cardType = this.cardTypes[index];\n if (!cardType) {\n throw new Error('No card definition found at index ' + index);\n }\n\n var _cardType = _slicedToArray(cardType, 2);\n\n var name = _cardType[0];\n var payload = _cardType[1];\n\n var card = this.findCard(name);\n\n return {\n card: card,\n payload: payload\n };\n }\n }, {\n key: '_createUnknownCard',\n value: function _createUnknownCard(name) {\n return {\n name: name,\n type: _mobiledocTextRendererUtilsRenderType['default'],\n render: this.unknownCardHandler\n };\n }\n }, {\n key: 'renderCardSection',\n value: function renderCardSection(_ref3) {\n var _ref32 = _slicedToArray(_ref3, 2);\n\n var type = _ref32[0];\n var index = _ref32[1];\n\n var _findCardByIndex2 = this._findCardByIndex(index);\n\n var card = _findCardByIndex2.card;\n var payload = _findCardByIndex2.payload;\n\n var cardArg = this._createCardArgument(card, payload);\n var rendered = card.render(cardArg);\n\n this._validateCardRender(rendered, card.name);\n\n return rendered || '';\n }\n }, {\n key: '_validateCardRender',\n value: function _validateCardRender(rendered, cardName) {\n if (!rendered) {\n return;\n }\n\n if (typeof rendered !== 'string') {\n throw new Error('Card \"' + cardName + '\" must render ' + _mobiledocTextRendererUtilsRenderType['default'] + ', but result was ' + typeof rendered + '\"');\n }\n }\n }, {\n key: '_registerTeardownCallback',\n value: function _registerTeardownCallback(callback) {\n this._teardownCallbacks.push(callback);\n }\n }, {\n key: '_createCardArgument',\n value: function _createCardArgument(card) {\n var _this3 = this;\n\n var payload = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];\n\n var env = {\n name: card.name,\n isInEditor: false,\n onTeardown: function onTeardown(callback) {\n return _this3._registerTeardownCallback(callback);\n }\n };\n\n var options = this.cardOptions;\n\n return { env: env, options: options, payload: payload };\n }\n }, {\n key: 'renderMarkupSection',\n value: function renderMarkupSection(_ref4) {\n var _ref42 = _slicedToArray(_ref4, 3);\n\n var type = _ref42[0];\n var tagName = _ref42[1];\n var markers = _ref42[2];\n\n return this.renderMarkers(markers);\n }\n }, {\n key: 'findAtom',\n value: function findAtom(name) {\n for (var i = 0; i < this.atoms.length; i++) {\n if (this.atoms[i].name === name) {\n return this.atoms[i];\n }\n }\n return this._createUnknownAtom(name);\n }\n }, {\n key: '_createUnknownAtom',\n value: function _createUnknownAtom(name) {\n return {\n name: name,\n type: _mobiledocTextRendererUtilsRenderType['default'],\n render: this.unknownAtomHandler\n };\n }\n }, {\n key: '_createAtomArgument',\n value: function _createAtomArgument(atom, value, payload) {\n var _this4 = this;\n\n var env = {\n name: atom.name,\n onTeardown: function onTeardown(callback) {\n return _this4._registerTeardownCallback(callback);\n }\n };\n\n var options = this.cardOptions;\n\n return { env: env, options: options, value: value, payload: payload };\n }\n }, {\n key: '_validateAtomRender',\n value: function _validateAtomRender(rendered, atomName) {\n if (!rendered) {\n return;\n }\n\n if (typeof rendered !== 'string') {\n throw new Error('Atom \"' + atomName + '\" must render ' + _mobiledocTextRendererUtilsRenderType['default'] + ', but result was ' + typeof rendered + '\"');\n }\n }\n }, {\n key: '_findAtomByIndex',\n value: function _findAtomByIndex(index) {\n var atomType = this.atomTypes[index];\n if (!atomType) {\n throw new Error('No atom definition found at index ' + index);\n }\n\n var _atomType = _slicedToArray(atomType, 3);\n\n var name = _atomType[0];\n var value = _atomType[1];\n var payload = _atomType[2];\n\n var atom = this.findAtom(name);\n\n return {\n atom: atom,\n value: value,\n payload: payload\n };\n }\n }, {\n key: '_renderAtom',\n value: function _renderAtom(index) {\n var _findAtomByIndex2 = this._findAtomByIndex(index);\n\n var atom = _findAtomByIndex2.atom;\n var value = _findAtomByIndex2.value;\n var payload = _findAtomByIndex2.payload;\n\n var atomArg = this._createAtomArgument(atom, value, payload);\n var rendered = atom.render(atomArg);\n\n this._validateAtomRender(rendered, atom.name);\n\n return rendered || '';\n }\n }, {\n key: 'renderMarkers',\n value: function renderMarkers(markers) {\n var _this5 = this;\n\n var str = '';\n markers.forEach(function (m) {\n var _m = _slicedToArray(m, 4);\n\n var type = _m[0];\n var value = _m[3];\n\n switch (type) {\n case _mobiledocTextRendererUtilsMarkerTypes.MARKUP_MARKER_TYPE:\n str += value;\n break;\n case _mobiledocTextRendererUtilsMarkerTypes.ATOM_MARKER_TYPE:\n str += _this5._renderAtom(value);\n break;\n default:\n throw new Error('Unknown markup type (' + type + ')');\n }\n });\n return str;\n }\n }, {\n key: '_defaultUnknownCardHandler',\n get: function get() {\n return function () {\n // for the text renderer, a missing card is a no-op\n };\n }\n }, {\n key: '_defaultUnknownAtomHandler',\n get: function get() {\n return function (_ref5) {\n var value = _ref5.value;\n\n return value || '';\n };\n }\n }]);\n\n return Renderer;\n })();\n\n exports['default'] = Renderer;\n});","define(\"mobiledoc-text-renderer/utils/marker-types\", [\"exports\"], function (exports) {\n \"use strict\";\n\n var MARKUP_MARKER_TYPE = 0;\n exports.MARKUP_MARKER_TYPE = MARKUP_MARKER_TYPE;\n var ATOM_MARKER_TYPE = 1;\n exports.ATOM_MARKER_TYPE = ATOM_MARKER_TYPE;\n});","define('mobiledoc-text-renderer/utils/render-type', ['exports'], function (exports) {\n 'use strict';\n\n exports['default'] = 'text';\n});","define(\"mobiledoc-text-renderer/utils/section-types\", [\"exports\"], function (exports) {\n \"use strict\";\n\n var MARKUP_SECTION_TYPE = 1;\n exports.MARKUP_SECTION_TYPE = MARKUP_SECTION_TYPE;\n var IMAGE_SECTION_TYPE = 2;\n exports.IMAGE_SECTION_TYPE = IMAGE_SECTION_TYPE;\n var LIST_SECTION_TYPE = 3;\n exports.LIST_SECTION_TYPE = LIST_SECTION_TYPE;\n var CARD_SECTION_TYPE = 10;\n exports.CARD_SECTION_TYPE = CARD_SECTION_TYPE;\n});"],"names":[],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9UA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5WA;AACA;AACA;AACA;AACA;AACA;AACA;;ACNA;AACA;AACA;AACA;;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;","file":"mobiledoc-text-renderer.js"}