astro 4.5.18 → 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 (54) hide show
  1. package/dist/@types/astro.d.ts +96 -3
  2. package/dist/core/app/index.js +8 -0
  3. package/dist/core/app/middlewares.d.ts +7 -0
  4. package/dist/core/app/middlewares.js +26 -0
  5. package/dist/core/app/types.d.ts +2 -1
  6. package/dist/core/base-pipeline.js +6 -3
  7. package/dist/core/build/generate.js +3 -2
  8. package/dist/core/build/plugins/plugin-manifest.js +3 -2
  9. package/dist/core/config/schema.d.ts +168 -65
  10. package/dist/core/config/schema.js +20 -13
  11. package/dist/core/constants.js +1 -1
  12. package/dist/core/cookies/cookies.d.ts +3 -11
  13. package/dist/core/cookies/cookies.js +9 -7
  14. package/dist/core/dev/dev.js +1 -1
  15. package/dist/core/errors/dev/utils.js +1 -1
  16. package/dist/core/errors/errors-data.d.ts +23 -0
  17. package/dist/core/errors/errors-data.js +13 -1
  18. package/dist/core/errors/overlay.js +2 -1
  19. package/dist/core/messages.js +2 -2
  20. package/dist/core/middleware/vite-plugin.js +8 -0
  21. package/dist/core/render/index.d.ts +1 -1
  22. package/dist/core/render/index.js +1 -1
  23. package/dist/core/render/{result.js → slots.js} +4 -2
  24. package/dist/core/routing/manifest/create.js +1 -1
  25. package/dist/i18n/index.d.ts +18 -1
  26. package/dist/i18n/index.js +107 -0
  27. package/dist/i18n/middleware.d.ts +1 -1
  28. package/dist/i18n/middleware.js +40 -81
  29. package/dist/i18n/utils.d.ts +2 -2
  30. package/dist/i18n/utils.js +20 -21
  31. package/dist/runtime/client/dev-toolbar/apps/astro.js +6 -1
  32. package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +1 -1
  33. package/dist/runtime/client/dev-toolbar/apps/settings.js +38 -1
  34. package/dist/runtime/client/dev-toolbar/apps/utils/window.d.ts +2 -1
  35. package/dist/runtime/client/dev-toolbar/apps/utils/window.js +18 -2
  36. package/dist/runtime/client/dev-toolbar/apps/xray.js +6 -1
  37. package/dist/runtime/client/dev-toolbar/entrypoint.js +3 -1
  38. package/dist/runtime/client/dev-toolbar/settings.d.ts +4 -1
  39. package/dist/runtime/client/dev-toolbar/settings.js +2 -1
  40. package/dist/runtime/client/dev-toolbar/toolbar.d.ts +2 -0
  41. package/dist/runtime/client/dev-toolbar/toolbar.js +25 -3
  42. package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
  43. package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
  44. package/dist/runtime/client/dev-toolbar/ui-library/select.d.ts +15 -0
  45. package/dist/runtime/client/dev-toolbar/ui-library/select.js +100 -0
  46. package/dist/runtime/client/dev-toolbar/ui-library/window.d.ts +9 -0
  47. package/dist/runtime/client/dev-toolbar/ui-library/window.js +53 -3
  48. package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
  49. package/dist/virtual-modules/i18n.d.ts +102 -0
  50. package/dist/virtual-modules/i18n.js +86 -6
  51. package/dist/vite-plugin-astro-server/plugin.js +2 -1
  52. package/dist/vite-plugin-astro-server/route.js +1 -1
  53. package/package.json +6 -5
  54. /package/dist/core/render/{result.d.ts → slots.d.ts} +0 -0
@@ -1,5 +1,10 @@
1
1
  import { settings } from "../settings.js";
