Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Refactor all exports to named exports #551

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. The format
### Changed

- Refactor decorators to not override the name config ([#549](https://github.com/studiometa/js-toolkit/issues/549), [#550](https://github.com/studiometa/js-toolkit/pull/550), [6436ef7d](https://github.com/studiometa/js-toolkit/commit/6436ef7d))
- Refactor all exports to be named exports ([#551](https://github.com/studiometa/js-toolkit/pull/551), [2e046016](https://github.com/studiometa/js-toolkit/commit/2e046016))

## [v3.0.0-beta.2](https://github.com/studiometa/js-toolkit/compare/3.0.0-beta.1..3.0.0-beta.2) (2024-11-21)

Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/Base/managers/EventsManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Base, BaseProps } from '../index.js';
import getAllProperties from '../../utils/object/getAllProperties.js';
import { getAllProperties } from '../../utils/object/getAllProperties.js';
import { dashCase, isArray, pascalCase } from '../../utils/index.js';
import { getEventTarget, eventIsNative, eventIsDefinedInConfig } from '../utils.js';
import { AbstractManager } from './AbstractManager.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/helpers/createApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type CreateAppOptions = Partial<Features> & {
* Instantiate and mount the given component on the given root element when the page has been loaded
* and return a function to use the app instance when it is ready.
*/
export default function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(
export function createApp<S extends BaseConstructor<Base>, T extends BaseProps = BaseProps>(
App: S,
options: HTMLElement | CreateAppOptions = {},
): () => Promise<S & Base<T>> {
Expand Down
4 changes: 2 additions & 2 deletions packages/js-toolkit/helpers/getClosestParent.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Base, BaseConstructor } from '../Base/index.js';
import getInstanceFromElement from './getInstanceFromElement.js';
import { getInstanceFromElement } from './getInstanceFromElement.js';
import { getAncestorWhere } from '../utils/index.js';

/**
* Get the closest parent of a component.
*/
export default function getClosestParent<T extends BaseConstructor>(
export function getClosestParent<T extends BaseConstructor>(
childInstance: Base,
ParentConstructor: T,
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/helpers/getInstanceFromElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { BaseConstructor, BaseEl } from '../Base/index.js';
/**
* Get a component instance from a DOM element.
*/
export default function getInstanceFromElement<T extends BaseConstructor>(
export function getInstanceFromElement<T extends BaseConstructor>(
element: BaseEl,
Constructor: T,
): InstanceType<T> | null {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/helpers/importOnInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isString, getComponentResolver } from '../utils/index.js';
* The parent component.
* @returns {Promise<InstanceType<T>>}
*/
export default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(
export function importOnInteraction<T extends BaseConstructor = BaseConstructor>(
fn: () => Promise<T | { default: T }>,
nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],
events: string | string[],
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/helpers/importOnMediaQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getComponentResolver } from '../utils/index.js';
* The media query name and value (see https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_features)
* @returns {Promise<T>}
*/
export default function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(
export function importOnMediaQuery<T extends BaseConstructor = BaseConstructor>(
fn: () => Promise<T | { default: T }>,
media: string,
): Promise<T> {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/helpers/importWhenIdle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ImportWhenIdleOptions = {
* The time to wait before triggering the callback if never idle.
* @returns {Promise<T>}
*/
export default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(
export function importWhenIdle<T extends BaseConstructor = BaseConstructor>(
fn: () => Promise<T | { default: T }>,
{ timeout = 1 }: ImportWhenIdleOptions = {},
): Promise<T> {
Expand Down
4 changes: 2 additions & 2 deletions packages/js-toolkit/helpers/importWhenPrefersMotion.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseConstructor } from '../Base/index.js';
import importOnMediaQuery from './importOnMediaQuery.js';
import { importOnMediaQuery } from './importOnMediaQuery.js';

/**
* Import a component if user does not reduce motion.
Expand All @@ -8,7 +8,7 @@ import importOnMediaQuery from './importOnMediaQuery.js';
* @param {() => Promise<T|{default:T}>} fn
* @returns {Promise<T>}
*/
export default function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(
export function importWhenPrefersMotion<T extends BaseConstructor = BaseConstructor>(
fn: () => Promise<T | { default: T }>,
): Promise<T> {
return importOnMediaQuery(fn, 'not (prefers-reduced-motion)');
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/helpers/importWhenVisible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getComponentResolver } from '../utils/index.js';
* Options for the `IntersectionObserver` instance.
* @returns {Promise<T>}
*/
export default function importWhenVisible<T extends BaseConstructor = BaseConstructor>(
export function importWhenVisible<T extends BaseConstructor = BaseConstructor>(
fn: () => Promise<T | { default: T }>,
nameOrSelectorOrElement: string | HTMLElement | HTMLElement[],
parent?: Base,
Expand Down
16 changes: 8 additions & 8 deletions packages/js-toolkit/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export * from './createApp.js';
export * from './getClosestParent.js';
export * from './getDirectChildren.js';
export { default as createApp } from './createApp.js';
export { default as getClosestParent } from './getClosestParent.js';
export { default as getInstanceFromElement } from './getInstanceFromElement.js';
export { default as importOnInteraction } from './importOnInteraction.js';
export { default as importWhenIdle } from './importWhenIdle.js';
export { default as importWhenVisible } from './importWhenVisible.js';
export { default as importOnMediaQuery } from './importOnMediaQuery.js';
export { default as importWhenPrefersMotion } from './importWhenPrefersMotion.js';
export * from './getInstanceFromElement.js';
export * from './importOnInteraction.js';
export * from './importOnMediaQuery.js';
export * from './importWhenIdle.js';
export * from './importWhenPrefersMotion.js';
export * from './importWhenVisible.js';
2 changes: 1 addition & 1 deletion packages/js-toolkit/services/KeyService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ServiceConfig, ServiceInterface } from './AbstractService.js';
import { AbstractService } from './AbstractService.js';
import keyCodes from '../utils/keyCodes.js';
import { keyCodes } from '../utils/keyCodes.js';

function getInitialKeyCodes(): Record<keyof typeof keyCodes, false> {
return Object.fromEntries(Object.keys(keyCodes).map((key) => [key, false])) as Record<
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/services/ResizeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ServiceConfig, ServiceInterface } from './AbstractService.js';
import { AbstractService } from './AbstractService.js';
import type { Features } from '../Base/features.js';
import { features } from '../Base/features.js';
import debounce from '../utils/debounce.js';
import { debounce } from '../utils/debounce.js';

export interface ResizeServiceProps<U extends Features['breakpoints'] = Features['breakpoints']> {
width: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/services/ScrollService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ServiceConfig, ServiceInterface } from './AbstractService.js';
import { AbstractService } from './AbstractService.js';
import debounce from '../utils/debounce.js';
import { debounce } from '../utils/debounce.js';
import { PASSIVE_CAPTURE_EVENT_OPTIONS } from './utils.js';

export interface ScrollServiceProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/collide/boundingRectToCircle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param {boolean} force Force usage of non-square DOMElements
* @returns {Circle} Circle object that can be used in collides functions
*/
export default function boundingRectToCircle({ x, y, width, height }, force = false) {
export function boundingRectToCircle({ x, y, width, height }, force = false) {
if (width !== height && !force) {
throw new Error('Initial DOMElement is not a square. Please use the force mode.');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/collide/collideCircleCircle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @param {Circle} circle2 Circle 2
* @returns {boolean} Are the sides of one circle touching the other ?
*/
export default function collideCircleCircle(circle1, circle2) {
export function collideCircleCircle(circle1, circle2) {
// get distance between the circle's centers
// use the Pythagorean Theorem to compute the distance
const distX = circle1.x - circle2.x;
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/collide/collideCircleRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @param {Rect} rect Rectangle
* @returns {boolean} Are the sides of the circle touching the rectangle ?
*/
export default function collideCircleRect(circle, rect) {
export function collideCircleRect(circle, rect) {
// temporary variables to set edges for testing
let testX = circle.x;
let testY = circle.y;
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/collide/collidePointCircle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @param {Circle} circle Circle
* @returns {boolean} Is the point inside the circle's bounds ?
*/
export default function collidePointCircle(point, circle) {
export function collidePointCircle(point, circle) {
// get distance between the point and circle's center
// using the Pythagorean Theorem
const distX = point.x - circle.x;
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/collide/collidePointRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @param {Rect} rect Rectangle
* @returns {boolean} Is the point inside the rectangle's bounds ?
*/
export default function collidePointRect(point, rect) {
export function collidePointRect(point, rect) {
return (
point.x >= rect.x && // right of the left edge AND
point.x <= rect.x + rect.width && // left of the right edge AND
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/collide/collideRectRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @param {Rect} rect2 Rectangle 2
* @returns {boolean} Are the sides of one rectangle touching the other ?
*/
export default function collideRectRect(rect1, rect2) {
export function collideRectRect(rect1, rect2) {
return (
rect1.x + rect1.width >= rect2.x && // rect1 right edge past rect2 left AND
rect1.x <= rect2.x + rect2.width && // rect1 left edge past rect2 right AND
Expand Down
12 changes: 6 additions & 6 deletions packages/js-toolkit/utils/collide/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Inspired by http://www.jeffreythompson.org/collision-detection/
*/
export { default as boundingRectToCircle } from './boundingRectToCircle.js';
export { default as collideCircleCircle } from './collideCircleCircle.js';
export { default as collideCircleRect } from './collideCircleRect.js';
export { default as collidePointCircle } from './collidePointCircle.js';
export { default as collidePointRect } from './collidePointRect.js';
export { default as collideRectRect } from './collideRectRect.js';
export { boundingRectToCircle } from './boundingRectToCircle.js';
export { collideCircleCircle } from './collideCircleCircle.js';
export { collideCircleRect } from './collideCircleRect.js';
export { collidePointCircle } from './collidePointCircle.js';
export { collidePointRect } from './collidePointRect.js';
export { collideRectRect } from './collideRectRect.js';
1 change: 0 additions & 1 deletion packages/js-toolkit/utils/css/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { isDefined, isFunction, isNumber } from '../is.js';
import { transform, TRANSFORM_PROPS } from './transform.js';
import { domScheduler as scheduler } from '../scheduler.js';
import { tween, normalizeEase } from '../tween.js';
// eslint-disable-next-line import/extensions
import { eachElements } from './utils.js';
import { startsWith } from '../string/index.js';
import type { TransformProps } from './transform.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/css/getOffsetSizes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Get a `DOMRect` like `Object` for an element, without its transforms.
*/
export default function getOffsetSizes(element: HTMLElement) {
export function getOffsetSizes(element: HTMLElement) {
let parent = element;
let x = -window.scrollX;
let y = -window.scrollY;
Expand Down
6 changes: 3 additions & 3 deletions packages/js-toolkit/utils/css/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * from './animate.js';
export { add as addClass, remove as removeClass, toggle as toggleClass } from './classes.js';
export { add as addStyle, remove as removeStyle } from './styles.js';
export { default as getOffsetSizes } from './getOffsetSizes.js';
export { default as matrix } from './matrix.js';
export { getOffsetSizes } from './getOffsetSizes.js';
export { matrix } from './matrix.js';
export { transform } from './transform.js';
export { default as transition } from './transition.js';
export { transition } from './transition.js';
export type { TransformProps } from './transform.js';
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/css/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type MatrixTransform = {
* // matrix(0.5, 0, 0, 0.5, 0, 0)
* ```
*/
export default function matrix(transform?: MatrixTransform): string {
export function matrix(transform?: MatrixTransform): string {
// eslint-disable-next-line no-param-reassign
transform = transform || {};
return `matrix(${transform.scaleX ?? 1}, ${transform.skewY ?? 0}, ${transform.skewX ?? 0}, ${
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/css/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async function singleTransition(
* @param {string} endMode Whether to remove or keep the `to` classes/styles
* @returns {Promise<void>} A promise resolving at the end of the transition.
*/
export default async function transition(
export async function transition(
elementOrElements: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>,
name: string | TransitionStyles,
endMode: 'keep' | 'remove' = 'remove',
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @param {number} [delay=300] The delay in ms to wait before calling the function.
* @returns {(...args:unknown[]) => void} The debounced function.
*/
export default function debounce(
export function debounce(
fn: (...args: unknown[]) => void,
delay = 300,
): (...args: unknown[]) => void {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/getComponentResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isFunction } from './is.js';
* @param {Function} fn
* @returns {Function}
*/
export default function getComponentResolver(fn) {
export function getComponentResolver(fn) {
return (resolve, cb?: () => unknown) => {
fn().then((module) => {
const ResolvedClass = module.default ?? module;
Expand Down
10 changes: 5 additions & 5 deletions packages/js-toolkit/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export { default as debounce } from './debounce.js';
export { debounce } from './debounce.js';
export * from './trapFocus.js';
export { default as keyCodes } from './keyCodes.js';
export { default as memoize } from './memoize.js';
export { keyCodes } from './keyCodes.js';
export { memoize } from './memoize.js';
export { nextFrame } from './nextFrame.js';
export { nextTick } from './nextTick.js';
export { nextMicrotask } from './nextMicrotask.js';
export { default as throttle } from './throttle.js';
export { throttle } from './throttle.js';
export { scrollTo } from './scrollTo.js';
export { default as getComponentResolver } from './getComponentResolver.js';
export { getComponentResolver } from './getComponentResolver.js';
export * from './is.js';
export * from './has.js';
export * from './css/index.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/keyCodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
export const keyCodes = {
ENTER: 13,
SPACE: 32,
TAB: 9,
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/math/clamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param {number} max
* @returns {number}
*/
export default function clamp(value: number, min: number, max: number) {
export function clamp(value: number, min: number, max: number) {
/* eslint-disable no-nested-ternary */
return min < max
? value < min
Expand Down
4 changes: 2 additions & 2 deletions packages/js-toolkit/utils/math/clamp01.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import clamp from './clamp.js';
import { clamp } from './clamp.js';

/**
* Clamp a value in the 0–1 range.
*
* @param {number} value
* @returns {number}
*/
export default function clamp01(value: number) {
export function clamp01(value: number) {
return clamp(value, 0, 1);
}
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/math/damp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @param {number} [precision=0.01] The precision used to calculate the latest value.
* @returns {number} The next value.
*/
export default function damp(
export function damp(
targetValue: number,
currentValue: number,
factor = 0.5,
Expand Down
14 changes: 7 additions & 7 deletions packages/js-toolkit/utils/math/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export * as ease from './ease.js';
export * from './createEases.js';
export * from './ease.js';
export { createRange } from './createRange.js';
export { default as clamp } from './clamp.js';
export { default as clamp01 } from './clamp01.js';
export { default as damp } from './damp.js';
export { default as inertiaFinalValue } from './inertiaFinalValue.js';
export { default as lerp } from './lerp.js';
export { default as map } from './map.js';
export { default as round } from './round.js';
export { clamp } from './clamp.js';
export { clamp01 } from './clamp01.js';
export { damp } from './damp.js';
export { inertiaFinalValue } from './inertiaFinalValue.js';
export { lerp } from './lerp.js';
export { map } from './map.js';
export { round } from './round.js';
export { mean } from './mean.js';
8 changes: 2 additions & 6 deletions packages/js-toolkit/utils/math/inertiaFinalValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import clamp from './clamp.js';
import { clamp } from './clamp.js';

/**
* Get the final damped value for a given factor.
Expand All @@ -8,11 +8,7 @@ import clamp from './clamp.js';
* @param {number} [dampFactor=0.85] The speed to reach the target value.
* @returns {number} The next value.
*/
export default function inertiaFinalValue(
initialValue: number,
initialDelta: number,
dampFactor = 0.85,
) {
export function inertiaFinalValue(initialValue: number, initialDelta: number, dampFactor = 0.85) {
// eslint-disable-next-line no-param-reassign
dampFactor = clamp(dampFactor, 0.00001, 0.99999);
let delta = initialDelta;
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/math/lerp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @param {number} ratio The ratio to get.
* @returns {number} The value between min and max corresponding to ratio.
*/
export default function lerp(min: number, max: number, ratio: number) {
export function lerp(min: number, max: number, ratio: number) {
return (1 - ratio) * min + ratio * max;
}
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/math/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @param {number} outputMax The output's maximum value.
* @returns {number} The input value mapped to the output range.
*/
export default function map(
export function map(
value: number,
inputMin: number,
inputMax: number,
Expand Down
2 changes: 1 addition & 1 deletion packages/js-toolkit/utils/math/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @param {number} [decimals=0] The number of decimals to keep.
* @returns {number} A rounded number to the given decimals length.
*/
export default function round(value: number, decimals = 0) {
export function round(value: number, decimals = 0) {
return Number(value.toFixed(decimals));
}
Loading