@kaciras-blog/media
Advanced tools
Comparing version 2.0.2 to 2.1.0
import { mean, median, sum } from "simple-statistics"; | ||
import { hrsize } from "../common.js"; | ||
import { formatSize } from "@kaciras/utilities"; | ||
import { CachedService, DispatchService, LocalFileStore, RasterOptimizer, SVGOptimizer, } from "../index.js"; | ||
@@ -32,4 +32,4 @@ const base = { | ||
count: items.length, | ||
median: hrsize(median(sizes)), | ||
mean: hrsize(mean(sizes)), | ||
median: formatSize(median(sizes)), | ||
mean: formatSize(mean(sizes)), | ||
"ratio %": (sum(sizes) / uncompressed * 100).toFixed(2), | ||
@@ -66,4 +66,4 @@ }); | ||
totalSize: sum(sizes), | ||
mean: hrsize(mean(sizes)), | ||
median: hrsize(median(sizes)), | ||
mean: formatSize(mean(sizes)), | ||
median: formatSize(median(sizes)), | ||
}); | ||
@@ -70,0 +70,0 @@ } |
import { mean, median, sum } from "simple-statistics"; | ||
import { hrsize } from "../common.js"; | ||
import { formatSize } from "@kaciras/utilities"; | ||
import { | ||
@@ -56,4 +56,4 @@ CachedService, | ||
count: items.length, | ||
median: hrsize(median(sizes)), | ||
mean: hrsize(mean(sizes)), | ||
median: formatSize(median(sizes)), | ||
mean: formatSize(mean(sizes)), | ||
"ratio %": (sum(sizes) / uncompressed * 100).toFixed(2), | ||
@@ -96,4 +96,4 @@ }); | ||
totalSize: sum(sizes), | ||
mean: hrsize(mean(sizes)), | ||
median: hrsize(median(sizes)), | ||
mean: formatSize(mean(sizes)), | ||
median: formatSize(median(sizes)), | ||
}); | ||
@@ -100,0 +100,0 @@ } |
@@ -53,18 +53,2 @@ import { xxHash3_128 } from "@kaciras-blog/nativelib"; | ||
} | ||
const SIZE_UNITS = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]; | ||
/** | ||
* Convert bytes to a human readable string. | ||
* | ||
* @param value The number to format. | ||
* @param fraction 1000 for SI or 1024 for IEC. | ||
*/ | ||
export function hrsize(value, fraction = 1024) { | ||
const size = Math.abs(value); | ||
if (size === 0) { | ||
return `${value.toFixed(2)} B`; | ||
} | ||
const i = ~~(Math.log2(size) / Math.log2(fraction)); | ||
const v = value / (fraction ** i); | ||
return `${v.toFixed(2)} ${SIZE_UNITS[i]}B`; | ||
} | ||
//# sourceMappingURL=common.js.map |
@@ -56,21 +56,1 @@ import { xxHash3_128 } from "@kaciras-blog/nativelib"; | ||
} | ||
const SIZE_UNITS = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"]; | ||
/** | ||
* Convert bytes to a human readable string. | ||
* | ||
* @param value The number to format. | ||
* @param fraction 1000 for SI or 1024 for IEC. | ||
*/ | ||
export function hrsize(value: number, fraction: 1024 | 1000 = 1024) { | ||
const size = Math.abs(value); | ||
if (size === 0) { | ||
return `${value.toFixed(2)} B`; | ||
} | ||
const i = ~~(Math.log2(size) / Math.log2(fraction)); | ||
const v = value / (fraction ** i); | ||
return `${v.toFixed(2)} ${SIZE_UNITS[i]}B`; | ||
} |
{ | ||
"name": "@kaciras-blog/media", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Media processor for Kaciras Blog", | ||
@@ -22,2 +22,3 @@ "license": "MIT", | ||
"@kaciras-blog/nativelib": "^0.3.1", | ||
"@kaciras/utilities": "^0.1.0", | ||
"cli-progress": "^3.10.0", | ||
@@ -29,3 +30,3 @@ "execa": "^6.1.0", | ||
"is-png": "^3.0.1", | ||
"log4js": "^6.4.3", | ||
"log4js": "^6.4.4", | ||
"mozjpeg": "^8.0.0", | ||
@@ -43,6 +44,6 @@ "sharp": "^0.30.3", | ||
"@types/sharp": "^0.30.0", | ||
"@types/svgo": "^2.6.2", | ||
"@types/svgo": "^2.6.3", | ||
"file-type": "^17.1.1" | ||
}, | ||
"readme": "# 项目简介\n\nKaciras Blog 的媒体处理库,支持图片、视频等资源的存储。\n\n主要功能:\n\n- 图片处理,包括裁剪、缩放、压缩等。\n\n- 优化图片,并转码为多种新格式。\n\n- 根据 Accept-* 头部自动选择最佳格式下载。\n\n- 上传同一视频的多种编码版本,同样下载时返回最佳格式。\n" | ||
"readme": "# @kaciras-blog/media\n\nKaciras Blog 的媒体处理库,支持图片、视频等资源的存储。\n\n主要功能:\n\n- 图片处理,包括裁剪、缩放、压缩等。\n\n- 优化图片,并转码为多种新格式。\n\n- 根据 Accept-* 头部自动选择最佳格式下载。\n\n- 上传同一视频的多种编码版本,同样下载时返回最佳格式。\n\n## 渐进升级策略\n\n有两种策略可以用来对资源进行渐进升级:\n\n* 前端选择:通过`<source>`指定多个 URL,浏览器自动忽略不支持的;还可以用 ServiceWorker 将请求重定向到优化版本。\n* 后端选择:服务端通过请求信息比如 `Accept` 判断客户端支持哪些,然后选出最佳的。\n\n后端选择通常具有更好的兼容性,例如构建图床服务,无需更改第三方网站的代码即可发送优化版本。但目前并非所有特性支持都能从请求中获取到,比如视频编码(hevc、av1)就不行。\n\n这两种策略并不矛盾,可以同时使用,本项目设计时就以支持后端选择为目标。\n" | ||
} |
@@ -1,2 +0,2 @@ | ||
# 项目简介 | ||
# @kaciras-blog/media | ||
@@ -14,1 +14,12 @@ Kaciras Blog 的媒体处理库,支持图片、视频等资源的存储。 | ||
- 上传同一视频的多种编码版本,同样下载时返回最佳格式。 | ||
## 渐进升级策略 | ||
有两种策略可以用来对资源进行渐进升级: | ||
* 前端选择:通过`<source>`指定多个 URL,浏览器自动忽略不支持的;还可以用 ServiceWorker 将请求重定向到优化版本。 | ||
* 后端选择:服务端通过请求信息比如 `Accept` 判断客户端支持哪些,然后选出最佳的。 | ||
后端选择通常具有更好的兼容性,例如构建图床服务,无需更改第三方网站的代码即可发送优化版本。但目前并非所有特性支持都能从请求中获取到,比如视频编码(hevc、av1)就不行。 | ||
这两种策略并不矛盾,可以同时使用,本项目设计时就以支持后端选择为目标。 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25
93034
13
1834
+ Added@kaciras/utilities@^0.1.0
+ Added@kaciras/utilities@0.1.0(transitive)
Updatedlog4js@^6.4.4