@verdocs/js-sdk 1.1.7 → 1.1.11

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.
@@ -1,4 +1,5 @@
1
1
  import { ISigningSession, ISigningSessionRequest } from './Types';
2
+ import { IFieldSetting } from '../Templates/Types';
2
3
  export declare type TDocumentStatus = 'complete' | 'pending' | 'in progress' | 'declined' | 'canceled';
3
4
  export declare type TRecipientStatus = 'invited' | 'opened' | 'signed' | 'submitted' | 'canceled' | 'pending' | 'declined';
4
5
  export declare type TRecipientType = 'signer' | 'cc' | 'approver';
@@ -63,6 +64,28 @@ export interface IRecipient {
63
64
  type: TRecipientType;
64
65
  updated_at: string;
65
66
  }
67
+ export interface IDocumentAsset {
68
+ created_at: string;
69
+ id: string;
70
+ mime: string;
71
+ name: string;
72
+ page_numbers: number;
73
+ updated_at: string;
74
+ url: string;
75
+ }
76
+ export interface IDocumentField {
77
+ envelope_id: string;
78
+ label: string | null;
79
+ name: string;
80
+ page: number;
81
+ recipient_role: string;
82
+ type: string;
83
+ required: boolean;
84
+ settings?: IFieldSetting;
85
+ setting?: IFieldSetting;
86
+ validator: string | null;
87
+ prepared?: boolean;
88
+ }
66
89
  export interface IDocument {
67
90
  id: string;
68
91
  created_at: string;
@@ -79,6 +102,9 @@ export interface IDocument {
79
102
  template_id: string;
80
103
  updated_at: string;
81
104
  organization_id: string | null;
105
+ certificate?: IDocumentAsset | null;
106
+ document?: IDocumentAsset | null;
107
+ fields?: IDocumentField[];
82
108
  }
83
109
  export interface IActivityEntry {
84
110
  id: string;
@@ -150,3 +176,4 @@ export declare const getSigningSession: (params: ISigningSessionRequest) => Prom
150
176
  export declare const getDocumentRecipients: (documentId: string) => Promise<IRecipient[]>;
151
177
  export declare const getDocument: (documentId: string) => Promise<IDocument>;
152
178
  export declare const getDocumentFile: (documentId: string, envelopeDocumentId: string) => Promise<string>;
179
+ export declare const updateDocumentField: (documentId: string, fieldName: string, value: any) => Promise<IFieldSetting>;
@@ -108,3 +108,10 @@ export var getDocumentFile = function (documentId, envelopeDocumentId) { return
108
108
  .then(function (r) { return Buffer.from(r.data, 'binary').toString('base64'); })];
109
109
  });
110
110
  }); };
111
+ export var updateDocumentField = function (documentId, fieldName, value) { return __awaiter(void 0, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ return [2 /*return*/, getEndpoint()
114
+ .api.put("/documents/".concat(documentId, "/fields/").concat(fieldName), value)
115
+ .then(function (r) { return r.data; })];
116
+ });
117
+ }); };
@@ -1,6 +1,7 @@
1
+ import { IRecipient } from './Documents';
1
2
  export declare type TRecipientAction = 'submit' | 'decline' | 'prepare' | 'update';
2
3
  export interface IUpdateRecipientParams {
3
4
  new_full_name?: string;
4
5
  agreed?: boolean;
5
6
  }
