lightview 1.7.1-b → 1.8.1-b

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 (49) hide show
  1. package/README.md +2 -2
  2. package/components/chart/chart.html +7 -5
  3. package/components/chart/example.html +3 -5
  4. package/components/chart.html +67 -65
  5. package/components/components.js +29 -9
  6. package/components/gantt/example.html +2 -7
  7. package/components/gantt/gantt.html +33 -26
  8. package/components/gauge/example.html +1 -1
  9. package/components/gauge/gauge.html +20 -0
  10. package/components/gauge.html +47 -44
  11. package/components/orgchart/example.html +25 -0
  12. package/components/orgchart/orgchart.html +41 -0
  13. package/components/repl/code-editor.html +64 -0
  14. package/components/repl/editor.html +37 -0
  15. package/components/repl/editorjs-inline-tool/index.js +3 -0
  16. package/components/repl/editorjs-inline-tool/inline-tools.js +28 -0
  17. package/components/repl/editorjs-inline-tool/tool.js +175 -0
  18. package/components/repl/repl-with-wysiwyg.html +355 -0
  19. package/components/repl/repl.html +345 -0
  20. package/components/repl/sup.js +44 -0
  21. package/components/repl/wysiwyg-repl.html +258 -0
  22. package/components/timeline/example.html +33 -0
  23. package/components/timeline/timeline.html +44 -0
  24. package/examples/anchor.html +11 -0
  25. package/examples/chart.html +22 -54
  26. package/examples/counter.html +5 -3
  27. package/examples/counter2.html +26 -0
  28. package/examples/directives.html +19 -17
  29. package/examples/forgeinform.html +45 -43
  30. package/examples/form.html +22 -20
  31. package/examples/gauge.html +2 -0
  32. package/examples/invalid-template-literals.html +5 -3
  33. package/examples/message.html +10 -4
  34. package/examples/nested.html +1 -1
  35. package/examples/object-bound-form.html +12 -10
  36. package/examples/remote.html +17 -15
  37. package/examples/shared.html +41 -0
  38. package/examples/xor.html +21 -19
  39. package/lightview.js +138 -90
  40. package/package.json +7 -2
  41. package/sites/client.html +48 -0
  42. package/sites/index.html +247 -0
  43. package/test/basic.html +17 -16
  44. package/test/basic.test.mjs +0 -10
  45. package/test/extended.html +17 -20
  46. package/types.js +10 -1
  47. package/unsplash.key +1 -0
  48. package/components/gauge/guage.html +0 -19
  49. package/examples/duration.html +0 -279