2
- import { closeOnOutsideClick, createWindowElement } from "./utils/window.js";
2
+ import { isValidPlacement, placements } from "../ui-library/window.js";
3
+ import {
4
+ closeOnOutsideClick,
5
+ createWindowElement,
6
+ synchronizePlacementOnUpdate
7
+ } from "./utils/window.js";
3
8
  const settingsRows = [
4
9
  {
5
10
  name: "Disable notifications",
@@ -30,6 +35,22 @@ const settingsRows = [
30
35
  settings.logger.verboseLog(`Verbose logging ${action}`);
31
36
  }
32
37
  }
38
+ },
39
+ {
40
+ name: "Placement",
41
+ description: "Adjust the placement of the dev toolbar.",
42
+ input: "select",
43
+ settingKey: "placement",
44
+ changeEvent: (evt) => {
45
+ if (evt.currentTarget instanceof HTMLSelectElement) {
46
+ const placement = evt.currentTarget.value;
47
+ if (isValidPlacement(placement)) {
48
+ document.querySelector("astro-dev-toolbar")?.setToolbarPlacement(placement);
49
+ settings.updateSetting("placement", placement);
50
+ settings.logger.verboseLog(`Placement set to ${placement}`);
51
+ }
52
+ }
53
+ }
33
54
  }
34
55
  ];
