@papercraftgames/estragon 0.1.0-beta.21 → 0.1.0-beta.22

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.
@@ -9,6 +9,7 @@ const Source = preload("source.gd")
9
9
  const MappedWriter = preload("source_map.gd")
10
10
 
11
11
  class Argument extends RefCounted:
12
+ var spread := false
12
13
  var expression: Model.GdExpression
13
14
  var type_name: String
14
15
  var name: String
@@ -100,6 +101,7 @@ func _collect(node: Model.Component, factory: Factory) -> void:
100
101
  for attribute in node.attributes:
101
102
  if attribute.value is Model.GdExpression:
102
103
  _argument(attribute.value, attribute.type_name, factory)
104
+ factory.arguments.back().spread = attribute.kind=="spread"
103
105
  if attribute.kind=="binding": factory.arguments.back().binding_path = attribute.binding_path
104
106
  for child in node.children:
105
107
  if child is Model.GdExpression: _argument(child,"Variant",factory)
@@ -143,8 +145,10 @@ func _call(node: Model.Component) -> void:
143
145
  if index > 0: _writer.append("," if multiline else ", ", node.span)
144
146
  if multiline: _writer.append("\n" + base + _module.indentation, argument.expression.span)
145
147
  _writer.append("(", argument.expression.span)
148
+ if argument.spread: _writer.append("preload("+_resource(Element)+").snapshot(",argument.expression.span)
146
149
  if argument.binding_path.is_empty(): _parts(argument.expression.parts)
147
150
  else: _binding_argument(argument)
151
+ if argument.spread: _writer.append(")",argument.expression.span)
148
152
  _writer.append(")", argument.expression.span)
149
153
  _writer.append(("\n" + base if multiline else "") + ")", node.span)
150
154
 
@@ -172,6 +176,8 @@ func _description(node: Model.Component, indentation: String) -> String:
172
176
  var bindings := PackedStringArray()
173
177
  var key := "null"
174
178
  var keyed := "false"
179
+ var expanded := node.attributes.any(func(item): return item.kind=="spread")
180
+ var ordered := PackedStringArray()
175
181
  for attribute in node.attributes:
176
182
  var value: String = _arguments[attribute.value].name if attribute.value is Model.GdExpression else literal(attribute.value)
177
183
  if attribute.kind == "binding":
@@ -181,6 +187,9 @@ func _description(node: Model.Component, indentation: String) -> String:
181
187
  key = value
182
188
  keyed = "true"
183
189
  continue
190
+ if expanded:
191
+ ordered.append("[%s, %s, %s]" % ["null" if attribute.kind=="spread" else _string(attribute.name),value,_string("%s:%d:%d" % [_file.name,attribute.name_span.start.line,attribute.name_span.start.column])])
192
+ continue
184
193
  var target := events if attribute.kind == "signal" else props
185
194
  target.append(_string(attribute.name)+": "+value)
186
195
  var children := PackedStringArray()
@@ -188,6 +197,7 @@ func _description(node: Model.Component, indentation: String) -> String:
188
197
  children.append(_arguments[child].name if child is Model.GdExpression else _description(child,indentation))
189
198
  var native_type := _string(node.runtime_class) if ClassDB.class_exists(node.runtime_class) else node.runtime_class
190
199
  _line("var %s := %s.new(%s, {%s}, {%s}, [%s], %s, %s, %s)" % [variable,_element_class,native_type,", ".join(props),", ".join(events),", ".join(children),_string("%s:%d:%d" % [_file.name,node.span.start.line,node.span.start.column]),key,keyed],node.span,indentation)
200
+ if expanded: _line(variable+".expand(["+", ".join(ordered)+"])",node.span,indentation)
191
201
  if not bindings.is_empty(): _line(variable+".bindings = {"+", ".join(bindings)+"}",node.span,indentation)
192
202
  return variable
193
203
 
@@ -57,6 +57,7 @@ class Literal extends SyntaxNode:
57
57
  kind = "raw-literal"
58
58
 
59
59
  class Attribute extends RefCounted:
60
+ var span: Span
60
61
  var binding_path: Array = []
61
62
  var kind: String = "property"
62
63
  var name: String
@@ -91,6 +91,15 @@ func _component(depth: int) -> Model.Component:
91
91
  if not separated:
92
92
  file.fail("Expected whitespace before a property, or a tag terminator", _cursor)
93
93
  return null
94
+ if _at("{"):
95
+ var spread := Model.Attribute.new()
96
+ spread.kind = "spread"
97
+ spread.name_span = file.span(_cursor,_cursor+1)
98
+ spread.value = _expression(true)
99
+ if spread.value==null: return null
100
+ spread.span = spread.value.span
101
+ node.attributes.append(spread)
102
+ continue
94
103
  var attribute_name := _name()
95
104
  if attribute_name == null: return null
96
105
  _whitespace()
@@ -124,6 +133,7 @@ func _component(depth: int) -> Model.Component:
124
133
  _cursor += 1
125
134
  lexer.token("markup-string", quote_start, _cursor)
126
135
  if attribute.value == null: return null
136
+ attribute.span = file.span(attribute.name_span.start.index,_cursor)
127
137
  node.attributes.append(attribute)
128
138
  _trivia()
129
139
  while not _at("</") and file.diagnostics.is_empty():
@@ -150,10 +160,23 @@ func _component(depth: int) -> Model.Component:
150
160
  node.span = file.span(start, _cursor)
