@wordpress/block-library 11.1.0 → 11.2.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/CHANGELOG.md +32 -0
- package/build/accordion-heading/block.json +1 -0
- package/build/archives/block.json +3 -0
- package/build/audio/edit.cjs +2 -1
- package/build/audio/edit.cjs.map +2 -2
- package/build/avatar/block.json +4 -0
- package/build/avatar/edit.cjs +31 -1
- package/build/avatar/edit.cjs.map +3 -3
- package/build/button/block.json +6 -0
- package/build/button/edit.cjs +9 -6
- package/build/button/edit.cjs.map +2 -2
- package/build/buttons/block.json +6 -1
- package/build/code/block.json +4 -0
- package/build/column/edit.cjs +5 -0
- package/build/column/edit.cjs.map +2 -2
- package/build/columns/block.json +4 -0
- package/build/columns/edit.cjs +21 -112
- package/build/columns/edit.cjs.map +3 -3
- package/build/comments/edit/placeholder.cjs +95 -87
- package/build/comments/edit/placeholder.cjs.map +2 -2
- package/build/comments-pagination/block.json +11 -0
- package/build/cover/block.json +2 -1
- package/build/cover/edit/index.cjs +26 -5
- package/build/cover/edit/index.cjs.map +2 -2
- package/build/cover/edit/inspector-controls.cjs +4 -1
- package/build/cover/edit/inspector-controls.cjs.map +2 -2
- package/build/cover/embed-video-utils.cjs +9 -8
- package/build/cover/embed-video-utils.cjs.map +2 -2
- package/build/cover/view.cjs +21 -0
- package/build/cover/view.cjs.map +7 -0
- package/build/details/block.json +3 -0
- package/build/embed/block.json +6 -1
- package/build/file/block.json +5 -0
- package/build/footnotes/block.json +4 -0
- package/build/gallery/block.json +13 -0
- package/build/gallery/dynamic-gallery.cjs +32 -93
- package/build/gallery/dynamic-gallery.cjs.map +3 -3
- package/build/gallery/edit.cjs +103 -40
- package/build/gallery/edit.cjs.map +2 -2
- package/build/gallery/order-controls.cjs +107 -0
- package/build/gallery/order-controls.cjs.map +7 -0
- package/build/gallery/order-images.cjs +92 -0
- package/build/gallery/order-images.cjs.map +7 -0
- package/build/gallery/order-options.cjs +62 -0
- package/build/gallery/order-options.cjs.map +7 -0
- package/build/gallery/use-dynamic-gallery.cjs +1 -7
- package/build/gallery/use-dynamic-gallery.cjs.map +2 -2
- package/build/gallery/use-get-media.cjs +2 -3
- package/build/gallery/use-get-media.cjs.map +2 -2
- package/build/group/edit.cjs +3 -3
- package/build/group/edit.cjs.map +2 -2
- package/build/heading/block.json +5 -0
- package/build/home-link/block.json +12 -0
- package/build/icon/components/custom-inserter/index.cjs +3 -1
- package/build/icon/components/custom-inserter/index.cjs.map +2 -2
- package/build/icon/edit.cjs +49 -5
- package/build/icon/edit.cjs.map +2 -2
- package/build/image/use-open-image-media-editor-modal.cjs +32 -28
- package/build/image/use-open-image-media-editor-modal.cjs.map +2 -2
- package/build/image/view.cjs +44 -50
- package/build/image/view.cjs.map +2 -2
- package/build/latest-comments/block.json +10 -0
- package/build/latest-posts/block.json +4 -0
- package/build/list/block.json +12 -1
- package/build/list-item/block.json +8 -1
- package/build/list-item/index.cjs +4 -0
- package/build/list-item/index.cjs.map +3 -3
- package/build/loginout/block.json +4 -0
- package/build/math/block.json +4 -0
- package/build/media-text/block.json +18 -0
- package/build/navigation-link/link-ui/index.cjs +33 -19
- package/build/navigation-link/link-ui/index.cjs.map +2 -2
- package/build/navigation-link/shared/index.cjs +5 -0
- package/build/navigation-link/shared/index.cjs.map +2 -2
- package/build/navigation-link/shared/use-block-suggestions.cjs +141 -0
- package/build/navigation-link/shared/use-block-suggestions.cjs.map +7 -0
- package/build/page-list/block.json +4 -0
- package/build/paragraph/block.json +1 -0
- package/build/post-author-biography/block.json +1 -0
- package/build/post-comments-form/block.json +5 -0
- package/build/post-content/block.json +2 -1
- package/build/post-excerpt/block.json +4 -0
- package/build/post-featured-image/block.json +1 -0
- package/build/post-featured-image/edit.cjs +1 -1
- package/build/post-featured-image/edit.cjs.map +2 -2
- package/build/post-terms/block.json +4 -0
- package/build/post-time-to-read/block.json +4 -0
- package/build/post-title/block.json +4 -0
- package/build/preformatted/block.json +4 -0
- package/build/pullquote/block.json +2 -1
- package/build/query-no-results/block.json +4 -0
- package/build/query-pagination/block.json +17 -0
- package/build/query-total/block.json +4 -0
- package/build/quote/block.json +2 -0
- package/build/read-more/block.json +5 -0
- package/build/rss/block.json +4 -0
- package/build/search/block.json +2 -1
- package/build/site-tagline/block.json +4 -0
- package/build/site-title/block.json +4 -0
- package/build/social-links/block.json +1 -0
- package/build/tab-list/block.json +4 -0
- package/build/tab-list/edit.cjs +3 -1
- package/build/tab-list/edit.cjs.map +3 -3
- package/build/tab-list/save.cjs +3 -1
- package/build/tab-list/save.cjs.map +3 -3
- package/build/tab-panels/block.json +3 -0
- package/build/tabs/block.json +3 -0
- package/build/term-count/block.json +5 -0
- package/build/term-description/block.json +4 -0
- package/build/term-name/block.json +6 -1
- package/build/term-template/block.json +4 -0
- package/build/utils/waveform-utils.cjs +2 -2
- package/build/utils/waveform-utils.cjs.map +2 -2
- package/build/verse/block.json +4 -0
- package/build/video/block.json +7 -1
- package/build/video/edit.cjs +10 -2
- package/build/video/edit.cjs.map +2 -2
- package/build-module/accordion-heading/block.json +1 -0
- package/build-module/archives/block.json +3 -0
- package/build-module/audio/edit.mjs +2 -1
- package/build-module/audio/edit.mjs.map +2 -2
- package/build-module/avatar/block.json +4 -0
- package/build-module/avatar/edit.mjs +33 -2
- package/build-module/avatar/edit.mjs.map +2 -2
- package/build-module/button/block.json +6 -0
- package/build-module/button/edit.mjs +11 -7
- package/build-module/button/edit.mjs.map +2 -2
- package/build-module/buttons/block.json +6 -1
- package/build-module/code/block.json +4 -0
- package/build-module/column/edit.mjs +5 -0
- package/build-module/column/edit.mjs.map +2 -2
- package/build-module/columns/block.json +4 -0
- package/build-module/columns/edit.mjs +22 -122
- package/build-module/columns/edit.mjs.map +2 -2
- package/build-module/comments/edit/placeholder.mjs +95 -87
- package/build-module/comments/edit/placeholder.mjs.map +2 -2
- package/build-module/comments-pagination/block.json +11 -0
- package/build-module/cover/block.json +2 -1
- package/build-module/cover/edit/index.mjs +32 -6
- package/build-module/cover/edit/index.mjs.map +2 -2
- package/build-module/cover/edit/inspector-controls.mjs +5 -2
- package/build-module/cover/edit/inspector-controls.mjs.map +2 -2
- package/build-module/cover/embed-video-utils.mjs +9 -8
- package/build-module/cover/embed-video-utils.mjs.map +2 -2
- package/build-module/cover/view.mjs +19 -0
- package/build-module/cover/view.mjs.map +7 -0
- package/build-module/details/block.json +3 -0
- package/build-module/embed/block.json +6 -1
- package/build-module/file/block.json +5 -0
- package/build-module/footnotes/block.json +4 -0
- package/build-module/gallery/block.json +13 -0
- package/build-module/gallery/dynamic-gallery.mjs +33 -97
- package/build-module/gallery/dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/edit.mjs +110 -42
- package/build-module/gallery/edit.mjs.map +2 -2
- package/build-module/gallery/order-controls.mjs +87 -0
- package/build-module/gallery/order-controls.mjs.map +7 -0
- package/build-module/gallery/order-images.mjs +66 -0
- package/build-module/gallery/order-images.mjs.map +7 -0
- package/build-module/gallery/order-options.mjs +33 -0
- package/build-module/gallery/order-options.mjs.map +7 -0
- package/build-module/gallery/use-dynamic-gallery.mjs +1 -7
- package/build-module/gallery/use-dynamic-gallery.mjs.map +2 -2
- package/build-module/gallery/use-get-media.mjs +2 -3
- package/build-module/gallery/use-get-media.mjs.map +2 -2
- package/build-module/group/edit.mjs +4 -4
- package/build-module/group/edit.mjs.map +2 -2
- package/build-module/heading/block.json +5 -0
- package/build-module/home-link/block.json +12 -0
- package/build-module/icon/components/custom-inserter/index.mjs +3 -1
- package/build-module/icon/components/custom-inserter/index.mjs.map +2 -2
- package/build-module/icon/edit.mjs +50 -6
- package/build-module/icon/edit.mjs.map +2 -2
- package/build-module/image/use-open-image-media-editor-modal.mjs +32 -28
- package/build-module/image/use-open-image-media-editor-modal.mjs.map +2 -2
- package/build-module/image/view.mjs +44 -50
- package/build-module/image/view.mjs.map +2 -2
- package/build-module/latest-comments/block.json +10 -0
- package/build-module/latest-posts/block.json +4 -0
- package/build-module/list/block.json +12 -1
- package/build-module/list-item/block.json +8 -1
- package/build-module/list-item/index.mjs +4 -0
- package/build-module/list-item/index.mjs.map +2 -2
- package/build-module/loginout/block.json +4 -0
- package/build-module/math/block.json +4 -0
- package/build-module/media-text/block.json +18 -0
- package/build-module/navigation-link/link-ui/index.mjs +39 -20
- package/build-module/navigation-link/link-ui/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/index.mjs +6 -0
- package/build-module/navigation-link/shared/index.mjs.map +2 -2
- package/build-module/navigation-link/shared/use-block-suggestions.mjs +120 -0
- package/build-module/navigation-link/shared/use-block-suggestions.mjs.map +7 -0
- package/build-module/page-list/block.json +4 -0
- package/build-module/paragraph/block.json +1 -0
- package/build-module/post-author-biography/block.json +1 -0
- package/build-module/post-comments-form/block.json +5 -0
- package/build-module/post-content/block.json +2 -1
- package/build-module/post-excerpt/block.json +4 -0
- package/build-module/post-featured-image/block.json +1 -0
- package/build-module/post-featured-image/edit.mjs +1 -1
- package/build-module/post-featured-image/edit.mjs.map +2 -2
- package/build-module/post-terms/block.json +4 -0
- package/build-module/post-time-to-read/block.json +4 -0
- package/build-module/post-title/block.json +4 -0
- package/build-module/preformatted/block.json +4 -0
- package/build-module/pullquote/block.json +2 -1
- package/build-module/query-no-results/block.json +4 -0
- package/build-module/query-pagination/block.json +17 -0
- package/build-module/query-total/block.json +4 -0
- package/build-module/quote/block.json +2 -0
- package/build-module/read-more/block.json +5 -0
- package/build-module/rss/block.json +4 -0
- package/build-module/search/block.json +2 -1
- package/build-module/site-tagline/block.json +4 -0
- package/build-module/site-title/block.json +4 -0
- package/build-module/social-links/block.json +1 -0
- package/build-module/tab-list/block.json +4 -0
- package/build-module/tab-list/edit.mjs +4 -1
- package/build-module/tab-list/edit.mjs.map +2 -2
- package/build-module/tab-list/save.mjs +4 -1
- package/build-module/tab-list/save.mjs.map +2 -2
- package/build-module/tab-panels/block.json +3 -0
- package/build-module/tabs/block.json +3 -0
- package/build-module/term-count/block.json +5 -0
- package/build-module/term-description/block.json +4 -0
- package/build-module/term-name/block.json +6 -1
- package/build-module/term-template/block.json +4 -0
- package/build-module/utils/waveform-utils.mjs +1 -1
- package/build-module/utils/waveform-utils.mjs.map +1 -1
- package/build-module/verse/block.json +4 -0
- package/build-module/video/block.json +7 -1
- package/build-module/video/edit.mjs +10 -2
- package/build-module/video/edit.mjs.map +2 -2
- package/build-style/avatar/editor-rtl.css +4 -0
- package/build-style/avatar/editor.css +4 -0
- package/build-style/comments-pagination/style-rtl.css +3 -0
- package/build-style/comments-pagination/style.css +3 -0
- package/build-style/common-rtl.css +32 -1
- package/build-style/common.css +35 -2
- package/build-style/editor-rtl.css +11 -4
- package/build-style/editor.css +11 -4
- package/build-style/embed/style-rtl.css +4 -1
- package/build-style/embed/style.css +4 -1
- package/build-style/gallery/editor-rtl.css +1 -3
- package/build-style/gallery/editor.css +1 -3
- package/build-style/image/style-rtl.css +11 -2
- package/build-style/image/style.css +11 -2
- package/build-style/media-text/style-rtl.css +4 -1
- package/build-style/media-text/style.css +4 -1
- package/build-style/query-pagination/style-rtl.css +3 -0
- package/build-style/query-pagination/style.css +3 -0
- package/build-style/style-rtl.css +70 -9
- package/build-style/style.css +73 -10
- package/build-style/table/editor-rtl.css +6 -1
- package/build-style/table/editor.css +6 -1
- package/build-style/table/style-rtl.css +4 -2
- package/build-style/table/style.css +4 -2
- package/build-style/tag-cloud/style-rtl.css +1 -1
- package/build-style/tag-cloud/style.css +1 -1
- package/build-style/verse/style-rtl.css +8 -1
- package/build-style/verse/style.css +8 -1
- package/build-types/gallery/order-controls.d.ts +58 -0
- package/build-types/gallery/order-controls.d.ts.map +1 -0
- package/build-types/gallery/order-options.d.ts +67 -0
- package/build-types/gallery/order-options.d.ts.map +1 -0
- package/package.json +44 -41
- package/src/accordion-heading/README.md +1 -0
- package/src/accordion-heading/block.json +1 -0
- package/src/archives/README.md +2 -0
- package/src/archives/block.json +3 -0
- package/src/audio/edit.jsx +2 -1
- package/src/avatar/README.md +2 -0
- package/src/avatar/block.json +4 -0
- package/src/avatar/edit.jsx +48 -2
- package/src/avatar/editor.scss +4 -0
- package/src/avatar/index.php +5 -3
- package/src/breadcrumbs/index.php +1 -1
- package/src/button/README.md +4 -0
- package/src/button/block.json +6 -0
- package/src/button/edit.jsx +47 -52
- package/src/button/index.php +47 -0
- package/src/buttons/README.md +4 -0
- package/src/buttons/block.json +6 -1
- package/src/code/README.md +3 -0
- package/src/code/block.json +4 -0
- package/src/column/edit.jsx +6 -0
- package/src/columns/README.md +3 -0
- package/src/columns/block.json +4 -0
- package/src/columns/edit.jsx +1 -131
- package/src/comments/edit/placeholder.jsx +5 -1
- package/src/comments-pagination/README.md +4 -0
- package/src/comments-pagination/block.json +11 -0
- package/src/comments-pagination/style.scss +3 -0
- package/src/common.scss +38 -0
- package/src/cover/README.md +1 -0
- package/src/cover/block.json +2 -1
- package/src/cover/edit/index.jsx +38 -6
- package/src/cover/edit/inspector-controls.jsx +10 -1
- package/src/cover/embed-video-utils.js +18 -10
- package/src/cover/index.php +44 -15
- package/src/cover/test/edit.browser.test.js +182 -2
- package/src/cover/test/embed-video-utils.test.js +48 -0
- package/src/cover/view.js +22 -0
- package/src/details/README.md +2 -0
- package/src/details/block.json +3 -0
- package/src/embed/README.md +4 -0
- package/src/embed/block.json +6 -1
- package/src/embed/style.scss +7 -1
- package/src/file/README.md +4 -0
- package/src/file/block.json +5 -0
- package/src/footnotes/README.md +3 -0
- package/src/footnotes/block.json +4 -0
- package/src/gallery/README.md +13 -0
- package/src/gallery/block.json +13 -0
- package/src/gallery/dynamic-gallery.jsx +11 -91
- package/src/gallery/edit.jsx +146 -47
- package/src/gallery/editor.scss +5 -9
- package/src/gallery/order-controls.tsx +143 -0
- package/src/gallery/order-images.js +111 -0
- package/src/gallery/order-options.ts +75 -0
- package/src/gallery/test/edit.jsdom.test.js +87 -10
- package/src/gallery/test/order-images.js +162 -0
- package/src/gallery/use-dynamic-gallery.js +1 -9
- package/src/gallery/use-get-media.js +7 -2
- package/src/group/edit.jsx +5 -5
- package/src/heading/README.md +4 -0
- package/src/heading/block.json +5 -0
- package/src/home-link/README.md +6 -0
- package/src/home-link/block.json +12 -0
- package/src/icon/components/custom-inserter/index.jsx +5 -1
- package/src/icon/edit.jsx +68 -7
- package/src/icon/index.php +1 -1
- package/src/image/index.php +3 -4
- package/src/image/style.scss +14 -2
- package/src/image/test/use-open-image-media-editor-modal.jsdom.test.js +122 -60
- package/src/image/use-open-image-media-editor-modal.js +37 -41
- package/src/image/view.js +64 -68
- package/src/latest-comments/README.md +3 -0
- package/src/latest-comments/block.json +10 -0
- package/src/latest-posts/README.md +3 -0
- package/src/latest-posts/block.json +4 -0
- package/src/list/README.md +6 -0
- package/src/list/block.json +12 -1
- package/src/list-item/README.md +6 -0
- package/src/list-item/block.json +8 -1
- package/src/list-item/index.js +5 -0
- package/src/loginout/README.md +3 -0
- package/src/loginout/block.json +4 -0
- package/src/math/README.md +3 -0
- package/src/math/block.json +4 -0
- package/src/media-text/README.md +17 -0
- package/src/media-text/block.json +18 -0
- package/src/media-text/style.scss +5 -1
- package/src/navigation/test/use-navigation-menu.jsdom.test.js +1 -1
- package/src/navigation-link/README.md +1 -1
- package/src/navigation-link/link-ui/index.jsx +60 -27
- package/src/navigation-link/link-ui/test/get-suggestions-query.jsdom.test.js +67 -0
- package/src/navigation-link/shared/index.js +4 -0
- package/src/navigation-link/shared/test/use-block-suggestions.jsdom.test.js +158 -0
- package/src/navigation-link/shared/test/use-entity-binding.jsdom.test.js +1 -7
- package/src/navigation-link/shared/use-block-suggestions.js +192 -0
- package/src/page-list/README.md +3 -0
- package/src/page-list/block.json +4 -0
- package/src/paragraph/README.md +1 -0
- package/src/paragraph/block.json +1 -0
- package/src/playlist/test/edit-component.jsdom.test.jsx +11 -11
- package/src/playlist-track/test/edit.jsdom.test.jsx +3 -3
- package/src/post-author-biography/README.md +1 -0
- package/src/post-author-biography/block.json +1 -0
- package/src/post-comments-form/README.md +3 -0
- package/src/post-comments-form/block.json +5 -0
- package/src/post-content/README.md +1 -0
- package/src/post-content/block.json +2 -1
- package/src/post-excerpt/README.md +3 -0
- package/src/post-excerpt/block.json +4 -0
- package/src/post-featured-image/block.json +1 -0
- package/src/post-featured-image/edit.jsx +2 -2
- package/src/post-terms/README.md +3 -0
- package/src/post-terms/block.json +4 -0
- package/src/post-time-to-read/README.md +3 -0
- package/src/post-time-to-read/block.json +4 -0
- package/src/post-title/README.md +3 -0
- package/src/post-title/block.json +4 -0
- package/src/preformatted/README.md +3 -0
- package/src/preformatted/block.json +4 -0
- package/src/pullquote/README.md +1 -0
- package/src/pullquote/block.json +2 -1
- package/src/query-no-results/README.md +3 -0
- package/src/query-no-results/block.json +4 -0
- package/src/query-pagination/README.md +4 -0
- package/src/query-pagination/block.json +17 -0
- package/src/query-pagination/style.scss +3 -0
- package/src/query-total/README.md +3 -0
- package/src/query-total/block.json +4 -0
- package/src/quote/README.md +2 -0
- package/src/quote/block.json +2 -0
- package/src/read-more/README.md +3 -0
- package/src/read-more/block.json +5 -0
- package/src/rss/README.md +3 -0
- package/src/rss/block.json +4 -0
- package/src/search/README.md +1 -0
- package/src/search/block.json +2 -1
- package/src/site-tagline/README.md +3 -0
- package/src/site-tagline/block.json +4 -0
- package/src/site-title/README.md +3 -0
- package/src/site-title/block.json +4 -0
- package/src/social-links/README.md +1 -0
- package/src/social-links/block.json +1 -0
- package/src/tab-list/README.md +2 -0
- package/src/tab-list/block.json +4 -0
- package/src/tab-list/edit.jsx +3 -0
- package/src/tab-list/save.jsx +3 -0
- package/src/tab-panels/README.md +2 -0
- package/src/tab-panels/block.json +3 -0
- package/src/table/editor.scss +8 -2
- package/src/table/style.scss +4 -4
- package/src/tabs/README.md +2 -0
- package/src/tabs/block.json +3 -0
- package/src/tag-cloud/style.scss +1 -1
- package/src/template-part/index.php +16 -3
- package/src/term-count/README.md +4 -0
- package/src/term-count/block.json +5 -0
- package/src/term-description/README.md +3 -0
- package/src/term-description/block.json +4 -0
- package/src/term-name/README.md +4 -0
- package/src/term-name/block.json +6 -1
- package/src/term-template/README.md +3 -0
- package/src/term-template/block.json +4 -0
- package/src/utils/test/waveform-player-auto-init.jsdom.test.js +25 -0
- package/src/utils/test/waveform-player-dependency.jsdom.test.js +7 -60
- package/src/utils/test/waveform-utils.browser.test.js +3 -15
- package/src/utils/waveform-utils.js +1 -1
- package/src/verse/README.md +4 -0
- package/src/verse/block.json +4 -0
- package/src/verse/style.scss +11 -2
- package/src/video/README.md +4 -0
- package/src/video/block.json +7 -1
- package/src/video/edit.jsx +13 -2
- package/build/columns/utils.cjs +0 -112
- package/build/columns/utils.cjs.map +0 -7
- package/build-module/columns/utils.mjs +0 -78
- package/build-module/columns/utils.mjs.map +0 -7
- package/src/columns/test/utils.js +0 -331
- package/src/columns/utils.js +0 -176
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/image/use-open-image-media-editor-modal.js"],
|
|
4
|
-
"sourcesContent": ["import { store as coreStore } from '@wordpress/core-data';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { unlock } from '../lock-unlock';\nimport {\n\tDEFAULT_MEDIA_SIZE_SLUG,\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_MEDIA,\n} from './constants';\n\nfunction normalizeImageBlockCaption( caption ) {\n\tif ( typeof caption !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tconst textContent = stripHTML( caption ).trim();\n\n\tif ( ! textContent ) {\n\t\treturn '';\n\t}\n\n\treturn caption.replace( /\\n/g, '<br>' );\n}\n\nfunction getAttachmentCaption( attachment ) {\n\tconst caption = attachment?.caption;\n\n\tif ( typeof caption === 'string' ) {\n\t\treturn normalizeImageBlockCaption( caption );\n\t}\n\n\tif (\n\t\tcaption &&\n\t\ttypeof caption === 'object' &&\n\t\tObject.hasOwn( caption, 'raw' )\n\t) {\n\t\treturn normalizeImageBlockCaption( caption.raw );\n\t}\n\n\treturn undefined;\n}\n\nexport function getImageBlockMetadataFromAttachment( attachment ) {\n\treturn {\n\t\talt:\n\t\t\ttypeof attachment?.alt_text === 'string'\n\t\t\t\t? attachment.alt_text\n\t\t\t\t: attachment?.alt || '',\n\t\tcaption: getAttachmentCaption( attachment ),\n\t};\n}\n\nfunction normalizeMetadataAttribute( value ) {\n\treturn value || '';\n}\n\nexport function getSyncedImageBlockAttributes(\n\tcurrentAttributes,\n\toriginalAttachment,\n\tupdatedAttachment\n) {\n\tif ( ! originalAttachment || ! updatedAttachment ) {\n\t\treturn {};\n\t}\n\n\tconst originalMetadata =\n\t\tgetImageBlockMetadataFromAttachment( originalAttachment );\n\tconst updatedMetadata =\n\t\tgetImageBlockMetadataFromAttachment( updatedAttachment );\n\tconst syncedAttributes = {};\n\n\tconst normalizedCurrentAlt = normalizeMetadataAttribute(\n\t\tcurrentAttributes.alt\n\t);\n\tif (\n\t\toriginalMetadata.alt !== updatedMetadata.alt &&\n\t\t( normalizedCurrentAlt === originalMetadata.alt ||\n\t\t\t! normalizedCurrentAlt )\n\t) {\n\t\tsyncedAttributes.alt = updatedMetadata.alt;\n\t}\n\n\tconst normalizedCurrentCaption = normalizeMetadataAttribute(\n\t\tcurrentAttributes.caption\n\t);\n\tif (\n\t\toriginalMetadata.caption !== undefined &&\n\t\tupdatedMetadata.caption !== undefined &&\n\t\toriginalMetadata.caption !== updatedMetadata.caption &&\n\t\t( normalizedCurrentCaption === originalMetadata.caption ||\n\t\t\t! normalizedCurrentCaption )\n\t) {\n\t\tsyncedAttributes.caption = updatedMetadata.caption || undefined;\n\t}\n\n\treturn syncedAttributes;\n}\n\n/**\n * Resolves the attributes needed to keep the selected image size on a new\n * attachment.\n *\n * WordPress skips generating a sub-size larger than the file itself, so the\n * selected size may not exist on the edited image; fall back to full when it\n * doesn't.\n *\n * @param {string|undefined} sizeSlug The block's currently selected size.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentSizeAttributes( sizeSlug, attachment ) {\n\tconst sizes = attachment.media_details?.sizes;\n\n\tif ( ! sizeSlug || sizeSlug === DEFAULT_MEDIA_SIZE_SLUG || ! sizes ) {\n\t\treturn undefined;\n\t}\n\n\tconst sizeUrl = sizes[ sizeSlug ]?.source_url;\n\n\tif ( sizeUrl ) {\n\t\treturn { url: sizeUrl };\n\t}\n\n\tconst fullUrl = attachment.source_url ?? sizes.full?.source_url;\n\n\treturn fullUrl\n\t\t? { url: fullUrl, sizeSlug: DEFAULT_MEDIA_SIZE_SLUG }\n\t\t: undefined;\n}\n\n/**\n * Resolves the link attributes needed to keep the block's link pointing at the\n * new attachment.\n *\n * Only the destinations derived from the attachment follow the edited image. A\n * `custom` link is the user's own URL and a `none` link has nothing to point\n * at, so both are left alone. When the record doesn't carry the field, the\n * existing link is kept rather than cleared.\n *\n * @param {string|undefined} linkDestination The block's link destination.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentLinkAttributes( linkDestination, attachment ) {\n\t// Media file links point at the full-size file, independently of the size\n\t// the block renders.\n\tif ( linkDestination === LINK_DESTINATION_MEDIA ) {\n\t\treturn attachment.source_url\n\t\t\t? { href: attachment.source_url }\n\t\t\t: undefined;\n\t}\n\n\tif ( linkDestination === LINK_DESTINATION_ATTACHMENT ) {\n\t\treturn attachment.link ? { href: attachment.link } : undefined;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Resolves the block attributes that are derived from the attachment, for an\n * edit that saved to a different one.\n *\n * Editing media (crop, rotate, flip) creates a new attachment with its own\n * generated sub-sizes and its own attachment page, and the media editor\n * reports the full-size file. Without re-deriving these, the size control\n * keeps reporting e.g. \"Medium\" while the block renders the full-size image,\n * and a \"Media file\" or \"Attachment page\" link still points at the image as it\n * was before the edit. Everything else the user set on the block — dimensions,\n * lightbox, title, custom links — is left untouched.\n *\n * @param {Object} blockAttributes The block's current attributes.\n * @param {Object|undefined} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, or undefined when the\n * attachment record isn't known yet.\n */\nexport function getNewAttachmentImageBlockAttributes(\n\tblockAttributes,\n\tattachment\n) {\n\tif ( ! attachment ) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\t...getNewAttachmentSizeAttributes(\n\t\t\tblockAttributes.sizeSlug,\n\t\t\tattachment\n\t\t),\n\t\t...getNewAttachmentLinkAttributes(\n\t\t\tblockAttributes.linkDestination,\n\t\t\tattachment\n\t\t),\n\t};\n}\n\nconst { openMediaEditorModalKey } = unlock( blockEditorPrivateApis );\n\nfunction getAttachmentFallbackForEmptyBlockMetadata( { alt, caption } ) {\n\tconst attachment = {};\n\n\tif ( ! alt ) {\n\t\tattachment.alt_text = '';\n\t}\n\n\tif ( ! caption?.toString() ) {\n\t\tattachment.caption = '';\n\t}\n\n\treturn Object.keys( attachment ).length ? attachment : undefined;\n}\n\nfunction hasKnownAttachmentMetadata( attachment ) {\n\tif ( ! attachment ) {\n\t\treturn false;\n\t}\n\n\tconst hasKnownAlt =\n\t\ttypeof attachment.alt_text === 'string' ||\n\t\ttypeof attachment.alt === 'string';\n\tconst hasKnownCaption =\n\t\tgetImageBlockMetadataFromAttachment( attachment ).caption !== undefined;\n\n\treturn hasKnownAlt && hasKnownCaption;\n}\n\nexport function useOpenImageMediaEditorModal( {\n\tattributes,\n\tsetAttributes,\n\tonClose,\n\tonUrlChange,\n} ) {\n\t// Keep this hook private to the Image block and pass the block attributes\n\t// object so the callsite stays compact. Destructure only the attributes\n\t// the update needs to read — those synced from the attachment's metadata,\n\t// and those derived from which attachment the block points at; add more\n\t// here if the sync policy grows.\n\tconst { id, url, alt, caption, sizeSlug, linkDestination } = attributes;\n\tconst registry = useRegistry();\n\tconst openMediaEditorModal = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()[ openMediaEditorModalKey ],\n\t\t[]\n\t);\n\t// Track the block's current attachment and metadata in a ref so\n\t// handleMediaUpdate can read the latest values without being listed as\n\t// dependencies (which would recreate the callback and re-register the\n\t// onUpdate handler on every block change while the modal is open).\n\tconst blockAttributesRef = useRef( {\n\t\tid,\n\t\turl,\n\t\talt,\n\t\tcaption: caption?.toString(),\n\t\tsizeSlug,\n\t\tlinkDestination,\n\t} );\n\t// Snapshot of the attachment's metadata taken just before the modal opens,\n\t// used as the baseline for detecting what changed during the editing session.\n\tconst mediaEditorMetadataBaselineRef = useRef();\n\t// Incremented on every handleMediaUpdate call; stale async continuations\n\t// check against this to bail out if a newer update has since started.\n\tconst mediaEditorMetadataSyncRequestRef = useRef( 0 );\n\t// The alt text and caption a save overwrote on the block, and the\n\t// attachment it moved the block away from. The media editor's Undo moves\n\t// the block back but reports only that attachment's id and url, so this is\n\t// what lets the update restore the block's own metadata too.\n\tconst mediaEditorUndoMetadataRef = useRef();\n\n\tuseEffect( () => {\n\t\tblockAttributesRef.current = {\n\t\t\tid,\n\t\t\turl,\n\t\t\talt,\n\t\t\tcaption: caption?.toString(),\n\t\t\tsizeSlug,\n\t\t\tlinkDestination,\n\t\t};\n\t}, [ alt, caption, id, linkDestination, sizeSlug, url ] );\n\n\t// Reads the cached attachment record. The `attachment` postType entity\n\t// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`\n\t// returns the edit-context record — carrying `caption` as `{ raw }` and a\n\t// usable `alt_text` — without us specifying a context. It is resolver-\n\t// backed, so on a cold cache this also kicks off the fetch and returns a\n\t// falsy value synchronously; that resolution shares its cache key with the\n\t// `resolveAttachmentRecord` call below (both keyed on the no-query\n\t// `getEntityRecord`), so the two dedupe into a single request.\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) =>\n\t\t\tregistry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t),\n\t\t[ registry ]\n\t);\n\n\tconst resolveAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\tconst resolveSelect = registry.resolveSelect( coreStore );\n\n\t\t\ttry {\n\t\t\t\treturn await resolveSelect.getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\t[ registry ]\n\t);\n\n\tconst resolveFreshAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\t// Invalidate the cached resolution so resolveAttachmentRecord\n\t\t\t// re-fetches the server state that reflects the media editor's\n\t\t\t// saved changes.\n\t\t\tconst { invalidateResolution } = registry.dispatch( coreStore );\n\n\t\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t] );\n\t\t\treturn resolveAttachmentRecord( attachmentId );\n\t\t},\n\t\t[ registry, resolveAttachmentRecord ]\n\t);\n\n\tconst handleMediaUpdate = useCallback(\n\t\tasync ( { id: newId, url: newUrl } ) => {\n\t\t\tif ( typeof newId !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture and clear the baseline so a rapid second save doesn't\n\t\t\t// reuse a stale snapshot.\n\t\t\tconst originalAttachment = mediaEditorMetadataBaselineRef.current;\n\t\t\tmediaEditorMetadataBaselineRef.current = undefined;\n\t\t\t// Likewise the metadata the last save overwrote: only the update\n\t\t\t// straight after that save, its Undo, may restore it.\n\t\t\tconst undoMetadata = mediaEditorUndoMetadataRef.current;\n\t\t\tmediaEditorUndoMetadataRef.current = undefined;\n\t\t\tconst syncRequest = ++mediaEditorMetadataSyncRequestRef.current;\n\t\t\tconst nextAttributes = {};\n\n\t\t\tconst currentBlockAttributes = blockAttributesRef.current;\n\t\t\tconst isNewAttachment = newId !== currentBlockAttributes.id;\n\n\t\t\tif ( isNewAttachment ) {\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? currentBlockAttributes.url;\n\t\t\t\tif ( nextAttributes.url !== currentBlockAttributes.url ) {\n\t\t\t\t\t// The block is about to point at a freshly generated file\n\t\t\t\t\t// the browser hasn't loaded yet; let the caller show a\n\t\t\t\t\t// loading state until its <img> fires load/error. Raising\n\t\t\t\t\t// it here, before anything is awaited, keeps the rest of\n\t\t\t\t\t// this update behind that loading state: the attributes\n\t\t\t\t\t// land in a single `setAttributes` at the end, so the\n\t\t\t\t\t// image never renders against half-updated settings.\n\t\t\t\t\tonUrlChange?.( nextAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\tid: nextAttributes.id,\n\t\t\t\t\turl: nextAttributes.url,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( originalAttachment || isNewAttachment ) {\n\t\t\t\t// Fetch fresh server state so this reflects what the media\n\t\t\t\t// editor actually saved, not a potentially stale cache.\n\t\t\t\tconst resolvedAttachment =\n\t\t\t\t\tawait resolveFreshAttachmentRecord( newId );\n\n\t\t\t\t// A newer update started while we were awaiting; discard\n\t\t\t\t// this one.\n\t\t\t\tif (\n\t\t\t\t\tsyncRequest !== mediaEditorMetadataSyncRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// A failed refetch returns nothing, which would leave the\n\t\t\t\t// block pointing at the new file while its size and link\n\t\t\t\t// still describe the old one. The record the media editor\n\t\t\t\t// received when it saved is already in the store, so fall\n\t\t\t\t// back to that rather than half-updating the block.\n\t\t\t\tconst attachmentRecord =\n\t\t\t\t\tresolvedAttachment ?? getCachedAttachmentRecord( newId );\n\n\t\t\t\tconst latestBlockAttributes = blockAttributesRef.current;\n\n\t\t\t\t// Sync alt text and caption back to the block only when\n\t\t\t\t// they were changed in the media editor. Fields the user\n\t\t\t\t// has independently customised on the block (i.e. values\n\t\t\t\t// that don't match the pre-session attachment metadata)\n\t\t\t\t// are left untouched. Without a baseline there's no way to\n\t\t\t\t// tell the two apart, so nothing is synced.\n\t\t\t\tif ( originalAttachment ) {\n\t\t\t\t\tconst resolvedMetadataAttributes =\n\t\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\toriginalAttachment,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( Object.keys( resolvedMetadataAttributes ).length ) {\n\t\t\t\t\t\tObject.assign(\n\t\t\t\t\t\t\tnextAttributes,\n\t\t\t\t\t\t\tresolvedMetadataAttributes\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Only a save to a new attachment offers an Undo, so\n\t\t\t\t\t\t// only then keep the values being overwritten.\n\t\t\t\t\t\tif ( isNewAttachment ) {\n\t\t\t\t\t\t\tmediaEditorUndoMetadataRef.current = {\n\t\t\t\t\t\t\t\tid: currentBlockAttributes.id,\n\t\t\t\t\t\t\t\tattributes: Object.fromEntries(\n\t\t\t\t\t\t\t\t\tObject.keys(\n\t\t\t\t\t\t\t\t\t\tresolvedMetadataAttributes\n\t\t\t\t\t\t\t\t\t).map( ( key ) => [\n\t\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t\tlatestBlockAttributes[ key ],\n\t\t\t\t\t\t\t\t\t] )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( isNewAttachment ) {\n\t\t\t\t\tconst derivedAttributes =\n\t\t\t\t\t\tgetNewAttachmentImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( derivedAttributes ) {\n\t\t\t\t\t\tObject.assign( nextAttributes, derivedAttributes );\n\n\t\t\t\t\t\t// The URL announced before the resolve was the\n\t\t\t\t\t\t// full-size file the media editor reported, and\n\t\t\t\t\t\t// deriving the selected size can change it.\n\t\t\t\t\t\t// Re-announce so the pending swap names the file\n\t\t\t\t\t\t// that actually lands: an update that is undone or\n\t\t\t\t\t\t// superseded never changes the <img> src, and the\n\t\t\t\t\t\t// block then clears its loading state by matching\n\t\t\t\t\t\t// the pending URL against the rendered one.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tderivedAttributes.url &&\n\t\t\t\t\t\t\tderivedAttributes.url !== latestBlockAttributes.url\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tonUrlChange?.( derivedAttributes.url );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// The media editor's Undo: the block is going back to the\n\t\t\t// attachment the last save moved it away from, so put back the\n\t\t\t// alt text and caption that save overwrote.\n\t\t\tif ( undoMetadata?.id === newId ) {\n\t\t\t\tObject.assign( nextAttributes, undoMetadata.attributes );\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...nextAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tgetCachedAttachmentRecord,\n\t\t\tonUrlChange,\n\t\t\tresolveFreshAttachmentRecord,\n\t\t\tsetAttributes,\n\t\t]\n\t);\n\n\tconst openImageMediaEditorModal = useCallback( async () => {\n\t\tif ( ! id || ! openMediaEditorModal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// A new session starts. Drop any metadata kept for the last save's\n\t\t// Undo, so a save in this session that returns the block to that same\n\t\t// attachment isn't mistaken for it.\n\t\tmediaEditorUndoMetadataRef.current = undefined;\n\n\t\t// Snapshot the attachment's current metadata before the user makes\n\t\t// any changes so handleMediaUpdate can compare against it later. Use\n\t\t// the cached record when it's already present; only resolve when\n\t\t// nothing is cached yet, then fall back to a minimal object derived\n\t\t// from the block's own attributes.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockAttributesRef.current\n\t\t\t);\n\t\tconst resolvedAttachmentRecord = hasKnownAttachmentMetadata(\n\t\t\tcachedAttachmentRecord\n\t\t)\n\t\t\t? undefined\n\t\t\t: await resolveAttachmentRecord( id );\n\n\t\tmediaEditorMetadataBaselineRef.current =\n\t\t\tresolvedAttachmentRecord ||\n\t\t\t( hasKnownAttachmentMetadata( cachedAttachmentRecord )\n\t\t\t\t? cachedAttachmentRecord\n\t\t\t\t: fallbackAttachmentRecord ) ||\n\t\t\tcachedAttachmentRecord;\n\n\t\topenMediaEditorModal( {\n\t\t\tid,\n\t\t\tonUpdate: handleMediaUpdate,\n\t\t\tonClose,\n\t\t} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\tonClose,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmC;AACnC,0BAGO;AACP,iBAAiD;AACjD,kBAAuC;AACvC,qBAA+C;AAC/C,yBAAuB;AACvB,uBAIO;AAEP,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,kBAAc,WAAAA,qBAAW,OAAQ,EAAE,KAAK;AAE9C,MAAK,CAAE,aAAc;AACpB,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ,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A,EACA;AACD,GAAI;AAMH,QAAM,EAAE,IAAI,KAAK,KAAK,SAAS,UAAU,
|
|
4
|
+
"sourcesContent": ["import { store as coreStore } from '@wordpress/core-data';\nimport {\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { __unstableStripHTML as stripHTML } from '@wordpress/dom';\nimport { useRegistry, useSelect } from '@wordpress/data';\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\nimport { unlock } from '../lock-unlock';\nimport {\n\tDEFAULT_MEDIA_SIZE_SLUG,\n\tLINK_DESTINATION_ATTACHMENT,\n\tLINK_DESTINATION_MEDIA,\n} from './constants';\n\nfunction normalizeImageBlockCaption( caption ) {\n\tif ( typeof caption !== 'string' ) {\n\t\treturn '';\n\t}\n\n\tconst textContent = stripHTML( caption ).trim();\n\n\tif ( ! textContent ) {\n\t\treturn '';\n\t}\n\n\treturn caption.replace( /\\n/g, '<br>' );\n}\n\nfunction getAttachmentCaption( attachment ) {\n\tconst caption = attachment?.caption;\n\n\tif ( typeof caption === 'string' ) {\n\t\treturn normalizeImageBlockCaption( caption );\n\t}\n\n\tif (\n\t\tcaption &&\n\t\ttypeof caption === 'object' &&\n\t\tObject.hasOwn( caption, 'raw' )\n\t) {\n\t\treturn normalizeImageBlockCaption( caption.raw );\n\t}\n\n\treturn undefined;\n}\n\nexport function getImageBlockMetadataFromAttachment( attachment ) {\n\treturn {\n\t\talt:\n\t\t\ttypeof attachment?.alt_text === 'string'\n\t\t\t\t? attachment.alt_text\n\t\t\t\t: attachment?.alt || '',\n\t\tcaption: getAttachmentCaption( attachment ),\n\t};\n}\n\nfunction normalizeMetadataAttribute( value ) {\n\treturn value || '';\n}\n\nexport function getSyncedImageBlockAttributes(\n\tcurrentAttributes,\n\toriginalAttachment,\n\tupdatedAttachment\n) {\n\tif ( ! originalAttachment || ! updatedAttachment ) {\n\t\treturn {};\n\t}\n\n\tconst originalMetadata =\n\t\tgetImageBlockMetadataFromAttachment( originalAttachment );\n\tconst updatedMetadata =\n\t\tgetImageBlockMetadataFromAttachment( updatedAttachment );\n\tconst syncedAttributes = {};\n\n\tconst normalizedCurrentAlt = normalizeMetadataAttribute(\n\t\tcurrentAttributes.alt\n\t);\n\tif (\n\t\toriginalMetadata.alt !== updatedMetadata.alt &&\n\t\t( normalizedCurrentAlt === originalMetadata.alt ||\n\t\t\t! normalizedCurrentAlt )\n\t) {\n\t\tsyncedAttributes.alt = updatedMetadata.alt;\n\t}\n\n\tconst normalizedCurrentCaption = normalizeMetadataAttribute(\n\t\tcurrentAttributes.caption\n\t);\n\tif (\n\t\toriginalMetadata.caption !== undefined &&\n\t\tupdatedMetadata.caption !== undefined &&\n\t\toriginalMetadata.caption !== updatedMetadata.caption &&\n\t\t( normalizedCurrentCaption === originalMetadata.caption ||\n\t\t\t! normalizedCurrentCaption )\n\t) {\n\t\tsyncedAttributes.caption = updatedMetadata.caption || undefined;\n\t}\n\n\treturn syncedAttributes;\n}\n\n/**\n * Resolves the attributes needed to keep the selected image size on a new\n * attachment.\n *\n * WordPress skips generating a sub-size larger than the file itself, so the\n * selected size may not exist on the edited image; fall back to full when it\n * doesn't.\n *\n * @param {string|undefined} sizeSlug The block's currently selected size.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentSizeAttributes( sizeSlug, attachment ) {\n\tconst sizes = attachment.media_details?.sizes;\n\n\tif ( ! sizeSlug || sizeSlug === DEFAULT_MEDIA_SIZE_SLUG || ! sizes ) {\n\t\treturn undefined;\n\t}\n\n\tconst sizeUrl = sizes[ sizeSlug ]?.source_url;\n\n\tif ( sizeUrl ) {\n\t\treturn { url: sizeUrl };\n\t}\n\n\tconst fullUrl = attachment.source_url ?? sizes.full?.source_url;\n\n\treturn fullUrl\n\t\t? { url: fullUrl, sizeSlug: DEFAULT_MEDIA_SIZE_SLUG }\n\t\t: undefined;\n}\n\n/**\n * Resolves the link attributes needed to keep the block's link pointing at the\n * new attachment.\n *\n * Only the destinations derived from the attachment follow the edited image. A\n * `custom` link is the user's own URL and a `none` link has nothing to point\n * at, so both are left alone. When the record doesn't carry the field, the\n * existing link is kept rather than cleared.\n *\n * @param {string|undefined} linkDestination The block's link destination.\n * @param {Object} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, if any.\n */\nfunction getNewAttachmentLinkAttributes( linkDestination, attachment ) {\n\t// Media file links point at the full-size file, independently of the size\n\t// the block renders.\n\tif ( linkDestination === LINK_DESTINATION_MEDIA ) {\n\t\treturn attachment.source_url\n\t\t\t? { href: attachment.source_url }\n\t\t\t: undefined;\n\t}\n\n\tif ( linkDestination === LINK_DESTINATION_ATTACHMENT ) {\n\t\treturn attachment.link ? { href: attachment.link } : undefined;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Resolves the block attributes that are derived from the attachment, for an\n * edit that saved to a different one.\n *\n * Editing media (crop, rotate, flip) creates a new attachment with its own\n * generated sub-sizes and its own attachment page, and the media editor\n * reports the full-size file. Without re-deriving these, the size control\n * keeps reporting e.g. \"Medium\" while the block renders the full-size image,\n * and a \"Media file\" or \"Attachment page\" link still points at the image as it\n * was before the edit. Everything else the user set on the block — dimensions,\n * lightbox, title, custom links — is left untouched.\n *\n * @param {Object} blockAttributes The block's current attributes.\n * @param {Object|undefined} attachment The new attachment record.\n *\n * @return {Object|undefined} Attributes to apply, or undefined when the\n * attachment record isn't known yet.\n */\nexport function getNewAttachmentImageBlockAttributes(\n\tblockAttributes,\n\tattachment\n) {\n\tif ( ! attachment ) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\t...getNewAttachmentSizeAttributes(\n\t\t\tblockAttributes.sizeSlug,\n\t\t\tattachment\n\t\t),\n\t\t...getNewAttachmentLinkAttributes(\n\t\t\tblockAttributes.linkDestination,\n\t\t\tattachment\n\t\t),\n\t};\n}\n\nconst { openMediaEditorModalKey } = unlock( blockEditorPrivateApis );\n\nfunction getAttachmentFallbackForEmptyBlockMetadata( { alt, caption } ) {\n\tconst attachment = {};\n\n\tif ( ! alt ) {\n\t\tattachment.alt_text = '';\n\t}\n\n\tif ( ! caption?.toString() ) {\n\t\tattachment.caption = '';\n\t}\n\n\treturn Object.keys( attachment ).length ? attachment : undefined;\n}\n\nfunction hasKnownAttachmentMetadata( attachment ) {\n\tif ( ! attachment ) {\n\t\treturn false;\n\t}\n\n\tconst hasKnownAlt =\n\t\ttypeof attachment.alt_text === 'string' ||\n\t\ttypeof attachment.alt === 'string';\n\tconst hasKnownCaption =\n\t\tgetImageBlockMetadataFromAttachment( attachment ).caption !== undefined;\n\n\treturn hasKnownAlt && hasKnownCaption;\n}\n\nexport function useOpenImageMediaEditorModal( {\n\tattributes,\n\tsetAttributes,\n\tonClose,\n\tonUrlChange,\n} ) {\n\t// Keep this hook private to the Image block and pass the block attributes\n\t// object so the callsite stays compact. Destructure only the attributes\n\t// the update needs to read — those synced from the attachment's metadata,\n\t// and those derived from which attachment the block points at; add more\n\t// here if the sync policy grows.\n\tconst { id, url, alt, caption, sizeSlug, linkDestination, href } =\n\t\tattributes;\n\tconst registry = useRegistry();\n\tconst openMediaEditorModal = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings()[ openMediaEditorModalKey ],\n\t\t[]\n\t);\n\t// Track the block's current attachment and metadata in a ref so\n\t// handleMediaUpdate can read the latest values without being listed as\n\t// dependencies (which would recreate the callback and re-register the\n\t// onUpdate handler on every block change while the modal is open).\n\tconst blockAttributesRef = useRef( {\n\t\tid,\n\t\turl,\n\t\talt,\n\t\tcaption: caption?.toString(),\n\t\tsizeSlug,\n\t\tlinkDestination,\n\t\thref,\n\t} );\n\t// Snapshot of the attachment's metadata taken just before the modal opens,\n\t// used as the baseline for detecting what changed during the editing session.\n\tconst mediaEditorMetadataBaselineRef = useRef();\n\t// Incremented on every handleMediaUpdate call; stale async continuations\n\t// check against this to bail out if a newer update has since started.\n\tconst mediaEditorMetadataSyncRequestRef = useRef( 0 );\n\n\tuseEffect( () => {\n\t\tblockAttributesRef.current = {\n\t\t\tid,\n\t\t\turl,\n\t\t\talt,\n\t\t\tcaption: caption?.toString(),\n\t\t\tsizeSlug,\n\t\t\tlinkDestination,\n\t\t\thref,\n\t\t};\n\t}, [ alt, caption, href, id, linkDestination, sizeSlug, url ] );\n\n\t// Reads the cached attachment record. The `attachment` postType entity\n\t// fetches with `context: 'edit'` by default, so `getEditedEntityRecord`\n\t// returns the edit-context record — carrying `caption` as `{ raw }` and a\n\t// usable `alt_text` — without us specifying a context. It is resolver-\n\t// backed, so on a cold cache this also kicks off the fetch and returns a\n\t// falsy value synchronously; that resolution shares its cache key with the\n\t// `resolveAttachmentRecord` call below (both keyed on the no-query\n\t// `getEntityRecord`), so the two dedupe into a single request.\n\tconst getCachedAttachmentRecord = useCallback(\n\t\t( attachmentId ) =>\n\t\t\tregistry\n\t\t\t\t.select( coreStore )\n\t\t\t\t.getEditedEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t),\n\t\t[ registry ]\n\t);\n\n\tconst resolveAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\tconst resolveSelect = registry.resolveSelect( coreStore );\n\n\t\t\ttry {\n\t\t\t\treturn await resolveSelect.getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'attachment',\n\t\t\t\t\tattachmentId\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t},\n\t\t[ registry ]\n\t);\n\n\tconst resolveFreshAttachmentRecord = useCallback(\n\t\tasync ( attachmentId ) => {\n\t\t\t// Invalidate the cached resolution so resolveAttachmentRecord\n\t\t\t// re-fetches the server state that reflects the media editor's\n\t\t\t// saved changes.\n\t\t\tconst { invalidateResolution } = registry.dispatch( coreStore );\n\n\t\t\tinvalidateResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\tattachmentId,\n\t\t\t] );\n\t\t\treturn resolveAttachmentRecord( attachmentId );\n\t\t},\n\t\t[ registry, resolveAttachmentRecord ]\n\t);\n\n\tconst handleMediaUpdate = useCallback(\n\t\tasync ( { id: newId, url: newUrl }, undoState ) => {\n\t\t\tif ( typeof newId !== 'number' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Capture and clear the baseline so a rapid second save doesn't\n\t\t\t// reuse a stale snapshot.\n\t\t\tconst originalAttachment = mediaEditorMetadataBaselineRef.current;\n\t\t\tmediaEditorMetadataBaselineRef.current = undefined;\n\t\t\tconst syncRequest = ++mediaEditorMetadataSyncRequestRef.current;\n\t\t\tconst nextAttributes = {};\n\n\t\t\tconst currentBlockAttributes = blockAttributesRef.current;\n\t\t\tconst isNewAttachment = newId !== currentBlockAttributes.id;\n\n\t\t\tif ( isNewAttachment ) {\n\t\t\t\t// Capture the block's selected-size URL, not the attachment's\n\t\t\t\t// full-size URL supplied by the modal's fallback Undo.\n\t\t\t\tundoState.undoAttributes.id = currentBlockAttributes.id;\n\t\t\t\tundoState.undoAttributes.url = currentBlockAttributes.url;\n\t\t\t\tnextAttributes.id = newId;\n\t\t\t\tnextAttributes.url = newUrl ?? currentBlockAttributes.url;\n\t\t\t\tif ( nextAttributes.url !== currentBlockAttributes.url ) {\n\t\t\t\t\t// The block is about to point at a freshly generated file\n\t\t\t\t\t// the browser hasn't loaded yet; let the caller show a\n\t\t\t\t\t// loading state until its <img> fires load/error. Raising\n\t\t\t\t\t// it here, before anything is awaited, keeps the rest of\n\t\t\t\t\t// this update behind that loading state: the attributes\n\t\t\t\t\t// land in a single `setAttributes` at the end, so the\n\t\t\t\t\t// image never renders against half-updated settings.\n\t\t\t\t\tonUrlChange?.( nextAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\tid: nextAttributes.id,\n\t\t\t\t\turl: nextAttributes.url,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( originalAttachment || isNewAttachment ) {\n\t\t\t\t// Fetch fresh server state so this reflects what the media\n\t\t\t\t// editor actually saved, not a potentially stale cache.\n\t\t\t\tconst resolvedAttachment =\n\t\t\t\t\tawait resolveFreshAttachmentRecord( newId );\n\n\t\t\t\t// A newer update started while we were awaiting; discard\n\t\t\t\t// this one.\n\t\t\t\tif (\n\t\t\t\t\tundoState.isUndone ||\n\t\t\t\t\tsyncRequest !== mediaEditorMetadataSyncRequestRef.current\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// A failed refetch returns nothing, which would leave the\n\t\t\t\t// block pointing at the new file while its size and link\n\t\t\t\t// still describe the old one. The record the media editor\n\t\t\t\t// received when it saved is already in the store, so fall\n\t\t\t\t// back to that rather than half-updating the block.\n\t\t\t\tconst attachmentRecord =\n\t\t\t\t\tresolvedAttachment ?? getCachedAttachmentRecord( newId );\n\n\t\t\t\tconst latestBlockAttributes = blockAttributesRef.current;\n\n\t\t\t\t// Sync alt text and caption back to the block only when\n\t\t\t\t// they were changed in the media editor. Fields the user\n\t\t\t\t// has independently customised on the block (i.e. values\n\t\t\t\t// that don't match the pre-session attachment metadata)\n\t\t\t\t// are left untouched. Without a baseline there's no way to\n\t\t\t\t// tell the two apart, so nothing is synced.\n\t\t\t\tif ( originalAttachment ) {\n\t\t\t\t\tconst resolvedMetadataAttributes =\n\t\t\t\t\t\tgetSyncedImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\toriginalAttachment,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( Object.keys( resolvedMetadataAttributes ).length ) {\n\t\t\t\t\t\tObject.assign(\n\t\t\t\t\t\t\tnextAttributes,\n\t\t\t\t\t\t\tresolvedMetadataAttributes\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( isNewAttachment ) {\n\t\t\t\t\tconst derivedAttributes =\n\t\t\t\t\t\tgetNewAttachmentImageBlockAttributes(\n\t\t\t\t\t\t\tlatestBlockAttributes,\n\t\t\t\t\t\t\tattachmentRecord\n\t\t\t\t\t\t);\n\n\t\t\t\t\tif ( derivedAttributes ) {\n\t\t\t\t\t\tObject.assign( nextAttributes, derivedAttributes );\n\n\t\t\t\t\t\t// The URL announced before the resolve was the\n\t\t\t\t\t\t// full-size file the media editor reported, and\n\t\t\t\t\t\t// deriving the selected size can change it.\n\t\t\t\t\t\t// Re-announce so the pending swap names the file\n\t\t\t\t\t\t// that actually lands: an update that is undone or\n\t\t\t\t\t\t// superseded never changes the <img> src, and the\n\t\t\t\t\t\t// block then clears its loading state by matching\n\t\t\t\t\t\t// the pending URL against the rendered one.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tderivedAttributes.url &&\n\t\t\t\t\t\t\tderivedAttributes.url !== latestBlockAttributes.url\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tonUrlChange?.( derivedAttributes.url );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( Object.keys( nextAttributes ).length ) {\n\t\t\t\t// Only restore values this save changed. Block-specific\n\t\t\t\t// metadata and unrelated edits must not be overwritten.\n\t\t\t\tfor ( const key of Object.keys( nextAttributes ) ) {\n\t\t\t\t\tif ( ! Object.hasOwn( undoState.undoAttributes, key ) ) {\n\t\t\t\t\t\tundoState.undoAttributes[ key ] =\n\t\t\t\t\t\t\tblockAttributesRef.current[ key ];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...nextAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( nextAttributes );\n\t\t\t}\n\t\t},\n\t\t[\n\t\t\tgetCachedAttachmentRecord,\n\t\t\tonUrlChange,\n\t\t\tresolveFreshAttachmentRecord,\n\t\t\tsetAttributes,\n\t\t]\n\t);\n\n\tconst openImageMediaEditorModal = useCallback( async () => {\n\t\tif ( ! id || ! openMediaEditorModal ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Snapshot the attachment's current metadata before the user makes\n\t\t// any changes so handleMediaUpdate can compare against it later. Use\n\t\t// the cached record when it's already present; only resolve when\n\t\t// nothing is cached yet, then fall back to a minimal object derived\n\t\t// from the block's own attributes.\n\t\tconst cachedAttachmentRecord = getCachedAttachmentRecord( id );\n\t\tconst fallbackAttachmentRecord =\n\t\t\tgetAttachmentFallbackForEmptyBlockMetadata(\n\t\t\t\tblockAttributesRef.current\n\t\t\t);\n\t\tconst resolvedAttachmentRecord = hasKnownAttachmentMetadata(\n\t\t\tcachedAttachmentRecord\n\t\t)\n\t\t\t? undefined\n\t\t\t: await resolveAttachmentRecord( id );\n\n\t\tmediaEditorMetadataBaselineRef.current =\n\t\t\tresolvedAttachmentRecord ||\n\t\t\t( hasKnownAttachmentMetadata( cachedAttachmentRecord )\n\t\t\t\t? cachedAttachmentRecord\n\t\t\t\t: fallbackAttachmentRecord ) ||\n\t\t\tcachedAttachmentRecord;\n\n\t\t// Each opening owns its Undo snapshot, so a later opening cannot\n\t\t// replace the values captured by an earlier snackbar.\n\t\tconst undoState = { undoAttributes: {}, isUndone: false };\n\t\topenMediaEditorModal( {\n\t\t\tid,\n\t\t\tonUpdate: ( updated ) => handleMediaUpdate( updated, undoState ),\n\t\t\tonUndo: () => {\n\t\t\t\tundoState.isUndone = true;\n\t\t\t\tconst { undoAttributes } = undoState;\n\t\t\t\tif ( Object.hasOwn( undoAttributes, 'url' ) ) {\n\t\t\t\t\tonUrlChange?.( undoAttributes.url );\n\t\t\t\t}\n\t\t\t\tblockAttributesRef.current = {\n\t\t\t\t\t...blockAttributesRef.current,\n\t\t\t\t\t...undoAttributes,\n\t\t\t\t};\n\t\t\t\tsetAttributes( undoAttributes );\n\t\t\t},\n\t\t\tonClose,\n\t\t} );\n\t}, [\n\t\tgetCachedAttachmentRecord,\n\t\thandleMediaUpdate,\n\t\tid,\n\t\tonClose,\n\t\tonUrlChange,\n\t\topenMediaEditorModal,\n\t\tresolveAttachmentRecord,\n\t\tsetAttributes,\n\t] );\n\n\treturn id && openMediaEditorModal ? openImageMediaEditorModal : undefined;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAmC;AACnC,0BAGO;AACP,iBAAiD;AACjD,kBAAuC;AACvC,qBAA+C;AAC/C,yBAAuB;AACvB,uBAIO;AAEP,SAAS,2BAA4B,SAAU;AAC9C,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAEA,QAAM,kBAAc,WAAAA,qBAAW,OAAQ,EAAE,KAAK;AAE9C,MAAK,CAAE,aAAc;AACpB,WAAO;AAAA,EACR;AAEA,SAAO,QAAQ,QAAS,OAAO,MAAO;AACvC;AAEA,SAAS,qBAAsB,YAAa;AAC3C,QAAM,UAAU,YAAY;AAE5B,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO,2BAA4B,OAAQ;AAAA,EAC5C;AAEA,MACC,WACA,OAAO,YAAY,YACnB,OAAO,OAAQ,SAAS,KAAM,GAC7B;AACD,WAAO,2BAA4B,QAAQ,GAAI;AAAA,EAChD;AAEA,SAAO;AACR;AAEO,SAAS,oCAAqC,YAAa;AACjE,SAAO;AAAA,IACN,KACC,OAAO,YAAY,aAAa,WAC7B,WAAW,WACX,YAAY,OAAO;AAAA,IACvB,SAAS,qBAAsB,UAAW;AAAA,EAC3C;AACD;AAEA,SAAS,2BAA4B,OAAQ;AAC5C,SAAO,SAAS;AACjB;AAEO,SAAS,8BACf,mBACA,oBACA,mBACC;AACD,MAAK,CAAE,sBAAsB,CAAE,mBAAoB;AAClD,WAAO,CAAC;AAAA,EACT;AAEA,QAAM,mBACL,oCAAqC,kBAAmB;AACzD,QAAM,kBACL,oCAAqC,iBAAkB;AACxD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,sBAAuB;AACrC;AAAA,IACD;AAOA,UAAM,yBAAyB,0BAA2B,EAAG;AAC7D,UAAM,2BACL;AAAA,MACC,mBAAmB;AAAA,IACpB;AACD,UAAM,2BAA2B;AAAA,MAChC;AAAA,IACD,IACG,SACA,MAAM,wBAAyB,EAAG;AAErC,mCAA+B,UAC9B,6BACE,2BAA4B,sBAAuB,IAClD,yBACA,6BACH;AAID,UAAM,YAAY,EAAE,gBAAgB,CAAC,GAAG,UAAU,MAAM;AACxD,yBAAsB;AAAA,MACrB;AAAA,MACA,UAAU,CAAE,YAAa,kBAAmB,SAAS,SAAU;AAAA,MAC/D,QAAQ,MAAM;AACb,kBAAU,WAAW;AACrB,cAAM,EAAE,eAAe,IAAI;AAC3B,YAAK,OAAO,OAAQ,gBAAgB,KAAM,GAAI;AAC7C,wBAAe,eAAe,GAAI;AAAA,QACnC;AACA,2BAAmB,UAAU;AAAA,UAC5B,GAAG,mBAAmB;AAAA,UACtB,GAAG;AAAA,QACJ;AACA,sBAAe,cAAe;AAAA,MAC/B;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO,MAAM,uBAAuB,4BAA4B;AACjE;",
|
|
6
6
|
"names": ["stripHTML", "blockEditorPrivateApis", "blockEditorStore", "coreStore"]
|
|
7
7
|
}
|
package/build/image/view.cjs
CHANGED
|
@@ -10,6 +10,7 @@ var touchStartEvent = {
|
|
|
10
10
|
startY: 0,
|
|
11
11
|
startTime: 0
|
|
12
12
|
};
|
|
13
|
+
var inertElements = [];
|
|
13
14
|
var focusableSelectors = [
|
|
14
15
|
".wp-lightbox-close-button",
|
|
15
16
|
".wp-lightbox-navigation-button"
|
|
@@ -281,7 +282,7 @@ var { state, actions, callbacks } = (0, import_interactivity.store)(
|
|
|
281
282
|
} = state.selectedImage.imageRef;
|
|
282
283
|
let { x: screenPosX, y: screenPosY } = state.selectedImage.imageRef.getBoundingClientRect();
|
|
283
284
|
const naturalRatio = naturalWidth / naturalHeight;
|
|
284
|
-
|
|
285
|
+
const originalRatio = originalWidth / originalHeight;
|
|
285
286
|
if (state.selectedImage.scaleAttr === "contain") {
|
|
286
287
|
if (naturalRatio > originalRatio) {
|
|
287
288
|
const heightWithoutSpace = originalWidth / naturalRatio;
|
|
@@ -293,47 +294,15 @@ var { state, actions, callbacks } = (0, import_interactivity.store)(
|
|
|
293
294
|
originalWidth = widthWithoutSpace;
|
|
294
295
|
}
|
|
295
296
|
}
|
|
296
|
-
|
|
297
|
-
let imgMaxWidth = parseFloat(
|
|
297
|
+
const imgMaxWidth = parseFloat(
|
|
298
298
|
state.selectedImage.targetWidth && state.selectedImage.targetWidth !== "none" ? state.selectedImage.targetWidth : naturalWidth
|
|
299
299
|
);
|
|
300
|
-
|
|
300
|
+
const imgMaxHeight = parseFloat(
|
|
301
301
|
state.selectedImage.targetHeight && state.selectedImage.targetHeight !== "none" ? state.selectedImage.targetHeight : naturalHeight
|
|
302
302
|
);
|
|
303
|
-
|
|
304
|
-
let containerMaxWidth = imgMaxWidth;
|
|
305
|
-
let containerMaxHeight = imgMaxHeight;
|
|
303
|
+
const fullSizeRatio = imgMaxWidth / imgMaxHeight;
|
|
306
304
|
let containerWidth = imgMaxWidth;
|
|
307
305
|
let containerHeight = imgMaxHeight;
|
|
308
|
-
if (naturalRatio.toFixed(2) !== imgRatio.toFixed(2)) {
|
|
309
|
-
if (naturalRatio > imgRatio) {
|
|
310
|
-
const reducedHeight = imgMaxWidth / naturalRatio;
|
|
311
|
-
if (imgMaxHeight - reducedHeight > imgMaxWidth) {
|
|
312
|
-
imgMaxHeight = reducedHeight;
|
|
313
|
-
imgMaxWidth = reducedHeight * naturalRatio;
|
|
314
|
-
} else {
|
|
315
|
-
imgMaxHeight = imgMaxWidth / naturalRatio;
|
|
316
|
-
}
|
|
317
|
-
} else {
|
|
318
|
-
const reducedWidth = imgMaxHeight * naturalRatio;
|
|
319
|
-
if (imgMaxWidth - reducedWidth > imgMaxHeight) {
|
|
320
|
-
imgMaxWidth = reducedWidth;
|
|
321
|
-
imgMaxHeight = reducedWidth / naturalRatio;
|
|
322
|
-
} else {
|
|
323
|
-
imgMaxWidth = imgMaxHeight * naturalRatio;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
containerWidth = imgMaxWidth;
|
|
327
|
-
containerHeight = imgMaxHeight;
|
|
328
|
-
imgRatio = imgMaxWidth / imgMaxHeight;
|
|
329
|
-
if (originalRatio > imgRatio) {
|
|
330
|
-
containerMaxWidth = imgMaxWidth;
|
|
331
|
-
containerMaxHeight = containerMaxWidth / originalRatio;
|
|
332
|
-
} else {
|
|
333
|
-
containerMaxHeight = imgMaxHeight;
|
|
334
|
-
containerMaxWidth = containerMaxHeight * originalRatio;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
306
|
if (originalWidth > containerWidth || originalHeight > containerHeight) {
|
|
338
307
|
containerWidth = originalWidth;
|
|
339
308
|
containerHeight = originalHeight;
|
|
@@ -357,23 +326,37 @@ var { state, actions, callbacks } = (0, import_interactivity.store)(
|
|
|
357
326
|
containerHeight
|
|
358
327
|
);
|
|
359
328
|
const targetContainerRatio = targetMaxWidth / targetMaxHeight;
|
|
360
|
-
if (
|
|
329
|
+
if (fullSizeRatio > targetContainerRatio) {
|
|
361
330
|
containerWidth = targetMaxWidth;
|
|
362
|
-
containerHeight = containerWidth /
|
|
331
|
+
containerHeight = containerWidth / fullSizeRatio;
|
|
363
332
|
} else {
|
|
364
333
|
containerHeight = targetMaxHeight;
|
|
365
|
-
containerWidth = containerHeight *
|
|
334
|
+
containerWidth = containerHeight * fullSizeRatio;
|
|
366
335
|
}
|
|
367
|
-
const
|
|
368
|
-
const
|
|
369
|
-
const
|
|
336
|
+
const hasCroppedSource = naturalRatio.toFixed(2) !== fullSizeRatio.toFixed(2);
|
|
337
|
+
const sourceRatio = hasCroppedSource ? naturalRatio : fullSizeRatio;
|
|
338
|
+
const containerScale = Math.max(
|
|
339
|
+
originalWidth / containerWidth,
|
|
340
|
+
originalHeight / containerHeight,
|
|
341
|
+
originalWidth / (containerHeight * sourceRatio),
|
|
342
|
+
originalHeight * sourceRatio / containerWidth
|
|
343
|
+
);
|
|
344
|
+
const thumbnailWidth = originalWidth / containerScale;
|
|
345
|
+
const thumbnailHeight = originalHeight / containerScale;
|
|
346
|
+
const cropX = (containerWidth - thumbnailWidth) / 2;
|
|
347
|
+
const cropY = (containerHeight - thumbnailHeight) / 2;
|
|
348
|
+
screenPosX -= cropX * containerScale;
|
|
349
|
+
screenPosY -= cropY * containerScale;
|
|
370
350
|
state.overlayStyles = `
|
|
371
351
|
--wp--lightbox-initial-top-position: ${screenPosY}px;
|
|
372
352
|
--wp--lightbox-initial-left-position: ${screenPosX}px;
|
|
373
353
|
--wp--lightbox-container-width: ${containerWidth + 1}px;
|
|
374
354
|
--wp--lightbox-container-height: ${containerHeight + 1}px;
|
|
375
|
-
--wp--lightbox-image-width: ${
|
|
376
|
-
--wp--lightbox-image-height: ${
|
|
355
|
+
--wp--lightbox-image-width: ${containerWidth}px;
|
|
356
|
+
--wp--lightbox-image-height: ${containerHeight}px;
|
|
357
|
+
--wp--lightbox-initial-clip: inset(${cropY}px ${cropX}px);
|
|
358
|
+
--wp--lightbox-thumbnail-width: ${hasCroppedSource ? thumbnailWidth : containerWidth}px;
|
|
359
|
+
--wp--lightbox-thumbnail-height: ${hasCroppedSource ? thumbnailHeight : containerHeight}px;
|
|
377
360
|
--wp--lightbox-scale: ${containerScale};
|
|
378
361
|
--wp--lightbox-scrollbar-width: ${window.innerWidth - document.documentElement.clientWidth}px;
|
|
379
362
|
`;
|
|
@@ -434,13 +417,24 @@ var { state, actions, callbacks } = (0, import_interactivity.store)(
|
|
|
434
417
|
}
|
|
435
418
|
},
|
|
436
419
|
setInertElements() {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
el.
|
|
440
|
-
|
|
441
|
-
|
|
420
|
+
if (!state.overlayEnabled) {
|
|
421
|
+
inertElements.forEach(
|
|
422
|
+
(el) => el.removeAttribute("inert")
|
|
423
|
+
);
|
|
424
|
+
inertElements = [];
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const { ref } = (0, import_interactivity.getElement)();
|
|
428
|
+
let node = ref;
|
|
429
|
+
while (node && node !== document.body && node.parentElement) {
|
|
430
|
+
for (const sibling of node.parentElement.children) {
|
|
431
|
+
if (sibling !== node && !sibling.hasAttribute("inert")) {
|
|
432
|
+
sibling.setAttribute("inert", "");
|
|
433
|
+
inertElements.push(sibling);
|
|
434
|
+
}
|
|
442
435
|
}
|
|
443
|
-
|
|
436
|
+
node = node.parentElement;
|
|
437
|
+
}
|
|
444
438
|
},
|
|
445
439
|
initTriggerButton() {
|
|
446
440
|
const { imageId } = (0, import_interactivity.getContext)();
|
package/build/image/view.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/image/view.js"],
|
|
4
|
-
"sourcesContent": ["import {\n\tstore,\n\tgetContext,\n\tgetElement,\n\tgetConfig,\n\twithSyncEvent,\n\twithScope,\n} from '@wordpress/interactivity';\nimport { IMAGE_PRELOAD_DELAY } from './constants';\n\n/**\n * Tracks whether user is touching screen; used to differentiate behavior for\n * touch and mouse input.\n *\n * @type {boolean}\n */\nlet isTouching = false;\n\n/**\n * Tracks the last time the screen was touched; used to differentiate behavior\n * for touch and mouse input.\n *\n * @type {number}\n */\nlet lastTouchTime = 0;\n\nconst touchStartEvent = {\n\tstartX: 0,\n\tstartY: 0,\n\tstartTime: 0,\n};\n\nconst focusableSelectors = [\n\t'.wp-lightbox-close-button',\n\t'.wp-lightbox-navigation-button',\n];\n\n/**\n * Returns the appropriate src URL for an image.\n *\n * @param {string} uploadedSrc - Full size image src.\n * @return {string} The source URL.\n */\nfunction getImageSrc( { uploadedSrc } ) {\n\treturn (\n\t\tuploadedSrc ||\n\t\t'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='\n\t);\n}\n\n/**\n * Returns the appropriate srcset for an image.\n *\n * @param {string} lightboxSrcset - Image srcset.\n * @return {string} The srcset value.\n */\nfunction getImageSrcset( { lightboxSrcset } ) {\n\treturn lightboxSrcset || '';\n}\n\nconst { state, actions, callbacks } = store(\n\t'core/image',\n\t{\n\t\tstate: {\n\t\t\tselectedImageId: null,\n\t\t\tselectedGalleryId: null,\n\t\t\tpreloadTimers: new Map(),\n\t\t\tpreloadedImageIds: new Set(),\n\t\t\tget galleryImages() {\n\t\t\t\tif ( ! state.selectedGalleryId ) {\n\t\t\t\t\treturn [ state.selectedImageId ];\n\t\t\t\t}\n\n\t\t\t\t// Get all images in this gallery and sort by galleryOrder\n\t\t\t\treturn Object.entries( state.metadata )\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( [ , value ] ) =>\n\t\t\t\t\t\t\tvalue.galleryId === state.selectedGalleryId\n\t\t\t\t\t)\n\t\t\t\t\t.sort( ( [ , a ], [ , b ] ) => {\n\t\t\t\t\t\tconst orderA = a.order ?? 0;\n\t\t\t\t\t\tconst orderB = b.order ?? 0;\n\t\t\t\t\t\treturn orderA - orderB;\n\t\t\t\t\t} )\n\t\t\t\t\t.map( ( [ key ] ) => key );\n\t\t\t},\n\t\t\tget selectedImageIndex() {\n\t\t\t\treturn state.galleryImages.findIndex(\n\t\t\t\t\t( id ) => id === state.selectedImageId\n\t\t\t\t);\n\t\t\t},\n\t\t\tget selectedImage() {\n\t\t\t\treturn state.metadata[ state.selectedImageId ];\n\t\t\t},\n\t\t\tget hasNavigationIcon() {\n\t\t\t\tconst { navigationButtonType } = state.selectedImage;\n\t\t\t\treturn (\n\t\t\t\t\tnavigationButtonType === 'icon' ||\n\t\t\t\t\tnavigationButtonType === 'both'\n\t\t\t\t);\n\t\t\t},\n\t\t\tget hasNavigationText() {\n\t\t\t\tconst { navigationButtonType } = state.selectedImage;\n\t\t\t\treturn (\n\t\t\t\t\tnavigationButtonType === 'text' ||\n\t\t\t\t\tnavigationButtonType === 'both'\n\t\t\t\t);\n\t\t\t},\n\t\t\tget thisImage() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\treturn state.metadata[ imageId ];\n\t\t\t},\n\t\t\tget hasNavigation() {\n\t\t\t\treturn state.galleryImages.length > 1;\n\t\t\t},\n\t\t\tget hasNextImage() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.selectedImageIndex + 1 < state.galleryImages.length\n\t\t\t\t);\n\t\t\t},\n\t\t\tget hasPreviousImage() {\n\t\t\t\treturn state.selectedImageIndex - 1 >= 0;\n\t\t\t},\n\t\t\tget overlayOpened() {\n\t\t\t\treturn state.selectedImageId !== null;\n\t\t\t},\n\t\t\tget roleAttribute() {\n\t\t\t\treturn state.overlayOpened ? 'dialog' : null;\n\t\t\t},\n\t\t\tget ariaModal() {\n\t\t\t\treturn state.overlayOpened ? 'true' : null;\n\t\t\t},\n\t\t\tget ariaLabel() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.selectedImage.customAriaLabel ||\n\t\t\t\t\tgetConfig().defaultAriaLabel\n\t\t\t\t);\n\t\t\t},\n\t\t\tget closeButtonAriaLabel() {\n\t\t\t\treturn state.hasNavigationText\n\t\t\t\t\t? undefined\n\t\t\t\t\t: getConfig().closeButtonText;\n\t\t\t},\n\t\t\tget prevButtonAriaLabel() {\n\t\t\t\treturn state.hasNavigationText\n\t\t\t\t\t? undefined\n\t\t\t\t\t: getConfig().prevButtonText;\n\t\t\t},\n\t\t\tget nextButtonAriaLabel() {\n\t\t\t\treturn state.hasNavigationText\n\t\t\t\t\t? undefined\n\t\t\t\t\t: getConfig().nextButtonText;\n\t\t\t},\n\t\t\tget enlargedSrc() {\n\t\t\t\treturn getImageSrc( state.selectedImage );\n\t\t\t},\n\t\t\tget enlargedSrcset() {\n\t\t\t\treturn getImageSrcset( state.selectedImage );\n\t\t\t},\n\t\t\tget figureStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.selectedImage.figureStyles?.replace(\n\t\t\t\t\t\t/margin[^;]*;?/g,\n\t\t\t\t\t\t''\n\t\t\t\t\t) };`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget imgStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.selectedImage.imgStyles?.replace(\n\t\t\t\t\t\t/;$/,\n\t\t\t\t\t\t''\n\t\t\t\t\t) }; object-fit:cover;`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget isContentHidden() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayEnabled &&\n\t\t\t\t\tstate.selectedImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t\tget isContentVisible() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\t! state.overlayEnabled &&\n\t\t\t\t\tstate.selectedImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t\tactions: {\n\t\t\tshowLightbox() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\t// Bails out if the image has not loaded yet.\n\t\t\t\tif ( ! state.metadata[ imageId ].imageRef?.complete ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Stores the positions of the scroll to fix it until the overlay is\n\t\t\t\t// closed.\n\t\t\t\tstate.scrollTopReset = document.documentElement.scrollTop;\n\t\t\t\tstate.scrollLeftReset = document.documentElement.scrollLeft;\n\n\t\t\t\t// Sets the selected image and gallery and enables the overlay.\n\t\t\t\tstate.selectedImageId = imageId;\n\t\t\t\tconst { galleryId } = getContext( 'core/gallery' ) || {};\n\t\t\t\tstate.selectedGalleryId = galleryId || null;\n\t\t\t\tstate.overlayEnabled = true;\n\n\t\t\t\t// Computes the styles of the overlay for the animation.\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t},\n\t\t\thideLightbox() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tstate.overlayEnabled = false;\n\n\t\t\t\t\t// Waits until the close animation has completed before allowing a\n\t\t\t\t\t// user to scroll again. The duration of this animation is defined in\n\t\t\t\t\t// the `styles.scss` file, but in any case we should wait a few\n\t\t\t\t\t// milliseconds longer than the duration, otherwise a user may scroll\n\t\t\t\t\t// too soon and cause the animation to look sloppy.\n\t\t\t\t\tsetTimeout( function () {\n\t\t\t\t\t\t// Delays before changing the focus. Otherwise the focus ring will\n\t\t\t\t\t\t// appear on Firefox before the image has finished animating, which\n\t\t\t\t\t\t// looks broken.\n\t\t\t\t\t\tstate.selectedImage.buttonRef.focus( {\n\t\t\t\t\t\t\tpreventScroll: true,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Resets the selected image and gallery ids.\n\t\t\t\t\t\tstate.selectedImageId = null;\n\t\t\t\t\t\tstate.selectedGalleryId = null;\n\t\t\t\t\t}, 450 );\n\t\t\t\t}\n\t\t\t},\n\t\t\tshowPreviousImage: withSyncEvent( ( event ) => {\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tconst nextIndex = state.hasPreviousImage\n\t\t\t\t\t? state.selectedImageIndex - 1\n\t\t\t\t\t: state.galleryImages.length - 1;\n\t\t\t\tstate.selectedImageId = state.galleryImages[ nextIndex ];\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t} ),\n\t\t\tshowNextImage: withSyncEvent( ( event ) => {\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tconst nextIndex = state.hasNextImage\n\t\t\t\t\t? state.selectedImageIndex + 1\n\t\t\t\t\t: 0;\n\t\t\t\tstate.selectedImageId = state.galleryImages[ nextIndex ];\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t} ),\n\t\t\thandleKeydown: withSyncEvent( ( event ) => {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tif ( event.key === 'Escape' ) {\n\t\t\t\t\t\tactions.hideLightbox();\n\t\t\t\t\t} else if ( event.key === 'ArrowLeft' ) {\n\t\t\t\t\t\tactions.showPreviousImage( event );\n\t\t\t\t\t} else if ( event.key === 'ArrowRight' ) {\n\t\t\t\t\t\tactions.showNextImage( event );\n\t\t\t\t\t} else if ( event.key === 'Tab' ) {\n\t\t\t\t\t\t// Traps focus within the overlay.\n\t\t\t\t\t\tconst focusableElements = Array.from(\n\t\t\t\t\t\t\tdocument.querySelectorAll( focusableSelectors )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst firstFocusableElement = focusableElements[ 0 ];\n\t\t\t\t\t\tconst lastFocusableElement =\n\t\t\t\t\t\t\tfocusableElements[ focusableElements.length - 1 ];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tevent.shiftKey &&\n\t\t\t\t\t\t\tevent.target === firstFocusableElement\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tlastFocusableElement.focus();\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t! event.shiftKey &&\n\t\t\t\t\t\t\tevent.target === lastFocusableElement\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tfirstFocusableElement.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchMove: withSyncEvent( ( event ) => {\n\t\t\t\t// On mobile devices, prevents triggering the scroll event because\n\t\t\t\t// otherwise the page jumps around when it resets the scroll position.\n\t\t\t\t// This also means that closing the lightbox requires that a user\n\t\t\t\t// perform a simple tap. This may be changed in the future if there is a\n\t\t\t\t// better alternative to override or reset the scroll position during\n\t\t\t\t// swipe actions.\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchStart( event ) {\n\t\t\t\tisTouching = true;\n\t\t\t\tconst t = event.touches && event.touches[ 0 ];\n\t\t\t\tif ( t ) {\n\t\t\t\t\ttouchStartEvent.startX = t.clientX;\n\t\t\t\t\ttouchStartEvent.startY = t.clientY;\n\t\t\t\t\ttouchStartEvent.startTime = Date.now();\n\t\t\t\t}\n\t\t\t},\n\t\t\thandleTouchEnd: withSyncEvent( ( event ) => {\n\t\t\t\tconst touchEndEvent =\n\t\t\t\t\t( event.changedTouches && event.changedTouches[ 0 ] ) ||\n\t\t\t\t\t( event.touches && event.touches[ 0 ] );\n\t\t\t\tconst now = Date.now();\n\n\t\t\t\tif ( touchEndEvent && state.overlayEnabled ) {\n\t\t\t\t\tconst deltaX =\n\t\t\t\t\t\ttouchEndEvent.clientX - touchStartEvent.startX;\n\t\t\t\t\tconst deltaY =\n\t\t\t\t\t\ttouchEndEvent.clientY - touchStartEvent.startY;\n\t\t\t\t\tconst absDeltaX = Math.abs( deltaX );\n\t\t\t\t\tconst absDeltaY = Math.abs( deltaY );\n\t\t\t\t\tconst elapsedMs = now - touchStartEvent.startTime;\n\t\t\t\t\tconst isHorizontalSwipe =\n\t\t\t\t\t\t// Swipe distance is greater than 50px\n\t\t\t\t\t\tabsDeltaX > 50 &&\n\t\t\t\t\t\t// Horizontal movement is much larger than the vertical movement\n\t\t\t\t\t\tabsDeltaX > absDeltaY * 1.5 &&\n\t\t\t\t\t\t// Fast action of less than 800ms\n\t\t\t\t\t\telapsedMs < 800;\n\n\t\t\t\t\tif ( isHorizontalSwipe ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tif ( deltaX < 0 ) {\n\t\t\t\t\t\t\tactions.showNextImage( event );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tactions.showPreviousImage( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlastTouchTime = now;\n\t\t\t\tisTouching = false;\n\t\t\t} ),\n\t\t\thandleScroll() {\n\t\t\t\t// Prevents scrolling behaviors that trigger content shift while the\n\t\t\t\t// lightbox is open. It would be better to accomplish through CSS alone,\n\t\t\t\t// but using overflow: hidden is currently the only way to do so and\n\t\t\t\t// that causes a layout to shift and prevents the zoom animation from\n\t\t\t\t// working in some cases because it's not possible to account for the\n\t\t\t\t// layout shift when doing the animation calculations. Instead, it uses\n\t\t\t\t// JavaScript to prevent and reset the scrolling behavior.\n\t\t\t\tif ( state.overlayOpened ) {\n\t\t\t\t\t// Avoids overriding the scroll behavior on mobile devices because\n\t\t\t\t\t// doing so breaks the pinch to zoom functionality, and users should\n\t\t\t\t\t// be able to zoom in further on the high-res image.\n\t\t\t\t\tif ( ! isTouching && Date.now() - lastTouchTime > 450 ) {\n\t\t\t\t\t\t// It doesn't rely on `event.preventDefault()` to prevent scrolling\n\t\t\t\t\t\t// because the scroll event can't be canceled, so it resets the\n\t\t\t\t\t\t// position instead.\n\t\t\t\t\t\twindow.scrollTo(\n\t\t\t\t\t\t\tstate.scrollLeftReset,\n\t\t\t\t\t\t\tstate.scrollTopReset\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tpreloadImage() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\t// Bails if it has already been preloaded. This could help\n\t\t\t\t// prevent unnecessary preloading of the same image multiple times,\n\t\t\t\t// leading to duplicate link elements in the document head.\n\t\t\t\tif ( state.preloadedImageIds.has( imageId ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Link element to preload the image.\n\t\t\t\tconst imageMetadata = state.metadata[ imageId ];\n\t\t\t\tconst imageLink = document.createElement( 'link' );\n\t\t\t\timageLink.rel = 'preload';\n\t\t\t\timageLink.as = 'image';\n\t\t\t\timageLink.href = getImageSrc( imageMetadata );\n\n\t\t\t\t// Apply srcset if available for responsive preloading\n\t\t\t\tconst srcset = getImageSrcset( imageMetadata );\n\t\t\t\tif ( srcset ) {\n\t\t\t\t\timageLink.setAttribute( 'imagesrcset', srcset );\n\t\t\t\t\timageLink.setAttribute( 'imagesizes', '100vw' );\n\t\t\t\t}\n\n\t\t\t\tdocument.head.appendChild( imageLink );\n\t\t\t\tstate.preloadedImageIds.add( imageId );\n\t\t\t},\n\t\t\tpreloadImageWithDelay() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\tactions.cancelPreload();\n\n\t\t\t\t// Set a new timer to preload the image after a short delay.\n\t\t\t\tconst timerId = setTimeout(\n\t\t\t\t\twithScope( () => {\n\t\t\t\t\t\tactions.preloadImage();\n\t\t\t\t\t\tstate.preloadTimers.delete( imageId );\n\t\t\t\t\t} ),\n\t\t\t\t\tIMAGE_PRELOAD_DELAY\n\t\t\t\t);\n\t\t\t\tstate.preloadTimers.set( imageId, timerId );\n\t\t\t},\n\t\t\tcancelPreload() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tif ( state.preloadTimers.has( imageId ) ) {\n\t\t\t\t\tclearTimeout( state.preloadTimers.get( imageId ) );\n\t\t\t\t\tstate.preloadTimers.delete( imageId );\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tcallbacks: {\n\t\t\tsetOverlayStyles() {\n\t\t\t\tif ( ! state.overlayEnabled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth: originalWidth,\n\t\t\t\t\toffsetHeight: originalHeight,\n\t\t\t\t} = state.selectedImage.imageRef;\n\t\t\t\tlet { x: screenPosX, y: screenPosY } =\n\t\t\t\t\tstate.selectedImage.imageRef.getBoundingClientRect();\n\n\t\t\t\t// Natural ratio of the image clicked to open the lightbox.\n\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t// Original ratio of the image clicked to open the lightbox.\n\t\t\t\tlet originalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// If it has object-fit: contain, recalculates the original sizes\n\t\t\t\t// and the screen position without the blank spaces.\n\t\t\t\tif ( state.selectedImage.scaleAttr === 'contain' ) {\n\t\t\t\t\tif ( naturalRatio > originalRatio ) {\n\t\t\t\t\t\tconst heightWithoutSpace = originalWidth / naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the top space.\n\t\t\t\t\t\tscreenPosY +=\n\t\t\t\t\t\t\t( originalHeight - heightWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalHeight = heightWithoutSpace;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst widthWithoutSpace = originalHeight * naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the left space.\n\t\t\t\t\t\tscreenPosX += ( originalWidth - widthWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalWidth = widthWithoutSpace;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\toriginalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// Typically, it uses the image's full-sized dimensions. If those\n\t\t\t\t// dimensions have not been set (i.e. an external image with only one\n\t\t\t\t// size), the image's dimensions in the lightbox are the same\n\t\t\t\t// as those of the image in the content.\n\t\t\t\tlet imgMaxWidth = parseFloat(\n\t\t\t\t\tstate.selectedImage.targetWidth &&\n\t\t\t\t\t\tstate.selectedImage.targetWidth !== 'none'\n\t\t\t\t\t\t? state.selectedImage.targetWidth\n\t\t\t\t\t\t: naturalWidth\n\t\t\t\t);\n\t\t\t\tlet imgMaxHeight = parseFloat(\n\t\t\t\t\tstate.selectedImage.targetHeight &&\n\t\t\t\t\t\tstate.selectedImage.targetHeight !== 'none'\n\t\t\t\t\t\t? state.selectedImage.targetHeight\n\t\t\t\t\t\t: naturalHeight\n\t\t\t\t);\n\n\t\t\t\t// Ratio of the biggest image stored in the database.\n\t\t\t\tlet imgRatio = imgMaxWidth / imgMaxHeight;\n\t\t\t\tlet containerMaxWidth = imgMaxWidth;\n\t\t\t\tlet containerMaxHeight = imgMaxHeight;\n\t\t\t\tlet containerWidth = imgMaxWidth;\n\t\t\t\tlet containerHeight = imgMaxHeight;\n\n\t\t\t\t// Checks if the target image has a different ratio than the original\n\t\t\t\t// one (thumbnail). Recalculates the width and height.\n\t\t\t\tif ( naturalRatio.toFixed( 2 ) !== imgRatio.toFixed( 2 ) ) {\n\t\t\t\t\tif ( naturalRatio > imgRatio ) {\n\t\t\t\t\t\t// If the width is reached before the height, it keeps the maxWidth\n\t\t\t\t\t\t// and recalculates the height unless the difference between the\n\t\t\t\t\t\t// maxHeight and the reducedHeight is higher than the maxWidth,\n\t\t\t\t\t\t// where it keeps the reducedHeight and recalculate the width.\n\t\t\t\t\t\tconst reducedHeight = imgMaxWidth / naturalRatio;\n\t\t\t\t\t\tif ( imgMaxHeight - reducedHeight > imgMaxWidth ) {\n\t\t\t\t\t\t\timgMaxHeight = reducedHeight;\n\t\t\t\t\t\t\timgMaxWidth = reducedHeight * naturalRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\timgMaxHeight = imgMaxWidth / naturalRatio;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the height is reached before the width, it keeps the maxHeight\n\t\t\t\t\t\t// and recalculate the width unlesss the difference between the\n\t\t\t\t\t\t// maxWidth and the reducedWidth is higher than the maxHeight, where\n\t\t\t\t\t\t// it keeps the reducedWidth and recalculate the height.\n\t\t\t\t\t\tconst reducedWidth = imgMaxHeight * naturalRatio;\n\t\t\t\t\t\tif ( imgMaxWidth - reducedWidth > imgMaxHeight ) {\n\t\t\t\t\t\t\timgMaxWidth = reducedWidth;\n\t\t\t\t\t\t\timgMaxHeight = reducedWidth / naturalRatio;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\timgMaxWidth = imgMaxHeight * naturalRatio;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontainerWidth = imgMaxWidth;\n\t\t\t\t\tcontainerHeight = imgMaxHeight;\n\t\t\t\t\timgRatio = imgMaxWidth / imgMaxHeight;\n\n\t\t\t\t\t// Calculates the max size of the container.\n\t\t\t\t\tif ( originalRatio > imgRatio ) {\n\t\t\t\t\t\tcontainerMaxWidth = imgMaxWidth;\n\t\t\t\t\t\tcontainerMaxHeight = containerMaxWidth / originalRatio;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcontainerMaxHeight = imgMaxHeight;\n\t\t\t\t\t\tcontainerMaxWidth = containerMaxHeight * originalRatio;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// If the image has been pixelated on purpose, it keeps that size.\n\t\t\t\tif (\n\t\t\t\t\toriginalWidth > containerWidth ||\n\t\t\t\t\toriginalHeight > containerHeight\n\t\t\t\t) {\n\t\t\t\t\tcontainerWidth = originalWidth;\n\t\t\t\t\tcontainerHeight = originalHeight;\n\t\t\t\t}\n\n\t\t\t\t// Calculates the final lightbox image size and the scale factor.\n\t\t\t\t// MaxWidth is either the window container (accounting for padding) or\n\t\t\t\t// the image resolution.\n\n\t\t\t\t// 480px width or less\n\t\t\t\tlet horizontalPadding = 0;\n\t\t\t\tlet verticalPadding = 160;\n\t\t\t\t// Greater than 480px wide and less than or equal to 960px\n\t\t\t\tif ( 480 < window.innerWidth ) {\n\t\t\t\t\thorizontalPadding = 80;\n\t\t\t\t\tverticalPadding = 160;\n\t\t\t\t}\n\t\t\t\t// Greater than 960px wide\n\t\t\t\tif ( 960 < window.innerWidth ) {\n\t\t\t\t\thorizontalPadding = state.hasNavigation ? 320 : 80;\n\t\t\t\t\tverticalPadding = 80;\n\t\t\t\t}\n\n\t\t\t\tconst targetMaxWidth = Math.min(\n\t\t\t\t\twindow.innerWidth - horizontalPadding,\n\t\t\t\t\tcontainerWidth\n\t\t\t\t);\n\t\t\t\tconst targetMaxHeight = Math.min(\n\t\t\t\t\twindow.innerHeight - verticalPadding,\n\t\t\t\t\tcontainerHeight\n\t\t\t\t);\n\t\t\t\tconst targetContainerRatio = targetMaxWidth / targetMaxHeight;\n\n\t\t\t\tif ( originalRatio > targetContainerRatio ) {\n\t\t\t\t\t// If targetMaxWidth is reached before targetMaxHeight.\n\t\t\t\t\tcontainerWidth = targetMaxWidth;\n\t\t\t\t\tcontainerHeight = containerWidth / originalRatio;\n\t\t\t\t} else {\n\t\t\t\t\t// If targetMaxHeight is reached before targetMaxWidth.\n\t\t\t\t\tcontainerHeight = targetMaxHeight;\n\t\t\t\t\tcontainerWidth = containerHeight * originalRatio;\n\t\t\t\t}\n\n\t\t\t\tconst containerScale = originalWidth / containerWidth;\n\t\t\t\tconst lightboxImgWidth =\n\t\t\t\t\timgMaxWidth * ( containerWidth / containerMaxWidth );\n\t\t\t\tconst lightboxImgHeight =\n\t\t\t\t\timgMaxHeight * ( containerHeight / containerMaxHeight );\n\n\t\t\t\t// As of this writing, using the calculations above will render the\n\t\t\t\t// lightbox with a small, erroneous whitespace on the left side of the\n\t\t\t\t// image in iOS Safari, perhaps due to an inconsistency in how browsers\n\t\t\t\t// handle absolute positioning and CSS transformation. In any case,\n\t\t\t\t// adding 1 pixel to the container width and height solves the problem,\n\t\t\t\t// though this can be removed if the issue is fixed in the future.\n\t\t\t\tstate.overlayStyles = `\n\t\t\t\t\t--wp--lightbox-initial-top-position: ${ screenPosY }px;\n\t\t\t\t\t--wp--lightbox-initial-left-position: ${ screenPosX }px;\n\t\t\t\t\t--wp--lightbox-container-width: ${ containerWidth + 1 }px;\n\t\t\t\t\t--wp--lightbox-container-height: ${ containerHeight + 1 }px;\n\t\t\t\t\t--wp--lightbox-image-width: ${ lightboxImgWidth }px;\n\t\t\t\t\t--wp--lightbox-image-height: ${ lightboxImgHeight }px;\n\t\t\t\t\t--wp--lightbox-scale: ${ containerScale };\n\t\t\t\t\t--wp--lightbox-scrollbar-width: ${\n\t\t\t\t\t\twindow.innerWidth - document.documentElement.clientWidth\n\t\t\t\t\t}px;\n\t\t\t\t`;\n\t\t\t},\n\t\t\tsetButtonStyles() {\n\t\t\t\tconst { ref } = getElement();\n\n\t\t\t\t// This guard prevents errors in images with the `srcset`\n\t\t\t\t// attribute, which can dispatch `load` events even after DOM\n\t\t\t\t// removal. Preact doesn't automatically clean up `load` event\n\t\t\t\t// listeners on unmounted `img` elements (see\n\t\t\t\t// https://github.com/preactjs/preact/issues/3141).\n\t\t\t\tif ( ! ref ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\tstate.metadata[ imageId ].imageRef = ref;\n\t\t\t\tstate.metadata[ imageId ].currentSrc = ref.currentSrc;\n\n\t\t\t\tconst {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth,\n\t\t\t\t\toffsetHeight,\n\t\t\t\t} = ref;\n\n\t\t\t\t// If the image isn't loaded yet, it can't calculate where the button\n\t\t\t\t// should be.\n\t\t\t\tif ( naturalWidth === 0 || naturalHeight === 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst figure = ref.parentElement;\n\t\t\t\tconst figureWidth = ref.parentElement.clientWidth;\n\n\t\t\t\t// It needs special handling for the height because a caption will cause\n\t\t\t\t// the figure to be taller than the image, which means it needs to\n\t\t\t\t// account for that when calculating the placement of the button in the\n\t\t\t\t// top right corner of the image.\n\t\t\t\tlet figureHeight = ref.parentElement.clientHeight;\n\t\t\t\tconst caption = figure.querySelector( 'figcaption' );\n\t\t\t\tif ( caption ) {\n\t\t\t\t\tconst captionComputedStyle =\n\t\t\t\t\t\twindow.getComputedStyle( caption );\n\t\t\t\t\tif (\n\t\t\t\t\t\t! [ 'absolute', 'fixed' ].includes(\n\t\t\t\t\t\t\tcaptionComputedStyle.position\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tfigureHeight =\n\t\t\t\t\t\t\tfigureHeight -\n\t\t\t\t\t\t\tcaption.offsetHeight -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginTop ) -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginBottom );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst buttonOffsetTop = figureHeight - offsetHeight;\n\t\t\t\tconst buttonOffsetRight = figureWidth - offsetWidth;\n\n\t\t\t\tlet buttonTop = buttonOffsetTop + 16;\n\t\t\t\tlet buttonRight = buttonOffsetRight + 16;\n\n\t\t\t\t// In the case of an image with object-fit: contain, the size of the\n\t\t\t\t// <img> element can be larger than the image itself, so it needs to\n\t\t\t\t// calculate where to place the button.\n\t\t\t\tif ( state.metadata[ imageId ].scaleAttr === 'contain' ) {\n\t\t\t\t\t// Natural ratio of the image.\n\t\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t\t// Offset ratio of the image.\n\t\t\t\t\tconst offsetRatio = offsetWidth / offsetHeight;\n\n\t\t\t\t\tif ( naturalRatio >= offsetRatio ) {\n\t\t\t\t\t\t// If it reaches the width first, it keeps the width and compute the\n\t\t\t\t\t\t// height.\n\t\t\t\t\t\tconst referenceHeight = offsetWidth / naturalRatio;\n\t\t\t\t\t\tbuttonTop =\n\t\t\t\t\t\t\t( offsetHeight - referenceHeight ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetTop +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t\tbuttonRight = buttonOffsetRight + 16;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If it reaches the height first, it keeps the height and compute\n\t\t\t\t\t\t// the width.\n\t\t\t\t\t\tconst referenceWidth = offsetHeight * naturalRatio;\n\t\t\t\t\t\tbuttonTop = buttonOffsetTop + 16;\n\t\t\t\t\t\tbuttonRight =\n\t\t\t\t\t\t\t( offsetWidth - referenceWidth ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetRight +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstate.metadata[ imageId ].buttonTop = buttonTop;\n\t\t\t\tstate.metadata[ imageId ].buttonRight = buttonRight;\n\t\t\t},\n\t\t\tsetOverlayFocus() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t// Moves the focus to the dialog when it opens.\n\t\t\t\t\tconst { ref } = getElement();\n\t\t\t\t\tref.focus();\n\t\t\t\t}\n\t\t\t},\n\t\t\tsetInertElements() {\n\t\t\t\t// Makes all children of the document inert exempt .wp-lightbox-overlay.\n\t\t\t\tdocument\n\t\t\t\t\t.querySelectorAll( 'body > :not(.wp-lightbox-overlay)' )\n\t\t\t\t\t.forEach( ( el ) => {\n\t\t\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t\t\tel.setAttribute( 'inert', '' );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tel.removeAttribute( 'inert' );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t},\n\t\t\tinitTriggerButton() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tconst { ref } = getElement();\n\t\t\t\tstate.metadata[ imageId ].buttonRef = ref;\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n"],
|
|
5
|
-
"mappings": ";;;AAAA,2BAOO;AACP,uBAAoC;AAQpC,IAAI,aAAa;AAQjB,IAAI,gBAAgB;AAEpB,IAAM,kBAAkB;AAAA,EACvB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,WAAW;AACZ;
|
|
4
|
+
"sourcesContent": ["import {\n\tstore,\n\tgetContext,\n\tgetElement,\n\tgetConfig,\n\twithSyncEvent,\n\twithScope,\n} from '@wordpress/interactivity';\nimport { IMAGE_PRELOAD_DELAY } from './constants';\n\n/**\n * Tracks whether user is touching screen; used to differentiate behavior for\n * touch and mouse input.\n *\n * @type {boolean}\n */\nlet isTouching = false;\n\n/**\n * Tracks the last time the screen was touched; used to differentiate behavior\n * for touch and mouse input.\n *\n * @type {number}\n */\nlet lastTouchTime = 0;\n\nconst touchStartEvent = {\n\tstartX: 0,\n\tstartY: 0,\n\tstartTime: 0,\n};\n\n/**\n * Elements made inert while the lightbox is open, so only those are restored\n * when it closes.\n *\n * @type {Element[]}\n */\nlet inertElements = [];\n\nconst focusableSelectors = [\n\t'.wp-lightbox-close-button',\n\t'.wp-lightbox-navigation-button',\n];\n\n/**\n * Returns the appropriate src URL for an image.\n *\n * @param {string} uploadedSrc - Full size image src.\n * @return {string} The source URL.\n */\nfunction getImageSrc( { uploadedSrc } ) {\n\treturn (\n\t\tuploadedSrc ||\n\t\t'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='\n\t);\n}\n\n/**\n * Returns the appropriate srcset for an image.\n *\n * @param {string} lightboxSrcset - Image srcset.\n * @return {string} The srcset value.\n */\nfunction getImageSrcset( { lightboxSrcset } ) {\n\treturn lightboxSrcset || '';\n}\n\nconst { state, actions, callbacks } = store(\n\t'core/image',\n\t{\n\t\tstate: {\n\t\t\tselectedImageId: null,\n\t\t\tselectedGalleryId: null,\n\t\t\tpreloadTimers: new Map(),\n\t\t\tpreloadedImageIds: new Set(),\n\t\t\tget galleryImages() {\n\t\t\t\tif ( ! state.selectedGalleryId ) {\n\t\t\t\t\treturn [ state.selectedImageId ];\n\t\t\t\t}\n\n\t\t\t\t// Get all images in this gallery and sort by galleryOrder\n\t\t\t\treturn Object.entries( state.metadata )\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( [ , value ] ) =>\n\t\t\t\t\t\t\tvalue.galleryId === state.selectedGalleryId\n\t\t\t\t\t)\n\t\t\t\t\t.sort( ( [ , a ], [ , b ] ) => {\n\t\t\t\t\t\tconst orderA = a.order ?? 0;\n\t\t\t\t\t\tconst orderB = b.order ?? 0;\n\t\t\t\t\t\treturn orderA - orderB;\n\t\t\t\t\t} )\n\t\t\t\t\t.map( ( [ key ] ) => key );\n\t\t\t},\n\t\t\tget selectedImageIndex() {\n\t\t\t\treturn state.galleryImages.findIndex(\n\t\t\t\t\t( id ) => id === state.selectedImageId\n\t\t\t\t);\n\t\t\t},\n\t\t\tget selectedImage() {\n\t\t\t\treturn state.metadata[ state.selectedImageId ];\n\t\t\t},\n\t\t\tget hasNavigationIcon() {\n\t\t\t\tconst { navigationButtonType } = state.selectedImage;\n\t\t\t\treturn (\n\t\t\t\t\tnavigationButtonType === 'icon' ||\n\t\t\t\t\tnavigationButtonType === 'both'\n\t\t\t\t);\n\t\t\t},\n\t\t\tget hasNavigationText() {\n\t\t\t\tconst { navigationButtonType } = state.selectedImage;\n\t\t\t\treturn (\n\t\t\t\t\tnavigationButtonType === 'text' ||\n\t\t\t\t\tnavigationButtonType === 'both'\n\t\t\t\t);\n\t\t\t},\n\t\t\tget thisImage() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\treturn state.metadata[ imageId ];\n\t\t\t},\n\t\t\tget hasNavigation() {\n\t\t\t\treturn state.galleryImages.length > 1;\n\t\t\t},\n\t\t\tget hasNextImage() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.selectedImageIndex + 1 < state.galleryImages.length\n\t\t\t\t);\n\t\t\t},\n\t\t\tget hasPreviousImage() {\n\t\t\t\treturn state.selectedImageIndex - 1 >= 0;\n\t\t\t},\n\t\t\tget overlayOpened() {\n\t\t\t\treturn state.selectedImageId !== null;\n\t\t\t},\n\t\t\tget roleAttribute() {\n\t\t\t\treturn state.overlayOpened ? 'dialog' : null;\n\t\t\t},\n\t\t\tget ariaModal() {\n\t\t\t\treturn state.overlayOpened ? 'true' : null;\n\t\t\t},\n\t\t\tget ariaLabel() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.selectedImage.customAriaLabel ||\n\t\t\t\t\tgetConfig().defaultAriaLabel\n\t\t\t\t);\n\t\t\t},\n\t\t\tget closeButtonAriaLabel() {\n\t\t\t\treturn state.hasNavigationText\n\t\t\t\t\t? undefined\n\t\t\t\t\t: getConfig().closeButtonText;\n\t\t\t},\n\t\t\tget prevButtonAriaLabel() {\n\t\t\t\treturn state.hasNavigationText\n\t\t\t\t\t? undefined\n\t\t\t\t\t: getConfig().prevButtonText;\n\t\t\t},\n\t\t\tget nextButtonAriaLabel() {\n\t\t\t\treturn state.hasNavigationText\n\t\t\t\t\t? undefined\n\t\t\t\t\t: getConfig().nextButtonText;\n\t\t\t},\n\t\t\tget enlargedSrc() {\n\t\t\t\treturn getImageSrc( state.selectedImage );\n\t\t\t},\n\t\t\tget enlargedSrcset() {\n\t\t\t\treturn getImageSrcset( state.selectedImage );\n\t\t\t},\n\t\t\tget figureStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.selectedImage.figureStyles?.replace(\n\t\t\t\t\t\t/margin[^;]*;?/g,\n\t\t\t\t\t\t''\n\t\t\t\t\t) };`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget imgStyles() {\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayOpened &&\n\t\t\t\t\t`${ state.selectedImage.imgStyles?.replace(\n\t\t\t\t\t\t/;$/,\n\t\t\t\t\t\t''\n\t\t\t\t\t) }; object-fit:cover;`\n\t\t\t\t);\n\t\t\t},\n\t\t\tget isContentHidden() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\tstate.overlayEnabled &&\n\t\t\t\t\tstate.selectedImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t\tget isContentVisible() {\n\t\t\t\tconst ctx = getContext();\n\t\t\t\treturn (\n\t\t\t\t\t! state.overlayEnabled &&\n\t\t\t\t\tstate.selectedImageId === ctx.imageId\n\t\t\t\t);\n\t\t\t},\n\t\t},\n\t\tactions: {\n\t\t\tshowLightbox() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\t// Bails out if the image has not loaded yet.\n\t\t\t\tif ( ! state.metadata[ imageId ].imageRef?.complete ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Stores the positions of the scroll to fix it until the overlay is\n\t\t\t\t// closed.\n\t\t\t\tstate.scrollTopReset = document.documentElement.scrollTop;\n\t\t\t\tstate.scrollLeftReset = document.documentElement.scrollLeft;\n\n\t\t\t\t// Sets the selected image and gallery and enables the overlay.\n\t\t\t\tstate.selectedImageId = imageId;\n\t\t\t\tconst { galleryId } = getContext( 'core/gallery' ) || {};\n\t\t\t\tstate.selectedGalleryId = galleryId || null;\n\t\t\t\tstate.overlayEnabled = true;\n\n\t\t\t\t// Computes the styles of the overlay for the animation.\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t},\n\t\t\thideLightbox() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tstate.overlayEnabled = false;\n\n\t\t\t\t\t// Waits until the close animation has completed before allowing a\n\t\t\t\t\t// user to scroll again. The duration of this animation is defined in\n\t\t\t\t\t// the `styles.scss` file, but in any case we should wait a few\n\t\t\t\t\t// milliseconds longer than the duration, otherwise a user may scroll\n\t\t\t\t\t// too soon and cause the animation to look sloppy.\n\t\t\t\t\tsetTimeout( function () {\n\t\t\t\t\t\t// Delays before changing the focus. Otherwise the focus ring will\n\t\t\t\t\t\t// appear on Firefox before the image has finished animating, which\n\t\t\t\t\t\t// looks broken.\n\t\t\t\t\t\tstate.selectedImage.buttonRef.focus( {\n\t\t\t\t\t\t\tpreventScroll: true,\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\t// Resets the selected image and gallery ids.\n\t\t\t\t\t\tstate.selectedImageId = null;\n\t\t\t\t\t\tstate.selectedGalleryId = null;\n\t\t\t\t\t}, 450 );\n\t\t\t\t}\n\t\t\t},\n\t\t\tshowPreviousImage: withSyncEvent( ( event ) => {\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tconst nextIndex = state.hasPreviousImage\n\t\t\t\t\t? state.selectedImageIndex - 1\n\t\t\t\t\t: state.galleryImages.length - 1;\n\t\t\t\tstate.selectedImageId = state.galleryImages[ nextIndex ];\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t} ),\n\t\t\tshowNextImage: withSyncEvent( ( event ) => {\n\t\t\t\tevent.stopPropagation();\n\t\t\t\tconst nextIndex = state.hasNextImage\n\t\t\t\t\t? state.selectedImageIndex + 1\n\t\t\t\t\t: 0;\n\t\t\t\tstate.selectedImageId = state.galleryImages[ nextIndex ];\n\t\t\t\tcallbacks.setOverlayStyles();\n\t\t\t} ),\n\t\t\thandleKeydown: withSyncEvent( ( event ) => {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tif ( event.key === 'Escape' ) {\n\t\t\t\t\t\tactions.hideLightbox();\n\t\t\t\t\t} else if ( event.key === 'ArrowLeft' ) {\n\t\t\t\t\t\tactions.showPreviousImage( event );\n\t\t\t\t\t} else if ( event.key === 'ArrowRight' ) {\n\t\t\t\t\t\tactions.showNextImage( event );\n\t\t\t\t\t} else if ( event.key === 'Tab' ) {\n\t\t\t\t\t\t// Traps focus within the overlay.\n\t\t\t\t\t\tconst focusableElements = Array.from(\n\t\t\t\t\t\t\tdocument.querySelectorAll( focusableSelectors )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst firstFocusableElement = focusableElements[ 0 ];\n\t\t\t\t\t\tconst lastFocusableElement =\n\t\t\t\t\t\t\tfocusableElements[ focusableElements.length - 1 ];\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tevent.shiftKey &&\n\t\t\t\t\t\t\tevent.target === firstFocusableElement\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tlastFocusableElement.focus();\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\t! event.shiftKey &&\n\t\t\t\t\t\t\tevent.target === lastFocusableElement\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\tfirstFocusableElement.focus();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchMove: withSyncEvent( ( event ) => {\n\t\t\t\t// On mobile devices, prevents triggering the scroll event because\n\t\t\t\t// otherwise the page jumps around when it resets the scroll position.\n\t\t\t\t// This also means that closing the lightbox requires that a user\n\t\t\t\t// perform a simple tap. This may be changed in the future if there is a\n\t\t\t\t// better alternative to override or reset the scroll position during\n\t\t\t\t// swipe actions.\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t}\n\t\t\t} ),\n\t\t\thandleTouchStart( event ) {\n\t\t\t\tisTouching = true;\n\t\t\t\tconst t = event.touches && event.touches[ 0 ];\n\t\t\t\tif ( t ) {\n\t\t\t\t\ttouchStartEvent.startX = t.clientX;\n\t\t\t\t\ttouchStartEvent.startY = t.clientY;\n\t\t\t\t\ttouchStartEvent.startTime = Date.now();\n\t\t\t\t}\n\t\t\t},\n\t\t\thandleTouchEnd: withSyncEvent( ( event ) => {\n\t\t\t\tconst touchEndEvent =\n\t\t\t\t\t( event.changedTouches && event.changedTouches[ 0 ] ) ||\n\t\t\t\t\t( event.touches && event.touches[ 0 ] );\n\t\t\t\tconst now = Date.now();\n\n\t\t\t\tif ( touchEndEvent && state.overlayEnabled ) {\n\t\t\t\t\tconst deltaX =\n\t\t\t\t\t\ttouchEndEvent.clientX - touchStartEvent.startX;\n\t\t\t\t\tconst deltaY =\n\t\t\t\t\t\ttouchEndEvent.clientY - touchStartEvent.startY;\n\t\t\t\t\tconst absDeltaX = Math.abs( deltaX );\n\t\t\t\t\tconst absDeltaY = Math.abs( deltaY );\n\t\t\t\t\tconst elapsedMs = now - touchStartEvent.startTime;\n\t\t\t\t\tconst isHorizontalSwipe =\n\t\t\t\t\t\t// Swipe distance is greater than 50px\n\t\t\t\t\t\tabsDeltaX > 50 &&\n\t\t\t\t\t\t// Horizontal movement is much larger than the vertical movement\n\t\t\t\t\t\tabsDeltaX > absDeltaY * 1.5 &&\n\t\t\t\t\t\t// Fast action of less than 800ms\n\t\t\t\t\t\telapsedMs < 800;\n\n\t\t\t\t\tif ( isHorizontalSwipe ) {\n\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\tif ( deltaX < 0 ) {\n\t\t\t\t\t\t\tactions.showNextImage( event );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tactions.showPreviousImage( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tlastTouchTime = now;\n\t\t\t\tisTouching = false;\n\t\t\t} ),\n\t\t\thandleScroll() {\n\t\t\t\t// Prevents scrolling behaviors that trigger content shift while the\n\t\t\t\t// lightbox is open. It would be better to accomplish through CSS alone,\n\t\t\t\t// but using overflow: hidden is currently the only way to do so and\n\t\t\t\t// that causes a layout to shift and prevents the zoom animation from\n\t\t\t\t// working in some cases because it's not possible to account for the\n\t\t\t\t// layout shift when doing the animation calculations. Instead, it uses\n\t\t\t\t// JavaScript to prevent and reset the scrolling behavior.\n\t\t\t\tif ( state.overlayOpened ) {\n\t\t\t\t\t// Avoids overriding the scroll behavior on mobile devices because\n\t\t\t\t\t// doing so breaks the pinch to zoom functionality, and users should\n\t\t\t\t\t// be able to zoom in further on the high-res image.\n\t\t\t\t\tif ( ! isTouching && Date.now() - lastTouchTime > 450 ) {\n\t\t\t\t\t\t// It doesn't rely on `event.preventDefault()` to prevent scrolling\n\t\t\t\t\t\t// because the scroll event can't be canceled, so it resets the\n\t\t\t\t\t\t// position instead.\n\t\t\t\t\t\twindow.scrollTo(\n\t\t\t\t\t\t\tstate.scrollLeftReset,\n\t\t\t\t\t\t\tstate.scrollTopReset\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tpreloadImage() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\t// Bails if it has already been preloaded. This could help\n\t\t\t\t// prevent unnecessary preloading of the same image multiple times,\n\t\t\t\t// leading to duplicate link elements in the document head.\n\t\t\t\tif ( state.preloadedImageIds.has( imageId ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Link element to preload the image.\n\t\t\t\tconst imageMetadata = state.metadata[ imageId ];\n\t\t\t\tconst imageLink = document.createElement( 'link' );\n\t\t\t\timageLink.rel = 'preload';\n\t\t\t\timageLink.as = 'image';\n\t\t\t\timageLink.href = getImageSrc( imageMetadata );\n\n\t\t\t\t// Apply srcset if available for responsive preloading\n\t\t\t\tconst srcset = getImageSrcset( imageMetadata );\n\t\t\t\tif ( srcset ) {\n\t\t\t\t\timageLink.setAttribute( 'imagesrcset', srcset );\n\t\t\t\t\timageLink.setAttribute( 'imagesizes', '100vw' );\n\t\t\t\t}\n\n\t\t\t\tdocument.head.appendChild( imageLink );\n\t\t\t\tstate.preloadedImageIds.add( imageId );\n\t\t\t},\n\t\t\tpreloadImageWithDelay() {\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\tactions.cancelPreload();\n\n\t\t\t\t// Set a new timer to preload the image after a short delay.\n\t\t\t\tconst timerId = setTimeout(\n\t\t\t\t\twithScope( () => {\n\t\t\t\t\t\tactions.preloadImage();\n\t\t\t\t\t\tstate.preloadTimers.delete( imageId );\n\t\t\t\t\t} ),\n\t\t\t\t\tIMAGE_PRELOAD_DELAY\n\t\t\t\t);\n\t\t\t\tstate.preloadTimers.set( imageId, timerId );\n\t\t\t},\n\t\t\tcancelPreload() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tif ( state.preloadTimers.has( imageId ) ) {\n\t\t\t\t\tclearTimeout( state.preloadTimers.get( imageId ) );\n\t\t\t\t\tstate.preloadTimers.delete( imageId );\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\tcallbacks: {\n\t\t\tsetOverlayStyles() {\n\t\t\t\tif ( ! state.overlayEnabled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth: originalWidth,\n\t\t\t\t\toffsetHeight: originalHeight,\n\t\t\t\t} = state.selectedImage.imageRef;\n\t\t\t\tlet { x: screenPosX, y: screenPosY } =\n\t\t\t\t\tstate.selectedImage.imageRef.getBoundingClientRect();\n\n\t\t\t\t// Natural ratio of the image clicked to open the lightbox.\n\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t// Original ratio of the image clicked to open the lightbox.\n\t\t\t\tconst originalRatio = originalWidth / originalHeight;\n\n\t\t\t\t// If it has object-fit: contain, recalculates the original sizes\n\t\t\t\t// and the screen position without the blank spaces.\n\t\t\t\tif ( state.selectedImage.scaleAttr === 'contain' ) {\n\t\t\t\t\tif ( naturalRatio > originalRatio ) {\n\t\t\t\t\t\tconst heightWithoutSpace = originalWidth / naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the top space.\n\t\t\t\t\t\tscreenPosY +=\n\t\t\t\t\t\t\t( originalHeight - heightWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalHeight = heightWithoutSpace;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst widthWithoutSpace = originalHeight * naturalRatio;\n\t\t\t\t\t\t// Recalculates screen position without the left space.\n\t\t\t\t\t\tscreenPosX += ( originalWidth - widthWithoutSpace ) / 2;\n\t\t\t\t\t\toriginalWidth = widthWithoutSpace;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Typically, it uses the image's full-sized dimensions. If those\n\t\t\t\t// dimensions have not been set (i.e. an external image with only one\n\t\t\t\t// size), the image's dimensions in the lightbox are the same\n\t\t\t\t// as those of the image in the content.\n\t\t\t\tconst imgMaxWidth = parseFloat(\n\t\t\t\t\tstate.selectedImage.targetWidth &&\n\t\t\t\t\t\tstate.selectedImage.targetWidth !== 'none'\n\t\t\t\t\t\t? state.selectedImage.targetWidth\n\t\t\t\t\t\t: naturalWidth\n\t\t\t\t);\n\t\t\t\tconst imgMaxHeight = parseFloat(\n\t\t\t\t\tstate.selectedImage.targetHeight &&\n\t\t\t\t\t\tstate.selectedImage.targetHeight !== 'none'\n\t\t\t\t\t\t? state.selectedImage.targetHeight\n\t\t\t\t\t\t: naturalHeight\n\t\t\t\t);\n\n\t\t\t\t// Ratio of the biggest image stored in the database.\n\t\t\t\tconst fullSizeRatio = imgMaxWidth / imgMaxHeight;\n\t\t\t\tlet containerWidth = imgMaxWidth;\n\t\t\t\tlet containerHeight = imgMaxHeight;\n\n\t\t\t\t// If the image has been pixelated on purpose, it keeps that size.\n\t\t\t\tif (\n\t\t\t\t\toriginalWidth > containerWidth ||\n\t\t\t\t\toriginalHeight > containerHeight\n\t\t\t\t) {\n\t\t\t\t\tcontainerWidth = originalWidth;\n\t\t\t\t\tcontainerHeight = originalHeight;\n\t\t\t\t}\n\n\t\t\t\t// Calculates the final lightbox image size and the scale factor.\n\t\t\t\t// MaxWidth is either the window container (accounting for padding) or\n\t\t\t\t// the image resolution.\n\n\t\t\t\t// 480px width or less\n\t\t\t\tlet horizontalPadding = 0;\n\t\t\t\tlet verticalPadding = 160;\n\t\t\t\t// Greater than 480px wide and less than or equal to 960px\n\t\t\t\tif ( 480 < window.innerWidth ) {\n\t\t\t\t\thorizontalPadding = 80;\n\t\t\t\t\tverticalPadding = 160;\n\t\t\t\t}\n\t\t\t\t// Greater than 960px wide\n\t\t\t\tif ( 960 < window.innerWidth ) {\n\t\t\t\t\thorizontalPadding = state.hasNavigation ? 320 : 80;\n\t\t\t\t\tverticalPadding = 80;\n\t\t\t\t}\n\n\t\t\t\tconst targetMaxWidth = Math.min(\n\t\t\t\t\twindow.innerWidth - horizontalPadding,\n\t\t\t\t\tcontainerWidth\n\t\t\t\t);\n\t\t\t\tconst targetMaxHeight = Math.min(\n\t\t\t\t\twindow.innerHeight - verticalPadding,\n\t\t\t\t\tcontainerHeight\n\t\t\t\t);\n\t\t\t\tconst targetContainerRatio = targetMaxWidth / targetMaxHeight;\n\n\t\t\t\tif ( fullSizeRatio > targetContainerRatio ) {\n\t\t\t\t\t// If targetMaxWidth is reached before targetMaxHeight.\n\t\t\t\t\tcontainerWidth = targetMaxWidth;\n\t\t\t\t\tcontainerHeight = containerWidth / fullSizeRatio;\n\t\t\t\t} else {\n\t\t\t\t\t// If targetMaxHeight is reached before targetMaxWidth.\n\t\t\t\t\tcontainerHeight = targetMaxHeight;\n\t\t\t\t\tcontainerWidth = containerHeight * fullSizeRatio;\n\t\t\t\t}\n\n\t\t\t\tconst hasCroppedSource =\n\t\t\t\t\tnaturalRatio.toFixed( 2 ) !== fullSizeRatio.toFixed( 2 );\n\t\t\t\tconst sourceRatio = hasCroppedSource\n\t\t\t\t\t? naturalRatio\n\t\t\t\t\t: fullSizeRatio;\n\n\t\t\t\t// Include any crop already applied to the thumbnail file.\n\t\t\t\tconst containerScale = Math.max(\n\t\t\t\t\toriginalWidth / containerWidth,\n\t\t\t\t\toriginalHeight / containerHeight,\n\t\t\t\t\toriginalWidth / ( containerHeight * sourceRatio ),\n\t\t\t\t\t( originalHeight * sourceRatio ) / containerWidth\n\t\t\t\t);\n\t\t\t\tconst thumbnailWidth = originalWidth / containerScale;\n\t\t\t\tconst thumbnailHeight = originalHeight / containerScale;\n\t\t\t\tconst cropX = ( containerWidth - thumbnailWidth ) / 2;\n\t\t\t\tconst cropY = ( containerHeight - thumbnailHeight ) / 2;\n\t\t\t\tscreenPosX -= cropX * containerScale;\n\t\t\t\tscreenPosY -= cropY * containerScale;\n\n\t\t\t\t// As of this writing, using the calculations above will render the\n\t\t\t\t// lightbox with a small, erroneous whitespace on the left side of the\n\t\t\t\t// image in iOS Safari, perhaps due to an inconsistency in how browsers\n\t\t\t\t// handle absolute positioning and CSS transformation. In any case,\n\t\t\t\t// adding 1 pixel to the container width and height solves the problem,\n\t\t\t\t// though this can be removed if the issue is fixed in the future.\n\t\t\t\tstate.overlayStyles = `\n\t\t\t\t\t--wp--lightbox-initial-top-position: ${ screenPosY }px;\n\t\t\t\t\t--wp--lightbox-initial-left-position: ${ screenPosX }px;\n\t\t\t\t\t--wp--lightbox-container-width: ${ containerWidth + 1 }px;\n\t\t\t\t\t--wp--lightbox-container-height: ${ containerHeight + 1 }px;\n\t\t\t\t\t--wp--lightbox-image-width: ${ containerWidth }px;\n\t\t\t\t\t--wp--lightbox-image-height: ${ containerHeight }px;\n\t\t\t\t\t--wp--lightbox-initial-clip: inset(${ cropY }px ${ cropX }px);\n\t\t\t\t\t--wp--lightbox-thumbnail-width: ${\n\t\t\t\t\t\thasCroppedSource ? thumbnailWidth : containerWidth\n\t\t\t\t\t}px;\n\t\t\t\t\t--wp--lightbox-thumbnail-height: ${\n\t\t\t\t\t\thasCroppedSource ? thumbnailHeight : containerHeight\n\t\t\t\t\t}px;\n\t\t\t\t\t--wp--lightbox-scale: ${ containerScale };\n\t\t\t\t\t--wp--lightbox-scrollbar-width: ${\n\t\t\t\t\t\twindow.innerWidth - document.documentElement.clientWidth\n\t\t\t\t\t}px;\n\t\t\t\t`;\n\t\t\t},\n\t\t\tsetButtonStyles() {\n\t\t\t\tconst { ref } = getElement();\n\n\t\t\t\t// This guard prevents errors in images with the `srcset`\n\t\t\t\t// attribute, which can dispatch `load` events even after DOM\n\t\t\t\t// removal. Preact doesn't automatically clean up `load` event\n\t\t\t\t// listeners on unmounted `img` elements (see\n\t\t\t\t// https://github.com/preactjs/preact/issues/3141).\n\t\t\t\tif ( ! ref ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { imageId } = getContext();\n\n\t\t\t\tstate.metadata[ imageId ].imageRef = ref;\n\t\t\t\tstate.metadata[ imageId ].currentSrc = ref.currentSrc;\n\n\t\t\t\tconst {\n\t\t\t\t\tnaturalWidth,\n\t\t\t\t\tnaturalHeight,\n\t\t\t\t\toffsetWidth,\n\t\t\t\t\toffsetHeight,\n\t\t\t\t} = ref;\n\n\t\t\t\t// If the image isn't loaded yet, it can't calculate where the button\n\t\t\t\t// should be.\n\t\t\t\tif ( naturalWidth === 0 || naturalHeight === 0 ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst figure = ref.parentElement;\n\t\t\t\tconst figureWidth = ref.parentElement.clientWidth;\n\n\t\t\t\t// It needs special handling for the height because a caption will cause\n\t\t\t\t// the figure to be taller than the image, which means it needs to\n\t\t\t\t// account for that when calculating the placement of the button in the\n\t\t\t\t// top right corner of the image.\n\t\t\t\tlet figureHeight = ref.parentElement.clientHeight;\n\t\t\t\tconst caption = figure.querySelector( 'figcaption' );\n\t\t\t\tif ( caption ) {\n\t\t\t\t\tconst captionComputedStyle =\n\t\t\t\t\t\twindow.getComputedStyle( caption );\n\t\t\t\t\tif (\n\t\t\t\t\t\t! [ 'absolute', 'fixed' ].includes(\n\t\t\t\t\t\t\tcaptionComputedStyle.position\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tfigureHeight =\n\t\t\t\t\t\t\tfigureHeight -\n\t\t\t\t\t\t\tcaption.offsetHeight -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginTop ) -\n\t\t\t\t\t\t\tparseFloat( captionComputedStyle.marginBottom );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst buttonOffsetTop = figureHeight - offsetHeight;\n\t\t\t\tconst buttonOffsetRight = figureWidth - offsetWidth;\n\n\t\t\t\tlet buttonTop = buttonOffsetTop + 16;\n\t\t\t\tlet buttonRight = buttonOffsetRight + 16;\n\n\t\t\t\t// In the case of an image with object-fit: contain, the size of the\n\t\t\t\t// <img> element can be larger than the image itself, so it needs to\n\t\t\t\t// calculate where to place the button.\n\t\t\t\tif ( state.metadata[ imageId ].scaleAttr === 'contain' ) {\n\t\t\t\t\t// Natural ratio of the image.\n\t\t\t\t\tconst naturalRatio = naturalWidth / naturalHeight;\n\t\t\t\t\t// Offset ratio of the image.\n\t\t\t\t\tconst offsetRatio = offsetWidth / offsetHeight;\n\n\t\t\t\t\tif ( naturalRatio >= offsetRatio ) {\n\t\t\t\t\t\t// If it reaches the width first, it keeps the width and compute the\n\t\t\t\t\t\t// height.\n\t\t\t\t\t\tconst referenceHeight = offsetWidth / naturalRatio;\n\t\t\t\t\t\tbuttonTop =\n\t\t\t\t\t\t\t( offsetHeight - referenceHeight ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetTop +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t\tbuttonRight = buttonOffsetRight + 16;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If it reaches the height first, it keeps the height and compute\n\t\t\t\t\t\t// the width.\n\t\t\t\t\t\tconst referenceWidth = offsetHeight * naturalRatio;\n\t\t\t\t\t\tbuttonTop = buttonOffsetTop + 16;\n\t\t\t\t\t\tbuttonRight =\n\t\t\t\t\t\t\t( offsetWidth - referenceWidth ) / 2 +\n\t\t\t\t\t\t\tbuttonOffsetRight +\n\t\t\t\t\t\t\t16;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tstate.metadata[ imageId ].buttonTop = buttonTop;\n\t\t\t\tstate.metadata[ imageId ].buttonRight = buttonRight;\n\t\t\t},\n\t\t\tsetOverlayFocus() {\n\t\t\t\tif ( state.overlayEnabled ) {\n\t\t\t\t\t// Moves the focus to the dialog when it opens.\n\t\t\t\t\tconst { ref } = getElement();\n\t\t\t\t\tref.focus();\n\t\t\t\t}\n\t\t\t},\n\t\t\tsetInertElements() {\n\t\t\t\tif ( ! state.overlayEnabled ) {\n\t\t\t\t\tinertElements.forEach( ( el ) =>\n\t\t\t\t\t\tel.removeAttribute( 'inert' )\n\t\t\t\t\t);\n\t\t\t\t\tinertElements = [];\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Inerts the overlay's siblings at each level, not its ancestors.\n\t\t\t\tconst { ref } = getElement();\n\t\t\t\tlet node = ref;\n\t\t\t\twhile ( node && node !== document.body && node.parentElement ) {\n\t\t\t\t\tfor ( const sibling of node.parentElement.children ) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tsibling !== node &&\n\t\t\t\t\t\t\t! sibling.hasAttribute( 'inert' )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tsibling.setAttribute( 'inert', '' );\n\t\t\t\t\t\t\tinertElements.push( sibling );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tnode = node.parentElement;\n\t\t\t\t}\n\t\t\t},\n\t\t\tinitTriggerButton() {\n\t\t\t\tconst { imageId } = getContext();\n\t\t\t\tconst { ref } = getElement();\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|
|
49
49
|
"link": true
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
+
"dimensions": {
|
|
53
|
+
"minHeight": true,
|
|
54
|
+
"minWidth": true
|
|
55
|
+
},
|
|
52
56
|
"html": false,
|
|
53
57
|
"spacing": {
|
|
54
58
|
"margin": true,
|
|
55
59
|
"padding": true
|
|
56
60
|
},
|
|
61
|
+
"__experimentalBorder": {
|
|
62
|
+
"color": true,
|
|
63
|
+
"radius": true,
|
|
64
|
+
"style": true,
|
|
65
|
+
"width": true
|
|
66
|
+
},
|
|
57
67
|
"shadow": true,
|
|
58
68
|
"typography": {
|
|
59
69
|
"fontSize": true,
|
package/build/list/block.json
CHANGED
|
@@ -58,6 +58,15 @@
|
|
|
58
58
|
"fontSize": true
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
|
+
"background": {
|
|
62
|
+
"backgroundImage": true,
|
|
63
|
+
"backgroundSize": true,
|
|
64
|
+
"gradient": true,
|
|
65
|
+
"__experimentalDefaultControls": {
|
|
66
|
+
"backgroundImage": true,
|
|
67
|
+
"gradient": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
61
70
|
"color": {
|
|
62
71
|
"gradients": true,
|
|
63
72
|
"link": true,
|
|
@@ -74,6 +83,7 @@
|
|
|
74
83
|
"padding": false
|
|
75
84
|
}
|
|
76
85
|
},
|
|
86
|
+
"shadow": true,
|
|
77
87
|
"__unstablePasteTextInline": true,
|
|
78
88
|
"__experimentalOnMerge": true,
|
|
79
89
|
"__experimentalSlashInserter": true,
|
|
@@ -83,7 +93,8 @@
|
|
|
83
93
|
"listView": true
|
|
84
94
|
},
|
|
85
95
|
"selectors": {
|
|
86
|
-
"border": ".wp-block-list:not(.wp-block-list .wp-block-list)"
|
|
96
|
+
"border": ".wp-block-list:not(.wp-block-list .wp-block-list)",
|
|
97
|
+
"shadow": ".wp-block-list:not(.wp-block-list .wp-block-list)"
|
|
87
98
|
},
|
|
88
99
|
"editorStyle": "wp-block-list-editor",
|
|
89
100
|
"style": "wp-block-list"
|
|
@@ -24,6 +24,11 @@
|
|
|
24
24
|
"html": false,
|
|
25
25
|
"className": false,
|
|
26
26
|
"splitting": true,
|
|
27
|
+
"background": {
|
|
28
|
+
"backgroundImage": true,
|
|
29
|
+
"backgroundSize": true,
|
|
30
|
+
"gradient": true
|
|
31
|
+
},
|
|
27
32
|
"__experimentalBorder": {
|
|
28
33
|
"color": true,
|
|
29
34
|
"radius": true,
|
|
@@ -46,6 +51,7 @@
|
|
|
46
51
|
"padding": false
|
|
47
52
|
}
|
|
48
53
|
},
|
|
54
|
+
"shadow": true,
|
|
49
55
|
"typography": {
|
|
50
56
|
"fontSize": true,
|
|
51
57
|
"lineHeight": true,
|
|
@@ -65,6 +71,7 @@
|
|
|
65
71
|
},
|
|
66
72
|
"selectors": {
|
|
67
73
|
"root": ".wp-block-list > li",
|
|
68
|
-
"border": ".wp-block-list:not(.wp-block-list .wp-block-list) > li"
|
|
74
|
+
"border": ".wp-block-list:not(.wp-block-list .wp-block-list) > li",
|
|
75
|
+
"shadow": ".wp-block-list:not(.wp-block-list .wp-block-list) > li"
|
|
69
76
|
}
|
|
70
77
|
}
|
|
@@ -38,15 +38,19 @@ __export(list_item_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(list_item_exports);
|
|
39
39
|
var import_icons = require("@wordpress/icons");
|
|
40
40
|
var import_block_editor = require("@wordpress/block-editor");
|
|
41
|
+
var import_blocks = require("@wordpress/blocks");
|
|
41
42
|
var import_init_block = __toESM(require("../utils/init-block.cjs"));
|
|
42
43
|
var import_block = __toESM(require("./block.json"));
|
|
43
44
|
var import_edit = __toESM(require("./edit.cjs"));
|
|
44
45
|
var import_save = __toESM(require("./save.cjs"));
|
|
45
46
|
var import_transforms = __toESM(require("./transforms.cjs"));
|
|
46
47
|
var import_lock_unlock = require("../lock-unlock.cjs");
|
|
48
|
+
var { editableRootKey } = (0, import_lock_unlock.unlock)(import_blocks.privateApis);
|
|
47
49
|
var { name } = import_block.default;
|
|
48
50
|
var settings = {
|
|
49
51
|
icon: import_icons.listItem,
|
|
52
|
+
// Opt into the editing host behaviour privately, like the paragraph.
|
|
53
|
+
[editableRootKey]: true,
|
|
50
54
|
edit: import_edit.default,
|
|
51
55
|
save: import_save.default,
|
|
52
56
|
merge(attributes, attributesToMerge) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/list-item/index.js"],
|
|
4
|
-
"sourcesContent": ["import { listItem as icon } from '@wordpress/icons';\nimport { privateApis } from '@wordpress/block-editor';\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\tsave,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\t...attributes,\n\t\t\tcontent: attributes.content + attributesToMerge.content,\n\t\t};\n\t},\n\ttransforms,\n\t[ unlock( privateApis ).requiresWrapperOnCopy ]: true,\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasContent = content?.trim().length > 0;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasContent ) ) {\n\t\t\treturn customName || content;\n\t\t}\n\n\t\tif ( context === 'breadcrumb' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,0BAA4B;AAC5B,wBAAsB;AACtB,mBAAqB;AACrB,kBAAiB;AACjB,kBAAiB;AACjB,wBAAuB;AACvB,yBAAuB;AAEvB,IAAM,EAAE,KAAK,IAAI,
|
|
6
|
-
"names": ["metadata", "icon", "edit", "save", "transforms", "initBlock", "metadata"]
|
|
4
|
+
"sourcesContent": ["import { listItem as icon } from '@wordpress/icons';\nimport { privateApis } from '@wordpress/block-editor';\nimport { privateApis as blocksPrivateApis } from '@wordpress/blocks';\nimport initBlock from '../utils/init-block';\nimport metadata from './block.json';\nimport edit from './edit';\nimport save from './save';\nimport transforms from './transforms';\nimport { unlock } from '../lock-unlock';\n\nconst { editableRootKey } = unlock( blocksPrivateApis );\n\nconst { name } = metadata;\n\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\t// Opt into the editing host behaviour privately, like the paragraph.\n\t[ editableRootKey ]: true,\n\tedit,\n\tsave,\n\tmerge( attributes, attributesToMerge ) {\n\t\treturn {\n\t\t\t...attributes,\n\t\t\tcontent: attributes.content + attributesToMerge.content,\n\t\t};\n\t},\n\ttransforms,\n\t[ unlock( privateApis ).requiresWrapperOnCopy ]: true,\n\t__experimentalLabel( attributes, { context } ) {\n\t\tconst { content } = attributes;\n\n\t\tconst customName = attributes?.metadata?.name;\n\t\tconst hasContent = content?.trim().length > 0;\n\n\t\t// In the list view, use the block's content as the label.\n\t\t// If the content is empty, fall back to the default label.\n\t\tif ( context === 'list-view' && ( customName || hasContent ) ) {\n\t\t\treturn customName || content;\n\t\t}\n\n\t\tif ( context === 'breadcrumb' && customName ) {\n\t\t\treturn customName;\n\t\t}\n\t},\n};\n\nexport const init = () => initBlock( { name, metadata, settings } );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,+BAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,0BAA4B;AAC5B,oBAAiD;AACjD,wBAAsB;AACtB,mBAAqB;AACrB,kBAAiB;AACjB,kBAAiB;AACjB,wBAAuB;AACvB,yBAAuB;AAEvB,IAAM,EAAE,gBAAgB,QAAI,2BAAQ,cAAAC,WAAkB;AAEtD,IAAM,EAAE,KAAK,IAAI,aAAAD;AAIV,IAAM,WAAW;AAAA,EACvB,mBAAAE;AAAA;AAAA,EAEA,CAAE,eAAgB,GAAG;AAAA,EACrB,kBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,MAAO,YAAY,mBAAoB;AACtC,WAAO;AAAA,MACN,GAAG;AAAA,MACH,SAAS,WAAW,UAAU,kBAAkB;AAAA,IACjD;AAAA,EACD;AAAA,EACA,8BAAAC;AAAA,EACA,KAAE,2BAAQ,+BAAY,EAAE,qBAAsB,GAAG;AAAA,EACjD,oBAAqB,YAAY,EAAE,QAAQ,GAAI;AAC9C,UAAM,EAAE,QAAQ,IAAI;AAEpB,UAAM,aAAa,YAAY,UAAU;AACzC,UAAM,aAAa,SAAS,KAAK,EAAE,SAAS;AAI5C,QAAK,YAAY,gBAAiB,cAAc,aAAe;AAC9D,aAAO,cAAc;AAAA,IACtB;AAEA,QAAK,YAAY,gBAAgB,YAAa;AAC7C,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEO,IAAM,OAAO,UAAM,kBAAAC,SAAW,EAAE,MAAM,uBAAAC,SAAU,SAAS,CAAE;",
|
|
6
|
+
"names": ["metadata", "blocksPrivateApis", "icon", "edit", "save", "transforms", "initBlock", "metadata"]
|
|
7
7
|
}
|