humanmap-vas 1.0.2 → 1.0.21

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.
@@ -117,19 +117,62 @@
117
117
  this._view=this.getAttribute('view') || 'head_right';
118
118
  this._zones=ZONES;
119
119
  this._selected=new Set();
120
- this._bg={
121
- head_right:'src/img/head_right.svg',
122
- head_left:'src/img/head_left.svg',
123
- neck_right:'src/img/neck_right.svg',
124
- neck_left:'src/img/neck_left.svg',
125
- thorax_front:'src/img/torax_front.svg',
126
- thorax_back:'src/img/torax_back.svg'
120
+
121
+ // Detectar automáticamente la ruta base del script (compatible con todos los entornos)
122
+ let scriptBase = '';
123
+ try {
124
+ if (document.currentScript && document.currentScript.src) {
125
+ scriptBase = document.currentScript.src.split('/').slice(0, -1).join('/') + '/';
126
+ } else {
127
+ const scripts = document.getElementsByTagName('script');
128
+ if (scripts.length > 0) {
129
+ const last = scripts[scripts.length - 1];
130
+ scriptBase = last.src.split('/').slice(0, -1).join('/') + '/';
131
+ }
132
+ }
133
+ } catch (err) {
134
+ console.warn('⚠️ No se pudo detectar ruta base del script:', err);
135
+ }
136
+
137
+ // Definir la raíz de imágenes (desde atributo o autodetectada)
138
+ this._imgRoot = this.getAttribute('img-root') || (scriptBase + 'src/img/');
139
+
140
+ // Configurar rutas base
141
+ this._bg = {
142
+ head_right: this._imgRoot + 'head_right.svg',
143
+ head_left: this._imgRoot + 'head_left.svg',
144
+ neck_right: this._imgRoot + 'neck_right.svg',
145
+ neck_left: this._imgRoot + 'neck_left.svg',
146
+ thorax_front: this._imgRoot + 'torax_front.svg',
147
+ thorax_back: this._imgRoot + 'torax_back.svg'
127
148
  };
128
149
  }
129
150
 
130
151
  connectedCallback(){this._renderShell();this._renderCanvas();}
131
- static get observedAttributes() { return ['view']; }
132
- attributeChangedCallback(n,o,v){if(o!==v&&n==='view'){this._view=v;if(this._root)this._renderCanvas();}}
152
+ static get observedAttributes() { return ['view', 'img-root']; }
153
+ attributeChangedCallback (name, oldValue, newValue) {
154
+ if (oldValue === newValue) return;
155
+
156
+ if (name === 'view') {
157
+ this._view = newValue;
158
+ if (this._root) this._renderCanvas();
159
+ return;
160
+ }
161
+
162
+ if (name === 'img-root' && newValue) {
163
+ this._imgRoot = newValue.endsWith('/') ? newValue : newValue + '/';
164
+ this._bg = {
165
+ head_right: this._imgRoot + 'head_right.svg',
166
+ head_left: this._imgRoot + 'head_left.svg',
167
+ neck_right: this._imgRoot + 'neck_right.svg',
168
+ neck_left: this._imgRoot + 'neck_left.svg',
169
+ thorax_front: this._imgRoot + 'torax_front.svg',
170
+ thorax_back: this._imgRoot + 'torax_back.svg'
171
+ };
172
+ if (this._root) this._renderCanvas();
173
+ return;
174
+ }
175
+ }
133
176
 
134
177
  getSelected(){
135
178
  const map=new Map(this._zones.map(z=>[z.id,z]));
@@ -142,8 +185,12 @@
142
185
  clear(){this._selected.clear();this._renderZones();this._emit();}
143
186
 
144
187
  _renderShell(){
145
- const style=document.createElement('style');style.textContent=STYLE;
146
- this._root=document.createElement('div');this._root.className='hm';
188
+ const style=document.createElement('style');
189
+ style.textContent=STYLE;
190
+
191
+ this._root=document.createElement('div');
192
+ this._root.className='hm';
193
+
147
194
  const opts=VIEWS.map(v=>`<option value="${v.id}">${v.label}</option>`).join('');
148
195
  this._root.innerHTML=`
149
196
  <div class="hm-toolbar">
@@ -163,6 +210,7 @@
163
210
  </svg>
164
211
  </div>`;
165
212
  this.shadowRoot.append(style,this._root);
213
+
166
214
  this._els={
167
215
  cur:this.shadowRoot.getElementById('cur'),
168
216
  picker:this.shadowRoot.getElementById('picker'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanmap-vas",
3
- "version": "1.0.2",
3
+ "version": "1.0.21",
4
4
  "description": "**HumanMap VAS** es una librería web que permite graficar el cuerpo humano con vistas anatómicas interactivas para identificar zonas según el sistema VAS. Desarrollada como *Web Component standalone*, puede integrarse fácilmente en proyectos **HTML**, **Django**, o **Vue.js**.",
5
5
  "main": "humanmap-vas-standalone.js",
6
6
  "files": [