@wordpress/block-library 8.23.0 → 8.24.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.
Files changed (136) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/block/edit.js +8 -11
  3. package/build/block/edit.js.map +1 -1
  4. package/build/block/edit.native.js +3 -4
  5. package/build/block/edit.native.js.map +1 -1
  6. package/build/button/edit.js +4 -7
  7. package/build/button/edit.js.map +1 -1
  8. package/build/column/edit.js +1 -1
  9. package/build/column/edit.js.map +1 -1
  10. package/build/column/edit.native.js +1 -1
  11. package/build/column/edit.native.js.map +1 -1
  12. package/build/cover/edit/index.js +2 -1
  13. package/build/cover/edit/index.js.map +1 -1
  14. package/build/file/edit.js +8 -9
  15. package/build/file/edit.js.map +1 -1
  16. package/build/file/view.js +4 -6
  17. package/build/file/view.js.map +1 -1
  18. package/build/group/edit.js +3 -7
  19. package/build/group/edit.js.map +1 -1
  20. package/build/image/edit.js +17 -18
  21. package/build/image/edit.js.map +1 -1
  22. package/build/image/edit.native.js +22 -15
  23. package/build/image/edit.native.js.map +1 -1
  24. package/build/image/image.js +35 -27
  25. package/build/image/image.js.map +1 -1
  26. package/build/image/index.js +2 -3
  27. package/build/image/index.js.map +1 -1
  28. package/build/image/view.js +233 -268
  29. package/build/image/view.js.map +1 -1
  30. package/build/navigation/view.js +153 -176
  31. package/build/navigation/view.js.map +1 -1
  32. package/build/navigation-link/index.js +2 -1
  33. package/build/navigation-link/index.js.map +1 -1
  34. package/build/pattern/edit.js +1 -3
  35. package/build/pattern/edit.js.map +1 -1
  36. package/build/post-template/edit.js +1 -1
  37. package/build/post-template/edit.js.map +1 -1
  38. package/build/query/view.js +52 -60
  39. package/build/query/view.js.map +1 -1
  40. package/build/search/view.js +66 -74
  41. package/build/search/view.js.map +1 -1
  42. package/build/utils/remove-anchor-tag.js +17 -0
  43. package/build/utils/remove-anchor-tag.js.map +1 -0
  44. package/build-module/block/edit.js +8 -11
  45. package/build-module/block/edit.js.map +1 -1
  46. package/build-module/block/edit.native.js +3 -4
  47. package/build-module/block/edit.native.js.map +1 -1
  48. package/build-module/button/edit.js +4 -7
  49. package/build-module/button/edit.js.map +1 -1
  50. package/build-module/column/edit.js +1 -1
  51. package/build-module/column/edit.js.map +1 -1
  52. package/build-module/column/edit.native.js +1 -1
  53. package/build-module/column/edit.native.js.map +1 -1
  54. package/build-module/cover/edit/index.js +2 -1
  55. package/build-module/cover/edit/index.js.map +1 -1
  56. package/build-module/file/edit.js +8 -9
  57. package/build-module/file/edit.js.map +1 -1
  58. package/build-module/file/view.js +5 -7
  59. package/build-module/file/view.js.map +1 -1
  60. package/build-module/group/edit.js +3 -7
  61. package/build-module/group/edit.js.map +1 -1
  62. package/build-module/image/edit.js +18 -19
  63. package/build-module/image/edit.js.map +1 -1
  64. package/build-module/image/edit.native.js +23 -16
  65. package/build-module/image/edit.native.js.map +1 -1
  66. package/build-module/image/image.js +36 -28
  67. package/build-module/image/image.js.map +1 -1
  68. package/build-module/image/index.js +2 -3
  69. package/build-module/image/index.js.map +1 -1
  70. package/build-module/image/view.js +234 -269
  71. package/build-module/image/view.js.map +1 -1
  72. package/build-module/navigation/view.js +154 -177
  73. package/build-module/navigation/view.js.map +1 -1
  74. package/build-module/navigation-link/index.js +2 -1
  75. package/build-module/navigation-link/index.js.map +1 -1
  76. package/build-module/pattern/edit.js +1 -3
  77. package/build-module/pattern/edit.js.map +1 -1
  78. package/build-module/post-template/edit.js +1 -1
  79. package/build-module/post-template/edit.js.map +1 -1
  80. package/build-module/query/view.js +53 -61
  81. package/build-module/query/view.js.map +1 -1
  82. package/build-module/search/view.js +67 -75
  83. package/build-module/search/view.js.map +1 -1
  84. package/build-module/utils/remove-anchor-tag.js +11 -0
  85. package/build-module/utils/remove-anchor-tag.js.map +1 -0
  86. package/build-style/cover/style-rtl.css +14 -14
  87. package/build-style/cover/style.css +14 -14
  88. package/build-style/editor-rtl.css +6 -9
  89. package/build-style/editor.css +6 -9
  90. package/build-style/gallery/style-rtl.css +28 -0
  91. package/build-style/gallery/style.css +28 -0
  92. package/build-style/image/editor-rtl.css +0 -3
  93. package/build-style/image/editor.css +0 -3
  94. package/build-style/style-rtl.css +42 -14
  95. package/build-style/style.css +42 -14
  96. package/package.json +32 -32
  97. package/src/block/edit.js +18 -19
  98. package/src/block/edit.native.js +5 -13
  99. package/src/button/edit.js +6 -6
  100. package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
  101. package/src/buttons/test/edit.native.js +0 -27
  102. package/src/column/edit.js +1 -1
  103. package/src/column/edit.native.js +1 -1
  104. package/src/cover/edit/index.js +1 -0
  105. package/src/cover/style.scss +1 -1
  106. package/src/cover/test/edit.js +1 -1
  107. package/src/editor.scss +6 -6
  108. package/src/file/edit.js +11 -10
  109. package/src/file/index.php +30 -11
  110. package/src/file/view.js +5 -7
  111. package/src/gallery/style.scss +1 -0
  112. package/src/group/edit.js +3 -11
  113. package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
  114. package/src/heading/test/index.native.js +40 -0
  115. package/src/image/block.json +2 -3
  116. package/src/image/edit.js +16 -21
  117. package/src/image/edit.native.js +17 -18
  118. package/src/image/editor.scss +0 -7
  119. package/src/image/image.js +48 -51
  120. package/src/image/index.php +54 -45
  121. package/src/image/view.js +278 -334
  122. package/src/navigation/index.php +19 -10
  123. package/src/navigation/view.js +159 -192
  124. package/src/navigation-link/block.json +2 -1
  125. package/src/paragraph/test/edit.native.js +37 -1
  126. package/src/pattern/edit.js +5 -3
  127. package/src/post-template/edit.js +1 -1
  128. package/src/query/index.php +36 -22
  129. package/src/query/view.js +58 -65
  130. package/src/query-pagination-next/index.php +3 -3
  131. package/src/query-pagination-numbers/index.php +1 -1
  132. package/src/query-pagination-previous/index.php +3 -3
  133. package/src/search/index.php +40 -40
  134. package/src/search/view.js +58 -63
  135. package/src/utils/remove-anchor-tag.js +10 -0
  136. package/tsconfig.json +1 -0
