@rubixstudios/payload-typesense 1.6.13 → 1.8.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 (186) hide show
  1. package/README.md +109 -114
  2. package/dist/components/ThemeProvider.d.ts +4 -3
  3. package/dist/components/ThemeProvider.d.ts.map +1 -1
  4. package/dist/components/ThemeProvider.js +15 -5
  5. package/dist/components/icons/clockIcon.d.ts +2 -0
  6. package/dist/components/icons/clockIcon.d.ts.map +1 -0
  7. package/dist/components/icons/clockIcon.js +16 -0
  8. package/dist/components/icons/collectionIcon.d.ts +2 -0
  9. package/dist/components/icons/collectionIcon.d.ts.map +1 -0
  10. package/dist/components/icons/collectionIcon.js +16 -0
  11. package/dist/components/icons/errorIcon.d.ts +2 -0
  12. package/dist/components/icons/errorIcon.d.ts.map +1 -0
  13. package/dist/components/icons/errorIcon.js +16 -0
  14. package/dist/components/icons/index.d.ts +7 -0
  15. package/dist/components/icons/index.d.ts.map +1 -0
  16. package/dist/components/icons/index.js +6 -0
  17. package/dist/components/icons/noResultsIcon.d.ts +4 -0
  18. package/dist/components/icons/noResultsIcon.d.ts.map +1 -0
  19. package/dist/components/icons/noResultsIcon.js +19 -0
  20. package/dist/components/icons/searchIcon.d.ts +4 -0
  21. package/dist/components/icons/searchIcon.d.ts.map +1 -0
  22. package/dist/components/icons/searchIcon.js +16 -0
  23. package/dist/components/icons/xIcon.d.ts +2 -0
  24. package/dist/components/icons/xIcon.d.ts.map +1 -0
  25. package/dist/components/icons/xIcon.js +17 -0
  26. package/dist/components/index.d.ts +10 -5
  27. package/dist/components/index.d.ts.map +1 -1
  28. package/dist/components/index.js +6 -3
  29. package/dist/components/render/Content.d.ts +26 -0
  30. package/dist/components/render/Content.d.ts.map +1 -0
  31. package/dist/components/render/Content.js +144 -0
  32. package/dist/components/render/Dialog.d.ts +20 -0
  33. package/dist/components/render/Dialog.d.ts.map +1 -0
  34. package/dist/components/render/Dialog.js +43 -0
  35. package/dist/components/render/Header.d.ts +4 -4
  36. package/dist/components/render/Header.d.ts.map +1 -1
  37. package/dist/components/render/Header.js +20 -39
  38. package/dist/components/render/Highlight.d.ts +3 -0
  39. package/dist/components/render/Highlight.d.ts.map +1 -0
  40. package/dist/components/render/Highlight.js +22 -0
  41. package/dist/components/render/NoResults.d.ts +4 -4
  42. package/dist/components/render/NoResults.d.ts.map +1 -1
  43. package/dist/components/render/NoResults.js +21 -45
  44. package/dist/components/render/ResultError.d.ts +4 -4
  45. package/dist/components/render/ResultError.d.ts.map +1 -1
  46. package/dist/components/render/ResultError.js +14 -38
  47. package/dist/components/render/Results.d.ts +7 -6
  48. package/dist/components/render/Results.d.ts.map +1 -1
  49. package/dist/components/render/Results.js +70 -141
  50. package/dist/components/render/index.d.ts +7 -4
  51. package/dist/components/render/index.d.ts.map +1 -1
  52. package/dist/components/render/index.js +7 -4
  53. package/dist/components/search/HeadlessDialog.d.ts +5 -0
  54. package/dist/components/search/HeadlessDialog.d.ts.map +1 -0
  55. package/dist/components/search/HeadlessDialog.js +254 -0
  56. package/dist/components/search/HeadlessInput.d.ts +5 -0
  57. package/dist/components/search/HeadlessInput.d.ts.map +1 -0
  58. package/dist/components/search/HeadlessInput.js +193 -0
  59. package/dist/components/search/SearchStyles.d.ts +8 -0
  60. package/dist/components/search/SearchStyles.d.ts.map +1 -0
  61. package/dist/components/search/SearchStyles.js +9 -0
  62. package/dist/components/themes/constant.d.ts +3 -0
  63. package/dist/components/themes/constant.d.ts.map +1 -0
  64. package/dist/components/themes/constant.js +75 -0
  65. package/dist/components/themes/hooks.d.ts +4 -42
  66. package/dist/components/themes/hooks.d.ts.map +1 -1
  67. package/dist/components/themes/hooks.js +35 -95
  68. package/dist/components/themes/index.d.ts +1 -0
  69. package/dist/components/themes/index.d.ts.map +1 -1
  70. package/dist/components/themes/index.js +1 -0
  71. package/dist/components/themes/themes.d.ts.map +1 -1
  72. package/dist/components/themes/themes.js +66 -27
  73. package/dist/components/themes/types.d.ts +62 -2
  74. package/dist/components/themes/types.d.ts.map +1 -1
  75. package/dist/components/themes/utils.d.ts +13 -18
  76. package/dist/components/themes/utils.d.ts.map +1 -1
  77. package/dist/components/themes/utils.js +466 -344
  78. package/dist/components/utils/decodeEntities.d.ts +2 -0
  79. package/dist/components/utils/decodeEntities.d.ts.map +1 -0
  80. package/dist/components/utils/decodeEntities.js +23 -0
  81. package/dist/components/utils/index.d.ts +4 -0
  82. package/dist/components/utils/index.d.ts.map +1 -0
  83. package/dist/components/utils/index.js +3 -0
  84. package/dist/components/utils/toKebab.d.ts +2 -0
  85. package/dist/components/utils/toKebab.d.ts.map +1 -0
  86. package/dist/components/utils/toKebab.js +3 -0
  87. package/dist/components/utils/toText.d.ts +2 -0
  88. package/dist/components/utils/toText.d.ts.map +1 -0
  89. package/dist/components/utils/toText.js +3 -0
  90. package/dist/endpoints/handler/createAdvancedSearch.d.ts +1 -1
  91. package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -1
  92. package/dist/endpoints/handler/createAdvancedSearch.js +133 -11
  93. package/dist/endpoints/handler/createCollections.d.ts +1 -1
  94. package/dist/endpoints/handler/createCollections.d.ts.map +1 -1
  95. package/dist/endpoints/handler/createCollections.js +8 -8
  96. package/dist/endpoints/handler/createSearch.d.ts +1 -1
  97. package/dist/endpoints/handler/createSearch.d.ts.map +1 -1
  98. package/dist/endpoints/handler/createSearch.js +85 -110
  99. package/dist/endpoints/handler/createSuggest.d.ts +1 -1
  100. package/dist/endpoints/handler/createSuggest.d.ts.map +1 -1
  101. package/dist/endpoints/handler/createSuggest.js +39 -22
  102. package/dist/endpoints/health.d.ts +2 -2
  103. package/dist/endpoints/health.d.ts.map +1 -1
  104. package/dist/endpoints/health.js +58 -52
  105. package/dist/endpoints/search.d.ts +2 -9
  106. package/dist/endpoints/search.d.ts.map +1 -1
  107. package/dist/endpoints/search.js +17 -16
  108. package/dist/{utils → hooks}/useDebounce.d.ts.map +1 -1
  109. package/dist/{utils → hooks}/useDebounce.js +2 -2
  110. package/dist/hooks/useSearch.d.ts +21 -0
  111. package/dist/hooks/useSearch.d.ts.map +1 -0
  112. package/dist/hooks/useSearch.js +126 -0
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +45 -34
  115. package/dist/lib/cache.d.ts.map +1 -1
  116. package/dist/lib/cache.js +54 -25
  117. package/dist/lib/client.d.ts +1 -1
  118. package/dist/lib/client.d.ts.map +1 -1
  119. package/dist/lib/client.js +35 -31
  120. package/dist/lib/hooks.d.ts +3 -11
  121. package/dist/lib/hooks.d.ts.map +1 -1
  122. package/dist/lib/hooks.js +15 -45
  123. package/dist/lib/initialization.d.ts +1 -1
  124. package/dist/lib/initialization.d.ts.map +1 -1
  125. package/dist/lib/initialization.js +54 -52
  126. package/dist/lib/schema-mapper.d.ts +3 -6
  127. package/dist/lib/schema-mapper.d.ts.map +1 -1
  128. package/dist/lib/schema-mapper.js +90 -84
  129. package/dist/lib/search-dialog.d.ts +169 -0
  130. package/dist/lib/search-dialog.d.ts.map +1 -0
  131. package/dist/lib/search-dialog.js +4 -0
  132. package/dist/lib/search-input.d.ts +93 -0
  133. package/dist/lib/search-input.d.ts.map +1 -0
  134. package/dist/lib/search-pagination.d.ts +38 -0
  135. package/dist/lib/search-pagination.d.ts.map +1 -0
  136. package/dist/lib/search-pagination.js +4 -0
  137. package/dist/lib/search.d.ts +25 -0
  138. package/dist/lib/search.d.ts.map +1 -0
  139. package/dist/lib/search.js +59 -0
  140. package/dist/lib/validation.d.ts +57 -39
  141. package/dist/lib/validation.d.ts.map +1 -1
  142. package/dist/lib/validation.js +92 -66
  143. package/dist/types.d.ts +193 -127
  144. package/dist/types.d.ts.map +1 -1
  145. package/dist/types.js +1 -1
  146. package/dist/utils/buildError.d.ts +1 -1
  147. package/dist/utils/buildError.d.ts.map +1 -1
  148. package/dist/utils/buildError.js +2 -2
  149. package/dist/utils/ensureCollection.d.ts +2 -2
  150. package/dist/utils/ensureCollection.d.ts.map +1 -1
  151. package/dist/utils/ensureCollection.js +138 -22
  152. package/dist/utils/extractText.d.ts.map +1 -1
  153. package/dist/utils/extractText.js +11 -8
  154. package/dist/utils/getCacheStats.d.ts.map +1 -1
  155. package/dist/utils/getCacheStats.js +1 -8
  156. package/dist/utils/getCollectionInfo.d.ts.map +1 -1
  157. package/dist/utils/getCollectionInfo.js +1 -1
  158. package/dist/utils/getCollections.d.ts +11 -0
  159. package/dist/utils/getCollections.d.ts.map +1 -0
  160. package/dist/utils/getCollections.js +152 -0
  161. package/dist/utils/keyboard.d.ts +4 -4
  162. package/dist/utils/keyboard.d.ts.map +1 -1
  163. package/dist/utils/keyboard.js +21 -23
  164. package/dist/utils/sortResults.d.ts +3 -0
  165. package/dist/utils/sortResults.d.ts.map +1 -0
  166. package/dist/utils/sortResults.js +103 -0
  167. package/dist/utils/testConnection.d.ts +1 -1
  168. package/dist/utils/testConnection.d.ts.map +1 -1
  169. package/dist/utils/testConnection.js +2 -2
  170. package/dist/utils/vectorSearch.d.ts +2 -5
  171. package/dist/utils/vectorSearch.d.ts.map +1 -1
  172. package/dist/utils/vectorSearch.js +24 -12
  173. package/package.json +16 -15
  174. package/dist/components/HeadlessSearchInput.d.ts +0 -5
  175. package/dist/components/HeadlessSearchInput.d.ts.map +0 -1
  176. package/dist/components/HeadlessSearchInput.js +0 -204
  177. package/dist/lib/headlessSearch.d.ts +0 -86
  178. package/dist/lib/headlessSearch.d.ts.map +0 -1
  179. package/dist/utils/getAllCollections.d.ts +0 -11
  180. package/dist/utils/getAllCollections.d.ts.map +0 -1
  181. package/dist/utils/getAllCollections.js +0 -103
  182. package/dist/utils/useSearch.d.ts +0 -18
  183. package/dist/utils/useSearch.d.ts.map +0 -1
  184. package/dist/utils/useSearch.js +0 -66
  185. /package/dist/{utils → hooks}/useDebounce.d.ts +0 -0
  186. /package/dist/lib/{headlessSearch.js → search-input.js} +0 -0
