@internetarchive/ia-item-navigator 0.0.0-a1 → 0.0.0-a14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/README.md +29 -19
  2. package/demo/app-root.ts +101 -34
  3. package/demo/index.html +9 -1
  4. package/dist/demo/app-root.d.ts +26 -7
  5. package/dist/demo/app-root.js +88 -34
  6. package/dist/demo/app-root.js.map +1 -1
  7. package/dist/src/interfaces/event-interfaces.d.ts +3 -13
  8. package/dist/src/interfaces/event-interfaces.js.map +1 -1
  9. package/dist/src/interfaces/menu-interfaces.d.ts +3 -2
  10. package/dist/src/interfaces/menu-interfaces.js.map +1 -1
  11. package/dist/src/interfaces/nav-controller-interface.d.ts +9 -0
  12. package/dist/src/interfaces/nav-controller-interface.js.map +1 -1
  13. package/dist/src/item-inspector/item-inspector.d.ts +0 -41
  14. package/dist/src/item-inspector/item-inspector.js +253 -215
  15. package/dist/src/item-inspector/item-inspector.js.map +1 -1
  16. package/dist/src/item-inspector/visual-mod-provider.d.ts +2 -0
  17. package/dist/src/item-inspector/visual-mod-provider.js +3 -0
  18. package/dist/src/item-inspector/visual-mod-provider.js.map +1 -1
  19. package/dist/src/item-navigator.d.ts +36 -22
  20. package/dist/src/item-navigator.js +118 -108
  21. package/dist/src/item-navigator.js.map +1 -1
  22. package/dist/src/loader.d.ts +5 -0
  23. package/dist/src/loader.js +8 -2
  24. package/dist/src/loader.js.map +1 -1
  25. package/dist/src/no-theater-available.d.ts +9 -0
  26. package/dist/src/no-theater-available.js +79 -0
  27. package/dist/src/no-theater-available.js.map +1 -0
  28. package/dist/test/book-nav-stub.d.ts +17 -0
  29. package/dist/test/book-nav-stub.js +42 -0
  30. package/dist/test/book-nav-stub.js.map +1 -0
  31. package/dist/test/ia-item-navigator.test.d.ts +2 -0
  32. package/dist/test/ia-item-navigator.test.js +321 -0
  33. package/dist/test/ia-item-navigator.test.js.map +1 -0
  34. package/dist/test/ia-stub-goody.d.ts +210 -0
  35. package/dist/test/ia-stub-goody.js +276 -0
  36. package/dist/test/ia-stub-goody.js.map +1 -0
  37. package/dist/test/ia-stub.d.ts +22 -0
  38. package/dist/test/ia-stub.js +35 -0
  39. package/dist/test/ia-stub.js.map +1 -0
  40. package/dist/test/no-theater-available.test.d.ts +1 -0
  41. package/dist/test/no-theater-available.test.js +27 -0
  42. package/dist/test/no-theater-available.test.js.map +1 -0
  43. package/package.json +4 -3
  44. package/src/interfaces/event-interfaces.ts +3 -14
  45. package/src/interfaces/menu-interfaces.ts +3 -2
  46. package/src/interfaces/nav-controller-interface.ts +13 -0
  47. package/src/item-navigator.ts +144 -122
  48. package/src/loader.ts +9 -2
  49. package/src/no-theater-available.ts +85 -0
  50. package/test/book-nav-stub.ts +35 -0
  51. package/test/ia-item-navigator.test.ts +443 -0
  52. package/test/ia-stub.ts +79 -0
  53. package/test/no-theater-available.test.ts +32 -0
  54. package/demo/demo-book-manifest.json +0 -1163
  55. package/src/item-inspector/files-by-type/files-by-type-provider.ts +0 -43
  56. package/src/item-inspector/files-by-type/ia-files-by-type.ts +0 -100
  57. package/src/item-inspector/item-inspector.ts +0 -235
  58. package/src/item-inspector/share-provider.ts +0 -51
  59. package/src/item-inspector/visual-mod-provider.ts +0 -60
  60. package/src/item-navigator-js.js +0 -372
  61. package/test/your-webcomponent.test.ts +0 -40
