photosuite 0.1.0 → 0.1.2

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.
@@ -1 +1 @@
1
- function e(e){let t=e.parentElement;if(!t)return e;let n=e;e.tagName.toLowerCase()===`img`&&t&&t.tagName.toLowerCase()===`a`&&t.classList.contains(`glightbox`)&&(n=t);let r=n.parentElement;if(r&&r.classList.contains(`photosuite-item`))return r;let i=document.createElement(`div`);i.className=`photosuite-item`;let a=n.parentElement;return a?(a.replaceChild(i,n),i.appendChild(n),i):i}function t(t,n,r){let i=new Set,a=t=>{let n=e(t);i.has(n)||n.querySelector(`img`)&&(r(n),i.add(n))};document.querySelectorAll(t).forEach(e=>{e.querySelectorAll(n).forEach(a),e.querySelectorAll(`img`).forEach(a)})}function n(e){if(e.querySelector(`.photosuite-caption`))return;let t=e.querySelector(`img`);if(!t)return;let n=String(t.getAttribute(`alt`)||``).trim();if(!n)return;let r=document.createElement(`div`);r.className=`photosuite-caption`,r.textContent=n,e.appendChild(r)}function r(e){if(e.querySelector(`.photosuite-exif`))return;let t=document.createElement(`div`);t.className=`photosuite-exif`,e.appendChild(t)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
1
+ function e(e){let t=e.parentElement;if(!t)return e;let n=e;e.tagName.toLowerCase()===`img`&&t&&t.tagName.toLowerCase()===`a`&&t.classList.contains(`glightbox`)&&(n=t);let r=n.parentElement;if(r&&r.classList.contains(`photosuite-item`))return r;let i=document.createElement(`div`);i.className=`photosuite-item`;let a=n.parentElement;return a?(a.replaceChild(i,n),i.appendChild(n),i):i}function t(t,n,r){let i=new Set,a=t=>{let n=e(t);i.has(n)||n.querySelector(`img`)&&(r(n),i.add(n))};document.querySelectorAll(t).forEach(e=>{e.querySelectorAll(n).forEach(a),e.querySelectorAll(`img`).forEach(a)})}function n(e){if(e.querySelector(`.photosuite-caption`))return;let t=e.querySelector(`img`);if(!t)return;let n=String(t.getAttribute(`alt`)||``).trim();if(!n)return;let r=document.createElement(`div`);r.className=`photosuite-caption`,r.textContent=n,e.appendChild(r)}function r(e){let t=e.querySelector(`.photosuite-exif`);if(t){t.textContent?.trim()||t.remove();return}}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
@@ -29,8 +29,10 @@ function ensureCaption(e) {
29
29
  r.className = "photosuite-caption", r.textContent = n, e.appendChild(r);
30
30
  }
31
31
  function ensureExif(e) {
32
- if (e.querySelector(".photosuite-exif")) return;
33
- let t = document.createElement("div");
34
- t.className = "photosuite-exif", e.appendChild(t);
32
+ let t = e.querySelector(".photosuite-exif");
33
+ if (t) {
34
+ t.textContent?.trim() || t.remove();
35
+ return;
36
+ }
35
37
  }
36
38
  export { ensureExif as n, processMedia as r, ensureCaption as t };
@@ -1,4 +1,4 @@
1
- import { n as ensureExif, r as processMedia } from "./dom-CDvVCbvk.js";
1
+ import { n as ensureExif, r as processMedia } from "./dom-CLdyQVUy.js";
2
2
  async function enableExif(n, r) {
3
3
  await Promise.resolve({ }), processMedia(n, r, (t) => {
4
4
  ensureExif(t);
@@ -0,0 +1 @@
1
+ const e=require(`./dom-CJtH5lQe.cjs`);async function t(t,n){await Promise.resolve().then(()=>require(`./exif-DwHkZ3YD.cjs`)),e.r(t,n,t=>{e.n(t)})}exports.enableExif=t;
@@ -9,7 +9,7 @@ function sync(e, t) {
9
9
  if (!n) return;
10
10
  let r = n.currentSrc || n.src;
11
11
  r && e.getAttribute("href") !== r && e.setAttribute("href", r);
12
- let i = n.getAttribute("alt");
12
+ let i = String(n.getAttribute("alt") || "").trim();
13
13
  i && !e.dataset.title && (e.dataset.title = i), e.dataset.gallery || (e.dataset.gallery = t);
14
14
  }
15
15
  function loadCss(e) {
@@ -0,0 +1 @@
1
+ function e(e,t){let n=e.currentSrc||e.src||``;if(!n)return;let r=String(e.getAttribute(`alt`)||``).trim(),i=document.createElement(`a`);i.href=n,i.className=`glightbox`,i.dataset.gallery=t,r&&(i.dataset.title=r),e.parentElement.replaceChild(i,e),i.appendChild(e)}function t(e,t){let n=e.querySelector(`img`);if(!n)return;let r=n.currentSrc||n.src;r&&e.getAttribute(`href`)!==r&&e.setAttribute(`href`,r);let i=String(n.getAttribute(`alt`)||``).trim();i&&!e.dataset.title&&(e.dataset.title=i),e.dataset.gallery||(e.dataset.gallery=t)}function n(e){if(!e||document.querySelector(`link[href="${e}"]`))return;let t=document.createElement(`link`);t.rel=`stylesheet`,t.href=e,document.head.appendChild(t)}function r(e){return new Promise(t=>{if(!e||typeof window.GLightbox==`function`)return t();let n=document.createElement(`script`);n.src=e,n.onload=()=>t(),document.head.appendChild(n)})}async function i(i){let a=i.selector,o=i.scope,s=i.gallery,c=i.cssUrl||`https://cos.lhasa.icu/dist/glightbox/glightbox.min.css`,l=i.jsUrl||`https://cos.lhasa.icu/dist/glightbox/glightbox.min.js`,u=new Set,d=new Set;document.querySelectorAll(o).forEach(e=>{e.querySelectorAll(`img`).forEach(e=>u.add(e)),e.querySelectorAll(a).forEach(e=>d.add(e))}),u.forEach(t=>{let n=t.parentElement,r=n&&n.tagName.toLowerCase()===`a`,i=r&&n.classList.contains(`glightbox`);(!r||!i)&&e(t,s)}),d.forEach(e=>t(e,s)),n(c),await r(l),(()=>{let e=window.GLightbox;if(typeof e==`function`){let t=window.__glightboxInstance;t&&t.destroy&&t.destroy();let n=Object.assign({},i.options||{},{selector:a});window.__glightboxInstance=e(n)}})()}exports.initGlightboxModule=i;
@@ -0,0 +1 @@
1
+ const e=require(`./dom-CJtH5lQe.cjs`);async function t(t,n){await Promise.resolve().then(()=>require(`./image-alts-D2zawu5U.cjs`)),e.r(t,n,t=>{e.t(t)})}exports.enableImageAlts=t;
@@ -1,4 +1,4 @@
1
- import { r as processMedia, t as ensureCaption } from "./dom-CDvVCbvk.js";
1
+ import { r as processMedia, t as ensureCaption } from "./dom-CLdyQVUy.js";
2
2
  async function enableImageAlts(n, r) {
3
3
  await Promise.resolve({ }), processMedia(n, r, (e) => {
4
4
  ensureCaption(e);
@@ -13,6 +13,10 @@ export default function astroPhotosuite(options: PhotosuiteOptions): {
13
13
  "astro:config:setup": ({ injectScript, updateConfig }: any) => void;
14
14
  };
15
15
  };
16
+ /**
17
+ * 允许使用 import { photosuite } from 'photosuite' 语法
18
+ */
19
+ export declare const photosuite: typeof astroPhotosuite;
16
20
  export { imageUrl } from './remark/imageUrl';
17
21
  export { exiftoolVendored } from './rehype/exiftoolVendored';
18
22
  export type { PhotosuiteOptions, ImageUrlOptions } from './types';
@@ -1 +1 @@
1
- function e(e){let t=e.scope;if(!t){console.warn(`Photosuite: 'scope' option is required.`);return}let n=e.selector??`a.glightbox`,r=e.gallery??`markdown`,i=e.glightbox??!0,a=e.imageAlts??!0,o=e.exif??!0,s=async()=>{if(!document.querySelector(t))return;let s=[];i&&s.push(Promise.resolve().then(()=>require(`./glightbox-D14wFv8j.cjs`)).then(i=>i.initGlightboxModule({selector:n,scope:t,gallery:r,options:e.glightboxOptions,cssUrl:e.glightboxCssUrl,jsUrl:e.glightboxJsUrl}))),a&&s.push(Promise.resolve().then(()=>require(`./imageAlts-CAX8Uksx.cjs`)).then(e=>e.enableImageAlts(t,n))),o&&s.push(Promise.resolve().then(()=>require(`./exif-DYpA7_Ip.cjs`)).then(e=>e.enableExif(t,n))),s.length&&Promise.all(s).catch(()=>{})};document.readyState===`complete`||document.readyState===`interactive`?s():document.addEventListener(`DOMContentLoaded`,s)}exports.photosuite=e;
1
+ function e(e){let t=e.scope;if(!t){console.warn(`Photosuite: 'scope' option is required.`);return}let n=e.selector??`a.glightbox`,r=e.gallery??`markdown`,i=e.glightbox??!0,a=e.imageAlts??!0,o=e.exif??!0,s=async()=>{if(!document.querySelector(t))return;let s=[];i&&s.push(Promise.resolve().then(()=>require(`./glightbox-lE-btsco.cjs`)).then(i=>i.initGlightboxModule({selector:n,scope:t,gallery:r,options:e.glightboxOptions,cssUrl:e.glightboxCssUrl,jsUrl:e.glightboxJsUrl}))),a&&s.push(Promise.resolve().then(()=>require(`./imageAlts-Bt8VtEfG.cjs`)).then(e=>e.enableImageAlts(t,n))),o&&s.push(Promise.resolve().then(()=>require(`./exif-CBo-Frgp.cjs`)).then(e=>e.enableExif(t,n))),s.length&&Promise.all(s).catch(()=>{})};document.readyState===`complete`||document.readyState===`interactive`?s():document.addEventListener(`DOMContentLoaded`,s)}exports.photosuite=e;
@@ -1,2 +1,2 @@
1
- :root{--photosuite-caption-size:12px;--photosuite-caption-color:#fff;--photosuite-exif-size:12px;--photosuite-exif-color:#fff;--photosuite-exif-bg:linear-gradient(to bottom,#0009,transparent);--photosuite-caption-bg:linear-gradient(to right,#000c,transparent)}:where(.photosuite-item img){display:block;box-shadow:none!important;border:none!important;border-radius:0!important;outline:none!important;margin:0!important;padding:0!important}.photosuite-item{line-height:0;display:inline-block;position:relative;overflow:hidden}.photosuite-item>a{display:block}.photosuite-caption{box-sizing:border-box;z-index:1;background:var(--photosuite-caption-bg);justify-content:flex-start;align-items:center;height:30px;padding:0 10px;font-style:normal;font-weight:400;line-height:1;display:flex;position:absolute;bottom:0;left:0;right:0;font-size:var(--photosuite-caption-size)!important;color:var(--photosuite-caption-color)!important}.photosuite-exif{box-sizing:border-box;z-index:1;background:var(--photosuite-exif-bg);opacity:0;pointer-events:none;justify-content:center;align-items:center;height:30px;padding:0 10px;font-style:normal;font-weight:400;line-height:1;transition:opacity .2s ease-in-out;display:flex;position:absolute;top:0;left:0;right:0;font-size:var(--photosuite-exif-size)!important;color:var(--photosuite-exif-color)!important}.photosuite-item:hover .photosuite-exif{opacity:1}
1
+ :root{--photosuite-caption-size:12px;--photosuite-caption-color:#fff;--photosuite-exif-size:12px;--photosuite-exif-color:#fff;--photosuite-exif-bg:linear-gradient(to bottom,#0009,transparent);--photosuite-caption-bg:linear-gradient(to right,#000c,transparent)}:where(.photosuite-item img){display:block;box-shadow:none!important;border:none!important;border-radius:0!important;outline:none!important;margin:0!important;padding:0!important}.photosuite-item{line-height:0;display:inline-block;position:relative;overflow:hidden}.photosuite-item>a{display:block}.photosuite-caption{box-sizing:border-box;z-index:1;background:var(--photosuite-caption-bg);justify-content:flex-start;align-items:center;height:30px;padding:0 10px;font-style:normal;font-weight:400;line-height:1;display:flex;position:absolute;bottom:0;left:0;right:0;font-size:var(--photosuite-caption-size)!important;color:var(--photosuite-caption-color)!important}.photosuite-exif{box-sizing:border-box;z-index:1;background:var(--photosuite-exif-bg);opacity:0;pointer-events:none;justify-content:center;align-items:center;height:30px;padding:0 10px;font-style:normal;font-weight:400;line-height:1;transition:opacity .2s ease-in-out;display:flex;position:absolute;top:0;left:0;right:0;font-size:var(--photosuite-exif-size)!important;color:var(--photosuite-exif-color)!important}.photosuite-exif:empty{display:none!important}.photosuite-item:hover .photosuite-exif{opacity:1}
2
2
  /*$vite$:1*/
@@ -7,14 +7,14 @@ function photosuite(e) {
7
7
  let n = e.selector ?? "a.glightbox", r = e.gallery ?? "markdown", i = e.glightbox ?? !0, a = e.imageAlts ?? !0, o = e.exif ?? !0, s = async () => {
8
8
  if (!document.querySelector(t)) return;
9
9
  let s = [];
10
- i && s.push(import("./glightbox-Cnkb5Vpt.js").then((i) => i.initGlightboxModule({
10
+ i && s.push(import("./glightbox-3dU8JRqr.js").then((i) => i.initGlightboxModule({
11
11
  selector: n,
12
12
  scope: t,
13
13
  gallery: r,
14
14
  options: e.glightboxOptions,
15
15
  cssUrl: e.glightboxCssUrl,
16
16
  jsUrl: e.glightboxJsUrl
17
- }))), a && s.push(import("./imageAlts-BAYP9b5j.js").then((e) => e.enableImageAlts(t, n))), o && s.push(import("./exif-Dr_aoh2F.js").then((e) => e.enableExif(t, n))), s.length && Promise.all(s).catch(() => {});
17
+ }))), a && s.push(import("./imageAlts-PnRBw8zl.js").then((e) => e.enableImageAlts(t, n))), o && s.push(import("./exif-Bvph_6jm.js").then((e) => e.enableExif(t, n))), s.length && Promise.all(s).catch(() => {});
18
18
  };
19
19
  document.readyState === "complete" || document.readyState === "interactive" ? s() : document.addEventListener("DOMContentLoaded", s);
20
20
  }
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`exiftool-vendored`),l=require(`node:fs`);l=s(l);let u=require(`node:fs/promises`);u=s(u);let d=require(`node:path`);d=s(d);let f=require(`node:http`);f=s(f);let p=require(`node:https`);p=s(p);let m=require(`node:os`);m=s(m);let h=require(`node:url`);var g=(...e)=>{let t=e.filter(e=>typeof e==`string`&&e!==``);if(t.length===0)return``;if(t.length===1)return t[0];let n=t[0],r=t[1],i=`${n.endsWith(`/`)?n.slice(0,-1):n}/${r.startsWith(`/`)?r.slice(1):r}`;return t.length>2?g(i,...t.slice(2)):i},_=e=>!(!e||/^https?:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`));function v(e={}){let{imageBase:t,imageDir:n=`imageDir`,fileDir:r=!1}=e;return(e,i)=>{let a=(i?.data?.astro?.frontmatter||i?.data?.frontmatter||{})[n]||``,o=(i?.path||i?.history?.[0]||``).split(/[\\/]/).pop()?.split(`.`).shift()||``,s=r?o:a,c=e=>{if(e){if(e.type===`image`){let n=e.url||``;(t||s)&&_(n)&&(e.url=g(t,s,n))}e.children&&e.children.length&&e.children.forEach(c)}};c(e)}}function y(e){try{let t=new h.URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}async function b(e){let t=m.tmpdir(),n=d.extname(e)||`.bin`,r=d.join(t,`exif-${Date.now()}-${Math.random().toString(36).slice(2)}${n}`),i=l.createWriteStream(r),a=e.startsWith(`https:`)?p:f;return await new Promise((t,n)=>{a.get(e,e=>{if(e.statusCode&&e.statusCode>=300&&e.statusCode<400&&e.headers.location,e.statusCode!==200){n(Error(`HTTP `+e.statusCode));return}e.pipe(i),i.on(`finish`,t),i.on(`error`,n)}).on(`error`,n)}),{path:r,cleanup:async()=>{try{await u.unlink(r)}catch{}}}}async function x(e){let t=await c.exiftool.read(e);return{SourceFile:t.SourceFile,ExifToolVersion:t.ExifToolVersion,MIMEType:t.MIMEType,FileType:t.FileType,Make:t.Make,Model:t.Model,LensModel:t.LensModel,DateTimeOriginal:t.DateTimeOriginal,CreateDate:t.CreateDate,ModifyDate:t.ModifyDate,ImageWidth:t.ImageWidth,ImageHeight:t.ImageHeight,GPSLatitude:t.GPSLatitude,GPSLongitude:t.GPSLongitude,FNumber:t.FNumber,ExposureTime:t.ExposureTime,ISO:t.ISO,FocalLength:t.FocalLength,warnings:t.warnings||[],errors:t.errors||[]}}function S(e,t){if(t==null)return``;switch(e){case`FNumber`:return`ƒ/${Number(t).toFixed(1)}`;case`ExposureTime`:return typeof t==`number`?t>=1?`${t}s`:`1/${Math.round(1/t)}s`:t.toString();case`ISO`:return`ISO ${t}`;case`FocalLength`:let e=t.toString();return e.endsWith(`mm`)?e:`${e}mm`;case`DateTimeOriginal`:return typeof t==`object`&&t.year?`${t.year}/${t.month}/${t.day}`:t.toString();default:return t.toString()}}async function C(e,t,n){let r=e.properties?.src;if(!r)return;let i=``,a;try{if(y(r)){let e=await b(r);i=e.path,a=e.cleanup}else if(d.isAbsolute(r))i=r;else{let e=d.dirname(t.path);i=d.resolve(e,r)}if(i&&(l.existsSync(i)||y(r))&&(l.existsSync(i)||(i=decodeURIComponent(i)),l.existsSync(i))){let t=await x(i);if(!(t.FNumber||t.ExposureTime||t.ISO))return;let r=typeof n.exif==`object`?n.exif:{},a=r.fields||[`Model`,`LensModel`,`FocalLength`,`FNumber`,`ExposureTime`,`ISO`,`DateTimeOriginal`],o=r.separator||` · `,s=a.map(e=>{let n=t[e];return n?S(e,n):null}).filter(Boolean);if(s.length===0)return;let c=s.join(o),l={...e.properties};e.tagName=`div`,e.properties={className:[`photosuite-item`]},e.children=[{type:`element`,tagName:`img`,properties:l,children:[]},{type:`element`,tagName:`div`,properties:{className:[`photosuite-exif`]},children:[{type:`text`,value:c}]}]}}catch(e){console.warn(`[photosuite] Failed to get EXIF for ${r}:`,e)}finally{a&&await a()}}function w(e={}){return async(t,n)=>{let r=[],i=t=>{t.type===`element`&&t.tagName===`img`&&r.push(C(t,n,e)),t.children&&t.children.forEach(i)};i(t),r.length>0&&await Promise.all(r)}}function T(e){return{name:`photosuite`,hooks:{"astro:config:setup":({injectScript:t,updateConfig:n})=>{t(`page`,`
2
- import { photosuite } from 'photosuite';
1
+ Object.defineProperty(exports,`__esModule`,{value:!0});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`exiftool-vendored`),l=require(`node:fs`);l=s(l);let u=require(`node:fs/promises`);u=s(u);let d=require(`node:path`);d=s(d);let f=require(`node:http`);f=s(f);let p=require(`node:https`);p=s(p);let m=require(`node:os`);m=s(m);let h=require(`node:url`);var g=(...e)=>{let t=e.filter(e=>typeof e==`string`&&e!==``);if(t.length===0)return``;if(t.length===1)return t[0];let n=t[0],r=t[1],i=`${n.endsWith(`/`)?n.slice(0,-1):n}/${r.startsWith(`/`)?r.slice(1):r}`;return t.length>2?g(i,...t.slice(2)):i},_=e=>!(!e||/^https?:\/\//i.test(e)||e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`));function v(e={}){let{imageBase:t,imageDir:n=`imageDir`,fileDir:r=!1}=e;return(e,i)=>{let a=(i?.data?.astro?.frontmatter||i?.data?.frontmatter||{})[n]||``,o=(i?.path||i?.history?.[0]||``).split(/[\\/]/).pop()?.split(`.`).shift()||``,s=r?o:a,c=e=>{if(e){if(e.type===`image`){let n=e.url||``;(t||s)&&_(n)&&(e.url=g(t,s,n))}e.children&&e.children.length&&e.children.forEach(c)}};c(e)}}function y(e){try{let t=new h.URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}async function b(e){let t=m.tmpdir(),n=d.extname(e)||`.bin`,r=d.join(t,`exif-${Date.now()}-${Math.random().toString(36).slice(2)}${n}`),i=l.createWriteStream(r),a=e.startsWith(`https:`)?p:f;return await new Promise((t,n)=>{a.get(e,e=>{if(e.statusCode&&e.statusCode>=300&&e.statusCode<400&&e.headers.location,e.statusCode!==200){n(Error(`HTTP `+e.statusCode));return}e.pipe(i),i.on(`finish`,t),i.on(`error`,n)}).on(`error`,n)}),{path:r,cleanup:async()=>{try{await u.unlink(r)}catch{}}}}async function x(e){let t=await c.exiftool.read(e);return{SourceFile:t.SourceFile,ExifToolVersion:t.ExifToolVersion,MIMEType:t.MIMEType,FileType:t.FileType,Make:t.Make,Model:t.Model,LensModel:t.LensModel,DateTimeOriginal:t.DateTimeOriginal,CreateDate:t.CreateDate,ModifyDate:t.ModifyDate,ImageWidth:t.ImageWidth,ImageHeight:t.ImageHeight,GPSLatitude:t.GPSLatitude,GPSLongitude:t.GPSLongitude,FNumber:t.FNumber,ExposureTime:t.ExposureTime,ISO:t.ISO,FocalLength:t.FocalLength,warnings:t.warnings||[],errors:t.errors||[]}}function S(e,t){if(t==null)return``;switch(e){case`FNumber`:return`ƒ/${Number(t).toFixed(1)}`;case`ExposureTime`:return typeof t==`number`?t>=1?`${t}s`:`1/${Math.round(1/t)}s`:t.toString();case`ISO`:return`ISO ${t}`;case`FocalLength`:let e=t.toString();return e.endsWith(`mm`)?e:`${e}mm`;case`DateTimeOriginal`:return typeof t==`object`&&t.year?`${t.year}/${t.month}/${t.day}`:t.toString();default:return t.toString()}}async function C(e,t,n){let r=e.properties?.src;if(!r)return;let i=``,a;try{if(y(r)){let e=await b(r);i=e.path,a=e.cleanup}else if(d.isAbsolute(r))i=r;else{let e=d.dirname(t.path);i=d.resolve(e,r)}if(i&&(l.existsSync(i)||y(r))&&(l.existsSync(i)||(i=decodeURIComponent(i)),l.existsSync(i))){let t=await x(i);if(!(t.FNumber&&t.ExposureTime&&t.ISO))return;let r=typeof n.exif==`object`?n.exif:{},a=r.fields||[`Model`,`LensModel`,`FocalLength`,`FNumber`,`ExposureTime`,`ISO`,`DateTimeOriginal`],o=r.separator||` · `,s=a.map(e=>{let n=t[e];return n?S(e,n):null}).filter(Boolean);if(s.length===0)return;let c=s.join(o),l={...e.properties};e.tagName=`div`,e.properties={className:[`photosuite-item`]},e.children=[{type:`element`,tagName:`img`,properties:l,children:[]},{type:`element`,tagName:`div`,properties:{className:[`photosuite-exif`]},children:[{type:`text`,value:c}]}]}}catch(e){console.warn(`[photosuite] Failed to get EXIF for ${r}:`,e)}finally{a&&await a()}}function w(e={}){return async(t,n)=>{let r=[],i=t=>{t.type===`element`&&t.tagName===`img`&&r.push(C(t,n,e)),t.children&&t.children.forEach(i)};i(t),r.length>0&&await Promise.all(r)}}function T(e){return{name:`photosuite`,hooks:{"astro:config:setup":({injectScript:t,updateConfig:n})=>{t(`page`,`
2
+ import { photosuite } from 'photosuite/client';
3
3
  const __opts = ${JSON.stringify(e)};
4
4
  const __run = () => photosuite(__opts);
5
5
  __run();
6
6
  document.addEventListener('astro:page-load', __run);
7
- `);let r=[],i=[];i.push([v,e]),e.exif!==!1&&r.push([w,e]);let a={markdown:{}};r.length>0&&(a.markdown.rehypePlugins=r),i.length>0&&(a.markdown.remarkPlugins=i),Object.keys(a.markdown).length>0&&n(a)}}}}exports.default=T,exports.exiftoolVendored=w,exports.imageUrl=v;
7
+ `);let r=[],i=[];i.push([v,e]),e.exif!==!1&&r.push([w,e]);let a={markdown:{}};r.length>0&&(a.markdown.rehypePlugins=r),i.length>0&&(a.markdown.remarkPlugins=i),Object.keys(a.markdown).length>0&&n(a)}}}}const E=T;exports.default=T,exports.exiftoolVendored=w,exports.imageUrl=v,exports.photosuite=E;
@@ -7,109 +7,109 @@ import * as https from "node:https";
7
7
  import * as os from "node:os";
8
8
  import { URL } from "node:url";
9
9
  var join = (...e) => {
10
- let s = e.filter((e) => typeof e == "string" && e !== "");
11
- if (s.length === 0) return "";
12
- if (s.length === 1) return s[0];
13
- let c = s[0], l = s[1], u = `${c.endsWith("/") ? c.slice(0, -1) : c}/${l.startsWith("/") ? l.slice(1) : l}`;
14
- return s.length > 2 ? join(u, ...s.slice(2)) : u;
10
+ let c = e.filter((e) => typeof e == "string" && e !== "");
11
+ if (c.length === 0) return "";
12
+ if (c.length === 1) return c[0];
13
+ let l = c[0], u = c[1], d = `${l.endsWith("/") ? l.slice(0, -1) : l}/${u.startsWith("/") ? u.slice(1) : u}`;
14
+ return c.length > 2 ? join(d, ...c.slice(2)) : d;
15
15
  }, isShort = (e) => !(!e || /^https?:\/\//i.test(e) || e.startsWith("/") || e.startsWith("./") || e.startsWith("../"));
16
16
  function imageUrl(e = {}) {
17
- let { imageBase: s, imageDir: c = "imageDir", fileDir: l = !1 } = e;
18
- return (e, u) => {
19
- let d = (u?.data?.astro?.frontmatter || u?.data?.frontmatter || {})[c] || "", f = (u?.path || u?.history?.[0] || "").split(/[\\/]/).pop()?.split(".").shift() || "", p = l ? f : d, g = (e) => {
17
+ let { imageBase: c, imageDir: l = "imageDir", fileDir: u = !1 } = e;
18
+ return (e, d) => {
19
+ let f = (d?.data?.astro?.frontmatter || d?.data?.frontmatter || {})[l] || "", p = (d?.path || d?.history?.[0] || "").split(/[\\/]/).pop()?.split(".").shift() || "", m = u ? p : f, _ = (e) => {
20
20
  if (e) {
21
21
  if (e.type === "image") {
22
- let c = e.url || "";
23
- (s || p) && isShort(c) && (e.url = join(s, p, c));
22
+ let l = e.url || "";
23
+ (c || m) && isShort(l) && (e.url = join(c, m, l));
24
24
  }
25
- e.children && e.children.length && e.children.forEach(g);
25
+ e.children && e.children.length && e.children.forEach(_);
26
26
  }
27
27
  };
28
- g(e);
28
+ _(e);
29
29
  };
30
30
  }
31
31
  function isHttpUrl(e) {
32
32
  try {
33
- let s = new URL(e);
34
- return s.protocol === "http:" || s.protocol === "https:";
33
+ let c = new URL(e);
34
+ return c.protocol === "http:" || c.protocol === "https:";
35
35
  } catch {
36
36
  return !1;
37
37
  }
38
38
  }
39
39
  async function downloadToTemp(e) {
40
- let p = os.tmpdir(), m = path.extname(e) || ".bin", h = path.join(p, `exif-${Date.now()}-${Math.random().toString(36).slice(2)}${m}`), g = fs.createWriteStream(h), _ = e.startsWith("https:") ? https : http;
41
- return await new Promise((s, c) => {
42
- _.get(e, (e) => {
40
+ let m = os.tmpdir(), h = path.extname(e) || ".bin", g = path.join(m, `exif-${Date.now()}-${Math.random().toString(36).slice(2)}${h}`), _ = fs.createWriteStream(g), v = e.startsWith("https:") ? https : http;
41
+ return await new Promise((c, l) => {
42
+ v.get(e, (e) => {
43
43
  if (e.statusCode && e.statusCode >= 300 && e.statusCode < 400 && e.headers.location, e.statusCode !== 200) {
44
- c(/* @__PURE__ */ Error("HTTP " + e.statusCode));
44
+ l(/* @__PURE__ */ Error("HTTP " + e.statusCode));
45
45
  return;
46
46
  }
47
- e.pipe(g), g.on("finish", s), g.on("error", c);
48
- }).on("error", c);
47
+ e.pipe(_), _.on("finish", c), _.on("error", l);
48
+ }).on("error", l);
49
49
  }), {
50
- path: h,
50
+ path: g,
51
51
  cleanup: async () => {
52
52
  try {
53
- await fsp.unlink(h);
53
+ await fsp.unlink(g);
54
54
  } catch {}
55
55
  }
56
56
  };
57
57
  }
58
- async function handleExif(s) {
59
- let c = await exiftool.read(s);
58
+ async function handleExif(c) {
59
+ let l = await exiftool.read(c);
60
60
  return {
61
- SourceFile: c.SourceFile,
62
- ExifToolVersion: c.ExifToolVersion,
63
- MIMEType: c.MIMEType,
64
- FileType: c.FileType,
65
- Make: c.Make,
66
- Model: c.Model,
67
- LensModel: c.LensModel,
68
- DateTimeOriginal: c.DateTimeOriginal,
69
- CreateDate: c.CreateDate,
70
- ModifyDate: c.ModifyDate,
71
- ImageWidth: c.ImageWidth,
72
- ImageHeight: c.ImageHeight,
73
- GPSLatitude: c.GPSLatitude,
74
- GPSLongitude: c.GPSLongitude,
75
- FNumber: c.FNumber,
76
- ExposureTime: c.ExposureTime,
77
- ISO: c.ISO,
78
- FocalLength: c.FocalLength,
79
- warnings: c.warnings || [],
80
- errors: c.errors || []
61
+ SourceFile: l.SourceFile,
62
+ ExifToolVersion: l.ExifToolVersion,
63
+ MIMEType: l.MIMEType,
64
+ FileType: l.FileType,
65
+ Make: l.Make,
66
+ Model: l.Model,
67
+ LensModel: l.LensModel,
68
+ DateTimeOriginal: l.DateTimeOriginal,
69
+ CreateDate: l.CreateDate,
70
+ ModifyDate: l.ModifyDate,
71
+ ImageWidth: l.ImageWidth,
72
+ ImageHeight: l.ImageHeight,
73
+ GPSLatitude: l.GPSLatitude,
74
+ GPSLongitude: l.GPSLongitude,
75
+ FNumber: l.FNumber,
76
+ ExposureTime: l.ExposureTime,
77
+ ISO: l.ISO,
78
+ FocalLength: l.FocalLength,
79
+ warnings: l.warnings || [],
80
+ errors: l.errors || []
81
81
  };
82
82
  }
83
- function formatField(e, s) {
84
- if (s == null) return "";
83
+ function formatField(e, c) {
84
+ if (c == null) return "";
85
85
  switch (e) {
86
- case "FNumber": return `ƒ/${Number(s).toFixed(1)}`;
87
- case "ExposureTime": return typeof s == "number" ? s >= 1 ? `${s}s` : `1/${Math.round(1 / s)}s` : s.toString();
88
- case "ISO": return `ISO ${s}`;
86
+ case "FNumber": return `ƒ/${Number(c).toFixed(1)}`;
87
+ case "ExposureTime": return typeof c == "number" ? c >= 1 ? `${c}s` : `1/${Math.round(1 / c)}s` : c.toString();
88
+ case "ISO": return `ISO ${c}`;
89
89
  case "FocalLength":
90
- let e = s.toString();
90
+ let e = c.toString();
91
91
  return e.endsWith("mm") ? e : `${e}mm`;
92
- case "DateTimeOriginal": return typeof s == "object" && s.year ? `${s.year}/${s.month}/${s.day}` : s.toString();
93
- default: return s.toString();
92
+ case "DateTimeOriginal": return typeof c == "object" && c.year ? `${c.year}/${c.month}/${c.day}` : c.toString();
93
+ default: return c.toString();
94
94
  }
95
95
  }
96
- async function processNode(e, c, u) {
97
- let d = e.properties?.src;
98
- if (!d) return;
99
- let f = "", p;
96
+ async function processNode(e, l, d) {
97
+ let f = e.properties?.src;
98
+ if (!f) return;
99
+ let p = "", m;
100
100
  try {
101
- if (isHttpUrl(d)) {
102
- let e = await downloadToTemp(d);
103
- f = e.path, p = e.cleanup;
104
- } else if (path.isAbsolute(d)) f = d;
101
+ if (isHttpUrl(f)) {
102
+ let e = await downloadToTemp(f);
103
+ p = e.path, m = e.cleanup;
104
+ } else if (path.isAbsolute(f)) p = f;
105
105
  else {
106
- let e = path.dirname(c.path);
107
- f = path.resolve(e, d);
106
+ let e = path.dirname(l.path);
107
+ p = path.resolve(e, f);
108
108
  }
109
- if (f && (fs.existsSync(f) || isHttpUrl(d)) && (fs.existsSync(f) || (f = decodeURIComponent(f)), fs.existsSync(f))) {
110
- let s = await handleExif(f);
111
- if (!(s.FNumber || s.ExposureTime || s.ISO)) return;
112
- let c = typeof u.exif == "object" ? u.exif : {}, l = c.fields || [
109
+ if (p && (fs.existsSync(p) || isHttpUrl(f)) && (fs.existsSync(p) || (p = decodeURIComponent(p)), fs.existsSync(p))) {
110
+ let c = await handleExif(p);
111
+ if (!(c.FNumber && c.ExposureTime && c.ISO)) return;
112
+ let l = typeof d.exif == "object" ? d.exif : {}, u = l.fields || [
113
113
  "Model",
114
114
  "LensModel",
115
115
  "FocalLength",
@@ -117,16 +117,16 @@ async function processNode(e, c, u) {
117
117
  "ExposureTime",
118
118
  "ISO",
119
119
  "DateTimeOriginal"
120
- ], d = c.separator || " · ", p = l.map((e) => {
121
- let c = s[e];
122
- return c ? formatField(e, c) : null;
120
+ ], f = l.separator || " · ", m = u.map((e) => {
121
+ let l = c[e];
122
+ return l ? formatField(e, l) : null;
123
123
  }).filter(Boolean);
124
- if (p.length === 0) return;
125
- let m = p.join(d), h = { ...e.properties };
124
+ if (m.length === 0) return;
125
+ let h = m.join(f), g = { ...e.properties };
126
126
  e.tagName = "div", e.properties = { className: ["photosuite-item"] }, e.children = [{
127
127
  type: "element",
128
128
  tagName: "img",
129
- properties: h,
129
+ properties: g,
130
130
  children: []
131
131
  }, {
132
132
  type: "element",
@@ -134,40 +134,41 @@ async function processNode(e, c, u) {
134
134
  properties: { className: ["photosuite-exif"] },
135
135
  children: [{
136
136
  type: "text",
137
- value: m
137
+ value: h
138
138
  }]
139
139
  }];
140
140
  }
141
141
  } catch (e) {
142
- console.warn(`[photosuite] Failed to get EXIF for ${d}:`, e);
142
+ console.warn(`[photosuite] Failed to get EXIF for ${f}:`, e);
143
143
  } finally {
144
- p && await p();
144
+ m && await m();
145
145
  }
146
146
  }
147
147
  function exiftoolVendored(e = {}) {
148
- return async (s, c) => {
149
- let l = [], u = (s) => {
150
- s.type === "element" && s.tagName === "img" && l.push(processNode(s, c, e)), s.children && s.children.forEach(u);
148
+ return async (c, l) => {
149
+ let u = [], d = (c) => {
150
+ c.type === "element" && c.tagName === "img" && u.push(processNode(c, l, e)), c.children && c.children.forEach(d);
151
151
  };
152
- u(s), l.length > 0 && await Promise.all(l);
152
+ d(c), u.length > 0 && await Promise.all(u);
153
153
  };
154
154
  }
155
155
  function astroPhotosuite(e) {
156
156
  return {
157
157
  name: "photosuite",
158
- hooks: { "astro:config:setup": ({ injectScript: s, updateConfig: c }) => {
159
- s("page", `
160
- import { photosuite } from 'photosuite';
158
+ hooks: { "astro:config:setup": ({ injectScript: c, updateConfig: l }) => {
159
+ c("page", `
160
+ import { photosuite } from 'photosuite/client';
161
161
  const __opts = ${JSON.stringify(e)};
162
162
  const __run = () => photosuite(__opts);
163
163
  __run();
164
164
  document.addEventListener('astro:page-load', __run);
165
165
  `);
166
- let l = [], u = [];
167
- u.push([imageUrl, e]), e.exif !== !1 && l.push([exiftoolVendored, e]);
168
- let d = { markdown: {} };
169
- l.length > 0 && (d.markdown.rehypePlugins = l), u.length > 0 && (d.markdown.remarkPlugins = u), Object.keys(d.markdown).length > 0 && c(d);
166
+ let u = [], d = [];
167
+ d.push([imageUrl, e]), e.exif !== !1 && u.push([exiftoolVendored, e]);
168
+ let f = { markdown: {} };
169
+ u.length > 0 && (f.markdown.rehypePlugins = u), d.length > 0 && (f.markdown.remarkPlugins = d), Object.keys(f.markdown).length > 0 && l(f);
170
170
  } }
171
171
  };
172
172
  }
173
- export { astroPhotosuite as default, exiftoolVendored, imageUrl };
173
+ const photosuite = astroPhotosuite;
174
+ export { astroPhotosuite as default, exiftoolVendored, imageUrl, photosuite };
package/package.json CHANGED
@@ -1,76 +1,70 @@
1
- {
2
- "name": "photosuite",
3
- "version": "0.1.0",
4
- "description": "A zero-config Astro integration for better images (Lightbox, EXIF, Path resolution).",
5
- "keywords": [
6
- "astro-integration",
7
- "lightbox",
8
- "exif",
9
- "gallery",
10
- "markdown-images",
11
- "photography",
12
- "zero-config"
13
- ],
14
- "author": "achuanya",
15
- "license": "GPL-3.0",
16
- "repository": {
17
- "type": "git",
18
- "url": "https://github.com/achuanya/photosuite"
19
- },
20
- "homepage": "https://photosuite.lhasa.icu",
21
- "bugs": "https://github.com/achuanya/photosuite/issues",
22
- "type": "module",
23
- "main": "./dist/photosuite.integration.js",
24
- "module": "./dist/photosuite.es.js",
25
- "types": "./dist/integration.d.ts",
26
- "exports": {
27
- ".": {
28
- "node": {
29
- "types": "./dist/integration.d.ts",
30
- "import": "./dist/photosuite.integration.js",
31
- "require": "./dist/photosuite.integration.cjs"
32
- },
33
- "types": "./dist/index.d.ts",
34
- "import": "./dist/photosuite.es.js",
35
- "require": "./dist/photosuite.cjs.js",
36
- "default": "./dist/photosuite.es.js"
37
- },
38
- "./client": {
39
- "types": "./dist/index.d.ts",
40
- "import": "./dist/photosuite.es.js",
41
- "require": "./dist/photosuite.cjs.js"
42
- },
43
- "./dist/photosuite.css": "./dist/photosuite.css"
44
- },
45
- "files": [
46
- "dist",
47
- "LICENSE",
48
- "README.md",
49
- "README.zh-CN.md"
50
- ],
51
- "scripts": {
52
- "dev": "vite",
53
- "build": "tsc && vite build",
54
- "preview": "vite preview"
55
- },
56
- "peerDependencies": {
57
- "astro": "^4.0.0 || ^5.0.0"
58
- },
59
- "dependencies": {
60
- "exiftool-vendored": "^34.1.0"
61
- },
62
- "devDependencies": {
63
- "@tailwindcss/postcss": "^4.1.17",
64
- "@types/node": "^25.0.3",
65
- "autoprefixer": "^10.4.22",
66
- "postcss": "^8.5.6",
67
- "sass": "^1.94.2",
68
- "tailwindcss": "^4.1.17",
69
- "typescript": "~5.9.3",
70
- "vite": "npm:rolldown-vite@7.2.5",
71
- "vite-plugin-dts": "^4.5.4"
72
- },
73
- "overrides": {
74
- "vite": "npm:rolldown-vite@7.2.5"
75
- }
76
- }
1
+ {
2
+ "name": "photosuite",
3
+ "version": "0.1.2",
4
+ "description": "A zero-config Astro integration for better images (Lightbox, EXIF, Path resolution).",
5
+ "keywords": [
6
+ "astro-integration",
7
+ "lightbox",
8
+ "exif",
9
+ "gallery",
10
+ "markdown-images",
11
+ "photography",
12
+ "zero-config"
13
+ ],
14
+ "author": "achuanya",
15
+ "license": "GPL-3.0",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/achuanya/photosuite"
19
+ },
20
+ "homepage": "https://photosuite.lhasa.icu",
21
+ "bugs": "https://github.com/achuanya/photosuite/issues",
22
+ "type": "module",
23
+ "main": "./dist/photosuite.integration.js",
24
+ "module": "./dist/photosuite.integration.js",
25
+ "types": "./dist/integration.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/integration.d.ts",
29
+ "import": "./dist/photosuite.integration.js",
30
+ "require": "./dist/photosuite.integration.cjs"
31
+ },
32
+ "./client": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/photosuite.es.js",
35
+ "require": "./dist/photosuite.cjs.js"
36
+ },
37
+ "./dist/photosuite.css": "./dist/photosuite.css"
38
+ },
39
+ "files": [
40
+ "dist",
41
+ "LICENSE",
42
+ "README.md",
43
+ "README.zh-CN.md"
44
+ ],
45
+ "scripts": {
46
+ "dev": "vite",
47
+ "build": "tsc && vite build",
48
+ "preview": "vite preview"
49
+ },
50
+ "peerDependencies": {
51
+ "astro": "^4.0.0 || ^5.0.0"
52
+ },
53
+ "dependencies": {
54
+ "exiftool-vendored": "^34.1.0"
55
+ },
56
+ "devDependencies": {
57
+ "@tailwindcss/postcss": "^4.1.17",
58
+ "@types/node": "^25.0.3",
59
+ "autoprefixer": "^10.4.22",
60
+ "postcss": "^8.5.6",
61
+ "sass": "^1.94.2",
62
+ "tailwindcss": "^4.1.17",
63
+ "typescript": "~5.9.3",
64
+ "vite": "npm:rolldown-vite@7.2.5",
65
+ "vite-plugin-dts": "^4.5.4"
66
+ },
67
+ "overrides": {
68
+ "vite": "npm:rolldown-vite@7.2.5"
69
+ }
70
+ }
@@ -1 +0,0 @@
1
- const e=require(`./dom-DMZsb49p.cjs`);async function t(t,n){await Promise.resolve().then(()=>require(`./exif-DwHkZ3YD.cjs`)),e.r(t,n,t=>{e.n(t)})}exports.enableExif=t;
@@ -1 +0,0 @@
1
- function e(e,t){let n=e.currentSrc||e.src||``;if(!n)return;let r=String(e.getAttribute(`alt`)||``).trim(),i=document.createElement(`a`);i.href=n,i.className=`glightbox`,i.dataset.gallery=t,r&&(i.dataset.title=r),e.parentElement.replaceChild(i,e),i.appendChild(e)}function t(e,t){let n=e.querySelector(`img`);if(!n)return;let r=n.currentSrc||n.src;r&&e.getAttribute(`href`)!==r&&e.setAttribute(`href`,r);let i=n.getAttribute(`alt`);i&&!e.dataset.title&&(e.dataset.title=i),e.dataset.gallery||(e.dataset.gallery=t)}function n(e){if(!e||document.querySelector(`link[href="${e}"]`))return;let t=document.createElement(`link`);t.rel=`stylesheet`,t.href=e,document.head.appendChild(t)}function r(e){return new Promise(t=>{if(!e||typeof window.GLightbox==`function`)return t();let n=document.createElement(`script`);n.src=e,n.onload=()=>t(),document.head.appendChild(n)})}async function i(i){let a=i.selector,o=i.scope,s=i.gallery,c=i.cssUrl||`https://cos.lhasa.icu/dist/glightbox/glightbox.min.css`,l=i.jsUrl||`https://cos.lhasa.icu/dist/glightbox/glightbox.min.js`,u=new Set,d=new Set;document.querySelectorAll(o).forEach(e=>{e.querySelectorAll(`img`).forEach(e=>u.add(e)),e.querySelectorAll(a).forEach(e=>d.add(e))}),u.forEach(t=>{let n=t.parentElement,r=n&&n.tagName.toLowerCase()===`a`,i=r&&n.classList.contains(`glightbox`);(!r||!i)&&e(t,s)}),d.forEach(e=>t(e,s)),n(c),await r(l),(()=>{let e=window.GLightbox;if(typeof e==`function`){let t=window.__glightboxInstance;t&&t.destroy&&t.destroy();let n=Object.assign({},i.options||{},{selector:a});window.__glightboxInstance=e(n)}})()}exports.initGlightboxModule=i;
@@ -1 +0,0 @@
1
- const e=require(`./dom-DMZsb49p.cjs`);async function t(t,n){await Promise.resolve().then(()=>require(`./image-alts-D2zawu5U.cjs`)),e.r(t,n,t=>{e.t(t)})}exports.enableImageAlts=t;