hokusai-zero 0.1.9 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 750449495b6ff533259afe965f85b4ec8da53768613b1636a011a9c0d63bfa54
4
- data.tar.gz: abedbc5fa46e999dfcd8af09b38d0bced547b527718cb4a5f5e88b639f358391
3
+ metadata.gz: 4542efc8a8b593b43f4366cafa23ac17be3af24eaf3e0b546808e98d9c40c107
4
+ data.tar.gz: c8acae8b6ab9799a49345885ac4dabe73bf3f2857b0d6fb5b0a375788291047e
5
5
  SHA512:
6
- metadata.gz: 1d4d7da22c16a69bb0e169027c25378395f3d3f58d7267bff3e26bdbcd323dafae067148e8d3c18dfcd59d87cd0b272072cd9735235f8f0f1681426f76474e73
7
- data.tar.gz: 8e8d26b0d9db21585c4575346233ba65467a6eb484a8ea17b121ab1b0972898c458393f284d0cfcd9a7e98e51061aaee71e3af878e304ef4345666d18b9e745e
6
+ metadata.gz: 8e306d86abb020663b9d2422a34d6e36535bf76b53a90c6542daf83128dbdb2df3d01672ffe90fed8efbcd3d25a23e570f2fd874734d1220d954113ad340a468
7
+ data.tar.gz: 4aefce03cb5cbd62ad5f240397de001c6c95904f3963f7918485366988db9d7aff4f885427e97aaf6158535dc3dc17ad01c4582e0d1b623e33cade8330d01c04
data/LICENSE CHANGED
@@ -1,7 +1,87 @@
1
- Copyright © 2025 <Sean Gregory>
1
+ LICENCE
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS COPYFARLEFT PUBLIC LICENSE (“LICENSE”). THE WORK IS PROTECTED BY COPYRIGHT AND ALL OTHER APPLICABLE LAWS. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED IN THIS LICENSE, YOU AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN AS CONSIDERATION FOR ACCEPTING THE TERMS AND CONDITIONS OF THIS LICENSE AND FOR AGREEING TO BE BOUND BY THE TERMS AND CONDITIONS OF THIS LICENSE.
4
+ 1 – DEFINITIONS
4
5
 
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+ a “Adaptation” means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image (“synching”) will be considered an Adaptation for the purpose of this License.
6
7
 
