@waline/client 3.12.2 → 3.14.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.
@@ -1,48 +1,57 @@
1
+ //#region src/version.d.ts
1
2
  declare const version: string;
2
-
3
+ //#endregion
4
+ //#region src/typings/options.d.ts
5
+ // oxlint-disable-next-line typescript/explicit-module-boundary-types, typescript/no-explicit-any
3
6
  type WalineAbort = (reason?: any) => void;
4
-
7
+ //#endregion
8
+ //#region src/pageview.d.ts
5
9
  interface WalinePageviewCountOptions {
6
- /**
7
- * Waline 服务端地址
8
- *
9
- * Waline server url
10
- */
11
- serverURL: string;
12
- /**
13
- * 浏览量 CSS 选择器
14
- *
15
- * Pageview CSS selector
16
- *
17
- * @default '.waline-pageview-count'
18
- */
19
- selector?: string;
20
- /**
21
- * 需要更新和获取的路径
22
- *
23
- * Path to be fetched and updated
24
- *
25
- * @default window.location.pathname
26
- */
27
- path?: string;
28
- /**
29
- * 是否在查询时更新 path 的浏览量
30
- *
31
- * Whether update pageviews when fetching path result
32
- *
33
- * @default true
34
- */
35
- update?: boolean;
36
- /**
37
- * 错误提示消息所使用的语言
38
- *
39
- * Language of error message
40
- *
41
- * @default navigator.language
42
- */
43
- lang?: string;
10
+ /**
11
+ * Waline 服务端地址
12
+ *
13
+ * Waline server url
14
+ */
15
+ serverURL: string;
16
+ /**
17
+ * 浏览量 CSS 选择器
18
+ *
19
+ * Pageview CSS selector
20
+ *
21
+ * @default '.waline-pageview-count'
22
+ */
23
+ selector?: string;
24
+ /**
25
+ * 需要更新和获取的路径
26
+ *
27
+ * Path to be fetched and updated
28
+ *
29
+ * @default window.location.pathname
30
+ */
31
+ path?: string;
32
+ /**
33
+ * 是否在查询时更新 path 的浏览量
34
+ *
35
+ * Whether update pageviews when fetching path result
36
+ *
37
+ * @default true
38
+ */
39
+ update?: boolean;
40
+ /**
41
+ * 错误提示消息所使用的语言
42
+ *
43
+ * Language of error message
44
+ *
45
+ * @default navigator.language
46
+ */
47
+ lang?: string;
44
48
  }
45
- declare const pageviewCount: ({ serverURL, path, selector, update, lang, }: WalinePageviewCountOptions) => WalineAbort;
46
-
47
- export { pageviewCount, version };
48
- export type { WalineAbort, WalinePageviewCountOptions };
49
+ declare const pageviewCount: ({
50
+ serverURL,
51
+ path,
52
+ selector,
53
+ update,
54
+ lang
55
+ }: WalinePageviewCountOptions) => WalineAbort;
56
+ //#endregion
57
+ export { type WalineAbort, WalinePageviewCountOptions, pageviewCount, version };
package/dist/pageview.js CHANGED
@@ -1,2 +1 @@
1
- const y="3.12.2",$={"Content-Type":"application/json"},h=e=>`${e.replace(/\/?$/,"/")}api/`,u=(e,t="")=>{if(typeof e=="object"&&e.errno)throw new TypeError(`${t} failed with ${e.errno}: ${e.errmsg}`);return e},f=({serverURL:e,lang:t,paths:r,type:o,signal:a})=>fetch(`${h(e)}article?path=${encodeURIComponent(r.join(","))}&type=${encodeURIComponent(o.join(","))}&lang=${t}`,{signal:a}).then(n=>n.json()).then(n=>u(n,"Get counter").data),R=({serverURL:e,lang:t,path:r,type:o,action:a})=>fetch(`${h(e)}article?lang=${t}`,{method:"POST",headers:$,body:JSON.stringify({path:r,type:o,action:a})}).then(n=>n.json()).then(n=>u(n,"Update counter").data),U=({serverURL:e,lang:t,paths:r,signal:o})=>f({serverURL:e,lang:t,paths:r,type:["time"],signal:o}),w=e=>R({...e,type:"time",action:"inc"}),L=(e="")=>e.replace(/\/$/u,""),b=e=>/^(https?:)?\/\//.test(e),d=e=>{const t=L(e);return b(t)?t:`https://${t}`},j=e=>{e.name!=="AbortError"&&console.error(e.message)},m=e=>{const{path:t}=e.dataset;return t!=null&&t.length?t:null},v=(e,t)=>{t.forEach((r,o)=>{const a=e[o].time;typeof a=="number"&&(r.textContent=a.toString())})},C=({serverURL:e,path:t=window.location.pathname,selector:r=".waline-pageview-count",update:o=!0,lang:a=navigator.language})=>{const n=new AbortController,i=[...document.querySelectorAll(r)],p=l=>{const s=m(l);return s!=null&&t!==s},g=l=>U({serverURL:d(e),paths:l.map(s=>m(s)??t),lang:a,signal:n.signal}).then(s=>{v(s,l)}).catch(j);if(o){const l=i.filter(c=>!p(c)),s=i.filter(c=>p(c));w({serverURL:d(e),path:t,lang:a}).then(c=>{v(c,l)}),s.length>0&&g(s)}else g(i);return n.abort.bind(n)};export{C as pageviewCount,y as version};
2
- //# sourceMappingURL=pageview.js.map
1
+ import{getPageview as e,updatePageview as t}from"@waline/api";const n=`3.14.0`,r=(e=``)=>e.replace(/\/$/u,``),i=e=>/^(https?:)?\/\//u.test(e),a=e=>{let t=r(e);return i(t)?t:`https://${t}`},o=e=>{e.name!==`AbortError`&&console.error(e.message)},s=e=>{let{path:t}=e.dataset;return t?.length?t:null},c=(e,t)=>{t.forEach((t,n)=>{let r=e[n].time;typeof r==`number`&&(t.textContent=r.toString())})},l=({serverURL:n,path:r=window.location.pathname,selector:i=`.waline-pageview-count`,update:l=!0,lang:u=navigator.language})=>{let d=new AbortController,f=[...document.querySelectorAll(i)],p=e=>{let t=s(e);return t!=null&&r!==t},m=t=>e({serverURL:a(n),paths:t.map(e=>s(e)??r),lang:u,signal:d.signal}).then(e=>{c(e,t)}).catch(o);if(l){let e=f.filter(e=>!p(e)),i=f.filter(e=>p(e));t({serverURL:a(n),path:r,lang:u}).then(t=>{c(t,e)}),i.length>0&&m(i)}else m(f);return d.abort.bind(d)};export{l as pageviewCount,n as version};