@neurodyn/model-viewer 0.0.13 → 0.0.15

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.
@@ -42,13 +42,85 @@ class ModelViewerDialogRenderer {
42
42
  }));
43
43
  }
44
44
  }
45
- function readTriggerProps(trigger, props = {}) {
45
+ function contract_attribute(name, parser, details) {
46
+ return {
47
+ kind: 'attribute',
48
+ name,
49
+ parse: parser.parse,
50
+ values: parser.values,
51
+ ...details
52
+ };
53
+ }
54
+ function defineTriggerContract() {
55
+ return (contract)=>contract;
56
+ }
57
+ function contract_attributeEntries(contract) {
58
+ return Object.entries(contract.fields).filter((entry)=>'attribute' === entry[1].kind);
59
+ }
60
+ function readRawAttribute(trigger, name, legacyNames = []) {
61
+ const value = trigger.getAttribute(name);
62
+ if (0 === legacyNames.length || value?.trim()) return value;
63
+ for (const legacyName of legacyNames){
64
+ const legacyValue = trigger.getAttribute(legacyName);
65
+ if (legacyValue?.trim()) return legacyValue;
66
+ }
67
+ return value;
68
+ }
69
+ function readTriggerAttributes(trigger, contract, options = {}) {
70
+ const values = {};
71
+ for (const [key, field] of contract_attributeEntries(contract)){
72
+ const name = `${contract.prefix}${field.name}`;
73
+ const option = options[key];
74
+ if (void 0 !== option) {
75
+ values[key] = field.normalizesOptions ? field.parse(option, {
76
+ attribute: name
77
+ }) : option;
78
+ continue;
79
+ }
80
+ values[key] = field.parse(readRawAttribute(trigger, name, field.legacyNames), {
81
+ attribute: name
82
+ });
83
+ }
84
+ return values;
85
+ }
86
+ function nullableText() {
46
87
  return {
47
- tinuuid: void 0 !== props.tinuuid ? props.tinuuid : trigger.getAttribute('data-neurodyn-model-viewer-tinuuid'),
48
- apiKey: void 0 !== props.apiKey ? props.apiKey : trigger.getAttribute('data-neurodyn-model-viewer-api-key'),
49
- hid: void 0 !== props.hid ? props.hid : trigger.getAttribute('data-neurodyn-model-viewer-hid')
88
+ parse: (raw)=>raw
50
89
  };
51
90
  }
91
+ const MODEL_VIEWER_INLINE_ATTRIBUTE = 'data-neurodyn-model-viewer';
92
+ const MODEL_VIEWER_DIALOG_TRIGGER_ATTRIBUTE = 'data-neurodyn-model-viewer-dialog';
93
+ const modelViewerContract = defineTriggerContract()({
94
+ prefix: 'data-neurodyn-model-viewer-',
95
+ markers: [
96
+ {
97
+ name: MODEL_VIEWER_DIALOG_TRIGGER_ATTRIBUTE,
98
+ description: 'Marks a dialog trigger for the embed build.'
99
+ },
100
+ {
101
+ name: MODEL_VIEWER_INLINE_ATTRIBUTE,
102
+ description: 'Marks a viewer container for the embed build.'
103
+ }
104
+ ],
105
+ fields: {
106
+ tinuuid: contract_attribute('tinuuid', nullableText(), {
107
+ required: true,
108
+ description: 'The unique identifier of the object.'
109
+ }),
110
+ apiKey: contract_attribute('api-key', nullableText(), {
111
+ required: true,
112
+ description: 'Public API key sent as `x-api-key`.'
113
+ }),
114
+ hid: contract_attribute('hid', nullableText(), {
115
+ required: false,
116
+ defaultValue: 'First material',
117
+ description: 'The identifier of a material variant.'
118
+ })
119
+ }
120
+ });
121
+ function readTriggerProps(trigger, props = {}) {
122
+ return readTriggerAttributes(trigger, modelViewerContract, props);
123
+ }
52
124
  class src_ModelViewer {
53
125
  roots = [];
54
126
  destroyed = false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neurodyn/model-viewer",
3
3
  "type": "module",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -22,7 +22,7 @@
22
22
  "react": "^19.2.0",
23
23
  "react-dom": "^19.2.0",
24
24
  "selector-observer": "^2.1.6",
25
- "@neurodyn/react-model-viewer": "0.0.13"
25
+ "@neurodyn/react-model-viewer": "0.1.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@microsoft/api-extractor": "^7.58.0",
@@ -40,6 +40,9 @@
40
40
  "dev": "rslib build --watch",
41
41
  "build": "rslib build",
42
42
  "test": "vitest run",
43
+ "test:contract": "vitest run",
44
+ "typecheck": "tsc --noEmit",
45
+ "docs:generate": "vitest run --update src/contract.docs.test.ts",
43
46
  "lint": "eslint .",
44
47
  "lint:fix": "eslint . --fix",
45
48
  "rsdoctor": "RSDOCTOR=true rslib build"