@skathi-native/cli 0.1.0-beta.2 → 0.1.0-beta.4

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.
Files changed (50) hide show
  1. package/aot/host-globals.json +105 -0
  2. package/aot/native.ts +142 -0
  3. package/aot/pin.ts +67 -0
  4. package/aot/toolchain.lock.json +17 -0
  5. package/aot/transform.ts +69 -0
  6. package/check/codes.ts +19 -0
  7. package/check/command.ts +5 -3
  8. package/check/index.ts +44 -1
  9. package/cli/aot-build.ts +192 -0
  10. package/cli/build-app.ts +102 -31
  11. package/cli/config.ts +45 -102
  12. package/cli/create.ts +12 -54
  13. package/cli/dev.ts +109 -19
  14. package/cli/effects.ts +162 -0
  15. package/cli/elf.ts +3 -2
  16. package/cli/help.ts +56 -148
  17. package/cli/host-fetch.ts +116 -54
  18. package/cli/host.ts +59 -39
  19. package/cli/sk.ts +440 -246
  20. package/cli/skpk.ts +6 -0
  21. package/cli/stamp.ts +2 -2
  22. package/cli/term.ts +169 -38
  23. package/cli/workload-cache.ts +258 -0
  24. package/effects/compile.ts +952 -0
  25. package/effects/redslangc.json +23 -0
  26. package/effects/redslangc.ts +220 -0
  27. package/effects/sk.slang +558 -0
  28. package/package.json +6 -2
  29. package/templates/icon.png +0 -0
  30. package/templates/minimal/.vscode/settings.json +3 -0
  31. package/templates/minimal/src/App.vue +2 -2
  32. package/templates/showcase/.vscode/settings.json +3 -0
  33. package/templates/showcase/shaders/sheen.slang +23 -0
  34. package/templates/showcase/src/components/Titlebar.vue +7 -3
  35. package/templates/showcase/src/engine.ts +3 -26
  36. package/templates/showcase/src/pages/AudioPage.vue +6 -9
  37. package/templates/showcase/src/pages/FilesPage.vue +11 -15
  38. package/templates/showcase/src/pages/FormsPage.vue +2 -3
  39. package/templates/showcase/src/pages/GraphicsPage.vue +13 -15
  40. package/templates/showcase/src/pages/HomePage.vue +1 -2
  41. package/templates/showcase/src/pages/LocalePage.vue +2 -2
  42. package/templates/showcase/src/pages/MediaPage.vue +1 -1
  43. package/templates/showcase/src/pages/MotionPage.vue +1 -1
  44. package/templates/showcase/src/pages/NetworkPage.vue +6 -5
  45. package/templates/showcase/src/pages/PermissionsPage.vue +2 -2
  46. package/templates/showcase/src/pages/StoragePage.vue +23 -36
  47. package/templates/showcase/src/pages/StylesPage.vue +9 -1
  48. package/templates/showcase/src/pages/SystemPage.vue +3 -3
  49. package/templates/showcase/src/styles.css +2 -2
  50. package/templates/showcase/src/components/Missing.vue +0 -26
