@yewdiel21/motion-kit 0.10.0 → 0.14.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 +155 -93
- package/dist/auto/index.d.ts +53 -3
- package/dist/auto/index.js +101 -3
- package/dist/auto/index.js.map +1 -1
- package/dist/{chunk-IKQ5FODN.js → chunk-6P4P7NU6.js} +2 -218
- package/dist/chunk-6P4P7NU6.js.map +1 -0
- package/dist/chunk-CU6SXW3E.js +20334 -0
- package/dist/chunk-CU6SXW3E.js.map +1 -0
- package/dist/{chunk-XAKC2QY7.js → chunk-EY4BJKC4.js} +3 -28
- package/dist/chunk-EY4BJKC4.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/attachment.css +266 -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 +591 -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 +232 -0
- package/dist/css/components/hold-confirm.css +87 -0
- package/dist/css/components/hover-card.css +13 -7
- package/dist/css/components/image-preview.css +195 -0
- package/dist/css/components/json-viewer.css +272 -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/notification-bell.css +127 -0
- package/dist/css/components/password-strength.css +183 -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/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/scratch-card.css +75 -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/tooltip.css +79 -0
- package/dist/css/components/tree-view.css +210 -0
- package/dist/css/components/virtual-list.css +195 -0
- package/dist/css/tokens.css +185 -181
- package/dist/elements/index.d.ts +674 -5
- package/dist/elements/index.js +1361 -8
- package/dist/elements/index.js.map +1 -1
- package/dist/{engine-GDGwQnJE.d.ts → engine-Cn6IhE3z.d.ts} +1 -1
- package/dist/engine-QECQnGz1.d.ts +33 -0
- package/dist/index.css +9104 -189
- package/dist/index.d.ts +89 -5
- package/dist/index.js +243 -9
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +579 -23
- package/dist/react/index.js +2042 -7
- package/dist/react/index.js.map +1 -1
- package/dist/{reduced-BmBzKH94.d.ts → reduced-BBUusld6.d.ts} +9 -2
- package/dist/reveal-DEvp6U6T.d.ts +2381 -0
- package/dist/{store-DYb3tTsZ.d.ts → store-DjkTBX7f.d.ts} +2 -2
- package/package.json +1 -1
- package/registry.json +406 -1
- package/src/auto/auto-init.ts +98 -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/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/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 +24 -0
- package/src/components/chart/chart.css +295 -0
- package/src/components/chart/element.ts +41 -0
- package/src/components/chart/engine.ts +811 -0
- package/src/components/chart/react.tsx +50 -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 +590 -0
- package/src/components/data-table/element.ts +54 -0
- package/src/components/data-table/engine.ts +1059 -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 +775 -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 +365 -0
- package/src/components/filter-builder/filter-builder.css +231 -0
- package/src/components/filter-builder/react.tsx +36 -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 +68 -6
- package/src/components/hover-card/hover-card.css +13 -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 +325 -0
- package/src/components/image-preview/image-preview.css +194 -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 +440 -0
- package/src/components/json-viewer/json-viewer.css +271 -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/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/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/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/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/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/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/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 +569 -0
- package/src/components/tree-view/react.tsx +78 -0
- package/src/components/tree-view/tree-view.css +209 -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/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 +147 -0
- package/src/index.ts +72 -0
- 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 +57 -0
- 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
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/* json-viewer — the tree in a monospace face inside a 12 px box on surface-2: keys in the text colour, a muted colon,
|
|
2
|
+
values by type (strings green, numbers blue, booleans violet, null muted and italic; colours with a swatch), objects
|
|
3
|
+
and lists as muted brackets and a count. Rows are 1.875rem; the copy button shows on hover or focus (always on touch
|
|
4
|
+
screens). A bar above (search, expand, collapse, copy) and the selected path below. Values that change flash in the
|
|
5
|
+
accent; new keys come in out of a blur. Give it a height with --mk-jv-height. */
|
|
6
|
+
.mk-json-viewer,
|
|
7
|
+
mk-json-viewer {
|
|
8
|
+
--mk-jv-height: none;
|
|
9
|
+
--mk-jv-string: #187a47;
|
|
10
|
+
--mk-jv-number: #2d5fc4;
|
|
11
|
+
--mk-jv-boolean: #8a3fc8;
|
|
12
|
+
display: grid;
|
|
13
|
+
gap: 0.5rem;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
color: var(--mk-text);
|
|
16
|
+
font-family: var(--mk-font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
17
|
+
font-size: 0.8125rem;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@media (prefers-color-scheme: dark) {
|
|
21
|
+
:where(:root:not([data-mk-mode='light'])) :is(.mk-json-viewer, mk-json-viewer) {
|
|
22
|
+
--mk-jv-string: #62d39b;
|
|
23
|
+
--mk-jv-number: #8db5ff;
|
|
24
|
+
--mk-jv-boolean: #cba0ff;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:where(:root[data-mk-mode='dark']) :is(.mk-json-viewer, mk-json-viewer) {
|
|
29
|
+
--mk-jv-string: #62d39b;
|
|
30
|
+
--mk-jv-number: #8db5ff;
|
|
31
|
+
--mk-jv-boolean: #cba0ff;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[data-mk-jv-bar] {
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
gap: 0.5rem;
|
|
38
|
+
min-width: 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
[data-mk-jv-search] {
|
|
42
|
+
box-sizing: border-box;
|
|
43
|
+
flex: 1 1 auto;
|
|
44
|
+
min-width: 0;
|
|
45
|
+
height: 2.25rem;
|
|
46
|
+
padding: 0 0.75rem;
|
|
47
|
+
border: 0;
|
|
48
|
+
border-radius: 12px;
|
|
49
|
+
outline: none;
|
|
50
|
+
background: var(--mk-surface-3);
|
|
51
|
+
color: inherit;
|
|
52
|
+
font: inherit;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
[data-mk-jv-search]:focus-visible {
|
|
56
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--mk-accent) 35%, transparent);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
[data-mk-jv-tools] {
|
|
60
|
+
display: flex;
|
|
61
|
+
flex: none;
|
|
62
|
+
gap: 0.125rem;
|
|
63
|
+
margin-left: auto;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[data-mk-jv-tool],
|
|
67
|
+
[data-mk-jv-copy] {
|
|
68
|
+
display: inline-grid;
|
|
69
|
+
flex: none;
|
|
70
|
+
place-items: center;
|
|
71
|
+
width: 2rem;
|
|
72
|
+
height: 2rem;
|
|
73
|
+
padding: 0;
|
|
74
|
+
border: 0;
|
|
75
|
+
border-radius: 8px;
|
|
76
|
+
background: transparent;
|
|
77
|
+
color: var(--mk-muted);
|
|
78
|
+
cursor: pointer;
|
|
79
|
+
transition:
|
|
80
|
+
background-color 0.15s,
|
|
81
|
+
color 0.15s,
|
|
82
|
+
opacity 0.15s;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
[data-mk-jv-tool]:hover,
|
|
86
|
+
[data-mk-jv-copy]:hover {
|
|
87
|
+
background: color-mix(in srgb, var(--mk-text) 8%, transparent);
|
|
88
|
+
color: var(--mk-text);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[data-mk-jv-tool]:focus-visible {
|
|
92
|
+
outline: 2px solid var(--mk-accent);
|
|
93
|
+
outline-offset: 1px;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
[data-mk-jv-tool][data-mk-copied],
|
|
97
|
+
[data-mk-jv-copy][data-mk-copied] {
|
|
98
|
+
color: var(--mk-accent);
|
|
99
|
+
opacity: 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
[data-mk-jv-tree] {
|
|
103
|
+
max-height: var(--mk-jv-height);
|
|
104
|
+
overflow: auto;
|
|
105
|
+
padding: 0.375rem;
|
|
106
|
+
border: 1px solid var(--mk-outline-soft);
|
|
107
|
+
border-radius: 12px;
|
|
108
|
+
background: var(--mk-surface-2);
|
|
109
|
+
overscroll-behavior: contain;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[data-mk-jv-tree] [data-mk-tree-row] {
|
|
113
|
+
min-height: 1.875rem;
|
|
114
|
+
padding-right: 0.25rem;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
[data-mk-jv-tree] [data-mk-tree-label] {
|
|
118
|
+
display: flex;
|
|
119
|
+
align-items: center;
|
|
120
|
+
gap: 0.375rem;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
[data-mk-jv-key] {
|
|
124
|
+
flex: 0 0 auto;
|
|
125
|
+
max-width: 45%;
|
|
126
|
+
overflow: hidden;
|
|
127
|
+
text-overflow: ellipsis;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
[data-mk-jv-key='name'] {
|
|
131
|
+
font-weight: 600;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
[data-mk-jv-key='index'] {
|
|
135
|
+
color: var(--mk-muted);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
[data-mk-jv-colon] {
|
|
139
|
+
flex: none;
|
|
140
|
+
margin-left: -0.375rem;
|
|
141
|
+
color: var(--mk-muted);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
[data-mk-jv-value] {
|
|
145
|
+
flex: 0 1 auto;
|
|
146
|
+
min-width: 0;
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
border-radius: 4px;
|
|
149
|
+
text-overflow: ellipsis;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
[data-mk-jv-value='string'] {
|
|
153
|
+
color: var(--mk-jv-string);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
[data-mk-jv-value='number'] {
|
|
157
|
+
color: var(--mk-jv-number);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
[data-mk-jv-value='boolean'] {
|
|
161
|
+
color: var(--mk-jv-boolean);
|
|
162
|
+
font-weight: 600;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
[data-mk-jv-value='null'] {
|
|
166
|
+
color: var(--mk-muted);
|
|
167
|
+
font-style: italic;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
[data-mk-jv-swatch] {
|
|
171
|
+
display: inline-block;
|
|
172
|
+
width: 0.75rem;
|
|
173
|
+
height: 0.75rem;
|
|
174
|
+
margin-right: 0.375rem;
|
|
175
|
+
border-radius: 4px;
|
|
176
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--mk-text) 20%, transparent);
|
|
177
|
+
vertical-align: -0.1em;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
[data-mk-jv-brackets] {
|
|
181
|
+
flex: none;
|
|
182
|
+
color: var(--mk-muted);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
[data-mk-jv-summary] {
|
|
186
|
+
flex: 0 1 auto;
|
|
187
|
+
min-width: 0;
|
|
188
|
+
overflow: hidden;
|
|
189
|
+
color: var(--mk-muted);
|
|
190
|
+
font-size: 0.75rem;
|
|
191
|
+
text-overflow: ellipsis;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
[data-mk-jv-copy] {
|
|
195
|
+
width: 1.625rem;
|
|
196
|
+
height: 1.625rem;
|
|
197
|
+
margin-left: auto;
|
|
198
|
+
border-radius: 6px;
|
|
199
|
+
opacity: 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
[data-mk-tree-row]:hover [data-mk-jv-copy],
|
|
203
|
+
[role='treeitem']:focus-visible > [data-mk-tree-row] [data-mk-jv-copy] {
|
|
204
|
+
opacity: 1;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@media (hover: none) {
|
|
208
|
+
[data-mk-jv-copy] {
|
|
209
|
+
opacity: 0.7;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
[data-mk-jv-changed] {
|
|
214
|
+
animation: mk-jv-flash 1.6s cubic-bezier(0.38, 0.49, 0, 1) both;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@keyframes mk-jv-flash {
|
|
218
|
+
0%,
|
|
219
|
+
30% {
|
|
220
|
+
background: color-mix(in srgb, var(--mk-accent) 26%, transparent);
|
|
221
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--mk-accent) 26%, transparent);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
100% {
|
|
225
|
+
background: transparent;
|
|
226
|
+
box-shadow: 0 0 0 3px transparent;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
[data-mk-jv-added] {
|
|
231
|
+
animation: mk-jv-added 0.55s ease-out both;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@keyframes mk-jv-added {
|
|
235
|
+
from {
|
|
236
|
+
opacity: 0;
|
|
237
|
+
filter: blur(6px);
|
|
238
|
+
transform: translateX(-8px);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
[data-mk-jv-foot] {
|
|
243
|
+
display: flex;
|
|
244
|
+
align-items: center;
|
|
245
|
+
gap: 0.25rem;
|
|
246
|
+
min-width: 0;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
[data-mk-jv-foot][hidden] {
|
|
250
|
+
display: none;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
[data-mk-jv-path] {
|
|
254
|
+
min-width: 0;
|
|
255
|
+
overflow: hidden;
|
|
256
|
+
padding: 0.25rem 0.5rem;
|
|
257
|
+
border-radius: 6px;
|
|
258
|
+
background: var(--mk-surface-3);
|
|
259
|
+
color: var(--mk-text);
|
|
260
|
+
font: inherit;
|
|
261
|
+
font-size: 0.75rem;
|
|
262
|
+
text-overflow: ellipsis;
|
|
263
|
+
white-space: nowrap;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
@media (prefers-reduced-motion: reduce) {
|
|
267
|
+
[data-mk-jv-changed],
|
|
268
|
+
[data-mk-jv-added] {
|
|
269
|
+
animation: none;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { forwardRef, useImperativeHandle, useRef, type HTMLAttributes } from 'react';
|
|
3
|
+
import { useIsomorphicLayoutEffect, useLatest } from '../../react/use-recipe';
|
|
4
|
+
import { createJsonViewer, type JsonViewerInstance, type JsonViewerOptions } from './engine';
|
|
5
|
+
|
|
6
|
+
export interface JsonViewerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onSelect' | 'onCopy' | 'children'>, JsonViewerOptions {}
|
|
7
|
+
|
|
8
|
+
export type JsonViewerHandle = Pick<JsonViewerInstance, 'expandAll' | 'collapseAll' | 'reveal' | 'filter' | 'copy'>;
|
|
9
|
+
|
|
10
|
+
/** <JsonViewer data={response} expandDepth={2} search />. New data keeps what was open and flashes what changed. */
|
|
11
|
+
export const JsonViewer = forwardRef<JsonViewerHandle, JsonViewerProps>(function JsonViewer(
|
|
12
|
+
{ data, expandDepth, rootName, search, toolbar, sortKeys, label, onSelect, onCopy, className, ...props },
|
|
13
|
+
handle,
|
|
14
|
+
) {
|
|
15
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
16
|
+
const instance = useRef<JsonViewerInstance | null>(null);
|
|
17
|
+
const select = useLatest(onSelect);
|
|
18
|
+
const copied = useLatest(onCopy);
|
|
19
|
+
const shown = useRef(data);
|
|
20
|
+
useImperativeHandle(
|
|
21
|
+
handle,
|
|
22
|
+
() => ({
|
|
23
|
+
expandAll: () => instance.current?.expandAll(),
|
|
24
|
+
collapseAll: () => instance.current?.collapseAll(),
|
|
25
|
+
reveal: (path) => instance.current?.reveal(path),
|
|
26
|
+
filter: (query) => instance.current?.filter(query),
|
|
27
|
+
copy: (path) => instance.current?.copy(path) ?? Promise.resolve(false),
|
|
28
|
+
}),
|
|
29
|
+
[],
|
|
30
|
+
);
|
|
31
|
+
useIsomorphicLayoutEffect(() => {
|
|
32
|
+
const created = createJsonViewer(ref.current, {
|
|
33
|
+
data: shown.current,
|
|
34
|
+
expandDepth,
|
|
35
|
+
rootName,
|
|
36
|
+
search,
|
|
37
|
+
toolbar,
|
|
38
|
+
sortKeys,
|
|
39
|
+
label,
|
|
40
|
+
onSelect: (path, value) => select.current?.(path, value),
|
|
41
|
+
onCopy: (text, path) => copied.current?.(text, path),
|
|
42
|
+
});
|
|
43
|
+
instance.current = created;
|
|
44
|
+
return () => {
|
|
45
|
+
created.destroy();
|
|
46
|
+
instance.current = null;
|
|
47
|
+
};
|
|
48
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
|
+
}, [expandDepth, rootName, String(search), toolbar, sortKeys, label]);
|
|
50
|
+
useIsomorphicLayoutEffect(() => {
|
|
51
|
+
if (shown.current === data) return;
|
|
52
|
+
shown.current = data;
|
|
53
|
+
instance.current?.setData(data);
|
|
54
|
+
}, [data]);
|
|
55
|
+
return <div {...props} ref={ref} className={['mk-json-viewer', className].filter(Boolean).join(' ')} />;
|
|
56
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# like-button
|
|
2
|
+
|
|
3
|
+
Botón de «me gusta» con corazón y contador (`aria-pressed`). Al darle: el corazón se encoge, se rellena desde el centro y rebota a 1.25 con curva elástica, salen un anillo y siete pares de partículas y el contador rueda hacia arriba. Al quitarlo, el relleno se vacía y el contador rueda hacia abajo.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<mk-like-button class="mk-like-button" count="128"></mk-like-button>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
`defineElements()`, `createLikeButton(root, options)` (root es el botón o lo contiene) o `<LikeButton count={128} onChange={(liked, count) => save(liked)} />` (con `liked` es controlado; `defaultLiked` si no).
|
|
10
|
+
|
|
11
|
+
Opciones: `liked=false`, `count=0`, `label='Me gusta'` (nombre accesible; el número visible se suma al nombre), `hideCount`, `onChange(liked, count)`. API: `setLiked(liked, notify=true)`, `setCount(n)`, `liked`, `count`, `destroy()`. Evento `mk:change` con `{liked, count}`. Cifras grandes en notación compacta.
|
|
12
|
+
|
|
13
|
+
Variables: `--mk-like-color` (#f43f5e), `--mk-like-color-2` (partículas). Movimiento reducido: el estado cambia sin rebote ni partículas.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { MkElement, defineElement, type OptionType } from '../../elements/base';
|
|
2
|
+
import { createLikeButton, type LikeButtonInstance } from './engine';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <mk-like-button class="mk-like-button" count="128"><button></button></mk-like-button>
|
|
6
|
+
* Toggles with a burst; emits mk:change ({liked, count}).
|
|
7
|
+
*/
|
|
8
|
+
export class MkLikeButtonElement extends MkElement<LikeButtonInstance> {
|
|
9
|
+
static options: Record<string, OptionType> = { liked: 'boolean', count: 'number', label: 'string', hideCount: 'boolean' };
|
|
10
|
+
|
|
11
|
+
protected create(options: Record<string, unknown>) {
|
|
12
|
+
// Without a button inside, one is made (and removed again on destroy).
|
|
13
|
+
let made: HTMLButtonElement | null = null;
|
|
14
|
+
if (!this.querySelector('button')) {
|
|
15
|
+
made = document.createElement('button');
|
|
16
|
+
made.type = 'button';
|
|
17
|
+
this.append(made);
|
|
18
|
+
}
|
|
19
|
+
const engine = createLikeButton(this, options);
|
|
20
|
+
if (made) {
|
|
21
|
+
const destroy = engine.destroy;
|
|
22
|
+
engine.destroy = () => {
|
|
23
|
+
destroy();
|
|
24
|
+
made!.remove();
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return engine;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// A new `liked` or `count` attribute updates in place (with the animation).
|
|
31
|
+
attributeChangedCallback(name: string, previous: string | null, next: string | null) {
|
|
32
|
+
if (previous === next || !this.instance) return;
|
|
33
|
+
if (name === 'liked') this.instance.setLiked(next !== null && next !== 'false', false);
|
|
34
|
+
else if (name === 'count') this.instance.setCount(Number(next));
|
|
35
|
+
else super.attributeChangedCallback(name, previous, next);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get liked() {
|
|
39
|
+
return this.instance?.liked ?? false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get count() {
|
|
43
|
+
return this.instance?.count ?? 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const defineLikeButton = () => defineElement('mk-like-button', MkLikeButtonElement);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { gsap, ELASTIC, EASE, registerMotion } from '../../core/gsap';
|
|
2
|
+
import { reduced } from '../../core/reduced';
|
|
3
|
+
import { numberFormat } from '../../core/dates';
|
|
4
|
+
import { createScope } from '../../core/scope';
|
|
5
|
+
import { inert, type Instance } from '../../core/types';
|
|
6
|
+
import { burst, rollDigits } from '../../motion/micro';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Like button: a heart and a count on a toggle button (aria-pressed). Liking it
|
|
10
|
+
* squeezes the heart, fills it from the centre and springs it to 1.25 and back
|
|
11
|
+
* (elastic), a ring and seven pairs of particles fly out, and the count rolls up.
|
|
12
|
+
* Unliking empties the heart with a small dip and rolls the count down.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export interface LikeButtonOptions {
|
|
16
|
+
liked?: boolean;
|
|
17
|
+
count?: number;
|
|
18
|
+
/** Accessible name (default 'Me gusta'). */
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Hide the count. */
|
|
21
|
+
hideCount?: boolean;
|
|
22
|
+
onChange?: (liked: boolean, count: number) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LikeButtonInstance extends Instance {
|
|
26
|
+
setLiked(liked: boolean, notify?: boolean): void;
|
|
27
|
+
setCount(count: number): void;
|
|
28
|
+
readonly liked: boolean;
|
|
29
|
+
readonly count: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
33
|
+
const HEART = 'M12 20.5s-7.5-4.6-7.5-10.1A4.4 4.4 0 0 1 12 7.6a4.4 4.4 0 0 1 7.5 2.8c0 5.5-7.5 10.1-7.5 10.1z';
|
|
34
|
+
|
|
35
|
+
export function createLikeButton(root: HTMLElement | null, options: LikeButtonOptions = {}): LikeButtonInstance {
|
|
36
|
+
const button = root ? ((root.matches('button') ? root : root.querySelector('button')) as HTMLButtonElement | null) : null;
|
|
37
|
+
if (!root || !button) return inert({ setLiked() {}, setCount() {}, liked: false, count: 0 });
|
|
38
|
+
registerMotion();
|
|
39
|
+
const scope = createScope();
|
|
40
|
+
let liked = Boolean(options.liked);
|
|
41
|
+
let count = Math.max(0, Math.round(Number.isFinite(options.count) ? options.count! : 0));
|
|
42
|
+
const format = (n: number) => numberFormat(root, { notation: n >= 10000 ? 'compact' : 'standard' }).format(n);
|
|
43
|
+
|
|
44
|
+
const made: Element[] = [];
|
|
45
|
+
scope.add(() => made.forEach((element) => element.remove()));
|
|
46
|
+
const icon = document.createElementNS(SVG, 'svg');
|
|
47
|
+
icon.setAttribute('viewBox', '0 0 24 24');
|
|
48
|
+
icon.setAttribute('aria-hidden', 'true');
|
|
49
|
+
icon.dataset.mkLikeIcon = '';
|
|
50
|
+
const outline = document.createElementNS(SVG, 'path');
|
|
51
|
+
outline.setAttribute('d', HEART);
|
|
52
|
+
outline.dataset.mkPart = 'outline';
|
|
53
|
+
const fill = document.createElementNS(SVG, 'path');
|
|
54
|
+
fill.setAttribute('d', HEART);
|
|
55
|
+
fill.dataset.mkPart = 'fill';
|
|
56
|
+
icon.append(outline, fill);
|
|
57
|
+
const name = document.createElement('span');
|
|
58
|
+
name.className = 'mk-sr-only';
|
|
59
|
+
name.textContent = options.label ?? 'Me gusta';
|
|
60
|
+
const counter = document.createElement('span');
|
|
61
|
+
counter.dataset.mkLikeCount = '';
|
|
62
|
+
counter.hidden = Boolean(options.hideCount);
|
|
63
|
+
button.prepend(icon);
|
|
64
|
+
button.append(name, counter);
|
|
65
|
+
made.push(icon, name, counter);
|
|
66
|
+
|
|
67
|
+
scope.attr(button, 'type', button.getAttribute('type') ?? 'button');
|
|
68
|
+
scope.attr(button, 'data-mk-like', '');
|
|
69
|
+
scope.attr(root, 'data-mk-ready', '');
|
|
70
|
+
|
|
71
|
+
const effects = new Set<gsap.core.Animation>();
|
|
72
|
+
const keep = (animation: gsap.core.Animation | null) => {
|
|
73
|
+
if (!animation) return;
|
|
74
|
+
effects.add(animation);
|
|
75
|
+
// Finished ones leave as new ones arrive: the animation's own onComplete stays untouched.
|
|
76
|
+
for (const effect of effects) if (effect.totalProgress() === 1) effects.delete(effect);
|
|
77
|
+
};
|
|
78
|
+
scope.add(() => {
|
|
79
|
+
for (const effect of effects) effect.kill();
|
|
80
|
+
effects.clear();
|
|
81
|
+
gsap.killTweensOf([icon, fill]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const paint = () => {
|
|
85
|
+
scope.attr(button, 'aria-pressed', String(liked));
|
|
86
|
+
gsap.set(fill, { scale: liked ? 1 : 0, transformOrigin: '50% 55%' });
|
|
87
|
+
counter.textContent = format(count);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const animate = (on: boolean, previous: number) => {
|
|
91
|
+
keep(rollDigits(counter, format(count), count >= previous ? 1 : -1, 0.4));
|
|
92
|
+
if (reduced()) return;
|
|
93
|
+
gsap.killTweensOf([icon, fill]);
|
|
94
|
+
if (on) {
|
|
95
|
+
keep(
|
|
96
|
+
gsap
|
|
97
|
+
.timeline()
|
|
98
|
+
.to(icon, { scale: 0.7, duration: 0.12, ease: 'power2.in' })
|
|
99
|
+
.fromTo(fill, { scale: 0 }, { scale: 1, duration: 0.3, ease: EASE.pop, transformOrigin: '50% 55%' }, '<0.05')
|
|
100
|
+
.to(icon, { scale: 1, duration: 0.9, ease: ELASTIC, clearProps: 'scale,transform' }, '<'),
|
|
101
|
+
);
|
|
102
|
+
keep(burst(button, { count: 7, distance: 30, colors: ['var(--mk-like-color)', 'var(--mk-like-color-2)'] }));
|
|
103
|
+
} else {
|
|
104
|
+
keep(
|
|
105
|
+
gsap
|
|
106
|
+
.timeline()
|
|
107
|
+
.to(fill, { scale: 0, duration: 0.25, ease: 'power2.in', transformOrigin: '50% 55%' })
|
|
108
|
+
.fromTo(icon, { scale: 0.85 }, { scale: 1, duration: 0.5, ease: EASE.click, clearProps: 'scale,transform' }, 0),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const setLiked = (next: boolean, notify = true) => {
|
|
114
|
+
if (scope.disposed || next === liked) return;
|
|
115
|
+
const previous = count;
|
|
116
|
+
liked = next;
|
|
117
|
+
count = Math.max(0, count + (next ? 1 : -1));
|
|
118
|
+
scope.attr(button, 'aria-pressed', String(liked));
|
|
119
|
+
animate(liked, previous);
|
|
120
|
+
if (reduced()) paint();
|
|
121
|
+
if (!notify) return;
|
|
122
|
+
options.onChange?.(liked, count);
|
|
123
|
+
root.dispatchEvent(new CustomEvent('mk:change', { bubbles: true, detail: { liked, count } }));
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
scope.on(button, 'click', () => setLiked(!liked));
|
|
127
|
+
paint();
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
setLiked,
|
|
131
|
+
setCount(next) {
|
|
132
|
+
if (scope.disposed || !Number.isFinite(next)) return;
|
|
133
|
+
const previous = count;
|
|
134
|
+
count = Math.max(0, Math.round(next));
|
|
135
|
+
if (count !== previous) keep(rollDigits(counter, format(count), count >= previous ? 1 : -1, 0.4));
|
|
136
|
+
},
|
|
137
|
+
get liked() {
|
|
138
|
+
return liked;
|
|
139
|
+
},
|
|
140
|
+
get count() {
|
|
141
|
+
return count;
|
|
142
|
+
},
|
|
143
|
+
destroy: () => scope.dispose(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* like-button — a Melonmind tonal pill with a heart and a count; liked, the heart fills with the like colour. */
|
|
2
|
+
.mk-like-button,
|
|
3
|
+
mk-like-button {
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[data-mk-like] {
|
|
8
|
+
--mk-like-color: #f43f5e;
|
|
9
|
+
--mk-like-color-2: #fb923c;
|
|
10
|
+
position: relative;
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: 0.45rem;
|
|
14
|
+
min-height: 2.75rem;
|
|
15
|
+
padding: 0 1rem 0 0.8rem;
|
|
16
|
+
border: 0;
|
|
17
|
+
border-radius: 64px;
|
|
18
|
+
background: var(--mk-surface-3);
|
|
19
|
+
color: var(--mk-text);
|
|
20
|
+
font: inherit;
|
|
21
|
+
font-weight: 500;
|
|
22
|
+
font-variant-numeric: tabular-nums;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
transition:
|
|
25
|
+
background-color 0.2s ease,
|
|
26
|
+
padding 400ms cubic-bezier(0.38, 0.49, 0, 2);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[data-mk-like]:hover {
|
|
30
|
+
background: var(--mk-surface-4);
|
|
31
|
+
padding-inline: 0.95rem 1.15rem;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
[data-mk-like][aria-pressed='true'] {
|
|
35
|
+
background: color-mix(in srgb, var(--mk-like-color) 14%, var(--mk-surface-3));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
[data-mk-like]:focus-visible {
|
|
39
|
+
outline: 2px solid var(--mk-accent);
|
|
40
|
+
outline-offset: 3px;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
[data-mk-like] [data-mk-like-icon] {
|
|
44
|
+
width: 1.5rem;
|
|
45
|
+
height: 1.5rem;
|
|
46
|
+
overflow: visible;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
[data-mk-like] [data-mk-part='outline'] {
|
|
50
|
+
fill: none;
|
|
51
|
+
stroke: currentColor;
|
|
52
|
+
stroke-width: 1.8;
|
|
53
|
+
stroke-linejoin: round;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[data-mk-like] [data-mk-part='fill'] {
|
|
57
|
+
fill: var(--mk-like-color);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[data-mk-like][aria-pressed='true'] [data-mk-part='outline'] {
|
|
61
|
+
stroke: var(--mk-like-color);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[data-mk-like] [data-mk-like-count] {
|
|
65
|
+
display: inline-flex;
|
|
66
|
+
min-width: 1ch;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[data-mk-like] [data-mk-like-count][hidden] {
|
|
70
|
+
display: none;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@media (prefers-reduced-motion: reduce) {
|
|
74
|
+
[data-mk-like] {
|
|
75
|
+
transition: none;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useRef, type ButtonHTMLAttributes } from 'react';
|
|
3
|
+
import { useIsomorphicLayoutEffect, useLatest } from '../../react/use-recipe';
|
|
4
|
+
import { createLikeButton, type LikeButtonInstance } from './engine';
|
|
5
|
+
|
|
6
|
+
export interface LikeButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'children'> {
|
|
7
|
+
/** Controlled state; without it the button keeps its own. */
|
|
8
|
+
liked?: boolean;
|
|
9
|
+
defaultLiked?: boolean;
|
|
10
|
+
count?: number;
|
|
11
|
+
label?: string;
|
|
12
|
+
hideCount?: boolean;
|
|
13
|
+
onChange?: (liked: boolean, count: number) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** <LikeButton count={128} onChange={(liked, count) => save(liked)} />. */
|
|
17
|
+
export function LikeButton({ liked, defaultLiked, count = 0, label, hideCount, onChange, className, ...props }: LikeButtonProps) {
|
|
18
|
+
const ref = useRef<HTMLButtonElement>(null);
|
|
19
|
+
const instance = useRef<LikeButtonInstance | null>(null);
|
|
20
|
+
const change = useLatest(onChange);
|
|
21
|
+
const start = useRef({ liked: liked ?? defaultLiked ?? false, count });
|
|
22
|
+
useIsomorphicLayoutEffect(() => {
|
|
23
|
+
const created = createLikeButton(ref.current, { ...start.current, label, hideCount, onChange: (next, total) => change.current?.(next, total) });
|
|
24
|
+
instance.current = created;
|
|
25
|
+
return () => {
|
|
26
|
+
start.current = { liked: created.liked, count: created.count };
|
|
27
|
+
created.destroy();
|
|
28
|
+
instance.current = null;
|
|
29
|
+
};
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
+
}, [label, hideCount]);
|
|
32
|
+
useIsomorphicLayoutEffect(() => {
|
|
33
|
+
if (liked !== undefined && instance.current && instance.current.liked !== liked) instance.current.setLiked(liked, false);
|
|
34
|
+
}, [liked]);
|
|
35
|
+
useIsomorphicLayoutEffect(() => {
|
|
36
|
+
if (instance.current && instance.current.count !== count) instance.current.setCount(count);
|
|
37
|
+
}, [count]);
|
|
38
|
+
return <button type="button" {...props} ref={ref} className={['mk-like-button', className].filter(Boolean).join(' ')} />;
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# link-preview
|
|
2
|
+
|
|
3
|
+
Tarjeta de enlace con miniatura (o la inicial del dominio), sitio, título y descripción alrededor de un enlace real; o un enlace que previsualiza esa tarjeta en un [hover-card](../hover-card/README.md) al señalar, enfocar o tocar. La app suministra los metadatos: no se descarga nada ni depende de un backend.
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<mk-link-preview class="mk-link-preview"
|
|
7
|
+
url="https://example.com/guia" title="Guía de movimiento" description="Curvas, duraciones y cuándo no animar."
|
|
8
|
+
image="/thumbs/guia.jpg" site-name="Motion Kit"></mk-link-preview>
|
|
9
|
+
|
|
10
|
+
<p>Lee la <mk-link-preview class="mk-link-preview" variant="hover" label="guía de movimiento" url="https://example.com/guia" title="Guía de movimiento"></mk-link-preview>.</p>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`defineElements()`, `createLinkPreview(root, options)` o `<LinkPreview url="…" title="…" description="…" image="…" siteName="…" variant="hover" label="guía" />`.
|
|
14
|
+
|
|
15
|
+
Opciones: `url`, `title`, `description`, `image`, `imageAlt` (por defecto decorativa), `siteName`, `variant='card'|'row'|'hover'` (`row`: miniatura al lado del texto), `label` (texto del enlace en hover), `target` (`_blank` añade `rel="noopener noreferrer"`) y, en hover, `openDelay`, `closeDelay`, `placement`, `onOpenChange`. API: `href` (el enlace usado o `null`), `hoverCard`, `destroy()`. Utilidades: `safeHref(url)`, `safeImage(url)`, `linkDomain(href)`.
|
|
16
|
+
|
|
17
|
+
Los enlaces aceptan sólo http(s) y rutas relativas: `javascript:`, `data:` u otros esquemas (también con espacios o saltos intercalados) dejan una tarjeta sin enlace. Las imágenes aceptan http(s), relativas, `blob:` y `data:image/…`. Todos los textos se insertan como texto. Si la miniatura falla, se oculta y queda la inicial (`data-mk-image="error"`); después de `destroy()` no hay listeners que cambien nada.
|
|
18
|
+
|
|
19
|
+
Con root vacío el motor crea el marcado y lo quita al destruir; con marcado propio (`[data-mk-link-card]`, `img[data-mk-link-image]`, `[data-mk-hover-trigger]` + `[data-mk-hover-panel]`) sólo añade el comportamiento. La tarjeta sigue a Melon Mind: imagen 16:9 con 8px de margen, inicial del sitio, título a dos líneas, descripción y un botón redondo que gira al señalar; en hover, la tarjeta va dentro del cristal inverso. Variables: `--mk-link-radius` (24px), `--mk-link-thumb` (5.5rem). Movimiento reducido quita la escala al pulsar y el giro.
|