151
161
  return node
152
162
 
153
- func _expression() -> Model.GdExpression:
163
+ func _expression(spread: bool = false) -> Model.GdExpression:
154
164
  var start := _cursor
155
- lexer.token("expression-open", start, start + 1)
156
- var scanned := _scan(start + 1, true)
165
+ var opening := 1
166
+ if spread:
167
+ var probe := Lexer.new(file)
168
+ var marker := start+1
169
+ while marker<file.text.length():
170
+ var token := probe.next_token(marker)
171
+ if token==null: return null
172
+ if token.kind not in ["whitespace","newline","comment","continuation"]: break
173
+ marker = token.span.end.index
174
+ if file.text.substr(marker,3)!="...":
175
+ file.fail("Expected ... in GGX spread attribute",marker)
176
+ return null
177
+ opening = marker+3-start
178
+ lexer.token("attribute-spread" if spread else "expression-open", start, start + opening)
179
+ var scanned := _scan(start + opening, true)
157
180
  if not file.diagnostics.is_empty(): return null
158
181
  if not scanned.has_token:
159
182
  file.fail("Expected a GDScript expression inside braces", start, scanned.end)
@@ -180,6 +203,9 @@ func _scan(start: int, braced: bool) -> Dictionary:
180
203
  var has_token := false
181
204
  while offset < file.text.length() and file.diagnostics.is_empty():
182
205
  var character := lexer.char_at(offset)
206
+ if file.text.substr(offset,3)=="...":
207
+ file.fail("Spread is only supported as {...expression} in a GGX opening attribute list",offset,offset+3)
208
+ break
183
209
  if braced and stack.is_empty() and character == "}":
184
210
  _copy(parts, copied, offset)
185
211
  return {"parts": parts, "end": offset, "has_token": has_token}
@@ -8,6 +8,7 @@ const Resolver = preload("native/resolver.gd")
8
8
  const StackContract = preload("../runtime/node/internal/stack_contract.gd")
9
9
  const VisualStyle = preload("../runtime/node/internal/visual_style_2d.gd")
10
10
  const Length = preload("../runtime/node/internal/length.gd")
11
+ const NativeAttributes = preload("../runtime/composition/native_attributes.gd")
11
12
  const Lexer = preload("lexer.gd")
12
13
  var file: Source
13
14
  var resolver
@@ -52,7 +53,12 @@ func _component(node: Model.Component) -> void:
52
53
  _error("Rect fill and background_color conflict; author only the canonical background_color or legacy fill",node.name_span)
53
54
  return
54
55
  var seen: Dictionary = {}
56
+ var expanded := node.attributes.any(func(item): return item.kind=="spread")
55
57
  for attribute in node.attributes:
58
+ if attribute.kind=="spread":
59
+ attribute.type_name = "Variant"
60
+ _node(attribute.value)
61
+ continue
56
62
  var name := attribute.name
57
63
  if VisualStyle.property(name) and VisualStyle.has_api(resolved.script) and not VisualStyle.supported(resolved.script):
58
64
  _error("Shared visual styling is unsupported on this participant",attribute.name_span)
@@ -87,7 +93,7 @@ func _component(node: Model.Component) -> void:
87
93
  _error("Inline anonymous GGX handlers are not supported; use a named handler/Callable", token.span)
88
94
  return
89
95
  index = token.span.end.index
90
- elif properties.has(name) and name not in ["owner", "script"] and not name.contains("/") and not (int(properties[name].usage) & PROPERTY_USAGE_READ_ONLY):
96
+ elif properties.has(name) and NativeAttributes.writable(resolved.native,resolved.script,name,properties[name]):
91
97
  attribute.type_name = "Variant" if Length.registered(resolved.script,name) or VisualStyle.registered(resolved.script,name) else _native_type(properties[name])
92
98
  if attribute.type_name.is_empty():
93
99
  _error("Unsupported Node property metadata: " + name, attribute.name_span)
@@ -95,7 +101,7 @@ func _component(node: Model.Component) -> void:
95
101
  else:
96
102
  _error("Removed layout API "+name+": use unit dimensions, grow and stretch" if name in ["flex","fill_width","fill_height","viewport_width_scale","viewport_height_scale"] else "Unknown, read-only or reserved Node property/signal " + name, attribute.name_span)
97
103
  return
98
- if StackContract.registered(resolved.script) and attribute.value is Model.Literal:
104
+ if not expanded and StackContract.registered(resolved.script) and attribute.value is Model.Literal:
99
105
  var message := StackContract.error(name,attribute.value.value,stack_direction,StackContract.preset(resolved.script))
100
106
  if not message.is_empty():
101
107
  _error(message,attribute.value.span)
@@ -129,7 +135,7 @@ func _component(node: Model.Component) -> void:
129
135
  _error("Node GGX children must be newly declared Node elements; expression adoption is unsupported", child.span)
130
136
  return
131
137
  _node(child)
132
- if child is Model.Component:
138
+ if child is Model.Component and not child.attributes.any(func(item): return item.kind=="spread"):
133
139
  for attribute in child.attributes:
134
140
  if attribute.name=="name" and attribute.value is Model.Literal:
135
141
  var name: String = str(attribute.value.value)
@@ -3,5 +3,5 @@
3
3
  name="Estragon"
