@yewdiel21/motion-kit 0.9.1 → 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 +72 -0
- package/dist/auto/index.d.ts +72 -3
- package/dist/auto/index.js +139 -3
- package/dist/auto/index.js.map +1 -1
- package/dist/{chunk-BFC27F2G.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-XDWBVFHQ.js → chunk-EY4BJKC4.js} +1203 -29
- 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/calendar.css +159 -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 +20 -0
- package/dist/css/components/image-preview.css +195 -0
- package/dist/css/components/input-otp.css +10 -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/pagination.css +11 -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/quantity.css +16 -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/slot-picker.css +126 -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/studio-dock.css +35 -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/trailer.css +37 -0
- package/dist/css/components/tree-view.css +210 -0
- package/dist/css/components/virtual-list.css +195 -0
- package/dist/css/controls.css +65 -0
- package/dist/css/tokens.css +185 -181
- package/dist/elements/index.d.ts +742 -5
- package/dist/elements/index.js +1527 -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 +10113 -181
- package/dist/index.d.ts +89 -5
- package/dist/index.js +285 -9
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +678 -23
- package/dist/react/index.js +2389 -7
- package/dist/react/index.js.map +1 -1
- package/dist/{reduced-B98f8LPs.d.ts → reduced-BBUusld6.d.ts} +206 -2
- package/dist/reveal-DEvp6U6T.d.ts +2381 -0
- package/dist/{store-pHiUvxP8.d.ts → store-DjkTBX7f.d.ts} +2 -2
- package/package.json +1 -1
- package/registry.json +583 -104
- package/skills/motion-kit/SKILL.md +209 -189
- package/src/auto/auto-init.ts +136 -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/calendar/README.md +82 -0
- package/src/components/calendar/calendar.css +158 -0
- package/src/components/calendar/element.ts +27 -0
- package/src/components/calendar/engine.ts +412 -0
- package/src/components/calendar/react.tsx +69 -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 +20 -0
- package/src/components/hover-card/element.ts +8 -0
- package/src/components/hover-card/engine.ts +131 -0
- package/src/components/hover-card/hover-card.css +19 -0
- package/src/components/hover-card/react.tsx +19 -0
- 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/input-otp/README.md +18 -0
- package/src/components/input-otp/element.ts +14 -0
- package/src/components/input-otp/engine.ts +106 -0
- package/src/components/input-otp/input-otp.css +9 -0
- package/src/components/input-otp/react.tsx +21 -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/pagination/README.md +17 -0
- package/src/components/pagination/element.ts +14 -0
- package/src/components/pagination/engine.ts +102 -0
- package/src/components/pagination/pagination.css +10 -0
- package/src/components/pagination/react.tsx +22 -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/quantity/README.md +20 -0
- package/src/components/quantity/element.ts +14 -0
- package/src/components/quantity/engine.ts +85 -0
- package/src/components/quantity/quantity.css +15 -0
- package/src/components/quantity/react.tsx +21 -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/slot-picker/README.md +68 -0
- package/src/components/slot-picker/element.ts +27 -0
- package/src/components/slot-picker/engine.ts +412 -0
- package/src/components/slot-picker/react.tsx +76 -0
- package/src/components/slot-picker/slot-picker.css +125 -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/studio-dock/README.md +44 -0
- package/src/components/studio-dock/element.ts +11 -0
- package/src/components/studio-dock/engine.ts +212 -0
- package/src/components/studio-dock/react.tsx +23 -0
- package/src/components/studio-dock/studio-dock.css +34 -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/trailer/README.md +28 -0
- package/src/components/trailer/element.ts +13 -0
- package/src/components/trailer/engine.ts +189 -0
- package/src/components/trailer/react.tsx +16 -0
- package/src/components/trailer/trailer.css +36 -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 +108 -0
- 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/controls/README.md +14 -0
- package/src/css/controls/status.css +63 -0
- package/src/css/tokens.css +186 -182
- package/src/elements/index.ts +171 -0
- package/src/index.ts +97 -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 +78 -0
- package/src/react/use-action-button.ts +6 -0
- package/src/react/use-editorial-reveal.ts +7 -0
- package/src/react/use-film-hero.ts +6 -0
- package/src/react/use-font-cycle.ts +7 -0
- package/src/react/use-image-zoom.ts +5 -0
- package/src/react/use-joined-cta.ts +5 -0
- package/src/react/use-local-clock.ts +5 -0
- package/src/react/use-scroll-dock.ts +5 -0
- package/src/react/use-sticker.ts +5 -0
- package/src/react/use-studio-dock.ts +8 -0
- package/src/react/use-thumbnail-nav.ts +7 -0
- package/src/react/use-trailer.ts +6 -0
- package/src/react/use-weight-hover.ts +5 -0
- package/src/recipes/action-button/README.md +31 -0
- package/src/recipes/action-button/action-button.css +113 -0
- package/src/recipes/action-button/create-action-button.ts +56 -0
- package/src/recipes/editorial-reveal/README.md +35 -0
- package/src/recipes/editorial-reveal/create-editorial-reveal.ts +91 -0
- package/src/recipes/editorial-reveal/editorial-reveal.css +17 -0
- package/src/recipes/film-hero/README.md +23 -0
- package/src/recipes/film-hero/create-film-hero.ts +65 -0
- package/src/recipes/film-hero/film-hero.css +29 -0
- package/src/recipes/font-cycle/README.md +11 -0
- package/src/recipes/font-cycle/create-font-cycle.ts +126 -0
- package/src/recipes/font-cycle/font-cycle.css +36 -0
- package/src/recipes/image-zoom/README.md +16 -0
- package/src/recipes/image-zoom/create-image-zoom.ts +27 -0
- package/src/recipes/image-zoom/image-zoom.css +7 -0
- package/src/recipes/joined-cta/README.md +13 -0
- package/src/recipes/joined-cta/create-joined-cta.ts +22 -0
- package/src/recipes/joined-cta/joined-cta.css +17 -0
- package/src/recipes/local-clock/README.md +31 -0
- package/src/recipes/local-clock/create-local-clock.ts +61 -0
- package/src/recipes/scroll-dock/README.md +46 -0
- package/src/recipes/scroll-dock/create-scroll-dock.ts +72 -0
- package/src/recipes/scroll-dock/scroll-dock.css +70 -0
- package/src/recipes/sticker/README.md +59 -0
- package/src/recipes/sticker/create-sticker.ts +490 -0
- package/src/recipes/sticker/sticker.css +112 -0
- package/src/recipes/thumbnail-nav/README.md +16 -0
- package/src/recipes/thumbnail-nav/create-thumbnail-nav.ts +165 -0
- package/src/recipes/thumbnail-nav/thumbnail-nav.css +108 -0
- package/src/recipes/weight-hover/README.md +37 -0
- package/src/recipes/weight-hover/create-weight-hover.ts +136 -0
- package/src/recipes/weight-hover/weight-hover.css +7 -0
- package/dist/chunk-BFC27F2G.js.map +0 -1
- package/dist/chunk-J6OCFNGU.js +0 -177
- package/dist/chunk-J6OCFNGU.js.map +0 -1
- package/dist/chunk-JQMJQSXD.js +0 -2374
- package/dist/chunk-JQMJQSXD.js.map +0 -1
- package/dist/chunk-XDWBVFHQ.js.map +0 -1
- package/dist/reveal-C0hCDcB_.d.ts +0 -415
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/* code-block — an editor surface, dark in both modes: a bar with three quiet dots, the file name, the language and a
|
|
2
|
+
glass copy button; mono lines with syntax colours, optional numbers and marked lines. A squared surface (radius 12)
|
|
3
|
+
so long lines never run into a curved corner. */
|
|
4
|
+
.mk-code-block,
|
|
5
|
+
mk-code-block {
|
|
6
|
+
--mk-code-radius: var(--mk-radius-sm, 12px);
|
|
7
|
+
--mk-code-bg: #0e0f11;
|
|
8
|
+
--mk-code-bar: #16171a;
|
|
9
|
+
--mk-code-text: #e6e8ec;
|
|
10
|
+
--mk-code-muted: #8a909b;
|
|
11
|
+
--mk-code-line: rgb(255 255 255 / 0.035);
|
|
12
|
+
--mk-code-mark: rgb(196 165 255 / 0.1);
|
|
13
|
+
--mk-code-keyword: #c4a5ff;
|
|
14
|
+
--mk-code-string: #9fe0b0;
|
|
15
|
+
--mk-code-number: #ffb86b;
|
|
16
|
+
--mk-code-comment: #7d8390;
|
|
17
|
+
--mk-code-function: #82b4ff;
|
|
18
|
+
--mk-code-tag: #ff8f8f;
|
|
19
|
+
--mk-code-attr: #ffd479;
|
|
20
|
+
--mk-code-property: #8fd6ff;
|
|
21
|
+
--mk-code-punctuation: #9aa0aa;
|
|
22
|
+
--mk-code-operator: #c9ced6;
|
|
23
|
+
position: relative;
|
|
24
|
+
display: block;
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
border-radius: var(--mk-code-radius);
|
|
27
|
+
background: var(--mk-code-bg);
|
|
28
|
+
box-shadow:
|
|
29
|
+
inset 0 0 0 1px rgb(255 255 255 / 0.06),
|
|
30
|
+
0 18px 40px -24px rgb(0 0 0 / 0.55);
|
|
31
|
+
color: var(--mk-code-text);
|
|
32
|
+
color-scheme: dark;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-header] {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: 0.75rem;
|
|
39
|
+
min-height: 3rem;
|
|
40
|
+
padding: 0.4rem 0.45rem 0.4rem 1rem;
|
|
41
|
+
background: var(--mk-code-bar);
|
|
42
|
+
box-shadow: inset 0 -1px 0 rgb(255 255 255 / 0.05);
|
|
43
|
+
font-family: var(--mk-font);
|
|
44
|
+
font-size: 0.8125rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-dots] {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
flex: none;
|
|
50
|
+
gap: 6px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-dots] i {
|
|
54
|
+
width: 10px;
|
|
55
|
+
height: 10px;
|
|
56
|
+
border-radius: 50%;
|
|
57
|
+
background: rgb(255 255 255 / 0.14);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-title] {
|
|
61
|
+
flex: 1;
|
|
62
|
+
min-width: 0;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
color: var(--mk-code-text);
|
|
65
|
+
font-weight: 500;
|
|
66
|
+
text-overflow: ellipsis;
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-language] {
|
|
71
|
+
padding: 0.15rem 0.5rem;
|
|
72
|
+
border-radius: 6px;
|
|
73
|
+
background: rgb(255 255 255 / 0.07);
|
|
74
|
+
color: var(--mk-code-muted);
|
|
75
|
+
font-family: var(--mk-font-mono, ui-monospace, monospace);
|
|
76
|
+
font-size: 0.75rem;
|
|
77
|
+
text-transform: lowercase;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
:is(.mk-code-block, mk-code-block) pre {
|
|
81
|
+
margin: 0;
|
|
82
|
+
padding: 1rem 0;
|
|
83
|
+
overflow-x: auto;
|
|
84
|
+
font-family: var(--mk-font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
85
|
+
font-size: 0.875rem;
|
|
86
|
+
line-height: 1.7;
|
|
87
|
+
tab-size: 2;
|
|
88
|
+
scrollbar-color: rgb(255 255 255 / 0.2) transparent;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:is(.mk-code-block, mk-code-block) pre:focus-visible {
|
|
92
|
+
outline: 2px solid var(--mk-code-keyword);
|
|
93
|
+
outline-offset: -4px;
|
|
94
|
+
border-radius: calc(var(--mk-code-radius) - 4px);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
:is(.mk-code-block, mk-code-block) code {
|
|
98
|
+
display: block;
|
|
99
|
+
min-width: max-content;
|
|
100
|
+
padding: 0 1.25rem;
|
|
101
|
+
font: inherit;
|
|
102
|
+
white-space: pre;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* Highlighted code: block lines (the newlines between them are not rendered in a grid). */
|
|
106
|
+
:is(.mk-code-block, mk-code-block) code:has([data-mk-code-line]) {
|
|
107
|
+
display: grid;
|
|
108
|
+
padding: 0;
|
|
109
|
+
counter-reset: mk-line;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-line] {
|
|
113
|
+
display: block;
|
|
114
|
+
translate: 0 var(--mk-line-y, 0);
|
|
115
|
+
min-height: 1.7em;
|
|
116
|
+
padding: 0 1.25rem;
|
|
117
|
+
transition: background-color 0.15s ease;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-line]:hover {
|
|
121
|
+
background: var(--mk-code-line);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-line][data-mk-highlight] {
|
|
125
|
+
background: var(--mk-code-mark);
|
|
126
|
+
box-shadow: inset 2px 0 0 var(--mk-code-keyword);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
:is(.mk-code-block, mk-code-block)[data-mk-line-numbers] [data-mk-code-line]::before {
|
|
130
|
+
counter-increment: mk-line;
|
|
131
|
+
content: counter(mk-line);
|
|
132
|
+
display: inline-block;
|
|
133
|
+
width: 2ch;
|
|
134
|
+
margin-right: 1.25rem;
|
|
135
|
+
color: var(--mk-code-muted);
|
|
136
|
+
opacity: 0.55;
|
|
137
|
+
text-align: right;
|
|
138
|
+
user-select: none;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='keyword'] { color: var(--mk-code-keyword); }
|
|
142
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='string'] { color: var(--mk-code-string); }
|
|
143
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='number'] { color: var(--mk-code-number); }
|
|
144
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='comment'] { color: var(--mk-code-comment); font-style: italic; }
|
|
145
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='function'] { color: var(--mk-code-function); }
|
|
146
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='tag'] { color: var(--mk-code-tag); }
|
|
147
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='attr'] { color: var(--mk-code-attr); }
|
|
148
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='property'] { color: var(--mk-code-property); }
|
|
149
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='punctuation'] { color: var(--mk-code-punctuation); }
|
|
150
|
+
:is(.mk-code-block, mk-code-block) [data-mk-token='operator'] { color: var(--mk-code-operator); }
|
|
151
|
+
|
|
152
|
+
/* The copy button: glass on the bar, or floating in the corner when authored outside it. */
|
|
153
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy] {
|
|
154
|
+
display: inline-flex;
|
|
155
|
+
flex: none;
|
|
156
|
+
align-items: center;
|
|
157
|
+
justify-content: center;
|
|
158
|
+
gap: 0.4rem;
|
|
159
|
+
min-height: 2.25rem;
|
|
160
|
+
padding: 0 0.9rem;
|
|
161
|
+
overflow: hidden;
|
|
162
|
+
border: 0;
|
|
163
|
+
border-radius: var(--mk-radius-xs, 8px);
|
|
164
|
+
background: rgb(255 255 255 / 0.08);
|
|
165
|
+
box-shadow:
|
|
166
|
+
inset 1px 1px 1px rgb(255 255 255 / 0.08),
|
|
167
|
+
inset -1px -1px 1px rgb(255 255 255 / 0.04);
|
|
168
|
+
color: var(--mk-code-text);
|
|
169
|
+
font-family: var(--mk-font);
|
|
170
|
+
font-size: 0.8125rem;
|
|
171
|
+
font-weight: 500;
|
|
172
|
+
white-space: nowrap;
|
|
173
|
+
cursor: pointer;
|
|
174
|
+
transition:
|
|
175
|
+
background-color 0.2s ease,
|
|
176
|
+
color 0.2s ease;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
:is(.mk-code-block, mk-code-block) > [data-mk-code-copy] {
|
|
180
|
+
position: absolute;
|
|
181
|
+
top: 3.5rem;
|
|
182
|
+
right: 0.6rem;
|
|
183
|
+
z-index: 1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy]:hover {
|
|
187
|
+
background: rgb(255 255 255 / 0.14);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy]:focus-visible {
|
|
191
|
+
outline: 2px solid var(--mk-code-keyword);
|
|
192
|
+
outline-offset: 2px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
:is(.mk-code-block, mk-code-block)[data-mk-copied] [data-mk-code-copy] {
|
|
196
|
+
background: #e6e8ec;
|
|
197
|
+
color: #0e0f11;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
:is(.mk-code-block, mk-code-block)[data-mk-copy-error] [data-mk-code-copy] {
|
|
201
|
+
background: rgb(255 120 120 / 0.18);
|
|
202
|
+
color: #ffb4b4;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* The icon turns into a check (or a cross) with a blur. */
|
|
206
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy] svg {
|
|
207
|
+
flex: none;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
:is(.mk-code-block, mk-code-block):is([data-mk-copied], [data-mk-copy-error]) [data-mk-code-copy] svg {
|
|
211
|
+
display: none;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
:is(.mk-code-block, mk-code-block):is([data-mk-copied], [data-mk-copy-error]) [data-mk-code-copy]::before {
|
|
215
|
+
content: '';
|
|
216
|
+
width: 16px;
|
|
217
|
+
height: 16px;
|
|
218
|
+
background: currentColor;
|
|
219
|
+
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / contain no-repeat;
|
|
220
|
+
animation: mk-code-check 0.4s cubic-bezier(0.1, 0.8, 0, 1.1);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
:is(.mk-code-block, mk-code-block)[data-mk-copy-error] [data-mk-code-copy]::before {
|
|
224
|
+
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* The button says what happened (the status says it to screen readers). */
|
|
228
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy-text][data-mk-feedback] {
|
|
229
|
+
font-size: 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy-text][data-mk-feedback]::after {
|
|
233
|
+
content: attr(data-mk-feedback);
|
|
234
|
+
font-size: 0.8125rem;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@keyframes mk-code-check {
|
|
238
|
+
from {
|
|
239
|
+
opacity: 0;
|
|
240
|
+
filter: blur(6px);
|
|
241
|
+
transform: scale(0.4) rotate(-20deg);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@media (max-width: 520px) {
|
|
246
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-dots] {
|
|
247
|
+
display: none;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
:is(.mk-code-block, mk-code-block) pre {
|
|
251
|
+
font-size: 0.8125rem;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@media (prefers-reduced-motion: reduce) {
|
|
256
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-copy]::before {
|
|
257
|
+
animation: none !important;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
:is(.mk-code-block, mk-code-block) [data-mk-code-line] {
|
|
261
|
+
transition: none;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MkElement, defineElement, type OptionType } from '../../elements/base';
|
|
2
|
+
import { createCodeBlock, type CodeBlockInstance } from './engine';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* <mk-code-block class="mk-code-block" title="Instalar" language="bash" line-numbers>
|
|
6
|
+
* <pre><code>npm install @yewdiel21/motion-kit gsap</code></pre>
|
|
7
|
+
* </mk-code-block>
|
|
8
|
+
* Header, copy button and status are made when absent. Emits `mk:copy` ({ok, code}).
|
|
9
|
+
*/
|
|
10
|
+
export class MkCodeBlockElement extends MkElement<CodeBlockInstance> {
|
|
11
|
+
static options: Record<string, OptionType> = {
|
|
12
|
+
code: 'string',
|
|
13
|
+
language: 'string',
|
|
14
|
+
title: 'string',
|
|
15
|
+
lineNumbers: 'boolean',
|
|
16
|
+
copyLabel: 'string',
|
|
17
|
+
copiedLabel: 'string',
|
|
18
|
+
errorLabel: 'string',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
protected create(options: Record<string, unknown>) {
|
|
22
|
+
return createCodeBlock(this, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
setCode(code: string) {
|
|
26
|
+
this.instance?.setCode(code);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
copy() {
|
|
30
|
+
return this.instance?.copy() ?? Promise.resolve(false);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const defineCodeBlock = () => defineElement('mk-code-block', MkCodeBlockElement);
|
|
@@ -0,0 +1,254 @@
|
|
|
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 { press } from '../../motion/micro';
|
|
6
|
+
import { languageFamily, renderCode } from './highlight';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Code block: <pre><code> with optional title/language header, line numbers and
|
|
10
|
+
* a copy button. Code is always text (textContent), so markup-looking strings
|
|
11
|
+
* show as code. Copy writes the exact string with the Clipboard API and reports
|
|
12
|
+
* success or failure in a polite status; on failure the code is selected so it
|
|
13
|
+
* can be copied by hand. A copy that finishes after destroy changes nothing.
|
|
14
|
+
* Parts (made when absent): pre > code, [data-mk-code-copy], [data-mk-code-status].
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface CodeBlockOptions {
|
|
18
|
+
/** The code; omitted, the text already in <code> is used (and read at copy time). */
|
|
19
|
+
code?: string;
|
|
20
|
+
language?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
lineNumbers?: boolean;
|
|
23
|
+
/** Colour the syntax (default: when the language is supported). */
|
|
24
|
+
highlight?: boolean;
|
|
25
|
+
/** 1-based lines to mark. */
|
|
26
|
+
highlightLines?: number[];
|
|
27
|
+
copyLabel?: string;
|
|
28
|
+
copiedLabel?: string;
|
|
29
|
+
errorLabel?: string;
|
|
30
|
+
onCopy?: (ok: boolean) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CodeBlockInstance extends Instance {
|
|
34
|
+
setCode(code: string): void;
|
|
35
|
+
/** Copy the code; resolves true when the clipboard took it. */
|
|
36
|
+
copy(): Promise<boolean>;
|
|
37
|
+
readonly code: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const COPY_ICON =
|
|
41
|
+
'<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5 15V6a2 2 0 0 1 2-2h8"/></svg>';
|
|
42
|
+
const FEEDBACK_MS = 2000;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* New code flows in line by line: opacity, blur 12 and an 8 px drop through the
|
|
46
|
+
* --mk-line-y custom property (no measured transform, so the newline text nodes
|
|
47
|
+
* between lines never move). Capped at 40 lines so long files stay quick.
|
|
48
|
+
*/
|
|
49
|
+
export function flowLines(root: Element | null) {
|
|
50
|
+
if (!root || reduced()) return null;
|
|
51
|
+
registerMotion();
|
|
52
|
+
const lines = [...root.querySelectorAll('[data-mk-code-line]')].slice(0, 40);
|
|
53
|
+
if (!lines.length) return null;
|
|
54
|
+
return gsap.fromTo(
|
|
55
|
+
lines,
|
|
56
|
+
{ opacity: 0, filter: 'blur(12px)', '--mk-line-y': '-8px' },
|
|
57
|
+
{ opacity: 1, filter: 'blur(0px)', '--mk-line-y': '0px', duration: 0.4, ease: 'power2.out', stagger: 0.015, clearProps: 'opacity,filter,--mk-line-y' },
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Line count of a code string (a final newline does not open a line). */
|
|
62
|
+
export const codeLines = (code: string) => Math.max(1, code.replace(/\n$/, '').split('\n').length);
|
|
63
|
+
|
|
64
|
+
export function createCodeBlock(root: HTMLElement | null, options: CodeBlockOptions = {}): CodeBlockInstance {
|
|
65
|
+
if (!root) return inert({ setCode() {}, copy: async () => false, code: '' });
|
|
66
|
+
registerMotion();
|
|
67
|
+
const scope = createScope();
|
|
68
|
+
const copyLabel = options.copyLabel ?? 'Copiar';
|
|
69
|
+
const copiedLabel = options.copiedLabel ?? 'Copiado';
|
|
70
|
+
const errorLabel = options.errorLabel ?? 'No se pudo copiar';
|
|
71
|
+
const made = <K extends keyof HTMLElementTagNameMap>(tag: K, place: (element: HTMLElementTagNameMap[K]) => void) => {
|
|
72
|
+
const element = document.createElement(tag);
|
|
73
|
+
place(element);
|
|
74
|
+
scope.add(() => element.remove());
|
|
75
|
+
return element;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
let pre = root.querySelector('pre');
|
|
79
|
+
if (!pre) pre = made('pre', (element) => root.append(element));
|
|
80
|
+
let code = pre.querySelector('code');
|
|
81
|
+
if (!code) code = made('code', (element) => pre!.append(element));
|
|
82
|
+
const authoredText = code.textContent ?? '';
|
|
83
|
+
let owned = false;
|
|
84
|
+
let text = authoredText;
|
|
85
|
+
/** From now on the engine writes the text (and puts the authored one back on destroy). */
|
|
86
|
+
const own = () => {
|
|
87
|
+
if (owned) return;
|
|
88
|
+
owned = true;
|
|
89
|
+
scope.add(() => (code!.textContent = authoredText));
|
|
90
|
+
};
|
|
91
|
+
if (options.code !== undefined) {
|
|
92
|
+
own();
|
|
93
|
+
text = options.code;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// The editor bar: three quiet dots, the file name, the language and the copy button.
|
|
97
|
+
let header = root.querySelector<HTMLElement>('[data-mk-code-header]');
|
|
98
|
+
if (!header) {
|
|
99
|
+
header = made('div', (element) => root.prepend(element));
|
|
100
|
+
header.dataset.mkCodeHeader = '';
|
|
101
|
+
const dots = document.createElement('span');
|
|
102
|
+
dots.dataset.mkCodeDots = '';
|
|
103
|
+
dots.setAttribute('aria-hidden', 'true');
|
|
104
|
+
dots.append(document.createElement('i'), document.createElement('i'), document.createElement('i'));
|
|
105
|
+
header.append(dots);
|
|
106
|
+
const name = document.createElement('span');
|
|
107
|
+
name.dataset.mkCodeTitle = '';
|
|
108
|
+
name.textContent = options.title ?? '';
|
|
109
|
+
header.append(name);
|
|
110
|
+
if (options.language) {
|
|
111
|
+
const language = document.createElement('span');
|
|
112
|
+
language.dataset.mkCodeLanguage = '';
|
|
113
|
+
language.textContent = options.language;
|
|
114
|
+
header.append(language);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (!root.querySelector('[data-mk-code-copy]')) {
|
|
118
|
+
const button = made('button', (element) => (header ?? root).append(element));
|
|
119
|
+
button.type = 'button';
|
|
120
|
+
button.dataset.mkCodeCopy = '';
|
|
121
|
+
button.innerHTML = `${COPY_ICON}<span data-mk-code-copy-text>${copyLabel.replace(/[&<>"]/g, (c) => `&#${c.charCodeAt(0)};`)}</span>`;
|
|
122
|
+
}
|
|
123
|
+
for (const button of root.querySelectorAll<HTMLButtonElement>('button[data-mk-code-copy]')) if (!button.hasAttribute('type')) scope.attr(button, 'type', 'button');
|
|
124
|
+
let status = root.querySelector<HTMLElement>('[data-mk-code-status]');
|
|
125
|
+
if (!status) {
|
|
126
|
+
status = made('span', (element) => root.append(element));
|
|
127
|
+
status.dataset.mkCodeStatus = '';
|
|
128
|
+
status.className = 'mk-sr-only';
|
|
129
|
+
status.setAttribute('role', 'status');
|
|
130
|
+
} else if (!status.matches('output') && !status.hasAttribute('role')) scope.attr(status, 'role', 'status');
|
|
131
|
+
const statusText = status.textContent;
|
|
132
|
+
scope.add(() => (status!.textContent = statusText));
|
|
133
|
+
|
|
134
|
+
// Long lines scroll: the region takes keyboard focus so it can be scrolled.
|
|
135
|
+
if (!pre.hasAttribute('tabindex')) scope.attr(pre, 'tabindex', '0');
|
|
136
|
+
if (options.language) scope.attr(root, 'data-mk-language', options.language);
|
|
137
|
+
if (options.lineNumbers) scope.attr(root, 'data-mk-line-numbers', '');
|
|
138
|
+
scope.attr(root, 'data-mk-ready', '');
|
|
139
|
+
|
|
140
|
+
// A framework that already rendered the lines owns them; the engine only copies.
|
|
141
|
+
const prerendered = Boolean(code.querySelector('[data-mk-code-line]'));
|
|
142
|
+
/** Text given through setCode while a framework renders the lines. */
|
|
143
|
+
let given: string | null = null;
|
|
144
|
+
const highlight = !prerendered && (options.highlight ?? languageFamily(options.language) !== 'plain');
|
|
145
|
+
if (highlight) own();
|
|
146
|
+
const render = () => {
|
|
147
|
+
if (highlight) renderCode(code!, text, options.language, options.highlightLines);
|
|
148
|
+
else if (owned) code!.textContent = text;
|
|
149
|
+
};
|
|
150
|
+
render();
|
|
151
|
+
const effects = new Set<gsap.core.Animation>();
|
|
152
|
+
const keep = (animation: gsap.core.Animation | null) => {
|
|
153
|
+
if (!animation) return;
|
|
154
|
+
effects.add(animation);
|
|
155
|
+
// Finished ones leave as new ones arrive: the animation's own onComplete stays untouched.
|
|
156
|
+
for (const effect of effects) if (effect.totalProgress() === 1) effects.delete(effect);
|
|
157
|
+
};
|
|
158
|
+
scope.add(() => {
|
|
159
|
+
for (const effect of effects) effect.kill();
|
|
160
|
+
effects.clear();
|
|
161
|
+
});
|
|
162
|
+
/** The copy button springs to the width of its new label (Melonmind's playful curve). */
|
|
163
|
+
const resize = (change: () => void) => {
|
|
164
|
+
const buttons = [...root.querySelectorAll<HTMLElement>('[data-mk-code-copy]')];
|
|
165
|
+
const before = buttons.map((button) => button.getBoundingClientRect().width);
|
|
166
|
+
change();
|
|
167
|
+
if (reduced()) return;
|
|
168
|
+
buttons.forEach((button, i) => {
|
|
169
|
+
const after = button.getBoundingClientRect().width;
|
|
170
|
+
if (!before[i] || !after || Math.abs(after - before[i]!) < 1) return;
|
|
171
|
+
keep(gsap.fromTo(button, { width: before[i] }, { width: after, duration: 0.45, ease: EASE.playful, clearProps: 'width' }));
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
let attempt = 0;
|
|
176
|
+
const feedback = (ok: boolean) => {
|
|
177
|
+
// The button shows the outcome too (CSS reads data-mk-feedback) and springs to its width.
|
|
178
|
+
const labels = [...root.querySelectorAll<HTMLElement>('[data-mk-code-copy-text]')];
|
|
179
|
+
resize(() => {
|
|
180
|
+
scope.attr(root, 'data-mk-copied', ok ? '' : null);
|
|
181
|
+
scope.attr(root, 'data-mk-copy-error', ok ? null : '');
|
|
182
|
+
for (const label of labels) scope.attr(label, 'data-mk-feedback', ok ? copiedLabel : errorLabel);
|
|
183
|
+
});
|
|
184
|
+
for (const button of root.querySelectorAll('[data-mk-code-copy]')) keep(press(button));
|
|
185
|
+
status!.textContent = ok ? copiedLabel : errorLabel;
|
|
186
|
+
const mine = attempt;
|
|
187
|
+
scope.timeout(() => {
|
|
188
|
+
if (mine !== attempt) return;
|
|
189
|
+
resize(() => {
|
|
190
|
+
scope.attr(root, 'data-mk-copied', null);
|
|
191
|
+
scope.attr(root, 'data-mk-copy-error', null);
|
|
192
|
+
for (const label of labels) scope.attr(label, 'data-mk-feedback', null);
|
|
193
|
+
});
|
|
194
|
+
}, FEEDBACK_MS);
|
|
195
|
+
};
|
|
196
|
+
const selectCode = () => {
|
|
197
|
+
const selection = typeof getSelection === 'function' ? getSelection() : null;
|
|
198
|
+
if (!selection) return;
|
|
199
|
+
const range = document.createRange();
|
|
200
|
+
range.selectNodeContents(code!);
|
|
201
|
+
selection.removeAllRanges();
|
|
202
|
+
selection.addRange(range);
|
|
203
|
+
};
|
|
204
|
+
const current = () => given ?? (owned ? text : ((code!.isConnected ? code : root.querySelector('code'))?.textContent ?? ''));
|
|
205
|
+
|
|
206
|
+
const copy = async () => {
|
|
207
|
+
if (scope.disposed) return false;
|
|
208
|
+
const mine = ++attempt;
|
|
209
|
+
const value = current();
|
|
210
|
+
let ok = false;
|
|
211
|
+
try {
|
|
212
|
+
if (!navigator.clipboard?.writeText) throw new Error('clipboard unavailable');
|
|
213
|
+
await navigator.clipboard.writeText(value);
|
|
214
|
+
ok = true;
|
|
215
|
+
} catch {
|
|
216
|
+
ok = false;
|
|
217
|
+
}
|
|
218
|
+
// Destroyed (or a newer copy started) meanwhile: leave the DOM alone.
|
|
219
|
+
if (scope.disposed) return false;
|
|
220
|
+
if (mine !== attempt) return ok;
|
|
221
|
+
feedback(ok);
|
|
222
|
+
if (!ok) selectCode();
|
|
223
|
+
options.onCopy?.(ok);
|
|
224
|
+
root.dispatchEvent(new CustomEvent('mk:copy', { bubbles: true, detail: { ok, code: value } }));
|
|
225
|
+
return ok;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// Delegated: a framework may replace the button.
|
|
229
|
+
scope.on(root, 'click', (event) => {
|
|
230
|
+
const button = (event.target as Element | null)?.closest('[data-mk-code-copy]');
|
|
231
|
+
if (button && root.contains(button)) void copy();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
setCode(next) {
|
|
236
|
+
if (scope.disposed) return;
|
|
237
|
+
// Framework-rendered lines: only the text to copy changes.
|
|
238
|
+
if (prerendered) {
|
|
239
|
+
given = String(next);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
own();
|
|
243
|
+
const changed = text !== String(next);
|
|
244
|
+
text = String(next);
|
|
245
|
+
render();
|
|
246
|
+
if (changed && highlight) keep(flowLines(code));
|
|
247
|
+
},
|
|
248
|
+
copy,
|
|
249
|
+
get code() {
|
|
250
|
+
return current();
|
|
251
|
+
},
|
|
252
|
+
destroy: () => scope.dispose(),
|
|
253
|
+
};
|
|
254
|
+
}
|