@skathi-native/cli 0.1.0-beta.4 → 0.2.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/aot-inputs.ts +21 -2
- package/build.ts +241 -60
- package/check/bundle.ts +265 -0
- package/check/graph.ts +3 -1
- package/check/index.ts +10 -1
- package/check/program.ts +26 -6
- package/cli/create.ts +29 -7
- package/devtools/commands.ts +25 -0
- package/effects/compile.ts +160 -31
- package/effects/sk.slang +353 -29
- package/package.json +7 -4
- package/prod.ts +40 -7
- package/svelte.ts +76 -0
- package/templates/icon.png +0 -0
- package/templates/showcase/assets/textures/golden.png +0 -0
- package/templates/showcase/assets/textures/hammered.png +0 -0
- package/templates/showcase/assets/textures/noir.png +0 -0
- package/templates/showcase/assets/textures/reeded.png +0 -0
- package/templates/showcase/assets/textures/teal-orange.png +0 -0
- package/templates/showcase/shaders/dissolve.slang +40 -0
- package/templates/showcase/shaders/fireflies.slang +58 -0
- package/templates/showcase/shaders/glass.slang +31 -0
- package/templates/showcase/shaders/grade.slang +34 -0
- package/templates/showcase/shaders/halftone.slang +42 -0
- package/templates/showcase/shaders/lens.slang +51 -0
- package/templates/showcase/shaders/nebula.slang +57 -0
- package/templates/showcase/shaders/orbit.slang +52 -0
- package/templates/showcase/shaders/pond.slang +76 -0
- package/templates/showcase/shaders/ripples.slang +71 -0
- package/templates/showcase/shaders/shatter.slang +116 -0
- package/templates/showcase/shaders/snow.slang +57 -0
- package/templates/showcase/shaders/spotlight.slang +52 -0
- package/templates/showcase/src/App.vue +11 -16
- package/templates/showcase/src/components/FullWindow.vue +77 -0
- package/templates/showcase/src/components/Page.vue +2 -0
- package/templates/showcase/src/fullwindow.ts +36 -0
- package/templates/showcase/src/icons.ts +2 -0
- package/templates/showcase/src/pages/GraphicsPage.vue +122 -0
- package/templates/showcase/src/pages/MotionPage.vue +71 -1
- package/templates/showcase/src/pages/ShadersPage.vue +443 -0
- package/templates/showcase/src/router.ts +32 -1
- package/templates/svelte/.vscode/settings.json +3 -0
- package/templates/svelte/assets/hello.txt +1 -0
- package/templates/svelte/src/App.svelte +142 -0
- package/templates/svelte/src/main.ts +4 -0
- package/vitecompat.ts +2 -0
package/effects/sk.slang
CHANGED
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
// the engine draws a premultiplied result (see `sk_finish`).
|
|
35
35
|
// * Effects compile at `ps_5_0`; the rest of gpui stays at `ps_4_1`.
|
|
36
36
|
// * An effect declares no textures, samplers or buffers: it reads
|
|
37
|
-
// `EffectInput` and its own fields, nothing else.
|
|
37
|
+
// `EffectInput` and its own fields, nothing else. An image is a field
|
|
38
|
+
// too: `SkTexture lut;`, `url(...)` in CSS.
|
|
38
39
|
|
|
39
40
|
module sk;
|
|
40
41
|
|
|
@@ -66,6 +67,62 @@ public struct SkBackdropAttribute
|
|
|
66
67
|
{
|
|
67
68
|
};
|
|
68
69
|
|
|
70
|
+
/// This effect shades its element's OWN painting: `input.content`,
|
|
71
|
+
/// `contentAt`, `contentAtPx`. The element and its whole subtree (background,
|
|
72
|
+
/// border, shadows, outline, children, text, video, carets, animations) paint
|
|
73
|
+
/// into an offscreen group the size of the window, at full opacity, and the
|
|
74
|
+
/// effect is drawn in their place; what it returns is all that shows of them.
|
|
75
|
+
///
|
|
76
|
+
/// * The drawn quad is the border box, dilated by a `[SkBleed]` parameter:
|
|
77
|
+
/// content can be moved out to it (a box-shadow outside the box shows only
|
|
78
|
+
/// there). Sampling anywhere else in the window is allowed and reads
|
|
79
|
+
/// transparent where the element painted nothing.
|
|
80
|
+
/// * `opacity` applies once, to the result; the content is opaque in the
|
|
81
|
+
/// group. `overflow` clips of ancestors cut the result like any effect's.
|
|
82
|
+
/// * A transform moves the content and the quad together; a rotation or skew
|
|
83
|
+
/// cannot be drawn by an effect, and the element then shows unshaded.
|
|
84
|
+
/// * Hit testing is unchanged: it follows layout, never pixels.
|
|
85
|
+
/// * The group is a Backdrop Root: a `backdrop-filter` or backdrop effect
|
|
86
|
+
/// inside it sees the element's own painting, not the page. The element's
|
|
87
|
+
/// own `backdrop-filter` still reads the page. With `[SkBackdrop]` too, the
|
|
88
|
+
/// effect owns its quad and composites the content over the backdrop
|
|
89
|
+
/// itself (`sk_over(input.backdrop, input.content)`).
|
|
90
|
+
/// * Cost: one window-sized offscreen target per nesting depth (pooled,
|
|
91
|
+
/// released after 90 idle frames) and the subtree drawn into it every
|
|
92
|
+
/// frame the window paints.
|
|
93
|
+
[__AttributeUsage(_AttributeTargets.Struct)]
|
|
94
|
+
public struct SkContentAttribute
|
|
95
|
+
{
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/// This effect keeps state from frame to frame: `input.history`,
|
|
99
|
+
/// `historyAt`, `historyAtPx` read what it stored the last time it stepped,
|
|
100
|
+
/// per element and effect. The history is two RGBA 16-bit float textures the
|
|
101
|
+
/// size of the drawn quad in device pixels (16 bytes a pixel), zero when the
|
|
102
|
+
/// element first draws, started over when that size changes and freed the
|
|
103
|
+
/// first frame the element is not painted.
|
|
104
|
+
///
|
|
105
|
+
/// Each step stores what `update` returns for every texel, unclamped; an
|
|
106
|
+
/// effect that does not declare `override float4 update(EffectInput input)`
|
|
107
|
+
/// stores what `shade` returned. Both
|
|
108
|
+
/// `shade` and `update` read the state as the LAST step left it, so the first
|
|
109
|
+
/// frame reads zeros. `update` runs with `input.historyPass` set and reads
|
|
110
|
+
/// content and history but never the backdrop.
|
|
111
|
+
///
|
|
112
|
+
/// * A history steps at most once per painted frame and at most about 75
|
|
113
|
+
/// times a second, so a simulation runs at the same speed at 60 and 144
|
|
114
|
+
/// Hz. It only steps while the window repaints: animate the effect
|
|
115
|
+
/// (`[SkAnimated]`, `[SkAnimatedFor]`, or `[SkPointer]`, which repaints
|
|
116
|
+
/// on pointer moves) for as long as the state should keep changing.
|
|
117
|
+
/// * Limits: no history on a quad longer than 4096 device pixels on a side,
|
|
118
|
+
/// and at most 256 MiB of histories per window; past them it reads zeros.
|
|
119
|
+
/// * The element needs an identity to key its state by (every Skathi element
|
|
120
|
+
/// has one).
|
|
121
|
+
[__AttributeUsage(_AttributeTargets.Struct)]
|
|
122
|
+
public struct SkHistoryAttribute
|
|
123
|
+
{
|
|
124
|
+
};
|
|
125
|
+
|
|
69
126
|
/// One line of author-facing documentation, echoed in CSS advisories.
|
|
70
127
|
[__AttributeUsage(_AttributeTargets.Struct)]
|
|
71
128
|
public struct SkDocAttribute
|
|
@@ -122,7 +179,7 @@ public struct SkOptionalAttribute
|
|
|
122
179
|
{
|
|
123
180
|
};
|
|
124
181
|
|
|
125
|
-
/// Pins this parameter to an explicit slot in the
|
|
182
|
+
/// Pins this parameter to an explicit slot in the 32-float parameter block,
|
|
126
183
|
/// instead of letting the packer choose. Unpinned fields then fill the gaps in
|
|
127
184
|
/// declaration order.
|
|
128
185
|
///
|
|
@@ -161,6 +218,47 @@ public struct SkAnimatedAttribute
|
|
|
161
218
|
{
|
|
162
219
|
};
|
|
163
220
|
|
|
221
|
+
/// Every component of this parameter is a time on the effect clock (the
|
|
222
|
+
/// clock `input.time` reads, which is `performance.now() / 1000` in JS). The
|
|
223
|
+
/// window keeps repainting until `seconds` after the latest of them, then the
|
|
224
|
+
/// effect costs nothing until a parameter changes: hand it the time something
|
|
225
|
+
/// started instead of rewriting an age every frame.
|
|
226
|
+
[__AttributeUsage(_AttributeTargets.Var)]
|
|
227
|
+
public struct SkAnimatedForAttribute
|
|
228
|
+
{
|
|
229
|
+
public float seconds;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/// A `float2` the host fills with the pointer's position in `input.local`
|
|
233
|
+
/// units: 0..1 across the element, beyond that outside it, anywhere in the
|
|
234
|
+
/// window. The last position stays when the pointer leaves the window. Not a
|
|
235
|
+
/// CSS argument. The element repaints when the pointer moves, and only
|
|
236
|
+
/// elements whose effect has a pointer parameter do.
|
|
237
|
+
[__AttributeUsage(_AttributeTargets.Var)]
|
|
238
|
+
public struct SkPointerAttribute
|
|
239
|
+
{
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/// On an `SkTexture`: the image is data (a normal map, noise, a LUT), sampled
|
|
243
|
+
/// as its file stores it — no premultiplication, alpha is just a fourth
|
|
244
|
+
/// channel. Without it the image is colour, sampled premultiplied in the same
|
|
245
|
+
/// sRGB-encoded space as `input.backdrop`.
|
|
246
|
+
[__AttributeUsage(_AttributeTargets.Var)]
|
|
247
|
+
public struct SkLinearAttribute
|
|
248
|
+
{
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/// A `float3` the host fills with times on the effect clock: when the pointer
|
|
252
|
+
/// last moved in the window, when it last entered the window and when it last
|
|
253
|
+
/// left it. It is in the window while `y > z`; `sk_pointer_presence` turns
|
|
254
|
+
/// the three into a fade. Long ago (about -1e4) until it happens. Not a CSS
|
|
255
|
+
/// argument; repaints like `[SkPointer]`, and with `[SkAnimatedFor]` keeps
|
|
256
|
+
/// repainting for a fade after each of them.
|
|
257
|
+
[__AttributeUsage(_AttributeTargets.Var)]
|
|
258
|
+
public struct SkPointerTimesAttribute
|
|
259
|
+
{
|
|
260
|
+
};
|
|
261
|
+
|
|
164
262
|
// ===========================================================================
|
|
165
263
|
// The engine's binding contract
|
|
166
264
|
// ===========================================================================
|
|
@@ -169,16 +267,23 @@ public struct SkAnimatedAttribute
|
|
|
169
267
|
// for EVERY gpui pipeline, t0 is the processed backdrop (the Dual-Kawase
|
|
170
268
|
// pyramid's top level), t2 the untouched render-target snapshot, b0 the shared
|
|
171
269
|
// globals. s1 clamps — s0 wraps, which bleeds the opposite screen edge into
|
|
172
|
-
// anything sampling near the border.
|
|
270
|
+
// anything sampling near the border. t3..t6 are an effect's `SkTexture`
|
|
271
|
+
// images and s2 the sampler that repeats them.
|
|
173
272
|
//
|
|
174
273
|
// They are declared HERE, in the module, rather than in a generated wrapper:
|
|
175
274
|
// Slang keeps explicit `register()` annotations through the HLSL and Metal
|
|
176
275
|
// backends (Metal: b0 buffer(0), t1 buffer(1), t0/t2 texture(0/2), s1
|
|
177
|
-
// sampler(1)), so the module is the right
|
|
276
|
+
// sampler(1), t3..t6 texture(3..6), s2 sampler(2)), so the module is the right
|
|
277
|
+
// home and an effect cannot move one.
|
|
178
278
|
//
|
|
179
279
|
// `[[vk::binding(binding, group)]]` is the same contract for the WGSL target,
|
|
180
280
|
// matching the pipeline layout in gpui_wgpu: group 0 the globals, group 1 the
|
|
181
|
-
// instance buffer, group 2 the backdrop textures and their sampler
|
|
281
|
+
// instance buffer, group 2 the backdrop textures and their sampler, then the
|
|
282
|
+
// images at 3..6 and their sampler at 9.
|
|
283
|
+
//
|
|
284
|
+
// t7 is the element's content (`[SkContent]`), t8 its history (`[SkHistory]`):
|
|
285
|
+
// WGSL group 2 bindings 7 and 8, Metal texture(7) and texture(8). Every effect
|
|
286
|
+
// pipeline binds them, transparent when the effect has neither.
|
|
182
287
|
|
|
183
288
|
public struct SkBounds
|
|
184
289
|
{
|
|
@@ -196,10 +301,10 @@ public struct SkCorners
|
|
|
196
301
|
|
|
197
302
|
/// Keep in sync with `gpui::EffectQuad` (vendor/zed/crates/gpui/src/scene.rs),
|
|
198
303
|
/// `struct EffectQuad` in gpui_windows/src/effects.hlsl and in
|
|
199
|
-
/// gpui_wgpu/src/shaders_effects.wgsl.
|
|
304
|
+
/// gpui_wgpu/src/shaders_effects.wgsl. 56 words / 224 bytes.
|
|
200
305
|
///
|
|
201
|
-
/// The parameter
|
|
202
|
-
/// aligns a `vec4` to 16 bytes, which would move
|
|
306
|
+
/// The parameter block is `float[]`, not `float4`s: a WGSL storage buffer
|
|
307
|
+
/// aligns a `vec4` to 16 bytes, which would move it from offset 72 to 80.
|
|
203
308
|
public struct SkEffectQuad
|
|
204
309
|
{
|
|
205
310
|
public uint order;
|
|
@@ -209,8 +314,7 @@ public struct SkEffectQuad
|
|
|
209
314
|
/// The content mask's rounded corners; see `sk_content_mask_coverage`.
|
|
210
315
|
public SkCorners content_mask_radii;
|
|
211
316
|
public SkCorners corner_radii;
|
|
212
|
-
public float
|
|
213
|
-
public float params1[4];
|
|
317
|
+
public float params[32];
|
|
214
318
|
public float opacity;
|
|
215
319
|
public float time;
|
|
216
320
|
public float bleed;
|
|
@@ -227,6 +331,23 @@ public Texture2D<float4> sk_backdrop_input : register(t0);
|
|
|
227
331
|
public Texture2D<float4> sk_backdrop_original : register(t2);
|
|
228
332
|
[[vk::binding(1, 2)]]
|
|
229
333
|
public SamplerState sk_clamp_sampler : register(s1);
|
|
334
|
+
[[vk::binding(7, 2)]]
|
|
335
|
+
public Texture2D<float4> sk_content : register(t7);
|
|
336
|
+
[[vk::binding(8, 2)]]
|
|
337
|
+
public Texture2D<float4> sk_history : register(t8);
|
|
338
|
+
|
|
339
|
+
// The images of `SkTexture` parameters, in declaration order, and the sampler
|
|
340
|
+
// that repeats them.
|
|
341
|
+
[[vk::binding(3, 2)]]
|
|
342
|
+
Texture2D<float4> sk_texture0 : register(t3);
|
|
343
|
+
[[vk::binding(4, 2)]]
|
|
344
|
+
Texture2D<float4> sk_texture1 : register(t4);
|
|
345
|
+
[[vk::binding(5, 2)]]
|
|
346
|
+
Texture2D<float4> sk_texture2 : register(t5);
|
|
347
|
+
[[vk::binding(6, 2)]]
|
|
348
|
+
Texture2D<float4> sk_texture3 : register(t6);
|
|
349
|
+
[[vk::binding(9, 2)]]
|
|
350
|
+
SamplerState sk_repeat_sampler : register(s2);
|
|
230
351
|
|
|
231
352
|
/// Scalar padding rather than a `uint3`: WGSL aligns a `vec3` to 16 bytes and
|
|
232
353
|
/// would grow the block from 48 to 64.
|
|
@@ -243,8 +364,11 @@ public cbuffer GlobalParams : register(b0)
|
|
|
243
364
|
public uint sk_global_pad2;
|
|
244
365
|
};
|
|
245
366
|
|
|
246
|
-
///
|
|
367
|
+
/// Bits of `SkEffectQuad::flags`, `gpui::EFFECT_FLAG_*`.
|
|
247
368
|
public static const uint SK_FLAG_NEEDS_BACKDROP = 1u;
|
|
369
|
+
public static const uint SK_FLAG_NEEDS_CONTENT = 2u;
|
|
370
|
+
public static const uint SK_FLAG_HISTORY = 4u;
|
|
371
|
+
public static const uint SK_FLAG_HISTORY_PASS = 8u;
|
|
248
372
|
|
|
249
373
|
|
|
250
374
|
// ===========================================================================
|
|
@@ -264,9 +388,8 @@ public struct EffectInput
|
|
|
264
388
|
public float2 px;
|
|
265
389
|
/// Element box size in device pixels.
|
|
266
390
|
public float2 size;
|
|
267
|
-
/// The backdrop behind this
|
|
268
|
-
///
|
|
269
|
-
/// snapshot. All zero for effects that did not ask for it.
|
|
391
|
+
/// The backdrop behind this pixel, premultiplied: `backdropAt(uv)`. All
|
|
392
|
+
/// zero for effects that did not ask for it.
|
|
270
393
|
public float4 backdrop;
|
|
271
394
|
/// Signed distance to the ELEMENT's rounded rect in device pixels:
|
|
272
395
|
/// negative inside, 0 on the edge, positive outside.
|
|
@@ -274,7 +397,8 @@ public struct EffectInput
|
|
|
274
397
|
/// Antialiased coverage of the element's rounded rect. 1 well inside,
|
|
275
398
|
/// 0 well outside.
|
|
276
399
|
public float coverage;
|
|
277
|
-
/// Seconds
|
|
400
|
+
/// Seconds on the effect clock, which shares its zero with JS:
|
|
401
|
+
/// `input.time == performance.now() / 1000` (rAF timestamps too).
|
|
278
402
|
public float time;
|
|
279
403
|
/// Device pixels per logical pixel (the DPI scale factor).
|
|
280
404
|
public float scale;
|
|
@@ -292,12 +416,124 @@ public struct EffectInput
|
|
|
292
416
|
public float clip;
|
|
293
417
|
/// Whether this effect asked for the backdrop.
|
|
294
418
|
public bool hasBackdrop;
|
|
295
|
-
///
|
|
296
|
-
///
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
419
|
+
/// The element's own painting at this pixel, premultiplied:
|
|
420
|
+
/// `contentAt(uv)`. All zero without `[SkContent]`.
|
|
421
|
+
public float4 content;
|
|
422
|
+
/// Whether this effect reads its content (`[SkContent]`).
|
|
423
|
+
public bool hasContent;
|
|
424
|
+
/// This effect's state at this pixel as the last step stored it:
|
|
425
|
+
/// `historyAtPx(px)`. All zero without `[SkHistory]`, on the first frame,
|
|
426
|
+
/// and where the engine keeps no history (see `[SkHistory]`).
|
|
427
|
+
public float4 history;
|
|
428
|
+
/// Whether this quad has a history to read.
|
|
429
|
+
public bool hasHistory;
|
|
430
|
+
/// Whether this run computes the next history state (`update`) rather
|
|
431
|
+
/// than the element's pixels.
|
|
432
|
+
public bool historyPass;
|
|
433
|
+
/// This quad's index in the instance buffer.
|
|
434
|
+
public uint quad;
|
|
435
|
+
|
|
436
|
+
/// Parameter slot `slot` (0..31) — the raw packing behind the named
|
|
437
|
+
/// fields on your effect struct. Bypasses the schema; prefer the fields.
|
|
438
|
+
public float param(uint slot)
|
|
439
|
+
{
|
|
440
|
+
return sk_effect_quads[this.quad].params[slot];
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// The backdrop. Both textures cover the whole window as it was painted
|
|
444
|
+
// before this effect, so any point may be sampled, not only the element's
|
|
445
|
+
// own area; outside the window they clamp to its edge. Neither holds the
|
|
446
|
+
// element's own background (a backdrop effect paints beneath it) nor
|
|
447
|
+
// another backdrop effect drawn in the same group (they never overlap).
|
|
448
|
+
// The blurred one is a lower-resolution pyramid level: blurred to
|
|
449
|
+
// `[SkBackdropRadius]`, or the raw snapshot when the effect has none.
|
|
450
|
+
// All four return zero for an effect without `[SkBackdrop]`.
|
|
451
|
+
|
|
452
|
+
/// The backdrop at a window UV (`input.uv` space), blurred to
|
|
453
|
+
/// `[SkBackdropRadius]` when the effect declares one.
|
|
454
|
+
public float4 backdropAt(float2 uv)
|
|
455
|
+
{
|
|
456
|
+
return this.hasBackdrop
|
|
457
|
+
? sk_backdrop_input.SampleLevel(sk_clamp_sampler, uv, 0.0)
|
|
458
|
+
: float4(0.0, 0.0, 0.0, 0.0);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/// The backdrop at a point in this element's device pixels (`input.px`
|
|
462
|
+
/// space), blurred like `backdropAt`.
|
|
463
|
+
public float4 backdropAtPx(float2 px)
|
|
464
|
+
{
|
|
465
|
+
return this.backdropAt(this.pxToUv(px));
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/// The untouched backdrop at a window UV, never blurred.
|
|
469
|
+
public float4 rawBackdropAt(float2 uv)
|
|
470
|
+
{
|
|
471
|
+
return this.hasBackdrop
|
|
472
|
+
? sk_backdrop_original.SampleLevel(sk_clamp_sampler, uv, 0.0)
|
|
473
|
+
: float4(0.0, 0.0, 0.0, 0.0);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/// The untouched backdrop at a point in this element's device pixels.
|
|
477
|
+
public float4 rawBackdropAtPx(float2 px)
|
|
478
|
+
{
|
|
479
|
+
return this.rawBackdropAt(this.pxToUv(px));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/// A point in this element's device pixels as a window UV.
|
|
483
|
+
public float2 pxToUv(float2 px)
|
|
484
|
+
{
|
|
485
|
+
return this.uv + (px - this.px) / sk_viewport_size;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// The content. It covers the whole window, like the backdrop: the
|
|
489
|
+
// element's painting where it is, transparent elsewhere; outside the
|
|
490
|
+
// window it clamps to the edge. Zero without `[SkContent]`.
|
|
491
|
+
|
|
492
|
+
/// The element's painting at a window UV (`input.uv` space).
|
|
493
|
+
public float4 contentAt(float2 uv)
|
|
494
|
+
{
|
|
495
|
+
return this.hasContent
|
|
496
|
+
? sk_content.SampleLevel(sk_clamp_sampler, uv, 0.0)
|
|
497
|
+
: float4(0.0, 0.0, 0.0, 0.0);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/// The element's painting at a point in its device pixels (`input.px`).
|
|
501
|
+
public float4 contentAtPx(float2 px)
|
|
502
|
+
{
|
|
503
|
+
return this.contentAt(this.pxToUv(px));
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/// The size of the content texture in texels: the window's, in device
|
|
507
|
+
/// pixels. One texel is one `px` unit.
|
|
508
|
+
public float2 contentSize()
|
|
509
|
+
{
|
|
510
|
+
return sk_viewport_size;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// The history: the drawn quad (the border box dilated by `bleed`) in
|
|
514
|
+
// device pixels, one texel each, clamped at its edge. Zero without
|
|
515
|
+
// `[SkHistory]`.
|
|
516
|
+
|
|
517
|
+
/// The state at a point in this element's device pixels (`input.px`).
|
|
518
|
+
public float4 historyAtPx(float2 px)
|
|
519
|
+
{
|
|
520
|
+
float2 size = this.historySize();
|
|
521
|
+
return this.hasHistory
|
|
522
|
+
? sk_history.SampleLevel(sk_clamp_sampler, (px + this.bleed) / size, 0.0)
|
|
523
|
+
: float4(0.0, 0.0, 0.0, 0.0);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/// The state at a window UV (`input.uv` space).
|
|
527
|
+
public float4 historyAt(float2 uv)
|
|
528
|
+
{
|
|
529
|
+
return this.historyAtPx(this.px + (uv - this.uv) * sk_viewport_size);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/// The size of the history in texels: the drawn quad's, in device pixels.
|
|
533
|
+
public float2 historySize()
|
|
534
|
+
{
|
|
535
|
+
return max(round(sk_effect_quads[this.quad].bounds.size), float2(1.0, 1.0));
|
|
536
|
+
}
|
|
301
537
|
|
|
302
538
|
/// Antialiased 0..1 coverage from a signed distance in device pixels.
|
|
303
539
|
/// One device pixel of feather, which is what the rest of gpui uses.
|
|
@@ -317,6 +553,68 @@ public struct EffectInput
|
|
|
317
553
|
}
|
|
318
554
|
};
|
|
319
555
|
|
|
556
|
+
/// An image parameter, written `url(...)` in CSS and resolved like an
|
|
557
|
+
/// `<img src>`. At most four per effect. Sampled bilinearly at mip 0, so it is
|
|
558
|
+
/// safe in loops and branches. Until the image has loaded, or when it fails or
|
|
559
|
+
/// is omitted, every read returns the field's `[SkDefault]` colour
|
|
560
|
+
/// (transparent without one) and `size` is zero.
|
|
561
|
+
public struct SkTexture
|
|
562
|
+
{
|
|
563
|
+
/// The image's size in texels; (0, 0) while it is missing.
|
|
564
|
+
public float2 size;
|
|
565
|
+
uint slot;
|
|
566
|
+
float4 fallback;
|
|
567
|
+
|
|
568
|
+
public bool loaded()
|
|
569
|
+
{
|
|
570
|
+
return this.size.x > 0.0;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/// The image at a 0..1 UV, clamped to its edge texels outside it.
|
|
574
|
+
public float4 sample(float2 uv)
|
|
575
|
+
{
|
|
576
|
+
return this.loaded() ? sk_texture_at(this.slot, sk_clamp_sampler, uv) : this.fallback;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/// The image at a UV, repeating outside 0..1.
|
|
580
|
+
public float4 sampleRepeat(float2 uv)
|
|
581
|
+
{
|
|
582
|
+
return this.loaded() ? sk_texture_at(this.slot, sk_repeat_sampler, uv) : this.fallback;
|
|
583
|
+
}
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
/// Built by the generated wrapper; an effect receives its `SkTexture` fields filled in.
|
|
587
|
+
public SkTexture sk_texture(uint slot, float2 size, float4 fallback)
|
|
588
|
+
{
|
|
589
|
+
SkTexture t;
|
|
590
|
+
t.size = size;
|
|
591
|
+
t.slot = slot;
|
|
592
|
+
t.fallback = fallback;
|
|
593
|
+
return t;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
float4 sk_texture_at(uint slot, SamplerState s, float2 uv)
|
|
597
|
+
{
|
|
598
|
+
float4 texel = float4(0.0, 0.0, 0.0, 0.0);
|
|
599
|
+
if (slot == 0u)
|
|
600
|
+
{
|
|
601
|
+
texel = sk_texture0.SampleLevel(s, uv, 0.0);
|
|
602
|
+
}
|
|
603
|
+
else if (slot == 1u)
|
|
604
|
+
{
|
|
605
|
+
texel = sk_texture1.SampleLevel(s, uv, 0.0);
|
|
606
|
+
}
|
|
607
|
+
else if (slot == 2u)
|
|
608
|
+
{
|
|
609
|
+
texel = sk_texture2.SampleLevel(s, uv, 0.0);
|
|
610
|
+
}
|
|
611
|
+
else if (slot == 3u)
|
|
612
|
+
{
|
|
613
|
+
texel = sk_texture3.SampleLevel(s, uv, 0.0);
|
|
614
|
+
}
|
|
615
|
+
return texel;
|
|
616
|
+
}
|
|
617
|
+
|
|
320
618
|
/// The one interface an effect implements.
|
|
321
619
|
public interface IEffect
|
|
322
620
|
{
|
|
@@ -333,6 +631,11 @@ public interface IEffect
|
|
|
333
631
|
/// nothing at runtime and removes the single most common way to get an
|
|
334
632
|
/// effect wrong.
|
|
335
633
|
static bool straightAlpha() { return false; }
|
|
634
|
+
|
|
635
|
+
/// With `[SkHistory]`: the state to store for this texel, read back next
|
|
636
|
+
/// step through `input.history`. Raw: not premultiplied, clamped or
|
|
637
|
+
/// covered, kept at 16-bit float precision. Defaults to `shade`.
|
|
638
|
+
float4 update(EffectInput input) { return this.shade(input); }
|
|
336
639
|
};
|
|
337
640
|
|
|
338
641
|
// ===========================================================================
|
|
@@ -405,7 +708,10 @@ public float4 sk_clamp_premultiplied(float4 color)
|
|
|
405
708
|
public EffectInput sk_begin(uint id, float4 frag_position)
|
|
406
709
|
{
|
|
407
710
|
SkEffectQuad q = sk_effect_quads[id];
|
|
408
|
-
|
|
711
|
+
bool history_pass = (q.flags & SK_FLAG_HISTORY_PASS) != 0u;
|
|
712
|
+
// A history pass draws into the history texture, whose texel (0,0) is
|
|
713
|
+
// the drawn quad's top-left device pixel.
|
|
714
|
+
float2 position = history_pass ? q.bounds.origin + frag_position.xy : frag_position.xy;
|
|
409
715
|
// SV_Position is the pixel centre, so this lands on a texel centre of the
|
|
410
716
|
// full-resolution snapshot.
|
|
411
717
|
float2 uv = position / sk_viewport_size;
|
|
@@ -428,19 +734,21 @@ public EffectInput sk_begin(uint id, float4 frag_position)
|
|
|
428
734
|
i.px = position - element_origin;
|
|
429
735
|
i.size = element_size;
|
|
430
736
|
i.local = i.px / element_size;
|
|
431
|
-
i.
|
|
432
|
-
|
|
433
|
-
|
|
737
|
+
i.hasBackdrop = has_backdrop;
|
|
738
|
+
i.hasContent = (q.flags & SK_FLAG_NEEDS_CONTENT) != 0u;
|
|
739
|
+
i.hasHistory = (q.flags & SK_FLAG_HISTORY) != 0u;
|
|
740
|
+
i.historyPass = history_pass;
|
|
741
|
+
i.quad = id;
|
|
742
|
+
i.bleed = q.bleed;
|
|
743
|
+
i.backdrop = i.backdropAt(uv);
|
|
744
|
+
i.content = i.contentAt(uv);
|
|
745
|
+
i.history = i.historyAtPx(i.px);
|
|
434
746
|
i.sd = sd_element;
|
|
435
747
|
i.coverage = saturate(0.5 - sd_element);
|
|
436
748
|
i.time = q.time;
|
|
437
749
|
i.scale = q.scale;
|
|
438
|
-
i.bleed = q.bleed;
|
|
439
750
|
i.opacity = q.opacity;
|
|
440
751
|
i.clip = sk_content_mask_coverage(position, q.content_mask, q.content_mask_radii);
|
|
441
|
-
i.hasBackdrop = has_backdrop;
|
|
442
|
-
i.params0 = float4(q.params0[0], q.params0[1], q.params0[2], q.params0[3]);
|
|
443
|
-
i.params1 = float4(q.params1[0], q.params1[1], q.params1[2], q.params1[3]);
|
|
444
752
|
return i;
|
|
445
753
|
}
|
|
446
754
|
|
|
@@ -455,6 +763,10 @@ public EffectInput sk_begin(uint id, float4 frag_position)
|
|
|
455
763
|
/// OneMinusSrcAlpha); blending it by source alpha would apply alpha twice.
|
|
456
764
|
public float4 sk_finish<T : IEffect>(T material, EffectInput i)
|
|
457
765
|
{
|
|
766
|
+
if (i.historyPass)
|
|
767
|
+
{
|
|
768
|
+
return material.update(i);
|
|
769
|
+
}
|
|
458
770
|
float4 shaded = material.shade(i);
|
|
459
771
|
if (T.straightAlpha())
|
|
460
772
|
{
|
|
@@ -485,6 +797,18 @@ public float4 sk_finish<T : IEffect>(T material, EffectInput i)
|
|
|
485
797
|
// Helpers
|
|
486
798
|
// ===========================================================================
|
|
487
799
|
|
|
800
|
+
/// 0..1: how present the pointer is in the window, from `[SkPointerTimes]`
|
|
801
|
+
/// and `input.time`, fading in over `seconds` after it enters and out over
|
|
802
|
+
/// `seconds` after it leaves. Pair the field with `[SkAnimatedFor(seconds)]`.
|
|
803
|
+
public float sk_pointer_presence(float3 times, float time, float seconds)
|
|
804
|
+
{
|
|
805
|
+
float fade = max(seconds, 1e-4);
|
|
806
|
+
float entered = saturate((time - times.y) / fade);
|
|
807
|
+
float atLeave = saturate((times.z - times.y) / fade);
|
|
808
|
+
float leaving = atLeave * (1.0 - saturate((time - times.z) / fade));
|
|
809
|
+
return times.y > times.z ? entered : leaving;
|
|
810
|
+
}
|
|
811
|
+
|
|
488
812
|
/// Straight alpha -> premultiplied.
|
|
489
813
|
public float4 sk_premultiply(float4 color)
|
|
490
814
|
{
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "git+https://github.com/argon-chat/skathi.git",
|
|
7
7
|
"directory": "packages/cli"
|
|
8
8
|
},
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.2.0",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"files": [
|
|
12
12
|
"aot",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"css-prefixes.ts",
|
|
24
24
|
"prod.ts",
|
|
25
25
|
"runtime-path.ts",
|
|
26
|
+
"svelte.ts",
|
|
26
27
|
"tailwind.ts",
|
|
27
28
|
"vitecompat.ts"
|
|
28
29
|
],
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@clack/prompts": "^1.9.0",
|
|
35
36
|
"@commander-js/extra-typings": "~15.1.0",
|
|
36
|
-
"@skathi-native/runtime": "0.
|
|
37
|
+
"@skathi-native/runtime": "0.2.0",
|
|
37
38
|
"@vue/compiler-sfc": "^3.5.41",
|
|
38
39
|
"commander": "~15.1.0",
|
|
39
40
|
"postcss": "^8.4.31",
|
|
@@ -41,7 +42,8 @@
|
|
|
41
42
|
"typescript": "5"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@modelcontextprotocol/sdk": "^1.30.0"
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
46
|
+
"svelte": "5.57.3"
|
|
45
47
|
},
|
|
46
48
|
"engines": {
|
|
47
49
|
"bun": ">=1.4"
|
|
@@ -57,7 +59,8 @@
|
|
|
57
59
|
"comments": {
|
|
58
60
|
"tailwindcss": "Pinned to 3.4.x: v3 emits literal declarations that crates/sk-css maps onto gpui; v4 uses var(--tw-*) + calc() + @property, which the engine does not fully resolve yet (see tailwind.ts).",
|
|
59
61
|
"@modelcontextprotocol/sdk": "devDependency: used only by devtools/mcp.ts. devtools/ctl.ts is dependency-free so an agent can drive the app through Bash without bun install.",
|
|
60
|
-
"typescript": "sk check and the AOT input inventory (sk build --aot-inputs). Builds do not invoke tsc: bun transpiles .ts directly."
|
|
62
|
+
"typescript": "sk check and the AOT input inventory (sk build --aot-inputs). Builds do not invoke tsc: bun transpiles .ts directly.",
|
|
63
|
+
"svelte": "devDependency: types and tests. A Svelte app compiles with its own svelte/compiler, the version its runtime is."
|
|
61
64
|
},
|
|
62
65
|
"publishConfig": {
|
|
63
66
|
"access": "public"
|
package/prod.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { asciiOnly, checkAscii, nonAsciiCount } from "./ascii";
|
|
|
21
21
|
import { AotInputs, aotEngineIdentity } from "./aot-inputs";
|
|
22
22
|
import type { ModuleGraph } from "./check/graph";
|
|
23
23
|
import { pruneVendorPrefixes } from "./css-prefixes";
|
|
24
|
+
import { SVELTE_SOURCE, compileSvelte } from "./svelte";
|
|
24
25
|
import {
|
|
25
26
|
RUNTIME_DIR,
|
|
26
27
|
RUNTIME_ENTRY,
|
|
@@ -166,6 +167,9 @@ for (const [k, v] of Object.entries(APP_DEFINES.defines)) {
|
|
|
166
167
|
} catch {}
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
// As Vite's production build: a package's `production` export (esm-env's DEV is `false`, not a NODE_ENV probe).
|
|
171
|
+
const PROD_CONDITIONS = ["production"];
|
|
172
|
+
|
|
169
173
|
const DEFINES: Record<string, string> = {
|
|
170
174
|
__DEV__: "false",
|
|
171
175
|
"process.env.NODE_ENV": '"production"',
|
|
@@ -416,7 +420,7 @@ const AOT_INPUTS = aotInputsDir
|
|
|
416
420
|
})
|
|
417
421
|
: null;
|
|
418
422
|
|
|
419
|
-
/** `--graph`: every .js/.ts/.vue file the build loaded, by absolute path. */
|
|
423
|
+
/** `--graph`: every .js/.ts/.vue/.svelte file the build loaded, by absolute path. */
|
|
420
424
|
const GRAPH_LOADED = new Set<string>();
|
|
421
425
|
const SHAPE_NOTES = new Map<string, number>();
|
|
422
426
|
const SHAPES = {
|
|
@@ -465,6 +469,16 @@ const vuePlugin = {
|
|
|
465
469
|
if (graphOut) GRAPH_LOADED.add(args.path);
|
|
466
470
|
return compileVue(args.path, source);
|
|
467
471
|
});
|
|
472
|
+
build.onLoad({ filter: SVELTE_SOURCE }, async (args: Bun.OnLoadArgs) => {
|
|
473
|
+
const id = toId(args.path);
|
|
474
|
+
if (graphOut) GRAPH_LOADED.add(args.path);
|
|
475
|
+
const source = await Bun.file(args.path).text();
|
|
476
|
+
const out = await compileSvelte(APP_ROOT, args.path, source, { dev: false, filename: id });
|
|
477
|
+
AOT_INPUTS?.svelte(args.path, source, out.js);
|
|
478
|
+
for (const w of out.warnings) advise(w);
|
|
479
|
+
if (out.css) cssById.set(id, await viteCss(out.css, args.path, `${id} <style>`));
|
|
480
|
+
return { contents: transformSource(out.js, args.path, SHAPES) ?? out.js, loader: "js" as const };
|
|
481
|
+
});
|
|
468
482
|
},
|
|
469
483
|
};
|
|
470
484
|
|
|
@@ -522,28 +536,45 @@ async function writeGraph(out: string) {
|
|
|
522
536
|
target: "browser",
|
|
523
537
|
define: DEFINES,
|
|
524
538
|
plugins: [viteShapesPlugin(SHAPES), vuePlugin, entryPlugin],
|
|
539
|
+
conditions: PROD_CONDITIONS,
|
|
525
540
|
minify: minify ? { whitespace: true, identifiers: true, syntax: true } : false,
|
|
526
|
-
sourcemap: "
|
|
541
|
+
sourcemap: "external",
|
|
527
542
|
metafile: true,
|
|
528
543
|
throw: false,
|
|
529
544
|
});
|
|
530
|
-
// Metafile keys are relative, to a base that varies between runs
|
|
531
|
-
// match them against the absolute paths the plugins loaded.
|
|
545
|
+
// Metafile keys and sourcemap sources are relative, to a base that varies between runs
|
|
546
|
+
// ("node_modules/…", "../../C:/…"): match them against the absolute paths the plugins loaded.
|
|
532
547
|
const byName = new Map<string, { key: string; path: string }[]>();
|
|
533
548
|
for (const path of GRAPH_LOADED) {
|
|
534
549
|
const key = resolve(path).split(sep).join("/").toLowerCase();
|
|
535
550
|
const name = key.slice(key.lastIndexOf("/") + 1);
|
|
536
551
|
byName.set(name, [...(byName.get(name) ?? []), { key, path: resolve(path) }]);
|
|
537
552
|
}
|
|
553
|
+
const loadedPaths = (key: string) => {
|
|
554
|
+
const tail = `/${key.replace(/^(?:\.\.\/)+/, "").replace(/^[A-Za-z]:\//, "")}`.toLowerCase();
|
|
555
|
+
return (byName.get(tail.slice(tail.lastIndexOf("/") + 1)) ?? []).filter((l) => l.key.endsWith(tail));
|
|
556
|
+
};
|
|
538
557
|
const modules = new Set<string>();
|
|
539
558
|
for (const output of Object.values(result.metafile?.outputs ?? {})) {
|
|
540
559
|
for (const [key, input] of Object.entries(output.inputs)) {
|
|
541
560
|
if (input.bytesInOutput <= 0) continue;
|
|
542
|
-
const
|
|
543
|
-
for (const loaded of byName.get(tail.slice(tail.lastIndexOf("/") + 1)) ?? [])
|
|
544
|
-
if (loaded.key.endsWith(tail)) modules.add(loaded.path);
|
|
561
|
+
for (const loaded of loadedPaths(key)) modules.add(loaded.path);
|
|
545
562
|
}
|
|
546
563
|
}
|
|
564
|
+
let bundle: ModuleGraph["bundle"];
|
|
565
|
+
const code = result.outputs.find((o) => o.kind === "entry-point");
|
|
566
|
+
const map = result.outputs.find((o) => o.kind === "sourcemap");
|
|
567
|
+
if (result.success && code && map) {
|
|
568
|
+
const raw = JSON.parse(await map.text()) as { sources: string[]; sourcesContent?: string[]; mappings: string };
|
|
569
|
+
const sources = raw.sources.map((key, i) => {
|
|
570
|
+
const [loaded, ...others] = loadedPaths(key);
|
|
571
|
+
if (!loaded || others.length) return null;
|
|
572
|
+
// Positions are the file's own only when the bundler read it as is (not a compiled .vue or .svelte).
|
|
573
|
+
const text = readFileSync(loaded.path, "utf8").replace(/^\uFEFF/, "");
|
|
574
|
+
return raw.sourcesContent?.[i] === text ? loaded.path : null;
|
|
575
|
+
});
|
|
576
|
+
bundle = { code: await code.text(), sources, mappings: raw.mappings };
|
|
577
|
+
}
|
|
547
578
|
const graph: ModuleGraph = {
|
|
548
579
|
schema: "skathi.module-graph",
|
|
549
580
|
version: 1,
|
|
@@ -557,6 +588,7 @@ async function writeGraph(out: string) {
|
|
|
557
588
|
},
|
|
558
589
|
declarations: [...new Bun.Glob("*.d.ts").scanSync({ cwd: RUNTIME_SRC_DIR, absolute: true })],
|
|
559
590
|
modules: [...modules].sort(),
|
|
591
|
+
...(bundle ? { bundle } : {}),
|
|
560
592
|
errors: result.logs
|
|
561
593
|
.filter((log) => log.level === "error")
|
|
562
594
|
.map((log) => ({
|
|
@@ -584,6 +616,7 @@ async function build() {
|
|
|
584
616
|
target: "browser",
|
|
585
617
|
define: DEFINES,
|
|
586
618
|
plugins: [viteShapesPlugin(SHAPES), vuePlugin, entryPlugin],
|
|
619
|
+
conditions: PROD_CONDITIONS,
|
|
587
620
|
minify: minify ? { whitespace: true, identifiers: true, syntax: true } : false,
|
|
588
621
|
sourcemap: "none",
|
|
589
622
|
});
|