4
4
  description="Native Gogo/GGX highlighting, compilation and validation before Play."
5
5
  author="Resist Design"
6
- version="0.1.0-beta.21"
6
+ version="0.1.0-beta.22"
7
7
  script="plugin.gd"
@@ -2,6 +2,7 @@ extends RefCounted
2
2
  const StackContract = preload("../node/internal/stack_contract.gd")
3
3
  const VisualStyle = preload("../node/internal/visual_style_2d.gd")
4
4
  const Length = preload("../node/internal/length.gd")
5
+ const NativeAttributes = preload("native_attributes.gd")
5
6
  const Profile = preload("profile.tres")
6
7
  ## F01 computation and retained static-shape records external to native objects.
7
8
  const Binding = preload("binding.gd")
@@ -16,6 +17,9 @@ class Mounted extends RefCounted:
16
17
  var keyed := false
17
18
  var slot: Array = []
18
19
  var properties: Dictionary = {}
20
+ var defaults: Dictionary = {}
21
+ var spread_owned: Dictionary = {}
22
+ var spread_applied: Dictionary = {}
19
23
  var handlers: Dictionary = {}
20
24
  var bindings: Dictionary = {}
21
25
  var children: Array = []
@@ -153,11 +157,16 @@ func _flush() -> void:
153
157
  # descriptor: callers may reuse either, and cycles must fail before native edits.
154
158
  func _normalize(value, ancestors: Array = [], level: int = 0):
155
159
  if not value is Element or level>128 or ancestors.has(value): return null
160
+ if not value.attribute_error.is_empty():
161
+ validation_error = value.attribute_error
162
+ return null
156
163
  if value.keyed and not _key_valid(value.key): return null
157
164
  var next := ancestors.duplicate()
158
165
  next.append(value)
159
166
  if Profile.is_enabled(): Profile.add("normalized_elements")
160
167
  var result := Element.new(value.type,value.properties,value.handlers,[],value.source,value.key,value.keyed)
168
+ result.origins = value.origins.duplicate()
169
+ result.spread_properties = value.spread_properties.duplicate()
161
170
  result.bindings = value.bindings.duplicate()
162
171
  if not _flatten(value.children,[],result.children,next,level+1): return null
163
172
  return result
@@ -220,8 +229,9 @@ func _valid(desired: Element, previous: Mounted) -> bool:
220
229
  else: return false
221
230
  for binding in desired.bindings.values():
222
231
  if not binding is Binding or not binding.valid: return false
223
- for handler in desired.handlers.values():
224
- if not handler is Callable or not handler.is_valid(): return false
232
+ for event in desired.handlers:
233
+ var handler = desired.handlers[event]
234
+ if not handler is Callable or not handler.is_valid(): return _invalid_attribute(desired,event,"signal requires a valid native Callable")
225
235
  var names := {}
226
236
  var keys := {}
227
237
  if desired.keyed and not _key_valid(desired.key): return false
@@ -234,7 +244,7 @@ func _valid(desired: Element, previous: Mounted) -> bool:
234
244
  keys[key] = true
235
245
  var name: String = str(child.properties.get("name",""))
236
246
  if not name.is_empty():
237
- if names.has(name): return false
247
+ if names.has(name): return _invalid_attribute(child,"name","duplicate declared sibling name "+name)
238
248
  names[name] = true
239
249
  return true
240
250
  func _collect_foreign(record, result: Array) -> void:
@@ -310,6 +320,16 @@ func _mount(desired: Element, parent: Node, owner: Node) -> Mounted:
310
320
  return record
311
321
  func _apply(desired: Element, record: Mounted) -> void:
312
322
  var node: Node = record.node.get_ref()
323
+ # Capture the real class/_init defaults before its first authored write, with
324
+ # no probe instances. Later first ownership preserves preexisting native state.
325
+ for key in desired.properties:
326
+ if not record.defaults.has(key):
327
+ record.defaults[key] = node.get(key)
328
+ # An unattached native Node starts unnamed, but set_name rejects empty
329
+ # names after attachment. Restore its native class label instead;
330
+ # Godot retains authority over sibling-name uniqueness.
331
+ if key=="name" and str(record.defaults[key]).is_empty(): record.defaults[key] = node.get_class()
332
+ var resets := _spread_resets(desired,record)
313
333
  for key in record.bindings.keys():
314
334
  if not desired.bindings.has(key) or not record.bindings[key].same(desired.bindings[key]):
315
335
  record.bindings[key].disconnect_edit()
@@ -323,7 +343,14 @@ func _apply(desired: Element, record: Mounted) -> void:
323
343
  if Profile.is_enabled(): Profile.add("property_writes")
324
344
  binding.attach(node,self)
325
345
  var stack := StackContract.registered(desired.type)
326
- if stack: node._apply_stack_policy(desired.properties)
346
+ if stack:
347
+ var policy := resets.duplicate()
348
+ policy.merge(desired.properties,true)
349
+ node._apply_stack_policy(policy)
350
+ for key in resets:
351
+ if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,resets[key])
352
+ writes += 1
353
+ if Profile.is_enabled(): Profile.add("property_writes")
327
354
  # An omitted previously declared border side removes that local override;
328
355
  # do not turn omission into permanent native state or change other props.
329
356
  if VisualStyle.supported(desired.type):
@@ -332,6 +359,12 @@ func _apply(desired: Element, record: Mounted) -> void:
332
359
  node.set(key,"auto")
