wowojs-cdn 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/wowo.min.js +7 -0
  2. package/package.json +21 -0
  3. package/wowo.js +227 -0
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Wowojs v1.2.1
3
+ * @license MIT
4
+ * @author Devied Rahmadsyah
5
+ */
6
+
7
+ !function(){"use strict";function t(t,e){a({modul:"State: $antek2",detail:{nama:t,value:e}});const n=sessionStorage.getItem(t);let o=null;try{if(null!==n&&(o=JSON.parse(n)),"function"==typeof e){const a=e(o);return sessionStorage.setItem(t,JSON.stringify(a)),a}return 1===arguments.length?o:(sessionStorage.setItem(t,JSON.stringify(e)),e)}catch(r){if(console.error(`Gagal memproses JSON untuk "${t}", mereset data...`,r),arguments.length>1){const a="function"==typeof e?e(null):e;return sessionStorage.setItem(t,JSON.stringify(a)),a}return null}}function e(t){const e=document.querySelector(t);e&&"function"==typeof e.render?e.render():document.addEventListener("DOMContentLoaded",()=>{e&&e.render()},{once:!0})}function a({modul:t,detail:e,aktif:a=!1}){history.push({waktu:(new Date).toLocaleTimeString(),modul:t,detail:e}),a&&console.dir(history)}window.$BuatWilayah=function({namaWilayah:t,isiWilayah:e,style:n="",methods:o={},deskripsi:r}){a({modul:"Component: $BuatWilayah",detail:{namaWilayah:t,isiWilayah:e,style:n||"tidak ada",methods:o||"tidak ada",deskripsi:r||"tidak ada"}});const i=`wowo-${t.toLowerCase()}`;customElements.get(i)||customElements.define(i,class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){this.render()}getProps(){const t={};for(let e of this.attributes)t[e.name]=e.value;return t}render(){const t=this.getProps(),a="function"==typeof e?e(t):e;let r=n?`<style>${n}</style>`:"";this.shadowRoot.innerHTML=a+r;this.shadowRoot.querySelectorAll("*").forEach(e=>{[...e.attributes].forEach(a=>{if(a.name.startsWith("@")){const n=a.name.slice(1),r=a.value.replace("()","");o[r]&&(e.addEventListener(n,e=>{o[r](e,t),this.render()}),e.removeAttribute(a.name))}})})}})},window.$antek2=t,window.$PecatAntek2=function(t){a({modul:"State: $PecatAntek2",detail:{nama:t}}),"string"==typeof t&&t.trim()||console.warn(`Nama tidak valid: ${t}`),null===sessionStorage.getItem(t)&&console.info(`Key "${t}" tidak ditemukan, tidak ada yang dihapus.`);try{sessionStorage.removeItem(t)}catch(e){console.error(`Gagal menghapus ${t}:`,e)}},window.$BangunEkonomi=function(t){a({modul:"Render: $BangunEkonomi",detail:t}),Array.isArray(t)?t.forEach(t=>{e(t)}):e(t)},window.$UrusKeuangan=function(t,e){a({modul:"Reducer: $UrusKeuangan",detail:[{reducer:t,action:e}]});try{return t(e)}catch(n){console.error(`terjadi error ${t} \n ${n}`)}},window.$CuriData=async function({data:e,state:n,request:o,reload:r=!1}){try{const i=await fetch(e,o);if(!i.ok)throw new Error(`Status: ${i.status}`);const s=await i.json();if(!s||"object"!=typeof s&&!Array.isArray(s))throw new Error(`Data ${e} bukan JSON kocak`);t(n,s),a({modul:"API: $CuriData",detail:{data:e,state:n}}),r&&location.reload()}catch(i){console.error(`Gagal curi data ${e}\n ${i}`)}},window.$Sejarah=a}();
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "wowojs-cdn",
3
+ "version": "1.0.0",
4
+ "description": "Akses wowojs lewat CDN",
5
+ "main": "wowo.js",
6
+ "unpkg": "dist/wowo.min.js",
7
+ "jsdelivr": "dist/wowo.min.js",
8
+ "scripts": {
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "build": "vite build"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "vite": "^7.3.1"
17
+ },
18
+ "devDependencies": {
19
+ "terser": "^5.46.0"
20
+ }
21
+ }
package/wowo.js ADDED
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Wowojs v1.2.1
3
+ * @license MIT
4
+ * @author Devied Rahmadsyah
5
+ */
6
+
7
+ function $BuatWilayah({
8
+ namaWilayah,
9
+ isiWilayah,
10
+ style = "",
11
+ methods = {},
12
+ deskripsi,
13
+ }) {
14
+ $Sejarah({
15
+ modul: "Component: $BuatWilayah",
16
+ detail: {
17
+ namaWilayah,
18
+ isiWilayah,
19
+ style: style || "tidak ada",
20
+ methods: methods || "tidak ada",
21
+ deskripsi: deskripsi || "tidak ada",
22
+ },
23
+ });
24
+
25
+ const tagName = `wowo-${namaWilayah.toLowerCase()}`;
26
+ if (customElements.get(tagName)) return;
27
+
28
+ customElements.define(
29
+ tagName,
30
+ class extends HTMLElement {
31
+ constructor() {
32
+ super();
33
+ this.attachShadow({ mode: "open" });
34
+ }
35
+
36
+ connectedCallback() {
37
+ this.render();
38
+ }
39
+
40
+ getProps() {
41
+ const props = {};
42
+ for (let attr of this.attributes) {
43
+ props[attr.name] = attr.value;
44
+ }
45
+ return props;
46
+ }
47
+
48
+ render() {
49
+ const props = this.getProps();
50
+ const konten =
51
+ typeof isiWilayah === "function" ? isiWilayah(props) : isiWilayah;
52
+ let css = style ? `<style>${style}</style>` : "";
53
+ this.shadowRoot.innerHTML = konten + css;
54
+
55
+ const allElements = this.shadowRoot.querySelectorAll("*");
56
+
57
+ allElements.forEach((el) => {
58
+ [...el.attributes].forEach((attr) => {
59
+ if (attr.name.startsWith("@")) {
60
+ const eventType = attr.name.slice(1);
61
+ const functionName = attr.value.replace("()", "");
62
+
63
+ if (methods[functionName]) {
64
+ el.addEventListener(eventType, (e) => {
65
+ methods[functionName](e, props);
66
+ this.render();
67
+ });
68
+
69
+ el.removeAttribute(attr.name);
70
+ }
71
+ }
72
+ });
73
+ });
74
+ }
75
+ },
76
+ );
77
+ }
78
+
79
+ function $antek2(name, value) {
80
+ $Sejarah({
81
+ modul: "State: $antek2",
82
+ detail: {
83
+ nama: name,
84
+ value: value,
85
+ },
86
+ });
87
+ const dataLama = sessionStorage.getItem(name);
88
+ let parsedLama = null;
89
+
90
+ try {
91
+ if (dataLama !== null) {
92
+ parsedLama = JSON.parse(dataLama);
93
+ }
94
+
95
+ if (typeof value === "function") {
96
+ const newValue = value(parsedLama);
97
+ sessionStorage.setItem(name, JSON.stringify(newValue));
98
+ return newValue;
99
+ } else if (arguments.length === 1) {
100
+ return parsedLama;
101
+ } else {
102
+ sessionStorage.setItem(name, JSON.stringify(value));
103
+ return value;
104
+ }
105
+ } catch (e) {
106
+ console.error(`Gagal memproses JSON untuk "${name}", mereset data...`, e);
107
+ if (arguments.length > 1) {
108
+ const defaultValue = typeof value === "function" ? value(null) : value;
109
+ sessionStorage.setItem(name, JSON.stringify(defaultValue));
110
+ return defaultValue;
111
+ }
112
+ return null;
113
+ }
114
+ }
115
+
116
+ function $PecatAntek2(name) {
117
+ $Sejarah({
118
+ modul: "State: $PecatAntek2",
119
+ detail: {
120
+ nama: name,
121
+ },
122
+ });
123
+ if (typeof name !== "string" || !name.trim()) {
124
+ console.warn(`Nama tidak valid: ${name}`);
125
+ }
126
+
127
+ if (sessionStorage.getItem(name) === null) {
128
+ console.info(`Key "${name}" tidak ditemukan, tidak ada yang dihapus.`);
129
+ }
130
+
131
+ try {
132
+ sessionStorage.removeItem(name);
133
+ } catch (e) {
134
+ console.error(`Gagal menghapus ${name}:`, e);
135
+ }
136
+ }
137
+
138
+ function $UrusKeuangan(reducer, action) {
139
+ $Sejarah({
140
+ modul: "Reducer: $UrusKeuangan",
141
+ detail: [
142
+ {
143
+ reducer: reducer,
144
+ action: action,
145
+ },
146
+ ],
147
+ });
148
+ try {
149
+ return reducer(action);
150
+ } catch (error) {
151
+ console.error(`terjadi error ${reducer}
152
+ ${error}`);
153
+ }
154
+ }
155
+
156
+ function $BangunEkonomi(components) {
157
+ $Sejarah({
158
+ modul: "Render: $BangunEkonomi",
159
+ detail: components,
160
+ });
161
+ if (Array.isArray(components)) {
162
+ components.forEach((comp) => {
163
+ const selector = typeof comp === "string" ? comp : comp;
164
+ eksekusi(selector);
165
+ });
166
+ } else {
167
+ eksekusi(components);
168
+ }
169
+ }
170
+ function eksekusi(components) {
171
+ const element = document.querySelector(components);
172
+ if (element && typeof element.render === "function") {
173
+ element.render();
174
+ } else {
175
+ document.addEventListener(
176
+ "DOMContentLoaded",
177
+ () => {
178
+ if (element) element.render();
179
+ },
180
+ { once: true },
181
+ );
182
+ }
183
+ }
184
+
185
+ async function $CuriData({ data, state, request, reload = false }) {
186
+ try {
187
+ const response = await fetch(data, request);
188
+ if (!response.ok) {
189
+ throw new Error(`Status: ${response.status}`);
190
+ }
191
+ const json = await response.json();
192
+ if (!json || (typeof json !== "object" && !Array.isArray(json))) {
193
+ throw new Error(`Data ${data} bukan JSON kocak`);
194
+ }
195
+ $antek2(state, json);
196
+ $Sejarah({
197
+ modul: "API: $CuriData",
198
+ detail: {
199
+ data: data,
200
+ state: state,
201
+ },
202
+ });
203
+ if (reload) location.reload();
204
+ } catch (e) {
205
+ console.error(`Gagal curi data ${data}
206
+ ${e}`);
207
+ }
208
+ }
209
+
210
+ function $Sejarah({ modul, detail, aktif = false }) {
211
+ history.push({
212
+ waktu: new Date().toLocaleTimeString(),
213
+ modul,
214
+ detail,
215
+ });
216
+ if (aktif) {
217
+ console.dir(history);
218
+ }
219
+ }
220
+
221
+ window.$BuatWilayah = $BuatWilayah;
222
+ window.$antek2 = $antek2;
223
+ window.$PecatAntek2 = $PecatAntek2;
224
+ window.$BangunEkonomi = $BangunEkonomi;
225
+ window.$UrusKeuangan = $UrusKeuangan;
226
+ window.$CuriData = $CuriData;
227
+ window.$Sejarah = $Sejarah;