@@ -0,0 +1,558 @@
1
+ // sk — the engine prelude every effect imports.
2
+ //
3
+ // import sk;
4
+ //
5
+ // [SkEffect("ripple")]
6
+ // struct Ripple : IEffect
7
+ // {
8
+ // [SkDefault("1.5")] [SkRange(0.0, 8.0)] float speed;
9
+ // [SkLength] [SkDefault("24")] float wavelength;
10
+ // [SkColor] [SkDefault("#7fd4ff")] float4 tint;
11
+ //
12
+ // float4 shade(EffectInput input) { ... }
13
+ // };
14
+ //
15
+ // That is the WHOLE authoring surface. No entry point, no semantics, no
16
+ // register bindings, no vertex stage — all of that lives below, and the
17
+ // compiler appends a short wrapper that calls `sk_begin` / `sk_finish`
18
+ // around your `shade`. One effect per file, in the app's `shaders/`:
19
+ // `sk build`, `sk run` and `sk publish` compile them into the app for every
20
+ // OS, `sk dev` recompiles on save, and `sk check` reports what fails.
21
+ // The attributes are not decoration. The compiler reflects them and turns
22
+ // that reflection into the CSS schema: `[SkEffect("ripple")]` is the
23
+ // function name, the FIELD ORDER is the argument order and the
24
+ // parameter-slot order, and the per-field attributes give the CSS type, the
25
+ // default and the clamp range. Nothing is registered twice; there is no Rust
26
+ // or JS list of your effect's parameters to keep in sync.
27
+ //
28
+ // Rules the engine cannot enforce for you:
29
+ // * Never call `Sample` inside a loop or a non-uniform branch — implicit
30
+ // derivatives are undefined there. Use `SampleLevel(..., 0)`.
31
+ // * `shade()` returns a PREMULTIPLIED colour by default. Either premultiply
32
+ // yourself (`sk_premultiply`) or opt out with
33
+ // `static override bool straightAlpha() { return true; }`. Either way
34
+ // the engine draws a premultiplied result (see `sk_finish`).
35
+ // * Effects compile at `ps_5_0`; the rest of gpui stays at `ps_4_1`.
36
+ // * An effect declares no textures, samplers or buffers: it reads
37
+ // `EffectInput` and its own fields, nothing else.
38
+
39
+ module sk;
40
+
41
+ // ===========================================================================
42
+ // Authoring attributes — reflected by the compiler, read into the schema
43
+ // ===========================================================================
44
+ //
45
+ // Slang user-defined attributes are declared as structs tagged
46
+ // `[__AttributeUsage]`; their arguments become the `arguments` array under
47
+ // `userAttribs` in `-reflection-json`. This is the ONLY channel by which
48
+ // information travels from a `.slang` file to the CPU side, which is why every
49
+ // piece of CSS-facing metadata is spelled as an attribute rather than as, say,
50
+ // a `static const` (not reflected) or a field initialiser (also not reflected).
51
+
52
+ /// The CSS function name: `[SkEffect("ripple")]` -> `--shading: ripple(...)`.
53
+ /// Required, exactly once, on the effect struct.
54
+ [__AttributeUsage(_AttributeTargets.Struct)]
55
+ public struct SkEffectAttribute
56
+ {
57
+ public string name;
58
+ };
59
+
60
+ /// This effect reads `input.backdrop`, so the renderer must snapshot the
61
+ /// render target and draw the quad with blending disabled. Costs a full
62
+ /// render-target copy per effect group — do not add it unless `shade` really
63
+ /// samples the backdrop. Implied by `[SkBackdropRadius]`.
64
+ [__AttributeUsage(_AttributeTargets.Struct)]
65
+ public struct SkBackdropAttribute
66
+ {
67
+ };
68
+
69
+ /// One line of author-facing documentation, echoed in CSS advisories.
70
+ [__AttributeUsage(_AttributeTargets.Struct)]
71
+ public struct SkDocAttribute
72
+ {
73
+ public string text;
74
+ };
75
+
76
+ /// The parameter's default, written the way it would be written in CSS:
77
+ /// `"1.5"`, `"0 0.5"`, `"#7fd4ff"`, `"#ffffff28"`.
78
+ ///
79
+ /// A STRING rather than floats on purpose: Slang attribute structs have a
80
+ /// fixed field list, so a numeric spelling would need one attribute per arity
81
+ /// (`SkDefault`, `SkDefault2`, `SkDefault3`, `SkDefault4`). One string covers
82
+ /// every arity AND lets a colour default be written as a hex literal.
83
+ [__AttributeUsage(_AttributeTargets.Var)]
84
+ public struct SkDefaultAttribute
85
+ {
86
+ public string value;
87
+ };
88
+
89
+ /// Inclusive clamp for a scalar parameter. Out-of-range CSS values are
90
+ /// clamped WITH an advisory, never dropped.
91
+ [__AttributeUsage(_AttributeTargets.Var)]
92
+ public struct SkRangeAttribute
93
+ {
94
+ public float lo;
95
+ public float hi;
96
+ };
97
+
98
+ /// The CSS argument is a `<length>` (`24px`), not a `<number>`. Lengths are
99
+ /// authored in LOGICAL pixels and multiplied by the device scale factor before
100
+ /// they reach the shader, so `input.px` and a length parameter are in the same
101
+ /// units on every monitor.
102
+ [__AttributeUsage(_AttributeTargets.Var)]
103
+ public struct SkLengthAttribute
104
+ {
105
+ };
106
+
107
+ /// The CSS argument is a `<color>`. Only legal on a `float4`; the four
108
+ /// channels arrive as straight-alpha RGBA in 0..1.
109
+ [__AttributeUsage(_AttributeTargets.Var)]
110
+ public struct SkColorAttribute
111
+ {
112
+ };
113
+
114
+ /// The CSS argument may be omitted. Matching is positional but type-directed,
115
+ /// so an omitted optional parameter is skipped when the argument in that
116
+ /// position does not have its type — which is how `glow(12px, 0.8)` and
117
+ /// `glow(#7fd4ff, 12px, 0.8)` both parse. An optional parameter must therefore
118
+ /// differ in CSS type from the parameter that follows it; the compiler rejects
119
+ /// the effect at compile time otherwise.
120
+ [__AttributeUsage(_AttributeTargets.Var)]
121
+ public struct SkOptionalAttribute
122
+ {
123
+ };
124
+
125
+ /// Pins this parameter to an explicit slot in the 8-float parameter block,
126
+ /// instead of letting the packer choose. Unpinned fields then fill the gaps in
127
+ /// declaration order.
128
+ ///
129
+ /// Needed only when the packing is ALREADY a published contract — `glow`'s is,
130
+ /// because CSS transitions interpolate slot by slot and its layout predates
131
+ /// reflection-driven packing. A new effect should never need this: declare the
132
+ /// fields in the order you want the CSS arguments and let the packer work.
133
+ [__AttributeUsage(_AttributeTargets.Var)]
134
+ public struct SkSlotAttribute
135
+ {
136
+ public int index;
137
+ };
138
+
139
+ /// This length parameter DILATES the drawn quad by its value, giving an outer
140
+ /// glow somewhere to land. At most one per effect.
141
+ [__AttributeUsage(_AttributeTargets.Var)]
142
+ public struct SkBleedAttribute
143
+ {
144
+ };
145
+
146
+ /// This length parameter is the radius the backdrop is blurred to before
147
+ /// `input.backdrop` is sampled. Implies `[SkBackdrop]`. At most one per
148
+ /// effect.
149
+ [__AttributeUsage(_AttributeTargets.Var)]
150
+ public struct SkBackdropRadiusAttribute
151
+ {
152
+ };
153
+
154
+ /// While this parameter is > 0 the effect is treated as animated and the
155
+ /// window keeps repainting. Put it on the parameter that actually drives
156
+ /// `input.time` (a speed), so `speed: 0` costs nothing. At most one per
157
+ /// effect; an effect with no `[SkAnimated]` parameter never repaints on its
158
+ /// own.
159
+ [__AttributeUsage(_AttributeTargets.Var)]
160
+ public struct SkAnimatedAttribute
161
+ {
162
+ };
163
+
164
+ // ===========================================================================
165
+ // The engine's binding contract
166
+ // ===========================================================================
167
+ //
168
+ // These registers are gpui's, not ours to choose: t1 is the instance buffer
169
+ // for EVERY gpui pipeline, t0 is the processed backdrop (the Dual-Kawase
170
+ // pyramid's top level), t2 the untouched render-target snapshot, b0 the shared
171
+ // globals. s1 clamps — s0 wraps, which bleeds the opposite screen edge into
172
+ // anything sampling near the border.
173
+ //
174
+ // They are declared HERE, in the module, rather than in a generated wrapper:
175
+ // Slang keeps explicit `register()` annotations through the HLSL and Metal
176
+ // backends (Metal: b0 buffer(0), t1 buffer(1), t0/t2 texture(0/2), s1
177
+ // sampler(1)), so the module is the right home and an effect cannot move one.
178
+ //
179
+ // `[[vk::binding(binding, group)]]` is the same contract for the WGSL target,
180
+ // 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.
182
+
183
+ public struct SkBounds
184
+ {
185
+ public float2 origin;
186
+ public float2 size;
187
+ };
188
+
189
+ public struct SkCorners
190
+ {
191
+ public float top_left;
192
+ public float top_right;
193
+ public float bottom_right;
194
+ public float bottom_left;
195
+ };
196
+
197
+ /// Keep in sync with `gpui::EffectQuad` (vendor/zed/crates/gpui/src/scene.rs),
198
+ /// `struct EffectQuad` in gpui_windows/src/effects.hlsl and in
199
+ /// gpui_wgpu/src/shaders_effects.wgsl. 32 words / 128 bytes.
200
+ ///
201
+ /// The parameter banks are `float[4]`, not `float4`: a WGSL storage buffer
202
+ /// aligns a `vec4` to 16 bytes, which would move `params0` from offset 72 to 80.
203
+ public struct SkEffectQuad
204
+ {
205
+ public uint order;
206
+ public uint effect_id;
207
+ public SkBounds bounds;
208
+ public SkBounds content_mask;
209
+ /// The content mask's rounded corners; see `sk_content_mask_coverage`.
210
+ public SkCorners content_mask_radii;
211
+ public SkCorners corner_radii;
212
+ public float params0[4];
213
+ public float params1[4];
214
+ public float opacity;
215
+ public float time;
216
+ public float bleed;
217
+ public float backdrop_blur_radius;
218
+ public float scale;
219
+ public uint flags;
220
+ };
221
+
222
+ [[vk::binding(0, 1)]]
223
+ public StructuredBuffer<SkEffectQuad> sk_effect_quads : register(t1);
224
+ [[vk::binding(0, 2)]]
225
+ public Texture2D<float4> sk_backdrop_input : register(t0);
226
+ [[vk::binding(2, 2)]]
227
+ public Texture2D<float4> sk_backdrop_original : register(t2);
228
+ [[vk::binding(1, 2)]]
229
+ public SamplerState sk_clamp_sampler : register(s1);
230
+
231
+ /// Scalar padding rather than a `uint3`: WGSL aligns a `vec3` to 16 bytes and
232
+ /// would grow the block from 48 to 64.
233
+ [[vk::binding(0, 0)]]
234
+ public cbuffer GlobalParams : register(b0)
235
+ {
236
+ public float4 sk_gamma_ratios;
237
+ public float2 sk_viewport_size;
238
+ public float sk_grayscale_enhanced_contrast;
239
+ public float sk_subpixel_enhanced_contrast;
240
+ public uint sk_is_bgr;
241
+ public uint sk_global_pad0;
242
+ public uint sk_global_pad1;
243
+ public uint sk_global_pad2;
244
+ };
245
+
246
+ /// Bit 0 of `SkEffectQuad::flags`.
247
+ public static const uint SK_FLAG_NEEDS_BACKDROP = 1u;
248
+
249
+
250
+ // ===========================================================================
251
+ // The authoring contract
252
+ // ===========================================================================
253
+
254
+ /// Everything the engine hands an effect, in one struct.
255
+ public struct EffectInput
256
+ {
257
+ /// Screen-space UV of this pixel (0..1 across the whole window). This is
258
+ /// the coordinate `backdrop` was sampled at.
259
+ public float2 uv;
260
+ /// Position within the element box, normalised 0..1. Values outside 0..1
261
+ /// occur when the effect declares a `[SkBleed]` parameter.
262
+ public float2 local;
263
+ /// Position within the element box in DEVICE pixels (top-left origin).
264
+ public float2 px;
265
+ /// Element box size in device pixels.
266
+ public float2 size;
267
+ /// The backdrop behind this quad, premultiplied. Blurred to
268
+ /// `[SkBackdropRadius]` when the effect declares one, otherwise the raw
269
+ /// snapshot. All zero for effects that did not ask for it.
270
+ public float4 backdrop;
271
+ /// Signed distance to the ELEMENT's rounded rect in device pixels:
272
+ /// negative inside, 0 on the edge, positive outside.
273
+ public float sd;
274
+ /// Antialiased coverage of the element's rounded rect. 1 well inside,
275
+ /// 0 well outside.
276
+ public float coverage;
277
+ /// Seconds since the process started — the clock an animated effect uses.
278
+ public float time;
279
+ /// Device pixels per logical pixel (the DPI scale factor).
280
+ public float scale;
281
+ /// How far outside the element's border box the drawn quad reaches, in
282
+ /// device pixels (the resolved `[SkBleed]` parameter, 0 without one).
283
+ public float bleed;
284
+ /// The element's `opacity`, already folded into the coverage the engine
285
+ /// applies after `shade` — exposed because an effect may want to fade a
286
+ /// component of its own by the same amount.
287
+ public float opacity;
288
+ /// The coverage of the content mask, the rounded clip of an `overflow`
289
+ /// ancestor with a `border-radius`: 1 inside it, and everywhere for a
290
+ /// square one. Folded into the coverage the engine applies after `shade`,
291
+ /// like `opacity`.
292
+ public float clip;
293
+ /// Whether this effect asked for the backdrop.
294
+ public bool hasBackdrop;
295
+ /// Parameter slots 0..3 — the raw packing behind the named fields on your
296
+ /// effect struct. Reading these directly works but bypasses the schema;
297
+ /// prefer the named fields.
298
+ public float4 params0;
299
+ /// Parameter slots 4..7.
300
+ public float4 params1;
301
+
302
+ /// Antialiased 0..1 coverage from a signed distance in device pixels.
303
+ /// One device pixel of feather, which is what the rest of gpui uses.
304
+ public float aa(float distance)
305
+ {
306
+ return saturate(0.5 - distance);
307
+ }
308
+
309
+ /// `local`, remapped so that (0,0) is the element centre and the SHORTER
310
+ /// axis spans -1..1 — the coordinate system almost every procedural
311
+ /// pattern actually wants, because it does not stretch with the element.
312
+ public float2 centered()
313
+ {
314
+ float2 c = this.local * 2.0 - 1.0;
315
+ float2 s = this.size / max(min(this.size.x, this.size.y), 1.0);
316
+ return c * s;
317
+ }
318
+ };
319
+
320
+ /// The one interface an effect implements.
321
+ public interface IEffect
322
+ {
323
+ /// Returns the colour for this pixel — PREMULTIPLIED, unless the effect
324
+ /// overrides `straightAlpha`.
325
+ float4 shade(EffectInput input);
326
+
327
+ /// Opt into authoring in STRAIGHT alpha:
328
+ ///
329
+ /// static override bool straightAlpha() { return true; }
330
+ ///
331
+ /// The engine then premultiplies whatever `shade` returns. Slang resolves
332
+ /// this at specialisation time, so the branch is folded away — it costs
333
+ /// nothing at runtime and removes the single most common way to get an
334
+ /// effect wrong.
335
+ static bool straightAlpha() { return false; }
336
+ };
337
+
338
+ // ===========================================================================
339
+ // Engine composition — generic over the effect type
340
+ // ===========================================================================
341
+ //
342
+ // `sk_begin` and `sk_finish` are what a generated wrapper calls; between them
343
+ // it does nothing but unpack the parameter slots into the effect struct's
344
+ // named fields (which is why the compiler needs reflection at all). Because
345
+ // `sk_finish` is generic over `T : IEffect`, Slang specialises the whole
346
+ // composition at compile time: there is no indirect call, no vtable, and the
347
+ // engine-owned coverage/premultiply/backdrop-restore logic lives in this
348
+ // module instead of being pasted into every effect as templated text.
349
+
350
+ float sk_pick_corner_radius(float2 center_to_point, SkCorners radii)
351
+ {
352
+ // Branchless on purpose: the obvious nested-if spelling makes Slang emit a
353
+ // temporary that fxc then reports as `warning X4000: use of potentially
354
+ // uninitialized variable`, which would surface in every effect author's
355
+ // build log for no reason.
356
+ float top = center_to_point.x < 0.0 ? radii.top_left : radii.top_right;
357
+ float bottom = center_to_point.x < 0.0 ? radii.bottom_left : radii.bottom_right;
358
+ return center_to_point.y < 0.0 ? top : bottom;
359
+ }
360
+
361
+ /// Signed distance to a rounded rect. Negative inside, 0 on the edge.
362
+ public float sk_quad_sdf(float2 point, SkBounds bounds, SkCorners radii)
363
+ {
364
+ float2 half_size = bounds.size / 2.0;
365
+ float2 center_to_point = point - (bounds.origin + half_size);
366
+ float radius = sk_pick_corner_radius(center_to_point, radii);
367
+ float2 corner_center_to_point = abs(center_to_point) - half_size + radius;
368
+ if (radius == 0.0)
369
+ {
370
+ return max(corner_center_to_point.x, corner_center_to_point.y);
371
+ }
372
+ return length(max(float2(0.0, 0.0), corner_center_to_point))
373
+ + min(0.0, max(corner_center_to_point.x, corner_center_to_point.y))
374
+ - radius;
375
+ }
376
+
377
+ /// The coverage of the quad's content mask, the rounded clip an `overflow`
378
+ /// ancestor with a `border-radius` pushes. All-zero radii are the plain rect
379
+ /// the clip distances already cut, so they return 1 before any SDF math.
380
+ /// Mirrors `content_mask_coverage` in gpui_windows/src/shaders.hlsl.
381
+ public float sk_content_mask_coverage(float2 position, SkBounds mask, SkCorners radii)
382
+ {
383
+ if (radii.top_left == 0.0 && radii.top_right == 0.0 &&
384
+ radii.bottom_right == 0.0 && radii.bottom_left == 0.0)
385
+ {
386
+ return 1.0;
387
+ }
388
+ return saturate(0.5 - sk_quad_sdf(position, mask, radii));
389
+ }
390
+
391
+ /// The DirectComposition swap chain is premultiplied; keep rgb <= a so the
392
+ /// compositor never sees an out-of-gamut pixel. Applied by `sk_finish`, never
393
+ /// by effect code, precisely so an effect cannot skip it.
394
+ public float4 sk_clamp_premultiplied(float4 color)
395
+ {
396
+ // Written as one construction rather than two component writes: the
397
+ // mutating spelling makes Slang emit an indexed store (`_S[int(3)] = …`)
398
+ // that fxc then reports as `warning X4000: use of potentially
399
+ // uninitialized variable` in every effect that links this function.
400
+ float a = saturate(color.a);
401
+ return float4(clamp(color.rgb, 0.0, float3(a, a, a)), a);
402
+ }
403
+
404
+ /// Builds the `EffectInput` for this pixel. Called by the generated wrapper.
405
+ public EffectInput sk_begin(uint id, float4 frag_position)
406
+ {
407
+ SkEffectQuad q = sk_effect_quads[id];
408
+ float2 position = frag_position.xy;
409
+ // SV_Position is the pixel centre, so this lands on a texel centre of the
410
+ // full-resolution snapshot.
411
+ float2 uv = position / sk_viewport_size;
412
+
413
+ // `bounds`/`corner_radii` describe the DRAW quad, which is the element's
414
+ // border box dilated by `bleed`. Dilating a rounded rect by b is a
415
+ // Minkowski sum with a disc of radius b, so its SDF is exactly the
416
+ // element's minus b — recover one from the other with a single add
417
+ // instead of carrying a second bounds pair through the instance buffer.
418
+ float sd_draw = sk_quad_sdf(position, q.bounds, q.corner_radii);
419
+ float sd_element = sd_draw + q.bleed;
420
+
421
+ float2 element_origin = q.bounds.origin + q.bleed;
422
+ float2 element_size = max(q.bounds.size - 2.0 * q.bleed, float2(1.0, 1.0));
423
+
424
+ bool has_backdrop = (q.flags & SK_FLAG_NEEDS_BACKDROP) != 0u;
425
+
426
+ EffectInput i;
427
+ i.uv = uv;
428
+ i.px = position - element_origin;
429
+ i.size = element_size;
430
+ i.local = i.px / element_size;
431
+ i.backdrop = has_backdrop
432
+ ? sk_backdrop_input.SampleLevel(sk_clamp_sampler, uv, 0.0)
433
+ : float4(0.0, 0.0, 0.0, 0.0);
434
+ i.sd = sd_element;
435
+ i.coverage = saturate(0.5 - sd_element);
436
+ i.time = q.time;
437
+ i.scale = q.scale;
438
+ i.bleed = q.bleed;
439
+ i.opacity = q.opacity;
440
+ 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
+ return i;
445
+ }
446
+
447
+ /// Runs the effect and applies everything the engine owns: the straight-alpha
448
+ /// convention, the premultiplied clamp, the drawn quad's antialiased coverage,
449
+ /// the element opacity, and — for a backdrop effect, which draws with blending
450
+ /// disabled and therefore owns every pixel of its quad — restoring the
451
+ /// untouched snapshot outside that coverage.
452
+ ///
453
+ /// The result is PREMULTIPLIED whatever `straightAlpha` says. Every renderer
454
+ /// blends a non-backdrop effect as premultiplied source-over (One,
455
+ /// OneMinusSrcAlpha); blending it by source alpha would apply alpha twice.
456
+ public float4 sk_finish<T : IEffect>(T material, EffectInput i)
457
+ {
458
+ float4 shaded = material.shade(i);
459
+ if (T.straightAlpha())
460
+ {
461
+ shaded = float4(shaded.rgb * shaded.a, shaded.a);
462
+ }
463
+ shaded = sk_clamp_premultiplied(shaded);
464
+
465
+ float sd_draw = i.sd - i.bleed;
466
+ float coverage = saturate(0.5 - sd_draw) * saturate(i.opacity) * i.clip;
467
+
468
+ // Single exit on purpose — an early `return` inside the branch makes fxc
469
+ // lose track of `shaded` and warn about it.
470
+ float4 result;
471
+ if (i.hasBackdrop)
472
+ {
473
+ float4 original =
474
+ sk_backdrop_original.SampleLevel(sk_clamp_sampler, i.uv, 0.0);
475
+ result = lerp(original, shaded, coverage);
476
+ }
477
+ else
478
+ {
479
+ result = shaded * coverage;
480
+ }
481
+ return sk_clamp_premultiplied(result);
482
+ }
483
+
484
+ // ===========================================================================
485
+ // Helpers
486
+ // ===========================================================================
487
+
488
+ /// Straight alpha -> premultiplied.
489
+ public float4 sk_premultiply(float4 color)
490
+ {
491
+ return float4(color.rgb * color.a, color.a);
492
+ }
493
+
494
+ /// Premultiplied `above` over premultiplied `below`.
495
+ public float4 sk_over(float4 below, float4 above)
496
+ {
497
+ return above + below * (1.0 - above.a);
498
+ }
499
+
500
+ /// Deterministic hash of a 2D point -> 0..1. Cheap, no texture needed.
501
+ public float sk_hash12(float2 p)
502
+ {
503
+ float3 p3 = frac(float3(p.x, p.y, p.x) * 0.1031);
504
+ p3 += dot(p3, float3(p3.y + 33.33, p3.z + 33.33, p3.x + 33.33));
505
+ return frac((p3.x + p3.y) * p3.z);
506
+ }
507
+
508
+ /// Deterministic hash of a 2D point -> two independent 0..1 values.
509
+ public float2 sk_hash22(float2 p)
510
+ {
511
+ float3 p3 = frac(float3(p.x, p.y, p.x) * float3(0.1031, 0.1030, 0.0973));
512
+ p3 += dot(p3, float3(p3.y + 33.33, p3.z + 33.33, p3.x + 33.33));
513
+ return frac((p3.xx + p3.yz) * p3.zy);
514
+ }
515
+
516
+ /// Value noise on a unit lattice, smoothstep-interpolated.
517
+ public float sk_value_noise(float2 p)
518
+ {
519
+ float2 i = floor(p);
520
+ float2 f = frac(p);
521
+ float2 u = f * f * (3.0 - 2.0 * f);
522
+ float a = sk_hash12(i);
523
+ float b = sk_hash12(i + float2(1.0, 0.0));
524
+ float c = sk_hash12(i + float2(0.0, 1.0));
525
+ float d = sk_hash12(i + float2(1.0, 1.0));
526
+ return lerp(lerp(a, b, u.x), lerp(c, d, u.x), u.y);
527
+ }
528
+
529
+ /// Three octaves of value noise. Unrolled: no `Sample` is involved, but a
530
+ /// fixed trip count keeps the generated HLSL flat.
531
+ public float sk_fbm(float2 p)
532
+ {
533
+ float sum = sk_value_noise(p) * 0.5;
534
+ sum += sk_value_noise(p * 2.03) * 0.25;
535
+ sum += sk_value_noise(p * 4.01) * 0.125;
536
+ return sum / 0.875;
537
+ }
538
+
539
+ /// Rotates a 2D point by `radians` about the origin.
540
+ public float2 sk_rotate(float2 p, float radians)
541
+ {
542
+ float s = sin(radians);
543
+ float c = cos(radians);
544
+ return float2(p.x * c - p.y * s, p.x * s + p.y * c);
545
+ }
546
+
547
+ /// Relative luminance of a linear-ish RGB triple.
548
+ public float sk_luma(float3 rgb)
549
+ {
550
+ return dot(rgb, float3(0.2126, 0.7152, 0.0722));
551
+ }
552
+
553
+ /// Inigo Quilez's cosine palette: `a + b * cos(2pi * (c * t + d))`. Four
554
+ /// float3 knobs that sweep a whole family of smooth, well-behaved gradients.
555
+ public float3 sk_palette(float t, float3 a, float3 b, float3 c, float3 d)
556
+ {
557
+ return a + b * cos(6.28318530718 * (c * t + d));
558
+ }
package/package.json CHANGED
@@ -6,11 +6,13 @@
6
6
  "url": "git+https://github.com/argon-chat/skathi.git",
