@c-technology/adaptive-ui 0.1.2 → 0.1.4
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/package.json +3 -4
- package/dist/index.cjs +0 -117
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -24
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-technology/adaptive-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Human-aware UI adaptation layer for web apps",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/index.esm.js",
|
|
7
7
|
"module": "./dist/index.esm.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": "./dist/index.esm.js",
|
|
12
|
-
"require": "./dist/index.
|
|
13
|
-
"types": "./dist/index.d.ts"
|
|
12
|
+
"require": "./dist/index.esm.js"
|
|
14
13
|
}
|
|
15
14
|
},
|
|
16
15
|
"files": [
|
package/dist/index.cjs
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
AdaptiveUI: () => AdaptiveUI,
|
|
24
|
-
focusMode: () => focusMode,
|
|
25
|
-
liteUI: () => liteUI,
|
|
26
|
-
useAdaptive: () => useAdaptive
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
|
-
// src/adaptive.ts
|
|
31
|
-
var AdaptiveUI = class {
|
|
32
|
-
constructor() {
|
|
33
|
-
this.context = /* @__PURE__ */ new Set();
|
|
34
|
-
this.strategies = [];
|
|
35
|
-
}
|
|
36
|
-
addContext(ctx) {
|
|
37
|
-
this.context.add(ctx);
|
|
38
|
-
}
|
|
39
|
-
has(ctx) {
|
|
40
|
-
return this.context.has(ctx);
|
|
41
|
-
}
|
|
42
|
-
strategy(strategy) {
|
|
43
|
-
this.strategies.push(strategy);
|
|
44
|
-
}
|
|
45
|
-
run() {
|
|
46
|
-
for (const s of this.strategies) {
|
|
47
|
-
if (s.conditions.every((c) => this.context.has(c))) {
|
|
48
|
-
s.actions();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
explain() {
|
|
53
|
-
return {
|
|
54
|
-
context: Array.from(this.context),
|
|
55
|
-
strategies: this.strategies.length
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// src/react.ts
|
|
61
|
-
var import_react = require("react");
|
|
62
|
-
|
|
63
|
-
// src/signals/network.ts
|
|
64
|
-
function detectSlowNetwork(onDetect) {
|
|
65
|
-
const connection = navigator.connection;
|
|
66
|
-
if (!connection) return;
|
|
67
|
-
if (connection.effectiveType === "2g" || connection.effectiveType === "slow-2g") {
|
|
68
|
-
onDetect();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// src/signals/battery.ts
|
|
73
|
-
async function detectLowBattery(onDetect) {
|
|
74
|
-
if (!("getBattery" in navigator)) return;
|
|
75
|
-
const battery = await navigator.getBattery();
|
|
76
|
-
if (battery.level < 0.2) {
|
|
77
|
-
onDetect();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// src/signals/behavior.ts
|
|
82
|
-
function detectImpatience(onDetect) {
|
|
83
|
-
let clicks = 0;
|
|
84
|
-
window.addEventListener("click", () => {
|
|
85
|
-
clicks++;
|
|
86
|
-
if (clicks >= 6) {
|
|
87
|
-
onDetect();
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// src/react.ts
|
|
93
|
-
function useAdaptive() {
|
|
94
|
-
const [adaptive] = (0, import_react.useState)(() => new AdaptiveUI());
|
|
95
|
-
(0, import_react.useEffect)(() => {
|
|
96
|
-
detectSlowNetwork(() => adaptive.addContext("slow-network"));
|
|
97
|
-
detectLowBattery(() => adaptive.addContext("low-battery"));
|
|
98
|
-
detectImpatience(() => adaptive.addContext("impatient"));
|
|
99
|
-
}, []);
|
|
100
|
-
return adaptive;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/strategies.ts
|
|
104
|
-
function liteUI() {
|
|
105
|
-
document.body.classList.add("ui-lite");
|
|
106
|
-
}
|
|
107
|
-
function focusMode() {
|
|
108
|
-
document.body.classList.add("ui-focus");
|
|
109
|
-
}
|
|
110
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
-
0 && (module.exports = {
|
|
112
|
-
AdaptiveUI,
|
|
113
|
-
focusMode,
|
|
114
|
-
liteUI,
|
|
115
|
-
useAdaptive
|
|
116
|
-
});
|
|
117
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/adaptive.ts","../src/react.ts","../src/signals/network.ts","../src/signals/battery.ts","../src/signals/behavior.ts","../src/strategies.ts"],"sourcesContent":["export { AdaptiveUI } from \"./adaptive\";\nexport { useAdaptive } from \"./react\";\nexport * from \"./strategies\";\n","export type Context =\n | \"slow-network\"\n | \"low-battery\"\n | \"impatient\"\n | \"new-user\";\n\ntype Strategy = {\n conditions: Context[];\n actions: () => void;\n};\n\nexport class AdaptiveUI {\n private context = new Set<Context>();\n private strategies: Strategy[] = [];\n\n addContext(ctx: Context) {\n this.context.add(ctx);\n }\n\n has(ctx: Context) {\n return this.context.has(ctx);\n }\n\n strategy(strategy: Strategy) {\n this.strategies.push(strategy);\n }\n\n run() {\n for (const s of this.strategies) {\n if (s.conditions.every(c => this.context.has(c))) {\n s.actions();\n }\n }\n }\n\n explain() {\n return {\n context: Array.from(this.context),\n strategies: this.strategies.length,\n };\n }\n}\n","import { useEffect, useState } from \"react\";\nimport { AdaptiveUI } from \"./adaptive\";\nimport { detectSlowNetwork } from \"./signals/network\";\nimport { detectLowBattery } from \"./signals/battery\";\nimport { detectImpatience } from \"./signals/behavior\";\n\nexport function useAdaptive() {\n const [adaptive] = useState(() => new AdaptiveUI());\n\n useEffect(() => {\n detectSlowNetwork(() => adaptive.addContext(\"slow-network\"));\n detectLowBattery(() => adaptive.addContext(\"low-battery\"));\n detectImpatience(() => adaptive.addContext(\"impatient\"));\n }, []);\n\n return adaptive;\n}\n","export function detectSlowNetwork(onDetect: () => void) {\n const connection = (navigator as any).connection;\n if (!connection) return;\n\n if (\n connection.effectiveType === \"2g\" ||\n connection.effectiveType === \"slow-2g\"\n ) {\n onDetect();\n }\n}\n","export async function detectLowBattery(onDetect: () => void) {\n if (!(\"getBattery\" in navigator)) return;\n\n const battery = await (navigator as any).getBattery();\n if (battery.level < 0.2) {\n onDetect();\n }\n}\n","export function detectImpatience(onDetect: () => void) {\n let clicks = 0;\n\n window.addEventListener(\"click\", () => {\n clicks++;\n if (clicks >= 6) {\n onDetect();\n }\n });\n}\n","export function liteUI() {\n document.body.classList.add(\"ui-lite\");\n}\n\nexport function focusMode() {\n document.body.classList.add(\"ui-focus\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,IAAM,aAAN,MAAiB;AAAA,EAAjB;AACL,SAAQ,UAAU,oBAAI,IAAa;AACnC,SAAQ,aAAyB,CAAC;AAAA;AAAA,EAElC,WAAW,KAAc;AACvB,SAAK,QAAQ,IAAI,GAAG;AAAA,EACtB;AAAA,EAEA,IAAI,KAAc;AAChB,WAAO,KAAK,QAAQ,IAAI,GAAG;AAAA,EAC7B;AAAA,EAEA,SAAS,UAAoB;AAC3B,SAAK,WAAW,KAAK,QAAQ;AAAA,EAC/B;AAAA,EAEA,MAAM;AACJ,eAAW,KAAK,KAAK,YAAY;AAC/B,UAAI,EAAE,WAAW,MAAM,OAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,GAAG;AAChD,UAAE,QAAQ;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA,EAEA,UAAU;AACR,WAAO;AAAA,MACL,SAAS,MAAM,KAAK,KAAK,OAAO;AAAA,MAChC,YAAY,KAAK,WAAW;AAAA,IAC9B;AAAA,EACF;AACF;;;ACzCA,mBAAoC;;;ACA7B,SAAS,kBAAkB,UAAsB;AACtD,QAAM,aAAc,UAAkB;AACtC,MAAI,CAAC,WAAY;AAEjB,MACE,WAAW,kBAAkB,QAC7B,WAAW,kBAAkB,WAC7B;AACA,aAAS;AAAA,EACX;AACF;;;ACVA,eAAsB,iBAAiB,UAAsB;AAC3D,MAAI,EAAE,gBAAgB,WAAY;AAElC,QAAM,UAAU,MAAO,UAAkB,WAAW;AACpD,MAAI,QAAQ,QAAQ,KAAK;AACvB,aAAS;AAAA,EACX;AACF;;;ACPO,SAAS,iBAAiB,UAAsB;AACrD,MAAI,SAAS;AAEb,SAAO,iBAAiB,SAAS,MAAM;AACrC;AACA,QAAI,UAAU,GAAG;AACf,eAAS;AAAA,IACX;AAAA,EACF,CAAC;AACH;;;AHHO,SAAS,cAAc;AAC5B,QAAM,CAAC,QAAQ,QAAI,uBAAS,MAAM,IAAI,WAAW,CAAC;AAElD,8BAAU,MAAM;AACd,sBAAkB,MAAM,SAAS,WAAW,cAAc,CAAC;AAC3D,qBAAiB,MAAM,SAAS,WAAW,aAAa,CAAC;AACzD,qBAAiB,MAAM,SAAS,WAAW,WAAW,CAAC;AAAA,EACzD,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;;;AIhBO,SAAS,SAAS;AACvB,WAAS,KAAK,UAAU,IAAI,SAAS;AACvC;AAEO,SAAS,YAAY;AAC1B,WAAS,KAAK,UAAU,IAAI,UAAU;AACxC;","names":[]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
type Context = "slow-network" | "low-battery" | "impatient" | "new-user";
|
|
2
|
-
type Strategy = {
|
|
3
|
-
conditions: Context[];
|
|
4
|
-
actions: () => void;
|
|
5
|
-
};
|
|
6
|
-
declare class AdaptiveUI {
|
|
7
|
-
private context;
|
|
8
|
-
private strategies;
|
|
9
|
-
addContext(ctx: Context): void;
|
|
10
|
-
has(ctx: Context): boolean;
|
|
11
|
-
strategy(strategy: Strategy): void;
|
|
12
|
-
run(): void;
|
|
13
|
-
explain(): {
|
|
14
|
-
context: Context[];
|
|
15
|
-
strategies: number;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
declare function useAdaptive(): AdaptiveUI;
|
|
20
|
-
|
|
21
|
-
declare function liteUI(): void;
|
|
22
|
-
declare function focusMode(): void;
|
|
23
|
-
|
|
24
|
-
export { AdaptiveUI, focusMode, liteUI, useAdaptive };
|