6
- export declare const updateRecipientStatus: (documentId: string, roleName: string, action: TRecipientAction, params?: IUpdateRecipientParams | undefined) => Promise<string>;
7
+ export declare const updateRecipientStatus: (documentId: string, roleName: string, action: TRecipientAction, params?: IUpdateRecipientParams | undefined) => Promise<IRecipient>;
@@ -57,6 +57,18 @@ export declare class VerdocsEndpoint {
57
57
  * ```
58
58
  */
59
59
  setAuthorization(accessToken: string | null): void;
60
+ /**
61
+ * Set the auth token used for signing sessions. Separating user from signing auth allows the same endpoint to be
62
+ * used for multiple operations, although it is recommended that a separate endpoint be created for each operation.
63
+ *
64
+ * ```typescript
65
+ * import {Endpoint} from '@verdocs/js-sdk/HTTP';
66
+ *
67
+ * const endpoint = new Endpoint();
68
+ * endpoint.setSigningAuthorization(accessToken);
69
+ * ```
70
+ */
71
+ setSigningAuthorization(accessToken: string | null): void;
60
72
  /**
61
73
  * Set the base URL for API calls. May also be set via the constructor.
62
74
  *
@@ -75,6 +75,25 @@ var VerdocsEndpoint = /** @class */ (function () {
75
75
  delete this.api.defaults.headers.Authorization;
76
76
  }
77
77
  };
78
+ /**
79
+ * Set the auth token used for signing sessions. Separating user from signing auth allows the same endpoint to be
80
+ * used for multiple operations, although it is recommended that a separate endpoint be created for each operation.
81
+ *
82
+ * ```typescript
83
+ * import {Endpoint} from '@verdocs/js-sdk/HTTP';
84
+ *
85
+ * const endpoint = new Endpoint();
86
+ * endpoint.setSigningAuthorization(accessToken);
87
+ * ```
88
+ */
89
+ VerdocsEndpoint.prototype.setSigningAuthorization = function (accessToken) {
90
+ if (accessToken) {
91
+ this.api.defaults.headers.signer = "Bearer ".concat(accessToken);
92
+ }
93
+ else {
94
+ delete this.api.defaults.headers.signer;
95
+ }
96
+ };
78
97
  /**
79
98
  * Set the base URL for API calls. May also be set via the constructor.
80
99
  *
@@ -1,4 +1,4 @@
1
- import { IDocument } from './Types';
1
+ import { ITemplateAsset } from './Types';
2
2
  /**
3
3
  * Get all the Documents associated to a particular Template.
4
4
  *
@@ -18,7 +18,7 @@ export declare const getDocuments: (templateId: string) => Promise<any>;
18
18
  * await Documents.createDocument(templateID, params);
19
19
  * ```
20
20
  */
21
- export declare const createDocument: (templateId: string, params: any) => Promise<IDocument>;
21
+ export declare const createDocument: (templateId: string, params: any) => Promise<ITemplateAsset>;
22
22
  /**
23
23
  * Get a specific Document.
24
24
  *
@@ -28,7 +28,7 @@ export declare const createDocument: (templateId: string, params: any) => Promis
28
28
  * await Documents.getDocument(templateID, documentID);
29
29
  * ```
30
30
  */
31
- export declare const getDocument: (templateId: string, documentId: string) => Promise<IDocument>;
31
+ export declare const getDocument: (templateId: string, documentId: string) => Promise<ITemplateAsset>;
32
32
  /**
33
33
  * Delete a specific Document.
34
34
  *
@@ -1,4 +1,4 @@
1
- import { IField } from './Types';
2
- export declare const createField: (templateId: string, params: IField) => Promise<IField>;
3
- export declare const editField: (templateId: string, fieldName: string, params: IField) => Promise<IField>;
1
+ import { ITemplateField } from './Types';
2
+ export declare const createField: (templateId: string, params: ITemplateField) => Promise<ITemplateField>;
3
+ export declare const editField: (templateId: string, fieldName: string, params: ITemplateField) => Promise<ITemplateField>;
4
4
  export declare const deleteField: (templateId: string, fieldName: string) => Promise<any>;
@@ -1,8 +1,8 @@
1
- import { IField, IRole } from './Types';
1
+ import { ITemplateField, IRole } from './Types';
2
2
  export declare const createRole: (templateId: string, params: IRole) => Promise<IRole>;
3
3
  export declare const getRoles: (templateId: string) => Promise<IRole[]>;
4
4
  export declare const getRole: (templateId: string, roleName: string) => Promise<IRole>;
5
5
  export declare const editRole: (templateId: string, roleName: string, params: IRole) => Promise<IRole>;
6
6
  export declare const deleteRole: (templateId: string, roleName: string) => Promise<any>;
7
- export declare const getRoleFields: (templateId: string, roleName: string) => Promise<IField[]>;
7
+ export declare const getRoleFields: (templateId: string, roleName: string) => Promise<ITemplateField[]>;
8
8
  export declare const deleteSequence: (templateId: string) => Promise<IRole[]>;
@@ -1,5 +1,5 @@
1
1
  export interface ITemplate {
2
- template_document?: IDocument;
2
+ template_document?: ITemplateAsset;
3
3
  pages?: IPage[];
4
4
  roles?: IRole[];
5
5
  counter?: number;
@@ -49,6 +49,24 @@ export declare enum TemplatePermissions {
49
49
  TEMPLATE_MEMBER_DELETE = "template:member:delete",
50
50
  TEMPLATE_MEMBER_VISIBILITY = "template:member:visibility"
51
51
  }
52
+ export declare enum TemplateSenderTypes {
53
+ CREATOR = "creator",
54
+ ORGANIZATION_MEMBER = "organization_member",
55
+ ORGANIZATION_MEMBER_AS_CREATOR = "organization_member_as_creator",
56
+ EVERYONE = "everyone",
57
+ EVERYONE_AS_CREATOR = "everyone_as_creator"
58
+ }
59
+ export declare enum TemplateActions {
60
+ CREATE_PERSONAL = "create_personal",
61
+ CREATE_ORG = "create_org",
62
+ CREATE_PUBLIC = "create_public",
63
+ READ = "read",
64
+ WRITE = "write",
65
+ DELETE = "delete",
66
+ CHANGE_VISIBILITY_PERSONAL = "change_visibility_personal",
67
+ CHANGE_VISIBILITY_ORG = "change_visibility_org",
68
+ CHANGE_VISIBILITY_PUBLIC = "change_visibility_public"
69
+ }
52
70
  export interface ITemplateSearchParams {
53
71
  id?: string;
54
72
  name?: string;
@@ -110,12 +128,13 @@ export interface IRole {
110
128
  email?: string;
111
129
  type: string;
112
130
  sequence: number;
113
- fields?: IField[];
131
+ fields?: ITemplateField[];
114
132
  delegator?: boolean;
115
133
  message?: string;
116
134
  phone?: string;
135
+ rgba?: string;
117
136
  }
118
- export interface IDocument {
137
+ export interface ITemplateAsset {
119
138
  url: string;
120
139
  name: string;
121
140
  page_numbers: number;
@@ -126,35 +145,39 @@ export interface IDocument {
126
145
  mime: string;
127
146
  thumbnail_url: string;
128
147
  }
129
- export interface IField {
148
+ export interface ITemplateField {
130
149
  name: string;
131
150
  role_name: string;
132
151
  template_id: string;
133
152
  type: string;
134
153
  required: boolean;
135
- setting?: ISetting;
154
+ setting?: IFieldSetting;
136
155
  page_sequence: number;
137
156
  validator?: string;
138
157
  label?: string;
139
158
  }
140
- export interface ISetting {
159
+ export interface IFieldSetting {
141
160
  x?: number;
142
161
  y?: number;
143
162
  width?: number;
144
163
  height?: number;
145
- result?: string;
164
+ result?: any;
146
165
  type?: string;
147
- options?: any[];
148
166
  value?: string;
167
+ leading?: number;
168
+ alignment?: number;
169
+ upperCase?: boolean;
170
+ options?: any[];
171
+ [key: string]: any;
149
172
  }
150
173
  export interface IPage {
151
174
  template_id: string;
152
175
  document_id: string;
153
- template_document?: IDocument;
176
+ template_document?: ITemplateAsset;
154
177
  sequence: number;
155
178
  page_number: number;
156
179
  thumbnail_url: string;
157
- fields?: IField[];
180
+ fields?: ITemplateField[];
158
181
  }
159
182
  export interface IReminder {
160
183
  id?: string;
@@ -10,6 +10,26 @@ export var TemplatePermissions;
10
10
  TemplatePermissions["TEMPLATE_MEMBER_DELETE"] = "template:member:delete";
11
11
  TemplatePermissions["TEMPLATE_MEMBER_VISIBILITY"] = "template:member:visibility";
12
12
  })(TemplatePermissions || (TemplatePermissions = {}));
13
+ export var TemplateSenderTypes;
14
+ (function (TemplateSenderTypes) {
15
+ TemplateSenderTypes["CREATOR"] = "creator";
16
+ TemplateSenderTypes["ORGANIZATION_MEMBER"] = "organization_member";
17
+ TemplateSenderTypes["ORGANIZATION_MEMBER_AS_CREATOR"] = "organization_member_as_creator";
18
+ TemplateSenderTypes["EVERYONE"] = "everyone";
19
+ TemplateSenderTypes["EVERYONE_AS_CREATOR"] = "everyone_as_creator";
20
+ })(TemplateSenderTypes || (TemplateSenderTypes = {}));
21
+ export var TemplateActions;
22
+ (function (TemplateActions) {
23
+ TemplateActions["CREATE_PERSONAL"] = "create_personal";
24
+ TemplateActions["CREATE_ORG"] = "create_org";
25
+ TemplateActions["CREATE_PUBLIC"] = "create_public";
26
+ TemplateActions["READ"] = "read";
27
+ TemplateActions["WRITE"] = "write";
28
+ TemplateActions["DELETE"] = "delete";
29
+ TemplateActions["CHANGE_VISIBILITY_PERSONAL"] = "change_visibility_personal";
30
+ TemplateActions["CHANGE_VISIBILITY_ORG"] = "change_visibility_org";
31
+ TemplateActions["CHANGE_VISIBILITY_PUBLIC"] = "change_visibility_public";
32
+ })(TemplateActions || (TemplateActions = {}));
13
33
  export var SortOptions;
14
34
  (function (SortOptions) {
15
35
  SortOptions["CREATED_AT"] = "created_at";
@@ -1,6 +1,11 @@
1
+ import { IRole, ITag } from './Types';
1
2
  export interface IValidator {
2
3
  name: string;
3
4
  regex: string;
4
5
  }
5
6
  export declare const getValidators: () => Promise<IValidator[]>;
6
7
  export declare const getValidator: (validatorName: string) => Promise<IValidator>;
8
+ export declare const isValidEmail: (value: string) => boolean;
9
+ export declare const isValidPhone: (value: string) => boolean;
10
+ export declare const isValidRoleName: (value: string, roles: IRole[]) => boolean;
11
+ export declare const isValidTag: (value: string, tags: ITag[]) => boolean;
@@ -1,3 +1,4 @@
1
+ import { simpleE164Validator } from '../Utils/Locales';
1
2
  import { getEndpoint } from '../HTTP/Transport';
2
3
  export var getValidators = function () {
3
4
  return getEndpoint()
@@ -9,3 +10,11 @@ export var getValidator = function (validatorName) {
9
10
  .api.get("/validators/".concat(validatorName))
10
11
  .then(function (r) { return r.data; });
11
12
  };
13
+ var EmailRegEx = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
14
+ export var isValidEmail = function (value) { return EmailRegEx.test(value); };
15
+ export var isValidPhone = function (value) { return simpleE164Validator(value); };
16
+ export var isValidRoleName = function (value, roles) { return roles.findIndex(function (role) { return role.name === value; }) !== -1; };
17
+ var TagRegEx = /^[a-zA-Z0-9-]{0,32}$/;
18
+ export var isValidTag = function (value, tags) {
19
+ return TagRegEx.test(value) || tags.findIndex(function (tag) { return tag.tag_name === value; }) !== -1;
20
+ };
@@ -0,0 +1,18 @@
1
+ import { IRole } from '../Templates/Types';
2
+ /**
3
+ * Given a `rgba(r,g,b,a)` string value, returns the hex equivalent, dropping the alpha channel.
4
+ */
5
+ export declare function getRGB(rgba: string): string;
6
+ /**
7
+ * Given a signer role index, return the color code for that signer.
8
+ */
9
+ export declare function getRGBA(roleIndex: number): "rgba(255, 193, 7, 0.4)" | "rgba(134, 134, 134, 0.3)" | "rgba(156, 39, 176, .4)" | "rgba(33, 150, 243, .4)" | "rgba(220, 231, 117, 0.3)" | "rgba(121, 134, 203, 0.3)" | "rgba(77, 182, 172, 0.3)" | "rgba(255, 202, 165, 0.3)" | "rgba(2, 247, 190, 0.3)" | "rgba(255, 138, 101, 0.3)" | "rgba(82, 255, 79, 0.3)" | "rgba(229, 115, 155, 0.3)";
10
+ /**
11
+ * Given a role name, return a color code for it. This works by computing a hash code so the specific color returned
12
+ * is not specified explicitly, but will be the same for every call with the same input value.
13
+ */
14
+ export declare function nameToRGBA(str: string): string | undefined;
15
+ /**
16
+ * Helper function to obtain a color code given a role name given various possible inputs.
17
+ */
18
+ export declare function getRoleColor(name: string, roles: IRole[], index?: number): string | undefined;
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Given a `rgba(r,g,b,a)` string value, returns the hex equivalent, dropping the alpha channel.
3
+ */
4
+ export function getRGB(rgba) {
5
+ var rgbNumbers = rgba.replace('rgba(', '').replace(')', '').split(',');
6
+ var rgbObject = {
7
+ red: +rgbNumbers[0],
8
+ green: +rgbNumbers[1],
9
+ blue: +rgbNumbers[2],
10
+ alpha: +rgbNumbers[3],
11
+ };
12
+ var alpha = 1 - rgbObject.alpha;
13
+ var red = Math.round((rgbObject.alpha * (rgbObject.red / 255) + alpha) * 255);
14
+ var green = Math.round((rgbObject.alpha * (rgbObject.green / 255) + alpha) * 255);
15
+ var blue = Math.round((rgbObject.alpha * (rgbObject.blue / 255) + alpha) * 255);
16
+ return '#' + rgbToHex(red) + rgbToHex(green) + rgbToHex(blue);
17
+ }
18
+ /**
19
+ * Given an RGB string value, returns the hex equivalent.
20
+ */
21
+ function rgbToHex(rgb) {
22
+ var hex = rgb.toString(16);
23
+ if (hex.length < 2) {
24
+ return '0' + hex;
25
+ }
26
+ return hex;
27
+ }
28
+ /**
29
+ * Given a signer role index, return the color code for that signer.
30
+ */
31
+ export function getRGBA(roleIndex) {
32
+ switch (roleIndex % 10) {
33
+ case 0:
34
+ return roleIndex === 0 ? 'rgba(255, 193, 7, 0.4)' : 'rgba(134, 134, 134, 0.3)'; // #FFE69C
35
+ case 1:
36
+ return 'rgba(156, 39, 176, .4)'; // '#E3C3E9'
37
+ case 2:
38
+ return 'rgba(33, 150, 243, .4)'; // '#C1E1FB'
39
+ case 3:
40
+ return 'rgba(220, 231, 117, 0.3)';
41
+ case 4:
42
+ return 'rgba(121, 134, 203, 0.3)';
43
+ case 5:
44
+ return 'rgba(77, 182, 172, 0.3)';
45
+ case 6:
46
+ return 'rgba(255, 202, 165, 0.3)';
47
+ case 7:
48
+ return 'rgba(2, 247, 190, 0.3)';
49
+ case 8:
50
+ return 'rgba(255, 138, 101, 0.3)';
51
+ case 9:
52
+ return 'rgba(82, 255, 79, 0.3)';
53
+ default:
54
+ return 'rgba(229, 115, 155, 0.3)';
55
+ }
56
+ }
57
+ /**
58
+ * Given a role name, return a color code for it. This works by computing a hash code so the specific color returned
59
+ * is not specified explicitly, but will be the same for every call with the same input value.
60
+ */
61
+ export function nameToRGBA(str) {
62
+ if (!!str) {
63
+ var validNum = parseInt(str.slice(-1), 10);
64
+ if (!isNaN(validNum)) {
65
+ str += (validNum * 99).toString();
66
+ }
67
+ var hash = 0;
68
+ for (var i = 0; i < str.length; i++) {
69
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
70
+ }
71
+ hash = Math.round(hash / 1.3);
72
+ var c = (hash & 0x00ffff08).toString(16).toUpperCase();
73
+ var hex = '#' + '00000'.substring(0, 6 - c.length) + c;
74
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
75
+ var color = {
76
+ r: parseInt(result[1], 16),
77
+ g: parseInt(result[2], 16),
78
+ b: parseInt(result[3], 16),
79
+ };
80
+ return "rgba(".concat(color.r, ", ").concat(color.g, ", ").concat(color.b, ", 0.2)");
81
+ }
82
+ }
83
+ /**
84
+ * Helper function to obtain a color code given a role name given various possible inputs.
85
+ */
86
+ export function getRoleColor(name, roles, index) {
87
+ if (index) {
88
+ return getRGBA(index);
89
+ }
90
+ else if (roles && roles.length > 0) {
91
+ var roleIndex = roles.findIndex(function (role) { return role.name === name; });
92
+ if (roleIndex > -1) {
93
+ return roles[roleIndex].rgba || getRGBA(roleIndex);
94
+ }
95
+ else {
96
+ return nameToRGBA(name);
97
+ }
98
+ }
99
+ else {
100
+ return nameToRGBA(name);
101
+ }
102
+ }
@@ -1 +1,6 @@
1
1
  export declare const formatShortTimeAgo: (val: any) => string;
2
+ export interface ITimePeriod {
3
+ start_time: string;
4
+ end_time: string;
5
+ }
6
+ export declare function timePeriod(type: string): ITimePeriod | null;
package/Utils/DateTime.js CHANGED
@@ -39,3 +39,41 @@ export var formatShortTimeAgo = function (val) {
39
39
  }
40
40
  return "".concat(timeDiff, "S");
41
41
  };
