@pie-players/pie-players-shared 0.3.29 → 0.3.30

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 (142) hide show
  1. package/{src → dist}/components/PieItemPlayer.svelte +156 -88
  2. package/dist/i18n/translations/en/tools.json +1 -1
  3. package/{src → dist}/i18n/use-i18n-standalone.svelte.ts +1 -0
  4. package/{src → dist}/i18n/use-i18n.svelte.ts +1 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/loader-config.d.ts +25 -0
  10. package/dist/loader-config.d.ts.map +1 -1
  11. package/dist/loader-config.js +5 -0
  12. package/dist/loader-config.js.map +1 -1
  13. package/dist/pie/config.d.ts.map +1 -1
  14. package/dist/pie/config.js +12 -5
  15. package/dist/pie/config.js.map +1 -1
  16. package/dist/pie/iife-loader.d.ts +35 -0
  17. package/dist/pie/iife-loader.d.ts.map +1 -1
  18. package/dist/pie/iife-loader.js +138 -2
  19. package/dist/pie/iife-loader.js.map +1 -1
  20. package/dist/pie/index.d.ts +3 -1
  21. package/dist/pie/index.d.ts.map +1 -1
  22. package/dist/pie/index.js +1 -0
  23. package/dist/pie/index.js.map +1 -1
  24. package/dist/pie/overrides.d.ts +9 -0
  25. package/dist/pie/overrides.d.ts.map +1 -1
  26. package/dist/pie/overrides.js +36 -0
  27. package/dist/pie/overrides.js.map +1 -1
  28. package/dist/pie/resource-monitor.d.ts +17 -0
  29. package/dist/pie/resource-monitor.d.ts.map +1 -1
  30. package/dist/pie/resource-monitor.js +284 -81
  31. package/dist/pie/resource-monitor.js.map +1 -1
  32. package/dist/pie/updates.d.ts.map +1 -1
  33. package/dist/pie/updates.js +65 -2
  34. package/dist/pie/updates.js.map +1 -1
  35. package/dist/security/index.d.ts +5 -0
  36. package/dist/security/index.d.ts.map +1 -0
  37. package/dist/security/index.js +5 -0
  38. package/dist/security/index.js.map +1 -0
  39. package/dist/security/sanitize-item-markup.d.ts +46 -0
  40. package/dist/security/sanitize-item-markup.d.ts.map +1 -0
  41. package/dist/security/sanitize-item-markup.js +174 -0
  42. package/dist/security/sanitize-item-markup.js.map +1 -0
  43. package/dist/security/sanitize-svg-icon.d.ts +15 -0
  44. package/dist/security/sanitize-svg-icon.d.ts.map +1 -0
  45. package/dist/security/sanitize-svg-icon.js +89 -0
  46. package/dist/security/sanitize-svg-icon.js.map +1 -0
  47. package/dist/security/validate-style-url.d.ts +28 -0
  48. package/dist/security/validate-style-url.d.ts.map +1 -0
  49. package/dist/security/validate-style-url.js +58 -0
  50. package/dist/security/validate-style-url.js.map +1 -0
  51. package/dist/security/wrap-overwide-images.d.ts +31 -0
  52. package/dist/security/wrap-overwide-images.d.ts.map +1 -0
  53. package/dist/security/wrap-overwide-images.js +92 -0
  54. package/dist/security/wrap-overwide-images.js.map +1 -0
  55. package/dist/server/npm-registry.d.ts +8 -0
  56. package/dist/server/npm-registry.d.ts.map +1 -0
  57. package/dist/server/npm-registry.js +60 -0
  58. package/dist/server/npm-registry.js.map +1 -0
  59. package/dist/types/index.d.ts +10 -0
  60. package/dist/types/index.d.ts.map +1 -1
  61. package/dist/types/index.js.map +1 -1
  62. package/dist/ui/first-focusable.d.ts +21 -0
  63. package/dist/ui/first-focusable.d.ts.map +1 -0
  64. package/dist/ui/first-focusable.js +73 -0
  65. package/dist/ui/first-focusable.js.map +1 -0
  66. package/dist/ui/focus-trap.d.ts.map +1 -1
  67. package/dist/ui/focus-trap.js +2 -13
  68. package/dist/ui/focus-trap.js.map +1 -1
  69. package/package.json +44 -34
  70. package/dist/i18n/scripts/check-coverage.d.ts +0 -16
  71. package/dist/i18n/scripts/check-coverage.d.ts.map +0 -1
  72. package/dist/i18n/scripts/check-coverage.js +0 -262
  73. package/dist/i18n/scripts/check-coverage.js.map +0 -1
  74. package/dist/i18n/scripts/scan-hardcoded.d.ts +0 -16
  75. package/dist/i18n/scripts/scan-hardcoded.d.ts.map +0 -1
  76. package/dist/i18n/scripts/scan-hardcoded.js +0 -266
  77. package/dist/i18n/scripts/scan-hardcoded.js.map +0 -1
  78. package/dist/i18n/use-i18n-standalone.svelte.d.ts +0 -87
  79. package/dist/i18n/use-i18n-standalone.svelte.d.ts.map +0 -1
  80. package/dist/i18n/use-i18n-standalone.svelte.js +0 -151
  81. package/dist/i18n/use-i18n-standalone.svelte.js.map +0 -1
  82. package/dist/i18n/use-i18n.svelte.d.ts +0 -67
  83. package/dist/i18n/use-i18n.svelte.d.ts.map +0 -1
  84. package/dist/i18n/use-i18n.svelte.js +0 -144
  85. package/dist/i18n/use-i18n.svelte.js.map +0 -1
  86. package/dist/instrumentation/providers/DataDogInstrumentationProvider.d.ts +0 -170
  87. package/dist/instrumentation/providers/DataDogInstrumentationProvider.d.ts.map +0 -1
  88. package/dist/instrumentation/providers/DataDogInstrumentationProvider.js +0 -183
  89. package/dist/instrumentation/providers/DataDogInstrumentationProvider.js.map +0 -1
  90. package/dist/theming/css-variables.d.ts +0 -7
  91. package/dist/theming/css-variables.d.ts.map +0 -1
  92. package/dist/theming/css-variables.js +0 -43
  93. package/dist/theming/css-variables.js.map +0 -1
  94. package/dist/theming/index.d.ts +0 -4
  95. package/dist/theming/index.d.ts.map +0 -1
  96. package/dist/theming/index.js +0 -3
  97. package/dist/theming/index.js.map +0 -1
  98. package/dist/theming/presets.d.ts +0 -7
  99. package/dist/theming/presets.d.ts.map +0 -1
  100. package/dist/theming/presets.js +0 -146
  101. package/dist/theming/presets.js.map +0 -1
  102. package/dist/theming/types.d.ts +0 -5
  103. package/dist/theming/types.d.ts.map +0 -1
  104. package/dist/theming/types.js +0 -2
  105. package/dist/theming/types.js.map +0 -1
  106. package/dist/types/custom-elements.d.ts +0 -158
  107. package/dist/types/custom-elements.d.ts.map +0 -1
  108. package/dist/types/custom-elements.js +0 -8
  109. package/dist/types/custom-elements.js.map +0 -1
  110. package/dist/types/search.d.ts +0 -105
  111. package/dist/types/search.d.ts.map +0 -1
  112. package/dist/types/search.js +0 -12
  113. package/dist/types/search.js.map +0 -1
  114. package/dist/types/transform.d.ts +0 -48
  115. package/dist/types/transform.d.ts.map +0 -1
  116. package/dist/types/transform.js +0 -21
  117. package/dist/types/transform.js.map +0 -1
  118. package/src/i18n/README.md +0 -223
  119. package/src/i18n/index.ts +0 -26
  120. package/src/i18n/loader.ts +0 -156
  121. package/src/i18n/scripts/check-coverage.ts +0 -345
  122. package/src/i18n/scripts/scan-hardcoded.ts +0 -342
  123. package/src/i18n/simple-i18n.ts +0 -236
  124. package/src/i18n/translations/ar/common.json +0 -36
  125. package/src/i18n/translations/ar/toolkit.json +0 -48
  126. package/src/i18n/translations/ar/tools.json +0 -103
  127. package/src/i18n/translations/en/common.json +0 -36
  128. package/src/i18n/translations/en/toolkit.json +0 -48
  129. package/src/i18n/translations/en/tools.json +0 -103
  130. package/src/i18n/translations/es/common.json +0 -36
  131. package/src/i18n/translations/es/toolkit.json +0 -48
  132. package/src/i18n/translations/es/tools.json +0 -103
  133. package/src/i18n/translations/zh/common.json +0 -36
  134. package/src/i18n/translations/zh/toolkit.json +0 -48
  135. package/src/i18n/translations/zh/tools.json +0 -103
  136. package/src/i18n/types.ts +0 -66
  137. /package/{src → dist}/components/PiePreviewLayout.svelte +0 -0
  138. /package/{src → dist}/components/PiePreviewToggle.svelte +0 -0
  139. /package/{src → dist}/components/PieSpinner.svelte +0 -0
  140. /package/{src → dist}/components/ToolSettingsButton.svelte +0 -0
  141. /package/{src → dist}/components/ToolSettingsPanel.svelte +0 -0
  142. /package/{src → dist}/components/index.ts +0 -0