7
7
  "directory": "packages/cli"
8
8
  },
9
- "version": "0.1.0-beta.2",
9
+ "version": "0.1.0-beta.4",
10
10
  "type": "module",
11
11
  "files": [
12
+ "aot",
12
13
  "cli",
13
14
  "check",
15
+ "effects",
14
16
  "templates",
15
17
  "devtools/apps.ts",
16
18
  "devtools/commands.ts",
@@ -30,8 +32,10 @@
30
32
  },
31
33
  "dependencies": {
32
34
  "@clack/prompts": "^1.9.0",
33
- "@skathi-native/runtime": "0.1.0-beta.2",
35
+ "@commander-js/extra-typings": "~15.1.0",
36
+ "@skathi-native/runtime": "0.1.0-beta.4",
34
37
  "@vue/compiler-sfc": "^3.5.41",
38
+ "commander": "~15.1.0",
35
39
  "postcss": "^8.4.31",
36
40
  "tailwindcss": "3.4",
37
41
  "typescript": "5"
Binary file
@@ -0,0 +1,3 @@
1
+ {
2
+ "css.customData": ["./node_modules/@skathi-native/runtime/css-data.json"]
3
+ }
@@ -42,7 +42,7 @@ onMounted(async () => {
42
42
  gap: 20px;
43
43
  padding: 32px;
44
44
  color: #f4f4f5;
45
- font-family: "Segoe UI", system-ui, sans-serif;
45
+ font-family: system-ui, sans-serif;
46
46
  }
47
47
  .card {
48
48
  width: 380px;
@@ -88,7 +88,7 @@ onMounted(async () => {
88
88
  text-align: center;
89
89
  }
90
90
  .code {
91
- font-family: "Cascadia Mono", Consolas, monospace;
91
+ font-family: monospace;
92
92
  font-size: 13px;
93
93
  color: #d4d4d8;
94
94
  }
@@ -0,0 +1,3 @@
1
+ {
2
+ "css.customData": ["./node_modules/@skathi-native/runtime/css-data.json"]
3
+ }
@@ -0,0 +1,23 @@
1
+ import sk;
2
+
3
+ // This app's own `--shading` effect. Every shaders/<name>.slang is compiled into the app by sk build
4
+ // and sk dev; the comments in the `sk` module are the authoring rules.
5
+ [SkEffect("sheen")]
6
+ [SkDoc("a band of light sweeping across the element")]
7
+ struct Sheen : IEffect
8
+ {
9
+ [SkAnimated] [SkDefault("0.5")] [SkRange(0.0, 4.0)]
10
+ float speed;
11
+
12
+ [SkColor] [SkOptional] [SkDefault("#ffffff")]
13
+ float4 tint;
14
+
15
+ static override bool straightAlpha() { return true; }
16
+
17
+ float4 shade(EffectInput input)
18
+ {
19
+ float sweep = frac(input.time * speed) * 1.6 - 0.3;
20
+ float band = saturate(1.0 - abs((input.local.x + input.local.y) * 0.5 - sweep) * 8.0);
21
+ return float4(tint.rgb, tint.a * band * band * 0.6);
22
+ }
23
+ };
@@ -3,7 +3,6 @@
3
3
  // strip drag the window, and `--window-control` on each button gives it the OS behaviour (snap layouts on maximize).
4
4
  import { appWindow } from "@skathi-native/runtime";
5
5
  import { onMounted, onUnmounted, ref } from "vue";
6
- import { nav } from "../engine";
7
6
  import { productName } from "../product";
8
7
 
9
8
  defineProps<{ page: string }>();
@@ -16,12 +15,12 @@ const read = () => {
16
15
  };
17
16
 
18
17
  onMounted(() => {
19
- nav.windowControlsOverlay.addEventListener("geometrychange", read);
18
+ navigator.windowControlsOverlay.addEventListener("geometrychange", read);
20
19
  appWindow.addEventListener("maximize", read);
21
20
  appWindow.addEventListener("unmaximize", read);
22
21
  });
23
22
  onUnmounted(() => {
24
- nav.windowControlsOverlay.removeEventListener("geometrychange", read);
23
+ navigator.windowControlsOverlay.removeEventListener("geometrychange", read);
25
24
  appWindow.removeEventListener("maximize", read);
26
25
  appWindow.removeEventListener("unmaximize", read);
27
26
  });
@@ -63,6 +62,11 @@ onUnmounted(() => {
63
62
  user-select: none;
64
63
  border-bottom: 1px solid var(--line);
65
64
  }
65
+ @media (display-mode: fullscreen) {
66
+ .titlebar {
67
+ display: none;
68
+ }
69
+ }
66
70
  .brand {
67
71
  display: flex;
68
72
  align-items: center;