@vanelsas/baredom 4.4.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/custom-elements.json +60 -1
  3. package/dist/all.d.ts +4 -0
  4. package/dist/all.js +222 -0
  5. package/dist/baredom.d.ts +1 -0
  6. package/dist/baremirror-alpha.js +27 -28
  7. package/dist/base.js +691 -673
  8. package/dist/integrity.json +113 -112
  9. package/dist/x-alert.js +17 -17
  10. package/dist/x-avatar-group.js +10 -10
  11. package/dist/x-avatar.js +14 -14
  12. package/dist/x-badge.js +9 -9
  13. package/dist/x-bento-grid.js +6 -6
  14. package/dist/x-bento-item.js +4 -4
  15. package/dist/x-breadcrumbs.js +18 -16
  16. package/dist/x-button.js +1 -1
  17. package/dist/x-calendar.js +41 -41
  18. package/dist/x-cancel-dialogue.js +16 -16
  19. package/dist/x-card.js +7 -7
  20. package/dist/x-carousel.js +37 -35
  21. package/dist/x-chart.js +48 -48
  22. package/dist/x-checkbox.js +1 -1
  23. package/dist/x-chip.js +1 -1
  24. package/dist/x-code.js +31 -31
  25. package/dist/x-collapse.js +11 -11
  26. package/dist/x-color-picker.js +47 -47
  27. package/dist/x-combobox.js +35 -35
  28. package/dist/x-command-palette.js +31 -31
  29. package/dist/x-confetti.js +24 -24
  30. package/dist/x-container.js +6 -6
  31. package/dist/x-context-menu.js +19 -19
  32. package/dist/x-copy.js +1 -1
  33. package/dist/x-currency-field.js +25 -25
  34. package/dist/x-date-picker.js +45 -45
  35. package/dist/x-divider.js +8 -8
  36. package/dist/x-drag-panel.js +33 -33
  37. package/dist/x-drawer.js +12 -12
  38. package/dist/x-drop-zone.js +11 -11
  39. package/dist/x-dropdown.js +12 -12
  40. package/dist/x-fieldset.js +6 -6
  41. package/dist/x-file-download.js +15 -15
  42. package/dist/x-file-upload.js +26 -26
  43. package/dist/x-floating-panel.js +23 -23
  44. package/dist/x-form-field.js +18 -18
  45. package/dist/x-form.js +10 -10
  46. package/dist/x-gaussian-blur.js +13 -13
  47. package/dist/x-grid.js +8 -8
  48. package/dist/x-i18n-provider.js +7 -7
  49. package/dist/x-i18n.js +4 -4
  50. package/dist/x-icon.js +7 -7
  51. package/dist/x-image.js +19 -19
  52. package/dist/x-kbd.js +16 -16
  53. package/dist/x-kinetic-canvas.js +25 -25
  54. package/dist/x-kinetic-font.js +26 -26
  55. package/dist/x-kinetic-typography.js +34 -34
  56. package/dist/x-liquid-dock.js +31 -31
  57. package/dist/x-liquid-fill.js +39 -39
  58. package/dist/x-liquid-glass.js +32 -32
  59. package/dist/x-menu-item.js +9 -9
  60. package/dist/x-menu.js +10 -10
  61. package/dist/x-metaball-cursor.js +26 -26
  62. package/dist/x-modal.js +13 -13
  63. package/dist/x-morph-stack.js +38 -38
  64. package/dist/x-multi-combobox.js +41 -41
  65. package/dist/x-navbar.js +15 -15
  66. package/dist/x-neural-glow.js +29 -29
  67. package/dist/x-notification-center.js +9 -9
  68. package/dist/x-organic-divider.js +18 -18
  69. package/dist/x-organic-progress.js +35 -35
  70. package/dist/x-organic-shape.js +12 -12
  71. package/dist/x-otp-input.js +22 -22
  72. package/dist/x-pagination.js +18 -16
  73. package/dist/x-particle-button.js +55 -54
  74. package/dist/x-popover.js +28 -28
  75. package/dist/x-progress-circle.js +8 -8
  76. package/dist/x-progress.js +8 -8
  77. package/dist/x-proximity-list.js +20 -20
  78. package/dist/x-radio.js +14 -13
  79. package/dist/x-range-slider.js +30 -30
  80. package/dist/x-rating.js +23 -23
  81. package/dist/x-ripple-effect.js +10 -10
  82. package/dist/x-scroll-parallax.js +17 -17
  83. package/dist/x-scroll-stack.js +17 -17
  84. package/dist/x-scroll-story.js +34 -32
  85. package/dist/x-scroll-timeline.js +50 -46
  86. package/dist/x-scroll.js +38 -38
  87. package/dist/x-search-field.js +1 -1
  88. package/dist/x-select.js +1 -1
  89. package/dist/x-sidebar.js +17 -17
  90. package/dist/x-skeleton-group.js +14 -13
  91. package/dist/x-skeleton.js +1 -1
  92. package/dist/x-slider.js +17 -17
  93. package/dist/x-soft-body.js +18 -18
  94. package/dist/x-spacer.js +4 -4
  95. package/dist/x-spinner.js +4 -4
  96. package/dist/x-splash.js +13 -13
  97. package/dist/x-split-pane.js +15 -15
  98. package/dist/x-spotlight-card.js +12 -12
  99. package/dist/x-stat.js +10 -10
  100. package/dist/x-stepper.js +15 -15
  101. package/dist/x-switch.js +12 -12
  102. package/dist/x-tab.js +7 -9
  103. package/dist/x-table-cell.js +20 -20
  104. package/dist/x-table-row.js +9 -9
  105. package/dist/x-table.js +14 -14
  106. package/dist/x-tabs.js +11 -11
  107. package/dist/x-text-area.js +20 -20
  108. package/dist/x-theme.js +26 -26
  109. package/dist/x-timeline-item.js +21 -21
  110. package/dist/x-timeline.js +9 -8
  111. package/dist/x-toast.js +22 -22
  112. package/dist/x-toaster.js +6 -6
  113. package/dist/x-tooltip.js +14 -13
  114. package/dist/x-trace-history.d.ts +5 -0
  115. package/dist/x-trace-history.js +116 -116
  116. package/dist/x-typography.js +6 -6
  117. package/dist/x-welcome-tour.js +64 -62
  118. package/package.json +7 -2
  119. package/scripts/prerender.mjs +70 -20