@@ -1,105 +0,0 @@
1
- /**
2
- * Local type definitions for search package types used in client code.
3
- *
4
- * These are copied from @pie-api-aws/search to avoid importing from a server-only package.
5
- * This prevents Vite from trying to process the package and its Node.js dependencies.
6
- *
7
- * Server-side code should import directly from @pie-api-aws/search.
8
- *
9
- * When these types change in the search package, they should be updated here as well.
10
- */
11
- export interface GenerationDebugInfo {
12
- step1: {
13
- prompt: string;
14
- response: string;
15
- parsedIntent: {
16
- subject?: string;
17
- standardSet?: string;
18
- gradeLevels: number[];
19
- keywords: string[];
20
- standardSearchHints: string[];
21
- [key: string]: any;
22
- };
23
- cost?: {
24
- inputTokens: number;
25
- outputTokens: number;
26
- estimatedCost: number;
27
- };
28
- };
29
- step2: {
30
- intent: {
31
- subject?: string;
32
- standardSet?: string;
33
- gradeLevels: number[];
34
- keywords: string[];
35
- standardSearchHints: string[];
36
- [key: string]: any;
37
- };
38
- searchQuery?: {
39
- filters: {
40
- subject?: string;
41
- standardSet?: string;
42
- gradeLevels: number[];
43
- };
44
- keywords: string[];
45
- searchHints: string[];
46
- [key: string]: any;
47
- };
48
- candidatesFound: number;
49
- candidatesEmbedded?: number;
50
- topStandards?: Array<{
51
- guid: string;
52
- title?: string;
53
- score?: number;
54
- similarity?: number;
55
- }>;
56
- topStandardsReturned?: number;
57
- cost?: {
58
- embeddingCalls: number;
59
- estimatedCost: number;
60
- };
61
- };
62
- step3: {
63
- prompt: string;
64
- response: string;
65
- parsedBlueprint: {
66
- name: string;
67
- description?: string;
68
- subject?: string;
69
- standardSet?: string;
70
- gradeLevels: number[];
71
- assessmentGoal?: {
72
- dokDistribution?: {
73
- dok1?: number;
74
- dok2?: number;
75
- dok3?: number;
76
- dok4?: number;
77
- };
78
- totalItemCount?: {
79
- target?: number;
80
- min?: number;
81
- max?: number;
82
- };
83
- [key: string]: any;
84
- };
85
- standards: Array<{
86
- guid: string;
87
- count: number;
88
- rationale?: string;
89
- [key: string]: any;
90
- }>;
91
- [key: string]: any;
92
- };
93
- cost?: {
94
- inputTokens: number;
95
- outputTokens: number;
96
- estimatedCost: number;
97
- };
98
- };
99
- totalCost?: {
100
- llmCalls: number;
101
- embeddingCalls?: number;
102
- estimatedTotalCost: number;
103
- };
104
- }
105
- //# sourceMappingURL=search.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/types/search.ts"],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;YACN,WAAW,EAAE,MAAM,CAAC;YACpB,YAAY,EAAE,MAAM,CAAC;YACrB,aAAa,EAAE,MAAM,CAAC;SACtB,CAAC;KACF,CAAC;IACF,SAAS,CAAC,EAAE;QACX,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,kBAAkB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACF"}
@@ -1,12 +0,0 @@
1
- /**
2
- * Local type definitions for search package types used in client code.
3
- *
4
- * These are copied from @pie-api-aws/search to avoid importing from a server-only package.
5
- * This prevents Vite from trying to process the package and its Node.js dependencies.
6
- *
7
- * Server-side code should import directly from @pie-api-aws/search.
8
- *
9
- * When these types change in the search package, they should be updated here as well.
10
- */
11
- export {};
12
- //# sourceMappingURL=search.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/types/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
@@ -1,48 +0,0 @@
1
- /**
2
- * Local type definitions for transform package types used in client code.
3
- *
4
- * These are copied from @pie-api-aws/transform to avoid importing from a server-only package.
5
- * This prevents Vite from trying to process the package and its Node.js dependencies.
6
- *
7
- * Server-side code should import directly from @pie-api-aws/transform.
8
- *
9
- * When these types change in the transform package, they should be updated here as well.
10
- */
11
- export type LearnosityItem = Partial<{
12
- reference?: string;
13
- description?: string;
14
- status?: string;
15
- scoring_type?: string;
16
- questions: Array<Partial<{
17
- id?: string;
18
- reference?: string;
19
- metaData?: {
20
- [key: string]: any;
21
- };
22
- data: {
23
- [key: string]: any;
24
- };
25
- [key: string]: any;
26
- }>>;
27
- tags?: {
28
- [key: string]: string[];
29
- };
30
- [key: string]: any;
31
- }>;
32
- export declare class LearnosityToPieMappingLog {
33
- learnosityTypes: string[];
34
- mappers: string[];
35
- pieElementTypes: string[];
36
- }
37
- export declare class PieToLearnosityMappingLog {
38
- learnosityTypes: string[];
39
- mappers: string[];
40
- pieElementTypes: string[];
41
- }
42
- export interface MapLearnosityToPieOptions {
43
- log: LearnosityToPieMappingLog;
44
- }
45
- export interface MapPieToLearnosityOptions {
46
- log: PieToLearnosityMappingLog;
47
- }
48
- //# sourceMappingURL=transform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../src/types/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,KAAK,CACf,OAAO,CAAC;QACP,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QAClC,IAAI,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACnB,CAAC,CACF,CAAC;IACF,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC;IACnC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB,CAAC,CAAC;AAEH,qBAAa,yBAAyB;IACrC,eAAe,EAAE,MAAM,EAAE,CAAM;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAM;IACvB,eAAe,EAAE,MAAM,EAAE,CAAM;CAC/B;AAED,qBAAa,yBAAyB;IACrC,eAAe,EAAE,MAAM,EAAE,CAAM;IAC/B,OAAO,EAAE,MAAM,EAAE,CAAM;IACvB,eAAe,EAAE,MAAM,EAAE,CAAM;CAC/B;AAED,MAAM,WAAW,yBAAyB;IACzC,GAAG,EAAE,yBAAyB,CAAC;CAC/B;AAED,MAAM,WAAW,yBAAyB;IACzC,GAAG,EAAE,yBAAyB,CAAC;CAC/B"}
@@ -1,21 +0,0 @@
1
- /**
2
- * Local type definitions for transform package types used in client code.
3
- *
4
- * These are copied from @pie-api-aws/transform to avoid importing from a server-only package.
5
- * This prevents Vite from trying to process the package and its Node.js dependencies.
6
- *
7
- * Server-side code should import directly from @pie-api-aws/transform.
8
- *
9
- * When these types change in the transform package, they should be updated here as well.
10
- */
11
- export class LearnosityToPieMappingLog {
12
- learnosityTypes = [];
13
- mappers = [];
14
- pieElementTypes = [];
15
- }
16
- export class PieToLearnosityMappingLog {
17
- learnosityTypes = [];
18
- mappers = [];
19
- pieElementTypes = [];
20
- }
21
- //# sourceMappingURL=transform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../src/types/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsBH,MAAM,OAAO,yBAAyB;IACrC,eAAe,GAAa,EAAE,CAAC;IAC/B,OAAO,GAAa,EAAE,CAAC;IACvB,eAAe,GAAa,EAAE,CAAC;CAC/B;AAED,MAAM,OAAO,yBAAyB;IACrC,eAAe,GAAa,EAAE,CAAC;IAC/B,OAAO,GAAa,EAAE,CAAC;IACvB,eAAe,GAAa,EAAE,CAAC;CAC/B"}
@@ -1,223 +0,0 @@
1
- # PIE Players i18n System
2
-
3
- Comprehensive internationalization system with support for English, Spanish, Chinese, and Arabic (RTL).
4
-
5
- ## Usage Patterns
6
-
7
- ### Pattern 1: Standalone Components (Recommended for Individual Components)
8
-
9
- Use `useI18nStandalone()` when building standalone components (tools, players) that don't require the full toolkit architecture.
10
-
11
- ```svelte
12
- <script lang="ts">
13
- import { useI18nStandalone } from '@pie-players/pie-players-shared/i18n';
14
-
15
- // Simple setup - no service injection needed
16
- const i18n = useI18nStandalone({
17
- locale: 'en', // Optional: defaults to browser language
18
- debug: false // Optional: enable debug logging
19
- });
20
- </script>
21
-
22
- <div dir={i18n.direction}>
23
- <button>{i18n.t('common.save')}</button>
24
- <span>{i18n.tn('assessment.questions', 10)}</span>
25
-
26
- <!-- Change locale dynamically -->
27
- <button onclick={() => i18n.setLocale('es')}>Español</button>
28
- <button onclick={() => i18n.setLocale('ar')}>العربية</button>
29
- </div>
30
- ```
31
-
32
- **Benefits:**
33
- - ✅ No service architecture required
34
- - ✅ Self-contained - manages its own I18nService instance
35
- - ✅ Full feature support (hybrid loading, RTL, pluralization)
36
- - ✅ Perfect for reusable components and tools
37
-
38
- ### Pattern 2: Integrated with Assessment Toolkit
39
-
40
- Use `useI18n()` when working within the full assessment toolkit where centralized locale management is needed.
41
-
42
- ```svelte
43
- <script lang="ts">
44
- import { useI18n } from '@pie-players/pie-players-shared/i18n';
45
-
46
- // Receive service from parent/context
47
- let { player } = $props();
48
- const i18n = useI18n(() => player.getI18nService());
49
- </script>
50
-
51
- <div dir={i18n.direction}>
52
- <button>{i18n.t('common.save')}</button>
53
- <span>{i18n.tn('assessment.questions', totalQuestions)}</span>
54
- </div>
55
- ```
56
-
57
- **Benefits:**
58
- - ✅ Centralized locale management across entire application
59
- - ✅ Locale preferences from student profile/IEP
60
- - ✅ Shared service instance - locale changes sync everywhere
61
- - ✅ Integration with accommodation system
62
-
63
- ### Pattern 3: Direct Service Usage (Advanced)
64
-
65
- For non-Svelte contexts or advanced use cases:
66
-
67
- ```typescript
68
- import { SimpleI18n, BUNDLED_TRANSLATIONS, loadTranslations } from '@pie-players/pie-players-shared/i18n';
69
-
70
- const i18n = new SimpleI18n({
71
- locale: 'en',
72
- bundledTranslations: BUNDLED_TRANSLATIONS,
73
- loadTranslations,
74
- });
75
-
76
- await i18n.initialize({ locale: 'es' });
77
-
78
- console.log(i18n.t('common.save')); // "Guardar"
79
- console.log(i18n.getDirection()); // "ltr"
80
-
81
- // Subscribe to changes
82
- const unsubscribe = i18n.subscribe(() => {
83
- console.log('Locale changed to:', i18n.getLocale());
84
- });
85
- ```
86
-
87
- ## Translation Functions
88
-
89
- ### `t(key, params?)` - Basic Translation
90
-
91
- ```typescript
92
- i18n.t('common.save') // "Save"
93
- i18n.t('common.cancel') // "Cancel"
94
-
95
- // With interpolation
96
- i18n.t('assessment.question_of', { current: 5, total: 20 })
97
- // "Question 5 of 20"
98
- ```
99
-
100
- ### `tn(key, count, params?)` - Pluralization
101
-
102
- ```typescript
103
- i18n.tn('assessment.questions', 1) // "1 Question"
104
- i18n.tn('assessment.questions', 10) // "10 Questions"
105
-
106
- // With additional params
107
- i18n.tn('common.item', count, { type: 'folder' })
108
- ```
109
-
110
- ## Available Translations
111
-
112
- ### Common Namespace (`common.*`)
113
- - Buttons: `save`, `cancel`, `close`, `back`, `next`, `previous`, `submit`
114
- - States: `loading`, `error`, `retry`
115
- - Common words: `question`, `item`, `character` (all with pluralization)
116
-
117
- ### Assessment Namespace (`assessment.*`)
118
- - `title` - Assessment title
119
- - `questions` - Question count (plural)
120
- - `question_of` - "Question X of Y"
121
- - `student_name` - Student name label
122
- - `fullscreen`, `exit_fullscreen` - Fullscreen controls
123
-
124
- ### Accommodation Namespace (`accommodation.*`)
125
- - `audio`, `audio_aria` - Audio/TTS controls
126
- - `contrast`, `contrast_aria` - Contrast controls
127
-
128
- ### Navigation Namespace (`navigation.*`)
129
- - `back`, `next`, `previous`, `submit` - Navigation buttons
130
- - `navigate_to` - "Navigate to question X"
131
- - `section` - Section label
132
-
133
- ### Tool Namespace (`tool.*`)
134
- - Tool names: `calculator`, `graph`, `periodic_table`, etc.
135
- - TTS controls: `tts.speak`, `tts.pause`, `tts.stop`, `tts.rate`
136
- - Calculator types: `calculator.basic`, `calculator.scientific`, `calculator.graphing`
137
- - Color schemes: `color_scheme.default`, `color_scheme.high_contrast`, `color_scheme.dark`
138
-
139
- ## Supported Languages
140
-
141
- - **English (en)** - Bundled (~15KB)
142
- - **Spanish (es)** - Lazy-loaded (~12KB)
143
- - **Chinese (zh)** - Lazy-loaded (~12KB)
144
- - **Arabic (ar)** - Lazy-loaded (~12KB) with RTL support
145
-
146
- ## RTL Support
147
-
148
- Arabic automatically switches to RTL mode:
149
-
150
- ```svelte
151
- <script>
152
- const i18n = useI18nStandalone({ locale: 'ar' });
153
- </script>
154
-
155
- <!-- direction automatically set to "rtl" -->
156
- <div dir={i18n.direction}>
157
- {i18n.t('assessment.title')} <!-- التقييم -->
158
- </div>
159
- ```
160
-
161
- ## API Reference
162
-
163
- ### Composable Return Value
164
-
165
- ```typescript
166
- {
167
- // Reactive getters
168
- locale: string; // Current locale (e.g., 'en', 'es')
169
- direction: 'ltr' | 'rtl'; // Text direction
170
- isLoading: boolean; // Locale loading state
171
- availableLocales: string[]; // List of loaded locales
172
-
173
- // Methods
174
- t(key: string, params?: Record<string, any>): string;
175
- tn(key: string, count: number, params?: Record<string, any>): string;
176
- setLocale(locale: string): Promise<void>;
177
- isLocaleLoaded(locale: string): boolean;
178
- hasKey(key: string): boolean;
179
- }
180
- ```
181
-
182
- ## When to Use Each Pattern
183
-
184
- | Scenario | Use Pattern |
185
- |----------|-------------|
186
- | Standalone tool component | `useI18nStandalone()` |
187
- | Reusable UI component | `useI18nStandalone()` |
188
- | Individual player | `useI18nStandalone()` |
189
- | Full assessment application | `useI18n()` |
190
- | Student profile integration | `useI18n()` |
191
- | IEP/504 locale requirements | `useI18n()` |
192
- | Non-Svelte code | `SimpleI18n` class |
193
-
194
- ## Performance
195
-
196
- - **Initial load**: ~15KB (English bundled)
197
- - **Lazy loading**: ~12KB per additional language (cached)
198
- - **Hybrid strategy**: Only loads languages when needed
199
- - **Service reuse**: `useI18nStandalone()` creates one service per component
200
-
201
- ## Adding New Translations
202
-
203
- Translation files are located at:
204
- ```
205
- packages/players-shared/src/i18n/translations/
206
- ├── en/ (common.json, toolkit.json, tools.json)
207
- ├── es/ (common.json, toolkit.json, tools.json)
208
- ├── zh/ (common.json, toolkit.json, tools.json)
209
- └── ar/ (common.json, toolkit.json, tools.json)
210
- ```
211
-
212
- Format:
213
- ```json
214
- {
215
- "common": {
216
- "save": "Save",
217
- "question": {
218
- "one": "Question",
219
- "other": "Questions"
220
- }
221
- }
222
- }
223
- ```
package/src/i18n/index.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * I18n Module
3
- *
4
- * Internationalization system for PIE Players.
5
- *
6
- * @module @pie-players/pie-players-shared/i18n
7
- */
8
-
9
- export {
10
- BUNDLED_TRANSLATIONS,
11
- getAvailableLocales,
12
- isRTLLocale,
13
- loadTranslations,
14
- } from "./loader.js";
15
- export { SimpleI18n } from "./simple-i18n.js";
16
- export type {
17
- I18nConfig,
18
- I18nServiceApi,
19
- PluralTranslation,
20
- TranslationBundle,
21
- } from "./types.js";
22
- export { useI18n } from "./use-i18n.svelte.js";
23
- export {
24
- type UseI18nStandaloneConfig,
25
- useI18nStandalone,
26
- } from "./use-i18n-standalone.svelte.js";
@@ -1,156 +0,0 @@
1
- /**
2
- * Translation Loader
3
- *
4
- * Implements hybrid loading strategy:
5
- * - English bundled with application
6
- * - Other languages loaded on demand
7
- *
8
- * Part of PIE Players i18n system.
9
- */
10
-
11
- // Import English translations (bundled)
12
- import enCommon from "./translations/en/common.json" with { type: "json" };
13
- import enToolkit from "./translations/en/toolkit.json" with { type: "json" };
14
- import enTools from "./translations/en/tools.json" with { type: "json" };
15
- import type { TranslationBundle } from "./types.js";
16
-
17
- // RTL locales
18
- const RTL_LOCALES = ["ar", "he", "fa", "ur"];
19
-
20
- /**
21
- * Bundled English translations
22
- * Available immediately without network request
23
- */
24
- export const BUNDLED_TRANSLATIONS: Record<string, TranslationBundle> = {
25
- en: {
26
- locale: "en",
27
- direction: "ltr",
28
- translations: {
29
- ...flattenTranslations(enCommon),
30
- ...flattenTranslations(enToolkit),
31
- ...flattenTranslations(enTools),
32
- },
33
- },
34
- };
35
-
36
- const LOCALE_IMPORTS: Record<string, () => Promise<[any, any, any]>> = {
37
- es: () =>
38
- Promise.all([
39
- import("./translations/es/common.json"),
40
- import("./translations/es/toolkit.json"),
41
- import("./translations/es/tools.json"),
42
- ]),
43
- zh: () =>
44
- Promise.all([
45
- import("./translations/zh/common.json"),
46
- import("./translations/zh/toolkit.json"),
47
- import("./translations/zh/tools.json"),
48
- ]),
49
- ar: () =>
50
- Promise.all([
51
- import("./translations/ar/common.json"),
52
- import("./translations/ar/toolkit.json"),
53
- import("./translations/ar/tools.json"),
54
- ]),
55
- };
56
-
57
- /**
58
- * Load translations for a locale
59
- *
60
- * @param locale Locale code (e.g., 'en', 'es', 'zh', 'ar')
61
- * @returns Translation bundle with flattened keys
62
- */
63
- export async function loadTranslations(
64
- locale: string,
65
- ): Promise<TranslationBundle> {
66
- // Return bundled English immediately
67
- if (locale === "en") {
68
- return BUNDLED_TRANSLATIONS.en;
69
- }
70
-
71
- const importer = LOCALE_IMPORTS[locale];
72
- if (!importer) {
73
- throw new Error(
74
- `Translation files not found for locale: ${locale}. Ensure translation files exist in packages/players-shared/src/i18n/translations/${locale}/`,
75
- );
76
- }
77
-
78
- // Lazy load other locales
79
- try {
80
- const [common, toolkit, tools] = await importer();
81
-
82
- return {
83
- locale,
84
- direction: RTL_LOCALES.includes(locale) ? "rtl" : "ltr",
85
- translations: {
86
- ...flattenTranslations(common.default || common),
87
- ...flattenTranslations(toolkit.default || toolkit),
88
- ...flattenTranslations(tools.default || tools),
89
- },
90
- };
91
- } catch (error) {
92
- console.error(`Failed to load translations for locale: ${locale}`, error);
93
- throw new Error(
94
- `Translation files not found for locale: ${locale}. Ensure translation files exist in packages/players-shared/src/i18n/translations/${locale}/`,
95
- );
96
- }
97
- }
98
-
99
- /**
100
- * Flatten nested JSON to dot notation
101
- *
102
- * Converts:
103
- * { "common": { "save": "Save" } }
104
- *
105
- * To:
106
- * { "common.save": "Save" }
107
- *
108
- * @param obj Nested translation object
109
- * @param prefix Current key prefix
110
- * @param result Accumulated result
111
- * @returns Flattened translation object
112
- */
113
- function flattenTranslations(
114
- obj: any,
115
- prefix = "",
116
- result: Record<string, any> = {},
117
- ): Record<string, any> {
118
- for (const [key, value] of Object.entries(obj)) {
119
- const newKey = prefix ? `${prefix}.${key}` : key;
120
-
121
- if (value && typeof value === "object" && !Array.isArray(value)) {
122
- // Check if it's a plural form (has 'one' or 'other' keys)
123
- if ("one" in value || "other" in value) {
124
- // This is a plural translation, keep it as an object
125
- result[newKey] = value;
126
- } else {
127
- // This is a nested object, flatten recursively
128
- flattenTranslations(value, newKey, result);
129
- }
130
- } else {
131
- // This is a leaf value
132
- result[newKey] = value;
133
- }
134
- }
135
-
136
- return result;
137
- }
138
-
139
- /**
140
- * Get available locales
141
- *
142
- * @returns Array of locale codes
143
- */
144
- export function getAvailableLocales(): string[] {
145
- return ["en", "es", "zh", "ar"];
146
- }
147
-
148
- /**
149
- * Check if locale is RTL
150
- *
151
- * @param locale Locale code
152
- * @returns True if locale is right-to-left
153
- */
154
- export function isRTLLocale(locale: string): boolean {
155
- return RTL_LOCALES.includes(locale);
156
- }