@@ -1,279 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Lightview:Examples:Duration timewave timeview</title>
6
- </head>
7
- <body>
8
- <script>
9
- const isDate = (value) => value && typeof(value)==="object" && value instanceof Date;
10
- const durationMilliseconds = {
11
- ms: 1,
12
- s: 1000,
13
- m: 1000 * 60,
14
- h: 1000 * 60 * 60,
15
- d: 1000 * 60 * 60 * 24,
16
- w: 1000 * 60 * 60 * 24 * 7,
17
- mo: 1000 * 60 * 60 * 2 * 365.2424177, // (1000 * 60 * 60 * 24 * 365.2424177)/12
18
- q: 1000 * 60 * 60 * 6 * 365.2424177, // (1000 * 60 * 60 * 24 * 365.2424177)/4
19
- y: 1000 * 60 * 60 * 24 * 365.2424177
20
- };
21
- const dateMath = {
22
- y(date,y) {
23
- date.setYear(date.getYear()+y);
24
- },
25
- q(date,q) {
26
- const newmonth = (q * 3) + date.getMonth();
27
- date.setMonth(newmonth>11 ? newmonth - 12 : newmonth);
28
- },
29
- mo(date,mo) {
30
- const newmonth = mo + date.getMonth();
31
- date.setMonth(newmonth>11 ? newmonth - 12 : newmonth);
32
- },
33
- w(date,w) {
34
- const dayofyear = Math.floor((date - new Date(date.getFullYear(), 0, 0)) / durationMilliseconds["d"]),
35
- newdayofyear = dayofyear + (w * 7),
36
- newtime = date.getTime() + (newdayofyear + durationMilliseconds["d"])
37
- date.setTime(newtime);
38
- },
39
- d(date,d) {
40
- const dayofyear = Math.floor((date - new Date(date.getFullYear(), 0, 0)) / durationMilliseconds["d"]),
41
- newdayofyear = dayofyear + d,
42
- newtime = date.getTime() + (newdayofyear + durationMilliseconds["d"])
43
- date.setTime(newtime);
44
- },
45
- h(date,h) {
46
- const newhour = h + date.getHours();
47
- date.setHours(newhour>23 ? 24-newhour : newhour);
48
- },
49
- m(date,m) {
50
- const newminutes = m + date.getMinutes();
51
- date.setMinutes(newminutes>59 ? 60-newminutes : newminutes);
52
- },
53
- s(date,s) {
54
- const newseconds = s + date.getSeconds();
55
- date.setSeconds(newseconds>59 ? 60-newseconds : newseconds);
56
- },
57
- ms(date,ms) {
58
- const newmseconds = ms + date.getMilliseconds()
59
- date.setMilliseconds(newmseconds>999 ? 1000-newmseconds : newmseconds);
60
- }
61
- }
62
- const parseDuration = (value) => {
63
- const type = typeof(value);
64
- if(value && type==="object" && value instanceof D) return value.valueOf();
65
- if(type==="number") return value;
66
- if(type==="string") {
67
- const parts = value.split(" ");
68
- let ms = 0;
69
- for(const part of parts) {
70
- const num = parseFloat(part),
71
- suffix = part.substring((num+"").length);
72
- if(typeof(num)==="number" && !isNaN(num) && suffix in durationMilliseconds) {
73
- ms += durationMilliseconds[suffix] * num;
74
- } else {
75
- throw new TypeError(`${part} in ${value} is not a valid duration`)
76
- }
77
- }
78
- return ms;
79
- }
80
- if(isDate(value)) return value.getTime();
81
- return null;
82
- };
83
- function Period(start,end) {
84
- if(!this || !(this instanceof Period)) return new Period(start,end);
85
- Object.defineProperty(this,"start",{
86
- set(value) {
87
- if (!value || typeof (value) !== "object" || !(value instanceof Date)) throw new TypeError(`Period boundary must be a Date`);
88
- start = value;
89
- }
90
- });
91
- Object.defineProperty(this,"end",{
92
- set(value) {
93
- if (!value || typeof (value) !== "object" || !(value instanceof Date)) throw new TypeError(`Period boundary must be a Date`);
94
- end = value;
95
- }
96
- });
97
- Object.defineProperty(this,"valueOf",{ value:() => {
98
- const t1 = start.getTime(),
99
- t2 = end.getTime();
100
- return D(Math.max(t1,t2)-Math.min(t1,t2))
101
- }});
102
- Object.defineProperty(this,"length",{get() { return this.valueOf();}});
103
- this.start = start;
104
- this.end = end;
105
- }
106
- function Clock(date=new Date(),{tz,hz}={}) {
107
- if(typeof(date)==="number") date = new Date(date);
108
- if(!date || typeof(date)!=="object" || !(date instanceof Date)) throw new TypeError(`Clock() expects a Date not ${JSON.stringify(date)}`);
109
- let tzoffset = now.getTimezoneOffset(),
110
- diff = 0;
111
- if(tz) {
112
- const thereLocaleStr = date.toLocaleString('en-US', {timeZone: tz}),
113
- thereDate = new Date(thereLocaleStr);
114
- diff = thereDate.getTime() - date.getTime();
115
- tzoffset = Math.round(tzoffset - (diff / (1000 * 60)));
116
- } else {
117
- tzoffset = date.getTimezoneOffset();
118
- }
119
- if(hz) {
120
- if(hz>60) console.warn(`Clock set to run faster than ${hz}hz. Excess CPU load beyond typical DOM refresh rate.`);
121
- const warp = date.getTime() - Date.now();
122
- setInterval(() => {
123
- date = new Date(Date.now() + warp);
124
- },1000/Math.abs(hz))
125
- }
126
- const extensions = {
127
- plus(duration,times=1) {
128
- if(typeof(duration)==="number") duration = D(duration);
129
- if(!D.is(duration)) throw new TypeError(`${JSON.stringify(duration)} is not a duration`);
130
- const parts = duration.toJSON().split(" "),
131
- result = new Date(date);
132
- Object.entries(dateMath).forEach(([key,math]) => {
133
- parts.some((part) => {
134
- if(part.endsWith(key)) {
135
- math(result,parseFloat(part)*times);
136
- return true;
137
- }
138
- })
139
- });
140
- return new Clock(result,{tz},true);
141
- },
142
- minus(duration) {
143
- this.plus(duration,-1);
144
- },
145
- clone({tz,hz}={}) {
146
- const thereDate = new Clock(new Date(),{tz}),
147
- thereOffset = thereDate.getTimezoneOffset(),
148
- offset = tzoffset - thereOffset,
149
- newDate = new Date(date.getTime() + offset * 1000 * 60)
150
- return new Clock(newDate,{tz,hz});
151
- },
152
- getTimezoneOffset() {
153
- return tzoffset;
154
- },
155
- toString() {
156
- const string = date.toString(),
157
- offset = tzoffset / 60,
158
- fraction = offset % 1,
159
- minutes = (1 - fraction) >= .017 ? `${Math.round(fraction * 60)}` : "00", // .017 = 1 minute
160
- hours = `${Math.abs(Math.round(offset))}`,
161
- gmt = `GMT${offset>0 ? "-" : "+"}${hours.padStart(2,"0")}${minutes.padStart(2,"0")}`,
162
- zone = tz ? ` (${tz})` : "";
163
- return string.replace(/GMT.*/g,gmt) + zone;
164
- }
165
- };
166
- const proxy = new Proxy(date,{
167
- get(target,property) {
168
- let value = extensions[property];
169
- if(value!==undefined) return value;
170
- if(property==="weekDay") {
171
- return target.getDay()+1;
172
- }
173
- if(property==="dayOfMonth") {
174
- return target.getDate();
175
- }
176
- if(property==="dayOfYear" || property==="ordinal") {
177
- return Math.floor((target - new Date(target.getFullYear(), 0, 0)) / durationMilliseconds["d"])
178
- }
179
- if(property==="isInLeapYear") {
180
- const year = date.getFullYear();
181
- return !(year % 4 || !(year % 100) && year % 400);
182
- }
183
- if(property==="offset") {
184
- return tzoffset;
185
- }
186
- if(property==="weekOfYear") {
187
- return Math.floor(((target - new Date(target.getFullYear(), 0, 0)) / durationMilliseconds["d"]) / 7)
188
- }
189
- value = date[property];
190
- if(typeof(value)==="function") return value.bind(target);
191
- if(typeof(property)==="string" && !property.startsWith("get")) {
192
- let fname = "get" + property[0].toUpperCase() + property.substring(1);
193
- if(typeof(target[fname])==="function") return target[fname]();
194
- fname += "s";
195
- if(typeof(target[fname])==="function") return target[fname]();
196
- }
197
- return value;
198
- }
199
- });
200
- return proxy;
201
- }
202
- Clock.min = (...clocks) => {
203
- const mintime = clocks.reduce((mintime,clock) => {
204
- const t = clock.getTime() + clock.getTimezoneOffset() * 1000 * 60;
205
- mintime = Math.min(t,mintime);
206
- },Infinity);
207
- return clocks.reduce((min,clock) => {
208
- if((clock.getTime() + clock.getTimezoneOffset() * 1000 * 60)===mintime) {
209
- min.push(clock);
210
- }
211
- return min;
212
- },[])
213
- }
214
- Clock.max = (...clocks) => {
215
- const maxtime = clocks.reduce((mintime,clock) => {
216
- const t = clock.getTime() + clock.getTimezoneOffset() * 1000 * 60;
217
- mintime = Math.max(t,mintime);
218
- },-Infinity);
219
- return clocks.reduce((min,clock) => {
220
- if((clock.getTime() + clock.getTimezoneOffset() * 1000 * 60)===maxtime) {
221
- min.push(clock);
222
- }
223
- return min;
224
- },[])
225
- }
226
- function D(value,type) {
227
- if(!this || !(this instanceof D)) return new D(value,type);
228
- let duration = value;
229
- if(isDate(duration)) {
230
- if(type && type!=="ms") throw new TypeError(`A date can't be used to initialize ${type}`);
231
- duration = value.getTime()+"ms";
232
- } else if(typeof(duration)==="number") {
233
- duration += type||"ms";
234
- }
235
- const valueof = parseDuration(duration);
236
- if(valueof==null) throw new TypeError(`${typeof(value)==="string" ? value : JSON.stringify(value)}${type!==undefined ? type :""} is not a valid duration`);
237
- Object.defineProperty(this,"type",{get() { return type; }});
238
- Object.defineProperty(this,"valueOf",{value:() => valueof});
239
- Object.defineProperty(this,"toJSON",{value:() => duration});
240
- return this;
241
- }
242
- D.is = (value) => value && typeof(value)==="object" && value instanceof D;
243
- D.prototype.to = function(type="ms") {
244
- const value = this.valueOf();
245
- if(type==="Date") {
246
- if(this instanceof Period) throw new TypeError(`Cannot convert Period to Date`);
247
- return new Date(value);
248
- }
249
- if(!(type in durationMilliseconds)) throw new TypeError(`${type} is not a valid duration type`);
250
- return value / durationMilliseconds[type];
251
- }
252
- D.prototype.days = function() { return this.to("d"); }
253
- D.prototype.Date = function() { return this.to("Date"); }
254
- D.Period = Period;
255
- Period.is = (value) => value && typeof(value)==="object" && value instanceof Period;
256
- Period.prototype = {...D.prototype};
257
- delete Period.prototype.Date;
258
-
259
-
260
- console.log(JSON.stringify(D(D("1d") + D("1w") + D("1w 2d")).days()));
261
- const now = new Date(),
262
- d = D(now) + D("1d"),
263
- nyc = Clock(now,{tz:"America/New_York",hz:60}),
264
- chicago = nyc.clone({tz:"America/Chicago"}),
265
- toronto = nyc.clone({tz:"America/Toronto"}),
266
- seattle = toronto.clone({tz:"America/Los_Angeles"});
267
- console.log(now,new Date(D(d)),new Date(d));
268
- console.log(D(1) instanceof D);
269
- console.log(now.getTime(),D(now,"ms").valueOf());
270
- console.log(JSON.stringify(Clock(now).plus(D("1mo"))));
271
- console.log(Clock(now).weekOfYear,Clock(now).dayOfYear);
272
- console.log(nyc.toString());
273
- console.log(toronto.toString());
274
- console.log(chicago.toString());
275
- console.log(seattle.toString());
276
- setInterval(() => console.log(nyc.toString()),1000*60);
277
- </script>
278
- </body>
279
- </html>