@@ -2,9 +2,11 @@
2
2
  // Writes a page back out with every shadow tree in its markup, as a declarative shadow root, so
3
3
  // the page shows its components before any script has run.
4
4
  //
5
- // Usage: node scripts/prerender.mjs [--static] <url> <output.html> [<url> <output.html> ...]
5
+ // Usage: node scripts/prerender.mjs [--static] [--tabs <n>] <url> <output.html> [<url> <output.html> ...]
6
6
  // --static leaves out every script and noscript element and sets data-static on the
7
7
  // html element, so the page can style a copy that runs no script.
8
+ // --tabs says how many pages are opened at once: 4 when it is not given, or fewer on a
9
+ // machine with fewer processors.
8
10
  // Each url is written to the output that follows it. One browser opens them all.
9
11
  // Needs: Node 22 or later, and Chrome. Set CHROME_PATH when Chrome is not found, and
10
12
  // CHROME_FLAGS for more flags, such as --no-sandbox in a container.
@@ -15,11 +17,14 @@
15
17
  import { spawn } from 'node:child_process';
16
18
  import { existsSync } from 'node:fs';
17
19
  import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
18
- import { tmpdir } from 'node:os';
20
+ import { availableParallelism, tmpdir } from 'node:os';
19
21
  import { basename, dirname, join } from 'node:path';
20
22
 
21
23
  const STEP_LIMIT_MS = 10_000;
22
24
  const PAGE_LIMIT_MS = 30_000;
25
+ // A tab draws its page on a processor of its own, and a page that waits for one may not finish
26
+ // within its limit. So no more tabs are opened than there are processors.
27
+ const TABS = Math.min(4, availableParallelism());
23
28
 