35
56
  var settings_default = {
@@ -40,6 +61,7 @@ var settings_default = {
40
61
  createSettingsWindow();
41
62
  document.addEventListener("astro:after-swap", createSettingsWindow);
42
63
  closeOnOutsideClick(eventTarget);
64
+ synchronizePlacementOnUpdate(eventTarget, canvas);
43
65
  function createSettingsWindow() {
44
66
  const windowElement = createWindowElement(
45
67
  `<style>
@@ -147,6 +169,21 @@ var settings_default = {
147
169
  label.append(astroToggle);
148
170
  break;
149
171
  }
172
+ case "select": {
173
+ const astroSelect = document.createElement("astro-dev-toolbar-select");
174
+ placements.forEach((placement) => {
175
+ const option = document.createElement("option");
176
+ option.setAttribute("value", placement);
177
+ if (placement === settings.config[setting.settingKey]) {
178
+ option.selected = true;
179
+ }
180
+ option.textContent = `${placement.slice(0, 1).toUpperCase()}${placement.slice(1)}`.replace("-", " ");
181
+ astroSelect.append(option);
182
+ });
183
+ astroSelect.element.addEventListener("change", setting.changeEvent);
184
+ label.append(astroSelect);
185
+ break;
186
+ }
150
187
  default:
151
188
  break;
152
189
  }
@@ -1,2 +1,3 @@
1
- export declare function createWindowElement(content: string): import("../../ui-library/window.js").DevToolbarWindow;
1
+ export declare function createWindowElement(content: string, placement?: "bottom-left" | "bottom-center" | "bottom-right"): import("../../ui-library/window.js").DevToolbarWindow;
2
2
  export declare function closeOnOutsideClick(eventTarget: EventTarget, additionalCheck?: (target: Element) => boolean): void;
3
+ export declare function synchronizePlacementOnUpdate(eventTarget: EventTarget, canvas: ShadowRoot): void;
@@ -1,6 +1,8 @@
1
- function createWindowElement(content) {
1
+ import { settings } from "../../settings.js";
2
+ function createWindowElement(content, placement = settings.config.placement) {
2
3
  const windowElement = document.createElement("astro-dev-toolbar-window");
3
4
  windowElement.innerHTML = content;
5
+ windowElement.placement = placement;
4
6
  return windowElement;
5
7
  }
6
8
  function closeOnOutsideClick(eventTarget, additionalCheck) {
@@ -30,7 +32,21 @@ function closeOnOutsideClick(eventTarget, additionalCheck) {
30
32
  }
31
33
  });
32
34
  }
35
+ function synchronizePlacementOnUpdate(eventTarget, canvas) {
36
+ eventTarget.addEventListener("placement-updated", (evt) => {
37
+ if (!(evt instanceof CustomEvent)) {
38
+ return;
39
+ }
40
+ const windowElement = canvas.querySelector("astro-dev-toolbar-window");
41
+ if (!windowElement) {
42
+ return;
43
+ }
44
+ const event = evt;
45
+ windowElement.placement = event.detail.placement;
46
+ });
47
+ }
33
48
  export {
34
49
  closeOnOutsideClick,
35
- createWindowElement
50
+ createWindowElement,
51
+ synchronizePlacementOnUpdate
36
52
  };
@@ -5,7 +5,11 @@ import {
5
5
  getElementsPositionInDocument,
6
6
  positionHighlight
7
7
  } from "./utils/highlight.js";
8
- import { closeOnOutsideClick, createWindowElement } from "./utils/window.js";
8
+ import {
9
+ closeOnOutsideClick,
10
+ createWindowElement,
11
+ synchronizePlacementOnUpdate
12
+ } from "./utils/window.js";
9
13
  const icon = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><path fill="#fff" d="M7.9 1.5v-.4a1.1 1.1 0 0 1 2.2 0v.4a1.1 1.1 0 1 1-2.2 0Zm-6.4 8.6a1.1 1.1 0 1 0 0-2.2h-.4a1.1 1.1 0 0 0 0 2.2h.4ZM12 3.7a1.1 1.1 0 0 0 1.4-.7l.4-1.1a1.1 1.1 0 0 0-2.1-.8l-.4 1.2a1.1 1.1 0 0 0 .7 1.4Zm-9.7 7.6-1.2.4a1.1 1.1 0 1 0 .8 2.1l1-.4a1.1 1.1 0 1 0-.6-2ZM20.8 17a1.9 1.9 0 0 1 0 2.6l-1.2 1.2a1.9 1.9 0 0 1-2.6 0l-4.3-4.2-1.6 3.6a1.9 1.9 0 0 1-1.7 1.2A1.9 1.9 0 0 1 7.5 20L2.7 5a1.9 1.9 0 0 1 2.4-2.4l15 5a1.9 1.9 0 0 1 .2 3.4l-3.7 1.6 4.2 4.3ZM19 18.3 14.6 14a1.9 1.9 0 0 1 .6-3l3.2-1.5L5.1 5.1l4.3 13.3 1.5-3.2a1.9 1.9 0 0 1 3-.6l4.4 4.4.7-.7Z"/></svg>';
10
14
  var xray_default = {
11
15
  id: "astro:xray",
@@ -17,6 +21,7 @@ var xray_default = {
17
21
  document.addEventListener("astro:after-swap", addIslandsOverlay);
18
22
  document.addEventListener("astro:page-load", refreshIslandsOverlayPositions);
19
23
  closeOnOutsideClick(eventTarget);
24
+ synchronizePlacementOnUpdate(eventTarget, canvas);
20
25
  function addIslandsOverlay() {
21
26
  islandsOverlays.forEach(({ highlightElement }) => {
22
27
  highlightElement.remove();
@@ -17,7 +17,8 @@ document.addEventListener("DOMContentLoaded", async () => {
17
17
  DevToolbarToggle,
18
18
  DevToolbarButton,
19
19
  DevToolbarBadge,
20
- DevToolbarIcon
20
+ DevToolbarIcon,
21
+ DevToolbarSelect
21
22
  }
22
23
  ] = await Promise.all([
23
24
  loadDevToolbarApps(),
@@ -38,6 +39,7 @@ document.addEventListener("DOMContentLoaded", async () => {
38
39
  customElements.define("astro-dev-toolbar-button", DevToolbarButton);
39
40
  customElements.define("astro-dev-toolbar-badge", DevToolbarBadge);
40
41
  customElements.define("astro-dev-toolbar-icon", DevToolbarIcon);
42
+ customElements.define("astro-dev-toolbar-select", DevToolbarSelect);
41
43
  const deprecated = (Parent) => class extends Parent {
42
44
  };
43
45
  customElements.define("astro-dev-overlay", deprecated(AstroDevToolbar));
@@ -1,14 +1,17 @@
1
+ import type { Placement } from './ui-library/window.js';
1
2
  export interface Settings {
2
3
  disableAppNotification: boolean;
3
4
  verbose: boolean;
5
+ placement: Placement;
4
6
  }
5
7
  export declare const defaultSettings: {
6
8
  disableAppNotification: false;
7
9
  verbose: false;
10
+ placement: "bottom-center";
8
11
  };
9
12
  export declare const settings: {
10
13
  readonly config: Settings;
11
- updateSetting: (key: keyof Settings, value: boolean) => void;
14
+ updateSetting: <Key extends keyof Settings>(key: Key, value: Settings[Key]) => void;
12
15
  logger: {
13
16
  log: (message: string, level?: 'log' | 'warn' | 'error') => void;
14
17
  warn: (message: string) => void;
@@ -1,6 +1,7 @@
1
1
  const defaultSettings = {
2
2
  disableAppNotification: false,
3
- verbose: false
3
+ verbose: false,
4
+ placement: "bottom-center"
4
5
  };
5
6
  const settings = getSettings();
6
7
  function getSettings() {
@@ -1,5 +1,6 @@
1
1
  import type { DevToolbarApp as DevToolbarAppDefinition } from '../../../@types/astro.js';
2
2
  import { type Icon } from './ui-library/icons.js';
3
+ import { type Placement } from './ui-library/window.js';
3
4
  export type DevToolbarApp = DevToolbarAppDefinition & {
4
5
  builtIn: boolean;
5
6
  active: boolean;
@@ -38,6 +39,7 @@ export declare class AstroDevToolbar extends HTMLElement {
38
39
  triggerDelayedHide(): void;
39
40
  setToolbarVisible(newStatus: boolean): void;
40
41
  setNotificationVisible(newStatus: boolean): void;
42
+ setToolbarPlacement(newPlacement: Placement): void;
41
43
  }
42
44
  export declare class DevToolbarCanvas extends HTMLElement {
43
45
  shadowRoot: ShadowRoot;
@@ -1,5 +1,6 @@
1
1
  import { settings } from "./settings.js";
2
2
  import { getIconElement, isDefinedIcon } from "./ui-library/icons.js";
3
+ import {} from "./ui-library/window.js";
3
4
  const WS_EVENT_NAME = "astro-dev-toolbar";
4
5
  const WS_EVENT_NAME_DEPRECATED = "astro-dev-overlay";
5
6
  const HOVER_DELAY = 2 * 1e3;
@@ -39,8 +40,6 @@ class AstroDevToolbar extends HTMLElement {
39
40
  #dev-toolbar-root {
40
41
  position: fixed;
41
42
  bottom: 0px;
42
- left: 50%;
43
- transform: translate(-50%, 0%);
44
43
  z-index: 2000000010;
45
44
  display: flex;
46
45
  flex-direction: column;
@@ -57,6 +56,17 @@ class AstroDevToolbar extends HTMLElement {
57
56
  opacity: 0.2;
58
57
  }
59
58
 
59
+ #dev-toolbar-root[data-placement="bottom-left"] {
60
+ left: 16px;
61
+ }
62
+ #dev-toolbar-root[data-placement="bottom-center"] {
63
+ left: 50%;
64
+ transform: translateX(-50%);
65
+ }
66
+ #dev-toolbar-root[data-placement="bottom-right"] {
67
+ right: 16px;
68
+ }
69
+
60
70
  #dev-bar-hitbox-above,
61
71
  #dev-bar-hitbox-below {
62
72
  width: 100%;
@@ -228,7 +238,7 @@ class AstroDevToolbar extends HTMLElement {
228
238
  width: 1px;
229
239
  }
230
240
  </style>
231
- <div id="dev-toolbar-root" data-hidden ${settings.config.disableAppNotification ? "data-no-notification" : ""}>
241
+ <div id="dev-toolbar-root" data-hidden ${settings.config.disableAppNotification ? "data-no-notification" : ""} data-placement="${settings.config.placement}">
232
242
  <div id="dev-bar-hitbox-above"></div>
233
243
  <div id="dev-bar">
234
244
  <div id="bar-container">
@@ -479,6 +489,18 @@ class AstroDevToolbar extends HTMLElement {
479
489
  const moreCanvas = this.getAppCanvasById("astro:more");
480
490
  moreCanvas?.shadowRoot?.querySelector("#dropdown")?.toggleAttribute("data-no-notification", !newStatus);
481
491
  }
492
+ setToolbarPlacement(newPlacement) {
493
+ this.devToolbarContainer?.setAttribute("data-placement", newPlacement);
494
+ this.apps.forEach((app) => {
495
+ app.eventTarget.dispatchEvent(
496
+ new CustomEvent("placement-updated", {
497
+ detail: {
498
+ placement: newPlacement
499
+ }
500
+ })
501
+ );
502
+ });
503
+ }
482
504
  }
483
505
  class DevToolbarCanvas extends HTMLElement {
484
506
  shadowRoot;
@@ -3,6 +3,7 @@ export { DevToolbarButton } from './button.js';
3
3
  export { DevToolbarCard } from './card.js';
4
4
  export { DevToolbarHighlight } from './highlight.js';
5
5
  export { DevToolbarIcon } from './icon.js';
6
+ export { DevToolbarSelect } from './select.js';
6
7
  export { DevToolbarToggle } from './toggle.js';
7
8
  export { DevToolbarTooltip } from './tooltip.js';
8
9
  export { DevToolbarWindow } from './window.js';
@@ -3,6 +3,7 @@ import { DevToolbarButton } from "./button.js";
3
3
  import { DevToolbarCard } from "./card.js";
4
4
  import { DevToolbarHighlight } from "./highlight.js";
5
5
  import { DevToolbarIcon } from "./icon.js";
6
+ import { DevToolbarSelect } from "./select.js";
6
7
  import { DevToolbarToggle } from "./toggle.js";
7
8
  import { DevToolbarTooltip } from "./tooltip.js";
8
9
  import { DevToolbarWindow } from "./window.js";
@@ -12,6 +13,7 @@ export {
12
13
  DevToolbarCard,
13
14
  DevToolbarHighlight,
14
15
  DevToolbarIcon,
16
+ DevToolbarSelect,
15
17
  DevToolbarToggle,
16
18
  DevToolbarTooltip,
17
19
  DevToolbarWindow
@@ -0,0 +1,15 @@
1
+ declare const styles: readonly ["purple", "gray", "red", "green", "yellow", "blue"];
2
+ type SelectStyle = (typeof styles)[number];
3
+ export declare class DevToolbarSelect extends HTMLElement {
4
+ shadowRoot: ShadowRoot;
5
+ element: HTMLSelectElement;
6
+ _selectStyle: SelectStyle;
7
+ get selectStyle(): "red" | "purple" | "gray" | "green" | "yellow" | "blue";
8
+ set selectStyle(value: "red" | "purple" | "gray" | "green" | "yellow" | "blue");
9
+ static observedAttributes: string[];
10
+ constructor();
11
+ connectedCallback(): void;
12
+ attributeChangedCallback(): void;
13
+ updateStyle(): void;
14
+ }
15
+ export {};
@@ -0,0 +1,100 @@
1
+ import { settings } from "../settings.js";
2
+ const styles = ["purple", "gray", "red", "green", "yellow", "blue"];
3
+ class DevToolbarSelect extends HTMLElement {
4
+ shadowRoot;
5
+ element;
6
+ _selectStyle = "gray";
7
+ get selectStyle() {
8
+ return this._selectStyle;
9
+ }
10
+ set selectStyle(value) {
11
+ if (!styles.includes(value)) {
12
+ settings.logger.error(`Invalid style: ${value}, expected one of ${styles.join(", ")}.`);
13
+ return;
14
+ }
15
+ this._selectStyle = value;
16
+ this.updateStyle();
17
+ }
18
+ static observedAttributes = ["select-style"];
19
+ constructor() {
20
+ super();
21
+ this.shadowRoot = this.attachShadow({ mode: "open" });
22
+ this.shadowRoot.innerHTML = `
23
+ <style>
24
+ :host {
25
+ --purple-text: rgba(224, 204, 250, 1);
26
+ --purple-border: rgba(113, 24, 226, 1);
27
+
28
+ --gray-text: rgba(191, 193, 201, 1);
29
+ --gray-border:rgba(191, 193, 201, 1);
30
+
31
+ --red-text: rgba(249, 196, 215, 1);
32
+ --red-border: rgba(179, 62, 102, 1);
33
+
34
+ --green-text: rgba(213, 249, 196, 1);
35
+ --green-border: rgba(61, 125, 31, 1);
36
+
37
+ --yellow-text: rgba(249, 233, 196, 1);
38
+ --yellow-border: rgba(181, 138, 45, 1);
39
+
40
+ --blue-text: rgba(189, 195, 255, 1);
41
+ --blue-border: rgba(54, 69, 217, 1);
42
+
43
+ --text-color: var(--gray-text);
44
+ --border-color: var(--gray-border);
45
+ }
46
+ select {
47
+ appearance: none;
48
+ text-align-last: center;
49
+ display: inline-block;
50
+ font-family: system-ui, sans-serif;
51
+ font-size: 14px;
52
+ padding: 4px 24px 4px 8px;
53
+ border: 1px solid var(--border-color);
54
+ border-radius: 4px;
55
+ color: var(--text-color);
56
+ background-color: transparent;
57
+ background-image:
58
+ linear-gradient(45deg, transparent 50%, var(--text-color) 50%),
59
+ linear-gradient(135deg, var(--text-color) 50%, transparent 50%);
60
+ background-position:
61
+ calc(100% - 12px) calc(1em - 2px),
62
+ calc(100% - 8px) calc(1em - 2px);
63
+ background-size: 4px 4px;
64
+ background-repeat: no-repeat;
65
+ }
66
+ </style>
67
+ <style id="selected-style"></style>
68
+ <slot></slot>
69
+ `;
70
+ this.element = document.createElement("select");
71
+ this.shadowRoot.addEventListener("slotchange", (event) => {
72
+ if (event.target instanceof HTMLSlotElement) {
73
+ this.element.append(...event.target.assignedNodes());
74
+ }
75
+ });
76
+ }
77
+ connectedCallback() {
78
+ this.shadowRoot.append(this.element);
79
+ this.updateStyle();
80
+ }
81
+ attributeChangedCallback() {
82
+ if (this.hasAttribute("select-style")) {
83
+ this.selectStyle = this.getAttribute("select-style");
84
+ }
85
+ }
86
+ updateStyle() {
87
+ const style = this.shadowRoot.querySelector("#selected-style");
88
+ if (style) {
89
+ style.innerHTML = `
90
+ :host {
91
+ --text-color: var(--${this.selectStyle}-text);
92
+ --border-color: var(--${this.selectStyle}-border);
93
+ }
94
+ `;
95
+ }
96
+ }
97
+ }
98
+ export {
99
+ DevToolbarSelect
100
+ };
@@ -1,5 +1,14 @@
1
+ export declare const placements: readonly ["bottom-left", "bottom-center", "bottom-right"];
2
+ export type Placement = (typeof placements)[number];
3
+ export declare function isValidPlacement(value: string): value is Placement;
1
4
  export declare class DevToolbarWindow extends HTMLElement {
2
5
  shadowRoot: ShadowRoot;
6
+ _placement: Placement;
7
+ get placement(): "bottom-left" | "bottom-center" | "bottom-right";
8
+ set placement(value: "bottom-left" | "bottom-center" | "bottom-right");
9
+ static observedAttributes: string[];
3
10
  constructor();
4
11
  connectedCallback(): Promise<void>;
12
+ attributeChangedCallback(): void;
13
+ updateStyle(): void;
5
14
  }
@@ -1,5 +1,25 @@
1
+ import { defaultSettings, settings } from "../settings.js";
2
+ const placements = ["bottom-left", "bottom-center", "bottom-right"];
3
+ function isValidPlacement(value) {
4
+ return placements.map(String).includes(value);
5
+ }
1
6
  class DevToolbarWindow extends HTMLElement {
2
7
  shadowRoot;
8
+ _placement = defaultSettings.placement;
9
+ get placement() {
10
+ return this._placement;
11
+ }
12
+ set placement(value) {
13
+ if (!isValidPlacement(value)) {
14
+ settings.logger.error(
15
+ `Invalid placement: ${value}, expected one of ${placements.join(", ")}, got ${value}.`
16
+ );
17
+ return;
18
+ }
19
+ this._placement = value;
20
+ this.updateStyle();
21
+ }
22
+ static observedAttributes = ["placement"];
3
23
  constructor() {
4
24
  super();
5
25
  this.shadowRoot = this.attachShadow({ mode: "open" });
@@ -22,8 +42,6 @@ class DevToolbarWindow extends HTMLElement {
22
42
  position: fixed;
23
43
  z-index: 999999999;
24
44
  bottom: 72px;
25
- left: 50%;
26
- transform: translateX(-50%);
27
45
  box-shadow: 0px 0px 0px 0px rgba(19, 21, 26, 0.30), 0px 1px 2px 0px rgba(19, 21, 26, 0.29), 0px 4px 4px 0px rgba(19, 21, 26, 0.26), 0px 10px 6px 0px rgba(19, 21, 26, 0.15), 0px 17px 7px 0px rgba(19, 21, 26, 0.04), 0px 26px 7px 0px rgba(19, 21, 26, 0.01);
28
46
  }
29
47
 
@@ -73,11 +91,43 @@ class DevToolbarWindow extends HTMLElement {
73
91
  line-height: 1.5em;
74
92
  }
75
93
  </style>
94
+ <style id="selected-style"></style>
76
95
 
77
96
  <slot />
78
97
  `;
98
+ this.updateStyle();
99
+ }
100
+ attributeChangedCallback() {
101
+ if (this.hasAttribute("placement"))
102
+ this.placement = this.getAttribute("placement");
103
+ }
104
+ updateStyle() {
105
+ const style = this.shadowRoot.querySelector("#selected-style");
106
+ if (style) {
107
+ const styleMap = {
108
+ "bottom-left": `
109
+ :host {
110
+ left: 16px;
111
+ }
112
+ `,
113
+ "bottom-center": `
114
+ :host {
115
+ left: 50%;
116
+ transform: translateX(-50%);
117
+ }
118
+ `,
119
+ "bottom-right": `
120
+ :host {
121
+ right: 16px;
122
+ }
123
+ `
124
+ };
125
+ style.innerHTML = styleMap[this.placement];
126
+ }
79
127
  }
80
128
  }
81
129
  export {
82
- DevToolbarWindow
130
+ DevToolbarWindow,
131
+ isValidPlacement,
132
+ placements
83
133
  };
@@ -3,7 +3,7 @@ declare const renderTemplateResultSym: unique symbol;
3
3
  export declare class RenderTemplateResult {
4
4
  [renderTemplateResultSym]: boolean;
5
5
  private htmlParts;
6
- private expressions;
6
+ expressions: any[];
7
7
  private error;
8
8
  constructor(htmlParts: TemplateStringsArray, expressions: unknown[]);
9
9
  render(destination: RenderDestination): Promise<void>;
@@ -1,4 +1,6 @@
1
+ import type { APIContext, AstroConfig, MiddlewareHandler, ValidRedirectStatus } from '../@types/astro.js';
1
2
  import * as I18nInternals from '../i18n/index.js';
3
+ import type { RedirectToFallback } from '../i18n/index.js';
2
4
  export { normalizeTheLocale, toCodes, toPaths } from '../i18n/index.js';
3
5
  export type GetLocaleOptions = I18nInternals.GetLocaleOptions;
4
6
  /**
@@ -124,3 +126,103 @@ export declare const getPathByLocale: (locale: string) => string;
124
126
  * ```
125
127
  */
126
128
  export declare const getLocaleByPath: (path: string) => string;
129
+ /**
130
+ * A function that can be used to check if the current path contains a configured locale.
131
+ *
132
+ * @param path The path that maps to a locale
133
+ * @returns Whether the `path` has the locale
134
+ *
135
+ * ## Example
136
+ *
137
+ * Given the following configuration:
138
+ *
139
+ * ```js
140
+ * // astro.config.mjs
141
+ *
142
+ * export default defineConfig({
143
+ * i18n: {
144
+ * locales: [
145
+ * { codes: ["it-VT", "it"], path: "italiano" },
146
+ * "es"
147
+ * ]
148
+ * }
149
+ * })
150
+ * ```
151
+ *
152
+ * Here's some use cases:
153
+ *
154
+ * ```js
155
+ * import { pathHasLocale } from "astro:i18n";
156
+ * getLocaleByPath("italiano"); // returns `true`
157
+ * getLocaleByPath("es"); // returns `true`
158
+ * getLocaleByPath("it-VT"); // returns `false`
159
+ * ```
160
+ */
161
+ export declare const pathHasLocale: (path: string) => boolean;
162
+ /**
163
+ *
164
+ * This function returns a redirect to the default locale configured in the
165
+ *
166
+ * @param {APIContext} context The context passed to the middleware
167
+ * @param {ValidRedirectStatus?} statusCode An optional status code for the redirect.
168
+ */
169
+ export declare let redirectToDefaultLocale: (context: APIContext, statusCode?: ValidRedirectStatus) => Response | undefined;
170
+ /**
171
+ *
172
+ * Use this function to return a 404 when:
173
+ * - the current path isn't a root. e.g. / or /<base>
174
+ * - the URL doesn't contain a locale
175
+ *
176
+ * When a `Response` is passed, the new `Response` emitted by this function will contain the same headers of the original response.
177
+ *
178
+ * @param {APIContext} context The context passed to the middleware
179
+ * @param {Response?} response An optional `Response` in case you're handling a `Response` coming from the `next` function.
180
+ *
181
+ */
182
+ export declare let notFound: (context: APIContext, response?: Response) => Response | undefined;
183
+ /**
184
+ * Checks whether the current URL contains a configured locale. Internally, this function will use `APIContext#url.pathname`
185
+ *
186
+ * @param {APIContext} context The context passed to the middleware
187
+ */
188
+ export declare let requestHasLocale: (context: APIContext) => boolean;
189
+ /**
190
+ * Allows to use the build-in fallback system of Astro
191
+ *
192
+ * @param {APIContext} context The context passed to the middleware
193
+ * @param {Response} response An optional `Response` in case you're handling a `Response` coming from the `next` function.
194
+ */
195
+ export declare let redirectToFallback: RedirectToFallback;
196
+ type OnlyObject<T> = T extends object ? T : never;
197
+ type NewAstroRoutingConfigWithoutManual = OnlyObject<NonNullable<AstroConfig['i18n']>['routing']>;
198
+ /**
199
+ * @param {AstroConfig['i18n']['routing']} customOptions
200
+ *
201
+ * A function that allows to programmatically create the Astro i18n middleware.
202
+ *
203
+ * This is use useful when you still want to use the default i18n logic, but add only few exceptions to your website.
204
+ *
205
+ * ## Examples
206
+ *
207
+ * ```js
208
+ * // middleware.js
209
+ * import { middleware } from "astro:i18n";
210
+ * import { sequence, defineMiddleware } from "astro:middleware";
211
+ *
212
+ * const customLogic = defineMiddleware(async (context, next) => {
213
+ * const response = await next();
214
+ *
215
+ * // Custom logic after resolving the response.
216
+ * // It's possible to catch the response coming from Astro i18n middleware.
217
+ *
218
+ * return response;
219
+ * });
220
+ *
221
+ * export const onRequest = sequence(customLogic, middleware({
222
+ * prefixDefaultLocale: true,
223
+ * redirectToDefaultLocale: false
224
+ * }))
225
+ *
226
+ * ```
227
+ */
228
+ export declare let middleware: (customOptions: NewAstroRoutingConfigWithoutManual) => MiddlewareHandler;