WebOrbiton
v1.5.0

AtheraStudio Code

585 lines · 21.3 KB
  1. (function () {
  2. "use strict";
  3. ​
  4. var A = window.Athera;
  5. var util = A.util;
  6. var fs = A.fs;
  7. ​
  8. var BADGES = {
  9. html: ["html", "<>"], htm: ["html", "<>"], php: ["php", "php"], css: ["css", "#"], scss: ["css", "S"],
  10. js: ["js", "JS"], mjs: ["js", "JS"], jsx: ["js", "JSX"], ts: ["ts", "TS"], tsx: ["ts", "TSX"],
  11. json: ["json", "{}"], jsonc: ["json", "{}"], xml: ["xml", "</>"], md: ["md", "M↓"], svg: ["img", "svg"], txt: ["txt", "≡"]
  12. };
  13. var NAMED = {
  14. "sitemap.xml": ["sitemap", "sitemap"], "sitemap_index.xml": ["sitemap", "sitemap"],
  15. "rss.xml": ["rss", "rss"], "feed.xml": ["rss", "rss"], "atom.xml": ["rss", "rss"]
  16. };
  17. A.fileBadge = function (name) {
  18. var named = NAMED[util.basename(name).toLowerCase()];
  19. if (named) return '<span class="ath-ficon" data-type="' + named[0] + '">' + A.icon(named[1]) + "</span>";
  20. var ext = util.ext(name);
  21. var b = BADGES[ext] || (fs.isImage(name) ? ["img", "▣"] : null);
  22. if (!b) return '<span class="ath-ficon ath-ficon-file">' + A.icon("file") + "</span>";
  23. return '<span class="ath-ficon" data-type="' + b[0] + '">' + util.esc(b[1]) + "</span>";
  24. };
  25. ​
  26. function isRasterImage(name) {
  27. return fs.isImage(name) && util.ext(name) !== "svg";
  28. }
  29. ​
  30. function canAutoSave(tab) {
  31. if (!tab || tab.kind !== "text" || !tab.dirty || tabs.list.indexOf(tab) < 0) return false;
  32. if (tab.path != null) return !!fs.provider && fs.provider.kind === "disk";
  33. return !!tab.handle;
  34. }
  35. ​
  36. var pending = new Set();
  37. var flushAutoSave = util.debounce(function () {
  38. var list = Array.from(pending);
  39. pending.clear();
  40. list.forEach(function (tab) { if (canAutoSave(tab)) tabs.save(tab, true); });
  41. }, 1000);
  42. ​
  43. var dragTab = null;
  44. var dropAt = -1;
  45. var marker = null;
  46. ​
  47. function reduced() {
  48. return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  49. }
  50. ​
  51. function onEnterEnd(e) {
  52. if (e.animationName !== "ath-tab-in") return;
  53. var n = e.currentTarget;
  54. n.classList.remove("is-entering");
  55. n.removeEventListener("animationend", onEnterEnd);
  56. if (n.classList.contains("is-active")) n.scrollIntoView({ block: "nearest", inline: "nearest" });
  57. }
  58. ​
  59. function leave(node, animate) {
  60. node.removeAttribute("draggable");
  61. if (!animate) { node.remove(); return; }
  62. node.style.setProperty("--w", node.offsetWidth + "px");
  63. node.classList.remove("is-entering");
  64. node.classList.add("is-leaving");
  65. var done = false;
  66. function finish() {
  67. if (done) return;
  68. done = true;
  69. node.remove();
  70. }
  71. node.addEventListener("animationend", function (e) {
  72. if (e.animationName === "ath-tab-out") finish();
  73. });
  74. setTimeout(finish, 600);
  75. }
  76. ​
  77. function buildTab(tab) {
  78. var node = util.el("div", { class: "ath-tab", role: "tab", draggable: "true" });
  79. node._tab = tab;
  80. node.innerHTML = A.fileBadge(tab.name) + '<span class="ath-tab-name"></span>';
  81. var close = util.el("button", { type: "button", class: "ath-tab-close", html: '<span class="ath-tab-dot"></span>' + A.icon("x") });
  82. close.addEventListener("click", function (e) { e.stopPropagation(); tabs.close(tab); });
  83. node.appendChild(close);
  84. node.addEventListener("mousedown", function (e) {
  85. if (e.button === 1) { e.preventDefault(); tabs.close(tab); }
  86. });
  87. node.addEventListener("click", function () { if (tab !== tabs.active) tabs.activate(tab); });
  88. node.addEventListener("contextmenu", function (e) {
  89. e.preventDefault();
  90. var i = tabs.list.indexOf(tab);
  91. var items = [
  92. { label: A.t("common.save"), icon: "save", kbd: "Ctrl+S", action: function () { tabs.save(tab); } },
  93. "-",
  94. { label: A.t("tabs.close"), icon: "x", kbd: "Alt+W", action: function () { tabs.close(tab); } },
  95. { label: A.t("tabs.close_others"), icon: "xCircle", action: function () { tabs.closeAll(tab); } },
  96. { label: A.t("tabs.close_all"), icon: "closeAll", action: function () { tabs.closeAll(); } }
  97. ];
  98. if (tabs.canReopen()) items.push("-", { label: A.t("cmd.reopen_tab"), icon: "undo", kbd: "Alt+T", action: function () { tabs.reopen(); } });
  99. var moves = [];
  100. if (i > 0) moves.push({ label: A.t("tabs.move_left"), kbd: "Alt+Shift+PgUp", icon: "arrowLeft", action: function () { tabs.shift(-1, tab); } });
  101. if (i >= 0 && i < tabs.list.length - 1) moves.push({ label: A.t("tabs.move_right"), kbd: "Alt+Shift+PgDn", icon: "arrowRight", action: function () { tabs.shift(1, tab); } });
  102. if (moves.length) items.push.apply(items, ["-"].concat(moves));
  103. A.ui.contextMenu(e.clientX, e.clientY, items);
  104. });
  105. node._name = null;
  106. return node;
  107. }
  108. ​
  109. function syncTab(node, tab) {
  110. var c = node.classList;
  111. c.toggle("is-active", tab === tabs.active);
  112. c.toggle("is-dirty", !!tab.dirty);
  113. node.setAttribute("aria-selected", tab === tabs.active ? "true" : "false");
  114. node.title = tab.path != null ? tab.path : tab.name + (tab.handle ? "" : " " + A.t("tabs.not_on_disk"));
  115. if (node._name !== tab.name) {
  116. node._name = tab.name;
  117. node.firstChild.outerHTML = A.fileBadge(tab.name);
  118. node.querySelector(".ath-tab-name").textContent = tab.name;
  119. }
  120. node.querySelector(".ath-tab-close").setAttribute("aria-label", A.t("tabs.close_named", { name: tab.name }));
  121. }
  122. ​
  123. function liveNodes() {
  124. return tabs.list.map(function (t) { return t._node; }).filter(Boolean);
  125. }
  126. ​
  127. function indexAt(x) {
  128. var nodes = liveNodes();
  129. for (var i = 0; i < nodes.length; i++) {
  130. var r = nodes[i].getBoundingClientRect();
  131. if (x < r.left + r.width / 2) return i;
  132. }
  133. return nodes.length;
  134. }
  135. ​
  136. function showMarker(index) {
  137. var nodes = liveNodes();
  138. if (!nodes.length) return hideMarker();
  139. var from = tabs.list.indexOf(dragTab);
  140. if (index === from || index === from + 1) return hideMarker();
  141. var host = tabs.el.getBoundingClientRect();
  142. var x = index < nodes.length ? nodes[index].getBoundingClientRect().left : nodes[nodes.length - 1].getBoundingClientRect().right;
  143. if (x < host.left - 1 || x > host.right + 1) return hideMarker();
  144. if (!marker) {
  145. marker = document.createElement("div");
  146. marker.className = "ath-tab-marker";
  147. document.body.appendChild(marker);
  148. }
  149. marker.style.top = host.top + "px";
  150. marker.style.height = host.height + "px";
  151. marker.style.transform = "translateX(" + Math.round(x) + "px)";
  152. marker.classList.add("is-visible");
  153. }
  154. ​
  155. function hideMarker() {
  156. if (marker) marker.classList.remove("is-visible");
  157. }
  158. ​
  159. function endTabDrag() {
  160. if (!dragTab) return;
  161. if (dragTab._node) dragTab._node.classList.remove("is-dragging");
  162. dragTab = null;
  163. dropAt = -1;
  164. hideMarker();
  165. if (tabs.el) tabs.el.classList.remove("is-reordering");
  166. }
  167. ​
  168. function initDrag(el) {
  169. el.addEventListener("dragstart", function (e) {
  170. var node = e.target.closest && e.target.closest(".ath-tab");
  171. if (!node || !node._tab || node.classList.contains("is-leaving")) return;
  172. dragTab = node._tab;
  173. e.dataTransfer.effectAllowed = "move";
  174. e.dataTransfer.setData("text/plain", dragTab.name);
  175. requestAnimationFrame(function () {
  176. if (dragTab && dragTab._node) dragTab._node.classList.add("is-dragging");
  177. el.classList.add("is-reordering");
  178. });
  179. });
  180. el.addEventListener("dragover", function (e) {
  181. if (!dragTab) return;
  182. e.preventDefault();
  183. e.dataTransfer.dropEffect = "move";
  184. var r = el.getBoundingClientRect();
  185. if (e.clientX < r.left + 48) el.scrollLeft -= 16;
  186. else if (e.clientX > r.right - 48) el.scrollLeft += 16;
  187. dropAt = indexAt(e.clientX);
  188. showMarker(dropAt);
  189. });
  190. el.addEventListener("dragleave", function (e) {
  191. if (dragTab && !el.contains(e.relatedTarget)) hideMarker();
  192. });
  193. el.addEventListener("drop", function (e) {
  194. if (!dragTab) return;
  195. e.preventDefault();
  196. e.stopPropagation();
  197. var tab = dragTab, to = indexAt(e.clientX);
  198. endTabDrag();
  199. tabs.reorder(tab, to);
  200. });
  201. el.addEventListener("dragend", endTabDrag);
  202. window.addEventListener("dragend", endTabDrag, true);
  203. window.addEventListener("drop", function () { setTimeout(endTabDrag, 0); }, true);
  204. }
  205. ​
  206. var seq = 0;
  207. var CLOSED_MAX = 20;
  208. var closed = [];
  209. ​
  210. function remember(tab) {
  211. if (tab.kind === "image" && tab.path == null && !tab.handle) return;
  212. var entry = { name: tab.name, path: tab.path, handle: tab.handle, kind: tab.kind, scrollTop: tab.scrollTop };
  213. if (tab.kind === "text") {
  214. var st = tabs.stateOf(tab);
  215. var sel = st.selection.main;
  216. entry.anchor = sel.anchor;
  217. entry.head = sel.head;
  218. if (tab.path == null && !tab.handle) entry.text = st.doc.toString();
  219. }
  220. closed = closed.filter(function (c) { return !(c.path != null && c.path === entry.path); });
  221. closed.push(entry);
  222. if (closed.length > CLOSED_MAX) closed.shift();
  223. }
  224. ​
  225. function restoreView(tab, entry) {
  226. if (!tab || tab.kind !== "text" || entry.anchor == null) return;
  227. var len = tabs.stateOf(tab).doc.length;
  228. var anchor = Math.min(entry.anchor, len), head = Math.min(entry.head, len);
  229. var view = A.editor.view;
  230. view.dispatch({ selection: { anchor: anchor, head: head } });
  231. requestAnimationFrame(function () { view.scrollDOM.scrollTop = entry.scrollTop || 0; });
  232. }
  233. ​
  234. var tabs = (A.tabs = {
  235. list: [],
  236. active: null,
  237. el: null,
  238. ​
  239. init: function (el) {
  240. tabs.el = el;
  241. initDrag(el);
  242. el.addEventListener("wheel", function (e) {
  243. if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) { el.scrollLeft += e.deltaY; e.preventDefault(); }
  244. }, { passive: false });
  245. A.on("doc-change", function (state) {
  246. var tab = tabs.active;
  247. if (!tab || tab.kind !== "text") return;
  248. var dirty = state.doc.length !== tab.savedDoc.length || !state.doc.eq(tab.savedDoc);
  249. if (dirty !== tab.dirty) { tab.dirty = dirty; tabs.render(); }
  250. if (dirty && A.settings.get("autoSave")) { pending.add(tab); flushAutoSave(); }
  251. });
  252. window.addEventListener("blur", function () {
  253. if (!A.settings.get("autoSave")) return;
  254. tabs.list.forEach(function (tab) { if (canAutoSave(tab)) tabs.save(tab, true); });
  255. });
  256. A.on("lang", function () { tabs.render(); });
  257. A.on("workspace", function () { tabs.clearClosed(); });
  258. tabs.render();
  259. },
  260. ​
  261. stateOf: function (tab) {
  262. return tab === tabs.active ? A.editor.view.state : tab.state;
  263. },
  264. ​
  265. textOf: function (tab) {
  266. return tabs.stateOf(tab).doc.toString();
  267. },
  268. ​
  269. byPath: function (path) {
  270. return tabs.list.find(function (t) { return t.path === path; }) || null;
  271. },
  272. ​
  273. contentOf: function (path) {
  274. var tab = tabs.byPath(path);
  275. return tab && tab.kind === "text" ? tabs.textOf(tab) : null;
  276. },
  277. ​
  278. canReopen: function () {
  279. return closed.length > 0;
  280. },
  281. ​
  282. clearClosed: function () {
  283. closed = [];
  284. },
  285. ​
  286. reopen: async function () {
  287. while (closed.length) {
  288. var entry = closed.pop();
  289. var tab = null;
  290. try {
  291. if (entry.path != null) {
  292. if (!fs.provider) continue;
  293. if (!(await fs.provider.exists(entry.path))) continue;
  294. tab = await tabs.openPath(entry.path);
  295. } else if (entry.handle) {
  296. var file = await entry.handle.getFile();
  297. tab = await tabs.openFile({ name: entry.name, handle: entry.handle, file: file });
  298. } else if (entry.kind === "text") {
  299. tab = tabs.create({ name: entry.name, text: entry.text || "", dirty: !!entry.text });
  300. }
  301. } catch (e) {
  302. continue;
  303. }
  304. if (tab) {
  305. restoreView(tab, entry);
  306. return tab;
  307. }
  308. }
  309. A.ui.toast(A.t("tabs.nothing_to_reopen"), "info");
  310. return null;
  311. },
  312. ​
  313. anyDirty: function () {
  314. return tabs.list.some(function (t) { return t.dirty; });
  315. },
  316. ​
  317. create: function (desc, options) {
  318. var tab = {
  319. id: ++seq,
  320. name: desc.name,
  321. path: desc.path == null ? null : desc.path,
  322. handle: desc.handle || null,
  323. kind: desc.imageUrl ? "image" : "text",
  324. imageUrl: desc.imageUrl || null,
  325. dirty: !!desc.dirty,
  326. scrollTop: 0
  327. };
  328. if (tab.kind === "text") {
  329. tab.state = A.editor.createState(desc.text || "", tab.name);
  330. tab.savedDoc = desc.dirty ? CM.EditorState.create({ doc: "" }).doc : tab.state.doc;
  331. }
  332. var at = tabs.active ? tabs.list.indexOf(tabs.active) + 1 : tabs.list.length;
  333. tabs.list.splice(at, 0, tab);
  334. tabs.activate(tab, options);
  335. return tab;
  336. },
  337. ​
  338. openPath: async function (path, options) {
  339. var existing = tabs.byPath(path);
  340. if (existing) return tabs.activate(existing, options);
  341. var name = util.basename(path);
  342. try {
  343. if (isRasterImage(name)) {
  344. var blob = await fs.provider.readFile(path);
  345. return tabs.byPath(path) || tabs.create({ name: name, path: path, imageUrl: URL.createObjectURL(blob) }, options);
  346. }
  347. if (fs.isBinary(name)) {
  348. A.ui.toast(A.t("tabs.binary", { name: name }), "warning");
  349. return null;
  350. }
  351. var text = await fs.provider.readText(path);
  352. return tabs.byPath(path) || tabs.create({ name: name, path: path, text: text }, options);
  353. } catch (e) {
  354. A.ui.toast(A.t("tabs.open_failed", { name: name, error: e.message }), "danger");
  355. return null;
  356. }
  357. },
  358. ​
  359. openFile: async function (item) {
  360. if (item.handle) {
  361. for (var t of tabs.list) {
  362. if (t.handle && await t.handle.isSameEntry(item.handle)) return tabs.activate(t);
  363. }
  364. }
  365. if (isRasterImage(item.name)) {
  366. return tabs.create({ name: item.name, handle: item.handle, imageUrl: URL.createObjectURL(item.file) });
  367. }
  368. if (fs.isBinary(item.name)) {
  369. A.ui.toast(A.t("tabs.binary", { name: item.name }), "warning");
  370. return null;
  371. }
  372. return tabs.create({ name: item.name, handle: item.handle, text: await item.file.text() });
  373. },
  374. ​
  375. newUntitled: function (name, text) {
  376. return tabs.create({ name: name, text: text || "", dirty: !!text });
  377. },
  378. ​
  379. activate: function (tab, options) {
  380. var prev = tabs.active;
  381. var view = A.editor.view;
  382. if (prev && prev !== tab && prev.kind === "text" && tabs.list.indexOf(prev) >= 0) {
  383. prev.state = view.state;
  384. prev.scrollTop = view.scrollDOM.scrollTop;
  385. }
  386. tabs.active = tab;
  387. if (tab && tab.kind === "text" && prev !== tab) {
  388. view.setState(A.editor.syncState(tab.state, tab.name));
  389. requestAnimationFrame(function () { view.scrollDOM.scrollTop = tab.scrollTop; });
  390. }
  391. tabs.render();
  392. A.emit("active-change", tab);
  393. if (tab && tab.kind === "text") {
  394. A.emit("cursor", view.state);
  395. if (!options || options.focusEditor !== false) A.editor.focus();
  396. }
  397. return tab;
  398. },
  399. ​
  400. move: function (dir) {
  401. if (tabs.list.length < 2) return;
  402. var i = tabs.list.indexOf(tabs.active);
  403. tabs.activate(tabs.list[(i + dir + tabs.list.length) % tabs.list.length]);
  404. },
  405. ​
  406. save: async function (tab, auto) {
  407. tab = tab || tabs.active;
  408. if (!tab || tab.kind !== "text") return false;
  409. if (!auto && tab === tabs.active && A.settings.get("formatOnSave") && A.intellisense.canFormat(tab.name)) {
  410. try { await A.intellisense.format(A.editor.view, tab.name); } catch (e) { A.ui.toast(e.message, "warning"); }
  411. }
  412. var state = tabs.stateOf(tab);
  413. var text = state.doc.toString();
  414. try {
  415. if (tab.path != null && fs.provider) {
  416. await fs.provider.write(tab.path, text);
  417. if (fs.provider.kind === "memory") {
  418. fs.download(tab.name, text);
  419. A.ui.toast(A.t("tabs.memory_saved", { name: tab.name }), "info");
  420. }
  421. } else if (tab.handle) {
  422. await fs.writeHandle(tab.handle, text);
  423. } else {
  424. var h = await fs.saveAs(tab.name, text);
  425. if (h === undefined) return false;
  426. if (h) tabs.retarget(tab, h.name, null, h);
  427. }
  428. } catch (e) {
  429. A.ui.toast(A.t("tabs.save_failed", { name: tab.name, error: e.message }), "danger");
  430. return false;
  431. }
  432. tab.savedDoc = state.doc;
  433. tab.dirty = !tabs.stateOf(tab).doc.eq(state.doc);
  434. tabs.render();
  435. A.emit("saved", tab);
  436. return true;
  437. },
  438. ​
  439. saveAll: async function () {
  440. var dirty = tabs.list.filter(function (t) { return t.dirty; });
  441. var ok = 0;
  442. for (var t of dirty) if (await tabs.save(t)) ok++;
  443. if (ok) A.ui.toast(A.tn("tabs.saved_count", ok), "success");
  444. },
  445. ​
  446. close: async function (tab, force) {
  447. tab = tab || tabs.active;
  448. if (!tab || tabs.list.indexOf(tab) < 0) return true;
  449. if (tab.dirty && !force) {
  450. tabs.activate(tab);
  451. var choice = await A.ui.dialog({
  452. title: A.t("tabs.unsaved_title"),
  453. body: util.el("p", { class: "ath-dialog-text" }, A.t("tabs.unsaved_text", { name: tab.name })),
  454. size: "sm",
  455. actions: [
  456. { label: A.t("common.cancel"), value: null, kind: "ghost" },
  457. { label: A.t("tabs.dont_save"), value: "discard", kind: "secondary" },
  458. { label: A.t("common.save"), value: "save", kind: "primary" }
  459. ]
  460. });
  461. if (!choice) return false;
  462. if (choice === "save" && !(await tabs.save(tab))) return false;
  463. }
  464. var i = tabs.list.indexOf(tab);
  465. if (i < 0) return true;
  466. if (!force) remember(tab);
  467. tabs.list.splice(i, 1);
  468. if (tab.imageUrl) URL.revokeObjectURL(tab.imageUrl);
  469. if (dragTab === tab) endTabDrag();
  470. if (tabs.active === tab) {
  471. tabs.active = null;
  472. tabs.activate(tabs.list[Math.min(i, tabs.list.length - 1)] || null);
  473. } else {
  474. tabs.render();
  475. }
  476. return true;
  477. },
  478. ​
  479. closeAll: async function (except) {
  480. for (var t of tabs.list.slice()) {
  481. if (t !== except && !(await tabs.close(t))) return false;
  482. }
  483. return true;
  484. },
  485. ​
  486. renamePath: function (oldPath, newPath) {
  487. tabs.list.forEach(function (t) {
  488. if (t.path == null) return;
  489. if (t.path === oldPath) tabs.retarget(t, util.basename(newPath), newPath);
  490. else if (t.path.indexOf(oldPath + "/") === 0) t.path = newPath + t.path.slice(oldPath.length);
  491. });
  492. tabs.render();
  493. },
  494. ​
  495. removePath: function (path) {
  496. tabs.list.slice().forEach(function (t) {
  497. if (t.path != null && (t.path === path || t.path.indexOf(path + "/") === 0)) tabs.close(t, true);
  498. });
  499. },
  500. ​
  501. retarget: function (tab, name, path, handle) {
  502. var langChanged = A.editor.langId(name) !== A.editor.langId(tab.name);
  503. tab.name = name;
  504. if (path !== undefined) tab.path = path;
  505. if (handle) tab.handle = handle;
  506. if (langChanged && tab.kind === "text") {
  507. var s = A.editor.setLanguage(tabs.stateOf(tab), name);
  508. if (tab === tabs.active) A.editor.view.setState(s);
  509. else tab.state = s;
  510. }
  511. if (tab === tabs.active) A.emit("active-change", tab);
  512. },
  513. ​
  514. reorder: function (tab, to) {
  515. var from = tabs.list.indexOf(tab);
  516. if (from < 0) return false;
  517. if (to > from) to--;
  518. to = Math.max(0, Math.min(tabs.list.length - 1, to));
  519. if (to === from) return false;
  520. var before = new Map();
  521. tabs.list.forEach(function (t) {
  522. if (t._node) before.set(t, t._node.getBoundingClientRect().left);
  523. });
  524. tabs.list.splice(from, 1);
  525. tabs.list.splice(to, 0, tab);
  526. tabs.render();
  527. if (!reduced()) {
  528. tabs.list.forEach(function (t) {
  529. var n = t._node, b = before.get(t);
  530. if (!n || b == null) return;
  531. var d = b - n.getBoundingClientRect().left;
  532. if (d) {
  533. n.animate(
  534. [{ transform: "translateX(" + d + "px)" }, { transform: "none" }],
  535. { duration: 240, easing: "cubic-bezier(0.22, 1, 0.36, 1)" }
  536. );
  537. }
  538. });
  539. }
  540. if (tab._node) tab._node.scrollIntoView({ block: "nearest", inline: "nearest" });
  541. return true;
  542. },
  543. ​
  544. shift: function (dir, tab) {
  545. tab = tab || tabs.active;
  546. if (!tab) return;
  547. var i = tabs.list.indexOf(tab);
  548. if (i < 0) return;
  549. var j = i + dir;
  550. if (j < 0 || j >= tabs.list.length) return;
  551. tabs.reorder(tab, dir > 0 ? j + 1 : j);
  552. },
  553. ​
  554. render: function () {
  555. var el = tabs.el;
  556. if (!el) return;
  557. var animate = el._ready && !reduced();
  558. var seen = new Set();
  559. var prev = null;
  560. tabs.list.forEach(function (tab) {
  561. var node = tab._node;
  562. if (!node) {
  563. node = tab._node = buildTab(tab);
  564. if (animate) {
  565. node.classList.add("is-entering");
  566. node.addEventListener("animationend", onEnterEnd);
  567. }
  568. }
  569. syncTab(node, tab);
  570. seen.add(node);
  571. var ref = prev ? prev.nextSibling : el.firstChild;
  572. if (node !== ref) el.insertBefore(node, ref);
  573. prev = node;
  574. });
  575. Array.from(el.children).forEach(function (n) {
  576. if (seen.has(n) || n.classList.contains("is-leaving")) return;
  577. leave(n, animate);
  578. });
  579. el._ready = true;
  580. var act = tabs.active && tabs.active._node;
  581. if (act) act.scrollIntoView({ block: "nearest", inline: "nearest" });
  582. document.title = (tabs.active ? (tabs.active.dirty ? "● " : "") + tabs.active.name + " · " : "") + "AtheraStudio Code";
  583. }
  584. });
  585. })();