@istmx/skills 1.2.0 → 2.0.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.
Files changed (111) hide show
  1. package/README.md +38 -20
  2. package/bin/cli.js +50 -24
  3. package/istm-animate/SKILL.md +31 -26
  4. package/istm-animate/core/motion-principles/SKILL.md +284 -0
  5. package/istm-animate/core/motion-principles/references/designers.md +127 -0
  6. package/istm-animate/core/motion-principles/references/easing-guide.md +231 -0
  7. package/istm-animate/core/motion-principles/references/enter-exit-recipes.md +466 -0
  8. package/istm-animate/frameworks/canvas-generative/SKILL.md +325 -0
  9. package/istm-animate/frameworks/canvas-generative/references/algorithms.md +925 -0
  10. package/istm-animate/frameworks/css-native/SKILL.md +319 -0
  11. package/istm-animate/frameworks/css-native/references/modern-css.md +465 -0
  12. package/istm-animate/frameworks/framer-motion/SKILL.md +187 -0
  13. package/istm-animate/frameworks/framer-motion/references/api.md +312 -0
  14. package/istm-animate/frameworks/gsap/SKILL.md +188 -0
  15. package/istm-animate/frameworks/gsap/references/core.md +218 -0
  16. package/istm-animate/frameworks/gsap/references/plugins.md +371 -0
  17. package/istm-animate/frameworks/gsap/references/scrolltrigger.md +325 -0
  18. package/istm-animate/frameworks/gsap/references/timeline.md +218 -0
  19. package/istm-animate/frameworks/threejs-r3f/SKILL.md +243 -0
  20. package/istm-animate/frameworks/threejs-r3f/references/scene-setup.md +392 -0
  21. package/istm-animate/frameworks/threejs-r3f/references/shaders.md +446 -0
  22. package/istm-animate/mobile/android/compose-graphics/SKILL.md +503 -0
  23. package/istm-animate/mobile/android/compose-graphics/references/agsl-recipes.md +356 -0
  24. package/istm-animate/mobile/android/compose-graphics/references/canvas-generative.md +282 -0
  25. package/istm-animate/mobile/android/compose-graphics/references/m3-expressive-deep.md +303 -0
  26. package/istm-animate/mobile/android/compose-motion/SKILL.md +359 -0
  27. package/istm-animate/mobile/android/compose-motion/references/gestures-compose.md +273 -0
  28. package/istm-animate/mobile/android/compose-motion/references/recomposition-and-anim.md +196 -0
  29. package/istm-animate/mobile/android/compose-motion/references/shared-transitions.md +281 -0
  30. package/istm-animate/mobile/android/compose-multiplatform/SKILL.md +311 -0
  31. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-interop.md +288 -0
  32. package/istm-animate/mobile/android/compose-multiplatform/references/cmp-platform-quirks.md +156 -0
  33. package/istm-animate/mobile/apple/swiftui-graphics/SKILL.md +408 -0
  34. package/istm-animate/mobile/apple/swiftui-graphics/references/canvas-swiftui.md +239 -0
  35. package/istm-animate/mobile/apple/swiftui-graphics/references/liquid-glass-deep.md +252 -0
  36. package/istm-animate/mobile/apple/swiftui-graphics/references/metal-recipes.md +382 -0
  37. package/istm-animate/mobile/apple/swiftui-motion/SKILL.md +379 -0
  38. package/istm-animate/mobile/apple/swiftui-motion/references/gestures-swiftui.md +336 -0
  39. package/istm-animate/mobile/apple/swiftui-motion/references/phase-keyframe-deep.md +231 -0
  40. package/istm-animate/mobile/apple/swiftui-motion/references/springs-cheatsheet.md +129 -0
  41. package/istm-animate/references/animate.md +199 -0
  42. package/istm-animate/references/audit.md +115 -0
  43. package/istm-animate/references/design-engineering.md +674 -0
  44. package/istm-animate/references/improve.md +101 -0
  45. package/istm-animate/references/opportunities.md +132 -0
  46. package/istm-animate/references/plan-template.md +73 -0
  47. package/istm-animate/references/recipes.md +324 -0
  48. package/istm-animate/references/review.md +112 -0
  49. package/istm-animate/references/standards.md +187 -0
  50. package/istm-animate/references/vocabulary.md +173 -0
  51. package/istm-awwward-designer/SKILL.md +29 -17
  52. package/istm-design/SKILL.md +31 -59
  53. package/istm-design/core/design-audit/SKILL.md +248 -0
  54. package/istm-design/core/desktop-principles/SKILL.md +363 -0
  55. package/istm-design/core/desktop-principles/references/keyboard-patterns.md +137 -0
  56. package/istm-design/core/desktop-principles/references/multi-window.md +105 -0
  57. package/istm-design/core/mobile-principles/SKILL.md +289 -0
  58. package/istm-design/core/mobile-principles/references/accessibility-mobile.md +175 -0
  59. package/istm-design/core/mobile-principles/references/gestures-deep.md +220 -0
  60. package/istm-design/core/ui-ux-pro-max/SKILL.md +392 -0
  61. package/istm-design/core/ui-ux-pro-max/UPSTREAM.md +23 -0
  62. package/istm-design/core/ui-ux-pro-max/data/app-interface.csv +31 -0
  63. package/istm-design/core/ui-ux-pro-max/data/charts.csv +26 -0
  64. package/istm-design/core/ui-ux-pro-max/data/colors.csv +193 -0
  65. package/istm-design/core/ui-ux-pro-max/data/google-fonts.csv +1924 -0
  66. package/istm-design/core/ui-ux-pro-max/data/icons.csv +106 -0
  67. package/istm-design/core/ui-ux-pro-max/data/landing.csv +35 -0
  68. package/istm-design/core/ui-ux-pro-max/data/motion.csv +17 -0
  69. package/istm-design/core/ui-ux-pro-max/data/products.csv +193 -0
  70. package/istm-design/core/ui-ux-pro-max/data/react-performance.csv +45 -0
  71. package/istm-design/core/ui-ux-pro-max/data/stacks/angular.csv +51 -0
  72. package/istm-design/core/ui-ux-pro-max/data/stacks/astro.csv +54 -0
  73. package/istm-design/core/ui-ux-pro-max/data/stacks/avalonia.csv +57 -0
  74. package/istm-design/core/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  75. package/istm-design/core/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  76. package/istm-design/core/ui-ux-pro-max/data/stacks/javafx.csv +76 -0
  77. package/istm-design/core/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  78. package/istm-design/core/ui-ux-pro-max/data/stacks/laravel.csv +51 -0
  79. package/istm-design/core/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  80. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxt-ui.csv +71 -0
  81. package/istm-design/core/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  82. package/istm-design/core/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  83. package/istm-design/core/ui-ux-pro-max/data/stacks/react.csv +54 -0
  84. package/istm-design/core/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  85. package/istm-design/core/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  86. package/istm-design/core/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  87. package/istm-design/core/ui-ux-pro-max/data/stacks/threejs.csv +54 -0
  88. package/istm-design/core/ui-ux-pro-max/data/stacks/uno.csv +60 -0
  89. package/istm-design/core/ui-ux-pro-max/data/stacks/uwp.csv +56 -0
  90. package/istm-design/core/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  91. package/istm-design/core/ui-ux-pro-max/data/stacks/winui.csv +60 -0
  92. package/istm-design/core/ui-ux-pro-max/data/stacks/wpf.csv +57 -0
  93. package/istm-design/core/ui-ux-pro-max/data/styles.csv +85 -0
  94. package/istm-design/core/ui-ux-pro-max/data/typography.csv +75 -0
  95. package/istm-design/core/ui-ux-pro-max/data/ui-reasoning.csv +162 -0
  96. package/istm-design/core/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  97. package/istm-design/core/ui-ux-pro-max/references/pro-rules.md +109 -0
  98. package/istm-design/core/ui-ux-pro-max/references/quick-reference.md +240 -0
  99. package/istm-design/core/ui-ux-pro-max/scripts/core.py +464 -0
  100. package/istm-design/core/ui-ux-pro-max/scripts/design_system.py +1371 -0
  101. package/istm-design/core/ui-ux-pro-max/scripts/search.py +162 -0
  102. package/istm-design/core/ui-ux-pro-max/scripts/tests/test_core.py +134 -0
  103. package/istm-design/core/ui-ux-pro-max/scripts/validate_data.py +114 -0
  104. package/istm-design/references/apple-design.md +282 -0
  105. package/istm-design/references/generation-guide.md +209 -0
  106. package/istm-design/references/pick-ui-library.md +77 -0
  107. package/istm-design/references/picker.md +197 -0
  108. package/istm-design/references/prototype.md +90 -0
  109. package/istm-design/references/schema.md +366 -0
  110. package/package.json +1 -1
  111. package/RELEASE_v1.2.0.md +0 -40
