@pugpigbolt/bridge 0.1.1 → 0.1.3
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/README.md +2 -2
- package/dist/chunks/bootstrap-B7Gwb_jl.mjs +1 -0
- package/dist/chunks/development-CzUmtUQR.mjs +1 -0
- package/dist/{index-BAapL0vP.d.mts → chunks/index-B2cNakTH.d.mts} +7 -108
- package/dist/chunks/mockBridgeService-M_48ewQL.mjs +27 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -19
- package/dist/vue.d.mts +9 -50
- package/dist/vue.mjs +1 -213
- package/package.json +2 -1
- package/dist/bootstrap-BzOJNz7-.mjs +0 -530
- package/dist/development-Bl8-5E3g.mjs +0 -56
- package/dist/mockBridgeService-vnaAIjCu.mjs +0 -272
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
//#region src/development/utils.ts
|
|
2
|
-
async function fetchJson(url, key) {
|
|
3
|
-
const json = await (await fetch(url)).json();
|
|
4
|
-
return key ? json?.[key] : json;
|
|
5
|
-
}
|
|
6
|
-
function triggerDownloadUpdates(editionId) {
|
|
7
|
-
let progress = 0;
|
|
8
|
-
let state = "idle";
|
|
9
|
-
if (window[editionId]) clearInterval(window[editionId]);
|
|
10
|
-
window[editionId] = setInterval(() => {
|
|
11
|
-
const isInComplete = progress <= 0;
|
|
12
|
-
const isComplete = progress >= 1;
|
|
13
|
-
state = isInComplete || isComplete ? "idle" : "downloading";
|
|
14
|
-
if (isComplete) clearInterval(window[editionId]);
|
|
15
|
-
window.pugpigUpdate("timeline", {
|
|
16
|
-
editionId,
|
|
17
|
-
state,
|
|
18
|
-
progress
|
|
19
|
-
});
|
|
20
|
-
progress += .05;
|
|
21
|
-
}, 500);
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/development/toast.ts
|
|
25
|
-
let toastContainer = null;
|
|
26
|
-
function getToastContainer() {
|
|
27
|
-
if (toastContainer) return toastContainer;
|
|
28
|
-
toastContainer = document.createElement("div");
|
|
29
|
-
toastContainer.id = "bridge-toast-container";
|
|
30
|
-
toastContainer.style.cssText = `
|
|
31
|
-
position: fixed;
|
|
32
|
-
top: 10px;
|
|
33
|
-
right: 10px;
|
|
34
|
-
z-index: 99999;
|
|
35
|
-
display: flex;
|
|
36
|
-
flex-direction: column;
|
|
37
|
-
gap: 8px;
|
|
38
|
-
pointer-events: none;
|
|
39
|
-
`;
|
|
40
|
-
document.body.appendChild(toastContainer);
|
|
41
|
-
return toastContainer;
|
|
42
|
-
}
|
|
43
|
-
function showToast(message, duration = 3e3) {
|
|
44
|
-
const container = getToastContainer();
|
|
45
|
-
const toast = document.createElement("div");
|
|
46
|
-
toast.style.cssText = `
|
|
47
|
-
background: #333;
|
|
48
|
-
color: #fff;
|
|
49
|
-
padding: 8px 12px;
|
|
50
|
-
border-radius: 4px;
|
|
51
|
-
font-size: 12px;
|
|
52
|
-
font-family: monospace;
|
|
53
|
-
max-width: 300px;
|
|
54
|
-
word-break: break-word;
|
|
55
|
-
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
|
|
56
|
-
animation: slideIn 0.3s ease;
|
|
57
|
-
pointer-events: auto;
|
|
58
|
-
`;
|
|
59
|
-
toast.textContent = message;
|
|
60
|
-
const style = document.createElement("style");
|
|
61
|
-
style.textContent = `
|
|
62
|
-
@keyframes slideIn {
|
|
63
|
-
from { transform: translateX(100%); opacity: 0; }
|
|
64
|
-
to { transform: translateX(0); opacity: 1; }
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
if (!document.querySelector("#bridge-toast-styles")) {
|
|
68
|
-
style.id = "bridge-toast-styles";
|
|
69
|
-
document.head.appendChild(style);
|
|
70
|
-
}
|
|
71
|
-
container.appendChild(toast);
|
|
72
|
-
setTimeout(() => {
|
|
73
|
-
toast.style.opacity = "0";
|
|
74
|
-
toast.style.transition = "opacity 0.3s ease";
|
|
75
|
-
setTimeout(() => toast.remove(), 300);
|
|
76
|
-
}, duration);
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/development/mockBridgeService.ts
|
|
80
|
-
function createPugpigBridgeService(config) {
|
|
81
|
-
return {
|
|
82
|
-
stories() {
|
|
83
|
-
window.stories = window.stories || createStories(config, config.stories);
|
|
84
|
-
return { stories: window.stories };
|
|
85
|
-
},
|
|
86
|
-
timeline() {
|
|
87
|
-
return {
|
|
88
|
-
progress: 0,
|
|
89
|
-
state: "idle"
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
timelines() {
|
|
93
|
-
window.timelines = window.timelines || config.timelines;
|
|
94
|
-
return window.timelines;
|
|
95
|
-
},
|
|
96
|
-
logInfo(payload) {
|
|
97
|
-
return console.info(JSON.parse(payload ?? "null"));
|
|
98
|
-
},
|
|
99
|
-
timelineInfo() {
|
|
100
|
-
const { themeUrl: themeURL, timelineType, metadata, debugLogs } = window.config ?? config;
|
|
101
|
-
const feedReference = (window.config ?? config).timeline;
|
|
102
|
-
return {
|
|
103
|
-
themeURL,
|
|
104
|
-
timelineType,
|
|
105
|
-
debugLogs,
|
|
106
|
-
metadata,
|
|
107
|
-
sourceURL: window.sourceURL || window.location.href,
|
|
108
|
-
feedReference
|
|
109
|
-
};
|
|
110
|
-
},
|
|
111
|
-
forwardTouchesWithin(payload) {
|
|
112
|
-
JSON.parse(payload ?? "[]").forEach((rect) => {
|
|
113
|
-
const div = document.createElement("div");
|
|
114
|
-
div.className = "forwardTouchesWithin";
|
|
115
|
-
div.style.position = "absolute";
|
|
116
|
-
div.style.width = rect.w + "px";
|
|
117
|
-
div.style.height = rect.h + "px";
|
|
118
|
-
div.style.top = rect.y + "px";
|
|
119
|
-
div.style.left = rect.x + "px";
|
|
120
|
-
div.style.outline = "3px solid red";
|
|
121
|
-
div.style.pointerEvents = "none";
|
|
122
|
-
document.body.appendChild(div);
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
clearForwardTouchesWithin() {
|
|
126
|
-
document.querySelectorAll(".forwardTouchesWithin").forEach((item) => item.remove());
|
|
127
|
-
},
|
|
128
|
-
issueAuthorisationStatus(feedids) {
|
|
129
|
-
return JSON.parse(feedids ?? "[]").reduce((obj, id) => {
|
|
130
|
-
obj[id] = true;
|
|
131
|
-
return obj;
|
|
132
|
-
}, {});
|
|
133
|
-
},
|
|
134
|
-
shouldViewWidget(_payload) {
|
|
135
|
-
return true;
|
|
136
|
-
},
|
|
137
|
-
viewArticle() {
|
|
138
|
-
console.log("eheheh");
|
|
139
|
-
},
|
|
140
|
-
startEditionDownload(p) {
|
|
141
|
-
const { editionId } = JSON.parse(p ?? "{}");
|
|
142
|
-
triggerDownloadUpdates(editionId);
|
|
143
|
-
},
|
|
144
|
-
deleteEdition(payload) {
|
|
145
|
-
const { editionId } = JSON.parse(payload ?? "{}");
|
|
146
|
-
window.pugpigUpdate("timeline", {
|
|
147
|
-
editionId,
|
|
148
|
-
state: "deleting"
|
|
149
|
-
});
|
|
150
|
-
setTimeout(() => window.pugpigUpdate("timeline", {
|
|
151
|
-
editionId,
|
|
152
|
-
state: "idle",
|
|
153
|
-
progress: 0
|
|
154
|
-
}), 1e3);
|
|
155
|
-
},
|
|
156
|
-
cancelEditionDownload(payload) {
|
|
157
|
-
const { editionId } = JSON.parse(payload ?? "{}");
|
|
158
|
-
if (window[editionId]) clearInterval(window[editionId]);
|
|
159
|
-
window.pugpigUpdate("timeline", {
|
|
160
|
-
editionId,
|
|
161
|
-
state: "idle",
|
|
162
|
-
progress: 0
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
timelinesInfo() {
|
|
166
|
-
const { theme, darkTheme, css, debugLogs, live_domain: baseurl } = window.config ?? config;
|
|
167
|
-
return {
|
|
168
|
-
baseurl,
|
|
169
|
-
filter: { ok: true },
|
|
170
|
-
css,
|
|
171
|
-
theme,
|
|
172
|
-
darkTheme,
|
|
173
|
-
debugLogs
|
|
174
|
-
};
|
|
175
|
-
},
|
|
176
|
-
storeGet(payload) {
|
|
177
|
-
const p = JSON.parse(payload ?? "null");
|
|
178
|
-
return localStorage.getItem(p);
|
|
179
|
-
},
|
|
180
|
-
storeSet(payload) {
|
|
181
|
-
const { key, value } = JSON.parse(payload ?? "{}");
|
|
182
|
-
const z = localStorage.setItem(key, value);
|
|
183
|
-
setTimeout(() => window.pugpigUpdate("storeGet", { key }), 200);
|
|
184
|
-
return z;
|
|
185
|
-
},
|
|
186
|
-
localeInfo() {
|
|
187
|
-
const { globalDir } = window.config ?? config;
|
|
188
|
-
return {
|
|
189
|
-
locale: "en_GB",
|
|
190
|
-
direction: globalDir
|
|
191
|
-
};
|
|
192
|
-
},
|
|
193
|
-
trackAnalyticsEvent(payload) {
|
|
194
|
-
return JSON.parse(payload ?? "null");
|
|
195
|
-
},
|
|
196
|
-
updateTime() {
|
|
197
|
-
return {
|
|
198
|
-
dateTime: Date.now(),
|
|
199
|
-
lastCheckedDateTime: Date.now()
|
|
200
|
-
};
|
|
201
|
-
},
|
|
202
|
-
authorisationStatus(_payload) {
|
|
203
|
-
return {
|
|
204
|
-
state: "active",
|
|
205
|
-
userInfo: {}
|
|
206
|
-
};
|
|
207
|
-
},
|
|
208
|
-
savedStories() {
|
|
209
|
-
return { savedStories: window.saved || [] };
|
|
210
|
-
},
|
|
211
|
-
readStories() {
|
|
212
|
-
return { readStories: window.read || [] };
|
|
213
|
-
},
|
|
214
|
-
localizableString(payload) {
|
|
215
|
-
const { stringId, params } = JSON.parse(payload ?? "{}");
|
|
216
|
-
return params?.length ? `${stringId}(${params.join(", ")})` : stringId;
|
|
217
|
-
},
|
|
218
|
-
localizableRelativeTimeString(payload) {
|
|
219
|
-
const { datetime } = JSON.parse(payload ?? "{}");
|
|
220
|
-
return datetime ? new Date(datetime).toLocaleDateString() : null;
|
|
221
|
-
},
|
|
222
|
-
localizableDateTimeString(payload) {
|
|
223
|
-
const { datetime } = JSON.parse(payload ?? "{}");
|
|
224
|
-
return datetime ? new Date(datetime).toLocaleString() : null;
|
|
225
|
-
},
|
|
226
|
-
localizableQuantityString(payload) {
|
|
227
|
-
const { stringId, quantity } = JSON.parse(payload ?? "{}");
|
|
228
|
-
return `${stringId}(${quantity})`;
|
|
229
|
-
},
|
|
230
|
-
setSaved(payload) {
|
|
231
|
-
const { story, saved } = JSON.parse(payload ?? "{}");
|
|
232
|
-
window.saved = window.saved || [];
|
|
233
|
-
const index = window.saved.findIndex(([a, b]) => a === story.feedid && b === story.entry.id);
|
|
234
|
-
if (!saved && index > -1) window.saved.splice(index, 1);
|
|
235
|
-
if (saved) window.saved.push([story.feedid, story.entry.id]);
|
|
236
|
-
window.pugpigUpdate("savedStories");
|
|
237
|
-
},
|
|
238
|
-
setRead(payload) {
|
|
239
|
-
const { story } = JSON.parse(payload ?? "{}");
|
|
240
|
-
window.read = window.read || [];
|
|
241
|
-
window.read.push([story.feedid, story.entry.id]);
|
|
242
|
-
window.pugpigUpdate("readStories");
|
|
243
|
-
return JSON.parse(payload ?? "null");
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function createStories(config, stories) {
|
|
248
|
-
return stories.map((entry) => ({
|
|
249
|
-
feedid: config?.timeline?.id || "Bolt Timeline",
|
|
250
|
-
entry,
|
|
251
|
-
saved: false,
|
|
252
|
-
locked: true,
|
|
253
|
-
baseURL: config.live_domain
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
function createPugpigBridgeServiceProxy(config) {
|
|
257
|
-
const service = createPugpigBridgeService(config);
|
|
258
|
-
return new Proxy(service, { get(target, propKey) {
|
|
259
|
-
const prop = target[propKey];
|
|
260
|
-
if (typeof prop !== "function") return target[propKey];
|
|
261
|
-
return (...args) => {
|
|
262
|
-
const jsonValue = prop(args[0]) ?? null;
|
|
263
|
-
if (config.debugLogs && jsonValue) {
|
|
264
|
-
showToast(`${propKey} ${JSON.stringify(args)}`);
|
|
265
|
-
console.log(`%c[Pugpig Bridge Service]%c[${propKey}]`, "color: green;", "color: orange;", propKey, prop(args[0]));
|
|
266
|
-
}
|
|
267
|
-
return jsonValue ? JSON.stringify(jsonValue) : void 0;
|
|
268
|
-
};
|
|
269
|
-
} });
|
|
270
|
-
}
|
|
271
|
-
//#endregion
|
|
272
|
-
export { createPugpigBridgeServiceProxy as n, fetchJson as r, createPugpigBridgeService as t };
|