etudes 0.60.0 → 0.63.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.
- package/lib/ExtractChild.d.ts +3 -5
- package/lib/ExtractChild.js.map +1 -1
- package/lib/ExtractChildren.d.ts +2 -2
- package/lib/ExtractChildren.js.map +1 -1
- package/lib/Map.d.ts +2 -2
- package/lib/Map.js.map +1 -1
- package/lib/MasonryGrid.d.ts +3 -3
- package/lib/MasonryGrid.js.map +1 -1
- package/lib/Repeat.d.ts +2 -2
- package/lib/Repeat.js.map +1 -1
- package/lib/SelectableButton.d.ts +3 -3
- package/lib/SelectableButton.js.map +1 -1
- package/lib/SwipeContainer.d.ts +3 -3
- package/lib/SwipeContainer.js.map +1 -1
- package/lib/WithTooltip.d.ts +2 -2
- package/lib/WithTooltip.js +3 -1
- package/lib/WithTooltip.js.map +1 -1
- package/lib/hooks/useElementRect.d.ts +10 -0
- package/lib/hooks/useElementRect.js +54 -0
- package/lib/hooks/useElementRect.js.map +1 -0
- package/lib/hooks/useViewportSize.d.ts +7 -0
- package/lib/hooks/useViewportSize.js +40 -0
- package/lib/hooks/useViewportSize.js.map +1 -0
- package/package.json +23 -26
package/lib/ExtractChild.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import React, { HTMLAttributes
|
|
2
|
-
export declare type Props =
|
|
3
|
-
declare const _default: React.ForwardRefExoticComponent<React.
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
} & React.RefAttributes<HTMLElement>>;
|
|
1
|
+
import React, { HTMLAttributes } from 'react';
|
|
2
|
+
export declare type Props = HTMLAttributes<HTMLElement>;
|
|
3
|
+
declare const _default: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLElement>>;
|
|
6
4
|
/**
|
|
7
5
|
* Extracts a single child of a parent component into its own component. If the parent component has
|
|
8
6
|
* multiple children, only the first one will be extracted, the rest will be ignored.
|
package/lib/ExtractChild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtractChild.js","sourceRoot":"/","sources":["ExtractChild.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,kDAAsB;AACtB,
|
|
1
|
+
{"version":3,"file":"ExtractChild.js","sourceRoot":"/","sources":["ExtractChild.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,kDAAsB;AACtB,6CAAiG;AAIjG;;;GAGG;AACH,kBAAe,IAAA,kBAAU,EAAqB,UAAC,EAI9C,EAAE,GAAG;IAHJ,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACN,KAAK,cAHqC,yBAI9C,CADS;IAER,IAAI,gBAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACvB,yCAAyC;QACzC,OAAO,CAAC,KAAK,CAAC,uEAAgE,QAAQ,CAAC,MAAM,sEAAmE,CAAC,CAAA;KAClK;IAED,OAAO,CACL,8DACG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAC,KAAK,EAAE,GAAG;QACjC,IAAI,GAAG,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;QAE7B,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,oBAAY,EAAC,KAAK,sBAAI,SAAS,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAK,KAAK,KAAE,GAAG,KAAA,IAAG,CAAA;SACvG;QAED,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CACD,CACJ,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import classNames from 'classnames'\nimport _ from 'lodash'\nimport React, { Children, cloneElement, forwardRef, HTMLAttributes, isValidElement } from 'react'\n\nexport type Props = HTMLAttributes<HTMLElement>\n\n/**\n * Extracts a single child of a parent component into its own component. If the parent component has\n * multiple children, only the first one will be extracted, the rest will be ignored.\n */\nexport default forwardRef<HTMLElement, Props>(({\n children,\n className,\n ...props\n}, ref) => {\n if (_.isArray(children)) {\n /* eslint-disable-next-line no-console */\n console.error(`[etudes::ExtractChild] Only one child is expected, but found ${children.length}. Only the first child is extracted while the rest are discarded.`)\n }\n\n return (\n <>\n {Children.map(children, (child, idx) => {\n if (idx > 0) return undefined\n\n if (isValidElement(child)) {\n return cloneElement(child, { className: classNames(className, child.props.className), ...props, ref })\n }\n\n return child\n })}\n </>\n )\n})\n"]}
|
package/lib/ExtractChildren.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HTMLAttributes
|
|
2
|
-
export declare type Props =
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
export declare type Props = HTMLAttributes<HTMLElement>;
|
|
3
3
|
/**
|
|
4
4
|
* Extracts all children of a parent component into its own component.
|
|
5
5
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtractChildren.js","sourceRoot":"/","sources":["ExtractChildren.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"ExtractChildren.js","sourceRoot":"/","sources":["ExtractChildren.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAmC;AACnC,6CAAqF;AAIrF;;GAEG;AACH,SAAwB,eAAe,CAAC,EAIhC;IAHN,IAAA,QAAQ,cAAA,EACR,SAAS,eAAA,EACN,KAAK,cAH8B,yBAIvC,CADS;IAER,OAAO,CACL,8DACG,gBAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,UAAC,KAAK,EAAE,GAAG;QACjC,IAAI,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;YACzB,OAAO,IAAA,oBAAY,EAAC,KAAK,aAAI,SAAS,EAAE,IAAA,oBAAU,EAAC,SAAS,EAAE,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,IAAK,KAAK,EAAG,CAAA;SAClG;QAED,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAhBD,kCAgBC","sourcesContent":["import classNames from 'classnames'\nimport React, { Children, cloneElement, HTMLAttributes, isValidElement } from 'react'\n\nexport type Props = HTMLAttributes<HTMLElement>\n\n/**\n * Extracts all children of a parent component into its own component.\n */\nexport default function ExtractChildren({\n children,\n className,\n ...props\n}: Props) {\n return (\n <>\n {Children.map(children, (child, idx) => {\n if (isValidElement(child)) {\n return cloneElement(child, { className: classNames(className, child.props.className), ...props })\n }\n\n return child\n })}\n </>\n )\n}\n"]}
|
package/lib/Map.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
export declare type Props<T> = {
|
|
3
|
-
children:
|
|
3
|
+
children: ReactNode | ((value: T, index: number) => ReactNode);
|
|
4
4
|
array?: T[];
|
|
5
5
|
};
|
|
6
6
|
export default function Map<T>({ array, children, }: Props<T>): JSX.Element;
|
package/lib/Map.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Map.js","sourceRoot":"/","sources":["Map.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Map.js","sourceRoot":"/","sources":["Map.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAkD;AAOlD,SAAwB,GAAG,CAAI,EAGpB;QAFT,KAAK,WAAA,EACL,QAAQ,cAAA;IAER,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,MAAM,SAAS,CAAC,gDAAyC,KAAK,CAAE,CAAC,CAAA;IAEhG,OAAO,CACL,8DACG,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CACnB,8BAAC,gBAAQ,IAAC,GAAG,EAAE,kBAAW,CAAC,CAAE,IAC1B,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAClD,CACZ,EAJoB,CAIpB,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAfD,sBAeC","sourcesContent":["import React, { Fragment, ReactNode } from 'react'\n\nexport type Props<T> = {\n children: ReactNode | ((value: T, index: number) => ReactNode)\n array?: T[]\n}\n\nexport default function Map<T>({\n array,\n children,\n}: Props<T>) {\n if (!(array instanceof Array)) throw TypeError(`Provided collection must be an array: ${array}`)\n\n return (\n <>\n {array.map((v, i) => (\n <Fragment key={`element-${i}`}>\n {typeof children === 'function' ? children(v, i) : children}\n </Fragment>\n ))}\n </>\n )\n}\n"]}
|
package/lib/MasonryGrid.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { HTMLAttributes
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
2
|
import { Orientation } from './types';
|
|
3
|
-
export declare type Props = HTMLAttributes<HTMLDivElement> &
|
|
3
|
+
export declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
4
4
|
areSectionsAligned?: boolean;
|
|
5
5
|
horizontalSpacing?: number;
|
|
6
6
|
isReversed?: boolean;
|
|
7
7
|
orientation?: Orientation;
|
|
8
8
|
sections?: number;
|
|
9
9
|
verticalSpacing?: number;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
/**
|
|
12
12
|
* This is a React component that arranges all of its immediate children in a masonry grid. Refrain
|
|
13
13
|
* from assigning CSS styles to it via `className` or `style` property, though they are still
|
package/lib/MasonryGrid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MasonryGrid.js","sourceRoot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AAM,GAAG,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;YACzB,KAAK,CAAC,GAAG,GAAG,GAAG,CAAA;YACf,KAAK,CAAC,MAAM,GAAG,cAAM,OAAA,kBAAkB,EAAE,EAApB,CAAoB,CAAA;SAC1C;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,OAAO,CACL,8BAAC,UAAU,eACL,KAAK,IACT,GAAG,EAAE,OAAO,EACZ,WAAW,EAAE,WAAW,EACxB,KAAK,wBACA,KAAK,KACR,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,CAAC,CAAC,WAAW,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,UAAG,SAAS,OAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EACtF,QAAQ,EAAE,CAAC,CAAC,WAAW,KAAK,YAAY,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAG,QAAQ,OAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EACrF,OAAO,EAAE,GAAG,QAGb,QAAQ,CACE,CACd,CAAA;AACH,CAAC;AApLD,8BAoLC;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,6KAE3B,4DAGU,EAA2D,qCAE5D,EAA6D,KACvE,KAHW,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAlD,CAAkD,EAE5D,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAApD,CAAoD,CACvE,CAAA","sourcesContent":["import React, { HTMLAttributes, PropsWithChildren, useEffect, useRef, useState } from 'react'\nimport { Rect } from 'spase'\nimport styled from 'styled-components'\nimport useResizeEffect from './hooks/useResizeEffect'\nimport { Orientation } from './types'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:masonry-grid') : () => {}\n\nexport type Props = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{\n areSectionsAligned?: boolean\n horizontalSpacing?: number\n isReversed?: boolean\n orientation?: Orientation\n sections?: number\n verticalSpacing?: number\n}>\n\nconst BASE_MODIFIER_CLASS_PREFIX = 'base-'\n\n/**\n * Computes the index and current length of the next available section for a specific base value,\n * based on a provided array of existing section lengths.\n *\n * @param currentSectionLengths - An array of the current section lengths.\n * @param base - The base value of the item to be inserted into the grid, and to be used to evaluate\n * the next available section.\n *\n * @returns An array consiting of the computed section index and its to-be length if a new item were\n * to be placed in it.\n */\nfunction computeNextAvailableSectionAndLengthByBase(currentSectionLengths: number[], base: number): [number, number] {\n const numSections = currentSectionLengths.length\n\n let sectionIdx = NaN\n let minLength = Infinity\n\n for (let i = 0; i < numSections; i++) {\n const length = currentSectionLengths[i]\n const isShorter = length < minLength\n const isEligibleSection = (i + base) <= numSections\n let hasRoomInSubsequentSections = true\n\n for (let j = 1; j < base; j++) {\n if (currentSectionLengths[i + j] > length) {\n hasRoomInSubsequentSections = false\n }\n }\n\n if (isShorter && isEligibleSection && hasRoomInSubsequentSections) {\n sectionIdx = i\n minLength = length\n }\n }\n\n if (isNaN(sectionIdx)) {\n return [0, computeMaxLength(currentSectionLengths, base)]\n }\n else {\n return [sectionIdx, minLength]\n }\n}\n\n/**\n * A helper function that computes the max section length of an array of section lengths. Only the\n * first n = `base` sections are inspected.\n *\n * @param currentSectionLengths - An array of section lengths.\n * @param base - The number representing the first n sections to inspect. Any non-numerical values\n * will be ignored and return value will be based on all sections. A `base` value will\n * be clamped between 1 and the maximum length of the array of section lengths.\n *\n * @returns The max section length.\n */\nfunction computeMaxLength(currentSectionLengths: number[], base?: number): number {\n let arr = currentSectionLengths\n\n if (base !== undefined && base !== null && !isNaN(base)) {\n arr = arr.slice(0, Math.max(1, Math.min(base, currentSectionLengths.length)))\n }\n\n return arr.reduce((out, curr, i) => (curr > out) ? curr : out, 0)\n}\n\n/**\n * Computes the base value of an element from its classes.\n *\n * @param element - The HTML element.\n * @param numSections - Total number of sections.\n *\n * @returns The computed base value that is clamped between 1 and max number of sections.\n */\nfunction computeBaseFromElement(element: HTMLElement, numSections: number): number {\n const classList = element.classList\n\n for (let i = 0; i < classList.length; i++) {\n const c = classList[i]\n\n if (c.startsWith(BASE_MODIFIER_CLASS_PREFIX)) {\n const base = parseFloat(c.replace(BASE_MODIFIER_CLASS_PREFIX, ''))\n if (!isNaN(base)) return Math.min(Math.max(base, 1), numSections)\n }\n }\n\n return 1\n}\n\n/**\n * Scans an HTML string and returns all the image sources.\n *\n * @param htmlString The HTML string.\n *\n * @returns The image sources.\n */\nfunction getAllImageSources(htmlString?: string): string[] {\n if (!htmlString) return []\n\n const regexImg = /<img.*?src=(\"|')(.*?)(\"|')/g\n const regexSrc = /<img.*?src=(\"|')(.*?)(\"|')/\n const imageTags = htmlString.match(regexImg) ?? []\n\n const out: string[] = []\n\n for (let i = 0; i < imageTags.length; i++) {\n const tag = imageTags[i]\n const src = tag.match(regexSrc)?.[2]\n\n if (!src) continue\n\n out.push(src)\n }\n\n return out\n}\n\n/**\n * This is a React component that arranges all of its immediate children in a masonry grid. Refrain\n * from assigning CSS styles to it via `className` or `style` property, though they are still\n * handled if absolutely necessary. Customize the grid via its supported properties. The grid can be\n * in either vertical or horizontal orientation. The length of every child element *parallel to the\n * direction of the orientation* is automatically set according to the number of sections specified\n * for the grid. This means that in an horizontally oriented grid, the *width* of each child element\n * is automatically set, whereas in a vertically oriented grid the *height* of each child element is\n * automatically set. Additionally, the *number of sections* corresponds to the maximum the number\n * of child elements present in the direction that is parallel to the orientation of the grid.\n * Hence, in a vertically oriented grid, *number of secitons* refers to the *number of rows*,\n * whereas in a horizontally oriented grid, *number of sections* refers to the *number of columns*.\n */\nexport default function MasonryGrid({\n areSectionsAligned = false,\n children,\n horizontalSpacing= 0,\n isReversed = false,\n orientation = 'vertical',\n sections = 3,\n style = {},\n verticalSpacing = 0,\n ...props\n}: Props) {\n const rootRef = useRef<HTMLDivElement>(null)\n\n const [minWidth, setMinWidth] = useState(NaN)\n const [minHeight, setMinHeight] = useState(NaN)\n const [maxWidth, setMaxWidth] = useState(NaN)\n const [maxHeight, setMaxHeight] = useState(NaN)\n\n const getCurrentWidth = () => Rect.from(rootRef.current)?.width ?? 0\n\n const getCurrentHeight = () => Rect.from(rootRef.current)?.height ?? 0\n\n const repositionChildren = () => {\n const rootNode = rootRef.current\n\n if (!rootNode) return\n\n debug('Repositioning children... OK')\n\n const children = rootNode.children\n const numSections = sections\n\n if (numSections <= 0) throw new Error('You must specifiy a minimum of 1 section(s) (a.k.a. row(s) for horizontal orientation, column(s) for vertical orientation) for a MasonryGrid instance')\n\n if (orientation === 'vertical') {\n const sectionHeights: number[] = [...new Array(numSections)].map(() => 0)\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const base = computeBaseFromElement(child, sections)\n const [colIdx, y] = computeNextAvailableSectionAndLengthByBase(sectionHeights, base)\n\n child.style.position = 'absolute'\n child.style.width = `calc(${100 / numSections * base}% - ${(horizontalSpacing * (numSections - 1) / numSections) * base}px + ${horizontalSpacing * (base - 1)}px)`\n child.style.height = ''\n child.style.left = `calc(${100 / numSections * colIdx}% - ${(horizontalSpacing * (numSections - 1) / numSections) * colIdx}px + ${horizontalSpacing * colIdx}px)`\n child.style.top = `${y + (y === 0 ? 0 : verticalSpacing)}px`\n\n for (let j = 0; j < base; j++) {\n sectionHeights[colIdx + j] = y + (y === 0 ? 0 : verticalSpacing) + (Rect.from(child)?.height ?? 0)\n }\n\n if (areSectionsAligned && ((colIdx + base) === numSections)) {\n const m = computeMaxLength(sectionHeights)\n\n for (let j = 0; j < numSections; j++) {\n sectionHeights[j] = m\n }\n }\n }\n\n const w = getCurrentWidth()\n const h = computeMaxLength(sectionHeights, numSections)\n\n setMinWidth(w)\n setMinHeight(h)\n\n if (!isNaN(h)) rootNode.style.height = `${h}px`\n\n if (isReversed) {\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const x = parseFloat(child.style.left)\n\n child.style.left = `${w - x - parseFloat(child.style.width)}px`\n }\n }\n }\n else {\n const sectionWidths: number[] = [...new Array(numSections)].map(() => 0)\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const base = computeBaseFromElement(child, sections)\n const [rowIdx, x] = computeNextAvailableSectionAndLengthByBase(sectionWidths, base)\n\n child.style.position = 'absolute'\n child.style.width = ''\n child.style.height = `calc(${100 / numSections * base}% - ${(verticalSpacing * (numSections - 1) / numSections) * base}px + ${verticalSpacing * (base - 1)}px)`\n child.style.top = `calc(${100 / numSections * rowIdx}% - ${(verticalSpacing * (numSections - 1) / numSections) * rowIdx}px + ${verticalSpacing * rowIdx}px)`\n child.style.left = `${x + (x === 0 ? 0 : horizontalSpacing)}px`\n\n for (let j = 0; j < base; j++) {\n sectionWidths[rowIdx + j] = x + (x === 0 ? 0 : horizontalSpacing) + (Rect.from(child)?.width ?? 0)\n }\n\n if (areSectionsAligned && ((rowIdx + base) === numSections)) {\n const m = computeMaxLength(sectionWidths)\n\n for (let j = 0; j < numSections; j++) {\n sectionWidths[j] = m\n }\n }\n }\n\n const h = getCurrentHeight()\n const w = computeMaxLength(sectionWidths, numSections)\n\n setMinHeight(h)\n setMinWidth(w)\n\n if (!isNaN(w)) rootNode.style.width = `${w}px`\n\n if (isReversed) {\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const y = parseFloat(child.style.top)\n\n child.style.top = `${h - y - parseFloat(child.style.height)}px`\n }\n }\n }\n }\n\n useResizeEffect(rootRef, {\n onResize: maxSize => {\n const currWidth = getCurrentWidth()\n const currHeight = getCurrentHeight()\n\n if ((minWidth !== currWidth) || (minHeight !== currHeight) || (maxSize.width !== maxWidth) || maxSize.height !== maxHeight) {\n repositionChildren()\n setMaxWidth(maxSize.width)\n setMaxHeight(maxSize.height)\n }\n },\n }, [areSectionsAligned, horizontalSpacing, isReversed, sections, verticalSpacing])\n\n useEffect(() => {\n const imageSources = getAllImageSources(rootRef.current?.innerHTML)\n\n if (imageSources.length === 0) return repositionChildren()\n\n const numImages = imageSources.length\n\n for (let i = 0; i < numImages; i++) {\n const src = imageSources[i]\n const image = new Image()\n image.src = src\n image.onload = () => repositionChildren()\n }\n }, [children])\n\n return (\n <StyledRoot\n {...props}\n ref={rootRef}\n orientation={orientation}\n style={{\n ...style,\n flex: '0 0 auto',\n minHeight: ((orientation === 'vertical' && !isNaN(minHeight)) ? `${minHeight}px` : ''),\n minWidth: ((orientation === 'horizontal' && !isNaN(minWidth)) ? `${minWidth}px` : ''),\n padding: '0',\n }}\n >\n {children}\n </StyledRoot>\n )\n}\n\nconst StyledRoot = styled.div<{\n orientation: Props['orientation']\n}>`\n box-sizing: border-box;\n display: block;\n height: ${props => props.orientation === 'vertical' ? 'auto' : '100%'};\n position: relative;\n width: ${props => props.orientation === 'horizontal' ? 'auto' : '100%'};\n`\n"]}
|
|
1
|
+
{"version":3,"file":"MasonryGrid.js","sourceRoot":"/","sources":["MasonryGrid.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA0E;AAC1E,+BAA4B;AAC5B,wEAAsC;AACtC,4EAAqD;AAGrD,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,cAAO,CAAC,CAAA;AAWzG,IAAM,0BAA0B,GAAG,OAAO,CAAA;AAE1C;;;;;;;;;;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AE,CAAC,CAAC,WAAW,KAAK,UAAU,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,UAAG,SAAS,OAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EACtF,QAAQ,EAAE,CAAC,CAAC,WAAW,KAAK,YAAY,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAG,QAAQ,OAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EACrF,OAAO,EAAE,GAAG,QAGb,QAAQ,CACE,CACd,CAAA;AACH,CAAC;AApLD,8BAoLC;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,6KAE3B,4DAGU,EAA2D,qCAE5D,EAA6D,KACvE,KAHW,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAlD,CAAkD,EAE5D,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAApD,CAAoD,CACvE,CAAA","sourcesContent":["import React, { HTMLAttributes, useEffect, useRef, useState } from 'react'\nimport { Rect } from 'spase'\nimport styled from 'styled-components'\nimport useResizeEffect from './hooks/useResizeEffect'\nimport { Orientation } from './types'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:masonry-grid') : () => {}\n\nexport type Props = HTMLAttributes<HTMLDivElement> & {\n areSectionsAligned?: boolean\n horizontalSpacing?: number\n isReversed?: boolean\n orientation?: Orientation\n sections?: number\n verticalSpacing?: number\n}\n\nconst BASE_MODIFIER_CLASS_PREFIX = 'base-'\n\n/**\n * Computes the index and current length of the next available section for a specific base value,\n * based on a provided array of existing section lengths.\n *\n * @param currentSectionLengths - An array of the current section lengths.\n * @param base - The base value of the item to be inserted into the grid, and to be used to evaluate\n * the next available section.\n *\n * @returns An array consiting of the computed section index and its to-be length if a new item were\n * to be placed in it.\n */\nfunction computeNextAvailableSectionAndLengthByBase(currentSectionLengths: number[], base: number): [number, number] {\n const numSections = currentSectionLengths.length\n\n let sectionIdx = NaN\n let minLength = Infinity\n\n for (let i = 0; i < numSections; i++) {\n const length = currentSectionLengths[i]\n const isShorter = length < minLength\n const isEligibleSection = (i + base) <= numSections\n let hasRoomInSubsequentSections = true\n\n for (let j = 1; j < base; j++) {\n if (currentSectionLengths[i + j] > length) {\n hasRoomInSubsequentSections = false\n }\n }\n\n if (isShorter && isEligibleSection && hasRoomInSubsequentSections) {\n sectionIdx = i\n minLength = length\n }\n }\n\n if (isNaN(sectionIdx)) {\n return [0, computeMaxLength(currentSectionLengths, base)]\n }\n else {\n return [sectionIdx, minLength]\n }\n}\n\n/**\n * A helper function that computes the max section length of an array of section lengths. Only the\n * first n = `base` sections are inspected.\n *\n * @param currentSectionLengths - An array of section lengths.\n * @param base - The number representing the first n sections to inspect. Any non-numerical values\n * will be ignored and return value will be based on all sections. A `base` value will\n * be clamped between 1 and the maximum length of the array of section lengths.\n *\n * @returns The max section length.\n */\nfunction computeMaxLength(currentSectionLengths: number[], base?: number): number {\n let arr = currentSectionLengths\n\n if (base !== undefined && base !== null && !isNaN(base)) {\n arr = arr.slice(0, Math.max(1, Math.min(base, currentSectionLengths.length)))\n }\n\n return arr.reduce((out, curr, i) => (curr > out) ? curr : out, 0)\n}\n\n/**\n * Computes the base value of an element from its classes.\n *\n * @param element - The HTML element.\n * @param numSections - Total number of sections.\n *\n * @returns The computed base value that is clamped between 1 and max number of sections.\n */\nfunction computeBaseFromElement(element: HTMLElement, numSections: number): number {\n const classList = element.classList\n\n for (let i = 0; i < classList.length; i++) {\n const c = classList[i]\n\n if (c.startsWith(BASE_MODIFIER_CLASS_PREFIX)) {\n const base = parseFloat(c.replace(BASE_MODIFIER_CLASS_PREFIX, ''))\n if (!isNaN(base)) return Math.min(Math.max(base, 1), numSections)\n }\n }\n\n return 1\n}\n\n/**\n * Scans an HTML string and returns all the image sources.\n *\n * @param htmlString The HTML string.\n *\n * @returns The image sources.\n */\nfunction getAllImageSources(htmlString?: string): string[] {\n if (!htmlString) return []\n\n const regexImg = /<img.*?src=(\"|')(.*?)(\"|')/g\n const regexSrc = /<img.*?src=(\"|')(.*?)(\"|')/\n const imageTags = htmlString.match(regexImg) ?? []\n\n const out: string[] = []\n\n for (let i = 0; i < imageTags.length; i++) {\n const tag = imageTags[i]\n const src = tag.match(regexSrc)?.[2]\n\n if (!src) continue\n\n out.push(src)\n }\n\n return out\n}\n\n/**\n * This is a React component that arranges all of its immediate children in a masonry grid. Refrain\n * from assigning CSS styles to it via `className` or `style` property, though they are still\n * handled if absolutely necessary. Customize the grid via its supported properties. The grid can be\n * in either vertical or horizontal orientation. The length of every child element *parallel to the\n * direction of the orientation* is automatically set according to the number of sections specified\n * for the grid. This means that in an horizontally oriented grid, the *width* of each child element\n * is automatically set, whereas in a vertically oriented grid the *height* of each child element is\n * automatically set. Additionally, the *number of sections* corresponds to the maximum the number\n * of child elements present in the direction that is parallel to the orientation of the grid.\n * Hence, in a vertically oriented grid, *number of secitons* refers to the *number of rows*,\n * whereas in a horizontally oriented grid, *number of sections* refers to the *number of columns*.\n */\nexport default function MasonryGrid({\n areSectionsAligned = false,\n children,\n horizontalSpacing= 0,\n isReversed = false,\n orientation = 'vertical',\n sections = 3,\n style = {},\n verticalSpacing = 0,\n ...props\n}: Props) {\n const rootRef = useRef<HTMLDivElement>(null)\n\n const [minWidth, setMinWidth] = useState(NaN)\n const [minHeight, setMinHeight] = useState(NaN)\n const [maxWidth, setMaxWidth] = useState(NaN)\n const [maxHeight, setMaxHeight] = useState(NaN)\n\n const getCurrentWidth = () => Rect.from(rootRef.current)?.width ?? 0\n\n const getCurrentHeight = () => Rect.from(rootRef.current)?.height ?? 0\n\n const repositionChildren = () => {\n const rootNode = rootRef.current\n\n if (!rootNode) return\n\n debug('Repositioning children... OK')\n\n const children = rootNode.children\n const numSections = sections\n\n if (numSections <= 0) throw new Error('You must specifiy a minimum of 1 section(s) (a.k.a. row(s) for horizontal orientation, column(s) for vertical orientation) for a MasonryGrid instance')\n\n if (orientation === 'vertical') {\n const sectionHeights: number[] = [...new Array(numSections)].map(() => 0)\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const base = computeBaseFromElement(child, sections)\n const [colIdx, y] = computeNextAvailableSectionAndLengthByBase(sectionHeights, base)\n\n child.style.position = 'absolute'\n child.style.width = `calc(${100 / numSections * base}% - ${(horizontalSpacing * (numSections - 1) / numSections) * base}px + ${horizontalSpacing * (base - 1)}px)`\n child.style.height = ''\n child.style.left = `calc(${100 / numSections * colIdx}% - ${(horizontalSpacing * (numSections - 1) / numSections) * colIdx}px + ${horizontalSpacing * colIdx}px)`\n child.style.top = `${y + (y === 0 ? 0 : verticalSpacing)}px`\n\n for (let j = 0; j < base; j++) {\n sectionHeights[colIdx + j] = y + (y === 0 ? 0 : verticalSpacing) + (Rect.from(child)?.height ?? 0)\n }\n\n if (areSectionsAligned && ((colIdx + base) === numSections)) {\n const m = computeMaxLength(sectionHeights)\n\n for (let j = 0; j < numSections; j++) {\n sectionHeights[j] = m\n }\n }\n }\n\n const w = getCurrentWidth()\n const h = computeMaxLength(sectionHeights, numSections)\n\n setMinWidth(w)\n setMinHeight(h)\n\n if (!isNaN(h)) rootNode.style.height = `${h}px`\n\n if (isReversed) {\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const x = parseFloat(child.style.left)\n\n child.style.left = `${w - x - parseFloat(child.style.width)}px`\n }\n }\n }\n else {\n const sectionWidths: number[] = [...new Array(numSections)].map(() => 0)\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const base = computeBaseFromElement(child, sections)\n const [rowIdx, x] = computeNextAvailableSectionAndLengthByBase(sectionWidths, base)\n\n child.style.position = 'absolute'\n child.style.width = ''\n child.style.height = `calc(${100 / numSections * base}% - ${(verticalSpacing * (numSections - 1) / numSections) * base}px + ${verticalSpacing * (base - 1)}px)`\n child.style.top = `calc(${100 / numSections * rowIdx}% - ${(verticalSpacing * (numSections - 1) / numSections) * rowIdx}px + ${verticalSpacing * rowIdx}px)`\n child.style.left = `${x + (x === 0 ? 0 : horizontalSpacing)}px`\n\n for (let j = 0; j < base; j++) {\n sectionWidths[rowIdx + j] = x + (x === 0 ? 0 : horizontalSpacing) + (Rect.from(child)?.width ?? 0)\n }\n\n if (areSectionsAligned && ((rowIdx + base) === numSections)) {\n const m = computeMaxLength(sectionWidths)\n\n for (let j = 0; j < numSections; j++) {\n sectionWidths[j] = m\n }\n }\n }\n\n const h = getCurrentHeight()\n const w = computeMaxLength(sectionWidths, numSections)\n\n setMinHeight(h)\n setMinWidth(w)\n\n if (!isNaN(w)) rootNode.style.width = `${w}px`\n\n if (isReversed) {\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (!(child instanceof HTMLElement)) continue\n\n const y = parseFloat(child.style.top)\n\n child.style.top = `${h - y - parseFloat(child.style.height)}px`\n }\n }\n }\n }\n\n useResizeEffect(rootRef, {\n onResize: maxSize => {\n const currWidth = getCurrentWidth()\n const currHeight = getCurrentHeight()\n\n if ((minWidth !== currWidth) || (minHeight !== currHeight) || (maxSize.width !== maxWidth) || maxSize.height !== maxHeight) {\n repositionChildren()\n setMaxWidth(maxSize.width)\n setMaxHeight(maxSize.height)\n }\n },\n }, [areSectionsAligned, horizontalSpacing, isReversed, sections, verticalSpacing])\n\n useEffect(() => {\n const imageSources = getAllImageSources(rootRef.current?.innerHTML)\n\n if (imageSources.length === 0) return repositionChildren()\n\n const numImages = imageSources.length\n\n for (let i = 0; i < numImages; i++) {\n const src = imageSources[i]\n const image = new Image()\n image.src = src\n image.onload = () => repositionChildren()\n }\n }, [children])\n\n return (\n <StyledRoot\n {...props}\n ref={rootRef}\n orientation={orientation}\n style={{\n ...style,\n flex: '0 0 auto',\n minHeight: ((orientation === 'vertical' && !isNaN(minHeight)) ? `${minHeight}px` : ''),\n minWidth: ((orientation === 'horizontal' && !isNaN(minWidth)) ? `${minWidth}px` : ''),\n padding: '0',\n }}\n >\n {children}\n </StyledRoot>\n )\n}\n\nconst StyledRoot = styled.div<{\n orientation: Props['orientation']\n}>`\n box-sizing: border-box;\n display: block;\n height: ${props => props.orientation === 'vertical' ? 'auto' : '100%'};\n position: relative;\n width: ${props => props.orientation === 'horizontal' ? 'auto' : '100%'};\n`\n"]}
|
package/lib/Repeat.d.ts
CHANGED
package/lib/Repeat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Repeat.js","sourceRoot":"/","sources":["Repeat.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Repeat.js","sourceRoot":"/","sources":["Repeat.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAkD;AAOlD;;GAEG;AACH,SAAwB,MAAM,CAAC,EAGvB;QAFN,aAAS,EAAT,KAAK,mBAAG,CAAC,KAAA,EACT,QAAQ,cAAA;IAER,OAAO,CACL,8DACG,yBAAI,KAAK,CAAC,KAAK,CAAC,UAAE,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAC/B,8BAAC,gBAAQ,IAAC,GAAG,EAAE,kBAAW,CAAC,CAAE,IAC1B,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAC/C,CACZ,EAJgC,CAIhC,CAAC,CACD,CACJ,CAAA;AACH,CAAC;AAbD,yBAaC","sourcesContent":["import React, { Fragment, ReactNode } from 'react'\n\nexport type Props = {\n children: ReactNode | ((index: number) => ReactNode)\n count?: number\n}\n\n/**\n * A tag-less component that repeats its children, automatically assigning each a unique key.\n */\nexport default function Repeat({\n count = 1,\n children,\n}: Props) {\n return (\n <>\n {[...Array(count)].map((_, i) => (\n <Fragment key={`element-${i}`}>\n {typeof children === 'function' ? children(i) : children}\n </Fragment>\n ))}\n </>\n )\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HTMLAttributes } from 'react';
|
|
2
|
-
export declare type Props = HTMLAttributes<HTMLButtonElement> & {
|
|
3
|
-
children?: (props: Pick<Props, 'isDeselectable' | 'isDisabled' | 'isSelected' | 'label'>) =>
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export declare type Props = Omit<HTMLAttributes<HTMLButtonElement>, 'children'> & {
|
|
3
|
+
children?: (props: Pick<Props, 'isDeselectable' | 'isDisabled' | 'isSelected' | 'label'>) => ReactNode;
|
|
4
4
|
isDeselectable?: boolean;
|
|
5
5
|
isDisabled?: boolean;
|
|
6
6
|
isSelected?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectableButton.js","sourceRoot":"/","sources":["SelectableButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"SelectableButton.js","sourceRoot":"/","sources":["SelectableButton.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA6E;AAC7E,wEAAsC;AAYtC,SAAwB,gBAAgB,CAAC,EASjC;;IARN,IAAA,QAAQ,cAAA,EACR,sBAAsB,EAAtB,cAAc,mBAAG,KAAK,KAAA,EACtB,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAClB,kBAAsC,EAA1B,kBAAkB,mBAAG,KAAK,KAAA,EACtC,KAAK,WAAA,EACL,UAAU,gBAAA,EACV,QAAQ,cAAA,EACL,KAAK,cAR+B,6FASxC,CADS;IAEF,IAAA,KAAA,OAA8B,IAAA,gBAAQ,EAAC,kBAAkB,CAAC,IAAA,EAAzD,UAAU,QAAA,EAAE,aAAa,QAAgC,CAAA;IAEhE,IAAM,eAAe,GAAG;QACtB,IAAI,UAAU;YAAE,OAAM;QAEtB,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,cAAc;gBAAE,OAAM;YAC3B,aAAa,CAAC,KAAK,CAAC,CAAA;YACpB,UAAU,aAAV,UAAU,uBAAV,UAAU,EAAI,CAAA;SACf;aACI;YACH,aAAa,CAAC,IAAI,CAAC,CAAA;YACnB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,EAAI,CAAA;SACb;IACH,CAAC,CAAA;IAED,IAAA,iBAAS,EAAC;QACR,aAAa,CAAC,kBAAkB,CAAC,CAAA;IACnC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAA;IAExB,OAAO,CACL,8BAAC,UAAU,eAAK,KAAK,IAAE,OAAO,EAAE,cAAM,OAAA,eAAe,EAAE,EAAjB,CAAiB,EAAE,QAAQ,EAAE,UAAU,IAAI,CAAC,UAAU,IAAI,CAAC,cAAc,CAAC,KAC7G,MAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,EAAE,cAAc,gBAAA,EAAE,UAAU,YAAA,EAAE,UAAU,YAAA,EAAE,KAAK,OAAA,EAAE,CAAC,mCAAI,KAAK,CAC5D,CACd,CAAA;AACH,CAAC;AAnCD,mCAmCC;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,MAAM,wHAAA,qDAI/B,IAAA,CAAA","sourcesContent":["import React, { HTMLAttributes, ReactNode, useEffect, useState } from 'react'\nimport styled from 'styled-components'\n\nexport type Props = Omit<HTMLAttributes<HTMLButtonElement>, 'children'> & {\n children?: (props: Pick<Props, 'isDeselectable' | 'isDisabled' | 'isSelected' | 'label'>) => ReactNode\n isDeselectable?: boolean\n isDisabled?: boolean\n isSelected?: boolean\n label?: string\n onDeselect?: () => void\n onSelect?: () => void\n}\n\nexport default function SelectableButton({\n children,\n isDeselectable = false,\n isDisabled = false,\n isSelected: externalIsSelected = false,\n label,\n onDeselect,\n onSelect,\n ...props\n}: Props) {\n const [isSelected, setIsSelected] = useState(externalIsSelected)\n\n const toggleSelection = () => {\n if (isDisabled) return\n\n if (isSelected) {\n if (!isDeselectable) return\n setIsSelected(false)\n onDeselect?.()\n }\n else {\n setIsSelected(true)\n onSelect?.()\n }\n }\n\n useEffect(() => {\n setIsSelected(externalIsSelected)\n }, [externalIsSelected])\n\n return (\n <StyledRoot {...props} onClick={() => toggleSelection()} disabled={isDisabled || (isSelected && !isDeselectable)}>\n {children?.({ isDeselectable, isDisabled, isSelected, label }) ?? label}\n </StyledRoot>\n )\n}\n\nconst StyledRoot = styled.button`\n &[disabled] {\n pointer-events: none;\n }\n`\n"]}
|
package/lib/SwipeContainer.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { HTMLAttributes
|
|
2
|
-
declare type Props = HTMLAttributes<HTMLDivElement> &
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
declare type Props = HTMLAttributes<HTMLDivElement> & {
|
|
3
3
|
isEnabled?: boolean;
|
|
4
4
|
threshold?: number;
|
|
5
5
|
onSwipeDown?: () => void;
|
|
6
6
|
onSwipeLeft?: () => void;
|
|
7
7
|
onSwipeRight?: () => void;
|
|
8
8
|
onSwipeUp?: () => void;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
/**
|
|
11
11
|
* An empty component with a backing `<div>` element that detects swipe gestures.
|
|
12
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwipeContainer.js","sourceRoot":"/","sources":["SwipeContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA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,EAAX,CAAW,EAC5B,YAAY,EAAE,cAAM,OAAA,YAAY,EAAE,EAAd,CAAc,KAEjC,QAAQ,CACE,CACd,CAAA;AACH,CAAC;AAzFD,iCAyFC;AAED,IAAM,UAAU,GAAG,2BAAM,CAAC,GAAG,yEAAA,MAE5B,IAAA,CAAA","sourcesContent":["import React, { HTMLAttributes, useState } from 'react'\nimport { Point } from 'spase'\nimport styled from 'styled-components'\n\ntype Props = HTMLAttributes<HTMLDivElement> & {\n isEnabled?: boolean\n threshold?: number\n onSwipeDown?: () => void\n onSwipeLeft?: () => void\n onSwipeRight?: () => void\n onSwipeUp?: () => void\n}\n\n/**\n * An empty component with a backing `<div>` element that detects swipe gestures.\n */\nexport default function SwipeContainer({\n children,\n isEnabled = true,\n threshold = 0.5,\n onSwipeDown,\n onSwipeLeft,\n onSwipeRight,\n onSwipeUp,\n ...props\n}: Props) {\n const [dragStartPosition, setDragStartPosition] = useState<Point | undefined>(undefined)\n const [dragEndPosition, setDragEndPosition] = useState<Point | undefined>(undefined)\n const [dragStartTime, setDragStartTime] = useState(NaN)\n\n const onDragStart = (x: number, y: number) => {\n if (isNaN(x) || isNaN(y)) return onDragCancel()\n setDragStartPosition(new Point([x, y]))\n }\n\n const onDragMove = (x: number, y: number) => {\n const startPosition = dragStartPosition\n\n if (startPosition === undefined) return\n\n const hasMovement = startPosition.x !== x || startPosition.y !== y\n const hasStartTime = !isNaN(dragStartTime)\n\n if (!hasMovement) return\n\n if (!hasStartTime) setDragStartTime(Date.now())\n\n setDragEndPosition(new Point([x, y]))\n }\n\n const onDragEnd = () => {\n const time = dragStartTime\n const startPosition = dragStartPosition\n const endPosition = dragEndPosition\n\n if (isNaN(time) || startPosition === undefined || endPosition === undefined) return\n\n const dt = Date.now() - time\n const dx = endPosition.x - startPosition.x\n const dy = endPosition.y - endPosition.y\n const vx = dx / dt\n const vy = dy / dt\n\n if (isEnabled) {\n if (Math.abs(vx) >= threshold && Math.abs(vx) > Math.abs(vy)) {\n if (vx > 0) {\n onSwipeRight?.()\n }\n else {\n onSwipeLeft?.()\n }\n }\n else if (Math.abs(vy) >= threshold && Math.abs(vy) > Math.abs(vx)) {\n if (vy > 0) {\n onSwipeDown?.()\n }\n else {\n onSwipeUp?.()\n }\n }\n }\n\n onDragCancel()\n }\n\n const onDragCancel = () => {\n setDragStartPosition(undefined)\n setDragEndPosition(undefined)\n setDragStartTime(NaN)\n }\n\n return (\n <StyledRoot\n {...props}\n onTouchStart={event => onDragStart(event.targetTouches[0].clientX, event.targetTouches[0].clientY)}\n onTouchMove={event => onDragMove(event.targetTouches[0].clientX, event.targetTouches[0].clientY)}\n onTouchEnd={() => onDragEnd()}\n onMouseDown={event => onDragStart(event.clientX, event.clientY)}\n onMouseMove={event => onDragMove(event.clientX, event.clientY)}\n onMouseUp={() => onDragEnd()}\n onMouseLeave={() => onDragCancel()}\n >\n {children}\n </StyledRoot>\n )\n}\n\nconst StyledRoot = styled.div`\n\n`\n"]}
|
package/lib/WithTooltip.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HTMLAttributes
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
2
|
import { CSSProp } from 'styled-components';
|
|
3
|
-
export declare type Props =
|
|
3
|
+
export declare type Props = HTMLAttributes<HTMLElement> & {
|
|
4
4
|
/**
|
|
5
5
|
* The height of the arrow. The width (longest edge) of the arrow is always twice its height.
|
|
6
6
|
*/
|
package/lib/WithTooltip.js
CHANGED
|
@@ -72,6 +72,7 @@ var react_1 = __importStar(require("react"));
|
|
|
72
72
|
var spase_1 = require("spase");
|
|
73
73
|
var styled_components_1 = __importStar(require("styled-components"));
|
|
74
74
|
var ExtractChild_1 = __importDefault(require("./ExtractChild"));
|
|
75
|
+
var useElementRect_1 = __importDefault(require("./hooks/useElementRect"));
|
|
75
76
|
function WithTooltip(_a) {
|
|
76
77
|
var _b = _a.arrowHeight, arrowHeight = _b === void 0 ? 8 : _b, _c = _a.backgroundColor, backgroundColor = _c === void 0 ? '#000' : _c, cssDialog = _a.cssDialog, _d = _a.disabledOnTouch, disabledOnTouch = _d === void 0 ? true : _d, hint = _a.hint, _e = _a.gap, gap = _e === void 0 ? 5 : _e, _f = _a.textColor, textColor = _f === void 0 ? '#fff' : _f, _g = _a.threshold, threshold = _g === void 0 ? 100 : _g, props = __rest(_a, ["arrowHeight", "backgroundColor", "cssDialog", "disabledOnTouch", "hint", "gap", "textColor", "threshold"]);
|
|
77
78
|
var computeAlignment = function (target, threshold) {
|
|
@@ -127,13 +128,14 @@ function WithTooltip(_a) {
|
|
|
127
128
|
var _h = __read((0, react_1.useState)(new spase_1.Size()), 2), textSize = _h[0], setTextSize = _h[1];
|
|
128
129
|
var _j = __read((0, react_1.useState)(undefined), 2), alignment = _j[0], setAlignment = _j[1];
|
|
129
130
|
var childRef = (0, react_1.useRef)(null);
|
|
131
|
+
var childRect = (0, useElementRect_1.default)(childRef);
|
|
130
132
|
(0, react_1.useEffect)(function () {
|
|
131
133
|
var childNode = childRef.current;
|
|
132
134
|
if (!childNode)
|
|
133
135
|
return;
|
|
134
136
|
setAlignment(computeAlignment(childNode, threshold));
|
|
135
137
|
setTextSize(computeTextSize(childNode, threshold));
|
|
136
|
-
}, []);
|
|
138
|
+
}, [childRect]);
|
|
137
139
|
return (react_1.default.createElement(StyledRoot, __assign({ arrowHeight: arrowHeight, backgroundColor: backgroundColor, ref: childRef, cssDialog: cssDialog, disabledOnTouch: disabledOnTouch, hint: hint, gap: gap, onMouseOver: function (event) { return onMouseOver(event); }, alignment: alignment, textColor: textColor, textSize: textSize }, props)));
|
|
138
140
|
}
|
|
139
141
|
exports.default = WithTooltip;
|
package/lib/WithTooltip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WithTooltip.js","sourceRoot":"/","sources":["WithTooltip.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,eAAe,EAArB,CAAqB,EACnC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EACrB,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,IAAI,EAAV,CAAU,EAS7B,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,QAAI,uBAAG,sIAAA,iBACxC,EAA+D,WACtE,EAAkE,UAClE,EAAoE,UACpE,EAA8D,QACjE,KAJU,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,UAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,OAAI,CAAC,CAAC,CAAC,MAAM,EACtE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,EAClE,qBAAqB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,EACpE,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,EAAE,CACjE,EALU,CAKV,EAGD,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,SAAS,EAA9D,CAA8D,CAI1E,CAAA","sourcesContent":["import React, { HTMLAttributes, MouseEvent, PropsWithChildren, RefObject, useEffect, useRef, useState } from 'react'\nimport { Rect, Size } from 'spase'\nimport styled, { css, CSSProp } from 'styled-components'\nimport ExtractChild from './ExtractChild'\n\nexport type Props = PropsWithChildren<HTMLAttributes<HTMLElement>> & {\n /**\n * The height of the arrow. The width (longest edge) of the arrow is always twice its height.\n */\n arrowHeight?: number\n\n /**\n * Color of the dialog background, same format as a CSS color string (i.e. '#000').\n */\n backgroundColor?: string\n\n /**\n * Specifies if the tooltip should be disabled in touch devices (i.e. `html` has class `.touch`).\n */\n disabledOnTouch?: boolean\n\n /**\n * The hint string to display in the tooltip.\n */\n hint: string\n\n /**\n * The gap (in pixels) between the target element and the tooltip, defaults to zero.\n */\n gap?: number\n\n /**\n * Color of the dialog text, same format as a CSS color string (i.e. '#000').\n */\n textColor?: string\n\n /**\n * The minimum space (in pixels) between the target element and the edge of the window required to\n * trigger an alignment change, defaults to `100px`.\n */\n threshold?: number\n\n /**\n * Custom CSS provided to the dialog. Not all CSS rules will take effect as they will be\n * overridden by internal rules.\n */\n cssDialog?: CSSProp<any>\n}\n\ntype Alignment = 'tl' | 'tc' | 'tr' | 'cl' | 'cr' | 'bl' | 'bc' | 'br'\n\nexport default function WithTooltip({\n arrowHeight = 8,\n backgroundColor = '#000',\n cssDialog,\n disabledOnTouch = true,\n hint,\n gap = 5,\n textColor = '#fff',\n threshold = 100,\n ...props\n}: Props) {\n const computeAlignment = (target: Element, threshold: number): Alignment => {\n const vrect = Rect.fromViewport()\n const rect = Rect.intersecting(target)\n\n if (rect) {\n const leftBound = (rect.left - vrect.left) < threshold\n const rightBound = (vrect.right - rect.right) < threshold\n const topBound = (rect.top - vrect.top) < threshold\n const bottomBound = (vrect.bottom - rect.bottom) < threshold\n\n if (leftBound && topBound) return 'br'\n if (leftBound && bottomBound) return 'tr'\n if (rightBound && topBound) return 'bl'\n if (rightBound && bottomBound) return 'tl'\n if (leftBound) return 'cr'\n if (rightBound) return 'cl'\n if (bottomBound) return 'tc'\n }\n\n return 'bc'\n }\n\n const computeTextSize = (target: Element, threshold: number): Size => {\n const computedStyle = window.getComputedStyle(target, '::after')\n const div = document.createElement('div')\n div.innerHTML = hint\n div.style.fontFamily = computedStyle.getPropertyValue('font-family')\n div.style.fontSize = computedStyle.getPropertyValue('font-size')\n div.style.fontStyle = computedStyle.getPropertyValue('font-style')\n div.style.fontVariant = computedStyle.getPropertyValue('font-variant')\n div.style.fontWeight = computedStyle.getPropertyValue('font-weight')\n div.style.left = '0'\n div.style.position = 'absolute'\n div.style.top = '0'\n div.style.visibility = 'hidden'\n div.style.whiteSpace = 'pre'\n\n document.body.appendChild(div)\n\n // Add 1px as buffer to mitigate precision discrepancies.\n const width = div.clientWidth + 1\n const height = div.clientHeight + 1\n\n document.body.removeChild(div)\n\n return new Size([width, height])\n }\n\n const onMouseOver = (event: MouseEvent) => {\n setAlignment(computeAlignment(event.currentTarget, threshold))\n setTextSize(computeTextSize(event.currentTarget, threshold))\n }\n\n const [textSize, setTextSize] = useState<Size | undefined>(new Size())\n const [alignment, setAlignment] = useState<Alignment | undefined>(undefined)\n\n const childRef = useRef<HTMLElement>(null)\n\n useEffect(() => {\n const childNode = childRef.current\n if (!childNode) return\n setAlignment(computeAlignment(childNode, threshold))\n setTextSize(computeTextSize(childNode, threshold))\n }, [])\n\n return (\n <StyledRoot\n arrowHeight={arrowHeight}\n backgroundColor={backgroundColor}\n ref={childRef}\n cssDialog={cssDialog}\n disabledOnTouch={disabledOnTouch}\n hint={hint}\n gap={gap}\n onMouseOver={event => onMouseOver(event)}\n alignment={alignment}\n textColor={textColor}\n textSize={textSize}\n {...props}\n />\n )\n}\n\nfunction makeDisplacementCSS(alignment: Alignment, arrowHeight: number, gap: number): CSSProp {\n switch (alignment) {\n case 'tl': return css`top: ${-arrowHeight}px; left: calc(50% + ${arrowHeight*2.5}px);`\n case 'tc': return css`top: ${-arrowHeight}px; left: 50%;`\n case 'tr': return css`top: ${-arrowHeight}px; right: calc(50% + ${arrowHeight*2.5}px);`\n case 'cl': return css`top: 50%; left: ${-arrowHeight}px;`\n case 'cr': return css`top: 50%; right: ${-arrowHeight}px;`\n case 'bl': return css`bottom: ${-arrowHeight}px; left: calc(50% + ${arrowHeight*2.5}px);`\n case 'bc': return css`bottom: ${-arrowHeight}px; left: 50%;`\n case 'br': return css`bottom: ${-arrowHeight}px; right: calc(50% + ${arrowHeight*2.5}px);`\n }\n}\n\nfunction makeDialogPositionCSS(alignment: Alignment, arrowHeight: number, gap: number): CSSProp {\n switch (alignment) {\n case 'tl': return css`transform: translate3d(calc(-100% - ${gap}px), calc(-100% - ${gap}px), 0);`\n case 'tc': return css`transform: translate3d(-50%, calc(-100% - ${gap}px), 0);`\n case 'tr': return css`transform: translate3d(calc(100% + ${gap}px), calc(-100% - ${gap}px), 0);`\n case 'cl': return css`transform: translate3d(calc(-100% - ${gap}px), -50%, 0);`\n case 'cr': return css`transform: translate3d(calc(100% + ${gap}px), -50%, 0);`\n case 'bl': return css`transform: translate3d(calc(-100% - ${gap}px), calc(100% + ${gap}px), 0);`\n case 'bc': return css`transform: translate3d(-50%, calc(100% + ${gap}px), 0);`\n case 'br': return css`transform: translate3d(calc(100% + ${gap}px), calc(100% + ${gap}px), 0);`\n }\n}\n\nfunction makeArrowPositionCSS(alignment: Alignment, arrowHeight: number, gap: number, color: string): CSSProp {\n return css`\n ${() => {\n switch (alignment) {\n case 'tl': return css`border-color: ${color} transparent transparent transparent;`\n case 'tc': return css`border-color: ${color} transparent transparent transparent;`\n case 'tr': return css`border-color: ${color} transparent transparent transparent;`\n case 'cl': return css`border-color: transparent transparent transparent ${color};`\n case 'cr': return css`border-color: transparent ${color} transparent transparent;`\n case 'bl': return css`border-color: transparent transparent ${color} transparent;`\n case 'bc': return css`border-color: transparent transparent ${color} transparent;`\n case 'br': return css`border-color: transparent transparent ${color} transparent;`\n }\n }}\n\n ${() => {\n switch (alignment) {\n case 'tl': return css`transform: translate3d(calc(0% - ${gap}px - ${arrowHeight*3}px), calc(0% - ${gap}px), 0);`\n case 'tc': return css`transform: translate3d(-50%, calc(0% - ${gap}px), 0);`\n case 'tr': return css`transform: translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% - ${gap}px), 0);`\n case 'cl': return css`transform: translate3d(calc(0% - ${gap}px), -50%, 0);`\n case 'cr': return css`transform: translate3d(calc(0% + ${gap}px), -50%, 0);`\n case 'bl': return css`transform: translate3d(calc(0% - ${gap}px - ${arrowHeight*3}px), calc(0% + ${gap}px), 0);`\n case 'bc': return css`transform: translate3d(-50%, calc(0% + ${gap}px), 0);`\n case 'br': return css`transform: translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% + ${gap}px), 0);`\n }\n }}\n `\n}\n\nconst StyledRoot = styled(ExtractChild)<{\n arrowHeight: number\n backgroundColor: string\n ref: RefObject<HTMLElement>\n cssDialog?: CSSProp\n disabledOnTouch: boolean\n hint: string\n gap: number\n alignment?: Alignment\n textColor: string\n textSize?: Size\n}>`\n cursor: pointer;\n position: relative;\n\n &::before {\n border-style: solid;\n border-width: ${props => props.arrowHeight}px;\n content: '';\n height: 0;\n opacity: 0;\n pointer-events: none;\n position: absolute;\n transition: opacity 200ms ease-out;\n width: 0;\n z-index: 10001;\n\n ${props => props.alignment && props.textSize && css`\n ${makeDisplacementCSS(props.alignment, props.arrowHeight, props.gap)}\n ${makeArrowPositionCSS(props.alignment, props.arrowHeight, props.gap, props.backgroundColor)}\n ${props.disabledOnTouch ? 'html.touch & { display: none; }' : ''}\n `}\n }\n\n &::after {\n box-sizing: content-box;\n font-size: 12px;\n max-width: 200px;\n padding: 10px 14px;\n text-align: left;\n\n ${props => props.cssDialog}\n\n background: ${props => props.backgroundColor};\n color: ${props => props.textColor};\n content: '${props => props.hint}';\n opacity: 0;\n overflow: hidden;\n pointer-events: none;\n position: absolute;\n transform: translate3d(0, 0, 0);\n transition: opacity 200ms ease-out;\n z-index: 10000;\n\n ${props => props.alignment && props.textSize && css`\n width: ${props.textSize.width > 0 ? `${props.textSize.width}px` : 'auto'};\n ${makeDisplacementCSS(props.alignment, props.arrowHeight, props.gap)}\n ${makeDialogPositionCSS(props.alignment, props.arrowHeight, props.gap)}\n ${props.disabledOnTouch ? 'html.touch & { display: none; }' : ''}\n `}\n }\n\n ${props => props.disabledOnTouch ? 'html:not(.touch) &:hover' : '&:hover'} {\n &::before { opacity: 1; }\n &::after { opacity: 1; }\n }\n`\n"]}
|
|
1
|
+
{"version":3,"file":"WithTooltip.js","sourceRoot":"/","sources":["WithTooltip.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAC,CAAC,EAAE,CACjE,EAJU,CAIV,EAUC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EAEZ,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,eAAe,EAArB,CAAqB,EACnC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,EAAf,CAAe,EACrB,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,IAAI,EAAV,CAAU,EAS7B,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,QAAI,uBAAG,sIAAA,iBACxC,EAA+D,WACtE,EAAkE,UAClE,EAAoE,UACpE,EAA8D,QACjE,KAJU,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,UAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,OAAI,CAAC,CAAC,CAAC,MAAM,EACtE,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,EAClE,qBAAqB,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,EACpE,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC,EAAE,CACjE,EALU,CAKV,EAGD,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,SAAS,EAA9D,CAA8D,CAI1E,CAAA","sourcesContent":["import React, { HTMLAttributes, MouseEvent, RefObject, useEffect, useRef, useState } from 'react'\nimport { Rect, Size } from 'spase'\nimport styled, { css, CSSProp } from 'styled-components'\nimport ExtractChild from './ExtractChild'\nimport useElementRect from './hooks/useElementRect'\n\nexport type Props = HTMLAttributes<HTMLElement> & {\n /**\n * The height of the arrow. The width (longest edge) of the arrow is always twice its height.\n */\n arrowHeight?: number\n\n /**\n * Color of the dialog background, same format as a CSS color string (i.e. '#000').\n */\n backgroundColor?: string\n\n /**\n * Specifies if the tooltip should be disabled in touch devices (i.e. `html` has class `.touch`).\n */\n disabledOnTouch?: boolean\n\n /**\n * The hint string to display in the tooltip.\n */\n hint: string\n\n /**\n * The gap (in pixels) between the target element and the tooltip, defaults to zero.\n */\n gap?: number\n\n /**\n * Color of the dialog text, same format as a CSS color string (i.e. '#000').\n */\n textColor?: string\n\n /**\n * The minimum space (in pixels) between the target element and the edge of the window required to\n * trigger an alignment change, defaults to `100px`.\n */\n threshold?: number\n\n /**\n * Custom CSS provided to the dialog. Not all CSS rules will take effect as they will be\n * overridden by internal rules.\n */\n cssDialog?: CSSProp<any>\n}\n\ntype Alignment = 'tl' | 'tc' | 'tr' | 'cl' | 'cr' | 'bl' | 'bc' | 'br'\n\nexport default function WithTooltip({\n arrowHeight = 8,\n backgroundColor = '#000',\n cssDialog,\n disabledOnTouch = true,\n hint,\n gap = 5,\n textColor = '#fff',\n threshold = 100,\n ...props\n}: Props) {\n const computeAlignment = (target: Element, threshold: number): Alignment => {\n const vrect = Rect.fromViewport()\n const rect = Rect.intersecting(target)\n\n if (rect) {\n const leftBound = (rect.left - vrect.left) < threshold\n const rightBound = (vrect.right - rect.right) < threshold\n const topBound = (rect.top - vrect.top) < threshold\n const bottomBound = (vrect.bottom - rect.bottom) < threshold\n\n if (leftBound && topBound) return 'br'\n if (leftBound && bottomBound) return 'tr'\n if (rightBound && topBound) return 'bl'\n if (rightBound && bottomBound) return 'tl'\n if (leftBound) return 'cr'\n if (rightBound) return 'cl'\n if (bottomBound) return 'tc'\n }\n\n return 'bc'\n }\n\n const computeTextSize = (target: Element, threshold: number): Size => {\n const computedStyle = window.getComputedStyle(target, '::after')\n const div = document.createElement('div')\n div.innerHTML = hint\n div.style.fontFamily = computedStyle.getPropertyValue('font-family')\n div.style.fontSize = computedStyle.getPropertyValue('font-size')\n div.style.fontStyle = computedStyle.getPropertyValue('font-style')\n div.style.fontVariant = computedStyle.getPropertyValue('font-variant')\n div.style.fontWeight = computedStyle.getPropertyValue('font-weight')\n div.style.left = '0'\n div.style.position = 'absolute'\n div.style.top = '0'\n div.style.visibility = 'hidden'\n div.style.whiteSpace = 'pre'\n\n document.body.appendChild(div)\n\n // Add 1px as buffer to mitigate precision discrepancies.\n const width = div.clientWidth + 1\n const height = div.clientHeight + 1\n\n document.body.removeChild(div)\n\n return new Size([width, height])\n }\n\n const onMouseOver = (event: MouseEvent) => {\n setAlignment(computeAlignment(event.currentTarget, threshold))\n setTextSize(computeTextSize(event.currentTarget, threshold))\n }\n\n const [textSize, setTextSize] = useState<Size | undefined>(new Size())\n const [alignment, setAlignment] = useState<Alignment | undefined>(undefined)\n const childRef = useRef<HTMLElement>(null)\n const childRect = useElementRect(childRef)\n\n useEffect(() => {\n const childNode = childRef.current\n if (!childNode) return\n setAlignment(computeAlignment(childNode, threshold))\n setTextSize(computeTextSize(childNode, threshold))\n }, [childRect])\n\n return (\n <StyledRoot\n arrowHeight={arrowHeight}\n backgroundColor={backgroundColor}\n ref={childRef}\n cssDialog={cssDialog}\n disabledOnTouch={disabledOnTouch}\n hint={hint}\n gap={gap}\n onMouseOver={event => onMouseOver(event)}\n alignment={alignment}\n textColor={textColor}\n textSize={textSize}\n {...props}\n />\n )\n}\n\nfunction makeDisplacementCSS(alignment: Alignment, arrowHeight: number, gap: number): CSSProp {\n switch (alignment) {\n case 'tl': return css`top: ${-arrowHeight}px; left: calc(50% + ${arrowHeight*2.5}px);`\n case 'tc': return css`top: ${-arrowHeight}px; left: 50%;`\n case 'tr': return css`top: ${-arrowHeight}px; right: calc(50% + ${arrowHeight*2.5}px);`\n case 'cl': return css`top: 50%; left: ${-arrowHeight}px;`\n case 'cr': return css`top: 50%; right: ${-arrowHeight}px;`\n case 'bl': return css`bottom: ${-arrowHeight}px; left: calc(50% + ${arrowHeight*2.5}px);`\n case 'bc': return css`bottom: ${-arrowHeight}px; left: 50%;`\n case 'br': return css`bottom: ${-arrowHeight}px; right: calc(50% + ${arrowHeight*2.5}px);`\n }\n}\n\nfunction makeDialogPositionCSS(alignment: Alignment, arrowHeight: number, gap: number): CSSProp {\n switch (alignment) {\n case 'tl': return css`transform: translate3d(calc(-100% - ${gap}px), calc(-100% - ${gap}px), 0);`\n case 'tc': return css`transform: translate3d(-50%, calc(-100% - ${gap}px), 0);`\n case 'tr': return css`transform: translate3d(calc(100% + ${gap}px), calc(-100% - ${gap}px), 0);`\n case 'cl': return css`transform: translate3d(calc(-100% - ${gap}px), -50%, 0);`\n case 'cr': return css`transform: translate3d(calc(100% + ${gap}px), -50%, 0);`\n case 'bl': return css`transform: translate3d(calc(-100% - ${gap}px), calc(100% + ${gap}px), 0);`\n case 'bc': return css`transform: translate3d(-50%, calc(100% + ${gap}px), 0);`\n case 'br': return css`transform: translate3d(calc(100% + ${gap}px), calc(100% + ${gap}px), 0);`\n }\n}\n\nfunction makeArrowPositionCSS(alignment: Alignment, arrowHeight: number, gap: number, color: string): CSSProp {\n return css`\n ${() => {\n switch (alignment) {\n case 'tl': return css`border-color: ${color} transparent transparent transparent;`\n case 'tc': return css`border-color: ${color} transparent transparent transparent;`\n case 'tr': return css`border-color: ${color} transparent transparent transparent;`\n case 'cl': return css`border-color: transparent transparent transparent ${color};`\n case 'cr': return css`border-color: transparent ${color} transparent transparent;`\n case 'bl': return css`border-color: transparent transparent ${color} transparent;`\n case 'bc': return css`border-color: transparent transparent ${color} transparent;`\n case 'br': return css`border-color: transparent transparent ${color} transparent;`\n }\n }}\n\n ${() => {\n switch (alignment) {\n case 'tl': return css`transform: translate3d(calc(0% - ${gap}px - ${arrowHeight*3}px), calc(0% - ${gap}px), 0);`\n case 'tc': return css`transform: translate3d(-50%, calc(0% - ${gap}px), 0);`\n case 'tr': return css`transform: translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% - ${gap}px), 0);`\n case 'cl': return css`transform: translate3d(calc(0% - ${gap}px), -50%, 0);`\n case 'cr': return css`transform: translate3d(calc(0% + ${gap}px), -50%, 0);`\n case 'bl': return css`transform: translate3d(calc(0% - ${gap}px - ${arrowHeight*3}px), calc(0% + ${gap}px), 0);`\n case 'bc': return css`transform: translate3d(-50%, calc(0% + ${gap}px), 0);`\n case 'br': return css`transform: translate3d(calc(100% + ${gap}px + ${arrowHeight}px), calc(0% + ${gap}px), 0);`\n }\n }}\n `\n}\n\nconst StyledRoot = styled(ExtractChild)<{\n arrowHeight: number\n backgroundColor: string\n ref: RefObject<HTMLElement>\n cssDialog?: CSSProp\n disabledOnTouch: boolean\n hint: string\n gap: number\n alignment?: Alignment\n textColor: string\n textSize?: Size\n}>`\n cursor: pointer;\n position: relative;\n\n &::before {\n border-style: solid;\n border-width: ${props => props.arrowHeight}px;\n content: '';\n height: 0;\n opacity: 0;\n pointer-events: none;\n position: absolute;\n transition: opacity 200ms ease-out;\n width: 0;\n z-index: 10001;\n\n ${props => props.alignment && props.textSize && css`\n ${makeDisplacementCSS(props.alignment, props.arrowHeight, props.gap)}\n ${makeArrowPositionCSS(props.alignment, props.arrowHeight, props.gap, props.backgroundColor)}\n ${props.disabledOnTouch ? 'html.touch & { display: none; }' : ''}\n `}\n }\n\n &::after {\n box-sizing: content-box;\n font-size: 12px;\n max-width: 200px;\n padding: 10px 14px;\n text-align: left;\n\n ${props => props.cssDialog}\n\n background: ${props => props.backgroundColor};\n color: ${props => props.textColor};\n content: '${props => props.hint}';\n opacity: 0;\n overflow: hidden;\n pointer-events: none;\n position: absolute;\n transform: translate3d(0, 0, 0);\n transition: opacity 200ms ease-out;\n z-index: 10000;\n\n ${props => props.alignment && props.textSize && css`\n width: ${props.textSize.width > 0 ? `${props.textSize.width}px` : 'auto'};\n ${makeDisplacementCSS(props.alignment, props.arrowHeight, props.gap)}\n ${makeDialogPositionCSS(props.alignment, props.arrowHeight, props.gap)}\n ${props.disabledOnTouch ? 'html.touch & { display: none; }' : ''}\n `}\n }\n\n ${props => props.disabledOnTouch ? 'html:not(.touch) &:hover' : '&:hover'} {\n &::before { opacity: 1; }\n &::after { opacity: 1; }\n }\n`\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { Rect } from 'spase';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for monitoring changes in and returning the size and position of the target element.
|
|
5
|
+
*
|
|
6
|
+
* @param targetRef - Reference to the target element.
|
|
7
|
+
*
|
|
8
|
+
* @returns The most current {@link Rect} of the target element.
|
|
9
|
+
*/
|
|
10
|
+
export default function useElementRect(targetRef: RefObject<Element>): Rect;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
var react_1 = require("react");
|
|
23
|
+
var resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
|
|
24
|
+
var spase_1 = require("spase");
|
|
25
|
+
/**
|
|
26
|
+
* Hook for monitoring changes in and returning the size and position of the target element.
|
|
27
|
+
*
|
|
28
|
+
* @param targetRef - Reference to the target element.
|
|
29
|
+
*
|
|
30
|
+
* @returns The most current {@link Rect} of the target element.
|
|
31
|
+
*/
|
|
32
|
+
function useElementRect(targetRef) {
|
|
33
|
+
var observerRef = (0, react_1.useRef)(undefined);
|
|
34
|
+
var _a = __read((0, react_1.useState)(new spase_1.Rect()), 2), rect = _a[0], setRect = _a[1];
|
|
35
|
+
(0, react_1.useEffect)(function () {
|
|
36
|
+
observerRef.current = new resize_observer_polyfill_1.default(function () {
|
|
37
|
+
var rect = spase_1.Rect.from(targetRef.current);
|
|
38
|
+
if (!rect)
|
|
39
|
+
return;
|
|
40
|
+
setRect(rect);
|
|
41
|
+
});
|
|
42
|
+
if (observerRef.current && targetRef.current) {
|
|
43
|
+
observerRef.current.observe(targetRef.current);
|
|
44
|
+
}
|
|
45
|
+
return function () {
|
|
46
|
+
if (observerRef.current && targetRef.current) {
|
|
47
|
+
observerRef.current.unobserve(targetRef.current);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}, [targetRef]);
|
|
51
|
+
return rect;
|
|
52
|
+
}
|
|
53
|
+
exports.default = useElementRect;
|
|
54
|
+
//# sourceMappingURL=useElementRect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useElementRect.js","sourceRoot":"/","sources":["hooks/useElementRect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+BAA8D;AAC9D,sFAAqD;AACrD,+BAA4B;AAE5B;;;;;;GAMG;AACH,SAAwB,cAAc,CAAC,SAA6B;IAClE,IAAM,WAAW,GAAG,IAAA,cAAM,EAA6B,SAAS,CAAC,CAAA;IAC3D,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,OAAO,GAAG,IAAI,kCAAc,CAAC;YACvC,IAAM,IAAI,GAAG,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAEzC,IAAI,CAAC,IAAI;gBAAE,OAAM;YAEjB,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;YAC5C,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC/C;QAED,OAAO;YACL,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjD;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC;AAzBD,iCAyBC","sourcesContent":["import { RefObject, useEffect, useRef, useState } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect } from 'spase'\n\n/**\n * Hook for monitoring changes in and returning the size and position of the target element.\n *\n * @param targetRef - Reference to the target element.\n *\n * @returns The most current {@link Rect} of the target element.\n */\nexport default function useElementRect(targetRef: RefObject<Element>): Rect {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [rect, setRect] = useState<Rect>(new Rect())\n\n useEffect(() => {\n observerRef.current = new ResizeObserver(() => {\n const rect = Rect.from(targetRef.current)\n\n if (!rect) return\n\n setRect(rect)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef])\n\n return rect\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
var react_1 = require("react");
|
|
20
|
+
var spase_1 = require("spase");
|
|
21
|
+
/**
|
|
22
|
+
* Hook for returning the size of the viewport whenever it changes.
|
|
23
|
+
*
|
|
24
|
+
* @returns The most current viewport size.
|
|
25
|
+
*/
|
|
26
|
+
function useViewportSize() {
|
|
27
|
+
var _a = __read((0, react_1.useState)(new spase_1.Size()), 2), size = _a[0], setSize = _a[1];
|
|
28
|
+
(0, react_1.useEffect)(function () {
|
|
29
|
+
function onViewportResize() {
|
|
30
|
+
var viewportSize = spase_1.Rect.fromViewport().size;
|
|
31
|
+
setSize(viewportSize);
|
|
32
|
+
}
|
|
33
|
+
window.addEventListener('resize', onViewportResize);
|
|
34
|
+
onViewportResize();
|
|
35
|
+
return function () { return window.removeEventListener('resize', onViewportResize); };
|
|
36
|
+
}, []);
|
|
37
|
+
return size;
|
|
38
|
+
}
|
|
39
|
+
exports.default = useViewportSize;
|
|
40
|
+
//# sourceMappingURL=useViewportSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useViewportSize.js","sourceRoot":"/","sources":["hooks/useViewportSize.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAA2C;AAC3C,+BAAkC;AAElC;;;;GAIG;AACH,SAAwB,eAAe;IAC/B,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,SAAS,gBAAgB;YACvB,IAAM,YAAY,GAAG,YAAI,CAAC,YAAY,EAAE,CAAC,IAAI,CAAA;YAC7C,OAAO,CAAC,YAAY,CAAC,CAAA;QACvB,CAAC;QAED,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;QAEnD,gBAAgB,EAAE,CAAA;QAElB,OAAO,cAAM,OAAA,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,EAAtD,CAAsD,CAAA;IACrE,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO,IAAI,CAAA;AACb,CAAC;AAjBD,kCAiBC","sourcesContent":["import { useEffect, useState } from 'react'\nimport { Rect, Size } from 'spase'\n\n/**\n * Hook for returning the size of the viewport whenever it changes.\n *\n * @returns The most current viewport size.\n */\nexport default function useViewportSize() {\n const [size, setSize] = useState<Size>(new Size())\n\n useEffect(() => {\n function onViewportResize() {\n const viewportSize = Rect.fromViewport().size\n setSize(viewportSize)\n }\n\n window.addEventListener('resize', onViewportResize)\n\n onViewportResize()\n\n return () => window.removeEventListener('resize', onViewportResize)\n }, [])\n\n return size\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "etudes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0",
|
|
4
4
|
"description": "A study of styled React components",
|
|
5
5
|
"main": "lib",
|
|
6
6
|
"scripts": {
|
|
@@ -29,50 +29,47 @@
|
|
|
29
29
|
"lib"
|
|
30
30
|
],
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.17.
|
|
33
|
-
"@babel/plugin-
|
|
34
|
-
"@babel/
|
|
35
|
-
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
36
|
-
"@babel/preset-env": "^7.16.11",
|
|
32
|
+
"@babel/core": "^7.17.10",
|
|
33
|
+
"@babel/plugin-transform-runtime": "^7.17.10",
|
|
34
|
+
"@babel/preset-env": "^7.17.10",
|
|
37
35
|
"@babel/preset-react": "^7.16.7",
|
|
38
36
|
"@babel/preset-typescript": "^7.16.7",
|
|
39
|
-
"@babel/runtime": "^7.17.
|
|
37
|
+
"@babel/runtime": "^7.17.9",
|
|
40
38
|
"@types/debug": "^4.1.7",
|
|
41
39
|
"@types/html-webpack-plugin": "^3.2.6",
|
|
42
|
-
"@types/lodash": "^4.14.
|
|
43
|
-
"@types/react": "^
|
|
44
|
-
"@types/react-dom": "^
|
|
40
|
+
"@types/lodash": "^4.14.182",
|
|
41
|
+
"@types/react": "^18.0.9",
|
|
42
|
+
"@types/react-dom": "^18.0.3",
|
|
45
43
|
"@types/react-transition-group": "^4.4.4",
|
|
46
|
-
"@types/styled-components": "^5.1.
|
|
44
|
+
"@types/styled-components": "^5.1.25",
|
|
47
45
|
"@types/webpack": "^5.28.0",
|
|
48
|
-
"@types/webpack-env": "^1.16.
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
50
|
-
"@typescript-eslint/parser": "^5.
|
|
51
|
-
"babel-loader": "^8.2.
|
|
52
|
-
"babel-plugin-styled-components": "^2.0.
|
|
46
|
+
"@types/webpack-env": "^1.16.4",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
49
|
+
"babel-loader": "^8.2.5",
|
|
50
|
+
"babel-plugin-styled-components": "^2.0.7",
|
|
53
51
|
"concurrently": "^7.1.0",
|
|
54
52
|
"cross-env": "^7.0.3",
|
|
55
53
|
"debug": "^4.3.4",
|
|
56
|
-
"eslint": "^8.
|
|
54
|
+
"eslint": "^8.15.0",
|
|
57
55
|
"file-loader": "^6.2.0",
|
|
58
56
|
"html-webpack-plugin": "^5.5.0",
|
|
59
|
-
"promptu": "^5.
|
|
57
|
+
"promptu": "^5.8.0",
|
|
60
58
|
"raw-loader": "^4.0.2",
|
|
61
|
-
"react": "^18.
|
|
62
|
-
"react-dom": "^18.
|
|
63
|
-
"react-is": "^18.0.0",
|
|
59
|
+
"react": "^18.1.0",
|
|
60
|
+
"react-dom": "^18.1.0",
|
|
64
61
|
"react-router": "^6.3.0",
|
|
65
62
|
"react-router-dom": "^6.3.0",
|
|
66
63
|
"rimraf": "^3.0.2",
|
|
67
64
|
"styled-components": "^5.3.5",
|
|
68
|
-
"ts-loader": "^9.
|
|
65
|
+
"ts-loader": "^9.3.0",
|
|
69
66
|
"ts-node": "^10.7.0",
|
|
70
|
-
"typescript": "^4.6.
|
|
67
|
+
"typescript": "^4.6.4",
|
|
71
68
|
"url-loader": "^4.1.1",
|
|
72
69
|
"wait-on": "^6.0.1",
|
|
73
|
-
"webpack": "^5.
|
|
70
|
+
"webpack": "^5.72.0",
|
|
74
71
|
"webpack-cli": "^4.9.2",
|
|
75
|
-
"webpack-dev-server": "^4.
|
|
72
|
+
"webpack-dev-server": "^4.9.0"
|
|
76
73
|
},
|
|
77
74
|
"dependencies": {
|
|
78
75
|
"classnames": "^2.3.1",
|
|
@@ -84,7 +81,7 @@
|
|
|
84
81
|
"spase": "^6.3.0"
|
|
85
82
|
},
|
|
86
83
|
"peerDependencies": {
|
|
87
|
-
"react": "^18.
|
|
84
|
+
"react": "^18.1.0",
|
|
88
85
|
"styled-components": "^5.3.5"
|
|
89
86
|
},
|
|
90
87
|
"optionalDependencies": {
|