@@ -7,7 +7,7 @@ var _interactivity = require("@wordpress/interactivity");
7
7
 
8
8
  const focusableSelectors = ['a[href]', 'area[href]', 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])', 'select:not([disabled]):not([aria-hidden])', 'textarea:not([disabled]):not([aria-hidden])', 'button:not([disabled]):not([aria-hidden])', 'iframe', 'object', 'embed', '[contenteditable]', '[tabindex]:not([tabindex^="-"])'];
9
9
 
10
- /*
10
+ /**
11
11
  * Stores a context-bound scroll handler.
12
12
  *
13
13
  * This callback could be defined inline inside of the store
@@ -22,7 +22,7 @@ const focusableSelectors = ['a[href]', 'area[href]', 'input:not([disabled]):not(
22
22
  */
23
23
  let scrollCallback;
24
24
 
25
- /*
25
+ /**
26
26
  * Tracks whether user is touching screen; used to
27
27
  * differentiate behavior for touch and mouse input.
28
28
  *
@@ -30,7 +30,7 @@ let scrollCallback;
30
30
  */
31
31
  let isTouching = false;
32
32
 
33
- /*
33
+ /**
34
34
  * Tracks the last time the screen was touched; used to
35
35
  * differentiate behavior for touch and mouse input.
36
36
  *
@@ -38,7 +38,7 @@ let isTouching = false;
38
38
  */
