@riebeckite/plugin-share 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -122,7 +122,6 @@ optional `className` is added to the root without replacing them.
122
122
  - `buildShareUrl(service, target, instance?)` — build one service URL
123
123
  - `buildShareLinks(options, target)` — build every link-bearing service
124
124
  - `renderShareControls(options, target)` — render the controls HTML
125
- - `injectShareControls(html, block, placement)` — insert into a note fragment
126
125
  - `initShare()` — client initializer (also via
127
126
  `@riebeckite/plugin-share/client`)
128
127
  - Constants: `SHARE_SERVICES`, `SHARE_ATTRIBUTE`, `SHARE_ROOT_CLASS`,
@@ -134,10 +133,9 @@ optional `className` is added to the root without replacing them.
134
133
 
135
134
  - Share URLs are fixed at build time. A full rebuild always recomputes them.
136
135
  - Mastodon cannot be enabled without a concrete instance.
137
- - The plugin inserts into the note fragment; a Site that owns its layout can
138
- move the controls with CSS or omit them per page.
136
+ - The plugin contributes controls to `article.before-content` for `top` and
137
+ `article.footer` for `bottom`; a Site places those semantic slots in its layout.
139
138
 
140
139
  ## See also
141
140
 
142
141
  - [Plugin guide](../../../docs/en/docs/reference/plugin-api.md)
143
-
package/README_ja.md CHANGED
@@ -122,7 +122,6 @@ import "@riebeckite/plugin-share/style.css";
122
122
  - `buildShareUrl(service, target, instance?)` — 1 サービスの URL を組み立てる
123
123
  - `buildShareLinks(options, target)` — リンクを持つサービスをすべて組み立てる
124
124
  - `renderShareControls(options, target)` — コントロールの HTML を生成する
125
- - `injectShareControls(html, block, placement)` — ノート断片に挿入する
126
125
  - `initShare()` — ブラウザ初期化関数(`@riebeckite/plugin-share/client` からも
127
126
  読み込める)
128
127
  - 定数: `SHARE_SERVICES`, `SHARE_ATTRIBUTE`, `SHARE_ROOT_CLASS`,
@@ -134,10 +133,9 @@ import "@riebeckite/plugin-share/style.css";
134
133
 
135
134
  - 共有 URL はビルド時に確定します。再ビルドすれば常に正しく再計算されます。
136
135
  - Mastodon は具体的なインスタンスなしには有効化できません。
137
- - プラグインはノート断片に挿入します。レイアウトを所有する Site は、CSS で
138
- 位置を変えたり、ページごとに出力しない選択もできます。
136
+ - `top` は `article.before-content`、`bottom` は `article.footer` にコントロールを
137
+ 提供します。Site は layout でその semantic slot を配置します。
139
138
 
140
139
  ## 関連
141
140
 
142
141
  - [プラグインガイド](../../../docs/ja/docs/reference/plugin-api.md)
143
-
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ShareOptions } from "./src/types.js";
2
2
  export { initShare } from "./src/client.js";
3
3
  export { DEFAULT_SHARE_ARIA_LABEL, DEFAULT_SHARE_COPIED_LABEL, DEFAULT_SHARE_COPY_FAILED_LABEL, DEFAULT_SHARE_LABELS, DEFAULT_SHARE_PLACEMENT, DEFAULT_SHARE_SERVICES, resolveShareOptions, validateShareOptions, } from "./src/options.js";
4
- export { injectShareControls, renderShareControls, SHARE_ATTRIBUTE, SHARE_ROOT_CLASS, } from "./src/render.js";
4
+ export { renderShareControls, SHARE_ATTRIBUTE, SHARE_ROOT_CLASS, } from "./src/render.js";
5
5
  export { buildAbsoluteUrl, buildShareLinks, buildShareUrl, normalizeMastodonInstance, type ShareTarget, } from "./src/services.js";
6
6
  export type { ResolvedShareOptions, ShareLink, ShareOptions, SharePlacement, ShareService, } from "./src/types.js";
7
7
  export { SHARE_SERVICES } from "./src/types.js";
@@ -10,8 +10,8 @@ export declare const SHARE_PLUGIN_NAME = "share";
10
10
  * Per-article share controls.
11
11
  *
12
12
  * For every entry the plugin builds absolute share URLs for the configured
13
- * services and injects the controls into the manifest entry HTML, which is the
14
- * final rendering source. The links are ordinary anchors, so they work without
13
+ * services and contributes the controls to an article layout slot. The links
14
+ * are ordinary anchors, so they work without
15
15
  * JavaScript; only the copy-link action is enhanced at runtime.
16
16
  */
17
17
  export declare function share(options?: ShareOptions): import("@riebeckite/core").RiebeckitePlugin<ShareOptions>;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // index.ts
