@stacksjs/cms 0.75.5 → 0.75.7
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/dist/article.d.ts +28 -0
- package/dist/article.js +2 -0
- package/package.json +9 -8
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ImageSize, RenderArticleOptions } from 'ts-medium-editor/article';
|
|
2
|
+
export type { EmbedProvider, ImageSize, RenderArticleOptions } from 'ts-medium-editor/article';
|
|
3
|
+
/**
|
|
4
|
+
* Width and height from an image file's header, without decoding it. Covers
|
|
5
|
+
* PNG, JPEG, GIF, WebP and AVIF, which is every format a blog serves.
|
|
6
|
+
*/
|
|
7
|
+
export declare function imageSize(bytes: Uint8Array): ImageSize | null;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves `/images/…` style paths against the public directory and reads
|
|
10
|
+
* their size. Remote URLs, and anything that would escape the directory,
|
|
11
|
+
* resolve to null. Cached per file until it changes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function publicImageResolver(publicDir?: string): (src: string) => ImageSize | null;
|
|
14
|
+
/** A rendered post body with figures, grids, zoom and embeds. */
|
|
15
|
+
export declare function renderPostHtml(html: string, options?: RenderPostOptions): string;
|
|
16
|
+
/** The article stylesheet, as CSS text. */
|
|
17
|
+
export declare function articleCss(): string;
|
|
18
|
+
/** A `<style>` tag carrying the article stylesheet, for a page's head. */
|
|
19
|
+
export declare function articleHead(): string;
|
|
20
|
+
/**
|
|
21
|
+
* A module `<script>` that turns on click-to-zoom and embed auto-height. The
|
|
22
|
+
* browser build of the article module is inlined, so the page needs no extra
|
|
23
|
+
* request and no bundler.
|
|
24
|
+
*/
|
|
25
|
+
export declare function articleScript(): string;
|
|
26
|
+
export declare interface RenderPostOptions extends RenderArticleOptions {
|
|
27
|
+
publicDir?: string
|
|
28
|
+
}
|
package/dist/article.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{existsSync,openSync,readFileSync,readSync,closeSync,statSync}from"node:fs";import{dirname,join,normalize,sep}from"node:path";import{fileURLToPath}from"node:url";import{renderArticle}from"ts-medium-editor/article";export function imageSize(bytes){const view=new DataView(bytes.buffer,bytes.byteOffset,bytes.byteLength),ascii=(at,length)=>String.fromCharCode(...bytes.subarray(at,at+length));if(bytes.length>=24&&bytes[0]===137&&ascii(1,3)==="PNG")return{width:view.getUint32(16),height:view.getUint32(20)};if(bytes.length>=10&&ascii(0,3)==="GIF")return{width:view.getUint16(6,!0),height:view.getUint16(8,!0)};if(bytes.length>=30&&ascii(0,4)==="RIFF"&&ascii(8,4)==="WEBP"){const chunk=ascii(12,4);if(chunk==="VP8 ")return{width:view.getUint16(26,!0)&16383,height:view.getUint16(28,!0)&16383};if(chunk==="VP8L"){const b=view.getUint32(21,!0);return{width:(b&16383)+1,height:(b>>14&16383)+1}}if(chunk==="VP8X"){const w=bytes[24]|bytes[25]<<8|bytes[26]<<16,h=bytes[27]|bytes[28]<<8|bytes[29]<<16;return{width:w+1,height:h+1}}return null}if(bytes.length>=12&&ascii(4,4)==="ftyp"){for(let i=8;i+16<=bytes.length;i++)if(bytes[i]===105&&ascii(i,4)==="ispe")return{width:view.getUint32(i+8),height:view.getUint32(i+12)};return null}if(bytes.length>=4&&bytes[0]===255&&bytes[1]===216){let i=2;while(i+9<bytes.length){if(bytes[i]!==255){i++;continue}const marker=bytes[i+1];if(marker===216||marker===1||marker>=208&&marker<=215){i+=2;continue}const length=view.getUint16(i+2);if(marker>=192&&marker<=207&&marker!==196&&marker!==200&&marker!==204)return{width:view.getUint16(i+7),height:view.getUint16(i+5)};i+=2+length}}return null}function readHead(file){const fd=openSync(file,"r");try{const buffer=new Uint8Array(65536),read=readSync(fd,buffer,0,buffer.length,0);return buffer.subarray(0,read)}finally{closeSync(fd)}}const sizeCache=new Map;export function publicImageResolver(publicDir=join(process.cwd(),"public")){const root=normalize(publicDir+sep);return(src)=>{if(!src.startsWith("/")||src.startsWith("//"))return null;let path;try{path=normalize(join(root,decodeURIComponent(src.split(/[?#]/)[0])))}catch{return null}if(!path.startsWith(root)||!existsSync(path))return null;const mtime=statSync(path).mtimeMs,cached=sizeCache.get(path);if(cached&&cached.mtime===mtime)return cached.size;let size=null;try{size=imageSize(readHead(path))}catch{}sizeCache.set(path,{mtime,size});return size}}export function renderPostHtml(html,options={}){const{publicDir,...rest}=options;return renderArticle(html,{resolveImage:publicImageResolver(publicDir),...rest})}let cachedCss=null,cachedScript=null;function packageFile(relative){const entry=fileURLToPath(import.meta.resolve("ts-medium-editor/article"));return join(dirname(dirname(entry)),relative)}export function articleCss(){if(cachedCss===null)cachedCss=readFileSync(packageFile("css/article.css"),"utf-8");return cachedCss}export function articleHead(){return`<style data-article>${articleCss()}</style>`}export function articleScript(){if(cachedScript===null){const source=readFileSync(packageFile("article/index.js"),"utf-8"),exports=source.match(/export\s*\{([^}]*)\};?\s*$/),binding=exports?.[1].split(",").map((part)=>part.trim().split(/\s+as\s+/)).find(([local,name])=>(name??local)==="mountArticle")?.[0];cachedScript=exports&&binding?`<script type="module">${source.slice(0,exports.index)}
|
|
2
|
+
${binding}()</script>`:""}return cachedScript}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/cms",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.7",
|
|
6
6
|
"description": "Stacks cms utilities.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -58,14 +58,15 @@
|
|
|
58
58
|
"prepublishOnly": "bun run build"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@stacksjs/database": "0.75.
|
|
62
|
-
"@stacksjs/error-handling": "0.75.
|
|
63
|
-
"@stacksjs/orm": "0.75.
|
|
64
|
-
"@stacksjs/path": "0.75.
|
|
65
|
-
"@stacksjs/sites": "0.75.
|
|
66
|
-
"@stacksjs/slug": "0.75.
|
|
61
|
+
"@stacksjs/database": "0.75.7",
|
|
62
|
+
"@stacksjs/error-handling": "0.75.7",
|
|
63
|
+
"@stacksjs/orm": "0.75.7",
|
|
64
|
+
"@stacksjs/path": "0.75.7",
|
|
65
|
+
"@stacksjs/sites": "0.75.7",
|
|
66
|
+
"@stacksjs/slug": "0.75.7",
|
|
67
67
|
"@stacksjs/stx": "^0.2.307",
|
|
68
|
-
"@stacksjs/validation": "0.75.
|
|
68
|
+
"@stacksjs/validation": "0.75.7",
|
|
69
|
+
"ts-medium-editor": "^0.2.0",
|
|
69
70
|
"ts-slug": "^0.1.0",
|
|
70
71
|
"ts-spreadsheets": "^0.2.0"
|
|
71
72
|
},
|