werewolf-ui 0.1.0-beta.2 → 0.1.0-beta.3

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 (88) hide show
  1. package/README.md +9 -5
  2. package/data/manifest.json +3779 -484
  3. package/data/native/android/WerewolfAlert.kt +1 -1
  4. package/data/native/android/WerewolfAlertDialog.kt +156 -0
  5. package/data/native/android/WerewolfAvatar.kt +393 -0
  6. package/data/native/android/WerewolfBackdropBlur.kt +89 -0
  7. package/data/native/android/WerewolfBadge.kt +1 -1
  8. package/data/native/android/WerewolfBottomNav.kt +333 -0
  9. package/data/native/android/WerewolfButton.kt +1 -1
  10. package/data/native/android/WerewolfButtonGroup.kt +54 -0
  11. package/data/native/android/WerewolfCard.kt +1 -1
  12. package/data/native/android/WerewolfCheckbox.kt +387 -0
  13. package/data/native/android/WerewolfCounter.kt +640 -0
  14. package/data/native/android/WerewolfDialog.kt +131 -0
  15. package/data/native/android/WerewolfEmptyState.kt +1 -1
  16. package/data/native/android/WerewolfField.kt +66 -0
  17. package/data/native/android/WerewolfIcons.kt +39 -1
  18. package/data/native/android/WerewolfInput.kt +1 -1
  19. package/data/native/android/WerewolfKbd.kt +1 -1
  20. package/data/native/android/WerewolfLabel.kt +2 -2
  21. package/data/native/android/WerewolfLayers.kt +385 -0
  22. package/data/native/android/WerewolfLink.kt +163 -0
  23. package/data/native/android/WerewolfList.kt +504 -0
  24. package/data/native/android/WerewolfListRuntime.kt +384 -0
  25. package/data/native/android/WerewolfMetadata.kt +180 -0
  26. package/data/native/android/WerewolfMeter.kt +189 -0
  27. package/data/native/android/WerewolfModifiers.kt +58 -4
  28. package/data/native/android/WerewolfProgress.kt +281 -0
  29. package/data/native/android/WerewolfRadioGroup.kt +382 -0
  30. package/data/native/android/WerewolfSelect.kt +330 -0
  31. package/data/native/android/WerewolfSeparator.kt +1 -1
  32. package/data/native/android/WerewolfSheet.kt +204 -0
  33. package/data/native/android/WerewolfSkeleton.kt +1 -1
  34. package/data/native/android/WerewolfSpinner.kt +1 -1
  35. package/data/native/android/WerewolfSwitch.kt +9 -57
  36. package/data/native/android/WerewolfTabs.kt +591 -0
  37. package/data/native/android/WerewolfTextarea.kt +329 -0
  38. package/data/native/android/WerewolfTheme.kt +3 -2
  39. package/data/native/android/WerewolfToast.kt +226 -0
  40. package/data/native/android/WerewolfToaster.kt +282 -0
  41. package/data/native/android/WerewolfToggle.kt +395 -0
  42. package/data/native/android/WerewolfToggleGroup.kt +427 -0
  43. package/data/native/android/WerewolfToken.kt +1 -1
  44. package/data/native/ios/WerewolfAlert.swift +1 -1
  45. package/data/native/ios/WerewolfAlertDialog.swift +185 -0
  46. package/data/native/ios/WerewolfAvatar.swift +552 -0
  47. package/data/native/ios/WerewolfBadge.swift +1 -1
  48. package/data/native/ios/WerewolfBottomNav.swift +422 -0
  49. package/data/native/ios/WerewolfButton.swift +1 -1
  50. package/data/native/ios/WerewolfButtonGroup.swift +62 -0
  51. package/data/native/ios/WerewolfCard.swift +1 -1
  52. package/data/native/ios/WerewolfCheckbox.swift +621 -0
  53. package/data/native/ios/WerewolfCounter.swift +768 -0
  54. package/data/native/ios/WerewolfDialog.swift +170 -0
  55. package/data/native/ios/WerewolfEmptyState.swift +1 -1
  56. package/data/native/ios/WerewolfField.swift +103 -0
  57. package/data/native/ios/WerewolfIcons.swift +13 -1
  58. package/data/native/ios/WerewolfInput.swift +1 -1
  59. package/data/native/ios/WerewolfKbd.swift +1 -1
  60. package/data/native/ios/WerewolfLabel.swift +2 -2
  61. package/data/native/ios/WerewolfLayers.swift +376 -0
  62. package/data/native/ios/WerewolfLink.swift +188 -0
  63. package/data/native/ios/WerewolfList.swift +603 -0
  64. package/data/native/ios/WerewolfListRuntime.swift +414 -0
  65. package/data/native/ios/WerewolfMetadata.swift +205 -0
  66. package/data/native/ios/WerewolfMeter.swift +186 -0
  67. package/data/native/ios/WerewolfModifiers.swift +106 -1
  68. package/data/native/ios/WerewolfProgress.swift +338 -0
  69. package/data/native/ios/WerewolfRadioGroup.swift +483 -0
  70. package/data/native/ios/WerewolfSelect.swift +418 -0
  71. package/data/native/ios/WerewolfSeparator.swift +1 -1
  72. package/data/native/ios/WerewolfSheet.swift +208 -0
  73. package/data/native/ios/WerewolfSkeleton.swift +1 -1
  74. package/data/native/ios/WerewolfSpinner.swift +1 -1
  75. package/data/native/ios/WerewolfSwitch.swift +18 -77
  76. package/data/native/ios/WerewolfTabs.swift +756 -0
  77. package/data/native/ios/WerewolfTextarea.swift +403 -0
  78. package/data/native/ios/WerewolfTheme.swift +1 -1
  79. package/data/native/ios/WerewolfToast.swift +278 -0
  80. package/data/native/ios/WerewolfToaster.swift +269 -0
  81. package/data/native/ios/WerewolfToggle.swift +647 -0
  82. package/data/native/ios/WerewolfToggleGroup.swift +511 -0
  83. package/data/native/ios/WerewolfToken.swift +1 -1
  84. package/dist/cli.mjs +2212 -352
  85. package/dist/core.mjs +2121 -308
  86. package/dist/lint.mjs +142 -18
  87. package/dist/project.mjs +2 -0
  88. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- // Generated file, must not be edited by hand. Source: components/alert.spec.json (werewolf-ui 0.1.0-beta.2).