@@ -1,43 +0,0 @@
1
- import { html, TemplateResult } from 'lit-element';
2
-
3
- import './ia-files-by-type';
4
- import '@internetarchive/icon-share/icon-share';
5
- import {
6
- IntMenuProvider,
7
- IntProviderArgs,
8
- } from '../../interfaces/menu-interfaces';
9
-
10
- export class FilesByTypeProvider implements IntMenuProvider {
11
- item: any = null;
12
-
13
- baseHost: string = 'https://archive.org';
14
-
15
- icon: TemplateResult = html`<p
16
- style="color: #fff; font-size: var(--iconHeight);"
17
- >
18
- F
19
- </p>`;
20
-
21
- id: string = 'filesByType';
22
-
23
- label: string = 'Files by type';
24
-
25
- component: TemplateResult | null = null;
26
-
27
- subPrefix: string = '';
28
-
29
- constructor(shareArgs: IntProviderArgs) {
30
- const { item, baseHost, subPrefix = '' } = shareArgs;
31
- const { title = '' } = item.metadata;
32
-
33
- this.item = item;
34
- this.baseHost = baseHost;
35
- this.subPrefix = subPrefix;
36
-
37
- this.component = html`<ia-files-by-type
38
- .item=${this.item}
39
- .description="${title}"
40
- .baseHost="${this.baseHost}"
41
- ></ia-files-by-type>`;
42
- }
43
- }
@@ -1,100 +0,0 @@
1
- import { MetadataResponse, File } from '@internetarchive/search-service';
2
- import { html, customElement, LitElement, property } from 'lit-element';
3
-
4
- interface CollapsedFileInt extends File {
5
- [menuId: string]: any;
6
- derivatives: [];
7
- }
8
-
9
- @customElement('ia-files-by-type')
10
- export default class IaFilesByType extends LitElement {
11
- @property({ type: Object }) item: MetadataResponse = {} as MetadataResponse;
12
-
13
- @property({ type: Array }) archivalArtifacts: File[] = [];
14
-
15
- @property({ type: Array }) collapsedFiles: CollapsedFileInt[] = [];
16
-
17
- firstUpdated() {
18
- this.collapseFiles();
19
- }
20
-
21
- render() {
22
- return html`
23
- <div>
24
- <p>there are ${this.collapsedFiles.length} original files</p>
25
-
26
- <p>there are ${this.archivalArtifacts.length} archival artifacts</p>
27
-
28
- <p></p>
29
- </div>
30
- `;
31
- }
32
-
33
- sortByViewer() {
34
- // const images = [];
35
- // const books = [];
36
- // const radio = [];
37
- // const audio = [];
38
- // const video = [];
39
- // const albums = [];
40
- // const software = [];
41
- // this.collapsedFiles.forEach((fi) => {
42
- // // if image
43
- // // sort by various viewers
44
- // })
45
-
46
- return true;
47
- }
48
-
49
- collapseFiles() {
50
- const { files = [] } = this?.item as MetadataResponse;
51
-
52
- const archivalArtifacts: File[] = [];
53
- const origDir: any = {};
54
-
55
- files.forEach(fi => {
56
- const { format, source, name, original = '' } = fi as File;
57
- if (
58
- format.toLowerCase() === 'metadata' ||
59
- format.toLowerCase() === 'item tile'
60
- ) {
61
- archivalArtifacts.push(fi);
62
- return;
63
- }
64
-
65
- let origEntry: any = {};
66
- if (source === 'original') {
67
- origEntry = origDir[name];
68
- if (!origEntry) {
69
- // add new
70
- origDir[name] = { ...fi, derivatives: [] } as CollapsedFileInt;
71
- origEntry = origDir[name];
72
- } else {
73
- // update
74
- const merged = { ...origEntry, ...fi };
75
- origDir[name] = merged;
76
- }
77
- return;
78
- }
79
-
80
- if (source === 'derivative') {
81
- const keyToFile = original || '';
82
- origEntry = origDir[keyToFile];
83
- if (!origEntry && original) {
84
- // add new
85
- const fileFrame = { derivatives: [] } as CollapsedFileInt;
86
- origEntry = fileFrame;
87
- origEntry?.derivatives.push(fi);
88
- origDir[keyToFile] = origEntry;
89
- origEntry = origDir[keyToFile];
90
- }
91
- origEntry?.derivatives.push(fi);
92
- }
93
- });
94
-
95
- this.archivalArtifacts = archivalArtifacts;
96
- this.collapsedFiles = Object.keys(origDir).map(
97
- (fileName: string) => origDir[fileName]
98
- );
99
- }
100
- }
@@ -1,235 +0,0 @@
1
- /* eslint-disable no-console */
2
- import {
3
- css,
4
- html,
5
- LitElement,
6
- customElement,
7
- property,
8
- state,
9
- } from 'lit-element';
10
- import { MetadataResponse } from '@internetarchive/search-service';
11
-
12
- import { IntNavController } from '../interfaces/nav-controller-interface';
13
- import {
14
- IntMenuProvider,
15
- IntMenuShortcut,
16
- } from '../interfaces/menu-interfaces';
17
-
18
- import { ShareProvider } from './share-provider';
19
- import { FilesByTypeProvider } from './files-by-type/files-by-type-provider';
20
- import { VisualModsProvider } from './visual-mod-provider';
21
-
22
- // eslint-disable-next-line no-shadow
23
- enum ItemInspectorEvents {
24
- menuUpdated = 'menuUpdated',
25
- updateSideMenu = 'updateSideMenu',
26
- PostInit = 'PostInit',
27
- ViewportInFullScreen = 'ViewportInFullScreen',
28
- }
29
-
30
- interface menuProvidersInt {
31
- [menuId: string]: IntMenuProvider;
32
- }
33
-
34
- @customElement('ia-item-inspector')
35
- export class IaItemInspector extends LitElement implements IntNavController {
36
- @property({ type: Object }) itemMD: MetadataResponse = {
37
- metadata: {},
38
- } as MetadataResponse;
39
-
40
- @property({ type: String }) baseHost = 'https://archive.org';
41
-
42
- @property({ type: Object }) menuProviders: menuProvidersInt = {};
43
-
44
- @property({ type: Array }) menuShortcuts: IntMenuShortcut[] = [];
45
-
46
- @property({ type: Boolean }) sideMenuOpen = false;
47
-
48
- @property({ type: Boolean }) fullscreenState = false;
49
-
50
- @state() fileCount: number = 0;
51
-
52
- @state() loaded: boolean = false;
53
-
54
- @state() private shortcutOrder = ['visualMods'];
55
-
56
- firstUpdated() {
57
- this.loaded = true;
58
- console.log('loaded ');
59
- }
60
-
61
- updated(changed: any) {
62
- if (changed.has('loaded')) {
63
- setTimeout(() => this.emitLoadingStatusUpdate(this.loaded), 1000);
64
- }
65
-
66
- if (changed.has('itemMD') && this.itemMD) {
67
- this.parseItemInfo();
68
- this.setMenu();
69
- }
70
-
71
- if (changed.has('menuProviders') || changed.has('menuShortcuts')) {
72
- this.updateMenuContents();
73
- }
74
- }
75
-
76
- render() {
77
- const { identifier = '' } = this.itemMD?.metadata;
78
- return html`
79
- <section>
80
- <div>
81
- <h2>${identifier}</h2>
82
- </div>
83
- <img src=${this.imageUrl} alt=${`${identifier} thumbnail`} />
84
- </section>
85
- `;
86
- }
87
-
88
- addMenuShortcut(menuId: keyof menuProvidersInt) {
89
- if (this.menuShortcuts.find(m => m.id === menuId)) {
90
- return;
91
- }
92
-
93
- const shortcut = this.menuProviders[menuId];
94
- this.menuShortcuts.push(shortcut);
95
- this.sortMenuShortcuts();
96
- this.emitMenuShortcutsUpdated();
97
- }
98
-
99
- /**
100
- * Removes a provider object from the menuShortcuts array and emits a
101
- * menuShortcutsUpdated event.
102
- */
103
- removeMenuShortcut(menuId: string) {
104
- this.menuShortcuts = this.menuShortcuts.filter(m => m.id !== menuId);
105
- this.emitMenuShortcutsUpdated();
106
- }
107
-
108
- /**
109
- * Sorts the menuShortcuts property by comparing each provider's id to
110
- * the id in each iteration over the shortcutOrder array.
111
- */
112
- sortMenuShortcuts() {
113
- this.menuShortcuts = this.shortcutOrder.reduce(
114
- (shortcuts: IntMenuShortcut[], id) => {
115
- const menu = this.menuShortcuts.find(m => m.id === id);
116
-
117
- // eslint-disable-next-line no-param-reassign
118
- if (menu) {
119
- shortcuts = [...shortcuts, menu];
120
- }
121
- console.log({ shortcuts, menu });
122
- return shortcuts;
123
- },
124
- []
125
- );
126
- }
127
-
128
- emitMenuShortcutsUpdated() {
129
- const event = new CustomEvent('menuShortcutsUpdated', {
130
- detail: this.menuShortcuts,
131
- });
132
- this.dispatchEvent(event);
133
- }
134
-
135
- setMenu() {
136
- const menuProviders = {
137
- share: new ShareProvider({
138
- item: this.itemMD,
139
- baseHost: this.baseHost,
140
- subPrefix: '',
141
- }),
142
- filesByType: new FilesByTypeProvider({
143
- item: this.itemMD,
144
- baseHost: this.baseHost,
145
- subPrefix: '',
146
- }),
147
- visualMods: new VisualModsProvider({
148
- updated: (modType: string) => {
149
- console.log('visal mods updated', modType);
150
- if (modType === 'toggleFullscreen') {
151
- this.updateFullscreenState();
152
- }
153
- },
154
- item: this.itemMD,
155
- baseHost: this.baseHost,
156
- subPrefix: '',
157
- // maybe DOM root for class configs?
158
- }),
159
- };
160
-
161
- this.menuProviders = menuProviders;
162
- this.addMenuShortcut('visualMods');
163
- }
164
-
165
- updateFullscreenState() {
166
- const nextFSState = !this.fullscreenState;
167
- this.fullscreenState = nextFSState;
168
- this.dispatchEvent(
169
- new CustomEvent('ViewportInFullScreen', {
170
- detail: nextFSState,
171
- })
172
- );
173
- }
174
-
175
- updateMenuContents() {
176
- const { share, filesByType, visualMods } = this.menuProviders;
177
- const availableMenus = [filesByType, share, visualMods].filter(
178
- menu => !!menu
179
- );
180
-
181
- const event = new CustomEvent(ItemInspectorEvents.menuUpdated, {
182
- detail: availableMenus,
183
- });
184
-
185
- this.dispatchEvent(event);
186
- }
187
-
188
- emitLoadingStatusUpdate(loaded: boolean) {
189
- const event = new CustomEvent('loadingStateUpdated', {
190
- detail: { loaded },
191
- });
192
- this.dispatchEvent(event);
193
- }
194
-
195
- parseItemInfo() {
196
- this.fileCount = this.itemMD?.files?.length || 0;
197
- }
198
-
199
- get imageUrl() {
200
- const { metadata = {} } = this.itemMD;
201
- const url = `${this.baseHost}/download/${metadata?.identifier}/__ia_thumb.jpg`;
202
- return url;
203
- }
204
-
205
- static get styles() {
206
- const main = css`
207
- :host {
208
- display: block;
209
- width: 100%;
210
- margin: 0 auto;
211
- position: relative;
212
- overflow: hidden;
213
- background-color: black;
214
- color: var(--primaryTextColor, #fff);
215
- }
216
-
217
- :host,
218
- section {
219
- min-height: inherit;
220
- height: inherit;
221
- }
222
-
223
- section {
224
- margin: auto;
225
- width: 100%;
226
- text-align: center;
227
- }
228
-
229
- img {
230
- border: 1px solid var(--primaryTextColor, #fff);
231
- }
232
- `;
233
- return [main];
234
- }
235
- }
@@ -1,51 +0,0 @@
1
- import { html, TemplateResult } from 'lit-element';
2
-
3
- import '@internetarchive/ia-sharing-options';
4
- import '@internetarchive/icon-share/icon-share';
5
- import {
6
- IntMenuProvider,
7
- IntProviderArgs,
8
- } from '../interfaces/menu-interfaces';
9
-
10
- export class ShareProvider implements IntMenuProvider {
11
- item: any = null;
12
-
13
- baseHost: string = 'https://archive.org';
14
-
15
- icon: TemplateResult = html`<ia-icon-share
16
- style="width: var(--iconWidth); height: var(--iconHeight);"
17
- ></ia-icon-share>`;
18
-
19
- id: string = 'share';
20
-
21
- label: string = 'Share this item';
22
-
23
- component: TemplateResult | null = null;
24
-
25
- subPrefix: string = '';
26
-
27
- encodedSubPrefix: string = '';
28
-
29
- constructor(shareArgs: IntProviderArgs) {
30
- const { item, baseHost, subPrefix = '' } = shareArgs;
31
- const { identifier = '', creator = '', title = '' } = item.metadata || {};
32
- const encodedSubPrefix = encodeURIComponent(subPrefix);
33
- const urlIdentifier =
34
- subPrefix && subPrefix !== identifier
35
- ? `${identifier}/${encodedSubPrefix}`
36
- : identifier;
37
-
38
- this.item = item;
39
- this.baseHost = baseHost;
40
- this.subPrefix = subPrefix;
41
- this.encodedSubPrefix = encodedSubPrefix;
42
-
43
- this.component = html`<ia-sharing-options
44
- identifier=${urlIdentifier}
45
- type="item"
46
- creator="${creator}"
47
- description="${title}"
48
- baseHost="${this.baseHost}"
49
- ></ia-sharing-options>`;
50
- }
51
- }
@@ -1,60 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /* eslint-disable max-classes-per-file */
3
-
4
- import { html, TemplateResult, customElement, LitElement } from 'lit-element';
5
-
6
- import '@internetarchive/ia-sharing-options';
7
- import '@internetarchive/icon-visual-adjustment/icon-visual-adjustment';
8
- import {
9
- IntMenuProvider,
10
- IntProviderArgs,
11
- } from '../interfaces/menu-interfaces';
12
-
13
- @customElement('ia-visual-mods')
14
- class VisualMods extends LitElement {
15
- toggleFullscreen() {
16
- this.dispatchEvent(new Event('fullscreenToggle'));
17
- }
18
-
19
- render() {
20
- return html`<section>
21
- <button @click=${this.toggleFullscreen}>Toggle Fullscreen</button>
22
- </section>`;
23
- }
24
- }
25
-
26
- export class VisualModsProvider implements IntMenuProvider {
27
- item: any = null;
28
-
29
- baseHost: string = 'https://archive.org';
30
-
31
- icon: TemplateResult = html`<ia-icon-visual-adjustment
32
- style="width: var(--iconWidth); height: var(--iconHeight);"
33
- ></ia-icon-visual-adjustment>`;
34
-
35
- id: string = 'visualMods';
36
-
37
- label: string = 'Visual Modifications';
38
-
39
- component: TemplateResult | null = null;
40
-
41
- subPrefix: string = '';
42
-
43
- encodedSubPrefix: string = '';
44
-
45
- updated: any = () => {};
46
-
47
- constructor(providerArgs: IntProviderArgs) {
48
- const { item, baseHost, subPrefix = '', updated } = providerArgs;
49
-
50
- this.updated = updated;
51
-
52
- this.component = html`<ia-visual-mods
53
- @fullscreenToggle=${() => this?.updated('toggleFullscreen')}
54
- ></ia-visual-mods>`;
55
- }
56
-
57
- toggleFullscreen() {
58
- this.updated('toggleFullscreen');
59
- }
60
- }