333
360
  writes += 1
334
361
  if Profile.is_enabled(): Profile.add("property_writes")
362
+ if Length.registered(desired.type,"min_width"):
363
+ for key in Length.MINIMUMS:
364
+ if record.properties.has(key) and not desired.properties.has(key):
365
+ node.set(key,0.0)
366
+ writes += 1
367
+ if Profile.is_enabled(): Profile.add("property_writes")
335
368
  for key in desired.properties:
336
369
  if not record.properties.has(key) or not is_same(record.properties[key],desired.properties[key]):
337
370
  if not stack or key not in ["direction","horizontal_align","vertical_align"]: node.set(key,desired.properties[key])
@@ -348,6 +381,45 @@ func _apply(desired: Element, record: Mounted) -> void:
348
381
  if node.connect(event,desired.handlers[event],Object.CONNECT_PERSIST)!=OK: push_error("F01 native handler connection failed: "+desired.source)
349
382
  record.properties = desired.properties.duplicate()
350
383
  record.handlers = desired.handlers.duplicate()
384
+ record.spread_owned = desired.spread_properties.duplicate()
385
+ record.spread_applied.clear()
386
+ for key in desired.properties:
387
+ if record.spread_owned.has(key): record.spread_applied[key] = node.get(key)
388
+
389
+ func _spread_resets(desired: Element, record) -> Dictionary:
390
+ var result := {}
391
+ if record==null or not _compatible(desired,record): return result
392
+ var node = record.node.get_ref()
393
+ for key in record.spread_applied:
394
+ if desired.properties.has(key) or key in Length.BORDER_EDGES or key in Length.MINIMUMS: continue
395
+ # Do not overwrite imperative native changes made since our last commit.
396
+ if is_same(node.get(key),record.spread_applied[key]) and not is_same(node.get(key),record.defaults[key]): result[key] = record.defaults[key]
397
+ return result
398
+
399
+ func _effective_name(desired: Element, record) -> String:
400
+ if desired.properties.has("name"): return str(desired.properties.name)
401
+ var resets := _spread_resets(desired,record)
402
+ if resets.has("name"): return str(resets.name)
403
+ return str(record.node.get_ref().name) if _compatible(desired,record) else ""
404
+
405
+ func _invalid_attribute(desired: Element, key: String, message: String) -> bool:
406
+ validation_error = desired.location(key)+": attribute '"+key+"': "+message+"; previous tree retained"
407
+ return false
408
+
409
+ func _handler_error(handler: Callable, emitted: int) -> String:
410
+ # Named methods expose public metadata on both supported engines. Custom
411
+ # Callables without method metadata retain native invocation semantics.
412
+ if handler.is_custom(): return ""
413
+ var target = handler.get_object()
414
+ if target==null: return ""
415
+ for method in target.get_method_list():
416
+ if method.name!=handler.get_method(): continue
417
+ if int(method.flags)&METHOD_FLAG_VARARG: return ""
418
+ var supplied := emitted
419
+ var maximum: int = method.args.size()
420
+ if supplied<maximum-method.default_args.size() or supplied>maximum: return "Callable arity does not match native signal"
421
+ return ""
422
+ return ""
351
423
  func _compatible(desired: Element, record: Mounted) -> bool:
352
424
  if record == null: return false
353
425
  if desired.borrowed != null or record.borrowed != null:
@@ -391,17 +463,20 @@ func _prepare_names(desired: Array, matches: Array, parent: Node) -> void:
391
463
  for index in range(desired.size()):
392
464
  var next = desired[index]
393
465
  var old = matches[index]
394
- if next==null or old==null or not next.properties.has("name"): continue
395
- if old.properties.has("name") and is_same(old.properties.name,next.properties.name): continue
466
+ if next==null or old==null: continue
467
+ if not next.properties.has("name") and not _spread_resets(next,old).has("name"): continue
468
+ var final_name := _effective_name(next,old)
396
469
  var node: Node = old.node.get_ref()
397
- if node==null or node.get_parent()!=parent or str(node.name)==str(next.properties.name): continue
398
- pending.append(node)
399
- targets[str(next.properties.name)] = true
400
- for node in pending:
470
+ if node==null or node.get_parent()!=parent or str(node.name)==final_name: continue
471
+ pending.append([node,old])
472
+ targets[final_name] = true
473
+ for pair in pending:
474
+ var node: Node = pair[0]
401
475
  if not targets.has(str(node.name)): continue
402
476
  var temporary := "_EstragonRename_"+str(node.get_instance_id())
403
477
  while parent.has_node(NodePath(temporary)): temporary += "_"
404
478
  node.name = temporary
479
+ if pair[1].spread_applied.has("name"): pair[1].spread_applied.name = node.name
405
480
  writes += 1
406
481
  if Profile.is_enabled(): Profile.add("property_writes")
407
482
  # Keep a longest increasing subsequence of actual native indices. Everything
@@ -473,6 +548,7 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
473
548
  var signals: Dictionary = contracts[desired.type].signals
474
549
  if StackContract.registered(desired.type):
475
550
  var policy: Dictionary = previous.properties.duplicate() if previous!=null and _compatible(desired,previous) else {}
551
+ policy.merge(_spread_resets(desired,previous),true)
476
552
  policy.merge(desired.properties,true)
477
553
  var fixed := StackContract.preset(desired.type)