7
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+ b “Collection” means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(f) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
9
+
10
+ c – “Distribute” means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale, gift or any other transfer of possession or ownership.
11
+
12
+ d – “Licensor” means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
13
+
14
+ e – “Original Author” means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
15
+
16
+ f – “Work” means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
17
+
18
+ g – “You” means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
19
+
20
+ h – “Publicly Perform” means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
21
+
22
+ i – “Reproduce” means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
23
+ 2 – FAIR DEALING RIGHTS
24
+
25
+ Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
26
+ 3 – LICENSE GRANT
27
+
28
+ Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
29
+
30
+ a – to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
31
+
32
+ b – to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked “The original work was translated from English to Spanish,” or a modification could indicate “The original work has been modified.”;
33
+
34
+ c – to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
35
+
36
+ d – to Distribute and Publicly Perform Adaptations. The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights set forth in Section 4(f).
37
+ 4 – RESTRICTIONS
38
+
39
+ The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
40
+
41
+ a – You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested.
42
+
43
+ b – Subject to the exception in Section 4(c), you may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in connection with the exchange of copyrighted works.
44
+
45
+ c – You may exercise the rights granted in Section 3 for commercial purposes only if:
46
+
47
+ i – You are a worker-owned business or worker-owned collective; and
48
+
49
+ ii – all financial gain, surplus, profits and benefits produced by the business or collective are distributed among the worker-owners
50
+
51
+ d – Any use by a business that is privately owned and managed, and that seeks to generate profit from the labor of employees paid by salary or other wages, is not permitted under this license.
52
+
53
+ e – If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution (“Attribution Parties”) in Licensor’s copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., “French translation of the Work by Original Author,” or “Screenplay based on original Work by Original Author”). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
54
+
55
+ f – For the avoidance of doubt:
56
+
57
+ i – Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
58
+
59
+ ii – Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(b) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and,
60
+
61
+ iii – Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(b).
62
+
63
+ g – Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author’s honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author’s honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
64
+ 5 – REPRESENTATIONS, WARRANTIES AND DISCLAIMER
65
+
66
+ UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
67
+ 6 – LIMITATION ON LIABILITY
68
+
69
+ EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
70
+ 7 – TERMINATION
71
+
72
+ a – This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
73
+
74
+ b – Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
75
+ 8 – MISCELLANEOUS
76
+
77
+ a – Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
78
+
79
+ b – Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
80
+
81
+ c – If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
82
+
83
+ d – No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
84
+
85
+ e – This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
86
+
87
+ f – The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
data/README.md CHANGED
@@ -5,14 +5,14 @@ A Ruby library for authoring GUI applications
5
5
  [![status-badge](https://ci.skinnyjames.net/api/badges/skinnyjames/hokusai/status.svg)](https://ci.skinnyjames.net/skinnyjames/hokusai)
6
6
  [![guides](https://img.shields.io/badge/guide-skinnyjames.net-black.svg)](https://hokusai.skinnyjames.net)
7
7
  [![docs](https://img.shields.io/badge/documentation-codeberg_pages-blue.svg)](https://skinnyjames.codeberg.page/hokusai/)
8
- [![license](https://img.shields.io/badge/license-mit-teal.svg)](https://mit-license.org/)
8
+ [![license](https://img.shields.io/badge/license-ppl-teal.svg)](https://commonspoly.cc/licence)
9
9
 
10
10
  ## Getting started
11
11
 
12
12
  In your Gemfile
13
13
 
14
14
  ```ruby
15
- gem "hokusai-zero", "0.1.9"
15
+ gem "hokusai-zero", "0.2.1"
16
16
  ```
17
17
 
18
18
  ## In order to run an application, you will need to install a backend
@@ -132,4 +132,4 @@ Steps:
132
132
 
133
133
  ## License
134
134
 
135
- Hokusai is released under the [MIT License](https://mit-license.org/)
135
+ Hokusai is released under the [Peer Production License](https://commonspoly.cc/licence)
data/hokusai.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'hokusai-zero'
3
- s.version = '0.1.9'
4
- s.licenses = ['MIT']
3
+ s.version = '0.2.1'
4
+ s.licenses = ['PPL']
5
5
  s.summary = "A Ruby library for writing GUI applications"
6
6
  s.authors = ["skinnyjames"]
7
7
  s.email = 'zero@skinnyjames.net'
@@ -0,0 +1,117 @@
1
+ describe Hokusai::Diff, focus: true do
2
+ def patches(before, after)
3
+ patches = []
4
+
5
+ Hokusai::Diff.new(before, after).patch do |item|
6
+ patches << item
7
+ end
8
+
9
+ patches
10
+ end
11
+
12
+ it "inserts new items" do
13
+ list = patches([], [[:key1, 1],[:key2, 2],[:key3, 3]])
14
+
15
+ expect(list.count).to eq(3)
16
+
17
+ list.each_with_index do |patch, i|
18
+ expect(patch).to be_a(Hokusai::InsertPatch)
19
+ expect(patch.target).to eq(i)
20
+ expect(patch.value).to eq(i+1)
21
+ expect(patch.delete).to be(true)
22
+ end
23
+ end
24
+
25
+ it "inserts new items and deletes old items" do
26
+ list = patches(
27
+ [[:key1, 1], [:key2, 2], [:key3, 3]],
28
+ [[:key1, 1], [:key4, 4], [:key3, 3]]
29
+ )
30
+
31
+ expect(list.count).to eq(1)
32
+
33
+ # removes key2 and inserts key4 with 1 insertpatch
34
+ expect(list.first).to be_a(Hokusai::InsertPatch)
35
+ expect(list.first.target).to eq(1)
36
+ expect(list.first.value).to eq(4)
37
+ expect(list.first.delete).to be(true)
38
+ end
39
+
40
+ it "updates items with new values on existing keys" do
41
+ list = patches(
42
+ [[:key1, 1], [:key2, 2], [:key3, 3]],
43
+ [[:key1, 1], [:key2, 4], [:key3, 3]]
44
+ )
45
+
46
+ expect(list.count).to eq(1)
47
+
48
+ # removes key2 and inserts key4 with 1 insertpatch
49
+ expect(list.first).to be_a(Hokusai::UpdatePatch)
50
+ expect(list.first.target).to eq(1)
51
+ expect(list.first.value).to eq(4)
52
+ end
53
+
54
+ it "moves items that have the same key and no longer are in the list" do
55
+ list = patches(
56
+ [[:key1, 1], [:key2, 2], [:key3, 3]],
57
+ [[:key1, 1], [:key3, 3]]
58
+ )
59
+
60
+ expect(list.count).to eq(1)
61
+ expect(list.first).to be_a(Hokusai::MovePatch)
62
+ expect(list.first.from).to eq(2)
63
+ expect(list.first.to).to eq(1)
64
+ expect(list.first.value).to eq(3)
65
+ expect(list.first.delete).to be(true)
66
+ end
67
+
68
+ it "deletes items that have different keys and no longer are in the list" do
69
+ list = patches(
70
+ [[:key1, 1], [:key2, 2], [:key3, 3]],
71
+ [[:key2, 2], [:key3, 3]]
72
+ )
73
+
74
+ expect(list.count).to eq(3)
75
+ # moves position 1 to 0
76
+ expect(list[0]).to be_a(Hokusai::MovePatch)
77
+ expect(list[0].from).to eq(1)
78
+ expect(list[0].to).to eq(0)
79
+ expect(list[0].delete).to be(true)
80
+
81
+ # moves position 2 to 1
82
+ expect(list[1]).to be_a(Hokusai::MovePatch)
83
+ expect(list[1].from).to eq(2)
84
+ expect(list[1].to).to eq(1)
85
+
86
+ # delete position 2
87
+ expect(list[2]).to be_a(Hokusai::DeletePatch)
88
+ expect(list[2].target).to eq(2)
89
+ end
90
+
91
+ it "moves items around" do
92
+ # [d, a, c] [(c), e, a, b]
93
+ list = patches(
94
+ [[:key1, :d], [:key2, :a], [:key3, :c]],
95
+ [[:key3, :c], [:key4, :e], [:key2, :a], [:key5, :b]]
96
+ )
97
+
98
+ expect(list.count).to eq(3)
99
+
100
+ # Moves [key3, c] to position 0 and deletes [key1, d]
101
+ expect(list[0]).to be_a(Hokusai::MovePatch)
102
+ expect(list[0].from).to eq(2)
103
+ expect(list[0].to).to eq(0)
104
+ expect(list[0].delete).to eq(true)
105
+
106
+ # Inserts [key4, e] into position 1
107
+ expect(list[1]).to be_a(Hokusai::InsertPatch)
108
+ expect(list[1].target).to eq(1)
109
+ expect(list[1].value).to eq(:e)
110
+ expect(list[1].delete).to be(false)
111
+
112
+ expect(list[2]).to be_a(Hokusai::InsertPatch)
113
+ expect(list[2].target).to eq(3)
114
+ expect(list[2].value).to eq(:b)
115
+ expect(list[2].delete).to eq(true) # delete doesn't need to be true here...
116
+ end
117
+ end
@@ -27,7 +27,7 @@ describe "Providers" do
27
27
  slot
28
28
  EOF
29
29
 
30
- provide :provision, counter_klass.new
30
+ provide :provision, counter_klass.new
31
31
 
32
32
  def state
33
33
  self.class.provides[:provision]
@@ -212,4 +212,91 @@ describe "Providers" do
212
212
  expect(provided.state.count).to eq(2)
213
213
  end
214
214
  end
215
+
216
+ describe "Loops with conditionals" do
217
+ let(:loop_if_container) do
218
+ provider_klass = provider
219
+ inject_klass = inject
220
+
221
+ c = Class.new(Hokusai::Block) do
222
+ template <<~EOF
223
+ [template]
224
+ container
225
+ provision
226
+ [for="value in values"]
227
+ vblock { :key="value" }
228
+ [if="show"]
229
+ vblock
230
+ inject
231
+ [else]
232
+ vblock
233
+ injectelse
234
+ control
235
+ EOF
236
+
237
+ uses(
238
+ container: Hokusai::Blocks::Vblock,
239
+ vblock: Hokusai::Blocks::Vblock,
240
+ control: inject_klass,
241
+ inject: inject_klass,
242
+ injectelse: inject_klass,
243
+ provision: provider_klass
244
+ )
245
+
246
+ attr_accessor :show
247
+
248
+ def initialize(**args)
249
+ @show = false
250
+
251
+ super
252
+ end
253
+
254
+ def values
255
+ [1,2,3,4,5]
256
+ end
257
+
258
+ def toggle
259
+ self.show = !show
260
+ end
261
+ end
262
+
263
+ c.mount
264
+ end
265
+
266
+ it "provisions extend to conditional children in loops" do
267
+ loop_if_container.toggle
268
+ loop_if_container.update
269
+
270
+ injecteds = get_blocks_by_type(loop_if_container, "inject")
271
+ provided = get_block_by_type(loop_if_container, "provision")
272
+ control = get_block_by_type(loop_if_container, "control")
273
+
274
+ injecteds.each do |injected|
275
+ expect(injected.provision.count).to eq(0)
276
+ end
277
+
278
+ injecteds.first.provision.increment
279
+
280
+ injecteds.each do |injected|
281
+ expect(injected.provision.count).to eq(1)
282
+ end
283
+
284
+ expect(provided.state.count).to eq(1)
285
+ expect(control.provision).to be(nil)
286
+
287
+ loop_if_container.toggle
288
+ loop_if_container.update
289
+
290
+ inject_elses = get_blocks_by_type(loop_if_container, "injectelse")
291
+
292
+ inject_elses.each do |inject_else|
293
+ expect(inject_else.provision).not_to be(nil)
294
+ expect(inject_else.provision.count).to eq(1)
295
+ end
296
+
297
+ inject_elses.first.provision.increment
298
+
299
+ expect(provided.state.count).to eq(2)
300
+ end
301
+ end
215
302
  end
@@ -192,6 +192,12 @@ module Hokusai::Backends
192
192
  last_input_hash = nil
193
193
 
194
194
  until Raylib.WindowShouldClose
195
+ if Raylib.IsWindowFocused
196
+ Raylib.DisableEventWaiting
197
+ else
198
+ Raylib.EnableEventWaiting
199
+ end
200
+
195
201
  last_width = Raylib.GetScreenWidth
196
202
  last_height = Raylib.GetScreenHeight
197
203
 
@@ -206,9 +206,7 @@ class Hokusai::Blocks::Text < Hokusai::Block
206
206
  self.last_content = content
207
207
  end
208
208
 
209
- height = internal_render(last_clamping, canvas)
210
- self.last_content = last_content
211
-
209
+ height = internal_render(last_clamping, canvas)
212
210
  new_height = height + padding.bottom + padding.top
213
211
  new_height -= size if markdown
214
212
 
@@ -2,11 +2,12 @@ module Hokusai
2
2
  # Represents a patch to move a loop item
3
3
  # from one location to another
4
4
  class MovePatch
5
- attr_accessor :from, :to, :delete
5
+ attr_accessor :from, :to, :value, :delete
6
6
 
7
- def initialize(from:, to:, delete: false)
7
+ def initialize(from:, to:, value:, delete: false)
8
8
  @from = from
9
9
  @to = to
10
+ @value = value
10
11
  @delete = delete
11
12
  end
12
13
  end
@@ -96,12 +97,12 @@ module Hokusai
96
97
  # move a to 2
97
98
  before[bi[:index]] = [ckey, current] # before[2] = a
98
99
  # update index
99
- mapbefore[ckey] = { index: bi, value: current }
100
+ mapbefore[ckey] = { index: bi[:index], value: current }
100
101
 
101
102
  # move c to 0
102
- yield MovePatch.new(from: bi, to: i)
103
+ yield MovePatch.new(from: bi[:index], to: i, value: bi[:value])
103
104
  else
104
- yield MovePatch.new(from: bi, to: i, delete: true)
105
+ yield MovePatch.new(from: bi[:index], to: i, value: bi[:value], delete: true)
105
106
  mapbefore[ckey] = nil
106
107
  deletions += 1
107
108
  # next
@@ -120,7 +120,7 @@ module Hokusai
120
120
  end
121
121
 
122
122
  def has_ast?(ast, index)
123
- if portal = children![index]&.node&.portal
123
+ if portal = children![index]&.node&.portal&.portal
124
124
  return portal.ast.object_id == ast.object_id
125
125
  end
126
126
 
@@ -71,9 +71,7 @@ module Hokusai
71
71
  child_block.node.meta.set_prop(ast.loop.var.to_sym, value)
72
72
  child_block.node.meta.publisher.add(target)
73
73
 
74
- UpdateEntry.new(child_block, block, target).register(context: ctx)
75
-
76
- child_block.class.provides.merge!(parent.class.provides)
74
+ UpdateEntry.new(child_block, block, target).register(context: ctx, providers: mount_providers.merge(child_block.providers))
77
75
 
78
76
  block.node.meta << child_block
79
77
 
@@ -150,9 +148,8 @@ module Hokusai
150
148
  ctx.add_entry(ast.loop.var, patch.value)
151
149
  children[patch.target].node.add_styles(target.class)
152
150
  children[patch.target].node.add_props_from_block(target, context: ctx)
153
- children[patch.target].node.meta.set_prop(ast.loop.var.to_sym, patch.value)
154
151
 
155
- UpdateEntry.new(children[patch.target], uparent, utarget).register(context: ctx)
152
+ # UpdateEntry.new(children[patch.target], uparent, utarget).register(context: ctx)
156
153
  when MovePatch
157
154
  if patch.delete
158
155
  from = children[patch.from]
@@ -203,12 +200,10 @@ module Hokusai
203
200
  portal = Node.new(ast)
204
201
  node = child_block_class.compile(target_ast.type, portal)
205
202
  node.add_props_from_block(target, context: ctx)
206
- child_block = NodeMounter.new(node, child_block_class).mount(context: ctx)
203
+ child_block = NodeMounter.new(node, child_block_class).mount(context: nil, providers: mount_providers.merge(ublock.providers))
207
204
  child_block.node.add_styles(target.class)
208
205
  child_block.node.meta.publisher.add(target)
209
206
 
210
- child_block.class.provides.merge!(parent.class.provides)
211
-
212
207
  if patch.delete
213
208
  children[patch.target] = child_block
214
209
  else
@@ -40,18 +40,19 @@ module Hokusai
40
40
  unless child_present.call(child)
41
41
  portal = Node.new(child, Node.new(child))
42
42
  node = child_block_klass.compile("root", portal)
43
+ node.add_styles(target.class)
44
+ node.add_props_from_block(target, context: context)
45
+ node.meta.publisher.add(target)
46
+
43
47
  stack = []
44
48
  child.children.each_with_index do |ast, ast_index|
45
- stack << MountEntry.new(ast_index, ast, ublock, uparent, utarget)
49
+ stack << MountEntry.new(ast_index, ast, ublock, uparent, utarget, providers: providers)
46
50
  end
47
51
 
48
- child_block = NodeMounter.new(node, child_block_klass, [stack]).mount(context: context, providers: providers)
49
- UpdateEntry.new(child_block, block, target).register(context: context, providers: providers)
50
-
51
- child_block.node.add_styles(target.class)
52
- child_block.node.add_props_from_block(target, context: context)
53
- child_block.node.meta.publisher.add(target)
52
+ child_block = NodeMounter.new(node, child_block_klass, [stack], previous_providers: providers).mount(context: context, providers: providers)
54
53
 
54
+ UpdateEntry.new(child_block, block, target).register(context: context, providers: providers)
55
+
55
56
  meta.children!.insert(index, child_block)
56
57
 
57
58
  child_block.public_send(:before_updated) if child_block.respond_to?(:before_updated)
@@ -66,21 +67,21 @@ module Hokusai
66
67
  end
67
68
 
68
69
  if child.has_else_condition? && !child.else_condition_active?
69
- portal = Node.new(child, Node.new(child))
70
+ portal = Node.new(child.else_ast, Node.new(child))
70
71
  else_child_block_klass = target.class.use(child.else_ast.type)
71
- node = else_child_block_klass.compile(child.else_ast.type, portal)
72
72
 
73
+ node = else_child_block_klass.compile(child.else_ast.type, portal)
74
+ node.add_styles(utarget.class)
75
+ node.add_props_from_block(utarget, context: context)
76
+ node.meta.publisher.add(utarget)
77
+
73
78
  stack = []
74
79
  child.else_ast.children.each_with_index do |ast, ast_index|
75
- stack << MountEntry.new(ast_index, ast, ublock, uparent, utarget)
80
+ stack << MountEntry.new(ast_index, ast, ublock, uparent, utarget, providers: providers)
76
81
  end
77
82
 
78
- child_block = NodeMounter.new(node, else_child_block_klass, [stack]).mount(context: context, providers: providers)
83
+ child_block = NodeMounter.new(node, else_child_block_klass, [stack], previous_providers: providers).mount(context: context, providers: providers)
79
84
  UpdateEntry.new(child_block, block, utarget).register(context: context, providers: providers)
80
-
81
- child_block.node.add_styles(utarget.class)
82
- child_block.node.add_props_from_block(utarget, context: context)
83
- child_block.node.meta.publisher.add(utarget)
84
85
  meta.children!.insert(index, child_block)
85
86
 
86
87
  child_block.public_send(:before_updated) if child_block.respond_to?(:before_updated)
@@ -7,8 +7,8 @@ module Hokusai
7
7
  attr_accessor :primary_stack, :secondary_stack
8
8
  attr_reader :root
9
9
 
10
- def initialize(node, klass, secondary_stack = [], previous_target = nil)
11
- @root = klass.new(node: node)
10
+ def initialize(node, klass, secondary_stack = [], previous_target = nil, previous_providers: {})
11
+ @root = klass.new(node: node, providers: previous_providers)
12
12
 
13
13
  raise Hokusai::Error.new("Root #{klass} doesn't have a node. Did you remember to call `super`?") if @root.node.nil?
14
14
 
@@ -106,7 +106,6 @@ module Hokusai
106
106
  end
107
107
  end
108
108
 
109
- root.public_send(:on_mounted) if root.respond_to?(:on_mounted)
110
109
  root
111
110
  end
112
111
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hokusai-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - skinnyjames
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-05-25 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ffi
@@ -94,7 +93,6 @@ dependencies:
94
93
  - - ">="
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
97
- description:
98
96
  email: zero@skinnyjames.net
99
97
  executables: []
100
98
  extensions:
@@ -197,6 +195,7 @@ files:
197
195
  - ui/spec/hokusai/automation/keys_transcoder_spec.rb
198
196
  - ui/spec/hokusai/automation/selector_spec.rb
199
197
  - ui/spec/hokusai/block_spec.rb
198
+ - ui/spec/hokusai/diff_spec.rb
200
199
  - ui/spec/hokusai/directives_spec.rb
201
200
  - ui/spec/hokusai/e2e/client_spec.rb
202
201
  - ui/spec/hokusai/e2e/meta_spec.rb
@@ -293,10 +292,9 @@ files:
293
292
  - xmake.lua
294
293
  homepage: https://codeberg.org/skinnyjames/hokusai
295
294
  licenses:
296
- - MIT
295
+ - PPL
297
296
  metadata:
298
297
  source_code_uri: https://codeberg.org/skinnyjames/hokusai
299
- post_install_message:
300
298
  rdoc_options: []
301
299
  require_paths:
302
300
  - ui/src
@@ -311,8 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
309
  - !ruby/object:Gem::Version
312
310
  version: '0'
313
311
  requirements: []
314
- rubygems_version: 3.5.18
315
- signing_key:
312
+ rubygems_version: 3.6.7
316
313
  specification_version: 4
317
314
  summary: A Ruby library for writing GUI applications
318
315
  test_files: []