Skip to content

Commit

Permalink
Merge pull request #117 from inokawa/strip-internal
Browse files Browse the repository at this point in the history
Remove internal types from bundle
  • Loading branch information
inokawa authored Nov 27, 2023
2 parents 52aa021 + 6111414 commit c7423d9
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 5 deletions.
38 changes: 37 additions & 1 deletion src/dom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { refKey } from "./utils";

/**
* @internal
*/
export const isSafari = (): boolean => {
const ua = navigator.userAgent.toLowerCase();
return ua.indexOf("safari") > -1 && ua.indexOf("chrome") <= -1;
Expand Down Expand Up @@ -68,14 +71,23 @@ const getValueFromStyle = (style: CSSStyleDeclaration, key: string): number => {
}
};

/**
* @internal
*/
export const getStyle = (e: Element) => getComputedStyle(e);

/**
* @internal
*/
export const hasPercentageUnit = (
widthOrHeight: React.CSSProperties["width"] | React.CSSProperties["height"]
): boolean => {
return typeof widthOrHeight === "string" && widthOrHeight.endsWith("%");
};

/**
* @internal
*/
export const getVerticalPadding = (style: CSSStyleDeclaration): number => {
return (
getValueFromStyle(style, "padding-top") +
Expand All @@ -85,6 +97,9 @@ export const getVerticalPadding = (style: CSSStyleDeclaration): number => {
);
};

/**
* @internal
*/
export const getHorizontalPadding = (style: CSSStyleDeclaration): number => {
return (
getValueFromStyle(style, "padding-left") +
Expand All @@ -94,6 +109,9 @@ export const getHorizontalPadding = (style: CSSStyleDeclaration): number => {
);
};

/**
* @internal
*/
export const getPointedElement = (
textarea: HTMLElement,
backdrop: HTMLElement,
Expand Down Expand Up @@ -136,13 +154,19 @@ const dispatchMouseEvent = (
target.dispatchEvent(new MouseEvent(type, init));
};

/**
* @internal
*/
export const dispatchClonedMouseEvent = (
pointed: HTMLElement,
e: MouseEvent
) => {
dispatchMouseEvent(pointed, e.type, e);
};

/**
* @internal
*/
export const dispatchMouseMoveEvent = (
pointed: HTMLElement | null,
prevPointed: HTMLElement | null,
Expand All @@ -160,6 +184,9 @@ export const dispatchMouseMoveEvent = (
}
};

/**
* @internal
*/
export const dispatchMouseOutEvent = (
prevPointed: HTMLElement | null,
e: MouseEvent
Expand All @@ -169,10 +196,16 @@ export const dispatchMouseOutEvent = (
}
};

/**
* @internal
*/
export const stopPropagation = (event: React.MouseEvent) => {
event.stopPropagation();
};

/**
* @internal
*/
export const syncBackdropStyle = (
textarea: HTMLElement,
backdrop: HTMLElement,
Expand All @@ -193,9 +226,12 @@ export const syncBackdropStyle = (
textareaStyle.caretColor = style?.caretColor || caretColorRef[refKey];
};

/**
* @internal
*/
export const listenEvent = <
E extends HTMLElement | Document,
K extends keyof GlobalEventHandlersEventMap
K extends keyof GlobalEventHandlersEventMap,
>(
el: E,
key: K,
Expand Down
8 changes: 7 additions & 1 deletion src/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import {
} from "./dom";
import { SelectionStore } from "./selection";

/**
* @internal
*/
export type TextareaRect = [
width: number,
height: number,
hPadding: number,
vPadding: number
vPadding: number,
];

/**
* @internal
*/
export const createTextareaObserver = (
textarea: HTMLTextAreaElement | HTMLInputElement,
backdrop: HTMLDivElement,
Expand Down
3 changes: 3 additions & 0 deletions src/regex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @internal
*/
export const execReg = (reg: RegExp, text: string): RegExpExecArray[] => {
const results: RegExpExecArray[] = [];
let match: RegExpExecArray | null = null;
Expand Down
9 changes: 9 additions & 0 deletions src/selection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { refKey } from "./utils";

/**
* @internal
*/
export type SelectionRange = [number | null, number | null];

/**
* @internal
*/
export const initSelectionStore = (
ref: React.RefObject<HTMLTextAreaElement | HTMLInputElement>,
onSelectionUpdate: (range: SelectionRange) => void
Expand Down Expand Up @@ -49,4 +55,7 @@ export const initSelectionStore = (
return handle;
};

/**
* @internal
*/
export type SelectionStore = ReturnType<typeof initSelectionStore>;
5 changes: 4 additions & 1 deletion src/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useEffect, useLayoutEffect } from "react";

// https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
/**
* https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
* @internal
*/
export const useIsomorphicLayoutEffect =
typeof window !== "undefined" ? useLayoutEffect : useEffect;
3 changes: 3 additions & 0 deletions src/useStatic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useRef } from "react";
import { refKey } from "./utils";

/**
* @internal
*/
export const useStatic = <T>(init: () => T): T => {
const ref = useRef<T>();
return ref[refKey] || (ref[refKey] = init());
Expand Down
8 changes: 7 additions & 1 deletion src/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/**
* @internal
*/
export const refKey = "current";

// for caret position detection
/**
* for caret position detection
* @internal
*/
export const CARET_DETECTOR = (
<span style={{ color: "transparent" }}>{"\u200b"}</span>
);
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"noFallthroughCasesInSwitch": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"exactOptionalPropertyTypes": true
"exactOptionalPropertyTypes": true,
"stripInternal": true
},
"include": ["src"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit c7423d9

Please sign in to comment.