ds-one 0.1.11-alpha.7 → 0.1.11-alpha.9

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.
@@ -1,4 +1,120 @@
1
1
  // 2025-04-23-device.ts
2
2
  // Device detection and context utilities
3
3
 
4
- // TODO: Implement device detection utilities
4
+ export type DeviceType = "mobile" | "tablet" | "desktop";
5
+
6
+ export interface DeviceInfo {
7
+ isMobile: boolean;
8
+ isTablet: boolean;
9
+ isDesktop: boolean;
10
+ isTouchCapable: boolean;
11
+ deviceType: DeviceType;
12
+ userAgent: string;
13
+ screenWidth: number;
14
+ screenHeight: number;
15
+ }
16
+
17
+ /**
18
+ * Comprehensive mobile device detection
19
+ * Combines user agent detection, touch capability, and viewport size
20
+ */
21
+ export function detectMobileDevice(): boolean {
22
+ if (typeof navigator === "undefined" || typeof window === "undefined") {
23
+ return false;
24
+ }
25
+
26
+ const nav = navigator as any;
27
+ const win = window as any;
28
+ const ua: string =
29
+ (nav && (nav.userAgent || nav.vendor)) || (win && win.opera) || "";
30
+
31
+ // User agent based detection
32
+ const uaMatchesMobile =
33
+ /Mobile|Android|iP(ad|hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)|Windows Phone|Phone|Tablet/i.test(
34
+ ua
35
+ );
36
+
37
+ // Touch capability detection
38
+ const touchPoints = (nav && nav.maxTouchPoints) || 0;
39
+ const isTouchCapable = touchPoints > 1;
40
+
41
+ // Viewport detection
42
+ const narrowViewport = win
43
+ ? Math.min(win.innerWidth || 0, win.innerHeight || 0) <= 820
44
+ : false;
45
+
46
+ return uaMatchesMobile || (isTouchCapable && narrowViewport);
47
+ }
48
+
49
+ /**
50
+ * Get detailed device information
51
+ */
52
+ export function getDeviceInfo(): DeviceInfo {
53
+ const isMobile = detectMobileDevice();
54
+ const nav = navigator as any;
55
+ const win = window as any;
56
+
57
+ const touchPoints = (nav && nav.maxTouchPoints) || 0;
58
+ const isTouchCapable = touchPoints > 1;
59
+
60
+ const screenWidth = win?.innerWidth || 0;
61
+ const screenHeight = win?.innerHeight || 0;
62
+ const isTablet = isMobile && Math.min(screenWidth, screenHeight) >= 600;
63
+
64
+ return {
65
+ isMobile,
66
+ isTablet,
67
+ isDesktop: !isMobile,
68
+ isTouchCapable,
69
+ deviceType: isMobile ? (isTablet ? "tablet" : "mobile") : "desktop",
70
+ userAgent: (nav && (nav.userAgent || nav.vendor)) || "",
71
+ screenWidth,
72
+ screenHeight,
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Initialize device detection and log to console
78
+ */
79
+ export function initDeviceDetection(): DeviceInfo {
80
+ const deviceInfo = getDeviceInfo();
81
+
82
+ // Log device detection results
83
+ if (deviceInfo.isMobile) {
84
+ console.log(
85
+ `[DS one] Mobile device detected - ${deviceInfo.deviceType} (${deviceInfo.screenWidth}x${deviceInfo.screenHeight})`
86
+ );
87
+ } else {
88
+ console.log(
89
+ `[DS one] Desktop device detected (${deviceInfo.screenWidth}x${deviceInfo.screenHeight})`
90
+ );
91
+ }
92
+
93
+ // Log additional details in development mode
94
+ if (typeof window !== "undefined" && (window as any).DS_ONE_DEBUG) {
95
+ console.log("[DS one] Device Info:", {
96
+ type: deviceInfo.deviceType,
97
+ isMobile: deviceInfo.isMobile,
98
+ isTablet: deviceInfo.isTablet,
99
+ isDesktop: deviceInfo.isDesktop,
100
+ isTouchCapable: deviceInfo.isTouchCapable,
101
+ viewport: `${deviceInfo.screenWidth}x${deviceInfo.screenHeight}`,
102
+ userAgent: deviceInfo.userAgent,
103
+ });
104
+ }
105
+
106
+ return deviceInfo;
107
+ }
108
+
109
+ // Auto-initialize when module loads
110
+ if (typeof window !== "undefined") {
111
+ // Wait for DOM to be ready
112
+ if (document.readyState === "loading") {
113
+ document.addEventListener("DOMContentLoaded", () => {
114
+ initDeviceDetection();
115
+ });
116
+ } else {
117
+ // DOM is already ready
118
+ initDeviceDetection();
119
+ }
120
+ }
@@ -1,4 +1,4 @@
1
- /* version 0.1.11-alpha.7 */
1
+ /* version 0.1.11-alpha.8 */
2
2
 
3
3
  input {
4
4
  padding: 0;
package/DS1/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  // DS one - Main entry point for all components
2
2
  // Export all components for easy importing
3
3
 
4
+ // Initialize device detection (will auto-detect and log on load)
5
+ import "./0-face/2025-04-23-device";
6
+
4
7
  // Initialize CDN loader (will auto-load external translations if available)
5
8
  import "./utils/cdn-loader";
6
9
 
@@ -42,3 +45,6 @@ export * from "./utils/viewMode";
42
45
  export * from "./utils/settings";
43
46
  export * from "./utils/pricing";
44
47
  export * from "./utils/scroll";
48
+
49
+ // Device detection
50
+ export * from "./0-face/2025-04-23-device";
@@ -124,13 +124,16 @@ async function fetchTranslationFile(
124
124
  source: string
125
125
  ): Promise<TranslationMap | null> {
126
126
  try {
127
+ console.log(`[DS one] Attempting to fetch translations from: ${source}`);
127
128
  const response = await fetch(source);
128
129
 
129
130
  if (!response.ok) {
131
+ console.log(`[DS one] Failed to fetch ${source} (${response.status})`);
130
132
  return null;
131
133
  }
132
134
 
133
135
  const translations = await response.json();
136
+ console.log(`[DS one] Successfully fetched JSON from ${source}`);
134
137
 
135
138
  if (!validateTranslationMap(translations)) {
136
139
  console.warn(
@@ -145,12 +148,14 @@ async function fetchTranslationFile(
145
148
  return null;
146
149
  }
147
150
 
151
+ console.log(`[DS one] Valid translations found: ${languages.join(", ")}`);
148
152
  return translations;
149
153
  } catch (error) {
150
154
  if (
151
155
  error instanceof TypeError &&
152
156
  error.message.includes("Failed to fetch")
153
157
  ) {
158
+ console.log(`[DS one] Network error fetching ${source}`);
154
159
  return null;
155
160
  }
156
161
 
@@ -1 +1,41 @@
1
- {}
1
+ {
2
+ "en": {
3
+ "language": "Language",
4
+ "theme": "Theme",
5
+ "home": "Home",
6
+ "about": "About",
7
+ "contact": "Contact",
8
+ "welcome": "Welcome",
9
+ "description": "Description",
10
+ "learnMore": "Learn More",
11
+ "copyright": "© 2025",
12
+ "siteTitle": "Site Title",
13
+ "downloadCV": "Download CV"
14
+ },
15
+ "da": {
16
+ "language": "Sprog",
17
+ "theme": "Tema",
18
+ "home": "Hjem",
19
+ "about": "Om",
20
+ "contact": "Kontakt",
21
+ "welcome": "Velkommen",
22
+ "description": "Beskrivelse",
23
+ "learnMore": "Lær Mere",
24
+ "copyright": "© 2025",
25
+ "siteTitle": "Site Titel",
26
+ "downloadCV": "Download CV"
27
+ },
28
+ "ja": {
29
+ "language": "言語",
30
+ "theme": "テーマ",
31
+ "home": "ホーム",
32
+ "about": "について",
33
+ "contact": "お問い合わせ",
34
+ "welcome": "ようこそ",
35
+ "description": "説明",
36
+ "learnMore": "詳細を見る",
37
+ "copyright": "© 2025",
38
+ "siteTitle": "サイトタイトル",
39
+ "downloadCV": "CVをダウンロード"
40
+ }
41
+ }
package/README.md CHANGED
@@ -27,7 +27,7 @@ npm install ds-one@alpha
27
27
  yarn add ds-one@alpha
28
28
  ```
29
29
 
30
- **Note**: Currently published as alpha version `0.1.11-alpha.7`. Use `@alpha` tag to install.
30
+ **Note**: Currently published as alpha version `0.1.11-alpha.9`. Use `@alpha` tag to install.
31
31
 
32
32
  ### Basic Usage
33
33
 
@@ -1 +1,25 @@
1
+ export type DeviceType = "mobile" | "tablet" | "desktop";
2
+ export interface DeviceInfo {
3
+ isMobile: boolean;
4
+ isTablet: boolean;
5
+ isDesktop: boolean;
6
+ isTouchCapable: boolean;
7
+ deviceType: DeviceType;
8
+ userAgent: string;
9
+ screenWidth: number;
10
+ screenHeight: number;
11
+ }
12
+ /**
13
+ * Comprehensive mobile device detection
14
+ * Combines user agent detection, touch capability, and viewport size
15
+ */
16
+ export declare function detectMobileDevice(): boolean;
17
+ /**
18
+ * Get detailed device information
19
+ */
20
+ export declare function getDeviceInfo(): DeviceInfo;
21
+ /**
22
+ * Initialize device detection and log to console
23
+ */
24
+ export declare function initDeviceDetection(): DeviceInfo;
1
25
  //# sourceMappingURL=2025-04-23-device.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"2025-04-23-device.d.ts","sourceRoot":"","sources":["../../DS1/0-face/2025-04-23-device.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"2025-04-23-device.d.ts","sourceRoot":"","sources":["../../DS1/0-face/2025-04-23-device.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzD,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CA0B5C;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAsB1C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,UAAU,CA4BhD"}
@@ -1,3 +1,86 @@
1
1
  // 2025-04-23-device.ts
2
2
  // Device detection and context utilities
3
- // TODO: Implement device detection utilities
3
+ /**
4
+ * Comprehensive mobile device detection
5
+ * Combines user agent detection, touch capability, and viewport size
6
+ */
7
+ export function detectMobileDevice() {
8
+ if (typeof navigator === "undefined" || typeof window === "undefined") {
9
+ return false;
10
+ }
11
+ const nav = navigator;
12
+ const win = window;
13
+ const ua = (nav && (nav.userAgent || nav.vendor)) || (win && win.opera) || "";
14
+ // User agent based detection
15
+ const uaMatchesMobile = /Mobile|Android|iP(ad|hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)|Windows Phone|Phone|Tablet/i.test(ua);
16
+ // Touch capability detection
17
+ const touchPoints = (nav && nav.maxTouchPoints) || 0;
18
+ const isTouchCapable = touchPoints > 1;
19
+ // Viewport detection
20
+ const narrowViewport = win
21
+ ? Math.min(win.innerWidth || 0, win.innerHeight || 0) <= 820
22
+ : false;
23
+ return uaMatchesMobile || (isTouchCapable && narrowViewport);
24
+ }
25
+ /**
26
+ * Get detailed device information
27
+ */
28
+ export function getDeviceInfo() {
29
+ const isMobile = detectMobileDevice();
30
+ const nav = navigator;
31
+ const win = window;
32
+ const touchPoints = (nav && nav.maxTouchPoints) || 0;
33
+ const isTouchCapable = touchPoints > 1;
34
+ const screenWidth = win?.innerWidth || 0;
35
+ const screenHeight = win?.innerHeight || 0;
36
+ const isTablet = isMobile && Math.min(screenWidth, screenHeight) >= 600;
37
+ return {
38
+ isMobile,
39
+ isTablet,
40
+ isDesktop: !isMobile,
41
+ isTouchCapable,
42
+ deviceType: isMobile ? (isTablet ? "tablet" : "mobile") : "desktop",
43
+ userAgent: (nav && (nav.userAgent || nav.vendor)) || "",
44
+ screenWidth,
45
+ screenHeight,
46
+ };
47
+ }
48
+ /**
49
+ * Initialize device detection and log to console
50
+ */
51
+ export function initDeviceDetection() {
52
+ const deviceInfo = getDeviceInfo();
53
+ // Log device detection results
54
+ if (deviceInfo.isMobile) {
55
+ console.log(`[DS one] Mobile device detected - ${deviceInfo.deviceType} (${deviceInfo.screenWidth}x${deviceInfo.screenHeight})`);
56
+ }
57
+ else {
58
+ console.log(`[DS one] Desktop device detected (${deviceInfo.screenWidth}x${deviceInfo.screenHeight})`);
59
+ }
60
+ // Log additional details in development mode
61
+ if (typeof window !== "undefined" && window.DS_ONE_DEBUG) {
62
+ console.log("[DS one] Device Info:", {
63
+ type: deviceInfo.deviceType,
64
+ isMobile: deviceInfo.isMobile,
65
+ isTablet: deviceInfo.isTablet,
66
+ isDesktop: deviceInfo.isDesktop,
67
+ isTouchCapable: deviceInfo.isTouchCapable,
68
+ viewport: `${deviceInfo.screenWidth}x${deviceInfo.screenHeight}`,
69
+ userAgent: deviceInfo.userAgent,
70
+ });
71
+ }
72
+ return deviceInfo;
73
+ }
74
+ // Auto-initialize when module loads
75
+ if (typeof window !== "undefined") {
76
+ // Wait for DOM to be ready
77
+ if (document.readyState === "loading") {
78
+ document.addEventListener("DOMContentLoaded", () => {
79
+ initDeviceDetection();
80
+ });
81
+ }
82
+ else {
83
+ // DOM is already ready
84
+ initDeviceDetection();
85
+ }
86
+ }
@@ -1,3 +1,67 @@
1
+ // dist/0-face/2025-04-23-device.js
2
+ function detectMobileDevice() {
3
+ if (typeof navigator === "undefined" || typeof window === "undefined") {
4
+ return false;
5
+ }
6
+ const nav = navigator;
7
+ const win = window;
8
+ const ua = nav && (nav.userAgent || nav.vendor) || win && win.opera || "";
9
+ const uaMatchesMobile = /Mobile|Android|iP(ad|hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)|Windows Phone|Phone|Tablet/i.test(ua);
10
+ const touchPoints = nav && nav.maxTouchPoints || 0;
11
+ const isTouchCapable = touchPoints > 1;
12
+ const narrowViewport = win ? Math.min(win.innerWidth || 0, win.innerHeight || 0) <= 820 : false;
13
+ return uaMatchesMobile || isTouchCapable && narrowViewport;
14
+ }
15
+ function getDeviceInfo() {
16
+ const isMobile = detectMobileDevice();
17
+ const nav = navigator;
18
+ const win = window;
19
+ const touchPoints = nav && nav.maxTouchPoints || 0;
20
+ const isTouchCapable = touchPoints > 1;
21
+ const screenWidth = win?.innerWidth || 0;
22
+ const screenHeight = win?.innerHeight || 0;
23
+ const isTablet = isMobile && Math.min(screenWidth, screenHeight) >= 600;
24
+ return {
25
+ isMobile,
26
+ isTablet,
27
+ isDesktop: !isMobile,
28
+ isTouchCapable,
29
+ deviceType: isMobile ? isTablet ? "tablet" : "mobile" : "desktop",
30
+ userAgent: nav && (nav.userAgent || nav.vendor) || "",
31
+ screenWidth,
32
+ screenHeight
33
+ };
34
+ }
35
+ function initDeviceDetection() {
36
+ const deviceInfo = getDeviceInfo();
37
+ if (deviceInfo.isMobile) {
38
+ console.log(`[DS one] Mobile device detected - ${deviceInfo.deviceType} (${deviceInfo.screenWidth}x${deviceInfo.screenHeight})`);
39
+ } else {
40
+ console.log(`[DS one] Desktop device detected (${deviceInfo.screenWidth}x${deviceInfo.screenHeight})`);
41
+ }
42
+ if (typeof window !== "undefined" && window.DS_ONE_DEBUG) {
43
+ console.log("[DS one] Device Info:", {
44
+ type: deviceInfo.deviceType,
45
+ isMobile: deviceInfo.isMobile,
46
+ isTablet: deviceInfo.isTablet,
47
+ isDesktop: deviceInfo.isDesktop,
48
+ isTouchCapable: deviceInfo.isTouchCapable,
49
+ viewport: `${deviceInfo.screenWidth}x${deviceInfo.screenHeight}`,
50
+ userAgent: deviceInfo.userAgent
51
+ });
52
+ }
53
+ return deviceInfo;
54
+ }
55
+ if (typeof window !== "undefined") {
56
+ if (document.readyState === "loading") {
57
+ document.addEventListener("DOMContentLoaded", () => {
58
+ initDeviceDetection();
59
+ });
60
+ } else {
61
+ initDeviceDetection();
62
+ }
63
+ }
64
+
1
65
  // dist/utils/cdn-loader.js
2
66
  var loadAttempted = false;
3
67
  var DEFAULT_TRANSLATION_FILES = [
@@ -69,11 +133,14 @@ function validateTranslationMap(candidate) {
69
133
  }
70
134
  async function fetchTranslationFile(source) {
71
135
  try {
136
+ console.log(`[DS one] Attempting to fetch translations from: ${source}`);
72
137
  const response = await fetch(source);
73
138
  if (!response.ok) {
139
+ console.log(`[DS one] Failed to fetch ${source} (${response.status})`);
74
140
  return null;
75
141
  }
76
142
  const translations = await response.json();
143
+ console.log(`[DS one] Successfully fetched JSON from ${source}`);
77
144
  if (!validateTranslationMap(translations)) {
78
145
  console.warn(`[DS one] Invalid translation format in ${source}. Expected object with language codes as keys.`);
79
146
  return null;
@@ -83,9 +150,11 @@ async function fetchTranslationFile(source) {
83
150
  console.warn(`[DS one] No languages found in ${source}`);
84
151
  return null;
85
152
  }
153
+ console.log(`[DS one] Valid translations found: ${languages.join(", ")}`);
86
154
  return translations;
87
155
  } catch (error) {
88
156
  if (error instanceof TypeError && error.message.includes("Failed to fetch")) {
157
+ console.log(`[DS one] Network error fetching ${source}`);
89
158
  return null;
90
159
  }
91
160
  console.error(`[DS one] Error loading external translations from ${source}:`, error);
@@ -681,7 +750,47 @@ o4?.({ LitElement: i4 });
681
750
  (s3.litElementVersions ?? (s3.litElementVersions = [])).push("4.2.1");
682
751
 
683
752
  // dist/utils/keys.json
684
- var keys_default = {};
753
+ var keys_default = {
754
+ en: {
755
+ language: "Language",
756
+ theme: "Theme",
757
+ home: "Home",
758
+ about: "About",
759
+ contact: "Contact",
760
+ welcome: "Welcome",
761
+ description: "Description",
762
+ learnMore: "Learn More",
763
+ copyright: "\xA9 2025",
764
+ siteTitle: "Site Title",
765
+ downloadCV: "Download CV"
766
+ },
767
+ da: {
768
+ language: "Sprog",
769
+ theme: "Tema",
770
+ home: "Hjem",
771
+ about: "Om",
772
+ contact: "Kontakt",
773
+ welcome: "Velkommen",
774
+ description: "Beskrivelse",
775
+ learnMore: "L\xE6r Mere",
776
+ copyright: "\xA9 2025",
777
+ siteTitle: "Site Titel",
778
+ downloadCV: "Download CV"
779
+ },
780
+ ja: {
781
+ language: "\u8A00\u8A9E",
782
+ theme: "\u30C6\u30FC\u30DE",
783
+ home: "\u30DB\u30FC\u30E0",
784
+ about: "\u306B\u3064\u3044\u3066",
785
+ contact: "\u304A\u554F\u3044\u5408\u308F\u305B",
786
+ welcome: "\u3088\u3046\u3053\u305D",
787
+ description: "\u8AAC\u660E",
788
+ learnMore: "\u8A73\u7D30\u3092\u898B\u308B",
789
+ copyright: "\xA9 2025",
790
+ siteTitle: "\u30B5\u30A4\u30C8\u30BF\u30A4\u30C8\u30EB",
791
+ downloadCV: "CV\u3092\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9"
792
+ }
793
+ };
685
794
 
686
795
  // dist/utils/language.js
687
796
  var LANGUAGE_PRIORITY_ORDER = [
@@ -4969,9 +5078,11 @@ export {
4969
5078
  clearScrollPosition,
4970
5079
  currentLanguage,
4971
5080
  currentTheme,
5081
+ detectMobileDevice,
4972
5082
  getAvailableLanguages,
4973
5083
  getAvailableLanguagesSync,
4974
5084
  getBrowserLanguage,
5085
+ getDeviceInfo,
4975
5086
  getLanguageDisplayName,
4976
5087
  getNotionText,
4977
5088
  getPriceLabel,
@@ -4979,6 +5090,7 @@ export {
4979
5090
  getText,
4980
5091
  getViewMode,
4981
5092
  hasTranslation,
5093
+ initDeviceDetection,
4982
5094
  initScrollManagement,
4983
5095
  loadTranslations,
4984
5096
  restoreScrollPosition,