@molecule/app-reputation-badge-svelte 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,267 @@
1
- # Temporary Holding Version
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-21T12:47:10.444Z
7
+ -->
2
8
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
9
+ # @molecule/app-reputation-badge-svelte
10
+
11
+ Svelte reputation/karma surfaces — `<ReputationBadge>` and `<BadgeShelf>` —
12
+ for forum, discussion-board, and social flagships.
13
+
14
+ `<ReputationBadge score={n} />` renders a compact-formatted score ("1.5k")
15
+ plus a tier chip; the tier derives from `score` via `levelForScore` and
16
+ `DEFAULT_THRESHOLDS` (contributor 100, trusted 500, veteran 2000,
17
+ legend 10000) unless you pass `level` or `thresholds`. `variant` is
18
+ `'compact'` (default) or `'full'` (stacked with a "Reputation" caption).
19
+ `<BadgeShelf badges limit onClick />` renders earned-badge icons with a
20
+ trailing `+N` overflow chip (`onClick(null)` signals "expand all").
21
+
22
+ This is the Svelte counterpart of `@molecule/app-reputation-badge-react`:
23
+ same exports, same props (React names), same DOM for the same input.
24
+
25
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
26
+ > It is written to be read by coding agents as much as by people, and is generated from this
27
+ > package's source — edit `src/index.ts` JSDoc, not this file.
28
+
29
+ ## Quick Start
30
+
31
+ ```svelte
32
+ <script lang="ts">
33
+ import { BadgeShelf, ReputationBadge } from '@molecule/app-reputation-badge-svelte'
34
+ import type { Badge } from '@molecule/app-reputation-badge-svelte'
35
+
36
+ let {
37
+ score,
38
+ badges,
39
+ onBadgeClick,
40
+ }: {
41
+ score: number
42
+ badges: Badge[]
43
+ onBadgeClick: (badge: Badge | null) => void
44
+ } = $props()
45
+ </script>
46
+
47
+ <div>
48
+ <ReputationBadge {score} variant="full" />
49
+ <BadgeShelf {badges} limit={5} onClick={onBadgeClick} />
50
+ </div>
51
+ ```
52
+
53
+ ## Type
54
+
55
+ `feature`
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ npm install @molecule/app-reputation-badge-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
61
+ ```
62
+
63
+ ## API
64
+
65
+ ### Interfaces
66
+
67
+ #### `ReputationThresholds`
68
+
69
+ Optional thresholds for deriving a `ReputationLevel` from a numeric score.
70
+
71
+ If a `level` prop isn't passed to `<ReputationBadge>`, the component will
72
+ pick the highest level whose threshold the `score` meets or exceeds.
73
+
74
+ Default thresholds:
75
+
76
+ - `contributor` >= 100
77
+ - `trusted` >= 500
78
+ - `veteran` >= 2000
79
+ - `legend` >= 10000
80
+ - below 100 → `newcomer`
81
+
82
+ ```typescript
83
+ interface ReputationThresholds {
84
+ /** Score >= contributor threshold ⇒ `'contributor'`. */
85
+ contributor: number
86
+ /** Score >= trusted threshold ⇒ `'trusted'`. */
87
+ trusted: number
88
+ /** Score >= veteran threshold ⇒ `'veteran'`. */
89
+ veteran: number
90
+ /** Score >= legend threshold ⇒ `'legend'`. */
91
+ legend: number
92
+ }
93
+ ```
94
+
95
+ #### `Badge`
96
+
97
+ A single earned badge — one icon on the `<BadgeShelf>` row.
98
+
99
+ ```typescript
100
+ interface Badge {
101
+ /** Stable identifier (used as the row key + click payload). */
102
+ id: string
103
+ /** Display name (translated upstream — passed verbatim). */
104
+ name: string
105
+ /** Optional longer description, shown in the native tooltip. */
106
+ description?: string
107
+ /** Icon glyph or short emoji (rendered inline). Mutually exclusive with `iconSrc`. */
108
+ icon?: string
109
+ /** Image URL for the badge icon. */
110
+ iconSrc?: string
111
+ /** ISO date string the badge was earned (passed back via `onClick`). */
112
+ earnedAt?: string
113
+ }
114
+ ```
115
+
116
+ #### `ReputationBadgeProps`
117
+
118
+ Props accepted by the `ReputationBadge` component — the same props
119
+ React's `@molecule/app-reputation-badge-react` accepts.
120
+
121
+ ```typescript
122
+ interface ReputationBadgeProps {
123
+ /** Numeric reputation / karma score. */
124
+ score: number
125
+ /**
126
+ * Explicit reputation level. If omitted, derived from `score` via
127
+ * `levelForScore` using `thresholds` (or `DEFAULT_THRESHOLDS`).
128
+ */
129
+ level?: ReputationLevel
130
+ /** Override the default score → level thresholds. */
131
+ thresholds?: ReputationThresholds
132
+ /**
133
+ * Layout variant.
134
+ * - `'compact'` (default) — score number inline with a small level chip.
135
+ * - `'full'` — stacked layout with a "Reputation" caption above the row.
136
+ */
137
+ variant?: 'compact' | 'full'
138
+ /** Extra classes merged onto the outer wrapper. */
139
+ className?: string
140
+ }
141
+ ```
142
+
143
+ #### `BadgeShelfProps`
144
+
145
+ Props accepted by the `BadgeShelf` component — the same props React's
146
+ `@molecule/app-reputation-badge-react` accepts.
147
+
148
+ ```typescript
149
+ interface BadgeShelfProps {
150
+ /** Earned badges to display, ordered most-prominent-first. */
151
+ badges: Badge[]
152
+ /**
153
+ * Maximum number of badge icons rendered inline. Any remaining are
154
+ * summarised in a trailing `+N` overflow chip.
155
+ *
156
+ * @default 5
157
+ */
158
+ limit?: number
159
+ /**
160
+ * Click handler — invoked with the clicked badge (or `null` when the
161
+ * trailing overflow chip is clicked, signalling "expand all").
162
+ */
163
+ onClick?: (badge: Badge | null) => void
164
+ /** Extra classes merged onto the outer row. */
165
+ className?: string
166
+ }
167
+ ```
168
+
169
+ ### Types
170
+
171
+ #### `ReputationLevel`
172
+
173
+ Reputation level identifiers — used to pick a tier color/label.
174
+
175
+ Apps that need finer granularity can pass a `level` string of any value;
176
+ unknown values fall back to `'newcomer'` styling.
177
+
178
+ ```typescript
179
+ type ReputationLevel = 'newcomer' | 'contributor' | 'trusted' | 'veteran' | 'legend'
180
+ ```
181
+
182
+ ### Functions
183
+
184
+ #### `levelForScore(score, thresholds)`
185
+
186
+ Derive a {@link ReputationLevel} from a numeric score.
187
+
188
+ Picks the highest level whose threshold is met or exceeded. Any score
189
+ below `thresholds.contributor` returns `'newcomer'`.
190
+
191
+ ```typescript
192
+ function levelForScore(score: number, thresholds?: ReputationThresholds): ReputationLevel
193
+ ```
194
+
195
+ - `score` — Reputation score (any non-negative number).
196
+ - `thresholds` — Optional override thresholds; defaults to {@link DEFAULT_THRESHOLDS}.
197
+
198
+ **Returns:** The derived reputation level.
199
+
200
+ #### `colorForLevel(level)`
201
+
202
+ Return the semantic Badge color for a given level.
203
+
204
+ Unknown levels fall back to `'secondary'`.
205
+
206
+ ```typescript
207
+ function colorForLevel(
208
+ level: ReputationLevel,
209
+ ): 'primary' | 'secondary' | 'success' | 'warning' | 'info'
210
+ ```
211
+
212
+ - `level` — The reputation level.
213
+
214
+ **Returns:** A badge color name from `@molecule/app-ui-vue`.
215
+
216
+ ### Constants
217
+
218
+ #### `BadgeShelf`
219
+
220
+ ```typescript
221
+ const BadgeShelf: LegacyComponentType
222
+ ```
223
+
224
+ #### `ReputationBadge`
225
+
226
+ ```typescript
227
+ const ReputationBadge: LegacyComponentType
228
+ ```
229
+
230
+ #### `DEFAULT_THRESHOLDS`
231
+
232
+ Default thresholds used when no `thresholds` prop is supplied.
233
+
234
+ ```typescript
235
+ const DEFAULT_THRESHOLDS: ReputationThresholds
236
+ ```
237
+
238
+ ## Injection Notes
239
+
240
+ ### Requirements
241
+
242
+ Peer dependencies:
243
+
244
+ - `@molecule/app-svelte` ^3.5.0
245
+ - `@molecule/app-ui` ^1.0.1
246
+ - `@molecule/app-ui-svelte` ^1.1.0
247
+ - `svelte` ^5.0.0
248
+
249
+ ### Runtime Dependencies
250
+
251
+ - `@molecule/app-svelte`
252
+ - `@molecule/app-ui`
253
+ - `@molecule/app-ui-svelte`
254
+ - `svelte`
255
+
256
+ - Both components throw unless mounted under `setMoleculeContext({ i18n })`
257
+ (`useTranslation()` needs it) with a ClassMap bonded via `setClassMap()`.
258
+ - This package exports a `Badge` TYPE (earned-badge data shape) — distinct
259
+ from the `Badge` COMPONENT in `@molecule/app-ui-svelte`; alias one when
260
+ importing both in a file.
261
+ - Server-side score/badge issuance pairs with `@molecule/api-reputation`.
262
+ - Translations live in the companion `@molecule/app-locales-reputation-badge`
263
+ bond (registered).
264
+
265
+ ## Translations
266
+
267
+ Translation strings are provided by `@molecule/app-locales-reputation-badge`.
@@ -0,0 +1,120 @@
1
+ <!--
2
+ BadgeShelf: the Svelte counterpart of
3
+ `@molecule/app-reputation-badge-react`'s `BadgeShelf` — a row of earned-badge
4
+ icons with a trailing `+N` overflow chip. Same props, same ClassMap tokens,
5
+ same i18n keys, same DOM for the same input: no badges renders nothing at
6
+ all, and `onClick` turns each icon (and the overflow chip, with `null`) into a
7
+ button.
8
+ -->
9
+ <script lang="ts">
10
+ import { useTranslation } from '@molecule/app-svelte'
11
+ import { getClassMap } from '@molecule/app-ui'
12
+
13
+ import type { Badge, BadgeShelfProps } from './types.js'
14
+
15
+ let { badges, limit = 5, onClick, className }: BadgeShelfProps = $props()
16
+
17
+ const cm = $derived(getClassMap())
18
+ const { t } = useTranslation()
19
+
20
+ const visible = $derived((badges ?? []).slice(0, limit))
21
+ const overflow = $derived(Math.max(0, (badges?.length ?? 0) - visible.length))
22
+ const interactive = $derived(typeof onClick === 'function')
23
+ const shelfLabel = $derived(
24
+ t(
25
+ 'badgeShelf.aria',
26
+ { count: badges?.length ?? 0 },
27
+ { defaultValue: '{{count}} badges earned' },
28
+ ),
29
+ )
30
+ const overflowLabel = $derived(
31
+ t(
32
+ 'badgeShelf.overflow.aria',
33
+ { count: overflow },
34
+ { defaultValue: 'Show {{count}} more badges' },
35
+ ),
36
+ )
37
+
38
+ /**
39
+ * The badge's native tooltip: its name, plus its description when set.
40
+ *
41
+ * @param badge - The badge.
42
+ * @returns The tooltip text.
43
+ */
44
+ function tooltip(badge: Badge): string {
45
+ return badge.description ? `${badge.name} — ${badge.description}` : badge.name
46
+ }
47
+ </script>
48
+
49
+ {#snippet icon(badge: Badge)}
50
+ {#if badge.iconSrc}
51
+ <img
52
+ src={badge.iconSrc}
53
+ alt=""
54
+ class={cm.cn(cm.shrink0)}
55
+ style="width: 24px; height: 24px"
56
+ data-mol-id="badge-shelf-icon-img"
57
+ />
58
+ {:else}
59
+ <span aria-hidden="true" data-mol-id="badge-shelf-icon-glyph">{badge.icon ?? '*'}</span>
60
+ {/if}
61
+ {/snippet}
62
+
63
+ {#if badges && badges.length > 0}
64
+ <ul
65
+ class={cm.cn(cm.flex({ align: 'center', gap: 'xs' }), className)}
66
+ data-mol-id="badge-shelf"
67
+ aria-label={shelfLabel}
68
+ >
69
+ {#each visible as badge (badge.id)}
70
+ <li
71
+ class={cm.cn(cm.flex({ align: 'center', justify: 'center' }))}
72
+ data-mol-id="badge-shelf-item"
73
+ data-badge-id={badge.id}
74
+ >
75
+ {#if interactive}
76
+ <button
77
+ type="button"
78
+ class={cm.cn(cm.flex({ align: 'center', justify: 'center' }), cm.roundedFull)}
79
+ onclick={() => onClick?.(badge)}
80
+ title={tooltip(badge)}
81
+ aria-label={badge.name}
82
+ data-mol-id="badge-shelf-button"
83
+ >
84
+ {@render icon(badge)}
85
+ </button>
86
+ {:else}
87
+ <span title={tooltip(badge)} aria-label={badge.name} role="img">
88
+ {@render icon(badge)}
89
+ </span>
90
+ {/if}
91
+ </li>
92
+ {/each}
93
+ {#if overflow > 0}
94
+ <li
95
+ class={cm.cn(cm.flex({ align: 'center', justify: 'center' }))}
96
+ data-mol-id="badge-shelf-overflow"
97
+ >
98
+ {#if interactive}
99
+ <button
100
+ type="button"
101
+ class={cm.cn(
102
+ cm.flex({ align: 'center', justify: 'center' }),
103
+ cm.roundedFull,
104
+ cm.textSize('xs'),
105
+ cm.fontWeight('semibold'),
106
+ )}
107
+ onclick={() => onClick?.(null)}
108
+ aria-label={overflowLabel}
109
+ data-mol-id="badge-shelf-overflow-button">+{overflow}</button
110
+ >
111
+ {:else}
112
+ <span
113
+ class={cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'))}
114
+ aria-label={overflowLabel}>+{overflow}</span
115
+ >
116
+ {/if}
117
+ </li>
118
+ {/if}
119
+ </ul>
120
+ {/if}
@@ -0,0 +1,5 @@
1
+ import type { BadgeShelfProps } from './types.js';
2
+ declare const BadgeShelf: import("svelte").Component<BadgeShelfProps, {}, "">;
3
+ type BadgeShelf = ReturnType<typeof BadgeShelf>;
4
+ export default BadgeShelf;
5
+ //# sourceMappingURL=BadgeShelf.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BadgeShelf.svelte.d.ts","sourceRoot":"","sources":["../src/BadgeShelf.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAS,eAAe,EAAE,MAAM,YAAY,CAAC;AAqFzD,QAAA,MAAM,UAAU,qDAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
@@ -0,0 +1,59 @@
1
+ <!--
2
+ ReputationBadge: the Svelte counterpart of
3
+ `@molecule/app-reputation-badge-react`'s `ReputationBadge` — a numeric score
4
+ plus a tier chip, in the compact (default) or full (captioned, stacked)
5
+ variant. Same props, same ClassMap tokens, same i18n keys, same DOM for the
6
+ same input: React's root flips between `<span>` (compact) and `<div>` (full),
7
+ and so does this component's.
8
+ -->
9
+ <script lang="ts">
10
+ import { useTranslation } from '@molecule/app-svelte'
11
+ import { getClassMap } from '@molecule/app-ui'
12
+ import { Badge } from '@molecule/app-ui-svelte'
13
+
14
+ import { formatScore, levelLabel } from './labels.js'
15
+ import { colorForLevel, DEFAULT_THRESHOLDS, levelForScore } from './levels.js'
16
+ import type { ReputationBadgeProps } from './types.js'
17
+
18
+ let { score, level, thresholds, variant = 'compact', className }: ReputationBadgeProps = $props()
19
+
20
+ const cm = $derived(getClassMap())
21
+ const { t } = useTranslation()
22
+
23
+ const resolvedLevel = $derived(level ?? levelForScore(score, thresholds ?? DEFAULT_THRESHOLDS))
24
+ const color = $derived(colorForLevel(resolvedLevel))
25
+ const label = $derived(levelLabel(t, resolvedLevel))
26
+ const formattedScore = $derived(formatScore(score))
27
+ const caption = $derived(t('reputationBadge.caption', {}, { defaultValue: 'Reputation' }))
28
+ const ariaLabel = $derived(
29
+ t(
30
+ 'reputationBadge.aria',
31
+ { score: formattedScore, level: label },
32
+ { defaultValue: '{{score}} reputation, {{level}}' },
33
+ ),
34
+ )
35
+ </script>
36
+
37
+ {#if variant === 'full'}
38
+ <div class={cm.cn(cm.stack(1), className)} data-mol-id="reputation-badge" aria-label={ariaLabel}>
39
+ <span class={cm.cn(cm.textSize('xs'), cm.fontWeight('medium'))}>{caption}</span>
40
+ <div class={cm.flex({ align: 'center', gap: 'sm' })} data-mol-id="reputation-badge-row">
41
+ <span
42
+ class={cm.cn(cm.textSize('lg'), cm.fontWeight('bold'))}
43
+ data-mol-id="reputation-badge-score">{formattedScore}</span
44
+ >
45
+ <Badge {color}>{label}</Badge>
46
+ </div>
47
+ </div>
48
+ {:else}
49
+ <span
50
+ class={cm.cn(cm.flex({ align: 'center', gap: 'xs' }), className)}
51
+ data-mol-id="reputation-badge"
52
+ aria-label={ariaLabel}
53
+ >
54
+ <span class={cm.fontWeight('semibold')} data-mol-id="reputation-badge-score"
55
+ >{formattedScore}</span
56
+ >
57
+ <Badge {color}>{label}</Badge>
58
+ </span>
59
+ {/if}
@@ -0,0 +1,5 @@
1
+ import type { ReputationBadgeProps } from './types.js';
2
+ declare const ReputationBadge: import("svelte").Component<ReputationBadgeProps, {}, "">;
3
+ type ReputationBadge = ReturnType<typeof ReputationBadge>;
4
+ export default ReputationBadge;
5
+ //# sourceMappingURL=ReputationBadge.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReputationBadge.svelte.d.ts","sourceRoot":"","sources":["../src/ReputationBadge.svelte"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAgDvD,QAAA,MAAM,eAAe,0DAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The package's components: one Svelte 5 component per React component in
3
+ * `@molecule/app-reputation-badge-react`, under the same React name.
4
+ *
5
+ * @module
6
+ */
7
+ export { default as BadgeShelf } from './BadgeShelf.svelte';
8
+ export { default as ReputationBadge } from './ReputationBadge.svelte';
9
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,0BAA0B,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The package's components: one Svelte 5 component per React component in
3
+ * `@molecule/app-reputation-badge-react`, under the same React name.
4
+ *
5
+ * @module
6
+ */
7
+ export { default as BadgeShelf } from './BadgeShelf.svelte';
8
+ export { default as ReputationBadge } from './ReputationBadge.svelte';
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Svelte reputation/karma surfaces — `<ReputationBadge>` and `<BadgeShelf>` —
3
+ * for forum, discussion-board, and social flagships.
4
+ *
5
+ * `<ReputationBadge score={n} />` renders a compact-formatted score ("1.5k")
6
+ * plus a tier chip; the tier derives from `score` via `levelForScore` and
7
+ * `DEFAULT_THRESHOLDS` (contributor 100, trusted 500, veteran 2000,
8
+ * legend 10000) unless you pass `level` or `thresholds`. `variant` is
9
+ * `'compact'` (default) or `'full'` (stacked with a "Reputation" caption).
10
+ * `<BadgeShelf badges limit onClick />` renders earned-badge icons with a
11
+ * trailing `+N` overflow chip (`onClick(null)` signals "expand all").
12
+ *
13
+ * This is the Svelte counterpart of `@molecule/app-reputation-badge-react`:
14
+ * same exports, same props (React names), same DOM for the same input.
15
+ *
16
+ * @example
17
+ * ```svelte
18
+ * <script lang="ts">
19
+ * import { BadgeShelf, ReputationBadge } from '@molecule/app-reputation-badge-svelte'
20
+ * import type { Badge } from '@molecule/app-reputation-badge-svelte'
21
+ *
22
+ * let { score, badges, onBadgeClick }: {
23
+ * score: number
24
+ * badges: Badge[]
25
+ * onBadgeClick: (badge: Badge | null) => void
26
+ * } = $props()
27
+ * </script>
28
+ *
29
+ * <div>
30
+ * <ReputationBadge {score} variant="full" />
31
+ * <BadgeShelf {badges} limit={5} onClick={onBadgeClick} />
32
+ * </div>
33
+ * ```
34
+ *
35
+ * @remarks
36
+ * - Both components throw unless mounted under `setMoleculeContext({ i18n })`
37
+ * (`useTranslation()` needs it) with a ClassMap bonded via `setClassMap()`.
38
+ * - This package exports a `Badge` TYPE (earned-badge data shape) — distinct
39
+ * from the `Badge` COMPONENT in `@molecule/app-ui-svelte`; alias one when
40
+ * importing both in a file.
41
+ * - Server-side score/badge issuance pairs with `@molecule/api-reputation`.
42
+ * - Translations live in the companion `@molecule/app-locales-reputation-badge`
43
+ * bond (registered).
44
+ *
45
+ * @module
46
+ */
47
+ export * from './components.js';
48
+ export * from './levels.js';
49
+ export * from './types.js';
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Svelte reputation/karma surfaces — `<ReputationBadge>` and `<BadgeShelf>` —
3
+ * for forum, discussion-board, and social flagships.
4
+ *
5
+ * `<ReputationBadge score={n} />` renders a compact-formatted score ("1.5k")
6
+ * plus a tier chip; the tier derives from `score` via `levelForScore` and
7
+ * `DEFAULT_THRESHOLDS` (contributor 100, trusted 500, veteran 2000,
8
+ * legend 10000) unless you pass `level` or `thresholds`. `variant` is
9
+ * `'compact'` (default) or `'full'` (stacked with a "Reputation" caption).
10
+ * `<BadgeShelf badges limit onClick />` renders earned-badge icons with a
11
+ * trailing `+N` overflow chip (`onClick(null)` signals "expand all").
12
+ *
13
+ * This is the Svelte counterpart of `@molecule/app-reputation-badge-react`:
14
+ * same exports, same props (React names), same DOM for the same input.
15
+ *
16
+ * @example
17
+ * ```svelte
18
+ * <script lang="ts">
19
+ * import { BadgeShelf, ReputationBadge } from '@molecule/app-reputation-badge-svelte'
20
+ * import type { Badge } from '@molecule/app-reputation-badge-svelte'
21
+ *
22
+ * let { score, badges, onBadgeClick }: {
23
+ * score: number
24
+ * badges: Badge[]
25
+ * onBadgeClick: (badge: Badge | null) => void
26
+ * } = $props()
27
+ * </script>
28
+ *
29
+ * <div>
30
+ * <ReputationBadge {score} variant="full" />
31
+ * <BadgeShelf {badges} limit={5} onClick={onBadgeClick} />
32
+ * </div>
33
+ * ```
34
+ *
35
+ * @remarks
36
+ * - Both components throw unless mounted under `setMoleculeContext({ i18n })`
37
+ * (`useTranslation()` needs it) with a ClassMap bonded via `setClassMap()`.
38
+ * - This package exports a `Badge` TYPE (earned-badge data shape) — distinct
39
+ * from the `Badge` COMPONENT in `@molecule/app-ui-svelte`; alias one when
40
+ * importing both in a file.
41
+ * - Server-side score/badge issuance pairs with `@molecule/api-reputation`.
42
+ * - Translations live in the companion `@molecule/app-locales-reputation-badge`
43
+ * bond (registered).
44
+ *
45
+ * @module
46
+ */
47
+ export * from './components.js';
48
+ export * from './levels.js';
49
+ export * from './types.js';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Score and level label formatting for the Svelte reputation badge — the same
3
+ * helper functions `@molecule/app-reputation-badge-react` keeps beside its
4
+ * component (module-private: not part of this package's exports).
5
+ *
6
+ * @module
7
+ */
8
+ import type { I18nProvider } from '@molecule/app-i18n';
9
+ import type { ReputationLevel } from './types.js';
10
+ /**
11
+ * The i18n translate function the bonded provider hands out.
12
+ */
13
+ type Translate = I18nProvider['t'];
14
+ /**
15
+ * Resolve a level's translated label — exactly React's `levelLabel`: one
16
+ * LITERAL i18n key per in-contract level, and the literal
17
+ * `reputationBadge.level.fallback` key (whose English is the bare `{{level}}`
18
+ * placeholder, so an unknown id renders as itself) for anything else.
19
+ *
20
+ * Literal keys, never one built from the level id: the i18n gate can only see
21
+ * literal keys, so a key built at runtime that no locale bond carries leaves
22
+ * every non-English user on English with nothing reporting it.
23
+ *
24
+ * @param t - The bonded translate function.
25
+ * @param level - The level id (may be out of contract).
26
+ * @returns The translated label.
27
+ */
28
+ export declare function levelLabel(t: Translate, level: ReputationLevel): string;
29
+ /**
30
+ * Compact-thousands formatter — keeps the badge readable at large scores.
31
+ *
32
+ * Examples: `42` → `"42"`, `1500` → `"1.5k"`, `12300` → `"12.3k"`,
33
+ * `1_250_000` → `"1.3m"`.
34
+ *
35
+ * @param score - The score to format.
36
+ * @returns A short human-readable string.
37
+ */
38
+ export declare function formatScore(score: number): string;
39
+ export {};
40
+ //# sourceMappingURL=labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../src/labels.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;GAEG;AACH,KAAK,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;AAElC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,GAAG,MAAM,CAevE;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAWjD"}
package/dist/labels.js ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Score and level label formatting for the Svelte reputation badge — the same
3
+ * helper functions `@molecule/app-reputation-badge-react` keeps beside its
4
+ * component (module-private: not part of this package's exports).
5
+ *
6
+ * @module
7
+ */
8
+ /**
9
+ * Resolve a level's translated label — exactly React's `levelLabel`: one
10
+ * LITERAL i18n key per in-contract level, and the literal
11
+ * `reputationBadge.level.fallback` key (whose English is the bare `{{level}}`
12
+ * placeholder, so an unknown id renders as itself) for anything else.
13
+ *
14
+ * Literal keys, never one built from the level id: the i18n gate can only see
15
+ * literal keys, so a key built at runtime that no locale bond carries leaves
16
+ * every non-English user on English with nothing reporting it.
17
+ *
18
+ * @param t - The bonded translate function.
19
+ * @param level - The level id (may be out of contract).
20
+ * @returns The translated label.
21
+ */
22
+ export function levelLabel(t, level) {
23
+ switch (level) {
24
+ case 'newcomer':
25
+ return t('reputationBadge.level.newcomer', {}, { defaultValue: 'Newcomer' });
26
+ case 'contributor':
27
+ return t('reputationBadge.level.contributor', {}, { defaultValue: 'Contributor' });
28
+ case 'trusted':
29
+ return t('reputationBadge.level.trusted', {}, { defaultValue: 'Trusted' });
30
+ case 'veteran':
31
+ return t('reputationBadge.level.veteran', {}, { defaultValue: 'Veteran' });
32
+ case 'legend':
33
+ return t('reputationBadge.level.legend', {}, { defaultValue: 'Legend' });
34
+ default:
35
+ return t('reputationBadge.level.fallback', { level }, { defaultValue: '{{level}}' });
36
+ }
37
+ }
38
+ /**
39
+ * Compact-thousands formatter — keeps the badge readable at large scores.
40
+ *
41
+ * Examples: `42` → `"42"`, `1500` → `"1.5k"`, `12300` → `"12.3k"`,
42
+ * `1_250_000` → `"1.3m"`.
43
+ *
44
+ * @param score - The score to format.
45
+ * @returns A short human-readable string.
46
+ */
47
+ export function formatScore(score) {
48
+ if (!Number.isFinite(score))
49
+ return '0';
50
+ const sign = score < 0 ? '-' : '';
51
+ const abs = Math.abs(score);
52
+ if (abs >= 1_000_000) {
53
+ return `${sign}${trimZero((abs / 1_000_000).toFixed(1))}m`;
54
+ }
55
+ if (abs >= 1_000) {
56
+ return `${sign}${trimZero((abs / 1_000).toFixed(1))}k`;
57
+ }
58
+ return `${sign}${Math.round(abs)}`;
59
+ }
60
+ /**
61
+ * Drop a trailing `.0` from a fixed-precision number string.
62
+ *
63
+ * @param s - The fixed-precision string (e.g. `"1.0"`).
64
+ * @returns The cleaned string (e.g. `"1"`).
65
+ */
66
+ function trimZero(s) {
67
+ return s.endsWith('.0') ? s.slice(0, -2) : s;
68
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Pure helpers for mapping reputation scores to levels and tier colors.
3
+ *
4
+ * Kept framework-free so they're trivially unit-testable, and identical to
5
+ * `@molecule/app-reputation-badge-react`'s helpers so both packages agree on
6
+ * every derivation.
7
+ *
8
+ * @module
9
+ */
10
+ import type { ReputationLevel, ReputationThresholds } from './types.js';
11
+ /**
12
+ * Default thresholds used when no `thresholds` prop is supplied.
13
+ */
14
+ export declare const DEFAULT_THRESHOLDS: ReputationThresholds;
15
+ /**
16
+ * Derive a {@link ReputationLevel} from a numeric score.
17
+ *
18
+ * Picks the highest level whose threshold is met or exceeded. Any score
19
+ * below `thresholds.contributor` returns `'newcomer'`.
20
+ *
21
+ * @param score - Reputation score (any non-negative number).
22
+ * @param thresholds - Optional override thresholds; defaults to {@link DEFAULT_THRESHOLDS}.
23
+ * @returns The derived reputation level.
24
+ */
25
+ export declare function levelForScore(score: number, thresholds?: ReputationThresholds): ReputationLevel;
26
+ /**
27
+ * Return the semantic Badge color for a given level.
28
+ *
29
+ * Unknown levels fall back to `'secondary'`.
30
+ *
31
+ * @param level - The reputation level.
32
+ * @returns A badge color name from `@molecule/app-ui-vue`.
33
+ */
34
+ export declare function colorForLevel(level: ReputationLevel): 'primary' | 'secondary' | 'success' | 'warning' | 'info';
35
+ //# sourceMappingURL=levels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"levels.d.ts","sourceRoot":"","sources":["../src/levels.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEvE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,oBAKhC,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,oBAAyC,GACpD,eAAe,CAMjB;AAmBD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,GACrB,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAE1D"}
package/dist/levels.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Pure helpers for mapping reputation scores to levels and tier colors.
3
+ *
4
+ * Kept framework-free so they're trivially unit-testable, and identical to
5
+ * `@molecule/app-reputation-badge-react`'s helpers so both packages agree on
6
+ * every derivation.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Default thresholds used when no `thresholds` prop is supplied.
12
+ */
13
+ export const DEFAULT_THRESHOLDS = {
14
+ contributor: 100,
15
+ trusted: 500,
16
+ veteran: 2000,
17
+ legend: 10000,
18
+ };
19
+ /**
20
+ * Derive a {@link ReputationLevel} from a numeric score.
21
+ *
22
+ * Picks the highest level whose threshold is met or exceeded. Any score
23
+ * below `thresholds.contributor` returns `'newcomer'`.
24
+ *
25
+ * @param score - Reputation score (any non-negative number).
26
+ * @param thresholds - Optional override thresholds; defaults to {@link DEFAULT_THRESHOLDS}.
27
+ * @returns The derived reputation level.
28
+ */
29
+ export function levelForScore(score, thresholds = DEFAULT_THRESHOLDS) {
30
+ if (score >= thresholds.legend)
31
+ return 'legend';
32
+ if (score >= thresholds.veteran)
33
+ return 'veteran';
34
+ if (score >= thresholds.trusted)
35
+ return 'trusted';
36
+ if (score >= thresholds.contributor)
37
+ return 'contributor';
38
+ return 'newcomer';
39
+ }
40
+ /**
41
+ * Maps a {@link ReputationLevel} to the semantic Badge color used by the
42
+ * shared `<Badge>` component (`@molecule/app-ui-svelte`).
43
+ *
44
+ * Apps that swap the ClassMap bond automatically restyle these chips.
45
+ */
46
+ const LEVEL_TO_COLOR = {
47
+ newcomer: 'secondary',
48
+ contributor: 'info',
49
+ trusted: 'primary',
50
+ veteran: 'success',
51
+ legend: 'warning',
52
+ };
53
+ /**
54
+ * Return the semantic Badge color for a given level.
55
+ *
56
+ * Unknown levels fall back to `'secondary'`.
57
+ *
58
+ * @param level - The reputation level.
59
+ * @returns A badge color name from `@molecule/app-ui-vue`.
60
+ */
61
+ export function colorForLevel(level) {
62
+ return LEVEL_TO_COLOR[level] ?? 'secondary';
63
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Public types for the reputation-badge-svelte feature.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Reputation level identifiers — used to pick a tier color/label.
8
+ *
9
+ * Apps that need finer granularity can pass a `level` string of any value;
10
+ * unknown values fall back to `'newcomer'` styling.
11
+ */
12
+ export type ReputationLevel = 'newcomer' | 'contributor' | 'trusted' | 'veteran' | 'legend';
13
+ /**
14
+ * Optional thresholds for deriving a `ReputationLevel` from a numeric score.
15
+ *
16
+ * If a `level` prop isn't passed to `<ReputationBadge>`, the component will
17
+ * pick the highest level whose threshold the `score` meets or exceeds.
18
+ *
19
+ * Default thresholds:
20
+ * - `contributor` >= 100
21
+ * - `trusted` >= 500
22
+ * - `veteran` >= 2000
23
+ * - `legend` >= 10000
24
+ * - below 100 → `newcomer`
25
+ */
26
+ export interface ReputationThresholds {
27
+ /** Score >= contributor threshold ⇒ `'contributor'`. */
28
+ contributor: number;
29
+ /** Score >= trusted threshold ⇒ `'trusted'`. */
30
+ trusted: number;
31
+ /** Score >= veteran threshold ⇒ `'veteran'`. */
32
+ veteran: number;
33
+ /** Score >= legend threshold ⇒ `'legend'`. */
34
+ legend: number;
35
+ }
36
+ /**
37
+ * A single earned badge — one icon on the `<BadgeShelf>` row.
38
+ */
39
+ export interface Badge {
40
+ /** Stable identifier (used as the row key + click payload). */
41
+ id: string;
42
+ /** Display name (translated upstream — passed verbatim). */
43
+ name: string;
44
+ /** Optional longer description, shown in the native tooltip. */
45
+ description?: string;
46
+ /** Icon glyph or short emoji (rendered inline). Mutually exclusive with `iconSrc`. */
47
+ icon?: string;
48
+ /** Image URL for the badge icon. */
49
+ iconSrc?: string;
50
+ /** ISO date string the badge was earned (passed back via `onClick`). */
51
+ earnedAt?: string;
52
+ }
53
+ /**
54
+ * Props accepted by the `ReputationBadge` component — the same props
55
+ * React's `@molecule/app-reputation-badge-react` accepts.
56
+ */
57
+ export interface ReputationBadgeProps {
58
+ /** Numeric reputation / karma score. */
59
+ score: number;
60
+ /**
61
+ * Explicit reputation level. If omitted, derived from `score` via
62
+ * `levelForScore` using `thresholds` (or `DEFAULT_THRESHOLDS`).
63
+ */
64
+ level?: ReputationLevel;
65
+ /** Override the default score → level thresholds. */
66
+ thresholds?: ReputationThresholds;
67
+ /**
68
+ * Layout variant.
69
+ * - `'compact'` (default) — score number inline with a small level chip.
70
+ * - `'full'` — stacked layout with a "Reputation" caption above the row.
71
+ */
72
+ variant?: 'compact' | 'full';
73
+ /** Extra classes merged onto the outer wrapper. */
74
+ className?: string;
75
+ }
76
+ /**
77
+ * Props accepted by the `BadgeShelf` component — the same props React's
78
+ * `@molecule/app-reputation-badge-react` accepts.
79
+ */
80
+ export interface BadgeShelfProps {
81
+ /** Earned badges to display, ordered most-prominent-first. */
82
+ badges: Badge[];
83
+ /**
84
+ * Maximum number of badge icons rendered inline. Any remaining are
85
+ * summarised in a trailing `+N` overflow chip.
86
+ *
87
+ * @default 5
88
+ */
89
+ limit?: number;
90
+ /**
91
+ * Click handler — invoked with the clicked badge (or `null` when the
92
+ * trailing overflow chip is clicked, signalling "expand all").
93
+ */
94
+ onClick?: (badge: Badge | null) => void;
95
+ /** Extra classes merged onto the outer row. */
96
+ className?: string;
97
+ }
98
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;AAE3F;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,oBAAoB;IACnC,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAA;IACnB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAA;IACf,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAA;IACf,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,+DAA+D;IAC/D,EAAE,EAAE,MAAM,CAAA;IACV,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAA;IACZ,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,qDAAqD;IACrD,UAAU,CAAC,EAAE,oBAAoB,CAAA;IACjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;IAC5B,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,MAAM,EAAE,KAAK,EAAE,CAAA;IACf;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,CAAA;IACvC,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Public types for the reputation-badge-svelte feature.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,75 @@
1
1
  {
2
2
  "name": "@molecule/app-reputation-badge-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "User reputation/karma badge with score, level chip, and earned-badges shelf",
5
+ "homepage": "https://www.molecule.dev/packages/app-reputation-badge-svelte",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "svelte": "./dist/index.js",
18
+ "files": [
19
+ "dist",
20
+ "!dist/**/__tests__",
21
+ "!dist/**/*.test.*",
22
+ "!dist/**/*.spec.*",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
27
+ "dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest"
30
+ },
31
+ "keywords": [
32
+ "molecule",
33
+ "reputation",
34
+ "badge",
35
+ "karma",
36
+ "svelte"
37
+ ],
38
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
39
+ "license": "Apache-2.0",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/molecule-dev/molecule.git",
43
+ "directory": "packages/app/features/reputation-badge-svelte"
44
+ },
45
+ "engines": {
46
+ "node": ">=20"
47
+ },
48
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "peerDependencies": {
53
+ "@molecule/app-svelte": "^3.5.0",
54
+ "@molecule/app-ui": "^1.0.1",
55
+ "@molecule/app-ui-svelte": "^1.1.0",
56
+ "svelte": "^5.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "@molecule/app-framework-conformance": "0.0.0",
60
+ "@molecule/app-i18n": "1.2.2",
61
+ "@molecule/app-icons": "1.0.4",
62
+ "@molecule/app-svelte": "3.9.0",
63
+ "@molecule/app-ui": "1.5.0",
64
+ "@molecule/app-ui-svelte": "1.2.1",
65
+ "@sveltejs/package": "3.0.2",
66
+ "@sveltejs/vite-plugin-svelte": "7.1.2",
67
+ "@types/node": "26.6.5",
68
+ "jsdom": "30.1.3",
69
+ "svelte": "5.57.2",
70
+ "svelte-check": "4.7.7",
71
+ "typescript": "6.0.3",
72
+ "vite": "8.3.5",
73
+ "vitest": "4.1.12"
74
+ }
75
+ }