@stacksjs/cms 0.75.7 → 0.75.9
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.js +1 -1
- package/package.json +9 -9
package/dist/article.js
CHANGED
|
@@ -1,2 +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]
|
|
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" data-stx-scoped>${source.slice(0,exports.index)}
|
|
2
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.9",
|
|
6
6
|
"description": "Stacks cms utilities.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -58,14 +58,14 @@
|
|
|
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.
|
|
67
|
-
"@stacksjs/stx": "^0.2.
|
|
68
|
-
"@stacksjs/validation": "0.75.
|
|
61
|
+
"@stacksjs/database": "0.75.9",
|
|
62
|
+
"@stacksjs/error-handling": "0.75.9",
|
|
63
|
+
"@stacksjs/orm": "0.75.9",
|
|
64
|
+
"@stacksjs/path": "0.75.9",
|
|
65
|
+
"@stacksjs/sites": "0.75.9",
|
|
66
|
+
"@stacksjs/slug": "0.75.9",
|
|
67
|
+
"@stacksjs/stx": "^0.2.317",
|
|
68
|
+
"@stacksjs/validation": "0.75.9",
|
|
69
69
|
"ts-medium-editor": "^0.2.0",
|
|
70
70
|
"ts-slug": "^0.1.0",
|
|
71
71
|
"ts-spreadsheets": "^0.2.0"
|