@guardian/interactive-component-library 0.3.1 → 0.3.2-rc1
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/dist/components/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/Map.d.ts +8 -0
- package/dist/components/molecules/canvas-map/Map.js +90 -0
- package/dist/components/molecules/canvas-map/context/MapContext.d.ts +19 -0
- package/dist/components/molecules/canvas-map/context/MapContext.js +20 -0
- package/dist/components/molecules/canvas-map/controls/ZoomControl.d.ts +6 -0
- package/dist/components/molecules/canvas-map/controls/ZoomControl.js +40 -0
- package/dist/components/molecules/canvas-map/controls/icons/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/controls/icons/minus.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/icons/minus.js +25 -0
- package/dist/components/molecules/canvas-map/controls/icons/plus.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/icons/plus.js +25 -0
- package/dist/components/molecules/canvas-map/controls/icons/reset.d.ts +3 -0
- package/dist/components/molecules/canvas-map/controls/icons/reset.js +25 -0
- package/dist/components/molecules/canvas-map/controls/index.d.ts +1 -0
- package/dist/components/molecules/canvas-map/controls/style.module.css.js +11 -0
- package/dist/components/molecules/canvas-map/index.d.ts +12 -0
- package/dist/components/molecules/canvas-map/lib/Feature.d.ts +44 -0
- package/dist/components/molecules/canvas-map/lib/Feature.js +113 -0
- package/dist/components/molecules/canvas-map/lib/FeatureCollection.d.ts +21 -0
- package/dist/components/molecules/canvas-map/lib/FeatureCollection.js +24 -0
- package/dist/components/molecules/canvas-map/lib/Map.d.ts +82 -0
- package/dist/components/molecules/canvas-map/lib/Map.js +267 -0
- package/dist/components/molecules/canvas-map/lib/View.d.ts +222 -0
- package/dist/components/molecules/canvas-map/lib/View.js +208 -0
- package/dist/components/molecules/canvas-map/lib/events/Dispatcher.d.ts +8 -0
- package/dist/components/molecules/canvas-map/lib/events/Dispatcher.js +35 -0
- package/dist/components/molecules/canvas-map/lib/events/MapEvent.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/events/MapEvent.js +9 -0
- package/dist/components/molecules/canvas-map/lib/events/index.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.d.ts +63 -0
- package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.js +122 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Geometry.d.ts +32 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Geometry.js +41 -0
- package/dist/components/molecules/canvas-map/lib/geometry/LineString.d.ts +12 -0
- package/dist/components/molecules/canvas-map/lib/geometry/LineString.js +19 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Point.d.ts +11 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Point.js +22 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Polygon.d.ts +16 -0
- package/dist/components/molecules/canvas-map/lib/geometry/Polygon.js +46 -0
- package/dist/components/molecules/canvas-map/lib/geometry/index.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/index.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.d.ts +5 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.js +95 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.js +65 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +52 -0
- package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +118 -0
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +57 -0
- package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +136 -0
- package/dist/components/molecules/canvas-map/lib/layers/index.d.ts +3 -0
- package/dist/components/molecules/canvas-map/lib/projection/index.d.ts +27 -0
- package/dist/components/molecules/canvas-map/lib/projection/index.js +12 -0
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.d.ts +16 -0
- package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +90 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +53 -0
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +21 -0
- package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +133 -0
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.d.ts +10 -0
- package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.js +79 -0
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.d.ts +15 -0
- package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +53 -0
- package/dist/components/molecules/canvas-map/lib/styles/Fill.d.ts +7 -0
- package/dist/components/molecules/canvas-map/lib/styles/Fill.js +15 -0
- package/dist/components/molecules/canvas-map/lib/styles/Stroke.d.ts +24 -0
- package/dist/components/molecules/canvas-map/lib/styles/Stroke.js +22 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +24 -0
- package/dist/components/molecules/canvas-map/lib/styles/Style.js +17 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.d.ts +146 -0
- package/dist/components/molecules/canvas-map/lib/styles/Text.js +116 -0
- package/dist/components/molecules/canvas-map/lib/styles/index.d.ts +4 -0
- package/dist/components/molecules/canvas-map/lib/util/array.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/util/array.js +15 -0
- package/dist/components/molecules/canvas-map/lib/util/bboxFeature.d.ts +8 -0
- package/dist/components/molecules/canvas-map/lib/util/bboxFeature.js +24 -0
- package/dist/components/molecules/canvas-map/lib/util/bounds.d.ts +47 -0
- package/dist/components/molecules/canvas-map/lib/util/bounds.js +61 -0
- package/dist/components/molecules/canvas-map/lib/util/coordinate.d.ts +26 -0
- package/dist/components/molecules/canvas-map/lib/util/coordinate.js +35 -0
- package/dist/components/molecules/canvas-map/lib/util/debug.d.ts +11 -0
- package/dist/components/molecules/canvas-map/lib/util/debug.js +27 -0
- package/dist/components/molecules/canvas-map/lib/util/deflate.d.ts +36 -0
- package/dist/components/molecules/canvas-map/lib/util/distance.d.ts +1 -0
- package/dist/components/molecules/canvas-map/lib/util/distance.js +12 -0
- package/dist/components/molecules/canvas-map/lib/util/dom.d.ts +9 -0
- package/dist/components/molecules/canvas-map/lib/util/dom.js +28 -0
- package/dist/components/molecules/canvas-map/lib/util/extent.d.ts +98 -0
- package/dist/components/molecules/canvas-map/lib/util/extent.js +118 -0
- package/dist/components/molecules/canvas-map/lib/util/index.d.ts +6 -0
- package/dist/components/molecules/canvas-map/lib/util/memoise.d.ts +10 -0
- package/dist/components/molecules/canvas-map/lib/util/memoise.js +20 -0
- package/dist/components/molecules/canvas-map/lib/util/resolution.d.ts +9 -0
- package/dist/components/molecules/canvas-map/lib/util/resolution.js +11 -0
- package/dist/components/molecules/canvas-map/lib/util/simplify.d.ts +114 -0
- package/dist/components/molecules/canvas-map/lib/util/size.d.ts +32 -0
- package/dist/components/molecules/canvas-map/lib/util/size.js +53 -0
- package/dist/components/molecules/canvas-map/lib/util/toRgba.d.ts +1 -0
- package/dist/components/molecules/canvas-map/lib/util/toRgba.js +25 -0
- package/dist/components/molecules/canvas-map/lib/util/uid.d.ts +5 -0
- package/dist/components/molecules/canvas-map/lib/util/uid.js +7 -0
- package/dist/components/molecules/canvas-map/lib/util/zoomLevel.d.ts +2 -0
- package/dist/components/molecules/canvas-map/lib/util/zoomLevel.js +14 -0
- package/dist/components/molecules/canvas-map/style.module.scss.js +20 -0
- package/dist/components/molecules/column-chart/column-chart-example.d.ts +35 -0
- package/dist/components/molecules/column-chart/column-chart-util.d.ts +1 -0
- package/dist/components/molecules/column-chart/index.d.ts +11 -0
- package/dist/components/molecules/column-chart/index.js +63 -0
- package/dist/components/molecules/column-chart/style.module.css.js +14 -0
- package/dist/components/molecules/control-change/index.d.ts +6 -0
- package/dist/components/molecules/control-change/index.js +29 -0
- package/dist/components/molecules/control-change/style.module.css.js +11 -0
- package/dist/components/molecules/dropdown/index.d.ts +11 -0
- package/dist/components/molecules/dropdown/index.js +191 -0
- package/dist/components/molecules/dropdown/style.module.css.js +50 -0
- package/dist/components/molecules/first-past-the-post-waffle/index.d.ts +5 -0
- package/dist/components/molecules/first-past-the-post-waffle/index.js +14 -0
- package/dist/components/molecules/first-past-the-post-waffle/style.module.css.js +14 -0
- package/dist/components/molecules/index.d.ts +18 -0
- package/dist/components/molecules/modal/index.d.ts +8 -0
- package/dist/components/molecules/modal/index.js +59 -0
- package/dist/components/molecules/modal/style.module.css.js +26 -0
- package/dist/components/molecules/option-picker/index.d.ts +26 -0
- package/dist/components/molecules/option-picker/index.js +94 -0
- package/dist/components/molecules/option-picker/style.module.css.js +35 -0
- package/dist/components/molecules/page-section/index.d.ts +8 -0
- package/dist/components/molecules/page-section/index.js +52 -0
- package/dist/components/molecules/page-section/style.module.scss.js +20 -0
- package/dist/components/molecules/party-profile/index.d.ts +10 -0
- package/dist/components/molecules/party-profile/index.js +29 -0
- package/dist/components/molecules/party-profile/style.module.css.js +26 -0
- package/dist/components/molecules/refresh-indicator/index.d.ts +4 -0
- package/dist/components/molecules/refresh-indicator/index.js +18 -0
- package/dist/components/molecules/refresh-indicator/style.module.scss.js +17 -0
- package/dist/components/molecules/responsive-grid/index.d.ts +10 -0
- package/dist/components/molecules/responsive-grid/index.js +19 -0
- package/dist/components/molecules/responsive-grid/style.module.scss.js +8 -0
- package/dist/components/molecules/result-summary/index.d.ts +8 -0
- package/dist/components/molecules/result-summary/index.js +40 -0
- package/dist/components/molecules/result-summary/style.module.css.js +11 -0
- package/dist/components/molecules/search-input/icons/search.d.ts +1 -0
- package/dist/components/molecules/search-input/icons/search.js +24 -0
- package/dist/components/molecules/search-input/icons/search.module.css.js +11 -0
- package/dist/components/molecules/search-input/index.d.ts +11 -0
- package/dist/components/molecules/search-input/index.js +165 -0
- package/dist/components/molecules/search-input/style.module.css.js +32 -0
- package/dist/components/molecules/slope-chart/index.d.ts +16 -0
- package/dist/components/molecules/slope-chart/index.js +139 -0
- package/dist/components/molecules/slope-chart/style.module.css.js +35 -0
- package/dist/components/molecules/svg-map/context/MapContext.d.ts +1 -0
- package/dist/components/molecules/svg-map/context/MapContext.js +5 -0
- package/dist/components/molecules/svg-map/context/SVGMapProvider.d.ts +10 -0
- package/dist/components/molecules/svg-map/context/SVGMapProvider.js +88 -0
- package/dist/components/molecules/svg-map/helpers/bboxFeature.d.ts +8 -0
- package/dist/components/molecules/svg-map/helpers/bboxFeature.js +26 -0
- package/dist/components/molecules/svg-map/helpers/dynamicPropValue.d.ts +1 -0
- package/dist/components/molecules/svg-map/helpers/dynamicPropValue.js +9 -0
- package/dist/components/molecules/svg-map/helpers/geoMath.d.ts +4 -0
- package/dist/components/molecules/svg-map/helpers/saveSVG.d.ts +1 -0
- package/dist/components/molecules/svg-map/hooks/useCamera.d.ts +0 -0
- package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.d.ts +4 -0
- package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.js +19 -0
- package/dist/components/molecules/svg-map/index.d.ts +38 -0
- package/dist/components/molecules/svg-map/index.js +121 -0
- package/dist/components/molecules/svg-map/layers/CompositionBorders.d.ts +3 -0
- package/dist/components/molecules/svg-map/layers/CompositionBorders.js +14 -0
- package/dist/components/molecules/svg-map/layers/Line.d.ts +7 -0
- package/dist/components/molecules/svg-map/layers/Line.js +48 -0
- package/dist/components/molecules/svg-map/layers/Point.d.ts +10 -0
- package/dist/components/molecules/svg-map/layers/Point.js +59 -0
- package/dist/components/molecules/svg-map/layers/Polygon.d.ts +9 -0
- package/dist/components/molecules/svg-map/layers/Polygon.js +75 -0
- package/dist/components/molecules/svg-map/layers/Prerendered.d.ts +3 -0
- package/dist/components/molecules/svg-map/layers/Prerendered.js +11 -0
- package/dist/components/molecules/svg-map/layers/compositionBorders.module.scss.js +8 -0
- package/dist/components/molecules/svg-map/layers/index.d.ts +5 -0
- package/dist/components/molecules/svg-map/layers/index.js +12 -0
- package/dist/components/molecules/svg-map/renderers/SVGRenderer.d.ts +3 -0
- package/dist/components/molecules/svg-map/renderers/SVGRenderer.js +32 -0
- package/dist/components/molecules/svg-map/style.module.css.js +11 -0
- package/dist/components/molecules/table/index.d.ts +7 -0
- package/dist/components/molecules/table/index.js +90 -0
- package/dist/components/molecules/table/style.module.scss.js +29 -0
- package/dist/components/molecules/table/useTable.d.ts +8 -0
- package/dist/components/molecules/table/useTable.js +128 -0
- package/dist/components/molecules/tooltip/index.d.ts +82 -0
- package/dist/components/molecules/tooltip/index.js +117 -0
- package/dist/components/molecules/tooltip/style.module.css.js +8 -0
- package/dist/components/molecules/topline-result/index.d.ts +3 -0
- package/dist/components/molecules/topline-result/index.js +61 -0
- package/dist/components/molecules/topline-result/style.module.scss.js +38 -0
- package/dist/components/organisms/coalitions-tracker/index.d.ts +16 -0
- package/dist/components/organisms/coalitions-tracker/index.js +151 -0
- package/dist/components/organisms/coalitions-tracker/style.module.scss.js +32 -0
- package/dist/components/organisms/index.d.ts +2 -0
- package/dist/components/organisms/ticker/gradient/index.d.ts +1 -0
- package/dist/components/organisms/ticker/gradient/index.js +35 -0
- package/dist/components/organisms/ticker/gradient/style.module.scss.js +14 -0
- package/dist/components/organisms/ticker/index.d.ts +5 -0
- package/dist/components/organisms/ticker/index.js +102 -0
- package/dist/components/organisms/ticker/style.module.scss.js +32 -0
- package/dist/components/particles/ad-slot/index.d.ts +40 -0
- package/dist/components/particles/ad-slot/index.js +34 -0
- package/dist/components/particles/ad-slot/style.module.css.js +11 -0
- package/dist/components/particles/arrow-button/index.d.ts +6 -0
- package/dist/components/particles/arrow-button/index.js +32 -0
- package/dist/components/particles/arrow-button/style.module.css.js +11 -0
- package/dist/components/particles/aspect-ratio-box/index.d.ts +4 -0
- package/dist/components/particles/aspect-ratio-box/index.js +15 -0
- package/dist/components/particles/aspect-ratio-box/style.module.css.js +6 -0
- package/dist/components/particles/button/index.d.ts +6 -0
- package/dist/components/particles/button/index.js +10 -0
- package/dist/components/particles/button/style.module.css.js +11 -0
- package/dist/components/particles/change-bar/index.d.ts +8 -0
- package/dist/components/particles/change-bar/index.js +27 -0
- package/dist/components/particles/change-bar/style.module.scss.js +14 -0
- package/dist/components/particles/chevron/index.d.ts +6 -0
- package/dist/components/particles/chevron/index.js +78 -0
- package/dist/components/particles/chevron/style.module.css.js +20 -0
- package/dist/components/particles/circle-icon/index.d.ts +6 -0
- package/dist/components/particles/circle-icon/index.js +32 -0
- package/dist/components/particles/circle-icon/style.module.css.js +14 -0
- package/dist/components/particles/close-button/index.d.ts +5 -0
- package/dist/components/particles/close-button/index.js +35 -0
- package/dist/components/particles/close-button/style.module.css.js +17 -0
- package/dist/components/particles/container/index.d.ts +5 -0
- package/dist/components/particles/container/index.js +13 -0
- package/dist/components/particles/container/style.module.scss.js +11 -0
- package/dist/components/particles/gradient-icon/index.d.ts +1 -0
- package/dist/components/particles/gradient-icon/index.js +46 -0
- package/dist/components/particles/gradient-icon/style.module.css.js +14 -0
- package/dist/components/particles/index.d.ts +18 -0
- package/dist/components/particles/info-button/index.d.ts +3 -0
- package/dist/components/particles/info-button/index.js +19 -0
- package/dist/components/particles/info-button/style.module.css.js +11 -0
- package/dist/components/particles/legend-item/index.d.ts +6 -0
- package/dist/components/particles/legend-item/index.js +26 -0
- package/dist/components/particles/legend-item/style.module.css.js +17 -0
- package/dist/components/particles/relative-time-sentence/index.d.ts +4 -0
- package/dist/components/particles/relative-time-sentence/index.js +14 -0
- package/dist/components/particles/relative-time-sentence/style.module.css.js +8 -0
- package/dist/components/particles/square-cut-corner-icon/index.d.ts +6 -0
- package/dist/components/particles/square-cut-corner-icon/index.js +56 -0
- package/dist/components/particles/square-cut-corner-icon/style.module.scss.js +17 -0
- package/dist/components/particles/square-icon/index.d.ts +5 -0
- package/dist/components/particles/square-icon/index.js +28 -0
- package/dist/components/particles/square-icon/style.module.scss.js +11 -0
- package/dist/components/particles/stacked-bar/index.d.ts +23 -0
- package/dist/components/particles/stacked-bar/index.js +140 -0
- package/dist/components/particles/stacked-bar/style.module.css.js +17 -0
- package/dist/components/particles/stacked-grid/index.d.ts +6 -0
- package/dist/components/particles/stacked-grid/index.js +35 -0
- package/dist/components/particles/stacked-grid/style.module.css.js +20 -0
- package/dist/components/particles/waffle/index.d.ts +14 -0
- package/dist/components/particles/waffle/index.js +76 -0
- package/dist/components/particles/waffle/style.module.css.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +147 -0
- package/dist/shared/colors/index.d.ts +2 -0
- package/dist/shared/helpers/createStore.d.ts +1 -0
- package/dist/shared/helpers/geometry.d.ts +3 -0
- package/dist/shared/helpers/geometry.js +16 -0
- package/dist/shared/helpers/geometry.test.d.ts +1 -0
- package/dist/shared/helpers/labelsUtil.d.ts +54 -0
- package/dist/shared/helpers/labelsUtil.js +58 -0
- package/dist/shared/helpers/labelsUtils.test.d.ts +1 -0
- package/dist/shared/helpers/shouldUpdate.d.ts +7 -0
- package/dist/shared/hooks/index.d.ts +3 -0
- package/dist/shared/hooks/useContainerSize.d.ts +1 -0
- package/dist/shared/hooks/useContainerSize.js +24 -0
- package/dist/shared/hooks/useTouchOrHover.d.ts +7 -0
- package/dist/shared/hooks/useTouchOrHover.js +103 -0
- package/dist/shared/hooks/useWindowSize.d.ts +4 -0
- package/dist/shared/hooks/useWindowSize.js +27 -0
- package/dist/style.css +74 -74
- package/dist/styles/helpers/mergeStyles.d.ts +1 -0
- package/dist/styles/helpers/mergeStyles.js +22 -0
- package/dist/styles/helpers/mergeStyles.test.d.ts +1 -0
- package/dist/styles/theme.config.d.ts +124 -0
- package/package.json +19 -10
- package/dist/interactive-component-library.js +0 -8370
- package/dist/interactive-component-library.js.map +0 -1
- package/dist/interactive-component-library.umd.cjs +0 -8365
- package/dist/interactive-component-library.umd.cjs.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsx } from "preact/jsx-runtime";
|
|
2
|
+
import defaultStyles from "./style.module.css.js";
|
|
3
|
+
import { mergeStyles } from "../../../styles/helpers/mergeStyles.js";
|
|
4
|
+
import { useContainerSize } from "../../../shared/hooks/useContainerSize.js";
|
|
5
|
+
import { useRef } from "preact/hooks";
|
|
6
|
+
const WaffleType = {
|
|
7
|
+
circle: "circle",
|
|
8
|
+
square: "square"
|
|
9
|
+
};
|
|
10
|
+
const WaffleUnit = ({ type, attributes }) => type === WaffleType.square ? /* @__PURE__ */ jsx("rect", { ...attributes }) : /* @__PURE__ */ jsx("circle", { ...attributes });
|
|
11
|
+
const Waffle = ({
|
|
12
|
+
units,
|
|
13
|
+
numberOfRows,
|
|
14
|
+
type = WaffleType.circle,
|
|
15
|
+
idAccessor,
|
|
16
|
+
onMouseOver = () => {
|
|
17
|
+
},
|
|
18
|
+
onClick = () => {
|
|
19
|
+
},
|
|
20
|
+
styles,
|
|
21
|
+
svgId
|
|
22
|
+
}) => {
|
|
23
|
+
const containerRef = useRef();
|
|
24
|
+
const containerSize = useContainerSize(containerRef);
|
|
25
|
+
const width = containerSize ? containerSize.width : 0;
|
|
26
|
+
const total = units.length;
|
|
27
|
+
const columns = Math.ceil(total / numberOfRows);
|
|
28
|
+
const unitWidth = width / columns;
|
|
29
|
+
const unitHeight = unitWidth;
|
|
30
|
+
const height = numberOfRows * unitHeight;
|
|
31
|
+
styles = mergeStyles(defaultStyles, styles);
|
|
32
|
+
return /* @__PURE__ */ jsx("div", { ref: containerRef, className: styles.container, children: containerSize && /* @__PURE__ */ jsx(
|
|
33
|
+
"svg",
|
|
34
|
+
{
|
|
35
|
+
viewBox: `0 0 ${width} ${height}`,
|
|
36
|
+
className: styles.svg,
|
|
37
|
+
id: svgId,
|
|
38
|
+
children: /* @__PURE__ */ jsx("g", { children: units.map((unit, j) => {
|
|
39
|
+
let attributes;
|
|
40
|
+
if (type === WaffleType.square) {
|
|
41
|
+
attributes = {
|
|
42
|
+
id: unit[idAccessor] || `w-${j}`,
|
|
43
|
+
onMouseOver: (e) => onMouseOver(unit, e),
|
|
44
|
+
onClick: (e) => onClick(unit, e),
|
|
45
|
+
class: `${styles.unit} ${unit.class}`,
|
|
46
|
+
height: unitHeight,
|
|
47
|
+
width: unitWidth,
|
|
48
|
+
x: unitWidth * Math.floor(j / numberOfRows),
|
|
49
|
+
y: unitHeight * (j % numberOfRows)
|
|
50
|
+
};
|
|
51
|
+
} else {
|
|
52
|
+
attributes = {
|
|
53
|
+
id: unit[idAccessor] || `w-${j}`,
|
|
54
|
+
onMouseOver: (e) => onMouseOver(unit, e),
|
|
55
|
+
onClick: (e) => onClick(unit, e),
|
|
56
|
+
class: `${styles.unit} ${unit.class}`,
|
|
57
|
+
r: unitWidth / 2,
|
|
58
|
+
transform: `translate(${unitWidth * Math.floor(j / numberOfRows) + unitWidth / 2}, ${unitHeight * (j % numberOfRows) + unitHeight / 2})`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return /* @__PURE__ */ jsx(
|
|
62
|
+
WaffleUnit,
|
|
63
|
+
{
|
|
64
|
+
type,
|
|
65
|
+
attributes
|
|
66
|
+
},
|
|
67
|
+
`wu-${j}`
|
|
68
|
+
);
|
|
69
|
+
}) })
|
|
70
|
+
}
|
|
71
|
+
) });
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
Waffle,
|
|
75
|
+
WaffleType
|
|
76
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
import { Chevron } from "./components/particles/chevron/index.js";
|
|
3
|
+
import { LegendItem } from "./components/particles/legend-item/index.js";
|
|
4
|
+
import { LabelOverlapConfig, LabelType, StackedBar } from "./components/particles/stacked-bar/index.js";
|
|
5
|
+
import { GradientIcon } from "./components/particles/gradient-icon/index.js";
|
|
6
|
+
import { Waffle, WaffleType } from "./components/particles/waffle/index.js";
|
|
7
|
+
import { InfoButton } from "./components/particles/info-button/index.js";
|
|
8
|
+
import { CircleIcon } from "./components/particles/circle-icon/index.js";
|
|
9
|
+
import { RelativeTimeSentence } from "./components/particles/relative-time-sentence/index.js";
|
|
10
|
+
import { Container } from "./components/particles/container/index.js";
|
|
11
|
+
import { ChangeBar } from "./components/particles/change-bar/index.js";
|
|
12
|
+
import { SquareCutCornerIcon } from "./components/particles/square-cut-corner-icon/index.js";
|
|
13
|
+
import { StackedGrid } from "./components/particles/stacked-grid/index.js";
|
|
14
|
+
import { SquareIcon } from "./components/particles/square-icon/index.js";
|
|
15
|
+
import { ArrowButton } from "./components/particles/arrow-button/index.js";
|
|
16
|
+
import { Button } from "./components/particles/button/index.js";
|
|
17
|
+
import { CloseButton } from "./components/particles/close-button/index.js";
|
|
18
|
+
import { AdSlot } from "./components/particles/ad-slot/index.js";
|
|
19
|
+
import { AspectRatioBox } from "./components/particles/aspect-ratio-box/index.js";
|
|
20
|
+
import { Table } from "./components/molecules/table/index.js";
|
|
21
|
+
import { SlopeChart } from "./components/molecules/slope-chart/index.js";
|
|
22
|
+
import { Tooltip } from "./components/molecules/tooltip/index.js";
|
|
23
|
+
import { ControlChange } from "./components/molecules/control-change/index.js";
|
|
24
|
+
import { FirstPastThePostWaffle } from "./components/molecules/first-past-the-post-waffle/index.js";
|
|
25
|
+
import { ToplineResult } from "./components/molecules/topline-result/index.js";
|
|
26
|
+
import { PageSection, SectionLayout } from "./components/molecules/page-section/index.js";
|
|
27
|
+
import { ColumnChart } from "./components/molecules/column-chart/index.js";
|
|
28
|
+
import { PartyProfile } from "./components/molecules/party-profile/index.js";
|
|
29
|
+
import { ResultSummary } from "./components/molecules/result-summary/index.js";
|
|
30
|
+
import { SearchInput } from "./components/molecules/search-input/index.js";
|
|
31
|
+
import { RefreshIndicator } from "./components/molecules/refresh-indicator/index.js";
|
|
32
|
+
import { GridType, ResponsiveGrid } from "./components/molecules/responsive-grid/index.js";
|
|
33
|
+
import { Modal } from "./components/molecules/modal/index.js";
|
|
34
|
+
import { Dropdown } from "./components/molecules/dropdown/index.js";
|
|
35
|
+
import { MapConfiguration, SVGMap, _Projection } from "./components/molecules/svg-map/index.js";
|
|
36
|
+
import { Map } from "./components/molecules/canvas-map/lib/Map.js";
|
|
37
|
+
import { ZoomControl } from "./components/molecules/canvas-map/controls/ZoomControl.js";
|
|
38
|
+
import { Feature } from "./components/molecules/canvas-map/lib/Feature.js";
|
|
39
|
+
import { FeatureCollection } from "./components/molecules/canvas-map/lib/FeatureCollection.js";
|
|
40
|
+
import { Dispatcher } from "./components/molecules/canvas-map/lib/events/Dispatcher.js";
|
|
41
|
+
import { MapEvent } from "./components/molecules/canvas-map/lib/events/MapEvent.js";
|
|
42
|
+
import { Projection } from "./components/molecules/canvas-map/lib/projection/index.js";
|
|
43
|
+
import { TextLayer } from "./components/molecules/canvas-map/lib/layers/TextLayer.js";
|
|
44
|
+
import { VectorLayer } from "./components/molecules/canvas-map/lib/layers/VectorLayer.js";
|
|
45
|
+
import { Style } from "./components/molecules/canvas-map/lib/styles/Style.js";
|
|
46
|
+
import { Stroke, StrokePosition } from "./components/molecules/canvas-map/lib/styles/Stroke.js";
|
|
47
|
+
import { Fill } from "./components/molecules/canvas-map/lib/styles/Fill.js";
|
|
48
|
+
import { Text } from "./components/molecules/canvas-map/lib/styles/Text.js";
|
|
49
|
+
import { GeoCoordinate } from "./components/molecules/canvas-map/lib/util/coordinate.js";
|
|
50
|
+
import { GeoBounds } from "./components/molecules/canvas-map/lib/util/bounds.js";
|
|
51
|
+
import { Extent, combineExtents, containsCoordinate, containsXY, extentForCoordinates } from "./components/molecules/canvas-map/lib/util/extent.js";
|
|
52
|
+
import { bboxFeature } from "./components/molecules/canvas-map/lib/util/bboxFeature.js";
|
|
53
|
+
import { resolutionForExtent } from "./components/molecules/canvas-map/lib/util/resolution.js";
|
|
54
|
+
import { zoomLevelForResolution, zoomLevelToZoomScale } from "./components/molecules/canvas-map/lib/util/zoomLevel.js";
|
|
55
|
+
import { interpolateFeatures } from "./components/molecules/canvas-map/lib/interpolators/interpolateFeatures.js";
|
|
56
|
+
import { interpolateFill, interpolateStroke, interpolateStyles } from "./components/molecules/canvas-map/lib/interpolators/interpolateStyles.js";
|
|
57
|
+
import { VectorSource } from "./components/molecules/canvas-map/lib/sources/VectorSource.js";
|
|
58
|
+
import { GeoJSON } from "./components/molecules/canvas-map/lib/formats/GeoJSON.js";
|
|
59
|
+
import "./components/molecules/canvas-map/Map.js";
|
|
60
|
+
import { OptionPicker } from "./components/molecules/option-picker/index.js";
|
|
61
|
+
import { CoalitionsTracker } from "./components/organisms/coalitions-tracker/index.js";
|
|
62
|
+
import { Ticker } from "./components/organisms/ticker/index.js";
|
|
63
|
+
import { useContainerSize } from "./shared/hooks/useContainerSize.js";
|
|
64
|
+
import { useTouchOrHover } from "./shared/hooks/useTouchOrHover.js";
|
|
65
|
+
import { useWindowSize } from "./shared/hooks/useWindowSize.js";
|
|
66
|
+
import * as index from "./components/molecules/svg-map/layers/index.js";
|
|
67
|
+
export {
|
|
68
|
+
AdSlot,
|
|
69
|
+
ArrowButton,
|
|
70
|
+
AspectRatioBox,
|
|
71
|
+
Button,
|
|
72
|
+
ChangeBar,
|
|
73
|
+
Chevron,
|
|
74
|
+
CircleIcon,
|
|
75
|
+
CloseButton,
|
|
76
|
+
CoalitionsTracker,
|
|
77
|
+
ColumnChart,
|
|
78
|
+
Container,
|
|
79
|
+
ControlChange,
|
|
80
|
+
Dispatcher,
|
|
81
|
+
Dropdown,
|
|
82
|
+
Extent,
|
|
83
|
+
Feature,
|
|
84
|
+
FeatureCollection,
|
|
85
|
+
Fill,
|
|
86
|
+
FirstPastThePostWaffle,
|
|
87
|
+
GeoBounds,
|
|
88
|
+
GeoCoordinate,
|
|
89
|
+
GeoJSON,
|
|
90
|
+
GradientIcon,
|
|
91
|
+
GridType,
|
|
92
|
+
InfoButton,
|
|
93
|
+
LabelOverlapConfig,
|
|
94
|
+
LabelType,
|
|
95
|
+
LegendItem,
|
|
96
|
+
Map,
|
|
97
|
+
MapConfiguration,
|
|
98
|
+
MapEvent,
|
|
99
|
+
index as MapLayers,
|
|
100
|
+
Modal,
|
|
101
|
+
OptionPicker,
|
|
102
|
+
PageSection,
|
|
103
|
+
PartyProfile,
|
|
104
|
+
Projection,
|
|
105
|
+
RefreshIndicator,
|
|
106
|
+
RelativeTimeSentence,
|
|
107
|
+
ResponsiveGrid,
|
|
108
|
+
ResultSummary,
|
|
109
|
+
SVGMap,
|
|
110
|
+
SearchInput,
|
|
111
|
+
SectionLayout,
|
|
112
|
+
SlopeChart,
|
|
113
|
+
SquareCutCornerIcon,
|
|
114
|
+
SquareIcon,
|
|
115
|
+
StackedBar,
|
|
116
|
+
StackedGrid,
|
|
117
|
+
Stroke,
|
|
118
|
+
StrokePosition,
|
|
119
|
+
Style,
|
|
120
|
+
Table,
|
|
121
|
+
Text,
|
|
122
|
+
TextLayer,
|
|
123
|
+
Ticker,
|
|
124
|
+
Tooltip,
|
|
125
|
+
ToplineResult,
|
|
126
|
+
VectorLayer,
|
|
127
|
+
VectorSource,
|
|
128
|
+
Waffle,
|
|
129
|
+
WaffleType,
|
|
130
|
+
ZoomControl,
|
|
131
|
+
_Projection,
|
|
132
|
+
bboxFeature,
|
|
133
|
+
combineExtents,
|
|
134
|
+
containsCoordinate,
|
|
135
|
+
containsXY,
|
|
136
|
+
extentForCoordinates,
|
|
137
|
+
interpolateFeatures,
|
|
138
|
+
interpolateFill,
|
|
139
|
+
interpolateStroke,
|
|
140
|
+
interpolateStyles,
|
|
141
|
+
resolutionForExtent,
|
|
142
|
+
useContainerSize,
|
|
143
|
+
useTouchOrHover,
|
|
144
|
+
useWindowSize,
|
|
145
|
+
zoomLevelForResolution,
|
|
146
|
+
zoomLevelToZoomScale
|
|
147
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function createStore(initialStore: any): ((selectorFn?: (store: any) => any) => any)[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function rectsIntersect(rect1, rect2) {
|
|
2
|
+
if (rect1.width === 0 || rect1.height === 0 || rect2.width === 0 || rect2.height === 0) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (rect1.x + rect1.width <= rect2.x || rect2.x + rect2.width <= rect1.x || rect1.y + rect1.height <= rect2.y || rect2.y + rect2.height <= rect1.y) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
function pointInsideRect(point, rect) {
|
|
11
|
+
return point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height;
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
pointInsideRect,
|
|
15
|
+
rectsIntersect
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template {Record<string, unknown>} T
|
|
3
|
+
* @param {T[]} labelPositions
|
|
4
|
+
* @param {number} iteration
|
|
5
|
+
* @param {number} labelSize
|
|
6
|
+
* @param {string} coordinate
|
|
7
|
+
* @param {boolean} moveBothLabels
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function preventOverlap<T extends Record<string, unknown>>(labelPositions: T[], iteration?: number, labelSize?: number, coordinate?: string, moveBothLabels?: boolean): T[];
|
|
11
|
+
/**
|
|
12
|
+
* Unique objects for a given key’s value;
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* const labels = [
|
|
17
|
+
* {key: 'alpha', value: 1 },
|
|
18
|
+
* {key: 'alpha', value: 9 },
|
|
19
|
+
* {key: 'delta', value: 4 },
|
|
20
|
+
*];
|
|
21
|
+
* console.log(uniqueBy(labels, 'key'));
|
|
22
|
+
* // [
|
|
23
|
+
* // {key: 'alpha', value: 1 },
|
|
24
|
+
* // {key: 'delta', value: 4 },
|
|
25
|
+
* // ]
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @template T extends Record<string, unknown>
|
|
29
|
+
* @param {T[]} array
|
|
30
|
+
* @param {keyof T} key
|
|
31
|
+
* @returns {T[]}
|
|
32
|
+
*/
|
|
33
|
+
export function uniqueBy<T>(array: T[], key: keyof T): T[];
|
|
34
|
+
/**
|
|
35
|
+
* @template {{ value: string }} T
|
|
36
|
+
* @param {T[]} labels
|
|
37
|
+
* @param {number} labelSize
|
|
38
|
+
* @param {string} coordinate
|
|
39
|
+
* @param {boolean} moveBothLabels
|
|
40
|
+
* @returns {T[]}
|
|
41
|
+
*/
|
|
42
|
+
export function positionLabels<T extends {
|
|
43
|
+
value: string;
|
|
44
|
+
}>(labels: T[], labelSize?: number, coordinate?: string, moveBothLabels?: boolean): T[];
|
|
45
|
+
/**
|
|
46
|
+
* Create a function that maps a value from a source domain to a target range.
|
|
47
|
+
*
|
|
48
|
+
* same as this one https://gist.github.com/vectorsize/7031902
|
|
49
|
+
*
|
|
50
|
+
* @param {[number, number]} domain
|
|
51
|
+
* @param {[number, number]} range
|
|
52
|
+
* @returns {(x: number) => number}
|
|
53
|
+
*/
|
|
54
|
+
export function scaleLinear(domain: [number, number], range: [number, number]): (x: number) => number;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
function preventOverlap(labelPositions, iteration = 0, labelSize = 12, coordinate = "y", moveBothLabels = true) {
|
|
2
|
+
const maxIterations = 10;
|
|
3
|
+
let totalOverlap = 0;
|
|
4
|
+
if (!isArrayWithCoordinates(labelPositions, coordinate)) return labelPositions;
|
|
5
|
+
for (let index = 1; index < labelPositions.length; index++) {
|
|
6
|
+
const previousElement = labelPositions[index - 1];
|
|
7
|
+
const element = labelPositions[index];
|
|
8
|
+
const overlap = previousElement[coordinate] - (element[coordinate] - labelSize);
|
|
9
|
+
if (overlap < 0) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (moveBothLabels) {
|
|
13
|
+
previousElement[coordinate] -= overlap / 2;
|
|
14
|
+
element[coordinate] += overlap / 2;
|
|
15
|
+
} else {
|
|
16
|
+
previousElement[coordinate] -= overlap;
|
|
17
|
+
}
|
|
18
|
+
totalOverlap += overlap;
|
|
19
|
+
}
|
|
20
|
+
if (totalOverlap > 0 && iteration < maxIterations) {
|
|
21
|
+
return preventOverlap(
|
|
22
|
+
labelPositions,
|
|
23
|
+
iteration + 1,
|
|
24
|
+
labelSize,
|
|
25
|
+
coordinate,
|
|
26
|
+
moveBothLabels
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return labelPositions;
|
|
30
|
+
}
|
|
31
|
+
function uniqueBy(array, key) {
|
|
32
|
+
return [...array.reduce((map, d) => map.set(d[key], d), /* @__PURE__ */ new Map()).values()];
|
|
33
|
+
}
|
|
34
|
+
function positionLabels(labels, labelSize = 12, coordinate = "y", moveBothLabels = true) {
|
|
35
|
+
labels = uniqueBy(labels, "value");
|
|
36
|
+
labels.sort((a, b) => a[coordinate] - b[coordinate]);
|
|
37
|
+
return preventOverlap(labels, 0, labelSize, coordinate, moveBothLabels);
|
|
38
|
+
}
|
|
39
|
+
function scaleLinear(domain, range) {
|
|
40
|
+
const [domainMin, domainMax] = domain;
|
|
41
|
+
const [rangeMin, rangeMax] = range;
|
|
42
|
+
const slope = (rangeMax - rangeMin) / (domainMax - domainMin);
|
|
43
|
+
const intercept = rangeMin - slope * domainMin;
|
|
44
|
+
return function(x) {
|
|
45
|
+
return slope * x + intercept;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function isArrayWithCoordinates(labelPositions, coordinate) {
|
|
49
|
+
return labelPositions.every(
|
|
50
|
+
(position) => typeof position[coordinate] === "number"
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
positionLabels,
|
|
55
|
+
preventOverlap,
|
|
56
|
+
scaleLinear,
|
|
57
|
+
uniqueBy
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function useContainerSize(containerRef: any): undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState, useLayoutEffect } from "preact/hooks";
|
|
2
|
+
function useContainerSize(containerRef) {
|
|
3
|
+
const [containerSize, setContainerSize] = useState();
|
|
4
|
+
useLayoutEffect(() => {
|
|
5
|
+
const container = containerRef.current;
|
|
6
|
+
if (!container) return;
|
|
7
|
+
const observer = new ResizeObserver((entries) => {
|
|
8
|
+
for (let entry of entries) {
|
|
9
|
+
setContainerSize({
|
|
10
|
+
width: entry.contentRect.width,
|
|
11
|
+
height: entry.contentRect.height
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
observer.observe(container);
|
|
16
|
+
return () => {
|
|
17
|
+
observer.disconnect();
|
|
18
|
+
};
|
|
19
|
+
}, [containerRef]);
|
|
20
|
+
return containerSize;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
useContainerSize
|
|
24
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useRef, useState, useEffect } from "preact/hooks";
|
|
2
|
+
import { pointInsideRect } from "../helpers/geometry.js";
|
|
3
|
+
function useTouchOrHover() {
|
|
4
|
+
const ref = useRef();
|
|
5
|
+
const [activeEvent, setActiveEvent] = useState();
|
|
6
|
+
const [position, setPosition] = useState();
|
|
7
|
+
const [isActive, setIsActive] = useState(false);
|
|
8
|
+
const [touchRect, setTouchRect] = useState();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const element = ref.current;
|
|
11
|
+
let touchCancelled = false;
|
|
12
|
+
const touchStarted = (event) => {
|
|
13
|
+
if (event.touches.length > 1) return;
|
|
14
|
+
touchCancelled = false;
|
|
15
|
+
const touch = event.touches[0];
|
|
16
|
+
const { clientX, clientY } = touch;
|
|
17
|
+
const rect = element.getBoundingClientRect();
|
|
18
|
+
const point = { x: clientX - rect.left, y: clientY - rect.top };
|
|
19
|
+
setPosition(point);
|
|
20
|
+
const touchRect2 = {
|
|
21
|
+
x: clientX - touch.radiusX,
|
|
22
|
+
y: clientY - touch.radiusY,
|
|
23
|
+
width: touch.radiusX * 2,
|
|
24
|
+
height: touch.radiusY * 2
|
|
25
|
+
};
|
|
26
|
+
setTouchRect(touchRect2);
|
|
27
|
+
setActiveEvent(event);
|
|
28
|
+
setIsActive(true);
|
|
29
|
+
event.stopPropagation();
|
|
30
|
+
};
|
|
31
|
+
const touchMoved = (event) => {
|
|
32
|
+
if (touchCancelled || event.targetTouches.length !== 1) return;
|
|
33
|
+
setActiveEvent(event);
|
|
34
|
+
const touch = event.targetTouches[0];
|
|
35
|
+
const { clientX, clientY } = touch;
|
|
36
|
+
const rect = element.getBoundingClientRect();
|
|
37
|
+
const point = { x: clientX - rect.left, y: clientY - rect.top };
|
|
38
|
+
if (!event.cancelable || !pointInsideRect(point, rect)) {
|
|
39
|
+
setIsActive(false);
|
|
40
|
+
touchCancelled = true;
|
|
41
|
+
} else {
|
|
42
|
+
setPosition(point);
|
|
43
|
+
setIsActive(true);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const touchEnded = (event) => {
|
|
47
|
+
if (event.cancelable) {
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
}
|
|
50
|
+
setActiveEvent(null);
|
|
51
|
+
setIsActive(false);
|
|
52
|
+
setPosition(null);
|
|
53
|
+
};
|
|
54
|
+
const mouseOver = (event) => {
|
|
55
|
+
const { clientX, clientY } = event;
|
|
56
|
+
const rect = element.getBoundingClientRect();
|
|
57
|
+
const x = clientX - rect.left;
|
|
58
|
+
const y = clientY - rect.top;
|
|
59
|
+
setPosition({ x, y });
|
|
60
|
+
setActiveEvent(event);
|
|
61
|
+
setIsActive(true);
|
|
62
|
+
};
|
|
63
|
+
const mouseMoved = (event) => {
|
|
64
|
+
const { clientX, clientY } = event;
|
|
65
|
+
const rect = element.getBoundingClientRect();
|
|
66
|
+
const x = clientX - rect.left;
|
|
67
|
+
const y = clientY - rect.top;
|
|
68
|
+
setActiveEvent(event);
|
|
69
|
+
setPosition({ x, y });
|
|
70
|
+
};
|
|
71
|
+
const mouseOut = () => {
|
|
72
|
+
setPosition(null);
|
|
73
|
+
setActiveEvent(null);
|
|
74
|
+
setIsActive(false);
|
|
75
|
+
};
|
|
76
|
+
element.addEventListener("touchstart", touchStarted);
|
|
77
|
+
element.addEventListener("touchmove", touchMoved);
|
|
78
|
+
element.addEventListener("touchend", touchEnded);
|
|
79
|
+
element.addEventListener("touchcancel", touchEnded);
|
|
80
|
+
element.addEventListener("mouseover", mouseOver);
|
|
81
|
+
element.addEventListener("mousemove", mouseMoved);
|
|
82
|
+
element.addEventListener("mouseout", mouseOut);
|
|
83
|
+
return () => {
|
|
84
|
+
element.removeEventListener("touchstart", touchStarted);
|
|
85
|
+
element.removeEventListener("touchmove", touchMoved);
|
|
86
|
+
element.removeEventListener("touchend", mouseOut);
|
|
87
|
+
element.removeEventListener("touchcancel", mouseOut);
|
|
88
|
+
element.removeEventListener("mouseover", touchStarted);
|
|
89
|
+
element.removeEventListener("mousemove", mouseMoved);
|
|
90
|
+
element.removeEventListener("mouseout", mouseOut);
|
|
91
|
+
};
|
|
92
|
+
}, []);
|
|
93
|
+
return {
|
|
94
|
+
touchOrHoverRef: ref,
|
|
95
|
+
touchOrHoverIsActive: isActive,
|
|
96
|
+
touchRect,
|
|
97
|
+
positionInTarget: position,
|
|
98
|
+
activeEvent
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
useTouchOrHover
|
|
103
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useState, useLayoutEffect } from "preact/hooks";
|
|
2
|
+
function useWindowSize() {
|
|
3
|
+
const [windowSize, setWindowSize] = useState(() => {
|
|
4
|
+
if (typeof window === "undefined") return { width: 0, height: 0 };
|
|
5
|
+
return {
|
|
6
|
+
width: window.innerWidth,
|
|
7
|
+
height: window.innerHeight
|
|
8
|
+
};
|
|
9
|
+
});
|
|
10
|
+
useLayoutEffect(() => {
|
|
11
|
+
if (typeof window === "undefined") return;
|
|
12
|
+
function handleResize() {
|
|
13
|
+
setWindowSize({
|
|
14
|
+
width: window.innerWidth,
|
|
15
|
+
height: window.innerHeight
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
window.addEventListener("resize", handleResize);
|
|
19
|
+
return () => {
|
|
20
|
+
window.removeEventListener("resize", handleResize);
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
return windowSize;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
useWindowSize
|
|
27
|
+
};
|