Skip to content

Commit 413c184

Browse files
committed
feat(src): add cr-pin attribute to control
Ref: #8 Introduce cr-pin attribute to control CR Pin behavior.
1 parent 84c18f4 commit 413c184

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

dev/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@
9797
nid="bafybeigda2fjjeta7725hbicpfzldygszl4gbllcaybwuetlemraauazwm"
9898
position="top right"
9999
heading-source="abstract"
100+
layout="curated"
101+
cz-title="produced for"
102+
visibility="always"
103+
action-button-text="donate"
104+
cr-pin="off"
100105
>
101106
<img
102107
src="https://ipfs-pin.numbersprotocol.io/ipfs/bafybeigda2fjjeta7725hbicpfzldygszl4gbllcaybwuetlemraauazwm"

src/capture-eye.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export class CaptureEye extends LitElement {
8080
@property({ type: String, attribute: 'action-button-link' })
8181
actionButtonLink = '';
8282

83+
/**
84+
* Control the CR Pin behavior. Default is on. Options: on, off
85+
*/
86+
@property({ type: String, attribute: 'cr-pin' })
87+
crPin = Constant.crPin.on;
88+
8389
@state({})
8490
protected _isFullVisibility = false;
8591

@@ -198,6 +204,7 @@ export class CaptureEye extends LitElement {
198204
engagementZones: this.engagementZones,
199205
actionButtonText: this.actionButtonText,
200206
actionButtonLink: this.actionButtonLink,
207+
crPin: this.crPin,
201208
position: {
202209
top: buttonRect.top + window.scrollY,
203210
left: buttonRect.left + window.scrollX,

src/constant.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface ConstantType {
3232
visibility: Visibility;
3333
color: Color;
3434
position: Position;
35+
crPin: CrPin;
3536
}
3637

3738
interface Layout {
@@ -56,6 +57,11 @@ interface Position {
5657
bottomRight: string;
5758
}
5859

60+
interface CrPin {
61+
on: string;
62+
off: string;
63+
}
64+
5965
const numbersCdnUrl = 'https://static-cdn.numbersprotocol.io';
6066

6167
export const Constant: ConstantType = {
@@ -102,4 +108,8 @@ export const Constant: ConstantType = {
102108
bottomLeft: 'bottom left',
103109
bottomRight: 'bottom right',
104110
},
111+
crPin: {
112+
on: 'on',
113+
off: 'off',
114+
},
105115
};

src/modal/modal.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export interface ModalOptions {
5757
actionButtonText?: string;
5858
actionButtonLink?: string;
5959
position?: { top: number; left: number; name: string };
60+
crPin?: string;
6061
}
6162

6263
@customElement('capture-eye-modal')
@@ -83,6 +84,7 @@ export class CaptureEyeModal extends LitElement {
8384
@state() protected _asset: AssetModel | undefined = undefined;
8485
@state() protected _assetLoaded = false;
8586
@state() protected _imageLoaded = false;
87+
@state() protected _crPin = Constant.crPin.on;
8688

8789
@query('.modal') modalElement!: HTMLDivElement;
8890

@@ -132,6 +134,9 @@ export class CaptureEyeModal extends LitElement {
132134
this._imageLoaded = false;
133135
this._engagementZones = options.engagementZones;
134136
}
137+
if (options.crPin !== undefined) {
138+
this._crPin = options.crPin;
139+
}
135140
this.preloadEngagementZoneImages();
136141
if (options.actionButtonText)
137142
this._actionButtonText = options.actionButtonText;
@@ -156,6 +161,7 @@ export class CaptureEyeModal extends LitElement {
156161
this._asset = undefined;
157162
this._assetLoaded = false;
158163
this._position = undefined;
164+
this._crPin = Constant.crPin.on;
159165
}
160166

161167
private remToPixels(rem: number): number {
@@ -257,7 +263,7 @@ export class CaptureEyeModal extends LitElement {
257263
/>`
258264
: html``;
259265

260-
const contentCredentials = this.isC2paSupported()
266+
const contentCredentials = this._crPin !== Constant.crPin.off && this.isC2paSupported()
261267
? html`<div
262268
class="button-content-credentials" title="Inspect Content Credentials"
263269
@click=${this.handleInspectContentCredentials}

src/test/modal_test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,4 +489,39 @@ suite('capture-eye-modal', () => {
489489

490490
expect(badge).to.exist;
491491
});
492+
493+
test('should hide content credentials when disabled', async () => {
494+
const el = await fixture<CaptureEyeModal>(html`
495+
<capture-eye-modal></capture-eye-modal>
496+
`);
497+
498+
el.updateAsset({
499+
encodingFormat: 'image/jpeg',
500+
}, true);
501+
502+
// By default, Content Credentials should be enabled
503+
await el.updateComplete;
504+
let buttonCr = el.shadowRoot!.querySelector('.button-content-credentials');
505+
expect(buttonCr).to.exist;
506+
507+
// Enable Content Credentials
508+
el.updateModalOptions({
509+
nid: '123',
510+
crPin: Constant.crPin.on
511+
});
512+
await el.updateComplete;
513+
514+
buttonCr = el.shadowRoot!.querySelector('.button-content-credentials');
515+
expect(buttonCr).to.exist;
516+
517+
// Disable Content Credentials
518+
el.updateModalOptions({
519+
nid: '123',
520+
crPin: Constant.crPin.off
521+
});
522+
await el.updateComplete;
523+
524+
buttonCr = el.shadowRoot!.querySelector('.button-content-credentials');
525+
expect(buttonCr).to.not.exist;
526+
});
492527
});

0 commit comments

Comments
 (0)