2
2
  import {
3
+ appendContentBodySlot,
3
4
  createClientEntry,
4
5
  createStyleAsset,
5
6
  definePlugin
@@ -228,29 +229,6 @@ function renderShareControls(options, target) {
228
229
  const ariaLabel = escapeHtmlAttribute(options.ariaLabel);
229
230
  return `<div class="${escapeHtmlAttribute(rootClass)}" ${SHARE_ATTRIBUTE} data-rr-share-placement="${escapeHtmlAttribute(options.placement)}" role="group" aria-label="${ariaLabel}"><ul class="${SHARE_ROOT_CLASS}__list">${items}${copyItem}</ul><p class="${SHARE_ROOT_CLASS}__status" role="status" aria-live="polite"></p></div>`;
230
231
  }
231
- function injectShareControls(html, block, placement) {
232
- if (block === "" || html.includes(SHARE_ATTRIBUTE)) return html;
233
- if (placement === "top") {
234
- const article = /<article\b[^>]*>/i.exec(html);
235
- if (article) {
236
- const end = article.index + article[0].length;
237
- return `${html.slice(0, end)}${block}${html.slice(end)}`;
238
- }
239
- const body = /<body\b[^>]*>/i.exec(html);
240
- if (body) {
241
- const end = body.index + body[0].length;
242
- return `${html.slice(0, end)}${block}${html.slice(end)}`;
243
- }
244
- return `${block}
245
- ${html}`;
246
- }
247
- const closeIndex = html.toLowerCase().lastIndexOf("</article>");
248
- if (closeIndex !== -1) {
249
- return `${html.slice(0, closeIndex)}${block}${html.slice(closeIndex)}`;
250
- }
251
- return `${html}
252
- ${block}`;
253
- }
254
232
  function renderLinkItem(link) {
255
233
  const modifier = `${SHARE_ROOT_CLASS}__link--${link.service}`;
256
234
  return `<li class="${SHARE_ROOT_CLASS}__item"><a class="${SHARE_ROOT_CLASS}__link ${modifier}" href="${escapeHtmlAttribute(link.url)}" target="_blank" rel="noopener noreferrer" data-share-service="${escapeHtmlAttribute(link.service)}">${escapeHtml(link.label)}</a></li>`;
@@ -339,14 +317,15 @@ function share(options = {}) {
339
317
  const { manifest, config } = context;
340
318
  if (!config) return;
341
319
  for (const entry of manifest.entries) {
342
- if (!entry.html || entry.html.includes(SHARE_ATTRIBUTE)) continue;
343
320
  const block = renderShareControls(resolved, {
344
321
  url: buildAbsoluteUrl(config, entry.permalink),
345
322
  title: entry.title
346
323
  });
347
324
  if (block === "") continue;
348
- const html = injectShareControls(entry.html, block, resolved.placement);
349
- entry.html = html;
325
+ const slot = resolved.placement === "top" ? "article.before-content" : "article.footer";
326
+ if (!hasSlotFragment(entry.bodySlots?.[slot], block)) {
327
+ appendContentBodySlot(entry, slot, block);
328
+ }
350
329
  }
351
330
  },
352
331
  assets: [createStyleAsset(SHARE_PLUGIN_NAME)],
@@ -354,6 +333,13 @@ function share(options = {}) {
354
333
  });
355
334
  }
356
335
  var sharePlugin = share;
336
+ function hasSlotFragment(slot, fragment) {
337
+ return slot === fragment || slot?.startsWith(`${fragment}
338
+ `) || slot?.endsWith(`
339
+ ${fragment}`) || slot?.includes(`
340
+ ${fragment}
341
+ `) || false;
342
+ }
357
343
  export {
358
344
  DEFAULT_SHARE_ARIA_LABEL,
359
345
  DEFAULT_SHARE_COPIED_LABEL,
@@ -369,7 +355,6 @@ export {
369
355
  buildShareLinks,
370
356
  buildShareUrl,
371
357
  initShare,
372
- injectShareControls,
373
358
  normalizeMastodonInstance,
374
359
  renderShareControls,
375
360
  resolveShareOptions,
@@ -1,5 +1,5 @@
1
1
  import { type ShareTarget } from "./services.js";
2
- import type { ResolvedShareOptions, SharePlacement } from "./types.js";
2
+ import type { ResolvedShareOptions } from "./types.js";
3
3
  /** Attribute that marks the generated controls for tests, CSS, and JS. */
4
4
  export declare const SHARE_ATTRIBUTE = "data-rr-share";
5
5
  /** Stable root hook every rendered set carries, even with a custom class. */
@@ -9,9 +9,3 @@ export declare const SHARE_ROOT_CLASS = "rr-share";
9
9
  * service can be rendered, so callers can leave the HTML untouched.
10
10
  */
11
11
  export declare function renderShareControls(options: ResolvedShareOptions, target: ShareTarget): string;
12
- /**
13
- * Inserts the rendered controls into a note fragment. Top placement lands
14
- * after the opening `<article>` (or at the start) and bottom placement lands
15
- * before the closing `</article>` (or at the end).
16
- */
17
- export declare function injectShareControls(html: string, block: string, placement: SharePlacement): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-share",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,7 @@
21
21
  "./style.css": "./style.css"
22
22
  },
23
23
  "dependencies": {
24
- "@riebeckite/core": "0.0.15"
24
+ "@riebeckite/core": "0.0.17"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsx": "^4.22.4"
package/style.css CHANGED
@@ -72,8 +72,3 @@
72
72
  .rr-share__status:empty {
73
73
  display: none;
74
74
  }
75
-
76
- html[data-theme="dark"] .rr-share,
77
- html.dark .rr-share {
78
- --rr-share-ink: var(--rb-color-paper, #ffffff);
79
- }