@stacksjs/image 0.75.29 → 0.75.30
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/app-icons.js +1 -1
- package/dist/theme.d.ts +11 -0
- package/dist/theme.js +2 -2
- package/package.json +3 -3
package/dist/app-icons.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import process from"node:process";import{generateAppIcons,generateFavicons}from"ts-images";import{projectFile,requireProjectFile}from"./theme";export async function generateAppIconSet(images,root=process.cwd()){const appIcons=images.appIcons;if(appIcons?.enabled!==!0||!appIcons.source)return{icons:[],favicons:[]};const source=requireProjectFile(appIcons.source,root,"App icon source"),platforms=appIcons.platforms??["ios","macos"],icons=platforms.length===0?[]:await generateAppIcons(source,{outputDir:projectFile(appIcons.outputDir??"resources/app-icons",root),platform:platforms.length===1?platforms[0]:"all"}),favicons=appIcons.favicon?await generateFavicons(source,projectFile(appIcons.faviconDir??"public",root),{manifest:appIcons.manifest===!1?!1:{name:images.brand,...appIcons.manifest??{}}}):[];return{icons,favicons}}
|
|
1
|
+
import process from"node:process";import{generateAppIcons,generateFavicons}from"ts-images";import{projectFile,requireProjectFile}from"./theme";export async function generateAppIconSet(images,root=process.cwd()){const appIcons=images.appIcons;if(appIcons?.enabled!==!0||!appIcons.source)return{icons:[],favicons:[]};const source=requireProjectFile(appIcons.source,root,"App icon source"),platforms=appIcons.platforms??["ios","macos"],icons=platforms.length===0?[]:await generateAppIcons(source,{outputDir:projectFile(appIcons.outputDir??"resources/app-icons",root),platform:platforms.length===1?platforms[0]:"all"}),favicons=appIcons.favicon?await generateFavicons(source,projectFile(appIcons.faviconDir??"public",root),{trim:appIcons.trim,manifest:appIcons.manifest===!1?!1:{name:images.brand,...appIcons.manifest??{}}}):[];return{icons,favicons}}
|
package/dist/theme.d.ts
CHANGED
|
@@ -34,6 +34,17 @@ export declare function device(value: ImageDeviceConfig | undefined): {
|
|
|
34
34
|
shadow?: { blur?: number, offsetX?: number, offsetY?: number, spread?: number, color?: RGBA }
|
|
35
35
|
} | undefined;
|
|
36
36
|
export declare function markPainter(path: string | undefined, root?: string): Promise<MarkPainter | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Crop the transparent margin off a mark, keeping its own proportions.
|
|
39
|
+
*
|
|
40
|
+
* An app icon drawn on Apple's grid is a squircle inside a transparent margin
|
|
41
|
+
* a fifth of its width, and a logo exported from a design tool often carries
|
|
42
|
+
* padding too. Drawn as is, the visible shape comes out smaller than the box
|
|
43
|
+
* the card sized for it, beside a wordmark that is exactly the size asked for.
|
|
44
|
+
* Bounds are found on alpha alone, since a transparent pixel's colour channels
|
|
45
|
+
* are whatever the encoder left there.
|
|
46
|
+
*/
|
|
47
|
+
export declare function trimTransparentEdges(image: ImageData, alphaThreshold?: number): ImageData;
|
|
37
48
|
/** Fold the shared palette into a generator's own, letting the generator win. */
|
|
38
49
|
export declare function themed<T extends ImageTheme>(images: ImagesConfig, section: T | undefined): T & ImageTheme;
|
|
39
50
|
/**
|
package/dist/theme.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{existsSync}from"node:fs";import{readFile}from"node:fs/promises";import{isAbsolute,resolve}from"node:path";import process from"node:process";import{decode,drawImage,parseColor}from"ts-images";export function projectFile(path,root=process.cwd()){return isAbsolute(path)?path:resolve(root,path)}export function requireProjectFile(path,root,describe){const resolved=projectFile(path,root);if(!existsSync(resolved))throw Error(`[image] ${describe} not found: ${path}
|
|
2
|
-
Looked in ${resolved}. Capture it before generating - \`buddy generate:images\` frames existing captures, it does not take them.`);return resolved}export function color(value){return value===void 0?void 0:parseColor(value)}export function background(value,root=process.cwd()){if(!value)return;return{color:color(value.color),gradient:value.gradient&&{angle:value.gradient.angle,stops:value.gradient.stops.map((stop)=>({offset:stop.offset,color:parseColor(stop.color)}))},glows:value.glows?.map((glow)=>({...glow,color:parseColor(glow.color)})),image:value.image?projectFile(value.image,root):void 0}}export function device(value){if(!value)return;return{radius:value.radius,scale:value.scale,borderColor:color(value.borderColor),shadow:value.shadow===!1?void 0:{...value.shadow??{},color:color(value.shadow?.color)}}}export async function markPainter(path,root=process.cwd()){if(!path)return;const mark=await decode(new Uint8Array(await readFile(projectFile(path,root)))),aspect=mark.height>0?mark.width/mark.height:1;return{aspect,draw:(canvas,box)=>{drawImage(canvas,mark,{x:box.x,y:box.y,width:box.width??box.size*aspect,height:box.size,fit:"contain"})}}}export function themed(images,section){return{...section??{},background:section?.background??images.background,color:section?.color??images.color,mutedColor:section?.mutedColor??images.mutedColor,accent:section?.accent??images.accent,device:section?.device??images.device,brand:section?.brand??images.brand,mark:section?.mark??images.mark,markPlate:section?.markPlate!==void 0?section.markPlate:images.markPlate}}
|
|
1
|
+
import{existsSync}from"node:fs";import{readFile}from"node:fs/promises";import{isAbsolute,resolve}from"node:path";import process from"node:process";import{crop,decode,drawImage,parseColor}from"ts-images";export function projectFile(path,root=process.cwd()){return isAbsolute(path)?path:resolve(root,path)}export function requireProjectFile(path,root,describe){const resolved=projectFile(path,root);if(!existsSync(resolved))throw Error(`[image] ${describe} not found: ${path}
|
|
2
|
+
Looked in ${resolved}. Capture it before generating - \`buddy generate:images\` frames existing captures, it does not take them.`);return resolved}export function color(value){return value===void 0?void 0:parseColor(value)}export function background(value,root=process.cwd()){if(!value)return;return{color:color(value.color),gradient:value.gradient&&{angle:value.gradient.angle,stops:value.gradient.stops.map((stop)=>({offset:stop.offset,color:parseColor(stop.color)}))},glows:value.glows?.map((glow)=>({...glow,color:parseColor(glow.color)})),image:value.image?projectFile(value.image,root):void 0}}export function device(value){if(!value)return;return{radius:value.radius,scale:value.scale,borderColor:color(value.borderColor),shadow:value.shadow===!1?void 0:{...value.shadow??{},color:color(value.shadow?.color)}}}export async function markPainter(path,root=process.cwd()){if(!path)return;const mark=trimTransparentEdges(await decode(new Uint8Array(await readFile(projectFile(path,root))))),aspect=mark.height>0?mark.width/mark.height:1;return{aspect,draw:(canvas,box)=>{drawImage(canvas,mark,{x:box.x,y:box.y,width:box.width??box.size*aspect,height:box.size,fit:"contain"})}}}export function trimTransparentEdges(image,alphaThreshold=8){let{width:left,height:top}=image,right=-1,bottom=-1;for(let y=0;y<image.height;y++)for(let x=0;x<image.width;x++)if((image.data[(y*image.width+x)*4+3]??0)>alphaThreshold){if(x<left)left=x;if(x>right)right=x;if(y<top)top=y;if(y>bottom)bottom=y}if(right<0||left===0&&top===0&&right===image.width-1&&bottom===image.height-1)return image;return crop(image,{left,top,width:right-left+1,height:bottom-top+1})}export function themed(images,section){return{...section??{},background:section?.background??images.background,color:section?.color??images.color,mutedColor:section?.mutedColor??images.mutedColor,accent:section?.accent??images.accent,device:section?.device??images.device,brand:section?.brand??images.brand,mark:section?.mark??images.mark,markPlate:section?.markPlate!==void 0?section.markPlate:images.markPlate}}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/image",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.30",
|
|
6
6
|
"description": "Native responsive image delivery for Stacks.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"prepublishOnly": "bun run build"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@stacksjs/types": "0.75.
|
|
35
|
-
"ts-images": "^0.2.
|
|
34
|
+
"@stacksjs/types": "0.75.30",
|
|
35
|
+
"ts-images": "^0.2.23"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"better-dx": "^0.2.24"
|