24
29
  const CHROME_PATHS = [
25
30
  process.env.CHROME_PATH,
@@ -102,10 +107,16 @@ const pageAsMarkup = async (limitMs, isStatic) => {
102
107
  return `<!doctype html>\n${htmlTag}${inside}</html>\n`;
103
108
  };
104
109
 
110
+ // Pages are opened in several tabs at once. Chrome slows down a tab that it takes to be in
111
+ // the background, its frames and its timers, and the script waits for frames. So no tab is
112
+ // slowed down, and each tab is told that it has the focus.
105
113
  const startChrome = (chromePath, profileDir) =>
106
114
  spawn(chromePath, [
107
115
  '--headless=new', '--remote-debugging-port=0', `--user-data-dir=${profileDir}`,
108
- '--no-first-run', '--disable-gpu', ...extraFlags(), 'about:blank',
116
+ '--no-first-run', '--disable-gpu',
117
+ '--disable-background-timer-throttling', '--disable-backgrounding-occluded-windows',
118
+ '--disable-renderer-backgrounding',
119
+ ...extraFlags(), 'about:blank',
109
120
  ]);
110
121
 
111
122
  const chromeAddress = chrome =>
@@ -126,7 +137,8 @@ const stopChrome = async (chrome, profileDir) => {
126
137
  };
127
138
 
128
139
  // A connection to Chrome over its debugging protocol: `send` gives the answer to one command,
129
- // and `next` the next event of one name.
140
+ // and `next` the next event of one name in one tab. Several tabs share the connection, so an
141
+ // event is matched by the session of its tab as well as by its name.
130
142
  const connect = async address => {
131
143
  const socket = new WebSocket(address);
132
144
  await new Promise((resolve, reject) => {
@@ -142,7 +154,8 @@ const connect = async address => {
142
154
  resolve?.(message);
143
155
  };
144
156
  const onAnswer = message => settle(answers, message.id, message);
145
- const onEvent = message => settle(events, message.method, message);
157
+ const eventKey = (method, sessionId) => `${sessionId ?? ''} ${method}`;
158
+ const onEvent = message => settle(events, eventKey(message.method, message.sessionId), message);
146
159
  socket.onmessage = ({ data }) => {
147
160
  const message = JSON.parse(data);
148
161
  (message.id ? onAnswer : onEvent)(message);
@@ -155,7 +168,7 @@ const connect = async address => {
155
168
  error ? reject(new Error(`${method}: ${error.message}`)) : resolve(result));
156
169
  socket.send(JSON.stringify({ id: lastId, method, params, sessionId }));
157
170
  }),
158
- next: method => new Promise(resolve => events.set(method, resolve)),
171
+ next: (method, sessionId) => new Promise(resolve => events.set(eventKey(method, sessionId), resolve)),
159
172
  close: () => socket.close(),
160
173
  };
161
174
  };
@@ -165,7 +178,8 @@ const prerender = async (browser, url, isStatic) => {
165
178
  try {
166
179
  const { sessionId } = await browser.send('Target.attachToTarget', { targetId, flatten: true });
167
180
  await browser.send('Page.enable', {}, sessionId);
168
- const loaded = browser.next('Page.loadEventFired');
181
+ await browser.send('Emulation.setFocusEmulationEnabled', { enabled: true }, sessionId);
182
+ const loaded = browser.next('Page.loadEventFired', sessionId);
169
183
  const { errorText } = await browser.send('Page.navigate', { url }, sessionId);
170
184
  if (errorText) throw new Error(`Could not open ${url}: ${errorText}`);
171
185
  await loaded;
@@ -185,21 +199,57 @@ const prerender = async (browser, url, isStatic) => {
185
199
 
186
200
  const shadowRootCount = markup => markup.split('shadowrootmode').length - 1;
187
201
 
188
- // Each page is opened in a tab of its own, one after the other, and written as soon as it is
189
- // read. A page that fails stops the run, and the pages before it stay written.
190
- const writePages = async (browser, pages, isStatic) => {
191
- for (const { url, output } of pages) {
192
- const markup = await within(PAGE_LIMIT_MS, `prerendering ${url}`, prerender(browser, url, isStatic));
193
- await mkdir(dirname(output), { recursive: true });
194
- await writeFile(output, markup);
195
- console.log(`${output}: ${markup.length} characters, ${shadowRootCount(markup)} shadow roots`);
196
- }
202
+ const writePage = async (browser, { url, output }, isStatic) => {
203
+ const markup = await within(PAGE_LIMIT_MS, `prerendering ${url}`, prerender(browser, url, isStatic));
204
+ await mkdir(dirname(output), { recursive: true });
205
+ await writeFile(output, markup);
206
+ console.log(`${output}: ${markup.length} characters, ${shadowRootCount(markup)} shadow roots`);
207
+ };
208
+
209
+ // The error of a run in which the pages of `failures` failed: the first, and how many more.
210
+ const failed = failures =>
211
+ failures.length === 1
212
+ ? failures[0]
213
+ : new Error(`${failures[0].message}\n${failures.length - 1} more of the pages that were open failed too.`);
214
+
215
+ // Each page is opened in a tab of its own, and written as soon as it is read. `tabs` pages are
216
+ // open at once: each tab takes the next page of the list when it is done with one, so the pages
217
+ // are written in the order in which they are done. A page that fails stops the run: no tab
218
+ // takes another page, the pages that are open are written, and the run ends with the first
219
+ // error, and says how many more failed.
220
+ const writePages = async (browser, pages, isStatic, tabs) => {
221
+ let next = 0;
222
+ const failures = [];
223
+ const work = async () => {
224
+ while (failures.length === 0 && next < pages.length) {
225
+ const page = pages[next];
226
+ next += 1;
227
+ try {
228
+ await writePage(browser, page, isStatic);
229
+ } catch (error) {
230
+ failures.push(error);
231
+ }
232
+ }
233
+ };
234
+ await Promise.all(Array.from({ length: Math.min(tabs, pages.length) }, work));
235
+ if (failures.length > 0) throw failed(failures);
197
236
  };
198
237
 
199
238
  const STATIC_FLAG = '--static';
239
+ const TABS_FLAG = '--tabs';
200
240
 
201
241
  // The script is run by its file, or as the command of the package. It names itself as it was run.
202
- const USAGE = `Usage: ${basename(process.argv[1] ?? 'prerender.mjs')} [--static] <url> <output.html> [<url> <output.html> ...]`;
242
+ const USAGE = `Usage: ${basename(process.argv[1] ?? 'prerender.mjs')} [--static] [--tabs <n>] <url> <output.html> [<url> <output.html> ...]`;
243
+
244
+ // The flags, and the arguments that are left: `--static`, and `--tabs` with the number that
245
+ // follows it.
246
+ const optionsOf = args => {
247
+ const at = args.indexOf(TABS_FLAG);
248
+ const tabs = at === -1 ? TABS : Number(args[at + 1]);
249
+ if (!Number.isInteger(tabs) || tabs < 1) throw new Error(`${TABS_FLAG} takes a whole number of 1 or more.\n${USAGE}`);
250
+ const rest = at === -1 ? args : [...args.slice(0, at), ...args.slice(at + 2)];
251
+ return { isStatic: rest.includes(STATIC_FLAG), tabs, rest: rest.filter(arg => arg !== STATIC_FLAG) };
252
+ };
203
253
 
204
254
  // The arguments after the flag are pairs: a url, and the file it is written to.
205
255
  const pagesOf = args => {
@@ -208,8 +258,8 @@ const pagesOf = args => {
208
258
  };
209
259
 
210
260
  const main = async args => {
211
- const isStatic = args.includes(STATIC_FLAG);
212
- const pages = pagesOf(args.filter(arg => arg !== STATIC_FLAG));
261
+ const { isStatic, tabs, rest } = optionsOf(args);
262
+ const pages = pagesOf(rest);
213
263
  const chromePath = findChrome();
214
264
  if (!chromePath) throw new Error('Chrome was not found. Set CHROME_PATH.');
215
265
  const profileDir = await mkdtemp(join(tmpdir(), 'prerender-'));
@@ -217,7 +267,7 @@ const main = async args => {
217
267
  try {
218
268
  const browser = await connect(await chromeAddress(chrome));
219
269
  try {
220
- await writePages(browser, pages, isStatic);
270
+ await writePages(browser, pages, isStatic, tabs);
221
271
  } finally {
222
272
  browser.close();
223
273
  }