quicklook-kit 0.5.0 → 0.7.0
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.markdown +146 -60
- package/dist/cli.mjs +250 -34
- package/dist/config-qdxXRvMf.mjs +271 -0
- package/dist/config.d.mts +64 -9
- package/dist/config.mjs +1 -1
- package/dist/runtime.d.mts +3 -3
- package/dist/runtime.mjs +1 -2
- package/dist/vite.d.mts +1 -3
- package/dist/vite.mjs +32 -9
- package/native/App/HostApp.swift +224 -8
- package/native/Extension/PreviewViewController.swift +8 -1
- package/native/Shared/Settings.swift +129 -0
- package/native/Windows/Plugin.cs +232 -0
- package/package.json +6 -4
- package/src/virtual.d.ts +2 -0
- package/dist/config-BQ-9qYNV.mjs +0 -113
package/README.markdown
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
[](https://www.npmjs.org/package/quicklook-kit)
|
|
5
5
|
[](https://github.com/idleberg/quicklook-kit/actions)
|
|
6
6
|
|
|
7
|
-
> Build
|
|
7
|
+
> Build Quick Look previews for macOS and Windows with Vite-based web frameworks, no Swift or C# required
|
|
8
8
|
|
|
9
|
-
Your preview is a web page. quicklook-kit builds it with your framework
|
|
9
|
+
Your preview is a web page. quicklook-kit builds it with your framework and wraps it in a small native host: a Quick Look extension on macOS, a [QuickLook](https://github.com/QL-Win/QuickLook) plugin on Windows. You never touch Swift, C# or Xcode.
|
|
10
10
|
|
|
11
11
|
Built-in support for SvelteKit, Astro, SolidStart, Nuxt and Analog. Any other framework that builds with Vite and writes a static `index.html` works through an integration.
|
|
12
12
|
|
|
13
13
|
## Requirements
|
|
14
14
|
|
|
15
|
-
- macOS 14 or later, with [Xcode](https://apps.apple.com/app/xcode/id497799835) installed
|
|
16
|
-
- [XcodeGen](https://github.com/yonaskolb/XcodeGen)
|
|
17
15
|
- [Node.js](https://nodejs.org) 22.17 or later, which runs the `quicklook` CLI
|
|
16
|
+
- For macOS: macOS 14 or later, with [Xcode](https://apps.apple.com/app/xcode/id497799835) and [XcodeGen](https://github.com/yonaskolb/XcodeGen) installed
|
|
17
|
+
- For Windows: the [.NET SDK](https://dotnet.microsoft.com/download), on any OS. Testing the plugin needs Windows with [QuickLook](https://github.com/QL-Win/QuickLook) and the Microsoft Edge WebView2 Runtime, which ships with Windows 11
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
@@ -31,23 +31,31 @@ To start from scratch, run `pnpm create quicklook` instead.
|
|
|
31
31
|
Create `quicklook.config.ts` in your project root:
|
|
32
32
|
|
|
33
33
|
```ts
|
|
34
|
-
import { defineConfig } from
|
|
34
|
+
import { defineConfig } from 'quicklook-kit';
|
|
35
35
|
|
|
36
36
|
export default defineConfig({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
name: 'Quick Look Example',
|
|
38
|
+
macos: {
|
|
39
|
+
bundleId: 'com.example.QuickLookExample',
|
|
40
|
+
types: [
|
|
41
|
+
{
|
|
42
|
+
id: 'com.example.QuickLookExample.example',
|
|
43
|
+
description: 'Example File',
|
|
44
|
+
extensions: ['example'],
|
|
45
|
+
conformsTo: ['public.plain-text'],
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
windows: {
|
|
50
|
+
id: 'QuickLook.Plugin.Example',
|
|
51
|
+
extensions: ['example'],
|
|
52
|
+
},
|
|
53
|
+
framework: 'sveltekit',
|
|
48
54
|
});
|
|
49
55
|
```
|
|
50
56
|
|
|
57
|
+
Each platform group is optional, but you need at least one: leave out `windows` to build for macOS only, or `macos` for Windows only.
|
|
58
|
+
|
|
51
59
|
A new type conforms to `public.plain-text` for text formats, or `public.data` for binary ones. To preview a type macOS already knows about, use a plain string like `'public.json'` in place of an object.
|
|
52
60
|
|
|
53
61
|
The config can also be `quicklook.config.js`, `.json`, `.yaml` or `.toml`, or a `.quicklookrc`. The keys are the same in every format.
|
|
@@ -55,15 +63,33 @@ The config can also be `quicklook.config.js`, `.json`, `.yaml` or `.toml`, or a
|
|
|
55
63
|
| Key | Default | |
|
|
56
64
|
| -------------- | ------------ | ---------------------------------------------------------------------------------- |
|
|
57
65
|
| `name` | required | App name, shown in Finder and System Settings |
|
|
58
|
-
| `
|
|
59
|
-
| `
|
|
66
|
+
| `macos` | none | macOS options, see below |
|
|
67
|
+
| `windows` | none | Windows options, see below |
|
|
60
68
|
| `framework` | required | `'sveltekit'`, `'astro'`, `'solid-start'`, `'nuxt'`, `'analog'`, or an integration |
|
|
61
|
-
| `icon` | none | Path to an `.icns` file for the app |
|
|
62
|
-
| `macOS` | `'14.0'` | Minimum macOS version |
|
|
63
69
|
| `integrations` | `[]` | See [Integrations](#integrations) |
|
|
64
70
|
| `csp` | locked down | Directives here replace the defaults of the same name |
|
|
65
71
|
| `maxFileSize` | `10_000_000` | Larger files get Quick Look's generic preview |
|
|
66
72
|
| `public` | `{}` | Values the page can read at build time |
|
|
73
|
+
| `settings` | `{}` | Settings the user edits in the app, see [Settings](#settings) |
|
|
74
|
+
| `devFile` | none | A file the dev server previews until you drop another, relative to the project |
|
|
75
|
+
|
|
76
|
+
Under `macos`:
|
|
77
|
+
|
|
78
|
+
| Key | Default | |
|
|
79
|
+
| ---------------- | -------- | ----------------------------------------- |
|
|
80
|
+
| `bundleId` | required | The extension gets `<bundleId>.Extension` |
|
|
81
|
+
| `types` | required | File types to preview |
|
|
82
|
+
| `icon` | none | Path to an `.icns` file for the app |
|
|
83
|
+
| `minimumVersion` | `'14.0'` | Minimum macOS version |
|
|
84
|
+
|
|
85
|
+
Under `windows`:
|
|
86
|
+
|
|
87
|
+
| Key | Default | |
|
|
88
|
+
| ------------ | -------- | ---------------------------------------------------------------------------------- |
|
|
89
|
+
| `id` | required | Plugin name, starting with `QuickLook.Plugin.`, e.g. `QuickLook.Plugin.Example` |
|
|
90
|
+
| `extensions` | required | File extensions to preview, without the dot. They win over QuickLook's own viewers |
|
|
91
|
+
|
|
92
|
+
Upgrading from a version without platform groups? The old top-level `bundleId`, `icon`, `macOS` and `types` now live under `macos`, with `macOS` renamed to `minimumVersion`.
|
|
67
93
|
|
|
68
94
|
A framework can take options as a `[name, options]` pair, e.g. `['sveltekit', { outDir: 'dist' }]` when your adapter writes somewhere other than the default.
|
|
69
95
|
|
|
@@ -80,7 +106,7 @@ Each framework needs a static, client-side build:
|
|
|
80
106
|
### 2. Add the Vite plugin
|
|
81
107
|
|
|
82
108
|
```ts
|
|
83
|
-
import { quicklook } from
|
|
109
|
+
import { quicklook } from 'quicklook-kit/vite';
|
|
84
110
|
|
|
85
111
|
// in the framework's Vite config
|
|
86
112
|
plugins: [quicklook()];
|
|
@@ -97,9 +123,9 @@ or in `tsconfig.json` under `compilerOptions.types` as `"quicklook-kit/virtual"`
|
|
|
97
123
|
### 3. Read the file
|
|
98
124
|
|
|
99
125
|
```ts
|
|
100
|
-
import { browserFile, config, nativeFile } from
|
|
126
|
+
import { browserFile, config, nativeFile } from 'virtual:quicklook';
|
|
101
127
|
|
|
102
|
-
const file = nativeFile(); // the previewed file
|
|
128
|
+
const file = nativeFile(); // the previewed file, undefined in the browser
|
|
103
129
|
config.public; // values from quicklook.config.*
|
|
104
130
|
```
|
|
105
131
|
|
|
@@ -111,69 +137,129 @@ config.public; // values from quicklook.config.*
|
|
|
111
137
|
|
|
112
138
|
Decode `bytes` however your format needs: `new TextDecoder().decode(file.bytes)` for text, or a parser for binary formats.
|
|
113
139
|
|
|
114
|
-
In the dev server, `nativeFile()` returns `undefined
|
|
140
|
+
In the dev server, `nativeFile()` returns `devFile` if you set one, and `undefined` otherwise. Pass a dropped or picked `File` to `browserFile()` to get the same shape.
|
|
115
141
|
|
|
116
142
|
### 4. Add scripts
|
|
117
143
|
|
|
118
144
|
```json
|
|
119
145
|
{
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
146
|
+
"scripts": {
|
|
147
|
+
"dev": "quicklook dev",
|
|
148
|
+
"build": "quicklook build",
|
|
149
|
+
"register": "quicklook build && quicklook register",
|
|
150
|
+
"unregister": "quicklook unregister"
|
|
151
|
+
}
|
|
126
152
|
}
|
|
127
153
|
```
|
|
128
154
|
|
|
129
155
|
## CLI
|
|
130
156
|
|
|
131
|
-
| Command | Description
|
|
132
|
-
| ---------------------- |
|
|
133
|
-
| `quicklook dev` | Starts the framework's dev server
|
|
134
|
-
| `quicklook build:web` | Builds the page only, into `.quicklook/web`
|
|
135
|
-
| `quicklook build` | Builds
|
|
136
|
-
| `quicklook register` |
|
|
137
|
-
| `quicklook unregister` | Removes
|
|
157
|
+
| Command | Description |
|
|
158
|
+
| ---------------------- | ----------------------------------------------------------------------------- |
|
|
159
|
+
| `quicklook dev` | Starts the framework's dev server |
|
|
160
|
+
| `quicklook build:web` | Builds the page only, into `.quicklook/web` |
|
|
161
|
+
| `quicklook build` | Builds every configured platform into `.quicklook/build/<platform>` |
|
|
162
|
+
| `quicklook register` | Installs the build on the current OS: the app on macOS, the plugin on Windows |
|
|
163
|
+
| `quicklook unregister` | Removes it again |
|
|
138
164
|
|
|
139
|
-
|
|
165
|
+
`build` takes `--platform macos` or `--platform windows` to build just one. The Windows plugin builds on any OS; the macOS app only on a Mac, so elsewhere `build` skips it. Run `build` and `register` again after every change.
|
|
140
166
|
|
|
141
|
-
If the preview doesn't show up, check `pluginkit -mAv | grep <your bundleId>`, and make sure no other app claims the same file type.
|
|
167
|
+
On macOS, `register` copies the app to `/Applications` and registers its extension. Select a file in Finder and press Space. If the preview doesn't show up, check `pluginkit -mAv | grep <your macos.bundleId>`, and make sure no other app claims the same file type.
|
|
168
|
+
|
|
169
|
+
On Windows, `register` copies the plugin to `%APPDATA%\pooi.moe\QuickLook\QuickLook.Plugin\<windows.id>`. Quit and restart QuickLook, then select a file in Explorer and press Space.
|
|
142
170
|
|
|
143
171
|
Add `.quicklook` to your `.gitignore`.
|
|
144
172
|
|
|
145
173
|
## Things to know
|
|
146
174
|
|
|
147
|
-
- **Nothing can be loaded from the network.** The
|
|
175
|
+
- **Nothing can be loaded from the network.** The native host serves your build from disk with a strict Content Security Policy, on both platforms. Import images, fonts and CSS normally and they get bundled. The dev server only reports violations in the console, without blocking them.
|
|
148
176
|
- **Inline scripts are allowed by hash.** Frameworks that bootstrap with inline `<script>` tags keep working; the hashes are added to the CSP at build time.
|
|
149
|
-
- **Test in Safari.**
|
|
177
|
+
- **Test in Safari and Edge.** macOS previews run in WebKit, like Safari; Windows previews in WebView2, like Edge.
|
|
150
178
|
- **The light/dark theme follows the system.** Use `prefers-color-scheme` in CSS.
|
|
151
|
-
- **The app is signed ad hoc.** Other people have to allow it in System Settings → Privacy & Security on first launch. Distributing it without that step requires an Apple Developer account and notarization.
|
|
179
|
+
- **The macOS app is signed ad hoc.** Other people have to allow it in System Settings → Privacy & Security on first launch. Distributing it without that step requires an Apple Developer account and notarization.
|
|
180
|
+
- **Windows users install the `.qlplugin`** from `.quicklook/build/windows` by previewing it in QuickLook and clicking the install button.
|
|
152
181
|
|
|
153
|
-
##
|
|
182
|
+
## Releasing
|
|
154
183
|
|
|
155
|
-
|
|
184
|
+
Projects made with `create quicklook` include a release workflow. Push a tag like `v1.0.0` and it builds every configured platform and attaches `<App>-v1.0.0-macos.zip` and `<App>-v1.0.0-windows.qlplugin` to a GitHub release.
|
|
185
|
+
|
|
186
|
+
If you publish a Homebrew cask, its URL needs the `-macos` suffix once you move to a release with platform groups.
|
|
187
|
+
|
|
188
|
+
## Settings
|
|
189
|
+
|
|
190
|
+
`settings` declares options the user can change. On macOS, the app shows a control for each entry, picked by its `type`:
|
|
156
191
|
|
|
157
192
|
```ts
|
|
158
|
-
|
|
193
|
+
settings: {
|
|
194
|
+
theme: {
|
|
195
|
+
type: "string",
|
|
196
|
+
default: "light",
|
|
197
|
+
enum: [{ value: "light", description: "Light" }, "dark"],
|
|
198
|
+
radio: true,
|
|
199
|
+
},
|
|
200
|
+
wrap: { type: "boolean", default: true, description: "Wrap **long** lines" },
|
|
201
|
+
fontSize: { type: "integer", default: 13, minimum: 9, maximum: 32 },
|
|
202
|
+
editor: {
|
|
203
|
+
type: "object",
|
|
204
|
+
properties: { tabSize: { type: "integer", default: 2, enum: [2, 4, 8] } },
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
```
|
|
159
208
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
209
|
+
| Type | Control |
|
|
210
|
+
| ------------------------------------------- | ------------------------------------------------------------------------- |
|
|
211
|
+
| `boolean` | Checkbox |
|
|
212
|
+
| `enum` (on `string`, `integer` or `number`) | Picker, or radio buttons with `radio: true` |
|
|
213
|
+
| `string` | Text field |
|
|
214
|
+
| `integer`, `number` | Number field, clamped to `minimum`/`maximum`; `integer` rejects fractions |
|
|
215
|
+
| `object` | A group with a heading, for nested `properties` |
|
|
165
216
|
|
|
166
|
-
|
|
167
|
-
async "build:done"({ outDir, config }) {},
|
|
217
|
+
Every entry except `object` needs a `default`. `title` defaults to the key in words (`fontSize` becomes "Font Size"), `description` is inline Markdown, and `order` sorts entries. `enum` entries are plain values or `{ value, description }`. A schema with an unknown type or field, a field on the wrong type, a key containing `.`, or a default that doesn't fit its type, `enum` or bounds fails the build with the key path, e.g. `settings.editor.tabSize: default 0 is below minimum 1`.
|
|
168
218
|
|
|
169
|
-
|
|
170
|
-
"xcode:spec"(spec, config) {
|
|
171
|
-
spec.targets.QuickLookExampleExtension.info.properties.MyKey = options.key;
|
|
172
|
-
},
|
|
219
|
+
The page reads the values, nested like the schema, with `settings()`:
|
|
173
220
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
221
|
+
```ts
|
|
222
|
+
import { settings } from 'virtual:quicklook';
|
|
223
|
+
|
|
224
|
+
const { wrap, editor } = settings();
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
In the dev server, `settings()` returns the defaults.
|
|
228
|
+
|
|
229
|
+
Windows has no settings window. Users set values in `%APPDATA%\pooi.moe\QuickLook\<windows.id>.config`, with nested keys joined by dots, and restart QuickLook. Values that don't fit the schema fall back to the default.
|
|
230
|
+
|
|
231
|
+
```xml
|
|
232
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
233
|
+
<Settings>
|
|
234
|
+
<theme>dark</theme>
|
|
235
|
+
<editor.tabSize>4</editor.tabSize>
|
|
236
|
+
</Settings>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Integrations
|
|
240
|
+
|
|
241
|
+
An integration is an object with a `name` and any of these hooks. They run in order: the framework first, then each entry in `integrations`.
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
import type { Integration } from 'quicklook-kit';
|
|
245
|
+
|
|
246
|
+
export default (options: { key: string }): Integration => ({
|
|
247
|
+
name: 'my-integration',
|
|
248
|
+
hooks: {
|
|
249
|
+
// Adjust the resolved config.
|
|
250
|
+
'config:resolved'(config) {},
|
|
251
|
+
|
|
252
|
+
// Post-process the framework's static output before it's bundled.
|
|
253
|
+
async 'build:done'({ outDir, config }) {},
|
|
254
|
+
|
|
255
|
+
// Edit the generated XcodeGen spec: Info.plist keys, entitlements, targets. macOS only.
|
|
256
|
+
'xcode:spec'(spec, config) {
|
|
257
|
+
spec.targets.QuickLookExampleExtension.info.properties.MyKey = options.key;
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
// Add Vite plugins wherever quicklook() is used.
|
|
261
|
+
vite: () => [],
|
|
262
|
+
},
|
|
177
263
|
});
|
|
178
264
|
```
|
|
179
265
|
|
|
@@ -181,7 +267,7 @@ Add it as an object, or by name so JSON and YAML configs can use it too. A name
|
|
|
181
267
|
|
|
182
268
|
```jsonc
|
|
183
269
|
{
|
|
184
|
-
|
|
270
|
+
"integrations": ["quicklook-some-package", ["./my-integration.ts", { "key": "value" }]]
|
|
185
271
|
}
|
|
186
272
|
```
|
|
187
273
|
|