mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-13 19:19:10 +00:00
Add support for svgaplayerweb in SVGA viewer
This commit is contained in:
@@ -74,6 +74,7 @@
|
|||||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2">
|
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.2">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="System.Text.Json" Version="9.0.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(DefineConstants)' != '' and $(DefineConstants.Contains('USESVGSKIA')) ">
|
<ItemGroup Condition=" '$(DefineConstants)' != '' and $(DefineConstants.Contains('USESVGSKIA')) ">
|
||||||
|
@@ -9,12 +9,13 @@
|
|||||||
*
|
*
|
||||||
* Features:
|
* Features:
|
||||||
* - Loads and plays SVGA animation files
|
* - Loads and plays SVGA animation files
|
||||||
* - Uses SVGA.js library for parsing and playback
|
* - Uses svga or svgaplayerweb library for parsing and playback
|
||||||
* - Automatically starts playback after loading
|
* - Automatically starts playback after loading
|
||||||
* - Handles asynchronous loading and mounting of SVGA files
|
* - Handles asynchronous loading and mounting of SVGA files
|
||||||
*/
|
*/
|
||||||
class SvgaViewer {
|
class SvgaViewer {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.useLite = false; // Use SVGA Lite version if true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,15 +24,32 @@ class SvgaViewer {
|
|||||||
*/
|
*/
|
||||||
async play() {
|
async play() {
|
||||||
const path = await chrome.webview.hostObjects.external.GetPath();
|
const path = await chrome.webview.hostObjects.external.GetPath();
|
||||||
const parser = new SVGA.Parser(); // Only SVGA 2.x supported
|
|
||||||
|
|
||||||
// Because the path is a local file, we need to convert it to a URL format
|
if (this.useLite) {
|
||||||
parser.load('https://' + path).then(svga => {
|
const parser = new SVGA.Parser(); // Only SVGA 2.x supported
|
||||||
const player = new SVGA.Player(document.getElementById('canvas'));
|
|
||||||
player.mount(svga).then(() => {
|
// Because the path is a local file, we need to convert it to a URL format
|
||||||
player.start();
|
parser.load('https://' + path).then(svga => {
|
||||||
|
const player = new SVGA.Player(document.getElementById('canvas'));
|
||||||
|
player.mount(svga).then(() => {
|
||||||
|
player.start();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
const size = JSON.parse(await chrome.webview.hostObjects.external.GetSize());
|
||||||
|
const parser = new SVGA.Parser('#canvas'); // Only SVGA 2.x supported
|
||||||
|
const player = new SVGA.Player('#canvas');
|
||||||
|
const canvas = document.getElementById('canvas');
|
||||||
|
|
||||||
|
canvas.width = size.width;
|
||||||
|
canvas.height = size.height;
|
||||||
|
|
||||||
|
// Because the path is a local file, we need to convert it to a URL format
|
||||||
|
parser.load('https://' + path, function (videoItem) {
|
||||||
|
player.setVideoItem(videoItem);
|
||||||
|
player.startAnimation();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,7 +19,9 @@
|
|||||||
<body>
|
<body>
|
||||||
<canvas id="canvas"></canvas>
|
<canvas id="canvas"></canvas>
|
||||||
<!--<script src="https://unpkg.com/svga/dist/index.min.js"></script>-->
|
<!--<script src="https://unpkg.com/svga/dist/index.min.js"></script>-->
|
||||||
<script src="svga/index.min.js"></script>
|
<!--<script src="svga/index.min.js"></script>-->
|
||||||
|
<!--<script src="https://unpkg.com/svgaplayerweb/build/svga.min.js"></script>-->
|
||||||
|
<script src="svgaplayerweb/svga.min.js"></script>
|
||||||
<script src="js/svga2html.js"></script>
|
<script src="js/svga2html.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
1
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/Web/svgaplayerweb/svga.min.js
vendored
Normal file
1
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Resources/Web/svgaplayerweb/svga.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -19,7 +19,7 @@ using System;
|
|||||||
|
|
||||||
namespace QuickLook.Plugin.ImageViewer.Webview;
|
namespace QuickLook.Plugin.ImageViewer.Webview;
|
||||||
|
|
||||||
internal interface IWebImagePanel : IDisposable
|
public interface IWebImagePanel : IDisposable
|
||||||
{
|
{
|
||||||
public void Preview(string path);
|
public void Preview(string path);
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ using System.Windows;
|
|||||||
|
|
||||||
namespace QuickLook.Plugin.ImageViewer.Webview;
|
namespace QuickLook.Plugin.ImageViewer.Webview;
|
||||||
|
|
||||||
internal interface IWebMetaProvider
|
public interface IWebMetaProvider
|
||||||
{
|
{
|
||||||
public Size GetSize();
|
public Size GetSize();
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,9 @@ using QuickLook.Plugin.ImageViewer.Webview.Svg;
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace QuickLook.Plugin.ImageViewer.Webview.Lottie;
|
namespace QuickLook.Plugin.ImageViewer.Webview.Lottie;
|
||||||
|
|
||||||
@@ -76,3 +78,15 @@ public class LottieImagePanel : SvgImagePanel
|
|||||||
base.WebView_WebResourceRequested(sender, args);
|
base.WebView_WebResourceRequested(sender, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ClassInterface(ClassInterfaceType.AutoDual)]
|
||||||
|
[ComVisible(true)]
|
||||||
|
public sealed class ScriptHandler(string path)
|
||||||
|
{
|
||||||
|
public string Path { get; } = path;
|
||||||
|
|
||||||
|
public async Task<string> GetPath()
|
||||||
|
{
|
||||||
|
return await Task.FromResult(new Uri(Path).AbsolutePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -15,21 +15,48 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
using Google.Protobuf.Compiler;
|
||||||
using QuickLook.Plugin.ImageViewer.Webview.Svg;
|
using QuickLook.Plugin.ImageViewer.Webview.Svg;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
namespace QuickLook.Plugin.ImageViewer.Webview.Svga;
|
namespace QuickLook.Plugin.ImageViewer.Webview.Svga;
|
||||||
|
|
||||||
public class SvgaImagePanel : SvgImagePanel
|
public class SvgaImagePanel(IWebMetaProvider metaWeb) : SvgImagePanel()
|
||||||
{
|
{
|
||||||
|
private readonly IWebMetaProvider _metaWeb = metaWeb;
|
||||||
|
|
||||||
public override void Preview(string path)
|
public override void Preview(string path)
|
||||||
{
|
{
|
||||||
FallbackPath = Path.GetDirectoryName(path);
|
FallbackPath = Path.GetDirectoryName(path);
|
||||||
|
|
||||||
ObjectForScripting ??= new ScriptHandler(path);
|
ObjectForScripting ??= new ScriptHandler(path, _metaWeb);
|
||||||
|
|
||||||
_homePage = _resources["/svga2html.html"];
|
_homePage = _resources["/svga2html.html"];
|
||||||
NavigateToUri(new Uri("file://quicklook/"));
|
NavigateToUri(new Uri("file://quicklook/"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ClassInterface(ClassInterfaceType.AutoDual)]
|
||||||
|
[ComVisible(true)]
|
||||||
|
public sealed class ScriptHandler(string path, IWebMetaProvider metaWeb)
|
||||||
|
{
|
||||||
|
public string Path { get; } = path;
|
||||||
|
public IWebMetaProvider MetaWeb { get; } = metaWeb;
|
||||||
|
|
||||||
|
public async Task<string> GetPath()
|
||||||
|
{
|
||||||
|
return await Task.FromResult(new Uri(Path).AbsolutePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetSize()
|
||||||
|
{
|
||||||
|
var size = MetaWeb.GetSize();
|
||||||
|
string jsonString = JsonSerializer.Serialize(new { width = size.Width, height = size.Height });
|
||||||
|
return await Task.FromResult(jsonString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -99,7 +99,7 @@ internal static class WebHandler
|
|||||||
ipWeb = ext switch
|
ipWeb = ext switch
|
||||||
{
|
{
|
||||||
".svg" => new SvgImagePanel(),
|
".svg" => new SvgImagePanel(),
|
||||||
".svga" => new SvgaImagePanel(),
|
".svga" => new SvgaImagePanel(metaWeb),
|
||||||
".lottie" or ".json" => new LottieImagePanel(),
|
".lottie" or ".json" => new LottieImagePanel(),
|
||||||
_ => throw new NotSupportedException($"Unsupported file type: {ext}")
|
_ => throw new NotSupportedException($"Unsupported file type: {ext}")
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user