478
554
  var direction = policy.get("direction",fixed if not fixed.is_empty() else "row")
@@ -480,41 +556,42 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
480
556
  var value = policy.get(key,direction if key=="direction" else "start")
481
557
  var message := StackContract.error(key,value,str(direction),fixed)
482
558
  if not message.is_empty():
483
- validation_error = desired.source+": "+message+"; previous tree retained"
559
+ validation_error = desired.location(key)+": "+message+"; previous tree retained"
484
560
  return false
485
561
  if VisualStyle.rect_conflict(desired.type,desired.properties.keys()):
486
- validation_error = desired.source+": Rect fill and background_color conflict; previous tree retained"
562
+ validation_error = desired.location("fill")+": Rect fill and background_color conflict; previous tree retained"
487
563
  return false
488
564
  for key in desired.properties:
489
- if not properties.has(key) or key in ["script","owner"] or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
565
+ var native: String = desired.type if desired.type is String else desired.type.get_instance_base_type()
566
+ if not properties.has(key) or not NativeAttributes.writable(native,desired.type,str(key),properties[key]): return _invalid_attribute(desired,str(key),"unknown, read-only or reserved native property")
490
567
  var value = desired.properties[key]
491
568
  if VisualStyle.property(str(key)) and VisualStyle.has_api(desired.type) and not VisualStyle.supported(desired.type):
492
- validation_error = desired.source+": shared visual styling is unsupported on this participant; previous tree retained"
569
+ validation_error = desired.location(str(key))+": shared visual styling is unsupported on this participant; previous tree retained"
493
570
  return false
494
571
  if key=="grow" and Length.registered(desired.type,"width") and (not typeof(value) in [TYPE_INT,TYPE_FLOAT] or not is_finite(float(value)) or value<0):
495
- validation_error = desired.source+": grow requires a finite nonnegative weight; previous tree retained"
572
+ validation_error = desired.location(str(key))+": grow requires a finite nonnegative weight; previous tree retained"
496
573
  return false
497
574
  if key=="fill" and VisualStyle.marked(desired.type,"ESTRAGON_RECT_STYLE"):
498
575
  if not value is Color or VisualStyle.parse_color(value).has("error"):
499
- validation_error = desired.source+": Rect fill requires a finite native Color; previous tree retained"
576
+ validation_error = desired.location(str(key))+": Rect fill requires a finite native Color; previous tree retained"
500
577
  return false
501
578
  if VisualStyle.registered(desired.type,key):
502
579
  var parsed := VisualStyle.parse_color(value)
503
580
  if parsed.has("error"):
504
- validation_error = desired.source+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
581
+ validation_error = desired.location(str(key))+": invalid style '"+str(key)+"': "+parsed.error+"; previous tree retained"
505
582
  return false
506
583
  if Length.registered(desired.type,key):
507
584
  var parsed := Length.parse(value,Length.domain(key,desired.type))
508
585
  if parsed.has("error"):
509
- validation_error = desired.source+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
586
+ validation_error = desired.location(str(key))+": invalid length '"+str(key)+"': "+parsed.error+"; previous tree retained"
510
587
  return false
511
588
  var kind: int = properties[key].type
512
- if kind!=TYPE_NIL and typeof(value)!=kind and not (kind==TYPE_FLOAT and typeof(value)==TYPE_INT) and not (kind==TYPE_OBJECT and value==null) and not (kind in [TYPE_STRING,TYPE_STRING_NAME] and typeof(value) in [TYPE_STRING,TYPE_STRING_NAME]): return false
589
+ if kind!=TYPE_NIL and typeof(value)!=kind and not (kind==TYPE_FLOAT and typeof(value)==TYPE_INT) and not (kind==TYPE_OBJECT and value==null) and not (kind in [TYPE_STRING,TYPE_STRING_NAME] and typeof(value) in [TYPE_STRING,TYPE_STRING_NAME]): return _invalid_attribute(desired,str(key),"incompatible native value type")
513
590
  if kind==TYPE_OBJECT and value!=null:
514
591
  var expected: String = str(properties[key].get("class_name",""))
515
- if ClassDB.class_exists(expected) and not value.is_class(expected): return false
592
+ if ClassDB.class_exists(expected) and not value.is_class(expected): return _invalid_attribute(desired,str(key),"incompatible native Object class "+expected)
516
593
  for key in desired.bindings:
517
- if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return false
594
+ if key!="value" or desired.properties.has(key) or desired.handlers.has("value_changed") or not properties.has(key) or properties[key].type!=TYPE_BOOL or int(properties[key].usage)&PROPERTY_USAGE_READ_ONLY: return _invalid_attribute(desired,"value_changed" if desired.handlers.has("value_changed") else str(key),"invalid or conflicting controlled binding")
518
595
  var args: Array = signals.get("value_changed",{}).get("args",[])
519
596
 
520
597
  # 4.0 lacks signal argument type metadata. Compiler source proof and
@@ -522,12 +599,14 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
522
599
  # reject a valid input on that engine.
523
600
  if args.size()!=1 or args[0].type not in [TYPE_NIL,TYPE_BOOL]: return false
524
601
  for key in desired.handlers:
525
- if not signals.has(key): return false
602
+ if not signals.has(key): return _invalid_attribute(desired,str(key),"unknown native signal")
603
+ var message := _handler_error(desired.handlers[key],signals[key].get("args",[]).size())
604
+ if not message.is_empty(): return _invalid_attribute(desired,str(key),message)
526
605
  var node: Node = previous.node.get_ref() if _compatible(desired,previous) else null
