index.umd.js 54 KB

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