jekyll-image-links 0.1.1 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e391437b6c74200eefcd0026a8f0dee1e707f1f0188e75d3c35fc8111ab81400
4
- data.tar.gz: 5ef0710e6e06906de397ae632571d815869072d83ce1ef8cae59d410a91ed849
3
+ metadata.gz: 8c93aabbb9cd425deaacd65bb022a89262b8799957d6817e58cd1a3ada3d640c
4
+ data.tar.gz: fe69971d43751442a622ed8571760f0ed5ebce7f74aca6bfa13942e9ec6b4521
5
5
  SHA512:
6
- metadata.gz: a961e536a871fb7130c8a9217864180879c6828f71ba9a059540e18ef03996ec7ab843273f963f05ae013b954d7deec071422c339a611dd66c6d2641f49055cb
7
- data.tar.gz: 39b53f9b774e08f6f5ecf51ca809bff1c7b83377ccb983abd8a7422725529874575ebb9d9aaa5feab90a693380a6b4a34c2b95b70bebbe7ca82350e5e2df6349
6
+ metadata.gz: 6e741d3e37b158ee40f071ea3fe8a833427e4a7321df076e3ecedb68ed6b67e48449be4764c105179364dc15c0c6465617bbbaedf123d8dc3e54e5bd6959196a
7
+ data.tar.gz: a74db4de8774eea228b99baca8a3d237807bd7167aa5c1e242798a6c9ec693e29905eba853563c2711c09ed78f3d15bcb97673abe1e2dc3e86306849003214fb
data/README.md CHANGED
@@ -2,17 +2,21 @@
2
2
 