527
606
  if parent != null:
528
- var name: String = str(desired.properties.get("name",str(node.name) if node != null else ""))
607
+ var name := _effective_name(desired,previous)
529
608
  for existing in parent.get_children():
530
- if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return false
609
+ if str(existing.name)==name and (previous==null or existing!=previous.node.get_ref()): return _invalid_attribute(desired,"name","native sibling name conflict "+name)
531
610
  var known: Array = []
532
611
  if node != null:
533
612
  for child in previous.children:
@@ -539,9 +618,9 @@ func _preflight(desired, previous, parent: Node, contracts: Variant = null) -> b
539
618
  if child == null or child.borrowed != null: continue
540
619
  var old = matches[index]
541
620
  if not _preflight(child,old,null,contracts): return false
542
- var name: String = str(child.properties.get("name",str(old.node.get_ref().name) if old!=null and _compatible(child,old) else ""))
621
+ var name := _effective_name(child,old)
543
622
  if not name.is_empty():
544
- if names.has(name): return false
623
+ if names.has(name): return _invalid_attribute(child,"name","duplicate effective sibling name "+name)
545
624
  names[name] = true
546
625
  if node != null:
547
626
  for existing in node.get_children():
@@ -14,6 +14,52 @@ var keyed: bool
14
14
  # Normalized authored child-slot/index path, external to native Nodes.
15
15
  var slot: Array = []
16
16
  var source: String
17
+ # Attribute provenance belongs to descriptions, never user Nodes or Dictionaries.
18
+ var origins: Dictionary = {}
19
+ var spread_properties: Dictionary = {}
20
+ var attribute_error := ""
21
+
22
+ # Snapshot at the argument evaluation point, before later expressions can mutate
23
+ # the same Dictionary. Values retain normal native reference semantics.
24
+ static func snapshot(value):
25
+ return value.duplicate() if value is Dictionary else value
26
+
27
+ func location(name: String) -> String:
28
+ return origins.get(name,source)
29
+
30
+ func expand(attributes: Array) -> void:
31
+ var values := {}
32
+ var signals := {}
33
+ var native: String = type if type is String else type.get_instance_base_type()
34
+ for event in ClassDB.class_get_signal_list(native): signals[str(event.name)] = true
35
+ var script = type if type is Script else null
36
+ while script != null:
37
+ for event in script.get_script_signal_list(): signals[str(event.name)] = true
38
+ script = script.get_base_script()
39
+ for entry in attributes:
40
+ if entry[0]!=null:
41
+ values[entry[0]] = entry[1]
42
+ origins[entry[0]] = entry[2]
43
+ spread_properties.erase(entry[0])
44
+ continue
45
+ if not entry[1] is Dictionary:
46
+ attribute_error = str(entry[2])+": GGX spread requires a Dictionary; previous tree retained"
47
+ return
48
+ for raw in entry[1]:
49
+ if not typeof(raw) in [TYPE_STRING,TYPE_STRING_NAME] or str(raw).is_empty():
50
+ attribute_error = str(entry[2])+": GGX spread key "+str(raw)+" requires a nonempty String/StringName; previous tree retained"
51
+ return
52
+ var name := str(raw)
53
+ if name=="key" or name.begins_with("bind:"):
54
+ attribute_error = str(entry[2])+": GGX spread key '"+name+"' must be explicitly authored; previous tree retained"
55
+ return
56
+ values[name] = entry[1][raw]
57
+ origins[name] = str(entry[2])+" (spread key '"+name+"')"
58
+ spread_properties[name] = true
59
+ for name in values:
60
+ if signals.has(name): handlers[name] = values[name]
61
+ else: properties[name] = values[name]
62
+
17
63
  func _init(native_type: Variant = null, props: Dictionary = {}, events: Dictionary = {}, descendants: Array = [], location: String = "", identity_key: Variant = null, has_key: bool = false) -> void:
18
64
  if Profile.is_enabled(): Profile.add("elements")
19
65
  key = identity_key
@@ -0,0 +1,26 @@
1
+ @tool
2
+ extends RefCounted
3
+ ## Native writable-property metadata, shared by compiler and description preflight.
4
+ # 4.0 lacks ClassDB's setter introspection. Its official 4.0.4 class reference
5
+ # declares these getter-only Node properties with setter="". This small bridge
6
+ # rejects them without probe Nodes or speculative setter-name inference. Newer
7
+ # engines use their actual ClassDB metadata, including newly introduced classes.
8
+ const BASELINE_READ_ONLY := {
9
+ "AnimationPlayer":["current_animation_length","current_animation_position"],
10
+ "Node":["multiplayer"],
11
+ "ShapeCast2D":["collision_result"],
12
+ "ShapeCast3D":["collision_result"],
13
+ "Timer":["time_left"],
14
+ }
15
+ static func writable(native: String, script, name: String, property: Dictionary) -> bool:
16
+ if name in ["owner","script"] or name.contains("/"): return false
17
+ if int(property.usage)&(PROPERTY_USAGE_READ_ONLY|PROPERTY_USAGE_CATEGORY|PROPERTY_USAGE_GROUP|PROPERTY_USAGE_SUBGROUP): return false
18
+ while script is Script:
19
+ for field in script.get_script_property_list():
20
+ if str(field.name)==name: return true
21
+ script = script.get_base_script()
22
+ if ClassDB.has_method("class_get_property_setter"):
23
+ return not str(ClassDB.call("class_get_property_setter",native,name)).is_empty()
24
+ for base in BASELINE_READ_ONLY:
25
+ if name in BASELINE_READ_ONLY[base] and ClassDB.is_parent_class(native,base): return false
26
+ return true
@@ -0,0 +1 @@
1
+ uid://ilri517yw03l
@@ -6,6 +6,7 @@ extends Node2D
6
6
  signal layout_applied(size: Vector2)