39
39
  let lastTouchTime = 0;
40
40
 
41
- /*
41
+ /**
42
42
  * Lightbox page-scroll handler: prevents scrolling.
43
43
  *
44
44
  * This handler is added to prevent scrolling behaviors that
@@ -54,304 +54,269 @@ let lastTouchTime = 0;
54
54
  * instead to not rely on JavaScript, but this seems to be the best approach
55
55
  * for now that provides the best visual experience.
56
56
  *
57
- * @param {Object} context Interactivity page context?
57
+ * @param {Object} ctx Context object with the `core/image` namespace.
58
58
  */
59
- function handleScroll(context) {
59
+ function handleScroll(ctx) {
60
60
  // We can't override the scroll behavior on mobile devices
61
61
  // because doing so breaks the pinch to zoom functionality, and we
62
62
  // want to allow users to zoom in further on the high-res image.
63
63
  if (!isTouching && Date.now() - lastTouchTime > 450) {
64
64
  // We are unable to use event.preventDefault() to prevent scrolling
65
65
  // because the scroll event can't be canceled, so we reset the position instead.
66
- window.scrollTo(context.core.image.scrollLeftReset, context.core.image.scrollTopReset);
66
+ window.scrollTo(ctx.scrollLeftReset, ctx.scrollTopReset);
67
67
  }
68
68
  }
69
- (0, _interactivity.store)({
69
+ const {
70
+ state,
71
+ actions,
72
+ callbacks
73
+ } = (0, _interactivity.store)('core/image', {
70
74
  state: {
71
- core: {
72
- image: {
73
- windowWidth: window.innerWidth,
74
- windowHeight: window.innerHeight
75
+ windowWidth: window.innerWidth,
76
+ windowHeight: window.innerHeight,
77
+ get roleAttribute() {
78
+ const ctx = (0, _interactivity.getContext)();
79
+ return ctx.lightboxEnabled ? 'dialog' : null;
80
+ },
81
+ get ariaModal() {
82
+ const ctx = (0, _interactivity.getContext)();
83
+ return ctx.lightboxEnabled ? 'true' : null;
84
+ },
85
+ get dialogLabel() {
86
+ const ctx = (0, _interactivity.getContext)();
87
+ return ctx.lightboxEnabled ? ctx.dialogLabel : null;
88
+ },
89
+ get lightboxObjectFit() {
90
+ const ctx = (0, _interactivity.getContext)();
91
+ if (ctx.initialized) {
92
+ return 'cover';
75
93
  }
94
+ },
95
+ get enlargedImgSrc() {
96
+ const ctx = (0, _interactivity.getContext)();
97
+ return ctx.initialized ? ctx.imageUploadedSrc : 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
76
98
  }
77
99
  },
78
100
  actions: {
79
- core: {
80
- image: {
81
- showLightbox: ({
82
- context,
83
- event
84
- }) => {
85
- // We can't initialize the lightbox until the reference
86
- // image is loaded, otherwise the UX is broken.
87
- if (!context.core.image.imageLoaded) {
88
- return;
89
- }
90
- context.core.image.initialized = true;
91
- context.core.image.lastFocusedElement = window.document.activeElement;
92
- context.core.image.scrollDelta = 0;
93
- context.core.image.pointerType = event.pointerType;
94
- context.core.image.lightboxEnabled = true;
95
- setStyles(context, context.core.image.imageRef);
96
- context.core.image.scrollTopReset = window.pageYOffset || document.documentElement.scrollTop;
101
+ showLightbox(event) {
102
+ const ctx = (0, _interactivity.getContext)();
103
+ // We can't initialize the lightbox until the reference
104
+ // image is loaded, otherwise the UX is broken.
105
+ if (!ctx.imageLoaded) {
106
+ return;
107
+ }
108
+ ctx.initialized = true;
109
+ ctx.lastFocusedElement = window.document.activeElement;
110
+ ctx.scrollDelta = 0;
111
+ ctx.pointerType = event.pointerType;
112
+ ctx.lightboxEnabled = true;
113
+ setStyles(ctx, ctx.imageRef);
114
+ ctx.scrollTopReset = window.pageYOffset || document.documentElement.scrollTop;
97
115
 
98
- // In most cases, this value will be 0, but this is included
99
- // in case a user has created a page with horizontal scrolling.
100
- context.core.image.scrollLeftReset = window.pageXOffset || document.documentElement.scrollLeft;
116
+ // In most cases, this value will be 0, but this is included
117
+ // in case a user has created a page with horizontal scrolling.
118
+ ctx.scrollLeftReset = window.pageXOffset || document.documentElement.scrollLeft;
101
119
 
102
- // We define and bind the scroll callback here so
103
- // that we can pass the context and as an argument.
104
- // We may be able to change this in the future if we
105
- // define the scroll callback in the store instead, but
106
- // this approach seems to tbe clearest for now.
107
- scrollCallback = handleScroll.bind(null, context);
120
+ // We define and bind the scroll callback here so
121
+ // that we can pass the context and as an argument.
122
+ // We may be able to change this in the future if we
123
+ // define the scroll callback in the store instead, but
124
+ // this approach seems to tbe clearest for now.
125
+ scrollCallback = handleScroll.bind(null, ctx);
108
126
 
109
- // We need to add a scroll event listener to the window
110
- // here because we are unable to otherwise access it via
111
- // the Interactivity API directives. If we add a native way
112
- // to access the window, we can remove this.
113
- window.addEventListener('scroll', scrollCallback, false);
114
- },
115
- hideLightbox: async ({
116
- context
117
- }) => {
118
- context.core.image.hideAnimationEnabled = true;
119
- if (context.core.image.lightboxEnabled) {
120
- // We want to wait until the close animation is completed
121
- // before allowing a user to scroll again. The duration of this
122
- // animation is defined in the styles.scss and depends on if the
123
- // animation is 'zoom' or 'fade', but in any case we should wait
124
- // a few milliseconds longer than the duration, otherwise a user
125
- // may scroll too soon and cause the animation to look sloppy.
126
- setTimeout(function () {
127
- window.removeEventListener('scroll', scrollCallback);
128
- // If we don't delay before changing the focus,
129
- // the focus ring will appear on Firefox before
130
- // the image has finished animating, which looks broken.
131
- context.core.image.lightboxTriggerRef.focus({
132
- preventScroll: true
133
- });
134
- }, 450);
135
- context.core.image.lightboxEnabled = false;
136
- }
137
- },
138
- handleKeydown: ({
139
- context,
140
- actions,
141
- event
142
- }) => {
143
- if (context.core.image.lightboxEnabled) {
144
- if (event.key === 'Tab' || event.keyCode === 9) {
145
- // If shift + tab it change the direction
146
- if (event.shiftKey && window.document.activeElement === context.core.image.firstFocusableElement) {
147
- event.preventDefault();
148
- context.core.image.lastFocusableElement.focus();
149
- } else if (!event.shiftKey && window.document.activeElement === context.core.image.lastFocusableElement) {
150
- event.preventDefault();
151
- context.core.image.firstFocusableElement.focus();
152
- }
153
- }
154
- if (event.key === 'Escape' || event.keyCode === 27) {
155
- actions.core.image.hideLightbox({
156
- context,
157
- event
158
- });
159
- }
160
- }
161
- },
162
- // This is fired just by lazily loaded
163
- // images on the page, not all images.
164
- handleLoad: ({
165
- context,
166
- effects,
167
- ref
168
- }) => {
169
- context.core.image.imageLoaded = true;
170
- context.core.image.imageCurrentSrc = ref.currentSrc;
171
- effects.core.image.setButtonStyles({
172
- context,
173
- ref
127
+ // We need to add a scroll event listener to the window
128
+ // here because we are unable to otherwise access it via
129
+ // the Interactivity API directives. If we add a native way
130
+ // to access the window, we can remove this.
131
+ window.addEventListener('scroll', scrollCallback, false);
132
+ },
133
+ hideLightbox() {
134
+ const ctx = (0, _interactivity.getContext)();
135
+ ctx.hideAnimationEnabled = true;
136
+ if (ctx.lightboxEnabled) {
137
+ // We want to wait until the close animation is completed
138
+ // before allowing a user to scroll again. The duration of this
139
+ // animation is defined in the styles.scss and depends on if the
140
+ // animation is 'zoom' or 'fade', but in any case we should wait
141
+ // a few milliseconds longer than the duration, otherwise a user
142
+ // may scroll too soon and cause the animation to look sloppy.
143
+ setTimeout(function () {
144
+ window.removeEventListener('scroll', scrollCallback);
145
+ // If we don't delay before changing the focus,
146
+ // the focus ring will appear on Firefox before
147
+ // the image has finished animating, which looks broken.
148
+ ctx.lightboxTriggerRef.focus({
149
+ preventScroll: true
174
150
  });
175
- },
176
- handleTouchStart: () => {
177
- isTouching = true;
178
- },
179
- handleTouchMove: ({
180
- context,
181
- event
182
- }) => {
183
- // On mobile devices, we want to prevent triggering the
184
- // scroll event because otherwise the page jumps around as
185
- // we reset the scroll position. This also means that closing
186
- // the lightbox requires that a user perform a simple tap. This
187
- // may be changed in the future if we find a better alternative
188
- // to override or reset the scroll position during swipe actions.
189
- if (context.core.image.lightboxEnabled) {
151
+ }, 450);
152
+ ctx.lightboxEnabled = false;
153
+ }
154
+ },
155
+ handleKeydown(event) {
156
+ const ctx = (0, _interactivity.getContext)();
157
+ if (ctx.lightboxEnabled) {
158
+ if (event.key === 'Tab' || event.keyCode === 9) {
159
+ // If shift + tab it change the direction
160
+ if (event.shiftKey && window.document.activeElement === ctx.firstFocusableElement) {
161
+ event.preventDefault();
162
+ ctx.lastFocusableElement.focus();
163
+ } else if (!event.shiftKey && window.document.activeElement === ctx.lastFocusableElement) {
190
164
  event.preventDefault();
165
+ ctx.firstFocusableElement.focus();
191
166
  }
192
- },
193
- handleTouchEnd: () => {
194
- // We need to wait a few milliseconds before resetting
195
- // to ensure that pinch to zoom works consistently
196
- // on mobile devices when the lightbox is open.
197
- lastTouchTime = Date.now();
198
- isTouching = false;
199
167
  }
200
- }
201
- }
202
- },
203
- selectors: {
204
- core: {
205
- image: {
206
- roleAttribute: ({
207
- context
208
- }) => {
209
- return context.core.image.lightboxEnabled ? 'dialog' : null;
210
- },
211
- ariaModal: ({
212
- context
213
- }) => {
214
- return context.core.image.lightboxEnabled ? 'true' : null;
215
- },
216
- dialogLabel: ({
217
- context
218
- }) => {
219
- return context.core.image.lightboxEnabled ? context.core.image.dialogLabel : null;
220
- },
221
- lightboxObjectFit: ({
222
- context
223
- }) => {
224
- if (context.core.image.initialized) {
225
- return 'cover';
226
- }
227
- },
228
- enlargedImgSrc: ({
229
- context
230
- }) => {
231
- return context.core.image.initialized ? context.core.image.imageUploadedSrc : 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
168
+ if (event.key === 'Escape' || event.keyCode === 27) {
169
+ actions.hideLightbox(event);
232
170
  }
233
171
  }
172
+ },
173
+ // This is fired just by lazily loaded
174
+ // images on the page, not all images.
175
+ handleLoad() {
176
+ const ctx = (0, _interactivity.getContext)();
177
+ const {
178
+ ref
179
+ } = (0, _interactivity.getElement)();
180
+ ctx.imageLoaded = true;
181
+ ctx.imageCurrentSrc = ref.currentSrc;
182
+ callbacks.setButtonStyles();
183
+ },
184
+ handleTouchStart() {
185
+ isTouching = true;
186
+ },
187
+ handleTouchMove(event) {
188
+ const ctx = (0, _interactivity.getContext)();
189
+ // On mobile devices, we want to prevent triggering the
190
+ // scroll event because otherwise the page jumps around as
191
+ // we reset the scroll position. This also means that closing
192
+ // the lightbox requires that a user perform a simple tap. This
193
+ // may be changed in the future if we find a better alternative
194
+ // to override or reset the scroll position during swipe actions.
195
+ if (ctx.lightboxEnabled) {
196
+ event.preventDefault();
197
+ }
198
+ },
199
+ handleTouchEnd() {
200
+ // We need to wait a few milliseconds before resetting
201
+ // to ensure that pinch to zoom works consistently
202
+ // on mobile devices when the lightbox is open.
203
+ lastTouchTime = Date.now();
204
+ isTouching = false;
234
205
  }
235
206
  },
236
- effects: {
237
- core: {
238
- image: {
239
- initOriginImage: ({
240
- context,
241
- ref
242
- }) => {
243
- context.core.image.imageRef = ref;
244
- context.core.image.lightboxTriggerRef = ref.parentElement.querySelector('.lightbox-trigger');
245
- if (ref.complete) {
246
- context.core.image.imageLoaded = true;
247
- context.core.image.imageCurrentSrc = ref.currentSrc;
248
- }
249
- },
250
- initLightbox: async ({
251
- context,
252
- ref
253
- }) => {
254
- if (context.core.image.lightboxEnabled) {
255
- const focusableElements = ref.querySelectorAll(focusableSelectors);
256
- context.core.image.firstFocusableElement = focusableElements[0];
257
- context.core.image.lastFocusableElement = focusableElements[focusableElements.length - 1];
207
+ callbacks: {
208
+ initOriginImage() {
209
+ const ctx = (0, _interactivity.getContext)();
210
+ const {
211
+ ref
212
+ } = (0, _interactivity.getElement)();
213
+ ctx.imageRef = ref;
214
+ ctx.lightboxTriggerRef = ref.parentElement.querySelector('.lightbox-trigger');
215
+ if (ref.complete) {
216
+ ctx.imageLoaded = true;
217
+ ctx.imageCurrentSrc = ref.currentSrc;
218
+ }
219
+ },
220
+ initLightbox() {
221
+ const ctx = (0, _interactivity.getContext)();
222
+ const {
223
+ ref
224
+ } = (0, _interactivity.getElement)();
225
+ if (ctx.lightboxEnabled) {
226
+ const focusableElements = ref.querySelectorAll(focusableSelectors);
227
+ ctx.firstFocusableElement = focusableElements[0];
228
+ ctx.lastFocusableElement = focusableElements[focusableElements.length - 1];
258
229
 
259
- // Move focus to the dialog when opening it.
260
- ref.focus();
261
- }
262
- },
263
- setButtonStyles: ({
264
- context,
265
- ref
266
- }) => {
267
- const {
268
- naturalWidth,
269
- naturalHeight,
270
- offsetWidth,
271
- offsetHeight
272
- } = ref;
230
+ // Move focus to the dialog when opening it.
231
+ ref.focus();
232
+ }
233
+ },
234
+ setButtonStyles() {
235
+ const {
236
+ ref
237
+ } = (0, _interactivity.getElement)();
238
+ const {
239
+ naturalWidth,
240
+ naturalHeight,
241
+ offsetWidth,
242
+ offsetHeight
243
+ } = ref;
273
244
 
274
- // If the image isn't loaded yet, we can't
275
- // calculate where the button should be.
276
- if (naturalWidth === 0 || naturalHeight === 0) {
277
- return;
278
- }
279
- const figure = ref.parentElement;
280
- const figureWidth = ref.parentElement.clientWidth;
245
+ // If the image isn't loaded yet, we can't
246
+ // calculate where the button should be.
247
+ if (naturalWidth === 0 || naturalHeight === 0) {
248
+ return;
249
+ }
250
+ const figure = ref.parentElement;
251
+ const figureWidth = ref.parentElement.clientWidth;
281
252
 
282
- // We need special handling for the height because
283
- // a caption will cause the figure to be taller than
284
- // the image, which means we need to account for that
285
- // when calculating the placement of the button in the
286
- // top right corner of the image.
287
- let figureHeight = ref.parentElement.clientHeight;
288
- const caption = figure.querySelector('figcaption');
289
- if (caption) {
290
- const captionComputedStyle = window.getComputedStyle(caption);
291
- if (!['absolute', 'fixed'].includes(captionComputedStyle.position)) {
292
- figureHeight = figureHeight - caption.offsetHeight - parseFloat(captionComputedStyle.marginTop) - parseFloat(captionComputedStyle.marginBottom);
293
- }
294
- }
295
- const buttonOffsetTop = figureHeight - offsetHeight;
296
- const buttonOffsetRight = figureWidth - offsetWidth;
253
+ // We need special handling for the height because
254
+ // a caption will cause the figure to be taller than
255
+ // the image, which means we need to account for that
256
+ // when calculating the placement of the button in the
257
+ // top right corner of the image.
258
+ let figureHeight = ref.parentElement.clientHeight;
259
+ const caption = figure.querySelector('figcaption');
260
+ if (caption) {
261
+ const captionComputedStyle = window.getComputedStyle(caption);
262
+ if (!['absolute', 'fixed'].includes(captionComputedStyle.position)) {
263
+ figureHeight = figureHeight - caption.offsetHeight - parseFloat(captionComputedStyle.marginTop) - parseFloat(captionComputedStyle.marginBottom);
264
+ }
265
+ }
266
+ const buttonOffsetTop = figureHeight - offsetHeight;
267
+ const buttonOffsetRight = figureWidth - offsetWidth;
268
+ const ctx = (0, _interactivity.getContext)();
297
269
 
298
- // In the case of an image with object-fit: contain, the
299
- // size of the <img> element can be larger than the image itself,
300
- // so we need to calculate where to place the button.
301
- if (context.core.image.scaleAttr === 'contain') {
302
- // Natural ratio of the image.
303
- const naturalRatio = naturalWidth / naturalHeight;
304
- // Offset ratio of the image.
305
- const offsetRatio = offsetWidth / offsetHeight;
306
- if (naturalRatio >= offsetRatio) {
307
- // If it reaches the width first, keep
308
- // the width and compute the height.
309
- const referenceHeight = offsetWidth / naturalRatio;
310
- context.core.image.imageButtonTop = (offsetHeight - referenceHeight) / 2 + buttonOffsetTop + 16;
311
- context.core.image.imageButtonRight = buttonOffsetRight + 16;
312
- } else {
313
- // If it reaches the height first, keep
314
- // the height and compute the width.
315
- const referenceWidth = offsetHeight * naturalRatio;
316
- context.core.image.imageButtonTop = buttonOffsetTop + 16;
317
- context.core.image.imageButtonRight = (offsetWidth - referenceWidth) / 2 + buttonOffsetRight + 16;
318
- }
319
- } else {
320
- context.core.image.imageButtonTop = buttonOffsetTop + 16;
321
- context.core.image.imageButtonRight = buttonOffsetRight + 16;
322
- }
323
- },
324
- setStylesOnResize: ({
325
- state,
326
- context,
327
- ref
328
- }) => {
329
- if (context.core.image.lightboxEnabled && (state.core.image.windowWidth || state.core.image.windowHeight)) {
330
- setStyles(context, ref);
331
- }
270
+ // In the case of an image with object-fit: contain, the
271
+ // size of the <img> element can be larger than the image itself,
272
+ // so we need to calculate where to place the button.
273
+ if (ctx.scaleAttr === 'contain') {
274
+ // Natural ratio of the image.
275
+ const naturalRatio = naturalWidth / naturalHeight;
276
+ // Offset ratio of the image.
277
+ const offsetRatio = offsetWidth / offsetHeight;
278
+ if (naturalRatio >= offsetRatio) {
279
+ // If it reaches the width first, keep
280
+ // the width and compute the height.
281
+ const referenceHeight = offsetWidth / naturalRatio;
282
+ ctx.imageButtonTop = (offsetHeight - referenceHeight) / 2 + buttonOffsetTop + 16;
283
+ ctx.imageButtonRight = buttonOffsetRight + 16;
284
+ } else {
285
+ // If it reaches the height first, keep
286
+ // the height and compute the width.
287
+ const referenceWidth = offsetHeight * naturalRatio;
288
+ ctx.imageButtonTop = buttonOffsetTop + 16;
289
+ ctx.imageButtonRight = (offsetWidth - referenceWidth) / 2 + buttonOffsetRight + 16;
332
290
  }
291
+ } else {
292
+ ctx.imageButtonTop = buttonOffsetTop + 16;
293
+ ctx.imageButtonRight = buttonOffsetRight + 16;
294
+ }
295
+ },
296
+ setStylesOnResize() {
297
+ const ctx = (0, _interactivity.getContext)();
298
+ const {
299
+ ref
300
+ } = (0, _interactivity.getElement)();
301
+ if (ctx.lightboxEnabled && (state.windowWidth || state.windowHeight)) {
302
+ setStyles(ctx, ref);
333
303
  }
334
304
  }
335
305
  }
336
- }, {
337
- afterLoad: ({
338
- state
339
- }) => {
340
- window.addEventListener('resize', debounce(() => {
341
- state.core.image.windowWidth = window.innerWidth;
342
- state.core.image.windowHeight = window.innerHeight;
343
- }));
344
- }
345
306
  });
307
+ window.addEventListener('resize', debounce(() => {
308
+ state.windowWidth = window.innerWidth;
309
+ state.windowHeight = window.innerHeight;
310
+ }));
346
311
 
347
- /*
312
+ /**
348
313
  * Computes styles for the lightbox and adds them to the document.
349
314
  *
350
315
  * @function
351
- * @param {Object} context - An Interactivity API context
352
- * @param {Object} event - A triggering event
316
+ * @param {Object} ctx - Context for the `core/image` namespace.
317
+ * @param {Object} ref - The element reference.
353
318
  */
354
- function setStyles(context, ref) {
319
+ function setStyles(ctx, ref) {
355
320
  // The reference img element lies adjacent
356
321
  // to the event target button in the DOM.
357
322
  let {
@@ -372,7 +337,7 @@ function setStyles(context, ref) {
372
337
 
373
338
  // If it has object-fit: contain, recalculate the original sizes
374
339
  // and the screen position without the blank spaces.
375
- if (context.core.image.scaleAttr === 'contain') {
340
+ if (ctx.scaleAttr === 'contain') {
376
341
  if (naturalRatio > originalRatio) {
377
342
  const heightWithoutSpace = originalWidth / naturalRatio;
378
343
  // Recalculate screen position without the top space.
@@ -391,8 +356,8 @@ function setStyles(context, ref) {
391
356
  // dimensions have not been set (i.e. an external image with only one size),
392
357
  // the image's dimensions in the lightbox are the same
393
358
  // as those of the image in the content.
394
- let imgMaxWidth = parseFloat(context.core.image.targetWidth !== 'none' ? context.core.image.targetWidth : naturalWidth);
395
- let imgMaxHeight = parseFloat(context.core.image.targetHeight !== 'none' ? context.core.image.targetHeight : naturalHeight);
359
+ let imgMaxWidth = parseFloat(ctx.targetWidth !== 'none' ? ctx.targetWidth : naturalWidth);
360
+ let imgMaxHeight = parseFloat(ctx.targetHeight !== 'none' ? ctx.targetHeight : naturalHeight);
396
361
 
397
362
  // Ratio of the biggest image stored in the database.
398
363
  let imgRatio = imgMaxWidth / imgMaxHeight;
@@ -503,12 +468,12 @@ function setStyles(context, ref) {
503
468
  `;
504
469
  }
505
470
 
506
- /*
471
+ /**
507
472
  * Debounces a function call.
508
473
  *
509
474
  * @function
510
475
  * @param {Function} func - A function to be called
511
- * @param {number} wait - The time to wait before calling the function
476
+ * @param {number} wait - The time to wait before calling the function
512
477
  */
513
478
  function debounce(func, wait = 50) {
514
479
  let timeout;