42
+ export function timePeriod(type) {
43
+ var endDate = new Date().getTime();
44
+ var today = new Date();
45
+ var month = today.getMonth();
46
+ var year = today.getFullYear();
47
+ var startDate = null;
48
+ switch (type) {
49
+ case '30d':
50
+ startDate = endDate - 60 * 60 * 24 * 30 * 1000;
51
+ break;
52
+ case '60d':
53
+ startDate = endDate - 60 * 60 * 24 * 60 * 1000;
54
+ break;
55
+ case '6m':
56
+ startDate = endDate - 60 * 60 * 24 * 30 * 6 * 1000;
57
+ break;
58
+ case 'this_month':
59
+ startDate = new Date(year, month, 1).getTime();
60
+ break;
61
+ case 'last_month':
62
+ startDate = new Date(year, month - 1, 1).getTime();
63
+ endDate = new Date(year, month, 0).getTime();
64
+ break;
65
+ case 'this_year':
66
+ startDate = new Date(year, 0, 1);
67
+ break;
68
+ case 'all_time':
69
+ default:
70
+ return null;
71
+ }
72
+ if (startDate === null && endDate === null) {
73
+ return null;
74
+ }
75
+ return {
76
+ start_time: new Date(startDate).toISOString(),
77
+ end_time: new Date(endDate).toISOString(),
78
+ };
79
+ }
@@ -0,0 +1,11 @@
1
+ import { IDocumentField } from '../Documents/Documents';
2
+ export declare function getHeight(field: IDocumentField): number;
3
+ export declare function getWidth(field: IDocumentField): number;
4
+ export declare function getRTop(y: number, fieldHeight: number, iTextHeight: number, yRatio: number): number;
5
+ export declare function getRLeft(x: number, ratio: number): number;
6
+ export declare function getRValue(y: number, ratio: number): number;
7
+ export declare function blobToBase64(image: Blob): Promise<unknown>;
8
+ export declare function getInputStyle(field: IDocumentField, mode: string, browserType: string): Record<string, string>;
9
+ export declare function getCheckboxLabelStyle(required: boolean): Record<string, any>;
10
+ export declare function getLetterSpacing(browserType: string): -0.0018 | -0.23594210526315787 | -0.0019;
11
+ export declare function rescale(r: number, n: number): number;
@@ -0,0 +1,137 @@
1
+ export function getHeight(field) {
2
+ var settings = field.settings || field.setting || {};
3
+ switch (field.type) {
4
+ case 'signature':
5
+ case 'initial':
6
+ return 36;
7
+ case 'checkbox':
8
+ case 'checkbox_group':
9
+ case 'radio_button_group':
10
+ return 13.5;
11
+ case 'attachment':
12
+ case 'payment':
13
+ return 24;
14
+ }
15
+ return settings.height || 0;
16
+ }
17
+ export function getWidth(field) {
18
+ var settings = field.settings || field.setting || {};
19
+ switch (field.type) {
20
+ case 'signature':
21
+ case 'initial':
22
+ return 82.63636363636;
23
+ case 'checkbox':
24
+ case 'checkbox_group':
25
+ case 'radio_button_group':
26
+ return 13.5;
27
+ case 'attachment':
28
+ case 'payment':
29
+ return 24;
30
+ case 'date':
31
+ return 64;
32
+ case 'dropdown':
33
+ return (settings === null || settings === void 0 ? void 0 : settings.width) || 64;
34
+ }
35
+ return (settings === null || settings === void 0 ? void 0 : settings.width) || 0;
36
+ }
37
+ export function getRTop(y, fieldHeight, iTextHeight, yRatio) {
38
+ return iTextHeight - (y + fieldHeight) * yRatio;
39
+ }
40
+ export function getRLeft(x, ratio) {
41
+ return x * ratio;
42
+ }
43
+ export function getRValue(y, ratio) {
44
+ return y * ratio;
45
+ }
46
+ export function blobToBase64(image) {
47
+ var fileReader = new FileReader();
48
+ return new Promise(function (resolve, reject) {
49
+ fileReader.onerror = function () {
50
+ reject(new DOMException('Problem reading blob.'));
51
+ };
52
+ fileReader.onload = function () {
53
+ resolve(fileReader.result);
54
+ };
55
+ fileReader.readAsDataURL(image);
56
+ });
57
+ }
58
+ export function getInputStyle(field, mode, browserType) {
59
+ var settings = field.settings || field.setting || {};
60
+ var fontSize = (settings === null || settings === void 0 ? void 0 : settings.font_size) || 11;
61
+ var style = {
62
+ height: '100%',
63
+ width: '100%',
64
+ background: 'none',
65
+ };
66
+ if (settings.font_size ||
67
+ field.type === 'date' ||
68
+ field.type === 'signature' ||
69
+ field.type === 'initial' ||
70
+ field.type === 'timestamp') {
71
+ style.fontSize = fontSize + 'px';
72
+ style.letterSpacing = '.3px !important';
73
+ }
74
+ if (field.type === 'dropdown') {
75
+ style.fontSize = '10.8px';
76
+ delete style.background;
77
+ }
78
+ if (field.type === 'textbox') {
79
+ style.fontSize = fontSize + 'px';
80
+ style.letterSpacing = getLetterSpacing(browserType) + 'px';
81
+ }
82
+ if (field.required) {
83
+ style.border = '1px solid #cc0000';
84
+ }
85
+ if ((field === null || field === void 0 ? void 0 : field.prepared) === true && mode !== 'prepareview') {
86
+ style.visibility = 'hidden';
87
+ }
88
+ if (settings.color) {
89
+ style.color = settings.color;
90
+ }
91
+ if (settings.upperCase) {
92
+ style.textTransform = 'uppercase';
93
+ }
94
+ if (settings.leading) {
95
+ style.lineHeight = "".concat(rescale(1, settings.leading + 0.5), "px");
96
+ }
97
+ return style;
98
+ }
99
+ export function getCheckboxLabelStyle(required) {
100
+ var labelStyle = {
101
+ position: 'absolute',
102
+ top: 0,
103
+ left: 0,
104
+ cursor: 'pointer',
105
+ height: "13.5px",
106
+ width: "13.5px",
107
+ backgroundColor: 'transparent',
108
+ border: '1px solid #777',
109
+ };
110
+ if (required) {
111
+ labelStyle.boxShadow = '0 0 0 1px #cc0000';
112
+ }
113
+ return labelStyle;
114
+ }
115
+ export function getLetterSpacing(browserType) {
116
+ switch (browserType) {
117
+ case 'opera':
118
+ return -0.0018;
119
+ case 'firefox':
120
+ return -0.23594210526315787;
121
+ case 'ie':
122
+ return -0.0019;
123
+ case 'edge':
124
+ return -0.0019;
125
+ case 'chrome':
126
+ return -0.0018;
127
+ case 'safari':
128
+ return -0.0018;
129
+ case 'blink':
130
+ return -0.0018;
131
+ default:
132
+ return -0.0018;
133
+ }
134
+ }
135
+ export function rescale(r, n) {
136
+ return r * n;
137
+ }
@@ -0,0 +1,18 @@
1
+ export interface ICountry {
2
+ code: string;
3
+ name: string;
4
+ value: string;
5
+ }
6
+ export declare const Countries: ICountry[];
7
+ export declare function getCountryByCode(code: string): ICountry | null;
8
+ export declare function isFrenchGuiana(code: string): boolean;
9
+ export declare function isGuadeloupe(code: string): boolean;
10
+ export declare function isMartinique(code: string): boolean;
11
+ export declare function isMayotte(code: string): boolean;
12
+ export declare function getPlusOneCountry(code: string): ICountry | null;
13
+ export declare function isCanada(code: string): boolean;
14
+ export declare function isAmericanSamoa(code: string): boolean;
15
+ export declare function isDominicanRepublic(code: string): boolean;
16
+ export declare function isPuertoRico(code: string): boolean;
17
+ export declare function getMatchingCountry(code: string, substrings: number): number;
18
+ export declare function simpleE164Validator(code: string): boolean;