parchment.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["Parchment"] = factory();
  8. else
  9. root["Parchment"] = factory();
  10. })(typeof self !== 'undefined' ? self : this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, {
  50. /******/ configurable: false,
  51. /******/ enumerable: true,
  52. /******/ get: getter
  53. /******/ });
  54. /******/ }
  55. /******/ };
  56. /******/
  57. /******/ // getDefaultExport function for compatibility with non-harmony modules
  58. /******/ __webpack_require__.n = function(module) {
  59. /******/ var getter = module && module.__esModule ?
  60. /******/ function getDefault() { return module['default']; } :
  61. /******/ function getModuleExports() { return module; };
  62. /******/ __webpack_require__.d(getter, 'a', getter);
  63. /******/ return getter;
  64. /******/ };
  65. /******/
  66. /******/ // Object.prototype.hasOwnProperty.call
  67. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  68. /******/
  69. /******/ // __webpack_public_path__
  70. /******/ __webpack_require__.p = "";
  71. /******/
  72. /******/ // Load entry module and return exports
  73. /******/ return __webpack_require__(__webpack_require__.s = 9);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports, __webpack_require__) {
  79. "use strict";
  80. var __extends = (this && this.__extends) || (function () {
  81. var extendStatics = Object.setPrototypeOf ||
  82. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  83. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  84. return function (d, b) {
  85. extendStatics(d, b);
  86. function __() { this.constructor = d; }
  87. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  88. };
  89. })();
  90. Object.defineProperty(exports, "__esModule", { value: true });
  91. var ParchmentError = /** @class */ (function (_super) {
  92. __extends(ParchmentError, _super);
  93. function ParchmentError(message) {
  94. var _this = this;
  95. message = '[Parchment] ' + message;
  96. _this = _super.call(this, message) || this;
  97. _this.message = message;
  98. _this.name = _this.constructor.name;
  99. return _this;
  100. }
  101. return ParchmentError;
  102. }(Error));
  103. exports.ParchmentError = ParchmentError;
  104. var attributes = {};
  105. var classes = {};
  106. var tags = {};
  107. var types = {};
  108. exports.DATA_KEY = '__blot';
  109. var Scope;
  110. (function (Scope) {
  111. Scope[Scope["TYPE"] = 3] = "TYPE";
  112. Scope[Scope["LEVEL"] = 12] = "LEVEL";
  113. Scope[Scope["ATTRIBUTE"] = 13] = "ATTRIBUTE";
  114. Scope[Scope["BLOT"] = 14] = "BLOT";
  115. Scope[Scope["INLINE"] = 7] = "INLINE";
  116. Scope[Scope["BLOCK"] = 11] = "BLOCK";
  117. Scope[Scope["BLOCK_BLOT"] = 10] = "BLOCK_BLOT";
  118. Scope[Scope["INLINE_BLOT"] = 6] = "INLINE_BLOT";
  119. Scope[Scope["BLOCK_ATTRIBUTE"] = 9] = "BLOCK_ATTRIBUTE";
  120. Scope[Scope["INLINE_ATTRIBUTE"] = 5] = "INLINE_ATTRIBUTE";
  121. Scope[Scope["ANY"] = 15] = "ANY";
  122. })(Scope = exports.Scope || (exports.Scope = {}));
  123. function create(input, value) {
  124. var match = query(input);
  125. if (match == null) {
  126. throw new ParchmentError("Unable to create " + input + " blot");
  127. }
  128. var BlotClass = match;
  129. var node =
  130. // @ts-ignore
  131. input instanceof Node || input['nodeType'] === Node.TEXT_NODE ? input : BlotClass.create(value);
  132. return new BlotClass(node, value);
  133. }
  134. exports.create = create;
  135. function find(node, bubble) {
  136. if (bubble === void 0) { bubble = false; }
  137. if (node == null)
  138. return null;
  139. // @ts-ignore
  140. if (node[exports.DATA_KEY] != null)
  141. return node[exports.DATA_KEY].blot;
  142. if (bubble)
  143. return find(node.parentNode, bubble);
  144. return null;
  145. }
  146. exports.find = find;
  147. function query(query, scope) {
  148. if (scope === void 0) { scope = Scope.ANY; }
  149. var match;
  150. if (typeof query === 'string') {
  151. match = types[query] || attributes[query];
  152. // @ts-ignore
  153. }
  154. else if (query instanceof Text || query['nodeType'] === Node.TEXT_NODE) {
  155. match = types['text'];
  156. }
  157. else if (typeof query === 'number') {
  158. if (query & Scope.LEVEL & Scope.BLOCK) {
  159. match = types['block'];
  160. }
  161. else if (query & Scope.LEVEL & Scope.INLINE) {
  162. match = types['inline'];
  163. }
  164. }
  165. else if (query instanceof HTMLElement) {
  166. var names = (query.getAttribute('class') || '').split(/\s+/);
  167. for (var i in names) {
  168. match = classes[names[i]];
  169. if (match)
  170. break;
  171. }
  172. match = match || tags[query.tagName];
  173. }
  174. if (match == null)
  175. return null;
  176. // @ts-ignore
  177. if (scope & Scope.LEVEL & match.scope && scope & Scope.TYPE & match.scope)
  178. return match;
  179. return null;
  180. }
  181. exports.query = query;
  182. function register() {
  183. var Definitions = [];
  184. for (var _i = 0; _i < arguments.length; _i++) {
  185. Definitions[_i] = arguments[_i];
  186. }
  187. if (Definitions.length > 1) {
  188. return Definitions.map(function (d) {
  189. return register(d);
  190. });
  191. }
  192. var Definition = Definitions[0];
  193. if (typeof Definition.blotName !== 'string' && typeof Definition.attrName !== 'string') {
  194. throw new ParchmentError('Invalid definition');
  195. }
  196. else if (Definition.blotName === 'abstract') {
  197. throw new ParchmentError('Cannot register abstract class');
  198. }
  199. types[Definition.blotName || Definition.attrName] = Definition;
  200. if (typeof Definition.keyName === 'string') {
  201. attributes[Definition.keyName] = Definition;
  202. }
  203. else {
  204. if (Definition.className != null) {
  205. classes[Definition.className] = Definition;
  206. }
  207. if (Definition.tagName != null) {
  208. if (Array.isArray(Definition.tagName)) {
  209. Definition.tagName = Definition.tagName.map(function (tagName) {
  210. return tagName.toUpperCase();
  211. });
  212. }
  213. else {
  214. Definition.tagName = Definition.tagName.toUpperCase();
  215. }
  216. var tagNames = Array.isArray(Definition.tagName) ? Definition.tagName : [Definition.tagName];
  217. tagNames.forEach(function (tag) {
  218. if (tags[tag] == null || Definition.className == null) {
  219. tags[tag] = Definition;
  220. }
  221. });
  222. }
  223. }
  224. return Definition;
  225. }
  226. exports.register = register;
  227. /***/ }),
  228. /* 1 */
  229. /***/ (function(module, exports, __webpack_require__) {
  230. "use strict";
  231. Object.defineProperty(exports, "__esModule", { value: true });
  232. var Registry = __webpack_require__(0);
  233. var Attributor = /** @class */ (function () {
  234. function Attributor(attrName, keyName, options) {
  235. if (options === void 0) { options = {}; }
  236. this.attrName = attrName;
  237. this.keyName = keyName;
  238. var attributeBit = Registry.Scope.TYPE & Registry.Scope.ATTRIBUTE;
  239. if (options.scope != null) {
  240. // Ignore type bits, force attribute bit
  241. this.scope = (options.scope & Registry.Scope.LEVEL) | attributeBit;
  242. }
  243. else {
  244. this.scope = Registry.Scope.ATTRIBUTE;
  245. }
  246. if (options.whitelist != null)
  247. this.whitelist = options.whitelist;
  248. }
  249. Attributor.keys = function (node) {
  250. return [].map.call(node.attributes, function (item) {
  251. return item.name;
  252. });
  253. };
  254. Attributor.prototype.add = function (node, value) {
  255. if (!this.canAdd(node, value))
  256. return false;
  257. node.setAttribute(this.keyName, value);
  258. return true;
  259. };
  260. Attributor.prototype.canAdd = function (node, value) {
  261. var match = Registry.query(node, Registry.Scope.BLOT & (this.scope | Registry.Scope.TYPE));
  262. if (match == null)
  263. return false;
  264. if (this.whitelist == null)
  265. return true;
  266. if (typeof value === 'string') {
  267. return this.whitelist.indexOf(value.replace(/["']/g, '')) > -1;
  268. }
  269. else {
  270. return this.whitelist.indexOf(value) > -1;
  271. }
  272. };
  273. Attributor.prototype.remove = function (node) {
  274. node.removeAttribute(this.keyName);
  275. };
  276. Attributor.prototype.value = function (node) {
  277. var value = node.getAttribute(this.keyName);
  278. if (this.canAdd(node, value) && value) {
  279. return value;
  280. }
  281. return '';
  282. };
  283. return Attributor;
  284. }());
  285. exports.default = Attributor;
  286. /***/ }),
  287. /* 2 */
  288. /***/ (function(module, exports, __webpack_require__) {
  289. "use strict";
  290. var __extends = (this && this.__extends) || (function () {
  291. var extendStatics = Object.setPrototypeOf ||
  292. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  293. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  294. return function (d, b) {
  295. extendStatics(d, b);
  296. function __() { this.constructor = d; }
  297. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  298. };
  299. })();
  300. Object.defineProperty(exports, "__esModule", { value: true });
  301. var linked_list_1 = __webpack_require__(11);
  302. var shadow_1 = __webpack_require__(5);
  303. var Registry = __webpack_require__(0);
  304. var ContainerBlot = /** @class */ (function (_super) {
  305. __extends(ContainerBlot, _super);
  306. function ContainerBlot(domNode) {
  307. var _this = _super.call(this, domNode) || this;
  308. _this.build();
  309. return _this;
  310. }
  311. ContainerBlot.prototype.appendChild = function (other) {
  312. this.insertBefore(other);
  313. };
  314. ContainerBlot.prototype.attach = function () {
  315. _super.prototype.attach.call(this);
  316. this.children.forEach(function (child) {
  317. child.attach();
  318. });
  319. };
  320. ContainerBlot.prototype.build = function () {
  321. var _this = this;
  322. this.children = new linked_list_1.default();
  323. // Need to be reversed for if DOM nodes already in order
  324. [].slice
  325. .call(this.domNode.childNodes)
  326. .reverse()
  327. .forEach(function (node) {
  328. try {
  329. var child = makeBlot(node);
  330. _this.insertBefore(child, _this.children.head || undefined);
  331. }
  332. catch (err) {
  333. if (err instanceof Registry.ParchmentError)
  334. return;
  335. else
  336. throw err;
  337. }
  338. });
  339. };
  340. ContainerBlot.prototype.deleteAt = function (index, length) {
  341. if (index === 0 && length === this.length()) {
  342. return this.remove();
  343. }
  344. this.children.forEachAt(index, length, function (child, offset, length) {
  345. child.deleteAt(offset, length);
  346. });
  347. };
  348. ContainerBlot.prototype.descendant = function (criteria, index) {
  349. var _a = this.children.find(index), child = _a[0], offset = _a[1];
  350. if ((criteria.blotName == null && criteria(child)) ||
  351. (criteria.blotName != null && child instanceof criteria)) {
  352. return [child, offset];
  353. }
  354. else if (child instanceof ContainerBlot) {
  355. return child.descendant(criteria, offset);
  356. }
  357. else {
  358. return [null, -1];
  359. }
  360. };
  361. ContainerBlot.prototype.descendants = function (criteria, index, length) {
  362. if (index === void 0) { index = 0; }
  363. if (length === void 0) { length = Number.MAX_VALUE; }
  364. var descendants = [];
  365. var lengthLeft = length;
  366. this.children.forEachAt(index, length, function (child, index, length) {
  367. if ((criteria.blotName == null && criteria(child)) ||
  368. (criteria.blotName != null && child instanceof criteria)) {
  369. descendants.push(child);
  370. }
  371. if (child instanceof ContainerBlot) {
  372. descendants = descendants.concat(child.descendants(criteria, index, lengthLeft));
  373. }
  374. lengthLeft -= length;
  375. });
  376. return descendants;
  377. };
  378. ContainerBlot.prototype.detach = function () {
  379. this.children.forEach(function (child) {
  380. child.detach();
  381. });
  382. _super.prototype.detach.call(this);
  383. };
  384. ContainerBlot.prototype.formatAt = function (index, length, name, value) {
  385. this.children.forEachAt(index, length, function (child, offset, length) {
  386. child.formatAt(offset, length, name, value);
  387. });
  388. };
  389. ContainerBlot.prototype.insertAt = function (index, value, def) {
  390. var _a = this.children.find(index), child = _a[0], offset = _a[1];
  391. if (child) {
  392. child.insertAt(offset, value, def);
  393. }
  394. else {
  395. var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
  396. this.appendChild(blot);
  397. }
  398. };
  399. ContainerBlot.prototype.insertBefore = function (childBlot, refBlot) {
  400. if (this.statics.allowedChildren != null &&
  401. !this.statics.allowedChildren.some(function (child) {
  402. return childBlot instanceof child;
  403. })) {
  404. throw new Registry.ParchmentError("Cannot insert " + childBlot.statics.blotName + " into " + this.statics.blotName);
  405. }
  406. childBlot.insertInto(this, refBlot);
  407. };
  408. ContainerBlot.prototype.length = function () {
  409. return this.children.reduce(function (memo, child) {
  410. return memo + child.length();
  411. }, 0);
  412. };
  413. ContainerBlot.prototype.moveChildren = function (targetParent, refNode) {
  414. this.children.forEach(function (child) {
  415. targetParent.insertBefore(child, refNode);
  416. });
  417. };
  418. ContainerBlot.prototype.optimize = function (context) {
  419. _super.prototype.optimize.call(this, context);
  420. if (this.children.length === 0) {
  421. if (this.statics.defaultChild != null) {
  422. var child = Registry.create(this.statics.defaultChild);
  423. this.appendChild(child);
  424. child.optimize(context);
  425. }
  426. else {
  427. this.remove();
  428. }
  429. }
  430. };
  431. ContainerBlot.prototype.path = function (index, inclusive) {
  432. if (inclusive === void 0) { inclusive = false; }
  433. var _a = this.children.find(index, inclusive), child = _a[0], offset = _a[1];
  434. var position = [[this, index]];
  435. if (child instanceof ContainerBlot) {
  436. return position.concat(child.path(offset, inclusive));
  437. }
  438. else if (child != null) {
  439. position.push([child, offset]);
  440. }
  441. return position;
  442. };
  443. ContainerBlot.prototype.removeChild = function (child) {
  444. this.children.remove(child);
  445. };
  446. ContainerBlot.prototype.replace = function (target) {
  447. if (target instanceof ContainerBlot) {
  448. target.moveChildren(this);
  449. }
  450. _super.prototype.replace.call(this, target);
  451. };
  452. ContainerBlot.prototype.split = function (index, force) {
  453. if (force === void 0) { force = false; }
  454. if (!force) {
  455. if (index === 0)
  456. return this;
  457. if (index === this.length())
  458. return this.next;
  459. }
  460. var after = this.clone();
  461. this.parent.insertBefore(after, this.next);
  462. this.children.forEachAt(index, this.length(), function (child, offset, length) {
  463. child = child.split(offset, force);
  464. after.appendChild(child);
  465. });
  466. return after;
  467. };
  468. ContainerBlot.prototype.unwrap = function () {
  469. this.moveChildren(this.parent, this.next);
  470. this.remove();
  471. };
  472. ContainerBlot.prototype.update = function (mutations, context) {
  473. var _this = this;
  474. var addedNodes = [];
  475. var removedNodes = [];
  476. mutations.forEach(function (mutation) {
  477. if (mutation.target === _this.domNode && mutation.type === 'childList') {
  478. addedNodes.push.apply(addedNodes, mutation.addedNodes);
  479. removedNodes.push.apply(removedNodes, mutation.removedNodes);
  480. }
  481. });
  482. removedNodes.forEach(function (node) {
  483. // Check node has actually been removed
  484. // One exception is Chrome does not immediately remove IFRAMEs
  485. // from DOM but MutationRecord is correct in its reported removal
  486. if (node.parentNode != null &&
  487. // @ts-ignore
  488. node.tagName !== 'IFRAME' &&
  489. document.body.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) {
  490. return;
  491. }
  492. var blot = Registry.find(node);
  493. if (blot == null)
  494. return;
  495. if (blot.domNode.parentNode == null || blot.domNode.parentNode === _this.domNode) {
  496. blot.detach();
  497. }
  498. });
  499. addedNodes
  500. .filter(function (node) {
  501. return node.parentNode == _this.domNode;
  502. })
  503. .sort(function (a, b) {
  504. if (a === b)
  505. return 0;
  506. if (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) {
  507. return 1;
  508. }
  509. return -1;
  510. })
  511. .forEach(function (node) {
  512. var refBlot = null;
  513. if (node.nextSibling != null) {
  514. refBlot = Registry.find(node.nextSibling);
  515. }
  516. var blot = makeBlot(node);
  517. if (blot.next != refBlot || blot.next == null) {
  518. if (blot.parent != null) {
  519. blot.parent.removeChild(_this);
  520. }
  521. _this.insertBefore(blot, refBlot || undefined);
  522. }
  523. });
  524. };
  525. return ContainerBlot;
  526. }(shadow_1.default));
  527. function makeBlot(node) {
  528. var blot = Registry.find(node);
  529. if (blot == null) {
  530. try {
  531. blot = Registry.create(node);
  532. }
  533. catch (e) {
  534. blot = Registry.create(Registry.Scope.INLINE);
  535. [].slice.call(node.childNodes).forEach(function (child) {
  536. // @ts-ignore
  537. blot.domNode.appendChild(child);
  538. });
  539. if (node.parentNode) {
  540. node.parentNode.replaceChild(blot.domNode, node);
  541. }
  542. blot.attach();
  543. }
  544. }
  545. return blot;
  546. }
  547. exports.default = ContainerBlot;
  548. /***/ }),
  549. /* 3 */
  550. /***/ (function(module, exports, __webpack_require__) {
  551. "use strict";
  552. var __extends = (this && this.__extends) || (function () {
  553. var extendStatics = Object.setPrototypeOf ||
  554. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  555. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  556. return function (d, b) {
  557. extendStatics(d, b);
  558. function __() { this.constructor = d; }
  559. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  560. };
  561. })();
  562. Object.defineProperty(exports, "__esModule", { value: true });
  563. var attributor_1 = __webpack_require__(1);
  564. var store_1 = __webpack_require__(6);
  565. var container_1 = __webpack_require__(2);
  566. var Registry = __webpack_require__(0);
  567. var FormatBlot = /** @class */ (function (_super) {
  568. __extends(FormatBlot, _super);
  569. function FormatBlot(domNode) {
  570. var _this = _super.call(this, domNode) || this;
  571. _this.attributes = new store_1.default(_this.domNode);
  572. return _this;
  573. }
  574. FormatBlot.formats = function (domNode) {
  575. if (typeof this.tagName === 'string') {
  576. return true;
  577. }
  578. else if (Array.isArray(this.tagName)) {
  579. return domNode.tagName.toLowerCase();
  580. }
  581. return undefined;
  582. };
  583. FormatBlot.prototype.format = function (name, value) {
  584. var format = Registry.query(name);
  585. if (format instanceof attributor_1.default) {
  586. this.attributes.attribute(format, value);
  587. }
  588. else if (value) {
  589. if (format != null && (name !== this.statics.blotName || this.formats()[name] !== value)) {
  590. this.replaceWith(name, value);
  591. }
  592. }
  593. };
  594. FormatBlot.prototype.formats = function () {
  595. var formats = this.attributes.values();
  596. var format = this.statics.formats(this.domNode);
  597. if (format != null) {
  598. formats[this.statics.blotName] = format;
  599. }
  600. return formats;
  601. };
  602. FormatBlot.prototype.replaceWith = function (name, value) {
  603. var replacement = _super.prototype.replaceWith.call(this, name, value);
  604. this.attributes.copy(replacement);
  605. return replacement;
  606. };
  607. FormatBlot.prototype.update = function (mutations, context) {
  608. var _this = this;
  609. _super.prototype.update.call(this, mutations, context);
  610. if (mutations.some(function (mutation) {
  611. return mutation.target === _this.domNode && mutation.type === 'attributes';
  612. })) {
  613. this.attributes.build();
  614. }
  615. };
  616. FormatBlot.prototype.wrap = function (name, value) {
  617. var wrapper = _super.prototype.wrap.call(this, name, value);
  618. if (wrapper instanceof FormatBlot && wrapper.statics.scope === this.statics.scope) {
  619. this.attributes.move(wrapper);
  620. }
  621. return wrapper;
  622. };
  623. return FormatBlot;
  624. }(container_1.default));
  625. exports.default = FormatBlot;
  626. /***/ }),
  627. /* 4 */
  628. /***/ (function(module, exports, __webpack_require__) {
  629. "use strict";
  630. var __extends = (this && this.__extends) || (function () {
  631. var extendStatics = Object.setPrototypeOf ||
  632. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  633. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  634. return function (d, b) {
  635. extendStatics(d, b);
  636. function __() { this.constructor = d; }
  637. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  638. };
  639. })();
  640. Object.defineProperty(exports, "__esModule", { value: true });
  641. var shadow_1 = __webpack_require__(5);
  642. var Registry = __webpack_require__(0);
  643. var LeafBlot = /** @class */ (function (_super) {
  644. __extends(LeafBlot, _super);
  645. function LeafBlot() {
  646. return _super !== null && _super.apply(this, arguments) || this;
  647. }
  648. LeafBlot.value = function (domNode) {
  649. return true;
  650. };
  651. LeafBlot.prototype.index = function (node, offset) {
  652. if (this.domNode === node ||
  653. this.domNode.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY) {
  654. return Math.min(offset, 1);
  655. }
  656. return -1;
  657. };
  658. LeafBlot.prototype.position = function (index, inclusive) {
  659. var offset = [].indexOf.call(this.parent.domNode.childNodes, this.domNode);
  660. if (index > 0)
  661. offset += 1;
  662. return [this.parent.domNode, offset];
  663. };
  664. LeafBlot.prototype.value = function () {
  665. return _a = {}, _a[this.statics.blotName] = this.statics.value(this.domNode) || true, _a;
  666. var _a;
  667. };
  668. LeafBlot.scope = Registry.Scope.INLINE_BLOT;
  669. return LeafBlot;
  670. }(shadow_1.default));
  671. exports.default = LeafBlot;
  672. /***/ }),
  673. /* 5 */
  674. /***/ (function(module, exports, __webpack_require__) {
  675. "use strict";
  676. Object.defineProperty(exports, "__esModule", { value: true });
  677. var Registry = __webpack_require__(0);
  678. var ShadowBlot = /** @class */ (function () {
  679. function ShadowBlot(domNode) {
  680. this.domNode = domNode;
  681. // @ts-ignore
  682. this.domNode[Registry.DATA_KEY] = { blot: this };
  683. }
  684. Object.defineProperty(ShadowBlot.prototype, "statics", {
  685. // Hack for accessing inherited static methods
  686. get: function () {
  687. return this.constructor;
  688. },
  689. enumerable: true,
  690. configurable: true
  691. });
  692. ShadowBlot.create = function (value) {
  693. if (this.tagName == null) {
  694. throw new Registry.ParchmentError('Blot definition missing tagName');
  695. }
  696. var node;
  697. if (Array.isArray(this.tagName)) {
  698. if (typeof value === 'string') {
  699. value = value.toUpperCase();
  700. if (parseInt(value).toString() === value) {
  701. value = parseInt(value);
  702. }
  703. }
  704. if (typeof value === 'number') {
  705. node = document.createElement(this.tagName[value - 1]);
  706. }
  707. else if (this.tagName.indexOf(value) > -1) {
  708. node = document.createElement(value);
  709. }
  710. else {
  711. node = document.createElement(this.tagName[0]);
  712. }
  713. }
  714. else {
  715. node = document.createElement(this.tagName);
  716. }
  717. if (this.className) {
  718. node.classList.add(this.className);
  719. }
  720. return node;
  721. };
  722. ShadowBlot.prototype.attach = function () {
  723. if (this.parent != null) {
  724. this.scroll = this.parent.scroll;
  725. }
  726. };
  727. ShadowBlot.prototype.clone = function () {
  728. var domNode = this.domNode.cloneNode(false);
  729. return Registry.create(domNode);
  730. };
  731. ShadowBlot.prototype.detach = function () {
  732. if (this.parent != null)
  733. this.parent.removeChild(this);
  734. // @ts-ignore
  735. delete this.domNode[Registry.DATA_KEY];
  736. };
  737. ShadowBlot.prototype.deleteAt = function (index, length) {
  738. var blot = this.isolate(index, length);
  739. blot.remove();
  740. };
  741. ShadowBlot.prototype.formatAt = function (index, length, name, value) {
  742. var blot = this.isolate(index, length);
  743. if (Registry.query(name, Registry.Scope.BLOT) != null && value) {
  744. blot.wrap(name, value);
  745. }
  746. else if (Registry.query(name, Registry.Scope.ATTRIBUTE) != null) {
  747. var parent_1 = Registry.create(this.statics.scope);
  748. blot.wrap(parent_1);
  749. parent_1.format(name, value);
  750. }
  751. };
  752. ShadowBlot.prototype.insertAt = function (index, value, def) {
  753. var blot = def == null ? Registry.create('text', value) : Registry.create(value, def);
  754. var ref = this.split(index);
  755. this.parent.insertBefore(blot, ref);
  756. };
  757. ShadowBlot.prototype.insertInto = function (parentBlot, refBlot) {
  758. if (refBlot === void 0) { refBlot = null; }
  759. if (this.parent != null) {
  760. this.parent.children.remove(this);
  761. }
  762. var refDomNode = null;
  763. parentBlot.children.insertBefore(this, refBlot);
  764. if (refBlot != null) {
  765. refDomNode = refBlot.domNode;
  766. }
  767. if (this.domNode.parentNode != parentBlot.domNode ||
  768. this.domNode.nextSibling != refDomNode) {
  769. parentBlot.domNode.insertBefore(this.domNode, refDomNode);
  770. }
  771. this.parent = parentBlot;
  772. this.attach();
  773. };
  774. ShadowBlot.prototype.isolate = function (index, length) {
  775. var target = this.split(index);
  776. target.split(length);
  777. return target;
  778. };
  779. ShadowBlot.prototype.length = function () {
  780. return 1;
  781. };
  782. ShadowBlot.prototype.offset = function (root) {
  783. if (root === void 0) { root = this.parent; }
  784. if (this.parent == null || this == root)
  785. return 0;
  786. return this.parent.children.offset(this) + this.parent.offset(root);
  787. };
  788. ShadowBlot.prototype.optimize = function (context) {
  789. // TODO clean up once we use WeakMap
  790. // @ts-ignore
  791. if (this.domNode[Registry.DATA_KEY] != null) {
  792. // @ts-ignore
  793. delete this.domNode[Registry.DATA_KEY].mutations;
  794. }
  795. };
  796. ShadowBlot.prototype.remove = function () {
  797. if (this.domNode.parentNode != null) {
  798. this.domNode.parentNode.removeChild(this.domNode);
  799. }
  800. this.detach();
  801. };
  802. ShadowBlot.prototype.replace = function (target) {
  803. if (target.parent == null)
  804. return;
  805. target.parent.insertBefore(this, target.next);
  806. target.remove();
  807. };
  808. ShadowBlot.prototype.replaceWith = function (name, value) {
  809. var replacement = typeof name === 'string' ? Registry.create(name, value) : name;
  810. replacement.replace(this);
  811. return replacement;
  812. };
  813. ShadowBlot.prototype.split = function (index, force) {
  814. return index === 0 ? this : this.next;
  815. };
  816. ShadowBlot.prototype.update = function (mutations, context) {
  817. // Nothing to do by default
  818. };
  819. ShadowBlot.prototype.wrap = function (name, value) {
  820. var wrapper = typeof name === 'string' ? Registry.create(name, value) : name;
  821. if (this.parent != null) {
  822. this.parent.insertBefore(wrapper, this.next);
  823. }
  824. wrapper.appendChild(this);
  825. return wrapper;
  826. };
  827. ShadowBlot.blotName = 'abstract';
  828. return ShadowBlot;
  829. }());
  830. exports.default = ShadowBlot;
  831. /***/ }),
  832. /* 6 */
  833. /***/ (function(module, exports, __webpack_require__) {
  834. "use strict";
  835. Object.defineProperty(exports, "__esModule", { value: true });
  836. var attributor_1 = __webpack_require__(1);
  837. var class_1 = __webpack_require__(7);
  838. var style_1 = __webpack_require__(8);
  839. var Registry = __webpack_require__(0);
  840. var AttributorStore = /** @class */ (function () {
  841. function AttributorStore(domNode) {
  842. this.attributes = {};
  843. this.domNode = domNode;
  844. this.build();
  845. }
  846. AttributorStore.prototype.attribute = function (attribute, value) {
  847. // verb
  848. if (value) {
  849. if (attribute.add(this.domNode, value)) {
  850. if (attribute.value(this.domNode) != null) {
  851. this.attributes[attribute.attrName] = attribute;
  852. }
  853. else {
  854. delete this.attributes[attribute.attrName];
  855. }
  856. }
  857. }
  858. else {
  859. attribute.remove(this.domNode);
  860. delete this.attributes[attribute.attrName];
  861. }
  862. };
  863. AttributorStore.prototype.build = function () {
  864. var _this = this;
  865. this.attributes = {};
  866. var attributes = attributor_1.default.keys(this.domNode);
  867. var classes = class_1.default.keys(this.domNode);
  868. var styles = style_1.default.keys(this.domNode);
  869. attributes
  870. .concat(classes)
  871. .concat(styles)
  872. .forEach(function (name) {
  873. var attr = Registry.query(name, Registry.Scope.ATTRIBUTE);
  874. if (attr instanceof attributor_1.default) {
  875. _this.attributes[attr.attrName] = attr;
  876. }
  877. });
  878. };
  879. AttributorStore.prototype.copy = function (target) {
  880. var _this = this;
  881. Object.keys(this.attributes).forEach(function (key) {
  882. var value = _this.attributes[key].value(_this.domNode);
  883. target.format(key, value);
  884. });
  885. };
  886. AttributorStore.prototype.move = function (target) {
  887. var _this = this;
  888. this.copy(target);
  889. Object.keys(this.attributes).forEach(function (key) {
  890. _this.attributes[key].remove(_this.domNode);
  891. });
  892. this.attributes = {};
  893. };
  894. AttributorStore.prototype.values = function () {
  895. var _this = this;
  896. return Object.keys(this.attributes).reduce(function (attributes, name) {
  897. attributes[name] = _this.attributes[name].value(_this.domNode);
  898. return attributes;
  899. }, {});
  900. };
  901. return AttributorStore;
  902. }());
  903. exports.default = AttributorStore;
  904. /***/ }),
  905. /* 7 */
  906. /***/ (function(module, exports, __webpack_require__) {
  907. "use strict";
  908. var __extends = (this && this.__extends) || (function () {
  909. var extendStatics = Object.setPrototypeOf ||
  910. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  911. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  912. return function (d, b) {
  913. extendStatics(d, b);
  914. function __() { this.constructor = d; }
  915. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  916. };
  917. })();
  918. Object.defineProperty(exports, "__esModule", { value: true });
  919. var attributor_1 = __webpack_require__(1);
  920. function match(node, prefix) {
  921. var className = node.getAttribute('class') || '';
  922. return className.split(/\s+/).filter(function (name) {
  923. return name.indexOf(prefix + "-") === 0;
  924. });
  925. }
  926. var ClassAttributor = /** @class */ (function (_super) {
  927. __extends(ClassAttributor, _super);
  928. function ClassAttributor() {
  929. return _super !== null && _super.apply(this, arguments) || this;
  930. }
  931. ClassAttributor.keys = function (node) {
  932. return (node.getAttribute('class') || '').split(/\s+/).map(function (name) {
  933. return name
  934. .split('-')
  935. .slice(0, -1)
  936. .join('-');
  937. });
  938. };
  939. ClassAttributor.prototype.add = function (node, value) {
  940. if (!this.canAdd(node, value))
  941. return false;
  942. this.remove(node);
  943. node.classList.add(this.keyName + "-" + value);
  944. return true;
  945. };
  946. ClassAttributor.prototype.remove = function (node) {
  947. var matches = match(node, this.keyName);
  948. matches.forEach(function (name) {
  949. node.classList.remove(name);
  950. });
  951. if (node.classList.length === 0) {
  952. node.removeAttribute('class');
  953. }
  954. };
  955. ClassAttributor.prototype.value = function (node) {
  956. var result = match(node, this.keyName)[0] || '';
  957. var value = result.slice(this.keyName.length + 1); // +1 for hyphen
  958. return this.canAdd(node, value) ? value : '';
  959. };
  960. return ClassAttributor;
  961. }(attributor_1.default));
  962. exports.default = ClassAttributor;
  963. /***/ }),
  964. /* 8 */
  965. /***/ (function(module, exports, __webpack_require__) {
  966. "use strict";
  967. var __extends = (this && this.__extends) || (function () {
  968. var extendStatics = Object.setPrototypeOf ||
  969. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  970. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  971. return function (d, b) {
  972. extendStatics(d, b);
  973. function __() { this.constructor = d; }
  974. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  975. };
  976. })();
  977. Object.defineProperty(exports, "__esModule", { value: true });
  978. var attributor_1 = __webpack_require__(1);
  979. function camelize(name) {
  980. var parts = name.split('-');
  981. var rest = parts
  982. .slice(1)
  983. .map(function (part) {
  984. return part[0].toUpperCase() + part.slice(1);
  985. })
  986. .join('');
  987. return parts[0] + rest;
  988. }
  989. var StyleAttributor = /** @class */ (function (_super) {
  990. __extends(StyleAttributor, _super);
  991. function StyleAttributor() {
  992. return _super !== null && _super.apply(this, arguments) || this;
  993. }
  994. StyleAttributor.keys = function (node) {
  995. return (node.getAttribute('style') || '').split(';').map(function (value) {
  996. var arr = value.split(':');
  997. return arr[0].trim();
  998. });
  999. };
  1000. StyleAttributor.prototype.add = function (node, value) {
  1001. if (!this.canAdd(node, value))
  1002. return false;
  1003. // @ts-ignore
  1004. node.style[camelize(this.keyName)] = value;
  1005. return true;
  1006. };
  1007. StyleAttributor.prototype.remove = function (node) {
  1008. // @ts-ignore
  1009. node.style[camelize(this.keyName)] = '';
  1010. if (!node.getAttribute('style')) {
  1011. node.removeAttribute('style');
  1012. }
  1013. };
  1014. StyleAttributor.prototype.value = function (node) {
  1015. // @ts-ignore
  1016. var value = node.style[camelize(this.keyName)];
  1017. return this.canAdd(node, value) ? value : '';
  1018. };
  1019. return StyleAttributor;
  1020. }(attributor_1.default));
  1021. exports.default = StyleAttributor;
  1022. /***/ }),
  1023. /* 9 */
  1024. /***/ (function(module, exports, __webpack_require__) {
  1025. module.exports = __webpack_require__(10);
  1026. /***/ }),
  1027. /* 10 */
  1028. /***/ (function(module, exports, __webpack_require__) {
  1029. "use strict";
  1030. Object.defineProperty(exports, "__esModule", { value: true });
  1031. var container_1 = __webpack_require__(2);
  1032. var format_1 = __webpack_require__(3);
  1033. var leaf_1 = __webpack_require__(4);
  1034. var scroll_1 = __webpack_require__(12);
  1035. var inline_1 = __webpack_require__(13);
  1036. var block_1 = __webpack_require__(14);
  1037. var embed_1 = __webpack_require__(15);
  1038. var text_1 = __webpack_require__(16);
  1039. var attributor_1 = __webpack_require__(1);
  1040. var class_1 = __webpack_require__(7);
  1041. var style_1 = __webpack_require__(8);
  1042. var store_1 = __webpack_require__(6);
  1043. var Registry = __webpack_require__(0);
  1044. var Parchment = {
  1045. Scope: Registry.Scope,
  1046. create: Registry.create,
  1047. find: Registry.find,
  1048. query: Registry.query,
  1049. register: Registry.register,
  1050. Container: container_1.default,
  1051. Format: format_1.default,
  1052. Leaf: leaf_1.default,
  1053. Embed: embed_1.default,
  1054. Scroll: scroll_1.default,
  1055. Block: block_1.default,
  1056. Inline: inline_1.default,
  1057. Text: text_1.default,
  1058. Attributor: {
  1059. Attribute: attributor_1.default,
  1060. Class: class_1.default,
  1061. Style: style_1.default,
  1062. Store: store_1.default,
  1063. },
  1064. };
  1065. exports.default = Parchment;
  1066. /***/ }),
  1067. /* 11 */
  1068. /***/ (function(module, exports, __webpack_require__) {
  1069. "use strict";
  1070. Object.defineProperty(exports, "__esModule", { value: true });
  1071. var LinkedList = /** @class */ (function () {
  1072. function LinkedList() {
  1073. this.head = this.tail = null;
  1074. this.length = 0;
  1075. }
  1076. LinkedList.prototype.append = function () {
  1077. var nodes = [];
  1078. for (var _i = 0; _i < arguments.length; _i++) {
  1079. nodes[_i] = arguments[_i];
  1080. }
  1081. this.insertBefore(nodes[0], null);
  1082. if (nodes.length > 1) {
  1083. this.append.apply(this, nodes.slice(1));
  1084. }
  1085. };
  1086. LinkedList.prototype.contains = function (node) {
  1087. var cur, next = this.iterator();
  1088. while ((cur = next())) {
  1089. if (cur === node)
  1090. return true;
  1091. }
  1092. return false;
  1093. };
  1094. LinkedList.prototype.insertBefore = function (node, refNode) {
  1095. if (!node)
  1096. return;
  1097. node.next = refNode;
  1098. if (refNode != null) {
  1099. node.prev = refNode.prev;
  1100. if (refNode.prev != null) {
  1101. refNode.prev.next = node;
  1102. }
  1103. refNode.prev = node;
  1104. if (refNode === this.head) {
  1105. this.head = node;
  1106. }
  1107. }
  1108. else if (this.tail != null) {
  1109. this.tail.next = node;
  1110. node.prev = this.tail;
  1111. this.tail = node;
  1112. }
  1113. else {
  1114. node.prev = null;
  1115. this.head = this.tail = node;
  1116. }
  1117. this.length += 1;
  1118. };
  1119. LinkedList.prototype.offset = function (target) {
  1120. var index = 0, cur = this.head;
  1121. while (cur != null) {
  1122. if (cur === target)
  1123. return index;
  1124. index += cur.length();
  1125. cur = cur.next;
  1126. }
  1127. return -1;
  1128. };
  1129. LinkedList.prototype.remove = function (node) {
  1130. if (!this.contains(node))
  1131. return;
  1132. if (node.prev != null)
  1133. node.prev.next = node.next;
  1134. if (node.next != null)
  1135. node.next.prev = node.prev;
  1136. if (node === this.head)
  1137. this.head = node.next;
  1138. if (node === this.tail)
  1139. this.tail = node.prev;
  1140. this.length -= 1;
  1141. };
  1142. LinkedList.prototype.iterator = function (curNode) {
  1143. if (curNode === void 0) { curNode = this.head; }
  1144. // TODO use yield when we can
  1145. return function () {
  1146. var ret = curNode;
  1147. if (curNode != null)
  1148. curNode = curNode.next;
  1149. return ret;
  1150. };
  1151. };
  1152. LinkedList.prototype.find = function (index, inclusive) {
  1153. if (inclusive === void 0) { inclusive = false; }
  1154. var cur, next = this.iterator();
  1155. while ((cur = next())) {
  1156. var length_1 = cur.length();
  1157. if (index < length_1 ||
  1158. (inclusive && index === length_1 && (cur.next == null || cur.next.length() !== 0))) {
  1159. return [cur, index];
  1160. }
  1161. index -= length_1;
  1162. }
  1163. return [null, 0];
  1164. };
  1165. LinkedList.prototype.forEach = function (callback) {
  1166. var cur, next = this.iterator();
  1167. while ((cur = next())) {
  1168. callback(cur);
  1169. }
  1170. };
  1171. LinkedList.prototype.forEachAt = function (index, length, callback) {
  1172. if (length <= 0)
  1173. return;
  1174. var _a = this.find(index), startNode = _a[0], offset = _a[1];
  1175. var cur, curIndex = index - offset, next = this.iterator(startNode);
  1176. while ((cur = next()) && curIndex < index + length) {
  1177. var curLength = cur.length();
  1178. if (index > curIndex) {
  1179. callback(cur, index - curIndex, Math.min(length, curIndex + curLength - index));
  1180. }
  1181. else {
  1182. callback(cur, 0, Math.min(curLength, index + length - curIndex));
  1183. }
  1184. curIndex += curLength;
  1185. }
  1186. };
  1187. LinkedList.prototype.map = function (callback) {
  1188. return this.reduce(function (memo, cur) {
  1189. memo.push(callback(cur));
  1190. return memo;
  1191. }, []);
  1192. };
  1193. LinkedList.prototype.reduce = function (callback, memo) {
  1194. var cur, next = this.iterator();
  1195. while ((cur = next())) {
  1196. memo = callback(memo, cur);
  1197. }
  1198. return memo;
  1199. };
  1200. return LinkedList;
  1201. }());
  1202. exports.default = LinkedList;
  1203. /***/ }),
  1204. /* 12 */
  1205. /***/ (function(module, exports, __webpack_require__) {
  1206. "use strict";
  1207. var __extends = (this && this.__extends) || (function () {
  1208. var extendStatics = Object.setPrototypeOf ||
  1209. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1210. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1211. return function (d, b) {
  1212. extendStatics(d, b);
  1213. function __() { this.constructor = d; }
  1214. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1215. };
  1216. })();
  1217. Object.defineProperty(exports, "__esModule", { value: true });
  1218. var container_1 = __webpack_require__(2);
  1219. var Registry = __webpack_require__(0);
  1220. var OBSERVER_CONFIG = {
  1221. attributes: true,
  1222. characterData: true,
  1223. characterDataOldValue: true,
  1224. childList: true,
  1225. subtree: true,
  1226. };
  1227. var MAX_OPTIMIZE_ITERATIONS = 100;
  1228. var ScrollBlot = /** @class */ (function (_super) {
  1229. __extends(ScrollBlot, _super);
  1230. function ScrollBlot(node) {
  1231. var _this = _super.call(this, node) || this;
  1232. _this.scroll = _this;
  1233. _this.observer = new MutationObserver(function (mutations) {
  1234. _this.update(mutations);
  1235. });
  1236. _this.observer.observe(_this.domNode, OBSERVER_CONFIG);
  1237. _this.attach();
  1238. return _this;
  1239. }
  1240. ScrollBlot.prototype.detach = function () {
  1241. _super.prototype.detach.call(this);
  1242. this.observer.disconnect();
  1243. };
  1244. ScrollBlot.prototype.deleteAt = function (index, length) {
  1245. this.update();
  1246. if (index === 0 && length === this.length()) {
  1247. this.children.forEach(function (child) {
  1248. child.remove();
  1249. });
  1250. }
  1251. else {
  1252. _super.prototype.deleteAt.call(this, index, length);
  1253. }
  1254. };
  1255. ScrollBlot.prototype.formatAt = function (index, length, name, value) {
  1256. this.update();
  1257. _super.prototype.formatAt.call(this, index, length, name, value);
  1258. };
  1259. ScrollBlot.prototype.insertAt = function (index, value, def) {
  1260. this.update();
  1261. _super.prototype.insertAt.call(this, index, value, def);
  1262. };
  1263. ScrollBlot.prototype.optimize = function (mutations, context) {
  1264. var _this = this;
  1265. if (mutations === void 0) { mutations = []; }
  1266. if (context === void 0) { context = {}; }
  1267. _super.prototype.optimize.call(this, context);
  1268. // We must modify mutations directly, cannot make copy and then modify
  1269. var records = [].slice.call(this.observer.takeRecords());
  1270. // Array.push currently seems to be implemented by a non-tail recursive function
  1271. // so we cannot just mutations.push.apply(mutations, this.observer.takeRecords());
  1272. while (records.length > 0)
  1273. mutations.push(records.pop());
  1274. // TODO use WeakMap
  1275. var mark = function (blot, markParent) {
  1276. if (markParent === void 0) { markParent = true; }
  1277. if (blot == null || blot === _this)
  1278. return;
  1279. if (blot.domNode.parentNode == null)
  1280. return;
  1281. // @ts-ignore
  1282. if (blot.domNode[Registry.DATA_KEY].mutations == null) {
  1283. // @ts-ignore
  1284. blot.domNode[Registry.DATA_KEY].mutations = [];
  1285. }
  1286. if (markParent)
  1287. mark(blot.parent);
  1288. };
  1289. var optimize = function (blot) {
  1290. // Post-order traversal
  1291. if (
  1292. // @ts-ignore
  1293. blot.domNode[Registry.DATA_KEY] == null ||
  1294. // @ts-ignore
  1295. blot.domNode[Registry.DATA_KEY].mutations == null) {
  1296. return;
  1297. }
  1298. if (blot instanceof container_1.default) {
  1299. blot.children.forEach(optimize);
  1300. }
  1301. blot.optimize(context);
  1302. };
  1303. var remaining = mutations;
  1304. for (var i = 0; remaining.length > 0; i += 1) {
  1305. if (i >= MAX_OPTIMIZE_ITERATIONS) {
  1306. throw new Error('[Parchment] Maximum optimize iterations reached');
  1307. }
  1308. remaining.forEach(function (mutation) {
  1309. var blot = Registry.find(mutation.target, true);
  1310. if (blot == null)
  1311. return;
  1312. if (blot.domNode === mutation.target) {
  1313. if (mutation.type === 'childList') {
  1314. mark(Registry.find(mutation.previousSibling, false));
  1315. [].forEach.call(mutation.addedNodes, function (node) {
  1316. var child = Registry.find(node, false);
  1317. mark(child, false);
  1318. if (child instanceof container_1.default) {
  1319. child.children.forEach(function (grandChild) {
  1320. mark(grandChild, false);
  1321. });
  1322. }
  1323. });
  1324. }
  1325. else if (mutation.type === 'attributes') {
  1326. mark(blot.prev);
  1327. }
  1328. }
  1329. mark(blot);
  1330. });
  1331. this.children.forEach(optimize);
  1332. remaining = [].slice.call(this.observer.takeRecords());
  1333. records = remaining.slice();
  1334. while (records.length > 0)
  1335. mutations.push(records.pop());
  1336. }
  1337. };
  1338. ScrollBlot.prototype.update = function (mutations, context) {
  1339. var _this = this;
  1340. if (context === void 0) { context = {}; }
  1341. mutations = mutations || this.observer.takeRecords();
  1342. // TODO use WeakMap
  1343. mutations
  1344. .map(function (mutation) {
  1345. var blot = Registry.find(mutation.target, true);
  1346. if (blot == null)
  1347. return null;
  1348. // @ts-ignore
  1349. if (blot.domNode[Registry.DATA_KEY].mutations == null) {
  1350. // @ts-ignore
  1351. blot.domNode[Registry.DATA_KEY].mutations = [mutation];
  1352. return blot;
  1353. }
  1354. else {
  1355. // @ts-ignore
  1356. blot.domNode[Registry.DATA_KEY].mutations.push(mutation);
  1357. return null;
  1358. }
  1359. })
  1360. .forEach(function (blot) {
  1361. if (blot == null ||
  1362. blot === _this ||
  1363. //@ts-ignore
  1364. blot.domNode[Registry.DATA_KEY] == null)
  1365. return;
  1366. // @ts-ignore
  1367. blot.update(blot.domNode[Registry.DATA_KEY].mutations || [], context);
  1368. });
  1369. // @ts-ignore
  1370. if (this.domNode[Registry.DATA_KEY].mutations != null) {
  1371. // @ts-ignore
  1372. _super.prototype.update.call(this, this.domNode[Registry.DATA_KEY].mutations, context);
  1373. }
  1374. this.optimize(mutations, context);
  1375. };
  1376. ScrollBlot.blotName = 'scroll';
  1377. ScrollBlot.defaultChild = 'block';
  1378. ScrollBlot.scope = Registry.Scope.BLOCK_BLOT;
  1379. ScrollBlot.tagName = 'DIV';
  1380. return ScrollBlot;
  1381. }(container_1.default));
  1382. exports.default = ScrollBlot;
  1383. /***/ }),
  1384. /* 13 */
  1385. /***/ (function(module, exports, __webpack_require__) {
  1386. "use strict";
  1387. var __extends = (this && this.__extends) || (function () {
  1388. var extendStatics = Object.setPrototypeOf ||
  1389. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1390. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1391. return function (d, b) {
  1392. extendStatics(d, b);
  1393. function __() { this.constructor = d; }
  1394. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1395. };
  1396. })();
  1397. Object.defineProperty(exports, "__esModule", { value: true });
  1398. var format_1 = __webpack_require__(3);
  1399. var Registry = __webpack_require__(0);
  1400. // Shallow object comparison
  1401. function isEqual(obj1, obj2) {
  1402. if (Object.keys(obj1).length !== Object.keys(obj2).length)
  1403. return false;
  1404. // @ts-ignore
  1405. for (var prop in obj1) {
  1406. // @ts-ignore
  1407. if (obj1[prop] !== obj2[prop])
  1408. return false;
  1409. }
  1410. return true;
  1411. }
  1412. var InlineBlot = /** @class */ (function (_super) {
  1413. __extends(InlineBlot, _super);
  1414. function InlineBlot() {
  1415. return _super !== null && _super.apply(this, arguments) || this;
  1416. }
  1417. InlineBlot.formats = function (domNode) {
  1418. if (domNode.tagName === InlineBlot.tagName)
  1419. return undefined;
  1420. return _super.formats.call(this, domNode);
  1421. };
  1422. InlineBlot.prototype.format = function (name, value) {
  1423. var _this = this;
  1424. if (name === this.statics.blotName && !value) {
  1425. this.children.forEach(function (child) {
  1426. if (!(child instanceof format_1.default)) {
  1427. child = child.wrap(InlineBlot.blotName, true);
  1428. }
  1429. _this.attributes.copy(child);
  1430. });
  1431. this.unwrap();
  1432. }
  1433. else {
  1434. _super.prototype.format.call(this, name, value);
  1435. }
  1436. };
  1437. InlineBlot.prototype.formatAt = function (index, length, name, value) {
  1438. if (this.formats()[name] != null || Registry.query(name, Registry.Scope.ATTRIBUTE)) {
  1439. var blot = this.isolate(index, length);
  1440. blot.format(name, value);
  1441. }
  1442. else {
  1443. _super.prototype.formatAt.call(this, index, length, name, value);
  1444. }
  1445. };
  1446. InlineBlot.prototype.optimize = function (context) {
  1447. _super.prototype.optimize.call(this, context);
  1448. var formats = this.formats();
  1449. if (Object.keys(formats).length === 0) {
  1450. return this.unwrap(); // unformatted span
  1451. }
  1452. var next = this.next;
  1453. if (next instanceof InlineBlot && next.prev === this && isEqual(formats, next.formats())) {
  1454. next.moveChildren(this);
  1455. next.remove();
  1456. }
  1457. };
  1458. InlineBlot.blotName = 'inline';
  1459. InlineBlot.scope = Registry.Scope.INLINE_BLOT;
  1460. InlineBlot.tagName = 'SPAN';
  1461. return InlineBlot;
  1462. }(format_1.default));
  1463. exports.default = InlineBlot;
  1464. /***/ }),
  1465. /* 14 */
  1466. /***/ (function(module, exports, __webpack_require__) {
  1467. "use strict";
  1468. var __extends = (this && this.__extends) || (function () {
  1469. var extendStatics = Object.setPrototypeOf ||
  1470. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1471. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1472. return function (d, b) {
  1473. extendStatics(d, b);
  1474. function __() { this.constructor = d; }
  1475. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1476. };
  1477. })();
  1478. Object.defineProperty(exports, "__esModule", { value: true });
  1479. var format_1 = __webpack_require__(3);
  1480. var Registry = __webpack_require__(0);
  1481. var BlockBlot = /** @class */ (function (_super) {
  1482. __extends(BlockBlot, _super);
  1483. function BlockBlot() {
  1484. return _super !== null && _super.apply(this, arguments) || this;
  1485. }
  1486. BlockBlot.formats = function (domNode) {
  1487. var tagName = Registry.query(BlockBlot.blotName).tagName;
  1488. if (domNode.tagName === tagName)
  1489. return undefined;
  1490. return _super.formats.call(this, domNode);
  1491. };
  1492. BlockBlot.prototype.format = function (name, value) {
  1493. if (Registry.query(name, Registry.Scope.BLOCK) == null) {
  1494. return;
  1495. }
  1496. else if (name === this.statics.blotName && !value) {
  1497. this.replaceWith(BlockBlot.blotName);
  1498. }
  1499. else {
  1500. _super.prototype.format.call(this, name, value);
  1501. }
  1502. };
  1503. BlockBlot.prototype.formatAt = function (index, length, name, value) {
  1504. if (Registry.query(name, Registry.Scope.BLOCK) != null) {
  1505. this.format(name, value);
  1506. }
  1507. else {
  1508. _super.prototype.formatAt.call(this, index, length, name, value);
  1509. }
  1510. };
  1511. BlockBlot.prototype.insertAt = function (index, value, def) {
  1512. if (def == null || Registry.query(value, Registry.Scope.INLINE) != null) {
  1513. // Insert text or inline
  1514. _super.prototype.insertAt.call(this, index, value, def);
  1515. }
  1516. else {
  1517. var after = this.split(index);
  1518. var blot = Registry.create(value, def);
  1519. after.parent.insertBefore(blot, after);
  1520. }
  1521. };
  1522. BlockBlot.prototype.update = function (mutations, context) {
  1523. if (navigator.userAgent.match(/Trident/)) {
  1524. this.build();
  1525. }
  1526. else {
  1527. _super.prototype.update.call(this, mutations, context);
  1528. }
  1529. };
  1530. BlockBlot.blotName = 'block';
  1531. BlockBlot.scope = Registry.Scope.BLOCK_BLOT;
  1532. BlockBlot.tagName = 'P';
  1533. return BlockBlot;
  1534. }(format_1.default));
  1535. exports.default = BlockBlot;
  1536. /***/ }),
  1537. /* 15 */
  1538. /***/ (function(module, exports, __webpack_require__) {
  1539. "use strict";
  1540. var __extends = (this && this.__extends) || (function () {
  1541. var extendStatics = Object.setPrototypeOf ||
  1542. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1543. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1544. return function (d, b) {
  1545. extendStatics(d, b);
  1546. function __() { this.constructor = d; }
  1547. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1548. };
  1549. })();
  1550. Object.defineProperty(exports, "__esModule", { value: true });
  1551. var leaf_1 = __webpack_require__(4);
  1552. var EmbedBlot = /** @class */ (function (_super) {
  1553. __extends(EmbedBlot, _super);
  1554. function EmbedBlot() {
  1555. return _super !== null && _super.apply(this, arguments) || this;
  1556. }
  1557. EmbedBlot.formats = function (domNode) {
  1558. return undefined;
  1559. };
  1560. EmbedBlot.prototype.format = function (name, value) {
  1561. // super.formatAt wraps, which is what we want in general,
  1562. // but this allows subclasses to overwrite for formats
  1563. // that just apply to particular embeds
  1564. _super.prototype.formatAt.call(this, 0, this.length(), name, value);
  1565. };
  1566. EmbedBlot.prototype.formatAt = function (index, length, name, value) {
  1567. if (index === 0 && length === this.length()) {
  1568. this.format(name, value);
  1569. }
  1570. else {
  1571. _super.prototype.formatAt.call(this, index, length, name, value);
  1572. }
  1573. };
  1574. EmbedBlot.prototype.formats = function () {
  1575. return this.statics.formats(this.domNode);
  1576. };
  1577. return EmbedBlot;
  1578. }(leaf_1.default));
  1579. exports.default = EmbedBlot;
  1580. /***/ }),
  1581. /* 16 */
  1582. /***/ (function(module, exports, __webpack_require__) {
  1583. "use strict";
  1584. var __extends = (this && this.__extends) || (function () {
  1585. var extendStatics = Object.setPrototypeOf ||
  1586. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1587. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1588. return function (d, b) {
  1589. extendStatics(d, b);
  1590. function __() { this.constructor = d; }
  1591. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1592. };
  1593. })();
  1594. Object.defineProperty(exports, "__esModule", { value: true });
  1595. var leaf_1 = __webpack_require__(4);
  1596. var Registry = __webpack_require__(0);
  1597. var TextBlot = /** @class */ (function (_super) {
  1598. __extends(TextBlot, _super);
  1599. function TextBlot(node) {
  1600. var _this = _super.call(this, node) || this;
  1601. _this.text = _this.statics.value(_this.domNode);
  1602. return _this;
  1603. }
  1604. TextBlot.create = function (value) {
  1605. return document.createTextNode(value);
  1606. };
  1607. TextBlot.value = function (domNode) {
  1608. var text = domNode.data;
  1609. // @ts-ignore
  1610. if (text['normalize'])
  1611. text = text['normalize']();
  1612. return text;
  1613. };
  1614. TextBlot.prototype.deleteAt = function (index, length) {
  1615. this.domNode.data = this.text = this.text.slice(0, index) + this.text.slice(index + length);
  1616. };
  1617. TextBlot.prototype.index = function (node, offset) {
  1618. if (this.domNode === node) {
  1619. return offset;
  1620. }
  1621. return -1;
  1622. };
  1623. TextBlot.prototype.insertAt = function (index, value, def) {
  1624. if (def == null) {
  1625. this.text = this.text.slice(0, index) + value + this.text.slice(index);
  1626. this.domNode.data = this.text;
  1627. }
  1628. else {
  1629. _super.prototype.insertAt.call(this, index, value, def);
  1630. }
  1631. };
  1632. TextBlot.prototype.length = function () {
  1633. return this.text.length;
  1634. };
  1635. TextBlot.prototype.optimize = function (context) {
  1636. _super.prototype.optimize.call(this, context);
  1637. this.text = this.statics.value(this.domNode);
  1638. if (this.text.length === 0) {
  1639. this.remove();
  1640. }
  1641. else if (this.next instanceof TextBlot && this.next.prev === this) {
  1642. this.insertAt(this.length(), this.next.value());
  1643. this.next.remove();
  1644. }
  1645. };
  1646. TextBlot.prototype.position = function (index, inclusive) {
  1647. if (inclusive === void 0) { inclusive = false; }
  1648. return [this.domNode, index];
  1649. };
  1650. TextBlot.prototype.split = function (index, force) {
  1651. if (force === void 0) { force = false; }
  1652. if (!force) {
  1653. if (index === 0)
  1654. return this;
  1655. if (index === this.length())
  1656. return this.next;
  1657. }
  1658. var after = Registry.create(this.domNode.splitText(index));
  1659. this.parent.insertBefore(after, this.next);
  1660. this.text = this.statics.value(this.domNode);
  1661. return after;
  1662. };
  1663. TextBlot.prototype.update = function (mutations, context) {
  1664. var _this = this;
  1665. if (mutations.some(function (mutation) {
  1666. return mutation.type === 'characterData' && mutation.target === _this.domNode;
  1667. })) {
  1668. this.text = this.statics.value(this.domNode);
  1669. }
  1670. };
  1671. TextBlot.prototype.value = function () {
  1672. return this.text;
  1673. };
  1674. TextBlot.blotName = 'text';
  1675. TextBlot.scope = Registry.Scope.INLINE_BLOT;
  1676. return TextBlot;
  1677. }(leaf_1.default));
  1678. exports.default = TextBlot;
  1679. /***/ })
  1680. /******/ ]);
  1681. });
  1682. //# sourceMappingURL=parchment.js.map