@@ -0,0 +1,408 @@
1
+ ---
2
+ name: swiftui-graphics
3
+ description: "Advanced SwiftUI visuals - Metal shaders (.colorEffect, .layerEffect, .distortionEffect), .visualEffect, Liquid Glass (iOS 26), Canvas, holographic and CRT effects."
4
+ ---
5
+
6
+ # SwiftUI Graphics
7
+
8
+ > Advanced SwiftUI visuals: Metal shaders, visual effects, Liquid Glass, Canvas.
9
+ > Loaded for advanced thesis (shaders, holographic, liquid-glass, distortion).
10
+ > Foundation: `../swiftui-motion/SKILL.md` covers the basics.
11
+ > Concise rules here. Deep-dives in `references/`.
12
+
13
+ ---
14
+
15
+ ## Decision Tree: Which API?
16
+
17
+ | Need | API |
18
+ |---|---|
19
+ | Pixel-level color manipulation | `.colorEffect(ShaderLibrary....)` |
20
+ | Pixel position / distortion | `.distortionEffect(ShaderLibrary....)` |
21
+ | Full layer with overlay (mix shader + bg) | `.layerEffect(ShaderLibrary....)` |
22
+ | View modifier with geometry context | `.visualEffect { content, geometry in }` |
23
+ | Custom drawing (paths, gradients) | `Canvas { context, size in }` |
24
+ | iOS 26+ glassmorphism | `.glassEffect()` / `GlassEffectContainer` |
25
+ | Performance dump | `Canvas` with `.opaque(true)` then export |
26
+
27
+ > **Default order of escalation:** built-in modifiers -> `.visualEffect` -> `Canvas` -> Metal shader. Reach for shaders only when the effect is per-pixel and animated.
28
+
29
+ ---
30
+
31
+ ## Metal Shaders Intro
32
+
33
+ SwiftUI binds to Metal Shading Language (MSL) via three modifiers shipped in iOS 17: `.colorEffect`, `.distortionEffect`, `.layerEffect`. You author a `.metal` file in your app target, mark functions with the `[[ stitchable ]]` attribute, and SwiftUI auto-generates the Swift binding via `ShaderLibrary.<functionName>(...)`. One library per app target. Shaders run on the GPU at native resolution; arguments are passed as `.float`, `.float2`, `.color`, `.image` from Swift. iOS 17+ only; for older targets, fall back to gradients, blur, or `Canvas`.
34
+
35
+ The three slots differ by what data they receive:
36
+ - `.colorEffect`: gets `(position, color)`, returns transformed color. No neighbor sampling.
37
+ - `.distortionEffect`: gets `(position)`, returns a new sample position. Pixels move, colors do not change.
38
+ - `.layerEffect`: gets `(position, SwiftUI::Layer layer)`, returns final color. Can sample anywhere within `maxSampleOffset`. Most expensive.
39
+
40
+ ---
41
+
42
+ ## Recipe: Ripple `.layerEffect`
43
+
44
+ Touch ripple that displaces nearby pixels along a sine wave.
45
+
46
+ ```swift
47
+ struct RippleView: View {
48
+ @State var rippleOrigin: CGPoint = .zero
49
+ @State var rippleTime: Float = 0
50
+
51
+ var body: some View {
52
+ Image("photo")
53
+ .resizable()
54
+ .scaledToFit()
55
+ .layerEffect(
56
+ ShaderLibrary.ripple(
57
+ .float2(Float(rippleOrigin.x), Float(rippleOrigin.y)),
58
+ .float(rippleTime),
59
+ .float(0.05) // amplitude
60
+ ),
61
+ maxSampleOffset: CGSize(width: 50, height: 50)
62
+ )
63
+ .onTapGesture { location in
64
+ rippleOrigin = location
65
+ rippleTime = 0
66
+ withAnimation(.linear(duration: 1.2)) {
67
+ rippleTime = 1.2
68
+ }
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ```metal
75
+ // Ripple.metal
76
+ #include <SwiftUI/SwiftUI_Metal.h>
77
+ using namespace metal;
78
+
79
+ [[ stitchable ]]
80
+ half4 ripple(float2 position, SwiftUI::Layer layer,
81
+ float2 origin, float time, float amp) {
82
+ float distance = length(position - origin);
83
+ float wave = sin(distance * 0.05 - time * 8.0) * amp;
84
+ float2 dir = normalize(position - origin);
85
+ float falloff = 1.0 / max(distance, 1.0);
86
+ float2 displaced = position + dir * wave * falloff * 50.0;
87
+ return layer.sample(displaced);
88
+ }
89
+ ```
90
+
91
+ **Why this works:**
92
+ - `[[ stitchable ]]` exposes the function to SwiftUI's runtime.
93
+ - The first two args (`position`, `SwiftUI::Layer layer`) are injected by SwiftUI for any `.layerEffect`. Your Swift-side args start at index 2.
94
+ - `maxSampleOffset` tells SwiftUI how far you may sample beyond the view bounds. Underestimate and you get clipping. Overestimate and you waste GPU.
95
+
96
+ ---
97
+
98
+ ## Recipe: Holographic `.colorEffect`
99
+
100
+ Oil-slick rainbow shimmer driven by time or scroll offset. Preserves luminance so dark regions stay dark.
101
+
102
+ ```metal
103
+ // Holographic.metal
104
+ #include <SwiftUI/SwiftUI_Metal.h>
105
+ using namespace metal;
106
+
107
+ [[ stitchable ]]
108
+ half4 holographic(float2 position, half4 color, float time) {
109
+ float n = position.x * 0.01 + position.y * 0.005 + time * 0.3;
110
+ half3 rainbow = half3(
111
+ sin(n * 2.0) * 0.5 + 0.5,
112
+ sin(n * 2.0 + 2.094) * 0.5 + 0.5,
113
+ sin(n * 2.0 + 4.188) * 0.5 + 0.5
114
+ );
115
+ half luminance = dot(color.rgb, half3(0.299, 0.587, 0.114));
116
+ return half4(mix(color.rgb, rainbow * luminance * 2.0, 0.5), color.a);
117
+ }
118
+ ```
119
+
120
+ ```swift
121
+ struct HolographicCard: View {
122
+ let startTime = Date()
123
+
124
+ var body: some View {
125
+ TimelineView(.animation) { timeline in
126
+ let elapsed = Float(timeline.date.timeIntervalSince(startTime))
127
+ Image("card")
128
+ .resizable()
129
+ .scaledToFit()
130
+ .colorEffect(
131
+ ShaderLibrary.holographic(.float(elapsed))
132
+ )
133
+ }
134
+ }
135
+ }
136
+ ```
137
+
138
+ > The 2.094 and 4.188 offsets are 2pi/3 and 4pi/3 -- they spread the three sine waves to RGB phases. Keep them.
139
+
140
+ ---
141
+
142
+ ## Recipe: CRT Scanlines
143
+
144
+ Vintage CRT effect: scanlines, flicker, subtle chromatic aberration.
145
+
146
+ ```metal
147
+ // CRT.metal
148
+ #include <SwiftUI/SwiftUI_Metal.h>
149
+ using namespace metal;
150
+
151
+ [[ stitchable ]]
152
+ half4 crt(float2 position, half4 color, float time) {
153
+ float scanline = sin(position.y * 1.5) * 0.04;
154
+ float flicker = sin(time * 60.0) * 0.02;
155
+ half3 result = color.rgb * (1.0 - scanline - flicker);
156
+ // chromatic aberration on R/B channels
157
+ return half4(result.r * 1.05, result.g, result.b * 1.05, color.a);
158
+ }
159
+ ```
160
+
161
+ ```swift
162
+ .colorEffect(ShaderLibrary.crt(.float(elapsed)))
163
+ ```
164
+
165
+ > For real chromatic aberration (shifted R/B sample positions), promote to `.layerEffect`. The version above only tints, which reads as CRT at small scale.
166
+
167
+ ---
168
+
169
+ ## `.visualEffect` (iOS 17+)
170
+
171
+ Modifier that exposes the view's `GeometryProxy` so you can react to its frame in any coordinate space without `GeometryReader` boilerplate.
172
+
173
+ ```swift
174
+ ScrollView {
175
+ LazyVStack(spacing: 16) {
176
+ ForEach(items) { item in
177
+ CardView(item: item)
178
+ .visualEffect { content, proxy in
179
+ let y = proxy.frame(in: .scrollView).minY
180
+ let scale = scale(for: y)
181
+ let opacity = opacity(for: y)
182
+ return content
183
+ .scaleEffect(scale)
184
+ .opacity(opacity)
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ func scale(for y: CGFloat) -> CGFloat {
191
+ let progress = max(0, min(1, y / 600))
192
+ return 0.85 + progress * 0.15
193
+ }
194
+ ```
195
+
196
+ **Use cases:**
197
+ - Parallax cards (move slower than scroll)
198
+ - Scroll-driven scale (cards grow as they enter view)
199
+ - Sticky reveal (clamp position via `.offset(y: max(0, -y))`)
200
+
201
+ > `.visualEffect` is purely visual: the geometry it returns is read-only and the modifier cannot trigger state updates. Don't try to write to `@State` from inside.
202
+
203
+ ---
204
+
205
+ ## Liquid Glass (iOS 26)
206
+
207
+ System glassmorphism with adaptive depth and morphing transitions. Built into the OS, optimized at the system level.
208
+
209
+ ```swift
210
+ @Namespace var glassNS
211
+
212
+ struct HeroCard: View {
213
+ var body: some View {
214
+ if #available(iOS 26.0, *) {
215
+ Image("hero")
216
+ .resizable()
217
+ .scaledToFit()
218
+ .glassEffect(.regular)
219
+ .glassEffectID("hero", in: glassNS)
220
+ } else {
221
+ Image("hero")
222
+ .resizable()
223
+ .scaledToFit()
224
+ .background(.ultraThinMaterial)
225
+ }
226
+ }
227
+ }
228
+ ```
229
+
230
+ For grouped surfaces that should morph as one (e.g., a tab bar that splits into separate pills on hover), wrap them in a container:
231
+
232
+ ```swift
233
+ GlassEffectContainer(spacing: 12) {
234
+ ForEach(tabs) { tab in
235
+ TabIcon(tab: tab)
236
+ .glassEffect(.regular)
237
+ .glassEffectID(tab.id, in: glassNS)
238
+ }
239
+ }
240
+ ```
241
+
242
+ > Pre-iOS 26: use `.background(.ultraThinMaterial)` for static glass. For morphing transitions, fall back to `matchedGeometryEffect` on a material-backed view (see `swiftui-motion`).
243
+
244
+ Deep-dive: `references/liquid-glass-deep.md`.
245
+
246
+ ---
247
+
248
+ ## Canvas (SwiftUI Native Drawing)
249
+
250
+ Vector drawing API. Paths, gradients, text, blend modes -- without leaving SwiftUI.
251
+
252
+ ```swift
253
+ struct SparkleField: View {
254
+ var body: some View {
255
+ Canvas { context, size in
256
+ for _ in 0..<20 {
257
+ let x = Double.random(in: 0...size.width)
258
+ let y = Double.random(in: 0...size.height)
259
+ let radius = Double.random(in: 1...4)
260
+ context.fill(
261
+ Path(ellipseIn: CGRect(x: x, y: y, width: radius, height: radius)),
262
+ with: .color(.white.opacity(.random(in: 0.3...1.0)))
263
+ )
264
+ }
265
+ }
266
+ }
267
+ }
268
+ ```
269
+
270
+ To animate, wrap in `TimelineView(.animation)` so the closure re-runs at frame rate:
271
+
272
+ ```swift
273
+ TimelineView(.animation) { timeline in
274
+ Canvas { context, size in
275
+ let t = timeline.date.timeIntervalSinceReferenceDate
276
+ // draw using t as time
277
+ }
278
+ }
279
+ ```
280
+
281
+ > `TimelineView(.animation)` redraws at the screen refresh rate. Use `.animation(minimumInterval: 0.1)` for slower animations to save power.
282
+
283
+ Deep-dive: `references/canvas-swiftui.md`.
284
+
285
+ ---
286
+
287
+ ## Performance Considerations
288
+
289
+ | Effect | Cost | Notes |
290
+ |---|---|---|
291
+ | `.colorEffect` | low | Runs per pixel, simple math, no neighbor access |
292
+ | `.distortionEffect` | medium | Sampling cost, branch-free is critical |
293
+ | `.layerEffect` | high | Full layer access, can sample anywhere |
294
+ | `Canvas` with TimelineView | varies | Depends on draw count and complexity |
295
+ | `.glassEffect` | medium-high | GPU heavy, fine on modern devices |
296
+
297
+ **Rules:**
298
+ 1. Avoid stacking >1 `.layerEffect` on the same view -- each is a full render pass.
299
+ 2. Precompute static parts (gradients, paths) outside the animated subtree.
300
+ 3. Profile with Instruments **GPU Frame Capture** and **Metal System Trace** before optimizing blindly.
301
+
302
+ ---
303
+
304
+ ## Anti-Patterns
305
+
306
+ ### 1. Stacked `.colorEffect` modifiers
307
+
308
+ Each modifier is a separate render pass.
309
+
310
+ ```swift
311
+ // BAD -- 5 GPU passes
312
+ Image(...)
313
+ .colorEffect(ShaderLibrary.tint(...))
314
+ .colorEffect(ShaderLibrary.scanlines(...))
315
+ .colorEffect(ShaderLibrary.grain(...))
316
+ .colorEffect(ShaderLibrary.vignette(...))
317
+ .colorEffect(ShaderLibrary.chromatic(...))
318
+
319
+ // GOOD -- one shader does all the ops in one pass
320
+ Image(...)
321
+ .colorEffect(ShaderLibrary.crtCombo(.float(time)))
322
+ ```
323
+
324
+ ### 2. Canvas redrawn on every state change
325
+
326
+ Canvas re-runs when any ancestor state changes. Without `TimelineView` or `EquatableView`, you redraw on input you never intended.
327
+
328
+ ```swift
329
+ // BAD -- redraws on parent re-render
330
+ struct Parent: View {
331
+ @State var unrelated = 0
332
+ var body: some View {
333
+ VStack {
334
+ Button("tick") { unrelated += 1 }
335
+ Canvas { context, size in expensiveDraw(context, size) }
336
+ }
337
+ }
338
+ }
339
+
340
+ // GOOD -- isolate via EquatableView or TimelineView
341
+ TimelineView(.animation) { _ in
342
+ Canvas { context, size in expensiveDraw(context, size) }
343
+ }
344
+ ```
345
+
346
+ ### 3. Hardcoded color values inside shader
347
+
348
+ Forces a recompile to change color. Pass them through.
349
+
350
+ ```metal
351
+ // BAD
352
+ half3 tint = half3(1.0, 0.4, 0.2);
353
+
354
+ // GOOD -- accept color from Swift
355
+ [[ stitchable ]]
356
+ half4 tinted(float2 pos, half4 color, half4 tint) {
357
+ return half4(color.rgb * tint.rgb, color.a);
358
+ }
359
+ ```
360
+
361
+ ```swift
362
+ .colorEffect(ShaderLibrary.tinted(.color(themeAccent)))
363
+ ```
364
+
365
+ ### 4. `.glassEffect` everywhere
366
+
367
+ Liquid Glass is expensive and visually noisy when overused. Reserve for hero / chrome surfaces.
368
+
369
+ ```swift
370
+ // BAD -- 30 glass cards in a list
371
+ LazyVStack {
372
+ ForEach(items) { item in
373
+ Card(item: item).glassEffect(.regular) // GPU melt
374
+ }
375
+ }
376
+
377
+ // GOOD -- glass on the floating tab bar, opaque cards underneath
378
+ ZStack(alignment: .bottom) {
379
+ ScrollView { LazyVStack { ForEach(items) { Card(item: $0) } } }
380
+ TabBar().glassEffect(.regular)
381
+ }
382
+ ```
383
+
384
+ ---
385
+
386
+ ## Quick Reference
387
+
388
+ | Need | Load |
389
+ |---|---|
390
+ | Metal recipes deep dive | `references/metal-recipes.md` |
391
+ | Liquid Glass patterns + iOS 26 specifics | `references/liquid-glass-deep.md` |
392
+ | Canvas drawing patterns | `references/canvas-swiftui.md` |
393
+ | Base animations | `../swiftui-motion/SKILL.md` |
394
+ | Foundation | `../motion-principles/SKILL.md` |
395
+ | Mobile UX (iOS) | `../mobile-principles/SKILL.md` |
396
+ | Desktop UX (macOS) | `../desktop-principles/SKILL.md` |
397
+
398
+ ---
399
+
400
+ ## Sources
401
+
402
+ - [twostraws/Inferno](https://github.com/twostraws/Inferno) - reference Metal shaders for SwiftUI
403
+ - [Treata11/iShader](https://github.com/Treata11/iShader)
404
+ - [jamesrochabrun/ShaderKit](https://github.com/jamesrochabrun/ShaderKit)
405
+ - [raphaelsalaja/metallurgy](https://github.com/raphaelsalaja/metallurgy)
406
+ - [eleev/swiftui-new-metal-shaders](https://github.com/eleev/swiftui-new-metal-shaders)
407
+ - [Apple Metal Shading Language Spec](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf)
408
+ - [Apple Shader documentation](https://developer.apple.com/documentation/swiftui/shader)
@@ -0,0 +1,239 @@
1
+ # Canvas (SwiftUI Native Drawing)
2
+
3
+ > Vector drawing without leaving SwiftUI. Paths, gradients, text, blend modes.
4
+ > Concise patterns for `Canvas` + `TimelineView`. iOS 15+.
5
+
6
+ ---
7
+
8
+ ## `Canvas` API Basics
9
+
10
+ ```swift
11
+ Canvas { context, size in
12
+ // draw using context, bounded by size
13
+ }
14
+ ```
15
+
16
+ The `context` is a `GraphicsContext`. The `size` is a `CGSize`.
17
+
18
+ **Key methods:**
19
+
20
+ | Method | Purpose |
21
+ |---|---|
22
+ | `context.fill(_ path: Path, with: GraphicsContext.Shading)` | Fill a path with color, gradient, image |
23
+ | `context.stroke(_ path: Path, with: ..., lineWidth:)` | Stroke a path |
24
+ | `context.draw(_ image: GraphicsContext.ResolvedImage, in: CGRect)` | Draw a resolved image |
25
+ | `context.draw(_ text: Text, at: CGPoint)` | Draw resolved text |
26
+ | `context.addFilter(_: GraphicsContext.Filter)` | Apply blur, shadow, color matrix |
27
+ | `context.transform = CGAffineTransform` | Cumulative transform |
28
+ | `context.clip(to: Path)` | Clip subsequent draws |
29
+ | `context.opacity = Double` | Set opacity for subsequent draws |
30
+ | `context.blendMode = GraphicsContext.BlendMode` | Set blend mode |
31
+
32
+ **Path construction:**
33
+ ```swift
34
+ // Built-in shapes
35
+ Path(ellipseIn: rect)
36
+ Path(roundedRect: rect, cornerRadius: 12)
37
+ Path(CGRect(...))
38
+
39
+ // Manual construction
40
+ var path = Path()
41
+ path.move(to: CGPoint(x: 0, y: 0))
42
+ path.addLine(to: CGPoint(x: 100, y: 100))
43
+ path.addQuadCurve(to: end, control: ctrl)
44
+ path.addArc(center: c, radius: r, startAngle: .zero, endAngle: .pi, clockwise: false)
45
+ path.closeSubpath()
46
+ ```
47
+
48
+ **Symbol drawing** (resolve a SwiftUI view inside Canvas):
49
+ ```swift
50
+ Canvas { context, size in
51
+ if let star = context.resolveSymbol(id: "star") {
52
+ context.draw(star, at: CGPoint(x: 50, y: 50))
53
+ }
54
+ } symbols: {
55
+ Image(systemName: "star.fill").tag("star").foregroundStyle(.yellow)
56
+ }
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Animating with TimelineView
62
+
63
+ `Canvas` does not animate by itself. Wrap in `TimelineView(.animation)` so the closure re-runs at the screen refresh rate.
64
+
65
+ ```swift
66
+ TimelineView(.animation) { timeline in
67
+ Canvas { context, size in
68
+ let t = timeline.date.timeIntervalSinceReferenceDate
69
+ // draw using t as time
70
+ }
71
+ }
72
+ ```
73
+
74
+ **Schedules:**
75
+
76
+ | Schedule | Use |
77
+ |---|---|
78
+ | `.animation` | Frame rate (60-120 Hz), best for visual animation |
79
+ | `.animation(minimumInterval: 0.1)` | 10 fps cap, save power for slow effects |
80
+ | `.periodic(from:by:)` | Fixed interval (clocks, counters) |
81
+ | `.explicit([dates])` | Manual schedule |
82
+
83
+ ---
84
+
85
+ ## Recipes
86
+
87
+ ### Sparkle Field
88
+
89
+ 30 random sparkles fading in/out with stable per-sparkle phase.
90
+
91
+ ```swift
92
+ struct Sparkle: Identifiable {
93
+ let id = UUID()
94
+ let position: CGPoint
95
+ let size: Double
96
+ let phase: Double
97
+ }
98
+
99
+ struct SparkleField: View {
100
+ let sparkles: [Sparkle] = (0..<30).map { _ in
101
+ Sparkle(
102
+ position: CGPoint(x: .random(in: 0...300), y: .random(in: 0...600)),
103
+ size: .random(in: 2...5),
104
+ phase: .random(in: 0...(2 * .pi))
105
+ )
106
+ }
107
+
108
+ var body: some View {
109
+ TimelineView(.animation) { timeline in
110
+ Canvas { context, size in
111
+ let t = timeline.date.timeIntervalSinceReferenceDate
112
+ for s in sparkles {
113
+ let alpha = (sin(t * 2 + s.phase) + 1) / 2 * 0.8 + 0.2
114
+ context.fill(
115
+ Path(ellipseIn: CGRect(
116
+ x: s.position.x, y: s.position.y,
117
+ width: s.size, height: s.size
118
+ )),
119
+ with: .color(.white.opacity(alpha))
120
+ )
121
+ }
122
+ }
123
+ }
124
+ .frame(width: 300, height: 600)
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Animated Sine Wave
130
+
131
+ ```swift
132
+ TimelineView(.animation) { timeline in
133
+ Canvas { context, size in
134
+ let t = timeline.date.timeIntervalSinceReferenceDate
135
+ var path = Path()
136
+ path.move(to: CGPoint(x: 0, y: size.height / 2))
137
+ for x in stride(from: 0, through: size.width, by: 2) {
138
+ let y = size.height / 2 + sin(x * 0.02 + t * 2) * 30
139
+ path.addLine(to: CGPoint(x: x, y: y))
140
+ }
141
+ context.stroke(path, with: .color(.cyan), lineWidth: 2)
142
+ }
143
+ }
144
+ ```
145
+
146
+ ### Particle Trail (cursor-following)
147
+
148
+ ```swift
149
+ struct ParticleTrail: View {
150
+ @State var trail: [CGPoint] = []
151
+
152
+ var body: some View {
153
+ Canvas { context, size in
154
+ for (i, point) in trail.enumerated() {
155
+ let alpha = Double(i) / Double(max(trail.count, 1))
156
+ let radius = 2 + alpha * 8
157
+ context.fill(
158
+ Path(ellipseIn: CGRect(
159
+ x: point.x - radius / 2, y: point.y - radius / 2,
160
+ width: radius, height: radius
161
+ )),
162
+ with: .color(.purple.opacity(alpha))
163
+ )
164
+ }
165
+ }
166
+ .gesture(
167
+ DragGesture(minimumDistance: 0)
168
+ .onChanged { value in
169
+ trail.append(value.location)
170
+ if trail.count > 30 { trail.removeFirst() }
171
+ }
172
+ )
173
+ }
174
+ }
175
+ ```
176
+
177
+ ### Gradient Mesh (moving anchors)
178
+
179
+ Radial gradients at moving anchor points, blended with `.plusLighter`.
180
+
181
+ ```swift
182
+ TimelineView(.animation) { timeline in
183
+ Canvas { context, size in
184
+ context.blendMode = .plusLighter
185
+ let t = timeline.date.timeIntervalSinceReferenceDate
186
+ let anchors = [
187
+ CGPoint(x: size.width * 0.3 + sin(t) * 50, y: size.height * 0.3 + cos(t) * 50),
188
+ CGPoint(x: size.width * 0.7 + cos(t * 0.7) * 50, y: size.height * 0.7 + sin(t * 0.7) * 50),
189
+ ]
190
+ let colors: [Color] = [.purple, .cyan]
191
+ for (anchor, color) in zip(anchors, colors) {
192
+ let gradient = Gradient(colors: [color.opacity(0.6), color.opacity(0)])
193
+ context.fill(
194
+ Path(CGRect(origin: .zero, size: size)),
195
+ with: .radialGradient(
196
+ gradient,
197
+ center: anchor,
198
+ startRadius: 0,
199
+ endRadius: 200
200
+ )
201
+ )
202
+ }
203
+ }
204
+ }
205
+ ```
206
+
207
+ ---
208
+
209
+ ## Performance
210
+
211
+ - **Canvas redraws on ancestor state changes.** Wrap with `EquatableView` or `.drawingGroup()` to control scope.
212
+ - **Heavy draws: precompute paths once** using `let path = Path { ... }` outside the closure or in `@State`.
213
+ - **Don't draw thousands of items.** For pixel-grain effects (smoke, fire, dense particles), `.layerEffect` with a Metal shader scales better.
214
+ - **`drawingGroup()`** turns Canvas into a single Metal-backed layer. Useful when nested in heavy hierarchies, but disables hit-testing on the contents.
215
+ - **Symbol resolve cost.** `context.resolveSymbol` is cheap once but called every frame. Cache outside if symbols never change.
216
+
217
+ ---
218
+
219
+ ## Canvas vs Metal Shader
220
+
221
+ | Need | Tool |
222
+ |---|---|
223
+ | Vector drawing (paths, shapes) | Canvas |
224
+ | Text rendering | Canvas (via `Text`) |
225
+ | Hundreds of distinct shapes with simple animation | Canvas |
226
+ | Pixel-level color manipulation | Metal shader (`.colorEffect`) |
227
+ | Pixel displacement, ripples, distortion | Metal shader (`.distortionEffect`/`.layerEffect`) |
228
+ | Thousands of particles, smoke, fluids | Metal shader or SpriteKit |
229
+ | Static / one-shot drawing | Canvas (no TimelineView) |
230
+
231
+ > **Rule:** if you can describe the effect in vectors, use Canvas. If it's per-pixel, use Metal.
232
+
233
+ ---
234
+
235
+ ## Sources
236
+
237
+ - [Apple Canvas documentation](https://developer.apple.com/documentation/swiftui/canvas)
238
+ - [Apple TimelineView documentation](https://developer.apple.com/documentation/swiftui/timelineview)
239
+ - [Apple GraphicsContext](https://developer.apple.com/documentation/swiftui/graphicscontext)