vvvfs 0.2.2 → 0.2.3

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/README.md CHANGED
@@ -102,12 +102,14 @@ const vvvfs = new VVVFS("vvvfs", {
102
102
  // 用法与 vvvfs 相当
103
103
  ```
104
104
 
105
- ### 使用 `<fs-img>` 自定义元素
105
+ ### 使用 `<fs-img>` / `<fs-audio>` / `<fs-video>` 自定义元素
106
106
 
107
- 库加载后会自动注册 `<fs-img>` 元素,可直接显示 vvvfs 中的图片文件:
107
+ 库加载后会自动注册这三个元素,可直接显示 / 播放 vvvfs 中的媒体文件:
108
108
 
109
109
  ```html
110
110
  <fs-img src="/home/user/Pictures/logo.png" alt="Logo" width="120"></fs-img>
111
+ <fs-audio src="/home/user/Music/demo.mp3"></fs-audio>
112
+ <fs-video src="/home/user/Videos/demo.mp4" width="320"></fs-video>
111
113
  ```
112
114
 
113
115
  ```javascript
@@ -117,19 +119,33 @@ img.src = "/home/user/Pictures/logo.png";
117
119
  document.body.appendChild(img);
118
120
  ```
119
121
 
120
- 属性:
122
+ 三者共有的属性:
121
123
 
122
- - `src` / `path`:图片在 vvvfs 中的路径(`src` 优先)
124
+ - `src` / `path`:文件在 vvvfs 中的路径(`src` 优先)
123
125
  - `dbname`:数据库名,默认 `vvvfs`;未指定且存在全局 `vvvfs` 实例时直接使用该实例
124
- - `alt` / `width` / `height`:透传到内部 `<img>` 元素
125
- - `watch`:存在时,文件内容发生变化后自动刷新
126
+ - `watch`:`true` 时启用文件监听,`false` 时停止监听;启用后文件内容发生变化会自动刷新(缺省或空值视为 `true`,兼容 `<fs-img watch>` 的写法)
127
+
128
+ 各自的属性:
129
+
130
+ - `<fs-img>`:`alt` / `width` / `height` 透传到内部 `<img>` 元素
131
+ - `<fs-audio>`:`autoplay` / `loop` / `muted` / `preload` 透传到内部 `<audio>` 元素;`controls` 默认开启,移除该属性即可关闭
132
+ - `<fs-video>`:`autoplay` / `loop` / `muted` / `preload` / `width` / `height` 透传到内部 `<video>` 元素;`controls` 默认开启,移除该属性即可关闭
126
133
 
127
134
  事件:`load`(加载完成)、`error`(加载失败),`detail` 中包含 `path` 与 `file`(或 `message`)。元素上还会写入 `data-state` 属性(`loading` / `loaded` / `error`),便于 CSS 定制。
128
135
 
129
- 内部使用 Shadow DOM 渲染:图片暴露为 `part="img"`,可用 `fs-img::part(img) { ... }` 定制样式;默认插槽内容会在加载失败或未设置路径时显示(如 `<fs-img src="/a.png">加载失败</fs-img>`)。
136
+ 此外提供 `data` 属性(JS 属性),返回当前媒体文件的 Blob 对象(未加载或加载失败时为 `null`),可用于上传、二次处理等场景。
137
+
138
+ 内部使用 Shadow DOM 渲染:媒体元素分别暴露为 `part="img"` / `part="audio"` / `part="video"`,可用 `fs-img::part(img) { ... }` 等定制样式;默认插槽内容会在加载失败或未设置路径时显示(如 `<fs-audio src="/a.mp3">加载失败</fs-audio>`)。
130
139
 
131
140
  ## 更新日志
132
141
 
142
+ ### 0.2.3
143
+
144
+ - 新增 `<fs-audio>` 自定义元素,可直接播放 vvvfs 中的音频文件
145
+ - 新增 `<fs-video>` 自定义元素,可直接播放 vvvfs 中的视频文件
146
+ - `<fs-img>` / `<fs-audio>` / `<fs-video>` 新增 `data` 属性,返回当前媒体文件的 Blob 对象(未加载时为 `null`)
147
+ - `<fs-img>` / `<fs-audio>` / `<fs-video>` 的 `watch` 属性支持 `true` / `false`,为 `false` 时停止文件监听
148
+
133
149
  ### 0.2.2
134
150
 
135
151
  - 新增 `<fs-img>` 自定义元素,可直接显示 vvvfs 中的图片文件
@@ -337,34 +353,50 @@ Using the `VVVFS.File` class:
337
353
  // The usage is equivalent to vvvfs
338
354
  ```
339
355
 
340
- ### Using the `<fs-img>` Custom Element
356
+ ### Using the `<fs-img>` / `<fs-audio>` / `<fs-video>` Custom Elements
341
357
 
342
- Once the library is loaded, the `<fs-img>` element is registered automatically and can display image files stored in vvvfs directly:
358
+ Once the library is loaded, these three elements are registered automatically and can display / play media files stored in vvvfs directly:
343
359
 
344
360
  ```html
345
361
  <fs-img src="/home/user/Pictures/logo.png" alt="Logo" width="120"></fs-img>
362
+ <fs-audio src="/home/user/Music/demo.mp3"></fs-audio>
363
+ <fs-video src="/home/user/Videos/demo.mp4" width="320"></fs-video>
346
364
  ```
347
365
 
348
366
  ```javascript
349
- // It can also be created dynamically
367
+ // They can also be created dynamically
350
368
  const img = document.createElement("fs-img");
351
369
  img.src = "/home/user/Pictures/logo.png";
352
370
  document.body.appendChild(img);
353
371
  ```
354
372
 
355
- Attributes:
373
+ Attributes shared by all three:
356
374
 
357
- - `src` / `path`: path of the image inside vvvfs (`src` takes precedence)
375
+ - `src` / `path`: path of the file inside vvvfs (`src` takes precedence)
358
376
  - `dbname`: database name, defaults to `vvvfs`; when omitted and a global `vvvfs` instance exists, that instance is used directly
359
- - `alt` / `width` / `height`: passed through to the inner `<img>` element
360
- - `watch`: when present, the image is refreshed automatically after the file content changes
377
+ - `watch`: `true` enables file watching and `false` disables it; when enabled, the media is refreshed automatically after the file content changes (a missing or empty value is treated as `true`, for compatibility with `<fs-img watch>`)
361
378
 
362
- Events: `load` (image loaded) and `error` (loading failed); `detail` contains `path` plus `file` (or `message`). A `data-state` attribute (`loading` / `loaded` / `error`) is also written to the element for CSS customization.
379
+ Element-specific attributes:
363
380
 
364
- Rendering happens inside a Shadow DOM: the image is exposed as `part="img"`, so it can be styled with `fs-img::part(img) { ... }`; the default slot content is shown when loading fails or no path is set (e.g. `<fs-img src="/a.png">failed</fs-img>`).
381
+ - `<fs-img>`: `alt` / `width` / `height` are passed through to the inner `<img>` element
382
+ - `<fs-audio>`: `autoplay` / `loop` / `muted` / `preload` are passed through to the inner `<audio>` element; `controls` is enabled by default and can be turned off by removing the attribute
383
+ - `<fs-video>`: `autoplay` / `loop` / `muted` / `preload` / `width` / `height` are passed through to the inner `<video>` element; `controls` is enabled by default and can be turned off by removing the attribute
384
+
385
+ Events: `load` (media loaded) and `error` (loading failed); `detail` contains `path` plus `file` (or `message`). A `data-state` attribute (`loading` / `loaded` / `error`) is also written to the element for CSS customization.
386
+
387
+ A `data` property (JS property) is also available, returning the Blob object of the current media file (`null` before loading or after a failure), which is useful for uploading or further processing.
388
+
389
+ Rendering happens inside a Shadow DOM: the media element is exposed as `part="img"` / `part="audio"` / `part="video"`, so it can be styled with `fs-img::part(img) { ... }` and friends; the default slot content is shown when loading fails or no path is set (e.g. `<fs-audio src="/a.mp3">failed</fs-audio>`).
365
390
 
366
391
  ## Changelog
367
392
 
393
+ ### 0.2.3
394
+
395
+ - Added the `<fs-audio>` custom element to play audio files stored in vvvfs directly
396
+ - Added the `<fs-video>` custom element to play video files stored in vvvfs directly
397
+ - Added the `data` property to `<fs-img>` / `<fs-audio>` / `<fs-video>`, returning the Blob object of the current media file (`null` before loading)
398
+ - The `watch` attribute of `<fs-img>` / `<fs-audio>` / `<fs-video>` now accepts `true` / `false`; `false` stops the file watching
399
+
368
400
  ### 0.2.2
369
401
 
370
402
  - Added the `<fs-img>` custom element to display image files stored in vvvfs directly