Skip to content

Commit

Permalink
format & bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
martrapp committed Feb 26, 2024
1 parent fa0d919 commit 32d5cce
Show file tree
Hide file tree
Showing 7 changed files with 680 additions and 159 deletions.
4 changes: 2 additions & 2 deletions animations/animation-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Kebab<T extends string, A extends string = ''> = T extends `${infer F}${inf
: A;
type KebabKeys<T> = { [K in keyof T as K extends string ? Kebab<K> : K]: T[K] };
type AnimationCSS = KebabKeys<Partial<CSSStyleDeclaration>>;
export type NamedAnimationPairs = Record<string, { new?: AnimationCSS; old?: AnimationCSS; }>;
export type NamedAnimationPairs = Record<string, { new?: AnimationCSS; old?: AnimationCSS }>;
export type ScopeAndStyles = {
scope: string;
styles: string;
Expand Down Expand Up @@ -117,6 +117,6 @@ const framesMap: Record<string, string> = {};
export const setKeyframes = (name: string, css: string) => (framesMap[name] = css);
export const getKeyframes = (name: string) => framesMap[name];

const stylesMap: Record<string,string> = {};
const stylesMap: Record<string, string> = {};
export const setStyles = (name: string, css: string) => (stylesMap[name] = css);
export const getStyles = (name: string) => stylesMap[name];
6 changes: 2 additions & 4 deletions components/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const decodeDiv = document.createElement('div');

export const ILLEGAL_TRANSITION_NAMES = "data-vtbot-illegal-transition-names"
export const ILLEGAL_TRANSITION_NAMES = 'data-vtbot-illegal-transition-names';
export function astroContextIds() {
const inStyleSheets = new Set<string>();
const inElements = new Set<string>();
Expand Down Expand Up @@ -38,7 +38,6 @@ export function astroContextIds() {
return { inStyleSheets, inElements };
}


type SupportedCSSProperties = 'view-transition-name';
// finds all elements of a _the current document_ with a given _string_ property in a style sheet
// document.styleSheets does not seem to work for arbitrary documents
Expand All @@ -54,7 +53,7 @@ export function elementsWithPropertyinStylesheet(
try {
[...sheet.cssRules].forEach((rule) => {
if (rule instanceof CSSStyleRule && rule.style[property as keyof CSSStyleDeclaration]) {
const name = rule.style[property as keyof CSSStyleDeclaration] as string;
const name = rule.style[property as keyof CSSStyleDeclaration] as string;
definedNames.delete(name);
const els = document.querySelectorAll(rule.selectorText);
map.set(name, new Set([...(map.get(name) ?? new Set()), ...[...els]]));
Expand Down Expand Up @@ -92,7 +91,6 @@ export function elementsWithPropertyInStyleAttribute(
return map;
}


// finds all elements _of the current document_ with a given property
// in their style attribute or in a style sheet
export function elementsWithStyleProperty(
Expand Down
8 changes: 7 additions & 1 deletion components/loading-indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export function initialize(onPageLoad?: () => void | Promise<void>, lowPrio = fa
document.addEventListener(TRANSITION_BEFORE_SWAP, doHide);
}

type Options = { src: string|undefined; top: string|undefined; bottom: string|undefined; left: string|undefined; right: string|undefined };
type Options = {
src: string | undefined;
top: string | undefined;
bottom: string | undefined;
left: string | undefined;
right: string | undefined;
};

export async function vtbotLoadingIndicator(options: Options) {
const loadingIndicator = document.getElementById('vtbot-loading-indicator');
Expand Down
17 changes: 10 additions & 7 deletions components/swap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ export const disarmKnownScripts = (doc: Document) => {
* Swap in the atttributes of the html element
*/
export const swapInHTMLAttributes = (doc: Document, rootAttributesToPreserve: string[]) => {
const preserve = (name: string) => name.startsWith('data-astro-') || rootAttributesToPreserve.includes(name);
const preserve = (name: string) =>
name.startsWith('data-astro-') || rootAttributesToPreserve.includes(name);
const html = document.documentElement;
[...html.attributes].forEach(
({ name }) => preserve(name) || html.removeAttribute(name)
);
[...doc.documentElement.attributes].forEach(({ name, value }) =>
preserve(name) || html.setAttribute(name, value)
[...html.attributes].forEach(({ name }) => preserve(name) || html.removeAttribute(name));
[...doc.documentElement.attributes].forEach(
({ name, value }) => preserve(name) || html.setAttribute(name, value)
);
};

Expand Down Expand Up @@ -76,7 +75,11 @@ export const restoreFocus = ({ activeElement, start, end }: SavedFocus) => {
* Execute all steps of the original swap function except the swap of the body element.
* Accepts a function to substitute the swap of the body element.
*/
export const customSwap = (doc: Document, rootAttributesToPreserve: string[] = [], swapBody: (doc: Document) => void) => {
export const customSwap = (
doc: Document,
rootAttributesToPreserve: string[] = [],
swapBody: (doc: Document) => void
) => {
disarmKnownScripts(doc);
swapInHTMLAttributes(doc, rootAttributesToPreserve);
swapInHeadElements(doc);
Expand Down
2 changes: 1 addition & 1 deletion integration/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {AstroIntegration } from 'astro';
import type { AstroIntegration } from 'astro';
import vitePluginVtbotExtend from './vite-plugin-extend';

type VtBotOptions = {
Expand Down
Loading

0 comments on commit 32d5cce

Please sign in to comment.