mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-13 19:19:10 +00:00
Add SVGA animation preview support
This commit is contained in:
@@ -48,7 +48,7 @@ public class Plugin : IViewer
|
||||
".pbm", ".pcx", ".pef", ".pgm", ".png", ".pnm", ".ppm", ".psb", ".psd", ".ptx", ".pxn",
|
||||
".qoi",
|
||||
".r3d", ".raf", ".raw", ".rw2", ".rwl", ".rwz",
|
||||
".sr2", ".srf", ".srw", ".svg", ".svgz",
|
||||
".sr2", ".srf", ".srw", ".svg", ".svga", ".svgz",
|
||||
".tga", ".tif", ".tiff",
|
||||
".wdp", ".webp", ".wmf",
|
||||
".x3f", ".xcf", ".xbm", ".xpm",
|
||||
@@ -114,7 +114,8 @@ public class Plugin : IViewer
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
if (path.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
|
||||
if (path.EndsWith(".svg", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.EndsWith(".svga", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (SettingHelper.Get("RenderSvgWeb", true, "QuickLook.Plugin.ImageViewer"))
|
||||
{
|
||||
@@ -145,7 +146,8 @@ public class Plugin : IViewer
|
||||
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
if (path.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
|
||||
if (path.EndsWith(".svg", StringComparison.OrdinalIgnoreCase)
|
||||
|| path.EndsWith(".svga", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (SettingHelper.Get("RenderSvgWeb", true, "QuickLook.Plugin.ImageViewer"))
|
||||
{
|
||||
|
@@ -91,7 +91,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\svg2html.*">
|
||||
<EmbeddedResource Include="Resources\svg*">
|
||||
<LogicalName>QuickLook.Plugin.ImageViewer.Resources.%(RecursiveDir)%(Filename)%(Extension)</LogicalName>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>SVGA Preview</title>
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<script src="https://unpkg.com/svga/dist/index.min.js"></script>
|
||||
<script src="svga2html.js"></script>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* SvgaViewer: Provides SVGA animation preview with the following features.
|
||||
*
|
||||
* Requirements:
|
||||
* - Requires the following HTML structure:
|
||||
* <canvas id="canvas">
|
||||
* </canvas>
|
||||
* - SVGA file path is obtained via chrome.webview.hostObjects.external.GetPath()
|
||||
*
|
||||
* Features:
|
||||
* - Loads and plays SVGA animation files
|
||||
* - Uses SVGA.js library for parsing and playback
|
||||
* - Automatically starts playback after loading
|
||||
* - Handles asynchronous loading and mounting of SVGA files
|
||||
*/
|
||||
class SvgaViewer {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Play SVGA file.
|
||||
* @async
|
||||
*/
|
||||
async play() {
|
||||
const path = await chrome.webview.hostObjects.external.GetPath();
|
||||
const parser = new SVGA.Parser();
|
||||
|
||||
// Because the path is a local file, we need to convert it to a URL format
|
||||
parser.load('https://' + path).then(svga => {
|
||||
const player = new SVGA.Player(document.getElementById('canvas'));
|
||||
player.mount(svga).then(() => {
|
||||
player.start();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Create the SVGA viewer and play
|
||||
new SvgaViewer().play();
|
@@ -99,7 +99,7 @@ public class SvgImagePanel : WebpagePanel
|
||||
|
||||
ObjectForScripting ??= new ScriptHandler(path);
|
||||
|
||||
_homePage = _resources["/svg2html.html"];
|
||||
_homePage = _resources[path.EndsWith(".svga", StringComparison.OrdinalIgnoreCase) ? "/svga2html.html" : "/svg2html.html"];
|
||||
NavigateToUri(new Uri("file://quicklook/"));
|
||||
}
|
||||
|
||||
@@ -145,6 +145,21 @@ public class SvgImagePanel : WebpagePanel
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (requestedUri.Scheme == "https")
|
||||
{
|
||||
var localPath = $"{requestedUri.Authority}:{requestedUri.AbsolutePath}".Replace('/', '\\');
|
||||
|
||||
if (localPath.StartsWith(_fallbackPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (File.Exists(localPath))
|
||||
{
|
||||
var fileStream = File.OpenRead(localPath);
|
||||
var response = _webView.CoreWebView2.Environment.CreateWebResourceResponse(
|
||||
fileStream, 200, "OK", MimeTypes.GetContentType() + "\r\nAccess-Control-Allow-Origin: *");
|
||||
args.Response = response;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -197,6 +212,16 @@ public sealed class ScriptHandler(string path)
|
||||
{
|
||||
public string Path { get; } = path;
|
||||
|
||||
public async Task<string> GetPath()
|
||||
{
|
||||
return await Task.FromResult(new Uri(Path).AbsolutePath);
|
||||
}
|
||||
|
||||
public async Task<string> GetUri()
|
||||
{
|
||||
return await Task.FromResult(new Uri(Path).AbsoluteUri);
|
||||
}
|
||||
|
||||
public async Task<string> GetSvgContent()
|
||||
{
|
||||
if (File.Exists(Path))
|
||||
|
@@ -23,6 +23,9 @@ public class SvgMetaProvider(string path)
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
if (_path.EndsWith(".svg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
var svgContent = File.ReadAllText(_path);
|
||||
@@ -56,6 +59,7 @@ public class SvgMetaProvider(string path)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
return _size;
|
||||
}
|
||||
|
Reference in New Issue
Block a user