@yewdiel21/motion-kit 0.10.0 → 0.15.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/README.md +81 -0
- package/bin/motion-kit.mjs +3 -3
- package/dist/auto/index.d.ts +56 -3
- package/dist/auto/index.js +107 -3
- package/dist/auto/index.js.map +1 -1
- package/dist/{chunk-XAKC2QY7.js → chunk-6IRJYXJU.js} +3 -28
- package/dist/chunk-6IRJYXJU.js.map +1 -0
- package/dist/chunk-A6QQCF6V.js +21333 -0
- package/dist/chunk-A6QQCF6V.js.map +1 -0
- package/dist/chunk-JXRS3OEA.js +3638 -0
- package/dist/chunk-JXRS3OEA.js.map +1 -0
- package/dist/chunk-QP4QJOEN.js +72 -0
- package/dist/chunk-QP4QJOEN.js.map +1 -0
- package/dist/css/components/activity-feed.css +240 -0
- package/dist/css/components/add-to-cart.css +72 -0
- package/dist/css/components/attachment.css +266 -0
- package/dist/css/components/bidirectional-slider.css +168 -0
- package/dist/css/components/breadcrumb.css +110 -0
- package/dist/css/components/chart-tooltip.css +168 -0
- package/dist/css/components/chart.css +296 -0
- package/dist/css/components/code-block.css +264 -0
- package/dist/css/components/color-area.css +82 -0
- package/dist/css/components/color-field.css +67 -0
- package/dist/css/components/color-picker.css +131 -0
- package/dist/css/components/color-slider.css +113 -0
- package/dist/css/components/command-search.css +252 -0
- package/dist/css/components/context-menu.css +23 -0
- package/dist/css/components/credit-card.css +288 -0
- package/dist/css/components/data-table.css +686 -0
- package/dist/css/components/date-range-picker.css +168 -0
- package/dist/css/components/date-time-picker.css +178 -0
- package/dist/css/components/drawer.css +58 -0
- package/dist/css/components/editable-table.css +201 -0
- package/dist/css/components/empty-state.css +61 -0
- package/dist/css/components/file-explorer.css +633 -0
- package/dist/css/components/filter-builder.css +227 -0
- package/dist/css/components/heatmap-chart.css +391 -0
- package/dist/css/components/hold-confirm.css +87 -0
- package/dist/css/components/hover-card.css +19 -7
- package/dist/css/components/image-preview.css +283 -0
- package/dist/css/components/json-viewer.css +304 -0
- package/dist/css/components/like-button.css +78 -0
- package/dist/css/components/link-preview.css +275 -0
- package/dist/css/components/loading-button.css +77 -0
- package/dist/css/components/multi-select.css +267 -0
- package/dist/css/components/nav.css +102 -102
- package/dist/css/components/notification-bell.css +127 -0
- package/dist/css/components/orbit-menu.css +130 -0
- package/dist/css/components/pagination.css +10 -5
- package/dist/css/components/password-strength.css +183 -0
- package/dist/css/components/pie-chart.css +390 -0
- package/dist/css/components/pill-button.css +135 -0
- package/dist/css/components/popover.css +25 -0
- package/dist/css/components/progress.css +140 -0
- package/dist/css/components/questionnaire.css +217 -0
- package/dist/css/components/radar-chart.css +370 -0
- package/dist/css/components/radial-chart.css +398 -0
- package/dist/css/components/range-calendar.css +186 -0
- package/dist/css/components/range-slider.css +192 -0
- package/dist/css/components/resizable-panel.css +243 -0
- package/dist/css/components/rich-text-editor.css +284 -0
- package/dist/css/components/sankey-chart.css +358 -0
- package/dist/css/components/scratch-card.css +75 -0
- package/dist/css/components/scroll-island.css +111 -0
- package/dist/css/components/select.css +136 -0
- package/dist/css/components/skeleton.css +108 -0
- package/dist/css/components/split-view.css +19 -0
- package/dist/css/components/star-rating.css +80 -0
- package/dist/css/components/stat-card.css +164 -0
- package/dist/css/components/swipe-actions.css +105 -0
- package/dist/css/components/tag-input.css +244 -0
- package/dist/css/components/time-field.css +88 -0
- package/dist/css/components/timeline.css +219 -0
- package/dist/css/components/toolbar.css +122 -0
- package/dist/css/components/tooltip.css +79 -0
- package/dist/css/components/tree-view.css +289 -0
- package/dist/css/components/virtual-list.css +195 -0
- package/dist/css/components/voice-dots.css +70 -0
- package/dist/css/tokens.css +185 -181
- package/dist/elements/index.d.ts +849 -7
- package/dist/elements/index.js +1642 -8
- package/dist/elements/index.js.map +1 -1
- package/dist/{engine-GDGwQnJE.d.ts → engine-5zRIssTO.d.ts} +11 -1
- package/dist/engine-QECQnGz1.d.ts +33 -0
- package/dist/index.css +10890 -311
- package/dist/index.d.ts +89 -5
- package/dist/index.js +273 -9
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +686 -24
- package/dist/react/index.js +2345 -9
- package/dist/react/index.js.map +1 -1
- package/dist/{reduced-BmBzKH94.d.ts → reduced-6X_bns60.d.ts} +9 -2
- package/dist/reveal-BfyKKsw4.d.ts +2474 -0
- package/dist/store-CA2Qcun_.d.ts +453 -0
- package/package.json +9 -16
- package/registry.json +1096 -543
- package/src/auto/auto-init.ts +104 -0
- package/src/components/activity-feed/README.md +56 -0
- package/src/components/activity-feed/activity-feed.css +239 -0
- package/src/components/activity-feed/element.ts +36 -0
- package/src/components/activity-feed/engine.ts +351 -0
- package/src/components/activity-feed/react.tsx +32 -0
- package/src/components/add-to-cart/README.md +34 -0
- package/src/components/add-to-cart/add-to-cart.css +71 -0
- package/src/components/add-to-cart/element.ts +20 -0
- package/src/components/add-to-cart/engine.ts +206 -0
- package/src/components/add-to-cart/react.tsx +29 -0
- package/src/components/attachment/README.md +27 -0
- package/src/components/attachment/attachment.css +265 -0
- package/src/components/attachment/element.ts +50 -0
- package/src/components/attachment/engine.ts +469 -0
- package/src/components/attachment/react.tsx +65 -0
- package/src/components/bidirectional-slider/README.md +46 -0
- package/src/components/bidirectional-slider/bidirectional-slider.css +167 -0
- package/src/components/bidirectional-slider/element.ts +42 -0
- package/src/components/bidirectional-slider/engine.ts +289 -0
- package/src/components/bidirectional-slider/react.tsx +45 -0
- package/src/components/breadcrumb/README.md +38 -0
- package/src/components/breadcrumb/breadcrumb.css +109 -0
- package/src/components/breadcrumb/element.ts +27 -0
- package/src/components/breadcrumb/engine.ts +249 -0
- package/src/components/breadcrumb/react.tsx +30 -0
- package/src/components/chart/README.md +34 -0
- package/src/components/chart/chart.css +295 -0
- package/src/components/chart/element.ts +43 -0
- package/src/components/chart/engine.ts +838 -0
- package/src/components/chart/parts.ts +237 -0
- package/src/components/chart/react.tsx +50 -0
- package/src/components/chart/use-chart.ts +55 -0
- package/src/components/chart-tooltip/README.md +53 -0
- package/src/components/chart-tooltip/chart-tooltip.css +167 -0
- package/src/components/chart-tooltip/element.ts +37 -0
- package/src/components/chart-tooltip/engine.ts +442 -0
- package/src/components/chart-tooltip/react.tsx +47 -0
- package/src/components/code-block/README.md +19 -0
- package/src/components/code-block/code-block.css +263 -0
- package/src/components/code-block/element.ts +34 -0
- package/src/components/code-block/engine.ts +254 -0
- package/src/components/code-block/highlight.ts +244 -0
- package/src/components/code-block/react.tsx +94 -0
- package/src/components/color-area/README.md +50 -0
- package/src/components/color-area/color-area.css +81 -0
- package/src/components/color-area/element.ts +26 -0
- package/src/components/color-area/engine.ts +246 -0
- package/src/components/color-area/react.tsx +42 -0
- package/src/components/color-field/README.md +43 -0
- package/src/components/color-field/color-field.css +66 -0
- package/src/components/color-field/element.ts +26 -0
- package/src/components/color-field/engine.ts +174 -0
- package/src/components/color-field/react.tsx +42 -0
- package/src/components/color-picker/README.md +45 -0
- package/src/components/color-picker/color-picker.css +130 -0
- package/src/components/color-picker/element.ts +45 -0
- package/src/components/color-picker/engine.ts +314 -0
- package/src/components/color-picker/react.tsx +47 -0
- package/src/components/color-slider/README.md +55 -0
- package/src/components/color-slider/color-slider.css +112 -0
- package/src/components/color-slider/element.ts +26 -0
- package/src/components/color-slider/engine.ts +234 -0
- package/src/components/color-slider/react.tsx +45 -0
- package/src/components/command-search/README.md +15 -0
- package/src/components/command-search/command-search.css +251 -0
- package/src/components/command-search/element.ts +36 -0
- package/src/components/command-search/engine.ts +356 -0
- package/src/components/command-search/match.ts +53 -0
- package/src/components/command-search/react.tsx +66 -0
- package/src/components/context-menu/README.md +31 -0
- package/src/components/context-menu/context-menu.css +22 -0
- package/src/components/context-menu/element.ts +40 -0
- package/src/components/context-menu/engine.ts +153 -0
- package/src/components/context-menu/react.tsx +57 -0
- package/src/components/credit-card/README.md +20 -0
- package/src/components/credit-card/card.ts +77 -0
- package/src/components/credit-card/credit-card.css +287 -0
- package/src/components/credit-card/element.ts +33 -0
- package/src/components/credit-card/engine.ts +410 -0
- package/src/components/credit-card/react.tsx +36 -0
- package/src/components/data-table/README.md +83 -0
- package/src/components/data-table/data-table.css +685 -0
- package/src/components/data-table/element.ts +54 -0
- package/src/components/data-table/engine.ts +1111 -0
- package/src/components/data-table/react.tsx +94 -0
- package/src/components/date-range-picker/README.md +51 -0
- package/src/components/date-range-picker/date-range-picker.css +167 -0
- package/src/components/date-range-picker/element.ts +52 -0
- package/src/components/date-range-picker/engine.ts +352 -0
- package/src/components/date-range-picker/react.tsx +57 -0
- package/src/components/date-time-picker/README.md +48 -0
- package/src/components/date-time-picker/date-time-picker.css +177 -0
- package/src/components/date-time-picker/element.ts +47 -0
- package/src/components/date-time-picker/engine.ts +350 -0
- package/src/components/date-time-picker/react.tsx +54 -0
- package/src/components/dialog/README.md +103 -102
- package/src/components/dialog/element.ts +123 -118
- package/src/components/dialog/engine.ts +449 -432
- package/src/components/drawer/README.md +28 -0
- package/src/components/drawer/drawer.css +57 -0
- package/src/components/drawer/element.ts +21 -0
- package/src/components/drawer/engine.ts +56 -0
- package/src/components/drawer/react.tsx +85 -0
- package/src/components/editable-table/README.md +67 -0
- package/src/components/editable-table/editable-table.css +200 -0
- package/src/components/editable-table/element.ts +45 -0
- package/src/components/editable-table/engine.ts +831 -0
- package/src/components/editable-table/react.tsx +79 -0
- package/src/components/empty-state/README.md +41 -0
- package/src/components/empty-state/element.ts +23 -0
- package/src/components/empty-state/empty-state.css +60 -0
- package/src/components/empty-state/engine.ts +232 -0
- package/src/components/empty-state/react.tsx +34 -0
- package/src/components/file-explorer/README.md +67 -0
- package/src/components/file-explorer/element.ts +39 -0
- package/src/components/file-explorer/engine.ts +1307 -0
- package/src/components/file-explorer/file-explorer.css +632 -0
- package/src/components/file-explorer/react.tsx +77 -0
- package/src/components/filter-builder/README.md +47 -0
- package/src/components/filter-builder/element.ts +34 -0
- package/src/components/filter-builder/engine.ts +396 -0
- package/src/components/filter-builder/filter-builder.css +226 -0
- package/src/components/filter-builder/react.tsx +36 -0
- package/src/components/heatmap-chart/README.md +48 -0
- package/src/components/heatmap-chart/element.ts +21 -0
- package/src/components/heatmap-chart/engine.ts +281 -0
- package/src/components/heatmap-chart/heatmap-chart.css +93 -0
- package/src/components/heatmap-chart/react.tsx +14 -0
- package/src/components/hold-confirm/README.md +13 -0
- package/src/components/hold-confirm/element.ts +24 -0
- package/src/components/hold-confirm/engine.ts +216 -0
- package/src/components/hold-confirm/hold-confirm.css +86 -0
- package/src/components/hold-confirm/react.tsx +28 -0
- package/src/components/hover-card/README.md +6 -2
- package/src/components/hover-card/engine.ts +98 -7
- package/src/components/hover-card/hover-card.css +19 -7
- package/src/components/image-preview/README.md +16 -0
- package/src/components/image-preview/element.ts +26 -0
- package/src/components/image-preview/engine.ts +405 -0
- package/src/components/image-preview/image-preview.css +282 -0
- package/src/components/image-preview/react.tsx +43 -0
- package/src/components/json-viewer/README.md +56 -0
- package/src/components/json-viewer/element.ts +37 -0
- package/src/components/json-viewer/engine.ts +449 -0
- package/src/components/json-viewer/json-viewer.css +303 -0
- package/src/components/json-viewer/react.tsx +56 -0
- package/src/components/like-button/README.md +13 -0
- package/src/components/like-button/element.ts +47 -0
- package/src/components/like-button/engine.ts +145 -0
- package/src/components/like-button/like-button.css +77 -0
- package/src/components/like-button/react.tsx +39 -0
- package/src/components/link-preview/README.md +19 -0
- package/src/components/link-preview/element.ts +29 -0
- package/src/components/link-preview/engine.ts +192 -0
- package/src/components/link-preview/link-preview.css +274 -0
- package/src/components/link-preview/react.tsx +101 -0
- package/src/components/loading-button/README.md +45 -0
- package/src/components/loading-button/element.ts +34 -0
- package/src/components/loading-button/engine.ts +201 -0
- package/src/components/loading-button/loading-button.css +76 -0
- package/src/components/loading-button/react.tsx +43 -0
- package/src/components/multi-select/README.md +48 -0
- package/src/components/multi-select/element.ts +28 -0
- package/src/components/multi-select/engine.ts +294 -0
- package/src/components/multi-select/multi-select.css +266 -0
- package/src/components/multi-select/react.tsx +39 -0
- package/src/components/nav/README.md +12 -10
- package/src/components/nav/element.ts +5 -5
- package/src/components/nav/engine.ts +21 -14
- package/src/components/nav/nav.css +102 -102
- package/src/components/nav/react.tsx +4 -4
- package/src/components/notification-bell/README.md +14 -0
- package/src/components/notification-bell/element.ts +48 -0
- package/src/components/notification-bell/engine.ts +202 -0
- package/src/components/notification-bell/notification-bell.css +126 -0
- package/src/components/notification-bell/react.tsx +57 -0
- package/src/components/orbit-menu/README.md +46 -0
- package/src/components/orbit-menu/element.ts +27 -0
- package/src/components/orbit-menu/engine.ts +179 -0
- package/src/components/orbit-menu/orbit-menu.css +129 -0
- package/src/components/orbit-menu/react.tsx +44 -0
- package/src/components/pagination/README.md +1 -1
- package/src/components/pagination/engine.ts +50 -4
- package/src/components/pagination/pagination.css +10 -5
- package/src/components/password-strength/README.md +17 -0
- package/src/components/password-strength/element.ts +22 -0
- package/src/components/password-strength/engine.ts +212 -0
- package/src/components/password-strength/password-strength.css +182 -0
- package/src/components/password-strength/react.tsx +36 -0
- package/src/components/password-strength/score.ts +62 -0
- package/src/components/pie-chart/README.md +48 -0
- package/src/components/pie-chart/element.ts +30 -0
- package/src/components/pie-chart/engine.ts +283 -0
- package/src/components/pie-chart/pie-chart.css +92 -0
- package/src/components/pie-chart/react.tsx +14 -0
- package/src/components/pill-button/README.md +46 -0
- package/src/components/pill-button/element.ts +16 -0
- package/src/components/pill-button/engine.ts +77 -0
- package/src/components/pill-button/pill-button.css +134 -0
- package/src/components/pill-button/react.tsx +32 -0
- package/src/components/popover/README.md +44 -0
- package/src/components/popover/element.ts +31 -0
- package/src/components/popover/engine.ts +114 -0
- package/src/components/popover/popover.css +24 -0
- package/src/components/popover/react.tsx +50 -0
- package/src/components/progress/README.md +17 -0
- package/src/components/progress/element.ts +30 -0
- package/src/components/progress/engine.ts +173 -0
- package/src/components/progress/progress.css +139 -0
- package/src/components/progress/react.tsx +35 -0
- package/src/components/questionnaire/README.md +32 -0
- package/src/components/questionnaire/element.ts +118 -0
- package/src/components/questionnaire/engine.ts +255 -0
- package/src/components/questionnaire/questionnaire.css +216 -0
- package/src/components/questionnaire/react.tsx +140 -0
- package/src/components/radar-chart/README.md +48 -0
- package/src/components/radar-chart/element.ts +30 -0
- package/src/components/radar-chart/engine.ts +327 -0
- package/src/components/radar-chart/radar-chart.css +72 -0
- package/src/components/radar-chart/react.tsx +14 -0
- package/src/components/radial-chart/README.md +48 -0
- package/src/components/radial-chart/element.ts +30 -0
- package/src/components/radial-chart/engine.ts +290 -0
- package/src/components/radial-chart/radial-chart.css +100 -0
- package/src/components/radial-chart/react.tsx +14 -0
- package/src/components/range-calendar/README.md +58 -0
- package/src/components/range-calendar/element.ts +42 -0
- package/src/components/range-calendar/engine.ts +390 -0
- package/src/components/range-calendar/range-calendar.css +185 -0
- package/src/components/range-calendar/react.tsx +56 -0
- package/src/components/range-slider/README.md +23 -0
- package/src/components/range-slider/element.ts +53 -0
- package/src/components/range-slider/engine.ts +316 -0
- package/src/components/range-slider/range-slider.css +191 -0
- package/src/components/range-slider/react.tsx +66 -0
- package/src/components/resizable-panel/README.md +61 -0
- package/src/components/resizable-panel/element.ts +36 -0
- package/src/components/resizable-panel/engine.ts +551 -0
- package/src/components/resizable-panel/react.tsx +74 -0
- package/src/components/resizable-panel/resizable-panel.css +242 -0
- package/src/components/rich-text-editor/README.md +57 -0
- package/src/components/rich-text-editor/element.ts +34 -0
- package/src/components/rich-text-editor/engine.ts +673 -0
- package/src/components/rich-text-editor/react.tsx +60 -0
- package/src/components/rich-text-editor/rich-text-editor.css +283 -0
- package/src/components/sankey-chart/README.md +48 -0
- package/src/components/sankey-chart/element.ts +31 -0
- package/src/components/sankey-chart/engine.ts +401 -0
- package/src/components/sankey-chart/react.tsx +14 -0
- package/src/components/sankey-chart/sankey-chart.css +60 -0
- package/src/components/scratch-card/README.md +15 -0
- package/src/components/scratch-card/element.ts +30 -0
- package/src/components/scratch-card/engine.ts +257 -0
- package/src/components/scratch-card/react.tsx +40 -0
- package/src/components/scratch-card/scratch-card.css +74 -0
- package/src/components/scroll-island/README.md +34 -0
- package/src/components/scroll-island/element.ts +16 -0
- package/src/components/scroll-island/engine.ts +252 -0
- package/src/components/scroll-island/react.tsx +26 -0
- package/src/components/scroll-island/scroll-island.css +110 -0
- package/src/components/select/README.md +34 -0
- package/src/components/select/element.ts +26 -0
- package/src/components/select/engine.ts +267 -0
- package/src/components/select/react.tsx +33 -0
- package/src/components/select/select.css +135 -0
- package/src/components/skeleton/README.md +15 -0
- package/src/components/skeleton/element.ts +32 -0
- package/src/components/skeleton/engine.ts +104 -0
- package/src/components/skeleton/react.tsx +41 -0
- package/src/components/skeleton/skeleton.css +107 -0
- package/src/components/split-view/README.md +50 -0
- package/src/components/split-view/element.ts +34 -0
- package/src/components/split-view/engine.ts +114 -0
- package/src/components/split-view/react.tsx +63 -0
- package/src/components/split-view/split-view.css +18 -0
- package/src/components/star-rating/README.md +14 -0
- package/src/components/star-rating/element.ts +26 -0
- package/src/components/star-rating/engine.ts +217 -0
- package/src/components/star-rating/react.tsx +33 -0
- package/src/components/star-rating/star-rating.css +79 -0
- package/src/components/stat-card/README.md +42 -0
- package/src/components/stat-card/element.ts +40 -0
- package/src/components/stat-card/engine.ts +283 -0
- package/src/components/stat-card/react.tsx +36 -0
- package/src/components/stat-card/stat-card.css +163 -0
- package/src/components/swipe-actions/README.md +19 -0
- package/src/components/swipe-actions/element.ts +26 -0
- package/src/components/swipe-actions/engine.ts +260 -0
- package/src/components/swipe-actions/react.tsx +80 -0
- package/src/components/swipe-actions/swipe-actions.css +104 -0
- package/src/components/tag-input/README.md +42 -0
- package/src/components/tag-input/element.ts +39 -0
- package/src/components/tag-input/engine.ts +313 -0
- package/src/components/tag-input/react.tsx +54 -0
- package/src/components/tag-input/tag-input.css +243 -0
- package/src/components/time-field/README.md +54 -0
- package/src/components/time-field/element.ts +38 -0
- package/src/components/time-field/engine.ts +110 -0
- package/src/components/time-field/react.tsx +45 -0
- package/src/components/time-field/time-field.css +87 -0
- package/src/components/timeline/README.md +57 -0
- package/src/components/timeline/element.ts +31 -0
- package/src/components/timeline/engine.ts +300 -0
- package/src/components/timeline/react.tsx +59 -0
- package/src/components/timeline/timeline.css +218 -0
- package/src/components/toolbar/README.md +46 -0
- package/src/components/toolbar/element.ts +30 -0
- package/src/components/toolbar/engine.ts +230 -0
- package/src/components/toolbar/react.tsx +34 -0
- package/src/components/toolbar/toolbar.css +121 -0
- package/src/components/tooltip/README.md +46 -0
- package/src/components/tooltip/element.ts +22 -0
- package/src/components/tooltip/engine.ts +288 -0
- package/src/components/tooltip/react.tsx +30 -0
- package/src/components/tooltip/tooltip.css +78 -0
- package/src/components/tree-view/README.md +61 -0
- package/src/components/tree-view/element.ts +32 -0
- package/src/components/tree-view/engine.ts +743 -0
- package/src/components/tree-view/react.tsx +82 -0
- package/src/components/tree-view/tree-view.css +288 -0
- package/src/components/virtual-list/README.md +81 -0
- package/src/components/virtual-list/element.ts +42 -0
- package/src/components/virtual-list/engine.ts +678 -0
- package/src/components/virtual-list/react.tsx +101 -0
- package/src/components/virtual-list/virtual-list.css +194 -0
- package/src/components/voice-dots/README.md +48 -0
- package/src/components/voice-dots/element.ts +45 -0
- package/src/components/voice-dots/engine.ts +243 -0
- package/src/components/voice-dots/react.tsx +52 -0
- package/src/components/voice-dots/voice-dots.css +69 -0
- package/src/core/chips.ts +196 -0
- package/src/core/color.ts +304 -0
- package/src/core/date-range.ts +67 -0
- package/src/core/dates.ts +11 -1
- package/src/core/files.ts +107 -0
- package/src/core/filter.ts +229 -0
- package/src/core/gsap.ts +80 -65
- package/src/core/listbox.ts +332 -0
- package/src/core/mark.ts +29 -0
- package/src/core/position.ts +89 -0
- package/src/core/relative-time.ts +77 -0
- package/src/core/segment-field.ts +373 -0
- package/src/core/segments.ts +153 -0
- package/src/core/tree.ts +116 -0
- package/src/core/virtual.ts +79 -0
- package/src/css/tokens.css +186 -182
- package/src/elements/index.ts +186 -0
- package/src/index.ts +88 -0
- package/src/motion/liquid.ts +14 -4
- package/src/motion/micro.ts +248 -0
- package/src/motion/sheet.ts +88 -65
- package/src/motion/surface.ts +9 -0
- package/src/react/index.ts +71 -1
- package/dist/chunk-IKQ5FODN.js +0 -1617
- package/dist/chunk-IKQ5FODN.js.map +0 -1
- package/dist/chunk-J6OCFNGU.js +0 -177
- package/dist/chunk-J6OCFNGU.js.map +0 -1
- package/dist/chunk-TFNRIZHU.js +0 -3977
- package/dist/chunk-TFNRIZHU.js.map +0 -1
- package/dist/chunk-XAKC2QY7.js.map +0 -1
- package/dist/reveal-jsX-uwUz.d.ts +0 -625
- package/dist/store-DYb3tTsZ.d.ts +0 -195
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { gsap, EASE, registerMotion } from '../../core/gsap';
|
|
2
|
+
import { reduced } from '../../core/reduced';
|
|
3
|
+
import { createScope } from '../../core/scope';
|
|
4
|
+
import { inert, type Instance } from '../../core/types';
|
|
5
|
+
import { chartFrame, finite, formatNumber, onWidth, round, slotColor, svg, SVG_NS } from '../chart/parts';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Sankey chart: flows between stages as bands as wide as their value, in
|
|
9
|
+
* chart's family. Nodes stand in columns by their depth (the ones that lead
|
|
10
|
+
* nowhere end at the right), stacked in the given order and centred; each
|
|
11
|
+
* band fades from its source's colour to its target's. The nodes grow from
|
|
12
|
+
* their middles, column after column, while the bands are wiped in from the
|
|
13
|
+
* left (.9 s); new data with the same nodes and flows glides every node and
|
|
14
|
+
* band. Pointing at a band (or the arrows) lights it and dims the rest, with
|
|
15
|
+
* "A → B" and its share in the tooltip; pointing at a node lights its bands.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export interface SankeyNode {
|
|
19
|
+
id: string;
|
|
20
|
+
label?: string;
|
|
21
|
+
color?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SankeyLink {
|
|
25
|
+
source: string;
|
|
26
|
+
target: string;
|
|
27
|
+
value: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SankeyChartOptions {
|
|
31
|
+
nodes?: SankeyNode[];
|
|
32
|
+
links?: SankeyLink[];
|
|
33
|
+
/** Plot height in px (default 320). */
|
|
34
|
+
height?: number;
|
|
35
|
+
/** Node width in px (default 12). */
|
|
36
|
+
nodeWidth?: number;
|
|
37
|
+
/** Space between nodes in a column, px (default 14). */
|
|
38
|
+
nodePadding?: number;
|
|
39
|
+
label?: string;
|
|
40
|
+
formatValue?: (value: number) => string;
|
|
41
|
+
emptyLabel?: string;
|
|
42
|
+
/** A flow was chosen (its index in `links`), or none. */
|
|
43
|
+
onSelect?: (index: number | null) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface SankeyChartInstance extends Instance {
|
|
47
|
+
update(options: SankeyChartOptions): void;
|
|
48
|
+
select(index: number | null): void;
|
|
49
|
+
readonly selected: number | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface Layout {
|
|
53
|
+
nodes: Array<{ x: number; y0: number; y1: number }>;
|
|
54
|
+
links: Array<{ sy: number; ty: number; width: number }>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createSankeyChart(root: HTMLElement | null, initial: SankeyChartOptions = {}): SankeyChartInstance {
|
|
58
|
+
if (!root) return inert({ update() {}, select() {}, selected: null });
|
|
59
|
+
registerMotion();
|
|
60
|
+
const scope = createScope();
|
|
61
|
+
const frame = chartFrame(root, scope, 'sankey');
|
|
62
|
+
const { plot, canvas } = frame;
|
|
63
|
+
let options: SankeyChartOptions = { ...initial };
|
|
64
|
+
let selected: number | null = null;
|
|
65
|
+
let hoverNode: number | null = null;
|
|
66
|
+
const uid = `mk-sankey-${Math.random().toString(36).slice(2, 8)}`;
|
|
67
|
+
|
|
68
|
+
const format = (value: number) => (options.formatValue ? options.formatValue(value) : formatNumber(value));
|
|
69
|
+
const modelOf = () => {
|
|
70
|
+
const nodes = (options.nodes ?? []).map((node, i, all) => ({ id: String(node.id), label: String(node.label ?? node.id), color: node.color ?? slotColor(i, Math.max(2, all.length)) }));
|
|
71
|
+
const index = new Map(nodes.map((node, i) => [node.id, i]));
|
|
72
|
+
const links = (options.links ?? [])
|
|
73
|
+
.map((link, i) => ({ source: index.get(String(link.source)) ?? -1, target: index.get(String(link.target)) ?? -1, value: link.value, given: i }))
|
|
74
|
+
.filter((link) => link.source >= 0 && link.target >= 0 && link.source !== link.target && finite(link.value) && link.value > 0);
|
|
75
|
+
// Depth: the longest way in from a source (bounded, so a loop cannot run away).
|
|
76
|
+
const depth = nodes.map(() => 0);
|
|
77
|
+
for (let pass = 0; pass < nodes.length; pass++) {
|
|
78
|
+
let moved = false;
|
|
79
|
+
for (const link of links) {
|
|
80
|
+
if (depth[link.target]! < depth[link.source]! + 1 && depth[link.source]! + 1 < nodes.length) {
|
|
81
|
+
depth[link.target] = depth[link.source]! + 1;
|
|
82
|
+
moved = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!moved) break;
|
|
86
|
+
}
|
|
87
|
+
const columns = Math.max(0, ...depth) + 1;
|
|
88
|
+
// The ones that lead nowhere end at the right.
|
|
89
|
+
nodes.forEach((_, i) => {
|
|
90
|
+
if (links.some((link) => link.source === i) || !links.some((link) => link.target === i)) return;
|
|
91
|
+
depth[i] = columns - 1;
|
|
92
|
+
});
|
|
93
|
+
const used = nodes.map((_, i) => links.some((link) => link.source === i || link.target === i));
|
|
94
|
+
const value = nodes.map((_, i) => Math.max(links.filter((link) => link.target === i).reduce((s, l) => s + l.value, 0), links.filter((link) => link.source === i).reduce((s, l) => s + l.value, 0)));
|
|
95
|
+
return { nodes, links, depth, columns, used, value };
|
|
96
|
+
};
|
|
97
|
+
let model = modelOf();
|
|
98
|
+
const hasData = () => model.links.length > 0;
|
|
99
|
+
|
|
100
|
+
let width = 600;
|
|
101
|
+
let height = 320;
|
|
102
|
+
const layoutOf = (): Layout => {
|
|
103
|
+
width = Math.max(240, Math.round(plot.clientWidth || root.clientWidth || 600));
|
|
104
|
+
height = Math.max(160, finite(options.height) ? options.height : 320);
|
|
105
|
+
const nodeWidth = Math.max(4, finite(options.nodeWidth) ? options.nodeWidth : 12);
|
|
106
|
+
const pad = Math.max(2, finite(options.nodePadding) ? options.nodePadding : 14);
|
|
107
|
+
const top = 6;
|
|
108
|
+
const usable = height - top * 2;
|
|
109
|
+
const columns = Array.from({ length: model.columns }, (_, c) => model.nodes.map((_, i) => i).filter((i) => model.used[i] && model.depth[i] === c));
|
|
110
|
+
const ky = Math.min(...columns.filter((list) => list.length).map((list) => (usable - pad * (list.length - 1)) / list.reduce((sum, i) => sum + model.value[i]!, 0)));
|
|
111
|
+
const step = model.columns > 1 ? (width - nodeWidth) / (model.columns - 1) : 0;
|
|
112
|
+
const nodes = model.nodes.map(() => ({ x: 0, y0: 0, y1: 0 }));
|
|
113
|
+
for (const list of columns) {
|
|
114
|
+
const total = list.reduce((sum, i) => sum + model.value[i]! * ky, 0) + pad * Math.max(0, list.length - 1);
|
|
115
|
+
let y = top + (usable - total) / 2;
|
|
116
|
+
for (const i of list) {
|
|
117
|
+
const h = Math.max(1, model.value[i]! * ky);
|
|
118
|
+
nodes[i] = { x: model.depth[i]! * step, y0: y, y1: y + h };
|
|
119
|
+
y += h + pad;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Bands leave a node in the order of their targets and arrive in the order of their sources.
|
|
123
|
+
const out = new Map<number, number>();
|
|
124
|
+
const into = new Map<number, number>();
|
|
125
|
+
const centre = (i: number) => (nodes[i]!.y0 + nodes[i]!.y1) / 2;
|
|
126
|
+
const links = model.links.map(() => ({ sy: 0, ty: 0, width: 0 }));
|
|
127
|
+
const order = model.links.map((_, k) => k);
|
|
128
|
+
for (const k of [...order].sort((a, b) => centre(model.links[a]!.target) - centre(model.links[b]!.target))) {
|
|
129
|
+
const link = model.links[k]!;
|
|
130
|
+
const w = link.value * ky;
|
|
131
|
+
const at = out.get(link.source) ?? nodes[link.source]!.y0;
|
|
132
|
+
links[k]!.sy = at + w / 2;
|
|
133
|
+
links[k]!.width = w;
|
|
134
|
+
out.set(link.source, at + w);
|
|
135
|
+
}
|
|
136
|
+
for (const k of [...order].sort((a, b) => centre(model.links[a]!.source) - centre(model.links[b]!.source))) {
|
|
137
|
+
const link = model.links[k]!;
|
|
138
|
+
const at = into.get(link.target) ?? nodes[link.target]!.y0;
|
|
139
|
+
links[k]!.ty = at + links[k]!.width / 2;
|
|
140
|
+
into.set(link.target, at + links[k]!.width);
|
|
141
|
+
}
|
|
142
|
+
return { nodes, links };
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
let shown: Layout | null = null;
|
|
146
|
+
let rects: SVGRectElement[] = [];
|
|
147
|
+
let bands: SVGPathElement[] = [];
|
|
148
|
+
let names: SVGTextElement[] = [];
|
|
149
|
+
let glide: gsap.core.Animation | null = null;
|
|
150
|
+
scope.add(() => glide?.kill());
|
|
151
|
+
const nodeWidth = () => Math.max(4, finite(options.nodeWidth) ? options.nodeWidth : 12);
|
|
152
|
+
|
|
153
|
+
const build = () => {
|
|
154
|
+
canvas.replaceChildren();
|
|
155
|
+
canvas.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
|
156
|
+
canvas.setAttribute('width', String(width));
|
|
157
|
+
canvas.setAttribute('height', String(height));
|
|
158
|
+
const defs = svg('defs');
|
|
159
|
+
const flows = svg('g', { 'data-mk-part': 'links' });
|
|
160
|
+
bands = model.links.map((link, k) => {
|
|
161
|
+
const gradient = svg('linearGradient', { id: `${uid}-${k}`, gradientUnits: 'userSpaceOnUse' });
|
|
162
|
+
const from = svg('stop', { offset: '0' });
|
|
163
|
+
from.style.stopColor = model.nodes[link.source]!.color;
|
|
164
|
+
const to = svg('stop', { offset: '1' });
|
|
165
|
+
to.style.stopColor = model.nodes[link.target]!.color;
|
|
166
|
+
gradient.append(from, to);
|
|
167
|
+
defs.append(gradient);
|
|
168
|
+
const band = svg('path', { 'data-mk-index': k });
|
|
169
|
+
band.style.fill = `url(#${uid}-${k})`;
|
|
170
|
+
flows.append(band);
|
|
171
|
+
return band;
|
|
172
|
+
});
|
|
173
|
+
const nodesLayer = svg('g', { 'data-mk-part': 'nodes' });
|
|
174
|
+
rects = model.nodes.map((node, i) => {
|
|
175
|
+
const rect = svg('rect', { width: nodeWidth(), rx: 3, 'data-mk-node': i });
|
|
176
|
+
rect.style.fill = node.color;
|
|
177
|
+
if (!model.used[i]) rect.style.display = 'none';
|
|
178
|
+
nodesLayer.append(rect);
|
|
179
|
+
return rect;
|
|
180
|
+
});
|
|
181
|
+
const labels = svg('g', { 'data-mk-part': 'labels' });
|
|
182
|
+
names = model.nodes.map((node, i) => {
|
|
183
|
+
const text = svg('text', { 'dominant-baseline': 'middle' });
|
|
184
|
+
text.textContent = node.label;
|
|
185
|
+
const amount = document.createElementNS(SVG_NS, 'tspan');
|
|
186
|
+
amount.setAttribute('data-mk-part', 'amount');
|
|
187
|
+
amount.textContent = ` ${format(model.value[i]!)}`;
|
|
188
|
+
text.append(amount);
|
|
189
|
+
if (!model.used[i]) text.style.display = 'none';
|
|
190
|
+
labels.append(text);
|
|
191
|
+
return text;
|
|
192
|
+
});
|
|
193
|
+
canvas.append(defs, flows, nodesLayer, labels);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const paint = (layout: Layout) => {
|
|
197
|
+
shown = layout;
|
|
198
|
+
const w = nodeWidth();
|
|
199
|
+
layout.nodes.forEach((node, i) => {
|
|
200
|
+
const rect = rects[i]!;
|
|
201
|
+
rect.setAttribute('x', String(round(node.x)));
|
|
202
|
+
rect.setAttribute('y', String(round(node.y0)));
|
|
203
|
+
rect.setAttribute('height', String(round(Math.max(1, node.y1 - node.y0))));
|
|
204
|
+
const last = model.depth[i] === model.columns - 1 && model.columns > 1;
|
|
205
|
+
const name = names[i]!;
|
|
206
|
+
const first = model.depth[i] === 0;
|
|
207
|
+
const x = round(last ? node.x - 8 : first ? node.x + w + 8 : node.x + w / 2);
|
|
208
|
+
const available = model.columns > 1 ? (width - w) / (model.columns - 1) - 20 : width - w - 16;
|
|
209
|
+
const characters = Math.max(3, Math.floor(available / 7));
|
|
210
|
+
const label = model.nodes[i]!.label;
|
|
211
|
+
if (name.firstChild) name.firstChild.textContent = label.length > characters ? `${label.slice(0, characters - 1)}…` : label;
|
|
212
|
+
name.setAttribute('x', String(x));
|
|
213
|
+
name.setAttribute('y', String(round((node.y0 + node.y1) / 2 - 7)));
|
|
214
|
+
name.setAttribute('text-anchor', last ? 'end' : first ? 'start' : 'middle');
|
|
215
|
+
const amount = name.querySelector('tspan');
|
|
216
|
+
amount?.setAttribute('x', String(x));
|
|
217
|
+
amount?.setAttribute('dy', '14');
|
|
218
|
+
});
|
|
219
|
+
layout.links.forEach((link, k) => {
|
|
220
|
+
const { source, target } = model.links[k]!;
|
|
221
|
+
const x0 = layout.nodes[source]!.x + w;
|
|
222
|
+
const x1 = layout.nodes[target]!.x;
|
|
223
|
+
const xm = (x0 + x1) / 2;
|
|
224
|
+
const h = link.width / 2;
|
|
225
|
+
const [s0, s1, t0, t1] = [link.sy - h, link.sy + h, link.ty - h, link.ty + h].map(round);
|
|
226
|
+
bands[k]!.setAttribute('d', `M${round(x0)},${s0}C${round(xm)},${s0} ${round(xm)},${t0} ${round(x1)},${t0}L${round(x1)},${t1}C${round(xm)},${t1} ${round(xm)},${s1} ${round(x0)},${s1}Z`);
|
|
227
|
+
const gradient = canvas.querySelector(`#${uid}-${k}`);
|
|
228
|
+
gradient?.setAttribute('x1', String(round(x0)));
|
|
229
|
+
gradient?.setAttribute('x2', String(round(x1)));
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const share = (part: number, whole: number) => new Intl.NumberFormat(undefined, { style: 'percent', maximumFractionDigits: 1 }).format(part / (whole || 1));
|
|
234
|
+
const paintSelection = (announce: boolean) => {
|
|
235
|
+
const lit = (k: number) => (selected !== null ? k === selected : hoverNode !== null ? model.links[k]!.source === hoverNode || model.links[k]!.target === hoverNode : false);
|
|
236
|
+
const any = selected !== null || hoverNode !== null;
|
|
237
|
+
bands.forEach((band, k) => {
|
|
238
|
+
band.toggleAttribute('data-mk-on', lit(k));
|
|
239
|
+
band.toggleAttribute('data-mk-dim', any && !lit(k));
|
|
240
|
+
});
|
|
241
|
+
rects.forEach((rect, i) => rect.toggleAttribute('data-mk-dim', any && !model.links.some((link, k) => lit(k) && (link.source === i || link.target === i))));
|
|
242
|
+
if (!shown || (selected === null && hoverNode === null)) {
|
|
243
|
+
frame.tip(null);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (selected !== null) {
|
|
247
|
+
const link = model.links[selected]!;
|
|
248
|
+
const geometry = shown.links[selected]!;
|
|
249
|
+
const x = (shown.nodes[link.source]!.x + shown.nodes[link.target]!.x + nodeWidth()) / 2;
|
|
250
|
+
const y = (geometry.sy + geometry.ty) / 2 - geometry.width / 2;
|
|
251
|
+
const from = model.nodes[link.source]!;
|
|
252
|
+
const to = model.nodes[link.target]!;
|
|
253
|
+
const rows = [{ name: `${share(link.value, model.value[link.source]!)} de ${from.label}`, color: from.color, value: format(link.value) }];
|
|
254
|
+
frame.tip({ x: round(x), y: round(y), title: `${from.label} → ${to.label}`, rows });
|
|
255
|
+
if (announce) frame.live.textContent = `${from.label} a ${to.label}: ${format(link.value)}`;
|
|
256
|
+
} else {
|
|
257
|
+
const i = hoverNode!;
|
|
258
|
+
const node = shown.nodes[i]!;
|
|
259
|
+
frame.tip({ x: round(node.x + nodeWidth() / 2), y: round(node.y0), title: model.nodes[i]!.label, rows: [{ name: 'Total', color: model.nodes[i]!.color, value: format(model.value[i]!) }] });
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const draw = (animate: boolean) => {
|
|
264
|
+
glide?.kill();
|
|
265
|
+
const name = options.label ?? 'Diagrama de flujo';
|
|
266
|
+
canvas.setAttribute('aria-label', hasData() ? `${name}. ${model.links.length} flujos entre ${model.used.filter(Boolean).length} etapas. Usa las flechas para recorrer los flujos.` : `${name}: ${options.emptyLabel ?? 'sin datos'}`);
|
|
267
|
+
frame.fillTable(name, ['Flujo', 'Valor'], model.links.map((link) => [`${model.nodes[link.source]!.label} → ${model.nodes[link.target]!.label}`, format(link.value)]));
|
|
268
|
+
frame.fillLegend([], false);
|
|
269
|
+
const ok = hasData();
|
|
270
|
+
frame.empty.hidden = ok;
|
|
271
|
+
frame.empty.textContent = options.emptyLabel ?? 'Sin datos para mostrar';
|
|
272
|
+
plot.hidden = !ok;
|
|
273
|
+
if (!ok) {
|
|
274
|
+
canvas.replaceChildren();
|
|
275
|
+
shown = null;
|
|
276
|
+
selected = null;
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (selected !== null && selected >= model.links.length) selected = null;
|
|
280
|
+
const before = shown;
|
|
281
|
+
const target = layoutOf();
|
|
282
|
+
const comparable = before && before.nodes.length === target.nodes.length && before.links.length === target.links.length;
|
|
283
|
+
build();
|
|
284
|
+
const done = () => {
|
|
285
|
+
paint(target);
|
|
286
|
+
paintSelection(false);
|
|
287
|
+
};
|
|
288
|
+
if (!animate || reduced()) return done();
|
|
289
|
+
if (comparable) {
|
|
290
|
+
// Same nodes and flows: every node and band glides to its new place.
|
|
291
|
+
const state = { t: 0 };
|
|
292
|
+
const mix = (a: number, b: number) => a + (b - a) * state.t;
|
|
293
|
+
glide = gsap.to(state, {
|
|
294
|
+
t: 1,
|
|
295
|
+
duration: 0.6,
|
|
296
|
+
ease: EASE.swatch,
|
|
297
|
+
onUpdate: () =>
|
|
298
|
+
paint({
|
|
299
|
+
nodes: target.nodes.map((node, i) => ({ x: mix(before!.nodes[i]!.x, node.x), y0: mix(before!.nodes[i]!.y0, node.y0), y1: mix(before!.nodes[i]!.y1, node.y1) })),
|
|
300
|
+
links: target.links.map((link, k) => ({ sy: mix(before!.links[k]!.sy, link.sy), ty: mix(before!.links[k]!.ty, link.ty), width: mix(before!.links[k]!.width, link.width) })),
|
|
301
|
+
}),
|
|
302
|
+
onComplete: done,
|
|
303
|
+
});
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
// First appearance: nodes grow from their middles column by column; the bands are wiped in from the left.
|
|
307
|
+
done();
|
|
308
|
+
const timeline = gsap.timeline();
|
|
309
|
+
rects.forEach((rect, i) => {
|
|
310
|
+
timeline.fromTo(rect, { scaleY: 0, transformOrigin: '50% 50%' }, { scaleY: 1, duration: 0.5, ease: EASE.swatch, clearProps: 'transform' }, (model.depth[i] ?? 0) * 0.12);
|
|
311
|
+
});
|
|
312
|
+
timeline.fromTo(names, { opacity: 0 }, { opacity: 1, duration: 0.4, stagger: 0.02, clearProps: 'opacity' }, 0.2);
|
|
313
|
+
const clip = svg('clipPath', { id: `${uid}-wipe` });
|
|
314
|
+
const rect = svg('rect', { x: 0, y: 0, width: 0, height });
|
|
315
|
+
clip.append(rect);
|
|
316
|
+
canvas.prepend(clip);
|
|
317
|
+
const flows = canvas.querySelector('[data-mk-part="links"]')!;
|
|
318
|
+
flows.setAttribute('clip-path', `url(#${uid}-wipe)`);
|
|
319
|
+
timeline.to(rect, { attr: { width }, duration: 0.9, ease: EASE.wipe, onComplete: () => {
|
|
320
|
+
flows.removeAttribute('clip-path');
|
|
321
|
+
clip.remove();
|
|
322
|
+
} }, 0.1);
|
|
323
|
+
glide = timeline;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
const select = (index: number | null, announce = false) => {
|
|
327
|
+
if (scope.disposed) return;
|
|
328
|
+
const n = model.links.length;
|
|
329
|
+
const next = index === null || !n ? null : ((Math.round(index) % n) + n) % n;
|
|
330
|
+
if (next === selected) return;
|
|
331
|
+
selected = next;
|
|
332
|
+
paintSelection(announce);
|
|
333
|
+
options.onSelect?.(selected === null ? null : model.links[selected]!.given);
|
|
334
|
+
const link = selected === null ? null : model.links[selected]!;
|
|
335
|
+
root.dispatchEvent(new CustomEvent('mk:select', { bubbles: true, detail: { index: link?.given ?? null, source: link ? model.nodes[link.source]!.id : null, target: link ? model.nodes[link.target]!.id : null, value: link?.value ?? null } }));
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
scope.on(canvas, 'pointermove', (event) => {
|
|
339
|
+
const target = event.target as Element;
|
|
340
|
+
const band = target.closest('[data-mk-index]');
|
|
341
|
+
const node = target.closest('[data-mk-node]');
|
|
342
|
+
if (node) {
|
|
343
|
+
const i = Number(node.getAttribute('data-mk-node'));
|
|
344
|
+
if (selected !== null) select(null);
|
|
345
|
+
if (hoverNode !== i) {
|
|
346
|
+
hoverNode = i;
|
|
347
|
+
paintSelection(false);
|
|
348
|
+
}
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
if (hoverNode !== null) {
|
|
352
|
+
hoverNode = null;
|
|
353
|
+
paintSelection(false);
|
|
354
|
+
}
|
|
355
|
+
select(band ? Number(band.getAttribute('data-mk-index')) : null);
|
|
356
|
+
});
|
|
357
|
+
scope.on(canvas, 'pointerleave', (event) => {
|
|
358
|
+
if ((event as PointerEvent).pointerType !== 'mouse') return;
|
|
359
|
+
hoverNode = null;
|
|
360
|
+
select(null);
|
|
361
|
+
paintSelection(false);
|
|
362
|
+
});
|
|
363
|
+
scope.on(canvas, 'focus', () => {
|
|
364
|
+
if (selected === null && hasData()) select(0, true);
|
|
365
|
+
});
|
|
366
|
+
scope.on(canvas, 'blur', () => select(null));
|
|
367
|
+
scope.on(canvas, 'keydown', (event) => {
|
|
368
|
+
const key = (event as KeyboardEvent).key;
|
|
369
|
+
const moves: Record<string, number | null> = { ArrowDown: (selected ?? -1) + 1, ArrowRight: (selected ?? -1) + 1, ArrowUp: (selected ?? 1) - 1, ArrowLeft: (selected ?? 1) - 1, Home: 0, End: model.links.length - 1, Escape: null };
|
|
370
|
+
if (!(key in moves) || !hasData()) return;
|
|
371
|
+
event.preventDefault();
|
|
372
|
+
select(moves[key]!, true);
|
|
373
|
+
});
|
|
374
|
+
onWidth(root, scope, () => {
|
|
375
|
+
if (!hasData()) return;
|
|
376
|
+
const layout = layoutOf();
|
|
377
|
+
build();
|
|
378
|
+
paint(layout);
|
|
379
|
+
paintSelection(false);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
draw(true);
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
update(next) {
|
|
386
|
+
if (scope.disposed) return;
|
|
387
|
+
options = { ...options, ...next };
|
|
388
|
+
model = modelOf();
|
|
389
|
+
draw(true);
|
|
390
|
+
},
|
|
391
|
+
select: (index) => {
|
|
392
|
+
// `index` is the flow's place in `links`.
|
|
393
|
+
const at = index === null ? null : model.links.findIndex((link) => link.given === index);
|
|
394
|
+
select(at === null || at < 0 ? null : at);
|
|
395
|
+
},
|
|
396
|
+
get selected() {
|
|
397
|
+
return selected === null ? null : model.links[selected]!.given;
|
|
398
|
+
},
|
|
399
|
+
destroy: () => scope.dispose(),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import type { HTMLAttributes } from 'react';
|
|
3
|
+
import { useChart } from '../chart/use-chart';
|
|
4
|
+
import { createSankeyChart, type SankeyChartInstance, type SankeyChartOptions } from './engine';
|
|
5
|
+
|
|
6
|
+
export interface SankeyChartProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect' | 'children'>, SankeyChartOptions {
|
|
7
|
+
instanceRef?: { current: SankeyChartInstance | null };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** <SankeyChart label="Embudo" nodes={[{ id: 'visitas' }, …]} links={[{ source: 'visitas', target: 'carrito', value: 420 }, …]} /> */
|
|
11
|
+
export function SankeyChart({ nodes, links, height, nodeWidth, nodePadding, label, emptyLabel, formatValue, onSelect, instanceRef, className, ...props }: SankeyChartProps) {
|
|
12
|
+
const ref = useChart(createSankeyChart, { nodes, links, height, nodeWidth, nodePadding, label, emptyLabel } as SankeyChartOptions, { formatValue, onSelect }, instanceRef);
|
|
13
|
+
return <div {...props} ref={ref} className={['mk-chart mk-sankey-chart', className].filter(Boolean).join(' ')} />;
|
|
14
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* sankey-chart — bands that fade from their source's colour to their target's (35 %), nodes with 3 px corners;
|
|
2
|
+
needs chart.css for the family. The flow under the pointer lights up, the rest step back. */
|
|
3
|
+
.mk-sankey-chart,
|
|
4
|
+
mk-sankey-chart {
|
|
5
|
+
display: grid;
|
|
6
|
+
gap: 1rem;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
[data-mk-chart-type='sankey'] [data-mk-chart-svg] {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
[data-mk-chart-type='sankey'] [data-mk-part='links'] path {
|
|
14
|
+
opacity: 0.35;
|
|
15
|
+
transition: opacity 0.2s ease;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[data-mk-chart-type='sankey'] [data-mk-part='links'] path[data-mk-on] {
|
|
19
|
+
opacity: 0.7;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[data-mk-chart-type='sankey'] [data-mk-part='links'] path[data-mk-dim] {
|
|
23
|
+
opacity: 0.1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[data-mk-chart-type='sankey'] [data-mk-part='nodes'] rect {
|
|
27
|
+
transition: opacity 0.2s ease;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[data-mk-chart-type='sankey'] [data-mk-part='nodes'] rect[data-mk-dim] {
|
|
31
|
+
opacity: 0.45;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[data-mk-chart-type='sankey'] [data-mk-part='labels'] text {
|
|
35
|
+
fill: var(--mk-text);
|
|
36
|
+
font-size: 12px;
|
|
37
|
+
font-weight: 500;
|
|
38
|
+
paint-order: stroke;
|
|
39
|
+
stroke: var(--mk-chart-surface);
|
|
40
|
+
stroke-width: 3px;
|
|
41
|
+
stroke-linejoin: round;
|
|
42
|
+
pointer-events: none;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
[data-mk-chart-type='sankey'] [data-mk-part='amount'] {
|
|
46
|
+
fill: var(--mk-muted);
|
|
47
|
+
font-weight: 400;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@media (prefers-reduced-motion: reduce) {
|
|
51
|
+
[data-mk-chart-type='sankey'] :is([data-mk-part='links'] path, [data-mk-part='nodes'] rect) {
|
|
52
|
+
transition: none;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@media (forced-colors: active) {
|
|
57
|
+
[data-mk-chart-type='sankey'] [data-mk-part='nodes'] rect {
|
|
58
|
+
fill: CanvasText !important;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# scratch-card
|
|
2
|
+
|
|
3
|
+
Rasca y gana para cupones: el contenido HTML real queda bajo una cubierta metalizada dibujada en canvas con brillo y «Rasca aquí». El puntero rasca con un pincel redondo y el progreso se mide por muestreo. Al pasar el umbral, el resto se disuelve con blur, el cupón entra con `pop` y salta confeti. Mientras está cubierto, el contenido es `inert`; el botón «Revelar» es la vía para teclado y lectores de pantalla, y la revelación se anuncia. Sin canvas 2D, la cubierta es CSS y el botón la retira.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<mk-scratch-card class="mk-scratch-card">
|
|
7
|
+
<div data-mk-scratch-content><strong>OTOÑO25</strong> · 25 % de descuento</div>
|
|
8
|
+
</mk-scratch-card>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`defineElements()`, `createScratchCard(root, options)` (sin `[data-mk-scratch-content]`, los hijos del root pasan a uno) o `<ScratchCard onReveal={claim}>…</ScratchCard>`.
|
|
12
|
+
|
|
13
|
+
Opciones: `threshold=0.5`, `brush=22` px, `coverLabel='Rasca aquí'`, `revealLabel='Revelar'`, `revealedLabel='Premio revelado'`, `celebrate=true`, `onProgress(p)`, `onReveal()`. API: `reveal()`, `reset()`, `revealed`, `progress`, `destroy()`. Eventos `mk:progress` `{progress}` y `mk:reveal`. El premio es de la app: el componente sólo lo tapa.
|
|
14
|
+
|
|
15
|
+
Movimiento reducido: la cubierta desaparece sin blur ni confeti.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MkElement, defineElement, type OptionType } from '../../elements/base';
|
|
2
|
+
import { createScratchCard, type ScratchCardInstance } from './engine';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <mk-scratch-card class="mk-scratch-card" threshold="0.5">
|
|
6
|
+
* <div data-mk-scratch-content>…the coupon…</div>
|
|
7
|
+
* </mk-scratch-card>
|
|
8
|
+
* Emits mk:progress ({progress}) and mk:reveal.
|
|
9
|
+
*/
|
|
10
|
+
export class MkScratchCardElement extends MkElement<ScratchCardInstance> {
|
|
11
|
+
static options: Record<string, OptionType> = { threshold: 'number', brush: 'number', coverLabel: 'string', revealLabel: 'string', revealedLabel: 'string', celebrate: 'boolean' };
|
|
12
|
+
|
|
13
|
+
protected create(options: Record<string, unknown>) {
|
|
14
|
+
return createScratchCard(this, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
reveal() {
|
|
18
|
+
this.instance?.reveal();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
reset() {
|
|
22
|
+
this.instance?.reset();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get revealed() {
|
|
26
|
+
return this.instance?.revealed ?? false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const defineScratchCard = () => defineElement('mk-scratch-card', MkScratchCardElement);
|