7
7
  const Coordinator = preload("internal/coordinator.gd")
8
8
  const ESTRAGON_LENGTHS := true
9
+ const ESTRAGON_MINIMUMS_2D := true
9
10
  const VisualStyle = preload("internal/visual_style_2d.gd")
10
11
  var _visual_style = VisualStyle.new()
11
12
  const Length = preload("internal/length.gd")
@@ -76,6 +77,16 @@ var padding_left: Variant = "auto":
76
77
  if is_same(padding_left,value) or not lengths.assign("padding_left",value): return
77
78
  padding_left = value
78
79
  _changed()
80
+ var min_width: Variant = 0.0:
81
+ set(value):
82
+ if is_same(min_width,value) or not lengths.assign("min_width",value): return
83
+ min_width = value
84
+ _changed()
85
+ var min_height: Variant = 0.0:
86
+ set(value):
87
+ if is_same(min_height,value) or not lengths.assign("min_height",value): return
88
+ min_height = value
89
+ _changed()
79
90
  var width: Variant = "auto":
80
91
  set(value):
81
92
  if is_same(width,value) or not lengths.assign("width",value): return
@@ -146,7 +157,7 @@ var layout_size: Vector2:
146
157
  var _layout_size := Vector2.ZERO
147
158
  var layout = Coordinator.new(self, 2, Coordinator.Mode.ENTRY if _is_layout_entry() else Coordinator.Mode.PARTICIPANT)
148
159
  func _get_property_list() -> Array[Dictionary]:
149
- var properties := Length.properties(["width","height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
160
+ var properties := Length.properties(["width","height","min_width","min_height","x","y","gap","padding","padding_top","padding_right","padding_bottom","padding_left","margin","margin_top","margin_right","margin_bottom","margin_left"])
150
161
  if VisualStyle.supported(get_script()): properties.append_array(Length.properties(["border_width","border_top_width","border_right_width","border_bottom_width","border_left_width","background_color","border_color"]))
151
162
  return properties
152
163
  static func valid_length(value) -> bool:
@@ -30,6 +30,8 @@ var fill := Vector3.ZERO
30
30
  var intrinsic := Vector3.ZERO
31
31
  # Native Control minimums constrain assigned slots, never read back from size.
32
32
  var allocation_minimum := Vector3.ZERO
33
+ # Authored border-box floors are independent of native adapter minimums.
34
+ var authored_minimum := Vector3.ZERO
33
35
  var padding := Vector4.ZERO # left, top, right, bottom; border-box insets
34
36
  var border := Vector4.ZERO # inside the border-box, before padding
35
37
  var margin := Vector4.ZERO # outside own geometry; consumed by the parent
@@ -108,23 +110,35 @@ func prepare(reference: Vector3, viewport: Vector2) -> void:
108
110
  if _length_context==context: return
109
111
  _length_context = context
110
112
  resolution_count += 1
111
- var before := [requested,gap,padding,border,margin,length_offset]
113
+ var before := [requested,gap,padding,border,margin,length_offset,authored_minimum]
112
114
  if not length_specs.is_empty():
113
115
  for index in range(3):
114
116
  requested[index] = _length(["width","height","depth"][index],index,requested[index])
115
117
  length_offset[index] = _length(["x","y","z"][index],index,0)
118
+ authored_minimum = Vector3(maxf(0,_length("min_width",0,0)),maxf(0,_length("min_height",1,0)),0)
116
119
  gap = _length("gap",axis,0)
117
120
  padding = _edges("padding")
118
121
  border = _edges("border")
119
122
  margin = _edges("margin")
120
- if before!=[requested,gap,padding,border,margin,length_offset]:
123
+ if before!=[requested,gap,padding,border,margin,length_offset,authored_minimum]:
121
124
  _measure_dirty = true
122
125
  _arrange_dirty = true
123
126
 
127
+ func minimum() -> Vector3:
128
+ var result := authored_minimum
129
+ var inherited: Vector3 = children[0].minimum() if transparent and children.size()==1 else Vector3.ZERO
130
+ for index in range(3): result[index] = maxf(result[index],maxf(allocation_minimum[index],inherited[index]))
131
+ return result
132
+
133
+ func constrain(extent: Vector3) -> Vector3:
134
+ var floor := minimum()
135
+ for index in range(3): extent[index] = maxf(extent[index],floor[index])
136
+ return extent
137
+
124
138
  func _content_basis() -> Vector3:
125
139
  var basis := Vector3(-1,-1,-1)
126
140
  for index in range(3):
127
- if requested[index]>=0: basis[index] = maxf(0,requested[index]-leading(padding+border)[index]-trailing(padding+border)[index])
141
+ if requested[index]>=0: basis[index] = maxf(0,maxf(requested[index],minimum()[index])-leading(padding+border)[index]-trailing(padding+border)[index])
128
142
  return basis
129
143
 
130
144
  static func valid_extent(value: Vector3) -> bool:
@@ -215,6 +229,7 @@ func measure() -> Vector3:
215
229
  measured = natural
216
230
  for axis in range(3):
217
231
  if requested[axis] >= 0: measured[axis] = requested[axis]
232
+ measured = constrain(measured)
218
233
  _measure_dirty = false
219
234
  return measured
220
235
 
@@ -227,6 +242,7 @@ func independent_axis(index: int) -> bool:
227
242
  return parent.independent_axis(index) if requested[index] < 0 and (fill[index] > 0 or (grow>0 if index==parent.axis else stretch>0)) else false
228
243
 
229
244
  func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
245
+ available = constrain(available)
230
246
  _external_axes = external_axes
231
247
  _warn_unanchored()
232
248
  var content := available-leading(padding+border)-trailing(padding+border)
@@ -280,7 +296,7 @@ func arrange(available: Vector3, external_axes: Vector3 = Vector3.ZERO) -> void:
280
296
  break
281
297
  var items: Array = []
282
298
  for child in children:
283
- items.append({"preferred":child.measured,"minimum":child.allocation_minimum,"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin)})
299
+ items.append({"preferred":child.measured,"minimum":child.minimum(),"requested":child.requested,"grow":child.grow,"stretch":child.stretch,"fill":child.fill,"outer":child.outer_extent(),"leading":leading(child.margin)})
284
300
  var policy := alignment.duplicate()
285
301
  if center: policy[axis] = "center"
286
302
  slots = StackPolicy.slots(items,content,axis,gap,policy)
@@ -7,6 +7,7 @@ extends RefCounted
7
7
  const VisualStyle = preload("visual_style_2d.gd")
8
8
  const LIMIT := 1.0e12
9
9
  const FACTORS := {"":1.0,"px":1.0,"in":96.0,"cm":96.0/2.54,"mm":96.0/25.4,"q":96.0/101.6,"pt":96.0/72.0,"pc":16.0}
10
+ const MINIMUMS := ["min_width","min_height"]
10
11
  const DIMENSIONS := ["width","height","depth"]
11
12
  const BORDER_EDGES := ["border_top_width","border_right_width","border_bottom_width","border_left_width"]
12
13
  const OFFSETS := ["x","y","z"]
@@ -16,6 +17,7 @@ var parse_count := 0
16
17
  static func domain(name: String, script = null) -> String:
17
18
  if name=="padding" and VisualStyle.marked(script,"ESTRAGON_BUTTON_STYLE"): return "edge"
18
19
  if name in DIMENSIONS: return "extent"
20
+ if name in MINIMUMS: return "edge"
19
21
  if name=="border_width": return "inset"
20
22
  if name in BORDER_EDGES: return "edge"
21
23
  if name in OFFSETS: return "offset"
@@ -23,6 +25,7 @@ static func domain(name: String, script = null) -> String:
23
25
  return "inset" if name=="gap" else ""
24
26
  static func registered(type, name: String) -> bool:
25
27
  if domain(name).is_empty() or not type is Script: return false
28
+ if name in MINIMUMS and not VisualStyle.marked(type,"ESTRAGON_MINIMUMS_2D"): return false
26
29
  if name=="border_width" or name in BORDER_EDGES:
27
30
  if not VisualStyle.supported(type): return false
28
31
  while type != null:
@@ -79,8 +82,8 @@ static func dependencies(specs: Dictionary, stack_axis: int) -> Array:
79
82
  for name in specs:
80
83
  var unit: String = specs[name].unit
81
84
  if unit=="%":
82
- if name in ["width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
83
- elif name in ["height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
85
+ if name in ["width","min_width","x","margin_left","margin_right","padding_left","padding_right","border_left_width","border_right_width"]: parent_axes.x = 1
86
+ elif name in ["height","min_height","y","margin_top","margin_bottom","padding_top","padding_bottom","border_top_width","border_bottom_width"]: parent_axes.y = 1
84
87
  elif name in ["depth","z"]: parent_axes.z = 1
85
88
  elif name=="gap": parent_axes[stack_axis] = 1
86
89
  else: parent_axes = Vector3(1,1,parent_axes.z)
@@ -29,9 +29,8 @@ func apply_layout_position(offset: Vector3) -> void:
29
29
  position = Vector2(value.x, value.y)
30
30
 
31
31
  func apply_layout_size(size: Vector3) -> void:
32
- _layout_size = Vector2(size.x, size.y)
33
- if layout.parent_coordinator() != null: layout._place(layout.model.offset)
34
- layout_applied.emit(_layout_size)
32
+ # Preserve bounds-aware placement through the inherited native size/redraw hook.
33
+ super.apply_layout_size(size)
35
34
 
36
35
  func get_native_bounds() -> Rect2:
37
36
  return Rect2(Vector2(bounds.origin.x, bounds.origin.y), Vector2(bounds.extent.x, bounds.extent.y))
package/package.json CHANGED
@@ -29,5 +29,5 @@
29
29
  "tag": "beta",
30
30
  "registry": "https://registry.npmjs.org/"
31
31
  },
32
- "version": "0.1.0-beta.21"
32
+ "version": "0.1.0-beta.22"
33
33
  }