@@ -1,382 +1,504 @@
1
+ import { toKebab } from '../utils/index.js';
2
+ import { parts, unitless } from './constant.js';
1
3
  import { defaultTheme, themes } from './themes.js';
2
- export function getTheme(themeName) {
3
- return themes[themeName] || defaultTheme;
4
+ const SYSTEM_THEME_QUERY = '(prefers-color-scheme: dark)';
5
+ export function getSystemTheme() {
6
+ return window.matchMedia(SYSTEM_THEME_QUERY).matches ? 'dark' : 'light';
4
7
  }
5
- export function mergeThemeConfig(config) {
6
- const baseTheme = typeof config.theme === 'string' ? getTheme(config.theme) : config.theme;
8
+ export function getServerTheme() {
9
+ return 'light';
10
+ }
11
+ export function systemTheme(callback) {
12
+ const media = window.matchMedia(SYSTEM_THEME_QUERY);
13
+ media.addEventListener('change', callback);
14
+ return ()=>media.removeEventListener('change', callback);
15
+ }
16
+ export function getTheme(name) {
17
+ return Object.hasOwn(themes, name) ? themes[name] ?? defaultTheme : defaultTheme;
18
+ }
19
+ export function mergeConfig(config) {
20
+ const base = typeof config.theme === 'string' ? getTheme(config.theme) : config.theme;
7
21
  return {
8
- ...baseTheme,
22
+ ...base,
9
23
  animations: {
10
- ...baseTheme.animations,
24
+ ...defaultTheme.animations,
25
+ ...base.animations,
11
26
  ...config.animations
12
27
  },
13
28
  colors: {
14
- ...baseTheme.colors,
29
+ ...defaultTheme.colors,
30
+ ...base.colors,
15
31
  ...config.colors
16
32
  },
17
33
  shadows: {
18
- ...baseTheme.shadows,
34
+ ...defaultTheme.shadows,
35
+ ...base.shadows,
19
36
  ...config.shadows
20
37
  },
21
38
  spacing: {
22
- ...baseTheme.spacing,
39
+ ...defaultTheme.spacing,
40
+ ...base.spacing,
23
41
  ...config.spacing
24
42
  },
25
43
  typography: {
26
- ...baseTheme.typography,
44
+ ...defaultTheme.typography,
45
+ ...base.typography,
27
46
  ...config.typography
28
47
  }
29
48
  };
30
49
  }
50
+ function serialize(styles) {
51
+ return Object.entries(styles).filter(([, value])=>value !== undefined).map(([key, value])=>{
52
+ const needsUnit = typeof value === 'number' && value !== 0 && !unitless.has(key) && !key.startsWith('--');
53
+ return `${toKebab(key)}:${needsUnit ? `${value}px` : value}`;
54
+ }).join(';');
55
+ }
31
56
  export function css(styles) {
32
- const toKebab = (key)=>key.replace(/([A-Z])/g, '-$1').toLowerCase();
33
- const serialize = (obj)=>Object.entries(obj).map(([prop, val])=>`${toKebab(prop)}: ${val}`).join('; ');
34
- return Object.entries(styles).map(([key, value])=>{
35
- if (typeof value === 'object' && value !== null) {
36
- return `${toKebab(key)} { ${serialize(value)} }`;
37
- }
38
- return `${toKebab(key)}: ${value}`;
39
- }).join('; ');
57
+ return Object.entries(styles).map(([key, value])=>typeof value === 'object' ? `${key}{${serialize(value)}}` : serialize({
58
+ [key]: value
59
+ })).filter(Boolean).join(';');
40
60
  }
41
- export function generateThemeClasses(theme, config = {}) {
42
- const enableAnimations = config.enableAnimations !== false;
43
- const enableShadows = config.enableShadows !== false;
44
- const enableRoundedCorners = config.enableRoundedCorners !== false;
45
- const containerStyles = css({
46
- margin: '0 auto',
47
- maxWidth: '600px',
48
- position: 'relative',
49
- width: '100%'
50
- });
51
- const inputContainerStyles = css({
52
- position: 'relative',
53
- width: '100%'
54
- });
55
- const resultsContainerStyles = css({
56
- backgroundColor: theme.colors.resultsBackground,
57
- border: `1px solid ${theme.colors.resultsBorder}`,
58
- borderRadius: enableRoundedCorners ? theme.spacing.resultsBorderRadius : '0',
59
- boxShadow: enableShadows ? theme.shadows.shadowLg : 'none',
60
- left: '0',
61
- marginBottom: '2px',
62
- marginTop: '2px',
63
- maxHeight: theme.spacing.resultsMaxHeight,
64
- overflowY: 'auto',
65
- position: 'absolute',
66
- right: '0',
67
- top: '100%',
68
- zIndex: '1000',
69
- ...enableAnimations && {
70
- animation: 'slideDown 0.2s ease-out'
71
- }
72
- });
73
- const inputStyles = css({
74
- '::placeholder': {
75
- color: theme.colors.inputPlaceholder
76
- },
77
- ':disabled': {
78
- backgroundColor: theme.colors.inputBackground,
79
- cursor: 'not-allowed',
80
- opacity: '0.6'
81
- },
82
- ':focus': {
83
- borderColor: theme.colors.inputBorderFocus,
84
- boxShadow: enableShadows ? `${theme.shadows.focusShadow} ${theme.shadows.focusShadowColor}` : 'none'
85
- },
86
- backgroundColor: theme.colors.inputBackground,
87
- border: `2px solid ${theme.colors.inputBorder}`,
88
- borderRadius: enableRoundedCorners ? theme.spacing.inputBorderRadius : '0',
89
- boxShadow: 'none',
90
- color: theme.colors.inputText,
91
- fontFamily: theme.typography.fontFamily,
92
- fontSize: theme.spacing.inputFontSize,
93
- fontWeight: theme.typography.fontWeightNormal,
94
- lineHeight: theme.typography.lineHeightNormal,
61
+ export function generateClasses(_theme, _config = {}) {
62
+ return Object.fromEntries(parts.map((part)=>[
63
+ part,
64
+ `typesense-search-${part}`
65
+ ]));
66
+ }
67
+ export function generateStyles(theme, config, scope) {
68
+ if (config.unstyled) return '';
69
+ const classes = generateClasses(theme, config);
70
+ const root = `:where([data-search-theme="${scope}"])`;
71
+ const color = theme.colors;
72
+ const spacing = theme.spacing;
73
+ const typography = theme.typography;
74
+ const rounded = config.enableRoundedCorners !== false;
75
+ const animated = config.enableAnimations !== false;
76
+ const shadows = config.enableShadows !== false;
77
+ const transition = animated ? `all ${theme.animations.transitionFast} ${theme.animations.easeInOut}` : 'none';
78
+ const focus = {
95
79
  outline: 'none',
96
- padding: theme.spacing.inputPadding,
97
- transition: enableAnimations ? `all ${theme.animations.transitionNormal} ${theme.animations.easeInOut}` : 'none',
98
- width: '100%'
99
- });
100
- const resultsStyles = css({
101
- backgroundColor: theme.colors.resultsBackground,
102
- border: `1px solid ${theme.colors.resultsBorder}`,
103
- borderRadius: enableRoundedCorners ? theme.spacing.resultsBorderRadius : '0',
104
- boxShadow: enableShadows ? theme.shadows.shadowLg : 'none',
105
- left: '0',
106
- maxHeight: theme.spacing.resultsMaxHeight,
107
- overflowY: 'auto',
108
- position: 'absolute',
109
- right: '0',
110
- top: '100%',
111
- zIndex: '1000'
112
- });
113
- const resultsHeaderStyles = css({
114
- alignItems: 'center',
115
- backgroundColor: theme.colors.headerBackground,
116
- borderBottom: `1px solid ${theme.colors.headerBorder}`,
117
- color: theme.colors.headerText,
118
- display: 'flex',
119
- fontFamily: theme.typography.fontFamily,
120
- fontSize: theme.spacing.headerFontSize,
121
- fontWeight: theme.typography.fontWeightMedium,
122
- justifyContent: 'space-between',
123
- padding: theme.spacing.headerPadding
124
- });
125
- const resultsListStyles = css({
126
- padding: '2px'
127
- });
128
- const resultItemStyles = css({
129
- ':focus': {
130
- backgroundColor: theme.colors.resultBackgroundFocus,
131
- boxShadow: enableShadows ? `inset 0 0 0 2px ${theme.colors.inputBorderFocus}` : 'none'
80
+ borderColor: color.inputBorderFocus,
81
+ boxShadow: shadows ? `${theme.shadows.focusShadow} ${theme.shadows.focusShadowColor}` : 'none',
82
+ ...config.styles?.inputFocus
83
+ };
84
+ const button = {
85
+ backgroundColor: color.triggerBackground ?? color.inputBackground,
86
+ color: color.triggerText ?? color.inputText,
87
+ border: `1px solid ${color.triggerBorder ?? color.inputBorder}`,
88
+ borderRadius: rounded ? spacing.triggerBorderRadius : '0',
89
+ cursor: 'pointer',
90
+ fontSize: typography.fontSizeSm,
91
+ padding: spacing.triggerPadding,
92
+ transition
93
+ };
94
+ const styles = {
95
+ container: {
96
+ margin: spacing.containerMargin,
97
+ maxWidth: spacing.containerMaxWidth,
98
+ position: 'relative',
99
+ width: '100%'
132
100
  },
133
- ':hover': {
134
- backgroundColor: theme.colors.resultBackgroundHover,
135
- transform: enableAnimations ? 'translateX(2px)' : 'none'
101
+ inputContainer: {
102
+ position: 'relative',
103
+ width: '100%'
136
104
  },
137
- ':last-child': {
138
- borderBottom: 'none'
105
+ input: {
106
+ backgroundColor: color.inputBackground,
107
+ border: `${spacing.inputBorderWidth} solid ${color.inputBorder}`,
108
+ borderRadius: rounded ? spacing.inputBorderRadius : '0',
109
+ color: color.inputText,
110
+ boxSizing: 'border-box',
111
+ fontSize: spacing.inputFontSize,
112
+ fontWeight: typography.fontWeightNormal,
113
+ lineHeight: typography.lineHeightNormal,
114
+ padding: spacing.inputPadding,
115
+ width: '100%',
116
+ outline: 'none',
117
+ transition,
118
+ ':focus': focus,
119
+ '::placeholder': {
120
+ color: color.inputPlaceholder
121
+ },
122
+ ':disabled': {
123
+ opacity: 0.6,
124
+ cursor: 'not-allowed'
125
+ }
139
126
  },
140
- backgroundColor: theme.colors.resultBackground,
141
- borderBottom: `1px solid ${theme.colors.resultBorder}`,
142
- cursor: 'pointer',
143
- outline: 'none',
144
- padding: theme.spacing.itemPadding,
145
- transition: enableAnimations ? `all ${theme.animations.transitionFast} ${theme.animations.easeInOut}` : 'none'
146
- });
147
- const resultTitleStyles = css({
148
- color: theme.colors.titleText,
149
- fontFamily: theme.typography.fontFamily,
150
- fontSize: theme.typography.fontSizeLg,
151
- fontWeight: theme.typography.fontWeightSemibold,
152
- lineHeight: theme.typography.lineHeightTight,
153
- marginBottom: '8px'
154
- });
155
- const resultDescriptionStyles = css({
156
- color: theme.colors.descriptionText,
157
- fontFamily: theme.typography.fontFamily,
158
- fontSize: theme.typography.fontSizeSm,
159
- lineHeight: theme.typography.lineHeightNormal,
160
- marginBottom: '8px'
161
- });
162
- const resultHighlightStyles = css({
163
- backgroundColor: theme.colors.highlightBackground,
164
- borderRadius: enableRoundedCorners ? '6px' : '0',
165
- color: theme.colors.descriptionText,
166
- fontFamily: theme.typography.fontFamily,
167
- fontSize: theme.typography.fontSizeSm,
168
- lineHeight: theme.typography.lineHeightNormal,
169
- marginBottom: '8px',
170
- mark: {
171
- backgroundColor: theme.colors.highlightBackground,
172
- borderRadius: enableRoundedCorners ? '3px' : '0',
173
- color: theme.colors.highlightText,
174
- fontWeight: theme.typography.fontWeightMedium,
175
- padding: '2px 4px'
176
- },
177
- padding: '8px 12px'
178
- });
179
- const resultMetaStyles = css({
180
- alignItems: 'center',
181
- color: theme.colors.metaText,
182
- display: 'flex',
183
- fontFamily: theme.typography.fontFamily,
184
- fontSize: theme.typography.fontSizeXs,
185
- justifyContent: 'space-between',
186
- marginTop: '8px'
187
- });
188
- const collectionBadgeStyles = css({
189
- backgroundColor: theme.colors.collectionBadge,
190
- borderRadius: enableRoundedCorners ? '12px' : '0',
191
- color: theme.colors.collectionBadgeText,
192
- display: 'inline-block',
193
- fontFamily: theme.typography.fontFamily,
194
- fontSize: theme.typography.fontSizeXs,
195
- fontWeight: theme.typography.fontWeightSemibold,
196
- letterSpacing: '0.5px',
197
- padding: '4px 8px',
198
- textTransform: 'uppercase'
199
- });
200
- const scoreBadgeStyles = css({
201
- backgroundColor: theme.colors.scoreBadge,
202
- borderRadius: enableRoundedCorners ? '4px' : '0',
203
- color: theme.colors.scoreBadgeText,
204
- display: 'inline-block',
205
- fontFamily: theme.typography.fontFamily,
206
- fontSize: theme.typography.fontSizeXs,
207
- fontWeight: theme.typography.fontWeightMedium,
208
- padding: '2px 6px'
209
- });
210
- const loadingStyles = css({
211
- alignItems: 'center',
212
- color: theme.colors.loadingText,
213
- display: 'flex',
214
- fontFamily: theme.typography.fontFamily,
215
- fontSize: theme.typography.fontSizeSm,
216
- gap: '12px',
217
- justifyContent: 'center',
218
- padding: '24px'
219
- });
220
- const loadingSpinnerStyles = css({
221
- animation: enableAnimations ? `spin 1s linear infinite` : 'none',
222
- border: `2px solid ${theme.colors.inputBorder}`,
223
- borderRadius: '50%',
224
- borderTop: `2px solid ${theme.colors.inputBorderFocus}`,
225
- height: '20px',
226
- width: '20px'
227
- });
228
- const errorStyles = css({
229
- alignItems: 'center',
230
- backgroundColor: theme.colors.errorBackground,
231
- borderBottom: `1px solid ${theme.colors.resultBorder}`,
232
- color: theme.colors.errorText,
233
- display: 'flex',
234
- fontFamily: theme.typography.fontFamily,
235
- fontSize: theme.typography.fontSizeSm,
236
- gap: '8px',
237
- padding: '16px'
238
- });
239
- const noResultsStyles = css({
240
- color: theme.colors.noResultsText,
241
- fontFamily: theme.typography.fontFamily,
242
- fontSize: theme.typography.fontSizeSm,
243
- padding: '40px 20px',
244
- textAlign: 'center'
245
- });
246
- const facetContainerStyles = css({
247
- backgroundColor: theme.colors.headerBackground,
248
- borderBottom: `1px solid ${theme.colors.headerBorder}`,
249
- padding: '16px'
250
- });
251
- const facetItemStyles = css({
252
- ':hover': {
253
- backgroundColor: theme.colors.facetActiveBackground,
254
- borderColor: theme.colors.facetActiveBackground,
255
- color: theme.colors.facetActiveText
256
- },
257
- backgroundColor: theme.colors.facetBackground,
258
- border: `1px solid ${theme.colors.facetBorder}`,
259
- borderRadius: enableRoundedCorners ? '16px' : '0',
260
- color: theme.colors.facetText,
261
- cursor: 'pointer',
262
- display: 'inline-block',
263
- fontFamily: theme.typography.fontFamily,
264
- fontSize: theme.typography.fontSizeXs,
265
- fontWeight: theme.typography.fontWeightMedium,
266
- margin: '4px',
267
- padding: '6px 12px',
268
- transition: enableAnimations ? `all ${theme.animations.transitionFast} ${theme.animations.easeInOut}` : 'none'
269
- });
270
- const facetItemActiveStyles = css({
271
- backgroundColor: theme.colors.facetActiveBackground,
272
- borderColor: theme.colors.facetActiveBackground,
273
- color: theme.colors.facetActiveText
274
- });
275
- const hiddenStyles = css({
276
- display: 'none'
277
- });
278
- const visibleStyles = css({
279
- display: 'block'
280
- });
281
- const focusableStyles = css({
282
- ':focus': {
283
- boxShadow: enableShadows ? `0 0 0 2px ${theme.colors.inputBorderFocus}` : 'none'
127
+ inputFocus: focus,
128
+ inputDisabled: {
129
+ opacity: 0.6,
130
+ cursor: 'not-allowed'
284
131
  },
285
- outline: 'none'
286
- });
287
- return {
288
- // Container classes
289
- container: containerStyles,
290
- inputContainer: inputContainerStyles,
291
- resultsContainer: resultsContainerStyles,
292
- // Input classes
293
- input: inputStyles,
294
- inputDisabled: '',
295
- inputFocus: '',
296
- // Results classes
297
- results: resultsStyles,
298
- resultsHeader: resultsHeaderStyles,
299
- resultsList: resultsListStyles,
300
- // Item classes
301
- resultItem: resultItemStyles,
302
- resultItemActive: '',
303
- resultItemFocus: '',
304
- resultItemHover: '',
305
- // Content classes
306
- resultDescription: resultDescriptionStyles,
307
- resultHighlight: resultHighlightStyles,
308
- resultMeta: resultMetaStyles,
309
- resultTitle: resultTitleStyles,
310
- // Badge classes
311
- collectionBadge: collectionBadgeStyles,
312
- scoreBadge: scoreBadgeStyles,
313
- // State classes
314
- error: errorStyles,
315
- loading: loadingStyles,
316
- loadingSpinner: loadingSpinnerStyles,
317
- noResults: noResultsStyles,
318
- // Facet classes
319
- facetContainer: facetContainerStyles,
320
- facetItem: facetItemStyles,
321
- facetItemActive: facetItemActiveStyles,
322
- // Utility classes
323
- focusable: focusableStyles,
324
- hidden: hiddenStyles,
325
- visible: visibleStyles
132
+ resultsContainer: {
133
+ backgroundColor: color.resultsBackground,
134
+ border: `${spacing.resultsBorderWidth} solid ${color.resultsBorder}`,
135
+ borderRadius: rounded ? spacing.resultsBorderRadius : '0',
136
+ boxShadow: shadows ? config.colors?.resultsShadow ?? theme.shadows.shadowLg : 'none',
137
+ boxSizing: 'border-box',
138
+ display: 'flex',
139
+ marginTop: spacing.resultsOffset,
140
+ maxHeight: spacing.resultsMaxHeight,
141
+ overflow: 'hidden',
142
+ padding: spacing.resultsPadding,
143
+ position: 'absolute',
144
+ left: 0,
145
+ right: 0,
146
+ top: '100%',
147
+ zIndex: spacing.resultsZIndex,
148
+ animation: animated ? `typesenseSearchSlideDown ${theme.animations.animationNormal} ${theme.animations.easeOut}` : 'none'
149
+ },
150
+ results: {
151
+ flex: 1,
152
+ minHeight: 0,
153
+ minWidth: 0,
154
+ overflowY: 'auto',
155
+ position: 'relative',
156
+ width: '100%'
157
+ },
158
+ resultsHeader: {
159
+ alignItems: 'center',
160
+ backgroundColor: color.headerBackground,
161
+ borderBottom: `1px solid ${color.headerBorder}`,
162
+ color: color.headerText,
163
+ display: 'flex',
164
+ fontSize: spacing.headerFontSize,
165
+ fontWeight: typography.fontWeightMedium,
166
+ gap: spacing.headerGap,
167
+ padding: spacing.headerPadding
168
+ },
169
+ resultsList: {
170
+ padding: spacing.resultsListPadding
171
+ },
172
+ resultItem: {
173
+ backgroundColor: color.resultBackground,
174
+ borderBottom: `1px solid ${color.resultBorder}`,
175
+ borderRadius: rounded ? spacing.itemBorderRadius : '0',
176
+ color: color.titleText,
177
+ cursor: 'pointer',
178
+ margin: spacing.itemMargin,
179
+ padding: spacing.itemPadding,
180
+ outline: 'none',
181
+ transition,
182
+ ':hover': {
183
+ backgroundColor: color.resultBackgroundHover,
184
+ ...config.styles?.resultItemHover
185
+ },
186
+ ':focus': {
187
+ backgroundColor: color.resultBackgroundFocus,
188
+ ...config.styles?.resultItemFocus
189
+ },
190
+ ':focus-visible': focus,
191
+ ':last-child': {
192
+ borderBottom: 'none'
193
+ }
194
+ },
195
+ resultItemHover: {
196
+ backgroundColor: color.resultBackgroundHover
197
+ },
198
+ resultItemFocus: {
199
+ backgroundColor: color.resultBackgroundFocus
200
+ },
201
+ resultItemActive: {
202
+ backgroundColor: color.resultBackgroundFocus
203
+ },
204
+ resultLayout: {
205
+ display: 'flex',
206
+ alignItems: 'flex-start',
207
+ gap: spacing.resultGap,
208
+ overflow: 'hidden'
209
+ },
210
+ resultIcon: {
211
+ display: 'flex',
212
+ alignItems: 'center',
213
+ justifyContent: 'center',
214
+ flexShrink: 0,
215
+ width: spacing.resultIconSize,
216
+ height: spacing.resultIconSize,
217
+ borderRadius: rounded ? spacing.inputBorderRadius : '0',
218
+ backgroundColor: color.collectionBadge,
219
+ color: color.collectionBadgeText,
220
+ fontSize: typography.fontSizeBase,
221
+ fontWeight: typography.fontWeightMedium
222
+ },
223
+ resultBody: {
224
+ flex: 1,
225
+ minWidth: 0
226
+ },
227
+ resultTitle: {
228
+ color: color.titleText,
229
+ fontSize: typography.fontSizeBase,
230
+ fontWeight: typography.fontWeightSemibold,
231
+ lineHeight: typography.lineHeightTight,
232
+ margin: spacing.resultTitleMargin,
233
+ overflow: 'hidden',
234
+ textOverflow: 'ellipsis',
235
+ whiteSpace: 'nowrap'
236
+ },
237
+ resultDescription: {
238
+ color: color.descriptionText,
239
+ display: '-webkit-box',
240
+ fontSize: typography.fontSizeSm,
241
+ fontWeight: typography.fontWeightNormal,
242
+ lineHeight: typography.lineHeightNormal,
243
+ margin: spacing.resultDescriptionMargin,
244
+ overflow: 'hidden',
245
+ WebkitBoxOrient: 'vertical',
246
+ WebkitLineClamp: spacing.descriptionLineClamp,
247
+ mark: {
248
+ backgroundColor: color.highlightBackground,
249
+ color: color.highlightText
250
+ }
251
+ },
252
+ resultHighlight: {
253
+ backgroundColor: color.highlightBackground,
254
+ color: color.highlightText
255
+ },
256
+ resultMeta: {
257
+ alignItems: 'center',
258
+ display: 'flex',
259
+ color: color.metaText,
260
+ fontSize: spacing.metaFontSize,
261
+ gap: spacing.resultGap,
262
+ padding: spacing.metaPadding
263
+ },
264
+ resultMetaItem: {
265
+ display: 'inline-flex',
266
+ alignItems: 'center',
267
+ gap: spacing.headerGap
268
+ },
269
+ collectionBadge: {
270
+ display: 'inline-block',
271
+ backgroundColor: color.collectionBadge,
272
+ color: color.collectionBadgeText,
273
+ padding: spacing.itemPadding,
274
+ borderRadius: rounded ? spacing.itemBorderRadius : '0'
275
+ },
276
+ scoreBadge: {
277
+ display: 'inline-block',
278
+ backgroundColor: color.scoreBadge,
279
+ color: color.scoreBadgeText,
280
+ fontSize: typography.fontSizeXs
281
+ },
282
+ loading: {
283
+ display: 'flex',
284
+ alignItems: 'center',
285
+ justifyContent: 'center',
286
+ gap: spacing.loadingGap,
287
+ padding: spacing.loadingPadding,
288
+ color: color.loadingText,
289
+ fontSize: typography.fontSizeSm
290
+ },
291
+ loadingIndicator: {
292
+ position: 'absolute',
293
+ right: spacing.resultGap,
294
+ top: '50%',
295
+ transform: 'translateY(-50%)',
296
+ pointerEvents: 'none'
297
+ },
298
+ loadingSpinner: {
299
+ width: spacing.loadingSpinnerSize,
300
+ height: spacing.loadingSpinnerSize,
301
+ border: `2px solid ${color.inputBorder}`,
302
+ borderTopColor: color.inputBorderFocus,
303
+ borderRadius: '50%',
304
+ animation: animated ? 'typesenseSearchSpin 1s linear infinite' : 'none'
305
+ },
306
+ error: {
307
+ alignItems: 'center',
308
+ display: 'flex',
309
+ backgroundColor: color.errorBackground,
310
+ color: color.errorText,
311
+ fontSize: typography.fontSizeSm,
312
+ padding: spacing.errorPadding,
313
+ gap: spacing.errorGap
314
+ },
315
+ noResults: {
316
+ color: color.noResultsText,
317
+ fontSize: typography.fontSizeSm,
318
+ padding: spacing.noResultsPadding,
319
+ textAlign: 'center'
320
+ },
321
+ noResultsTitle: {
322
+ color: color.titleText,
323
+ fontSize: typography.fontSizeSm,
324
+ fontWeight: typography.fontWeightMedium,
325
+ margin: 0
326
+ },
327
+ noResultsDescription: {
328
+ color: color.descriptionText,
329
+ fontSize: typography.fontSizeSm,
330
+ margin: 0
331
+ },
332
+ facetContainer: {
333
+ backgroundColor: color.headerBackground,
334
+ borderBottom: `1px solid ${color.headerBorder}`,
335
+ padding: spacing.headerPadding
336
+ },
337
+ facetItem: {
338
+ ...button,
339
+ backgroundColor: color.facetBackground,
340
+ color: color.facetText,
341
+ borderColor: color.facetBorder,
342
+ ':hover': {
343
+ backgroundColor: color.facetActiveBackground,
344
+ color: color.facetActiveText
345
+ }
346
+ },
347
+ facetItemActive: {
348
+ backgroundColor: color.facetActiveBackground,
349
+ color: color.facetActiveText
350
+ },
351
+ focusable: {
352
+ ':focus-visible': focus
353
+ },
354
+ hidden: {
355
+ display: 'none'
356
+ },
357
+ visible: {
358
+ display: 'block'
359
+ },
360
+ trigger: {
361
+ ...button,
362
+ ':focus-visible': focus,
363
+ ':disabled': {
364
+ opacity: 0.6,
365
+ cursor: 'not-allowed'
366
+ }
367
+ },
368
+ dialog: {
369
+ position: 'fixed',
370
+ inset: 0,
371
+ margin: 'auto',
372
+ height: 'fit-content',
373
+ minHeight: 0,
374
+ backgroundColor: color.dialogBackground ?? color.resultsBackground,
375
+ color: color.inputText,
376
+ border: `${spacing.resultsBorderWidth} solid ${color.resultsBorder}`,
377
+ borderRadius: rounded ? spacing.dialogBorderRadius : '0',
378
+ boxShadow: shadows ? theme.shadows.shadowXl : 'none',
379
+ boxSizing: 'border-box',
380
+ width: spacing.dialogWidth,
381
+ maxWidth: 'calc(100vw - 2rem)',
382
+ maxHeight: spacing.dialogMaxHeight,
383
+ padding: spacing.dialogPadding,
384
+ overflowY: 'auto',
385
+ '::backdrop': {
386
+ backgroundColor: color.dialogBackdrop ?? 'rgba(0,0,0,0.45)',
387
+ ...config.styles?.dialogBackdrop
388
+ }
389
+ },
390
+ dialogBackdrop: {
391
+ backgroundColor: color.dialogBackdrop
392
+ },
393
+ dialogHeader: {
394
+ display: 'flex',
395
+ alignItems: 'center',
396
+ justifyContent: 'space-between',
397
+ gap: spacing.dialogGap,
398
+ padding: spacing.dialogHeaderPadding
399
+ },
400
+ dialogTitle: {
401
+ color: color.titleText,
402
+ fontSize: typography.fontSizeLg,
403
+ fontWeight: typography.fontWeightSemibold,
404
+ margin: 0
405
+ },
406
+ dialogContent: {
407
+ display: 'flex',
408
+ flexDirection: 'column',
409
+ minHeight: 0
410
+ },
411
+ dialogResults: {
412
+ maxHeight: spacing.resultsMaxHeight,
413
+ overflowY: 'auto',
414
+ marginTop: '4px',
415
+ minHeight: 0
416
+ },
417
+ pagination: {
418
+ display: 'flex',
419
+ flexWrap: 'wrap',
420
+ alignItems: 'center',
421
+ justifyContent: 'space-between',
422
+ padding: spacing.paginationPadding,
423
+ gap: spacing.paginationGap,
424
+ borderTop: `1px solid ${color.headerBorder}`
425
+ },
426
+ paginationButton: {
427
+ ...button,
428
+ backgroundColor: color.paginationBackground ?? color.inputBackground,
429
+ color: color.paginationText ?? color.inputText,
430
+ borderColor: color.paginationBorder ?? color.inputBorder,
431
+ padding: spacing.paginationButtonPadding,
432
+ borderRadius: rounded ? spacing.paginationBorderRadius : '0',
433
+ ':focus-visible': focus,
434
+ ':disabled': {
435
+ opacity: 0.5,
436
+ cursor: 'not-allowed'
437
+ }
438
+ },
439
+ paginationStatus: {
440
+ color: color.metaText,
441
+ fontSize: typography.fontSizeSm
442
+ }
326
443
  };
444
+ const rules = parts.map((part)=>{
445
+ const selector = `${root} .${classes[part]},${root}.${classes[part]}`;
446
+ const style = {
447
+ ...styles[part],
448
+ ...config.styles?.[part]
449
+ };
450
+ const plain = {};
451
+ const nested = [];
452
+ for (const [key, value] of Object.entries(style)){
453
+ if (typeof value === 'object' && value !== null) {
454
+ const suffix = key.startsWith(':') ? key : ` ${key}`;
455
+ nested.push(`${selector.split(',').map((s)=>`${s}${suffix}`).join(',')}{${serialize(value)}}`);
456
+ } else {
457
+ plain[key] = value;
458
+ }
459
+ }
460
+ return `${selector}{${serialize(plain)}}${nested.join('')}`;
461
+ }).join('\n');
462
+ const keyframes = `
463
+ @keyframes typesenseSearchSpin{to{transform:rotate(360deg)}}
464
+ @keyframes typesenseSearchSlideDown{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}`;
465
+ const reducedMotion = `
466
+ @media(prefers-reduced-motion:reduce){${root} *,${root}{animation:none!important;transition:none!important}}`;
467
+ return `${rules}\n${keyframes}\n${reducedMotion}`;
327
468
  }
328
- /**
329
- * Apply theme to a CSS class with optional variant
330
- */ export function applyTheme(theme, element, variant) {
331
- const classes = generateThemeClasses(theme);
332
- if (variant) {
333
- const variantKey = `${element}${variant.charAt(0).toUpperCase() + variant.slice(1)}`;
334
- return `${classes[element] || ''} ${classes[variantKey] || ''}`;
335
- }
336
- return classes[element] || '';
469
+ export function applyTheme(theme, element, variant, config = {}) {
470
+ const classes = generateClasses(theme, config);
471
+ const base = classes[element] ?? '';
472
+ const key = variant ? `${element}${variant.charAt(0).toUpperCase()}${variant.slice(1)}` : undefined;
473
+ return [
474
+ base,
475
+ key ? classes[key] : ''
476
+ ].filter(Boolean).join(' ');
337
477
  }
338
- /**
339
- * Check if theme is dark mode
340
- */ export function isDarkTheme(theme) {
478
+ export function isDarkTheme(theme) {
341
479
  return theme.name === 'dark' || theme.colors.inputBackground.includes('#1f') || theme.colors.inputBackground.includes('#0f');
342
480
  }
343
- /**
344
- * Check if theme is light mode
345
- */ export function isLightTheme(theme) {
481
+ export function isLightTheme(theme) {
346
482
  return !isDarkTheme(theme);
347
483
  }
348
- /**
349
- * Get theme-specific CSS variables
350
- */ export function getThemeVariables(theme) {
351
- return {
352
- '--search-collection-badge': theme.colors.collectionBadge,
353
- '--search-collection-badge-text': theme.colors.collectionBadgeText,
354
- '--search-description-text': theme.colors.descriptionText,
355
- '--search-error-bg': theme.colors.errorBackground,
356
- '--search-error-text': theme.colors.errorText,
357
- '--search-facet-active-bg': theme.colors.facetActiveBackground,
358
- '--search-facet-active-text': theme.colors.facetActiveText,
359
- '--search-facet-bg': theme.colors.facetBackground,
360
- '--search-facet-border': theme.colors.facetBorder,
361
- '--search-facet-text': theme.colors.facetText,
362
- '--search-header-bg': theme.colors.headerBackground,
363
- '--search-header-text': theme.colors.headerText,
364
- '--search-highlight-bg': theme.colors.highlightBackground,
365
- '--search-highlight-text': theme.colors.highlightText,
484
+ export function getThemeVariables(theme) {
485
+ const variables = {};
486
+ for (const [key, value] of Object.entries(theme.colors)){
487
+ if (value !== undefined) variables[`--search-${toKebab(key)}`] = value;
488
+ }
489
+ for (const [key, value] of Object.entries(theme.spacing)){
490
+ if (value !== undefined) variables[`--search-${toKebab(key)}`] = String(value);
491
+ }
492
+ Object.assign(variables, {
366
493
  '--search-input-bg': theme.colors.inputBackground,
367
- '--search-input-border': theme.colors.inputBorder,
368
- '--search-input-border-focus': theme.colors.inputBorderFocus,
369
- '--search-input-placeholder': theme.colors.inputPlaceholder,
370
- '--search-input-text': theme.colors.inputText,
371
- '--search-loading-text': theme.colors.loadingText,
372
- '--search-meta-text': theme.colors.metaText,
373
- '--search-no-results-text': theme.colors.noResultsText,
494
+ '--search-results-bg': theme.colors.resultsBackground,
495
+ '--search-header-bg': theme.colors.headerBackground,
374
496
  '--search-result-bg': theme.colors.resultBackground,
375
497
  '--search-result-bg-hover': theme.colors.resultBackgroundHover,
376
- '--search-results-bg': theme.colors.resultsBackground,
377
- '--search-results-border': theme.colors.resultsBorder,
378
- '--search-score-badge': theme.colors.scoreBadge,
379
- '--search-score-badge-text': theme.colors.scoreBadgeText,
380
- '--search-title-text': theme.colors.titleText
381
- };
498
+ '--search-error-bg': theme.colors.errorBackground,
499
+ '--search-highlight-bg': theme.colors.highlightBackground,
500
+ '--search-facet-bg': theme.colors.facetBackground,
501
+ '--search-facet-active-bg': theme.colors.facetActiveBackground
502
+ });
503
+ return variables;
382
504
  }