3
3
  A Jekyll plugin for [Just the Docs](https://github.com/just-the-docs/just-the-docs) sites that adds clickable polygon regions on images.
4
4
 
5
- Inspired by the Dynamic Map Viewer in [5etools](https://github.com/5etools/5etools-src), which uses custom JavaScript (not HTML `<map>` tags) to define polygon click areas on large map images.
5
+ Inspired by the Dynamic Map Viewer in [5etools](https://github.com/5etools/5etools-src).
6
6
 
7
7
  ## Features
8
8
 
9
- - Define polygon click regions in Markdown using a Liquid tag
9
+ - Define polygon click regions in Markdown using a Liquid tag inline or using an external YAML file
10
10
  - Click a region to navigate to an internal or external link
11
+ - Automatic point rescaling for variable image dimensions (i.e. `width: 50%`)
11
12
  - Hold **Shift** while clicking to open the link in a new tab
12
- - Integrates with [jekyll-hover-popup](https://github.com/directsun/jekyll-hover-popup) when both plugins are enabled: region clicks open pinned hover-popup windows (no page darkening), and the map viewer opens inside a hover-popup window too
13
13
  - Optional **Dynamic Map Viewer** button with zoom, pan, and region highlighting
14
14
  - Optional region labels overlaid on the image
15
- - Load region data inline or from a YAML file
15
+ - Integrates with [jekyll-hover-popup](https://github.com/sunflowermans/hover-popup) when both plugins are enabled:
16
+ - Map viewer opens inside a hover-popup window
17
+ - Region clicks open pinned hover-popup windows
18
+
19
+ https://github.com/user-attachments/assets/9b2f123b-56a4-43f4-984f-2dbfa7b844f9
16
20
 
17
21
  ## Install
18
22
 
@@ -95,13 +99,6 @@ When `width` and `height` are in the YAML file, you can omit them from the tag a
95
99
  {% endimage_map %}
96
100
  ```
97
101
 
98
- Legacy form still works — numeric `width`/`height` on the tag or `<img>` define the native coordinate system when the YAML file does not include them:
99
-
100
- ```liquid
101
- {% image_map src="/assets/maps/example.webp" width="1200" height="800" file="assets/maps/example-map.yml" %}
102
- {% endimage_map %}
103
- ```
104
-
105
102
  ### Tag options
106
103
 
107
104
  | Attribute | Description |
@@ -119,7 +116,7 @@ Legacy form still works — numeric `width`/`height` on the tag or `<img>` defin
119
116
 
120
117
  ### Manual HTML (portable markup)
121
118
 
122
- You can also write image maps directly in Markdown using `{::nomarkdown}` blocks. Only an `<img>` tag is required — no `<figure>` wrapper. Put configuration on the image itself using `data-jil-*` attributes.
119
+ You can also write image maps directly in Markdown using `{::nomarkdown}` blocks. Only an `<img>` tag is required. Put configuration on the image itself using `data-jil-*` attributes.
123
120
 
124
121
  Store the **native** image dimensions in the YAML file. Region `points` use that coordinate system. Use CSS on the `<img>` for **display** size (percentages, max width/height, and so on). At build time those display styles are moved to the surrounding `.jil-map-host` wrapper so percentage sizes resolve against the page layout correctly.
125
122
 
@@ -153,16 +150,7 @@ regions:
153
150
  points: [[120, 80], [420, 80], [420, 320], [120, 320]]
154
151
  ```
155
152
 
156
- Display sizing alternatives on the `<img>`:
157
-
158
- | Attribute | Example | Description |
159
- |-----------|---------|-------------|
160
- | `style` | `width:100%;max-width:900px;height:auto` | Full CSS control (recommended) |
161
- | `width` / `height` | `width="100%"` or `width="800"` | Display size when YAML provides native dimensions |
162
- | `data-jil-max-width` | `900px` or `80%` | Shorthand for `max-width` |
163
- | `data-jil-max-height` | `600px` | Shorthand for `max-height` |
164
-
165
- Portable images are detected by `class="jil-map-image"` together with region data (`data-jil-regions`, an adjacent `<script class="jil-regions-data">` block, or legacy `data-jil-map="true"`). Legacy `<figure data-jil-map="true">` markup is still supported.
153
+ Qualified images are detected by `class="jil-map-image"` together with region data (`data-jil-regions`)
166
154
 
167
155
  | Attribute | Description |
168
156
  |-----------|-------------|
@@ -175,21 +163,10 @@ Portable images are detected by `class="jil-map-image"` together with region dat
175
163
 
176
164
  ## Coordinate system
177
165
 
178
- Region `points` use the image's native pixel coordinates, matching the 5etools `mapRegions` format. Define the native size once in the YAML file (`width` and `height`) or on the tag/image when not using YAML dimensions. For example, a 4937×3439 map uses coordinates in that range.
166
+ Region `points` use the image's native pixel coordinates. Define the native size once in the YAML file (`width` and `height`) or on the tag/image when not using YAML dimensions. For example, a 4937×3439 map uses coordinates in that range.
179
167
 
180
168
  The plugin scales clicks from whatever size the image is displayed at back into that native coordinate system. Changing display size with CSS, percentages, or max width/height does not require editing region points.
181
169
 
182
- ## How this relates to 5etools
183
-
184
- 5etools stores regions as `mapRegions` on image entries in JSON data, then renders them with a custom `RenderMap` class (`js/render-map.js`) that:
185
-
186
- - draws the image on a `<canvas>`
187
- - overlays clickable polygons
188
- - uses a ray-casting algorithm for hit detection
189
- - opens linked adventure content in hover windows
190
-
191
- This plugin uses the same polygon coordinate model and the same hit-detection approach, adapted for Jekyll pages with normal `href` links instead of 5etools' internal book area IDs.
192
-
193
170
  ## License
194
171
 
195
- MIT
172
+ [MIT](LICENSE)
@@ -248,7 +248,21 @@
248
248
  });
249
249
  zoomFit.addEventListener("click", fitZoom);
250
250
 
251
+ let dragStart = null;
252
+ let didPan = false;
253
+
254
+ const cursorForPoint = (event) => {
255
+ const point = canvasPointFromEvent(canvas, state.zoom, event);
256
+ const region = firstIntersectedRegion(mapData.regions, point);
257
+ return region ? "pointer" : "grab";
258
+ };
259
+
251
260
  canvas.addEventListener("click", (event) => {
261
+ if (didPan) {
262
+ didPan = false;
263
+ event.preventDefault();
264
+ return;
265
+ }
252
266
  const point = canvasPointFromEvent(canvas, state.zoom, event);
253
267
  const region = firstIntersectedRegion(mapData.regions, point);
254
268
  if (!region) return;
@@ -257,15 +271,21 @@
257
271
  });
258
272
 
259
273
  canvas.addEventListener("mousemove", (event) => {
260
- const point = canvasPointFromEvent(canvas, state.zoom, event);
261
- const region = firstIntersectedRegion(mapData.regions, point);
262
- canvas.style.cursor = region ? "pointer" : "grab";
274
+ if (dragStart) return;
275
+ canvas.style.cursor = cursorForPoint(event);
263
276
  });
264
277
 
265
- let dragStart = null;
266
278
  canvas.addEventListener("mousedown", (event) => {
267
- if (event.button !== 2) return;
279
+ // Left-drag empty areas to pan; right-drag pans from anywhere.
280
+ if (event.button === 0) {
281
+ const point = canvasPointFromEvent(canvas, state.zoom, event);
282
+ if (firstIntersectedRegion(mapData.regions, point)) return;
283
+ } else if (event.button !== 2) {
284
+ return;
285
+ }
286
+
268
287
  event.preventDefault();
288
+ didPan = false;
269
289
  dragStart = {
270
290
  x: event.clientX,
271
291
  y: event.clientY,
@@ -275,15 +295,25 @@
275
295
  canvas.style.cursor = "grabbing";
276
296
  });
277
297
 
278
- window.addEventListener("mouseup", () => {
298
+ window.addEventListener("mouseup", (event) => {
299
+ if (!dragStart) return;
279
300
  dragStart = null;
280
- canvas.style.cursor = "grab";
301
+ canvas.style.cursor = cursorForPoint(event);
302
+ // Clear after the trailing click so a pan doesn't open a region.
303
+ if (didPan) {
304
+ setTimeout(() => {
305
+ didPan = false;
306
+ }, 0);
307
+ }
281
308
  });
282
309
 
283
310
  window.addEventListener("mousemove", (event) => {
284
311
  if (!dragStart) return;
285
- scroll.scrollLeft = dragStart.scrollLeft + (dragStart.x - event.clientX);
286
- scroll.scrollTop = dragStart.scrollTop + (dragStart.y - event.clientY);
312
+ const dx = dragStart.x - event.clientX;
313
+ const dy = dragStart.y - event.clientY;
314
+ if (Math.abs(dx) > 2 || Math.abs(dy) > 2) didPan = true;
315
+ scroll.scrollLeft = dragStart.scrollLeft + dx;
316
+ scroll.scrollTop = dragStart.scrollTop + dy;
287
317
  });
288
318
 
289
319
  canvas.addEventListener("contextmenu", (event) => event.preventDefault());
@@ -11,8 +11,7 @@ module Jekyll
11
11
  html = doc.output.to_s
12
12
  next unless html.include?('data-jil-image-map="true"') || MapRenderer.portable_markup?(html)
13
13
 
14
- assets_path = cfg["assets_path"] || "/assets/jekyll-image-links"
15
- assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
14
+ assets_path = resolve_assets_path(site, cfg)
16
15
 
17
16
  begin
18
17
  html = MapRenderer.enhance_html(html, site: site, page: doc, cfg: cfg)
@@ -23,6 +22,21 @@ module Jekyll
23
22
  end
24
23
  end
25
24
 
25
+ # Site-root path (e.g. "/assets/jekyll-image-links"), with site.baseurl prepended.
26
+ def self.resolve_assets_path(site, cfg)
27
+ assets_path = cfg["assets_path"] || "/assets/jekyll-image-links"
28
+ assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
29
+
30
+ baseurl = site.config["baseurl"].to_s
31
+ baseurl = "" if baseurl == "/"
32
+ baseurl = baseurl.chomp("/")
33
+
34
+ return assets_path if baseurl.empty?
35
+ return assets_path if assets_path == baseurl || assets_path.start_with?("#{baseurl}/")
36
+
37
+ "#{baseurl}#{assets_path}"
38
+ end
39
+
26
40
  def self.build_jil_config(site, cfg)
27
41
  return { useHoverPopup: false } if cfg["use_hover_popup"] == false
28
42
  return { useHoverPopup: true } if cfg["use_hover_popup"] == true
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module ImageLinks
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-image-links
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun