index.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. // export const ContextNode = Syringe.defineToken('');
  4. var FragmentResult = function FragmentResult(_layoutContext, _node, options) {
  5. this._layoutContext = void 0;
  6. this._node = void 0;
  7. this.options = void 0;
  8. this.layoutContext = void 0;
  9. this.inlineSize = void 0;
  10. this.blockSize = void 0;
  11. this.node = void 0;
  12. this.childFragments = void 0;
  13. this.data = void 0;
  14. this._layoutContext = _layoutContext;
  15. this._node = _node;
  16. this.options = options;
  17. this.layoutContext = _layoutContext;
  18. this.inlineSize = options === null || options === void 0 ? void 0 : options.inlineSize;
  19. this.blockSize = options === null || options === void 0 ? void 0 : options.blockSize;
  20. this.childFragments = options === null || options === void 0 ? void 0 : options.childFragments;
  21. this.data = options.data;
  22. this.node = _node;
  23. };
  24. (function (LayoutTaskType) {
  25. LayoutTaskType["Layout"] = "layout";
  26. LayoutTaskType["IntrinsicSizes"] = "intrinsic-sizes";
  27. })(exports.LayoutTaskType || (exports.LayoutTaskType = {}));
  28. var ChildDisplayType;
  29. (function (ChildDisplayType) {
  30. ChildDisplayType[ChildDisplayType["block"] = 0] = "block";
  31. ChildDisplayType[ChildDisplayType["normal"] = 1] = "normal";
  32. })(ChildDisplayType || (ChildDisplayType = {}));
  33. var LayoutSizingMode;
  34. (function (LayoutSizingMode) {
  35. LayoutSizingMode[LayoutSizingMode["block-like"] = 0] = "block-like";
  36. LayoutSizingMode[LayoutSizingMode["manual"] = 1] = "manual";
  37. })(LayoutSizingMode || (LayoutSizingMode = {}));
  38. (function (PropertyName) {
  39. PropertyName["LAYOUT"] = "display";
  40. PropertyName["LEFT"] = "left";
  41. PropertyName["TOP"] = "top";
  42. PropertyName["BOTTOM"] = "bottom";
  43. PropertyName["RIGHT"] = "right";
  44. PropertyName["WIDTH"] = "width";
  45. PropertyName["HEIGHT"] = "height";
  46. PropertyName["MIN_WIDTH"] = "minWidth";
  47. PropertyName["MAX_WIDTH"] = "maxWidth";
  48. PropertyName["MIN_HEIGHT"] = "minHeight";
  49. PropertyName["MAX_HEIGHT"] = "maxHeight";
  50. PropertyName["BOX_SIZING"] = "boxSizing";
  51. PropertyName["PADDING"] = "padding";
  52. PropertyName["PADDING_TOP"] = "paddingTop";
  53. PropertyName["PADDING_BOTTOM"] = "paddingBottom";
  54. PropertyName["PADDING_START"] = "paddingLeft";
  55. PropertyName["PADDING_END"] = "paddingRight";
  56. PropertyName["MARGIN"] = "margin";
  57. PropertyName["MARGIN_TOP"] = "marginTop";
  58. PropertyName["MARGIN_BOTTOM"] = "marginBottom";
  59. PropertyName["MARGIN_START"] = "marginLeft";
  60. PropertyName["MARGIN_END"] = "marginRight";
  61. PropertyName["BORDER"] = "border";
  62. PropertyName["BORDER_TOP"] = "borderTop";
  63. PropertyName["BORDER_BOTTOM"] = "borderBottom";
  64. PropertyName["BORDER_START"] = "borderLeft";
  65. PropertyName["BORDER_END"] = "borderRight";
  66. PropertyName["FLEX_DIRECTION"] = "flexDirection";
  67. PropertyName["FLEX_WRAP"] = "flexWrap";
  68. PropertyName["FLEX_FLOW"] = "flexFlow";
  69. PropertyName["ALIGN_ITEMS"] = "alignItems";
  70. PropertyName["ALIGN_CONTENT"] = "alignContent";
  71. PropertyName["JUSTIFY_CONTENT"] = "justifyContent";
  72. PropertyName["FLEX"] = "flex";
  73. PropertyName["ALIGN_SELF"] = "alignSelf";
  74. PropertyName["FLEX_SHRINK"] = "flexShrink";
  75. PropertyName["FLEX_BASIS"] = "flexBasis";
  76. PropertyName["FLEX_GROW"] = "flexGrow";
  77. PropertyName["OFFSET_WIDTH"] = "offsetWidth";
  78. PropertyName["OFFSET_HEIGHT"] = "offsetHeight";
  79. PropertyName["ORDER"] = "order";
  80. })(exports.PropertyName || (exports.PropertyName = {}));
  81. function _regeneratorRuntime() {
  82. _regeneratorRuntime = function () {
  83. return exports;
  84. };
  85. var exports = {},
  86. Op = Object.prototype,
  87. hasOwn = Op.hasOwnProperty,
  88. defineProperty = Object.defineProperty || function (obj, key, desc) {
  89. obj[key] = desc.value;
  90. },
  91. $Symbol = "function" == typeof Symbol ? Symbol : {},
  92. iteratorSymbol = $Symbol.iterator || "@@iterator",
  93. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  94. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  95. function define(obj, key, value) {
  96. return Object.defineProperty(obj, key, {
  97. value: value,
  98. enumerable: !0,
  99. configurable: !0,
  100. writable: !0
  101. }), obj[key];
  102. }
  103. try {
  104. define({}, "");
  105. } catch (err) {
  106. define = function (obj, key, value) {
  107. return obj[key] = value;
  108. };
  109. }
  110. function wrap(innerFn, outerFn, self, tryLocsList) {
  111. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  112. generator = Object.create(protoGenerator.prototype),
  113. context = new Context(tryLocsList || []);
  114. return defineProperty(generator, "_invoke", {
  115. value: makeInvokeMethod(innerFn, self, context)
  116. }), generator;
  117. }
  118. function tryCatch(fn, obj, arg) {
  119. try {
  120. return {
  121. type: "normal",
  122. arg: fn.call(obj, arg)
  123. };
  124. } catch (err) {
  125. return {
  126. type: "throw",
  127. arg: err
  128. };
  129. }
  130. }
  131. exports.wrap = wrap;
  132. var ContinueSentinel = {};
  133. function Generator() {}
  134. function GeneratorFunction() {}
  135. function GeneratorFunctionPrototype() {}
  136. var IteratorPrototype = {};
  137. define(IteratorPrototype, iteratorSymbol, function () {
  138. return this;
  139. });
  140. var getProto = Object.getPrototypeOf,
  141. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  142. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  143. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  144. function defineIteratorMethods(prototype) {
  145. ["next", "throw", "return"].forEach(function (method) {
  146. define(prototype, method, function (arg) {
  147. return this._invoke(method, arg);
  148. });
  149. });
  150. }
  151. function AsyncIterator(generator, PromiseImpl) {
  152. function invoke(method, arg, resolve, reject) {
  153. var record = tryCatch(generator[method], generator, arg);
  154. if ("throw" !== record.type) {
  155. var result = record.arg,
  156. value = result.value;
  157. return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  158. invoke("next", value, resolve, reject);
  159. }, function (err) {
  160. invoke("throw", err, resolve, reject);
  161. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  162. result.value = unwrapped, resolve(result);
  163. }, function (error) {
  164. return invoke("throw", error, resolve, reject);
  165. });
  166. }
  167. reject(record.arg);
  168. }
  169. var previousPromise;
  170. defineProperty(this, "_invoke", {
  171. value: function (method, arg) {
  172. function callInvokeWithMethodAndArg() {
  173. return new PromiseImpl(function (resolve, reject) {
  174. invoke(method, arg, resolve, reject);
  175. });
  176. }
  177. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  178. }
  179. });
  180. }
  181. function makeInvokeMethod(innerFn, self, context) {
  182. var state = "suspendedStart";
  183. return function (method, arg) {
  184. if ("executing" === state) throw new Error("Generator is already running");
  185. if ("completed" === state) {
  186. if ("throw" === method) throw arg;
  187. return doneResult();
  188. }
  189. for (context.method = method, context.arg = arg;;) {
  190. var delegate = context.delegate;
  191. if (delegate) {
  192. var delegateResult = maybeInvokeDelegate(delegate, context);
  193. if (delegateResult) {
  194. if (delegateResult === ContinueSentinel) continue;
  195. return delegateResult;
  196. }
  197. }
  198. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  199. if ("suspendedStart" === state) throw state = "completed", context.arg;
  200. context.dispatchException(context.arg);
  201. } else "return" === context.method && context.abrupt("return", context.arg);
  202. state = "executing";
  203. var record = tryCatch(innerFn, self, context);
  204. if ("normal" === record.type) {
  205. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  206. return {
  207. value: record.arg,
  208. done: context.done
  209. };
  210. }
  211. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  212. }
  213. };
  214. }
  215. function maybeInvokeDelegate(delegate, context) {
  216. var methodName = context.method,
  217. method = delegate.iterator[methodName];
  218. if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
  219. var record = tryCatch(method, delegate.iterator, context.arg);
  220. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  221. var info = record.arg;
  222. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  223. }
  224. function pushTryEntry(locs) {
  225. var entry = {
  226. tryLoc: locs[0]
  227. };
  228. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  229. }
  230. function resetTryEntry(entry) {
  231. var record = entry.completion || {};
  232. record.type = "normal", delete record.arg, entry.completion = record;
  233. }
  234. function Context(tryLocsList) {
  235. this.tryEntries = [{
  236. tryLoc: "root"
  237. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  238. }
  239. function values(iterable) {
  240. if (iterable) {
  241. var iteratorMethod = iterable[iteratorSymbol];
  242. if (iteratorMethod) return iteratorMethod.call(iterable);
  243. if ("function" == typeof iterable.next) return iterable;
  244. if (!isNaN(iterable.length)) {
  245. var i = -1,
  246. next = function next() {
  247. for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  248. return next.value = undefined, next.done = !0, next;
  249. };
  250. return next.next = next;
  251. }
  252. }
  253. return {
  254. next: doneResult
  255. };
  256. }
  257. function doneResult() {
  258. return {
  259. value: undefined,
  260. done: !0
  261. };
  262. }
  263. return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
  264. value: GeneratorFunctionPrototype,
  265. configurable: !0
  266. }), defineProperty(GeneratorFunctionPrototype, "constructor", {
  267. value: GeneratorFunction,
  268. configurable: !0
  269. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  270. var ctor = "function" == typeof genFun && genFun.constructor;
  271. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  272. }, exports.mark = function (genFun) {
  273. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  274. }, exports.awrap = function (arg) {
  275. return {
  276. __await: arg
  277. };
  278. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  279. return this;
  280. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  281. void 0 === PromiseImpl && (PromiseImpl = Promise);
  282. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  283. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  284. return result.done ? result.value : iter.next();
  285. });
  286. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  287. return this;
  288. }), define(Gp, "toString", function () {
  289. return "[object Generator]";
  290. }), exports.keys = function (val) {
  291. var object = Object(val),
  292. keys = [];
  293. for (var key in object) keys.push(key);
  294. return keys.reverse(), function next() {
  295. for (; keys.length;) {
  296. var key = keys.pop();
  297. if (key in object) return next.value = key, next.done = !1, next;
  298. }
  299. return next.done = !0, next;
  300. };
  301. }, exports.values = values, Context.prototype = {
  302. constructor: Context,
  303. reset: function (skipTempReset) {
  304. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
  305. },
  306. stop: function () {
  307. this.done = !0;
  308. var rootRecord = this.tryEntries[0].completion;
  309. if ("throw" === rootRecord.type) throw rootRecord.arg;
  310. return this.rval;
  311. },
  312. dispatchException: function (exception) {
  313. if (this.done) throw exception;
  314. var context = this;
  315. function handle(loc, caught) {
  316. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  317. }
  318. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  319. var entry = this.tryEntries[i],
  320. record = entry.completion;
  321. if ("root" === entry.tryLoc) return handle("end");
  322. if (entry.tryLoc <= this.prev) {
  323. var hasCatch = hasOwn.call(entry, "catchLoc"),
  324. hasFinally = hasOwn.call(entry, "finallyLoc");
  325. if (hasCatch && hasFinally) {
  326. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  327. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  328. } else if (hasCatch) {
  329. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  330. } else {
  331. if (!hasFinally) throw new Error("try statement without catch or finally");
  332. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  333. }
  334. }
  335. }
  336. },
  337. abrupt: function (type, arg) {
  338. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  339. var entry = this.tryEntries[i];
  340. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  341. var finallyEntry = entry;
  342. break;
  343. }
  344. }
  345. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  346. var record = finallyEntry ? finallyEntry.completion : {};
  347. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  348. },
  349. complete: function (record, afterLoc) {
  350. if ("throw" === record.type) throw record.arg;
  351. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  352. },
  353. finish: function (finallyLoc) {
  354. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  355. var entry = this.tryEntries[i];
  356. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  357. }
  358. },
  359. catch: function (tryLoc) {
  360. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  361. var entry = this.tryEntries[i];
  362. if (entry.tryLoc === tryLoc) {
  363. var record = entry.completion;
  364. if ("throw" === record.type) {
  365. var thrown = record.arg;
  366. resetTryEntry(entry);
  367. }
  368. return thrown;
  369. }
  370. }
  371. throw new Error("illegal catch attempt");
  372. },
  373. delegateYield: function (iterable, resultName, nextLoc) {
  374. return this.delegate = {
  375. iterator: values(iterable),
  376. resultName: resultName,
  377. nextLoc: nextLoc
  378. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  379. }
  380. }, exports;
  381. }
  382. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  383. try {
  384. var info = gen[key](arg);
  385. var value = info.value;
  386. } catch (error) {
  387. reject(error);
  388. return;
  389. }
  390. if (info.done) {
  391. resolve(value);
  392. } else {
  393. Promise.resolve(value).then(_next, _throw);
  394. }
  395. }
  396. function _asyncToGenerator(fn) {
  397. return function () {
  398. var self = this,
  399. args = arguments;
  400. return new Promise(function (resolve, reject) {
  401. var gen = fn.apply(self, args);
  402. function _next(value) {
  403. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  404. }
  405. function _throw(err) {
  406. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  407. }
  408. _next(undefined);
  409. });
  410. };
  411. }
  412. function _defineProperties(target, props) {
  413. for (var i = 0; i < props.length; i++) {
  414. var descriptor = props[i];
  415. descriptor.enumerable = descriptor.enumerable || false;
  416. descriptor.configurable = true;
  417. if ("value" in descriptor) descriptor.writable = true;
  418. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  419. }
  420. }
  421. function _createClass(Constructor, protoProps, staticProps) {
  422. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  423. if (staticProps) _defineProperties(Constructor, staticProps);
  424. Object.defineProperty(Constructor, "prototype", {
  425. writable: false
  426. });
  427. return Constructor;
  428. }
  429. function _toPrimitive(input, hint) {
  430. if (typeof input !== "object" || input === null) return input;
  431. var prim = input[Symbol.toPrimitive];
  432. if (prim !== undefined) {
  433. var res = prim.call(input, hint || "default");
  434. if (typeof res !== "object") return res;
  435. throw new TypeError("@@toPrimitive must return a primitive value.");
  436. }
  437. return (hint === "string" ? String : Number)(input);
  438. }
  439. function _toPropertyKey(arg) {
  440. var key = _toPrimitive(arg, "string");
  441. return typeof key === "symbol" ? key : String(key);
  442. }
  443. /**
  444. * This function allow you to modify a JS Promise by adding some status properties.
  445. * Based on: http://stackoverflow.com/questions/21485545/is-there-a-way-to-tell-if-an-es6-promise-is-fulfilled-rejected-resolved
  446. * But modified according to the specs of promises : https://promisesaplus.com/
  447. */
  448. var makeQuerablePromise = function makeQuerablePromise(promise) {
  449. // Don't modify any promise that has been already modified.
  450. if (promise.isRejected || promise.isFulfilled) return promise;
  451. // Set initial state
  452. var isPending = true;
  453. var isRejected = false;
  454. var isFulfilled = false;
  455. var fullFilledValue;
  456. // Observe the promise, saving the fulfillment in a closure scope.
  457. var result = promise.then(function (v) {
  458. isFulfilled = true;
  459. isPending = false;
  460. fullFilledValue = v;
  461. return v;
  462. }, function (e) {
  463. isRejected = true;
  464. isPending = false;
  465. throw e;
  466. });
  467. result.isFulfilled = function () {
  468. return isFulfilled;
  469. };
  470. result.isPending = function () {
  471. return isPending;
  472. };
  473. result.isRejected = function () {
  474. return isRejected;
  475. };
  476. result.getFullFilledValue = function () {
  477. return fullFilledValue;
  478. };
  479. return result;
  480. };
  481. /**
  482. * Simple implementation of the deferred pattern.
  483. * An object that exposes a promise and functions to resolve and reject it.
  484. */
  485. var Deferred = function Deferred() {
  486. var _this = this;
  487. this.resolve = void 0;
  488. this.reject = void 0;
  489. this.promise = new Promise(function (resolve, reject) {
  490. _this.resolve = resolve;
  491. _this.reject = reject;
  492. });
  493. };
  494. var LayoutChildren = /*#__PURE__*/function () {
  495. function LayoutChildren(_layoutContext, options) {
  496. this._layoutContext = void 0;
  497. this.options = void 0;
  498. this.node = void 0;
  499. this.styleMap = void 0;
  500. this.layoutContext = void 0;
  501. this._layoutContext = _layoutContext;
  502. this.options = options;
  503. this.layoutContext = _layoutContext;
  504. this.node = options.node;
  505. this.styleMap = options.node.getAllStyle();
  506. }
  507. var _proto = LayoutChildren.prototype;
  508. _proto.intrinsicSizes = function intrinsicSizes() {
  509. // if (this.contextId !== this.layoutContext.contextId) {
  510. // throw new Error('Invalid State: wrong layout context');
  511. // }
  512. var deferred = new Deferred();
  513. this.layoutContext.appendWorkTask({
  514. layoutChild: this,
  515. taskType: exports.LayoutTaskType.IntrinsicSizes,
  516. deferred: deferred
  517. });
  518. return deferred.promise;
  519. };
  520. _proto.layoutNextFragment = function layoutNextFragment(constraints) {
  521. // if (this.layoutContext.contextId !== this.layoutContext.contextId) {
  522. // throw new Error('Invalid State: wrong layout context');
  523. // }
  524. if (this.layoutContext.mode === exports.LayoutTaskType.IntrinsicSizes) {
  525. throw new Error('Not Supported: cant call layoutNextFragment in intrinsicSizes');
  526. }
  527. var deferred = new Deferred();
  528. this.layoutContext.appendWorkTask({
  529. layoutConstraints: constraints,
  530. layoutChild: this,
  531. taskType: exports.LayoutTaskType.Layout,
  532. deferred: deferred
  533. });
  534. return deferred.promise;
  535. };
  536. return LayoutChildren;
  537. }();
  538. var guid = 0;
  539. /**
  540. * 每次layout 有单独的 context
  541. */
  542. var LayoutContext = /*#__PURE__*/function () {
  543. function LayoutContext(options) {
  544. this.options = void 0;
  545. this.contextId = void 0;
  546. this.workQueue = [];
  547. this.mode = void 0;
  548. this.layoutChildrenFactory = void 0;
  549. this.fragmentResultFactory = void 0;
  550. this.layoutFragmentFactory = void 0;
  551. this.options = options;
  552. this.contextId = "" + guid++;
  553. this.mode = options.mode;
  554. this.layoutChildrenFactory = options.layoutChildrenFactory;
  555. this.fragmentResultFactory = options.fragmentResultFactory;
  556. this.layoutFragmentFactory = options.layoutFragmentFactory;
  557. }
  558. var _proto = LayoutContext.prototype;
  559. _proto.appendWorkTask = function appendWorkTask(work) {
  560. this.workQueue.push(work);
  561. };
  562. _proto.clearWorkQueue = function clearWorkQueue() {
  563. this.workQueue = [];
  564. };
  565. return LayoutContext;
  566. }();
  567. var AbstractLayoutDefinition = function AbstractLayoutDefinition() {};
  568. AbstractLayoutDefinition.inputProperties = void 0;
  569. AbstractLayoutDefinition.childrenInputProperties = void 0;
  570. AbstractLayoutDefinition.layoutOptions = void 0;
  571. var SCROLLBAR_SIZES = [0, 0, 0, 0];
  572. /**
  573. * https://drafts.css-houdini.org/css-layout-api/#layoutedges
  574. * the size of border, scrollbar, padding
  575. */
  576. var LayoutEdges = function LayoutEdges(options) {
  577. var _styleMap$get$value, _styleMap$get, _styleMap$get$value2, _styleMap$get2, _styleMap$get$value3, _styleMap$get3, _styleMap$get$value4, _styleMap$get4, _styleMap$get$value5, _styleMap$get5, _styleMap$get$value6, _styleMap$get6, _styleMap$get$value7, _styleMap$get7, _styleMap$get$value8, _styleMap$get8;
  578. this.options = void 0;
  579. this.inlineStart = void 0;
  580. this.inlineEnd = void 0;
  581. this.blockStart = void 0;
  582. this.blockEnd = void 0;
  583. // Convenience attributes for the sum in one direction.
  584. this.inline = void 0;
  585. this.block = void 0;
  586. this.options = options;
  587. var node = options.node;
  588. var styleMap = node.getAllStyle();
  589. var borderTopWidth = (_styleMap$get$value = (_styleMap$get = styleMap.get(exports.PropertyName.PADDING_TOP)) === null || _styleMap$get === void 0 ? void 0 : _styleMap$get.value) !== null && _styleMap$get$value !== void 0 ? _styleMap$get$value : 0;
  590. var borderRightWidth = (_styleMap$get$value2 = (_styleMap$get2 = styleMap.get(exports.PropertyName.PADDING_END)) === null || _styleMap$get2 === void 0 ? void 0 : _styleMap$get2.value) !== null && _styleMap$get$value2 !== void 0 ? _styleMap$get$value2 : 0;
  591. var borderBottomWidth = (_styleMap$get$value3 = (_styleMap$get3 = styleMap.get(exports.PropertyName.PADDING_BOTTOM)) === null || _styleMap$get3 === void 0 ? void 0 : _styleMap$get3.value) !== null && _styleMap$get$value3 !== void 0 ? _styleMap$get$value3 : 0;
  592. var borderLeftWidth = (_styleMap$get$value4 = (_styleMap$get4 = styleMap.get(exports.PropertyName.PADDING_START)) === null || _styleMap$get4 === void 0 ? void 0 : _styleMap$get4.value) !== null && _styleMap$get$value4 !== void 0 ? _styleMap$get$value4 : 0;
  593. var paddingTopWidth = (_styleMap$get$value5 = (_styleMap$get5 = styleMap.get(exports.PropertyName.PADDING_TOP)) === null || _styleMap$get5 === void 0 ? void 0 : _styleMap$get5.value) !== null && _styleMap$get$value5 !== void 0 ? _styleMap$get$value5 : 0;
  594. var paddingRightWidth = (_styleMap$get$value6 = (_styleMap$get6 = styleMap.get(exports.PropertyName.PADDING_END)) === null || _styleMap$get6 === void 0 ? void 0 : _styleMap$get6.value) !== null && _styleMap$get$value6 !== void 0 ? _styleMap$get$value6 : 0;
  595. var paddingBottomWidth = (_styleMap$get$value7 = (_styleMap$get7 = styleMap.get(exports.PropertyName.PADDING_BOTTOM)) === null || _styleMap$get7 === void 0 ? void 0 : _styleMap$get7.value) !== null && _styleMap$get$value7 !== void 0 ? _styleMap$get$value7 : 0;
  596. var paddingLeftWidth = (_styleMap$get$value8 = (_styleMap$get8 = styleMap.get(exports.PropertyName.PADDING_START)) === null || _styleMap$get8 === void 0 ? void 0 : _styleMap$get8.value) !== null && _styleMap$get$value8 !== void 0 ? _styleMap$get$value8 : 0;
  597. this.blockStart = borderTopWidth + SCROLLBAR_SIZES[0] + paddingTopWidth;
  598. this.inlineStart = borderRightWidth + SCROLLBAR_SIZES[1] + paddingRightWidth;
  599. this.blockEnd = borderBottomWidth + SCROLLBAR_SIZES[2] + paddingBottomWidth;
  600. this.inlineEnd = borderLeftWidth + SCROLLBAR_SIZES[3] + paddingLeftWidth;
  601. this.block = this.blockStart + this.blockEnd;
  602. this.inline = this.inlineStart + this.inlineEnd;
  603. };
  604. var delay = function delay(minisecond) {
  605. if (minisecond === void 0) {
  606. minisecond = 0;
  607. }
  608. return new Promise(function (resolve) {
  609. setTimeout(function () {
  610. resolve();
  611. }, minisecond);
  612. });
  613. };
  614. var LayoutEngine = /*#__PURE__*/function () {
  615. function LayoutEngine(_layoutRegistry, _layoutContextFactory, _layoutEdgesFactory) {
  616. this._layoutRegistry = void 0;
  617. this._layoutContextFactory = void 0;
  618. this._layoutEdgesFactory = void 0;
  619. this.layoutRegistry = void 0;
  620. this.layoutContextFactory = void 0;
  621. this.layoutEdgesFactory = void 0;
  622. this._layoutRegistry = _layoutRegistry;
  623. this._layoutContextFactory = _layoutContextFactory;
  624. this._layoutEdgesFactory = _layoutEdgesFactory;
  625. this.layoutRegistry = _layoutRegistry;
  626. this.layoutContextFactory = _layoutContextFactory;
  627. this.layoutEdgesFactory = _layoutEdgesFactory;
  628. // layoutContributions.getContributions().forEach((layoutContrib) => {
  629. // layoutContrib.registerLayout(_layoutRegistry);
  630. // });
  631. }
  632. /**
  633. * This function takes the root of the box-tree, a LayoutConstraints object, and compute the position of every node in the tree
  634. * @param rootNode root node of the layout object tree
  635. * @param rootPageConstraints layout constraints
  636. * @returns
  637. */
  638. var _proto = LayoutEngine.prototype;
  639. _proto.computeLayout =
  640. /*#__PURE__*/
  641. function () {
  642. var _computeLayout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(rootNode, rootPageConstraints) {
  643. return _regeneratorRuntime().wrap(function _callee$(_context) {
  644. while (1) switch (_context.prev = _context.next) {
  645. case 0:
  646. _context.next = 2;
  647. return this.determineIntrinsicSizes(rootNode, rootNode.children);
  648. case 2:
  649. _context.next = 4;
  650. return this.calculateLayout(rootNode, rootNode.children, rootPageConstraints);
  651. case 4:
  652. case "end":
  653. return _context.stop();
  654. }
  655. }, _callee, this);
  656. }));
  657. function computeLayout(_x, _x2) {
  658. return _computeLayout.apply(this, arguments);
  659. }
  660. return computeLayout;
  661. }()
  662. /**
  663. * calculate intrinsicSize of node tree, use depth dirst / post order traversal
  664. * @param rootNode
  665. */
  666. ;
  667. _proto.determineAllIntrinsicSizes =
  668. /*#__PURE__*/
  669. function () {
  670. var _determineAllIntrinsicSizes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(rootNode) {
  671. return _regeneratorRuntime().wrap(function _callee2$(_context2) {
  672. while (1) switch (_context2.prev = _context2.next) {
  673. case 0:
  674. case "end":
  675. return _context2.stop();
  676. }
  677. }, _callee2);
  678. }));
  679. function determineAllIntrinsicSizes(_x3) {
  680. return _determineAllIntrinsicSizes.apply(this, arguments);
  681. }
  682. return determineAllIntrinsicSizes;
  683. }();
  684. _proto.getLayoutDefinitionName = function getLayoutDefinitionName(node) {
  685. var layoutStyle = node.getAllStyle().get(exports.PropertyName.LAYOUT);
  686. if (!layoutStyle) {
  687. throw new Error('layout property not found');
  688. }
  689. return layoutStyle.value;
  690. }
  691. /**
  692. * calculate the min/max content size of node
  693. * @param node current layout object
  694. * @param childNodes children of the current node
  695. */;
  696. _proto.determineIntrinsicSizes =
  697. /*#__PURE__*/
  698. function () {
  699. var _determineIntrinsicSizes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(node, childNodes) {
  700. var layoutName;
  701. return _regeneratorRuntime().wrap(function _callee3$(_context3) {
  702. while (1) switch (_context3.prev = _context3.next) {
  703. case 0:
  704. layoutName = this.getLayoutDefinitionName(node);
  705. _context3.next = 3;
  706. return this.invokeIntrinsicSizesCallback(layoutName, node, childNodes);
  707. case 3:
  708. case "end":
  709. return _context3.stop();
  710. }
  711. }, _callee3, this);
  712. }));
  713. function determineIntrinsicSizes(_x4, _x5) {
  714. return _determineIntrinsicSizes.apply(this, arguments);
  715. }
  716. return determineIntrinsicSizes;
  717. }();
  718. _proto.invokeIntrinsicSizesCallback = /*#__PURE__*/function () {
  719. var _invokeIntrinsicSizesCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(layoutName, node, childNodes) {
  720. var LayoutDef, layoutInstance, context, _LayoutDef$inputPrope, inputProperties, children, edges, styleMap, value, generator, intrinsicSizesValue;
  721. return _regeneratorRuntime().wrap(function _callee4$(_context4) {
  722. while (1) switch (_context4.prev = _context4.next) {
  723. case 0:
  724. LayoutDef = this.layoutRegistry.getLayout(layoutName);
  725. layoutInstance = new LayoutDef();
  726. context = this.layoutContextFactory({
  727. mode: exports.LayoutTaskType.IntrinsicSizes
  728. });
  729. _LayoutDef$inputPrope = LayoutDef.inputProperties, inputProperties = _LayoutDef$inputPrope === void 0 ? [] : _LayoutDef$inputPrope;
  730. children = [];
  731. childNodes.forEach(function (childNode) {
  732. var layoutChild = context.layoutChildrenFactory({
  733. node: childNode
  734. });
  735. children.push(layoutChild);
  736. });
  737. edges = this.layoutEdgesFactory({
  738. node: node
  739. });
  740. styleMap = node.getStyle.apply(node, inputProperties); // TODO compare to cache ( children edges styleMap )
  741. value = layoutInstance.intrinsicSizes(children, edges, styleMap);
  742. generator = this.runWorkQueue(value, context.workQueue);
  743. generator.next();
  744. _context4.next = 13;
  745. return delay();
  746. case 13:
  747. intrinsicSizesValue = generator.next().value;
  748. context.clearWorkQueue();
  749. node.setIntrisicSizes(intrinsicSizesValue);
  750. case 16:
  751. case "end":
  752. return _context4.stop();
  753. }
  754. }, _callee4, this);
  755. }));
  756. function invokeIntrinsicSizesCallback(_x6, _x7, _x8) {
  757. return _invokeIntrinsicSizesCallback.apply(this, arguments);
  758. }
  759. return invokeIntrinsicSizesCallback;
  760. }();
  761. _proto.calculateLayout = /*#__PURE__*/function () {
  762. var _calculateLayout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(node, childNodes, layoutConstraints) {
  763. var layoutName;
  764. return _regeneratorRuntime().wrap(function _callee5$(_context5) {
  765. while (1) switch (_context5.prev = _context5.next) {
  766. case 0:
  767. layoutName = this.getLayoutDefinitionName(node);
  768. _context5.next = 3;
  769. return this.invokeLayoutCallback(layoutName, node, childNodes, layoutConstraints);
  770. case 3:
  771. case "end":
  772. return _context5.stop();
  773. }
  774. }, _callee5, this);
  775. }));
  776. function calculateLayout(_x9, _x10, _x11) {
  777. return _calculateLayout.apply(this, arguments);
  778. }
  779. return calculateLayout;
  780. }();
  781. _proto.invokeLayoutCallback = /*#__PURE__*/function () {
  782. var _invokeLayoutCallback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(layoutName, node, childNodes, layoutConstraints) {
  783. var LayoutDef, layoutInstance, context, _LayoutDef$inputPrope2, inputProperties, children, edges, styleMap, value, generator, fragmentResultvalue, fragmentResult, layoutFragment;
  784. return _regeneratorRuntime().wrap(function _callee6$(_context6) {
  785. while (1) switch (_context6.prev = _context6.next) {
  786. case 0:
  787. LayoutDef = this.layoutRegistry.getLayout(layoutName);
  788. layoutInstance = new LayoutDef();
  789. context = this.layoutContextFactory({
  790. mode: exports.LayoutTaskType.Layout
  791. });
  792. _LayoutDef$inputPrope2 = LayoutDef.inputProperties, inputProperties = _LayoutDef$inputPrope2 === void 0 ? [] : _LayoutDef$inputPrope2;
  793. children = [];
  794. childNodes.forEach(function (childNode) {
  795. var layoutChild = context.layoutChildrenFactory({
  796. node: childNode
  797. });
  798. children.push(layoutChild);
  799. });
  800. edges = this.layoutEdgesFactory({
  801. node: node
  802. });
  803. styleMap = node.getStyle.apply(node, inputProperties); // TODO compare to cache ( children styleMap layoutConstraints )
  804. value = layoutInstance.layout(children, edges, layoutConstraints, styleMap);
  805. generator = this.runWorkQueue(value, context.workQueue);
  806. generator.next();
  807. _context6.next = 13;
  808. return delay();
  809. case 13:
  810. fragmentResultvalue = generator.next().value;
  811. context.clearWorkQueue();
  812. fragmentResult = fragmentResultvalue instanceof FragmentResult ? fragmentResultvalue : context.fragmentResultFactory(fragmentResultvalue);
  813. layoutFragment = context.layoutFragmentFactory({
  814. inlineSize: fragmentResult.inlineSize,
  815. blockSize: fragmentResult.blockSize,
  816. data: fragmentResult.data
  817. });
  818. node.setComputedLayout(layoutFragment);
  819. childNodes.forEach(function (childNode, index) {
  820. childNode.setComputedLayout(fragmentResult.childFragments[index]);
  821. });
  822. case 19:
  823. case "end":
  824. return _context6.stop();
  825. }
  826. }, _callee6, this);
  827. }));
  828. function invokeLayoutCallback(_x12, _x13, _x14, _x15) {
  829. return _invokeLayoutCallback.apply(this, arguments);
  830. }
  831. return invokeLayoutCallback;
  832. }();
  833. _proto.runWorkQueue = /*#__PURE__*/_regeneratorRuntime().mark(function runWorkQueue(promise, workQueue) {
  834. var _this = this;
  835. var querablePromise;
  836. return _regeneratorRuntime().wrap(function runWorkQueue$(_context7) {
  837. while (1) switch (_context7.prev = _context7.next) {
  838. case 0:
  839. querablePromise = makeQuerablePromise(promise);
  840. if (workQueue.length > 0 && querablePromise.isPending()) {
  841. workQueue.forEach(function (workTask) {
  842. if (workTask.taskType === exports.LayoutTaskType.IntrinsicSizes) {
  843. var layoutChild = workTask.layoutChild,
  844. deferred = workTask.deferred;
  845. var node = layoutChild.node;
  846. deferred.resolve(_this.getNodeIntrisicSizes(node));
  847. }
  848. if (workTask.taskType === exports.LayoutTaskType.Layout) {
  849. var _layoutChild = workTask.layoutChild,
  850. _deferred = workTask.deferred,
  851. layoutConstraints = workTask.layoutConstraints;
  852. var _node = _layoutChild.node,
  853. layoutContext = _layoutChild.layoutContext;
  854. var fragment = _this.getNodeFragment(_node, layoutConstraints);
  855. _deferred.resolve(layoutContext.layoutFragmentFactory(fragment));
  856. }
  857. });
  858. }
  859. // wait promise to resolve
  860. _context7.next = 4;
  861. return;
  862. case 4:
  863. if (querablePromise.isFulfilled()) {
  864. _context7.next = 6;
  865. break;
  866. }
  867. throw new Error('promise not fullfilled!');
  868. case 6:
  869. return _context7.abrupt("return", querablePromise.getFullFilledValue());
  870. case 7:
  871. case "end":
  872. return _context7.stop();
  873. }
  874. }, runWorkQueue);
  875. });
  876. _proto.getNodeIntrisicSizes = function getNodeIntrisicSizes(node) {
  877. var _styleMap$get, _node$intrisicSizes, _styleMap$get2, _styleMap$get3, _node$intrisicSizes2, _styleMap$get4, _styleMap$get5, _node$intrisicSizes3, _styleMap$get6, _styleMap$get7, _node$intrisicSizes4, _styleMap$get8;
  878. // calculate from border box, depend on writing mode of current layout
  879. var styleMap = node.getAllStyle();
  880. var minWidth = ((_styleMap$get = styleMap.get(exports.PropertyName.MIN_WIDTH)) === null || _styleMap$get === void 0 ? void 0 : _styleMap$get.value) || ((_node$intrisicSizes = node.intrisicSizes) === null || _node$intrisicSizes === void 0 ? void 0 : _node$intrisicSizes.minContentInlineSize) || ((_styleMap$get2 = styleMap.get(exports.PropertyName.WIDTH)) === null || _styleMap$get2 === void 0 ? void 0 : _styleMap$get2.value) || 0;
  881. var maxWidth = ((_styleMap$get3 = styleMap.get(exports.PropertyName.MAX_WIDTH)) === null || _styleMap$get3 === void 0 ? void 0 : _styleMap$get3.value) || ((_node$intrisicSizes2 = node.intrisicSizes) === null || _node$intrisicSizes2 === void 0 ? void 0 : _node$intrisicSizes2.maxContentInlineSize) || ((_styleMap$get4 = styleMap.get(exports.PropertyName.WIDTH)) === null || _styleMap$get4 === void 0 ? void 0 : _styleMap$get4.value) || 0;
  882. var minHeight = ((_styleMap$get5 = styleMap.get(exports.PropertyName.MIN_HEIGHT)) === null || _styleMap$get5 === void 0 ? void 0 : _styleMap$get5.value) || ((_node$intrisicSizes3 = node.intrisicSizes) === null || _node$intrisicSizes3 === void 0 ? void 0 : _node$intrisicSizes3.minContentBlockSize) || ((_styleMap$get6 = styleMap.get(exports.PropertyName.HEIGHT)) === null || _styleMap$get6 === void 0 ? void 0 : _styleMap$get6.value) || 0;
  883. var maxHeight = ((_styleMap$get7 = styleMap.get(exports.PropertyName.MAX_HEIGHT)) === null || _styleMap$get7 === void 0 ? void 0 : _styleMap$get7.value) || ((_node$intrisicSizes4 = node.intrisicSizes) === null || _node$intrisicSizes4 === void 0 ? void 0 : _node$intrisicSizes4.maxContentBlockSize) || ((_styleMap$get8 = styleMap.get(exports.PropertyName.HEIGHT)) === null || _styleMap$get8 === void 0 ? void 0 : _styleMap$get8.value) || 0;
  884. return {
  885. minContentInlineSize: minWidth,
  886. maxContentInlineSize: maxWidth,
  887. minContentBlockSize: minHeight,
  888. maxContentBlockSize: maxHeight
  889. };
  890. };
  891. _proto.getNodeFragment = function getNodeFragment(node, constraints) {
  892. var _node$getComputedLayo, _node$getAllStyle$get, _node$getAllStyle$get2, _node$getComputedLayo2, _node$getAllStyle$get3, _node$getAllStyle$get4;
  893. // TODO
  894. var width = ((_node$getComputedLayo = node.getComputedLayout()) === null || _node$getComputedLayo === void 0 ? void 0 : _node$getComputedLayo.inlineSize) || ((_node$getAllStyle$get = node.getAllStyle().get(exports.PropertyName.MIN_WIDTH)) === null || _node$getAllStyle$get === void 0 ? void 0 : _node$getAllStyle$get.value) || ((_node$getAllStyle$get2 = node.getAllStyle().get(exports.PropertyName.WIDTH)) === null || _node$getAllStyle$get2 === void 0 ? void 0 : _node$getAllStyle$get2.value) || 0;
  895. var height = ((_node$getComputedLayo2 = node.getComputedLayout()) === null || _node$getComputedLayo2 === void 0 ? void 0 : _node$getComputedLayo2.blockSize) || ((_node$getAllStyle$get3 = node.getAllStyle().get(exports.PropertyName.MIN_HEIGHT)) === null || _node$getAllStyle$get3 === void 0 ? void 0 : _node$getAllStyle$get3.value) || ((_node$getAllStyle$get4 = node.getAllStyle().get(exports.PropertyName.HEIGHT)) === null || _node$getAllStyle$get4 === void 0 ? void 0 : _node$getAllStyle$get4.value) || 0;
  896. return {
  897. inlineSize: width,
  898. blockSize: height,
  899. data: constraints.data
  900. };
  901. };
  902. return LayoutEngine;
  903. }();
  904. /**
  905. * 布局的结果
  906. */
  907. var LayoutFragment = function LayoutFragment(_layoutContext, options) {
  908. this._layoutContext = void 0;
  909. this.options = void 0;
  910. this.layoutContext = void 0;
  911. this.inlineSize = void 0;
  912. this.blockSize = void 0;
  913. this.inlineOffset = void 0;
  914. this.blockOffset = void 0;
  915. this.data = void 0;
  916. this._layoutContext = _layoutContext;
  917. this.options = options;
  918. this.layoutContext = _layoutContext;
  919. this.inlineSize = options.inlineSize;
  920. this.blockSize = options.blockSize;
  921. this.inlineOffset = 0;
  922. this.blockOffset = 0;
  923. this.data = options.data;
  924. };
  925. var id = 1;
  926. var LayoutObject = /*#__PURE__*/function () {
  927. function LayoutObject(style) {
  928. if (style === void 0) {
  929. style = new Map();
  930. }
  931. this.id = void 0;
  932. this.style = void 0;
  933. this.dirty = void 0;
  934. this.parent = void 0;
  935. this.children = void 0;
  936. this.internalIntrisicSizes = void 0;
  937. this.computedLayout = void 0;
  938. this.measureFn = void 0;
  939. this.id = id++;
  940. this.style = style;
  941. this.parent = undefined;
  942. this.children = [];
  943. this.dirty = false;
  944. }
  945. /**
  946. * set the intrinsic size of leaf node, different basic shape has different size, compsed shape has
  947. * @param measure measure function
  948. */
  949. var _proto = LayoutObject.prototype;
  950. _proto.setMeasure = function setMeasure(measure) {
  951. this.measureFn = measure;
  952. };
  953. _proto.setIntrisicSizes = function setIntrisicSizes(intrisicSizes) {
  954. this.internalIntrisicSizes = intrisicSizes;
  955. };
  956. _proto.addChild = function addChild(child) {
  957. var _this$children;
  958. (_this$children = this.children) === null || _this$children === void 0 ? void 0 : _this$children.push(child);
  959. };
  960. _proto.insertChild = function insertChild(index, child) {
  961. this.children.splice(index, 0, child);
  962. };
  963. _proto.removeChild = function removeChild(child) {
  964. var _this$children2;
  965. var index = (_this$children2 = this.children) === null || _this$children2 === void 0 ? void 0 : _this$children2.findIndex(function (node) {
  966. return node.id === child.id;
  967. });
  968. this.removeChildAtIndex(index);
  969. };
  970. _proto.removeChildAtIndex = function removeChildAtIndex(index) {
  971. this.children.splice(index, 1);
  972. };
  973. _proto.replaceChildAtIndex = function replaceChildAtIndex(index, child) {
  974. this.children.splice(index, 1, child);
  975. };
  976. _proto.setStyle = function setStyle(property, value) {
  977. this.style.set(property, value);
  978. }
  979. // setStyles(styles: Record<StyleProperty, StyleInputValue>) {
  980. // this.style = StylePropertyMap.create({ styles }).styles;
  981. // }
  982. ;
  983. _proto.getStyle = function getStyle() {
  984. var _this = this;
  985. var returnStyle = new Map();
  986. for (var _len = arguments.length, properties = new Array(_len), _key = 0; _key < _len; _key++) {
  987. properties[_key] = arguments[_key];
  988. }
  989. properties.forEach(function (prop) {
  990. var propertyValue = _this.style.get(prop);
  991. if (propertyValue) {
  992. returnStyle.set(prop, propertyValue);
  993. }
  994. });
  995. return returnStyle;
  996. };
  997. _proto.getAllStyle = function getAllStyle() {
  998. return this.style;
  999. };
  1000. _proto.markDirty = function markDirty() {
  1001. this.dirty = true;
  1002. };
  1003. _proto.idDirty = function idDirty() {
  1004. return this.dirty;
  1005. };
  1006. _proto.getSize = function getSize() {
  1007. var _this$style$get$value, _this$style$get, _this$style$get$value2, _this$style$get2;
  1008. var width = (_this$style$get$value = (_this$style$get = this.style.get(exports.PropertyName.WIDTH)) === null || _this$style$get === void 0 ? void 0 : _this$style$get.value) !== null && _this$style$get$value !== void 0 ? _this$style$get$value : 0;
  1009. var height = (_this$style$get$value2 = (_this$style$get2 = this.style.get(exports.PropertyName.HEIGHT)) === null || _this$style$get2 === void 0 ? void 0 : _this$style$get2.value) !== null && _this$style$get$value2 !== void 0 ? _this$style$get$value2 : 0;
  1010. return {
  1011. width: width,
  1012. height: height
  1013. };
  1014. };
  1015. _proto.computeLayout = /*#__PURE__*/function () {
  1016. var _computeLayout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
  1017. var size;
  1018. return _regeneratorRuntime().wrap(function _callee$(_context) {
  1019. while (1) switch (_context.prev = _context.next) {
  1020. case 0:
  1021. size = this.getSize();
  1022. _context.next = 3;
  1023. return layoutEngine.computeLayout(this, {
  1024. availableInlineSize: size.width,
  1025. availableBlockSize: size.height,
  1026. fixedInlineSize: size.width,
  1027. fixedBlockSize: size.height,
  1028. percentageInlineSize: size.width,
  1029. percentageBlockSize: size.height,
  1030. data: undefined
  1031. });
  1032. case 3:
  1033. case "end":
  1034. return _context.stop();
  1035. }
  1036. }, _callee, this);
  1037. }));
  1038. function computeLayout() {
  1039. return _computeLayout.apply(this, arguments);
  1040. }
  1041. return computeLayout;
  1042. }();
  1043. _proto.setComputedLayout = function setComputedLayout(computedLayout) {
  1044. this.computedLayout = computedLayout;
  1045. };
  1046. _proto.getComputedLayout = function getComputedLayout() {
  1047. return this.computedLayout;
  1048. };
  1049. _proto.getAllComputedLayout = function getAllComputedLayout() {};
  1050. _proto.toString = function toString() {
  1051. return "LayoutObject " + this.id;
  1052. };
  1053. _createClass(LayoutObject, [{
  1054. key: "intrisicSizes",
  1055. get: function get() {
  1056. return this.internalIntrisicSizes;
  1057. }
  1058. }, {
  1059. key: "childCount",
  1060. get: function get() {
  1061. return this.children.length;
  1062. }
  1063. }]);
  1064. return LayoutObject;
  1065. }();
  1066. var DefaultLayoutRegistry = /*#__PURE__*/function () {
  1067. function DefaultLayoutRegistry() {
  1068. this.registry = new Map();
  1069. }
  1070. var _proto = DefaultLayoutRegistry.prototype;
  1071. _proto.hasLayout = function hasLayout(name) {
  1072. return this.registry.has(name);
  1073. }
  1074. /**
  1075. *
  1076. * @param name layout name, default to 'absolute'
  1077. * @returns layout object
  1078. */;
  1079. _proto.getLayout = function getLayout(name) {
  1080. if (name === void 0) {
  1081. name = 'absolute';
  1082. }
  1083. if (!this.hasLayout(name)) {
  1084. throw new Error("invalid layout property: " + name);
  1085. }
  1086. return this.registry.get(name);
  1087. };
  1088. _proto.updateLayout = function updateLayout(name, layout) {
  1089. this.registry.set(name, layout);
  1090. };
  1091. _proto.registerLayout = function registerLayout(name, layout) {
  1092. if (name === '') {
  1093. throw new TypeError("layout name cant't be empty");
  1094. }
  1095. if (DefaultLayoutRegistry.reservedLayout.includes(name)) {
  1096. throw new Error("layout name '" + name + "' is a system reserved layout name, please use another name");
  1097. }
  1098. if (this.hasLayout(name)) {
  1099. throw new Error("layout '" + name + "' already exist.");
  1100. }
  1101. this.registry.set(name, layout);
  1102. };
  1103. _proto.deleteLayout = function deleteLayout(name) {
  1104. this.registry.delete(name);
  1105. };
  1106. _createClass(DefaultLayoutRegistry, [{
  1107. key: "size",
  1108. get: function get() {
  1109. return this.registry.size;
  1110. }
  1111. }]);
  1112. return DefaultLayoutRegistry;
  1113. }();
  1114. // 系统保留的布局名称,外部用户不能使用
  1115. // private static reservedLayout = ['relative', 'absolute', 'fixed', 'flex', 'dagre', 'autolayout'];
  1116. DefaultLayoutRegistry.reservedLayout = [];
  1117. // import { LayoutEdges, LayoutEdgesOptions } from './LayoutEdges';
  1118. // const layoutRegistry = new DefaultLayoutRegistry();
  1119. // const layoutEdgesFactory = (options: LayoutEdgesOptions) => {
  1120. // return new LayoutEdges(options);
  1121. // };
  1122. // const layoutContextFactory = (options: LayoutEdgesOptions) => {
  1123. // // const layoutChildrenFactory = (childOptions: LayoutChildrenOptions) => {
  1124. // // return new LayoutChildren(childOptions);
  1125. // // };
  1126. // // container.register({
  1127. // // token: LayoutChildrenFactory,
  1128. // // useFactory: (childContext) => {
  1129. // // return (childOptions: LayoutChildrenOptions) => {
  1130. // // const childContainer = childContext.container.createChild();
  1131. // // childContainer.register({
  1132. // // token: LayoutChildrenOptions,
  1133. // // useValue: childOptions,
  1134. // // });
  1135. // // return childContainer.get(LayoutChildren);
  1136. // // };
  1137. // // },
  1138. // // });
  1139. // // container.register(FragmentResult);
  1140. // // container.register({
  1141. // // token: FragmentResultFactory,
  1142. // // useFactory: (childContext) => {
  1143. // // return (childOptions, node) => {
  1144. // // const childContainer = childContext.container.createChild();
  1145. // // childContainer.register({
  1146. // // token: FragmentResultOptions,
  1147. // // useValue: childOptions,
  1148. // // });
  1149. // // childContainer.register({
  1150. // // token: ContextNode,
  1151. // // useValue: node,
  1152. // // });
  1153. // // return childContainer.get(FragmentResult);
  1154. // // };
  1155. // // },
  1156. // // });
  1157. // // container.register(LayoutFragment);
  1158. // // container.register({
  1159. // // token: LayoutFragmentFactory,
  1160. // // useFactory: (childContext) => {
  1161. // // return (childOptions) => {
  1162. // // const childContainer = childContext.container.createChild();
  1163. // // childContainer.register({
  1164. // // token: LayoutFragmentOptions,
  1165. // // useValue: childOptions,
  1166. // // });
  1167. // // return childContainer.get(LayoutFragment);
  1168. // // };
  1169. // // },
  1170. // // });
  1171. // // const layoutChildrenFactory = container.get(LayoutChildrenFactory);
  1172. // // const layoutFragmentFactory = (childContext) => {
  1173. // // return (childOptions) => {
  1174. // // return new LayoutFragment(childOptions);
  1175. // // };
  1176. // // };
  1177. // // const fragmentResultFactory = container.get(FragmentResultFactory);
  1178. // // const layoutContext = new LayoutContext({
  1179. // // ...options,
  1180. // // layoutChildrenFactory,
  1181. // // layoutFragmentFactory,
  1182. // // fragmentResultFactory,
  1183. // // });
  1184. // // return layoutContext;
  1185. // }
  1186. // export const layoutEngine = new LayoutEngine(layoutRegistry);
  1187. var layoutEngine = null;
  1188. exports.AbstractLayoutDefinition = AbstractLayoutDefinition;
  1189. exports.DefaultLayoutRegistry = DefaultLayoutRegistry;
  1190. exports.FragmentResult = FragmentResult;
  1191. exports.LayoutChildren = LayoutChildren;
  1192. exports.LayoutContext = LayoutContext;
  1193. exports.LayoutEdges = LayoutEdges;
  1194. exports.LayoutEngine = LayoutEngine;
  1195. exports.LayoutFragment = LayoutFragment;
  1196. exports.LayoutObject = LayoutObject;
  1197. exports.layoutEngine = layoutEngine;