1
+ // Generated file, must not be edited by hand. Source: components/alert.spec.json (werewolf-ui 0.1.0-beta.3).
2
2
  package dev.werewolfui
3
3
 
4
4
  import androidx.compose.foundation.background
@@ -0,0 +1,156 @@
1
+ // Generated file, must not be edited by hand. Source: components/alert-dialog.spec.json (werewolf-ui 0.1.0-beta.3).
2
+ package dev.werewolfui
3
+
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.border
6
+ import androidx.compose.foundation.focusGroup
7
+ import androidx.compose.foundation.layout.Arrangement
8
+ import androidx.compose.foundation.layout.Box
9
+ import androidx.compose.foundation.layout.Column
10
+ import androidx.compose.foundation.layout.fillMaxWidth
11
+ import androidx.compose.foundation.layout.padding
12
+ import androidx.compose.foundation.shape.RoundedCornerShape
13
+ import androidx.compose.foundation.text.BasicText
14
+ import androidx.compose.runtime.Composable
15
+ import androidx.compose.runtime.CompositionLocalProvider
16
+ import androidx.compose.runtime.LaunchedEffect
17
+ import androidx.compose.runtime.remember
18
+ import androidx.compose.runtime.withFrameNanos
19
+ import androidx.compose.ui.Alignment
20
+ import androidx.compose.ui.Modifier
21
+ import androidx.compose.ui.focus.FocusRequester
22
+ import androidx.compose.ui.focus.focusRequester
23
+ import androidx.compose.ui.graphics.Color
24
+ import androidx.compose.ui.semantics.clearAndSetSemantics
25
+ import androidx.compose.ui.text.TextStyle
26
+ import androidx.compose.ui.unit.Dp
27
+ import androidx.compose.ui.unit.TextUnit
28
+ import dev.werewolfui.runtime.LocalWerewolf
29
+ import dev.werewolfui.runtime.LocalWerewolfContentColor
30
+ import dev.werewolfui.runtime.LocalWerewolfFonts
31
+ import dev.werewolfui.runtime.WerewolfFontRole
32
+ import dev.werewolfui.runtime.WerewolfLayer
33
+ import dev.werewolfui.runtime.WerewolfPresent
34
+ import dev.werewolfui.runtime.werewolfFontWeight
35
+ import dev.werewolfui.runtime.werewolfShadow
36
+ import dev.werewolfui.tokens.WerewolfShadowLayer
37
+
38
+ enum class WerewolfAlertDialogSize {
39
+ Md,
40
+ }
41
+
42
+ @Composable
43
+ fun WerewolfAlertDialog(
44
+ open: Boolean,
45
+ onOpenChange: (Boolean) -> Unit,
46
+ title: String,
47
+ description: String,
48
+ modifier: Modifier = Modifier,
49
+ size: WerewolfAlertDialogSize = WerewolfAlertDialogSize.Md,
50
+ cancel: @Composable () -> Unit,
51
+ media: (@Composable () -> Unit)? = null,
52
+ action: @Composable () -> Unit,
53
+ ) {
54
+ WerewolfPresent(
55
+ open = open,
56
+ layer = WerewolfLayer.Dialog,
57
+ title = title,
58
+ onDismissRequest = { onOpenChange(false) },
59
+ dismissOnScrim = false,
60
+ ) {
61
+ val t = LocalWerewolf.current
62
+ val initialFocus = remember { FocusRequester() }
63
+ LaunchedEffect(Unit) {
64
+ withFrameNanos { }
65
+ initialFocus.requestFocus()
66
+ }
67
+ // werewolf:property=content.background-color
68
+ val contentBackgroundColor = t.colorBackgroundRaised
69
+ // werewolf:property=content.border-color
70
+ val contentBorderColor = t.colorBorder
71
+ // werewolf:property=content.border-radius
72
+ val contentBorderRadius = t.radiusPage
73
+ // werewolf:property=content.border-width
74
+ val contentBorderWidth = t.borderWidth
75
+ // werewolf:property=content.box-shadow
76
+ val contentBoxShadow = t.shadowHigh
77
+ // werewolf:property=content.color
78
+ val contentColor = t.colorTextPrimary
79
+ // werewolf:property=content.font-family
80
+ val contentFontFamily = t.fontFamilySans
81
+ // werewolf:property=content.gap
82
+ val contentGap = t.spacingLg
83
+ // werewolf:property=content.padding
84
+ val contentPadding = t.spacingXl
85
+ // werewolf:property=header.gap
86
+ val headerGap = t.spacingSm
87
+ // werewolf:property=title.color
88
+ val titleColor = t.colorTextPrimary
89
+ // werewolf:property=title.font-size
90
+ val titleFontSize = t.fontSizeMd
91
+ // werewolf:property=title.font-weight
92
+ val titleFontWeight = t.fontWeightMedium
93
+ // werewolf:property=description.color
94
+ val descriptionColor = t.colorTextSecondary
95
+ // werewolf:property=description.font-size
96
+ val descriptionFontSize = t.fontSizeSm
97
+ // werewolf:property=footer.gap
98
+ val footerGap = t.spacingSm
99
+ val contentShape = RoundedCornerShape(contentBorderRadius)
100
+ CompositionLocalProvider(LocalWerewolfContentColor provides contentColor) {
101
+ Column(
102
+ modifier = modifier
103
+ .fillMaxWidth()
104
+ .fillMaxWidth()
105
+ .background(contentBackgroundColor, contentShape)
106
+ .border(contentBorderWidth, contentBorderColor, contentShape)
107
+ .padding(contentPadding)
108
+ .werewolfShadow(contentBoxShadow),
109
+ verticalArrangement = Arrangement.spacedBy(contentGap, Alignment.CenterVertically),
110
+ horizontalAlignment = Alignment.CenterHorizontally,
111
+ ) {
112
+ if (media != null) {
113
+ Box(
114
+ modifier = Modifier
115
+ .clearAndSetSemantics {},
116
+ ) {
117
+ media?.invoke()
118
+ }
119
+ }
120
+ Column(
121
+ verticalArrangement = Arrangement.spacedBy(headerGap, Alignment.CenterVertically),
122
+ horizontalAlignment = Alignment.Start,
123
+ ) {
124
+ BasicText(
125
+ text = title,
126
+ style = TextStyle(
127
+ color = titleColor,
128
+ fontSize = titleFontSize,
129
+ fontWeight = werewolfFontWeight(titleFontWeight),
130
+ ),
131
+ )
132
+ BasicText(
133
+ text = description,
134
+ style = TextStyle(
135
+ color = descriptionColor,
136
+ fontSize = descriptionFontSize,
137
+ ),
138
+ )
139
+ }
140
+ Column(
141
+ verticalArrangement = Arrangement.spacedBy(footerGap, Alignment.CenterVertically),
142
+ horizontalAlignment = Alignment.CenterHorizontally,
143
+ ) {
144
+ action()
145
+ Box(
146
+ modifier = Modifier
147
+ .focusRequester(initialFocus)
148
+ .focusGroup(),
149
+ ) {
150
+ cancel()
151
+ }
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
@@ -0,0 +1,393 @@
1
+ // Generated file, must not be edited by hand. Source: components/avatar.spec.json (werewolf-ui 0.1.0-beta.3).
2
+ package dev.werewolfui
3
+
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.height
7
+ import androidx.compose.foundation.layout.width
8
+ import androidx.compose.foundation.shape.RoundedCornerShape
9
+ import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.CompositionLocalProvider
11
+ import androidx.compose.ui.Alignment
12
+ import androidx.compose.ui.Modifier
13
+ import androidx.compose.ui.draw.clip
14
+ import androidx.compose.ui.graphics.Color
15
+ import androidx.compose.ui.semantics.Role
16
+ import androidx.compose.ui.semantics.contentDescription
17
+ import androidx.compose.ui.semantics.hideFromAccessibility
18
+ import androidx.compose.ui.semantics.role
19
+ import androidx.compose.ui.semantics.semantics
20
+ import androidx.compose.ui.unit.Dp
21
+ import androidx.compose.ui.unit.TextUnit
22
+ import dev.werewolfui.runtime.LocalWerewolf
23
+ import dev.werewolfui.runtime.LocalWerewolfContentColor
24
+ import dev.werewolfui.runtime.LocalWerewolfFonts
25
+ import dev.werewolfui.runtime.LocalWerewolfTextStyle
26
+ import dev.werewolfui.runtime.WerewolfFontRole
27
+ import dev.werewolfui.tokens.WerewolfEasing
28
+
29
+ enum class WerewolfAvatarColor {
30
+ Gray,
31
+ Red,
32
+ Orange,
33
+ Yellow,
34
+ Green,
35
+ Teal,
36
+ Blue,
37
+ Purple,
38
+ Pink,
39
+ }
40
+
41
+ enum class WerewolfAvatarShape {
42
+ Circle,
43
+ Square,
44
+ }
45
+
46
+ enum class WerewolfAvatarSize {
47
+ Xs,
48
+ Sm,
49
+ Md,
50
+ Lg,
51
+ Xl,
52
+ }
53
+
54
+ enum class WerewolfAvatarVariant {
55
+ Soft,
56
+ Solid,
57
+ }
58
+
59
+ @Composable
60
+ fun WerewolfAvatar(
61
+ alt: String,
62
+ modifier: Modifier = Modifier,
63
+ color: WerewolfAvatarColor = WerewolfAvatarColor.Gray,
64
+ shape: WerewolfAvatarShape = WerewolfAvatarShape.Circle,
65
+ size: WerewolfAvatarSize = WerewolfAvatarSize.Md,
66
+ variant: WerewolfAvatarVariant = WerewolfAvatarVariant.Soft,
67
+ icon: (@Composable () -> Unit)? = null,
68
+ image: (@Composable () -> Unit)? = null,
69
+ fallback: @Composable () -> Unit,
70
+ ) {
71
+ val t = LocalWerewolf.current
72
+ // werewolf:property=root.background-color
73
+ val rootBackgroundColor: Color = when (color) {
74
+ // werewolf:color=gray
75
+ WerewolfAvatarColor.Gray -> when (variant) {
76
+ // werewolf:variant=soft
77
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundGray
78
+ // werewolf:variant=solid
79
+ WerewolfAvatarVariant.Solid -> t.colorGray
80
+ }
81
+ // werewolf:color=red
82
+ WerewolfAvatarColor.Red -> when (variant) {
83
+ // werewolf:variant=soft
84
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundRed
85
+ // werewolf:variant=solid
86
+ WerewolfAvatarVariant.Solid -> t.colorRed
87
+ }
88
+ // werewolf:color=orange
89
+ WerewolfAvatarColor.Orange -> when (variant) {
90
+ // werewolf:variant=soft
91
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundOrange
92
+ // werewolf:variant=solid
93
+ WerewolfAvatarVariant.Solid -> t.colorOrange
94
+ }
95
+ // werewolf:color=yellow
96
+ WerewolfAvatarColor.Yellow -> when (variant) {
97
+ // werewolf:variant=soft
98
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundYellow
99
+ // werewolf:variant=solid
100
+ WerewolfAvatarVariant.Solid -> t.colorYellow
101
+ }
102
+ // werewolf:color=green
103
+ WerewolfAvatarColor.Green -> when (variant) {
104
+ // werewolf:variant=soft
105
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundGreen
106
+ // werewolf:variant=solid
107
+ WerewolfAvatarVariant.Solid -> t.colorGreen
108
+ }
109
+ // werewolf:color=teal
110
+ WerewolfAvatarColor.Teal -> when (variant) {
111
+ // werewolf:variant=soft
112
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundTeal
113
+ // werewolf:variant=solid
114
+ WerewolfAvatarVariant.Solid -> t.colorTeal
115
+ }
116
+ // werewolf:color=blue
117
+ WerewolfAvatarColor.Blue -> when (variant) {
118
+ // werewolf:variant=soft
119
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundBlue
120
+ // werewolf:variant=solid
121
+ WerewolfAvatarVariant.Solid -> t.colorBlue
122
+ }
123
+ // werewolf:color=purple
124
+ WerewolfAvatarColor.Purple -> when (variant) {
125
+ // werewolf:variant=soft
126
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundPurple
127
+ // werewolf:variant=solid
128
+ WerewolfAvatarVariant.Solid -> t.colorPurple
129
+ }
130
+ // werewolf:color=pink
131
+ WerewolfAvatarColor.Pink -> when (variant) {
132
+ // werewolf:variant=soft
133
+ WerewolfAvatarVariant.Soft -> t.colorBackgroundPink
134
+ // werewolf:variant=solid
135
+ WerewolfAvatarVariant.Solid -> t.colorPink
136
+ }
137
+ }
138
+ // werewolf:property=root.border-radius
139
+ val rootBorderRadius: Dp = when (shape) {
140
+ // werewolf:shape=circle
141
+ WerewolfAvatarShape.Circle -> t.radiusFull
142
+ // werewolf:shape=square
143
+ WerewolfAvatarShape.Square -> t.radiusElement
144
+ }
145
+ // werewolf:property=root.color
146
+ val rootColor: Color = when (color) {
147
+ // werewolf:color=gray
148
+ WerewolfAvatarColor.Gray -> when (variant) {
149
+ // werewolf:variant=soft
150
+ WerewolfAvatarVariant.Soft -> t.colorTextGray
151
+ // werewolf:variant=solid
152
+ WerewolfAvatarVariant.Solid -> t.colorTextOnGray
153
+ }
154
+ // werewolf:color=red
155
+ WerewolfAvatarColor.Red -> when (variant) {
156
+ // werewolf:variant=soft
157
+ WerewolfAvatarVariant.Soft -> t.colorTextRed
158
+ // werewolf:variant=solid
159
+ WerewolfAvatarVariant.Solid -> t.colorTextOnRed
160
+ }
161
+ // werewolf:color=orange
162
+ WerewolfAvatarColor.Orange -> when (variant) {
163
+ // werewolf:variant=soft
164
+ WerewolfAvatarVariant.Soft -> t.colorTextOrange
165
+ // werewolf:variant=solid
166
+ WerewolfAvatarVariant.Solid -> t.colorTextOnOrange
167
+ }
168
+ // werewolf:color=yellow
169
+ WerewolfAvatarColor.Yellow -> when (variant) {
170
+ // werewolf:variant=soft
171
+ WerewolfAvatarVariant.Soft -> t.colorTextYellow
172
+ // werewolf:variant=solid
173
+ WerewolfAvatarVariant.Solid -> t.colorTextOnYellow
174
+ }
175
+ // werewolf:color=green
176
+ WerewolfAvatarColor.Green -> when (variant) {
177
+ // werewolf:variant=soft
178
+ WerewolfAvatarVariant.Soft -> t.colorTextGreen
179
+ // werewolf:variant=solid
180
+ WerewolfAvatarVariant.Solid -> t.colorTextOnGreen
181
+ }
182
+ // werewolf:color=teal
183
+ WerewolfAvatarColor.Teal -> when (variant) {
184
+ // werewolf:variant=soft
185
+ WerewolfAvatarVariant.Soft -> t.colorTextTeal
186
+ // werewolf:variant=solid
187
+ WerewolfAvatarVariant.Solid -> t.colorTextOnTeal
188
+ }
189
+ // werewolf:color=blue
190
+ WerewolfAvatarColor.Blue -> when (variant) {
191
+ // werewolf:variant=soft
192
+ WerewolfAvatarVariant.Soft -> t.colorTextBlue
193
+ // werewolf:variant=solid
194
+ WerewolfAvatarVariant.Solid -> t.colorTextOnBlue
195
+ }
196
+ // werewolf:color=purple
197
+ WerewolfAvatarColor.Purple -> when (variant) {
198
+ // werewolf:variant=soft
199
+ WerewolfAvatarVariant.Soft -> t.colorTextPurple
200
+ // werewolf:variant=solid
201
+ WerewolfAvatarVariant.Solid -> t.colorTextOnPurple
202
+ }
203
+ // werewolf:color=pink
204
+ WerewolfAvatarColor.Pink -> when (variant) {
205
+ // werewolf:variant=soft
206
+ WerewolfAvatarVariant.Soft -> t.colorTextPink
207
+ // werewolf:variant=solid
208
+ WerewolfAvatarVariant.Solid -> t.colorTextOnPink
209
+ }
210
+ }
211
+ // werewolf:property=root.font-family
212
+ val rootFontFamily = t.fontFamilySans
213
+ // werewolf:property=root.font-size
214
+ val rootFontSize: TextUnit = when (size) {
215
+ // werewolf:size=xs
216
+ WerewolfAvatarSize.Xs -> t.fontSizeXs
217
+ // werewolf:size=sm
218
+ WerewolfAvatarSize.Sm -> t.fontSizeXs
219
+ // werewolf:size=md
220
+ WerewolfAvatarSize.Md -> t.fontSizeSm
221
+ // werewolf:size=lg
222
+ WerewolfAvatarSize.Lg -> t.fontSizeMd
223
+ // werewolf:size=xl
224
+ WerewolfAvatarSize.Xl -> t.fontSizeLg
225
+ }
226
+ // werewolf:property=root.font-weight
227
+ val rootFontWeight = t.fontWeightMedium
228
+ // werewolf:property=root.height
229
+ val rootHeight: Dp = when (size) {
230
+ // werewolf:size=xs
231
+ WerewolfAvatarSize.Xs -> t.spacingLg + t.spacingXs
232
+ // werewolf:size=sm
233
+ WerewolfAvatarSize.Sm -> t.spacingXl
234
+ // werewolf:size=md
235
+ WerewolfAvatarSize.Md -> t.spacing2xl
236
+ // werewolf:size=lg
237
+ WerewolfAvatarSize.Lg -> t.spacing2xl + t.spacingSm
238
+ // werewolf:size=xl
239
+ WerewolfAvatarSize.Xl -> t.spacing3xl
240
+ }
241
+ // werewolf:property=root.width
242
+ val rootWidth: Dp = when (size) {
243
+ // werewolf:size=xs
244
+ WerewolfAvatarSize.Xs -> t.spacingLg + t.spacingXs
245
+ // werewolf:size=sm
246
+ WerewolfAvatarSize.Sm -> t.spacingXl
247
+ // werewolf:size=md
248
+ WerewolfAvatarSize.Md -> t.spacing2xl
249
+ // werewolf:size=lg
250
+ WerewolfAvatarSize.Lg -> t.spacing2xl + t.spacingSm
251
+ // werewolf:size=xl
252
+ WerewolfAvatarSize.Xl -> t.spacing3xl
253
+ }
254
+ // werewolf:property=icon.color
255
+ val iconColor: Color? = when (color) {
256
+ // werewolf:color=gray
257
+ WerewolfAvatarColor.Gray -> when (variant) {
258
+ // werewolf:variant=soft
259
+ WerewolfAvatarVariant.Soft -> t.colorTextGray
260
+ // werewolf:variant=solid
261
+ WerewolfAvatarVariant.Solid -> null
262
+ }
263
+ // werewolf:color=red
264
+ WerewolfAvatarColor.Red -> when (variant) {
265
+ // werewolf:variant=soft
266
+ WerewolfAvatarVariant.Soft -> t.colorTextRed
267
+ // werewolf:variant=solid
268
+ WerewolfAvatarVariant.Solid -> null
269
+ }
270
+ // werewolf:color=orange
271
+ WerewolfAvatarColor.Orange -> when (variant) {
272
+ // werewolf:variant=soft
273
+ WerewolfAvatarVariant.Soft -> t.colorTextOrange
274
+ // werewolf:variant=solid
275
+ WerewolfAvatarVariant.Solid -> null
276
+ }
277
+ // werewolf:color=yellow
278
+ WerewolfAvatarColor.Yellow -> when (variant) {
279
+ // werewolf:variant=soft
280
+ WerewolfAvatarVariant.Soft -> t.colorTextYellow
281
+ // werewolf:variant=solid
282
+ WerewolfAvatarVariant.Solid -> null
283
+ }
284
+ // werewolf:color=green
285
+ WerewolfAvatarColor.Green -> when (variant) {
286
+ // werewolf:variant=soft
287
+ WerewolfAvatarVariant.Soft -> t.colorTextGreen
288
+ // werewolf:variant=solid
289
+ WerewolfAvatarVariant.Solid -> null
290
+ }
291
+ // werewolf:color=teal
292
+ WerewolfAvatarColor.Teal -> when (variant) {
293
+ // werewolf:variant=soft
294
+ WerewolfAvatarVariant.Soft -> t.colorTextTeal
295
+ // werewolf:variant=solid
296
+ WerewolfAvatarVariant.Solid -> null
297
+ }
298
+ // werewolf:color=blue
299
+ WerewolfAvatarColor.Blue -> when (variant) {
300
+ // werewolf:variant=soft
301
+ WerewolfAvatarVariant.Soft -> t.colorTextBlue
302
+ // werewolf:variant=solid
303
+ WerewolfAvatarVariant.Solid -> null
304
+ }
305
+ // werewolf:color=purple
306
+ WerewolfAvatarColor.Purple -> when (variant) {
307
+ // werewolf:variant=soft
308
+ WerewolfAvatarVariant.Soft -> t.colorTextPurple
309
+ // werewolf:variant=solid
310
+ WerewolfAvatarVariant.Solid -> null
311
+ }
312
+ // werewolf:color=pink
313
+ WerewolfAvatarColor.Pink -> when (variant) {
314
+ // werewolf:variant=soft
315
+ WerewolfAvatarVariant.Soft -> t.colorTextPink
316
+ // werewolf:variant=solid
317
+ WerewolfAvatarVariant.Solid -> null
318
+ }
319
+ }
320
+ // werewolf:property=icon.height
321
+ val iconHeight: Dp = when (size) {
322
+ // werewolf:size=xs
323
+ WerewolfAvatarSize.Xs -> t.sizeIconSm
324
+ // werewolf:size=sm
325
+ WerewolfAvatarSize.Sm -> t.sizeIconSm
326
+ // werewolf:size=md
327
+ WerewolfAvatarSize.Md -> t.sizeIconMd
328
+ // werewolf:size=lg
329
+ WerewolfAvatarSize.Lg -> t.sizeIconLg
330
+ // werewolf:size=xl
331
+ WerewolfAvatarSize.Xl -> t.sizeIconLg
332
+ }
333
+ // werewolf:property=icon.width
334
+ val iconWidth: Dp = when (size) {
335
+ // werewolf:size=xs
336
+ WerewolfAvatarSize.Xs -> t.sizeIconSm
337
+ // werewolf:size=sm
338
+ WerewolfAvatarSize.Sm -> t.sizeIconSm
339
+ // werewolf:size=md
340
+ WerewolfAvatarSize.Md -> t.sizeIconMd
341
+ // werewolf:size=lg
342
+ WerewolfAvatarSize.Lg -> t.sizeIconLg
343
+ // werewolf:size=xl
344
+ WerewolfAvatarSize.Xl -> t.sizeIconLg
345
+ }
346
+ // werewolf:property=image.transition-duration
347
+ val imageTransitionDuration = t.durationMediumMs
348
+ // werewolf:property=image.transition-timing-function
349
+ val imageTransitionTimingFunction = t.easeStandard
350
+ val rootShape = RoundedCornerShape(rootBorderRadius)
351
+ val rootTextStyle = LocalWerewolfFonts.current.textStyle(
352
+ when (rootFontFamily) {
353
+ t.fontFamilySans -> WerewolfFontRole.Sans
354
+ else -> WerewolfFontRole.Mono
355
+ },
356
+ rootFontSize,
357
+ rootFontWeight,
358
+ TextUnit.Unspecified,
359
+ )
360
+ CompositionLocalProvider(
361
+ LocalWerewolfContentColor provides rootColor,
362
+ LocalWerewolfTextStyle provides rootTextStyle,
363
+ ) {
364
+ Box(
365
+ modifier = modifier
366
+ .semantics {
367
+ role = Role.Image
368
+ if (alt.isEmpty()) hideFromAccessibility() else contentDescription = alt
369
+ }
370
+ .width(rootWidth)
371
+ .height(rootHeight)
372
+ .background(rootBackgroundColor, rootShape)
373
+ .clip(rootShape),
374
+ contentAlignment = Alignment.Center,
375
+ ) {
376
+ fallback()
377
+ if (icon != null) {
378
+ Box(
379
+ modifier = Modifier
380
+ .width(iconWidth)
381
+ .height(iconHeight),
382
+ ) {
383
+ CompositionLocalProvider(LocalWerewolfContentColor provides (iconColor ?: Color.Transparent)) {
384
+ icon()
385
+ }
386
+ }
387
+ }
388
+ if (image != null) {
389
+ image?.invoke()
390
+ }
391
+ }
392
+ }
393
+ }
@@ -0,0 +1,89 @@
1
+ // Werewolf native runtime. Hand-written, independent of the seed.
2
+ package dev.werewolfui.runtime
3
+
4
+ import android.os.Build
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.runtime.Composable
8
+ import androidx.compose.runtime.getValue
9
+ import androidx.compose.runtime.mutableStateOf
10
+ import androidx.compose.runtime.remember
11
+ import androidx.compose.runtime.setValue
12
+ import androidx.compose.runtime.staticCompositionLocalOf
13
+ import androidx.compose.ui.Modifier
14
+ import androidx.compose.ui.draw.clip
15
+ import androidx.compose.ui.draw.drawWithContent
16
+ import androidx.compose.ui.geometry.Offset
17
+ import androidx.compose.ui.graphics.BlurEffect
18
+ import androidx.compose.ui.graphics.ColorFilter
19
+ import androidx.compose.ui.graphics.ColorMatrix
20
+ import androidx.compose.ui.graphics.Shape
21
+ import androidx.compose.ui.graphics.TileMode
22
+ import androidx.compose.ui.graphics.drawscope.translate
23
+ import androidx.compose.ui.graphics.layer.GraphicsLayer
24
+ import androidx.compose.ui.graphics.layer.drawLayer
25
+ import androidx.compose.ui.graphics.rememberGraphicsLayer
26
+ import androidx.compose.ui.layout.onGloballyPositioned
27
+ import androidx.compose.ui.layout.positionInRoot
28
+ import androidx.compose.ui.unit.IntSize
29
+
30
+ internal object WerewolfSpike {
31
+ var backdropBlur: Boolean = false
32
+ }
33
+
34
+ internal enum class WerewolfMaterialLevel {
35
+ Thin,
36
+ }
37
+
38
+ internal class WerewolfBackdrop(val layer: GraphicsLayer) {
39
+ var origin by mutableStateOf(Offset.Zero)
40
+ }
41
+
42
+ internal val LocalWerewolfBackdrop = staticCompositionLocalOf<WerewolfBackdrop?> { null }
43
+
44
+ @Composable
45
+ internal fun WerewolfBackdropSource(content: @Composable () -> Unit) {
46
+ if (!WerewolfSpike.backdropBlur || Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
47
+ content()
48
+ return
49
+ }
50
+ val backdrop = WerewolfBackdrop(rememberGraphicsLayer())
51
+ androidx.compose.runtime.CompositionLocalProvider(LocalWerewolfBackdrop provides backdrop) {
52
+ androidx.compose.foundation.layout.Box(
53
+ Modifier
54
+ .onGloballyPositioned { backdrop.origin = it.positionInRoot() }
55
+ .drawWithContent {
56
+ backdrop.layer.record { this@drawWithContent.drawContent() }
57
+ drawLayer(backdrop.layer)
58
+ },
59
+ ) {
60
+ content()
61
+ }
62
+ }
63
+ }
64
+
65
+ @Composable
66
+ internal fun Modifier.werewolfBackdropBlur(level: WerewolfMaterialLevel = WerewolfMaterialLevel.Thin, shape: Shape): Modifier {
67
+ val theme = LocalWerewolf.current
68
+ val backdrop = LocalWerewolfBackdrop.current
69
+ val active = WerewolfSpike.backdropBlur && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && backdrop != null
70
+ if (!active || backdrop == null) return this.clip(shape).background(theme.colorBackgroundSurface, shape)
71
+ val effect = rememberGraphicsLayer()
72
+ var position by remember { mutableStateOf(Offset.Zero) }
73
+ val radius = with(androidx.compose.ui.platform.LocalDensity.current) { theme.blurMaterialThin.toPx() }
74
+ return this
75
+ .onGloballyPositioned { position = it.positionInRoot() }
76
+ .clip(shape)
77
+ .drawWithContent {
78
+ val local = position - backdrop.origin
79
+ effect.renderEffect = BlurEffect(radius, radius, TileMode.Clamp)
80
+ effect.colorFilter = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(theme.saturateMaterialThin) })
81
+ effect.record(this, layoutDirection, IntSize(size.width.toInt(), size.height.toInt())) {
82
+ translate(-local.x, -local.y) { drawLayer(backdrop.layer) }
83
+ }
84
+ drawLayer(effect)
85
+ drawContent()
86
+ }
87
+ .background(theme.colorBackgroundMaterialThin, shape)
88
+ .border(theme.borderWidth, theme.colorBorderMaterialEdge, shape)
89
+ }
@@ -1,4 +1,4 @@
1
- // Generated file, must not be edited by hand. Source: components/badge.spec.json (werewolf-ui 0.1.0-beta.2).
1
+ // Generated file, must not be edited by hand. Source: components/badge.spec.json (werewolf-ui 0.1.0-beta.3).
2
2
  package dev.werewolfui
3
3
 
4
4
  import androidx.compose.foundation.background