Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
gertvdb committed Jun 29, 2024
1 parent a99ac8d commit 4c2a301
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 59 deletions.
8 changes: 8 additions & 0 deletions build/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

var e=class{constructor(r,s,o,t,c){this.prefersReducedMotion=r,this.prefersContrast=s,this.prefersReducedTransparency=o,this.prefersColorSchema=t,this.invertedColors=c;}prefersDarkMode(){return this.prefersColorSchema==="dark"}prefersHighContrast(){return this.prefersContrast==="more"}prefersLowContrast(){return this.prefersContrast==="less"}},a=()=>{let n=matchMedia("(prefers-reduced-motion: reduce)").matches?"reduce":"no-preference",r=matchMedia("(prefers-contrast: more)").matches?"more":matchMedia("(prefers-contrast: less)").matches?"less":matchMedia("(prefers-contrast: custom)").matches?"custom":"no-preference",s=matchMedia("(prefers-reduced-transparency: reduce)").matches?"reduce":"no-preference",o=matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",t=matchMedia("(inverted-colors: inverted)").matches?"inverted":"none";return new e(n,r,s,o,t)};

exports.BrowserAccessibilityPreferences = e;
exports.useBrowserAccessibilityPreferences = a;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9hY2Nlc3NpYmlsaXR5L3ByZWZlcmVuY2VzLnRzIl0sIm5hbWVzIjpbIkJyb3dzZXJBY2Nlc3NpYmlsaXR5UHJlZmVyZW5jZXMiLCJwcmVmZXJzUmVkdWNlZE1vdGlvbiIsInByZWZlcnNDb250cmFzdCIsInByZWZlcnNSZWR1Y2VkVHJhbnNwYXJlbmN5IiwicHJlZmVyc0NvbG9yU2NoZW1hIiwiaW52ZXJ0ZWRDb2xvcnMiLCJ1c2VCcm93c2VyQWNjZXNzaWJpbGl0eVByZWZlcmVuY2VzIiwicmVkdWNlZE1vdGlvbiJdLCJt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xcbiAgICApO1xuICB9O1xuXG5leHBvcnQgeyB1c2VCcm93c2VyQWNjZXNzaWJpbGl0eVByZWZlcmVuY2VzIH07XG4iXX0=
19 changes: 19 additions & 0 deletions build/index.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type prefersReducedMotion = "no-preference" | "reduce";
type prefersContrast = "no-preference" | "more" | "less" | "custom";
type prefersReducedTransparency = "no-preference" | "reduce";
type prefersColorSchema = "light" | "dark";
type invertedColors = "none" | "inverted";
declare class BrowserAccessibilityPreferences {
readonly prefersReducedMotion: prefersReducedMotion;
readonly prefersContrast: prefersContrast;
readonly prefersReducedTransparency: prefersReducedTransparency;
readonly prefersColorSchema: prefersColorSchema;
readonly invertedColors: invertedColors;
constructor(prefersReducedMotion: prefersReducedMotion, prefersContrast: prefersContrast, prefersReducedTransparency: prefersReducedTransparency, prefersColorSchema: prefersColorSchema, invertedColors: invertedColors);
prefersDarkMode(): boolean;
prefersHighContrast(): boolean;
prefersLowContrast(): boolean;
}
declare const useBrowserAccessibilityPreferences: () => BrowserAccessibilityPreferences;

export { BrowserAccessibilityPreferences, type invertedColors, type prefersColorSchema, type prefersContrast, type prefersReducedMotion, type prefersReducedTransparency, useBrowserAccessibilityPreferences };
19 changes: 19 additions & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
type prefersReducedMotion = "no-preference" | "reduce";
type prefersContrast = "no-preference" | "more" | "less" | "custom";
type prefersReducedTransparency = "no-preference" | "reduce";
type prefersColorSchema = "light" | "dark";
type invertedColors = "none" | "inverted";
declare class BrowserAccessibilityPreferences {
readonly prefersReducedMotion: prefersReducedMotion;
readonly prefersContrast: prefersContrast;
readonly prefersReducedTransparency: prefersReducedTransparency;
readonly prefersColorSchema: prefersColorSchema;
readonly invertedColors: invertedColors;
constructor(prefersReducedMotion: prefersReducedMotion, prefersContrast: prefersContrast, prefersReducedTransparency: prefersReducedTransparency, prefersColorSchema: prefersColorSchema, invertedColors: invertedColors);
prefersDarkMode(): boolean;
prefersHighContrast(): boolean;
prefersLowContrast(): boolean;
}
declare const useBrowserAccessibilityPreferences: () => BrowserAccessibilityPreferences;

export { BrowserAccessibilityPreferences, type invertedColors, type prefersColorSchema, type prefersContrast, type prefersReducedMotion, type prefersReducedTransparency, useBrowserAccessibilityPreferences };
5 changes: 5 additions & 0 deletions build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 59 additions & 58 deletions src/accessibility/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,75 @@ export type prefersColorSchema = "light" | "dark";
export type invertedColors = "none" | "inverted";

export class BrowserAccessibilityPreferences {
readonly prefersReducedMotion: prefersReducedMotion;
readonly prefersContrast: prefersContrast;
readonly prefersReducedTransparency: prefersReducedTransparency;
readonly prefersColorSchema: prefersColorSchema;
readonly invertedColors: invertedColors;
readonly prefersReducedMotion: prefersReducedMotion;
readonly prefersContrast: prefersContrast;
readonly prefersReducedTransparency: prefersReducedTransparency;
readonly prefersColorSchema: prefersColorSchema;
readonly invertedColors: invertedColors;

constructor(
prefersReducedMotion: prefersReducedMotion,
prefersContrast: prefersContrast,
prefersReducedTransparency: prefersReducedTransparency,
prefersColorSchema: prefersColorSchema,
invertedColors: invertedColors,
) {
this.prefersReducedMotion = prefersReducedMotion;
this.prefersContrast = prefersContrast;
this.prefersReducedTransparency = prefersReducedTransparency;
this.prefersColorSchema = prefersColorSchema;
this.invertedColors = invertedColors;
}
constructor(
prefersReducedMotion: prefersReducedMotion,
prefersContrast: prefersContrast,
prefersReducedTransparency: prefersReducedTransparency,
prefersColorSchema: prefersColorSchema,
invertedColors: invertedColors,
) {
this.prefersReducedMotion = prefersReducedMotion;
this.prefersContrast = prefersContrast;
this.prefersReducedTransparency = prefersReducedTransparency;
this.prefersColorSchema = prefersColorSchema;
this.invertedColors = invertedColors;
}

prefersDarkMode(): boolean {
return this.prefersColorSchema === "dark";
}
prefersDarkMode(): boolean {
return this.prefersColorSchema === "dark";
}

prefersHighContrast(): boolean {
return this.prefersContrast === "more";
}
prefersHighContrast(): boolean {
return this.prefersContrast === "more";
}

prefersLowContrast(): boolean {
return this.prefersContrast === "less";
}
prefersLowContrast(): boolean {
return this.prefersContrast === "less";
}
}

const useBrowserAccessibilityPreferences = (): BrowserAccessibilityPreferences => {
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches
? "reduce"
: "no-preference";
const useBrowserAccessibilityPreferences =
(): BrowserAccessibilityPreferences => {
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches
? "reduce"
: "no-preference";

const prefersContrast = matchMedia("(prefers-contrast: more)").matches
? "more"
: matchMedia("(prefers-contrast: less)").matches
? "less"
: matchMedia("(prefers-contrast: custom)").matches
? "custom"
: "no-preference";
const prefersContrast = matchMedia("(prefers-contrast: more)").matches
? "more"
: matchMedia("(prefers-contrast: less)").matches
? "less"
: matchMedia("(prefers-contrast: custom)").matches
? "custom"
: "no-preference";

const prefersReducedTransparency = matchMedia(
"(prefers-reduced-transparency: reduce)",
).matches
? "reduce"
: "no-preference";
const prefersReducedTransparency = matchMedia(
"(prefers-reduced-transparency: reduce)",
).matches
? "reduce"
: "no-preference";

const prefersColorSchema = matchMedia("(prefers-color-scheme: dark)")
.matches
? "dark"
: "light";
const prefersColorSchema = matchMedia("(prefers-color-scheme: dark)")
.matches
? "dark"
: "light";

const invertedColors = matchMedia("(inverted-colors: inverted)").matches
? "inverted"
: "none";
const invertedColors = matchMedia("(inverted-colors: inverted)").matches
? "inverted"
: "none";

return new BrowserAccessibilityPreferences(
reducedMotion,
prefersContrast,
prefersReducedTransparency,
prefersColorSchema,
invertedColors,
);
};
return new BrowserAccessibilityPreferences(
reducedMotion,
prefersContrast,
prefersReducedTransparency,
prefersColorSchema,
invertedColors,
);
};

export { useBrowserAccessibilityPreferences };
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export type { prefersReducedMotion, prefersContrast, prefersReducedTransparency, prefersColorSchema, invertedColors } from "@/accessibility/preferences";
export type {
prefersReducedMotion,
prefersContrast,
prefersReducedTransparency,
prefersColorSchema,
invertedColors,
} from "@/accessibility/preferences";
export { BrowserAccessibilityPreferences } from "@/accessibility/preferences";
export { useBrowserAccessibilityPreferences } from "@/accessibility/preferences";

0 comments on commit 4c2a301

Please sign in to comment.